@valbuild/core 0.13.6 → 0.13.7
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 -2
- package/dist/declarations/src/index.d.ts +1 -2
- package/dist/declarations/src/val/index.d.ts +1 -1
- package/dist/{index-e496913b.cjs.prod.js → index-104b3b67.cjs.prod.js} +142 -666
- package/dist/{index-43176a0e.cjs.dev.js → index-2f65eaa1.cjs.dev.js} +142 -666
- package/dist/{index-bc255f5a.esm.js → index-b861a6d2.esm.js} +146 -670
- 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 +6 -3
- package/src/expr/eval.ts +39 -51
- package/src/expr/repl.ts +25 -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 +7 -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-2f65eaa1.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-104b3b67.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-b861a6d2.esm.js';
|
2
|
+
export { F as FILE_REF_PROP, G as GenericSelector, S as Schema, V as VAL_EXTENSION, p as expr } from './index-b861a6d2.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-2f65eaa1.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-104b3b67.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-b861a6d2.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,13 @@ 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
189
|
(ref) => {
|
190
|
-
return
|
190
|
+
return newSelectorProxy(
|
191
|
+
sources[ref as keyof typeof sources],
|
192
|
+
ref as SourcePath
|
193
|
+
);
|
191
194
|
},
|
192
195
|
[]
|
193
196
|
),
|
package/src/expr/eval.ts
CHANGED
@@ -4,8 +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,
|
8
|
-
import { Json } from "../Json";
|
7
|
+
import { isSerializedVal, SourcePath } from "../val";
|
9
8
|
|
10
9
|
export class EvalError {
|
11
10
|
constructor(public readonly message: string, public readonly expr: Expr) {}
|
@@ -25,11 +24,11 @@ type LocalSelector<S extends Source> = {
|
|
25
24
|
};
|
26
25
|
|
27
26
|
const MAX_STACK_SIZE = 100; // an arbitrary semi-large number
|
28
|
-
|
27
|
+
function evaluateSync(
|
29
28
|
expr: Expr,
|
30
|
-
getSource: (
|
29
|
+
getSource: (ref: string) => LocalSelector<Source>,
|
31
30
|
stack: readonly LocalSelector<Source>[][]
|
32
|
-
):
|
31
|
+
): LocalSelector<Source> {
|
33
32
|
// TODO: amount of evaluates should be limited?
|
34
33
|
if (stack.length > MAX_STACK_SIZE) {
|
35
34
|
throw new EvalError(
|
@@ -49,9 +48,7 @@ async function evaluateAsync(
|
|
49
48
|
throw new EvalError("cannot call 'val' as anonymous function", expr);
|
50
49
|
}
|
51
50
|
if (expr.children[1] instanceof StringLiteral) {
|
52
|
-
|
53
|
-
const source = await getSource(path as ModulePath);
|
54
|
-
return newSelectorProxy(source, path as SourcePath);
|
51
|
+
return getSource(expr.children[1].value);
|
55
52
|
} else {
|
56
53
|
throw new EvalError(
|
57
54
|
"argument of 'val' must be a string literal",
|
@@ -65,7 +62,7 @@ async function evaluateAsync(
|
|
65
62
|
expr
|
66
63
|
);
|
67
64
|
}
|
68
|
-
const value =
|
65
|
+
const value = evaluateSync(expr.children[1], getSource, stack);
|
69
66
|
|
70
67
|
const valObj = value[SourceOrExpr];
|
71
68
|
const valPath = value[Path];
|
@@ -78,10 +75,7 @@ async function evaluateAsync(
|
|
78
75
|
try {
|
79
76
|
const serialized = JSON.parse(valObj);
|
80
77
|
if (isSerializedVal(serialized)) {
|
81
|
-
return newSelectorProxy(
|
82
|
-
serialized.val,
|
83
|
-
serialized.valPath ?? undefined
|
84
|
-
);
|
78
|
+
return newSelectorProxy(serialized.val, serialized.valPath);
|
85
79
|
}
|
86
80
|
const parsedValue = newSelectorProxy(JSON.parse(valObj), valPath);
|
87
81
|
return parsedValue;
|
@@ -104,18 +98,16 @@ async function evaluateAsync(
|
|
104
98
|
expr
|
105
99
|
);
|
106
100
|
}
|
107
|
-
const res =
|
101
|
+
const res = evaluateSync(expr.children[1], getSource, stack);
|
108
102
|
return newSelectorProxy(JSON.stringify(res[SourceOrExpr]));
|
109
103
|
}
|
110
104
|
}
|
111
|
-
const prop = (
|
112
|
-
SourceOrExpr
|
113
|
-
];
|
105
|
+
const prop = evaluateSync(expr.children[0], getSource, stack)[SourceOrExpr];
|
114
106
|
if (expr.children.length === 1) {
|
115
107
|
// TODO: return if literal only?
|
116
108
|
return newSelectorProxy(prop);
|
117
109
|
}
|
118
|
-
const obj =
|
110
|
+
const obj = evaluateSync(expr.children[1], getSource, stack);
|
119
111
|
if (typeof prop !== "string" && typeof prop !== "number") {
|
120
112
|
throw new EvalError(
|
121
113
|
`cannot access ${JSON.stringify(obj)} with property ${JSON.stringify(
|
@@ -139,7 +131,7 @@ async function evaluateAsync(
|
|
139
131
|
}
|
140
132
|
if (expr.children[0] instanceof Sym) {
|
141
133
|
return maybeFunction((...args: any[]) => {
|
142
|
-
return
|
134
|
+
return evaluateSync(
|
143
135
|
expr.children[2],
|
144
136
|
getSource,
|
145
137
|
stack.concat([args])
|
@@ -156,9 +148,7 @@ async function evaluateAsync(
|
|
156
148
|
if (expr.children[0] instanceof Sym) {
|
157
149
|
if (expr.children[0].value === "val") {
|
158
150
|
if (expr.children[1] instanceof StringLiteral) {
|
159
|
-
|
160
|
-
const source = await getSource(path as ModulePath);
|
161
|
-
return newSelectorProxy(source, path as SourcePath);
|
151
|
+
return getSource(expr.children[1].value);
|
162
152
|
} else {
|
163
153
|
throw new EvalError(
|
164
154
|
"argument of 'val' must be a string literal",
|
@@ -181,7 +171,7 @@ async function evaluateAsync(
|
|
181
171
|
);
|
182
172
|
}
|
183
173
|
return maybeFunction(
|
184
|
-
...args.map((arg) =>
|
174
|
+
...args.map((arg) => evaluateSync(arg, getSource, stack))
|
185
175
|
);
|
186
176
|
}
|
187
177
|
const maybeValue = obj[prop];
|
@@ -215,42 +205,40 @@ async function evaluateAsync(
|
|
215
205
|
return newSelectorProxy(expr.value);
|
216
206
|
} else if (expr instanceof StringTemplate) {
|
217
207
|
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
|
-
)
|
208
|
+
expr.children
|
209
|
+
.map((child) => {
|
210
|
+
if (child instanceof Sym && child.value === "()") {
|
211
|
+
return "null";
|
212
|
+
}
|
213
|
+
const evalRes = evaluateSync(child, getSource, stack);
|
214
|
+
if (
|
215
|
+
child.type === "StringLiteral" ||
|
216
|
+
child.type === "StringTemplate"
|
217
|
+
) {
|
218
|
+
return evalRes[SourceOrExpr];
|
219
|
+
}
|
220
|
+
if (Path in evalRes) {
|
221
|
+
// a selector, so serialize to Val
|
222
|
+
return JSON.stringify({
|
223
|
+
val: evalRes[SourceOrExpr],
|
224
|
+
valPath: evalRes[Path],
|
225
|
+
});
|
226
|
+
}
|
227
|
+
return JSON.stringify(evalRes[SourceOrExpr]);
|
228
|
+
})
|
229
|
+
.join("")
|
242
230
|
);
|
243
231
|
}
|
244
232
|
throw new EvalError(`could not evaluate`, expr);
|
245
233
|
}
|
246
234
|
|
247
|
-
export
|
235
|
+
export function evaluate(
|
248
236
|
expr: Expr,
|
249
|
-
source: (ref: string) =>
|
237
|
+
source: (ref: string) => LocalSelector<Source>,
|
250
238
|
stack: readonly LocalSelector<Source>[][]
|
251
|
-
):
|
239
|
+
): result.Result<LocalSelector<Source>, EvalError> {
|
252
240
|
try {
|
253
|
-
return result.ok(
|
241
|
+
return result.ok(evaluateSync(expr, source, stack));
|
254
242
|
} catch (err) {
|
255
243
|
if (err instanceof EvalError) {
|
256
244
|
return result.err(err);
|
package/src/expr/repl.ts
CHANGED
@@ -54,30 +54,32 @@ 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
|
+
(ref) =>
|
61
|
+
newSelectorProxy(
|
62
|
+
sources[ref as keyof typeof sources],
|
63
|
+
ref as SourcePath
|
64
|
+
),
|
60
65
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
}
|
79
|
-
})
|
80
|
-
)
|
66
|
+
[]
|
67
|
+
),
|
68
|
+
result.map((v) => {
|
69
|
+
try {
|
70
|
+
console.log(selectorToVal(v).val);
|
71
|
+
callback(null, undefined);
|
72
|
+
} catch (e) {
|
73
|
+
callback(
|
74
|
+
null,
|
75
|
+
`\x1b[31mInvalid function! Expected selector, but got:\x1b[0m:\n${JSON.stringify(
|
76
|
+
v
|
77
|
+
)}\n\nDetails: ${
|
78
|
+
e instanceof Error ? e.message : JSON.stringify(e)
|
79
|
+
}`
|
80
|
+
);
|
81
|
+
}
|
82
|
+
})
|
81
83
|
);
|
82
84
|
}
|
83
85
|
},
|
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,14 @@ 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
|
-
(ref) =>
|
292
|
+
(ref) =>
|
293
|
+
newSelectorProxy(
|
294
|
+
modules[ref as keyof typeof modules],
|
295
|
+
ref as SourcePath
|
296
|
+
),
|
293
297
|
[]
|
294
298
|
);
|
295
299
|
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 (
|