@valbuild/core 0.13.6 → 0.13.8
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/declarations/src/expr/eval.d.ts +1 -1
- package/dist/declarations/src/index.d.ts +1 -2
- package/dist/declarations/src/val/index.d.ts +1 -1
- package/dist/{index-bc255f5a.esm.js → index-296cb2b6.esm.js} +148 -670
- package/dist/{index-43176a0e.cjs.dev.js → index-9663f28a.cjs.dev.js} +144 -666
- package/dist/{index-e496913b.cjs.prod.js → index-b2270f8f.cjs.prod.js} +144 -666
- package/dist/valbuild-core.cjs.dev.js +4 -5
- package/dist/valbuild-core.cjs.prod.js +4 -5
- package/dist/valbuild-core.esm.js +5 -6
- package/expr/dist/valbuild-core-expr.cjs.dev.js +1 -1
- package/expr/dist/valbuild-core-expr.cjs.prod.js +1 -1
- package/expr/dist/valbuild-core-expr.esm.js +1 -1
- package/package.json +1 -1
- package/src/expr/eval.test.ts +4 -4
- package/src/expr/eval.ts +41 -50
- package/src/expr/repl.ts +21 -23
- package/src/fetchVal.ts +2 -5
- package/src/index.ts +1 -2
- package/src/selector/SelectorProxy.ts +2 -2
- package/src/selector/selector.test.ts +3 -3
- package/src/val/index.ts +1 -1
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
4
4
|
|
5
|
-
var expr_dist_valbuildCoreExpr = require('./index-
|
5
|
+
var expr_dist_valbuildCoreExpr = require('./index-9663f28a.cjs.dev.js');
|
6
6
|
var createClass = require('./createClass-a436dbfe.cjs.dev.js');
|
7
7
|
var result = require('./result-48320acd.cjs.dev.js');
|
8
8
|
var ops = require('./ops-87cdbafc.cjs.dev.js');
|
@@ -729,7 +729,7 @@ function serializedValOfSelectorSource(selector) {
|
|
729
729
|
return {
|
730
730
|
val: array.map(function (item, i) {
|
731
731
|
return rec(expr_dist_valbuildCoreExpr.isSelector(item) // NOTE: We do this since selectors currently do not create selectors of items unless specifically required.
|
732
|
-
? item : expr_dist_valbuildCoreExpr.newSelectorProxy(item, expr_dist_valbuildCoreExpr.createValPathOfItem(valPath
|
732
|
+
? item : expr_dist_valbuildCoreExpr.newSelectorProxy(item, expr_dist_valbuildCoreExpr.createValPathOfItem(valPath, i)));
|
733
733
|
}),
|
734
734
|
valPath: valPath
|
735
735
|
};
|
@@ -813,10 +813,10 @@ function newValProxy(val) {
|
|
813
813
|
return target.length;
|
814
814
|
}
|
815
815
|
if (hasOwn(source, prop)) {
|
816
|
-
var _Reflect$get$valPath, _Reflect$get
|
816
|
+
var _Reflect$get$valPath, _Reflect$get;
|
817
817
|
return newValProxy({
|
818
818
|
val: Reflect.get(target, prop).val,
|
819
|
-
valPath: (_Reflect$get$valPath = (_Reflect$get = Reflect.get(target, prop)) === null || _Reflect$get === void 0 ? void 0 : _Reflect$get.valPath) !== null && _Reflect$get$valPath !== void 0 ? _Reflect$get$valPath : expr_dist_valbuildCoreExpr.createValPathOfItem(
|
819
|
+
valPath: (_Reflect$get$valPath = (_Reflect$get = Reflect.get(target, prop)) === null || _Reflect$get === void 0 ? void 0 : _Reflect$get.valPath) !== null && _Reflect$get$valPath !== void 0 ? _Reflect$get$valPath : expr_dist_valbuildCoreExpr.createValPathOfItem(val.valPath, Array.isArray(target) ? Number(prop) : prop)
|
820
820
|
});
|
821
821
|
}
|
822
822
|
return Reflect.get(target, prop);
|
@@ -1024,7 +1024,6 @@ var Internal = {
|
|
1024
1024
|
getRawSource: getRawSource,
|
1025
1025
|
resolvePath: resolvePath,
|
1026
1026
|
splitModuleIdAndModulePath: splitModuleIdAndModulePath,
|
1027
|
-
serializedValOfSelectorSource: serializedValOfSelectorSource,
|
1028
1027
|
fetchVal: fetchVal,
|
1029
1028
|
isVal: expr_dist_valbuildCoreExpr.isVal
|
1030
1029
|
};
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
4
4
|
|
5
|
-
var expr_dist_valbuildCoreExpr = require('./index-
|
5
|
+
var expr_dist_valbuildCoreExpr = require('./index-b2270f8f.cjs.prod.js');
|
6
6
|
var createClass = require('./createClass-de7426aa.cjs.prod.js');
|
7
7
|
var result = require('./result-26f67b40.cjs.prod.js');
|
8
8
|
var ops = require('./ops-ae4d1bc2.cjs.prod.js');
|
@@ -729,7 +729,7 @@ function serializedValOfSelectorSource(selector) {
|
|
729
729
|
return {
|
730
730
|
val: array.map(function (item, i) {
|
731
731
|
return rec(expr_dist_valbuildCoreExpr.isSelector(item) // NOTE: We do this since selectors currently do not create selectors of items unless specifically required.
|
732
|
-
? item : expr_dist_valbuildCoreExpr.newSelectorProxy(item, expr_dist_valbuildCoreExpr.createValPathOfItem(valPath
|
732
|
+
? item : expr_dist_valbuildCoreExpr.newSelectorProxy(item, expr_dist_valbuildCoreExpr.createValPathOfItem(valPath, i)));
|
733
733
|
}),
|
734
734
|
valPath: valPath
|
735
735
|
};
|
@@ -813,10 +813,10 @@ function newValProxy(val) {
|
|
813
813
|
return target.length;
|
814
814
|
}
|
815
815
|
if (hasOwn(source, prop)) {
|
816
|
-
var _Reflect$get$valPath, _Reflect$get
|
816
|
+
var _Reflect$get$valPath, _Reflect$get;
|
817
817
|
return newValProxy({
|
818
818
|
val: Reflect.get(target, prop).val,
|
819
|
-
valPath: (_Reflect$get$valPath = (_Reflect$get = Reflect.get(target, prop)) === null || _Reflect$get === void 0 ? void 0 : _Reflect$get.valPath) !== null && _Reflect$get$valPath !== void 0 ? _Reflect$get$valPath : expr_dist_valbuildCoreExpr.createValPathOfItem(
|
819
|
+
valPath: (_Reflect$get$valPath = (_Reflect$get = Reflect.get(target, prop)) === null || _Reflect$get === void 0 ? void 0 : _Reflect$get.valPath) !== null && _Reflect$get$valPath !== void 0 ? _Reflect$get$valPath : expr_dist_valbuildCoreExpr.createValPathOfItem(val.valPath, Array.isArray(target) ? Number(prop) : prop)
|
820
820
|
});
|
821
821
|
}
|
822
822
|
return Reflect.get(target, prop);
|
@@ -1024,7 +1024,6 @@ var Internal = {
|
|
1024
1024
|
getRawSource: getRawSource,
|
1025
1025
|
resolvePath: resolvePath,
|
1026
1026
|
splitModuleIdAndModulePath: splitModuleIdAndModulePath,
|
1027
|
-
serializedValOfSelectorSource: serializedValOfSelectorSource,
|
1028
1027
|
fetchVal: fetchVal,
|
1029
1028
|
isVal: expr_dist_valbuildCoreExpr.isVal
|
1030
1029
|
};
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import { _ as _inherits, a as _createSuper, S as Schema, g as getValPath, n as newSelectorProxy, b as SourceOrExpr, E as Expr, I as ImageSchema, c as _objectSpread2, d as _defineProperty, V as VAL_EXTENSION, i as image, P as Path, e as createValPathOfItem, f as isSelector, h as isSerializedVal, j as file, k as isFile, F as FILE_REF_PROP, l as convertImageSource, m as getSchema, o as isVal } from './index-
|
2
|
-
export { F as FILE_REF_PROP, G as GenericSelector, S as Schema, V as VAL_EXTENSION, p as expr } from './index-
|
1
|
+
import { _ as _inherits, a as _createSuper, S as Schema, g as getValPath, n as newSelectorProxy, b as SourceOrExpr, E as Expr, I as ImageSchema, c as _objectSpread2, d as _defineProperty, V as VAL_EXTENSION, i as image, P as Path, e as createValPathOfItem, f as isSelector, h as isSerializedVal, j as file, k as isFile, F as FILE_REF_PROP, l as convertImageSource, m as getSchema, o as isVal } from './index-296cb2b6.esm.js';
|
2
|
+
export { F as FILE_REF_PROP, G as GenericSelector, S as Schema, V as VAL_EXTENSION, p as expr } from './index-296cb2b6.esm.js';
|
3
3
|
import { _ as _classCallCheck, a as _createClass, b as _typeof, c as _slicedToArray, d as _toConsumableArray } from './createClass-012eebbf.esm.js';
|
4
4
|
import { _ as _createForOfIteratorHelper, i as isErr, a as isOk, e as err, o as ok } from './result-b96df128.esm.js';
|
5
5
|
import { P as PatchError } from './ops-6fae92a1.esm.js';
|
@@ -726,7 +726,7 @@ function serializedValOfSelectorSource(selector) {
|
|
726
726
|
return {
|
727
727
|
val: array.map(function (item, i) {
|
728
728
|
return rec(isSelector(item) // NOTE: We do this since selectors currently do not create selectors of items unless specifically required.
|
729
|
-
? item : newSelectorProxy(item, createValPathOfItem(valPath
|
729
|
+
? item : newSelectorProxy(item, createValPathOfItem(valPath, i)));
|
730
730
|
}),
|
731
731
|
valPath: valPath
|
732
732
|
};
|
@@ -810,10 +810,10 @@ function newValProxy(val) {
|
|
810
810
|
return target.length;
|
811
811
|
}
|
812
812
|
if (hasOwn(source, prop)) {
|
813
|
-
var _Reflect$get$valPath, _Reflect$get
|
813
|
+
var _Reflect$get$valPath, _Reflect$get;
|
814
814
|
return newValProxy({
|
815
815
|
val: Reflect.get(target, prop).val,
|
816
|
-
valPath: (_Reflect$get$valPath = (_Reflect$get = Reflect.get(target, prop)) === null || _Reflect$get === void 0 ? void 0 : _Reflect$get.valPath) !== null && _Reflect$get$valPath !== void 0 ? _Reflect$get$valPath : createValPathOfItem(
|
816
|
+
valPath: (_Reflect$get$valPath = (_Reflect$get = Reflect.get(target, prop)) === null || _Reflect$get === void 0 ? void 0 : _Reflect$get.valPath) !== null && _Reflect$get$valPath !== void 0 ? _Reflect$get$valPath : createValPathOfItem(val.valPath, Array.isArray(target) ? Number(prop) : prop)
|
817
817
|
});
|
818
818
|
}
|
819
819
|
return Reflect.get(target, prop);
|
@@ -1021,7 +1021,6 @@ var Internal = {
|
|
1021
1021
|
getRawSource: getRawSource,
|
1022
1022
|
resolvePath: resolvePath,
|
1023
1023
|
splitModuleIdAndModulePath: splitModuleIdAndModulePath,
|
1024
|
-
serializedValOfSelectorSource: serializedValOfSelectorSource,
|
1025
1024
|
fetchVal: fetchVal,
|
1026
1025
|
isVal: isVal
|
1027
1026
|
};
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
4
4
|
|
5
|
-
var expr_dist_valbuildCoreExpr = require('../../dist/index-
|
5
|
+
var expr_dist_valbuildCoreExpr = require('../../dist/index-9663f28a.cjs.dev.js');
|
6
6
|
require('../../dist/createClass-a436dbfe.cjs.dev.js');
|
7
7
|
require('../../dist/result-48320acd.cjs.dev.js');
|
8
8
|
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
4
4
|
|
5
|
-
var expr_dist_valbuildCoreExpr = require('../../dist/index-
|
5
|
+
var expr_dist_valbuildCoreExpr = require('../../dist/index-b2270f8f.cjs.prod.js');
|
6
6
|
require('../../dist/createClass-de7426aa.cjs.prod.js');
|
7
7
|
require('../../dist/result-26f67b40.cjs.prod.js');
|
8
8
|
|
@@ -1,3 +1,3 @@
|
|
1
|
-
export { C as Call, E as Expr, N as NilSym, r as StringLiteral, s as StringTemplate, t as Sym, u as evaluate, q as parse } from '../../dist/index-
|
1
|
+
export { C as Call, E as Expr, N as NilSym, r as StringLiteral, s as StringTemplate, t as Sym, u as evaluate, q as parse } from '../../dist/index-296cb2b6.esm.js';
|
2
2
|
import '../../dist/createClass-012eebbf.esm.js';
|
3
3
|
import '../../dist/result-b96df128.esm.js';
|
package/package.json
CHANGED
package/src/expr/eval.test.ts
CHANGED
@@ -176,7 +176,7 @@ describe("eval", () => {
|
|
176
176
|
EvalTestCases.filter(({ focus }) =>
|
177
177
|
EvalTestCases.some((v) => v.focus) ? focus : true
|
178
178
|
)
|
179
|
-
)('evaluate: "$expr"',
|
179
|
+
)('evaluate: "$expr"', ({ expr, expected }) => {
|
180
180
|
const parseRes = parse(expr);
|
181
181
|
if (result.isErr(parseRes)) {
|
182
182
|
return expect(parseRes).toHaveProperty("value");
|
@@ -184,10 +184,10 @@ describe("eval", () => {
|
|
184
184
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
185
185
|
expect(
|
186
186
|
pipe(
|
187
|
-
|
187
|
+
evaluate(
|
188
188
|
parseRes.value,
|
189
|
-
(
|
190
|
-
return
|
189
|
+
(path) => {
|
190
|
+
return sources[path as keyof typeof sources];
|
191
191
|
},
|
192
192
|
[]
|
193
193
|
),
|
package/src/expr/eval.ts
CHANGED
@@ -4,7 +4,7 @@ import { Source } from "../source";
|
|
4
4
|
import { result } from "../fp";
|
5
5
|
import { Path, SourceOrExpr } from "../selector";
|
6
6
|
import { newSelectorProxy } from "../selector/SelectorProxy";
|
7
|
-
import { isSerializedVal,
|
7
|
+
import { isSerializedVal, SourcePath } from "../val";
|
8
8
|
import { Json } from "../Json";
|
9
9
|
|
10
10
|
export class EvalError {
|
@@ -25,11 +25,11 @@ type LocalSelector<S extends Source> = {
|
|
25
25
|
};
|
26
26
|
|
27
27
|
const MAX_STACK_SIZE = 100; // an arbitrary semi-large number
|
28
|
-
|
28
|
+
function evaluateSync(
|
29
29
|
expr: Expr,
|
30
|
-
getSource: (
|
30
|
+
getSource: (path: string) => Json,
|
31
31
|
stack: readonly LocalSelector<Source>[][]
|
32
|
-
):
|
32
|
+
): LocalSelector<Source> {
|
33
33
|
// TODO: amount of evaluates should be limited?
|
34
34
|
if (stack.length > MAX_STACK_SIZE) {
|
35
35
|
throw new EvalError(
|
@@ -49,9 +49,8 @@ async function evaluateAsync(
|
|
49
49
|
throw new EvalError("cannot call 'val' as anonymous function", expr);
|
50
50
|
}
|
51
51
|
if (expr.children[1] instanceof StringLiteral) {
|
52
|
-
const path = expr.children[1].value;
|
53
|
-
|
54
|
-
return newSelectorProxy(source, path as SourcePath);
|
52
|
+
const path = expr.children[1].value as SourcePath;
|
53
|
+
return newSelectorProxy(getSource(path), path);
|
55
54
|
} else {
|
56
55
|
throw new EvalError(
|
57
56
|
"argument of 'val' must be a string literal",
|
@@ -65,7 +64,7 @@ async function evaluateAsync(
|
|
65
64
|
expr
|
66
65
|
);
|
67
66
|
}
|
68
|
-
const value =
|
67
|
+
const value = evaluateSync(expr.children[1], getSource, stack);
|
69
68
|
|
70
69
|
const valObj = value[SourceOrExpr];
|
71
70
|
const valPath = value[Path];
|
@@ -78,10 +77,7 @@ async function evaluateAsync(
|
|
78
77
|
try {
|
79
78
|
const serialized = JSON.parse(valObj);
|
80
79
|
if (isSerializedVal(serialized)) {
|
81
|
-
return newSelectorProxy(
|
82
|
-
serialized.val,
|
83
|
-
serialized.valPath ?? undefined
|
84
|
-
);
|
80
|
+
return newSelectorProxy(serialized.val, serialized.valPath);
|
85
81
|
}
|
86
82
|
const parsedValue = newSelectorProxy(JSON.parse(valObj), valPath);
|
87
83
|
return parsedValue;
|
@@ -104,18 +100,16 @@ async function evaluateAsync(
|
|
104
100
|
expr
|
105
101
|
);
|
106
102
|
}
|
107
|
-
const res =
|
103
|
+
const res = evaluateSync(expr.children[1], getSource, stack);
|
108
104
|
return newSelectorProxy(JSON.stringify(res[SourceOrExpr]));
|
109
105
|
}
|
110
106
|
}
|
111
|
-
const prop = (
|
112
|
-
SourceOrExpr
|
113
|
-
];
|
107
|
+
const prop = evaluateSync(expr.children[0], getSource, stack)[SourceOrExpr];
|
114
108
|
if (expr.children.length === 1) {
|
115
109
|
// TODO: return if literal only?
|
116
110
|
return newSelectorProxy(prop);
|
117
111
|
}
|
118
|
-
const obj =
|
112
|
+
const obj = evaluateSync(expr.children[1], getSource, stack);
|
119
113
|
if (typeof prop !== "string" && typeof prop !== "number") {
|
120
114
|
throw new EvalError(
|
121
115
|
`cannot access ${JSON.stringify(obj)} with property ${JSON.stringify(
|
@@ -139,7 +133,7 @@ async function evaluateAsync(
|
|
139
133
|
}
|
140
134
|
if (expr.children[0] instanceof Sym) {
|
141
135
|
return maybeFunction((...args: any[]) => {
|
142
|
-
return
|
136
|
+
return evaluateSync(
|
143
137
|
expr.children[2],
|
144
138
|
getSource,
|
145
139
|
stack.concat([args])
|
@@ -156,9 +150,8 @@ async function evaluateAsync(
|
|
156
150
|
if (expr.children[0] instanceof Sym) {
|
157
151
|
if (expr.children[0].value === "val") {
|
158
152
|
if (expr.children[1] instanceof StringLiteral) {
|
159
|
-
const path = expr.children[1].value;
|
160
|
-
|
161
|
-
return newSelectorProxy(source, path as SourcePath);
|
153
|
+
const path = expr.children[1].value as SourcePath;
|
154
|
+
return newSelectorProxy(getSource(path), path);
|
162
155
|
} else {
|
163
156
|
throw new EvalError(
|
164
157
|
"argument of 'val' must be a string literal",
|
@@ -181,7 +174,7 @@ async function evaluateAsync(
|
|
181
174
|
);
|
182
175
|
}
|
183
176
|
return maybeFunction(
|
184
|
-
...args.map((arg) =>
|
177
|
+
...args.map((arg) => evaluateSync(arg, getSource, stack))
|
185
178
|
);
|
186
179
|
}
|
187
180
|
const maybeValue = obj[prop];
|
@@ -215,42 +208,40 @@ async function evaluateAsync(
|
|
215
208
|
return newSelectorProxy(expr.value);
|
216
209
|
} else if (expr instanceof StringTemplate) {
|
217
210
|
return newSelectorProxy(
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
.join("")
|
241
|
-
)
|
211
|
+
expr.children
|
212
|
+
.map((child) => {
|
213
|
+
if (child instanceof Sym && child.value === "()") {
|
214
|
+
return "null";
|
215
|
+
}
|
216
|
+
const evalRes = evaluateSync(child, getSource, stack);
|
217
|
+
if (
|
218
|
+
child.type === "StringLiteral" ||
|
219
|
+
child.type === "StringTemplate"
|
220
|
+
) {
|
221
|
+
return evalRes[SourceOrExpr];
|
222
|
+
}
|
223
|
+
if (Path in evalRes) {
|
224
|
+
// a selector, so serialize to Val
|
225
|
+
return JSON.stringify({
|
226
|
+
val: evalRes[SourceOrExpr],
|
227
|
+
valPath: evalRes[Path],
|
228
|
+
});
|
229
|
+
}
|
230
|
+
return JSON.stringify(evalRes[SourceOrExpr]);
|
231
|
+
})
|
232
|
+
.join("")
|
242
233
|
);
|
243
234
|
}
|
244
235
|
throw new EvalError(`could not evaluate`, expr);
|
245
236
|
}
|
246
237
|
|
247
|
-
export
|
238
|
+
export function evaluate(
|
248
239
|
expr: Expr,
|
249
|
-
source: (ref: string) =>
|
240
|
+
source: (ref: string) => Json,
|
250
241
|
stack: readonly LocalSelector<Source>[][]
|
251
|
-
):
|
242
|
+
): result.Result<LocalSelector<Source>, EvalError> {
|
252
243
|
try {
|
253
|
-
return result.ok(
|
244
|
+
return result.ok(evaluateSync(expr, source, stack));
|
254
245
|
} catch (err) {
|
255
246
|
if (err instanceof EvalError) {
|
256
247
|
return result.err(err);
|
package/src/expr/repl.ts
CHANGED
@@ -54,30 +54,28 @@ repl
|
|
54
54
|
lines += underline + "\x1b[0m\n";
|
55
55
|
callback(null, lines);
|
56
56
|
} else {
|
57
|
-
|
58
|
-
|
59
|
-
|
57
|
+
pipe(
|
58
|
+
evaluate(
|
59
|
+
res.value,
|
60
|
+
(path) => sources[path as keyof typeof sources],
|
60
61
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
}
|
79
|
-
})
|
80
|
-
)
|
62
|
+
[]
|
63
|
+
),
|
64
|
+
result.map((v) => {
|
65
|
+
try {
|
66
|
+
console.log(selectorToVal(v).val);
|
67
|
+
callback(null, undefined);
|
68
|
+
} catch (e) {
|
69
|
+
callback(
|
70
|
+
null,
|
71
|
+
`\x1b[31mInvalid function! Expected selector, but got:\x1b[0m:\n${JSON.stringify(
|
72
|
+
v
|
73
|
+
)}\n\nDetails: ${
|
74
|
+
e instanceof Error ? e.message : JSON.stringify(e)
|
75
|
+
}`
|
76
|
+
);
|
77
|
+
}
|
78
|
+
})
|
81
79
|
);
|
82
80
|
}
|
83
81
|
},
|
package/src/fetchVal.ts
CHANGED
@@ -88,10 +88,7 @@ export function serializedValOfSelectorSource<T extends SelectorSource>(
|
|
88
88
|
rec(
|
89
89
|
isSelector(item) // NOTE: We do this since selectors currently do not create selectors of items unless specifically required.
|
90
90
|
? item
|
91
|
-
: newSelectorProxy(
|
92
|
-
item,
|
93
|
-
createValPathOfItem(valPath ?? undefined, i)
|
94
|
-
)
|
91
|
+
: newSelectorProxy(item, createValPathOfItem(valPath, i))
|
95
92
|
)
|
96
93
|
),
|
97
94
|
valPath,
|
@@ -190,7 +187,7 @@ function newValProxy<T extends Json>(val: SerializedVal): Val<T> {
|
|
190
187
|
valPath:
|
191
188
|
Reflect.get(target, prop)?.valPath ??
|
192
189
|
createValPathOfItem(
|
193
|
-
val.valPath
|
190
|
+
val.valPath,
|
194
191
|
Array.isArray(target) ? Number(prop) : prop
|
195
192
|
),
|
196
193
|
} as SerializedVal);
|
package/src/index.ts
CHANGED
@@ -32,7 +32,7 @@ export {
|
|
32
32
|
type SelectorOf,
|
33
33
|
GenericSelector,
|
34
34
|
} from "./selector";
|
35
|
-
import { getVal
|
35
|
+
import { getVal } from "./fetchVal";
|
36
36
|
import {
|
37
37
|
getRawSource,
|
38
38
|
resolvePath,
|
@@ -51,7 +51,6 @@ const Internal = {
|
|
51
51
|
getRawSource,
|
52
52
|
resolvePath,
|
53
53
|
splitModuleIdAndModulePath,
|
54
|
-
serializedValOfSelectorSource,
|
55
54
|
fetchVal,
|
56
55
|
isVal,
|
57
56
|
};
|
@@ -35,7 +35,7 @@ export function newSelectorProxy(
|
|
35
35
|
if (isSelector(source)) {
|
36
36
|
return source;
|
37
37
|
} else if (isSerializedVal(source)) {
|
38
|
-
return newSelectorProxy(source.val, source.valPath
|
38
|
+
return newSelectorProxy(source.val, source.valPath);
|
39
39
|
}
|
40
40
|
}
|
41
41
|
|
@@ -174,7 +174,7 @@ export function newSelectorProxy(
|
|
174
174
|
function selectorAsVal(sel: any): any {
|
175
175
|
if (isSerializedVal(sel)) {
|
176
176
|
// is a serialized val
|
177
|
-
return selectorAsVal(newSelectorProxy(sel.val, sel.valPath
|
177
|
+
return selectorAsVal(newSelectorProxy(sel.val, sel.valPath));
|
178
178
|
} else if (
|
179
179
|
typeof sel === "object" &&
|
180
180
|
sel &&
|
@@ -277,7 +277,7 @@ const RemoteAndLocaleSelectorModuleTestCases = SelectorModuleTestCases.flatMap(
|
|
277
277
|
describe("selector", () => {
|
278
278
|
test.each(RemoteAndLocaleSelectorModuleTestCases)(
|
279
279
|
"$description",
|
280
|
-
|
280
|
+
({ input, expected, remote }) => {
|
281
281
|
if (input instanceof Error) {
|
282
282
|
throw input;
|
283
283
|
}
|
@@ -286,10 +286,10 @@ describe("selector", () => {
|
|
286
286
|
const localeRes = input();
|
287
287
|
expect(selectorToVal(localeRes)).toStrictEqual(expected);
|
288
288
|
} else {
|
289
|
-
const res =
|
289
|
+
const res = evaluate(
|
290
290
|
// @ts-expect-error TODO: fix this
|
291
291
|
input()[SourceOrExpr],
|
292
|
-
(
|
292
|
+
(path) => modules[path as keyof typeof modules],
|
293
293
|
[]
|
294
294
|
);
|
295
295
|
if (result.isErr(res)) {
|
package/src/val/index.ts
CHANGED
@@ -10,7 +10,7 @@ import { FileSource } from "../source/file";
|
|
10
10
|
|
11
11
|
export type SerializedVal = {
|
12
12
|
val: SerializedVal | Json;
|
13
|
-
valPath: SourcePath |
|
13
|
+
valPath: SourcePath | undefined;
|
14
14
|
};
|
15
15
|
export function isSerializedVal(val: unknown): val is SerializedVal {
|
16
16
|
return (
|