@opencode/codemode 2.1.4 → 2.2.1
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 +33 -4
- package/dist/codemode.d.ts +9 -7
- package/dist/codemode.js +1 -1
- package/dist/data.d.ts +5 -4
- package/dist/data.js +7 -4
- package/dist/extension.d.ts +17 -4
- package/dist/extension.js +8 -0
- package/dist/interpreter/callback.d.ts +10 -10
- package/dist/interpreter/callback.js +43 -31
- package/dist/interpreter/errors.d.ts +1 -1
- package/dist/interpreter/errors.js +12 -15
- package/dist/interpreter/execute.js +59 -29
- package/dist/interpreter/extensions.d.ts +2 -2
- package/dist/interpreter/extensions.js +46 -18
- package/dist/interpreter/generators.js +162 -19
- package/dist/interpreter/globals.js +12 -9
- package/dist/interpreter/interpreter.d.ts +20 -13
- package/dist/interpreter/interpreter.js +1329 -1147
- package/dist/interpreter/intrinsics.js +1 -2
- package/dist/interpreter/model.d.ts +4 -7
- package/dist/interpreter/model.js +1 -11
- package/dist/interpreter/native.d.ts +7 -8
- package/dist/interpreter/native.js +4 -10
- package/dist/interpreter/objects.d.ts +47 -21
- package/dist/interpreter/objects.js +33 -12
- package/dist/interpreter/promises.d.ts +15 -53
- package/dist/interpreter/promises.js +226 -401
- package/dist/interpreter/runner.d.ts +188 -0
- package/dist/interpreter/runner.js +492 -0
- package/dist/stdlib/array.d.ts +3 -3
- package/dist/stdlib/array.js +106 -102
- package/dist/stdlib/bytes.d.ts +3 -3
- package/dist/stdlib/bytes.js +46 -41
- package/dist/stdlib/collections.d.ts +5 -5
- package/dist/stdlib/collections.js +160 -165
- package/dist/stdlib/date.d.ts +1 -1
- package/dist/stdlib/date.js +28 -20
- package/dist/stdlib/headers.d.ts +1 -1
- package/dist/stdlib/headers.js +14 -19
- package/dist/stdlib/iterator.d.ts +1 -1
- package/dist/stdlib/iterator.js +140 -122
- package/dist/stdlib/json.js +9 -12
- package/dist/stdlib/math.js +10 -10
- package/dist/stdlib/number.d.ts +2 -2
- package/dist/stdlib/object.d.ts +1 -1
- package/dist/stdlib/object.js +21 -22
- package/dist/stdlib/regexp.d.ts +1 -1
- package/dist/stdlib/regexp.js +2 -3
- package/dist/stdlib/string.d.ts +1 -1
- package/dist/stdlib/string.js +18 -20
- package/dist/stdlib/url.d.ts +5 -5
- package/dist/stdlib/url.js +32 -33
- package/dist/stdlib/value.d.ts +2 -2
- package/dist/stdlib/web.d.ts +2 -2
- package/package.json +2 -1
package/dist/stdlib/string.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Effect } from "effect";
|
|
2
1
|
import { constructor, fn, methods } from "../interpreter/native.js";
|
|
3
2
|
import { checkArrayLength, checkStringLength } from "../interpreter/limits.js";
|
|
4
3
|
import { invalidData, IteratorSymbol, rangeError, typeError } from "../interpreter/model.js";
|
|
@@ -19,7 +18,7 @@ const replaceAllNeedsGlobal = (pattern) => {
|
|
|
19
18
|
throw typeError(`String.replaceAll requires a regular expression with the global (g) flag: write /${pattern.source}/${pattern.flags}g, or use String.replace to replace only the first match.`);
|
|
20
19
|
}
|
|
21
20
|
};
|
|
22
|
-
|
|
21
|
+
function* replaceWithCallback(ctx, value, name, args) {
|
|
23
22
|
const builtins = ctx.builtins;
|
|
24
23
|
const apply = applyCollectionCallback(ctx, args[1], `String.${name}`);
|
|
25
24
|
const matches = [];
|
|
@@ -51,18 +50,16 @@ const replaceWithCallback = (ctx, value, name, args) => {
|
|
|
51
50
|
else
|
|
52
51
|
value.replaceAll(search, collect);
|
|
53
52
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
});
|
|
65
|
-
};
|
|
53
|
+
const output = [];
|
|
54
|
+
let end = 0;
|
|
55
|
+
for (const match of matches) {
|
|
56
|
+
const replacement = yield* apply(match.args);
|
|
57
|
+
output.push(value.slice(end, match.offset), coerceToString(replacement));
|
|
58
|
+
end = match.offset + match.match.length;
|
|
59
|
+
}
|
|
60
|
+
output.push(value.slice(end));
|
|
61
|
+
return output.join("");
|
|
62
|
+
}
|
|
66
63
|
export const stringGlobal = (ctx) => {
|
|
67
64
|
const builtins = ctx.builtins;
|
|
68
65
|
const string = constructor(builtins, builtins.String, {
|
|
@@ -81,7 +78,7 @@ export const stringGlobal = (ctx) => {
|
|
|
81
78
|
[
|
|
82
79
|
"raw",
|
|
83
80
|
1,
|
|
84
|
-
(_, args)
|
|
81
|
+
function* (_, args) {
|
|
85
82
|
const template = args[0];
|
|
86
83
|
const raw = template instanceof Obj ? get(template, "raw") : undefined;
|
|
87
84
|
if (!(raw instanceof Obj))
|
|
@@ -90,11 +87,12 @@ export const stringGlobal = (ctx) => {
|
|
|
90
87
|
checkArrayLength(count);
|
|
91
88
|
// Each literal is followed by its substitution, except the last literal, or when substitutions run out.
|
|
92
89
|
const parts = Array.from({ length: count }, (_, index) => index + 1 < count && index + 1 < args.length ? [get(raw, index), args[index + 1]] : [get(raw, index)]).flat();
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
90
|
+
const strings = [];
|
|
91
|
+
for (const part of parts)
|
|
92
|
+
strings.push(yield* toPrimitiveString(ctx, part));
|
|
93
|
+
const output = strings.join("");
|
|
94
|
+
checkStringLength(output.length);
|
|
95
|
+
return output;
|
|
98
96
|
},
|
|
99
97
|
],
|
|
100
98
|
]);
|
package/dist/stdlib/url.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Eval } from "../interpreter/runner.js";
|
|
2
2
|
import { type Value } from "../interpreter/objects.js";
|
|
3
3
|
import type { Interpreter } from "../interpreter/interpreter.js";
|
|
4
4
|
type UriFunction = "encodeURI" | "encodeURIComponent" | "decodeURI" | "decodeURIComponent";
|
|
5
|
-
export declare const uriGlobal: <R>(ctx: Interpreter<R>, name: UriFunction) => import("../interpreter/objects.js").Native
|
|
6
|
-
export declare const urlGlobal: <R>(ctx: Interpreter<R>) => import("../interpreter/objects.js").Native
|
|
5
|
+
export declare const uriGlobal: <R>(ctx: Interpreter<R>, name: UriFunction) => import("../interpreter/objects.js").Native;
|
|
6
|
+
export declare const urlGlobal: <R>(ctx: Interpreter<R>) => import("../interpreter/objects.js").Native;
|
|
7
7
|
/**
|
|
8
8
|
* Reads a synchronous iterable of `[name, value]` pairs as strings; `undefined` when `init` is not iterable. As in
|
|
9
9
|
* WebIDL, the whole sequence is converted before any pair's length is checked.
|
|
10
10
|
*/
|
|
11
|
-
export declare
|
|
12
|
-
export declare const urlSearchParamsGlobal: <R>(ctx: Interpreter<R>) => import("../interpreter/objects.js").Native
|
|
11
|
+
export declare function readPairs<R>(ctx: Interpreter<R>, init: Value, label: string): Eval<Array<[string, string]> | undefined>;
|
|
12
|
+
export declare const urlSearchParamsGlobal: <R>(ctx: Interpreter<R>) => import("../interpreter/objects.js").Native;
|
|
13
13
|
export {};
|
package/dist/stdlib/url.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Effect } from "effect";
|
|
2
1
|
import { constructor, fn, methods, prototypeFrom, receiver, requiresNew } from "../interpreter/native.js";
|
|
3
2
|
import { IteratorSymbol, PendingThrow, typeError, uriError } from "../interpreter/model.js";
|
|
4
3
|
import { define, defineAccessor, entries, get, hidden, Arr, hostIterator, Obj, URLObj, URLSearchParamsObj, coerceToString, isRuntimeReference, } from "../interpreter/objects.js";
|
|
@@ -52,7 +51,7 @@ export const urlGlobal = (ctx) => {
|
|
|
52
51
|
name: "URL",
|
|
53
52
|
length: 1,
|
|
54
53
|
call: requiresNew("URL"),
|
|
55
|
-
construct: (args, newTarget) =>
|
|
54
|
+
construct: (args, newTarget) => construct(args, prototypeFrom(newTarget, proto)),
|
|
56
55
|
});
|
|
57
56
|
const parse = (name) => [
|
|
58
57
|
name,
|
|
@@ -95,29 +94,33 @@ export const urlGlobal = (ctx) => {
|
|
|
95
94
|
]);
|
|
96
95
|
return url;
|
|
97
96
|
};
|
|
98
|
-
|
|
97
|
+
function* readPair(ctx, value, label) {
|
|
99
98
|
const cursor = yield* ctx.iterate(value);
|
|
100
99
|
if (cursor === undefined)
|
|
101
100
|
throw typeError(`${label} expects iterable [name, value] pairs.`);
|
|
102
101
|
const items = [];
|
|
103
102
|
while (true) {
|
|
104
|
-
const step = yield* cursor.next;
|
|
103
|
+
const step = yield* cursor.next();
|
|
105
104
|
if (step.done)
|
|
106
105
|
return items;
|
|
107
|
-
items.push(yield* preserveConsumerError(cursor.close,
|
|
106
|
+
items.push(yield* preserveConsumerError(cursor.close, pairString(step.value)));
|
|
108
107
|
}
|
|
109
|
-
}
|
|
108
|
+
}
|
|
109
|
+
// A step, so a failing conversion closes the pair's iterator.
|
|
110
|
+
function* pairString(value) {
|
|
111
|
+
return coerceToString(value);
|
|
112
|
+
}
|
|
110
113
|
/**
|
|
111
114
|
* Reads a synchronous iterable of `[name, value]` pairs as strings; `undefined` when `init` is not iterable. As in
|
|
112
115
|
* WebIDL, the whole sequence is converted before any pair's length is checked.
|
|
113
116
|
*/
|
|
114
|
-
export
|
|
117
|
+
export function* readPairs(ctx, init, label) {
|
|
115
118
|
const cursor = yield* ctx.iterate(init);
|
|
116
119
|
if (cursor === undefined)
|
|
117
120
|
return undefined;
|
|
118
121
|
const pairs = [];
|
|
119
122
|
while (true) {
|
|
120
|
-
const step = yield* cursor.next;
|
|
123
|
+
const step = yield* cursor.next();
|
|
121
124
|
if (step.done) {
|
|
122
125
|
if (pairs.some((entry) => entry.length !== 2))
|
|
123
126
|
throw typeError(`${label} expects iterable [name, value] pairs.`);
|
|
@@ -125,31 +128,29 @@ export const readPairs = (ctx, init, label) => Effect.gen(function* () {
|
|
|
125
128
|
}
|
|
126
129
|
pairs.push(yield* preserveConsumerError(cursor.close, readPair(ctx, step.value, label)));
|
|
127
130
|
}
|
|
128
|
-
}
|
|
129
|
-
|
|
131
|
+
}
|
|
132
|
+
function* constructURLSearchParams(ctx, init, proto) {
|
|
130
133
|
const wrap = (params) => new URLSearchParamsObj(proto, params);
|
|
131
134
|
if (init === undefined)
|
|
132
|
-
return
|
|
135
|
+
return wrap(new URLSearchParams());
|
|
133
136
|
if (init instanceof URLSearchParamsObj)
|
|
134
|
-
return
|
|
137
|
+
return wrap(new URLSearchParams(init.params));
|
|
135
138
|
if (typeof init === "string")
|
|
136
|
-
return
|
|
139
|
+
return wrap(new URLSearchParams(init));
|
|
137
140
|
if (init === null || typeof init === "number" || typeof init === "boolean") {
|
|
138
|
-
return
|
|
141
|
+
return wrap(new URLSearchParams(coerceToString(init)));
|
|
139
142
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
});
|
|
152
|
-
};
|
|
143
|
+
const pairs = yield* readPairs(ctx, init, "new URLSearchParams(...)");
|
|
144
|
+
if (pairs !== undefined)
|
|
145
|
+
return wrap(new URLSearchParams(pairs));
|
|
146
|
+
if (isRuntimeReference(init)) {
|
|
147
|
+
throw typeError("new URLSearchParams(...) expects a query string, data object, or synchronous iterable pairs.");
|
|
148
|
+
}
|
|
149
|
+
if (!(init instanceof Obj)) {
|
|
150
|
+
throw typeError("new URLSearchParams(...) expects a query string, data object, iterable pairs, or URLSearchParams.");
|
|
151
|
+
}
|
|
152
|
+
return wrap(new URLSearchParams(Object.fromEntries(entries(init).map(([key, value]) => [key, coerceToString(value)]))));
|
|
153
|
+
}
|
|
153
154
|
export const urlSearchParamsGlobal = (ctx) => {
|
|
154
155
|
const builtins = ctx.builtins;
|
|
155
156
|
const proto = builtins.URLSearchParams;
|
|
@@ -239,15 +240,13 @@ export const urlSearchParamsGlobal = (ctx) => {
|
|
|
239
240
|
[
|
|
240
241
|
"forEach",
|
|
241
242
|
1,
|
|
242
|
-
(thisValue, args)
|
|
243
|
+
function* (thisValue, args) {
|
|
243
244
|
requireArgs("forEach", args, 1);
|
|
244
245
|
const target = self(thisValue, "forEach");
|
|
245
246
|
const apply = applyCollectionCallback(ctx, args[0], "URLSearchParams.forEach");
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
return undefined;
|
|
250
|
-
});
|
|
247
|
+
for (const [key, value] of Array.from(target.params.entries()))
|
|
248
|
+
yield* apply([value, key, target], args[1]);
|
|
249
|
+
return undefined;
|
|
251
250
|
},
|
|
252
251
|
],
|
|
253
252
|
]);
|
package/dist/stdlib/value.d.ts
CHANGED
|
@@ -2,6 +2,6 @@ import { type Native, type Value } from "../interpreter/objects.js";
|
|
|
2
2
|
import type { Interpreter } from "../interpreter/interpreter.js";
|
|
3
3
|
export declare const compoundOperators: Set<string>;
|
|
4
4
|
export type Coercion = "Number" | "String" | "Boolean" | "parseInt" | "parseFloat" | "isFinite" | "isNaN";
|
|
5
|
-
export declare const coerce: <R>(ctx: Interpreter<R>, name: Coercion, args: Array<Value>) => import("
|
|
5
|
+
export declare const coerce: <R>(ctx: Interpreter<R>, name: Coercion, args: Array<Value>) => import("../interpreter/objects.js").NativeResult;
|
|
6
6
|
/** A global coercion function such as `Number` or `parseInt`. */
|
|
7
|
-
export declare const coercion: <R>(ctx: Interpreter<R>, name: Coercion, length?: number) => Native
|
|
7
|
+
export declare const coercion: <R>(ctx: Interpreter<R>, name: Coercion, length?: number) => Native;
|
package/dist/stdlib/web.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Obj } from "../interpreter/objects.js";
|
|
2
2
|
import type { Interpreter } from "../interpreter/interpreter.js";
|
|
3
|
-
export declare const base64Global: <R>(ctx: Interpreter<R>, name: "atob" | "btoa") => import("../interpreter/objects.js").Native
|
|
4
|
-
export declare const structuredCloneGlobal: <R>(ctx: Interpreter<R>) => import("../interpreter/objects.js").Native
|
|
3
|
+
export declare const base64Global: <R>(ctx: Interpreter<R>, name: "atob" | "btoa") => import("../interpreter/objects.js").Native;
|
|
4
|
+
export declare const structuredCloneGlobal: <R>(ctx: Interpreter<R>) => import("../interpreter/objects.js").Native;
|
|
5
5
|
export declare const cryptoGlobal: <R>(ctx: Interpreter<R>) => Obj;
|
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": "2.1
|
|
4
|
+
"version": "2.2.1",
|
|
5
5
|
"description": "Effect-native confined code execution over schema-described tools",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"license": "MIT",
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
},
|
|
25
25
|
"scripts": {
|
|
26
26
|
"build": "bun run script/build.ts",
|
|
27
|
+
"pack": "bun run script/pack.ts",
|
|
27
28
|
"typecheck": "bun check --no-script",
|
|
28
29
|
"typecheck:tsc": "tsc --noEmit",
|
|
29
30
|
"test": "bun test"
|