Repository navigation
Conversation
One napi-rs 3 crate, recipher-js, defines the Cipher, Keyset and Ciphertext classes and runs encrypt and decrypt of one string through the engine. @napi-rs/cli v3 builds it and writes its TypeScript declarations to the committed native.d.ts. The TypeScript holds Result, RecipherError, the typed signatures over the native methods, and the adapter that turns each native outcome into a Result, so no call throws.
keyset.encrypt takes every value in vitaminc's JavaScript mapping, an array of them in one key request, and a JSON document made with json(..), a native class that reads the document when it is made. Ciphertext carries the kind it opens as, and Ciphertext.fromBytes(bytes, kind) reads stored bytes as a kind, kinds.json among them. vitaminc's refusals each get a code of their own. The binding interface is 2.
record(..), encrypt(..) and passthrough() declare a record as plain data. The crate builds the engine's plan from it with the engine's own types, once for each declaration, and encrypts and decrypts rows, and one field or an array of one field, through dynamic::Planned. A refusal names the record and the field. A decrypted row's inspect hides its values. The binding interface is 3.
…causes A RecipherError held the engine's code and a message with the help appended to it, and two of the structured fields. It now holds the whole diagnostic, as the Go SDK's does: help and url as properties of their own, every structured field, and the cause chain. A cause from another library is named as one and its message is never copied. A test lists every code the SDK gives an error of its own and checks each one's form.
|
Contributor
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true |
miette's Diagnostic has a severity, and the Go SDK's Diagnostic carries it. A RecipherError now does too: error unless the engine's diagnostic states warning or advice.
fields holds every structured field of the engine's error, the reason token among them, so the typed reason property was the same string a second way. It is removed. field and record stay: the SDK names them where the engine does not.
This was referenced Nov 24, 2026
coderdan
force-pushed
the
feat/recipher-js-records
branch
from
November 24, 2026 12:45
a0479fc to
17a20ff
Compare
This was referenced Nov 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
On top of #1776. A
RecipherErrornow carries the engine's whole diagnostic, the way the Go SDK'sDiagnosticdoes, instead of a code and a message with the help glued onto it.The engine's errors are miette diagnostics: each has a stable code, and many have a help text, structured fields and a chain of causes. Before this change the TypeScript SDK kept the code, appended the help to
message, read two of the fields (reasonandfield) and dropped the causes.The package is still private and takes no changeset.
Changes
helpandurlare properties of their own.messageis the engine's one line and nothing else, so a caller can show the help separately or leave it out.toString()prints the help on a second line.severityis the diagnostic's, as in Go:errorunless the engine's diagnostic stateswarningoradvice. No engine error states one today, so it is alwayserror.fieldsholds every structured field the engine gives (ErrorPayload::payload), bysnake_casename. The typedreasonproperty is gone, sincefields.reasonis the same string.fieldandrecordare unchanged.causeslists the errors behind this one, outermost first. A cause that is one of the engine's own errors gives its code and message. A cause from another library gives the fixed textan error from another library, and its own message is never copied: that text is not ours and can quote a value. This is the rule the Go guest's encoder follows (packages/stack-guest-abi/src/last_error.rs).recipher::…codes). It reads the Rust and TypeScript sources, checks each code's form with the engine'sdiagnostic::is_code_of, and fails when a code is added without being added to the list.serde-jsonfeature is on, sofieldscrosses as a plain object.thiserroris a dev-dependency for the test's probe errors. Both were already in the lockfile.The README's error section now has an example and a table of the properties.
Verification
Run locally in a worktree, with the debug addon rebuilt:
cargo test --locked --all-features: 39 and 4 passed.cargo fmt --all --checkandcargo clippy --locked --all-targets --all-features -- -D warnings: clean.vitest run: 29 passed.vitest run --config vitest.addon.config.ts: 76 passed.tsc --noEmit: clean. Biome: clean.native.d.tsis regenerated bybuild:debugand committed.Not run: the release build, and anything on Linux or Windows. CI is the check for those.
Review notes
urlis alwaysundefinedtoday. No engine error that the SDK can reach sets one. Engine errors have codes but no documentation links — decide the URL format and give every code a page #1790 is the engine issue for deciding the URL format and giving each code a page. The property is here so the link appears with no SDK change when the engine has it.reasonproperty is removed. It was the same string asfields.reason.fieldandrecordstay as typed properties: the SDK sets them itself where the engine does not name them (a value out of its field's range, a stored row's misfit), so they are not always infields.stack-guest-abi. Engine errors have codes but no documentation links — decide the URL format and give every code a page #1790 proposes moving it tostack-profileso both SDKs share it.fromNativereads an error without them.Related