Skip to content

Commit 58a728f

Browse files
dhermanclaude
andcommitted
feat(neon): Add typescript-ordermap feature
Adds a `typescript-ordermap` feature flag that provides a TypeScript impl for `ordermap::OrderMap<K, V>`, mapping to `Record<K, V>` (same as `HashMap` and `BTreeMap`). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent ad1867e commit 58a728f

4 files changed

Lines changed: 35 additions & 5 deletions

File tree

Cargo.lock

Lines changed: 14 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/neon/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ serde = { version = "1.0.197", optional = true }
4040
serde_json = { version = "1.0.114", optional = true }
4141
chrono = { version = "0.4", optional = true, default-features = false }
4242
uuid = { version = "1", optional = true }
43+
ordermap = { version = "1", optional = true }
4344

4445
[dependencies.tokio]
4546
version = "1.34.0"
@@ -63,6 +64,9 @@ typescript-chrono = ["typescript", "dep:chrono"]
6364
# TypeScript impl for uuid::Uuid (→ string)
6465
typescript-uuid = ["typescript", "dep:uuid"]
6566

67+
# TypeScript impl for ordermap::OrderMap<K, V> (→ Record<K, V>)
68+
typescript-ordermap = ["typescript", "dep:ordermap"]
69+
6670
# Enable the creation of external binary buffers. This is disabled by default
6771
# since these APIs fail at runtime in environments that enable the V8 memory
6872
# cage (such as Electron: https://www.electronjs.org/blog/v8-memory-cage).

crates/neon/src/typescript.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,22 @@ impl TypeScript for uuid::Uuid {
445445
}
446446
}
447447

448+
// ——— OrderMap ———
449+
450+
#[cfg(feature = "typescript-ordermap")]
451+
impl<K: TypeScript, V: TypeScript> TypeScript for ordermap::OrderMap<K, V> {
452+
fn ts_type() -> Cow<'static, str> {
453+
let k = K::ts_type();
454+
let v = V::ts_type();
455+
format!("Record<{k}, {v}>").into()
456+
}
457+
458+
fn ts_collect(decls: &mut BTreeMap<String, String>) {
459+
K::ts_collect(decls);
460+
V::ts_collect(decls);
461+
}
462+
}
463+
448464
// ——— Serde JSON wrapper ———
449465

450466
#[cfg(feature = "serde")]

doc/typescript.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ When an export uses a type from an external crate (e.g., `chrono::DateTime`,
353353
that type. There are three mechanisms to handle this:
354354

355355
1. **Built-in impls behind feature flags.** Neon can ship `TypeScript` implementations
356-
for popular crates: `neon = { features = ["typescript-chrono", "typescript-uuid"] }`.
356+
for popular crates: `neon = { features = ["typescript-chrono", "typescript-uuid", "typescript-ordermap"] }`.
357357
Each impl is a few lines mapping to the obvious TS type.
358358

359359
2. **Manual trait implementation.** Users can implement `TypeScript` for any type in

0 commit comments

Comments
 (0)