Skip to content

Translator.fromExports: the ESM wasm-import delivery path (runtime half) - #60

Merged
lann merged 1 commit into
mainfrom
translator-from-exports
Aug 10, 2026
Merged

Translator.fromExports: the ESM wasm-import delivery path (runtime half)#60
lann merged 1 commit into
mainfrom
translator-from-exports

Conversation

@lann

@lann lann commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

PR 3 of 4 from the #16 delivery design note (reordered before the package PR, which builds on it).

Deno's native wasm-module imports are the ideal translator delivery there — stable (unlike raw byte imports), permission-free (unlike readFile), module-cache-delivered — but they yield an instantiated namespace. Translator.fromExports(ns, {buildHash?}) wraps it: no compile, no copy.

Key pin: a dynamically wasm-imported shim translates byte-identically (envelope equality) to the create(bytes) path. Sharing safety documented (one ESM instance per realm; translate is synchronous end-to-end so calls cannot interleave). buildHash stays honest: unrecoverable from an instance → null (cache already refuses politely) or caller-supplied.

Gates: test-runtime 347/0, check. Next: @deltic/translator + defaultTranslator() consuming this on the Deno path.

…delivery path)

Item 4 of the #16 delivery design note, runtime half. Deno's native wasm-
module imports are stable, permission-free, and cached like any module —
the ideal translator delivery on Deno — but they hand back an
instantiated NAMESPACE, which Translator could not consume (create takes
bytes or a Module and instantiates internally).

fromExports(ns, {buildHash?}) wraps the namespace: no compile, no copy.
The private constructor now takes the exports record; the missing-export
validation is unchanged and refuses namespaces by name. Sharing is safe
by construction — ESM yields one instance per realm and translate() is
synchronous end-to-end, so calls cannot interleave — documented on the
method. buildHash cannot be recovered from an instance: null by default
(the artifact cache already handles that, cache/core.ts:120-127) or
supplied by a caller that knows the asset's hash (a published package
shipping a sidecar digest).

Pins (translator_from_exports_test.ts): a dynamically wasm-imported shim
translates BYTE-IDENTICALLY to the bytes-constructed path (envelope
equality); repeated translations on the shared instance are stable; a
short namespace is refused naming the missing export; the buildHash
contract.

Gates: test-runtime (full), check.
@lann
lann enabled auto-merge August 10, 2026 22:25
@lann
lann merged commit eb3f8d0 into main Aug 10, 2026
4 checks passed
@lannbot
lannbot deleted the translator-from-exports branch August 23, 2026 16:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant