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.
Files changed (68) hide show
  1. package/docs/_shell/consumer-assets.html +3 -3
  2. package/docs/assets/vendor/hd-wallet-ui/2.2.1/sdn-wallet-callback.0f2dee485c8f0d7afe5f70b4b42093a382c92d32af551bd71b41733336091c7a.js +1 -0
  3. package/docs/assets/vendor/hd-wallet-ui/2.2.1/sdn-wallet-public-client.9ab041131df957fcb6ef7e3d87bf9d19fe313bc5d7f1e53337752faf0ba354da.js +1 -0
  4. package/docs/assets/vendor/hd-wallet-ui/2.2.1/sdn-wallet-public-client.c3f68d1cfd88478f10d836a5e829d1dfc6a10157972cf0f7d4d319d0636f2cc4.css +32 -0
  5. package/docs/assets/vendor/sdn-stack-nav/1.0.1/sdn-stack-nav.24eb3001afc5448a90cef87e53bb4e599c0ae4dc9e14bafb6d1236e0233c6008.js +283 -0
  6. package/docs/assets/vendor/sdn-stack-nav/1.0.1/sdn-stack-nav.36a36359ce18322185e9ff179f88175bab67d5ad84a14d9c08a54f2ff27267e7.css +118 -0
  7. package/docs/browser-wasmedge-isomorphic.html +3 -3
  8. package/docs/byo-wasm-quickstart.html +3 -3
  9. package/docs/conformance.html +3 -3
  10. package/docs/events-abi.html +3 -3
  11. package/docs/families/analytics.html +3 -3
  12. package/docs/families/attitude.html +3 -3
  13. package/docs/families/behavior.html +3 -3
  14. package/docs/families/breakup.html +3 -3
  15. package/docs/families/conjunction.html +3 -3
  16. package/docs/families/data-source.html +3 -3
  17. package/docs/families/effects.html +3 -3
  18. package/docs/families/environment.html +3 -3
  19. package/docs/families/estimation.html +3 -3
  20. package/docs/families/gnc.html +3 -3
  21. package/docs/families/maneuver.html +3 -3
  22. package/docs/families/obstruction.html +3 -3
  23. package/docs/families/propagator.html +3 -3
  24. package/docs/families/propulsion.html +3 -3
  25. package/docs/families/reentry.html +3 -3
  26. package/docs/families/rf.html +3 -3
  27. package/docs/families/scheduler.html +3 -3
  28. package/docs/families/sensor.html +3 -3
  29. package/docs/families/signature.html +3 -3
  30. package/docs/flatsql-host-contract.html +3 -3
  31. package/docs/flatsql-streaming-standard.html +3 -3
  32. package/docs/gpu-module-abi.html +3 -3
  33. package/docs/index.html +3 -3
  34. package/docs/isomorphic-pthreads.html +3 -3
  35. package/docs/isomorphic-sdn-runtime-plan.html +3 -3
  36. package/docs/language-runtime-matrix.html +3 -3
  37. package/docs/module-bundle-runtime-plan.html +3 -3
  38. package/docs/module-publication-standard.html +3 -3
  39. package/docs/node-red-default-node-parity.html +3 -3
  40. package/docs/protect-and-sign.html +3 -3
  41. package/docs/protocol-installation.html +3 -3
  42. package/docs/publication-submission.html +3 -3
  43. package/docs/secrets-capability.html +3 -3
  44. package/docs/testing-harness.html +3 -3
  45. package/docs/tri-runtime-parity-gate.html +3 -3
  46. package/docs/tri-runtime-parity.html +3 -3
  47. package/docs/wallet-callback.html +1 -1
  48. package/package.json +1 -1
  49. package/src/compiler/compileCache.js +495 -0
  50. package/src/compiler/compileModule.js +537 -509
  51. package/src/compiler/emceptionNode.js +127 -1
  52. package/src/compiler/guestLinkFiles.js +60 -0
  53. package/src/compiler/index.d.ts +7 -0
  54. package/src/compiler/index.js +7 -0
  55. package/src/compiler/wasmObjectSymbols.js +369 -0
  56. package/src/flow/flowCompiler.js +124 -4
  57. package/src/flow/flowRuntimeHost.js +2 -2
  58. package/src/host/abi.js +2 -3
  59. package/src/host/hostWorkerBundleSources.js +3 -3
  60. package/src/host/hostcallWire.js +3 -2
  61. package/src/host/providerAccess.js +2 -3
  62. package/src/host/typedDispatch.js +2 -2
  63. package/src/host/wasiShim.js +5 -1
  64. package/src/index.d.ts +93 -0
  65. package/src/runtime-host/flatsqlRuntimeStore.js +2 -2
  66. package/src/testing/isomorphicHarness.js +15 -1
  67. package/src/testing/parityGate.js +14 -9
  68. package/src/utils/guestText.js +12 -0
@@ -48,7 +48,16 @@ import {
48
48
 
49
49
  import { generateEmbeddedManifestSource } from "../embeddedManifest.js";
50
50
  import { generateInvokeSupportHeader } from "../compiler/invokeGlue.js";
51
- import { runWithEmceptionLock } from "../compiler/emceptionNode.js";
51
+ import { getEmceptionCompileIdentity, runWithEmceptionLock } from "../compiler/emceptionNode.js";
52
+ import {
53
+ COMPILE_CACHE_FORMAT,
54
+ digestFiles,
55
+ digestOf,
56
+ getNativeClangIdentity,
57
+ getSdkCompileIdentity,
58
+ openCompileCache,
59
+ sha256Hex,
60
+ } from "../compiler/compileCache.js";
52
61
  import {
53
62
  assertPthreadArtifact,
54
63
  assertPthreadFlagsPresent,
@@ -395,7 +404,7 @@ async function loadDependencyFromDirectory(dir) {
395
404
  readFile(path.join(guestLinkDir, GUEST_LINK_OBJECT_FILENAME)),
396
405
  readFile(path.join(guestLinkDir, GUEST_LINK_METADATA_FILENAME), "utf8").then(JSON.parse),
397
406
  ]);
398
- return { objectBytes: new Uint8Array(objectBytes), metadata };
407
+ return { objectBytes: new Uint8Array(objectBytes), metadata, guestLinkDir };
399
408
  };
400
409
  try {
401
410
  entry.guestLink = await readGuestLink("guest-link");
@@ -409,9 +418,57 @@ async function loadDependencyFromDirectory(dir) {
409
418
  } catch {
410
419
  entry.guestLinkLinked = null;
411
420
  }
421
+ // Shared library objects the guest-link metadata lists (metadata.version 2):
422
+ // outside the try above, so a listed library that is missing or does not
423
+ // hash to its recorded sha256 fails the flow rather than dropping the module.
424
+ for (const guestLink of [entry.guestLink, entry.guestLinkLinked]) {
425
+ if (guestLink) guestLink.libraries = await readGuestLinkLibraries(guestLink, manifest.pluginId);
426
+ }
412
427
  return entry;
413
428
  }
414
429
 
430
+ async function readGuestLinkLibraries(guestLink, pluginId) {
431
+ const listed = guestLink.metadata?.libraries;
432
+ if (listed === undefined || listed === null) return [];
433
+ if (!Array.isArray(listed)) {
434
+ throw new Error(`Plugin "${pluginId}": guest-link metadata.libraries must be an array.`);
435
+ }
436
+ const libraries = [];
437
+ for (const library of listed) {
438
+ const file = String(library?.file ?? "");
439
+ const resolved = path.resolve(guestLink.guestLinkDir, file);
440
+ if (!file || !resolved.startsWith(guestLink.guestLinkDir + path.sep)) {
441
+ throw new Error(`Plugin "${pluginId}": guest-link library ${JSON.stringify(library?.name)} has no file inside its guest-link dir.`);
442
+ }
443
+ if (!/^sdm_lib_[A-Za-z0-9_]+_$/.test(String(library?.namespace ?? ""))) {
444
+ throw new Error(`Plugin "${pluginId}": guest-link library ${JSON.stringify(library?.name)} has no sdm_lib_ namespace.`);
445
+ }
446
+ const objectBytes = new Uint8Array(await readFile(resolved));
447
+ const sha256 = bytesToHex(await sha256Bytes(objectBytes));
448
+ if (sha256 !== library.sha256) {
449
+ throw new Error(
450
+ `Plugin "${pluginId}": guest-link library ${file} hashes to ${sha256}, but its metadata records ${library.sha256}.`,
451
+ );
452
+ }
453
+ libraries.push({ ...library, objectBytes });
454
+ }
455
+ return libraries;
456
+ }
457
+
458
+ // Each shared library namespace once, in first-use order. A namespace is the
459
+ // library's name, version and a digest of its source, defines, flags and
460
+ // toolchain kind, so two modules carrying the same namespace carry the same
461
+ // library and the flow links one copy of it.
462
+ function collectFlowLibraryObjects(linkedDependencies) {
463
+ const byNamespace = new Map();
464
+ for (const dependency of linkedDependencies) {
465
+ for (const library of dependency.guestLink?.libraries ?? []) {
466
+ if (!byNamespace.has(library.namespace)) byNamespace.set(library.namespace, library);
467
+ }
468
+ }
469
+ return Array.from(byNamespace.values());
470
+ }
471
+
415
472
  async function scanForDependencyDirs(root, found) {
416
473
  let entries;
417
474
  try {
@@ -3035,6 +3092,56 @@ async function linkFlowArtifactWithWasiThreads({
3035
3092
  }
3036
3093
  }
3037
3094
 
3095
+ // The flow link through the compile cache (src/compiler/compileCache.js): keyed
3096
+ // on every generated source, every dependency and library object, the link
3097
+ // mode, the toolchain identity, the SDK compiler identity and this file's
3098
+ // bytes (its compile and link flags). An unchanged flow is not relinked.
3099
+ const FLOW_COMPILER_SOURCE = new URL(import.meta.url);
3100
+ let flowCompilerDigestPromise = null;
3101
+
3102
+ async function linkFlowArtifactCached(link, threadModel, inputs) {
3103
+ const cache = openCompileCache();
3104
+ if (!cache) return link(inputs);
3105
+ flowCompilerDigestPromise ??= readFile(FLOW_COMPILER_SOURCE).then((bytes) => sha256Hex(bytes));
3106
+ let toolchain;
3107
+ if (threadModel === FLOW_THREAD_MODEL.SINGLE_THREAD) {
3108
+ toolchain = { kind: "emception", id: await getEmceptionCompileIdentity() };
3109
+ } else {
3110
+ const wasi = resolveWasiThreadsToolchain();
3111
+ toolchain = {
3112
+ kind: "wasi",
3113
+ id: await getNativeClangIdentity({
3114
+ drivers: [wasi.clangxx],
3115
+ toolchainArgs: wasi.toolchainArgs,
3116
+ roots: [wasi.sysroot, wasi.resourceDir],
3117
+ }),
3118
+ };
3119
+ }
3120
+ const key = digestOf({
3121
+ format: COMPILE_CACHE_FORMAT,
3122
+ step: "flow-link",
3123
+ sdk: await getSdkCompileIdentity(),
3124
+ flowCompiler: await flowCompilerDigestPromise,
3125
+ toolchain,
3126
+ threadModel,
3127
+ engineLinked: Boolean(inputs.engineLinked),
3128
+ sequential: Boolean(inputs.sequential),
3129
+ sources: digestFiles({
3130
+ "flow_runtime.cpp": inputs.runtimeSource,
3131
+ "space_data_module_invoke.h": inputs.invokeHeader,
3132
+ "flow_generated.inc": inputs.generatedInc,
3133
+ "flow-manifest-exports.cpp": inputs.manifestSource,
3134
+ "flow-program-exports.cpp": inputs.programSource,
3135
+ }),
3136
+ objects: inputs.dependencyObjects.map((bytes) => sha256Hex(bytes)),
3137
+ });
3138
+ const entry = await cache.get(key);
3139
+ if (entry?.blobs?.wasm) return entry.blobs.wasm;
3140
+ const wasmBytes = await link(inputs);
3141
+ await cache.put(key, { wasm: wasmBytes }, { step: "flow-link" });
3142
+ return wasmBytes;
3143
+ }
3144
+
3038
3145
  /**
3039
3146
  * Compile a validated flow document into the linked-direct flow bundle.
3040
3147
  * Returns { check, manifest, artifact, outputs, report }.
@@ -3129,13 +3236,16 @@ export async function compileFlowProgram({
3129
3236
  check.threadModel !== FLOW_THREAD_MODEL.SINGLE_THREAD
3130
3237
  ? linkFlowArtifactWithWasiThreads
3131
3238
  : linkFlowArtifactWithEmception;
3132
- let wasmBytes = await linkFlowArtifact({
3239
+ let wasmBytes = await linkFlowArtifactCached(linkFlowArtifact, check.threadModel, {
3133
3240
  runtimeSource,
3134
3241
  invokeHeader: generateInvokeSupportHeader(),
3135
3242
  generatedInc,
3136
3243
  manifestSource,
3137
3244
  programSource,
3138
- dependencyObjects: linkedDependencies.map((dependency) => dependency.guestLink.objectBytes),
3245
+ dependencyObjects: [
3246
+ ...linkedDependencies.map((dependency) => dependency.guestLink.objectBytes),
3247
+ ...collectFlowLibraryObjects(linkedDependencies).map((library) => library.objectBytes),
3248
+ ],
3139
3249
  engineLinked: Boolean(check.engineLinkage),
3140
3250
  sequential: check.threadModel === FLOW_THREAD_MODEL.WASI_SEQUENTIAL,
3141
3251
  });
@@ -3185,6 +3295,16 @@ export async function compileFlowProgram({
3185
3295
  publisher: dependency.artifactLock?.publisher ?? null,
3186
3296
  symbolPrefix: dependency.guestLink?.metadata?.symbolPrefix ?? null,
3187
3297
  methodSymbols: dependency.guestLink?.metadata?.methodSymbols ?? {},
3298
+ ...(dependency.guestLink?.libraries?.length
3299
+ ? {
3300
+ libraries: dependency.guestLink.libraries.map(({ name, version, namespace, sha256: librarySha256 }) => ({
3301
+ name,
3302
+ version,
3303
+ namespace,
3304
+ sha256: librarySha256,
3305
+ })),
3306
+ }
3307
+ : {}),
3188
3308
  });
3189
3309
  }
3190
3310
  for (const component of check.componentDependencies ?? []) {
@@ -15,6 +15,7 @@
15
15
  */
16
16
 
17
17
  import { createBrowserWasiShim } from "../host/wasiShim.js";
18
+ import { decodeGuestText } from "../utils/guestText.js";
18
19
  import {
19
20
  assertArtifactRuntimeTarget,
20
21
  detectBrowserLeg,
@@ -151,7 +152,6 @@ function typeRefMatchesDescriptor(typeRef = {}, descriptor, wireFormat) {
151
152
  return true;
152
153
  }
153
154
 
154
- const textDecoder = new TextDecoder();
155
155
  const textEncoder = new TextEncoder();
156
156
 
157
157
  function assertDescriptorAbiGeneration(generation) {
@@ -314,7 +314,7 @@ export async function createFlowRuntimeHost(options = {}) {
314
314
  let end = ptr;
315
315
  const limit = Math.min(heap.length, ptr + maxLength);
316
316
  while (end < limit && heap[end] !== 0) end++;
317
- return textDecoder.decode(heap.subarray(ptr, end));
317
+ return decodeGuestText(heap.subarray(ptr, end));
318
318
  }
319
319
 
320
320
  function writeBytes(ptr, bytes) {
package/src/host/abi.js CHANGED
@@ -7,8 +7,7 @@ import {
7
7
  import { isTypedHostCall } from "../standards/runtimeContracts.js";
8
8
  import { answerTypedHostCall } from "./typedDispatch.js";
9
9
  import { ADAPTER_OPERATIONS } from "./adapterOperations.js";
10
-
11
- const textDecoder = new TextDecoder();
10
+ import { decodeGuestText } from "../utils/guestText.js";
12
11
 
13
12
  export const DEFAULT_HOSTCALL_IMPORT_MODULE = "space_data_module_host";
14
13
  export const HOSTCALL_STATUS_OK = 0;
@@ -423,7 +422,7 @@ export function createHostcallBridge(options = {}) {
423
422
  `Hostcall request exceeds ${maxRequestBytes} byte limit.`,
424
423
  );
425
424
  }
426
- const operation = textDecoder.decode(
425
+ const operation = decodeGuestText(
427
426
  readMemoryBytes(getMemory, operationPtr, operationLen, "Operation"),
428
427
  );
429
428
  const payload = readMemoryBytes(getMemory, payloadPtr, payloadLen, "Payload");