@syntropika/tembra-sdk 0.2.2 → 0.3.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 +43 -17
- package/dist/authoring/types.d.ts +64 -3
- package/dist/authoring/wit.d.ts +6 -0
- package/dist/bridge/commands.d.ts +1190 -0
- package/dist/bridge/identifiers.d.ts +2 -0
- package/dist/bridge/kernel.d.ts +18 -107
- package/dist/bridge/protocol.d.ts +3 -138
- package/dist/browser.d.ts +14 -1
- package/dist/browser.js +141 -3332
- package/dist/chunks/browser-b8jamxw2.js +3399 -0
- package/dist/chunks/execution-nsqc6nrt.js +1419 -0
- package/dist/chunks/index-01zk0xqx.js +160 -0
- package/dist/chunks/index-3fjdfdfd.js +152 -0
- package/dist/chunks/index-aaymjn7v.js +787 -0
- package/dist/chunks/index-c1w7z9hx.js +356 -0
- package/dist/chunks/index-h8t0n42q.js +738 -0
- package/dist/chunks/index-hfds9mzp.js +308 -0
- package/dist/chunks/index-kr4x67wt.js +177 -0
- package/dist/chunks/index-kr6bnh34.js +117 -0
- package/dist/chunks/index-kyt9dj0a.js +1421 -0
- package/dist/chunks/index-n1wxzc9w.js +830 -0
- package/dist/chunks/index-pvac426d.js +74 -0
- package/dist/chunks/index-smyds5ce.js +3234 -0
- package/dist/chunks/index-sse8aapb.js +121 -0
- package/dist/chunks/index-v6heph77.js +643 -0
- package/dist/chunks/index-xrdvnv37.js +3448 -0
- package/dist/chunks/index-za4mg94e.js +26 -0
- package/dist/chunks/index-zkqmnjj8.js +167 -0
- package/dist/coordinator.js +9 -500
- package/dist/error.d.ts +2 -0
- package/dist/errors.d.ts +3 -0
- package/dist/guest.d.ts +173 -0
- package/dist/guest.js +26 -0
- package/dist/host.d.ts +36 -30
- package/dist/host.js +37 -3310
- package/dist/http/bytes.d.ts +8 -0
- package/dist/http/events.d.ts +7 -0
- package/dist/http.d.ts +45 -0
- package/dist/http.js +291 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +49 -862
- package/dist/infrastructure/rpc/client.d.ts +2 -1
- package/dist/infrastructure/rpc/resources.d.ts +28 -0
- package/dist/interpreter/abi.d.ts +54 -0
- package/dist/interpreter/acquire.d.ts +18 -0
- package/dist/interpreter/browser-network.d.ts +52 -0
- package/dist/interpreter/browser-port.d.ts +55 -0
- package/dist/interpreter/browser.d.ts +79 -0
- package/dist/interpreter/cli.d.ts +5 -0
- package/dist/interpreter/codec.d.ts +42 -0
- package/dist/interpreter/component/execution.d.ts +42 -0
- package/dist/interpreter/component/host.d.ts +69 -0
- package/dist/interpreter/component/instance.d.ts +40 -0
- package/dist/interpreter/component/kernel.d.ts +120 -0
- package/dist/interpreter/component/names.d.ts +5 -0
- package/dist/interpreter/component/port.d.ts +85 -0
- package/dist/interpreter/component/prepared.d.ts +97 -0
- package/dist/interpreter/component/resources.d.ts +45 -0
- package/dist/interpreter/component/revision.d.ts +87 -0
- package/dist/interpreter/component/scope.d.ts +116 -0
- package/dist/interpreter/component/streams.d.ts +28 -0
- package/dist/interpreter/component/values.d.ts +79 -0
- package/dist/interpreter/component/wasi-filesystem.d.ts +21 -0
- package/dist/interpreter/component/wasi-host.d.ts +64 -0
- package/dist/interpreter/component/wasi-http.d.ts +33 -0
- package/dist/interpreter/component/wasi-sockets.d.ts +183 -0
- package/dist/interpreter/component/wasi.d.ts +41 -0
- package/dist/interpreter/core.d.ts +64 -0
- package/dist/interpreter/fetch-http-provider.d.ts +17 -0
- package/dist/interpreter/filesystem/contract.d.ts +85 -0
- package/dist/interpreter/filesystem/memory.d.ts +3 -0
- package/dist/interpreter/filesystem/opfs.d.ts +3 -0
- package/dist/interpreter/filesystem/scope.d.ts +35 -0
- package/dist/interpreter/filesystem.d.ts +8 -0
- package/dist/interpreter/gate.d.ts +6 -0
- package/dist/interpreter/host-protocol.d.ts +100 -0
- package/dist/interpreter/http-ingress-fetch.d.ts +7 -0
- package/dist/interpreter/http-ingress.d.ts +96 -0
- package/dist/interpreter/http-provider.d.ts +85 -0
- package/dist/interpreter/io.d.ts +20 -0
- package/dist/interpreter/mobile.d.ts +149 -0
- package/dist/interpreter/native-ingress.d.ts +95 -0
- package/dist/interpreter/node-port.d.ts +25 -0
- package/dist/interpreter/node.d.ts +36 -0
- package/dist/interpreter/revision.d.ts +64 -0
- package/dist/interpreter/scope.d.ts +89 -0
- package/dist/interpreter/socket-addresses.d.ts +50 -0
- package/dist/interpreter/socket-provider.d.ts +110 -0
- package/dist/interpreter/standard-cli.d.ts +34 -0
- package/dist/interpreter/standard-codec.d.ts +96 -0
- package/dist/interpreter/standard-filesystem.d.ts +47 -0
- package/dist/interpreter/standard-host.d.ts +71 -0
- package/dist/interpreter/standard-http-values.d.ts +159 -0
- package/dist/interpreter/standard-http.d.ts +9 -0
- package/dist/interpreter/standard-ingress.d.ts +63 -0
- package/dist/interpreter/standard-sockets.d.ts +177 -0
- package/dist/interpreter/standard-streams.d.ts +218 -0
- package/dist/interpreter/standard-system.d.ts +35 -0
- package/dist/interpreter/standard-utf8.d.ts +4 -0
- package/dist/interpreter/standard.d.ts +18 -0
- package/dist/interpreter/types.d.ts +152 -0
- package/dist/interpreter/wit-shape.d.ts +92 -0
- package/dist/manager.js +5 -332
- package/dist/msgpack.js +9 -615
- package/dist/node.d.ts +8 -1
- package/dist/node.js +248 -3321
- package/dist/rpc.js +196 -699
- package/dist/runtime/adapters.d.ts +120 -0
- package/dist/runtime/adapters.js +38 -0
- package/dist/runtime/calls.d.ts +7 -6
- package/dist/runtime/lifecycle.d.ts +3 -1
- package/dist/runtime/orbs.d.ts +5 -4
- package/dist/runtime/references.d.ts +27 -1
- package/dist/runtime/reload.d.ts +5 -3
- package/dist/runtime/scopes.d.ts +1 -1
- package/dist/runtime/signals.d.ts +4 -0
- package/dist/runtime/wit-client.d.ts +38 -0
- package/dist/telemetry.js +4 -25
- package/dist/tooling/build.d.ts +2 -2
- package/dist/tooling/client-resources.d.ts +23 -0
- package/dist/tooling/client.d.ts +10 -0
- package/dist/tooling/component-glue.d.ts +17 -0
- package/dist/tooling/component.d.ts +11 -0
- package/dist/tooling/index.d.ts +3 -1
- package/dist/tooling/index.js +1155 -102
- package/dist/tooling/resolver.d.ts +4 -4
- package/dist/tooling/typecheck.d.ts +2 -1
- package/dist/tooling/types.d.ts +27 -12
- package/dist/tooling/wit.d.ts +9 -0
- package/dist/wasi/wasi-clocks-types.d.ts +2 -0
- package/dist/wasi/wasi-http-client.d.ts +5 -0
- package/dist/wasi/wasi-http-types.d.ts +285 -0
- package/dist/wasi/wasi-sockets-ip-name-lookup.d.ts +23 -0
- package/dist/wasi/wasi-sockets-types.d.ts +146 -0
- package/package.json +62 -35
- package/src/authoring/declaration.ts +1 -1
- package/src/authoring/types.ts +53 -3
- package/src/authoring/wit.ts +15 -0
- package/src/bridge/commands.ts +1105 -0
- package/src/bridge/identifiers.ts +2 -0
- package/src/bridge/kernel.ts +56 -98
- package/src/bridge/protocol.ts +3 -142
- package/src/browser.ts +90 -6
- package/src/context-key.ts +4 -7
- package/src/error.ts +1 -1
- package/src/errors.ts +7 -0
- package/src/guest.ts +327 -0
- package/src/host.ts +128 -23
- package/src/http/bytes.ts +87 -0
- package/src/http/events.ts +34 -0
- package/src/http.ts +272 -0
- package/src/index.ts +3 -0
- package/src/infrastructure/rpc/client.ts +136 -17
- package/src/infrastructure/rpc/resources.ts +123 -0
- package/src/interpreter/abi.ts +69 -0
- package/src/interpreter/acquire.ts +58 -0
- package/src/interpreter/browser-network.ts +170 -0
- package/src/interpreter/browser-port.ts +425 -0
- package/src/interpreter/browser.ts +340 -0
- package/src/interpreter/cli.ts +30 -0
- package/src/interpreter/codec.ts +298 -0
- package/src/interpreter/component/execution.ts +264 -0
- package/src/interpreter/component/host.ts +409 -0
- package/src/interpreter/component/instance.ts +138 -0
- package/src/interpreter/component/kernel.ts +611 -0
- package/src/interpreter/component/names.ts +13 -0
- package/src/interpreter/component/port.ts +598 -0
- package/src/interpreter/component/prepared.ts +194 -0
- package/src/interpreter/component/resources.ts +345 -0
- package/src/interpreter/component/revision.ts +702 -0
- package/src/interpreter/component/scope.ts +447 -0
- package/src/interpreter/component/streams.ts +180 -0
- package/src/interpreter/component/values.ts +254 -0
- package/src/interpreter/component/wasi-filesystem.ts +472 -0
- package/src/interpreter/component/wasi-host.ts +197 -0
- package/src/interpreter/component/wasi-http.ts +939 -0
- package/src/interpreter/component/wasi-sockets.ts +958 -0
- package/src/interpreter/component/wasi.ts +238 -0
- package/src/interpreter/core.ts +386 -0
- package/src/interpreter/fetch-http-provider.ts +98 -0
- package/src/interpreter/filesystem/contract.ts +138 -0
- package/src/interpreter/filesystem/memory.ts +180 -0
- package/src/interpreter/filesystem/opfs.ts +294 -0
- package/src/interpreter/filesystem/scope.ts +390 -0
- package/src/interpreter/filesystem.ts +20 -0
- package/src/interpreter/gate.ts +55 -0
- package/src/interpreter/host-protocol.ts +242 -0
- package/src/interpreter/http-ingress-fetch.ts +133 -0
- package/src/interpreter/http-ingress.ts +203 -0
- package/src/interpreter/http-provider.ts +105 -0
- package/src/interpreter/io.ts +66 -0
- package/src/interpreter/mobile.ts +385 -0
- package/src/interpreter/native-ingress.ts +550 -0
- package/src/interpreter/node-port.ts +218 -0
- package/src/interpreter/node.ts +114 -0
- package/src/interpreter/revision.ts +450 -0
- package/src/interpreter/scope.ts +453 -0
- package/src/interpreter/socket-addresses.ts +246 -0
- package/src/interpreter/socket-provider.ts +126 -0
- package/src/interpreter/standard-cli.ts +184 -0
- package/src/interpreter/standard-codec.ts +403 -0
- package/src/interpreter/standard-filesystem.ts +545 -0
- package/src/interpreter/standard-host.ts +840 -0
- package/src/interpreter/standard-http-values.ts +624 -0
- package/src/interpreter/standard-http.ts +622 -0
- package/src/interpreter/standard-ingress.ts +344 -0
- package/src/interpreter/standard-sockets.ts +847 -0
- package/src/interpreter/standard-streams.ts +710 -0
- package/src/interpreter/standard-system.ts +182 -0
- package/src/interpreter/standard-utf8.ts +72 -0
- package/src/interpreter/standard.ts +283 -0
- package/src/interpreter/types.ts +163 -0
- package/src/interpreter/wit-shape.ts +175 -0
- package/src/node.ts +43 -14
- package/src/runtime/activities.ts +6 -6
- package/src/runtime/adapters.ts +314 -0
- package/src/runtime/calls.ts +213 -90
- package/src/runtime/context.ts +7 -7
- package/src/runtime/lifecycle.ts +36 -17
- package/src/runtime/orbs.ts +81 -39
- package/src/runtime/programs.ts +16 -8
- package/src/runtime/references.ts +128 -11
- package/src/runtime/reload.ts +71 -30
- package/src/runtime/resources.ts +2 -2
- package/src/runtime/scopes.ts +17 -17
- package/src/runtime/session.ts +3 -1
- package/src/runtime/signals.ts +31 -0
- package/src/runtime/wit-client.ts +228 -0
- package/src/tooling/build.ts +152 -54
- package/src/tooling/client-resources.ts +74 -0
- package/src/tooling/client.ts +531 -0
- package/src/tooling/component-glue.ts +288 -0
- package/src/tooling/component.ts +225 -0
- package/src/tooling/index.ts +3 -7
- package/src/tooling/resolver.ts +42 -25
- package/src/tooling/typecheck.ts +59 -4
- package/src/tooling/types.ts +27 -12
- package/src/tooling/wit.ts +188 -0
- package/dist/embedded.d.ts +0 -1
- package/dist/embedded.js +0 -1
- package/src/embedded.ts +0 -301
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CodecTag,
|
|
3
|
+
CodecId
|
|
4
|
+
} from "./index-kr4x67wt.js";
|
|
5
|
+
import {
|
|
6
|
+
Errors2,
|
|
7
|
+
refuse
|
|
8
|
+
} from "./index-c1w7z9hx.js";
|
|
9
|
+
|
|
10
|
+
// src/codecs/json.ts
|
|
11
|
+
var marker = "$tembra";
|
|
12
|
+
function pack(value, visiting) {
|
|
13
|
+
if (typeof value === "bigint")
|
|
14
|
+
return { [marker]: [CodecTag.Bigint, value.toString()] };
|
|
15
|
+
if (value instanceof Uint8Array)
|
|
16
|
+
return { [marker]: [CodecTag.Bytes, [...value]] };
|
|
17
|
+
if (value === null || typeof value === "string" || typeof value === "boolean")
|
|
18
|
+
return value;
|
|
19
|
+
if (typeof value === "number") {
|
|
20
|
+
if (!Number.isFinite(value) || Number.isInteger(value) && !Number.isSafeInteger(value))
|
|
21
|
+
refuse(Errors2.Invalid.JsonNumber, "Use BigInt for integers outside the safe Number range");
|
|
22
|
+
return value;
|
|
23
|
+
}
|
|
24
|
+
if (typeof value !== "object")
|
|
25
|
+
refuse(Errors2.Invalid.JsonValue, "This JSON codec requires explicit portable values");
|
|
26
|
+
if (visiting.has(value))
|
|
27
|
+
refuse(Errors2.Invalid.JsonCycle);
|
|
28
|
+
const prototype = Object.getPrototypeOf(value);
|
|
29
|
+
if (!Array.isArray(value) && prototype !== Object.prototype && prototype !== null)
|
|
30
|
+
refuse(Errors2.Invalid.JsonType, "Supply a codec for custom object types");
|
|
31
|
+
visiting.add(value);
|
|
32
|
+
try {
|
|
33
|
+
if (Array.isArray(value))
|
|
34
|
+
return Array.from(value, (child) => pack(child, visiting));
|
|
35
|
+
const entries = Reflect.ownKeys(value).map((key) => {
|
|
36
|
+
if (typeof key !== "string")
|
|
37
|
+
refuse(Errors2.Invalid.JsonSymbol);
|
|
38
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
39
|
+
if (!Object.hasOwn(descriptor, "value"))
|
|
40
|
+
refuse(Errors2.Invalid.JsonAccessor);
|
|
41
|
+
return [key, pack(descriptor.value, visiting)];
|
|
42
|
+
});
|
|
43
|
+
return Object.hasOwn(value, marker) ? { [marker]: [CodecTag.Object, entries] } : Object.fromEntries(entries);
|
|
44
|
+
} finally {
|
|
45
|
+
visiting.delete(value);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function unpack(value) {
|
|
49
|
+
if (value === null || typeof value !== "object") {
|
|
50
|
+
if (typeof value === "number" && Number.isInteger(value) && !Number.isSafeInteger(value))
|
|
51
|
+
refuse(Errors2.Invalid.JsonNumber);
|
|
52
|
+
return value;
|
|
53
|
+
}
|
|
54
|
+
if (Array.isArray(value))
|
|
55
|
+
return value.map(unpack);
|
|
56
|
+
if (Object.hasOwn(value, marker)) {
|
|
57
|
+
const tag = value[marker];
|
|
58
|
+
if (Object.keys(value).length !== 1 || !Array.isArray(tag) || tag.length !== 2)
|
|
59
|
+
refuse(Errors2.Invalid.JsonTag);
|
|
60
|
+
const [type, data] = tag;
|
|
61
|
+
if (type === CodecTag.Bigint && typeof data === "string" && /^-?(0|[1-9]\d*)$/.test(data))
|
|
62
|
+
return BigInt(data);
|
|
63
|
+
if (type === CodecTag.Bytes && Array.isArray(data) && data.every((v) => Number.isInteger(v) && v >= 0 && v <= 255))
|
|
64
|
+
return Uint8Array.from(data);
|
|
65
|
+
if (type === CodecTag.Object && Array.isArray(data)) {
|
|
66
|
+
if (!data.every((entry) => Array.isArray(entry) && entry.length === 2 && typeof entry[0] === "string"))
|
|
67
|
+
refuse(Errors2.Invalid.JsonTag);
|
|
68
|
+
return Object.fromEntries(data.map(([key, child]) => [key, unpack(child)]));
|
|
69
|
+
}
|
|
70
|
+
refuse(Errors2.Invalid.JsonTag, "Unknown or malformed portable type tag");
|
|
71
|
+
}
|
|
72
|
+
return Object.fromEntries(Object.entries(value).map(([key, child]) => [key, unpack(child)]));
|
|
73
|
+
}
|
|
74
|
+
function utf8(text) {
|
|
75
|
+
const output = [];
|
|
76
|
+
for (const character of text) {
|
|
77
|
+
let point = character.codePointAt(0);
|
|
78
|
+
if (point >= 55296 && point <= 57343)
|
|
79
|
+
point = 65533;
|
|
80
|
+
if (point < 128)
|
|
81
|
+
output.push(point);
|
|
82
|
+
else if (point < 2048)
|
|
83
|
+
output.push(192 | point >> 6, 128 | point & 63);
|
|
84
|
+
else if (point < 65536)
|
|
85
|
+
output.push(224 | point >> 12, 128 | point >> 6 & 63, 128 | point & 63);
|
|
86
|
+
else
|
|
87
|
+
output.push(240 | point >> 18, 128 | point >> 12 & 63, 128 | point >> 6 & 63, 128 | point & 63);
|
|
88
|
+
}
|
|
89
|
+
return Uint8Array.from(output);
|
|
90
|
+
}
|
|
91
|
+
function text(bytes) {
|
|
92
|
+
const output = [];
|
|
93
|
+
for (let index = 0;index < bytes.length; ) {
|
|
94
|
+
const first = bytes[index++];
|
|
95
|
+
if (first < 128) {
|
|
96
|
+
output.push(String.fromCharCode(first));
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
const count = first >= 194 && first <= 223 ? 1 : first >= 224 && first <= 239 ? 2 : first >= 240 && first <= 244 ? 3 : -1;
|
|
100
|
+
if (count < 0 || index + count > bytes.length)
|
|
101
|
+
refuse(Errors2.Invalid.Utf8);
|
|
102
|
+
let point = first & 127 >> count + 1;
|
|
103
|
+
for (let offset = 0;offset < count; offset++) {
|
|
104
|
+
const next = bytes[index++];
|
|
105
|
+
if ((next & 192) !== 128)
|
|
106
|
+
refuse(Errors2.Invalid.Utf8);
|
|
107
|
+
point = point << 6 | next & 63;
|
|
108
|
+
}
|
|
109
|
+
if (point < [0, 128, 2048, 65536][count] || point > 1114111 || point >= 55296 && point <= 57343)
|
|
110
|
+
refuse(Errors2.Invalid.Utf8);
|
|
111
|
+
output.push(String.fromCodePoint(point));
|
|
112
|
+
}
|
|
113
|
+
return output.join("");
|
|
114
|
+
}
|
|
115
|
+
var jsonCodec2 = Object.freeze({
|
|
116
|
+
id: CodecId.Json,
|
|
117
|
+
serialize: (value) => utf8(JSON.stringify(pack(value, new WeakSet))),
|
|
118
|
+
deserialize: (bytes) => unpack(JSON.parse(text(bytes)))
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
export { utf8, text, jsonCodec2 };
|