@valbuild/core 0.93.0 → 0.95.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 (29) hide show
  1. package/dist/declarations/src/getSourcePathFromRoute.d.ts +15 -0
  2. package/dist/declarations/src/index.d.ts +1 -0
  3. package/dist/declarations/src/initSchema.d.ts +59 -2
  4. package/dist/declarations/src/initVal.d.ts +8 -0
  5. package/dist/declarations/src/module.d.ts +2 -1
  6. package/dist/declarations/src/router.d.ts +4 -0
  7. package/dist/declarations/src/schema/file.d.ts +7 -4
  8. package/dist/declarations/src/schema/files.d.ts +56 -0
  9. package/dist/declarations/src/schema/image.d.ts +11 -7
  10. package/dist/declarations/src/schema/images.d.ts +85 -0
  11. package/dist/declarations/src/schema/object.d.ts +2 -0
  12. package/dist/declarations/src/schema/record.d.ts +20 -1
  13. package/dist/declarations/src/schema/validation/ValidationFix.d.ts +1 -1
  14. package/dist/declarations/src/selector/index.d.ts +1 -1
  15. package/dist/declarations/src/source/index.d.ts +3 -2
  16. package/dist/declarations/src/source/remote.d.ts +1 -1
  17. package/dist/declarations/src/source/richtext.d.ts +2 -2
  18. package/dist/{index-d1491224.esm.js → index-1e99dc98.esm.js} +605 -178
  19. package/dist/{index-4421cd12.cjs.prod.js → index-37395d55.cjs.prod.js} +604 -176
  20. package/dist/{index-fcce0216.cjs.dev.js → index-e7f3333f.cjs.dev.js} +604 -176
  21. package/dist/{result-daff1cae.esm.js → result-4bd63123.esm.js} +1 -1
  22. package/dist/valbuild-core.cjs.dev.js +2 -1
  23. package/dist/valbuild-core.cjs.prod.js +2 -1
  24. package/dist/valbuild-core.esm.js +2 -2
  25. package/fp/dist/valbuild-core-fp.esm.js +1 -1
  26. package/package.json +1 -1
  27. package/patch/dist/valbuild-core-patch.cjs.dev.js +2 -1
  28. package/patch/dist/valbuild-core-patch.cjs.prod.js +2 -1
  29. package/patch/dist/valbuild-core-patch.esm.js +4 -3
@@ -2,46 +2,6 @@
2
2
 
3
3
  var result = require('./result-787e35f6.cjs.prod.js');
4
4
 
5
- function _arrayWithHoles(r) {
6
- if (Array.isArray(r)) return r;
7
- }
8
-
9
- function _iterableToArrayLimit(r, l) {
10
- var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
11
- if (null != t) {
12
- var e,
13
- n,
14
- i,
15
- u,
16
- a = [],
17
- f = !0,
18
- o = !1;
19
- try {
20
- if (i = (t = t.call(r)).next, 0 === l) {
21
- if (Object(t) !== t) return;
22
- f = !1;
23
- } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
24
- } catch (r) {
25
- o = !0, n = r;
26
- } finally {
27
- try {
28
- if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
29
- } finally {
30
- if (o) throw n;
31
- }
32
- }
33
- return a;
34
- }
35
- }
36
-
37
- function _nonIterableRest() {
38
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
39
- }
40
-
41
- function _slicedToArray(r, e) {
42
- return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || result._unsupportedIterableToArray(r, e) || _nonIterableRest();
43
- }
44
-
45
5
  function _arrayWithoutHoles(r) {
46
6
  if (Array.isArray(r)) return result._arrayLikeToArray(r);
47
7
  }
@@ -115,6 +75,46 @@ function _objectSpread2(e) {
115
75
  return e;
116
76
  }
117
77
 
78
+ function _arrayWithHoles(r) {
79
+ if (Array.isArray(r)) return r;
80
+ }
81
+
82
+ function _iterableToArrayLimit(r, l) {
83
+ var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
84
+ if (null != t) {
85
+ var e,
86
+ n,
87
+ i,
88
+ u,
89
+ a = [],
90
+ f = !0,
91
+ o = !1;
92
+ try {
93
+ if (i = (t = t.call(r)).next, 0 === l) {
94
+ if (Object(t) !== t) return;
95
+ f = !1;
96
+ } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
97
+ } catch (r) {
98
+ o = !0, n = r;
99
+ } finally {
100
+ try {
101
+ if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
102
+ } finally {
103
+ if (o) throw n;
104
+ }
105
+ }
106
+ return a;
107
+ }
108
+ }
109
+
110
+ function _nonIterableRest() {
111
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
112
+ }
113
+
114
+ function _slicedToArray(r, e) {
115
+ return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || result._unsupportedIterableToArray(r, e) || _nonIterableRest();
116
+ }
117
+
118
118
  function _classCallCheck(a, n) {
119
119
  if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
120
120
  }
@@ -131,55 +131,6 @@ function _createClass(e, r, t) {
131
131
  }), e;
132
132
  }
133
133
 
134
- function _getPrototypeOf(t) {
135
- return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) {
136
- return t.__proto__ || Object.getPrototypeOf(t);
137
- }, _getPrototypeOf(t);
138
- }
139
-
140
- function _isNativeReflectConstruct() {
141
- try {
142
- var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
143
- } catch (t) {}
144
- return (_isNativeReflectConstruct = function () {
145
- return !!t;
146
- })();
147
- }
148
-
149
- function _assertThisInitialized(e) {
150
- if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
151
- return e;
152
- }
153
-
154
- function _possibleConstructorReturn(t, e) {
155
- if (e && ("object" == typeof e || "function" == typeof e)) return e;
156
- if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined");
157
- return _assertThisInitialized(t);
158
- }
159
-
160
- function _callSuper(t, o, e) {
161
- return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e));
162
- }
163
-
164
- function _setPrototypeOf(t, e) {
165
- return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
166
- return t.__proto__ = e, t;
167
- }, _setPrototypeOf(t, e);
168
- }
169
-
170
- function _inherits(t, e) {
171
- if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function");
172
- t.prototype = Object.create(e && e.prototype, {
173
- constructor: {
174
- value: t,
175
- writable: !0,
176
- configurable: !0
177
- }
178
- }), Object.defineProperty(t, "prototype", {
179
- writable: !1
180
- }), e && _setPrototypeOf(t, e);
181
- }
182
-
183
134
  // import { RemoteCompatibleSource, RemoteSource } from "../source/remote";
184
135
 
185
136
  // import { SerializedI18nSchema } from "./future/i18n";
@@ -276,6 +227,55 @@ var Schema = /*#__PURE__*/function () {
276
227
 
277
228
  // TODO: SourceError<"Could not determine type of Schema">
278
229
 
230
+ function _getPrototypeOf(t) {
231
+ return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) {
232
+ return t.__proto__ || Object.getPrototypeOf(t);
233
+ }, _getPrototypeOf(t);
234
+ }
235
+
236
+ function _isNativeReflectConstruct() {
237
+ try {
238
+ var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
239
+ } catch (t) {}
240
+ return (_isNativeReflectConstruct = function () {
241
+ return !!t;
242
+ })();
243
+ }
244
+
245
+ function _assertThisInitialized(e) {
246
+ if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
247
+ return e;
248
+ }
249
+
250
+ function _possibleConstructorReturn(t, e) {
251
+ if (e && ("object" == typeof e || "function" == typeof e)) return e;
252
+ if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined");
253
+ return _assertThisInitialized(t);
254
+ }
255
+
256
+ function _callSuper(t, o, e) {
257
+ return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e));
258
+ }
259
+
260
+ function _setPrototypeOf(t, e) {
261
+ return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
262
+ return t.__proto__ = e, t;
263
+ }, _setPrototypeOf(t, e);
264
+ }
265
+
266
+ function _inherits(t, e) {
267
+ if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function");
268
+ t.prototype = Object.create(e && e.prototype, {
269
+ constructor: {
270
+ value: t,
271
+ writable: !0,
272
+ configurable: !0
273
+ }
274
+ }), Object.defineProperty(t, "prototype", {
275
+ writable: !1
276
+ }), e && _setPrototypeOf(t, e);
277
+ }
278
+
279
279
  /**
280
280
  * @internal
281
281
  */
@@ -378,30 +378,65 @@ function isFile(obj) {
378
378
  return _typeof(obj) === "object" && obj !== null && VAL_EXTENSION in obj && obj[VAL_EXTENSION] === "file" && FILE_REF_PROP in obj && typeof obj[FILE_REF_PROP] === "string";
379
379
  }
380
380
 
381
+ function isVal(val) {
382
+ return _typeof(val) === "object" && val !== null && val !== undefined && Path in val && "val" in val;
383
+ }
384
+
385
+ /**
386
+ * The path of the source value.
387
+ *
388
+ * @example
389
+ * '/app/blogs.val.ts?p=0.text' // the text property of the first element of the /app/blogs module
390
+ */
391
+
392
+ /**
393
+ * The path inside the module.
394
+ *
395
+ * @example
396
+ * '0."text"' // the text property of the first element of the module
397
+ */
398
+
399
+ /**
400
+ * The path of the module.
401
+ *
402
+ * @example
403
+ * '/app/blogs.val.ts'
404
+ */
405
+
406
+ /**
407
+ * The patchId of the parent patch, or "head" if there is no parent patch.
408
+ */
409
+
410
+ function getValPath(valOrSelector) {
411
+ return valOrSelector[Path];
412
+ }
413
+
381
414
  var FileSchema = /*#__PURE__*/function (_Schema) {
382
415
  function FileSchema(options) {
383
416
  var _this;
384
417
  var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
385
418
  var isRemote = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
386
419
  var customValidateFunctions = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
420
+ var moduleMetadata = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
387
421
  _classCallCheck(this, FileSchema);
388
422
  _this = _callSuper(this, FileSchema);
389
423
  _this.options = options;
390
424
  _this.opt = opt;
391
425
  _this.isRemote = isRemote;
392
426
  _this.customValidateFunctions = customValidateFunctions;
427
+ _this.moduleMetadata = moduleMetadata;
393
428
  return _this;
394
429
  }
395
430
  _inherits(FileSchema, _Schema);
396
431
  return _createClass(FileSchema, [{
397
432
  key: "remote",
398
433
  value: function remote() {
399
- return new FileSchema(this.options, this.opt, true);
434
+ return new FileSchema(this.options, this.opt, true, this.customValidateFunctions, this.moduleMetadata);
400
435
  }
401
436
  }, {
402
437
  key: "validate",
403
438
  value: function validate(validationFunction) {
404
- return new FileSchema(this.options, this.opt, this.isRemote, [].concat(_toConsumableArray(this.customValidateFunctions), [validationFunction]));
439
+ return new FileSchema(this.options, this.opt, this.isRemote, [].concat(_toConsumableArray(this.customValidateFunctions), [validationFunction]), this.moduleMetadata);
405
440
  }
406
441
  }, {
407
442
  key: "executeValidate",
@@ -562,18 +597,20 @@ var FileSchema = /*#__PURE__*/function (_Schema) {
562
597
  }, {
563
598
  key: "nullable",
564
599
  value: function nullable() {
565
- return new FileSchema(this.options, true);
600
+ return new FileSchema(this.options, true, this.isRemote, this.customValidateFunctions, this.moduleMetadata);
566
601
  }
567
602
  }, {
568
603
  key: "executeSerialize",
569
604
  value: function executeSerialize() {
570
605
  var _this$customValidateF;
606
+ var modulePaths = this.moduleMetadata ? Object.keys(this.moduleMetadata) : [];
571
607
  return {
572
608
  type: "file",
573
609
  options: this.options,
574
610
  opt: this.opt,
575
611
  remote: this.isRemote,
576
- customValidate: this.customValidateFunctions && ((_this$customValidateF = this.customValidateFunctions) === null || _this$customValidateF === void 0 ? void 0 : _this$customValidateF.length) > 0
612
+ customValidate: this.customValidateFunctions && ((_this$customValidateF = this.customValidateFunctions) === null || _this$customValidateF === void 0 ? void 0 : _this$customValidateF.length) > 0,
613
+ referencedModule: modulePaths.length > 0 ? modulePaths[0] : undefined
577
614
  };
578
615
  }
579
616
  }, {
@@ -584,6 +621,19 @@ var FileSchema = /*#__PURE__*/function (_Schema) {
584
621
  }]);
585
622
  }(Schema);
586
623
  var file = function file(options) {
624
+ var isModule = !!options && !!Internal.getValPath(options);
625
+ if (isModule) {
626
+ var allModules = {};
627
+ for (var _i = 0, _arr = [options]; _i < _arr.length; _i++) {
628
+ var valModule = _arr[_i];
629
+ var modulePath = getValPath(valModule);
630
+ if (modulePath === undefined) {
631
+ throw new Error("Invalid argument passed to s.file(). Expected a ValModule constructed through c.define, but got an object without a valid module path.");
632
+ }
633
+ allModules[modulePath] = getSource(valModule);
634
+ }
635
+ return new FileSchema({}, false, false, [], allModules);
636
+ }
587
637
  return new FileSchema(options);
588
638
  };
589
639
  function convertFileSource(src) {
@@ -606,39 +656,6 @@ function convertFileSource(src) {
606
656
  };
607
657
  }
608
658
 
609
- function isVal(val) {
610
- return _typeof(val) === "object" && val !== null && val !== undefined && Path in val && "val" in val;
611
- }
612
-
613
- /**
614
- * The path of the source value.
615
- *
616
- * @example
617
- * '/app/blogs.val.ts?p=0.text' // the text property of the first element of the /app/blogs module
618
- */
619
-
620
- /**
621
- * The path inside the module.
622
- *
623
- * @example
624
- * '0."text"' // the text property of the first element of the module
625
- */
626
-
627
- /**
628
- * The path of the module.
629
- *
630
- * @example
631
- * '/app/blogs.val.ts'
632
- */
633
-
634
- /**
635
- * The patchId of the parent patch, or "head" if there is no parent patch.
636
- */
637
-
638
- function getValPath(valOrSelector) {
639
- return valOrSelector[Path];
640
- }
641
-
642
659
  function createValPathOfItem(arrayPath, prop) {
643
660
  if (_typeof(prop) === "symbol") {
644
661
  throw Error("Cannot create val path of array item with symbol prop: ".concat(prop.toString()));
@@ -738,6 +755,12 @@ var StringSchema = /*#__PURE__*/function (_Schema) {
738
755
  if (this.opt && (src === null || src === undefined)) {
739
756
  return errors.length > 0 ? _defineProperty({}, path, errors) : false;
740
757
  }
758
+ if (!this.opt && (src === null || src === undefined)) {
759
+ return _defineProperty({}, path, [{
760
+ message: "Expected 'string', got '".concat(src === null ? "null" : "undefined", "'"),
761
+ value: src
762
+ }]);
763
+ }
741
764
  if (typeof src !== "string") {
742
765
  return _defineProperty({}, path, [{
743
766
  message: "Expected 'string', got '".concat(_typeof(src), "'"),
@@ -1717,28 +1740,31 @@ var ImageSchema = /*#__PURE__*/function (_Schema) {
1717
1740
  var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1718
1741
  var isRemote = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
1719
1742
  var customValidateFunctions = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
1743
+ var moduleMetadata = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
1720
1744
  _classCallCheck(this, ImageSchema);
1721
1745
  _this = _callSuper(this, ImageSchema);
1722
1746
  _this.options = options;
1723
1747
  _this.opt = opt;
1724
1748
  _this.isRemote = isRemote;
1725
1749
  _this.customValidateFunctions = customValidateFunctions;
1750
+ _this.moduleMetadata = moduleMetadata;
1726
1751
  return _this;
1727
1752
  }
1728
1753
  _inherits(ImageSchema, _Schema);
1729
1754
  return _createClass(ImageSchema, [{
1730
1755
  key: "remote",
1731
1756
  value: function remote() {
1732
- return new ImageSchema(this.options, this.opt, true);
1757
+ return new ImageSchema(this.options, this.opt, true, this.customValidateFunctions, this.moduleMetadata);
1733
1758
  }
1734
1759
  }, {
1735
1760
  key: "validate",
1736
1761
  value: function validate(validationFunction) {
1737
- return new ImageSchema(this.options, this.opt, this.isRemote, [].concat(_toConsumableArray(this.customValidateFunctions), [validationFunction]));
1762
+ return new ImageSchema(this.options, this.opt, this.isRemote, [].concat(_toConsumableArray(this.customValidateFunctions), [validationFunction]), this.moduleMetadata);
1738
1763
  }
1739
1764
  }, {
1740
1765
  key: "executeValidate",
1741
1766
  value: function executeValidate(path, src) {
1767
+ var _src$metadata$mimeTyp, _src$metadata;
1742
1768
  var customValidationErrors = this.executeCustomValidateFunctions(src, this.customValidateFunctions, {
1743
1769
  path: path
1744
1770
  });
@@ -1786,8 +1812,7 @@ var ImageSchema = /*#__PURE__*/function (_Schema) {
1786
1812
  }
1787
1813
  var _ref8 = this.options || {},
1788
1814
  accept = _ref8.accept;
1789
- var _ref9 = src.metadata || {},
1790
- mimeType = _ref9.mimeType;
1815
+ var mimeType = (_src$metadata$mimeTyp = (_src$metadata = src.metadata) === null || _src$metadata === void 0 ? void 0 : _src$metadata.mimeType) !== null && _src$metadata$mimeTyp !== void 0 ? _src$metadata$mimeTyp : "";
1791
1816
  if (accept && mimeType && !mimeType.includes("/")) {
1792
1817
  return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
1793
1818
  message: "Invalid mime type format. Got: '".concat(mimeType, "'"),
@@ -1848,6 +1873,13 @@ var ImageSchema = /*#__PURE__*/function (_Schema) {
1848
1873
  fixes: ["image:check-metadata"]
1849
1874
  }]));
1850
1875
  }
1876
+ var isReferencedModule = Object.keys(this.moduleMetadata).length > 0;
1877
+ if (src.metadata === undefined && isReferencedModule) {
1878
+ if (customValidationErrors.length === 0) {
1879
+ return false;
1880
+ }
1881
+ return _defineProperty({}, path, _toConsumableArray(customValidationErrors));
1882
+ }
1851
1883
  return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
1852
1884
  message: "Could not validate Image metadata.",
1853
1885
  value: src,
@@ -1907,18 +1939,20 @@ var ImageSchema = /*#__PURE__*/function (_Schema) {
1907
1939
  }, {
1908
1940
  key: "nullable",
1909
1941
  value: function nullable() {
1910
- return new ImageSchema(this.options, true, this.isRemote);
1942
+ return new ImageSchema(this.options, true, this.isRemote, this.customValidateFunctions, this.moduleMetadata);
1911
1943
  }
1912
1944
  }, {
1913
1945
  key: "executeSerialize",
1914
1946
  value: function executeSerialize() {
1915
1947
  var _this$customValidateF;
1948
+ var modulePaths = this.moduleMetadata ? Object.keys(this.moduleMetadata) : [];
1916
1949
  return {
1917
1950
  type: "image",
1918
1951
  options: this.options,
1919
1952
  opt: this.opt,
1920
1953
  remote: this.isRemote,
1921
- customValidate: this.customValidateFunctions && ((_this$customValidateF = this.customValidateFunctions) === null || _this$customValidateF === void 0 ? void 0 : _this$customValidateF.length) > 0
1954
+ customValidate: this.customValidateFunctions && ((_this$customValidateF = this.customValidateFunctions) === null || _this$customValidateF === void 0 ? void 0 : _this$customValidateF.length) > 0,
1955
+ referencedModule: modulePaths.length > 0 ? modulePaths[0] : undefined
1922
1956
  };
1923
1957
  }
1924
1958
  }, {
@@ -1929,6 +1963,19 @@ var ImageSchema = /*#__PURE__*/function (_Schema) {
1929
1963
  }]);
1930
1964
  }(Schema);
1931
1965
  var image = function image(options) {
1966
+ var isModule = !!options && !!Internal.getValPath(options);
1967
+ if (isModule) {
1968
+ var allModules = {};
1969
+ for (var _i = 0, _arr = [options]; _i < _arr.length; _i++) {
1970
+ var valModule = _arr[_i];
1971
+ var modulePath = getValPath(valModule);
1972
+ if (modulePath === undefined) {
1973
+ throw new Error("Invalid argument passed to s.image(). Expected a ValModule constructed through c.define, but got an object without a valid module path.");
1974
+ }
1975
+ allModules[modulePath] = getSource(valModule);
1976
+ }
1977
+ return new ImageSchema({}, false, false, [], allModules);
1978
+ }
1932
1979
  return new ImageSchema(options);
1933
1980
  };
1934
1981
 
@@ -2200,6 +2247,10 @@ var RichTextSchema = /*#__PURE__*/function (_Schema) {
2200
2247
  }])
2201
2248
  };
2202
2249
  }
2250
+ var supportedTags = ["p", "span", "h1", "h2", "h3", "h4", "h5", "h6", "ol", "ul", "li", "a", "img", "br"];
2251
+ if (!supportedTags.includes(node.tag)) {
2252
+ addError(path, "Tag '".concat(node.tag, "' is not supported. Supported tags: ").concat(supportedTags.join(", ")), true);
2253
+ }
2203
2254
  if (node.tag === "h1" && !((_this2$options$block = _this2.options.block) !== null && _this2$options$block !== void 0 && _this2$options$block.h1)) {
2204
2255
  addError(path, "'h' block is not valid", false);
2205
2256
  }
@@ -2272,7 +2323,7 @@ var RichTextSchema = /*#__PURE__*/function (_Schema) {
2272
2323
  if (!((_this2$options$inline4 = _this2.options.inline) !== null && _this2$options$inline4 !== void 0 && _this2$options$inline4.img)) {
2273
2324
  addError(path, "'img' inline is not valid", false);
2274
2325
  } else if ((_this2$options$inline5 = _this2.options.inline) !== null && _this2$options$inline5 !== void 0 && _this2$options$inline5.img) {
2275
- var _this2$options$inline6, _this2$options$inline7;
2326
+ var _this2$options$inline6;
2276
2327
  if (!("src" in node)) {
2277
2328
  return {
2278
2329
  v: _defineProperty({}, path, [{
@@ -2282,7 +2333,8 @@ var RichTextSchema = /*#__PURE__*/function (_Schema) {
2282
2333
  };
2283
2334
  }
2284
2335
  var srcPath = unsafeCreateSourcePath(path, "src");
2285
- var imageValidationErrors = _typeof((_this2$options$inline6 = _this2.options.inline) === null || _this2$options$inline6 === void 0 ? void 0 : _this2$options$inline6.img) === "object" ? (_this2$options$inline7 = _this2.options.inline) === null || _this2$options$inline7 === void 0 ? void 0 : _this2$options$inline7.img["executeValidate"](srcPath, node.src) : new ImageSchema({}, false, false)["executeValidate"](srcPath, node.src);
2336
+ var imgSchema = (_this2$options$inline6 = _this2.options.inline) === null || _this2$options$inline6 === void 0 ? void 0 : _this2$options$inline6.img;
2337
+ var imageValidationErrors = _typeof(imgSchema) === "object" ? imgSchema["executeValidate"](srcPath, node.src) : new ImageSchema({}, false, false)["executeValidate"](srcPath, node.src);
2286
2338
  if (imageValidationErrors) {
2287
2339
  for (var _validationErrorPathS in imageValidationErrors) {
2288
2340
  var _current$_validationE;
@@ -2616,6 +2668,39 @@ var richtext = function richtext(options) {
2616
2668
  return new RichTextSchema(options !== null && options !== void 0 ? options : {});
2617
2669
  };
2618
2670
 
2671
+ var RegEx = /^(https?:\/\/[^/]+)\/file\/p\/([^/]+)\/b\/([^/]+)\/v\/([^/]+)\/h\/([^/]+)\/f\/([^/]+)\/p\/(.+)$/;
2672
+ function splitRemoteRef(ref) {
2673
+ if (ref[0] === "/") {
2674
+ return {
2675
+ status: "error",
2676
+ error: "Not a remote ref: " + ref
2677
+ };
2678
+ }
2679
+ var match = ref.match(RegEx);
2680
+ if (!match) {
2681
+ return {
2682
+ status: "error",
2683
+ error: "Invalid remote ref: " + ref
2684
+ };
2685
+ }
2686
+ if (match[7].indexOf("public/val/") !== 0) {
2687
+ return {
2688
+ status: "error",
2689
+ error: "Invalid remote ref: " + ref
2690
+ };
2691
+ }
2692
+ return {
2693
+ status: "success",
2694
+ remoteHost: match[1],
2695
+ projectId: match[2],
2696
+ bucket: match[3],
2697
+ version: match[4],
2698
+ validationHash: match[5],
2699
+ fileHash: match[6],
2700
+ filePath: match[7]
2701
+ };
2702
+ }
2703
+
2619
2704
  var RecordSchema = /*#__PURE__*/function (_Schema) {
2620
2705
  function RecordSchema(item) {
2621
2706
  var _this;
@@ -2623,6 +2708,7 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
2623
2708
  var customValidateFunctions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
2624
2709
  var currentRouter = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
2625
2710
  var keySchema = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : null;
2711
+ var mediaOptions = arguments.length > 5 ? arguments[5] : undefined;
2626
2712
  _classCallCheck(this, RecordSchema);
2627
2713
  _this = _callSuper(this, RecordSchema);
2628
2714
  _defineProperty(_this, "renderInput", null);
@@ -2631,13 +2717,14 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
2631
2717
  _this.customValidateFunctions = customValidateFunctions;
2632
2718
  _this.currentRouter = currentRouter;
2633
2719
  _this.keySchema = keySchema;
2720
+ _this.mediaOptions = mediaOptions;
2634
2721
  return _this;
2635
2722
  }
2636
2723
  _inherits(RecordSchema, _Schema);
2637
2724
  return _createClass(RecordSchema, [{
2638
2725
  key: "validate",
2639
2726
  value: function validate(validationFunction) {
2640
- return new RecordSchema(this.item, this.opt, [].concat(_toConsumableArray(this.customValidateFunctions), [validationFunction]), this.currentRouter, this.keySchema);
2727
+ return new RecordSchema(this.item, this.opt, [].concat(_toConsumableArray(this.customValidateFunctions), [validationFunction]), this.currentRouter, this.keySchema, this.mediaOptions);
2641
2728
  }
2642
2729
  }, {
2643
2730
  key: "executeValidate",
@@ -2681,6 +2768,40 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
2681
2768
  } finally {
2682
2769
  _iterator.f();
2683
2770
  }
2771
+ if (this.mediaOptions) {
2772
+ var checkFix = this.mediaOptions.type === "images" ? "images:check-unique-folder" : "files:check-unique-folder";
2773
+ var uniqueCheckError = {
2774
+ message: "Gallery directory '".concat(this.mediaOptions.directory, "' must be unique across all galleries"),
2775
+ value: {
2776
+ directory: this.mediaOptions.directory,
2777
+ type: this.mediaOptions.type
2778
+ },
2779
+ fixes: [checkFix]
2780
+ };
2781
+ if (error) {
2782
+ if (error[path]) {
2783
+ error[path] = [].concat(_toConsumableArray(error[path]), [uniqueCheckError]);
2784
+ } else {
2785
+ error = _objectSpread2(_objectSpread2({}, error), {}, _defineProperty({}, path, [uniqueCheckError]));
2786
+ }
2787
+ } else {
2788
+ error = _defineProperty({}, path, [uniqueCheckError]);
2789
+ }
2790
+ var allFilesCheckFix = this.mediaOptions.type === "images" ? "images:check-all-files" : "files:check-all-files";
2791
+ var allFilesCheckError = {
2792
+ message: "Directory '".concat(this.mediaOptions.directory, "' may have files not tracked by this gallery"),
2793
+ value: {
2794
+ directory: this.mediaOptions.directory,
2795
+ type: this.mediaOptions.type
2796
+ },
2797
+ fixes: [allFilesCheckFix]
2798
+ };
2799
+ if (error[path]) {
2800
+ error[path] = [].concat(_toConsumableArray(error[path]), [allFilesCheckError]);
2801
+ } else {
2802
+ error = _objectSpread2(_objectSpread2({}, error), {}, _defineProperty({}, path, [allFilesCheckError]));
2803
+ }
2804
+ }
2684
2805
  Object.entries(src).forEach(function (_ref5) {
2685
2806
  var _ref6 = _slicedToArray(_ref5, 2),
2686
2807
  key = _ref6[0],
@@ -2714,6 +2835,16 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
2714
2835
  error = _this2.appendValidationError(error, path, "Internal error: could not create path at ".concat(!path && typeof path === "string" ? "<empty string>" : path, " at key ").concat(elem),
2715
2836
  // Should! never happen
2716
2837
  src);
2838
+ } else if (_this2.mediaOptions) {
2839
+ // Media collection: validate key (path/URL) and entry (metadata)
2840
+ var keyErr = _this2.validateMediaKey(subPath, key);
2841
+ if (keyErr) {
2842
+ error = error ? _objectSpread2(_objectSpread2({}, error), keyErr) : keyErr;
2843
+ }
2844
+ var entryErr = _this2.validateMediaEntry(subPath, elem);
2845
+ if (entryErr) {
2846
+ error = error ? _objectSpread2(_objectSpread2({}, error), entryErr) : entryErr;
2847
+ }
2717
2848
  } else {
2718
2849
  var subError = _this2.item["executeValidate"](subPath, elem);
2719
2850
  if (subError && error) {
@@ -2725,6 +2856,176 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
2725
2856
  });
2726
2857
  return error;
2727
2858
  }
2859
+ }, {
2860
+ key: "isRemoteUrl",
2861
+ value: function isRemoteUrl(url) {
2862
+ return url.startsWith("https://") || url.startsWith("http://");
2863
+ }
2864
+ }, {
2865
+ key: "validateMediaKey",
2866
+ value: function validateMediaKey(path, key) {
2867
+ if (!this.mediaOptions) {
2868
+ return false;
2869
+ }
2870
+ var _this$mediaOptions = this.mediaOptions,
2871
+ directory = _this$mediaOptions.directory,
2872
+ isRemote = _this$mediaOptions.remote,
2873
+ type = _this$mediaOptions.type;
2874
+ var mediaLabel = type === "images" ? "images" : "files";
2875
+ var checkRemoteFix = type === "images" ? "images:check-remote" : "files:check-remote";
2876
+ var isRemoteUrl = this.isRemoteUrl(key);
2877
+ var isLocalPath = key === directory || key.startsWith(directory + "/");
2878
+ if (isRemote) {
2879
+ // When remote is enabled, accept either remote URLs or local paths
2880
+ if (isRemoteUrl) {
2881
+ // Validate remote URL format using splitRemoteRef
2882
+ var remoteResult = splitRemoteRef(key);
2883
+ if (remoteResult.status === "error") {
2884
+ return _defineProperty({}, path, [{
2885
+ message: "Invalid remote URL format. Use Val tooling (CLI, VS Code extension, or Val Studio) to upload ".concat(mediaLabel, ". Got: ").concat(key),
2886
+ value: key,
2887
+ fixes: [checkRemoteFix]
2888
+ }]);
2889
+ }
2890
+ // Check that the file path in the remote URL matches our directory constraint
2891
+ var remotePath = "/" + remoteResult.filePath;
2892
+ if (remotePath !== directory && !remotePath.startsWith(directory + "/")) {
2893
+ return _defineProperty({}, path, [{
2894
+ message: "Remote file path '".concat(remotePath, "' is not in expected directory '").concat(directory, "'. Use Val tooling to upload ").concat(mediaLabel, " to the correct directory."),
2895
+ value: key,
2896
+ fixes: [checkRemoteFix]
2897
+ }]);
2898
+ }
2899
+ return false;
2900
+ }
2901
+ if (!isLocalPath) {
2902
+ return _defineProperty({}, path, [{
2903
+ message: "Expected a remote URL (https://...) or a local path starting with ".concat(directory, "/. Got: ").concat(key),
2904
+ value: key
2905
+ }]);
2906
+ }
2907
+ } else {
2908
+ // When remote is disabled, only accept local paths
2909
+ if (isRemoteUrl) {
2910
+ return _defineProperty({}, path, [{
2911
+ message: "Remote URLs are not allowed. Use .remote() to enable remote ".concat(mediaLabel, ". Got: ").concat(key),
2912
+ value: key,
2913
+ fixes: [checkRemoteFix]
2914
+ }]);
2915
+ }
2916
+ if (!isLocalPath) {
2917
+ return _defineProperty({}, path, [{
2918
+ message: "File path must be within the ".concat(directory, "/ directory. Got: ").concat(key),
2919
+ value: key
2920
+ }]);
2921
+ }
2922
+ }
2923
+ return false;
2924
+ }
2925
+ }, {
2926
+ key: "validateMediaEntry",
2927
+ value: function validateMediaEntry(path, entry) {
2928
+ if (!this.mediaOptions) {
2929
+ return false;
2930
+ }
2931
+ var _this$mediaOptions2 = this.mediaOptions,
2932
+ type = _this$mediaOptions2.type,
2933
+ accept = _this$mediaOptions2.accept,
2934
+ altSchema = _this$mediaOptions2.altSchema;
2935
+ if (_typeof(entry) !== "object" || entry === null) {
2936
+ return _defineProperty({}, path, [{
2937
+ message: "Expected 'object', got '".concat(_typeof(entry), "'"),
2938
+ value: entry
2939
+ }]);
2940
+ }
2941
+ var entryObj = entry;
2942
+ var errors = [];
2943
+ if (type === "images") {
2944
+ // Validate width
2945
+ if (typeof entryObj.width !== "number" || entryObj.width <= 0) {
2946
+ errors.push({
2947
+ message: "Expected 'width' to be a positive number, got '".concat(entryObj.width, "'"),
2948
+ value: entry
2949
+ });
2950
+ }
2951
+
2952
+ // Validate height
2953
+ if (typeof entryObj.height !== "number" || entryObj.height <= 0) {
2954
+ errors.push({
2955
+ message: "Expected 'height' to be a positive number, got '".concat(entryObj.height, "'"),
2956
+ value: entry
2957
+ });
2958
+ }
2959
+ }
2960
+
2961
+ // Validate mimeType
2962
+ if (typeof entryObj.mimeType !== "string") {
2963
+ errors.push({
2964
+ message: "Expected 'mimeType' to be a string, got '".concat(_typeof(entryObj.mimeType), "'"),
2965
+ value: entry
2966
+ });
2967
+ } else {
2968
+ var mimeTypeError = this.validateMediaMimeType(entryObj.mimeType, accept);
2969
+ if (mimeTypeError) {
2970
+ errors.push({
2971
+ message: mimeTypeError,
2972
+ value: entry
2973
+ });
2974
+ }
2975
+ }
2976
+ if (type === "images") {
2977
+ // Validate hotspot if present
2978
+ if (entryObj.hotspot !== undefined) {
2979
+ var hs = entryObj.hotspot;
2980
+ if (_typeof(entryObj.hotspot) !== "object" || typeof hs.x !== "number" || typeof hs.y !== "number") {
2981
+ errors.push({
2982
+ message: "Hotspot must be an object with x and y as numbers.",
2983
+ value: entry
2984
+ });
2985
+ }
2986
+ }
2987
+
2988
+ // Validate alt using the alt schema
2989
+ var altPath = createValPathOfItem(path, "alt");
2990
+ if (altPath && altSchema) {
2991
+ var altError = altSchema["executeValidate"](altPath, entryObj.alt);
2992
+ if (altError) {
2993
+ return errors.length > 0 ? _objectSpread2(_objectSpread2({}, altError), {}, _defineProperty({}, path, errors)) : altError;
2994
+ }
2995
+ }
2996
+ }
2997
+ if (errors.length > 0) {
2998
+ return _defineProperty({}, path, errors);
2999
+ }
3000
+ return false;
3001
+ }
3002
+ }, {
3003
+ key: "validateMediaMimeType",
3004
+ value: function validateMediaMimeType(mimeType, accept) {
3005
+ if (!mimeType.includes("/")) {
3006
+ return "Invalid mime type format. Got: '".concat(mimeType, "'");
3007
+ }
3008
+ var acceptedTypes = accept.split(",").map(function (type) {
3009
+ return type.trim();
3010
+ });
3011
+ var isValidMimeType = acceptedTypes.some(function (acceptedType) {
3012
+ if (acceptedType === "*/*") {
3013
+ return true;
3014
+ }
3015
+ if (acceptedType === "image/*") {
3016
+ return mimeType.startsWith("image/");
3017
+ }
3018
+ if (acceptedType.endsWith("/*")) {
3019
+ var baseType = acceptedType.slice(0, -2);
3020
+ return mimeType.startsWith(baseType);
3021
+ }
3022
+ return acceptedType === mimeType;
3023
+ });
3024
+ if (!isValidMimeType) {
3025
+ return "Mime type mismatch. Found '".concat(mimeType, "' but schema accepts '").concat(accept, "'");
3026
+ }
3027
+ return null;
3028
+ }
2728
3029
  }, {
2729
3030
  key: "executeAssert",
2730
3031
  value: function executeAssert(path, src) {
@@ -2734,6 +3035,15 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
2734
3035
  data: src
2735
3036
  };
2736
3037
  }
3038
+ if (src === null) {
3039
+ return {
3040
+ success: false,
3041
+ errors: _defineProperty({}, path, [{
3042
+ message: "Expected 'object', got 'null'",
3043
+ typeError: true
3044
+ }])
3045
+ };
3046
+ }
2737
3047
  if (_typeof(src) !== "object") {
2738
3048
  return {
2739
3049
  success: false,
@@ -2760,12 +3070,19 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
2760
3070
  }, {
2761
3071
  key: "nullable",
2762
3072
  value: function nullable() {
2763
- return new RecordSchema(this.item, true, this.customValidateFunctions, this.currentRouter, this.keySchema);
3073
+ return new RecordSchema(this.item, true, this.customValidateFunctions, this.currentRouter, this.keySchema, this.mediaOptions);
2764
3074
  }
2765
3075
  }, {
2766
3076
  key: "router",
2767
3077
  value: function router(_router) {
2768
- return new RecordSchema(this.item, this.opt, this.customValidateFunctions, _router, this.keySchema);
3078
+ return new RecordSchema(this.item, this.opt, this.customValidateFunctions, _router, this.keySchema, this.mediaOptions);
3079
+ }
3080
+ }, {
3081
+ key: "remote",
3082
+ value: function remote() {
3083
+ return new RecordSchema(this.item, this.opt, this.customValidateFunctions, this.currentRouter, this.keySchema, this.mediaOptions ? _objectSpread2(_objectSpread2({}, this.mediaOptions), {}, {
3084
+ remote: true
3085
+ }) : undefined);
2769
3086
  }
2770
3087
  }, {
2771
3088
  key: "getRouterValidations",
@@ -2813,7 +3130,7 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
2813
3130
  key: "executeSerialize",
2814
3131
  value: function executeSerialize() {
2815
3132
  var _this$keySchema, _this$currentRouter, _this$customValidateF;
2816
- return {
3133
+ var result = {
2817
3134
  type: "record",
2818
3135
  item: this.item["executeSerialize"](),
2819
3136
  key: (_this$keySchema = this.keySchema) === null || _this$keySchema === void 0 ? void 0 : _this$keySchema["executeSerialize"](),
@@ -2821,6 +3138,16 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
2821
3138
  router: (_this$currentRouter = this.currentRouter) === null || _this$currentRouter === void 0 ? void 0 : _this$currentRouter.getRouterId(),
2822
3139
  customValidate: this.customValidateFunctions && ((_this$customValidateF = this.customValidateFunctions) === null || _this$customValidateF === void 0 ? void 0 : _this$customValidateF.length) > 0
2823
3140
  };
3141
+ if (this.mediaOptions) {
3142
+ result.mediaType = this.mediaOptions.type;
3143
+ result.accept = this.mediaOptions.accept;
3144
+ result.directory = this.mediaOptions.directory;
3145
+ result.remote = this.mediaOptions.remote;
3146
+ if (this.mediaOptions.altSchema) {
3147
+ result.alt = this.mediaOptions.altSchema["executeSerialize"]();
3148
+ }
3149
+ }
3150
+ return result;
2824
3151
  }
2825
3152
  }, {
2826
3153
  key: "executeRender",
@@ -2857,10 +3184,10 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
2857
3184
  data: {
2858
3185
  layout: "list",
2859
3186
  parent: "record",
2860
- items: Object.entries(src).map(function (_ref8) {
2861
- var _ref9 = _slicedToArray(_ref8, 2),
2862
- key = _ref9[0],
2863
- val = _ref9[1];
3187
+ items: Object.entries(src).map(function (_ref13) {
3188
+ var _ref14 = _slicedToArray(_ref13, 2),
3189
+ key = _ref14[0],
3190
+ val = _ref14[1];
2864
3191
  // NB NB: display is actually defined by the user
2865
3192
  var _prepare = prepare({
2866
3193
  key: key,
@@ -2915,14 +3242,11 @@ function record(keyOrSchema, schema) {
2915
3242
 
2916
3243
  function define(id,
2917
3244
  // TODO: `/${string}`
2918
-
2919
3245
  schema, source) {
2920
3246
  return _defineProperty(_defineProperty(_defineProperty({}, GetSource, source), GetSchema, schema), Path, id);
2921
3247
  }
2922
3248
  function getSource(valModule) {
2923
- var sourceOrExpr = valModule[GetSource];
2924
- var source = sourceOrExpr;
2925
- return source;
3249
+ return valModule[GetSource];
2926
3250
  }
2927
3251
  function splitModuleFilePathAndModulePath(path) {
2928
3252
  var pathOfSep = path.indexOf(ModuleFilePathSep);
@@ -3853,6 +4177,44 @@ var keyOf = function keyOf(valModule) {
3853
4177
  return new KeyOfSchema(serializedRefSchema, getValPath(valModule));
3854
4178
  };
3855
4179
 
4180
+ /**
4181
+ * Options for s.files()
4182
+ */
4183
+
4184
+ /**
4185
+ * Metadata for a file entry in the files record
4186
+ */
4187
+
4188
+ /**
4189
+ * Define a collection of files.
4190
+ *
4191
+ * @example
4192
+ * ```typescript
4193
+ * const schema = s.files({
4194
+ * accept: "application/pdf",
4195
+ * directory: "/public/val/documents",
4196
+ * });
4197
+ * export default c.define("/content/documents.val.ts", schema, {
4198
+ * "/public/val/documents/report.pdf": {
4199
+ * mimeType: "application/pdf",
4200
+ * },
4201
+ * });
4202
+ * ```
4203
+ */
4204
+ var files = function files(options) {
4205
+ var _options$directory, _options$remote;
4206
+ var directory = (_options$directory = options.directory) !== null && _options$directory !== void 0 ? _options$directory : "/public/val";
4207
+ var itemSchema = new ObjectSchema({
4208
+ mimeType: new StringSchema({}, false)
4209
+ }, false);
4210
+ return new RecordSchema(itemSchema, false, [], null, null, {
4211
+ type: "files",
4212
+ accept: options.accept,
4213
+ directory: directory,
4214
+ remote: (_options$remote = options.remote) !== null && _options$remote !== void 0 ? _options$remote : false
4215
+ });
4216
+ };
4217
+
3856
4218
  var DateSchema = /*#__PURE__*/function (_Schema) {
3857
4219
  function DateSchema(options) {
3858
4220
  var _this;
@@ -4001,6 +4363,59 @@ function router(router, item) {
4001
4363
  return recordSchema;
4002
4364
  }
4003
4365
 
4366
+ /**
4367
+ * Alt schema type - can be a string, nullable string, or a record of locale to string
4368
+ */
4369
+
4370
+ /**
4371
+ * Options for s.images()
4372
+ */
4373
+
4374
+ /**
4375
+ * Metadata for an image entry in the images record
4376
+ */
4377
+
4378
+ // Item schema types for images (alt simplified to string | null for typing)
4379
+
4380
+ /**
4381
+ * Define a collection of images.
4382
+ *
4383
+ * @example
4384
+ * ```typescript
4385
+ * const schema = s.images({
4386
+ * accept: "image/webp",
4387
+ * directory: "/public/val/images",
4388
+ * alt: s.string().minLength(4),
4389
+ * });
4390
+ * export default c.define("/content/images.val.ts", schema, {
4391
+ * "/public/val/images/hero.webp": {
4392
+ * width: 1920,
4393
+ * height: 1080,
4394
+ * mimeType: "image/webp",
4395
+ * alt: "Hero image",
4396
+ * },
4397
+ * });
4398
+ * ```
4399
+ */
4400
+ var images = function images(options) {
4401
+ var _options$directory, _options$alt, _options$remote;
4402
+ var directory = (_options$directory = options.directory) !== null && _options$directory !== void 0 ? _options$directory : "/public/val";
4403
+ var altSchema = (_options$alt = options.alt) !== null && _options$alt !== void 0 ? _options$alt : string().nullable();
4404
+ var itemSchema = new ObjectSchema({
4405
+ width: new NumberSchema(undefined, false),
4406
+ height: new NumberSchema(undefined, false),
4407
+ mimeType: new StringSchema({}, false),
4408
+ alt: altSchema
4409
+ }, false);
4410
+ return new RecordSchema(itemSchema, false, [], null, null, {
4411
+ type: "images",
4412
+ accept: options.accept,
4413
+ directory: directory,
4414
+ remote: (_options$remote = options.remote) !== null && _options$remote !== void 0 ? _options$remote : false,
4415
+ altSchema: altSchema
4416
+ });
4417
+ };
4418
+
4004
4419
  // import type { F } from "ts-toolbelt";
4005
4420
  // import { i18n, I18n } from "./schema/future/i18n";
4006
4421
  // import { oneOf } from "./schema/future/oneOf";
@@ -4024,9 +4439,11 @@ function initSchema() {
4024
4439
  keyOf: keyOf,
4025
4440
  record: record,
4026
4441
  file: file,
4442
+ files: files,
4027
4443
  date: date,
4028
4444
  route: route,
4029
- router: router
4445
+ router: router,
4446
+ images: images
4030
4447
  // i18n: i18n(locales),
4031
4448
  };
4032
4449
  }
@@ -4175,33 +4592,6 @@ function modules(config, modules) {
4175
4592
  };
4176
4593
  }
4177
4594
 
4178
- var RegEx = /^(https?:\/\/[^/]+)\/file\/p\/([^/]+)\/b\/([^/]+)\/v\/([^/]+)\/h\/([^/]+)\/f\/([^/]+)\/p\/(.+)$/;
4179
- function splitRemoteRef(ref) {
4180
- var match = ref.match(RegEx);
4181
- if (!match) {
4182
- return {
4183
- status: "error",
4184
- error: "Invalid remote ref: " + ref
4185
- };
4186
- }
4187
- if (match[7].indexOf("public/val/") !== 0) {
4188
- return {
4189
- status: "error",
4190
- error: "Invalid remote ref: " + ref
4191
- };
4192
- }
4193
- return {
4194
- status: "success",
4195
- remoteHost: match[1],
4196
- projectId: match[2],
4197
- bucket: match[3],
4198
- version: match[4],
4199
- validationHash: match[5],
4200
- fileHash: match[6],
4201
- filePath: match[7]
4202
- };
4203
- }
4204
-
4205
4595
  var DEFAULT_VAL_REMOTE_HOST = "https://remote.val.build";
4206
4596
  function convertRemoteSource(src) {
4207
4597
  if (src !== null && src !== void 0 && src.patch_id) {
@@ -5434,7 +5824,7 @@ function getFileHash(text) {
5434
5824
  }
5435
5825
 
5436
5826
  function deserializeSchema(serialized) {
5437
- var _serialized$options, _serialized$options2;
5827
+ var _serialized$options, _serialized$options2, _serialized$accept, _serialized$directory, _serialized$remote;
5438
5828
  switch (serialized.type) {
5439
5829
  case "string":
5440
5830
  return new StringSchema(_objectSpread2(_objectSpread2({}, serialized.options), {}, {
@@ -5477,7 +5867,13 @@ function deserializeSchema(serialized) {
5477
5867
  return new RichTextSchema(deserializedOptions, serialized.opt);
5478
5868
  }
5479
5869
  case "record":
5480
- return new RecordSchema(deserializeSchema(serialized.item), serialized.opt, [], null, serialized.key ? deserializeSchema(serialized.key) : null);
5870
+ return new RecordSchema(deserializeSchema(serialized.item), serialized.opt, [], null, serialized.key ? deserializeSchema(serialized.key) : null, serialized.mediaType ? {
5871
+ type: serialized.mediaType,
5872
+ accept: (_serialized$accept = serialized.accept) !== null && _serialized$accept !== void 0 ? _serialized$accept : "*/*",
5873
+ directory: (_serialized$directory = serialized.directory) !== null && _serialized$directory !== void 0 ? _serialized$directory : "/public/val",
5874
+ remote: (_serialized$remote = serialized.remote) !== null && _serialized$remote !== void 0 ? _serialized$remote : false,
5875
+ altSchema: serialized.alt ? deserializeSchema(serialized.alt) : undefined
5876
+ } : undefined);
5481
5877
  case "keyOf":
5482
5878
  return new KeyOfSchema(serialized.schema, serialized.path, serialized.opt);
5483
5879
  case "route":
@@ -5723,6 +6119,37 @@ function parseNextJsRoutePattern(moduleFilePath) {
5723
6119
  return [];
5724
6120
  }
5725
6121
 
6122
+ /**
6123
+ * Given a URL pathname (e.g. "/blogs/blog-1") and all serialized module schemas,
6124
+ * finds the matching next-app-router module and returns the module file path
6125
+ * and the source path for that route's content.
6126
+ *
6127
+ * External routers (e.g. external-url-router) are intentionally skipped.
6128
+ * Returns null if no next-app-router module matches the pathname.
6129
+ */
6130
+ function getSourcePathFromRoute(pathname, schemas) {
6131
+ for (var _i = 0, _arr = Object.entries(schemas); _i < _arr.length; _i++) {
6132
+ var _arr$_i = _slicedToArray(_arr[_i], 2),
6133
+ moduleFilePath = _arr$_i[0],
6134
+ schema = _arr$_i[1];
6135
+ if (schema.type !== "record" || schema.router !== "next-app-router") {
6136
+ continue;
6137
+ }
6138
+ var routePattern = parseNextJsRoutePattern(moduleFilePath);
6139
+ var _validateUrlAgainstPa = validateUrlAgainstPattern(pathname, routePattern),
6140
+ isValid = _validateUrlAgainstPa.isValid;
6141
+ if (isValid) {
6142
+ var sourcePath = "".concat(moduleFilePath, "?p=").concat(JSON.stringify(pathname));
6143
+ return {
6144
+ moduleFilePath: moduleFilePath,
6145
+ sourcePath: sourcePath,
6146
+ route: pathname
6147
+ };
6148
+ }
6149
+ }
6150
+ return null;
6151
+ }
6152
+
5726
6153
  var ModuleFilePathSep = "?p=";
5727
6154
  var FATAL_ERROR_TYPES = ["no-schema", "no-source", "invalid-id", "no-module", "invalid-patch"];
5728
6155
  var DEFAULT_CONTENT_HOST = "https://content.val.build";
@@ -5859,6 +6286,7 @@ exports._toConsumableArray = _toConsumableArray;
5859
6286
  exports._typeof = _typeof;
5860
6287
  exports.derefPatch = derefPatch;
5861
6288
  exports.deserializeSchema = deserializeSchema;
6289
+ exports.getSourcePathFromRoute = getSourcePathFromRoute;
5862
6290
  exports.initVal = initVal;
5863
6291
  exports.modules = modules;
5864
6292
  exports.splitModuleFilePathAndModulePath = splitModuleFilePathAndModulePath;