space-data-module-sdk 0.9.9 → 0.9.12
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 +3 -3
- package/docs/assets/vendor/hd-wallet-ui/2.2.1/sdn-wallet-callback.0f2dee485c8f0d7afe5f70b4b42093a382c92d32af551bd71b41733336091c7a.js +1 -0
- package/docs/assets/vendor/hd-wallet-ui/2.2.1/sdn-wallet-public-client.9ab041131df957fcb6ef7e3d87bf9d19fe313bc5d7f1e53337752faf0ba354da.js +1 -0
- package/docs/assets/vendor/hd-wallet-ui/2.2.1/sdn-wallet-public-client.c3f68d1cfd88478f10d836a5e829d1dfc6a10157972cf0f7d4d319d0636f2cc4.css +32 -0
- package/docs/assets/vendor/sdn-stack-nav/1.0.1/sdn-stack-nav.24eb3001afc5448a90cef87e53bb4e599c0ae4dc9e14bafb6d1236e0233c6008.js +283 -0
- package/docs/assets/vendor/sdn-stack-nav/1.0.1/sdn-stack-nav.36a36359ce18322185e9ff179f88175bab67d5ad84a14d9c08a54f2ff27267e7.css +118 -0
- package/docs/browser-wasmedge-isomorphic.html +3 -3
- package/docs/byo-wasm-quickstart.html +3 -3
- package/docs/conformance.html +3 -3
- package/docs/events-abi.html +3 -3
- package/docs/families/analytics.html +3 -3
- package/docs/families/attitude.html +3 -3
- package/docs/families/behavior.html +3 -3
- package/docs/families/breakup.html +3 -3
- package/docs/families/conjunction.html +3 -3
- package/docs/families/data-source.html +3 -3
- package/docs/families/effects.html +3 -3
- package/docs/families/environment.html +3 -3
- package/docs/families/estimation.html +3 -3
- package/docs/families/gnc.html +3 -3
- package/docs/families/maneuver.html +3 -3
- package/docs/families/obstruction.html +3 -3
- package/docs/families/propagator.html +3 -3
- package/docs/families/propulsion.html +3 -3
- package/docs/families/reentry.html +3 -3
- package/docs/families/rf.html +3 -3
- package/docs/families/scheduler.html +3 -3
- package/docs/families/sensor.html +3 -3
- package/docs/families/signature.html +3 -3
- package/docs/flatsql-host-contract.html +3 -3
- package/docs/flatsql-streaming-standard.html +3 -3
- package/docs/gpu-module-abi.html +3 -3
- package/docs/index.html +3 -3
- package/docs/isomorphic-pthreads.html +3 -3
- package/docs/isomorphic-sdn-runtime-plan.html +3 -3
- package/docs/language-runtime-matrix.html +3 -3
- package/docs/module-bundle-runtime-plan.html +3 -3
- package/docs/module-publication-standard.html +3 -3
- package/docs/node-red-default-node-parity.html +3 -3
- package/docs/protect-and-sign.html +3 -3
- package/docs/protocol-installation.html +3 -3
- package/docs/publication-submission.html +3 -3
- package/docs/secrets-capability.html +3 -3
- package/docs/testing-harness.html +3 -3
- package/docs/tri-runtime-parity-gate.html +3 -3
- package/docs/tri-runtime-parity.html +3 -3
- package/docs/wallet-callback.html +1 -1
- package/package.json +1 -1
- package/src/compiler/compileCache.js +495 -0
- package/src/compiler/compileModule.js +537 -509
- package/src/compiler/emceptionNode.js +127 -1
- package/src/compiler/guestLinkFiles.js +60 -0
- package/src/compiler/index.d.ts +7 -0
- package/src/compiler/index.js +7 -0
- package/src/compiler/wasmObjectSymbols.js +369 -0
- package/src/flow/flowCompiler.js +124 -4
- package/src/flow/flowRuntimeHost.js +2 -2
- package/src/host/abi.js +2 -3
- package/src/host/hostWorkerBundleSources.js +3 -3
- package/src/host/hostcallWire.js +3 -2
- package/src/host/providerAccess.js +2 -3
- package/src/host/typedDispatch.js +2 -2
- package/src/host/wasiShim.js +5 -1
- package/src/index.d.ts +93 -0
- package/src/runtime-host/flatsqlRuntimeStore.js +2 -2
- package/src/testing/isomorphicHarness.js +15 -1
- package/src/testing/parityGate.js +14 -9
- package/src/utils/guestText.js +12 -0
package/src/host/hostcallWire.js
CHANGED
|
@@ -18,7 +18,8 @@
|
|
|
18
18
|
* responses (meta = { ok, result } | { ok, error }).
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
import { decodeGuestText } from "../utils/guestText.js";
|
|
22
|
+
|
|
22
23
|
const textEncoder = new TextEncoder();
|
|
23
24
|
|
|
24
25
|
export const HOSTCALL_BINARY_REF_KEY = "$bin";
|
|
@@ -143,7 +144,7 @@ export function decodeHostcallEnvelope(bytes) {
|
|
|
143
144
|
throw new RangeError("Hostcall envelope meta exceeds envelope bounds.");
|
|
144
145
|
}
|
|
145
146
|
const meta = JSON.parse(
|
|
146
|
-
|
|
147
|
+
decodeGuestText(bytes.subarray(offset, offset + metaLength)),
|
|
147
148
|
);
|
|
148
149
|
offset += metaLength;
|
|
149
150
|
const segmentCount = view.getUint32(offset, true);
|
|
@@ -29,8 +29,7 @@ import {
|
|
|
29
29
|
providerErrorName,
|
|
30
30
|
providerSourceId,
|
|
31
31
|
} from "./providerAccessAbi.js";
|
|
32
|
-
|
|
33
|
-
const textDecoder = new TextDecoder();
|
|
32
|
+
import { decodeGuestText } from "../utils/guestText.js";
|
|
34
33
|
|
|
35
34
|
function isThenable(value) {
|
|
36
35
|
return value !== null && typeof value?.then === "function";
|
|
@@ -588,7 +587,7 @@ export function createProviderAccessBridge(options = {}) {
|
|
|
588
587
|
function acquire(reqPtr, reqLen, descPtr) {
|
|
589
588
|
try {
|
|
590
589
|
const request = JSON.parse(
|
|
591
|
-
|
|
590
|
+
decodeGuestText(guestView(getMemory, reqPtr, reqLen)),
|
|
592
591
|
);
|
|
593
592
|
// RASTER IN. A coverage field is 512x512 = 262,144 positions; encoding
|
|
594
593
|
// those as JSON would be a multi-megabyte request string parsed per
|
|
@@ -13,10 +13,10 @@ import {
|
|
|
13
13
|
import * as hostOps from "../generated/runtime/aligned/HostOps_aligned.js";
|
|
14
14
|
import { cryptoAlgorithm, deliverMode, reconcileKind, sandboxWant } from "../generated/runtime/aligned/HostOps_enums.js";
|
|
15
15
|
import { base64ToBytes, bytesToBase64 } from "../utils/encoding.js";
|
|
16
|
+
import { decodeGuestText } from "../utils/guestText.js";
|
|
16
17
|
|
|
17
|
-
const textDecoder = new TextDecoder();
|
|
18
18
|
const textEncoder = new TextEncoder();
|
|
19
|
-
const text = (bytes) => (bytes === undefined ? undefined :
|
|
19
|
+
const text = (bytes) => (bytes === undefined ? undefined : decodeGuestText(bytes));
|
|
20
20
|
const bytesOf = (value) => (value === undefined || value === null ? undefined : value instanceof Uint8Array ? value : typeof value === "string" ? textEncoder.encode(value) : new Uint8Array(value));
|
|
21
21
|
const items = (values) => (values || []).map((v) => ({ VALUE: String(v) }));
|
|
22
22
|
const unix = (value) => BigInt(Math.round(value instanceof Date ? value.getTime() : Number(value)));
|
package/src/host/wasiShim.js
CHANGED
|
@@ -278,7 +278,11 @@ export function createBrowserWasiShim(options = {}) {
|
|
|
278
278
|
if (!cryptoApi?.getRandomValues) {
|
|
279
279
|
return ERRNO_NOSYS;
|
|
280
280
|
}
|
|
281
|
-
|
|
281
|
+
// A browser refuses crypto.getRandomValues on a view of shared memory (a threads guest): fill a private
|
|
282
|
+
// buffer, then copy it into the guest.
|
|
283
|
+
const random = new Uint8Array(bufLen);
|
|
284
|
+
cryptoApi.getRandomValues(random);
|
|
285
|
+
mem8().set(random, bufPtr);
|
|
282
286
|
return ERRNO_SUCCESS;
|
|
283
287
|
}
|
|
284
288
|
|
package/src/index.d.ts
CHANGED
|
@@ -993,6 +993,8 @@ export interface CompilationResult {
|
|
|
993
993
|
tempDir: string | null;
|
|
994
994
|
wasmBytes: Uint8Array;
|
|
995
995
|
guestLink: GuestLinkArtifact | null;
|
|
996
|
+
/** Which compile steps the content cache answered. */
|
|
997
|
+
compileCache?: CompileCacheReport;
|
|
996
998
|
manifestWarnings: string[];
|
|
997
999
|
report: ComplianceReport;
|
|
998
1000
|
}
|
|
@@ -1005,6 +1007,8 @@ export interface GuestLinkArtifact {
|
|
|
1005
1007
|
threadModel: ModuleThreadModelName;
|
|
1006
1008
|
capabilities: string[];
|
|
1007
1009
|
objectBytes: Uint8Array;
|
|
1010
|
+
/** Present when the compile linked `libraries`. */
|
|
1011
|
+
libraries?: GuestLinkLibrary[];
|
|
1008
1012
|
}
|
|
1009
1013
|
|
|
1010
1014
|
/**
|
|
@@ -1081,12 +1085,101 @@ export function compileModuleFromSource(options: {
|
|
|
1081
1085
|
guestLinkCapabilities?: string[];
|
|
1082
1086
|
catalog?: StandardsEntry[];
|
|
1083
1087
|
standardsRoot?: string;
|
|
1088
|
+
/**
|
|
1089
|
+
* The content-addressed compile cache. Default on, at
|
|
1090
|
+
* SPACE_DATA_MODULE_SDK_CACHE_DIR, else $XDG_CACHE_HOME/space-data-module-sdk,
|
|
1091
|
+
* else ~/.cache/space-data-module-sdk. `false` (or the environment
|
|
1092
|
+
* SPACE_DATA_MODULE_SDK_COMPILE_CACHE=0) compiles everything; `{ dir }`
|
|
1093
|
+
* names another cache directory.
|
|
1094
|
+
*/
|
|
1095
|
+
compileCache?: boolean | { dir?: string };
|
|
1096
|
+
/**
|
|
1097
|
+
* Shared libraries compiled once into their own objects and linked by the
|
|
1098
|
+
* module (and once per flow): see GuestLinkLibrary. The module source
|
|
1099
|
+
* declares their functions; the library sources define them.
|
|
1100
|
+
*/
|
|
1101
|
+
libraries?: ModuleLibrarySource[];
|
|
1084
1102
|
}): Promise<CompilationResult>;
|
|
1085
1103
|
|
|
1104
|
+
export interface ModuleLibrarySource {
|
|
1105
|
+
/** Letters, digits, '.', '_', '-'; starts with a letter. */
|
|
1106
|
+
name: string;
|
|
1107
|
+
/** Letters, digits, '.', '_', '-' (e.g. "3.1.2", "vallado-2020"). */
|
|
1108
|
+
version: string;
|
|
1109
|
+
sourceCode: string;
|
|
1110
|
+
/** Default "c". */
|
|
1111
|
+
language?: "c" | "c++";
|
|
1112
|
+
/** NAME or NAME=VALUE, for this library's compile only. */
|
|
1113
|
+
defines?: string[];
|
|
1114
|
+
}
|
|
1115
|
+
|
|
1116
|
+
/**
|
|
1117
|
+
* A shared library object. Its strong global symbols are renamed into
|
|
1118
|
+
* `namespace` (sdm_lib_<name>_<version>_<digest>_, the digest covering its
|
|
1119
|
+
* source, defines, flags and toolchain kind); the module object's references
|
|
1120
|
+
* follow. A flow links each namespace once.
|
|
1121
|
+
*/
|
|
1122
|
+
export interface GuestLinkLibrary {
|
|
1123
|
+
name: string;
|
|
1124
|
+
version: string;
|
|
1125
|
+
language: "c" | "c++";
|
|
1126
|
+
namespace: string;
|
|
1127
|
+
sha256: string;
|
|
1128
|
+
objectBytes: Uint8Array;
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1131
|
+
/**
|
|
1132
|
+
* Write a compilation's guest-link files into `dir` (dist/guest-link):
|
|
1133
|
+
* module-link.o, libraries/<name>-<version>-<sha12>.o and metadata.json
|
|
1134
|
+
* (version 1 without libraries, 2 with a `libraries` list). `metadata` adds
|
|
1135
|
+
* fields to metadata.json.
|
|
1136
|
+
*/
|
|
1137
|
+
export function writeGuestLinkFiles(
|
|
1138
|
+
compilation: CompilationResult,
|
|
1139
|
+
dir: string,
|
|
1140
|
+
metadata?: Record<string, unknown>,
|
|
1141
|
+
): Promise<Record<string, unknown>>;
|
|
1142
|
+
|
|
1143
|
+
export interface CompileCacheReport {
|
|
1144
|
+
enabled: boolean;
|
|
1145
|
+
dir: string | null;
|
|
1146
|
+
/** Steps answered from the cache: "module", "manifest", "invoke", "link". */
|
|
1147
|
+
hits: string[];
|
|
1148
|
+
/** Steps that ran the toolchain. */
|
|
1149
|
+
misses: string[];
|
|
1150
|
+
/** Wall time of each step that ran, in ms. */
|
|
1151
|
+
stepMs: Record<string, number>;
|
|
1152
|
+
}
|
|
1153
|
+
|
|
1154
|
+
export function pruneCompileCache(options?: {
|
|
1155
|
+
dir?: string;
|
|
1156
|
+
maxBytes?: number;
|
|
1157
|
+
}): Promise<{ removedEntries: number; removedBytes: number; keptBytes: number }>;
|
|
1158
|
+
|
|
1159
|
+
export function resolveCompileCacheRoot(dir?: string): string;
|
|
1160
|
+
|
|
1086
1161
|
export function cleanupCompilation(
|
|
1087
1162
|
result: CompilationResult,
|
|
1088
1163
|
): Promise<void>;
|
|
1089
1164
|
|
|
1165
|
+
/**
|
|
1166
|
+
* The guest-link object of a compiled module object (module.o): every strong,
|
|
1167
|
+
* global symbol it defines with a C identifier for a name, and every manifest
|
|
1168
|
+
* method id, renamed to `<symbolPrefix><name>` in the object's symbol table.
|
|
1169
|
+
* compileModuleFromSource derives `guestLink.objectBytes` this way from its one
|
|
1170
|
+
* module compile.
|
|
1171
|
+
*/
|
|
1172
|
+
export function deriveGuestLinkObject(options: {
|
|
1173
|
+
objectBytes: Uint8Array;
|
|
1174
|
+
pluginId: string;
|
|
1175
|
+
methodIds?: string[];
|
|
1176
|
+
}): {
|
|
1177
|
+
symbolPrefix: string;
|
|
1178
|
+
methodSymbols: Record<string, string>;
|
|
1179
|
+
renamedSymbols: string[];
|
|
1180
|
+
objectBytes: Uint8Array;
|
|
1181
|
+
};
|
|
1182
|
+
|
|
1090
1183
|
export function protectModuleArtifact(options: {
|
|
1091
1184
|
manifest: PluginManifest;
|
|
1092
1185
|
wasmBytes?: Uint8Array;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { DirectAccessor, FlatSQLDatabase } from "flatsql";
|
|
2
|
+
import { decodeGuestText } from "../utils/guestText.js";
|
|
2
3
|
|
|
3
4
|
const RUNTIME_ROW_TABLE = "RuntimeHostRow";
|
|
4
5
|
const RUNTIME_ROW_SCHEMA = `
|
|
@@ -9,7 +10,6 @@ table RuntimeHostRow {
|
|
|
9
10
|
`;
|
|
10
11
|
|
|
11
12
|
const encoder = new TextEncoder();
|
|
12
|
-
const decoder = new TextDecoder();
|
|
13
13
|
|
|
14
14
|
function clonePayload(payload) {
|
|
15
15
|
if (payload === null || payload === undefined) {
|
|
@@ -151,7 +151,7 @@ function decodeRuntimeRowMetadata(data) {
|
|
|
151
151
|
throw new Error("Invalid runtime row metadata layout.");
|
|
152
152
|
}
|
|
153
153
|
return {
|
|
154
|
-
schemaFileId:
|
|
154
|
+
schemaFileId: decodeGuestText(bytes.subarray(schemaStart, schemaEnd)),
|
|
155
155
|
rowId: Number(view.getBigUint64(rowIdOffset, true)),
|
|
156
156
|
};
|
|
157
157
|
}
|
|
@@ -19,6 +19,7 @@ import { fileURLToPath } from "node:url";
|
|
|
19
19
|
|
|
20
20
|
import { createBrowserModuleHarness } from "../host/browserModuleHarness.js";
|
|
21
21
|
import { loadModule } from "../host/isomorphicLoader.js";
|
|
22
|
+
import { analyzeWasmThreadFeatures } from "../compiler/pthreadArtifactGuard.js";
|
|
22
23
|
|
|
23
24
|
export const STANDALONE_RUNTIME_KINDS = Object.freeze(["browser", "wasmedge"]);
|
|
24
25
|
|
|
@@ -40,6 +41,15 @@ export function isWasmEdgeAvailable() {
|
|
|
40
41
|
return result.status === 0;
|
|
41
42
|
}
|
|
42
43
|
|
|
44
|
+
function artifactNeedsThreads(wasmPath) {
|
|
45
|
+
try {
|
|
46
|
+
const features = analyzeWasmThreadFeatures(new Uint8Array(fs.readFileSync(wasmPath)));
|
|
47
|
+
return features.hasSharedMemory || features.hasWasiThreadSpawnImport;
|
|
48
|
+
} catch {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
43
53
|
export async function createStandaloneHarness(runtimeKind, wasmPath, options = {}) {
|
|
44
54
|
const resolvedWasmPath = resolveWasmPath(wasmPath);
|
|
45
55
|
if (runtimeKind === "browser") {
|
|
@@ -70,7 +80,11 @@ export async function createStandaloneHarness(runtimeKind, wasmPath, options = {
|
|
|
70
80
|
wasmSource: resolvedWasmPath,
|
|
71
81
|
runtimeKind: "wasmedge",
|
|
72
82
|
surface: options.surface ?? "command",
|
|
73
|
-
|
|
83
|
+
// Unset, WasmEdge's threads proposal follows the artifact: on for a
|
|
84
|
+
// shared memory (wasi-threads, and wasi-sequential on
|
|
85
|
+
// wasm32-wasip1-threads) or a wasi thread-spawn import, which WasmEdge
|
|
86
|
+
// refuses to instantiate without it; off otherwise.
|
|
87
|
+
enableThreads: options.enableThreads ?? artifactNeedsThreads(resolvedWasmPath),
|
|
74
88
|
wasmEdgeBinary: options.wasmEdgeBinary,
|
|
75
89
|
wasmEdgeRunnerBinary: options.wasmEdgeRunnerBinary,
|
|
76
90
|
args: options.args,
|
|
@@ -1216,15 +1216,20 @@ export async function runParityGate(options = {}) {
|
|
|
1216
1216
|
const behavioral = [];
|
|
1217
1217
|
for (const artifact of artifacts) {
|
|
1218
1218
|
if (!artifact.fixture) continue;
|
|
1219
|
-
// Behavioral lanes are
|
|
1220
|
-
//
|
|
1221
|
-
// it
|
|
1222
|
-
//
|
|
1223
|
-
|
|
1224
|
-
|
|
1219
|
+
// Behavioral lanes are the gate's active lanes: a lane the caller did not
|
|
1220
|
+
// request is never compared (the Docker lane is optional; owner
|
|
1221
|
+
// 2026-10-22: "we don't need it for any of these tasks"), and a requested
|
|
1222
|
+
// lane that is not up already failed above as lane-unavailable. They are
|
|
1223
|
+
// scoped by the artifact's OWN declaration too: a WasmEdge-only artifact
|
|
1224
|
+
// has no browser behaviour to compare, and running it there would score
|
|
1225
|
+
// the harness's (correct) refusal as a divergence. The scoping is
|
|
1226
|
+
// RECORDED — a skipped lane is evidence, never silence.
|
|
1227
|
+
const requestedHarnessLanes = [
|
|
1228
|
+
...(activeLanes.includes("browser") ? ["browser"] : []),
|
|
1225
1229
|
...(wasmedgeLanes.includes("wasmedge-native") ? ["wasmedge"] : []),
|
|
1226
|
-
"docker-wasmedge",
|
|
1227
|
-
]
|
|
1230
|
+
...(wasmedgeLanes.includes("wasmedge-docker") ? ["docker-wasmedge"] : []),
|
|
1231
|
+
];
|
|
1232
|
+
const harnessLanes = requestedHarnessLanes.filter((laneName) =>
|
|
1228
1233
|
laneIsInDeclaredScope(
|
|
1229
1234
|
laneName === "wasmedge"
|
|
1230
1235
|
? "wasmedge-native"
|
|
@@ -1235,7 +1240,7 @@ export async function runParityGate(options = {}) {
|
|
|
1235
1240
|
artifact.declaredCapabilities,
|
|
1236
1241
|
),
|
|
1237
1242
|
);
|
|
1238
|
-
const outOfScopeLanes =
|
|
1243
|
+
const outOfScopeLanes = requestedHarnessLanes.filter(
|
|
1239
1244
|
(laneName) => !harnessLanes.includes(laneName),
|
|
1240
1245
|
);
|
|
1241
1246
|
if (harnessLanes.length < 2) {
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// The one place a JavaScript host turns bytes read out of a WebAssembly guest into text.
|
|
2
|
+
//
|
|
3
|
+
// A guest built for wasm32-wasip1-threads (the wasi-sequential modules too) owns a SharedArrayBuffer memory, so the
|
|
4
|
+
// views a host takes over it are shared. Chromium's TextDecoder refuses them ("The provided ArrayBufferView value
|
|
5
|
+
// must not be shared"); Node and WasmEdge accept them, so the browser alone failed. A shared view can also change
|
|
6
|
+
// under the decoder. Decode an owned copy, so every host reads the same bytes in every runtime.
|
|
7
|
+
const decoder = new TextDecoder();
|
|
8
|
+
|
|
9
|
+
/** The UTF-8 text of `bytes`, a Uint8Array that may be a view of shared guest memory. */
|
|
10
|
+
export function decodeGuestText(bytes) {
|
|
11
|
+
return decoder.decode(bytes.slice());
|
|
12
|
+
}
|