@hew-lang/sandbox-vm 0.6.2 → 0.6.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/README.md +43 -4
- package/cli/test-runner.mjs +4 -1
- package/dist/interpreter/interpreter.d.ts +1 -1
- package/dist/interpreter/interpreter.js +1 -1
- package/dist/interpreter/parity-runner.js +1 -1
- package/dist/interpreter/run-program.d.ts +3 -2
- package/dist/interpreter/run-program.js +5 -3
- package/dist/interpreter/schema-validator.d.ts +9 -4
- package/dist/interpreter/schema-validator.js +15 -49
- package/dist/interpreter/types.d.ts +4 -0
- package/dist/interpreter/v1/browser-directory.d.ts +107 -0
- package/dist/interpreter/v1/browser-directory.js +288 -0
- package/dist/interpreter/v1/calendar.d.ts +4 -0
- package/dist/interpreter/v1/calendar.js +64 -0
- package/dist/interpreter/v1/codecs.js +2 -2
- package/dist/interpreter/v1/exec.d.ts +2 -2
- package/dist/interpreter/v1/exec.js +439 -183
- package/dist/interpreter/v1/instructions.generated.d.ts +1135 -0
- package/dist/interpreter/v1/instructions.generated.js +106 -0
- package/dist/interpreter/v1/package-graph.d.ts +2 -0
- package/dist/interpreter/v1/package-graph.js +729 -0
- package/dist/interpreter/v1/package-validator.generated.d.ts +3 -0
- package/dist/interpreter/v1/package-validator.generated.js +75902 -0
- package/dist/interpreter/v1/package.d.ts +5 -680
- package/dist/interpreter/v1/package.js +0 -12
- package/dist/interpreter/v1/scheduler.d.ts +5 -1
- package/dist/interpreter/v1/scheduler.js +32 -3
- package/dist/interpreter/v1/shims.d.ts +250 -7
- package/dist/interpreter/v1/shims.js +430 -150
- package/dist/interpreter/v1/structural.d.ts +2 -28
- package/dist/interpreter/v1/timestamp.d.ts +7 -0
- package/dist/interpreter/v1/timestamp.js +54 -0
- package/dist/interpreter/v1/validate.d.ts +8 -2
- package/dist/interpreter/v1/validate.js +190 -202
- package/dist/interpreter/v1/value-operations.d.ts +7 -2
- package/dist/interpreter/v1/value-operations.js +13 -6
- package/dist/interpreter/values.d.ts +4 -0
- package/dist/interpreter/values.js +6 -0
- package/dist/interpreter/worker.js +4 -3
- package/package.json +4 -4
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type VmValue } from "../values.js";
|
|
2
|
+
import type { AggregateShape } from "./package.js";
|
|
3
|
+
export declare function calendarResultFields(symbol: string): readonly string[] | undefined;
|
|
4
|
+
export declare function executeCalendar(bridge: ((request: string) => string) | undefined, symbol: string, args: VmValue[], shape: AggregateShape | null): VmValue;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { stringValue } from "../values.js";
|
|
2
|
+
const TIME_FIELDS = ["status", "seconds", "nanoseconds", "message"];
|
|
3
|
+
const CALENDAR_FIELDS = {
|
|
4
|
+
hew_calendar_format: ["status", "text", "message"],
|
|
5
|
+
hew_calendar_parse: TIME_FIELDS,
|
|
6
|
+
hew_calendar_from_parts: TIME_FIELDS,
|
|
7
|
+
hew_calendar_components: [
|
|
8
|
+
"status",
|
|
9
|
+
"year",
|
|
10
|
+
"month",
|
|
11
|
+
"day",
|
|
12
|
+
"hour",
|
|
13
|
+
"minute",
|
|
14
|
+
"second",
|
|
15
|
+
"nanosecond",
|
|
16
|
+
"weekday",
|
|
17
|
+
"days_in_month",
|
|
18
|
+
"message",
|
|
19
|
+
],
|
|
20
|
+
};
|
|
21
|
+
export function calendarResultFields(symbol) {
|
|
22
|
+
return CALENDAR_FIELDS[symbol];
|
|
23
|
+
}
|
|
24
|
+
export function executeCalendar(bridge, symbol, args, shape) {
|
|
25
|
+
if (!bridge)
|
|
26
|
+
throw new Error("calendar operations require the hew-wasm executeCalendar bridge");
|
|
27
|
+
const fields = calendarResultFields(symbol);
|
|
28
|
+
if (!shape ||
|
|
29
|
+
!fields ||
|
|
30
|
+
shape.fields.length !== fields.length ||
|
|
31
|
+
shape.fields.some((field, index) => field !== fields[index]))
|
|
32
|
+
throw new Error("calendar operation lacks its checked result shape");
|
|
33
|
+
const request = {
|
|
34
|
+
operation: symbol.slice("hew_calendar_".length),
|
|
35
|
+
args: args.map((value) => {
|
|
36
|
+
if (value.kind === "i64")
|
|
37
|
+
return value.value.toString();
|
|
38
|
+
if (value.kind === "string")
|
|
39
|
+
return value.value;
|
|
40
|
+
throw new Error("invalid calendar argument");
|
|
41
|
+
}),
|
|
42
|
+
};
|
|
43
|
+
const result = JSON.parse(bridge(JSON.stringify(request)));
|
|
44
|
+
if (typeof result.status !== "number" ||
|
|
45
|
+
![0, 1, 2, 3].includes(result.status) ||
|
|
46
|
+
typeof result.message !== "string")
|
|
47
|
+
throw new Error("calendar bridge returned an invalid result");
|
|
48
|
+
return {
|
|
49
|
+
kind: "record",
|
|
50
|
+
typeId: shape.name,
|
|
51
|
+
shape: shape.id,
|
|
52
|
+
fields: shape.fields.map((field) => {
|
|
53
|
+
const value = result[field];
|
|
54
|
+
if (result.status === 0 && value === undefined)
|
|
55
|
+
throw new Error("calendar bridge omitted a successful result field");
|
|
56
|
+
if (field === "message" || field === "text")
|
|
57
|
+
return stringValue(value === undefined ? "" : String(value));
|
|
58
|
+
return {
|
|
59
|
+
kind: "i64",
|
|
60
|
+
value: BigInt(value === undefined ? 0 : String(value)),
|
|
61
|
+
};
|
|
62
|
+
}),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
@@ -148,7 +148,7 @@ function* fromBridge(pkg, shape, id, value, context) {
|
|
|
148
148
|
}
|
|
149
149
|
if ("Map" in node || "Set" in node) {
|
|
150
150
|
const family = "Map" in node ? "Map" : "Set";
|
|
151
|
-
const map = yield* collectionOperation(pkg, family, "New", [], [], null);
|
|
151
|
+
const map = yield* collectionOperation(pkg, { handler: "collection", family, operation: "New" }, [], [], null);
|
|
152
152
|
for (const item of array(value)) {
|
|
153
153
|
const itemFields = array(item);
|
|
154
154
|
const pair = "Map" in node ? itemFields : [itemFields[0], null];
|
|
@@ -159,7 +159,7 @@ function* fromBridge(pkg, shape, id, value, context) {
|
|
|
159
159
|
if (map.kind !== "map")
|
|
160
160
|
throw new Error("codec collection has no map storage");
|
|
161
161
|
const size = map.entries.size;
|
|
162
|
-
yield* collectionOperation(pkg, family, "Insert", [map, key, member], context.callbacks[id] ?? [], null);
|
|
162
|
+
yield* collectionOperation(pkg, { handler: "collection", family, operation: "Insert" }, [map, key, member], context.callbacks[id] ?? [], null);
|
|
163
163
|
if (!context.propertyInput && map.entries.size === size)
|
|
164
164
|
throw new Duplicate(itemFields["Map" in node ? 2 : 1]);
|
|
165
165
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { RunOptions, SandboxTrace } from "../types.js";
|
|
2
|
-
import type {
|
|
3
|
-
export declare function runPackageV1(pkg:
|
|
2
|
+
import type { CheckedPackage } from "../schema-validator.js";
|
|
3
|
+
export declare function runPackageV1(pkg: CheckedPackage, options?: RunOptions): Promise<SandboxTrace>;
|