@valbuild/core 0.16.0 → 0.17.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/ROADMAP.md +106 -0
- package/dist/declarations/src/ValApi.d.ts +26 -0
- package/dist/declarations/src/expr/eval.d.ts +1 -1
- package/dist/declarations/src/future/fetchVal.d.ts +5 -0
- package/dist/declarations/src/index.d.ts +36 -9
- package/dist/declarations/src/initSchema.d.ts +2 -10
- package/dist/declarations/src/initVal.d.ts +3 -21
- package/dist/declarations/src/module.d.ts +2 -14
- package/dist/declarations/src/schema/image.d.ts +1 -1
- package/dist/declarations/src/schema/index.d.ts +3 -5
- package/dist/declarations/src/schema/keyOf.d.ts +23 -0
- package/dist/declarations/src/schema/record.d.ts +19 -0
- package/dist/declarations/src/schema/union.d.ts +1 -0
- package/dist/declarations/src/selector/SelectorProxy.d.ts +7 -0
- package/dist/declarations/src/selector/array.d.ts +2 -13
- package/dist/declarations/src/selector/file.d.ts +1 -4
- package/dist/declarations/src/selector/future/array.d.ts +17 -0
- package/dist/declarations/src/selector/future/boolean.d.ts +2 -0
- package/dist/declarations/src/selector/future/file.d.ts +9 -0
- package/dist/declarations/src/selector/{i18n.d.ts → future/i18n.d.ts} +2 -2
- package/dist/declarations/src/selector/future/index.d.ts +81 -0
- package/dist/declarations/src/selector/future/number.d.ts +2 -0
- package/dist/declarations/src/selector/future/object.d.ts +10 -0
- package/dist/declarations/src/selector/future/primitive.d.ts +9 -0
- package/dist/declarations/src/selector/{remote.d.ts → future/remote.d.ts} +1 -1
- package/dist/declarations/src/selector/future/string.d.ts +2 -0
- package/dist/declarations/src/selector/index.d.ts +5 -32
- package/dist/declarations/src/selector/object.d.ts +2 -9
- package/dist/declarations/src/selector/primitive.d.ts +3 -9
- package/dist/declarations/src/source/{i18n.d.ts → future/i18n.d.ts} +2 -2
- package/dist/declarations/src/source/{remote.d.ts → future/remote.d.ts} +3 -3
- package/dist/declarations/src/source/index.d.ts +4 -3
- package/dist/declarations/src/val/index.d.ts +2 -2
- package/dist/{SelectorProxy-63c2d0e2.esm.js → index-369caccf.esm.js} +23 -195
- package/dist/{index-af761363.esm.js → index-3e3e839e.esm.js} +189 -1
- package/dist/{index-2fff5ca8.cjs.dev.js → index-486c7fbf.cjs.dev.js} +242 -54
- package/dist/{index-cac9ecbd.cjs.prod.js → index-601a7d73.cjs.prod.js} +242 -54
- package/dist/{SelectorProxy-2af1b2b8.cjs.prod.js → index-8706c87e.cjs.prod.js} +25 -199
- package/dist/{SelectorProxy-873782a5.cjs.dev.js → index-a6e642dd.cjs.dev.js} +25 -199
- package/dist/{ops-1b6e0e35.cjs.prod.js → ops-0d09f8ee.cjs.prod.js} +258 -126
- package/dist/{ops-74661336.esm.js → ops-23a5abb2.esm.js} +195 -65
- package/dist/{ops-ea4827fc.cjs.dev.js → ops-f3015423.cjs.dev.js} +258 -126
- package/dist/valbuild-core.cjs.dev.js +585 -198
- package/dist/valbuild-core.cjs.prod.js +585 -198
- package/dist/valbuild-core.esm.js +520 -134
- package/expr/dist/valbuild-core-expr.cjs.dev.js +8 -8
- package/expr/dist/valbuild-core-expr.cjs.prod.js +8 -8
- package/expr/dist/valbuild-core-expr.esm.js +2 -2
- package/package.json +2 -3
- package/patch/dist/valbuild-core-patch.cjs.dev.js +24 -24
- package/patch/dist/valbuild-core-patch.cjs.prod.js +24 -24
- package/patch/dist/valbuild-core-patch.esm.js +3 -3
- package/src/ValApi.ts +85 -0
- package/src/expr/eval.test.ts +2 -2
- package/src/expr/eval.ts +2 -2
- package/src/{fetchVal.test.ts → future/fetchVal.test.ts} +57 -57
- package/src/{fetchVal.ts → future/fetchVal.ts} +17 -22
- package/src/index.ts +46 -14
- package/src/initSchema.ts +11 -12
- package/src/initVal.ts +42 -52
- package/src/module.test.ts +40 -40
- package/src/module.ts +53 -43
- package/src/patch/deref.test.ts +1 -1
- package/src/patch/deref.ts +1 -1
- package/src/patch/json.test.ts +0 -1
- package/src/schema/{i18n.ts → future/i18n.ts} +12 -10
- package/src/schema/{oneOf.ts → future/oneOf.ts} +19 -17
- package/src/schema/image.ts +1 -1
- package/src/schema/index.ts +16 -13
- package/src/schema/keyOf.ts +167 -0
- package/src/schema/record.ts +103 -0
- package/src/schema/union.ts +1 -1
- package/src/schema/validation.test.ts +195 -130
- package/src/selector/SelectorProxy.ts +15 -15
- package/src/selector/array.ts +2 -26
- package/src/selector/file.ts +1 -9
- package/src/selector/{ExprProxy.test.ts → future/ExprProxy.test.ts} +2 -2
- package/src/selector/{ExprProxy.ts → future/ExprProxy.ts} +9 -2
- package/src/selector/{SelectorProxy.test.ts → future/SelectorProxy.test.ts} +4 -4
- package/src/selector/future/SelectorProxy.ts +238 -0
- package/src/selector/future/array.ts +37 -0
- package/src/selector/future/boolean.ts +4 -0
- package/src/selector/future/file.ts +14 -0
- package/src/selector/{i18n.ts → future/i18n.ts} +2 -2
- package/src/selector/future/index.ts +165 -0
- package/src/selector/future/number.ts +4 -0
- package/src/selector/future/object.ts +22 -0
- package/src/selector/future/primitive.ts +17 -0
- package/src/selector/{remote.ts → future/remote.ts} +1 -1
- package/src/selector/{selector.test.ts → future/selector.test.ts} +8 -28
- package/src/selector/{selectorOf.ts → future/selectorOf.ts} +1 -1
- package/src/selector/future/string.ts +4 -0
- package/src/selector/index.ts +4 -46
- package/src/selector/object.ts +2 -19
- package/src/selector/primitive.ts +3 -16
- package/src/source/{i18n.ts → future/i18n.ts} +2 -2
- package/src/source/{remote.ts → future/remote.ts} +3 -3
- package/src/source/index.ts +3 -2
- package/src/val/array.ts +1 -1
- package/src/val/index.ts +2 -2
- package/src/val/object.ts +1 -1
- package/dist/declarations/src/fetchVal.d.ts +0 -5
- package/dist/declarations/src/schema/i18n.d.ts +0 -22
- package/dist/declarations/src/schema/oneOf.d.ts +0 -23
@@ -1,6 +1,6 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
|
-
var
|
3
|
+
var index$1 = require('./index-a6e642dd.cjs.dev.js');
|
4
4
|
var result = require('./result-48320acd.cjs.dev.js');
|
5
5
|
|
6
6
|
var WHITE_SPACE = ["\n", "\r", "\t", " "];
|
@@ -71,7 +71,7 @@ function tokenize(input) {
|
|
71
71
|
}
|
72
72
|
var cursorOffset = peek === "'" && !escaped ? 2 : _char === "$" && peek === "{" ? 3 : 1;
|
73
73
|
if (value) {
|
74
|
-
tokens.push(
|
74
|
+
tokens.push(index$1._objectSpread2({
|
75
75
|
type: "string",
|
76
76
|
span: [_start + 1, cursor - cursorOffset],
|
77
77
|
value: value
|
@@ -118,8 +118,8 @@ function tokenize(input) {
|
|
118
118
|
return [tokens, cursor];
|
119
119
|
}
|
120
120
|
|
121
|
-
var ParserError = /*#__PURE__*/
|
122
|
-
|
121
|
+
var ParserError = /*#__PURE__*/index$1._createClass(function ParserError(message, span) {
|
122
|
+
index$1._classCallCheck(this, ParserError);
|
123
123
|
this.message = message;
|
124
124
|
this.span = span;
|
125
125
|
});
|
@@ -131,7 +131,7 @@ function parseTokens(inputTokens) {
|
|
131
131
|
if (((_tokens$ = tokens[0]) === null || _tokens$ === void 0 ? void 0 : _tokens$.type) === "ws" && ((_tokens$2 = tokens[1]) === null || _tokens$2 === void 0 ? void 0 : _tokens$2.type) === ")" || ((_tokens$3 = tokens[0]) === null || _tokens$3 === void 0 ? void 0 : _tokens$3.type) === ")") {
|
132
132
|
slurpWs();
|
133
133
|
tokens.shift();
|
134
|
-
return result.ok(new
|
134
|
+
return result.ok(new index$1.Sym("()", [first.span[0], first.span[1] + 1]));
|
135
135
|
}
|
136
136
|
var args = [];
|
137
137
|
var completed = false;
|
@@ -152,7 +152,7 @@ function parseTokens(inputTokens) {
|
|
152
152
|
if ((last === null || last === void 0 ? void 0 : last.type) !== ")") {
|
153
153
|
return result.err(new ParserError("unbalanced parens: missing a ')'", [first.span[0], first.span[1] + 1]));
|
154
154
|
}
|
155
|
-
return result.ok(new
|
155
|
+
return result.ok(new index$1.Call(args, isAnon, [first.span[0], ((_args$slice$0$span = args.slice(-1)[0].span) === null || _args$slice$0$span === void 0 ? void 0 : _args$slice$0$span[1]) || -1]));
|
156
156
|
}
|
157
157
|
function slurpWs() {
|
158
158
|
while (((_tokens$9 = tokens[0]) === null || _tokens$9 === void 0 ? void 0 : _tokens$9.type) === "ws") {
|
@@ -183,7 +183,7 @@ function parseTokens(inputTokens) {
|
|
183
183
|
return _res2;
|
184
184
|
}
|
185
185
|
} else if ((nextToken === null || nextToken === void 0 ? void 0 : nextToken.type) === "string") {
|
186
|
-
children.push(new
|
186
|
+
children.push(new index$1.StringLiteral(nextToken.unescapedValue || nextToken.value || "", nextToken.span));
|
187
187
|
}
|
188
188
|
}
|
189
189
|
var last = tokens.shift();
|
@@ -193,7 +193,7 @@ function parseTokens(inputTokens) {
|
|
193
193
|
} else if (last.type !== "'") {
|
194
194
|
return result.err(new ParserError("unbalanced string template: expected '''", last.span));
|
195
195
|
}
|
196
|
-
return result.ok(new
|
196
|
+
return result.ok(new index$1.StringTemplate(children, [first.span[0], last.span[1]]));
|
197
197
|
}
|
198
198
|
function slurpString(first) {
|
199
199
|
var _tokens$11, _tokens$12, _tokens$13;
|
@@ -203,13 +203,13 @@ function parseTokens(inputTokens) {
|
|
203
203
|
if (!last || !stringToken) {
|
204
204
|
throw Error("Unexpected error: stringToken or last is undefined");
|
205
205
|
}
|
206
|
-
return result.ok(new
|
206
|
+
return result.ok(new index$1.StringLiteral(stringToken.unescapedValue || stringToken.value || "", [first.span[0], last.span[1]]));
|
207
207
|
} else if (((_tokens$13 = tokens[0]) === null || _tokens$13 === void 0 ? void 0 : _tokens$13.type) === "'") {
|
208
208
|
var _last2 = tokens.shift();
|
209
209
|
if (!_last2) {
|
210
210
|
throw Error("Unexpected error: last is undefined");
|
211
211
|
}
|
212
|
-
return result.ok(new
|
212
|
+
return result.ok(new index$1.StringLiteral("", [first.span[0], _last2.span[1]]));
|
213
213
|
} else {
|
214
214
|
return slurpTemplate(first);
|
215
215
|
}
|
@@ -238,7 +238,7 @@ function parseTokens(inputTokens) {
|
|
238
238
|
if ((_first$value5 = first.value) !== null && _first$value5 !== void 0 && _first$value5.includes("{") || (_first$value6 = first.value) !== null && _first$value6 !== void 0 && _first$value6.includes("}")) {
|
239
239
|
return result.err(new ParserError("unexpected token: '{' and '}' are not allowed in tokens", first.span));
|
240
240
|
}
|
241
|
-
return result.ok(new
|
241
|
+
return result.ok(new index$1.Sym(first.value || "", first.span));
|
242
242
|
} else {
|
243
243
|
return result.err(new ParserError("expected '(', '!(' or literal or token".concat(first.value || first.type ? ", got: '".concat(first.value || first.type, "'") : ""), first.span));
|
244
244
|
}
|
@@ -256,19 +256,207 @@ function parseTokens(inputTokens) {
|
|
256
256
|
function parse(input) {
|
257
257
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
258
258
|
var _tokenize = tokenize(input),
|
259
|
-
_tokenize2 =
|
259
|
+
_tokenize2 = index$1._slicedToArray(_tokenize, 2),
|
260
260
|
tokens = _tokenize2[0];
|
261
261
|
_tokenize2[1]; // TODO: we can use cursor to improve error messages / spans
|
262
262
|
return parseTokens(tokens);
|
263
263
|
}
|
264
264
|
|
265
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
266
|
+
|
267
|
+
/**
|
268
|
+
* Selectors can be used to select parts of a Val module.
|
269
|
+
* Unlike queries, joins, aggregates etc is and will not be supported.
|
270
|
+
*
|
271
|
+
* They are designed to be be used as if they were "normal" JSON data,
|
272
|
+
* though some concessions had to be made because of TypeScript limitations.
|
273
|
+
*
|
274
|
+
* Selectors works equally on source content, defined in code, and remote content.
|
275
|
+
*
|
276
|
+
* @example
|
277
|
+
* // Select the title of a document
|
278
|
+
* const titles = useVal(docsVal.map((doc) => doc.title));
|
279
|
+
*
|
280
|
+
* @example
|
281
|
+
* // Match on a union type
|
282
|
+
* const titles = useVal(docsVal.map((doc) => doc.fold("type")({
|
283
|
+
* newsletter: (newsletter) => newsletter.title,
|
284
|
+
* email: (email) => email.subject,
|
285
|
+
* }));
|
286
|
+
*
|
287
|
+
*/
|
288
|
+
|
289
|
+
/**
|
290
|
+
* @internal
|
291
|
+
*/
|
292
|
+
var GetSchema = Symbol("GetSchema");
|
293
|
+
/**
|
294
|
+
/**
|
295
|
+
* @internal
|
296
|
+
*/
|
297
|
+
var Path = Symbol("Path");
|
298
|
+
/**
|
299
|
+
* @internal
|
300
|
+
*/
|
301
|
+
var SourceOrExpr = Symbol("SourceOrExpr");
|
302
|
+
|
303
|
+
/**
|
304
|
+
* Use this type to convert types that accepts both Source and Selectors
|
305
|
+
*
|
306
|
+
* An example would be where literals are supported like in most higher order functions (e.g. map in array)
|
307
|
+
**/
|
308
|
+
|
309
|
+
function hasOwn(obj, prop) {
|
310
|
+
return Object.prototype.hasOwnProperty.call(obj, prop);
|
311
|
+
}
|
312
|
+
function _andThen(f, source, path) {
|
313
|
+
if (source) {
|
314
|
+
return newSelectorProxy(f(newSelectorProxy(source, path)));
|
315
|
+
}
|
316
|
+
return newSelectorProxy(source, path);
|
317
|
+
}
|
318
|
+
function isSelector(source) {
|
319
|
+
return index$1._typeof(source) === "object" && source !== null && (SourceOrExpr in source || Path in source);
|
320
|
+
}
|
321
|
+
function newSelectorProxy(source, path, moduleSchema) {
|
322
|
+
var _ref;
|
323
|
+
if (index$1._typeof(source) === "object") {
|
324
|
+
if (isSelector(source)) {
|
325
|
+
return source;
|
326
|
+
} else if (index$1.isSerializedVal(source)) {
|
327
|
+
return newSelectorProxy(source.val, source.valPath);
|
328
|
+
}
|
329
|
+
}
|
330
|
+
if (source && source[index$1.FILE_REF_PROP] && source[index$1.VAL_EXTENSION] === "file") {
|
331
|
+
var fileRef = source[index$1.FILE_REF_PROP];
|
332
|
+
if (typeof fileRef !== "string") {
|
333
|
+
throw Error("Invalid file ref: " + fileRef);
|
334
|
+
}
|
335
|
+
return newSelectorProxy(index$1.convertFileSource(source), path, moduleSchema);
|
336
|
+
}
|
337
|
+
switch (index$1._typeof(source)) {
|
338
|
+
case "function":
|
339
|
+
case "symbol":
|
340
|
+
throw Error("Invalid selector type: ".concat(index$1._typeof(source), ": ").concat(source));
|
341
|
+
case "object":
|
342
|
+
// Handles both objects and arrays!
|
343
|
+
if (source !== null) {
|
344
|
+
return new Proxy(source, {
|
345
|
+
// TODO: see proxy docs if we want more traps
|
346
|
+
has: function has(target, prop) {
|
347
|
+
if (prop === SourceOrExpr) {
|
348
|
+
return true;
|
349
|
+
}
|
350
|
+
if (prop === Path) {
|
351
|
+
return true;
|
352
|
+
}
|
353
|
+
if (prop === "andThen") {
|
354
|
+
return true;
|
355
|
+
}
|
356
|
+
if (prop === GetSchema) {
|
357
|
+
return true;
|
358
|
+
}
|
359
|
+
return prop in target;
|
360
|
+
},
|
361
|
+
get: function get(target, prop) {
|
362
|
+
if (prop === SourceOrExpr) {
|
363
|
+
return source;
|
364
|
+
}
|
365
|
+
if (prop === Path) {
|
366
|
+
return path;
|
367
|
+
}
|
368
|
+
if (prop === GetSchema) {
|
369
|
+
return moduleSchema;
|
370
|
+
}
|
371
|
+
if (prop === "andThen") {
|
372
|
+
return function (f) {
|
373
|
+
return _andThen(f, source, path);
|
374
|
+
};
|
375
|
+
}
|
376
|
+
if (Array.isArray(target)) {
|
377
|
+
if (prop === "filter") {
|
378
|
+
return function (f) {
|
379
|
+
var filtered = target.map(function (a, i) {
|
380
|
+
return newSelectorProxy(a, createValPathOfItem(path, i), moduleSchema === null || moduleSchema === void 0 ? void 0 : moduleSchema.item);
|
381
|
+
}).filter(function (a) {
|
382
|
+
if (f && f instanceof index$1.Schema) {
|
383
|
+
return f.assert(unValify(a));
|
384
|
+
} else {
|
385
|
+
return unValify(f(a));
|
386
|
+
}
|
387
|
+
});
|
388
|
+
return newSelectorProxy(filtered, path, moduleSchema);
|
389
|
+
};
|
390
|
+
} else if (prop === "map") {
|
391
|
+
return function (f) {
|
392
|
+
var filtered = target.map(function (a, i) {
|
393
|
+
var valueOrSelector = f(newSelectorProxy(a, createValPathOfItem(path, i), moduleSchema === null || moduleSchema === void 0 ? void 0 : moduleSchema.item), newSelectorProxy(i));
|
394
|
+
if (isSelector(valueOrSelector)) {
|
395
|
+
return valueOrSelector;
|
396
|
+
}
|
397
|
+
return newSelectorProxy(valueOrSelector);
|
398
|
+
});
|
399
|
+
return newSelectorProxy(filtered, path, moduleSchema);
|
400
|
+
};
|
401
|
+
}
|
402
|
+
}
|
403
|
+
if (Array.isArray(target) && prop === "length") {
|
404
|
+
return newSelectorProxy(target.length);
|
405
|
+
}
|
406
|
+
var reflectedValue = Reflect.get(target, prop);
|
407
|
+
if (hasOwn(source, prop)) {
|
408
|
+
if (!Number.isNaN(Number(prop))) {
|
409
|
+
return newSelectorProxy(reflectedValue, createValPathOfItem(path, Number(prop)), moduleSchema === null || moduleSchema === void 0 ? void 0 : moduleSchema.item);
|
410
|
+
}
|
411
|
+
return newSelectorProxy(reflectedValue, createValPathOfItem(path, prop), moduleSchema === null || moduleSchema === void 0 ? void 0 : moduleSchema.items[prop]);
|
412
|
+
}
|
413
|
+
return reflectedValue;
|
414
|
+
}
|
415
|
+
});
|
416
|
+
}
|
417
|
+
// intentional fallthrough
|
418
|
+
// eslint-disable-next-line no-fallthrough
|
419
|
+
default:
|
420
|
+
return _ref = {
|
421
|
+
eq: function eq(other) {
|
422
|
+
var otherValue = other;
|
423
|
+
if (isSelector(other)) {
|
424
|
+
otherValue = other[SourceOrExpr];
|
425
|
+
if (otherValue instanceof index$1.Expr) {
|
426
|
+
throw Error("TODO: Cannot evaluate equality with an Expr");
|
427
|
+
}
|
428
|
+
}
|
429
|
+
return newSelectorProxy(source === otherValue, undefined);
|
430
|
+
},
|
431
|
+
andThen: function andThen(f) {
|
432
|
+
return _andThen(f, source === undefined ? null : source, path);
|
433
|
+
}
|
434
|
+
}, index$1._defineProperty(_ref, SourceOrExpr, source === undefined ? null : source), index$1._defineProperty(_ref, Path, path), index$1._defineProperty(_ref, GetSchema, moduleSchema), _ref;
|
435
|
+
}
|
436
|
+
}
|
437
|
+
function createValPathOfItem(arrayPath, prop) {
|
438
|
+
if (index$1._typeof(prop) === "symbol") {
|
439
|
+
throw Error("Cannot create val path of array item with symbol prop: ".concat(prop.toString()));
|
440
|
+
}
|
441
|
+
return arrayPath && "".concat(arrayPath, ".").concat(JSON.stringify(prop));
|
442
|
+
}
|
443
|
+
|
444
|
+
// TODO: could we do .val on the objects instead?
|
445
|
+
function unValify(valueOrSelector) {
|
446
|
+
if (index$1._typeof(valueOrSelector) === "object" && (SourceOrExpr in valueOrSelector || Path in valueOrSelector)) {
|
447
|
+
var selectorValue = valueOrSelector[SourceOrExpr];
|
448
|
+
return selectorValue;
|
449
|
+
}
|
450
|
+
return valueOrSelector;
|
451
|
+
}
|
452
|
+
|
265
453
|
var EvalError = /*#__PURE__*/function () {
|
266
454
|
function EvalError(message, expr) {
|
267
|
-
|
455
|
+
index$1._classCallCheck(this, EvalError);
|
268
456
|
this.message = message;
|
269
457
|
this.expr = expr;
|
270
458
|
}
|
271
|
-
|
459
|
+
index$1._createClass(EvalError, [{
|
272
460
|
key: "toString",
|
273
461
|
value: function toString() {
|
274
462
|
return "".concat(this.message, " in: ").concat(this.expr.transpile());
|
@@ -286,15 +474,15 @@ function evaluateSync(expr, getSource, stack) {
|
|
286
474
|
}).join(", ");
|
287
475
|
}).join(" -> ")), expr);
|
288
476
|
}
|
289
|
-
if (expr instanceof
|
290
|
-
if (expr.children[0] instanceof
|
477
|
+
if (expr instanceof index$1.Call) {
|
478
|
+
if (expr.children[0] instanceof index$1.Sym) {
|
291
479
|
if (expr.children[0].value === "val") {
|
292
480
|
if (expr.isAnon) {
|
293
481
|
throw new EvalError("cannot call 'val' as anonymous function", expr);
|
294
482
|
}
|
295
|
-
if (expr.children[1] instanceof
|
483
|
+
if (expr.children[1] instanceof index$1.StringLiteral) {
|
296
484
|
var _path = expr.children[1].value;
|
297
|
-
return
|
485
|
+
return newSelectorProxy(getSource(_path), _path);
|
298
486
|
} else {
|
299
487
|
throw new EvalError("argument of 'val' must be a string literal", expr);
|
300
488
|
}
|
@@ -303,17 +491,17 @@ function evaluateSync(expr, getSource, stack) {
|
|
303
491
|
throw new EvalError("must call 'json' with exactly one argument", expr);
|
304
492
|
}
|
305
493
|
var value = evaluateSync(expr.children[1], getSource, stack);
|
306
|
-
var valObj = value[
|
307
|
-
var valPath = value[
|
494
|
+
var valObj = value[SourceOrExpr];
|
495
|
+
var valPath = value[Path];
|
308
496
|
if (typeof valObj !== "string") {
|
309
497
|
throw new EvalError("cannot parse JSON: ".concat(JSON.stringify(valObj), ", expected string"), expr.children[1]);
|
310
498
|
}
|
311
499
|
try {
|
312
500
|
var serialized = JSON.parse(valObj);
|
313
|
-
if (
|
314
|
-
return
|
501
|
+
if (index$1.isSerializedVal(serialized)) {
|
502
|
+
return newSelectorProxy(serialized.val, serialized.valPath);
|
315
503
|
}
|
316
|
-
var parsedValue =
|
504
|
+
var parsedValue = newSelectorProxy(JSON.parse(valObj), valPath);
|
317
505
|
return parsedValue;
|
318
506
|
} catch (e) {
|
319
507
|
if (e instanceof SyntaxError) {
|
@@ -327,13 +515,13 @@ function evaluateSync(expr, getSource, stack) {
|
|
327
515
|
throw new EvalError("must call 'stringify' with exactly one argument", expr);
|
328
516
|
}
|
329
517
|
var res = evaluateSync(expr.children[1], getSource, stack);
|
330
|
-
return
|
518
|
+
return newSelectorProxy(JSON.stringify(res[SourceOrExpr]));
|
331
519
|
}
|
332
520
|
}
|
333
|
-
var prop = evaluateSync(expr.children[0], getSource, stack)[
|
521
|
+
var prop = evaluateSync(expr.children[0], getSource, stack)[SourceOrExpr];
|
334
522
|
if (expr.children.length === 1) {
|
335
523
|
// TODO: return if literal only?
|
336
|
-
return
|
524
|
+
return newSelectorProxy(prop);
|
337
525
|
}
|
338
526
|
var obj = evaluateSync(expr.children[1], getSource, stack);
|
339
527
|
if (typeof prop !== "string" && typeof prop !== "number") {
|
@@ -344,9 +532,9 @@ function evaluateSync(expr, getSource, stack) {
|
|
344
532
|
// anon functions:
|
345
533
|
var maybeFunction = obj[prop];
|
346
534
|
if (typeof maybeFunction !== "function") {
|
347
|
-
throw new EvalError("cannot access property ".concat(JSON.stringify(prop), " of ").concat(JSON.stringify(obj), ": required higher ordered function got ").concat(
|
535
|
+
throw new EvalError("cannot access property ".concat(JSON.stringify(prop), " of ").concat(JSON.stringify(obj), ": required higher ordered function got ").concat(index$1._typeof(obj[prop])), expr);
|
348
536
|
}
|
349
|
-
if (expr.children[0] instanceof
|
537
|
+
if (expr.children[0] instanceof index$1.Sym) {
|
350
538
|
return maybeFunction(function () {
|
351
539
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
352
540
|
args[_key] = arguments[_key];
|
@@ -358,11 +546,11 @@ function evaluateSync(expr, getSource, stack) {
|
|
358
546
|
}
|
359
547
|
} else {
|
360
548
|
// non-anon functions:
|
361
|
-
if (expr.children[0] instanceof
|
549
|
+
if (expr.children[0] instanceof index$1.Sym) {
|
362
550
|
if (expr.children[0].value === "val") {
|
363
|
-
if (expr.children[1] instanceof
|
551
|
+
if (expr.children[1] instanceof index$1.StringLiteral) {
|
364
552
|
var _path2 = expr.children[1].value;
|
365
|
-
return
|
553
|
+
return newSelectorProxy(getSource(_path2), _path2);
|
366
554
|
} else {
|
367
555
|
throw new EvalError("argument of 'val' must be a string literal", expr);
|
368
556
|
}
|
@@ -372,24 +560,24 @@ function evaluateSync(expr, getSource, stack) {
|
|
372
560
|
if (args.length > 0) {
|
373
561
|
var _maybeFunction = obj[prop];
|
374
562
|
if (typeof _maybeFunction !== "function") {
|
375
|
-
throw new EvalError("cannot access property ".concat(JSON.stringify(prop), " of ").concat(JSON.stringify(obj), ": required function got ").concat(
|
563
|
+
throw new EvalError("cannot access property ".concat(JSON.stringify(prop), " of ").concat(JSON.stringify(obj), ": required function got ").concat(index$1._typeof(obj[prop])), expr);
|
376
564
|
}
|
377
|
-
return _maybeFunction.apply(void 0,
|
565
|
+
return _maybeFunction.apply(void 0, index$1._toConsumableArray(args.map(function (arg) {
|
378
566
|
return evaluateSync(arg, getSource, stack);
|
379
567
|
})));
|
380
568
|
}
|
381
569
|
var maybeValue = obj[prop];
|
382
570
|
if (typeof maybeValue === "function") {
|
383
|
-
throw new EvalError("cannot access property ".concat(JSON.stringify(prop), " of ").concat(JSON.stringify(obj), ": required value got ").concat(
|
571
|
+
throw new EvalError("cannot access property ".concat(JSON.stringify(prop), " of ").concat(JSON.stringify(obj), ": required value got ").concat(index$1._typeof(obj[prop])), expr);
|
384
572
|
}
|
385
573
|
return maybeValue;
|
386
574
|
}
|
387
575
|
}
|
388
|
-
} else if (expr instanceof
|
576
|
+
} else if (expr instanceof index$1.Sym) {
|
389
577
|
if (expr.value.startsWith("@")) {
|
390
578
|
var _stack$Number;
|
391
579
|
var _expr$value$slice$spl = expr.value.slice(2, -1).split(","),
|
392
|
-
_expr$value$slice$spl2 =
|
580
|
+
_expr$value$slice$spl2 = index$1._slicedToArray(_expr$value$slice$spl, 3),
|
393
581
|
i = _expr$value$slice$spl2[0],
|
394
582
|
j = _expr$value$slice$spl2[1],
|
395
583
|
rest = _expr$value$slice$spl2[2];
|
@@ -402,28 +590,28 @@ function evaluateSync(expr, getSource, stack) {
|
|
402
590
|
}
|
403
591
|
return stackValue;
|
404
592
|
} else if (expr.value === "()") {
|
405
|
-
return
|
593
|
+
return newSelectorProxy(null);
|
406
594
|
}
|
407
|
-
return
|
408
|
-
} else if (expr instanceof
|
409
|
-
return
|
410
|
-
} else if (expr instanceof
|
411
|
-
return
|
412
|
-
if (child instanceof
|
595
|
+
return newSelectorProxy(expr.value);
|
596
|
+
} else if (expr instanceof index$1.StringLiteral) {
|
597
|
+
return newSelectorProxy(expr.value);
|
598
|
+
} else if (expr instanceof index$1.StringTemplate) {
|
599
|
+
return newSelectorProxy(expr.children.map(function (child) {
|
600
|
+
if (child instanceof index$1.Sym && child.value === "()") {
|
413
601
|
return "null";
|
414
602
|
}
|
415
603
|
var evalRes = evaluateSync(child, getSource, stack);
|
416
604
|
if (child.type === "StringLiteral" || child.type === "StringTemplate") {
|
417
|
-
return evalRes[
|
605
|
+
return evalRes[SourceOrExpr];
|
418
606
|
}
|
419
|
-
if (
|
607
|
+
if (Path in evalRes) {
|
420
608
|
// a selector, so serialize to Val
|
421
609
|
return JSON.stringify({
|
422
|
-
val: evalRes[
|
423
|
-
valPath: evalRes[
|
610
|
+
val: evalRes[SourceOrExpr],
|
611
|
+
valPath: evalRes[Path]
|
424
612
|
});
|
425
613
|
}
|
426
|
-
return JSON.stringify(evalRes[
|
614
|
+
return JSON.stringify(evalRes[SourceOrExpr]);
|
427
615
|
}).join(""));
|
428
616
|
}
|
429
617
|
throw new EvalError("could not evaluate", expr);
|
@@ -442,12 +630,12 @@ function evaluate(expr, source, stack) {
|
|
442
630
|
var index = /*#__PURE__*/Object.freeze({
|
443
631
|
__proto__: null,
|
444
632
|
parse: parse,
|
445
|
-
Call:
|
446
|
-
Expr:
|
447
|
-
NilSym:
|
448
|
-
StringLiteral:
|
449
|
-
StringTemplate:
|
450
|
-
Sym:
|
633
|
+
Call: index$1.Call,
|
634
|
+
Expr: index$1.Expr,
|
635
|
+
NilSym: index$1.NilSym,
|
636
|
+
StringLiteral: index$1.StringLiteral,
|
637
|
+
StringTemplate: index$1.StringTemplate,
|
638
|
+
Sym: index$1.Sym,
|
451
639
|
evaluate: evaluate
|
452
640
|
});
|
453
641
|
|