space-data-module-sdk 0.8.27 → 0.9.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 +5 -4
- package/docs/assembly.js +0 -18
- package/docs/assets/ai-credits/ai-credits.js +116 -0
- package/docs/assets/sdn-chrome/sdn-chrome.css +434 -0
- package/docs/assets/sdn-chrome/sdn-chrome.js +236 -0
- package/docs/browser-wasmedge-isomorphic.html +29 -41
- package/docs/byo-wasm-quickstart.html +29 -41
- package/docs/conformance.html +29 -41
- package/docs/events-abi.html +29 -41
- package/docs/families/analytics.html +29 -41
- package/docs/families/attitude.html +29 -41
- package/docs/families/behavior.html +29 -41
- package/docs/families/breakup.html +29 -41
- package/docs/families/conjunction.html +29 -41
- package/docs/families/data-source.html +29 -41
- package/docs/families/effects.html +29 -41
- package/docs/families/environment.html +29 -41
- package/docs/families/estimation.html +29 -41
- package/docs/families/gnc.html +29 -41
- package/docs/families/maneuver.html +29 -41
- package/docs/families/obstruction.html +29 -41
- package/docs/families/propagator.html +29 -41
- package/docs/families/propulsion.html +29 -41
- package/docs/families/reentry.html +29 -41
- package/docs/families/rf.html +29 -41
- package/docs/families/scheduler.html +29 -41
- package/docs/families/sensor.html +29 -41
- package/docs/families/signature.html +29 -41
- package/docs/flatsql-host-contract.html +29 -41
- package/docs/flatsql-streaming-standard.html +29 -41
- package/docs/gpu-module-abi.html +29 -41
- package/docs/index.html +43 -47
- package/docs/isomorphic-pthreads.html +29 -41
- package/docs/isomorphic-sdn-runtime-plan.html +29 -41
- package/docs/language-runtime-matrix.html +29 -41
- package/docs/media/module-sdk-reel-poster.webp +0 -0
- package/docs/media/module-sdk-reel.mp4 +0 -0
- package/docs/media/module-sdk-reel.webm +0 -0
- package/docs/media/reel/reel.css +53 -0
- package/docs/media/reel/reel.js +272 -0
- package/docs/module-bundle-runtime-plan.html +29 -41
- package/docs/module-publication-standard.html +29 -41
- package/docs/node-red-default-node-parity.html +29 -41
- package/docs/protect-and-sign.html +29 -41
- package/docs/protocol-installation.html +29 -41
- package/docs/publication-submission.html +29 -41
- package/docs/secrets-capability.html +29 -41
- package/docs/styles.css +89 -157
- package/docs/testing-harness.html +29 -41
- package/docs/tri-runtime-parity-gate.html +29 -41
- package/docs/tri-runtime-parity.html +29 -41
- package/package.json +5 -3
- package/schemas/runtime/FlowNotice.fbs +39 -0
- package/schemas/runtime/HostOps.fbs +453 -0
- package/schemas/runtime/HttpRequest.fbs +25 -0
- package/schemas/runtime/HttpResponse.fbs +24 -0
- package/schemas/runtime/IngestRequest.fbs +58 -0
- package/schemas/runtime/IngestResult.fbs +23 -0
- package/schemas/runtime/ModuleConfig.fbs +41 -0
- package/schemas/runtime/RuntimeCommon.fbs +33 -0
- package/schemas/runtime/TimerTick.fbs +18 -0
- package/src/compiler/compileModule.js +20 -2
- package/src/generated/runtime/aligned/HostOps_aligned.js +3924 -0
- package/src/generated/runtime/aligned/HostOps_aligned.ts +4620 -0
- package/src/generated/runtime/aligned/HostOps_enums.js +14 -0
- package/src/generated/runtime/aligned/HostOps_enums.ts +7 -0
- package/src/generated/runtime/cpp/FlowNotice_generated.h +367 -0
- package/src/generated/runtime/cpp/HostOps_aligned.h +3547 -0
- package/src/generated/runtime/cpp/HttpRequest_generated.h +317 -0
- package/src/generated/runtime/cpp/HttpResponse_generated.h +315 -0
- package/src/generated/runtime/cpp/IngestRequest_generated.h +764 -0
- package/src/generated/runtime/cpp/IngestResult_generated.h +319 -0
- package/src/generated/runtime/cpp/ModuleConfig_generated.h +604 -0
- package/src/generated/runtime/cpp/RuntimeCommon_generated.h +410 -0
- package/src/generated/runtime/cpp/TimerTick_generated.h +229 -0
- package/src/generated/runtime/sdn/runtime/ArchiveTarget.js +78 -0
- package/src/generated/runtime/sdn/runtime/ArchiveTarget.ts +104 -0
- package/src/generated/runtime/sdn/runtime/ConfigEntry.js +202 -0
- package/src/generated/runtime/sdn/runtime/ConfigEntry.ts +251 -0
- package/src/generated/runtime/sdn/runtime/ConfigTable.js +80 -0
- package/src/generated/runtime/sdn/runtime/ConfigTable.ts +97 -0
- package/src/generated/runtime/sdn/runtime/FlowNotice.js +196 -0
- package/src/generated/runtime/sdn/runtime/FlowNotice.ts +254 -0
- package/src/generated/runtime/sdn/runtime/Header.js +79 -0
- package/src/generated/runtime/sdn/runtime/Header.ts +100 -0
- package/src/generated/runtime/sdn/runtime/HttpRequest.js +216 -0
- package/src/generated/runtime/sdn/runtime/HttpRequest.ts +265 -0
- package/src/generated/runtime/sdn/runtime/HttpResponse.js +216 -0
- package/src/generated/runtime/sdn/runtime/HttpResponse.ts +267 -0
- package/src/generated/runtime/sdn/runtime/IngestRequest.js +121 -0
- package/src/generated/runtime/sdn/runtime/IngestRequest.ts +155 -0
- package/src/generated/runtime/sdn/runtime/IngestResult.js +184 -0
- package/src/generated/runtime/sdn/runtime/IngestResult.ts +235 -0
- package/src/generated/runtime/sdn/runtime/ModuleConfig.js +92 -0
- package/src/generated/runtime/sdn/runtime/ModuleConfig.ts +114 -0
- package/src/generated/runtime/sdn/runtime/Provenance.js +288 -0
- package/src/generated/runtime/sdn/runtime/Provenance.ts +368 -0
- package/src/generated/runtime/sdn/runtime/SourceTags.js +181 -0
- package/src/generated/runtime/sdn/runtime/SourceTags.ts +253 -0
- package/src/generated/runtime/sdn/runtime/TimerTick.js +119 -0
- package/src/generated/runtime/sdn/runtime/TimerTick.ts +148 -0
- package/src/generated/runtime/sdn/runtime/configValueKind.js +12 -0
- package/src/generated/runtime/sdn/runtime/configValueKind.ts +19 -0
- package/src/generated/runtime/sdn/runtime/flowNoticeKind.js +11 -0
- package/src/generated/runtime/sdn/runtime/flowNoticeKind.ts +34 -0
- package/src/generated/runtime/sdn/runtime/reconcileMode.js +9 -0
- package/src/generated/runtime/sdn/runtime/reconcileMode.ts +23 -0
- package/src/generated/runtime/sdn/runtime.js +16 -0
- package/src/generated/runtime/sdn/runtime.ts +17 -0
- package/src/host/abi.js +20 -3
- package/src/host/browserHost.js +2 -0
- package/src/host/cpp/typedHostcall.hpp +201 -0
- package/src/host/hostWorkerBundleSources.js +3 -3
- package/src/host/nodeHost.js +1 -0
- package/src/host/typedDispatch.js +230 -0
- package/src/invoke/codec.js +3 -2
- package/src/standards/runtimeContracts.js +536 -0
- package/src/standards/sharedCatalog.js +27 -0
|
@@ -0,0 +1,536 @@
|
|
|
1
|
+
// The module runtime contracts (schemas/runtime/*.fbs, namespace sdn.runtime): the typed FlatBuffer frames that cross a
|
|
2
|
+
// module port, a host connector or the flow runtime - TimerTick, HttpRequest, HttpResponse, ModuleConfig,
|
|
3
|
+
// IngestRequest, IngestResult, FlowNotice (typed-contracts 1.0, owner 2026-10-13: "flatbuffer SDS only"; no JSON
|
|
4
|
+
// forms). The generated classes (scripts/generate-runtime-bindings.mjs) and, for JS hosts and tests, one encoder and
|
|
5
|
+
// decoder per frame over plain objects. A frame is one FlatBuffer finished with its file identifier (TICK, HREQ, ...);
|
|
6
|
+
// identifierOf reads it back. 64-bit times and counts are numbers here (exact to 2^53) and BigInt in the bindings.
|
|
7
|
+
import * as flatbuffers from "flatbuffers";
|
|
8
|
+
import {
|
|
9
|
+
ArchiveTargetT,
|
|
10
|
+
ConfigEntryT,
|
|
11
|
+
ConfigTableT,
|
|
12
|
+
FlowNotice,
|
|
13
|
+
FlowNoticeT,
|
|
14
|
+
HeaderT,
|
|
15
|
+
HttpRequest,
|
|
16
|
+
HttpRequestT,
|
|
17
|
+
HttpResponse,
|
|
18
|
+
HttpResponseT,
|
|
19
|
+
IngestRequest,
|
|
20
|
+
IngestRequestT,
|
|
21
|
+
IngestResult,
|
|
22
|
+
IngestResultT,
|
|
23
|
+
ModuleConfig,
|
|
24
|
+
ModuleConfigT,
|
|
25
|
+
ProvenanceT,
|
|
26
|
+
SourceTagsT,
|
|
27
|
+
TimerTick,
|
|
28
|
+
TimerTickT,
|
|
29
|
+
configValueKind,
|
|
30
|
+
flowNoticeKind,
|
|
31
|
+
reconcileMode,
|
|
32
|
+
} from "../generated/runtime/sdn/runtime.js";
|
|
33
|
+
import * as hostOps from "../generated/runtime/aligned/HostOps_aligned.js";
|
|
34
|
+
import {
|
|
35
|
+
decodePluginInvokeRequest,
|
|
36
|
+
decodePluginInvokeResponse,
|
|
37
|
+
encodePluginInvokeRequest,
|
|
38
|
+
encodePluginInvokeResponse,
|
|
39
|
+
} from "../invoke/codec.js";
|
|
40
|
+
|
|
41
|
+
export * from "../generated/runtime/sdn/runtime.js";
|
|
42
|
+
export * from "../generated/runtime/aligned/HostOps_enums.js";
|
|
43
|
+
|
|
44
|
+
export const RUNTIME_FILE_IDENTIFIERS = Object.freeze({
|
|
45
|
+
TimerTick: "TICK",
|
|
46
|
+
HttpRequest: "HREQ",
|
|
47
|
+
HttpResponse: "HRSP",
|
|
48
|
+
ModuleConfig: "MCFG",
|
|
49
|
+
IngestRequest: "INGQ",
|
|
50
|
+
IngestResult: "INGR",
|
|
51
|
+
FlowNotice: "FNTC",
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
/** The 4-character file identifier of a FlatBuffer frame (bytes 4-7), or "" when it has none. */
|
|
55
|
+
export function identifierOf(bytes) {
|
|
56
|
+
const b = bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes);
|
|
57
|
+
if (b.length < 8) return "";
|
|
58
|
+
return String.fromCharCode(b[4], b[5], b[6], b[7]);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const big = (n) => BigInt(Math.max(0, Math.trunc(Number(n) || 0)));
|
|
62
|
+
const num = (n) => (typeof n === "bigint" ? Number(n) : Number(n) || 0);
|
|
63
|
+
const bytesOf = (v) => (v == null ? [] : Array.from(v instanceof Uint8Array ? v : new Uint8Array(v)));
|
|
64
|
+
const u8 = (a) => Uint8Array.from(a || []);
|
|
65
|
+
const str = (v) => (v == null ? "" : String(v));
|
|
66
|
+
|
|
67
|
+
function finish(object, finishBuffer) {
|
|
68
|
+
const builder = new flatbuffers.Builder(256);
|
|
69
|
+
finishBuffer(builder, object.pack(builder));
|
|
70
|
+
return builder.asUint8Array().slice();
|
|
71
|
+
}
|
|
72
|
+
function rootOf(bytes, Type, getRoot, id) {
|
|
73
|
+
const bb = new flatbuffers.ByteBuffer(bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes));
|
|
74
|
+
if (!Type.bufferHasIdentifier(bb)) throw new Error(`not a ${id} frame (identifier "${identifierOf(bytes)}")`);
|
|
75
|
+
return getRoot(bb).unpack();
|
|
76
|
+
}
|
|
77
|
+
const headersT = (headers) =>
|
|
78
|
+
Object.entries(headers || {})
|
|
79
|
+
.map(([name, value]) => new HeaderT(String(name).toLowerCase(), String(value)))
|
|
80
|
+
.sort((a, b) => (a.NAME < b.NAME ? -1 : a.NAME > b.NAME ? 1 : 0));
|
|
81
|
+
const headersOf = (list) => Object.fromEntries((list || []).map((h) => [h.NAME, h.VALUE]));
|
|
82
|
+
|
|
83
|
+
// ---- TimerTick --------------------------------------------------------------------------------------------------
|
|
84
|
+
|
|
85
|
+
/** @param {{triggerId?:string, scheduledMs?:number, firedMs?:number, sequence?:number}} t */
|
|
86
|
+
export function encodeTimerTick(t = {}) {
|
|
87
|
+
return finish(new TimerTickT(str(t.triggerId), big(t.scheduledMs), big(t.firedMs), big(t.sequence)), TimerTick.finishTimerTickBuffer);
|
|
88
|
+
}
|
|
89
|
+
export function decodeTimerTick(bytes) {
|
|
90
|
+
const t = rootOf(bytes, TimerTick, TimerTick.getRootAsTimerTick, "TICK");
|
|
91
|
+
return { triggerId: t.TRIGGER_ID || "", scheduledMs: num(t.SCHEDULED_MS), firedMs: num(t.FIRED_MS), sequence: num(t.SEQUENCE) };
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// ---- HttpRequest / HttpResponse -------------------------------------------------------------------------------
|
|
95
|
+
|
|
96
|
+
/** @param {{method?:string, url:string, headers?:Record<string,string>, body?:Uint8Array, timeoutMs?:number, maxBytes?:number, context?:Uint8Array}} r */
|
|
97
|
+
export function encodeHttpRequest(r) {
|
|
98
|
+
if (!r?.url) throw new Error("HttpRequest: url is required");
|
|
99
|
+
return finish(
|
|
100
|
+
new HttpRequestT(str(r.method || "GET").toUpperCase(), String(r.url), headersT(r.headers), bytesOf(r.body), Math.max(0, r.timeoutMs | 0), big(r.maxBytes), bytesOf(r.context)),
|
|
101
|
+
HttpRequest.finishHttpRequestBuffer,
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
export function decodeHttpRequest(bytes) {
|
|
105
|
+
const r = rootOf(bytes, HttpRequest, HttpRequest.getRootAsHttpRequest, "HREQ");
|
|
106
|
+
return { method: r.METHOD || "GET", url: r.URL || "", headers: headersOf(r.HEADERS), body: u8(r.BODY), timeoutMs: r.TIMEOUT_MS, maxBytes: num(r.MAX_BYTES), context: u8(r.CONTEXT) };
|
|
107
|
+
}
|
|
108
|
+
/** @param {{url?:string, status?:number, headers?:Record<string,string>, body?:Uint8Array, context?:Uint8Array, error?:string, retrievedMs?:number}} r */
|
|
109
|
+
export function encodeHttpResponse(r = {}) {
|
|
110
|
+
return finish(
|
|
111
|
+
new HttpResponseT(str(r.url), r.status | 0, headersT(r.headers), bytesOf(r.body), bytesOf(r.context), str(r.error), big(r.retrievedMs)),
|
|
112
|
+
HttpResponse.finishHttpResponseBuffer,
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
export function decodeHttpResponse(bytes) {
|
|
116
|
+
const r = rootOf(bytes, HttpResponse, HttpResponse.getRootAsHttpResponse, "HRSP");
|
|
117
|
+
return { url: r.URL || "", status: r.STATUS, headers: headersOf(r.HEADERS), body: u8(r.BODY), context: u8(r.CONTEXT), error: r.ERROR || "", retrievedMs: num(r.RETRIEVED_MS) };
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// ---- ModuleConfig -----------------------------------------------------------------------------------------------
|
|
121
|
+
|
|
122
|
+
function entryOf(key, value) {
|
|
123
|
+
const e = new ConfigEntryT(String(key));
|
|
124
|
+
if (typeof value === "string") { e.KIND = configValueKind.String; e.STRING_VALUE = value; }
|
|
125
|
+
else if (typeof value === "number" || typeof value === "bigint") { e.KIND = configValueKind.Number; e.NUMBER_VALUE = Number(value); }
|
|
126
|
+
else if (typeof value === "boolean") { e.KIND = configValueKind.Bool; e.BOOL_VALUE = value; }
|
|
127
|
+
else if (Array.isArray(value)) {
|
|
128
|
+
if (value.every((v) => typeof v === "number")) { e.KIND = configValueKind.NumberList; e.NUMBERS = value.map(Number); }
|
|
129
|
+
else if (value.every((v) => v && typeof v === "object" && !Array.isArray(v))) { e.KIND = configValueKind.TableList; e.TABLES = value.map((t) => new ConfigTableT(entriesOf(t))); }
|
|
130
|
+
else if (value.every((v) => typeof v === "string")) { e.KIND = configValueKind.StringList; e.STRINGS = value.slice(); }
|
|
131
|
+
else throw new Error(`ModuleConfig: ${key} mixes value kinds`);
|
|
132
|
+
} else if (value && typeof value === "object") { e.KIND = configValueKind.TableList; e.TABLES = [new ConfigTableT(entriesOf(value))]; }
|
|
133
|
+
else throw new Error(`ModuleConfig: ${key} has no config value kind (${value === null ? "null" : typeof value})`);
|
|
134
|
+
return e;
|
|
135
|
+
}
|
|
136
|
+
const entriesOf = (object) => Object.keys(object || {}).filter((k) => object[k] !== undefined).sort().map((k) => entryOf(k, object[k]));
|
|
137
|
+
function valueOf(e) {
|
|
138
|
+
switch (e.KIND) {
|
|
139
|
+
case configValueKind.String: return e.STRING_VALUE || "";
|
|
140
|
+
case configValueKind.Number: return e.NUMBER_VALUE;
|
|
141
|
+
case configValueKind.Bool: return e.BOOL_VALUE;
|
|
142
|
+
case configValueKind.StringList: return (e.STRINGS || []).slice();
|
|
143
|
+
case configValueKind.NumberList: return (e.NUMBERS || []).slice();
|
|
144
|
+
case configValueKind.TableList: return (e.TABLES || []).map((t) => objectOf(t.ENTRIES));
|
|
145
|
+
default: throw new Error(`ModuleConfig: ${e.KEY} has an unknown value kind ${e.KIND}`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
const objectOf = (entries) => Object.fromEntries((entries || []).map((e) => [e.KEY, valueOf(e)]));
|
|
149
|
+
|
|
150
|
+
/** A plain object (strings, numbers, booleans, lists of them, nested objects or lists of objects) as a ModuleConfig. */
|
|
151
|
+
export function encodeModuleConfig(config = {}) {
|
|
152
|
+
return finish(new ModuleConfigT(entriesOf(config)), ModuleConfig.finishModuleConfigBuffer);
|
|
153
|
+
}
|
|
154
|
+
/** A ModuleConfig back as a plain object (a single nested table is returned as a one-element list). */
|
|
155
|
+
export function decodeModuleConfig(bytes) {
|
|
156
|
+
return objectOf(rootOf(bytes, ModuleConfig, ModuleConfig.getRootAsModuleConfig, "MCFG").ENTRIES);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// ---- IngestRequest / IngestResult -------------------------------------------------------------------------------
|
|
160
|
+
|
|
161
|
+
const RECONCILE = { duplicates: reconcileMode.Duplicates, none: reconcileMode.None, current: reconcileMode.Current };
|
|
162
|
+
const RECONCILE_NAME = Object.fromEntries(Object.entries(RECONCILE).map(([k, v]) => [v, k]));
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* @param {{schema:string, tags:{providerId?:string, sourceName?:string, batchId?:string, sourceUrl?:string, contentKeyId?:string,
|
|
166
|
+
* sourcePeer?:string, license?:string, licenseUrl?:string, citation?:string, shareAlike?:boolean}, reconcile?:"duplicates"|"none"|"current",
|
|
167
|
+
* archive?:{source:string, name:string}, provenance?:object}} r
|
|
168
|
+
*/
|
|
169
|
+
export function encodeIngestRequest(r) {
|
|
170
|
+
if (!r?.schema || !r?.tags) throw new Error("IngestRequest: schema and tags are required");
|
|
171
|
+
const t = r.tags;
|
|
172
|
+
const tags = new SourceTagsT(str(t.providerId), str(t.sourceName), str(t.batchId), str(t.sourceUrl), str(t.contentKeyId), str(t.sourcePeer), str(t.license), str(t.licenseUrl), str(t.citation), !!t.shareAlike);
|
|
173
|
+
const p = r.provenance;
|
|
174
|
+
const provenance = p
|
|
175
|
+
? new ProvenanceT(str(p.sourceUrl), p.httpStatus | 0, str(p.etag), str(p.lastModified), str(p.contentType), big(p.retrievedMs), str(p.parser), str(p.parserVersion),
|
|
176
|
+
str(p.sourceSha256), str(p.normalizedSha256), big(p.normalizedCount), Object.keys(p.schemaCounts || {}), Object.values(p.schemaCounts || {}).map(big), (p.warnings || []).map(String), !!p.fromCache)
|
|
177
|
+
: null;
|
|
178
|
+
const reconcile = RECONCILE[r.reconcile || "duplicates"];
|
|
179
|
+
if (reconcile === undefined) throw new Error(`IngestRequest: unknown reconcile ${r.reconcile}`);
|
|
180
|
+
return finish(
|
|
181
|
+
new IngestRequestT(String(r.schema), tags, reconcile, r.archive ? new ArchiveTargetT(str(r.archive.source), str(r.archive.name)) : null, provenance),
|
|
182
|
+
IngestRequest.finishIngestRequestBuffer,
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
export function decodeIngestRequest(bytes) {
|
|
186
|
+
const r = rootOf(bytes, IngestRequest, IngestRequest.getRootAsIngestRequest, "INGQ");
|
|
187
|
+
const t = r.TAGS, p = r.PROVENANCE;
|
|
188
|
+
return {
|
|
189
|
+
schema: r.SCHEMA,
|
|
190
|
+
tags: { providerId: t.PROVIDER_ID || "", sourceName: t.SOURCE_NAME || "", batchId: t.BATCH_ID || "", sourceUrl: t.SOURCE_URL || "", contentKeyId: t.CONTENT_KEY_ID || "",
|
|
191
|
+
sourcePeer: t.SOURCE_PEER || "", license: t.LICENSE || "", licenseUrl: t.LICENSE_URL || "", citation: t.CITATION || "", shareAlike: t.SHARE_ALIKE },
|
|
192
|
+
reconcile: RECONCILE_NAME[r.RECONCILE],
|
|
193
|
+
archive: r.ARCHIVE ? { source: r.ARCHIVE.SOURCE || "", name: r.ARCHIVE.NAME || "" } : null,
|
|
194
|
+
provenance: p
|
|
195
|
+
? { sourceUrl: p.SOURCE_URL || "", httpStatus: p.HTTP_STATUS, etag: p.ETAG || "", lastModified: p.LAST_MODIFIED || "", contentType: p.CONTENT_TYPE || "", retrievedMs: num(p.RETRIEVED_MS),
|
|
196
|
+
parser: p.PARSER || "", parserVersion: p.PARSER_VERSION || "", sourceSha256: p.SOURCE_SHA256 || "", normalizedSha256: p.NORMALIZED_SHA256 || "", normalizedCount: num(p.NORMALIZED_COUNT),
|
|
197
|
+
schemaCounts: Object.fromEntries((p.SCHEMAS || []).map((s, i) => [s, num(p.SCHEMA_COUNTS[i])])), warnings: (p.WARNINGS || []).slice(), fromCache: p.FROM_CACHE }
|
|
198
|
+
: null,
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
/** @param {{schema?:string, providerId?:string, sourceName?:string, batchId?:string, inserted?:number, reconciledDuplicates?:number, reconciledOldBatches?:number, archived?:string, refused?:string}} r */
|
|
202
|
+
export function encodeIngestResult(r = {}) {
|
|
203
|
+
return finish(
|
|
204
|
+
new IngestResultT(str(r.schema), str(r.providerId), str(r.sourceName), str(r.batchId), big(r.inserted), big(r.reconciledDuplicates), big(r.reconciledOldBatches), str(r.archived), str(r.refused)),
|
|
205
|
+
IngestResult.finishIngestResultBuffer,
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
export function decodeIngestResult(bytes) {
|
|
209
|
+
const r = rootOf(bytes, IngestResult, IngestResult.getRootAsIngestResult, "INGR");
|
|
210
|
+
return { schema: r.SCHEMA || "", providerId: r.PROVIDER_ID || "", sourceName: r.SOURCE_NAME || "", batchId: r.BATCH_ID || "", inserted: num(r.INSERTED),
|
|
211
|
+
reconciledDuplicates: num(r.RECONCILED_DUPLICATES), reconciledOldBatches: num(r.RECONCILED_OLD_BATCHES), archived: r.ARCHIVED || "", refused: r.REFUSED || "" };
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// ---- FlowNotice -------------------------------------------------------------------------------------------------
|
|
215
|
+
|
|
216
|
+
const NOTICE = { unchanged: flowNoticeKind.Unchanged, skipped: flowNoticeKind.Skipped, missing: flowNoticeKind.Missing, expired: flowNoticeKind.Expired, info: flowNoticeKind.Info };
|
|
217
|
+
const NOTICE_NAME = Object.fromEntries(Object.entries(NOTICE).map(([k, v]) => [v, k]));
|
|
218
|
+
|
|
219
|
+
/** @param {{kind:"unchanged"|"skipped"|"missing"|"expired"|"info", schema?:string, providerId?:string, sourceName?:string, batchId?:string, count?:number, reason?:string, items?:string[], atMs?:number}} n */
|
|
220
|
+
export function encodeFlowNotice(n) {
|
|
221
|
+
const kind = NOTICE[n?.kind];
|
|
222
|
+
if (kind === undefined) throw new Error(`FlowNotice: unknown kind ${n?.kind}`);
|
|
223
|
+
return finish(
|
|
224
|
+
new FlowNoticeT(kind, str(n.schema), str(n.providerId), str(n.sourceName), str(n.batchId), big(n.count), str(n.reason), (n.items || []).map(String), big(n.atMs)),
|
|
225
|
+
FlowNotice.finishFlowNoticeBuffer,
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
export function decodeFlowNotice(bytes) {
|
|
229
|
+
const n = rootOf(bytes, FlowNotice, FlowNotice.getRootAsFlowNotice, "FNTC");
|
|
230
|
+
return { kind: NOTICE_NAME[n.KIND], schema: n.SCHEMA || "", providerId: n.PROVIDER_ID || "", sourceName: n.SOURCE_NAME || "", batchId: n.BATCH_ID || "",
|
|
231
|
+
count: num(n.COUNT), reason: n.REASON || "", items: (n.ITEMS || []).slice(), atMs: num(n.AT_MS) };
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// ---- hostcalls: SDS $PIV in the module -> host direction, aligned-binary records + raw frames ---------------------
|
|
235
|
+
|
|
236
|
+
/** The schema a hostcall record frame's TAB.TYPE_REF names (schemas/runtime/HostOps.fbs, aligned layout). */
|
|
237
|
+
export const HOST_OPS_SCHEMA = "HostOps.fbs";
|
|
238
|
+
|
|
239
|
+
function recordClass(type) {
|
|
240
|
+
const Class = hostOps[type];
|
|
241
|
+
if (typeof Class !== "function" || !Class.SIZE) throw new Error(`hostcall: ${type} is not a HostOps record`);
|
|
242
|
+
return Class;
|
|
243
|
+
}
|
|
244
|
+
// The generated aligned accessors: field FIELD_NAME is read by fIELD_NAME() and written by setFIELD_NAME(); strings,
|
|
245
|
+
// nested records and vectors carry a presence bit (hasX / setHasX); vectors are xLength / xAt.
|
|
246
|
+
const getterOf = (field) => field[0].toLowerCase() + field.slice(1);
|
|
247
|
+
function fieldsOf(Class) {
|
|
248
|
+
const names = Object.getOwnPropertyNames(Class.prototype);
|
|
249
|
+
return names.filter((n) => n.startsWith("set") && !n.startsWith("setHas") && !n.endsWith("Length") && !n.endsWith("At")).map((n) => n.slice(3))
|
|
250
|
+
.concat(names.filter((n) => n.startsWith("set") && n.endsWith("At") && !n.startsWith("setHas")).map((n) => n.slice(3, -2)));
|
|
251
|
+
}
|
|
252
|
+
function writeRecord(Class, view, value, where) {
|
|
253
|
+
for (const [field, v] of Object.entries(value || {})) {
|
|
254
|
+
if (v === undefined || v === null) continue;
|
|
255
|
+
const proto = Class.prototype, g = getterOf(field);
|
|
256
|
+
if (typeof proto[`set${field}At`] === "function") {
|
|
257
|
+
view[`set${field}Length`](v.length);
|
|
258
|
+
v.forEach((item, i) => view[`set${field}At`](i, item));
|
|
259
|
+
if (typeof proto[`setHas${field}`] === "function") view[`setHas${field}`](true);
|
|
260
|
+
if (view[`${g}Length`]() !== v.length) throw new RangeError(`${where}.${field}: ${v.length} items exceed the record's bound`);
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
if (typeof proto[`set${field}`] !== "function") {
|
|
264
|
+
// a nested record: written through its view
|
|
265
|
+
if (typeof proto[g] === "function" && typeof v === "object") {
|
|
266
|
+
const nested = view[g]();
|
|
267
|
+
writeRecord(nested.constructor, nested, v, `${where}.${field}`);
|
|
268
|
+
if (typeof proto[`setHas${field}`] === "function") view[`setHas${field}`](true);
|
|
269
|
+
continue;
|
|
270
|
+
}
|
|
271
|
+
throw new Error(`${where}: no field ${field}`);
|
|
272
|
+
}
|
|
273
|
+
if (typeof proto[`setHas${field}`] === "function") view[`setHas${field}`](true);
|
|
274
|
+
view[`set${field}`](typeof v === "number" && typeof view[g]() === "bigint" ? BigInt(v) : v);
|
|
275
|
+
// an aligned string holds a bounded number of bytes: refuse rather than truncate
|
|
276
|
+
if (typeof v === "string" && view[g]() !== v) throw new RangeError(`${where}.${field}: "${v.slice(0, 40)}..." exceeds the record's ${new TextEncoder().encode(view[g]()).length}-byte string`);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
function readRecord(Class, view) {
|
|
280
|
+
const out = {};
|
|
281
|
+
for (const field of fieldsOf(Class)) {
|
|
282
|
+
const g = getterOf(field);
|
|
283
|
+
if (typeof view[`has${field}`] === "function" && !view[`has${field}`]()) { out[field] = typeof view[`${g}Length`] === "function" ? [] : null; continue; }
|
|
284
|
+
if (typeof view[`${g}Length`] === "function") { out[field] = Array.from({ length: view[`${g}Length`]() }, (_, i) => view[`${g}At`](i)); continue; }
|
|
285
|
+
out[field] = view[g]();
|
|
286
|
+
}
|
|
287
|
+
for (const n of Object.getOwnPropertyNames(Class.prototype)) { // nested records (getter, presence, no setter)
|
|
288
|
+
if (n.startsWith("has") || n.startsWith("set") || n === "constructor") continue;
|
|
289
|
+
const field = n[0].toUpperCase() + n.slice(1);
|
|
290
|
+
if (field in out || typeof Class.prototype[`setHas${field}`] !== "function") continue;
|
|
291
|
+
out[field] = view[`has${field}`]() ? readRecord(view[n]().constructor, view[n]()) : null;
|
|
292
|
+
}
|
|
293
|
+
return out;
|
|
294
|
+
}
|
|
295
|
+
/** One aligned record of HostOps type `type` from plain field values (FIELD_NAME: value). */
|
|
296
|
+
export function encodeHostOpsRecord(type, value) {
|
|
297
|
+
const Class = recordClass(type), bytes = new Uint8Array(Class.SIZE);
|
|
298
|
+
writeRecord(Class, Class.fromPointer(bytes.buffer, 0), value, type);
|
|
299
|
+
return bytes;
|
|
300
|
+
}
|
|
301
|
+
/** A run of aligned records (a list port), back to back at the type's stride. */
|
|
302
|
+
export function encodeHostOpsList(type, values) {
|
|
303
|
+
const Class = recordClass(type), bytes = new Uint8Array(Class.SIZE * values.length);
|
|
304
|
+
values.forEach((v, i) => writeRecord(Class, Class.fromPointer(bytes.buffer, i * Class.SIZE), v, `${type}[${i}]`));
|
|
305
|
+
return bytes;
|
|
306
|
+
}
|
|
307
|
+
function readFrames(frames, where) {
|
|
308
|
+
const records = {}, lists = {}, raw = {};
|
|
309
|
+
for (const frame of frames || []) {
|
|
310
|
+
const port = frame.portId ?? frame.PORT_ID, tr = frame.typeRef || {}, type = tr.rootType ?? tr.rootTypeName ?? tr.ROOT_TYPE ?? null;
|
|
311
|
+
const payload = frame.payload instanceof Uint8Array ? frame.payload : new Uint8Array(frame.payload || []);
|
|
312
|
+
if ((frame.wireFormat ?? tr.wireFormat) === "aligned-binary" && type) {
|
|
313
|
+
const Class = recordClass(type), copy = payload.slice(); // (a copy: the decoded views outlive the envelope)
|
|
314
|
+
if (copy.length % Class.SIZE) throw new RangeError(`${where}: ${port} is ${copy.length} bytes, not a whole number of ${type} (${Class.SIZE})`);
|
|
315
|
+
const items = Array.from({ length: copy.length / Class.SIZE }, (_, i) => readRecord(Class, Class.fromPointer(copy.buffer, i * Class.SIZE)));
|
|
316
|
+
if (Number(tr.byteLength ?? 0) > 0) records[port] = { type, value: items[0] ?? null }; else lists[port] = { type, values: items };
|
|
317
|
+
} else raw[port] = payload.slice();
|
|
318
|
+
}
|
|
319
|
+
return { records, lists, raw };
|
|
320
|
+
}
|
|
321
|
+
const toBytes = (v) => (typeof v === "string" ? new TextEncoder().encode(v) : v instanceof Uint8Array ? v : new Uint8Array(v));
|
|
322
|
+
function buildFrames(spec, { record, recordPort, recordType, raw = {}, lists = {} }, rawPorts, listPorts, where) {
|
|
323
|
+
const frames = [];
|
|
324
|
+
if (record != null) {
|
|
325
|
+
if (!recordType) throw new Error(`${where}: takes no ${recordPort} record`);
|
|
326
|
+
const Class = recordClass(recordType);
|
|
327
|
+
frames.push({ portId: recordPort, wireFormat: "aligned-binary", typeRef: { schemaName: HOST_OPS_SCHEMA, rootType: recordType, wireFormat: "aligned-binary", byteLength: Class.SIZE, requiredAlignment: Class.ALIGN }, payload: encodeHostOpsRecord(recordType, record) });
|
|
328
|
+
}
|
|
329
|
+
for (const [port, values] of Object.entries(lists)) {
|
|
330
|
+
const type = listPorts[port];
|
|
331
|
+
if (!type) throw new Error(`${where}: no list port ${port}`);
|
|
332
|
+
const Class = recordClass(type);
|
|
333
|
+
frames.push({ portId: port, wireFormat: "aligned-binary", typeRef: { schemaName: HOST_OPS_SCHEMA, rootType: type, wireFormat: "aligned-binary", byteLength: 0, requiredAlignment: Class.ALIGN }, payload: encodeHostOpsList(type, values) });
|
|
334
|
+
}
|
|
335
|
+
for (const [port, bytes] of Object.entries(raw)) {
|
|
336
|
+
if (!rawPorts.includes(port)) throw new Error(`${where}: no raw port ${port}`);
|
|
337
|
+
frames.push({ portId: port, payload: toBytes(bytes) });
|
|
338
|
+
}
|
|
339
|
+
return frames;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* A module's call to its host: an SDS $PIV request. METHOD_ID is the operation; its frames are the "params" aligned
|
|
344
|
+
* record, its list ports (runs of aligned records) and its raw ports (bytes) as HOST_OPERATIONS declares them.
|
|
345
|
+
* @param {string} op
|
|
346
|
+
* @param {{params?:object, lists?:Record<string,object[]>, raw?:Record<string,Uint8Array|string>}} [call] field values
|
|
347
|
+
* by schema name (e.g. { params: { SCHEMA: "WXF.fbs", BEFORE_MS: 1791900000000n } })
|
|
348
|
+
*/
|
|
349
|
+
export function encodeHostCall(op, call = {}) {
|
|
350
|
+
const spec = HOST_OPERATIONS[op];
|
|
351
|
+
if (!spec) throw new Error(`hostcall: unknown operation ${op}`);
|
|
352
|
+
const inputs = buildFrames(spec, { record: call.params, recordPort: "params", recordType: spec.params, raw: call.raw, lists: call.lists }, spec.rawIn, spec.listsIn, op);
|
|
353
|
+
return encodePluginInvokeRequest({ methodId: op, inputs });
|
|
354
|
+
}
|
|
355
|
+
/** @returns {{op:string, params:object|null, lists:Record<string,object[]>, raw:Record<string,Uint8Array>}} */
|
|
356
|
+
export function decodeHostCall(bytes) {
|
|
357
|
+
const request = decodePluginInvokeRequest(bytes);
|
|
358
|
+
const op = request.methodId ?? "", { records, lists, raw } = readFrames(request.inputs, op);
|
|
359
|
+
const spec = HOST_OPERATIONS[op];
|
|
360
|
+
if (spec && records.params && records.params.type !== spec.params) throw new Error(`hostcall: ${op} takes ${spec.params}, the frame carries ${records.params.type}`);
|
|
361
|
+
return { op, params: records.params?.value ?? null, lists: Object.fromEntries(Object.entries(lists).map(([k, v]) => [k, v.values])), raw };
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/** The error codes a host answers with (PIVResponse.ERROR_CODE). */
|
|
365
|
+
export const HOSTCALL_ERROR_CODES = Object.freeze(["unsupported", "not-authorized", "invalid-params", "failed", "refused", "sandbox", "timeout", "too-large"]);
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* The host's answer: an SDS $PIV response - the "result" aligned record, list and raw ports (STATUS OK), or STATUS
|
|
369
|
+
* FAILED with ERROR_CODE (HOSTCALL_ERROR_CODES) and ERROR_MESSAGE.
|
|
370
|
+
* @param {{op:string, ok:boolean, result?:object, lists?:Record<string,object[]>, raw?:Record<string,Uint8Array|string>, error?:{code:string, message?:string}}} r
|
|
371
|
+
*/
|
|
372
|
+
export function encodeHostCallResult(r) {
|
|
373
|
+
if (r?.ok) {
|
|
374
|
+
const spec = HOST_OPERATIONS[r.op];
|
|
375
|
+
if (!spec) throw new Error(`hostcall: unknown operation ${r.op}`);
|
|
376
|
+
const outputs = buildFrames(spec, { record: r.result, recordPort: "result", recordType: spec.result, raw: r.raw, lists: r.lists }, spec.rawOut, spec.listsOut, `${r.op} result`);
|
|
377
|
+
return encodePluginInvokeResponse({ statusCode: 0, outputs });
|
|
378
|
+
}
|
|
379
|
+
const code = r?.error?.code ?? "failed";
|
|
380
|
+
if (!HOSTCALL_ERROR_CODES.includes(code)) throw new Error(`hostcall: unknown error code ${code}`);
|
|
381
|
+
return encodePluginInvokeResponse({ statusCode: 1, status: "FAILED", errorCode: code, errorMessage: str(r?.error?.message) });
|
|
382
|
+
}
|
|
383
|
+
/** @returns {{ok:boolean, result:object|null, lists:Record<string,object[]>, raw:Record<string,Uint8Array>, error:{code:string, message:string}|null}} */
|
|
384
|
+
export function decodeHostCallResult(bytes) {
|
|
385
|
+
const response = decodePluginInvokeResponse(bytes);
|
|
386
|
+
if (response.errorCode || (response.status !== undefined && response.status !== 0 && response.status !== "OK")) {
|
|
387
|
+
return { ok: false, result: null, lists: {}, raw: {}, error: { code: response.errorCode || "failed", message: response.errorMessage || "" } };
|
|
388
|
+
}
|
|
389
|
+
const { records, lists, raw } = readFrames(response.outputs, "hostcall result");
|
|
390
|
+
return { ok: true, result: records.result?.value ?? null, lists: Object.fromEntries(Object.entries(lists).map(([k, v]) => [k, v.values])), raw, error: null };
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* Whether a hostcall payload is the typed one (an SDS $PIV request) rather than the JSON-meta envelope of
|
|
395
|
+
* src/host/hostcallWire.js: while hosts move over they answer a $PIV call with a $PIV response. The JSON envelope goes
|
|
396
|
+
* once every module is typed (graph: sdk-compliance-typed-only-20261013).
|
|
397
|
+
*/
|
|
398
|
+
export function isTypedHostCall(payload) {
|
|
399
|
+
return identifierOf(payload) === "$PIV";
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
// ---- the operations ---------------------------------------------------------------------------------------------------
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* Every host operation a module can call, under the names the hosts serve today (the Go node's and the SDK JS hosts'),
|
|
406
|
+
* with its frames: the "params" / "result" aligned record types (HostOps.fbs; null: none), raw ports (bytes) and list
|
|
407
|
+
* ports (runs of aligned records), and the capability it needs (null: none).
|
|
408
|
+
*/
|
|
409
|
+
const op = (params, result, capability, frames = {}) => Object.freeze({
|
|
410
|
+
params, result, capability,
|
|
411
|
+
rawIn: Object.freeze(frames.rawIn || []), rawOut: Object.freeze(frames.rawOut || []),
|
|
412
|
+
listsIn: Object.freeze(frames.listsIn || {}), listsOut: Object.freeze(frames.listsOut || {}),
|
|
413
|
+
});
|
|
414
|
+
const CRYPTO_IN = ["data", "key", "private_key", "public_key", "signature", "nonce", "aad", "ikm", "salt", "info", "envelope"];
|
|
415
|
+
const CRYPTO_OUT = ["data", "nonce", "private_key", "public_key"];
|
|
416
|
+
const crypto = (result, capability) => op("CryptoParams", result, capability, { rawIn: CRYPTO_IN, rawOut: CRYPTO_OUT });
|
|
417
|
+
const STREAM = { rawOut: ["stream"] };
|
|
418
|
+
const SQL_IN = { rawIn: ["sql"], listsIn: { sql_params: "SqlValue" } };
|
|
419
|
+
export const HOST_OPERATIONS = Object.freeze({
|
|
420
|
+
// host, clock, random, node, config
|
|
421
|
+
"host.runtimeTarget": op(null, null, null, { rawOut: ["value"] }),
|
|
422
|
+
"host.listCapabilities": op(null, null, null, { listsOut: { items: "TextValue" } }),
|
|
423
|
+
"host.listSupportedCapabilities": op(null, null, null, { listsOut: { items: "TextValue" } }),
|
|
424
|
+
"host.listOperations": op(null, null, null, { listsOut: { items: "TextValue" } }),
|
|
425
|
+
"host.hasCapability": op("HasCapabilityParams", "BoolValue", null),
|
|
426
|
+
"clock.now": op(null, "TimeValue", "clock"),
|
|
427
|
+
"clock.nowIso": op(null, null, "clock", { rawOut: ["value"] }),
|
|
428
|
+
"clock.monotonicNow": op(null, "NumberValue", "clock"),
|
|
429
|
+
"random.bytes": op("RandomBytesParams", null, "random", { rawOut: ["data"] }),
|
|
430
|
+
"node.publicKey": op(null, null, null, { rawOut: ["value"] }),
|
|
431
|
+
"node.peerId": op(null, null, null, { rawOut: ["value"] }),
|
|
432
|
+
"plugin.getConfig": op(null, null, null, { listsOut: { entries: "ConfigEntry" } }),
|
|
433
|
+
// network
|
|
434
|
+
"http.request": op("HttpParams", "HttpResult", "http", { rawIn: ["url", "headers", "body"], rawOut: ["url", "headers", "body"] }),
|
|
435
|
+
"websocket.exchange": op("WebsocketParams", "WebsocketResult", "websocket", { rawIn: ["url", "protocols", "message"], rawOut: ["url", "body"] }),
|
|
436
|
+
"mqtt.publish": op("MqttParams", "MqttResult", "mqtt", { rawIn: ["payload", "password"] }),
|
|
437
|
+
"mqtt.subscribeOnce": op("MqttParams", "MqttResult", "mqtt", { rawIn: ["password"], rawOut: ["body"] }),
|
|
438
|
+
"tcp.request": op("SocketParams", "SocketResult", "tcp", { rawIn: ["data"], rawOut: ["body"] }),
|
|
439
|
+
"udp.request": op("SocketParams", "SocketResult", "udp", { rawIn: ["data"], rawOut: ["body"] }),
|
|
440
|
+
"tls.request": op("SocketParams", "SocketResult", "tls", { rawIn: ["data", "ca", "cert", "key"], rawOut: ["body"] }),
|
|
441
|
+
// storage
|
|
442
|
+
"storage.query": op("StorageQueryParams", null, "storage_query", { listsOut: { records_meta: "StoredRecordMeta" }, rawOut: ["records"] }),
|
|
443
|
+
"storage.write": op("StorageWriteParams", "StorageWriteResult", "storage_write", { rawIn: ["data"] }),
|
|
444
|
+
"storage.delete": op("StorageDeleteParams", null, "storage_write"),
|
|
445
|
+
"storage.expire": op("StorageExpireParams", "StorageExpireResult", "storage_write"),
|
|
446
|
+
"storage.ingest_with_source": op("StorageIngestParams", "StorageIngestResult", "storage_ingest", { rawIn: ["records", "archive"], listsIn: { provenance: "Provenance" } }),
|
|
447
|
+
"storage.flatsql_query_stream": op("SqlStreamParams", "StreamResult", "storage_query", { ...SQL_IN, ...STREAM }),
|
|
448
|
+
"storage.flatsql_epoch_stream": op("EpochStreamParams", "StreamResult", "storage_query", STREAM),
|
|
449
|
+
"storage.query_sandboxed": op("SandboxQueryParams", "SandboxQueryResult", "storage_query", { ...SQL_IN, rawOut: ["stream"], listsOut: { columns: "TextValue", cells: "SqlValue" } }),
|
|
450
|
+
"storage.query_surface": op(null, "QuerySurfaceLimits", "storage_query", { listsOut: { tables: "SurfaceTable", columns: "SurfaceColumn" } }),
|
|
451
|
+
"storage.flatsql_cache_key": op("CacheKeyParams", null, "storage_query", { ...SQL_IN, listsIn: { ...SQL_IN.listsIn, projection: "TextValue" }, rawOut: ["value"] }),
|
|
452
|
+
// crypto: the node's operations
|
|
453
|
+
"crypto.hash": crypto(null, "crypto_hash"),
|
|
454
|
+
"crypto.sign": crypto(null, "crypto_sign"),
|
|
455
|
+
"crypto.verify": crypto("BoolValue", "crypto_verify"),
|
|
456
|
+
"crypto.encrypt": crypto(null, "crypto_encrypt"),
|
|
457
|
+
"crypto.decrypt": crypto(null, "crypto_decrypt"),
|
|
458
|
+
"crypto.key_agreement": crypto(null, "crypto_key_agreement"),
|
|
459
|
+
"crypto.kdf": crypto(null, "crypto_kdf"),
|
|
460
|
+
"crypto.generate_key": crypto(null, "crypto_sign"),
|
|
461
|
+
"crypto.random": crypto(null, "crypto_hash"),
|
|
462
|
+
// crypto: both hosts
|
|
463
|
+
"crypto.ed25519.publicKeyFromSeed": crypto(null, "crypto_sign"),
|
|
464
|
+
"crypto.ed25519.sign": crypto(null, "crypto_sign"),
|
|
465
|
+
"crypto.ed25519.verify": crypto("BoolValue", "crypto_verify"),
|
|
466
|
+
"crypto.secp256k1.publicKeyFromPrivate": crypto(null, "crypto_sign"),
|
|
467
|
+
"crypto.secp256k1.sign": crypto(null, "crypto_sign"),
|
|
468
|
+
"crypto.secp256k1.verify": crypto("BoolValue", "crypto_verify"),
|
|
469
|
+
// crypto: the JS hosts' operations
|
|
470
|
+
"crypto.sha256": crypto(null, "crypto_hash"),
|
|
471
|
+
"crypto.sha512": crypto(null, "crypto_hash"),
|
|
472
|
+
"crypto.hkdf": crypto(null, "crypto_kdf"),
|
|
473
|
+
"crypto.aesGcmEncrypt": crypto(null, "crypto_encrypt"),
|
|
474
|
+
"crypto.aesGcmDecrypt": crypto(null, "crypto_decrypt"),
|
|
475
|
+
"crypto.x25519.generateKeypair": crypto(null, "crypto_key_agreement"),
|
|
476
|
+
"crypto.x25519.publicKey": crypto(null, "crypto_key_agreement"),
|
|
477
|
+
"crypto.x25519.sharedSecret": crypto(null, "crypto_key_agreement"),
|
|
478
|
+
"crypto.sealedBox.encryptForRecipient": crypto(null, "crypto_encrypt"),
|
|
479
|
+
"crypto.sealedBox.decryptFromEnvelope": crypto(null, "crypto_decrypt"),
|
|
480
|
+
"crypto.secp256k1.signDigest": crypto(null, "crypto_sign"),
|
|
481
|
+
"crypto.secp256k1.verifyDigest": crypto("BoolValue", "crypto_verify"),
|
|
482
|
+
// keyslot, secrets
|
|
483
|
+
"keyslot.sign": op("KeyslotParams", null, "wallet_sign", { rawIn: ["payload"], rawOut: ["data"] }),
|
|
484
|
+
"keyslot.unwrap": op("KeyslotParams", null, "wallet_sign", { rawIn: ["ephemeral_public_key", "nonce", "ciphertext"], rawOut: ["data"] }),
|
|
485
|
+
"secrets.get": op("SecretParams", "SecretResult", "secrets", { rawOut: ["secret"] }),
|
|
486
|
+
"secrets.status": op("SecretParams", "SecretResult", "secrets"),
|
|
487
|
+
"secrets.put": op("SecretParams", "SecretResult", "secrets", { rawIn: ["secret"] }),
|
|
488
|
+
"secrets.clear": op("SecretParams", null, "secrets"),
|
|
489
|
+
// ipfs, pubsub, protocol, p2p, node status
|
|
490
|
+
"ipfs.add": op("IpfsParams", "IpfsResult", "ipfs", { rawIn: ["data"] }),
|
|
491
|
+
"ipfs.cat": op("IpfsParams", null, "ipfs", { rawOut: ["data"] }),
|
|
492
|
+
"ipfs.ls": op("IpfsParams", null, "ipfs", { listsOut: { links: "IpfsLink" } }),
|
|
493
|
+
"ipfs.pin_add": op("IpfsParams", null, "ipfs", { listsOut: { items: "TextValue" } }),
|
|
494
|
+
"ipfs.pin_rm": op("IpfsParams", null, "ipfs", { listsOut: { items: "TextValue" } }),
|
|
495
|
+
"ipfs.pin_ls": op("IpfsParams", null, "ipfs", { listsOut: { pins: "IpfsPin" } }),
|
|
496
|
+
"ipfs.dag_get": op("IpfsParams", null, "ipfs", { rawOut: ["data"] }),
|
|
497
|
+
"ipfs.name_resolve": op("IpfsParams", "IpfsResult", "ipfs"),
|
|
498
|
+
"ipfs.name_publish": op("IpfsParams", "IpfsResult", "ipfs"),
|
|
499
|
+
"ipfs.id": op(null, "IpfsResult", "ipfs", { listsOut: { addresses: "TextValue" } }),
|
|
500
|
+
"ipfs.swarm_peers": op(null, null, "ipfs", { listsOut: { peers: "IpfsSwarmPeer" } }),
|
|
501
|
+
"ipfs.pubsub_publish": op("PubsubParams", null, "ipfs", { rawIn: ["data"] }),
|
|
502
|
+
"pubsub.publish": op("PubsubParams", null, "pubsub", { rawIn: ["data"] }),
|
|
503
|
+
"pubsub.subscribe": op("PubsubParams", "PubsubSubscribed", "pubsub"),
|
|
504
|
+
"pubsub.unsubscribe": op("PubsubParams", null, "pubsub"),
|
|
505
|
+
"pubsub.list_topics": op(null, null, "pubsub", { listsOut: { items: "TextValue" } }),
|
|
506
|
+
"protocol.request": op("ProtocolParams", null, "protocol_dial", { rawIn: ["payload"], rawOut: ["data"] }),
|
|
507
|
+
"protocol_dial.dial": op("ProtocolParams", null, "protocol_dial"),
|
|
508
|
+
"protocol_handle.register": op("ProtocolParams", null, "protocol_handle"),
|
|
509
|
+
"protocol_handle.unregister": op("ProtocolParams", null, "protocol_handle"),
|
|
510
|
+
"p2p.peers_snapshot": op("P2pParams", "P2pSummary", "p2p_read", { listsOut: { peers: "P2pPeer", peer_addresses: "P2pPeerValue", peer_standards: "P2pPeerValue" }, rawOut: ["records"] }),
|
|
511
|
+
"p2p.standards_snapshot": op("P2pParams", null, "p2p_read", { listsOut: { entries: "P2pPnmEntry" }, rawOut: ["records"] }),
|
|
512
|
+
"p2p.pnm_history": op("P2pParams", "P2pSummary", "p2p_read", { listsOut: { entries: "P2pPnmEntry" }, rawOut: ["records"] }),
|
|
513
|
+
"p2p.latest_dataset": op("P2pParams", "P2pLatestDataset", "p2p_read", { rawOut: ["stream"] }),
|
|
514
|
+
"node_status_read.status": op(null, "NodeStatusReport", "node_status_read", { listsOut: { bandwidth_history: "NodeBandwidthSample" } }),
|
|
515
|
+
"node_activity_read.activity": op("NodeActivityParams", null, "node_activity_read", { listsOut: { events: "NodeActivityEvent" } }),
|
|
516
|
+
// the JS hosts' timers, schedule, filesystem, exec, context
|
|
517
|
+
"timers.delay": op("TimersDelayParams", null, "timers"),
|
|
518
|
+
"schedule.parse": op("ScheduleParams", null, "schedule_cron", { listsOut: { fields: "CronField" } }),
|
|
519
|
+
"schedule.matches": op("ScheduleParams", "BoolValue", "schedule_cron"),
|
|
520
|
+
"schedule.next": op("ScheduleParams", "TimeValue", "schedule_cron"),
|
|
521
|
+
"filesystem.resolvePath": op(null, null, "filesystem", { rawIn: ["path"], rawOut: ["path"] }),
|
|
522
|
+
"filesystem.readFile": op(null, null, "filesystem", { rawIn: ["path"], rawOut: ["data"] }),
|
|
523
|
+
"filesystem.writeFile": op(null, null, "filesystem", { rawIn: ["path", "data"] }),
|
|
524
|
+
"filesystem.appendFile": op(null, null, "filesystem", { rawIn: ["path", "data"] }),
|
|
525
|
+
"filesystem.deleteFile": op(null, null, "filesystem", { rawIn: ["path"] }),
|
|
526
|
+
"filesystem.mkdir": op("FsParams", null, "filesystem", { rawIn: ["path"] }),
|
|
527
|
+
"filesystem.readdir": op(null, null, "filesystem", { rawIn: ["path"], listsOut: { entries: "FsEntry" } }),
|
|
528
|
+
"filesystem.stat": op(null, "FsStat", "filesystem", { rawIn: ["path"], rawOut: ["path"] }),
|
|
529
|
+
"filesystem.rename": op(null, null, "filesystem", { rawIn: ["path", "to_path"] }),
|
|
530
|
+
"exec.execFile": op("ExecParams", "ExecResult", "process_exec", { rawIn: ["file", "cwd", "input"], listsIn: { args: "TextValue", env: "EnvVar" }, rawOut: ["stdout", "stderr"] }),
|
|
531
|
+
"context.get": op("ContextParams", "BoolValue", "context_read", { rawOut: ["value"] }),
|
|
532
|
+
"context.listKeys": op("ContextParams", null, "context_read", { listsOut: { items: "TextValue" } }),
|
|
533
|
+
"context.listScopes": op(null, null, "context_read", { listsOut: { items: "TextValue" } }),
|
|
534
|
+
"context.set": op("ContextParams", null, "context_write", { rawIn: ["value"] }),
|
|
535
|
+
"context.delete": op("ContextParams", "BoolValue", "context_write"),
|
|
536
|
+
});
|
|
@@ -33,6 +33,33 @@ const sharedModuleCatalogEntries = [
|
|
|
33
33
|
fileIdentifier: "HRSP",
|
|
34
34
|
source: "shared-module-runtime",
|
|
35
35
|
},
|
|
36
|
+
// The rest of the module runtime contracts (schemas/runtime/*.fbs, typed-contracts 1.0, owner 2026-10-13:
|
|
37
|
+
// "flatbuffer SDS only"): TimerTick, HttpRequest and HttpResponse above gain their IDL there; these complete the
|
|
38
|
+
// set - node config, the storage-ingest connector's request and result, and a pass's notice to the flow runtime.
|
|
39
|
+
{
|
|
40
|
+
schemaCode: "MODULECONFIG",
|
|
41
|
+
schemaName: "ModuleConfig.fbs",
|
|
42
|
+
fileIdentifier: "MCFG",
|
|
43
|
+
source: "shared-module-runtime",
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
schemaCode: "INGESTREQUEST",
|
|
47
|
+
schemaName: "IngestRequest.fbs",
|
|
48
|
+
fileIdentifier: "INGQ",
|
|
49
|
+
source: "shared-module-runtime",
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
schemaCode: "INGESTRESULT",
|
|
53
|
+
schemaName: "IngestResult.fbs",
|
|
54
|
+
fileIdentifier: "INGR",
|
|
55
|
+
source: "shared-module-runtime",
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
schemaCode: "FLOWNOTICE",
|
|
59
|
+
schemaName: "FlowNotice.fbs",
|
|
60
|
+
fileIdentifier: "FNTC",
|
|
61
|
+
source: "shared-module-runtime",
|
|
62
|
+
},
|
|
36
63
|
{
|
|
37
64
|
schemaCode: "DETACHEDSIGNATURE",
|
|
38
65
|
schemaName: "DetachedSignature.fbs",
|