hayson-binding-shared
Everything a hayson language binding needs that is not about the foreign boundary itself. This
crate holds the parts that would otherwise be duplicated between
hayson-napi (Node native
addon) and hayson-wasm
(wasm32-wasip1):
errors— maps everyhayson-engineDatabaseError/TableErrorvariant onto a stable, machine-readable envelope ({ code, message, ...fields }) that a TS shim can switch on to re-throw the matching typed error.json— converts the engine's result types (HaysonRecord,TableStats,IntegrityReport,CompactionResult, query-plan summaries, …) into theserde_json::Valueshapes the bindings hand back across the boundary.options— parses the JSON document a binding'sopen()call receives into the engine's nativeOpenOptions(layout, locking, compaction, cipher settings), rejecting malformed input before the engine is ever touched.predicate— parses the JSON predicate/query documentTable::querytakes, including the operator aliaseshayson-server's ownpredicate_jsonaccepts, so a caller already speaking to the gRPC server can send the same document to an embedded binding.
Nothing in this crate knows what it is bound to — no NAPI types, no wasm-bindgen. The bindings
that do own their own handle bookkeeping and their own way of raising an error, and both depend on
the whole of this crate to avoid drifting apart on error shapes, option parsing or predicate
semantics.
Installation
Usage
use ;
// Turn an `open()` options JSON document into the engine's native `OpenOptions`.
let open_options = parse_open_options.unwrap;
// Turn a query predicate JSON document into the engine's `QuerySpec`.
let query_spec = parse_predicate.unwrap;
// Map an engine error onto the stable envelope a binding throws across the FFI boundary.
let envelope = describe_database_error;
See each module's doc comments for the exact function signatures and JSON shapes.