@opencode/codemode 2.0.32 → 2.1.0
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/stdlib/array.js +6 -4
- package/dist/stdlib/bytes.js +19 -14
- package/dist/stdlib/number.js +2 -7
- package/dist/stdlib/value.d.ts +1 -1
- package/dist/tool-runtime.d.ts +1 -1
- package/package.json +3 -3
package/dist/stdlib/array.js
CHANGED
|
@@ -335,10 +335,12 @@ export const arrayGlobal = (ctx) => {
|
|
|
335
335
|
if (!(index in target.items))
|
|
336
336
|
continue;
|
|
337
337
|
const mapped = yield* apply([target.items[index], index, target], args[1]);
|
|
338
|
-
if (mapped instanceof Arr)
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
338
|
+
if (mapped instanceof Arr) {
|
|
339
|
+
// forEach skips holes, as flattening does; spreading would turn them into undefined.
|
|
340
|
+
mapped.items.forEach((item) => values.push(item));
|
|
341
|
+
continue;
|
|
342
|
+
}
|
|
343
|
+
values.push(mapped);
|
|
342
344
|
}
|
|
343
345
|
return wrap(values);
|
|
344
346
|
});
|
package/dist/stdlib/bytes.js
CHANGED
|
@@ -4,10 +4,15 @@ import { constructor, methods, prototypeFrom, receiver, requiresNew } from "../i
|
|
|
4
4
|
import { IteratorSymbol, rangeError, syntaxError, typeError } from "../interpreter/model.js";
|
|
5
5
|
import { define, defineAccessor, get, hidden, Arr, Bytes, hostIterator, Obj, coerceToInteger, coerceToNumber, coerceToString, } from "../interpreter/objects.js";
|
|
6
6
|
import { describeValue } from "../interpreter/references.js";
|
|
7
|
+
import { applyCollectionCallback } from "../interpreter/callback.js";
|
|
7
8
|
import { callbackMethods, sortArray } from "./array.js";
|
|
8
|
-
/**
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
/**
|
|
10
|
+
* The bytes a Uint8Array, array, or other iterable of numbers describes; the host array clamps each value. As in
|
|
11
|
+
* TypedArray.from, a mapper sees the original values, after the source is consumed in full.
|
|
12
|
+
*/
|
|
13
|
+
const collectBytes = (ctx, source, name, mapper, thisArg) => {
|
|
14
|
+
const apply = mapper === undefined ? undefined : applyCollectionCallback(ctx, mapper, name);
|
|
15
|
+
if (source instanceof Bytes && apply === undefined)
|
|
11
16
|
return Effect.succeed(new Uint8Array(source.bytes));
|
|
12
17
|
return Effect.gen(function* () {
|
|
13
18
|
const cursor = yield* ctx.iterate(source);
|
|
@@ -18,10 +23,12 @@ const collectBytes = (ctx, source, name) => {
|
|
|
18
23
|
while (true) {
|
|
19
24
|
const step = yield* cursor.next;
|
|
20
25
|
if (step.done)
|
|
21
|
-
|
|
22
|
-
values.push(
|
|
26
|
+
break;
|
|
27
|
+
values.push(step.value);
|
|
23
28
|
checkArrayLength(values.length);
|
|
24
29
|
}
|
|
30
|
+
const mapped = apply === undefined ? values : yield* Effect.forEach(values, (value, index) => apply([value, index], thisArg));
|
|
31
|
+
return Uint8Array.from(mapped, coerceToNumber);
|
|
25
32
|
});
|
|
26
33
|
};
|
|
27
34
|
const constructBytes = (ctx, args, proto) => {
|
|
@@ -56,13 +63,15 @@ export const uint8ArrayGlobal = (ctx) => {
|
|
|
56
63
|
}
|
|
57
64
|
};
|
|
58
65
|
methods(builtins, uint8Array, [
|
|
59
|
-
["from", 1, (_, args) => Effect.map(collectBytes(ctx, args[0], "Uint8Array.from"), wrap)],
|
|
66
|
+
["from", 1, (_, args) => Effect.map(collectBytes(ctx, args[0], "Uint8Array.from", args[1], args[2]), wrap)],
|
|
60
67
|
["of", 0, (_, args) => wrap(Uint8Array.from(args, coerceToNumber))],
|
|
61
68
|
["fromBase64", 1, (_, args) => decode("fromBase64", args, (text) => Uint8Array.fromBase64(text))],
|
|
62
69
|
["fromHex", 1, (_, args) => decode("fromHex", args, (text) => Uint8Array.fromHex(text))],
|
|
63
70
|
]);
|
|
64
71
|
const self = (thisValue, name) => receiver(Bytes, thisValue, `Uint8Array.prototype.${name}`);
|
|
65
72
|
const optNumber = (value) => (value === undefined ? undefined : coerceToInteger(value));
|
|
73
|
+
// Uint8Array cannot contain NaN, so non-number search values never match a byte.
|
|
74
|
+
const search = (value) => (typeof value === "number" ? value : NaN);
|
|
66
75
|
const wrapAll = (items) => new Arr(builtins.Array, items);
|
|
67
76
|
defineAccessor(proto, "length", (thisValue) => self(thisValue, "length").bytes.length);
|
|
68
77
|
methods(builtins, proto, [
|
|
@@ -127,25 +136,21 @@ export const uint8ArrayGlobal = (ctx) => {
|
|
|
127
136
|
});
|
|
128
137
|
},
|
|
129
138
|
],
|
|
130
|
-
[
|
|
131
|
-
"indexOf",
|
|
132
|
-
1,
|
|
133
|
-
(thisValue, args) => self(thisValue, "indexOf").bytes.indexOf(coerceToNumber(args[0]), optNumber(args[1])),
|
|
134
|
-
],
|
|
139
|
+
["indexOf", 1, (thisValue, args) => self(thisValue, "indexOf").bytes.indexOf(search(args[0]), optNumber(args[1]))],
|
|
135
140
|
[
|
|
136
141
|
"lastIndexOf",
|
|
137
142
|
1,
|
|
138
143
|
(thisValue, args) => {
|
|
139
144
|
const target = self(thisValue, "lastIndexOf").bytes;
|
|
140
145
|
return args.length < 2
|
|
141
|
-
? target.lastIndexOf(
|
|
142
|
-
: target.lastIndexOf(
|
|
146
|
+
? target.lastIndexOf(search(args[0]))
|
|
147
|
+
: target.lastIndexOf(search(args[0]), optNumber(args[1]));
|
|
143
148
|
},
|
|
144
149
|
],
|
|
145
150
|
[
|
|
146
151
|
"includes",
|
|
147
152
|
1,
|
|
148
|
-
(thisValue, args) => self(thisValue, "includes").bytes.includes(
|
|
153
|
+
(thisValue, args) => self(thisValue, "includes").bytes.includes(search(args[0]), optNumber(args[1])),
|
|
149
154
|
],
|
|
150
155
|
[
|
|
151
156
|
"join",
|
package/dist/stdlib/number.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { constructor, constants, methods } from "../interpreter/native.js";
|
|
2
2
|
import { coerceToNumber } from "../interpreter/objects.js";
|
|
3
|
-
import {
|
|
3
|
+
import { typeError } from "../interpreter/model.js";
|
|
4
4
|
import { withPrimitives } from "../interpreter/callback.js";
|
|
5
5
|
import { coerce, coercion } from "./value.js";
|
|
6
6
|
export const numberGlobal = (ctx) => {
|
|
@@ -47,12 +47,7 @@ export const numberGlobal = (ctx) => {
|
|
|
47
47
|
["toLocaleString", 0, (thisValue) => self(thisValue, "toLocaleString").toLocaleString("en-US")],
|
|
48
48
|
formatting("toExponential", (value, digits) => value.toExponential(digits)),
|
|
49
49
|
formatting("toPrecision", (value, digits) => (digits === undefined ? value.toString() : value.toPrecision(digits))),
|
|
50
|
-
formatting("toString", (value, radix) =>
|
|
51
|
-
if (radix !== undefined && (radix < 2 || radix > 36)) {
|
|
52
|
-
throw rangeError("Number.toString radix must be between 2 and 36.");
|
|
53
|
-
}
|
|
54
|
-
return value.toString(radix);
|
|
55
|
-
}),
|
|
50
|
+
formatting("toString", (value, radix) => value.toString(radix)),
|
|
56
51
|
["valueOf", 0, (thisValue) => self(thisValue, "valueOf")],
|
|
57
52
|
]);
|
|
58
53
|
return number;
|
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>) =>
|
|
5
|
+
export declare const coerce: <R>(ctx: Interpreter<R>, name: Coercion, args: Array<Value>) => import("effect/Effect").Effect<Value, unknown, R> | Value;
|
|
6
6
|
/** A global coercion function such as `Number` or `parseInt`. */
|
|
7
7
|
export declare const coercion: <R>(ctx: Interpreter<R>, name: Coercion, length?: number) => Native<R>;
|
package/dist/tool-runtime.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { DiagnosticKind } from "./codemode.js";
|
|
|
4
4
|
import { type Namespace } from "./namespace.js";
|
|
5
5
|
import { type Tool } from "./tool.js";
|
|
6
6
|
import type { Tools } from "./tools.js";
|
|
7
|
-
export declare const compareText: (left: string, right: string) =>
|
|
7
|
+
export declare const compareText: (left: string, right: string) => -1 | 0 | 1;
|
|
8
8
|
export type Services<T> = ServicesOf<T, []>;
|
|
9
9
|
type ServicesOf<T, Depth extends ReadonlyArray<unknown>> = Depth["length"] extends 8 ? never : T extends {
|
|
10
10
|
readonly _tag: "CodeModeTool";
|
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.0
|
|
4
|
+
"version": "2.1.0",
|
|
5
5
|
"description": "Effect-native confined code execution over schema-described tools",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"license": "MIT",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
},
|
|
25
25
|
"scripts": {
|
|
26
26
|
"build": "bun run script/build.ts",
|
|
27
|
-
"typecheck": "
|
|
27
|
+
"typecheck": "tsc --noEmit",
|
|
28
28
|
"test": "bun test"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
@@ -34,6 +34,6 @@
|
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@tsconfig/bun": "1.0.9",
|
|
36
36
|
"@types/bun": "1.4.0",
|
|
37
|
-
"@typescript/native
|
|
37
|
+
"@typescript/native": "npm:typescript@7.0.2"
|
|
38
38
|
}
|
|
39
39
|
}
|