recurram 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,16 @@
1
+ [package]
2
+ name = "recurram-napi"
3
+ version = "0.1.0"
4
+ edition = "2021"
5
+
6
+ [lib]
7
+ crate-type = ["cdylib"]
8
+
9
+ [dependencies]
10
+ recurram-bridge = { path = "../recurram-bridge" }
11
+ napi = { version = "2.16", default-features = false, features = ["napi8", "serde-json"] }
12
+ napi-derive = "2.16"
13
+ serde_json = "1.0"
14
+
15
+ [build-dependencies]
16
+ napi-build = "2.1"
@@ -0,0 +1,3 @@
1
+ fn main() {
2
+ napi_build::setup();
3
+ }
@@ -0,0 +1,230 @@
1
+ use recurram_bridge::{
2
+ decode_direct, decode_to_compact_json, decode_to_transport_json, encode_batch_compact_json,
3
+ encode_batch_direct_from_json, encode_batch_transport_json, encode_compact_json,
4
+ encode_direct_from_json, encode_transport_json, encode_with_schema_transport_json, BridgeError,
5
+ BridgeSessionEncoder, TransportValue,
6
+ };
7
+ use napi::bindgen_prelude::Buffer;
8
+ use napi_derive::napi;
9
+
10
+ fn to_napi_error(error: BridgeError) -> napi::Error {
11
+ napi::Error::from_reason(error.to_string())
12
+ }
13
+
14
+ fn transport_to_json(transport: TransportValue) -> napi::Result<serde_json::Value> {
15
+ serde_json::to_value(transport).map_err(|e| napi::Error::from_reason(e.to_string()))
16
+ }
17
+
18
+ // ── JSON-string based API (now using simd-json for parsing) ─────────────────
19
+
20
+ #[napi(js_name = "encodeTransportJson")]
21
+ pub fn encode_transport_json_napi(value_json: String) -> napi::Result<Buffer> {
22
+ encode_transport_json(value_json)
23
+ .map(Buffer::from)
24
+ .map_err(to_napi_error)
25
+ }
26
+
27
+ #[napi(js_name = "decodeToTransportJson")]
28
+ pub fn decode_to_transport_json_napi(bytes: Buffer) -> napi::Result<String> {
29
+ decode_to_transport_json(bytes.as_ref()).map_err(to_napi_error)
30
+ }
31
+
32
+ #[napi(js_name = "decodeToCompactJson")]
33
+ pub fn decode_to_compact_json_napi(bytes: Buffer) -> napi::Result<String> {
34
+ decode_to_compact_json(bytes.as_ref()).map_err(to_napi_error)
35
+ }
36
+
37
+ #[napi(js_name = "encodeWithSchemaTransportJson")]
38
+ pub fn encode_with_schema_transport_json_napi(
39
+ schema_json: String,
40
+ value_json: String,
41
+ ) -> napi::Result<Buffer> {
42
+ encode_with_schema_transport_json(schema_json, value_json)
43
+ .map(Buffer::from)
44
+ .map_err(to_napi_error)
45
+ }
46
+
47
+ #[napi(js_name = "encodeBatchTransportJson")]
48
+ pub fn encode_batch_transport_json_napi(values_json: String) -> napi::Result<Buffer> {
49
+ encode_batch_transport_json(values_json)
50
+ .map(Buffer::from)
51
+ .map_err(to_napi_error)
52
+ }
53
+
54
+ // ── Direct serde API (JS object → serde_json::Value → fast parse → encode) ─
55
+
56
+ #[napi(js_name = "encodeDirect")]
57
+ pub fn encode_direct_napi(value: serde_json::Value) -> napi::Result<Buffer> {
58
+ encode_direct_from_json(value)
59
+ .map(Buffer::from)
60
+ .map_err(to_napi_error)
61
+ }
62
+
63
+ #[napi(js_name = "decodeDirect")]
64
+ pub fn decode_direct_napi(bytes: Buffer) -> napi::Result<serde_json::Value> {
65
+ let transport = decode_direct(bytes.as_ref()).map_err(to_napi_error)?;
66
+ transport_to_json(transport)
67
+ }
68
+
69
+ #[napi(js_name = "encodeBatchDirect")]
70
+ pub fn encode_batch_direct_napi(values: serde_json::Value) -> napi::Result<Buffer> {
71
+ encode_batch_direct_from_json(values)
72
+ .map(Buffer::from)
73
+ .map_err(to_napi_error)
74
+ }
75
+
76
+ // ── Compact JSON API (smaller JSON via tagged arrays, simd-json parsed) ─────
77
+
78
+ #[napi(js_name = "encodeCompactJson")]
79
+ pub fn encode_compact_json_napi(json: String) -> napi::Result<Buffer> {
80
+ encode_compact_json(json)
81
+ .map(Buffer::from)
82
+ .map_err(to_napi_error)
83
+ }
84
+
85
+ #[napi(js_name = "encodeBatchCompactJson")]
86
+ pub fn encode_batch_compact_json_napi(json: String) -> napi::Result<Buffer> {
87
+ encode_batch_compact_json(json)
88
+ .map(Buffer::from)
89
+ .map_err(to_napi_error)
90
+ }
91
+
92
+ // ── Session encoder ─────────────────────────────────────────────────────────
93
+
94
+ #[napi]
95
+ pub struct SessionEncoder {
96
+ inner: BridgeSessionEncoder,
97
+ }
98
+
99
+ #[napi]
100
+ impl SessionEncoder {
101
+ #[napi(constructor)]
102
+ pub fn new(options_json: Option<String>) -> napi::Result<Self> {
103
+ let inner = BridgeSessionEncoder::new(options_json.as_deref()).map_err(to_napi_error)?;
104
+ Ok(Self { inner })
105
+ }
106
+
107
+ // JSON-string methods (now using simd-json for parsing internally)
108
+ #[napi(js_name = "encodeTransportJson")]
109
+ pub fn encode_transport_json(&mut self, value_json: String) -> napi::Result<Buffer> {
110
+ self.inner
111
+ .encode_transport_json(value_json)
112
+ .map(Buffer::from)
113
+ .map_err(to_napi_error)
114
+ }
115
+
116
+ #[napi(js_name = "encodeWithSchemaTransportJson")]
117
+ pub fn encode_with_schema_transport_json(
118
+ &mut self,
119
+ schema_json: String,
120
+ value_json: String,
121
+ ) -> napi::Result<Buffer> {
122
+ self.inner
123
+ .encode_with_schema_transport_json(schema_json, value_json)
124
+ .map(Buffer::from)
125
+ .map_err(to_napi_error)
126
+ }
127
+
128
+ #[napi(js_name = "encodeBatchTransportJson")]
129
+ pub fn encode_batch_transport_json(&mut self, values_json: String) -> napi::Result<Buffer> {
130
+ self.inner
131
+ .encode_batch_transport_json(values_json)
132
+ .map(Buffer::from)
133
+ .map_err(to_napi_error)
134
+ }
135
+
136
+ #[napi(js_name = "encodePatchTransportJson")]
137
+ pub fn encode_patch_transport_json(&mut self, value_json: String) -> napi::Result<Buffer> {
138
+ self.inner
139
+ .encode_patch_transport_json(value_json)
140
+ .map(Buffer::from)
141
+ .map_err(to_napi_error)
142
+ }
143
+
144
+ #[napi(js_name = "encodeMicroBatchTransportJson")]
145
+ pub fn encode_micro_batch_transport_json(
146
+ &mut self,
147
+ values_json: String,
148
+ ) -> napi::Result<Buffer> {
149
+ self.inner
150
+ .encode_micro_batch_transport_json(values_json)
151
+ .map(Buffer::from)
152
+ .map_err(to_napi_error)
153
+ }
154
+
155
+ // Direct serde methods (JS object → serde_json::Value → fast parse → encode)
156
+ #[napi(js_name = "encodeDirect")]
157
+ pub fn encode_direct(&mut self, value: serde_json::Value) -> napi::Result<Buffer> {
158
+ self.inner
159
+ .encode_direct_from_json(value)
160
+ .map(Buffer::from)
161
+ .map_err(to_napi_error)
162
+ }
163
+
164
+ #[napi(js_name = "encodeBatchDirect")]
165
+ pub fn encode_batch_direct(&mut self, values: serde_json::Value) -> napi::Result<Buffer> {
166
+ self.inner
167
+ .encode_batch_direct_from_json(values)
168
+ .map(Buffer::from)
169
+ .map_err(to_napi_error)
170
+ }
171
+
172
+ #[napi(js_name = "encodePatchDirect")]
173
+ pub fn encode_patch_direct(&mut self, value: serde_json::Value) -> napi::Result<Buffer> {
174
+ self.inner
175
+ .encode_patch_direct_from_json(value)
176
+ .map(Buffer::from)
177
+ .map_err(to_napi_error)
178
+ }
179
+
180
+ #[napi(js_name = "encodeMicroBatchDirect")]
181
+ pub fn encode_micro_batch_direct(&mut self, values: serde_json::Value) -> napi::Result<Buffer> {
182
+ self.inner
183
+ .encode_micro_batch_direct_from_json(values)
184
+ .map(Buffer::from)
185
+ .map_err(to_napi_error)
186
+ }
187
+
188
+ // Compact JSON methods (tagged array format, ~50% smaller JSON, simd-json parsed)
189
+ #[napi(js_name = "encodeCompactJson")]
190
+ pub fn encode_compact_json(&mut self, json: String) -> napi::Result<Buffer> {
191
+ self.inner
192
+ .encode_compact_json(json)
193
+ .map(Buffer::from)
194
+ .map_err(to_napi_error)
195
+ }
196
+
197
+ #[napi(js_name = "encodeBatchCompactJson")]
198
+ pub fn encode_batch_compact_json(&mut self, json: String) -> napi::Result<Buffer> {
199
+ self.inner
200
+ .encode_batch_compact_json(json)
201
+ .map(Buffer::from)
202
+ .map_err(to_napi_error)
203
+ }
204
+
205
+ #[napi(js_name = "encodePatchCompactJson")]
206
+ pub fn encode_patch_compact_json(&mut self, json: String) -> napi::Result<Buffer> {
207
+ self.inner
208
+ .encode_patch_compact_json(json)
209
+ .map(Buffer::from)
210
+ .map_err(to_napi_error)
211
+ }
212
+
213
+ #[napi(js_name = "encodeMicroBatchCompactJson")]
214
+ pub fn encode_micro_batch_compact_json(&mut self, json: String) -> napi::Result<Buffer> {
215
+ self.inner
216
+ .encode_micro_batch_compact_json(json)
217
+ .map(Buffer::from)
218
+ .map_err(to_napi_error)
219
+ }
220
+
221
+ #[napi]
222
+ pub fn reset(&mut self) {
223
+ self.inner.reset();
224
+ }
225
+ }
226
+
227
+ #[napi(js_name = "createSessionEncoder")]
228
+ pub fn create_session_encoder(options_json: Option<String>) -> napi::Result<SessionEncoder> {
229
+ SessionEncoder::new(options_json)
230
+ }
@@ -0,0 +1,11 @@
1
+ [package]
2
+ name = "recurram-wasm"
3
+ version = "0.1.0"
4
+ edition = "2021"
5
+
6
+ [lib]
7
+ crate-type = ["cdylib", "rlib"]
8
+
9
+ [dependencies]
10
+ recurram-bridge = { path = "../recurram-bridge" }
11
+ wasm-bindgen = "0.2"
@@ -0,0 +1,98 @@
1
+ use recurram_bridge::{
2
+ decode_to_transport_json, encode_batch_transport_json, encode_transport_json,
3
+ encode_with_schema_transport_json, BridgeSessionEncoder,
4
+ };
5
+ use wasm_bindgen::prelude::*;
6
+
7
+ fn into_js_error(error: impl ToString) -> JsValue {
8
+ JsValue::from_str(&error.to_string())
9
+ }
10
+
11
+ #[wasm_bindgen(js_name = encodeTransportJson)]
12
+ pub fn encode_transport_json_wasm(value_json: String) -> Result<Vec<u8>, JsValue> {
13
+ encode_transport_json(value_json).map_err(into_js_error)
14
+ }
15
+
16
+ #[wasm_bindgen(js_name = decodeToTransportJson)]
17
+ pub fn decode_to_transport_json_wasm(bytes: &[u8]) -> Result<String, JsValue> {
18
+ decode_to_transport_json(bytes).map_err(into_js_error)
19
+ }
20
+
21
+ #[wasm_bindgen(js_name = encodeWithSchemaTransportJson)]
22
+ pub fn encode_with_schema_transport_json_wasm(
23
+ schema_json: String,
24
+ value_json: String,
25
+ ) -> Result<Vec<u8>, JsValue> {
26
+ encode_with_schema_transport_json(schema_json, value_json).map_err(into_js_error)
27
+ }
28
+
29
+ #[wasm_bindgen(js_name = encodeBatchTransportJson)]
30
+ pub fn encode_batch_transport_json_wasm(values_json: String) -> Result<Vec<u8>, JsValue> {
31
+ encode_batch_transport_json(values_json).map_err(into_js_error)
32
+ }
33
+
34
+ #[wasm_bindgen]
35
+ pub struct SessionEncoder {
36
+ inner: BridgeSessionEncoder,
37
+ }
38
+
39
+ #[wasm_bindgen]
40
+ impl SessionEncoder {
41
+ #[wasm_bindgen(constructor)]
42
+ pub fn new(options_json: Option<String>) -> Result<SessionEncoder, JsValue> {
43
+ let inner = BridgeSessionEncoder::new(options_json.as_deref()).map_err(into_js_error)?;
44
+ Ok(Self { inner })
45
+ }
46
+
47
+ #[wasm_bindgen(js_name = encodeTransportJson)]
48
+ pub fn encode_transport_json(&mut self, value_json: String) -> Result<Vec<u8>, JsValue> {
49
+ self.inner
50
+ .encode_transport_json(value_json)
51
+ .map_err(into_js_error)
52
+ }
53
+
54
+ #[wasm_bindgen(js_name = encodeWithSchemaTransportJson)]
55
+ pub fn encode_with_schema_transport_json(
56
+ &mut self,
57
+ schema_json: String,
58
+ value_json: String,
59
+ ) -> Result<Vec<u8>, JsValue> {
60
+ self.inner
61
+ .encode_with_schema_transport_json(schema_json, value_json)
62
+ .map_err(into_js_error)
63
+ }
64
+
65
+ #[wasm_bindgen(js_name = encodeBatchTransportJson)]
66
+ pub fn encode_batch_transport_json(&mut self, values_json: String) -> Result<Vec<u8>, JsValue> {
67
+ self.inner
68
+ .encode_batch_transport_json(values_json)
69
+ .map_err(into_js_error)
70
+ }
71
+
72
+ #[wasm_bindgen(js_name = encodePatchTransportJson)]
73
+ pub fn encode_patch_transport_json(&mut self, value_json: String) -> Result<Vec<u8>, JsValue> {
74
+ self.inner
75
+ .encode_patch_transport_json(value_json)
76
+ .map_err(into_js_error)
77
+ }
78
+
79
+ #[wasm_bindgen(js_name = encodeMicroBatchTransportJson)]
80
+ pub fn encode_micro_batch_transport_json(
81
+ &mut self,
82
+ values_json: String,
83
+ ) -> Result<Vec<u8>, JsValue> {
84
+ self.inner
85
+ .encode_micro_batch_transport_json(values_json)
86
+ .map_err(into_js_error)
87
+ }
88
+
89
+ #[wasm_bindgen]
90
+ pub fn reset(&mut self) {
91
+ self.inner.reset();
92
+ }
93
+ }
94
+
95
+ #[wasm_bindgen(js_name = createSessionEncoder)]
96
+ pub fn create_session_encoder(options_json: Option<String>) -> Result<SessionEncoder, JsValue> {
97
+ SessionEncoder::new(options_json)
98
+ }
@@ -0,0 +1,4 @@
1
+ import type { InitOptions } from "./types.js";
2
+ import type { RuntimeBackend, RuntimeKind } from "./runtime/types.js";
3
+ export declare function initBackend(options?: InitOptions): Promise<RuntimeKind>;
4
+ export declare function requireBackend(): RuntimeBackend;
@@ -0,0 +1,47 @@
1
+ let backend = null;
2
+ let initPromise = null;
3
+ export async function initBackend(options = {}) {
4
+ if (backend) {
5
+ return backend.kind;
6
+ }
7
+ if (!initPromise) {
8
+ initPromise = loadBackend(options).catch((error) => {
9
+ initPromise = null;
10
+ throw error;
11
+ });
12
+ }
13
+ backend = await initPromise;
14
+ return backend.kind;
15
+ }
16
+ export function requireBackend() {
17
+ if (!backend) {
18
+ throw new Error("recurram is not initialized. Call await init() before encode/decode.");
19
+ }
20
+ return backend;
21
+ }
22
+ async function loadBackend(options) {
23
+ const prefer = options.prefer;
24
+ if (prefer === "napi") {
25
+ if (!isNodeRuntime()) {
26
+ throw new Error("N-API backend is only available in Node.js");
27
+ }
28
+ const { loadNodeBackend } = await import("./runtime/node-backend.js");
29
+ return loadNodeBackend();
30
+ }
31
+ if (prefer === "wasm") {
32
+ if (isNodeRuntime()) {
33
+ throw new Error("WASM backend is intended for browser JS. Use prefer: 'napi' on Node.js");
34
+ }
35
+ const { loadWasmBackend } = await import("./runtime/wasm-backend.js");
36
+ return loadWasmBackend(options.wasmInput);
37
+ }
38
+ if (isNodeRuntime()) {
39
+ const { loadNodeBackend } = await import("./runtime/node-backend.js");
40
+ return loadNodeBackend();
41
+ }
42
+ const { loadWasmBackend } = await import("./runtime/wasm-backend.js");
43
+ return loadWasmBackend(options.wasmInput);
44
+ }
45
+ function isNodeRuntime() {
46
+ return typeof process !== "undefined" && Boolean(process.versions?.node);
47
+ }
@@ -0,0 +1,51 @@
1
+ import type { InitOptions, RecurramValue, Schema, SessionOptions } from "./types.js";
2
+ import type { RuntimeKind, RuntimeSessionEncoder } from "./runtime/types.js";
3
+ export type { InitOptions, RecurramValue, Schema, SchemaField, SessionOptions, UnknownReferencePolicy, } from "./types.js";
4
+ export declare function init(options?: InitOptions): Promise<RuntimeKind>;
5
+ export declare function toTransportJson(value: RecurramValue): string;
6
+ export declare function fromTransportJson(valueJson: string): RecurramValue;
7
+ export declare function toTransportJsonBatch(values: RecurramValue[]): string;
8
+ export declare function encodeTransportJson(valueJson: string): Uint8Array;
9
+ export declare function decodeToTransportJson(bytes: Uint8Array): string;
10
+ export declare function encodeBatchTransportJson(valuesJson: string): Uint8Array;
11
+ export declare function encode(value: RecurramValue): Uint8Array;
12
+ export declare function decode(bytes: Uint8Array): RecurramValue;
13
+ export declare function encodeWithSchema(schema: Schema, value: RecurramValue): Uint8Array;
14
+ export declare function encodeBatch(values: RecurramValue[]): Uint8Array;
15
+ export declare function encodeDirect(value: RecurramValue): Uint8Array;
16
+ export declare function decodeDirect(bytes: Uint8Array): RecurramValue;
17
+ export declare function encodeBatchDirect(values: RecurramValue[]): Uint8Array;
18
+ export declare function toCompactJson(value: RecurramValue): string;
19
+ export declare function toCompactJsonBatch(values: RecurramValue[]): string;
20
+ export declare function encodeCompactJson(json: string): Uint8Array;
21
+ export declare function decodeToCompactJson(bytes: Uint8Array): string;
22
+ export declare function encodeBatchCompactJson(json: string): Uint8Array;
23
+ export declare function encodeCompact(value: RecurramValue): Uint8Array;
24
+ export declare function encodeBatchCompact(values: RecurramValue[]): Uint8Array;
25
+ export declare function createSessionEncoder(options?: SessionOptions): SessionEncoder;
26
+ export declare class SessionEncoder {
27
+ #private;
28
+ constructor(inner: RuntimeSessionEncoder);
29
+ encode(value: RecurramValue): Uint8Array;
30
+ encodeTransportJson(valueJson: string): Uint8Array;
31
+ encodeWithSchema(schema: Schema, value: RecurramValue): Uint8Array;
32
+ encodeBatch(values: RecurramValue[]): Uint8Array;
33
+ encodeBatchTransportJson(valuesJson: string): Uint8Array;
34
+ encodePatch(value: RecurramValue): Uint8Array;
35
+ encodePatchTransportJson(valueJson: string): Uint8Array;
36
+ encodeMicroBatch(values: RecurramValue[]): Uint8Array;
37
+ encodeMicroBatchTransportJson(valuesJson: string): Uint8Array;
38
+ encodeDirect(value: RecurramValue): Uint8Array;
39
+ encodeBatchDirect(values: RecurramValue[]): Uint8Array;
40
+ encodePatchDirect(value: RecurramValue): Uint8Array;
41
+ encodeMicroBatchDirect(values: RecurramValue[]): Uint8Array;
42
+ encodeCompact(value: RecurramValue): Uint8Array;
43
+ encodeCompactJson(json: string): Uint8Array;
44
+ encodeBatchCompact(values: RecurramValue[]): Uint8Array;
45
+ encodeBatchCompactJson(json: string): Uint8Array;
46
+ encodePatchCompact(value: RecurramValue): Uint8Array;
47
+ encodePatchCompactJson(json: string): Uint8Array;
48
+ encodeMicroBatchCompact(values: RecurramValue[]): Uint8Array;
49
+ encodeMicroBatchCompactJson(json: string): Uint8Array;
50
+ reset(): void;
51
+ }
package/dist/index.js ADDED
@@ -0,0 +1,152 @@
1
+ import { initBackend, requireBackend } from "./backend.js";
2
+ import { deserializeCompact, deserializeValue, fromTransportValue, serializeCompact, serializeCompactBatch, serializeSchema, serializeSessionOptions, serializeValue, serializeValues, toTransportValue, toTransportValues, } from "./transport.js";
3
+ export async function init(options = {}) {
4
+ return initBackend(options);
5
+ }
6
+ // ── Transport JSON helpers (pre-serialized JSON string) ─────────────────────
7
+ export function toTransportJson(value) {
8
+ return serializeValue(value);
9
+ }
10
+ export function fromTransportJson(valueJson) {
11
+ return deserializeValue(valueJson);
12
+ }
13
+ export function toTransportJsonBatch(values) {
14
+ return serializeValues(values);
15
+ }
16
+ // ── JSON-string based raw API ───────────────────────────────────────────────
17
+ export function encodeTransportJson(valueJson) {
18
+ return requireBackend().encodeTransportJson(valueJson);
19
+ }
20
+ export function decodeToTransportJson(bytes) {
21
+ return requireBackend().decodeToTransportJson(bytes);
22
+ }
23
+ export function encodeBatchTransportJson(valuesJson) {
24
+ return requireBackend().encodeBatchTransportJson(valuesJson);
25
+ }
26
+ // ── High-level API (RecurramValue → compact JSON → encode) ──────────────────────
27
+ // Uses the compact transport format internally for best performance.
28
+ export function encode(value) {
29
+ return requireBackend().encodeCompactJson(serializeCompact(value));
30
+ }
31
+ export function decode(bytes) {
32
+ return deserializeCompact(requireBackend().decodeToCompactJson(bytes));
33
+ }
34
+ export function encodeWithSchema(schema, value) {
35
+ return requireBackend().encodeWithSchemaTransportJson(serializeSchema(schema), serializeValue(value));
36
+ }
37
+ export function encodeBatch(values) {
38
+ return requireBackend().encodeBatchCompactJson(serializeCompactBatch(values));
39
+ }
40
+ // ── Direct API (bypasses JSON.stringify, passes JS object to Rust serde) ────
41
+ export function encodeDirect(value) {
42
+ return requireBackend().encodeDirect(toTransportValue(value));
43
+ }
44
+ export function decodeDirect(bytes) {
45
+ const transport = requireBackend().decodeDirect(bytes);
46
+ return fromTransportValue(transport);
47
+ }
48
+ export function encodeBatchDirect(values) {
49
+ return requireBackend().encodeBatchDirect(toTransportValues(values));
50
+ }
51
+ // ── Compact JSON API (smaller transport format, ~50% less JSON) ─────────────
52
+ export function toCompactJson(value) {
53
+ return serializeCompact(value);
54
+ }
55
+ export function toCompactJsonBatch(values) {
56
+ return serializeCompactBatch(values);
57
+ }
58
+ export function encodeCompactJson(json) {
59
+ return requireBackend().encodeCompactJson(json);
60
+ }
61
+ export function decodeToCompactJson(bytes) {
62
+ return requireBackend().decodeToCompactJson(bytes);
63
+ }
64
+ export function encodeBatchCompactJson(json) {
65
+ return requireBackend().encodeBatchCompactJson(json);
66
+ }
67
+ export function encodeCompact(value) {
68
+ return requireBackend().encodeCompactJson(serializeCompact(value));
69
+ }
70
+ export function encodeBatchCompact(values) {
71
+ return requireBackend().encodeBatchCompactJson(serializeCompactBatch(values));
72
+ }
73
+ // ── Session encoder ─────────────────────────────────────────────────────────
74
+ export function createSessionEncoder(options = {}) {
75
+ const raw = requireBackend().createSessionEncoder(serializeSessionOptions(options));
76
+ return new SessionEncoder(raw);
77
+ }
78
+ export class SessionEncoder {
79
+ #inner;
80
+ constructor(inner) {
81
+ this.#inner = inner;
82
+ }
83
+ // High-level (RecurramValue → compact JSON string → Rust)
84
+ encode(value) {
85
+ return this.#inner.encodeCompactJson(serializeCompact(value));
86
+ }
87
+ encodeTransportJson(valueJson) {
88
+ return this.#inner.encodeTransportJson(valueJson);
89
+ }
90
+ encodeWithSchema(schema, value) {
91
+ return this.#inner.encodeWithSchemaTransportJson(serializeSchema(schema), serializeValue(value));
92
+ }
93
+ encodeBatch(values) {
94
+ return this.#inner.encodeBatchCompactJson(serializeCompactBatch(values));
95
+ }
96
+ encodeBatchTransportJson(valuesJson) {
97
+ return this.#inner.encodeBatchTransportJson(valuesJson);
98
+ }
99
+ encodePatch(value) {
100
+ return this.#inner.encodePatchCompactJson(serializeCompact(value));
101
+ }
102
+ encodePatchTransportJson(valueJson) {
103
+ return this.#inner.encodePatchTransportJson(valueJson);
104
+ }
105
+ encodeMicroBatch(values) {
106
+ return this.#inner.encodeMicroBatchCompactJson(serializeCompactBatch(values));
107
+ }
108
+ encodeMicroBatchTransportJson(valuesJson) {
109
+ return this.#inner.encodeMicroBatchTransportJson(valuesJson);
110
+ }
111
+ // Direct (RecurramValue → TransportValue object → Rust serde, no JSON string)
112
+ encodeDirect(value) {
113
+ return this.#inner.encodeDirect(toTransportValue(value));
114
+ }
115
+ encodeBatchDirect(values) {
116
+ return this.#inner.encodeBatchDirect(toTransportValues(values));
117
+ }
118
+ encodePatchDirect(value) {
119
+ return this.#inner.encodePatchDirect(toTransportValue(value));
120
+ }
121
+ encodeMicroBatchDirect(values) {
122
+ return this.#inner.encodeMicroBatchDirect(toTransportValues(values));
123
+ }
124
+ // Compact JSON (RecurramValue → compact JSON string → Rust)
125
+ encodeCompact(value) {
126
+ return this.#inner.encodeCompactJson(serializeCompact(value));
127
+ }
128
+ encodeCompactJson(json) {
129
+ return this.#inner.encodeCompactJson(json);
130
+ }
131
+ encodeBatchCompact(values) {
132
+ return this.#inner.encodeBatchCompactJson(serializeCompactBatch(values));
133
+ }
134
+ encodeBatchCompactJson(json) {
135
+ return this.#inner.encodeBatchCompactJson(json);
136
+ }
137
+ encodePatchCompact(value) {
138
+ return this.#inner.encodePatchCompactJson(serializeCompact(value));
139
+ }
140
+ encodePatchCompactJson(json) {
141
+ return this.#inner.encodePatchCompactJson(json);
142
+ }
143
+ encodeMicroBatchCompact(values) {
144
+ return this.#inner.encodeMicroBatchCompactJson(serializeCompactBatch(values));
145
+ }
146
+ encodeMicroBatchCompactJson(json) {
147
+ return this.#inner.encodeMicroBatchCompactJson(json);
148
+ }
149
+ reset() {
150
+ this.#inner.reset();
151
+ }
152
+ }
@@ -0,0 +1,2 @@
1
+ import type { RuntimeBackend } from "./types.js";
2
+ export declare function loadNodeBackend(): RuntimeBackend;
@@ -0,0 +1,45 @@
1
+ import { createRequire } from "node:module";
2
+ import { fileURLToPath } from "node:url";
3
+ export function loadNodeBackend() {
4
+ const require = createRequire(import.meta.url);
5
+ const modulePath = fileURLToPath(new URL("../../native/recurram_napi.node", import.meta.url));
6
+ const native = require(modulePath);
7
+ return {
8
+ kind: "napi",
9
+ encodeTransportJson: (valueJson) => asUint8Array(native.encodeTransportJson(valueJson)),
10
+ decodeToTransportJson: (bytes) => native.decodeToTransportJson(bytes),
11
+ decodeToCompactJson: (bytes) => native.decodeToCompactJson(bytes),
12
+ encodeWithSchemaTransportJson: (schemaJson, valueJson) => asUint8Array(native.encodeWithSchemaTransportJson(schemaJson, valueJson)),
13
+ encodeBatchTransportJson: (valuesJson) => asUint8Array(native.encodeBatchTransportJson(valuesJson)),
14
+ encodeDirect: (value) => asUint8Array(native.encodeDirect(value)),
15
+ decodeDirect: (bytes) => native.decodeDirect(bytes),
16
+ encodeBatchDirect: (values) => asUint8Array(native.encodeBatchDirect(values)),
17
+ encodeCompactJson: (json) => asUint8Array(native.encodeCompactJson(json)),
18
+ encodeBatchCompactJson: (json) => asUint8Array(native.encodeBatchCompactJson(json)),
19
+ createSessionEncoder: (optionsJson) => {
20
+ const inner = native.createSessionEncoder(optionsJson);
21
+ return wrapSessionEncoder(inner);
22
+ },
23
+ };
24
+ }
25
+ function wrapSessionEncoder(inner) {
26
+ return {
27
+ encodeTransportJson: (valueJson) => asUint8Array(inner.encodeTransportJson(valueJson)),
28
+ encodeWithSchemaTransportJson: (schemaJson, valueJson) => asUint8Array(inner.encodeWithSchemaTransportJson(schemaJson, valueJson)),
29
+ encodeBatchTransportJson: (valuesJson) => asUint8Array(inner.encodeBatchTransportJson(valuesJson)),
30
+ encodePatchTransportJson: (valueJson) => asUint8Array(inner.encodePatchTransportJson(valueJson)),
31
+ encodeMicroBatchTransportJson: (valuesJson) => asUint8Array(inner.encodeMicroBatchTransportJson(valuesJson)),
32
+ encodeDirect: (value) => asUint8Array(inner.encodeDirect(value)),
33
+ encodeBatchDirect: (values) => asUint8Array(inner.encodeBatchDirect(values)),
34
+ encodePatchDirect: (value) => asUint8Array(inner.encodePatchDirect(value)),
35
+ encodeMicroBatchDirect: (values) => asUint8Array(inner.encodeMicroBatchDirect(values)),
36
+ encodeCompactJson: (json) => asUint8Array(inner.encodeCompactJson(json)),
37
+ encodeBatchCompactJson: (json) => asUint8Array(inner.encodeBatchCompactJson(json)),
38
+ encodePatchCompactJson: (json) => asUint8Array(inner.encodePatchCompactJson(json)),
39
+ encodeMicroBatchCompactJson: (json) => asUint8Array(inner.encodeMicroBatchCompactJson(json)),
40
+ reset: () => inner.reset(),
41
+ };
42
+ }
43
+ function asUint8Array(value) {
44
+ return value;
45
+ }