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