@opencode/codemode 0.0.0-dev-19402 → 0.0.0-dev-19404
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.
|
@@ -3,4 +3,5 @@ export declare const isRuntimeReference: (value: unknown) => boolean;
|
|
|
3
3
|
export declare const containsRuntimeReference: (value: unknown) => boolean;
|
|
4
4
|
export declare const containsOpaqueReference: (value: unknown) => boolean;
|
|
5
5
|
export declare const rejectCircularInsertion: (container: object, value: unknown, label: string, node: AstNode, seen?: Set<object>) => void;
|
|
6
|
+
export declare const describeValue: (value: unknown) => string;
|
|
6
7
|
export declare const typeofValue: (value: unknown) => string;
|
|
@@ -50,6 +50,35 @@ export const rejectCircularInsertion = (container, value, label, node, seen = ne
|
|
|
50
50
|
throw new InterpreterRuntimeError(`${label} contains a circular value.`, node, "InvalidDataValue");
|
|
51
51
|
}
|
|
52
52
|
};
|
|
53
|
+
export const describeValue = (value) => {
|
|
54
|
+
if (value === null)
|
|
55
|
+
return "null";
|
|
56
|
+
if (Array.isArray(value))
|
|
57
|
+
return "an array";
|
|
58
|
+
if (value instanceof Values.Promise)
|
|
59
|
+
return "an un-awaited Promise";
|
|
60
|
+
if (value instanceof ToolReference)
|
|
61
|
+
return "a tool reference";
|
|
62
|
+
if (value instanceof Values.Date)
|
|
63
|
+
return "a Date";
|
|
64
|
+
if (value instanceof Values.RegExp)
|
|
65
|
+
return "a RegExp";
|
|
66
|
+
if (value instanceof Values.Map)
|
|
67
|
+
return "a Map";
|
|
68
|
+
if (value instanceof Values.Set)
|
|
69
|
+
return "a Set";
|
|
70
|
+
if (value instanceof Values.URL)
|
|
71
|
+
return "a URL";
|
|
72
|
+
if (value instanceof Values.URLSearchParams)
|
|
73
|
+
return "a URLSearchParams";
|
|
74
|
+
if (value instanceof CodeModeGenerator)
|
|
75
|
+
return "a generator";
|
|
76
|
+
if (isRuntimeReference(value))
|
|
77
|
+
return "a function";
|
|
78
|
+
if (typeof value === "object")
|
|
79
|
+
return "a data object";
|
|
80
|
+
return `a ${typeof value}`;
|
|
81
|
+
};
|
|
53
82
|
export const typeofValue = (value) => {
|
|
54
83
|
if (value instanceof HostFunction ||
|
|
55
84
|
value instanceof CodeModeFunction ||
|
|
@@ -8,7 +8,7 @@ import { HostFunction, HostNamespace } from "./host.js";
|
|
|
8
8
|
import { invokeIntrinsic } from "./methods.js";
|
|
9
9
|
import { preserveConsumerError } from "./runner.js";
|
|
10
10
|
import { invokePromiseInstanceMethod, PromiseRuntime, resolvePromise, resolvePromiseValue } from "./promises.js";
|
|
11
|
-
import { containsOpaqueReference, isRuntimeReference, rejectCircularInsertion, typeofValue } from "./references.js";
|
|
11
|
+
import { containsOpaqueReference, describeValue, isRuntimeReference, rejectCircularInsertion, typeofValue, } from "./references.js";
|
|
12
12
|
import { ScopeStack } from "./scope.js";
|
|
13
13
|
import { arrayMethods, mapMethods, setMethods } from "../stdlib/collections.js";
|
|
14
14
|
import { dateMethods } from "../stdlib/date.js";
|
|
@@ -804,7 +804,7 @@ class Frame {
|
|
|
804
804
|
}
|
|
805
805
|
if (pattern.type === "ObjectPattern") {
|
|
806
806
|
if (value === null || typeof value !== "object" || isRuntimeReference(value)) {
|
|
807
|
-
throw new InterpreterRuntimeError(
|
|
807
|
+
throw new InterpreterRuntimeError(`Object destructuring requires a data object or array value, received ${describeValue(value)}.`, pattern, "InvalidDataValue");
|
|
808
808
|
}
|
|
809
809
|
const consumed = new Set();
|
|
810
810
|
for (const property of pattern.properties) {
|
|
@@ -851,7 +851,7 @@ class Frame {
|
|
|
851
851
|
}
|
|
852
852
|
if (pattern.type === "ObjectPattern") {
|
|
853
853
|
if (value === null || typeof value !== "object" || isRuntimeReference(value)) {
|
|
854
|
-
throw new InterpreterRuntimeError(
|
|
854
|
+
throw new InterpreterRuntimeError(`Object destructuring requires a data object or array value, received ${describeValue(value)}.`, pattern, "InvalidDataValue");
|
|
855
855
|
}
|
|
856
856
|
const source = value;
|
|
857
857
|
const consumed = new Set();
|
|
@@ -1575,7 +1575,7 @@ class Frame {
|
|
|
1575
1575
|
if (spread === null || spread === undefined || Values.isValue(spread))
|
|
1576
1576
|
continue;
|
|
1577
1577
|
if (typeof spread !== "object" || Array.isArray(spread) || isRuntimeReference(spread)) {
|
|
1578
|
-
throw new InterpreterRuntimeError(
|
|
1578
|
+
throw new InterpreterRuntimeError(`Object spread requires a data object, received ${describeValue(spread)}.`, property, "InvalidDataValue");
|
|
1579
1579
|
}
|
|
1580
1580
|
for (const [key, value] of Object.entries(spread)) {
|
|
1581
1581
|
if (isBlockedMember(key))
|
|
@@ -1781,7 +1781,7 @@ class Frame {
|
|
|
1781
1781
|
return new ComputedValue(undefined);
|
|
1782
1782
|
}
|
|
1783
1783
|
if (isRuntimeReference(objectValue)) {
|
|
1784
|
-
throw new InterpreterRuntimeError(
|
|
1784
|
+
throw new InterpreterRuntimeError(`Cannot read properties of ${describeValue(objectValue)}; only data values expose properties.`, objectNode, "InvalidDataValue");
|
|
1785
1785
|
}
|
|
1786
1786
|
if (typeof objectValue !== "object" || objectValue === null) {
|
|
1787
1787
|
throw new InterpreterRuntimeError("Cannot access a property on a non-object value.", objectNode);
|
package/dist/stdlib/array.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
2
|
import { HostFunction, sync, syncCall } from "../interpreter/host.js";
|
|
3
3
|
import { CodeModeGenerator, InterpreterRuntimeError } from "../interpreter/model.js";
|
|
4
|
+
import { describeValue } from "../interpreter/references.js";
|
|
4
5
|
import { applyCollectionCallback, preserveConsumerError } from "../interpreter/runner.js";
|
|
5
|
-
import { Values } from "../values.js";
|
|
6
6
|
const constructArray = (args, node) => {
|
|
7
7
|
if (args.length !== 1)
|
|
8
8
|
return [...args];
|
|
@@ -16,9 +16,6 @@ const constructArray = (args, node) => {
|
|
|
16
16
|
return new Array(first);
|
|
17
17
|
};
|
|
18
18
|
const arrayLikeSource = (source, node) => {
|
|
19
|
-
if (source instanceof Values.Promise) {
|
|
20
|
-
throw new InterpreterRuntimeError("Array.from received an un-awaited Promise; await it before creating the array.", node, "InvalidDataValue");
|
|
21
|
-
}
|
|
22
19
|
if (source !== null &&
|
|
23
20
|
typeof source === "object" &&
|
|
24
21
|
(Object.getPrototypeOf(source) === Object.prototype || Object.getPrototypeOf(source) === null) &&
|
|
@@ -29,7 +26,7 @@ const arrayLikeSource = (source, node) => {
|
|
|
29
26
|
throw new RangeError("Invalid array length");
|
|
30
27
|
return { length: normalized, source };
|
|
31
28
|
}
|
|
32
|
-
throw new InterpreterRuntimeError(
|
|
29
|
+
throw new InterpreterRuntimeError(`Array.from expects an array, string, Map, Set, or array-like value, received ${describeValue(source)}.`, node, "InvalidDataValue");
|
|
33
30
|
};
|
|
34
31
|
const arrayFrom = (runner, args, node) => {
|
|
35
32
|
const source = args[0];
|
|
@@ -2,7 +2,7 @@ import { Effect } from "effect";
|
|
|
2
2
|
import { isBlockedMember } from "../data.js";
|
|
3
3
|
import { HostFunction, requiresNew } from "../interpreter/host.js";
|
|
4
4
|
import { InterpreterRuntimeError, isRecord } from "../interpreter/model.js";
|
|
5
|
-
import { isRuntimeReference } from "../interpreter/references.js";
|
|
5
|
+
import { describeValue, isRuntimeReference } from "../interpreter/references.js";
|
|
6
6
|
import { applyCollectionCallback, preserveConsumerError, toPrimitive } from "../interpreter/runner.js";
|
|
7
7
|
import { Values } from "../values.js";
|
|
8
8
|
import { coerceToString } from "./value.js";
|
|
@@ -66,7 +66,7 @@ const coerceGroupByPropertyKey = (runner, value, node) => {
|
|
|
66
66
|
if (value instanceof Values.Promise)
|
|
67
67
|
return Effect.succeed("[object Promise]");
|
|
68
68
|
if (!Values.isValue(value) && isRuntimeReference(value)) {
|
|
69
|
-
throw new InterpreterRuntimeError(
|
|
69
|
+
throw new InterpreterRuntimeError(`Object.groupBy callback must return a data value, received ${describeValue(value)}.`, node, "InvalidDataValue");
|
|
70
70
|
}
|
|
71
71
|
return Effect.map(toPrimitive(runner, value, "string", node), coerceToString);
|
|
72
72
|
};
|
package/dist/stdlib/object.js
CHANGED
|
@@ -2,7 +2,7 @@ import { Effect } from "effect";
|
|
|
2
2
|
import { isBlockedMember, toProgram } from "../data.js";
|
|
3
3
|
import { HostFunction, sync, syncCall } from "../interpreter/host.js";
|
|
4
4
|
import { AsyncIteratorSymbol, InterpreterRuntimeError, IteratorSymbol } from "../interpreter/model.js";
|
|
5
|
-
import { containsOpaqueReference, rejectCircularInsertion, typeofValue } from "../interpreter/references.js";
|
|
5
|
+
import { containsOpaqueReference, describeValue, rejectCircularInsertion, typeofValue, } from "../interpreter/references.js";
|
|
6
6
|
import { preserveConsumerError } from "../interpreter/runner.js";
|
|
7
7
|
import { ToolReference } from "../tool-runtime.js";
|
|
8
8
|
import { Values } from "../values.js";
|
|
@@ -13,15 +13,9 @@ const requireObject = (name, input, node) => {
|
|
|
13
13
|
return input;
|
|
14
14
|
if (Values.isValue(input))
|
|
15
15
|
return {};
|
|
16
|
-
|
|
17
|
-
throw new InterpreterRuntimeError(`Object.${name} received an un-awaited Promise; await it before inspecting the result.`, node, "InvalidDataValue");
|
|
18
|
-
}
|
|
19
|
-
if (input === null || typeof input !== "object") {
|
|
20
|
-
throw new InterpreterRuntimeError(`Object.${name} expects a data object or array.`, node, "InvalidDataValue");
|
|
21
|
-
}
|
|
22
|
-
const prototype = Object.getPrototypeOf(input);
|
|
16
|
+
const prototype = input === null || typeof input !== "object" ? undefined : Object.getPrototypeOf(input);
|
|
23
17
|
if (prototype !== null && prototype !== Object.prototype) {
|
|
24
|
-
throw new InterpreterRuntimeError(`Object.${name} expects a data object or array.`, node, "InvalidDataValue");
|
|
18
|
+
throw new InterpreterRuntimeError(`Object.${name} expects a data object or array, received ${describeValue(input)}.`, node, "InvalidDataValue");
|
|
25
19
|
}
|
|
26
20
|
return input;
|
|
27
21
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "@opencode/codemode",
|
|
4
|
-
"version": "0.0.0-dev-
|
|
4
|
+
"version": "0.0.0-dev-19404",
|
|
5
5
|
"description": "Effect-native confined code execution over schema-described tools",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"license": "MIT",
|