space-data-module-sdk 0.5.15 → 0.5.19
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 +51 -0
- package/package.json +13 -4
- package/schemas/HostStorageAbi.fbs +53 -0
- package/src/browser.js +6 -0
- package/src/bundle/codec.js +1 -1
- package/src/compiler/compileModule.js +3 -0
- package/src/compliance/pluginCompliance.js +1 -2
- package/src/generated/orbpro/invoke/plugin-invoke-request.js +1 -1
- package/src/generated/orbpro/invoke/plugin-invoke-response.js +1 -1
- package/src/generated/orbpro/manifest/accepted-type-set.js +1 -1
- package/src/generated/orbpro/manifest/build-artifact.js +1 -1
- package/src/generated/orbpro/manifest/host-capability.js +1 -1
- package/src/generated/orbpro/manifest/method-manifest.js +1 -1
- package/src/generated/orbpro/manifest/plugin-manifest.js +1 -1
- package/src/generated/orbpro/manifest/port-manifest.js +1 -1
- package/src/generated/orbpro/manifest/protocol-spec.js +1 -1
- package/src/generated/orbpro/manifest/timer-spec.js +1 -1
- package/src/generated/orbpro/module/canonicalization-rule.js +1 -1
- package/src/generated/orbpro/module/module-bundle-entry.js +1 -1
- package/src/generated/orbpro/module/module-bundle.js +1 -1
- package/src/generated/orbpro/stream/flat-buffer-type-ref.js +1 -1
- package/src/generated/orbpro/stream/typed-arena-buffer.js +1 -1
- package/src/host/browserEdgeShims.js +355 -0
- package/src/host/browserHost.js +399 -0
- package/src/host/index.js +4 -0
- package/src/host/isomorphicLoader.js +101 -0
- package/src/host/wasiShim.js +275 -0
- package/src/index.d.ts +364 -0
- package/src/index.js +1 -0
- package/src/invoke/codec.js +1 -1
- package/src/manifest/codec.js +1 -1
- package/src/manifest/typeRefs.js +49 -12
- package/src/runtime-host/flatsqlRuntimeStore.js +217 -0
- package/src/runtime-host/index.js +21 -0
- package/src/runtime-host/moduleRegistry.js +92 -0
- package/src/runtime-host/runtimeRegionStore.js +245 -0
- package/src/testing/browserModuleHarness.js +275 -0
- package/src/testing/buildWasmEdgeRunner.js +41 -2
- package/src/testing/index.d.ts +173 -2
- package/src/testing/index.js +5 -0
- package/src/testing/moduleHarness.js +102 -1
- package/src/testing/native/wasmedge_emscripten_pthread_runner.c +2319 -209
- package/src/testing/processInvoke.js +250 -9
- package/src/testing/streamInvokeCodec.js +175 -0
- package/src/transport/records.js +19 -6
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createPluginInvokeProcessClient,
|
|
3
|
+
createWasmEdgeStreamProcessClient,
|
|
3
4
|
resolveWasmEdgePluginLaunchPlan,
|
|
4
5
|
} from "./processInvoke.js";
|
|
5
6
|
|
|
@@ -10,6 +11,15 @@ function normalizeRuntimeDescriptor(options = {}) {
|
|
|
10
11
|
return options;
|
|
11
12
|
}
|
|
12
13
|
|
|
14
|
+
function isRuntimeHostProfile(runtime = {}) {
|
|
15
|
+
return (
|
|
16
|
+
String(runtime.hostProfile ?? "").trim().toLowerCase() === "runtime-host" ||
|
|
17
|
+
Array.isArray(runtime.modules) ||
|
|
18
|
+
(typeof runtime.defaultModuleId === "string" &&
|
|
19
|
+
runtime.defaultModuleId.trim().length > 0)
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
13
23
|
export function resolveModuleHarnessLaunchPlan(options = {}) {
|
|
14
24
|
const runtime = normalizeRuntimeDescriptor(options);
|
|
15
25
|
if (runtime.launchPlan && typeof runtime.launchPlan === "object") {
|
|
@@ -41,20 +51,111 @@ export async function createModuleHarness(options = {}) {
|
|
|
41
51
|
const runtime = normalizeRuntimeDescriptor(options);
|
|
42
52
|
const kind = String(runtime.kind ?? "process").trim().toLowerCase();
|
|
43
53
|
const launchPlan = resolveModuleHarnessLaunchPlan(options);
|
|
44
|
-
const
|
|
54
|
+
const runtimeHost = isRuntimeHostProfile(runtime);
|
|
55
|
+
const processClient =
|
|
56
|
+
kind === "wasmedge"
|
|
57
|
+
? await createWasmEdgeStreamProcessClient({ launchPlan })
|
|
58
|
+
: await createPluginInvokeProcessClient({ launchPlan });
|
|
59
|
+
const configuredModules = Array.isArray(runtime.modules) ? [...runtime.modules] : [];
|
|
60
|
+
if (
|
|
61
|
+
kind === "wasmedge" &&
|
|
62
|
+
runtimeHost &&
|
|
63
|
+
configuredModules.length === 0 &&
|
|
64
|
+
typeof runtime.wasmPath === "string" &&
|
|
65
|
+
runtime.wasmPath.trim().length > 0
|
|
66
|
+
) {
|
|
67
|
+
configuredModules.push({
|
|
68
|
+
moduleId:
|
|
69
|
+
typeof runtime.defaultModuleId === "string" &&
|
|
70
|
+
runtime.defaultModuleId.trim().length > 0
|
|
71
|
+
? runtime.defaultModuleId.trim()
|
|
72
|
+
: "default",
|
|
73
|
+
wasmPath: runtime.wasmPath,
|
|
74
|
+
metadata: runtime.metadata ?? null,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
for (const moduleDefinition of configuredModules) {
|
|
79
|
+
await processClient.installModule(moduleDefinition);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
let defaultModuleId =
|
|
83
|
+
typeof runtime.defaultModuleId === "string" && runtime.defaultModuleId.trim().length > 0
|
|
84
|
+
? runtime.defaultModuleId.trim()
|
|
85
|
+
: configuredModules[0]?.moduleId ?? null;
|
|
45
86
|
|
|
46
87
|
return {
|
|
47
88
|
runtime: {
|
|
48
89
|
...runtime,
|
|
49
90
|
kind,
|
|
91
|
+
hostProfile: runtimeHost ? "runtime-host" : runtime.hostProfile,
|
|
50
92
|
},
|
|
51
93
|
launchPlan,
|
|
52
94
|
invokeRaw(requestBytes) {
|
|
53
95
|
return processClient.invokeRaw(requestBytes);
|
|
54
96
|
},
|
|
55
97
|
invoke(request) {
|
|
98
|
+
if (runtimeHost) {
|
|
99
|
+
if (!defaultModuleId) {
|
|
100
|
+
throw new Error(
|
|
101
|
+
"Runtime-host invoke() requires an installed defaultModuleId.",
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
return processClient.invokeModule(defaultModuleId, request);
|
|
105
|
+
}
|
|
56
106
|
return processClient.invoke(request);
|
|
57
107
|
},
|
|
108
|
+
async installModule(definition) {
|
|
109
|
+
const installed = await processClient.installModule(definition);
|
|
110
|
+
if (
|
|
111
|
+
runtimeHost &&
|
|
112
|
+
(!defaultModuleId || defaultModuleId.trim().length === 0) &&
|
|
113
|
+
typeof installed?.moduleId === "string" &&
|
|
114
|
+
installed.moduleId.trim().length > 0
|
|
115
|
+
) {
|
|
116
|
+
defaultModuleId = installed.moduleId.trim();
|
|
117
|
+
}
|
|
118
|
+
return installed;
|
|
119
|
+
},
|
|
120
|
+
listModules() {
|
|
121
|
+
return processClient.listModules();
|
|
122
|
+
},
|
|
123
|
+
async unloadModule(moduleId) {
|
|
124
|
+
const unloaded = await processClient.unloadModule(moduleId);
|
|
125
|
+
if (unloaded && moduleId === defaultModuleId) {
|
|
126
|
+
if (runtimeHost) {
|
|
127
|
+
const remainingModules = await processClient.listModules();
|
|
128
|
+
defaultModuleId = remainingModules[0]?.moduleId ?? null;
|
|
129
|
+
} else {
|
|
130
|
+
defaultModuleId = null;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return unloaded;
|
|
134
|
+
},
|
|
135
|
+
invokeModule(moduleId, request) {
|
|
136
|
+
return processClient.invokeModule(moduleId, request);
|
|
137
|
+
},
|
|
138
|
+
appendRow(options) {
|
|
139
|
+
return processClient.appendRow(options);
|
|
140
|
+
},
|
|
141
|
+
listRows(schemaFileId = null) {
|
|
142
|
+
return processClient.listRows(schemaFileId);
|
|
143
|
+
},
|
|
144
|
+
resolveRow(handle) {
|
|
145
|
+
return processClient.resolveRow(handle);
|
|
146
|
+
},
|
|
147
|
+
queryRows(sql) {
|
|
148
|
+
return processClient.queryRows(sql);
|
|
149
|
+
},
|
|
150
|
+
allocateRegion(options) {
|
|
151
|
+
return processClient.allocateRegion(options);
|
|
152
|
+
},
|
|
153
|
+
describeRegion(regionId) {
|
|
154
|
+
return processClient.describeRegion(regionId);
|
|
155
|
+
},
|
|
156
|
+
resolveRecord(query) {
|
|
157
|
+
return processClient.resolveRecord(query);
|
|
158
|
+
},
|
|
58
159
|
destroy() {
|
|
59
160
|
return processClient.destroy();
|
|
60
161
|
},
|