You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
2.3 KiB
Markdown
54 lines
2.3 KiB
Markdown
+++
|
|
title = "[TRIAGE] NanoID crate WASM compatibility with workers-rs target"
|
|
priority = 9
|
|
status = "done"
|
|
ticket_type = "task"
|
|
dependencies = []
|
|
+++
|
|
|
|
<context>
|
|
This is a triage decision ticket. It must be resolved before dependent implementation tickets can proceed.
|
|
</context>
|
|
|
|
<question>
|
|
NanoID crate WASM compatibility: does the chosen nanoid crate compile for wasm32-unknown-unknown with the workers-rs target? Some crates use thread-local RNG which is not available in WASM.
|
|
</question>
|
|
|
|
<options>
|
|
1. **nanoid crate** — check if it supports `getrandom` with `js` feature for WASM.
|
|
2. **uuid v4** — widely compatible, UUIDs are slightly longer than NanoIDs but universally supported.
|
|
3. **Custom NanoID** — implement NanoID generation using `getrandom` + custom alphabet. ~20 lines of code, no extra dependency.
|
|
</options>
|
|
|
|
<resolution>
|
|
**RESOLVED 2026-03-02 — Use UUID v4 (`uuid` crate).**
|
|
|
|
### Decision: Option 2 — uuid v4
|
|
|
|
The `nanoid` crate (v0.4.0) depends on `rand ^0.8`, which uses `thread_rng()` (thread-local RNG).
|
|
Thread-local storage is unreliable in wasm32-unknown-unknown, and the underlying `getrandom`
|
|
`wasm_js` feature is explicitly discouraged in libraries by the getrandom maintainers.
|
|
|
|
`uuid = { version = "1", features = ["v4", "serde"] }` with `getrandom = { version = "0.2",
|
|
features = ["js"] }` (wasm32 cfg section only) is the proven, zero-risk approach for
|
|
Cloudflare Workers. UUID v4 produces 36-char hyphenated IDs — slightly longer than NanoID's 21
|
|
chars, but negligible in practice and universally supported.
|
|
|
|
### Created ticket
|
|
|
|
7a0d9f — "Implement generate_id() in src/lib.rs — UUID v4 for WASM-compatible quote IDs"
|
|
- `generate_id()` in `src/lib.rs` returns `uuid::Uuid::new_v4().to_string()`
|
|
- Cargo.toml adds `uuid` to `[dependencies]` and `getrandom/js` under `[target.'cfg(target_arch = "wasm32")'.dependencies]`
|
|
- Ticket 05f8ae (PUT handler) and 1f5bb5 (Cargo.toml) updated to reference this approach
|
|
|
|
### Updated tickets
|
|
|
|
- 05f8ae: "Generate a NanoID for the quote ID" → use `generate_id()` from lib.rs (UUID v4)
|
|
- 1f5bb5: Add `uuid = { version = "1", features = ["v4", "serde"] }` to [dependencies]; add
|
|
`getrandom = { version = "0.2", features = ["js"] }` under wasm32 cfg
|
|
</resolution>
|
|
|
|
<commit>
|
|
`chore(quotesdb): resolve triage — nanoid-crate-wasm-compatibility-with-workersrs-target`
|
|
</commit>
|