space-data-module-sdk 0.9.16 → 0.10.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/docs/_shell/consumer-assets.html +1 -1
- package/docs/assets/sdn-chrome/sdn-chrome.js +1 -1
- package/docs/assets/vendor/sdn-stack-nav/{1.0.1/sdn-stack-nav.24eb3001afc5448a90cef87e53bb4e599c0ae4dc9e14bafb6d1236e0233c6008.js → 1.2.0/sdn-stack-nav.ba268c55a1551bcacc390ac01347c319335a1660787b55b4b239df00fc3c1a4c.js} +5 -0
- package/docs/browser-wasmedge-isomorphic.html +1 -1
- package/docs/byo-wasm-quickstart.html +1 -1
- package/docs/conformance.html +1 -1
- package/docs/events-abi.html +1 -1
- package/docs/families/analytics.html +1 -1
- package/docs/families/attitude.html +1 -1
- package/docs/families/behavior.html +1 -1
- package/docs/families/breakup.html +1 -1
- package/docs/families/conjunction.html +1 -1
- package/docs/families/data-source.html +1 -1
- package/docs/families/effects.html +1 -1
- package/docs/families/environment.html +1 -1
- package/docs/families/estimation.html +1 -1
- package/docs/families/gnc.html +1 -1
- package/docs/families/maneuver.html +1 -1
- package/docs/families/obstruction.html +1 -1
- package/docs/families/propagator.html +1 -1
- package/docs/families/propulsion.html +1 -1
- package/docs/families/reentry.html +1 -1
- package/docs/families/rf.html +1 -1
- package/docs/families/scheduler.html +1 -1
- package/docs/families/sensor.html +1 -1
- package/docs/families/signature.html +1 -1
- package/docs/flatsql-host-contract.html +16 -44
- package/docs/flatsql-host-contract.md +35 -107
- package/docs/flatsql-streaming-standard.html +14 -9
- package/docs/flatsql-streaming-standard.md +15 -10
- package/docs/gpu-module-abi.html +1 -1
- package/docs/index.html +1 -1
- package/docs/isomorphic-pthreads.html +1 -1
- package/docs/isomorphic-sdn-runtime-plan.html +1 -1
- package/docs/language-runtime-matrix.html +1 -1
- package/docs/module-bundle-runtime-plan.html +1 -1
- package/docs/module-publication-standard.html +1 -1
- package/docs/node-red-default-node-parity.html +1 -1
- package/docs/protect-and-sign.html +1 -1
- package/docs/protocol-installation.html +1 -1
- package/docs/publication-submission.html +1 -1
- package/docs/secrets-capability.html +1 -1
- package/docs/testing-harness.html +2 -2
- package/docs/testing-harness.md +7 -1
- package/docs/tri-runtime-parity-gate.html +1 -1
- package/docs/tri-runtime-parity.html +1 -1
- package/package.json +5 -5
- package/parity/gate.json +3 -3
- package/src/index.d.ts +25 -11
- package/src/runtime-host/flatbufferStreamIngestor.js +49 -170
- package/src/runtime-host/flatsqlQueryProtocol.js +76 -0
- package/src/runtime-host/flatsqlRuntimeStore.js +79 -278
- package/src/runtime-host/index.js +3 -1
- package/src/testing/parityGate.js +1 -1
- /package/docs/assets/vendor/sdn-stack-nav/{1.0.1 → 1.2.0}/sdn-stack-nav.36a36359ce18322185e9ff179f88175bab67d5ad84a14d9c08a54f2ff27267e7.css +0 -0
|
@@ -1,288 +1,89 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { FlatSQL } from "flatsql";
|
|
2
|
+
import { encodeFlatSqlQuery, decodeFlatSqlResult } from "./flatsqlQueryProtocol.js";
|
|
3
3
|
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
rowId: ulong;
|
|
9
|
-
}
|
|
10
|
-
`;
|
|
11
|
-
|
|
12
|
-
const encoder = new TextEncoder();
|
|
13
|
-
|
|
14
|
-
function clonePayload(payload) {
|
|
15
|
-
if (payload === null || payload === undefined) {
|
|
16
|
-
return payload ?? null;
|
|
17
|
-
}
|
|
18
|
-
if (typeof structuredClone === "function") {
|
|
19
|
-
return structuredClone(payload);
|
|
20
|
-
}
|
|
21
|
-
return clonePayloadFallback(payload, new WeakMap());
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function clonePayloadFallback(payload, seen) {
|
|
25
|
-
if (payload instanceof Date) {
|
|
26
|
-
return new Date(payload.getTime());
|
|
27
|
-
}
|
|
28
|
-
if (payload instanceof RegExp) {
|
|
29
|
-
return new RegExp(payload.source, payload.flags);
|
|
30
|
-
}
|
|
31
|
-
if (payload instanceof Map) {
|
|
32
|
-
if (seen.has(payload)) {
|
|
33
|
-
return seen.get(payload);
|
|
34
|
-
}
|
|
35
|
-
const cloned = new Map();
|
|
36
|
-
seen.set(payload, cloned);
|
|
37
|
-
for (const [key, value] of payload.entries()) {
|
|
38
|
-
cloned.set(clonePayloadFallback(key, seen), clonePayloadFallback(value, seen));
|
|
39
|
-
}
|
|
40
|
-
return cloned;
|
|
41
|
-
}
|
|
42
|
-
if (payload instanceof Set) {
|
|
43
|
-
if (seen.has(payload)) {
|
|
44
|
-
return seen.get(payload);
|
|
45
|
-
}
|
|
46
|
-
const cloned = new Set();
|
|
47
|
-
seen.set(payload, cloned);
|
|
48
|
-
for (const value of payload.values()) {
|
|
49
|
-
cloned.add(clonePayloadFallback(value, seen));
|
|
50
|
-
}
|
|
51
|
-
return cloned;
|
|
52
|
-
}
|
|
53
|
-
if (ArrayBuffer.isView(payload)) {
|
|
54
|
-
if (payload instanceof DataView) {
|
|
55
|
-
return new DataView(
|
|
56
|
-
payload.buffer.slice(
|
|
57
|
-
payload.byteOffset,
|
|
58
|
-
payload.byteOffset + payload.byteLength,
|
|
59
|
-
),
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
const clonedBuffer = payload.buffer.slice(
|
|
63
|
-
payload.byteOffset,
|
|
64
|
-
payload.byteOffset + payload.byteLength,
|
|
65
|
-
);
|
|
66
|
-
return new payload.constructor(clonedBuffer, 0, payload.length);
|
|
67
|
-
}
|
|
68
|
-
if (payload instanceof ArrayBuffer) {
|
|
69
|
-
return payload.slice(0);
|
|
70
|
-
}
|
|
71
|
-
if (Array.isArray(payload)) {
|
|
72
|
-
if (seen.has(payload)) {
|
|
73
|
-
return seen.get(payload);
|
|
74
|
-
}
|
|
75
|
-
const cloned = [];
|
|
76
|
-
seen.set(payload, cloned);
|
|
77
|
-
for (const value of payload) {
|
|
78
|
-
cloned.push(clonePayloadFallback(value, seen));
|
|
79
|
-
}
|
|
80
|
-
return cloned;
|
|
81
|
-
}
|
|
82
|
-
if (typeof payload === "object") {
|
|
83
|
-
if (seen.has(payload)) {
|
|
84
|
-
return seen.get(payload);
|
|
85
|
-
}
|
|
86
|
-
const prototype = Object.getPrototypeOf(payload);
|
|
87
|
-
const cloned = Object.create(prototype ?? Object.prototype);
|
|
88
|
-
seen.set(payload, cloned);
|
|
89
|
-
for (const key of Reflect.ownKeys(payload)) {
|
|
90
|
-
const descriptor = Object.getOwnPropertyDescriptor(payload, key);
|
|
91
|
-
if (!descriptor) {
|
|
92
|
-
continue;
|
|
93
|
-
}
|
|
94
|
-
if ("value" in descriptor) {
|
|
95
|
-
descriptor.value = clonePayloadFallback(descriptor.value, seen);
|
|
96
|
-
}
|
|
97
|
-
Object.defineProperty(cloned, key, descriptor);
|
|
98
|
-
}
|
|
99
|
-
return cloned;
|
|
100
|
-
}
|
|
101
|
-
return payload;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
function normalizeSchemaFileId(value) {
|
|
105
|
-
if (typeof value !== "string" || value.trim().length === 0) {
|
|
106
|
-
throw new TypeError("schemaFileId must be a non-empty string");
|
|
107
|
-
}
|
|
108
|
-
return value.trim();
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
function normalizeRowHandle(handle) {
|
|
112
|
-
if (!handle || typeof handle !== "object") {
|
|
113
|
-
throw new TypeError("row handle is required");
|
|
114
|
-
}
|
|
115
|
-
const schemaFileId = normalizeSchemaFileId(handle.schemaFileId);
|
|
116
|
-
const rowId = Number(handle.rowId);
|
|
117
|
-
if (!Number.isInteger(rowId) || rowId <= 0) {
|
|
118
|
-
throw new TypeError("rowId must be a positive integer");
|
|
4
|
+
const quote = name => `"${name.replaceAll('"', '""')}"`;
|
|
5
|
+
const fileId = value => {
|
|
6
|
+
if (typeof value !== "string" || new TextEncoder().encode(value).length !== 4) {
|
|
7
|
+
throw new TypeError("schemaFileId must be the four-byte FlatBuffer file identifier");
|
|
119
8
|
}
|
|
120
|
-
return
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
function escapeSqlStringLiteral(value) {
|
|
124
|
-
return String(value).replaceAll("'", "''");
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
function encodeRuntimeRowMetadata({ schemaFileId, rowId }) {
|
|
128
|
-
const schemaBytes = encoder.encode(normalizeSchemaFileId(schemaFileId));
|
|
129
|
-
const encoded = new Uint8Array(4 + schemaBytes.byteLength + 8);
|
|
130
|
-
const view = new DataView(encoded.buffer);
|
|
131
|
-
view.setUint32(0, schemaBytes.byteLength, true);
|
|
132
|
-
encoded.set(schemaBytes, 4);
|
|
133
|
-
view.setBigUint64(4 + schemaBytes.byteLength, BigInt(rowId), true);
|
|
134
|
-
return encoded;
|
|
135
|
-
}
|
|
9
|
+
return value;
|
|
10
|
+
};
|
|
136
11
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
throw new Error("
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
schemaFileId: decodeGuestText(bytes.subarray(schemaStart, schemaEnd)),
|
|
155
|
-
rowId: Number(view.getBigUint64(rowIdOffset, true)),
|
|
12
|
+
/** Durable binary records. Schema compilation and result rendering belong to
|
|
13
|
+
* the caller; the engine owns row IDs, deduplication, indexes and persistence. */
|
|
14
|
+
export function createFlatSqlRuntimeStore(options = {}) {
|
|
15
|
+
const schemas = new Map();
|
|
16
|
+
let opening, closed = false;
|
|
17
|
+
const database = () => {
|
|
18
|
+
if (closed) throw new Error("Runtime row store is closed");
|
|
19
|
+
return opening ??= (async () => {
|
|
20
|
+
const db = options.database ?? await FlatSQL.open(options.engine);
|
|
21
|
+
try {
|
|
22
|
+
for (const spec of options.schemas ?? []) {
|
|
23
|
+
const id = fileId(spec.fileIdentifier);
|
|
24
|
+
await db.registerSchema(spec); schemas.set(id, spec);
|
|
25
|
+
}
|
|
26
|
+
return db;
|
|
27
|
+
} catch (error) { await db.close(); throw error; }
|
|
28
|
+
})();
|
|
156
29
|
};
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
return null;
|
|
171
|
-
}
|
|
172
|
-
current = current[segment];
|
|
30
|
+
async function registerSchema(schema) {
|
|
31
|
+
const id = fileId(schema.fileIdentifier);
|
|
32
|
+
await (await database()).registerSchema(schema);
|
|
33
|
+
schemas.set(id, schema);
|
|
34
|
+
}
|
|
35
|
+
async function schemaFor(id) {
|
|
36
|
+
id = fileId(id);
|
|
37
|
+
await database();
|
|
38
|
+
if (!schemas.has(id)) {
|
|
39
|
+
const spec = (options.schemas ?? []).find(s => s.fileIdentifier === id)
|
|
40
|
+
?? await options.resolveSchema?.(id);
|
|
41
|
+
if (!spec || spec.fileIdentifier !== id) throw new Error(`No binary schema registered for ${id}`);
|
|
42
|
+
await registerSchema(spec);
|
|
173
43
|
}
|
|
174
|
-
return
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
)
|
|
191
|
-
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
};
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
export function createFlatSqlRuntimeStore(options = {}) {
|
|
208
|
-
const accessor = options.accessor ?? createRuntimeRowAccessor();
|
|
209
|
-
const payloadStore = options.payloadStore ?? new Map();
|
|
210
|
-
const database =
|
|
211
|
-
options.database ??
|
|
212
|
-
FlatSQLDatabase.fromSchema(
|
|
213
|
-
RUNTIME_ROW_SCHEMA,
|
|
214
|
-
accessor,
|
|
215
|
-
options.databaseName ?? "runtime-host",
|
|
216
|
-
);
|
|
217
|
-
const nextRowIdBySchema = new Map();
|
|
218
|
-
const existingRows = database.query(
|
|
219
|
-
`SELECT schemaFileId, rowId FROM ${RUNTIME_ROW_TABLE} ORDER BY schemaFileId, rowId`,
|
|
220
|
-
);
|
|
221
|
-
for (const row of existingRows.rows ?? []) {
|
|
222
|
-
const schemaFileId = normalizeSchemaFileId(row[0]);
|
|
223
|
-
const rowId = Number(row[1]);
|
|
224
|
-
if (Number.isInteger(rowId) && rowId > 0) {
|
|
225
|
-
nextRowIdBySchema.set(
|
|
226
|
-
schemaFileId,
|
|
227
|
-
Math.max(nextRowIdBySchema.get(schemaFileId) ?? 0, rowId),
|
|
228
|
-
);
|
|
44
|
+
return schemas.get(id);
|
|
45
|
+
}
|
|
46
|
+
async function query(sql, params = [], limits = {}) {
|
|
47
|
+
return decodeFlatSqlResult(await (await database()).execute(encodeFlatSqlQuery(sql, params), limits));
|
|
48
|
+
}
|
|
49
|
+
async function appendRow({ schemaFileId, payload }) {
|
|
50
|
+
const schema = await schemaFor(schemaFileId);
|
|
51
|
+
if (!(payload instanceof Uint8Array) || payload.length < 8) throw new TypeError("payload must be a FlatBuffer Uint8Array");
|
|
52
|
+
if (String.fromCharCode(...payload.subarray(4, 8)) !== schema.fileIdentifier) throw new Error("Record file identifier does not match its schema");
|
|
53
|
+
const frame = new Uint8Array(payload.length + 4);
|
|
54
|
+
new DataView(frame.buffer).setUint32(0, payload.length, true);
|
|
55
|
+
frame.set(payload, 4);
|
|
56
|
+
const receipt = decodeFlatSqlResult(await (await database()).ingest(schema.name, frame));
|
|
57
|
+
const row = receipt.rows[0];
|
|
58
|
+
if (receipt.rows.length !== 1 || Number(row[1]) === 0) throw new Error(`FlatSQL rejected record: ${row?.[3] ?? "missing receipt"}`);
|
|
59
|
+
const rowId = Number(row[2]);
|
|
60
|
+
if (!Number.isSafeInteger(rowId) || rowId < 1) throw new RangeError("Row ID exceeds the host identity range");
|
|
61
|
+
return { schemaFileId: schema.fileIdentifier, rowId };
|
|
62
|
+
}
|
|
63
|
+
async function listRows(schemaFileId) {
|
|
64
|
+
const ids = schemaFileId == null ? [...new Set([...schemas.keys(), ...(options.schemas ?? []).map(s => s.fileIdentifier)])].sort() : [fileId(schemaFileId)];
|
|
65
|
+
const out = [];
|
|
66
|
+
for (const id of ids) {
|
|
67
|
+
const schema = await schemaFor(id);
|
|
68
|
+
const result = await query(`SELECT _rowid,_data FROM ${quote(schema.name)} ORDER BY _rowid`);
|
|
69
|
+
for (const [rowId, payload] of result.rows) {
|
|
70
|
+
const value = Number(rowId);
|
|
71
|
+
if (!Number.isSafeInteger(value) || value < 1) throw new RangeError("Row ID exceeds the host identity range");
|
|
72
|
+
out.push({ handle: { schemaFileId: id, rowId: value }, payload });
|
|
73
|
+
}
|
|
229
74
|
}
|
|
75
|
+
return out;
|
|
230
76
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
const
|
|
234
|
-
const
|
|
235
|
-
|
|
236
|
-
database.insert(RUNTIME_ROW_TABLE, {
|
|
237
|
-
schemaFileId: normalizedSchemaFileId,
|
|
238
|
-
rowId: nextRowId,
|
|
239
|
-
});
|
|
240
|
-
payloadStore.set(
|
|
241
|
-
buildRowKey(normalizedSchemaFileId, nextRowId),
|
|
242
|
-
clonePayload(payload),
|
|
243
|
-
);
|
|
244
|
-
return {
|
|
245
|
-
schemaFileId: normalizedSchemaFileId,
|
|
246
|
-
rowId: nextRowId,
|
|
247
|
-
};
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
function resolveRow(handle) {
|
|
251
|
-
const normalizedHandle = normalizeRowHandle(handle);
|
|
252
|
-
return (
|
|
253
|
-
listRows(normalizedHandle.schemaFileId).find(
|
|
254
|
-
(row) => row.handle.rowId === normalizedHandle.rowId,
|
|
255
|
-
) ?? null
|
|
256
|
-
);
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
function listRows(schemaFileId = null) {
|
|
260
|
-
const normalizedSchemaFileId =
|
|
261
|
-
schemaFileId === null || schemaFileId === undefined
|
|
262
|
-
? null
|
|
263
|
-
: normalizeSchemaFileId(schemaFileId);
|
|
264
|
-
const result =
|
|
265
|
-
normalizedSchemaFileId === null
|
|
266
|
-
? database.query(
|
|
267
|
-
`SELECT schemaFileId, rowId FROM ${RUNTIME_ROW_TABLE} ORDER BY schemaFileId, rowId`,
|
|
268
|
-
)
|
|
269
|
-
: database.query(
|
|
270
|
-
`SELECT schemaFileId, rowId FROM ${RUNTIME_ROW_TABLE} WHERE schemaFileId = '${escapeSqlStringLiteral(normalizedSchemaFileId)}' ORDER BY rowId`,
|
|
271
|
-
);
|
|
272
|
-
return (result.rows ?? []).map((row) => rowViewFromQueryRow(row, payloadStore));
|
|
77
|
+
async function resolveRow(handle) {
|
|
78
|
+
if (!Number.isSafeInteger(handle?.rowId) || handle.rowId < 1) throw new TypeError("rowId must be a positive safe integer");
|
|
79
|
+
const schema = await schemaFor(handle.schemaFileId);
|
|
80
|
+
const result = await query(`SELECT _data FROM ${quote(schema.name)} WHERE _rowid=?1`, [handle.rowId]);
|
|
81
|
+
return result.rows.length ? { handle: { schemaFileId: schema.fileIdentifier, rowId: handle.rowId }, payload: result.rows[0][0] } : null;
|
|
273
82
|
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
}
|
|
279
|
-
return cloneQueryResult(database.query(sql));
|
|
83
|
+
async function close() {
|
|
84
|
+
if (closed) return;
|
|
85
|
+
closed = true;
|
|
86
|
+
if (opening) await (await opening).close();
|
|
280
87
|
}
|
|
281
|
-
|
|
282
|
-
return {
|
|
283
|
-
appendRow,
|
|
284
|
-
listRows,
|
|
285
|
-
query,
|
|
286
|
-
resolveRow,
|
|
287
|
-
};
|
|
88
|
+
return { registerSchema, appendRow, listRows, query, resolveRow, close };
|
|
288
89
|
}
|
|
@@ -46,7 +46,7 @@ function listCapabilityOperations(capabilities) {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
export function createRuntimeHost(options = {}) {
|
|
49
|
-
const rows = options.rows ?? createFlatSqlRuntimeStore();
|
|
49
|
+
const rows = options.rows ?? createFlatSqlRuntimeStore(options.rowStore);
|
|
50
50
|
const regions = options.regions ?? createRuntimeRegionStore();
|
|
51
51
|
const moduleRegistry = options.moduleRegistry ?? createModuleRegistry();
|
|
52
52
|
const capabilities = createCapabilityRegistry(options.capabilities);
|
|
@@ -114,3 +114,5 @@ export {
|
|
|
114
114
|
// Flow-tier validating method registry (vendored sdn-flow semantics; distinct
|
|
115
115
|
// from createModuleRegistry's module-lifecycle registry).
|
|
116
116
|
export { MethodRegistry } from "./methodRegistry.js";
|
|
117
|
+
|
|
118
|
+
export { encodeFlatSqlQuery, decodeFlatSqlResult } from "./flatsqlQueryProtocol.js";
|
|
@@ -279,7 +279,7 @@ export function makeExternalArtifact(spec) {
|
|
|
279
279
|
// --- WasmEdge probe lanes -------------------------------------------------------
|
|
280
280
|
|
|
281
281
|
const UNKNOWN_IMPORT_RE =
|
|
282
|
-
/unknown import[\s\S]*?When linking module:\s*"([^"]*)"\s*,\s*function name:\s*"([^"]*)"/;
|
|
282
|
+
/unknown import[\s\S]*?When linking module:\s*"([^"]*)"\s*,\s*(?:function|memory|table|global) name:\s*"([^"]*)"/;
|
|
283
283
|
|
|
284
284
|
/**
|
|
285
285
|
* Classify a bare-WasmEdge probe run.
|