space-data-module-sdk 0.9.1 → 0.9.3
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/package.json +1 -1
- package/schemas/runtime/HostOps.fbs +6 -12
- package/src/generated/runtime/aligned/HostOps_aligned.js +0 -59
- package/src/generated/runtime/aligned/HostOps_aligned.ts +0 -70
- package/src/generated/runtime/aligned/HostOps_enums.js +0 -2
- package/src/generated/runtime/aligned/HostOps_enums.ts +0 -1
- package/src/generated/runtime/cpp/HostOps_aligned.h +0 -56
- package/src/host/cpp/typedHostcall.hpp +248 -0
- package/src/host/hostWorkerBundleSources.js +3 -3
- package/src/host/typedDispatch.js +27 -22
- package/src/standards/runtimeContracts.js +3 -2
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
decodeHostCall,
|
|
8
8
|
decodeSqlValues,
|
|
9
9
|
encodeHostCallResult,
|
|
10
|
+
encodeModuleConfig,
|
|
10
11
|
encodeSqlValues,
|
|
11
12
|
} from "../standards/runtimeContracts.js";
|
|
12
13
|
import * as hostOps from "../generated/runtime/aligned/HostOps_aligned.js";
|
|
@@ -192,28 +193,32 @@ function sqlCell(v) {
|
|
|
192
193
|
if (typeof v === "string") return { t: "str", v };
|
|
193
194
|
throw failed(`storage.query_sandboxed: a cell is a ${Array.isArray(v) ? "list" : typeof v} (nested values are not SQL values)`);
|
|
194
195
|
}
|
|
195
|
-
/**
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
if (
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
196
|
+
/**
|
|
197
|
+
* plugin.getConfig: the config as one ModuleConfig FlatBuffer (MCFG) on raw "config" - number arrays NumberList, string
|
|
198
|
+
* arrays StringList, nested objects and arrays of objects TableList, keys sorted (encodeModuleConfig). Unset values
|
|
199
|
+
* (null / undefined) are left out; a value with no config kind (a Date, a function, a list mixing kinds) is refused.
|
|
200
|
+
*/
|
|
201
|
+
function configOf(value, path) {
|
|
202
|
+
if (value === null || value === undefined) return undefined;
|
|
203
|
+
if (typeof value === "bigint") return Number(value);
|
|
204
|
+
if (Array.isArray(value)) return value.filter((v) => v !== null && v !== undefined).map((v, i) => configOf(v, `${path}.${i}`));
|
|
205
|
+
if (typeof value === "object") {
|
|
206
|
+
if (value instanceof Date || ArrayBuffer.isView(value) || value instanceof ArrayBuffer) throw failed(`plugin.getConfig: ${path} is a ${value.constructor?.name ?? "object"}`);
|
|
207
|
+
const out = {};
|
|
208
|
+
for (const key of Object.keys(value)) { const v = configOf(value[key], path ? `${path}.${key}` : key); if (v !== undefined) out[key] = v; }
|
|
209
|
+
return out;
|
|
210
|
+
}
|
|
211
|
+
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") return value;
|
|
212
|
+
throw failed(`plugin.getConfig: ${path} is a ${typeof value}`);
|
|
213
|
+
}
|
|
214
|
+
function moduleConfig(config) {
|
|
215
|
+
const plain = configOf(config ?? {}, "") ?? {};
|
|
216
|
+
if (Array.isArray(plain) || typeof plain !== "object") throw failed("plugin.getConfig: the config is not an object");
|
|
217
|
+
try {
|
|
218
|
+
return encodeModuleConfig(plain);
|
|
219
|
+
} catch (error) {
|
|
220
|
+
throw failed(`plugin.getConfig: ${error.message}`);
|
|
215
221
|
}
|
|
216
|
-
return entries;
|
|
217
222
|
}
|
|
218
223
|
function secretRequest({ params, raw }) {
|
|
219
224
|
const request = { id: str(params?.ID) };
|
|
@@ -333,7 +338,7 @@ const ADAPTERS = {
|
|
|
333
338
|
"crypto.ed25519.verify": { in: ({ raw }) => ({ message: raw.data, signature: raw.signature, publicKey: raw.public_key }), out: bool },
|
|
334
339
|
|
|
335
340
|
// ---- the Go node's operations, through the embedder's adapters (adapterOperations.js) ------------------------------
|
|
336
|
-
"plugin.getConfig": { in: () => ({}), out: (v) => ({
|
|
341
|
+
"plugin.getConfig": { in: () => ({}), out: (v) => ({ raw: { config: moduleConfig(v) } }) },
|
|
337
342
|
"node.peerId": { in: () => ({}), out: nodeText("peer ID") },
|
|
338
343
|
"node.publicKey": { in: () => ({}), out: nodeText("public key") },
|
|
339
344
|
"secrets.get": { in: secretRequest, out: (v) => ({ result: fit("SecretResult", { ID: str(v?.id), USERNAME: str(v?.username), CONFIGURED: true }), raw: { secret: bytesOf(v?.secret) ?? new Uint8Array(0) } }) },
|
|
@@ -133,7 +133,8 @@ function entryOf(key, value) {
|
|
|
133
133
|
else throw new Error(`ModuleConfig: ${key} has no config value kind (${value === null ? "null" : typeof value})`);
|
|
134
134
|
return e;
|
|
135
135
|
}
|
|
136
|
-
|
|
136
|
+
// A key whose value is null or undefined is left out, as the Go node does: "not configured".
|
|
137
|
+
const entriesOf = (object) => Object.keys(object || {}).filter((k) => object[k] !== undefined && object[k] !== null).sort().map((k) => entryOf(k, object[k]));
|
|
137
138
|
function valueOf(e) {
|
|
138
139
|
switch (e.KIND) {
|
|
139
140
|
case configValueKind.String: return e.STRING_VALUE || "";
|
|
@@ -489,7 +490,7 @@ export const HOST_OPERATIONS = Object.freeze({
|
|
|
489
490
|
"random.bytes": op("RandomBytesParams", null, "random", { rawOut: ["data"] }),
|
|
490
491
|
"node.publicKey": op(null, null, null, { rawOut: ["value"] }),
|
|
491
492
|
"node.peerId": op(null, null, null, { rawOut: ["value"] }),
|
|
492
|
-
"plugin.getConfig": op(null, null, null, {
|
|
493
|
+
"plugin.getConfig": op(null, null, null, { rawOut: ["config"] }),
|
|
493
494
|
// network
|
|
494
495
|
"http.request": op("HttpParams", "HttpResult", "http", { rawIn: ["url", "headers", "body"], rawOut: ["url", "headers", "body"] }),
|
|
495
496
|
"websocket.exchange": op("WebsocketParams", "WebsocketResult", "websocket", { rawIn: ["url", "protocols", "message"], rawOut: ["url", "body"] }),
|