@valbuild/core 0.16.0 → 0.18.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.
Files changed (104) hide show
  1. package/ROADMAP.md +106 -0
  2. package/dist/declarations/src/ValApi.d.ts +26 -0
  3. package/dist/declarations/src/expr/eval.d.ts +1 -1
  4. package/dist/declarations/src/future/fetchVal.d.ts +5 -0
  5. package/dist/declarations/src/index.d.ts +36 -9
  6. package/dist/declarations/src/initSchema.d.ts +8 -10
  7. package/dist/declarations/src/initVal.d.ts +3 -21
  8. package/dist/declarations/src/module.d.ts +2 -14
  9. package/dist/declarations/src/schema/image.d.ts +1 -1
  10. package/dist/declarations/src/schema/index.d.ts +3 -5
  11. package/dist/declarations/src/schema/keyOf.d.ts +23 -0
  12. package/dist/declarations/src/schema/record.d.ts +19 -0
  13. package/dist/declarations/src/schema/union.d.ts +1 -0
  14. package/dist/declarations/src/selector/SelectorProxy.d.ts +7 -0
  15. package/dist/declarations/src/selector/array.d.ts +2 -13
  16. package/dist/declarations/src/selector/file.d.ts +1 -4
  17. package/dist/declarations/src/selector/future/array.d.ts +17 -0
  18. package/dist/declarations/src/selector/future/boolean.d.ts +2 -0
  19. package/dist/declarations/src/selector/future/file.d.ts +9 -0
  20. package/dist/declarations/src/selector/{i18n.d.ts → future/i18n.d.ts} +2 -2
  21. package/dist/declarations/src/selector/future/index.d.ts +81 -0
  22. package/dist/declarations/src/selector/future/number.d.ts +2 -0
  23. package/dist/declarations/src/selector/future/object.d.ts +10 -0
  24. package/dist/declarations/src/selector/future/primitive.d.ts +9 -0
  25. package/dist/declarations/src/selector/{remote.d.ts → future/remote.d.ts} +1 -1
  26. package/dist/declarations/src/selector/future/string.d.ts +2 -0
  27. package/dist/declarations/src/selector/index.d.ts +5 -32
  28. package/dist/declarations/src/selector/object.d.ts +2 -9
  29. package/dist/declarations/src/selector/primitive.d.ts +3 -9
  30. package/dist/declarations/src/source/{i18n.d.ts → future/i18n.d.ts} +2 -2
  31. package/dist/declarations/src/source/{remote.d.ts → future/remote.d.ts} +3 -3
  32. package/dist/declarations/src/source/index.d.ts +4 -3
  33. package/dist/declarations/src/val/index.d.ts +2 -2
  34. package/dist/{index-2fff5ca8.cjs.dev.js → index-486c7fbf.cjs.dev.js} +242 -54
  35. package/dist/{index-af761363.esm.js → index-4abf3a1f.esm.js} +189 -1
  36. package/dist/{index-cac9ecbd.cjs.prod.js → index-601a7d73.cjs.prod.js} +242 -54
  37. package/dist/{SelectorProxy-2af1b2b8.cjs.prod.js → index-8706c87e.cjs.prod.js} +25 -199
  38. package/dist/{SelectorProxy-873782a5.cjs.dev.js → index-a6e642dd.cjs.dev.js} +25 -199
  39. package/dist/{SelectorProxy-63c2d0e2.esm.js → index-a9235737.esm.js} +23 -195
  40. package/dist/{ops-1b6e0e35.cjs.prod.js → ops-0d09f8ee.cjs.prod.js} +258 -126
  41. package/dist/{ops-74661336.esm.js → ops-a2a295f8.esm.js} +195 -65
  42. package/dist/{ops-ea4827fc.cjs.dev.js → ops-f3015423.cjs.dev.js} +258 -126
  43. package/dist/valbuild-core.cjs.dev.js +784 -197
  44. package/dist/valbuild-core.cjs.prod.js +784 -197
  45. package/dist/valbuild-core.esm.js +719 -133
  46. package/expr/dist/valbuild-core-expr.cjs.dev.js +8 -8
  47. package/expr/dist/valbuild-core-expr.cjs.prod.js +8 -8
  48. package/expr/dist/valbuild-core-expr.esm.js +2 -2
  49. package/package.json +2 -3
  50. package/patch/dist/valbuild-core-patch.cjs.dev.js +24 -24
  51. package/patch/dist/valbuild-core-patch.cjs.prod.js +24 -24
  52. package/patch/dist/valbuild-core-patch.esm.js +3 -3
  53. package/src/ValApi.ts +85 -0
  54. package/src/expr/eval.test.ts +2 -2
  55. package/src/expr/eval.ts +2 -2
  56. package/src/{fetchVal.test.ts → future/fetchVal.test.ts} +57 -57
  57. package/src/{fetchVal.ts → future/fetchVal.ts} +17 -22
  58. package/src/index.ts +46 -14
  59. package/src/initSchema.ts +17 -12
  60. package/src/initVal.ts +42 -52
  61. package/src/module.test.ts +40 -40
  62. package/src/module.ts +53 -43
  63. package/src/patch/deref.test.ts +1 -1
  64. package/src/patch/deref.ts +1 -1
  65. package/src/patch/json.test.ts +0 -1
  66. package/src/schema/{i18n.ts → future/i18n.ts} +12 -10
  67. package/src/schema/{oneOf.ts → future/oneOf.ts} +19 -17
  68. package/src/schema/image.ts +1 -1
  69. package/src/schema/index.ts +16 -13
  70. package/src/schema/keyOf.ts +167 -0
  71. package/src/schema/record.ts +103 -0
  72. package/src/schema/union.ts +1 -1
  73. package/src/schema/validation.test.ts +195 -130
  74. package/src/selector/SelectorProxy.ts +15 -15
  75. package/src/selector/array.ts +2 -26
  76. package/src/selector/file.ts +1 -9
  77. package/src/selector/{ExprProxy.test.ts → future/ExprProxy.test.ts} +2 -2
  78. package/src/selector/{ExprProxy.ts → future/ExprProxy.ts} +9 -2
  79. package/src/selector/{SelectorProxy.test.ts → future/SelectorProxy.test.ts} +4 -4
  80. package/src/selector/future/SelectorProxy.ts +238 -0
  81. package/src/selector/future/array.ts +37 -0
  82. package/src/selector/future/boolean.ts +4 -0
  83. package/src/selector/future/file.ts +14 -0
  84. package/src/selector/{i18n.ts → future/i18n.ts} +2 -2
  85. package/src/selector/future/index.ts +165 -0
  86. package/src/selector/future/number.ts +4 -0
  87. package/src/selector/future/object.ts +22 -0
  88. package/src/selector/future/primitive.ts +17 -0
  89. package/src/selector/{remote.ts → future/remote.ts} +1 -1
  90. package/src/selector/{selector.test.ts → future/selector.test.ts} +8 -28
  91. package/src/selector/{selectorOf.ts → future/selectorOf.ts} +1 -1
  92. package/src/selector/future/string.ts +4 -0
  93. package/src/selector/index.ts +4 -46
  94. package/src/selector/object.ts +2 -19
  95. package/src/selector/primitive.ts +3 -16
  96. package/src/source/{i18n.ts → future/i18n.ts} +2 -2
  97. package/src/source/{remote.ts → future/remote.ts} +3 -3
  98. package/src/source/index.ts +3 -2
  99. package/src/val/array.ts +1 -1
  100. package/src/val/index.ts +2 -2
  101. package/src/val/object.ts +1 -1
  102. package/dist/declarations/src/fetchVal.d.ts +0 -5
  103. package/dist/declarations/src/schema/i18n.d.ts +0 -22
  104. package/dist/declarations/src/schema/oneOf.d.ts +0 -23
@@ -218,21 +218,26 @@ function _createSuper(Derived) {
218
218
  };
219
219
  }
220
220
 
221
+ // import { RemoteCompatibleSource, RemoteSource } from "../source/remote";
222
+
223
+ // import { SerializedI18nSchema } from "./future/i18n";
224
+ // import { SerializedOneOfSchema } from "./future/oneOf";
221
225
  var Schema = /*#__PURE__*/function () {
222
226
  function Schema() {
223
227
  _classCallCheck(this, Schema);
224
228
  }
225
229
  _createClass(Schema, [{
226
- key: "remote",
227
- value: function remote() {
228
- // TODO: Schema<never, "Cannot create remote schema from non-remote source.">
229
- throw new Error("You need Val Ultra to use .remote()");
230
- }
230
+ key: "appendValidationError",
231
+ value:
232
+ // remote(): Src extends RemoteCompatibleSource
233
+ // ? Schema<RemoteSource<Src>>
234
+ // : never {
235
+ // // TODO: Schema<never, "Cannot create remote schema from non-remote source.">
236
+ // throw new Error("You need Val Ultra to use .remote()");
237
+ // }
231
238
 
232
239
  /** MUTATES! since internal and perf sensitive */
233
- }, {
234
- key: "appendValidationError",
235
- value: function appendValidationError(current, path, message, value) {
240
+ function appendValidationError(current, path, message, value) {
236
241
  if (current) {
237
242
  if (current[path]) {
238
243
  current[path].push({
@@ -259,30 +264,6 @@ var Schema = /*#__PURE__*/function () {
259
264
 
260
265
  // TODO: SourceError<"Could not determine type of Schema">
261
266
 
262
- /* eslint-disable @typescript-eslint/no-unused-vars */
263
-
264
- /**
265
- * Selectors can be used to select parts of a Val module.
266
- * Unlike queries, joins, aggregates etc is and will not be supported.
267
- *
268
- * They are designed to be be used as if they were "normal" JSON data,
269
- * though some concessions had to be made because of TypeScript limitations.
270
- *
271
- * Selectors works equally on source content, defined in code, and remote content.
272
- *
273
- * @example
274
- * // Select the title of a document
275
- * const titles = useVal(docsVal.map((doc) => doc.title));
276
- *
277
- * @example
278
- * // Match on a union type
279
- * const titles = useVal(docsVal.map((doc) => doc.fold("type")({
280
- * newsletter: (newsletter) => newsletter.title,
281
- * email: (email) => email.subject,
282
- * }));
283
- *
284
- */
285
-
286
267
  /**
287
268
  * @internal
288
269
  */
@@ -295,27 +276,18 @@ var Path = Symbol("Path");
295
276
  /**
296
277
  * @internal
297
278
  */
298
- var SourceOrExpr = Symbol("SourceOrExpr");
279
+ var GetSource = Symbol("GetSource");
299
280
  /**
300
281
  * @internal
301
282
  */
302
283
  var ValError = Symbol("ValError");
303
- var GenericSelector = /*#__PURE__*/function () {
304
- function GenericSelector(valOrExpr, path, schema, error) {
305
- _classCallCheck(this, GenericSelector);
306
- this[Path] = path;
307
- this[SourceOrExpr] = valOrExpr;
308
- this[ValError] = error;
309
- this[GetSchema] = schema;
310
- }
311
- _createClass(GenericSelector, [{
312
- key: "assert",
313
- value: function assert(schema, other) {
314
- throw new Error("Not implemented");
315
- }
316
- }]);
317
- return GenericSelector;
318
- }();
284
+ var GenericSelector = /*#__PURE__*/_createClass(function GenericSelector(valOrExpr, path, schema, error) {
285
+ _classCallCheck(this, GenericSelector);
286
+ this[Path] = path;
287
+ this[GetSource] = valOrExpr;
288
+ this[ValError] = error;
289
+ this[GetSchema] = schema;
290
+ });
319
291
 
320
292
  /**
321
293
  * Use this type to convert types that accepts both Source and Selectors
@@ -534,7 +506,7 @@ var ImageSchema = /*#__PURE__*/function (_Schema) {
534
506
  var image = function image(options) {
535
507
  return new ImageSchema(options);
536
508
  };
537
- var convertImageSource = function convertImageSource(src) {
509
+ var convertFileSource = function convertFileSource(src) {
538
510
  var _src$metadata;
539
511
  // TODO: /public should be configurable
540
512
  return {
@@ -575,148 +547,4 @@ function getValPath(valOrSelector) {
575
547
  return valOrSelector[Path];
576
548
  }
577
549
 
578
- function hasOwn(obj, prop) {
579
- return Object.prototype.hasOwnProperty.call(obj, prop);
580
- }
581
- function _andThen(f, source, path) {
582
- if (source) {
583
- return newSelectorProxy(f(newSelectorProxy(source, path)));
584
- }
585
- return newSelectorProxy(source, path);
586
- }
587
- function isSelector(source) {
588
- return _typeof(source) === "object" && source !== null && (SourceOrExpr in source || Path in source);
589
- }
590
- function newSelectorProxy(source, path, moduleSchema) {
591
- var _ref;
592
- if (_typeof(source) === "object") {
593
- if (isSelector(source)) {
594
- return source;
595
- } else if (isSerializedVal(source)) {
596
- return newSelectorProxy(source.val, source.valPath);
597
- }
598
- }
599
- if (source && source[FILE_REF_PROP] && source[VAL_EXTENSION] === "file") {
600
- var fileRef = source[FILE_REF_PROP];
601
- if (typeof fileRef !== "string") {
602
- throw Error("Invalid file ref: " + fileRef);
603
- }
604
- return newSelectorProxy(convertImageSource(source), path, moduleSchema);
605
- }
606
- switch (_typeof(source)) {
607
- case "function":
608
- case "symbol":
609
- throw Error("Invalid selector type: ".concat(_typeof(source), ": ").concat(source));
610
- case "object":
611
- // Handles both objects and arrays!
612
- if (source !== null) {
613
- return new Proxy(source, {
614
- // TODO: see proxy docs if we want more traps
615
- has: function has(target, prop) {
616
- if (prop === SourceOrExpr) {
617
- return true;
618
- }
619
- if (prop === Path) {
620
- return true;
621
- }
622
- if (prop === "andThen") {
623
- return true;
624
- }
625
- if (prop === GetSchema) {
626
- return true;
627
- }
628
- return prop in target;
629
- },
630
- get: function get(target, prop) {
631
- if (prop === SourceOrExpr) {
632
- return source;
633
- }
634
- if (prop === Path) {
635
- return path;
636
- }
637
- if (prop === GetSchema) {
638
- return moduleSchema;
639
- }
640
- if (prop === "andThen") {
641
- return function (f) {
642
- return _andThen(f, source, path);
643
- };
644
- }
645
- if (Array.isArray(target)) {
646
- if (prop === "filter") {
647
- return function (f) {
648
- var filtered = target.map(function (a, i) {
649
- return newSelectorProxy(a, createValPathOfItem(path, i), moduleSchema === null || moduleSchema === void 0 ? void 0 : moduleSchema.item);
650
- }).filter(function (a) {
651
- if (f && f instanceof Schema) {
652
- return f.assert(unValify(a));
653
- } else {
654
- return unValify(f(a));
655
- }
656
- });
657
- return newSelectorProxy(filtered, path, moduleSchema);
658
- };
659
- } else if (prop === "map") {
660
- return function (f) {
661
- var filtered = target.map(function (a, i) {
662
- var valueOrSelector = f(newSelectorProxy(a, createValPathOfItem(path, i), moduleSchema === null || moduleSchema === void 0 ? void 0 : moduleSchema.item), newSelectorProxy(i));
663
- if (isSelector(valueOrSelector)) {
664
- return valueOrSelector;
665
- }
666
- return newSelectorProxy(valueOrSelector);
667
- });
668
- return newSelectorProxy(filtered, path, moduleSchema);
669
- };
670
- }
671
- }
672
- if (Array.isArray(target) && prop === "length") {
673
- return newSelectorProxy(target.length);
674
- }
675
- var reflectedValue = Reflect.get(target, prop);
676
- if (hasOwn(source, prop)) {
677
- if (!Number.isNaN(Number(prop))) {
678
- return newSelectorProxy(reflectedValue, createValPathOfItem(path, Number(prop)), moduleSchema === null || moduleSchema === void 0 ? void 0 : moduleSchema.item);
679
- }
680
- return newSelectorProxy(reflectedValue, createValPathOfItem(path, prop), moduleSchema === null || moduleSchema === void 0 ? void 0 : moduleSchema.items[prop]);
681
- }
682
- return reflectedValue;
683
- }
684
- });
685
- }
686
- // intentional fallthrough
687
- // eslint-disable-next-line no-fallthrough
688
- default:
689
- return _ref = {
690
- eq: function eq(other) {
691
- var otherValue = other;
692
- if (isSelector(other)) {
693
- otherValue = other[SourceOrExpr];
694
- if (otherValue instanceof Expr) {
695
- throw Error("TODO: Cannot evaluate equality with an Expr");
696
- }
697
- }
698
- return newSelectorProxy(source === otherValue, undefined);
699
- },
700
- andThen: function andThen(f) {
701
- return _andThen(f, source === undefined ? null : source, path);
702
- }
703
- }, _defineProperty(_ref, SourceOrExpr, source === undefined ? null : source), _defineProperty(_ref, Path, path), _defineProperty(_ref, GetSchema, moduleSchema), _ref;
704
- }
705
- }
706
- function createValPathOfItem(arrayPath, prop) {
707
- if (_typeof(prop) === "symbol") {
708
- throw Error("Cannot create val path of array item with symbol prop: ".concat(prop.toString()));
709
- }
710
- return arrayPath && "".concat(arrayPath, ".").concat(JSON.stringify(prop));
711
- }
712
-
713
- // TODO: could we do .val on the objects instead?
714
- function unValify(valueOrSelector) {
715
- if (_typeof(valueOrSelector) === "object" && (SourceOrExpr in valueOrSelector || Path in valueOrSelector)) {
716
- var selectorValue = valueOrSelector[SourceOrExpr];
717
- return selectorValue;
718
- }
719
- return valueOrSelector;
720
- }
721
-
722
- export { Call as C, Expr as E, FILE_REF_PROP as F, GenericSelector as G, ImageSchema as I, NilSym as N, Path as P, Schema as S, VAL_EXTENSION as V, _inherits as _, _createSuper as a, _classCallCheck as b, _createClass as c, _objectSpread2 as d, _defineProperty as e, _typeof as f, getValPath as g, file as h, image as i, _slicedToArray as j, isFile as k, createValPathOfItem as l, SourceOrExpr as m, newSelectorProxy as n, isSelector as o, isSerializedVal as p, convertImageSource as q, getSchema as r, isVal as s, Sym as t, StringLiteral as u, StringTemplate as v, _toConsumableArray as w };
550
+ export { Call as C, Expr as E, FILE_REF_PROP as F, GetSchema as G, ImageSchema as I, NilSym as N, Path as P, Schema as S, VAL_EXTENSION as V, _inherits as _, _createSuper as a, _classCallCheck as b, _createClass as c, _defineProperty as d, _typeof as e, _slicedToArray as f, getValPath as g, _objectSpread2 as h, image as i, file as j, isFile as k, GetSource as l, isSerializedVal as m, convertFileSource as n, getSchema as o, isVal as p, GenericSelector as q, Sym as r, StringLiteral as s, StringTemplate as t, _toConsumableArray as u };