@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
@@ -220,21 +220,26 @@ function _createSuper(Derived) {
|
|
220
220
|
};
|
221
221
|
}
|
222
222
|
|
223
|
+
// import { RemoteCompatibleSource, RemoteSource } from "../source/remote";
|
224
|
+
|
225
|
+
// import { SerializedI18nSchema } from "./future/i18n";
|
226
|
+
// import { SerializedOneOfSchema } from "./future/oneOf";
|
223
227
|
var Schema = /*#__PURE__*/function () {
|
224
228
|
function Schema() {
|
225
229
|
_classCallCheck(this, Schema);
|
226
230
|
}
|
227
231
|
_createClass(Schema, [{
|
228
|
-
key: "
|
229
|
-
value:
|
230
|
-
|
231
|
-
|
232
|
-
|
232
|
+
key: "appendValidationError",
|
233
|
+
value:
|
234
|
+
// remote(): Src extends RemoteCompatibleSource
|
235
|
+
// ? Schema<RemoteSource<Src>>
|
236
|
+
// : never {
|
237
|
+
// // TODO: Schema<never, "Cannot create remote schema from non-remote source.">
|
238
|
+
// throw new Error("You need Val Ultra to use .remote()");
|
239
|
+
// }
|
233
240
|
|
234
241
|
/** MUTATES! since internal and perf sensitive */
|
235
|
-
|
236
|
-
key: "appendValidationError",
|
237
|
-
value: function appendValidationError(current, path, message, value) {
|
242
|
+
function appendValidationError(current, path, message, value) {
|
238
243
|
if (current) {
|
239
244
|
if (current[path]) {
|
240
245
|
current[path].push({
|
@@ -261,30 +266,6 @@ var Schema = /*#__PURE__*/function () {
|
|
261
266
|
|
262
267
|
// TODO: SourceError<"Could not determine type of Schema">
|
263
268
|
|
264
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
265
|
-
|
266
|
-
/**
|
267
|
-
* Selectors can be used to select parts of a Val module.
|
268
|
-
* Unlike queries, joins, aggregates etc is and will not be supported.
|
269
|
-
*
|
270
|
-
* They are designed to be be used as if they were "normal" JSON data,
|
271
|
-
* though some concessions had to be made because of TypeScript limitations.
|
272
|
-
*
|
273
|
-
* Selectors works equally on source content, defined in code, and remote content.
|
274
|
-
*
|
275
|
-
* @example
|
276
|
-
* // Select the title of a document
|
277
|
-
* const titles = useVal(docsVal.map((doc) => doc.title));
|
278
|
-
*
|
279
|
-
* @example
|
280
|
-
* // Match on a union type
|
281
|
-
* const titles = useVal(docsVal.map((doc) => doc.fold("type")({
|
282
|
-
* newsletter: (newsletter) => newsletter.title,
|
283
|
-
* email: (email) => email.subject,
|
284
|
-
* }));
|
285
|
-
*
|
286
|
-
*/
|
287
|
-
|
288
269
|
/**
|
289
270
|
* @internal
|
290
271
|
*/
|
@@ -297,27 +278,18 @@ var Path = Symbol("Path");
|
|
297
278
|
/**
|
298
279
|
* @internal
|
299
280
|
*/
|
300
|
-
var
|
281
|
+
var GetSource = Symbol("GetSource");
|
301
282
|
/**
|
302
283
|
* @internal
|
303
284
|
*/
|
304
285
|
var ValError = Symbol("ValError");
|
305
|
-
var GenericSelector = /*#__PURE__*/function () {
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
}
|
313
|
-
_createClass(GenericSelector, [{
|
314
|
-
key: "assert",
|
315
|
-
value: function assert(schema, other) {
|
316
|
-
throw new Error("Not implemented");
|
317
|
-
}
|
318
|
-
}]);
|
319
|
-
return GenericSelector;
|
320
|
-
}();
|
286
|
+
var GenericSelector = /*#__PURE__*/_createClass(function GenericSelector(valOrExpr, path, schema, error) {
|
287
|
+
_classCallCheck(this, GenericSelector);
|
288
|
+
this[Path] = path;
|
289
|
+
this[GetSource] = valOrExpr;
|
290
|
+
this[ValError] = error;
|
291
|
+
this[GetSchema] = schema;
|
292
|
+
});
|
321
293
|
|
322
294
|
/**
|
323
295
|
* Use this type to convert types that accepts both Source and Selectors
|
@@ -536,7 +508,7 @@ var ImageSchema = /*#__PURE__*/function (_Schema) {
|
|
536
508
|
var image = function image(options) {
|
537
509
|
return new ImageSchema(options);
|
538
510
|
};
|
539
|
-
var
|
511
|
+
var convertFileSource = function convertFileSource(src) {
|
540
512
|
var _src$metadata;
|
541
513
|
// TODO: /public should be configurable
|
542
514
|
return {
|
@@ -577,159 +549,16 @@ function getValPath(valOrSelector) {
|
|
577
549
|
return valOrSelector[Path];
|
578
550
|
}
|
579
551
|
|
580
|
-
function hasOwn(obj, prop) {
|
581
|
-
return Object.prototype.hasOwnProperty.call(obj, prop);
|
582
|
-
}
|
583
|
-
function _andThen(f, source, path) {
|
584
|
-
if (source) {
|
585
|
-
return newSelectorProxy(f(newSelectorProxy(source, path)));
|
586
|
-
}
|
587
|
-
return newSelectorProxy(source, path);
|
588
|
-
}
|
589
|
-
function isSelector(source) {
|
590
|
-
return _typeof(source) === "object" && source !== null && (SourceOrExpr in source || Path in source);
|
591
|
-
}
|
592
|
-
function newSelectorProxy(source, path, moduleSchema) {
|
593
|
-
var _ref;
|
594
|
-
if (_typeof(source) === "object") {
|
595
|
-
if (isSelector(source)) {
|
596
|
-
return source;
|
597
|
-
} else if (isSerializedVal(source)) {
|
598
|
-
return newSelectorProxy(source.val, source.valPath);
|
599
|
-
}
|
600
|
-
}
|
601
|
-
if (source && source[FILE_REF_PROP] && source[VAL_EXTENSION] === "file") {
|
602
|
-
var fileRef = source[FILE_REF_PROP];
|
603
|
-
if (typeof fileRef !== "string") {
|
604
|
-
throw Error("Invalid file ref: " + fileRef);
|
605
|
-
}
|
606
|
-
return newSelectorProxy(convertImageSource(source), path, moduleSchema);
|
607
|
-
}
|
608
|
-
switch (_typeof(source)) {
|
609
|
-
case "function":
|
610
|
-
case "symbol":
|
611
|
-
throw Error("Invalid selector type: ".concat(_typeof(source), ": ").concat(source));
|
612
|
-
case "object":
|
613
|
-
// Handles both objects and arrays!
|
614
|
-
if (source !== null) {
|
615
|
-
return new Proxy(source, {
|
616
|
-
// TODO: see proxy docs if we want more traps
|
617
|
-
has: function has(target, prop) {
|
618
|
-
if (prop === SourceOrExpr) {
|
619
|
-
return true;
|
620
|
-
}
|
621
|
-
if (prop === Path) {
|
622
|
-
return true;
|
623
|
-
}
|
624
|
-
if (prop === "andThen") {
|
625
|
-
return true;
|
626
|
-
}
|
627
|
-
if (prop === GetSchema) {
|
628
|
-
return true;
|
629
|
-
}
|
630
|
-
return prop in target;
|
631
|
-
},
|
632
|
-
get: function get(target, prop) {
|
633
|
-
if (prop === SourceOrExpr) {
|
634
|
-
return source;
|
635
|
-
}
|
636
|
-
if (prop === Path) {
|
637
|
-
return path;
|
638
|
-
}
|
639
|
-
if (prop === GetSchema) {
|
640
|
-
return moduleSchema;
|
641
|
-
}
|
642
|
-
if (prop === "andThen") {
|
643
|
-
return function (f) {
|
644
|
-
return _andThen(f, source, path);
|
645
|
-
};
|
646
|
-
}
|
647
|
-
if (Array.isArray(target)) {
|
648
|
-
if (prop === "filter") {
|
649
|
-
return function (f) {
|
650
|
-
var filtered = target.map(function (a, i) {
|
651
|
-
return newSelectorProxy(a, createValPathOfItem(path, i), moduleSchema === null || moduleSchema === void 0 ? void 0 : moduleSchema.item);
|
652
|
-
}).filter(function (a) {
|
653
|
-
if (f && f instanceof Schema) {
|
654
|
-
return f.assert(unValify(a));
|
655
|
-
} else {
|
656
|
-
return unValify(f(a));
|
657
|
-
}
|
658
|
-
});
|
659
|
-
return newSelectorProxy(filtered, path, moduleSchema);
|
660
|
-
};
|
661
|
-
} else if (prop === "map") {
|
662
|
-
return function (f) {
|
663
|
-
var filtered = target.map(function (a, i) {
|
664
|
-
var valueOrSelector = f(newSelectorProxy(a, createValPathOfItem(path, i), moduleSchema === null || moduleSchema === void 0 ? void 0 : moduleSchema.item), newSelectorProxy(i));
|
665
|
-
if (isSelector(valueOrSelector)) {
|
666
|
-
return valueOrSelector;
|
667
|
-
}
|
668
|
-
return newSelectorProxy(valueOrSelector);
|
669
|
-
});
|
670
|
-
return newSelectorProxy(filtered, path, moduleSchema);
|
671
|
-
};
|
672
|
-
}
|
673
|
-
}
|
674
|
-
if (Array.isArray(target) && prop === "length") {
|
675
|
-
return newSelectorProxy(target.length);
|
676
|
-
}
|
677
|
-
var reflectedValue = Reflect.get(target, prop);
|
678
|
-
if (hasOwn(source, prop)) {
|
679
|
-
if (!Number.isNaN(Number(prop))) {
|
680
|
-
return newSelectorProxy(reflectedValue, createValPathOfItem(path, Number(prop)), moduleSchema === null || moduleSchema === void 0 ? void 0 : moduleSchema.item);
|
681
|
-
}
|
682
|
-
return newSelectorProxy(reflectedValue, createValPathOfItem(path, prop), moduleSchema === null || moduleSchema === void 0 ? void 0 : moduleSchema.items[prop]);
|
683
|
-
}
|
684
|
-
return reflectedValue;
|
685
|
-
}
|
686
|
-
});
|
687
|
-
}
|
688
|
-
// intentional fallthrough
|
689
|
-
// eslint-disable-next-line no-fallthrough
|
690
|
-
default:
|
691
|
-
return _ref = {
|
692
|
-
eq: function eq(other) {
|
693
|
-
var otherValue = other;
|
694
|
-
if (isSelector(other)) {
|
695
|
-
otherValue = other[SourceOrExpr];
|
696
|
-
if (otherValue instanceof Expr) {
|
697
|
-
throw Error("TODO: Cannot evaluate equality with an Expr");
|
698
|
-
}
|
699
|
-
}
|
700
|
-
return newSelectorProxy(source === otherValue, undefined);
|
701
|
-
},
|
702
|
-
andThen: function andThen(f) {
|
703
|
-
return _andThen(f, source === undefined ? null : source, path);
|
704
|
-
}
|
705
|
-
}, _defineProperty(_ref, SourceOrExpr, source === undefined ? null : source), _defineProperty(_ref, Path, path), _defineProperty(_ref, GetSchema, moduleSchema), _ref;
|
706
|
-
}
|
707
|
-
}
|
708
|
-
function createValPathOfItem(arrayPath, prop) {
|
709
|
-
if (_typeof(prop) === "symbol") {
|
710
|
-
throw Error("Cannot create val path of array item with symbol prop: ".concat(prop.toString()));
|
711
|
-
}
|
712
|
-
return arrayPath && "".concat(arrayPath, ".").concat(JSON.stringify(prop));
|
713
|
-
}
|
714
|
-
|
715
|
-
// TODO: could we do .val on the objects instead?
|
716
|
-
function unValify(valueOrSelector) {
|
717
|
-
if (_typeof(valueOrSelector) === "object" && (SourceOrExpr in valueOrSelector || Path in valueOrSelector)) {
|
718
|
-
var selectorValue = valueOrSelector[SourceOrExpr];
|
719
|
-
return selectorValue;
|
720
|
-
}
|
721
|
-
return valueOrSelector;
|
722
|
-
}
|
723
|
-
|
724
552
|
exports.Call = Call;
|
725
553
|
exports.Expr = Expr;
|
726
554
|
exports.FILE_REF_PROP = FILE_REF_PROP;
|
727
555
|
exports.GenericSelector = GenericSelector;
|
556
|
+
exports.GetSchema = GetSchema;
|
557
|
+
exports.GetSource = GetSource;
|
728
558
|
exports.ImageSchema = ImageSchema;
|
729
559
|
exports.NilSym = NilSym;
|
730
560
|
exports.Path = Path;
|
731
561
|
exports.Schema = Schema;
|
732
|
-
exports.SourceOrExpr = SourceOrExpr;
|
733
562
|
exports.StringLiteral = StringLiteral;
|
734
563
|
exports.StringTemplate = StringTemplate;
|
735
564
|
exports.Sym = Sym;
|
@@ -743,14 +572,11 @@ exports._objectSpread2 = _objectSpread2;
|
|
743
572
|
exports._slicedToArray = _slicedToArray;
|
744
573
|
exports._toConsumableArray = _toConsumableArray;
|
745
574
|
exports._typeof = _typeof;
|
746
|
-
exports.
|
747
|
-
exports.createValPathOfItem = createValPathOfItem;
|
575
|
+
exports.convertFileSource = convertFileSource;
|
748
576
|
exports.file = file;
|
749
577
|
exports.getSchema = getSchema;
|
750
578
|
exports.getValPath = getValPath;
|
751
579
|
exports.image = image;
|
752
580
|
exports.isFile = isFile;
|
753
|
-
exports.isSelector = isSelector;
|
754
581
|
exports.isSerializedVal = isSerializedVal;
|
755
582
|
exports.isVal = isVal;
|
756
|
-
exports.newSelectorProxy = newSelectorProxy;
|
@@ -220,21 +220,26 @@ function _createSuper(Derived) {
|
|
220
220
|
};
|
221
221
|
}
|
222
222
|
|
223
|
+
// import { RemoteCompatibleSource, RemoteSource } from "../source/remote";
|
224
|
+
|
225
|
+
// import { SerializedI18nSchema } from "./future/i18n";
|
226
|
+
// import { SerializedOneOfSchema } from "./future/oneOf";
|
223
227
|
var Schema = /*#__PURE__*/function () {
|
224
228
|
function Schema() {
|
225
229
|
_classCallCheck(this, Schema);
|
226
230
|
}
|
227
231
|
_createClass(Schema, [{
|
228
|
-
key: "
|
229
|
-
value:
|
230
|
-
|
231
|
-
|
232
|
-
|
232
|
+
key: "appendValidationError",
|
233
|
+
value:
|
234
|
+
// remote(): Src extends RemoteCompatibleSource
|
235
|
+
// ? Schema<RemoteSource<Src>>
|
236
|
+
// : never {
|
237
|
+
// // TODO: Schema<never, "Cannot create remote schema from non-remote source.">
|
238
|
+
// throw new Error("You need Val Ultra to use .remote()");
|
239
|
+
// }
|
233
240
|
|
234
241
|
/** MUTATES! since internal and perf sensitive */
|
235
|
-
|
236
|
-
key: "appendValidationError",
|
237
|
-
value: function appendValidationError(current, path, message, value) {
|
242
|
+
function appendValidationError(current, path, message, value) {
|
238
243
|
if (current) {
|
239
244
|
if (current[path]) {
|
240
245
|
current[path].push({
|
@@ -261,30 +266,6 @@ var Schema = /*#__PURE__*/function () {
|
|
261
266
|
|
262
267
|
// TODO: SourceError<"Could not determine type of Schema">
|
263
268
|
|
264
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
265
|
-
|
266
|
-
/**
|
267
|
-
* Selectors can be used to select parts of a Val module.
|
268
|
-
* Unlike queries, joins, aggregates etc is and will not be supported.
|
269
|
-
*
|
270
|
-
* They are designed to be be used as if they were "normal" JSON data,
|
271
|
-
* though some concessions had to be made because of TypeScript limitations.
|
272
|
-
*
|
273
|
-
* Selectors works equally on source content, defined in code, and remote content.
|
274
|
-
*
|
275
|
-
* @example
|
276
|
-
* // Select the title of a document
|
277
|
-
* const titles = useVal(docsVal.map((doc) => doc.title));
|
278
|
-
*
|
279
|
-
* @example
|
280
|
-
* // Match on a union type
|
281
|
-
* const titles = useVal(docsVal.map((doc) => doc.fold("type")({
|
282
|
-
* newsletter: (newsletter) => newsletter.title,
|
283
|
-
* email: (email) => email.subject,
|
284
|
-
* }));
|
285
|
-
*
|
286
|
-
*/
|
287
|
-
|
288
269
|
/**
|
289
270
|
* @internal
|
290
271
|
*/
|
@@ -297,27 +278,18 @@ var Path = Symbol("Path");
|
|
297
278
|
/**
|
298
279
|
* @internal
|
299
280
|
*/
|
300
|
-
var
|
281
|
+
var GetSource = Symbol("GetSource");
|
301
282
|
/**
|
302
283
|
* @internal
|
303
284
|
*/
|
304
285
|
var ValError = Symbol("ValError");
|
305
|
-
var GenericSelector = /*#__PURE__*/function () {
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
}
|
313
|
-
_createClass(GenericSelector, [{
|
314
|
-
key: "assert",
|
315
|
-
value: function assert(schema, other) {
|
316
|
-
throw new Error("Not implemented");
|
317
|
-
}
|
318
|
-
}]);
|
319
|
-
return GenericSelector;
|
320
|
-
}();
|
286
|
+
var GenericSelector = /*#__PURE__*/_createClass(function GenericSelector(valOrExpr, path, schema, error) {
|
287
|
+
_classCallCheck(this, GenericSelector);
|
288
|
+
this[Path] = path;
|
289
|
+
this[GetSource] = valOrExpr;
|
290
|
+
this[ValError] = error;
|
291
|
+
this[GetSchema] = schema;
|
292
|
+
});
|
321
293
|
|
322
294
|
/**
|
323
295
|
* Use this type to convert types that accepts both Source and Selectors
|
@@ -536,7 +508,7 @@ var ImageSchema = /*#__PURE__*/function (_Schema) {
|
|
536
508
|
var image = function image(options) {
|
537
509
|
return new ImageSchema(options);
|
538
510
|
};
|
539
|
-
var
|
511
|
+
var convertFileSource = function convertFileSource(src) {
|
540
512
|
var _src$metadata;
|
541
513
|
// TODO: /public should be configurable
|
542
514
|
return {
|
@@ -577,159 +549,16 @@ function getValPath(valOrSelector) {
|
|
577
549
|
return valOrSelector[Path];
|
578
550
|
}
|
579
551
|
|
580
|
-
function hasOwn(obj, prop) {
|
581
|
-
return Object.prototype.hasOwnProperty.call(obj, prop);
|
582
|
-
}
|
583
|
-
function _andThen(f, source, path) {
|
584
|
-
if (source) {
|
585
|
-
return newSelectorProxy(f(newSelectorProxy(source, path)));
|
586
|
-
}
|
587
|
-
return newSelectorProxy(source, path);
|
588
|
-
}
|
589
|
-
function isSelector(source) {
|
590
|
-
return _typeof(source) === "object" && source !== null && (SourceOrExpr in source || Path in source);
|
591
|
-
}
|
592
|
-
function newSelectorProxy(source, path, moduleSchema) {
|
593
|
-
var _ref;
|
594
|
-
if (_typeof(source) === "object") {
|
595
|
-
if (isSelector(source)) {
|
596
|
-
return source;
|
597
|
-
} else if (isSerializedVal(source)) {
|
598
|
-
return newSelectorProxy(source.val, source.valPath);
|
599
|
-
}
|
600
|
-
}
|
601
|
-
if (source && source[FILE_REF_PROP] && source[VAL_EXTENSION] === "file") {
|
602
|
-
var fileRef = source[FILE_REF_PROP];
|
603
|
-
if (typeof fileRef !== "string") {
|
604
|
-
throw Error("Invalid file ref: " + fileRef);
|
605
|
-
}
|
606
|
-
return newSelectorProxy(convertImageSource(source), path, moduleSchema);
|
607
|
-
}
|
608
|
-
switch (_typeof(source)) {
|
609
|
-
case "function":
|
610
|
-
case "symbol":
|
611
|
-
throw Error("Invalid selector type: ".concat(_typeof(source), ": ").concat(source));
|
612
|
-
case "object":
|
613
|
-
// Handles both objects and arrays!
|
614
|
-
if (source !== null) {
|
615
|
-
return new Proxy(source, {
|
616
|
-
// TODO: see proxy docs if we want more traps
|
617
|
-
has: function has(target, prop) {
|
618
|
-
if (prop === SourceOrExpr) {
|
619
|
-
return true;
|
620
|
-
}
|
621
|
-
if (prop === Path) {
|
622
|
-
return true;
|
623
|
-
}
|
624
|
-
if (prop === "andThen") {
|
625
|
-
return true;
|
626
|
-
}
|
627
|
-
if (prop === GetSchema) {
|
628
|
-
return true;
|
629
|
-
}
|
630
|
-
return prop in target;
|
631
|
-
},
|
632
|
-
get: function get(target, prop) {
|
633
|
-
if (prop === SourceOrExpr) {
|
634
|
-
return source;
|
635
|
-
}
|
636
|
-
if (prop === Path) {
|
637
|
-
return path;
|
638
|
-
}
|
639
|
-
if (prop === GetSchema) {
|
640
|
-
return moduleSchema;
|
641
|
-
}
|
642
|
-
if (prop === "andThen") {
|
643
|
-
return function (f) {
|
644
|
-
return _andThen(f, source, path);
|
645
|
-
};
|
646
|
-
}
|
647
|
-
if (Array.isArray(target)) {
|
648
|
-
if (prop === "filter") {
|
649
|
-
return function (f) {
|
650
|
-
var filtered = target.map(function (a, i) {
|
651
|
-
return newSelectorProxy(a, createValPathOfItem(path, i), moduleSchema === null || moduleSchema === void 0 ? void 0 : moduleSchema.item);
|
652
|
-
}).filter(function (a) {
|
653
|
-
if (f && f instanceof Schema) {
|
654
|
-
return f.assert(unValify(a));
|
655
|
-
} else {
|
656
|
-
return unValify(f(a));
|
657
|
-
}
|
658
|
-
});
|
659
|
-
return newSelectorProxy(filtered, path, moduleSchema);
|
660
|
-
};
|
661
|
-
} else if (prop === "map") {
|
662
|
-
return function (f) {
|
663
|
-
var filtered = target.map(function (a, i) {
|
664
|
-
var valueOrSelector = f(newSelectorProxy(a, createValPathOfItem(path, i), moduleSchema === null || moduleSchema === void 0 ? void 0 : moduleSchema.item), newSelectorProxy(i));
|
665
|
-
if (isSelector(valueOrSelector)) {
|
666
|
-
return valueOrSelector;
|
667
|
-
}
|
668
|
-
return newSelectorProxy(valueOrSelector);
|
669
|
-
});
|
670
|
-
return newSelectorProxy(filtered, path, moduleSchema);
|
671
|
-
};
|
672
|
-
}
|
673
|
-
}
|
674
|
-
if (Array.isArray(target) && prop === "length") {
|
675
|
-
return newSelectorProxy(target.length);
|
676
|
-
}
|
677
|
-
var reflectedValue = Reflect.get(target, prop);
|
678
|
-
if (hasOwn(source, prop)) {
|
679
|
-
if (!Number.isNaN(Number(prop))) {
|
680
|
-
return newSelectorProxy(reflectedValue, createValPathOfItem(path, Number(prop)), moduleSchema === null || moduleSchema === void 0 ? void 0 : moduleSchema.item);
|
681
|
-
}
|
682
|
-
return newSelectorProxy(reflectedValue, createValPathOfItem(path, prop), moduleSchema === null || moduleSchema === void 0 ? void 0 : moduleSchema.items[prop]);
|
683
|
-
}
|
684
|
-
return reflectedValue;
|
685
|
-
}
|
686
|
-
});
|
687
|
-
}
|
688
|
-
// intentional fallthrough
|
689
|
-
// eslint-disable-next-line no-fallthrough
|
690
|
-
default:
|
691
|
-
return _ref = {
|
692
|
-
eq: function eq(other) {
|
693
|
-
var otherValue = other;
|
694
|
-
if (isSelector(other)) {
|
695
|
-
otherValue = other[SourceOrExpr];
|
696
|
-
if (otherValue instanceof Expr) {
|
697
|
-
throw Error("TODO: Cannot evaluate equality with an Expr");
|
698
|
-
}
|
699
|
-
}
|
700
|
-
return newSelectorProxy(source === otherValue, undefined);
|
701
|
-
},
|
702
|
-
andThen: function andThen(f) {
|
703
|
-
return _andThen(f, source === undefined ? null : source, path);
|
704
|
-
}
|
705
|
-
}, _defineProperty(_ref, SourceOrExpr, source === undefined ? null : source), _defineProperty(_ref, Path, path), _defineProperty(_ref, GetSchema, moduleSchema), _ref;
|
706
|
-
}
|
707
|
-
}
|
708
|
-
function createValPathOfItem(arrayPath, prop) {
|
709
|
-
if (_typeof(prop) === "symbol") {
|
710
|
-
throw Error("Cannot create val path of array item with symbol prop: ".concat(prop.toString()));
|
711
|
-
}
|
712
|
-
return arrayPath && "".concat(arrayPath, ".").concat(JSON.stringify(prop));
|
713
|
-
}
|
714
|
-
|
715
|
-
// TODO: could we do .val on the objects instead?
|
716
|
-
function unValify(valueOrSelector) {
|
717
|
-
if (_typeof(valueOrSelector) === "object" && (SourceOrExpr in valueOrSelector || Path in valueOrSelector)) {
|
718
|
-
var selectorValue = valueOrSelector[SourceOrExpr];
|
719
|
-
return selectorValue;
|
720
|
-
}
|
721
|
-
return valueOrSelector;
|
722
|
-
}
|
723
|
-
|
724
552
|
exports.Call = Call;
|
725
553
|
exports.Expr = Expr;
|
726
554
|
exports.FILE_REF_PROP = FILE_REF_PROP;
|
727
555
|
exports.GenericSelector = GenericSelector;
|
556
|
+
exports.GetSchema = GetSchema;
|
557
|
+
exports.GetSource = GetSource;
|
728
558
|
exports.ImageSchema = ImageSchema;
|
729
559
|
exports.NilSym = NilSym;
|
730
560
|
exports.Path = Path;
|
731
561
|
exports.Schema = Schema;
|
732
|
-
exports.SourceOrExpr = SourceOrExpr;
|
733
562
|
exports.StringLiteral = StringLiteral;
|
734
563
|
exports.StringTemplate = StringTemplate;
|
735
564
|
exports.Sym = Sym;
|
@@ -743,14 +572,11 @@ exports._objectSpread2 = _objectSpread2;
|
|
743
572
|
exports._slicedToArray = _slicedToArray;
|
744
573
|
exports._toConsumableArray = _toConsumableArray;
|
745
574
|
exports._typeof = _typeof;
|
746
|
-
exports.
|
747
|
-
exports.createValPathOfItem = createValPathOfItem;
|
575
|
+
exports.convertFileSource = convertFileSource;
|
748
576
|
exports.file = file;
|
749
577
|
exports.getSchema = getSchema;
|
750
578
|
exports.getValPath = getValPath;
|
751
579
|
exports.image = image;
|
752
580
|
exports.isFile = isFile;
|
753
|
-
exports.isSelector = isSelector;
|
754
581
|
exports.isSerializedVal = isSerializedVal;
|
755
582
|
exports.isVal = isVal;
|
756
|
-
exports.newSelectorProxy = newSelectorProxy;
|