foobar
foobar
DDeno
Created by foobar on 9/15/2024 in #help
KV multimap / unordered keys search
the code example shows that you can't do it with prefix, only if your criterias meet exactly your key
5 replies
DDeno
Created by foobar on 9/15/2024 in #help
KV multimap / unordered keys search
in my example, I want to get all keys including ["users", "basket"]or ["basket", "users"], ie I don't care for orders. kv only authorises strict prefix, here only ["users","alex"] works In a real usecase, I want to filter on some criteria (country, city, sport...)
5 replies
DDeno
Created by Kei on 7/19/2024 in #help
What is the best way to find the specific npm package available on Deno?
@MaDsEn is building a site to check compatibility
4 replies
DDeno
Created by foobar on 7/2/2024 in #help
Share a data between multiple instances Deno Deploy
The new versions, agnostic to 1st instance
/**
* Channel for broadcasting key
*/
const channel = new BroadcastChannel("JWT_KEY");

let keyReceived = false;
let key = generateKey();

channel.onmessage = async (event: MessageEvent<Message>) => {
const message = event.data;
if (message.nature === "newinstance") {
// all instance send key
channel.postMessage({ nature: "key", data: key });
}
if (message.nature === "key" && !keyReceived) {
// only instance with keyReceived = false change key
keyReceived = true;
// new key
key = message.data;
}
};

/**
* All instance post the message
* if 1st instance => no onmessage (1:keyReceived = false )
* if 2nd instance => only 1st instance receive message => send key (1:keyReceived = false ; 2:keyReceived = true )
* if 3rd instance => all instance send message => first reponse received is good (1:keyReceived = true ; 2:keyReceived = true ; 3:keyReceived = true )
*/
channel.postMessage({ nature: "newinstance" });
/**
* Channel for broadcasting key
*/
const channel = new BroadcastChannel("JWT_KEY");

let keyReceived = false;
let key = generateKey();

channel.onmessage = async (event: MessageEvent<Message>) => {
const message = event.data;
if (message.nature === "newinstance") {
// all instance send key
channel.postMessage({ nature: "key", data: key });
}
if (message.nature === "key" && !keyReceived) {
// only instance with keyReceived = false change key
keyReceived = true;
// new key
key = message.data;
}
};

/**
* All instance post the message
* if 1st instance => no onmessage (1:keyReceived = false )
* if 2nd instance => only 1st instance receive message => send key (1:keyReceived = false ; 2:keyReceived = true )
* if 3rd instance => all instance send message => first reponse received is good (1:keyReceived = true ; 2:keyReceived = true ; 3:keyReceived = true )
*/
channel.postMessage({ nature: "newinstance" });
8 replies
DDeno
Created by foobar on 7/2/2024 in #help
Share a data between multiple instances Deno Deploy
thanks for your answer and information on instance. The key is a new key at each deploy that I don't want to set as en env variable. I didn't want also call kv at each time I read the key (too much read on kv if I can avoid it).
8 replies
DDeno
Created by foobar on 6/27/2024 in #help
Jsr, esm, x and external ref
I have the error message that zod-openapi is looking for export '@hono/hono@4.4.8'. How to link them with npm ?
8 replies
DDeno
Created by foobar on 5/24/2024 in #help
Debug test in visual studio & deno.jsonc
4 replies
DDeno
Created by foobar on 5/20/2024 in #help
Data sync input between parent and children
Thanks it works. I was a little bit out of date 😄 and I am upgrading with deno/fresh
4 replies
DDeno
Created by foobar on 5/20/2024 in #help
Data sync input between parent and children
routes/ToDoPage.tsx
export const handler: Handlers = {
async GET(req: Request, ctx: FreshContext) {
//...
// retrieve initial data from a DB (KV)
const initialData = await todo.list();
const res = await ctx.render({
...ctx.state,
initialData,
});
return res;
},
};

export default function ToDoPage(
{ data: { initialData } }: {data: { initialData: Todo[] }},
) {
// Save data modified in DB todos
const save = ()=> { //... }
return (
<>
// Print Todo Items
<ToDos data={initialData} />
</>
);
}
export const handler: Handlers = {
async GET(req: Request, ctx: FreshContext) {
//...
// retrieve initial data from a DB (KV)
const initialData = await todo.list();
const res = await ctx.render({
...ctx.state,
initialData,
});
return res;
},
};

export default function ToDoPage(
{ data: { initialData } }: {data: { initialData: Todo[] }},
) {
// Save data modified in DB todos
const save = ()=> { //... }
return (
<>
// Print Todo Items
<ToDos data={initialData} />
</>
);
}
islands/todos.tsx
export default function ToDos(props: Props) {
const data = useSignal<BenchItem[]>(props.data);
const message = useSignal("");

const addItem = () => {
const item = {
id: data.value.length,
name: "new item",
};
data.value = data.value.concat(item);
};

const change = (item: BenchItem) => {
// ?? code is correct ??
const newData = data.value.filter((x) => x.id !== item.id);
newData.push(item);
data.value = newData;
};

return (
<>
<button class="btn btn-primary" onClick={addItem}>
Add todo
</button>
// ?? Pass a signal item instead ??
{data.value?.map((item) => (
<TodoItem
item={item}
change={change}
/>
))}
</>
);
}
export default function ToDos(props: Props) {
const data = useSignal<BenchItem[]>(props.data);
const message = useSignal("");

const addItem = () => {
const item = {
id: data.value.length,
name: "new item",
};
data.value = data.value.concat(item);
};

const change = (item: BenchItem) => {
// ?? code is correct ??
const newData = data.value.filter((x) => x.id !== item.id);
newData.push(item);
data.value = newData;
};

return (
<>
<button class="btn btn-primary" onClick={addItem}>
Add todo
</button>
// ?? Pass a signal item instead ??
{data.value?.map((item) => (
<TodoItem
item={item}
change={change}
/>
))}
</>
);
}
islands/todoItem.tsx
const TodoItem = ({ item, change }) => {
// ?? use Signal to track change or only trigger a change function ??
const newItem = useSignal(item);

const doChange = useCallback(() => {
// ?? what to do here ??
// infinite loop ?
change(newItem.value);
}, [newItem]);

return (
<>
<input
type="text"
// ?? infinite loop ??
value={newItem.name}
// ?? doChange or link with a signal variable ??
onChange={doChange}
/>
</>
);
};
const TodoItem = ({ item, change }) => {
// ?? use Signal to track change or only trigger a change function ??
const newItem = useSignal(item);

const doChange = useCallback(() => {
// ?? what to do here ??
// infinite loop ?
change(newItem.value);
}, [newItem]);

return (
<>
<input
type="text"
// ?? infinite loop ??
value={newItem.name}
// ?? doChange or link with a signal variable ??
onChange={doChange}
/>
</>
);
};
4 replies
DDeno
Created by Poncho on 2/22/2024 in #help
Encryption using Deno KV and OAuth?
For my knowledge, why put key in kv store could be wrong ? effectively, in env variable nobody can see the key, in kv store, only admin can see it
7 replies
DDeno
Created by Poncho on 2/22/2024 in #help
Encryption using Deno KV and OAuth?
You need key to encrypt/decrypt. 3 possibilities for me, key - can be hard coding (bad way) - get from .env - store it in KV
7 replies
DDeno
Created by foobar on 2/20/2024 in #help
npm import : class is not found but it is well declared in node_module
5 replies
DDeno
Created by foobar on 1/15/2024 in #help
Fresh, deno deploy microservices and auth
Thanks for desmystify those points
12 replies
DDeno
Created by foobar on 1/15/2024 in #help
Fresh, deno deploy microservices and auth
Serve API with fresh is a good idea. I have 10 microservices in order to have a project more maintenable. In your proposal, don't i come back to a monolithic app ? what is the threshold in size of code between monolothic or microservice ?
12 replies
DDeno
Created by Wereii on 1/15/2024 in #help
rusty_v8 - how to pass data from js/v8 into rust
not function but maybe can help
4 replies
DDeno
Created by Wereii on 1/15/2024 in #help
rusty_v8 - how to pass data from js/v8 into rust
4 replies
DDeno
Created by foobar on 1/12/2024 in #help
Get input from an island, make calculus then render ?
Thx. I was afraid of missing something. I will write value in hidden input in order that form submisson could post data from island
3 replies
DDeno
Created by foobar on 10/28/2023 in #help
WASM / Extract and manipulate Array of Date
Solution on stackoverflow
use js_sys::{Array, Date, JsString};
use wasm_bindgen::prelude::*;

#[wasm_bindgen(js_name = DateArrayToString)]
pub fn date_array_to_string(arr: Array) -> JsString {
let mut result = JsString::from("");
for date_value in arr.values() {
let d: Date = date_value.expect("Some error occured.").into();
result = result.concat(&d.to_string());
}

result
}
use js_sys::{Array, Date, JsString};
use wasm_bindgen::prelude::*;

#[wasm_bindgen(js_name = DateArrayToString)]
pub fn date_array_to_string(arr: Array) -> JsString {
let mut result = JsString::from("");
for date_value in arr.values() {
let d: Date = date_value.expect("Some error occured.").into();
result = result.concat(&d.to_string());
}

result
}
3 replies