@opencode/codemode 0.0.0-dev-19566 → 0.0.0-dev-19568
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 +8 -1
- package/dist/interpreter/errors.js +50 -33
- package/dist/interpreter/execute.js +2 -2
- package/dist/interpreter/generators.js +3 -3
- package/dist/interpreter/globals.js +6 -6
- package/dist/interpreter/model.d.ts +22 -13
- package/dist/interpreter/model.js +18 -13
- package/dist/interpreter/native.d.ts +4 -5
- package/dist/interpreter/native.js +9 -8
- package/dist/interpreter/objects.d.ts +7 -5
- package/dist/interpreter/objects.js +3 -1
- package/dist/interpreter/promises.d.ts +2 -4
- package/dist/interpreter/promises.js +46 -46
- package/dist/interpreter/references.d.ts +1 -2
- package/dist/interpreter/references.js +3 -3
- package/dist/interpreter/runner.d.ts +6 -7
- package/dist/interpreter/runner.js +10 -10
- package/dist/interpreter/runtime.js +86 -79
- package/dist/interpreter/scope.js +6 -6
- package/dist/stdlib/array.d.ts +1 -2
- package/dist/stdlib/array.js +80 -84
- package/dist/stdlib/collections.js +57 -57
- package/dist/stdlib/date.js +21 -21
- package/dist/stdlib/json.js +13 -13
- package/dist/stdlib/math.js +11 -15
- package/dist/stdlib/number.js +21 -25
- package/dist/stdlib/object.d.ts +2 -2
- package/dist/stdlib/object.js +32 -36
- package/dist/stdlib/regexp.d.ts +2 -3
- package/dist/stdlib/regexp.js +15 -15
- package/dist/stdlib/string.js +69 -65
- package/dist/stdlib/url.js +55 -55
- package/dist/stdlib/value.js +4 -4
- package/dist/stdlib/web.js +4 -4
- package/package.json +1 -1
package/dist/stdlib/url.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
2
|
import { toProgram, ToolRuntimeError } from "../data.js";
|
|
3
3
|
import { constructor, fn, methods, prototypeFrom, receiver, requiresNew } from "../interpreter/native.js";
|
|
4
|
-
import {
|
|
4
|
+
import { PendingThrow, typeError, uriError } from "../interpreter/model.js";
|
|
5
5
|
import { defineAccessor, entries, isWrapper, ProgramArray, ProgramObject, ProgramURL, ProgramURLSearchParams, } from "../interpreter/objects.js";
|
|
6
6
|
import { isRuntimeReference } from "../interpreter/references.js";
|
|
7
7
|
import { applyCollectionCallback, preserveConsumerError } from "../interpreter/runner.js";
|
|
@@ -26,22 +26,22 @@ const uriFunctions = {
|
|
|
26
26
|
decodeURI,
|
|
27
27
|
decodeURIComponent,
|
|
28
28
|
};
|
|
29
|
-
export const uriGlobal = (runner, name) => fn(runner.prototypes, name, 1, (_, args
|
|
29
|
+
export const uriGlobal = (runner, name) => fn(runner.prototypes, name, 1, (_, args) => {
|
|
30
30
|
const value = uriArgument(runner.prototypes, args[0], `${name} input`);
|
|
31
31
|
try {
|
|
32
32
|
return uriFunctions[name](value);
|
|
33
33
|
}
|
|
34
34
|
catch (error) {
|
|
35
|
-
throw uriError(`${name} received malformed URI data: ${error instanceof Error ? error.message : String(error)}
|
|
35
|
+
throw uriError(`${name} received malformed URI data: ${error instanceof Error ? error.message : String(error)}`);
|
|
36
36
|
}
|
|
37
37
|
});
|
|
38
38
|
const urlArgument = (protos, value, label) => value instanceof ProgramURL ? value.url.href : uriArgument(protos, value, label);
|
|
39
39
|
export const urlGlobal = (runner) => {
|
|
40
40
|
const protos = runner.prototypes;
|
|
41
41
|
const proto = protos.URL;
|
|
42
|
-
const construct = (args, into
|
|
42
|
+
const construct = (args, into) => {
|
|
43
43
|
if (args.length === 0) {
|
|
44
|
-
throw
|
|
44
|
+
throw typeError("new URL(...) requires a URL string and an optional base URL.");
|
|
45
45
|
}
|
|
46
46
|
const input = urlArgument(protos, args[0], "new URL input");
|
|
47
47
|
const base = args[1] === undefined ? undefined : urlArgument(protos, args[1], "new URL base");
|
|
@@ -49,21 +49,21 @@ export const urlGlobal = (runner) => {
|
|
|
49
49
|
return new ProgramURL(into, protos.URLSearchParams, new URL(input, base));
|
|
50
50
|
}
|
|
51
51
|
catch {
|
|
52
|
-
throw
|
|
52
|
+
throw typeError(`new URL(...) received an invalid URL${base === undefined ? "" : " or base URL"}.`);
|
|
53
53
|
}
|
|
54
54
|
};
|
|
55
55
|
const url = constructor(protos, proto, {
|
|
56
56
|
name: "URL",
|
|
57
57
|
length: 1,
|
|
58
58
|
call: requiresNew("URL"),
|
|
59
|
-
construct: (args, newTarget
|
|
59
|
+
construct: (args, newTarget) => Effect.sync(() => construct(args, prototypeFrom(newTarget, proto))),
|
|
60
60
|
});
|
|
61
61
|
const parse = (name) => [
|
|
62
62
|
name,
|
|
63
63
|
1,
|
|
64
|
-
(_, args
|
|
64
|
+
(_, args) => {
|
|
65
65
|
if (args.length === 0)
|
|
66
|
-
throw
|
|
66
|
+
throw typeError(`URL.${name} requires a URL argument.`);
|
|
67
67
|
const input = urlArgument(protos, args[0], `URL.${name} input`);
|
|
68
68
|
const base = args[1] === undefined ? undefined : urlArgument(protos, args[1], `URL.${name} base`);
|
|
69
69
|
try {
|
|
@@ -76,7 +76,7 @@ export const urlGlobal = (runner) => {
|
|
|
76
76
|
},
|
|
77
77
|
];
|
|
78
78
|
methods(protos, url, [parse("canParse"), parse("parse")]);
|
|
79
|
-
const self = (thisValue, name
|
|
79
|
+
const self = (thisValue, name) => receiver(ProgramURL, thisValue, `URL.prototype.${name}`);
|
|
80
80
|
for (const name of urlProperties) {
|
|
81
81
|
defineAccessor(proto, name, (thisValue) => self(thisValue, name).url[name], name === "origin"
|
|
82
82
|
? undefined
|
|
@@ -87,23 +87,23 @@ export const urlGlobal = (runner) => {
|
|
|
87
87
|
target.url[name] = uriArgument(protos, value, `URL.${name} value`);
|
|
88
88
|
}
|
|
89
89
|
catch (error) {
|
|
90
|
-
if (error instanceof
|
|
90
|
+
if (error instanceof PendingThrow || error instanceof ToolRuntimeError)
|
|
91
91
|
throw error;
|
|
92
|
-
throw
|
|
92
|
+
throw typeError(`URL.${name} received an invalid value.`);
|
|
93
93
|
}
|
|
94
94
|
});
|
|
95
95
|
}
|
|
96
96
|
defineAccessor(proto, "searchParams", (thisValue) => self(thisValue, "searchParams").searchParams);
|
|
97
97
|
methods(protos, proto, [
|
|
98
|
-
["toString", 0, (thisValue
|
|
99
|
-
["toJSON", 0, (thisValue
|
|
98
|
+
["toString", 0, (thisValue) => self(thisValue, "toString").url.href],
|
|
99
|
+
["toJSON", 0, (thisValue) => self(thisValue, "toJSON").url.href],
|
|
100
100
|
]);
|
|
101
101
|
return url;
|
|
102
102
|
};
|
|
103
|
-
const readPair = (runner, value
|
|
104
|
-
const cursor = yield* runner.syncIterator(value
|
|
103
|
+
const readPair = (runner, value) => Effect.gen(function* () {
|
|
104
|
+
const cursor = yield* runner.syncIterator(value);
|
|
105
105
|
if (cursor === undefined) {
|
|
106
|
-
throw
|
|
106
|
+
throw typeError("new URLSearchParams(...) expects iterable [name, value] pairs.");
|
|
107
107
|
}
|
|
108
108
|
const items = [];
|
|
109
109
|
while (true) {
|
|
@@ -113,7 +113,7 @@ const readPair = (runner, value, node) => Effect.gen(function* () {
|
|
|
113
113
|
items.push(yield* preserveConsumerError(cursor, Effect.sync(() => uriArgument(runner.prototypes, step.value, "URLSearchParams pair value"))));
|
|
114
114
|
}
|
|
115
115
|
});
|
|
116
|
-
const constructURLSearchParams = (runner, init, proto
|
|
116
|
+
const constructURLSearchParams = (runner, init, proto) => {
|
|
117
117
|
const wrap = (params) => new ProgramURLSearchParams(proto, params);
|
|
118
118
|
if (init === undefined)
|
|
119
119
|
return Effect.succeed(wrap(new URLSearchParams()));
|
|
@@ -125,27 +125,27 @@ const constructURLSearchParams = (runner, init, proto, node) => {
|
|
|
125
125
|
return Effect.succeed(wrap(new URLSearchParams(coerceToString(init))));
|
|
126
126
|
}
|
|
127
127
|
return Effect.gen(function* () {
|
|
128
|
-
const cursor = yield* runner.syncIterator(init
|
|
128
|
+
const cursor = yield* runner.syncIterator(init);
|
|
129
129
|
if (cursor !== undefined) {
|
|
130
130
|
const pairs = [];
|
|
131
131
|
while (true) {
|
|
132
132
|
const step = yield* cursor.next;
|
|
133
133
|
if (step.done) {
|
|
134
134
|
if (pairs.some((entry) => entry.length !== 2)) {
|
|
135
|
-
throw
|
|
135
|
+
throw typeError("new URLSearchParams(...) expects iterable [name, value] pairs.");
|
|
136
136
|
}
|
|
137
137
|
return wrap(new URLSearchParams(pairs.map((entry) => [entry[0] ?? "", entry[1] ?? ""])));
|
|
138
138
|
}
|
|
139
|
-
pairs.push(yield* preserveConsumerError(cursor, readPair(runner, step.value
|
|
139
|
+
pairs.push(yield* preserveConsumerError(cursor, readPair(runner, step.value)));
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
142
|
if (isRuntimeReference(init)) {
|
|
143
|
-
throw
|
|
143
|
+
throw typeError("new URLSearchParams(...) expects a query string, data object, or synchronous iterable pairs.");
|
|
144
144
|
}
|
|
145
145
|
if (isWrapper(init))
|
|
146
146
|
return wrap(new URLSearchParams());
|
|
147
147
|
if (!(init instanceof ProgramObject)) {
|
|
148
|
-
throw
|
|
148
|
+
throw typeError("new URLSearchParams(...) expects a query string, data object, iterable pairs, or URLSearchParams.");
|
|
149
149
|
}
|
|
150
150
|
return wrap(new URLSearchParams(Object.fromEntries(entries(init).map(([key, value]) => [key, coerceToString(value)]))));
|
|
151
151
|
});
|
|
@@ -156,14 +156,14 @@ export const urlSearchParamsGlobal = (runner) => {
|
|
|
156
156
|
const searchParams = constructor(protos, proto, {
|
|
157
157
|
name: "URLSearchParams",
|
|
158
158
|
call: requiresNew("URLSearchParams"),
|
|
159
|
-
construct: (args, newTarget
|
|
159
|
+
construct: (args, newTarget) => constructURLSearchParams(runner, args[0], prototypeFrom(newTarget, proto)),
|
|
160
160
|
});
|
|
161
|
-
const self = (thisValue, name
|
|
161
|
+
const self = (thisValue, name) => receiver(ProgramURLSearchParams, thisValue, `URLSearchParams.prototype.${name}`);
|
|
162
162
|
const wrap = (items) => new ProgramArray(protos.Array, items);
|
|
163
163
|
const arg = (name, args, index) => uriArgument(protos, args[index], `URLSearchParams.${name} argument ${index + 1}`);
|
|
164
|
-
const requireArgs = (name, args, count
|
|
164
|
+
const requireArgs = (name, args, count) => {
|
|
165
165
|
if (args.length < count) {
|
|
166
|
-
throw
|
|
166
|
+
throw typeError(`URLSearchParams.${name} requires ${count} argument${count === 1 ? "" : "s"}.`);
|
|
167
167
|
}
|
|
168
168
|
};
|
|
169
169
|
defineAccessor(proto, "size", (thisValue) => self(thisValue, "size").params.size);
|
|
@@ -171,18 +171,18 @@ export const urlSearchParamsGlobal = (runner) => {
|
|
|
171
171
|
[
|
|
172
172
|
"append",
|
|
173
173
|
2,
|
|
174
|
-
(thisValue, args
|
|
175
|
-
requireArgs("append", args, 2
|
|
176
|
-
self(thisValue, "append"
|
|
174
|
+
(thisValue, args) => {
|
|
175
|
+
requireArgs("append", args, 2);
|
|
176
|
+
self(thisValue, "append").params.append(arg("append", args, 0), arg("append", args, 1));
|
|
177
177
|
return undefined;
|
|
178
178
|
},
|
|
179
179
|
],
|
|
180
180
|
[
|
|
181
181
|
"delete",
|
|
182
182
|
1,
|
|
183
|
-
(thisValue, args
|
|
184
|
-
requireArgs("delete", args, 1
|
|
185
|
-
const params = self(thisValue, "delete"
|
|
183
|
+
(thisValue, args) => {
|
|
184
|
+
requireArgs("delete", args, 1);
|
|
185
|
+
const params = self(thisValue, "delete").params;
|
|
186
186
|
if (args[1] !== undefined)
|
|
187
187
|
params.delete(arg("delete", args, 0), arg("delete", args, 1));
|
|
188
188
|
else
|
|
@@ -193,25 +193,25 @@ export const urlSearchParamsGlobal = (runner) => {
|
|
|
193
193
|
[
|
|
194
194
|
"get",
|
|
195
195
|
1,
|
|
196
|
-
(thisValue, args
|
|
197
|
-
requireArgs("get", args, 1
|
|
198
|
-
return self(thisValue, "get"
|
|
196
|
+
(thisValue, args) => {
|
|
197
|
+
requireArgs("get", args, 1);
|
|
198
|
+
return self(thisValue, "get").params.get(arg("get", args, 0));
|
|
199
199
|
},
|
|
200
200
|
],
|
|
201
201
|
[
|
|
202
202
|
"getAll",
|
|
203
203
|
1,
|
|
204
|
-
(thisValue, args
|
|
205
|
-
requireArgs("getAll", args, 1
|
|
206
|
-
return wrap(self(thisValue, "getAll"
|
|
204
|
+
(thisValue, args) => {
|
|
205
|
+
requireArgs("getAll", args, 1);
|
|
206
|
+
return wrap(self(thisValue, "getAll").params.getAll(arg("getAll", args, 0)));
|
|
207
207
|
},
|
|
208
208
|
],
|
|
209
209
|
[
|
|
210
210
|
"has",
|
|
211
211
|
1,
|
|
212
|
-
(thisValue, args
|
|
213
|
-
requireArgs("has", args, 1
|
|
214
|
-
const params = self(thisValue, "has"
|
|
212
|
+
(thisValue, args) => {
|
|
213
|
+
requireArgs("has", args, 1);
|
|
214
|
+
const params = self(thisValue, "has").params;
|
|
215
215
|
return args[1] !== undefined
|
|
216
216
|
? params.has(arg("has", args, 0), arg("has", args, 1))
|
|
217
217
|
: params.has(arg("has", args, 0));
|
|
@@ -220,35 +220,35 @@ export const urlSearchParamsGlobal = (runner) => {
|
|
|
220
220
|
[
|
|
221
221
|
"set",
|
|
222
222
|
2,
|
|
223
|
-
(thisValue, args
|
|
224
|
-
requireArgs("set", args, 2
|
|
225
|
-
self(thisValue, "set"
|
|
223
|
+
(thisValue, args) => {
|
|
224
|
+
requireArgs("set", args, 2);
|
|
225
|
+
self(thisValue, "set").params.set(arg("set", args, 0), arg("set", args, 1));
|
|
226
226
|
return undefined;
|
|
227
227
|
},
|
|
228
228
|
],
|
|
229
229
|
[
|
|
230
230
|
"sort",
|
|
231
231
|
0,
|
|
232
|
-
(thisValue
|
|
233
|
-
self(thisValue, "sort"
|
|
232
|
+
(thisValue) => {
|
|
233
|
+
self(thisValue, "sort").params.sort();
|
|
234
234
|
return undefined;
|
|
235
235
|
},
|
|
236
236
|
],
|
|
237
|
-
["keys", 0, (thisValue
|
|
238
|
-
["values", 0, (thisValue
|
|
237
|
+
["keys", 0, (thisValue) => wrap(Array.from(self(thisValue, "keys").params.keys()))],
|
|
238
|
+
["values", 0, (thisValue) => wrap(Array.from(self(thisValue, "values").params.values()))],
|
|
239
239
|
[
|
|
240
240
|
"entries",
|
|
241
241
|
0,
|
|
242
|
-
(thisValue
|
|
242
|
+
(thisValue) => wrap(Array.from(self(thisValue, "entries").params.entries(), ([key, value]) => wrap([key, value]))),
|
|
243
243
|
],
|
|
244
|
-
["toString", 0, (thisValue
|
|
244
|
+
["toString", 0, (thisValue) => self(thisValue, "toString").params.toString()],
|
|
245
245
|
[
|
|
246
246
|
"forEach",
|
|
247
247
|
1,
|
|
248
|
-
(thisValue, args
|
|
249
|
-
requireArgs("forEach", args, 1
|
|
250
|
-
const target = self(thisValue, "forEach"
|
|
251
|
-
const apply = applyCollectionCallback(runner, args[0], "URLSearchParams.forEach"
|
|
248
|
+
(thisValue, args) => {
|
|
249
|
+
requireArgs("forEach", args, 1);
|
|
250
|
+
const target = self(thisValue, "forEach");
|
|
251
|
+
const apply = applyCollectionCallback(runner, args[0], "URLSearchParams.forEach");
|
|
252
252
|
return Effect.gen(function* () {
|
|
253
253
|
for (const [key, value] of Array.from(target.params.entries()))
|
|
254
254
|
yield* apply([value, key, target]);
|
package/dist/stdlib/value.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { toProgram } from "../data.js";
|
|
2
2
|
import { fn } from "../interpreter/native.js";
|
|
3
|
-
import {
|
|
3
|
+
import { typeError } from "../interpreter/model.js";
|
|
4
4
|
import { get, isWrapper, ProgramArray, ProgramDate, ProgramError, ProgramMap, ProgramRegExp, ProgramSet, ProgramURL, ProgramURLSearchParams, } from "../interpreter/objects.js";
|
|
5
5
|
export const compoundOperators = new Set(["+=", "-=", "*=", "/=", "%=", "**=", "&=", "|=", "^=", "<<=", ">>=", ">>>="]);
|
|
6
6
|
/** The built-in string form of a value, without consulting program-defined `toString` methods. */
|
|
@@ -49,7 +49,7 @@ export const coerceToNumber = (value) => {
|
|
|
49
49
|
return Number(coerceToString(value));
|
|
50
50
|
return value !== null && typeof value === "object" ? Number.NaN : Number(value);
|
|
51
51
|
};
|
|
52
|
-
const coerce = (runner, name, args
|
|
52
|
+
const coerce = (runner, name, args) => {
|
|
53
53
|
// Native: Number() is 0 and String() is "", unlike their undefined-argument forms; the
|
|
54
54
|
// other coercers match native through the undefined-argument path below.
|
|
55
55
|
if (args.length === 0) {
|
|
@@ -86,7 +86,7 @@ const coerce = (runner, name, args, node) => {
|
|
|
86
86
|
if (name === "parseInt") {
|
|
87
87
|
const radix = args[1];
|
|
88
88
|
if (radix !== undefined && typeof radix !== "number") {
|
|
89
|
-
throw
|
|
89
|
+
throw typeError("parseInt expects a numeric radix.");
|
|
90
90
|
}
|
|
91
91
|
return parseInt(coerceToString(value), radix);
|
|
92
92
|
}
|
|
@@ -95,4 +95,4 @@ const coerce = (runner, name, args, node) => {
|
|
|
95
95
|
return coerceToString(value);
|
|
96
96
|
};
|
|
97
97
|
/** A global coercion function such as `Number` or `parseInt`. */
|
|
98
|
-
export const coercion = (runner, name, length = 1) => fn(runner.prototypes, name, length, (_, args
|
|
98
|
+
export const coercion = (runner, name, length = 1) => fn(runner.prototypes, name, length, (_, args) => toProgram(runner.prototypes, coerce(runner, name, args), `${name} result`));
|
package/dist/stdlib/web.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { fn, methods } from "../interpreter/native.js";
|
|
2
|
-
import {
|
|
2
|
+
import { typeError } from "../interpreter/model.js";
|
|
3
3
|
import { ProgramObject } from "../interpreter/objects.js";
|
|
4
4
|
import { coerceToString } from "./value.js";
|
|
5
5
|
// WebIDL DOMString conversion: a missing argument is a TypeError, anything else stringifies. Invalid input is a
|
|
6
6
|
// TypeError as well; browsers throw a DOMException named InvalidCharacterError, which CodeMode does not have.
|
|
7
|
-
export const base64Global = (runner, name) => fn(runner.prototypes, name, 1, (_, args
|
|
7
|
+
export const base64Global = (runner, name) => fn(runner.prototypes, name, 1, (_, args) => {
|
|
8
8
|
if (args.length === 0)
|
|
9
|
-
throw
|
|
9
|
+
throw typeError(`${name} requires 1 argument (a string)`);
|
|
10
10
|
const input = coerceToString(args[0]);
|
|
11
11
|
try {
|
|
12
12
|
return name === "atob" ? atob(input) : btoa(input);
|
|
13
13
|
}
|
|
14
14
|
catch {
|
|
15
|
-
throw
|
|
15
|
+
throw typeError("The string contains invalid characters.");
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
18
|
export const cryptoGlobal = (runner) => {
|
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-19568",
|
|
5
5
|
"description": "Effect-native confined code execution over schema-described tools",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"license": "MIT",
|