@mark1russell7/vex 0.11.1 → 0.11.2
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/build/index.d.ts.map +1 -1
- package/build/index.js +12 -17
- package/build/index.js.map +1 -1
- package/package.json +1 -1
- package/src/builder.ts +3 -5
- package/src/codec.ts +8 -5
- package/src/evaluate.ts +2 -4
- package/src/json.ts +4 -3
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package",
|
|
3
3
|
"name": "@mark1russell7/vex",
|
|
4
|
-
"version": "0.11.
|
|
4
|
+
"version": "0.11.2",
|
|
5
5
|
"description": "Vex: typed spreadsheet formulas over domain objects. The kernel and the typed builder.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"typescript",
|
package/src/builder.ts
CHANGED
|
@@ -722,8 +722,8 @@ class ChainImpl {
|
|
|
722
722
|
|
|
723
723
|
fork(branches: Readonly<Record<string, (c: ChainImpl) => { readonly program: Expr }>>): ChainImpl {
|
|
724
724
|
const { name, start } = this.#bound();
|
|
725
|
-
|
|
726
|
-
|
|
725
|
+
// Object.fromEntries gives an own field for each name, also for "__proto__" (V-062).
|
|
726
|
+
const fields = Object.fromEntries(Object.entries(branches).map(([n, f]) => [n, f(start).program]));
|
|
727
727
|
return new ChainImpl({ ...this.#s, expr: let_({ [name]: this.#s.expr }, rec(fields)) });
|
|
728
728
|
}
|
|
729
729
|
|
|
@@ -1013,9 +1013,7 @@ class RootImpl {
|
|
|
1013
1013
|
return { kind: "vex.fn", params, build };
|
|
1014
1014
|
}
|
|
1015
1015
|
rec(fields: Readonly<Record<string, unknown>>): Arg<unknown> {
|
|
1016
|
-
|
|
1017
|
-
for (const [n, a] of Object.entries(fields)) out[n] = toExpr(a, []);
|
|
1018
|
-
return argToken(rec(out));
|
|
1016
|
+
return argToken(rec(Object.fromEntries(Object.entries(fields).map(([n, a]) => [n, toExpr(a, [])]))));
|
|
1019
1017
|
}
|
|
1020
1018
|
list(items: readonly (readonly [string, unknown])[] = []): ListChainImpl {
|
|
1021
1019
|
// LIST.LITERAL: a literal of the list, with a value for each item.
|
package/src/codec.ts
CHANGED
|
@@ -52,12 +52,14 @@ export function encodeValue(u: unknown, domains: readonly AnyDomain[]): Result<u
|
|
|
52
52
|
return ok(out);
|
|
53
53
|
}
|
|
54
54
|
if (isPlainRecord(u)) {
|
|
55
|
-
const
|
|
55
|
+
const entries: [string, unknown][] = [];
|
|
56
56
|
for (const [k, x] of Object.entries(u)) {
|
|
57
57
|
const r = encodeValue(x, domains);
|
|
58
58
|
if (!r.ok) return r;
|
|
59
|
-
|
|
59
|
+
entries.push([k, r.value]);
|
|
60
60
|
}
|
|
61
|
+
// Object.fromEntries gives an own field for each key, also for "__proto__" (V-062).
|
|
62
|
+
const out = Object.fromEntries(entries);
|
|
61
63
|
return ok(Object.hasOwn(u, "$vex") ? ({ $vex: "escape", value: out } satisfies Encoded) : out);
|
|
62
64
|
}
|
|
63
65
|
// A plain array or record stays data. Another object is a value of a domain, or it has no JSON form.
|
|
@@ -81,13 +83,14 @@ export function decodeValue(u: unknown, domains: readonly AnyDomain[]): Result<u
|
|
|
81
83
|
}
|
|
82
84
|
if (!isRecord(u)) return ok(u);
|
|
83
85
|
const fields = (record: Readonly<Record<string, unknown>>): Result<unknown> => {
|
|
84
|
-
const
|
|
86
|
+
const entries: [string, unknown][] = [];
|
|
85
87
|
for (const [k, x] of Object.entries(record)) {
|
|
86
88
|
const r = decodeValue(x, domains);
|
|
87
89
|
if (!r.ok) return r;
|
|
88
|
-
|
|
90
|
+
entries.push([k, r.value]);
|
|
89
91
|
}
|
|
90
|
-
|
|
92
|
+
// A key "__proto__" of the data is an own field too (V-062).
|
|
93
|
+
return ok(Object.fromEntries(entries));
|
|
91
94
|
};
|
|
92
95
|
// A record without the key $vex matches none of the forms below, so it stays data too.
|
|
93
96
|
const kind = u["$vex"];
|
package/src/evaluate.ts
CHANGED
|
@@ -263,10 +263,8 @@ class Compiler {
|
|
|
263
263
|
return (f, c) => {
|
|
264
264
|
const values = this.#all(fields, f, c, path, "fields");
|
|
265
265
|
if (!values.ok) return this.#emit(c, info, f, values);
|
|
266
|
-
|
|
267
|
-
names.
|
|
268
|
-
out[n] = values.value[i];
|
|
269
|
-
});
|
|
266
|
+
// Object.fromEntries gives an own field for each name, also for "__proto__" (V-062).
|
|
267
|
+
const out = Object.fromEntries(names.map((n, i) => [n, values.value[i]]));
|
|
270
268
|
return this.#emit(c, info, f, ok(Object.freeze(out)));
|
|
271
269
|
};
|
|
272
270
|
}
|
package/src/json.ts
CHANGED
|
@@ -25,13 +25,14 @@ function mapValues(u: unknown, f: (value: unknown) => Result<unknown>): Result<u
|
|
|
25
25
|
}
|
|
26
26
|
out[key] = items;
|
|
27
27
|
} else if (isRecord(list)) {
|
|
28
|
-
const
|
|
28
|
+
const entries: [string, unknown][] = [];
|
|
29
29
|
for (const [k, x] of Object.entries(list)) {
|
|
30
30
|
const r = mapValues(x, f);
|
|
31
31
|
if (!r.ok) return r;
|
|
32
|
-
|
|
32
|
+
entries.push([k, r.value]);
|
|
33
33
|
}
|
|
34
|
-
|
|
34
|
+
// A binding or a field with the name "__proto__" is an own field too (V-062).
|
|
35
|
+
out[key] = Object.fromEntries(entries);
|
|
35
36
|
}
|
|
36
37
|
return undefined;
|
|
37
38
|
};
|