@valbuild/core 0.13.5 → 0.13.6
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 +2 -1
- package/dist/declarations/src/index.d.ts +2 -1
- package/dist/declarations/src/val/index.d.ts +1 -1
- package/dist/{index-2f65eaa1.cjs.dev.js → index-43176a0e.cjs.dev.js} +666 -142
- package/dist/{index-b861a6d2.esm.js → index-bc255f5a.esm.js} +670 -146
- package/dist/{index-104b3b67.cjs.prod.js → index-e496913b.cjs.prod.js} +666 -142
- package/dist/valbuild-core.cjs.dev.js +5 -4
- package/dist/valbuild-core.cjs.prod.js +5 -4
- package/dist/valbuild-core.esm.js +6 -5
- 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 +3 -6
- package/src/expr/eval.ts +51 -39
- package/src/expr/repl.ts +23 -25
- package/src/fetchVal.ts +5 -2
- package/src/index.ts +2 -1
- package/src/selector/SelectorProxy.ts +2 -2
- package/src/selector/selector.test.ts +3 -7
- 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-43176a0e.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, i)));
|
732
|
+
? item : expr_dist_valbuildCoreExpr.newSelectorProxy(item, expr_dist_valbuildCoreExpr.createValPathOfItem(valPath !== null && valPath !== void 0 ? valPath : undefined, 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, _val$valPath;
|
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(val.valPath, Array.isArray(target) ? Number(prop) : prop)
|
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 = val.valPath) !== null && _val$valPath !== void 0 ? _val$valPath : undefined, Array.isArray(target) ? Number(prop) : prop)
|
820
820
|
});
|
821
821
|
}
|
822
822
|
return Reflect.get(target, prop);
|
@@ -1024,6 +1024,7 @@ var Internal = {
|
|
1024
1024
|
getRawSource: getRawSource,
|
1025
1025
|
resolvePath: resolvePath,
|
1026
1026
|
splitModuleIdAndModulePath: splitModuleIdAndModulePath,
|
1027
|
+
serializedValOfSelectorSource: serializedValOfSelectorSource,
|
1027
1028
|
fetchVal: fetchVal,
|
1028
1029
|
isVal: expr_dist_valbuildCoreExpr.isVal
|
1029
1030
|
};
|
@@ -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-e496913b.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, i)));
|
732
|
+
? item : expr_dist_valbuildCoreExpr.newSelectorProxy(item, expr_dist_valbuildCoreExpr.createValPathOfItem(valPath !== null && valPath !== void 0 ? valPath : undefined, 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, _val$valPath;
|
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(val.valPath, Array.isArray(target) ? Number(prop) : prop)
|
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 = val.valPath) !== null && _val$valPath !== void 0 ? _val$valPath : undefined, Array.isArray(target) ? Number(prop) : prop)
|
820
820
|
});
|
821
821
|
}
|
822
822
|
return Reflect.get(target, prop);
|
@@ -1024,6 +1024,7 @@ var Internal = {
|
|
1024
1024
|
getRawSource: getRawSource,
|
1025
1025
|
resolvePath: resolvePath,
|
1026
1026
|
splitModuleIdAndModulePath: splitModuleIdAndModulePath,
|
1027
|
+
serializedValOfSelectorSource: serializedValOfSelectorSource,
|
1027
1028
|
fetchVal: fetchVal,
|
1028
1029
|
isVal: expr_dist_valbuildCoreExpr.isVal
|
1029
1030
|
};
|
@@ -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-bc255f5a.esm.js';
|
2
|
+
export { F as FILE_REF_PROP, G as GenericSelector, S as Schema, V as VAL_EXTENSION, p as expr } from './index-bc255f5a.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, i)));
|
729
|
+
? item : newSelectorProxy(item, createValPathOfItem(valPath !== null && valPath !== void 0 ? valPath : undefined, 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, _val$valPath;
|
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(val.valPath, Array.isArray(target) ? Number(prop) : prop)
|
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 = val.valPath) !== null && _val$valPath !== void 0 ? _val$valPath : undefined, Array.isArray(target) ? Number(prop) : prop)
|
817
817
|
});
|
818
818
|
}
|
819
819
|
return Reflect.get(target, prop);
|
@@ -1021,6 +1021,7 @@ var Internal = {
|
|
1021
1021
|
getRawSource: getRawSource,
|
1022
1022
|
resolvePath: resolvePath,
|
1023
1023
|
splitModuleIdAndModulePath: splitModuleIdAndModulePath,
|
1024
|
+
serializedValOfSelectorSource: serializedValOfSelectorSource,
|
1024
1025
|
fetchVal: fetchVal,
|
1025
1026
|
isVal: isVal
|
1026
1027
|
};
|
@@ -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-43176a0e.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-e496913b.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-bc255f5a.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"', ({ expr, expected }) => {
|
179
|
+
)('evaluate: "$expr"', async ({ expr, expected }) => {
|
180
180
|
const parseRes = parse(expr);
|
181
181
|
if (result.isErr(parseRes)) {
|
182
182
|
return expect(parseRes).toHaveProperty("value");
|
@@ -184,13 +184,10 @@ describe("eval", () => {
|
|
184
184
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
185
185
|
expect(
|
186
186
|
pipe(
|
187
|
-
evaluate(
|
187
|
+
await evaluate(
|
188
188
|
parseRes.value,
|
189
189
|
(ref) => {
|
190
|
-
return
|
191
|
-
sources[ref as keyof typeof sources],
|
192
|
-
ref as SourcePath
|
193
|
-
);
|
190
|
+
return Promise.resolve(sources[ref as keyof typeof sources]);
|
194
191
|
},
|
195
192
|
[]
|
196
193
|
),
|
package/src/expr/eval.ts
CHANGED
@@ -4,7 +4,8 @@ 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, SourcePath } from "../val";
|
7
|
+
import { isSerializedVal, ModulePath, SourcePath } from "../val";
|
8
|
+
import { Json } from "../Json";
|
8
9
|
|
9
10
|
export class EvalError {
|
10
11
|
constructor(public readonly message: string, public readonly expr: Expr) {}
|
@@ -24,11 +25,11 @@ type LocalSelector<S extends Source> = {
|
|
24
25
|
};
|
25
26
|
|
26
27
|
const MAX_STACK_SIZE = 100; // an arbitrary semi-large number
|
27
|
-
function
|
28
|
+
async function evaluateAsync(
|
28
29
|
expr: Expr,
|
29
|
-
getSource: (
|
30
|
+
getSource: (modulePath: ModulePath) => Promise<Json>,
|
30
31
|
stack: readonly LocalSelector<Source>[][]
|
31
|
-
): LocalSelector<Source
|
32
|
+
): Promise<LocalSelector<Source>> {
|
32
33
|
// TODO: amount of evaluates should be limited?
|
33
34
|
if (stack.length > MAX_STACK_SIZE) {
|
34
35
|
throw new EvalError(
|
@@ -48,7 +49,9 @@ function evaluateSync(
|
|
48
49
|
throw new EvalError("cannot call 'val' as anonymous function", expr);
|
49
50
|
}
|
50
51
|
if (expr.children[1] instanceof StringLiteral) {
|
51
|
-
|
52
|
+
const path = expr.children[1].value;
|
53
|
+
const source = await getSource(path as ModulePath);
|
54
|
+
return newSelectorProxy(source, path as SourcePath);
|
52
55
|
} else {
|
53
56
|
throw new EvalError(
|
54
57
|
"argument of 'val' must be a string literal",
|
@@ -62,7 +65,7 @@ function evaluateSync(
|
|
62
65
|
expr
|
63
66
|
);
|
64
67
|
}
|
65
|
-
const value =
|
68
|
+
const value = await evaluateAsync(expr.children[1], getSource, stack);
|
66
69
|
|
67
70
|
const valObj = value[SourceOrExpr];
|
68
71
|
const valPath = value[Path];
|
@@ -75,7 +78,10 @@ function evaluateSync(
|
|
75
78
|
try {
|
76
79
|
const serialized = JSON.parse(valObj);
|
77
80
|
if (isSerializedVal(serialized)) {
|
78
|
-
return newSelectorProxy(
|
81
|
+
return newSelectorProxy(
|
82
|
+
serialized.val,
|
83
|
+
serialized.valPath ?? undefined
|
84
|
+
);
|
79
85
|
}
|
80
86
|
const parsedValue = newSelectorProxy(JSON.parse(valObj), valPath);
|
81
87
|
return parsedValue;
|
@@ -98,16 +104,18 @@ function evaluateSync(
|
|
98
104
|
expr
|
99
105
|
);
|
100
106
|
}
|
101
|
-
const res =
|
107
|
+
const res = await evaluateAsync(expr.children[1], getSource, stack);
|
102
108
|
return newSelectorProxy(JSON.stringify(res[SourceOrExpr]));
|
103
109
|
}
|
104
110
|
}
|
105
|
-
const prop =
|
111
|
+
const prop = (await evaluateAsync(expr.children[0], getSource, stack))[
|
112
|
+
SourceOrExpr
|
113
|
+
];
|
106
114
|
if (expr.children.length === 1) {
|
107
115
|
// TODO: return if literal only?
|
108
116
|
return newSelectorProxy(prop);
|
109
117
|
}
|
110
|
-
const obj =
|
118
|
+
const obj = await evaluateAsync(expr.children[1], getSource, stack);
|
111
119
|
if (typeof prop !== "string" && typeof prop !== "number") {
|
112
120
|
throw new EvalError(
|
113
121
|
`cannot access ${JSON.stringify(obj)} with property ${JSON.stringify(
|
@@ -131,7 +139,7 @@ function evaluateSync(
|
|
131
139
|
}
|
132
140
|
if (expr.children[0] instanceof Sym) {
|
133
141
|
return maybeFunction((...args: any[]) => {
|
134
|
-
return
|
142
|
+
return evaluateAsync(
|
135
143
|
expr.children[2],
|
136
144
|
getSource,
|
137
145
|
stack.concat([args])
|
@@ -148,7 +156,9 @@ function evaluateSync(
|
|
148
156
|
if (expr.children[0] instanceof Sym) {
|
149
157
|
if (expr.children[0].value === "val") {
|
150
158
|
if (expr.children[1] instanceof StringLiteral) {
|
151
|
-
|
159
|
+
const path = expr.children[1].value;
|
160
|
+
const source = await getSource(path as ModulePath);
|
161
|
+
return newSelectorProxy(source, path as SourcePath);
|
152
162
|
} else {
|
153
163
|
throw new EvalError(
|
154
164
|
"argument of 'val' must be a string literal",
|
@@ -171,7 +181,7 @@ function evaluateSync(
|
|
171
181
|
);
|
172
182
|
}
|
173
183
|
return maybeFunction(
|
174
|
-
...args.map((arg) =>
|
184
|
+
...args.map((arg) => evaluateAsync(arg, getSource, stack))
|
175
185
|
);
|
176
186
|
}
|
177
187
|
const maybeValue = obj[prop];
|
@@ -205,40 +215,42 @@ function evaluateSync(
|
|
205
215
|
return newSelectorProxy(expr.value);
|
206
216
|
} else if (expr instanceof StringTemplate) {
|
207
217
|
return newSelectorProxy(
|
208
|
-
|
209
|
-
.
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
218
|
+
await Promise.all(
|
219
|
+
expr.children
|
220
|
+
.map(async (child) => {
|
221
|
+
if (child instanceof Sym && child.value === "()") {
|
222
|
+
return "null";
|
223
|
+
}
|
224
|
+
const evalRes = await evaluateAsync(child, getSource, stack);
|
225
|
+
if (
|
226
|
+
child.type === "StringLiteral" ||
|
227
|
+
child.type === "StringTemplate"
|
228
|
+
) {
|
229
|
+
return evalRes[SourceOrExpr];
|
230
|
+
}
|
231
|
+
if (Path in evalRes) {
|
232
|
+
// a selector, so serialize to Val
|
233
|
+
return JSON.stringify({
|
234
|
+
val: evalRes[SourceOrExpr],
|
235
|
+
valPath: evalRes[Path],
|
236
|
+
});
|
237
|
+
}
|
238
|
+
return JSON.stringify(evalRes[SourceOrExpr]);
|
239
|
+
})
|
240
|
+
.join("")
|
241
|
+
)
|
230
242
|
);
|
231
243
|
}
|
232
244
|
throw new EvalError(`could not evaluate`, expr);
|
233
245
|
}
|
234
246
|
|
235
|
-
export function evaluate(
|
247
|
+
export async function evaluate(
|
236
248
|
expr: Expr,
|
237
|
-
source: (ref: string) =>
|
249
|
+
source: (ref: string) => Promise<Json>,
|
238
250
|
stack: readonly LocalSelector<Source>[][]
|
239
|
-
): result.Result<LocalSelector<Source>, EvalError
|
251
|
+
): Promise<result.Result<LocalSelector<Source>, EvalError>> {
|
240
252
|
try {
|
241
|
-
return result.ok(
|
253
|
+
return result.ok(await evaluateAsync(expr, source, stack));
|
242
254
|
} catch (err) {
|
243
255
|
if (err instanceof EvalError) {
|
244
256
|
return result.err(err);
|
package/src/expr/repl.ts
CHANGED
@@ -54,32 +54,30 @@ repl
|
|
54
54
|
lines += underline + "\x1b[0m\n";
|
55
55
|
callback(null, lines);
|
56
56
|
} else {
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
(ref) =>
|
61
|
-
newSelectorProxy(
|
62
|
-
sources[ref as keyof typeof sources],
|
63
|
-
ref as SourcePath
|
64
|
-
),
|
57
|
+
evaluate(
|
58
|
+
res.value,
|
59
|
+
(ref) => Promise.resolve(sources[ref as keyof typeof sources]),
|
65
60
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
61
|
+
[]
|
62
|
+
).then((res) =>
|
63
|
+
pipe(
|
64
|
+
res,
|
65
|
+
result.map((v) => {
|
66
|
+
try {
|
67
|
+
console.log(selectorToVal(v).val);
|
68
|
+
callback(null, undefined);
|
69
|
+
} catch (e) {
|
70
|
+
callback(
|
71
|
+
null,
|
72
|
+
`\x1b[31mInvalid function! Expected selector, but got:\x1b[0m:\n${JSON.stringify(
|
73
|
+
v
|
74
|
+
)}\n\nDetails: ${
|
75
|
+
e instanceof Error ? e.message : JSON.stringify(e)
|
76
|
+
}`
|
77
|
+
);
|
78
|
+
}
|
79
|
+
})
|
80
|
+
)
|
83
81
|
);
|
84
82
|
}
|
85
83
|
},
|
package/src/fetchVal.ts
CHANGED
@@ -88,7 +88,10 @@ 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(
|
91
|
+
: newSelectorProxy(
|
92
|
+
item,
|
93
|
+
createValPathOfItem(valPath ?? undefined, i)
|
94
|
+
)
|
92
95
|
)
|
93
96
|
),
|
94
97
|
valPath,
|
@@ -187,7 +190,7 @@ function newValProxy<T extends Json>(val: SerializedVal): Val<T> {
|
|
187
190
|
valPath:
|
188
191
|
Reflect.get(target, prop)?.valPath ??
|
189
192
|
createValPathOfItem(
|
190
|
-
val.valPath,
|
193
|
+
val.valPath ?? undefined,
|
191
194
|
Array.isArray(target) ? Number(prop) : prop
|
192
195
|
),
|
193
196
|
} 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 } from "./fetchVal";
|
35
|
+
import { getVal, serializedValOfSelectorSource } from "./fetchVal";
|
36
36
|
import {
|
37
37
|
getRawSource,
|
38
38
|
resolvePath,
|
@@ -51,6 +51,7 @@ const Internal = {
|
|
51
51
|
getRawSource,
|
52
52
|
resolvePath,
|
53
53
|
splitModuleIdAndModulePath,
|
54
|
+
serializedValOfSelectorSource,
|
54
55
|
fetchVal,
|
55
56
|
isVal,
|
56
57
|
};
|
@@ -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 ?? undefined);
|
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 ?? undefined));
|
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
|
-
({ input, expected, remote }) => {
|
280
|
+
async ({ input, expected, remote }) => {
|
281
281
|
if (input instanceof Error) {
|
282
282
|
throw input;
|
283
283
|
}
|
@@ -286,14 +286,10 @@ describe("selector", () => {
|
|
286
286
|
const localeRes = input();
|
287
287
|
expect(selectorToVal(localeRes)).toStrictEqual(expected);
|
288
288
|
} else {
|
289
|
-
const res = evaluate(
|
289
|
+
const res = await evaluate(
|
290
290
|
// @ts-expect-error TODO: fix this
|
291
291
|
input()[SourceOrExpr],
|
292
|
-
(ref) =>
|
293
|
-
newSelectorProxy(
|
294
|
-
modules[ref as keyof typeof modules],
|
295
|
-
ref as SourcePath
|
296
|
-
),
|
292
|
+
(ref) => Promise.resolve(modules[ref as keyof typeof modules]),
|
297
293
|
[]
|
298
294
|
);
|
299
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 | null;
|
14
14
|
};
|
15
15
|
export function isSerializedVal(val: unknown): val is SerializedVal {
|
16
16
|
return (
|