@muxion/cabi-generate-cli-node 0.0.0-stage → 0.2.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.
- package/README.md +79 -2
- package/dist/bridges.d.ts +5 -0
- package/dist/bridges.d.ts.map +1 -0
- package/dist/bridges.js +331 -0
- package/dist/bridges.js.map +1 -0
- package/dist/calls.d.ts +4 -0
- package/dist/calls.d.ts.map +1 -0
- package/dist/calls.js +131 -0
- package/dist/calls.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +35 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/names.d.ts +5 -0
- package/dist/names.d.ts.map +1 -0
- package/dist/names.js +56 -0
- package/dist/names.js.map +1 -0
- package/dist/native.d.ts +8 -0
- package/dist/native.d.ts.map +1 -0
- package/dist/native.js +390 -0
- package/dist/native.js.map +1 -0
- package/dist/schema.d.ts +71 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +512 -0
- package/dist/schema.js.map +1 -0
- package/dist/typescript.d.ts +3 -0
- package/dist/typescript.d.ts.map +1 -0
- package/dist/typescript.js +138 -0
- package/dist/typescript.js.map +1 -0
- package/package.json +49 -4
- package/schema/cabi-v2.schema.json +313 -0
package/README.md
CHANGED
|
@@ -1,3 +1,80 @@
|
|
|
1
|
-
#
|
|
1
|
+
# cabi-generate-cli-node
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Compile a version-2 YAML ABI document to JavaScript views and calls, Rust arena
|
|
4
|
+
types and an operation interface, and a C11 header.
|
|
5
|
+
|
|
6
|
+
```sh
|
|
7
|
+
npm run generate --workspace=@muxion/cabi-generate-cli-node -- schema.yaml output-directory
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
The source has `version: 2`, an underscore `namespace`, a positive `abiVersion`,
|
|
11
|
+
named `types`, and named `functions`. See
|
|
12
|
+
[`cabi-v2.schema.json`](schema/cabi-v2.schema.json) for the formal JSON Schema.
|
|
13
|
+
JSON Schema checks document shape. The compiler also checks references, integer
|
|
14
|
+
ranges, layouts, parameter access, return types and handle lifecycle
|
|
15
|
+
declarations. It accepts YAML and JSON syntax. Duplicate keys, aliases, unknown YAML tags,
|
|
16
|
+
and integers outside the safe integer range are rejected. Version 1 is rejected.
|
|
17
|
+
|
|
18
|
+
All storage is little endian. Scalar widths and alignment are fixed. Struct
|
|
19
|
+
fields, function parameters, and union variants use ordered arrays.
|
|
20
|
+
Struct and union padding is explicit in generated C and Rust types. Arrays have
|
|
21
|
+
fixed positive lengths. Slices store a `u32` arena offset and element count.
|
|
22
|
+
`offset_pointer` stores a `u32` arena offset. Zero denotes an absent offset;
|
|
23
|
+
nonempty slices cannot use zero. `unit` is only an empty union variant.
|
|
24
|
+
|
|
25
|
+
Enums have an explicit integer representation and integer values. Union tags are
|
|
26
|
+
unsigned integers. JSON tag values must be exact safe integers. Binary `u64` and
|
|
27
|
+
`i64` storage can contain all 64 bits. JavaScript binary accessors use branded
|
|
28
|
+
`bigint`; boundary `u64` and `i64` values use `bigint`.
|
|
29
|
+
|
|
30
|
+
`native_pointer` defines a named runtime handle with a target and release method.
|
|
31
|
+
It is stored as `u64`, but it is not a memory address. Its creation method must
|
|
32
|
+
accept one `arena_bytes` parameter and declare the handle as their return type. The
|
|
33
|
+
release method takes that handle and returns JSON `null`. The runtime must
|
|
34
|
+
reject zero and stale handles.
|
|
35
|
+
|
|
36
|
+
Arena lifetime is an API rule, with no `retain` property in the schema. The
|
|
37
|
+
application must keep the arena valid until the engine is closed. Do not free,
|
|
38
|
+
detach, resize, or replace it while the engine is open. The Node bridge keeps
|
|
39
|
+
a strong reference to the buffer until engine close.
|
|
40
|
+
|
|
41
|
+
Methods take scalars and handles directly. Composite input parameters use
|
|
42
|
+
`offset_pointer` with `access: read`, `write`, or `read_write`. Every method has one declared return type, or JSON `null` for no value.
|
|
43
|
+
The runtime adds an `i32` status return and a final result pointer; these are
|
|
44
|
+
not schema parameters or return types. C exports take a final `uint8_t *result`.
|
|
45
|
+
Raw `CabiNative` JavaScript calls take a final `Uint8Array` and return the status as a number,
|
|
46
|
+
including methods with no value. On success, the declared value is written in
|
|
47
|
+
little-endian form into the result buffer. Void methods accept an empty buffer.
|
|
48
|
+
Failed operations do not publish a return value. C callers must provide enough
|
|
49
|
+
storage; Node and WASM validate the result buffer length.
|
|
50
|
+
|
|
51
|
+
Generated `CabiCalls` owns its result buffer. Its methods take only the declared
|
|
52
|
+
parameters and return decoded schema values. A nonzero status throws `CabiError`
|
|
53
|
+
with `code` equal to that status. Void methods return `undefined` after success.
|
|
54
|
+
Decoded byte slices and composite values are copied before the result buffer or
|
|
55
|
+
arena can be reused. Boundary 64-bit values use `bigint`; binary views
|
|
56
|
+
keep their tagged `bigint` accessors.
|
|
57
|
+
|
|
58
|
+
Generated value types, C structs, and Rust structs keep schema names. JavaScript
|
|
59
|
+
binary view classes add the `View` suffix. Inline layouts use names from their
|
|
60
|
+
schema path. Binary views validate bounds, alignment, and overflow. The native
|
|
61
|
+
runtime also validates live allocation ranges. C symbols use the namespace
|
|
62
|
+
prefix. Rust and JavaScript method names match source keys.
|
|
63
|
+
|
|
64
|
+
The CLI writes `schema.ts`, `schema.rs`, `schema.h`, and `layout.json`. Rust types
|
|
65
|
+
use byte arrays, explicit padding, and little-endian accessors. C uses C11
|
|
66
|
+
alignment and byte accessors. Both targets assert sizes, alignment, and field
|
|
67
|
+
offsets at compile time. Optional Rust derives support `bytemuck` and `zerocopy`.
|
|
68
|
+
|
|
69
|
+
Tests compile and run JavaScript, C, and Rust output, compare bytes, and compile
|
|
70
|
+
Rust output for wasm32. They require `clang`, `rustc`, and the
|
|
71
|
+
`wasm32-unknown-unknown` Rust target.
|
|
72
|
+
|
|
73
|
+
The library also exports `generateNode`, `generateWasm`, and
|
|
74
|
+
`generateWasmRuntime` for engine bridges. `generateRust` accepts
|
|
75
|
+
`operationsModule` to emit C exports that forward to handwritten Rust functions.
|
|
76
|
+
Protocol repositories use these generators to update their runtime packages.
|
|
77
|
+
|
|
78
|
+
Generated TypeScript puts all imports at the top and includes ESLint, Oxlint,
|
|
79
|
+
and Prettier ignore comments. Exclude generated files in `.prettierignore` to
|
|
80
|
+
skip formatting the full file; `prettier-ignore` skips only the next node.
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type CompiledSchema } from './schema.js';
|
|
2
|
+
export declare const generateNode: (schema: CompiledSchema) => string;
|
|
3
|
+
export declare const generateWasm: (schema: CompiledSchema) => string;
|
|
4
|
+
export declare const generateWasmRuntime: (schema: CompiledSchema) => string;
|
|
5
|
+
//# sourceMappingURL=bridges.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bridges.d.ts","sourceRoot":"","sources":["../src/bridges.ts"],"names":[],"mappings":"AACA,OAAO,EAA8C,KAAK,cAAc,EAAE,MAAM,aAAa,CAAA;AAyB7F,eAAO,MAAM,YAAY,WAAY,cAAc,KAAG,MAqGrD,CAAA;AAED,eAAO,MAAM,YAAY,WAAY,cAAc,KAAG,MA4BrD,CAAA;AAED,eAAO,MAAM,mBAAmB,WAAY,cAAc,KAAG,MA8L5D,CAAA"}
|
package/dist/bridges.js
ADDED
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
/* oxlint-disable no-ternary -- Expressions select generated target types and output contracts. */
|
|
2
|
+
import { isPrimitive, resolveNode, variantIdLiteral } from './schema.js';
|
|
3
|
+
const scalar = (schema, index) => {
|
|
4
|
+
const node = schema.nodes[resolveNode(schema, index)];
|
|
5
|
+
if (node.kind === 'native_pointer') {
|
|
6
|
+
return 'u64';
|
|
7
|
+
}
|
|
8
|
+
if (node.kind === 'enum') {
|
|
9
|
+
return node.tag;
|
|
10
|
+
}
|
|
11
|
+
if (isPrimitive(node.kind)) {
|
|
12
|
+
return node.kind;
|
|
13
|
+
}
|
|
14
|
+
return undefined;
|
|
15
|
+
};
|
|
16
|
+
const cType = (kind) => {
|
|
17
|
+
if (kind === 'f32') {
|
|
18
|
+
return 'float';
|
|
19
|
+
}
|
|
20
|
+
if (kind === 'f64') {
|
|
21
|
+
return 'double';
|
|
22
|
+
}
|
|
23
|
+
return `${kind.startsWith('u') ? 'uint' : 'int'}${kind.slice(1)}_t`;
|
|
24
|
+
};
|
|
25
|
+
export const generateNode = (schema) => {
|
|
26
|
+
const output = [
|
|
27
|
+
`/* Generated N-API bridge. Do not edit. */
|
|
28
|
+
#include <node_api.h>
|
|
29
|
+
#include <math.h>
|
|
30
|
+
#include <stdlib.h>
|
|
31
|
+
#include "${schema.namespace}.h"
|
|
32
|
+
typedef struct engine_record { uint64_t handle; napi_ref arena; struct engine_record *next; } engine_record;
|
|
33
|
+
typedef struct { engine_record *engines; } bridge_state;
|
|
34
|
+
static napi_value number(napi_env env, int32_t value) { napi_value result; return napi_create_int32(env, value, &result) == napi_ok ? result : NULL; }
|
|
35
|
+
static bridge_state *state(napi_env env) { void *value = NULL; return napi_get_instance_data(env, &value) == napi_ok ? value : NULL; }
|
|
36
|
+
static engine_record *find(bridge_state *value, uint64_t handle) { for (engine_record *record = value->engines; record; record = record->next) if (record->handle == handle) return record; return NULL; }
|
|
37
|
+
static int32_t close_engine(napi_env env, bridge_state *value, uint64_t handle, uint8_t *result) {
|
|
38
|
+
engine_record **link = &value->engines;
|
|
39
|
+
while (*link && (*link)->handle != handle) link = &(*link)->next;
|
|
40
|
+
if (!*link) return 4;
|
|
41
|
+
engine_record *record = *link; *link = record->next;
|
|
42
|
+
int32_t status = ${schema.namespace}_engine_close(handle, result);
|
|
43
|
+
napi_delete_reference(env, record->arena); free(record); return status;
|
|
44
|
+
}
|
|
45
|
+
static void finalize(napi_env env, void *data, void *hint) { (void)hint; bridge_state *value = data; uint8_t result = 0; while (value->engines) close_engine(env, value, value->engines->handle, &result); free(value); }
|
|
46
|
+
static bool numeric(napi_env env, napi_value value, double min, double max, bool integer, double *out) { return napi_get_value_double(env, value, out) == napi_ok && isfinite(*out) && *out >= min && *out <= max && (!integer || trunc(*out) == *out); }
|
|
47
|
+
static bool unsigned64(napi_env env, napi_value value, uint64_t *out) { bool lossless; return napi_get_value_bigint_uint64(env, value, out, &lossless) == napi_ok && lossless; }
|
|
48
|
+
${Object.values(schema.functions).some((method) => method.params.some((param) => param.node !== -1 && scalar(schema, param.node) === 'i64')) ? 'static bool signed64(napi_env env, napi_value value, int64_t *out) { bool lossless; return napi_get_value_bigint_int64(env, value, out, &lossless) == napi_ok && lossless; }' : ''}
|
|
49
|
+
static bool bytes(napi_env env, napi_value value, void **data, size_t *len) { napi_typedarray_type type; napi_value buffer; size_t offset; return napi_get_typedarray_info(env, value, &type, len, data, &buffer, &offset) == napi_ok && type == napi_uint8_array; }
|
|
50
|
+
`,
|
|
51
|
+
];
|
|
52
|
+
for (const [name, method] of Object.entries(schema.functions)) {
|
|
53
|
+
const count = method.params.length + 1;
|
|
54
|
+
const size = method.returns === null ? 0 : schema.nodes[method.returns].size;
|
|
55
|
+
output.push(`static napi_value call_${name}(napi_env env, napi_callback_info info) {
|
|
56
|
+
napi_value args[${count}]; size_t count = ${count};
|
|
57
|
+
if (napi_get_cb_info(env, info, &count, args, NULL, NULL) != napi_ok || count != ${count}) return number(env, 4);
|
|
58
|
+
bridge_state *bridge = state(env); if (!bridge) return NULL;
|
|
59
|
+
void *result_data; size_t result_len; if (!bytes(env, args[${count - 1}], &result_data, &result_len) ${size > 0 ? `|| result_len < ${size}` : ''}) return number(env, 4);`);
|
|
60
|
+
const forwarded = [];
|
|
61
|
+
method.params.forEach((param, index) => {
|
|
62
|
+
if (param.node === -1) {
|
|
63
|
+
output.push(` void *arena_data; size_t arena_len; if (!bytes(env, args[${index}], &arena_data, &arena_len) || arena_len > UINT32_MAX) return number(env, 4);`);
|
|
64
|
+
forwarded.push('arena_data', '(uint32_t)arena_len');
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
const kind = scalar(schema, param.node) ?? 'u32';
|
|
68
|
+
const floating = kind.startsWith('f');
|
|
69
|
+
const bits = Number(kind.slice(1));
|
|
70
|
+
let max = Math.min(2 ** (bits - 1) - 1, Number.MAX_SAFE_INTEGER);
|
|
71
|
+
let min = Math.max(-(2 ** (bits - 1)), Number.MIN_SAFE_INTEGER);
|
|
72
|
+
if (kind.startsWith('u')) {
|
|
73
|
+
max = Math.min(2 ** bits - 1, Number.MAX_SAFE_INTEGER);
|
|
74
|
+
min = 0;
|
|
75
|
+
}
|
|
76
|
+
if (floating) {
|
|
77
|
+
max = Number.MAX_VALUE;
|
|
78
|
+
if (kind === 'f32') {
|
|
79
|
+
max = 3.4028234663852886e38;
|
|
80
|
+
}
|
|
81
|
+
min = -max;
|
|
82
|
+
}
|
|
83
|
+
if (kind === 'u64' || kind === 'i64') {
|
|
84
|
+
output.push(` ${cType(kind)} arg_${param.name}; if (!${kind === 'u64' ? 'unsigned64' : 'signed64'}(env, args[${index}], &arg_${param.name})) return number(env, 4);`);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
output.push(` double arg_${param.name}; if (!numeric(env, args[${index}], ${min}, ${max}, ${!floating}, &arg_${param.name})) return number(env, 4);`);
|
|
88
|
+
}
|
|
89
|
+
if (schema.nodes[resolveNode(schema, param.node)].kind === 'native_pointer' &&
|
|
90
|
+
name !== 'engine_close') {
|
|
91
|
+
output.push(` if (!find(bridge, (uint64_t)arg_${param.name})) return number(env, 4);`);
|
|
92
|
+
}
|
|
93
|
+
forwarded.push(`(${cType(kind)})arg_${param.name}`);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
forwarded.push('result_data');
|
|
97
|
+
if (name === 'engine_close') {
|
|
98
|
+
output.push(' return number(env, close_engine(env, bridge, (uint64_t)arg_engine, result_data));\n}');
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
output.push(` int32_t status = ${schema.namespace}_${name}(${forwarded.join(', ')});`);
|
|
102
|
+
if (name === 'engine_new') {
|
|
103
|
+
output.push(` if (status == 0) { uint64_t handle = 0; for (size_t index = 0; index < 8; index++) handle |= (uint64_t)((uint8_t *)result_data)[index] << (8 * index);
|
|
104
|
+
engine_record *record = malloc(sizeof(*record)); if (!record) { ${schema.namespace}_engine_close(handle, result_data); return number(env, 17); }
|
|
105
|
+
if (napi_create_reference(env, args[0], 1, &record->arena) != napi_ok) { free(record); ${schema.namespace}_engine_close(handle, result_data); return NULL; }
|
|
106
|
+
record->handle = handle; record->next = bridge->engines; bridge->engines = record; }`);
|
|
107
|
+
}
|
|
108
|
+
output.push(' return number(env, status);\n}');
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
output.push(`NAPI_MODULE_INIT() { bridge_state *bridge = calloc(1, sizeof(*bridge)); if (!bridge || napi_set_instance_data(env, bridge, finalize, NULL) != napi_ok) { free(bridge); return NULL; }
|
|
112
|
+
napi_property_descriptor methods[] = {
|
|
113
|
+
${Object.keys(schema.functions)
|
|
114
|
+
.map((name) => ` {"${name}", NULL, call_${name}, NULL, NULL, NULL, napi_default, NULL},`)
|
|
115
|
+
.join('\n')}
|
|
116
|
+
};
|
|
117
|
+
return napi_define_properties(env, exports, sizeof(methods) / sizeof(methods[0]), methods) == napi_ok ? exports : NULL; }`);
|
|
118
|
+
return output.join('\n').replaceAll(/[\t ]+$/gmu, '');
|
|
119
|
+
};
|
|
120
|
+
export const generateWasm = (schema) => {
|
|
121
|
+
const output = [
|
|
122
|
+
'// Generated WASM calls. Do not edit.',
|
|
123
|
+
'use wasm_bindgen::prelude::*;',
|
|
124
|
+
'use crate::NativeEngine;',
|
|
125
|
+
'#[wasm_bindgen]',
|
|
126
|
+
'impl NativeEngine {',
|
|
127
|
+
];
|
|
128
|
+
for (const [name, method] of Object.entries(schema.functions).filter(([key]) => key !== 'engine_new' && key !== 'engine_close')) {
|
|
129
|
+
const params = method.params
|
|
130
|
+
.slice(1)
|
|
131
|
+
.map((param) => `${param.name}: ${scalar(schema, param.node) ?? 'u32'}`);
|
|
132
|
+
params.push('result: &mut [u8]');
|
|
133
|
+
const size = method.returns === null ? 0 : schema.nodes[method.returns].size;
|
|
134
|
+
output.push(` pub fn ${name}(&mut self, ${params.join(', ')}) -> i32 {
|
|
135
|
+
${size > 0 ? `if result.len() < ${size} { return 4; }` : ''}`);
|
|
136
|
+
const args = ['self.handle'];
|
|
137
|
+
for (const param of method.params.slice(1)) {
|
|
138
|
+
args.push(param.name);
|
|
139
|
+
}
|
|
140
|
+
args.push('result.as_mut_ptr()');
|
|
141
|
+
output.push(` unsafe { fluxmux_core::boundary::${schema.namespace}_${name}(${args.join(', ')}) }
|
|
142
|
+
}`);
|
|
143
|
+
}
|
|
144
|
+
output.push('}');
|
|
145
|
+
return output.join('\n').replaceAll(/[\t ]+$/gmu, '');
|
|
146
|
+
};
|
|
147
|
+
export const generateWasmRuntime = (schema) => {
|
|
148
|
+
const flat = new Map();
|
|
149
|
+
const isFlat = (index, visiting = new Set()) => {
|
|
150
|
+
const known = flat.get(index);
|
|
151
|
+
if (known !== undefined) {
|
|
152
|
+
return known;
|
|
153
|
+
}
|
|
154
|
+
if (visiting.has(index)) {
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
visiting.add(index);
|
|
158
|
+
const node = schema.nodes[index];
|
|
159
|
+
let value = true;
|
|
160
|
+
if (node.kind === 'ref') {
|
|
161
|
+
value = isFlat(node.item, visiting);
|
|
162
|
+
}
|
|
163
|
+
else if (node.kind === 'struct') {
|
|
164
|
+
value = node.fields.every((field) => isFlat(field.node, visiting));
|
|
165
|
+
}
|
|
166
|
+
else if (node.kind === 'array') {
|
|
167
|
+
value = isFlat(node.item, visiting);
|
|
168
|
+
}
|
|
169
|
+
else if (node.kind === 'union' || node.kind === 'slice' || node.kind === 'offset_pointer') {
|
|
170
|
+
value = false;
|
|
171
|
+
}
|
|
172
|
+
visiting.delete(index);
|
|
173
|
+
flat.set(index, value);
|
|
174
|
+
return value;
|
|
175
|
+
};
|
|
176
|
+
const metadata = schema.nodes.map((node, index) => ({
|
|
177
|
+
...node,
|
|
178
|
+
flat: isFlat(index),
|
|
179
|
+
variants: node.variants.map((variant) => ({ ...variant, id: variantIdLiteral(variant.id) })),
|
|
180
|
+
}));
|
|
181
|
+
const output = [
|
|
182
|
+
`/* eslint-disable */
|
|
183
|
+
/* oxlint-disable */
|
|
184
|
+
// prettier-ignore
|
|
185
|
+
// Generated WASM arena bridge. Do not edit.
|
|
186
|
+
import type { NativeRuntime } from '@muxion/core-js'
|
|
187
|
+
import type { NativeEngine } from '../../generated/fluxmux_core_wasm.js'
|
|
188
|
+
interface State { arena: Uint8Array; native: NativeEngine }
|
|
189
|
+
interface ArenaContext { source: Uint8Array; target: Uint8Array; data: DataView; visited: Array<Set<number> | undefined>; ranges: Array<[number, number]> }
|
|
190
|
+
export interface WasmExports { readonly memory: WebAssembly.Memory; readonly NativeEngine: typeof NativeEngine }
|
|
191
|
+
const layouts = ${JSON.stringify(metadata)}
|
|
192
|
+
export const createWasmRuntime = (load: () => WasmExports): NativeRuntime => {
|
|
193
|
+
const engines = new Map<bigint, State>()
|
|
194
|
+
const nativeBytes = (state: State): Uint8Array => new Uint8Array(load().memory.buffer, state.native.arena_address(), state.arena.byteLength)
|
|
195
|
+
const rangeEnd = (start: number, count: number, size: number, limit: number): number => {
|
|
196
|
+
const length = count * size
|
|
197
|
+
const end = start + length
|
|
198
|
+
if (!Number.isSafeInteger(start) || start < 0 || !Number.isSafeInteger(count) || count < 0 || !Number.isSafeInteger(length) || !Number.isSafeInteger(end) || end > limit) throw new RangeError('invalid arena range')
|
|
199
|
+
return end
|
|
200
|
+
}
|
|
201
|
+
const copyRanges = (context: ArenaContext): void => {
|
|
202
|
+
context.ranges.sort((left, right) => left[0] - right[0])
|
|
203
|
+
let start = -1
|
|
204
|
+
let end = -1
|
|
205
|
+
for (const range of context.ranges) {
|
|
206
|
+
if (range[0] <= end) { end = Math.max(end, range[1]); continue }
|
|
207
|
+
if (start >= 0) context.target.set(context.source.subarray(start, end), start)
|
|
208
|
+
;[start, end] = range
|
|
209
|
+
}
|
|
210
|
+
if (start >= 0) context.target.set(context.source.subarray(start, end), start)
|
|
211
|
+
}
|
|
212
|
+
const collectArenaRanges = (context: ArenaContext, offset: number, nodeIndex: number): void => {
|
|
213
|
+
const node = layouts[nodeIndex]
|
|
214
|
+
if (!node) throw new RangeError('unknown arena layout')
|
|
215
|
+
if (node.kind === 'ref') { collectArenaRanges(context, offset, node.item); return }
|
|
216
|
+
const end = rangeEnd(offset, 1, node.size, context.source.byteLength)
|
|
217
|
+
if (offset === 0 || offset % node.align !== 0) throw new RangeError('invalid arena reference')
|
|
218
|
+
const seen = context.visited[nodeIndex] ?? new Set<number>()
|
|
219
|
+
context.visited[nodeIndex] = seen
|
|
220
|
+
if (seen.has(offset)) return
|
|
221
|
+
seen.add(offset)
|
|
222
|
+
context.ranges.push([offset, end])
|
|
223
|
+
if (node.flat) return
|
|
224
|
+
if (node.kind === 'struct') {
|
|
225
|
+
for (const field of node.fields) if (!layouts[field.node]?.flat) collectArenaRanges(context, offset + field.offset, field.node)
|
|
226
|
+
} else if (node.kind === 'slice' || node.kind === 'offset_pointer') {
|
|
227
|
+
const start = context.data.getUint32(offset, true)
|
|
228
|
+
const count = node.kind === 'slice' ? context.data.getUint32(offset + 4, true) : start === 0 ? 0 : 1
|
|
229
|
+
const item = layouts[node.item]
|
|
230
|
+
if (!item) throw new RangeError('unknown arena element')
|
|
231
|
+
const itemsEnd = rangeEnd(start, count, item.size, context.source.byteLength)
|
|
232
|
+
if ((start === 0 && count !== 0) || start % item.align !== 0) throw new RangeError('invalid arena slice')
|
|
233
|
+
if (count === 0) return
|
|
234
|
+
if (item.flat) context.ranges.push([start, itemsEnd])
|
|
235
|
+
else for (let index = 0; index < count; index++) collectArenaRanges(context, start + index * item.size, node.item)
|
|
236
|
+
} else if (node.kind === 'array') {
|
|
237
|
+
const item = layouts[node.item]
|
|
238
|
+
if (!item) throw new RangeError('unknown array element')
|
|
239
|
+
for (let index = 0; index < node.length; index++) collectArenaRanges(context, offset + index * item.size, node.item)
|
|
240
|
+
} else if (node.kind === 'union') {
|
|
241
|
+
const tag = node.tag === 'u8' ? String(context.data.getUint8(offset)) : node.tag === 'u16' ? String(context.data.getUint16(offset, true)) : node.tag === 'u32' ? String(context.data.getUint32(offset, true)) : String(context.data.getBigUint64(offset, true))
|
|
242
|
+
const variant = node.variants.find((variant) => variant.id === tag)
|
|
243
|
+
if (!variant) throw new RangeError('invalid arena union tag')
|
|
244
|
+
if (layouts[variant.node]?.kind !== 'unit' && !layouts[variant.node]?.flat) collectArenaRanges(context, offset + node.payloadOffset, variant.node)
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
const sync = (state: State, offset: number, nodeIndex: number, toNative: boolean): void => {
|
|
248
|
+
const native = nativeBytes(state)
|
|
249
|
+
const source = toNative ? state.arena : native
|
|
250
|
+
const target = toNative ? native : state.arena
|
|
251
|
+
const context: ArenaContext = {source, target, data: new DataView(source.buffer, source.byteOffset, source.byteLength), visited: [], ranges: []}
|
|
252
|
+
collectArenaRanges(context, offset, nodeIndex)
|
|
253
|
+
copyRanges(context)
|
|
254
|
+
}
|
|
255
|
+
const collectReturnRanges = (context: ArenaContext, bytes: Uint8Array, data: DataView, offset: number, nodeIndex: number): void => {
|
|
256
|
+
const node = layouts[nodeIndex]
|
|
257
|
+
if (!node || rangeEnd(offset, 1, node.size, bytes.byteLength) > bytes.byteLength) throw new RangeError('invalid return layout')
|
|
258
|
+
if (node.kind === 'ref') { collectReturnRanges(context, bytes, data, offset, node.item); return }
|
|
259
|
+
if (node.flat) return
|
|
260
|
+
if (node.kind === 'struct') { for (const field of node.fields) if (!layouts[field.node]?.flat) collectReturnRanges(context, bytes, data, offset + field.offset, field.node); return }
|
|
261
|
+
if (node.kind === 'slice' || node.kind === 'offset_pointer') {
|
|
262
|
+
const start = data.getUint32(offset, true)
|
|
263
|
+
const count = node.kind === 'slice' ? data.getUint32(offset + 4, true) : start === 0 ? 0 : 1
|
|
264
|
+
const item = layouts[node.item]
|
|
265
|
+
if (!item || (start === 0 && count !== 0) || start % item.align !== 0) throw new RangeError('invalid returned arena slice')
|
|
266
|
+
rangeEnd(start, count, item.size, context.source.byteLength)
|
|
267
|
+
if (count === 0) return
|
|
268
|
+
if (item.flat) context.ranges.push([start, start + count * item.size])
|
|
269
|
+
else for (let index = 0; index < count; index++) collectArenaRanges(context, start + index * item.size, node.item)
|
|
270
|
+
} else if (node.kind === 'array') {
|
|
271
|
+
const item = layouts[node.item]
|
|
272
|
+
if (!item) throw new RangeError('invalid return array')
|
|
273
|
+
for (let index = 0; index < node.length; index++) collectReturnRanges(context, bytes, data, offset + index * item.size, node.item)
|
|
274
|
+
} else if (node.kind === 'union') {
|
|
275
|
+
const tag = node.tag === 'u8' ? String(data.getUint8(offset)) : node.tag === 'u16' ? String(data.getUint16(offset, true)) : node.tag === 'u32' ? String(data.getUint32(offset, true)) : String(data.getBigUint64(offset, true))
|
|
276
|
+
const variant = node.variants.find((item) => item.id === tag)
|
|
277
|
+
if (!variant) throw new RangeError('invalid return union')
|
|
278
|
+
if (layouts[variant.node]?.kind !== 'unit' && !layouts[variant.node]?.flat) collectReturnRanges(context, bytes, data, offset + node.payloadOffset, variant.node)
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
const syncReturn = (state: State, bytes: Uint8Array, offset: number, nodeIndex: number): void => {
|
|
282
|
+
const source = nativeBytes(state)
|
|
283
|
+
const context: ArenaContext = {source, target: state.arena, data: new DataView(source.buffer, source.byteOffset, source.byteLength), visited: [], ranges: []}
|
|
284
|
+
collectReturnRanges(context, bytes, new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength), offset, nodeIndex)
|
|
285
|
+
copyRanges(context)
|
|
286
|
+
}
|
|
287
|
+
return {
|
|
288
|
+
engine_new: (arena, result) => {
|
|
289
|
+
if (arena.byteLength < 266240 || arena.byteLength > 0xffffffff || result.byteLength < 8) return 4
|
|
290
|
+
const { NativeEngine } = load()
|
|
291
|
+
const native = new NativeEngine(arena.byteLength, result)
|
|
292
|
+
const engine = native.handle()
|
|
293
|
+
engines.set(engine, {arena, native})
|
|
294
|
+
return 0
|
|
295
|
+
},
|
|
296
|
+
engine_close: (engine, result) => {
|
|
297
|
+
const state = engines.get(engine)
|
|
298
|
+
if (!state) return 4
|
|
299
|
+
const status = state.native.dispose(result); state.native.free(); engines.delete(engine)
|
|
300
|
+
return status
|
|
301
|
+
},`,
|
|
302
|
+
];
|
|
303
|
+
for (const [name, method] of Object.entries(schema.functions).filter(([key]) => key !== 'engine_new' && key !== 'engine_close')) {
|
|
304
|
+
const args = method.params.slice(1).map((param) => param.name);
|
|
305
|
+
const size = method.returns === null ? 0 : schema.nodes[method.returns].size;
|
|
306
|
+
output.push(` ${name}: (engine${args.length > 0 ? `, ${args.join(', ')}` : ''}, result) => {
|
|
307
|
+
const state = engines.get(engine)
|
|
308
|
+
if (!state || result.byteLength < ${size}) return 4
|
|
309
|
+
try {`);
|
|
310
|
+
for (const param of method.params.filter((item) => item.access === 'read' || item.access === 'read_write')) {
|
|
311
|
+
output.push(` sync(state, ${param.name}, ${schema.nodes[resolveNode(schema, param.node)].item}, true)`);
|
|
312
|
+
}
|
|
313
|
+
output.push(` const status = state.native.${name}(${[...args, 'result'].join(', ')})
|
|
314
|
+
if (status !== 0) return status`);
|
|
315
|
+
for (const param of method.params.filter((item) => item.access === 'write' || item.access === 'read_write')) {
|
|
316
|
+
output.push(` sync(state, ${param.name}, ${schema.nodes[resolveNode(schema, param.node)].item}, false)`);
|
|
317
|
+
}
|
|
318
|
+
if (method.returns !== null) {
|
|
319
|
+
output.push(` syncReturn(state, result, 0, ${method.returns})`);
|
|
320
|
+
}
|
|
321
|
+
output.push(` return status
|
|
322
|
+
} catch (error) {
|
|
323
|
+
if (error instanceof RangeError) return 4
|
|
324
|
+
throw error
|
|
325
|
+
}
|
|
326
|
+
},`);
|
|
327
|
+
}
|
|
328
|
+
output.push(' }\n}');
|
|
329
|
+
return output.join('\n').replaceAll(/[\t ]+$/gmu, '');
|
|
330
|
+
};
|
|
331
|
+
//# sourceMappingURL=bridges.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bridges.js","sourceRoot":"","sources":["../src/bridges.ts"],"names":[],"mappings":"AAAA,kGAAkG;AAClG,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,gBAAgB,EAAuB,MAAM,aAAa,CAAA;AAE7F,MAAM,MAAM,GAAG,CAAC,MAAsB,EAAE,KAAa,EAAsB,EAAE;IAC3E,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,CAAE,CAAA;IACtD,IAAI,IAAI,CAAC,IAAI,KAAK,gBAAgB,EAAE,CAAC;QACnC,OAAO,KAAK,CAAA;IACd,CAAC;IACD,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;QACzB,OAAO,IAAI,CAAC,GAAG,CAAA;IACjB,CAAC;IACD,IAAI,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QAC3B,OAAO,IAAI,CAAC,IAAI,CAAA;IAClB,CAAC;IACD,OAAO,SAAS,CAAA;AAClB,CAAC,CAAA;AACD,MAAM,KAAK,GAAG,CAAC,IAAY,EAAU,EAAE;IACrC,IAAI,IAAI,KAAK,KAAK,EAAE,CAAC;QACnB,OAAO,OAAO,CAAA;IAChB,CAAC;IACD,IAAI,IAAI,KAAK,KAAK,EAAE,CAAC;QACnB,OAAO,QAAQ,CAAA;IACjB,CAAC;IACD,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAA;AACrE,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,MAAsB,EAAU,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,CAAA"}
|
package/dist/calls.js
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/* oxlint-disable no-ternary -- Expressions select generated ABI types. */
|
|
2
|
+
import { typeNames } from './names.js';
|
|
3
|
+
import { isPrimitive, resolveNode, variantIdLiteral } from './schema.js';
|
|
4
|
+
/** Calls own their result storage and decode values before it can be reused. */
|
|
5
|
+
export const generateCalls = (schema) => {
|
|
6
|
+
const names = typeNames(schema);
|
|
7
|
+
const name = (index) => names.get(resolveNode(schema, index));
|
|
8
|
+
const scalar = (index) => {
|
|
9
|
+
const node = schema.nodes[resolveNode(schema, index)];
|
|
10
|
+
if (node.kind === 'native_pointer' ||
|
|
11
|
+
node.kind === 'u64' ||
|
|
12
|
+
(node.kind === 'enum' && node.tag === 'u64')) {
|
|
13
|
+
return 'bigint';
|
|
14
|
+
}
|
|
15
|
+
if (node.kind === 'i64' || (node.kind === 'enum' && node.tag === 'i64')) {
|
|
16
|
+
return 'bigint';
|
|
17
|
+
}
|
|
18
|
+
if (isPrimitive(node.kind)) {
|
|
19
|
+
return node.kind;
|
|
20
|
+
}
|
|
21
|
+
if (node.kind === 'enum') {
|
|
22
|
+
return node.tag;
|
|
23
|
+
}
|
|
24
|
+
return 'u32';
|
|
25
|
+
};
|
|
26
|
+
const types = [];
|
|
27
|
+
const decoders = [];
|
|
28
|
+
for (const [index, type] of names) {
|
|
29
|
+
const node = schema.nodes[index];
|
|
30
|
+
let valueType = scalar(index);
|
|
31
|
+
if (node.kind === 'struct') {
|
|
32
|
+
valueType = `{ ${node.fields.map((field) => `${field.name}: ${name(field.node)}`).join('; ')} }`;
|
|
33
|
+
}
|
|
34
|
+
if (node.kind === 'array' || node.kind === 'slice') {
|
|
35
|
+
valueType =
|
|
36
|
+
schema.nodes[resolveNode(schema, node.item)].kind === 'u8'
|
|
37
|
+
? 'Uint8Array'
|
|
38
|
+
: `${name(node.item)}[]`;
|
|
39
|
+
}
|
|
40
|
+
if (node.kind === 'offset_pointer') {
|
|
41
|
+
valueType = `${name(node.item)} | null`;
|
|
42
|
+
}
|
|
43
|
+
if (node.kind === 'unit') {
|
|
44
|
+
valueType = 'Record<string, never>';
|
|
45
|
+
}
|
|
46
|
+
if (node.kind === 'union') {
|
|
47
|
+
valueType = node.variants
|
|
48
|
+
.map((variant) => `{ tag: ${variantIdLiteral(variant.id)}${node.tag === 'u64' ? 'n' : ''}; value: ${name(variant.node)} }`)
|
|
49
|
+
.join(' | ');
|
|
50
|
+
}
|
|
51
|
+
types.push(`export type ${type} = ${valueType}`);
|
|
52
|
+
const body = [
|
|
53
|
+
`export const decode${type} = (bytes: Uint8Array, offset: u32, arena: Uint8Array, active = new Set<string>()): ${type} => {`,
|
|
54
|
+
` const key = '${type}:' + offset`,
|
|
55
|
+
` if (active.has(key)) throw new RangeError('cyclic arena return')`,
|
|
56
|
+
' active.add(key)',
|
|
57
|
+
' try {',
|
|
58
|
+
];
|
|
59
|
+
if (node.kind === 'unit') {
|
|
60
|
+
body.push(' return {}');
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
body.push(node.kind === 'struct'
|
|
64
|
+
? ` new ${type}View(bytes, offset)`
|
|
65
|
+
: ` const view = new ${type}View(bytes, offset)`);
|
|
66
|
+
if (isPrimitive(node.kind) || node.kind === 'native_pointer' || node.kind === 'enum') {
|
|
67
|
+
body.push(' return view.value');
|
|
68
|
+
}
|
|
69
|
+
else if (node.kind === 'struct') {
|
|
70
|
+
body.push(` return { ${node.fields.map((field) => `${field.name}: decode${name(field.node)}(bytes, (offset + ${field.offset}) as u32, arena, active)`).join(', ')} }`);
|
|
71
|
+
}
|
|
72
|
+
else if (node.kind === 'offset_pointer') {
|
|
73
|
+
body.push(' if (view.offset === 0) return null', ` validateRange(arena, view.offset, 1 as u32, ${schema.nodes[node.item].size} as u32, ${schema.nodes[node.item].align} as u32)`, ` return decode${name(node.item)}(arena, view.offset, arena, active)`);
|
|
74
|
+
}
|
|
75
|
+
else if (node.kind === 'array' || node.kind === 'slice') {
|
|
76
|
+
const slice = node.kind === 'slice';
|
|
77
|
+
const source = slice ? 'arena' : 'bytes';
|
|
78
|
+
const start = slice ? 'view.offset' : 'offset';
|
|
79
|
+
const item = schema.nodes[resolveNode(schema, node.item)];
|
|
80
|
+
body.push(` validateRange(${source}, ${start}, view.length, ${item.size} as u32, ${item.align} as u32)`);
|
|
81
|
+
if (item.kind === 'u8') {
|
|
82
|
+
body.push(` return new Uint8Array(${source}.subarray(${start}, ${start} + view.length))`);
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
body.push(` const values: ${name(node.item)}[] = []`, ` for (let index = 0; index < view.length; index++) values.push(decode${name(node.item)}(${source}, (${start} + index * ${item.size}) as u32, arena, active))`, ' return values');
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
else if (node.kind === 'union') {
|
|
89
|
+
body.push(' switch (view.tag) {', ...node.variants.map((variant) => ` case ${type}View.tag_${variant.name}: return { tag: ${variantIdLiteral(variant.id)}${node.tag === 'u64' ? 'n' : ''}, value: decode${name(variant.node)}(bytes, (offset + ${node.payloadOffset}) as u32, arena, active) }`), " default: throw new RangeError('invalid native union tag')", ' }');
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
body.push(' } finally { active.delete(key) }', '}');
|
|
93
|
+
if (!/arena(?:,|\)|\.)/u.test(body.slice(1).join('\n'))) {
|
|
94
|
+
body[0] = body[0].replace('arena: Uint8Array', '_arena: Uint8Array');
|
|
95
|
+
}
|
|
96
|
+
if (node.kind === 'unit') {
|
|
97
|
+
body[0] = body[0].replace('bytes: Uint8Array', '_bytes: Uint8Array');
|
|
98
|
+
}
|
|
99
|
+
decoders.push(body.join('\n'));
|
|
100
|
+
}
|
|
101
|
+
for (const [alias, index] of Object.entries(schema.types)) {
|
|
102
|
+
if (alias !== name(index)) {
|
|
103
|
+
types.push(`export type ${alias} = ${name(index)}`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (Object.keys(schema.functions).length === 0) {
|
|
107
|
+
return `${types.join('\n')}\n${decoders.join('\n')}\n`;
|
|
108
|
+
}
|
|
109
|
+
const size = Math.max(0, ...Object.values(schema.functions).map((method) => method.returns === null ? 0 : schema.nodes[method.returns].size));
|
|
110
|
+
const raw = ['export interface CabiNative {'];
|
|
111
|
+
const calls = [
|
|
112
|
+
'export class CabiCalls {',
|
|
113
|
+
' readonly #native: CabiNative',
|
|
114
|
+
' readonly #arena: Uint8Array',
|
|
115
|
+
` readonly #result = new Uint8Array(${size})`,
|
|
116
|
+
' constructor(native: CabiNative, arena: Uint8Array) { this.#native = native; this.#arena = arena }',
|
|
117
|
+
];
|
|
118
|
+
for (const [methodName, method] of Object.entries(schema.functions)) {
|
|
119
|
+
const params = method.params.map((param) => `${param.name}: ${param.node === -1 ? 'Uint8Array' : scalar(param.node)}`);
|
|
120
|
+
const args = method.params.map((param) => param.name);
|
|
121
|
+
const returned = method.returns === null ? 'void' : name(method.returns);
|
|
122
|
+
raw.push(` ${methodName}: (${[...params, 'result: Uint8Array'].join(', ')}) => number`);
|
|
123
|
+
calls.push(` ${methodName}(${params.join(', ')}): ${returned} {`, ` const status = this.#native.${methodName}(${[...args, 'this.#result'].join(', ')})`, ' if (status !== 0) throw new CabiError(status)', ...(method.returns === null
|
|
124
|
+
? []
|
|
125
|
+
: [` return decode${returned}(this.#result, 0 as u32, this.#arena)`]), ' }');
|
|
126
|
+
}
|
|
127
|
+
raw.push('}');
|
|
128
|
+
calls.push('}');
|
|
129
|
+
return `export { CabiError } from '@muxion/cabi-runtime-js'\n${types.join('\n')}\n${decoders.join('\n')}\n${raw.join('\n')}\n${calls.join('\n')}\n`;
|
|
130
|
+
};
|
|
131
|
+
//# sourceMappingURL=calls.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calls.js","sourceRoot":"","sources":["../src/calls.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AACtC,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