@opencode/codemode 0.0.0-beta-19365 → 0.0.0-beta-19381
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/dist/interpreter/errors.d.ts +4 -6
- package/dist/interpreter/errors.js +20 -4
- package/dist/interpreter/execute.js +2 -3
- package/dist/interpreter/globals.d.ts +13 -0
- package/dist/interpreter/globals.js +59 -0
- package/dist/interpreter/host.d.ts +41 -0
- package/dist/interpreter/host.js +44 -0
- package/dist/interpreter/methods.d.ts +3 -23
- package/dist/interpreter/methods.js +8 -183
- package/dist/interpreter/model.d.ts +0 -41
- package/dist/interpreter/model.js +0 -56
- package/dist/interpreter/promises.d.ts +7 -8
- package/dist/interpreter/promises.js +45 -22
- package/dist/interpreter/references.js +11 -28
- package/dist/interpreter/runner.d.ts +23 -0
- package/dist/interpreter/runner.js +42 -0
- package/dist/interpreter/runtime.d.ts +11 -92
- package/dist/interpreter/runtime.js +75 -452
- package/dist/stdlib/array.d.ts +3 -0
- package/dist/stdlib/array.js +73 -0
- package/dist/stdlib/collections.d.ts +6 -1
- package/dist/stdlib/collections.js +120 -1
- package/dist/stdlib/console.d.ts +3 -2
- package/dist/stdlib/console.js +11 -2
- package/dist/stdlib/date.d.ts +3 -2
- package/dist/stdlib/date.js +27 -11
- package/dist/stdlib/json.d.ts +4 -4
- package/dist/stdlib/json.js +6 -2
- package/dist/stdlib/math.d.ts +3 -7
- package/dist/stdlib/math.js +85 -153
- package/dist/stdlib/number.d.ts +1 -3
- package/dist/stdlib/number.js +28 -36
- package/dist/stdlib/object.d.ts +4 -6
- package/dist/stdlib/object.js +101 -71
- package/dist/stdlib/regexp.d.ts +2 -4
- package/dist/stdlib/regexp.js +32 -9
- package/dist/stdlib/string.d.ts +1 -3
- package/dist/stdlib/string.js +14 -16
- package/dist/stdlib/url.d.ts +8 -4
- package/dist/stdlib/url.js +97 -21
- package/dist/stdlib/value.d.ts +5 -3
- package/dist/stdlib/value.js +21 -19
- package/package.json +1 -1
- package/dist/interpreter/iterator.d.ts +0 -13
- package/dist/interpreter/iterator.js +0 -4
- package/dist/stdlib/promise.d.ts +0 -2
- package/dist/stdlib/promise.js +0 -1
package/dist/stdlib/value.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { sync } from "../interpreter/host.js";
|
|
2
|
+
import { InterpreterRuntimeError } from "../interpreter/model.js";
|
|
2
3
|
import { toProgram } from "../data.js";
|
|
3
4
|
import { Values } from "../values.js";
|
|
4
5
|
export const errorConstructors = new Set([
|
|
@@ -11,7 +12,6 @@ export const errorConstructors = new Set([
|
|
|
11
12
|
"URIError",
|
|
12
13
|
"AggregateError",
|
|
13
14
|
]);
|
|
14
|
-
export const valueConstructors = new Set(["Date", "RegExp", "Map", "Set", "URL", "URLSearchParams"]);
|
|
15
15
|
export const compoundOperators = new Set(["+=", "-=", "*=", "/=", "%=", "**=", "&=", "|=", "^=", "<<=", ">>=", ">>>="]);
|
|
16
16
|
const ErrorBrand = Symbol("codemode.error");
|
|
17
17
|
export const createErrorValue = (name, message) => {
|
|
@@ -69,51 +69,53 @@ export const coerceToNumber = (value) => {
|
|
|
69
69
|
return Number(coerceToString(value));
|
|
70
70
|
return value !== null && typeof value === "object" ? Number.NaN : Number(value);
|
|
71
71
|
};
|
|
72
|
-
|
|
72
|
+
const coerce = (name, args, node) => {
|
|
73
73
|
// Native: Number() is 0 and String() is "", unlike their undefined-argument forms; the
|
|
74
74
|
// other coercers match native through the undefined-argument path below.
|
|
75
75
|
if (args.length === 0) {
|
|
76
|
-
if (
|
|
76
|
+
if (name === "Number")
|
|
77
77
|
return 0;
|
|
78
|
-
if (
|
|
78
|
+
if (name === "String")
|
|
79
79
|
return "";
|
|
80
80
|
}
|
|
81
81
|
const raw = args[0];
|
|
82
82
|
// Error values are plain SafeObjects; the toProgram path below would strip their brand.
|
|
83
|
-
if (
|
|
83
|
+
if (name === "String" && errorBrandName(raw) !== undefined)
|
|
84
84
|
return coerceToString(raw);
|
|
85
85
|
if (Values.isValue(raw)) {
|
|
86
|
-
if (
|
|
86
|
+
if (name === "Boolean")
|
|
87
87
|
return true;
|
|
88
|
-
if (
|
|
88
|
+
if (name === "Number")
|
|
89
89
|
return coerceToNumber(raw);
|
|
90
|
-
if (
|
|
90
|
+
if (name === "String")
|
|
91
91
|
return coerceToString(raw);
|
|
92
|
-
if (
|
|
92
|
+
if (name === "isFinite")
|
|
93
93
|
return Number.isFinite(coerceToNumber(raw));
|
|
94
|
-
if (
|
|
94
|
+
if (name === "isNaN")
|
|
95
95
|
return Number.isNaN(coerceToNumber(raw));
|
|
96
|
-
if (
|
|
96
|
+
if (name === "parseInt")
|
|
97
97
|
return parseInt(coerceToString(raw));
|
|
98
98
|
return parseFloat(coerceToString(raw));
|
|
99
99
|
}
|
|
100
|
-
const value = toProgram(raw, `${
|
|
101
|
-
if (
|
|
100
|
+
const value = toProgram(raw, `${name} input`);
|
|
101
|
+
if (name === "Number")
|
|
102
102
|
return coerceToNumber(value);
|
|
103
|
-
if (
|
|
103
|
+
if (name === "Boolean")
|
|
104
104
|
return Boolean(value);
|
|
105
|
-
if (
|
|
105
|
+
if (name === "isFinite")
|
|
106
106
|
return Number.isFinite(coerceToNumber(value));
|
|
107
|
-
if (
|
|
107
|
+
if (name === "isNaN")
|
|
108
108
|
return Number.isNaN(coerceToNumber(value));
|
|
109
|
-
if (
|
|
109
|
+
if (name === "parseInt") {
|
|
110
110
|
const radix = args[1];
|
|
111
111
|
if (radix !== undefined && typeof radix !== "number") {
|
|
112
112
|
throw new InterpreterRuntimeError("parseInt expects a numeric radix.", node);
|
|
113
113
|
}
|
|
114
114
|
return parseInt(coerceToString(value), radix);
|
|
115
115
|
}
|
|
116
|
-
if (
|
|
116
|
+
if (name === "parseFloat")
|
|
117
117
|
return parseFloat(coerceToString(value));
|
|
118
118
|
return coerceToString(value);
|
|
119
119
|
};
|
|
120
|
+
/** A global coercion function such as `Number` or `parseInt`. */
|
|
121
|
+
export const coercion = (name, options = {}) => sync(name, (args, node) => toProgram(coerce(name, args, node), `${name} result`), options);
|
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-beta-
|
|
4
|
+
"version": "0.0.0-beta-19381",
|
|
5
5
|
"description": "Effect-native confined code execution over schema-described tools",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"license": "MIT",
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Effect } from "effect";
|
|
2
|
-
import type { AstNode } from "./model.js";
|
|
3
|
-
export type IteratorCursor<R> = {
|
|
4
|
-
readonly next: Effect.Effect<{
|
|
5
|
-
readonly done: boolean;
|
|
6
|
-
readonly value: unknown;
|
|
7
|
-
}, unknown, R>;
|
|
8
|
-
readonly close: Effect.Effect<void, unknown, R>;
|
|
9
|
-
};
|
|
10
|
-
export type SyncIteratorRunner<R> = {
|
|
11
|
-
readonly syncIterator: (value: unknown, node: AstNode) => Effect.Effect<IteratorCursor<R> | undefined, unknown, R>;
|
|
12
|
-
};
|
|
13
|
-
export declare const preserveConsumerError: <A, R>(cursor: IteratorCursor<R>, effect: Effect.Effect<A, unknown, R>) => Effect.Effect<A, unknown, R>;
|
package/dist/stdlib/promise.d.ts
DELETED
package/dist/stdlib/promise.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const promiseStatics = new Set(["all", "allSettled", "race", "any", "resolve", "reject"]);
|