@valbuild/core 0.102.0 → 0.103.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/index.d.ts +11 -10
- package/dist/declarations/src/initSchema.d.ts +27 -14
- package/dist/declarations/src/initVal.d.ts +0 -6
- package/dist/declarations/src/module.d.ts +1 -4
- package/dist/declarations/src/render.d.ts +3 -5
- package/dist/declarations/src/schema/array.d.ts +1 -1
- package/dist/declarations/src/schema/file.d.ts +17 -17
- package/dist/declarations/src/schema/image.d.ts +15 -6
- package/dist/declarations/src/schema/index.d.ts +1 -1
- package/dist/declarations/src/schema/record.d.ts +3 -5
- package/dist/declarations/src/schema/remote.d.ts +0 -10
- package/dist/declarations/src/selector/SelectorProxy.d.ts +9 -2
- package/dist/declarations/src/selector/index.d.ts +3 -7
- package/dist/declarations/src/source/file.d.ts +6 -24
- package/dist/declarations/src/source/index.d.ts +3 -7
- package/dist/declarations/src/source/json.d.ts +1 -1
- package/dist/declarations/src/source/media.d.ts +98 -0
- package/dist/declarations/src/source/remote.d.ts +0 -14
- package/dist/declarations/src/source/richtext.d.ts +5 -7
- package/dist/declarations/src/val/index.d.ts +2 -5
- package/dist/{index-796fd204.esm.js → index-267a8e9c.esm.js} +847 -804
- package/dist/{index-30ecb49c.cjs.dev.js → index-2e40f2ae.cjs.dev.js} +845 -804
- package/dist/{index-ca1bbeb2.cjs.prod.js → index-3572060f.cjs.prod.js} +845 -804
- package/dist/{result-4bd63123.esm.js → result-daff1cae.esm.js} +1 -1
- package/dist/valbuild-core.cjs.dev.js +1 -3
- package/dist/valbuild-core.cjs.prod.js +1 -3
- 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 +1 -1
- package/patch/dist/valbuild-core-patch.cjs.prod.js +1 -1
- package/patch/dist/valbuild-core-patch.esm.js +3 -3
- package/dist/declarations/src/selector/file.d.ts +0 -10
- package/dist/declarations/src/selector/image.d.ts +0 -3
- package/dist/declarations/src/source/image.d.ts +0 -19
|
@@ -1,4 +1,44 @@
|
|
|
1
|
-
import { _ as
|
|
1
|
+
import { _ as _unsupportedIterableToArray, a as _arrayLikeToArray, b as _createForOfIteratorHelper, i as isErr, c as isOk, e as err, o as ok } from './result-daff1cae.esm.js';
|
|
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
|
+
}
|
|
2
42
|
|
|
3
43
|
function _arrayWithoutHoles(r) {
|
|
4
44
|
if (Array.isArray(r)) return _arrayLikeToArray(r);
|
|
@@ -51,82 +91,69 @@ function _defineProperty(e, r, t) {
|
|
|
51
91
|
}) : e[r] = t, e;
|
|
52
92
|
}
|
|
53
93
|
|
|
54
|
-
function
|
|
55
|
-
|
|
56
|
-
if (Object.getOwnPropertySymbols) {
|
|
57
|
-
var o = Object.getOwnPropertySymbols(e);
|
|
58
|
-
r && (o = o.filter(function (r) {
|
|
59
|
-
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
60
|
-
})), t.push.apply(t, o);
|
|
61
|
-
}
|
|
62
|
-
return t;
|
|
94
|
+
function _classCallCheck(a, n) {
|
|
95
|
+
if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
|
|
63
96
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
|
|
70
|
-
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
71
|
-
});
|
|
97
|
+
|
|
98
|
+
function _defineProperties(e, r) {
|
|
99
|
+
for (var t = 0; t < r.length; t++) {
|
|
100
|
+
var o = r[t];
|
|
101
|
+
o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o);
|
|
72
102
|
}
|
|
73
|
-
|
|
103
|
+
}
|
|
104
|
+
function _createClass(e, r, t) {
|
|
105
|
+
return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {
|
|
106
|
+
writable: !1
|
|
107
|
+
}), e;
|
|
74
108
|
}
|
|
75
109
|
|
|
76
|
-
function
|
|
77
|
-
|
|
110
|
+
function _getPrototypeOf(t) {
|
|
111
|
+
return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) {
|
|
112
|
+
return t.__proto__ || Object.getPrototypeOf(t);
|
|
113
|
+
}, _getPrototypeOf(t);
|
|
78
114
|
}
|
|
79
115
|
|
|
80
|
-
function
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
-
}
|
|
116
|
+
function _isNativeReflectConstruct() {
|
|
117
|
+
try {
|
|
118
|
+
var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
|
|
119
|
+
} catch (t) {}
|
|
120
|
+
return (_isNativeReflectConstruct = function () {
|
|
121
|
+
return !!t;
|
|
122
|
+
})();
|
|
106
123
|
}
|
|
107
124
|
|
|
108
|
-
function
|
|
109
|
-
|
|
125
|
+
function _assertThisInitialized(e) {
|
|
126
|
+
if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
127
|
+
return e;
|
|
110
128
|
}
|
|
111
129
|
|
|
112
|
-
function
|
|
113
|
-
|
|
130
|
+
function _possibleConstructorReturn(t, e) {
|
|
131
|
+
if (e && ("object" == typeof e || "function" == typeof e)) return e;
|
|
132
|
+
if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined");
|
|
133
|
+
return _assertThisInitialized(t);
|
|
114
134
|
}
|
|
115
135
|
|
|
116
|
-
function
|
|
117
|
-
|
|
136
|
+
function _callSuper(t, o, e) {
|
|
137
|
+
return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e));
|
|
118
138
|
}
|
|
119
139
|
|
|
120
|
-
function
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}
|
|
140
|
+
function _setPrototypeOf(t, e) {
|
|
141
|
+
return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
|
|
142
|
+
return t.__proto__ = e, t;
|
|
143
|
+
}, _setPrototypeOf(t, e);
|
|
125
144
|
}
|
|
126
|
-
|
|
127
|
-
|
|
145
|
+
|
|
146
|
+
function _inherits(t, e) {
|
|
147
|
+
if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function");
|
|
148
|
+
t.prototype = Object.create(e && e.prototype, {
|
|
149
|
+
constructor: {
|
|
150
|
+
value: t,
|
|
151
|
+
writable: !0,
|
|
152
|
+
configurable: !0
|
|
153
|
+
}
|
|
154
|
+
}), Object.defineProperty(t, "prototype", {
|
|
128
155
|
writable: !1
|
|
129
|
-
}), e;
|
|
156
|
+
}), e && _setPrototypeOf(t, e);
|
|
130
157
|
}
|
|
131
158
|
|
|
132
159
|
// import { RemoteCompatibleSource, RemoteSource } from "../source/remote";
|
|
@@ -253,55 +280,6 @@ var Schema = /*#__PURE__*/function () {
|
|
|
253
280
|
|
|
254
281
|
// TODO: SourceError<"Could not determine type of Schema">
|
|
255
282
|
|
|
256
|
-
function _getPrototypeOf(t) {
|
|
257
|
-
return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) {
|
|
258
|
-
return t.__proto__ || Object.getPrototypeOf(t);
|
|
259
|
-
}, _getPrototypeOf(t);
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
function _isNativeReflectConstruct() {
|
|
263
|
-
try {
|
|
264
|
-
var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
|
|
265
|
-
} catch (t) {}
|
|
266
|
-
return (_isNativeReflectConstruct = function () {
|
|
267
|
-
return !!t;
|
|
268
|
-
})();
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
function _assertThisInitialized(e) {
|
|
272
|
-
if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
273
|
-
return e;
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
function _possibleConstructorReturn(t, e) {
|
|
277
|
-
if (e && ("object" == typeof e || "function" == typeof e)) return e;
|
|
278
|
-
if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined");
|
|
279
|
-
return _assertThisInitialized(t);
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
function _callSuper(t, o, e) {
|
|
283
|
-
return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e));
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
function _setPrototypeOf(t, e) {
|
|
287
|
-
return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
|
|
288
|
-
return t.__proto__ = e, t;
|
|
289
|
-
}, _setPrototypeOf(t, e);
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
function _inherits(t, e) {
|
|
293
|
-
if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function");
|
|
294
|
-
t.prototype = Object.create(e && e.prototype, {
|
|
295
|
-
constructor: {
|
|
296
|
-
value: t,
|
|
297
|
-
writable: !0,
|
|
298
|
-
configurable: !0
|
|
299
|
-
}
|
|
300
|
-
}), Object.defineProperty(t, "prototype", {
|
|
301
|
-
writable: !1
|
|
302
|
-
}), e && _setPrototypeOf(t, e);
|
|
303
|
-
}
|
|
304
|
-
|
|
305
283
|
// Identity symbols are registered in the global Symbol registry so that
|
|
306
284
|
// multiple bundled copies of @valbuild/core (e.g. the editor SPA bundle vs.
|
|
307
285
|
// the host Next.js bundle) resolve to the same Symbol instance. Without
|
|
@@ -343,383 +321,47 @@ function getSchema(selector) {
|
|
|
343
321
|
return selector[GetSchema];
|
|
344
322
|
}
|
|
345
323
|
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
*
|
|
352
|
-
*
|
|
353
|
-
*
|
|
354
|
-
*
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
*
|
|
366
|
-
*
|
|
367
|
-
*
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
// export function file<Metadata extends { readonly [key: string]: Json }>(
|
|
389
|
-
// ref: `${typeof directory}/${string}`,
|
|
390
|
-
// metadata: Metadata
|
|
391
|
-
// ): FileSource<Metadata>;
|
|
392
|
-
// export function file(
|
|
393
|
-
// ref: `${typeof directory}/${string}`,
|
|
394
|
-
// metadata?: undefined
|
|
395
|
-
// ): FileSource<undefined>;
|
|
396
|
-
// export function file<
|
|
397
|
-
// Metadata extends { readonly [key: string]: Json } | undefined
|
|
398
|
-
// >(
|
|
399
|
-
// ref: `${typeof directory}/${string}`,
|
|
400
|
-
// metadata?: Metadata
|
|
401
|
-
// ): FileSource<Metadata> {
|
|
402
|
-
// return {
|
|
403
|
-
// [FILE_REF_PROP]: ref,
|
|
404
|
-
// [VAL_EXTENSION]: "file",
|
|
405
|
-
// metadata,
|
|
406
|
-
// } as FileSource<Metadata>;
|
|
407
|
-
// }
|
|
408
|
-
|
|
409
|
-
function isFile(obj) {
|
|
410
|
-
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";
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
function isVal(val) {
|
|
414
|
-
return _typeof(val) === "object" && val !== null && val !== undefined && Path in val && "val" in val;
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
/**
|
|
418
|
-
* The path of the source value.
|
|
419
|
-
*
|
|
420
|
-
* @example
|
|
421
|
-
* '/app/blogs.val.ts?p=0.text' // the text property of the first element of the /app/blogs module
|
|
422
|
-
*/
|
|
423
|
-
|
|
424
|
-
/**
|
|
425
|
-
* The path inside the module.
|
|
426
|
-
*
|
|
427
|
-
* @example
|
|
428
|
-
* '0."text"' // the text property of the first element of the module
|
|
429
|
-
*/
|
|
430
|
-
|
|
431
|
-
/**
|
|
432
|
-
* The path of the module.
|
|
433
|
-
*
|
|
434
|
-
* @example
|
|
435
|
-
* '/app/blogs.val.ts'
|
|
436
|
-
*/
|
|
437
|
-
|
|
438
|
-
/**
|
|
439
|
-
* The patchId of the parent patch, or "head" if there is no parent patch.
|
|
440
|
-
*/
|
|
441
|
-
|
|
442
|
-
function getValPath(valOrSelector) {
|
|
443
|
-
return valOrSelector[Path];
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
var FileSchema = /*#__PURE__*/function (_Schema) {
|
|
447
|
-
function FileSchema(options) {
|
|
448
|
-
var _this;
|
|
449
|
-
var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
450
|
-
var isRemote = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
451
|
-
var customValidateFunctions = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
|
|
452
|
-
var moduleMetadata = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
|
|
453
|
-
var isReadonly = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
|
|
454
|
-
var isHidden = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : false;
|
|
455
|
-
var description = arguments.length > 7 ? arguments[7] : undefined;
|
|
456
|
-
_classCallCheck(this, FileSchema);
|
|
457
|
-
_this = _callSuper(this, FileSchema);
|
|
458
|
-
_this.options = options;
|
|
459
|
-
_this.opt = opt;
|
|
460
|
-
_this.isRemote = isRemote;
|
|
461
|
-
_this.customValidateFunctions = customValidateFunctions;
|
|
462
|
-
_this.moduleMetadata = moduleMetadata;
|
|
463
|
-
_this.isReadonly = isReadonly;
|
|
464
|
-
_this.isHidden = isHidden;
|
|
465
|
-
_this.description = description;
|
|
466
|
-
return _this;
|
|
467
|
-
}
|
|
468
|
-
_inherits(FileSchema, _Schema);
|
|
469
|
-
return _createClass(FileSchema, [{
|
|
470
|
-
key: "describe",
|
|
471
|
-
value: function describe(description) {
|
|
472
|
-
return new FileSchema(this.options, this.opt, this.isRemote, this.customValidateFunctions, this.moduleMetadata, this.isReadonly, this.isHidden, description !== null && description !== void 0 ? description : undefined);
|
|
473
|
-
}
|
|
474
|
-
}, {
|
|
475
|
-
key: "remote",
|
|
476
|
-
value: function remote() {
|
|
477
|
-
return new FileSchema(this.options, this.opt, true, this.customValidateFunctions, this.moduleMetadata, this.isReadonly, this.isHidden, this.description);
|
|
478
|
-
}
|
|
479
|
-
}, {
|
|
480
|
-
key: "validate",
|
|
481
|
-
value: function validate(validationFunction) {
|
|
482
|
-
return new FileSchema(this.options, this.opt, this.isRemote, [].concat(_toConsumableArray(this.customValidateFunctions), [validationFunction]), this.moduleMetadata, this.isReadonly, this.isHidden, this.description);
|
|
483
|
-
}
|
|
484
|
-
}, {
|
|
485
|
-
key: "executeValidate",
|
|
486
|
-
value: function executeValidate(path, src) {
|
|
487
|
-
var customValidationErrors = this.executeCustomValidateFunctions(src, this.customValidateFunctions, {
|
|
488
|
-
path: path
|
|
489
|
-
});
|
|
490
|
-
if (this.opt && (src === null || src === undefined)) {
|
|
491
|
-
return customValidationErrors.length > 0 ? _defineProperty({}, path, customValidationErrors) : false;
|
|
492
|
-
}
|
|
493
|
-
if (src === null || src === undefined) {
|
|
494
|
-
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
495
|
-
message: "Non-optional file was null or undefined.",
|
|
496
|
-
value: src
|
|
497
|
-
}]));
|
|
498
|
-
}
|
|
499
|
-
if (typeof src[FILE_REF_PROP] !== "string") {
|
|
500
|
-
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
501
|
-
message: "File did not have a file reference string. Got: ".concat(_typeof(src[FILE_REF_PROP])),
|
|
502
|
-
value: src
|
|
503
|
-
}]));
|
|
504
|
-
}
|
|
505
|
-
if (this.isRemote && src[VAL_EXTENSION] !== "remote") {
|
|
506
|
-
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
507
|
-
message: "Expected a remote file, but got a local file.",
|
|
508
|
-
value: src,
|
|
509
|
-
fixes: ["file:upload-remote"]
|
|
510
|
-
}]));
|
|
511
|
-
}
|
|
512
|
-
if (this.isRemote && src[VAL_EXTENSION] === "remote") {
|
|
513
|
-
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
514
|
-
message: "Remote file was not checked.",
|
|
515
|
-
value: src,
|
|
516
|
-
fixes: ["file:check-remote"]
|
|
517
|
-
}]));
|
|
518
|
-
}
|
|
519
|
-
if (!this.isRemote && src[VAL_EXTENSION] === "remote") {
|
|
520
|
-
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
521
|
-
message: "Expected locale file, but found remote.",
|
|
522
|
-
value: src,
|
|
523
|
-
fixes: ["file:download-remote"]
|
|
524
|
-
}]));
|
|
525
|
-
}
|
|
526
|
-
if (src[VAL_EXTENSION] !== "file") {
|
|
527
|
-
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
528
|
-
message: "File did not have the valid file extension type. Got: ".concat(src[VAL_EXTENSION]),
|
|
529
|
-
value: src
|
|
530
|
-
}]));
|
|
531
|
-
}
|
|
532
|
-
var _ref8 = this.options || {},
|
|
533
|
-
accept = _ref8.accept;
|
|
534
|
-
var _ref9 = src.metadata || {},
|
|
535
|
-
mimeType = _ref9.mimeType;
|
|
536
|
-
if (accept && mimeType && !mimeType.includes("/")) {
|
|
537
|
-
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
538
|
-
message: "Invalid mime type format. Got: ".concat(mimeType),
|
|
539
|
-
value: src
|
|
540
|
-
}]));
|
|
541
|
-
}
|
|
542
|
-
if (accept && mimeType && mimeType.includes("/")) {
|
|
543
|
-
var acceptedTypes = accept.split(",").map(function (type) {
|
|
544
|
-
return type.trim();
|
|
545
|
-
});
|
|
546
|
-
var isValidMimeType = acceptedTypes.some(function (acceptedType) {
|
|
547
|
-
if (acceptedType === "*/*") {
|
|
548
|
-
return true;
|
|
549
|
-
}
|
|
550
|
-
if (acceptedType.endsWith("/*")) {
|
|
551
|
-
var baseType = acceptedType.slice(0, -2);
|
|
552
|
-
return mimeType.startsWith(baseType);
|
|
553
|
-
}
|
|
554
|
-
return acceptedType === mimeType;
|
|
555
|
-
});
|
|
556
|
-
if (!isValidMimeType) {
|
|
557
|
-
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
558
|
-
message: "Mime type mismatch. Found '".concat(mimeType, "' but schema accepts '").concat(accept, "'"),
|
|
559
|
-
value: src
|
|
560
|
-
}]));
|
|
561
|
-
}
|
|
562
|
-
}
|
|
563
|
-
var fileMimeType = Internal.filenameToMimeType(src[FILE_REF_PROP]);
|
|
564
|
-
if (!fileMimeType) {
|
|
565
|
-
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
566
|
-
message: "Could not determine mime type from file extension. Got: ".concat(src[FILE_REF_PROP]),
|
|
567
|
-
value: src
|
|
568
|
-
}]));
|
|
569
|
-
}
|
|
570
|
-
if (fileMimeType !== mimeType) {
|
|
571
|
-
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
572
|
-
message: "Mime type and file extension not matching. Mime type is '".concat(mimeType, "' but file extension is '").concat(fileMimeType, "'"),
|
|
573
|
-
value: src
|
|
574
|
-
}]));
|
|
575
|
-
}
|
|
576
|
-
if (src.metadata) {
|
|
577
|
-
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
578
|
-
message: "Found metadata, but it could not be validated. File metadata must be an object with the mimeType.",
|
|
579
|
-
// These validation errors will have to be picked up by logic outside of this package and revalidated. Reasons: 1) we have to read files to verify the metadata, which is handled differently in different runtimes (Browser, QuickJS, Node.js); 2) we want to keep this package dependency free.
|
|
580
|
-
value: src,
|
|
581
|
-
fixes: ["file:check-metadata"]
|
|
582
|
-
}]));
|
|
583
|
-
}
|
|
584
|
-
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
585
|
-
message: "Missing File metadata.",
|
|
586
|
-
value: src,
|
|
587
|
-
fixes: ["file:add-metadata"]
|
|
588
|
-
}]));
|
|
589
|
-
}
|
|
590
|
-
}, {
|
|
591
|
-
key: "executeAssert",
|
|
592
|
-
value: function executeAssert(path, src) {
|
|
593
|
-
if (this.opt && src === null) {
|
|
594
|
-
return {
|
|
595
|
-
success: true,
|
|
596
|
-
data: src
|
|
597
|
-
};
|
|
598
|
-
}
|
|
599
|
-
if (src === null) {
|
|
600
|
-
return {
|
|
601
|
-
success: false,
|
|
602
|
-
errors: _defineProperty({}, path, [{
|
|
603
|
-
message: "Expected 'object', got 'null'",
|
|
604
|
-
typeError: true
|
|
605
|
-
}])
|
|
606
|
-
};
|
|
607
|
-
}
|
|
608
|
-
if (_typeof(src) !== "object") {
|
|
609
|
-
return {
|
|
610
|
-
success: false,
|
|
611
|
-
errors: _defineProperty({}, path, [{
|
|
612
|
-
message: "Expected object, got '".concat(_typeof(src), "'"),
|
|
613
|
-
typeError: true
|
|
614
|
-
}])
|
|
615
|
-
};
|
|
616
|
-
}
|
|
617
|
-
if (!(FILE_REF_PROP in src)) {
|
|
618
|
-
return {
|
|
619
|
-
success: false,
|
|
620
|
-
errors: _defineProperty({}, path, [{
|
|
621
|
-
message: "Value of this schema must use: 'c.file' (error type: missing_ref_prop)",
|
|
622
|
-
typeError: true
|
|
623
|
-
}])
|
|
624
|
-
};
|
|
625
|
-
}
|
|
626
|
-
if (!(VAL_EXTENSION in src && src[VAL_EXTENSION] === "file")) {
|
|
627
|
-
return {
|
|
628
|
-
success: false,
|
|
629
|
-
errors: _defineProperty({}, path, [{
|
|
630
|
-
message: "Value of this schema must use: 'c.file' (error type: missing_file_extension)",
|
|
631
|
-
typeError: true
|
|
632
|
-
}])
|
|
633
|
-
};
|
|
634
|
-
}
|
|
635
|
-
return {
|
|
636
|
-
success: true,
|
|
637
|
-
data: src
|
|
638
|
-
};
|
|
639
|
-
}
|
|
640
|
-
}, {
|
|
641
|
-
key: "nullable",
|
|
642
|
-
value: function nullable() {
|
|
643
|
-
return new FileSchema(this.options, true, this.isRemote, this.customValidateFunctions, this.moduleMetadata, this.isReadonly, this.isHidden, this.description);
|
|
644
|
-
}
|
|
645
|
-
}, {
|
|
646
|
-
key: "readonly",
|
|
647
|
-
value: function readonly() {
|
|
648
|
-
return new FileSchema(this.options, this.opt, this.isRemote, this.customValidateFunctions, this.moduleMetadata, true, this.isHidden, this.description);
|
|
649
|
-
}
|
|
650
|
-
}, {
|
|
651
|
-
key: "hidden",
|
|
652
|
-
value: function hidden() {
|
|
653
|
-
return new FileSchema(this.options, this.opt, this.isRemote, this.customValidateFunctions, this.moduleMetadata, this.isReadonly, true, this.description);
|
|
654
|
-
}
|
|
655
|
-
}, {
|
|
656
|
-
key: "executeCustomValidateAt",
|
|
657
|
-
value: function executeCustomValidateAt(path, src) {
|
|
658
|
-
return this.executeCustomValidateFunctions(src, this.customValidateFunctions, {
|
|
659
|
-
path: path
|
|
660
|
-
});
|
|
661
|
-
}
|
|
662
|
-
}, {
|
|
663
|
-
key: "executeSerialize",
|
|
664
|
-
value: function executeSerialize() {
|
|
665
|
-
var _this$customValidateF;
|
|
666
|
-
var modulePaths = this.moduleMetadata ? Object.keys(this.moduleMetadata) : [];
|
|
667
|
-
return {
|
|
668
|
-
type: "file",
|
|
669
|
-
options: this.options,
|
|
670
|
-
opt: this.opt,
|
|
671
|
-
remote: this.isRemote,
|
|
672
|
-
customValidate: this.customValidateFunctions && ((_this$customValidateF = this.customValidateFunctions) === null || _this$customValidateF === void 0 ? void 0 : _this$customValidateF.length) > 0,
|
|
673
|
-
referencedModule: modulePaths.length > 0 ? modulePaths[0] : undefined,
|
|
674
|
-
readonly: this.isReadonly,
|
|
675
|
-
hidden: this.isHidden,
|
|
676
|
-
description: this.description
|
|
677
|
-
};
|
|
678
|
-
}
|
|
679
|
-
}, {
|
|
680
|
-
key: "executeRender",
|
|
681
|
-
value: function executeRender() {
|
|
682
|
-
return {};
|
|
683
|
-
}
|
|
684
|
-
}]);
|
|
685
|
-
}(Schema);
|
|
686
|
-
var file = function file(options) {
|
|
687
|
-
var isModule = !!options && !!Internal.getValPath(options);
|
|
688
|
-
if (isModule) {
|
|
689
|
-
var allModules = {};
|
|
690
|
-
for (var _i = 0, _arr = [options]; _i < _arr.length; _i++) {
|
|
691
|
-
var valModule = _arr[_i];
|
|
692
|
-
var modulePath = getValPath(valModule);
|
|
693
|
-
if (modulePath === undefined) {
|
|
694
|
-
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.");
|
|
695
|
-
}
|
|
696
|
-
allModules[modulePath] = getSource(valModule);
|
|
697
|
-
}
|
|
698
|
-
return new FileSchema({}, false, false, [], allModules);
|
|
699
|
-
}
|
|
700
|
-
return new FileSchema(options);
|
|
701
|
-
};
|
|
702
|
-
function convertFileSource(src) {
|
|
703
|
-
// TODO: /public should be configurable
|
|
704
|
-
if (!src[FILE_REF_PROP].startsWith("/public")) {
|
|
705
|
-
return {
|
|
706
|
-
url: src[FILE_REF_PROP] + (src.patch_id ? "?patch_id=".concat(src["patch_id"]) : ""),
|
|
707
|
-
metadata: src.metadata
|
|
708
|
-
};
|
|
709
|
-
}
|
|
710
|
-
if (src.patch_id) {
|
|
711
|
-
return {
|
|
712
|
-
url: "/api/val/files" + src[FILE_REF_PROP] + "?patch_id=".concat(src["patch_id"]),
|
|
713
|
-
metadata: src.metadata
|
|
714
|
-
};
|
|
715
|
-
}
|
|
716
|
-
return {
|
|
717
|
-
url: src[FILE_REF_PROP].slice("/public".length),
|
|
718
|
-
metadata: src.metadata
|
|
719
|
-
};
|
|
720
|
-
}
|
|
721
|
-
|
|
722
|
-
function createValPathOfItem(arrayPath, prop) {
|
|
324
|
+
function isVal(val) {
|
|
325
|
+
return _typeof(val) === "object" && val !== null && val !== undefined && Path in val && "val" in val;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* The path of the source value.
|
|
330
|
+
*
|
|
331
|
+
* @example
|
|
332
|
+
* '/app/blogs.val.ts?p=0.text' // the text property of the first element of the /app/blogs module
|
|
333
|
+
*/
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* The path inside the module.
|
|
337
|
+
*
|
|
338
|
+
* @example
|
|
339
|
+
* '0."text"' // the text property of the first element of the module
|
|
340
|
+
*/
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* The path of the module.
|
|
344
|
+
*
|
|
345
|
+
* @example
|
|
346
|
+
* '/app/blogs.val.ts'
|
|
347
|
+
*/
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* The patchId of the parent patch, or "head" if there is no parent patch.
|
|
351
|
+
*/
|
|
352
|
+
|
|
353
|
+
function getValPath(valOrSelector) {
|
|
354
|
+
return valOrSelector[Path];
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
function createValPathOfItem(
|
|
358
|
+
/**
|
|
359
|
+
* `ModuleFilePath` is accepted because the no-separator branch below is
|
|
360
|
+
* exactly that case: a path with no `?p=` yet gets one, and the key becomes
|
|
361
|
+
* the first module-path segment. Callers walking a module from its root had
|
|
362
|
+
* to widen the type themselves, and hand-rolled the concatenation instead.
|
|
363
|
+
*/
|
|
364
|
+
arrayPath, prop) {
|
|
723
365
|
if (_typeof(prop) === "symbol") {
|
|
724
366
|
throw Error("Cannot create val path of array item with symbol prop: ".concat(prop.toString()));
|
|
725
367
|
}
|
|
@@ -746,6 +388,28 @@ function unsafeCreateSourcePath(path, itemKey) {
|
|
|
746
388
|
return "".concat(path).concat(Internal.ModuleFilePathSep).concat(JSON.stringify(itemKey));
|
|
747
389
|
}
|
|
748
390
|
|
|
391
|
+
function ownKeys(e, r) {
|
|
392
|
+
var t = Object.keys(e);
|
|
393
|
+
if (Object.getOwnPropertySymbols) {
|
|
394
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
395
|
+
r && (o = o.filter(function (r) {
|
|
396
|
+
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
397
|
+
})), t.push.apply(t, o);
|
|
398
|
+
}
|
|
399
|
+
return t;
|
|
400
|
+
}
|
|
401
|
+
function _objectSpread2(e) {
|
|
402
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
403
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
|
404
|
+
r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
|
|
405
|
+
_defineProperty(e, r, t[r]);
|
|
406
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
|
|
407
|
+
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
return e;
|
|
411
|
+
}
|
|
412
|
+
|
|
749
413
|
var StringSchema = /*#__PURE__*/function (_Schema) {
|
|
750
414
|
function StringSchema(options) {
|
|
751
415
|
var _this;
|
|
@@ -2030,6 +1694,170 @@ var union = function union(key) {
|
|
|
2030
1694
|
return new UnionSchema(key, objects);
|
|
2031
1695
|
};
|
|
2032
1696
|
|
|
1697
|
+
var RegEx = /^(https?:\/\/[^/]+)\/file\/p\/([^/]+)\/b\/([^/]+)\/v\/([^/]+)\/h\/([^/]+)\/f\/([^/]+)\/p\/(.+)$/;
|
|
1698
|
+
function splitRemoteRef(ref) {
|
|
1699
|
+
if (ref[0] === "/") {
|
|
1700
|
+
return {
|
|
1701
|
+
status: "error",
|
|
1702
|
+
error: "Not a remote ref: " + ref
|
|
1703
|
+
};
|
|
1704
|
+
}
|
|
1705
|
+
var match = ref.match(RegEx);
|
|
1706
|
+
if (!match) {
|
|
1707
|
+
return {
|
|
1708
|
+
status: "error",
|
|
1709
|
+
error: "Invalid remote ref: " + ref
|
|
1710
|
+
};
|
|
1711
|
+
}
|
|
1712
|
+
if (match[7].indexOf("public/") !== 0) {
|
|
1713
|
+
return {
|
|
1714
|
+
status: "error",
|
|
1715
|
+
error: "Invalid remote ref: " + ref
|
|
1716
|
+
};
|
|
1717
|
+
}
|
|
1718
|
+
if (match[7].split("/").some(function (segment) {
|
|
1719
|
+
return segment === "." || segment === "..";
|
|
1720
|
+
})) {
|
|
1721
|
+
return {
|
|
1722
|
+
status: "error",
|
|
1723
|
+
error: "Invalid remote ref: " + ref
|
|
1724
|
+
};
|
|
1725
|
+
}
|
|
1726
|
+
return {
|
|
1727
|
+
status: "success",
|
|
1728
|
+
remoteHost: match[1],
|
|
1729
|
+
projectId: match[2],
|
|
1730
|
+
bucket: match[3],
|
|
1731
|
+
version: match[4],
|
|
1732
|
+
validationHash: match[5],
|
|
1733
|
+
fileHash: match[6],
|
|
1734
|
+
filePath: match[7]
|
|
1735
|
+
};
|
|
1736
|
+
}
|
|
1737
|
+
|
|
1738
|
+
/** What must stay in frame when a page crops an image. */
|
|
1739
|
+
|
|
1740
|
+
/**
|
|
1741
|
+
* The authored fields of a gallery-backed image (`s.image(galleryModule)`):
|
|
1742
|
+
* `width`/`height`/`mimeType` live in the gallery, so they are not repeated
|
|
1743
|
+
* here. One place per fact.
|
|
1744
|
+
*/
|
|
1745
|
+
|
|
1746
|
+
/**
|
|
1747
|
+
* The structural supertype of every media source.
|
|
1748
|
+
*
|
|
1749
|
+
* It is a named member of the `Source` / `SelectorSource` unions rather than
|
|
1750
|
+
* "just an object" because `SourceObject` is `{[key: string]: Source}` and
|
|
1751
|
+
* `Source` excludes `undefined` — an object with optional properties does not
|
|
1752
|
+
* satisfy it.
|
|
1753
|
+
*/
|
|
1754
|
+
|
|
1755
|
+
/** A path is remote unless it is under `/public`. */
|
|
1756
|
+
function isRemoteMediaPath(path) {
|
|
1757
|
+
return !path.startsWith("/public");
|
|
1758
|
+
}
|
|
1759
|
+
|
|
1760
|
+
/**
|
|
1761
|
+
* Where the bytes of a media source are actually served from.
|
|
1762
|
+
*
|
|
1763
|
+
* Two states, and conflating them is the recurring bug: uncommitted bytes live
|
|
1764
|
+
* in the patch directory and are served by the API with the `patch_id` that put
|
|
1765
|
+
* them there; committed bytes live at the path itself, with `/public` stripped.
|
|
1766
|
+
*/
|
|
1767
|
+
function mediaUrl(src) {
|
|
1768
|
+
var path = src.path;
|
|
1769
|
+
// TODO: /public should be configurable
|
|
1770
|
+
if (!isRemoteMediaPath(path)) {
|
|
1771
|
+
if (src.patch_id) {
|
|
1772
|
+
return "/api/val/files".concat(path, "?patch_id=").concat(src.patch_id);
|
|
1773
|
+
}
|
|
1774
|
+
return path.slice("/public".length);
|
|
1775
|
+
}
|
|
1776
|
+
if (src.patch_id) {
|
|
1777
|
+
var splitRemoteRefRes = splitRemoteRef(path);
|
|
1778
|
+
if (splitRemoteRefRes.status === "success") {
|
|
1779
|
+
return "/api/val/files/".concat(splitRemoteRefRes.filePath, "?patch_id=").concat(src.patch_id, "&remote=true&ref=").concat(encodeURIComponent(path));
|
|
1780
|
+
}
|
|
1781
|
+
// Not a remote ref either — an absolute path outside /public. Serve it as
|
|
1782
|
+
// written, but keep the patch id so a draft still resolves.
|
|
1783
|
+
return "".concat(path, "?patch_id=").concat(src.patch_id);
|
|
1784
|
+
}
|
|
1785
|
+
return path;
|
|
1786
|
+
}
|
|
1787
|
+
|
|
1788
|
+
/**
|
|
1789
|
+
* A media source plus the URL its bytes are served from.
|
|
1790
|
+
*
|
|
1791
|
+
* `url` is the only generated field: everything else the consumer sees was
|
|
1792
|
+
* either authored or filled in from the gallery.
|
|
1793
|
+
*/
|
|
1794
|
+
function resolveMedia(src) {
|
|
1795
|
+
return _objectSpread2(_objectSpread2({}, src), {}, {
|
|
1796
|
+
url: mediaUrl(src)
|
|
1797
|
+
});
|
|
1798
|
+
}
|
|
1799
|
+
function isMediaSchema(schema) {
|
|
1800
|
+
return _typeof(schema) === "object" && schema !== null && "type" in schema && (schema.type === "image" || schema.type === "file");
|
|
1801
|
+
}
|
|
1802
|
+
|
|
1803
|
+
/**
|
|
1804
|
+
* Fill in what a gallery-backed field does not carry itself.
|
|
1805
|
+
*
|
|
1806
|
+
* `s.image(galleryModule)` stores only `{path, alt?, hotspot?}` — the
|
|
1807
|
+
* dimensions and mime type live in the gallery module, keyed by path. This is
|
|
1808
|
+
* the single implementation of that lookup; core, stega/RSC and the Studio all
|
|
1809
|
+
* call it rather than each rolling their own.
|
|
1810
|
+
*
|
|
1811
|
+
* `alt` is filled in too, because a gallery holds the alt text an editor typed
|
|
1812
|
+
* once for a file used in several places — but only when the field does not
|
|
1813
|
+
* have its own, so a per-image override wins. A gallery whose `alt` schema is a
|
|
1814
|
+
* locale record holds an object rather than a string; that is left alone rather
|
|
1815
|
+
* than copied into a field typed `string`, and making the override
|
|
1816
|
+
* locale-shaped is a separate change.
|
|
1817
|
+
*
|
|
1818
|
+
* The double lookup is load-bearing: a remote gallery keys its entries by the
|
|
1819
|
+
* remote URL while the file itself stays on disk under its local path.
|
|
1820
|
+
*/
|
|
1821
|
+
function fillFromGallery(src, schema, getModuleSource) {
|
|
1822
|
+
if (!isMediaSchema(schema) || !schema.referencedModule) {
|
|
1823
|
+
return src;
|
|
1824
|
+
}
|
|
1825
|
+
var moduleSource = getModuleSource(schema.referencedModule);
|
|
1826
|
+
if (!moduleSource || _typeof(moduleSource) !== "object" || Array.isArray(moduleSource)) {
|
|
1827
|
+
return src;
|
|
1828
|
+
}
|
|
1829
|
+
var entries = moduleSource;
|
|
1830
|
+
var key = src.path in entries ? src.path : null;
|
|
1831
|
+
if (key === null) {
|
|
1832
|
+
var splitRemoteRefRes = splitRemoteRef(src.path);
|
|
1833
|
+
if (splitRemoteRefRes.status === "success" && splitRemoteRefRes.filePath in entries) {
|
|
1834
|
+
key = splitRemoteRefRes.filePath;
|
|
1835
|
+
}
|
|
1836
|
+
}
|
|
1837
|
+
if (key === null) {
|
|
1838
|
+
return src;
|
|
1839
|
+
}
|
|
1840
|
+
var entry = entries[key];
|
|
1841
|
+
if (!entry || _typeof(entry) !== "object" || Array.isArray(entry)) {
|
|
1842
|
+
return src;
|
|
1843
|
+
}
|
|
1844
|
+
var _ref = entry,
|
|
1845
|
+
width = _ref.width,
|
|
1846
|
+
height = _ref.height,
|
|
1847
|
+
mimeType = _ref.mimeType,
|
|
1848
|
+
alt = _ref.alt;
|
|
1849
|
+
var hasOwnAlt = typeof src.alt === "string";
|
|
1850
|
+
return _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({}, src), width !== undefined ? {
|
|
1851
|
+
width: width
|
|
1852
|
+
} : {}), height !== undefined ? {
|
|
1853
|
+
height: height
|
|
1854
|
+
} : {}), mimeType !== undefined ? {
|
|
1855
|
+
mimeType: mimeType
|
|
1856
|
+
} : {}), !hasOwnAlt && typeof alt === "string" ? {
|
|
1857
|
+
alt: alt
|
|
1858
|
+
} : {});
|
|
1859
|
+
}
|
|
1860
|
+
|
|
2033
1861
|
var ImageSchema = /*#__PURE__*/function (_Schema) {
|
|
2034
1862
|
function ImageSchema(options) {
|
|
2035
1863
|
var _this;
|
|
@@ -2071,7 +1899,7 @@ var ImageSchema = /*#__PURE__*/function (_Schema) {
|
|
|
2071
1899
|
}, {
|
|
2072
1900
|
key: "executeValidate",
|
|
2073
1901
|
value: function executeValidate(path, src) {
|
|
2074
|
-
var _src$
|
|
1902
|
+
var _src$mimeType;
|
|
2075
1903
|
var customValidationErrors = this.executeCustomValidateFunctions(src, this.customValidateFunctions, {
|
|
2076
1904
|
path: path
|
|
2077
1905
|
});
|
|
@@ -2084,42 +1912,68 @@ var ImageSchema = /*#__PURE__*/function (_Schema) {
|
|
|
2084
1912
|
value: src
|
|
2085
1913
|
}]));
|
|
2086
1914
|
}
|
|
2087
|
-
if (
|
|
1915
|
+
if (typeof src.path !== "string") {
|
|
1916
|
+
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
1917
|
+
message: "Image did not have a path string. Got: ".concat(_typeof(src.path)),
|
|
1918
|
+
value: src
|
|
1919
|
+
}]));
|
|
1920
|
+
}
|
|
1921
|
+
// Remote-ness is a property of the path, not of a marker on the value:
|
|
1922
|
+
// anything outside /public is remote.
|
|
1923
|
+
var isRemotePath = isRemoteMediaPath(src.path);
|
|
1924
|
+
if (this.isRemote && !isRemotePath) {
|
|
2088
1925
|
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
2089
1926
|
message: "Expected a remote image, but got a local image.",
|
|
2090
1927
|
value: src,
|
|
2091
1928
|
fixes: ["image:upload-remote"]
|
|
2092
1929
|
}]));
|
|
2093
1930
|
}
|
|
2094
|
-
if (this.isRemote &&
|
|
1931
|
+
if (this.isRemote && isRemotePath) {
|
|
2095
1932
|
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
2096
1933
|
message: "Remote image was not checked.",
|
|
2097
1934
|
value: src,
|
|
2098
1935
|
fixes: ["image:check-remote"]
|
|
2099
1936
|
}]));
|
|
2100
1937
|
}
|
|
2101
|
-
if (!this.isRemote &&
|
|
1938
|
+
if (!this.isRemote && isRemotePath) {
|
|
2102
1939
|
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
2103
|
-
message: "Expected
|
|
1940
|
+
message: "Expected local image, but found remote.",
|
|
2104
1941
|
value: src,
|
|
2105
1942
|
fixes: ["image:download-remote"]
|
|
2106
1943
|
}]));
|
|
2107
1944
|
}
|
|
2108
|
-
if (
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
1945
|
+
if (src.hotspot !== undefined) {
|
|
1946
|
+
if (_typeof(src.hotspot) !== "object" || src.hotspot === null || typeof src.hotspot.x !== "number" || typeof src.hotspot.y !== "number") {
|
|
1947
|
+
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
1948
|
+
message: "Hotspot must be an object with x and y as numbers.",
|
|
1949
|
+
value: src
|
|
1950
|
+
}]));
|
|
1951
|
+
}
|
|
2113
1952
|
}
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
1953
|
+
var galleryEntries = this.galleryEntries();
|
|
1954
|
+
if (galleryEntries) {
|
|
1955
|
+
// The dimensions and mime type of a gallery image are stored once, in the
|
|
1956
|
+
// gallery. Repeating them on the field is how the two get to disagree.
|
|
1957
|
+
var repeated = ["width", "height", "mimeType"].filter(function (key) {
|
|
1958
|
+
return src[key] !== undefined;
|
|
1959
|
+
});
|
|
1960
|
+
if (repeated.length > 0) {
|
|
1961
|
+
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
1962
|
+
message: "An image from a gallery must not carry its own ".concat(repeated.join(", "), ": ").concat(repeated.length === 1 ? "it is" : "they are", " stored in the gallery module."),
|
|
1963
|
+
value: src
|
|
1964
|
+
}]));
|
|
1965
|
+
}
|
|
1966
|
+
if (!(src.path in galleryEntries)) {
|
|
1967
|
+
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
1968
|
+
message: "The gallery does not have an image at '".concat(src.path, "'."),
|
|
1969
|
+
value: src
|
|
1970
|
+
}]));
|
|
1971
|
+
}
|
|
1972
|
+
return customValidationErrors.length > 0 ? _defineProperty({}, path, customValidationErrors) : false;
|
|
2119
1973
|
}
|
|
2120
|
-
var
|
|
2121
|
-
accept =
|
|
2122
|
-
var mimeType = (_src$
|
|
1974
|
+
var _ref1 = this.options || {},
|
|
1975
|
+
accept = _ref1.accept;
|
|
1976
|
+
var mimeType = (_src$mimeType = src.mimeType) !== null && _src$mimeType !== void 0 ? _src$mimeType : "";
|
|
2123
1977
|
if (accept && mimeType && !mimeType.includes("/")) {
|
|
2124
1978
|
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
2125
1979
|
message: "Invalid mime type format. Got: '".concat(mimeType, "'"),
|
|
@@ -2149,10 +2003,10 @@ var ImageSchema = /*#__PURE__*/function (_Schema) {
|
|
|
2149
2003
|
}]));
|
|
2150
2004
|
}
|
|
2151
2005
|
}
|
|
2152
|
-
var fileMimeType = Internal.filenameToMimeType(src
|
|
2006
|
+
var fileMimeType = Internal.filenameToMimeType(src.path);
|
|
2153
2007
|
if (!fileMimeType) {
|
|
2154
2008
|
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
2155
|
-
message: "Could not determine mime type from file extension. Got: ".concat(src
|
|
2009
|
+
message: "Could not determine mime type from file extension. Got: ".concat(src.path),
|
|
2156
2010
|
value: src,
|
|
2157
2011
|
fixes: ["image:check-metadata"]
|
|
2158
2012
|
}]));
|
|
@@ -2164,35 +2018,37 @@ var ImageSchema = /*#__PURE__*/function (_Schema) {
|
|
|
2164
2018
|
fixes: ["image:check-metadata"]
|
|
2165
2019
|
}]));
|
|
2166
2020
|
}
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
value: src
|
|
2173
|
-
}]));
|
|
2174
|
-
}
|
|
2175
|
-
}
|
|
2021
|
+
|
|
2022
|
+
// Whether the dimensions match the bytes can only be answered by reading
|
|
2023
|
+
// the file, which this package deliberately cannot do — so it is always
|
|
2024
|
+
// handed on as a fix.
|
|
2025
|
+
if (src.width !== undefined || src.height !== undefined || src.mimeType !== undefined) {
|
|
2176
2026
|
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
2177
|
-
message: "Found metadata, but it could not be validated.
|
|
2178
|
-
// These validation errors will have to be picked up by logic outside of this package and revalidated. Reasons: 1) we have to read files to verify the metadata, which is handled differently in different runtimes (Browser, QuickJS, Node.js); 2) we want to keep this package dependency free.
|
|
2027
|
+
message: "Found image metadata, but it could not be validated. An image must have a width (positive number), a height (positive number) and a mime type.",
|
|
2179
2028
|
value: src,
|
|
2180
2029
|
fixes: ["image:check-metadata"]
|
|
2181
2030
|
}]));
|
|
2182
2031
|
}
|
|
2183
|
-
var isReferencedModule = Object.keys(this.moduleMetadata).length > 0;
|
|
2184
|
-
if (src.metadata === undefined && isReferencedModule) {
|
|
2185
|
-
if (customValidationErrors.length === 0) {
|
|
2186
|
-
return false;
|
|
2187
|
-
}
|
|
2188
|
-
return _defineProperty({}, path, _toConsumableArray(customValidationErrors));
|
|
2189
|
-
}
|
|
2190
2032
|
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
2191
2033
|
message: "Could not validate Image metadata.",
|
|
2192
2034
|
value: src,
|
|
2193
2035
|
fixes: ["image:add-metadata"]
|
|
2194
2036
|
}]));
|
|
2195
2037
|
}
|
|
2038
|
+
|
|
2039
|
+
/**
|
|
2040
|
+
* The entries of the gallery this field points at, or null when it is a
|
|
2041
|
+
* standalone field.
|
|
2042
|
+
*/
|
|
2043
|
+
}, {
|
|
2044
|
+
key: "galleryEntries",
|
|
2045
|
+
value: function galleryEntries() {
|
|
2046
|
+
var modulePaths = Object.keys(this.moduleMetadata);
|
|
2047
|
+
if (modulePaths.length === 0) {
|
|
2048
|
+
return null;
|
|
2049
|
+
}
|
|
2050
|
+
return this.moduleMetadata[modulePaths[0]];
|
|
2051
|
+
}
|
|
2196
2052
|
}, {
|
|
2197
2053
|
key: "executeAssert",
|
|
2198
2054
|
value: function executeAssert(path, src) {
|
|
@@ -2220,20 +2076,11 @@ var ImageSchema = /*#__PURE__*/function (_Schema) {
|
|
|
2220
2076
|
}])
|
|
2221
2077
|
};
|
|
2222
2078
|
}
|
|
2223
|
-
if (!(
|
|
2224
|
-
return {
|
|
2225
|
-
success: false,
|
|
2226
|
-
errors: _defineProperty({}, path, [{
|
|
2227
|
-
message: "Value of this schema must use: 'c.image' (error type: missing_ref_prop)",
|
|
2228
|
-
typeError: true
|
|
2229
|
-
}])
|
|
2230
|
-
};
|
|
2231
|
-
}
|
|
2232
|
-
if (!(VAL_EXTENSION in src && src[VAL_EXTENSION] === "file")) {
|
|
2079
|
+
if (!("path" in src) || typeof src.path !== "string") {
|
|
2233
2080
|
return {
|
|
2234
2081
|
success: false,
|
|
2235
2082
|
errors: _defineProperty({}, path, [{
|
|
2236
|
-
message: "
|
|
2083
|
+
message: "An image must be an object with a 'path' (error type: missing_path)",
|
|
2237
2084
|
typeError: true
|
|
2238
2085
|
}])
|
|
2239
2086
|
};
|
|
@@ -2289,7 +2136,15 @@ var ImageSchema = /*#__PURE__*/function (_Schema) {
|
|
|
2289
2136
|
}
|
|
2290
2137
|
}]);
|
|
2291
2138
|
}(Schema);
|
|
2292
|
-
|
|
2139
|
+
|
|
2140
|
+
/**
|
|
2141
|
+
* An image picked from a gallery. Its dimensions and mime type live in the
|
|
2142
|
+
* gallery, so the field carries only what a person typed.
|
|
2143
|
+
*/
|
|
2144
|
+
|
|
2145
|
+
/** An image of its own, carrying its own dimensions and mime type. */
|
|
2146
|
+
|
|
2147
|
+
function image(options) {
|
|
2293
2148
|
var isModule = !!options && !!Internal.getValPath(options);
|
|
2294
2149
|
if (isModule) {
|
|
2295
2150
|
var allModules = {};
|
|
@@ -2304,7 +2159,7 @@ var image = function image(options) {
|
|
|
2304
2159
|
return new ImageSchema({}, false, false, [], allModules);
|
|
2305
2160
|
}
|
|
2306
2161
|
return new ImageSchema(options);
|
|
2307
|
-
}
|
|
2162
|
+
}
|
|
2308
2163
|
|
|
2309
2164
|
var RouteSchema = /*#__PURE__*/function (_Schema) {
|
|
2310
2165
|
function RouteSchema(options) {
|
|
@@ -3177,6 +3032,20 @@ function _asyncToGenerator(n) {
|
|
|
3177
3032
|
};
|
|
3178
3033
|
}
|
|
3179
3034
|
|
|
3035
|
+
/* Branded extension types: file, remote, i18n */
|
|
3036
|
+
var VAL_EXTENSION = "_type";
|
|
3037
|
+
|
|
3038
|
+
/**
|
|
3039
|
+
* A phantom type parameter is one that doesn't show up at runtime, but is checked statically (and only) at compile time.
|
|
3040
|
+
*
|
|
3041
|
+
* An example where this is useful is remote types, where the type of the remote source is known at compile time,
|
|
3042
|
+
* but the value is not there before it is fetched.
|
|
3043
|
+
*
|
|
3044
|
+
* @example
|
|
3045
|
+
* type Example<T> = string & PhantomType<T>;
|
|
3046
|
+
*
|
|
3047
|
+
**/
|
|
3048
|
+
|
|
3180
3049
|
/**
|
|
3181
3050
|
* The string used as the `_type` discriminator of a {@link JsonSource}.
|
|
3182
3051
|
*/
|
|
@@ -3314,56 +3183,15 @@ function _resolveJsonValues() {
|
|
|
3314
3183
|
return _ref3.apply(this, arguments);
|
|
3315
3184
|
};
|
|
3316
3185
|
}()));
|
|
3317
|
-
case 6:
|
|
3318
|
-
entries = _context2.v;
|
|
3319
|
-
return _context2.a(2, Object.fromEntries(entries));
|
|
3320
|
-
case 7:
|
|
3321
|
-
return _context2.a(2, source);
|
|
3322
|
-
}
|
|
3323
|
-
}, _callee2);
|
|
3324
|
-
}));
|
|
3325
|
-
return _resolveJsonValues.apply(this, arguments);
|
|
3326
|
-
}
|
|
3327
|
-
|
|
3328
|
-
var RegEx = /^(https?:\/\/[^/]+)\/file\/p\/([^/]+)\/b\/([^/]+)\/v\/([^/]+)\/h\/([^/]+)\/f\/([^/]+)\/p\/(.+)$/;
|
|
3329
|
-
function splitRemoteRef(ref) {
|
|
3330
|
-
if (ref[0] === "/") {
|
|
3331
|
-
return {
|
|
3332
|
-
status: "error",
|
|
3333
|
-
error: "Not a remote ref: " + ref
|
|
3334
|
-
};
|
|
3335
|
-
}
|
|
3336
|
-
var match = ref.match(RegEx);
|
|
3337
|
-
if (!match) {
|
|
3338
|
-
return {
|
|
3339
|
-
status: "error",
|
|
3340
|
-
error: "Invalid remote ref: " + ref
|
|
3341
|
-
};
|
|
3342
|
-
}
|
|
3343
|
-
if (match[7].indexOf("public/") !== 0) {
|
|
3344
|
-
return {
|
|
3345
|
-
status: "error",
|
|
3346
|
-
error: "Invalid remote ref: " + ref
|
|
3347
|
-
};
|
|
3348
|
-
}
|
|
3349
|
-
if (match[7].split("/").some(function (segment) {
|
|
3350
|
-
return segment === "." || segment === "..";
|
|
3351
|
-
})) {
|
|
3352
|
-
return {
|
|
3353
|
-
status: "error",
|
|
3354
|
-
error: "Invalid remote ref: " + ref
|
|
3355
|
-
};
|
|
3356
|
-
}
|
|
3357
|
-
return {
|
|
3358
|
-
status: "success",
|
|
3359
|
-
remoteHost: match[1],
|
|
3360
|
-
projectId: match[2],
|
|
3361
|
-
bucket: match[3],
|
|
3362
|
-
version: match[4],
|
|
3363
|
-
validationHash: match[5],
|
|
3364
|
-
fileHash: match[6],
|
|
3365
|
-
filePath: match[7]
|
|
3366
|
-
};
|
|
3186
|
+
case 6:
|
|
3187
|
+
entries = _context2.v;
|
|
3188
|
+
return _context2.a(2, Object.fromEntries(entries));
|
|
3189
|
+
case 7:
|
|
3190
|
+
return _context2.a(2, source);
|
|
3191
|
+
}
|
|
3192
|
+
}, _callee2);
|
|
3193
|
+
}));
|
|
3194
|
+
return _resolveJsonValues.apply(this, arguments);
|
|
3367
3195
|
}
|
|
3368
3196
|
|
|
3369
3197
|
/**
|
|
@@ -4860,12 +4688,264 @@ var KeyOfSchema = /*#__PURE__*/function (_Schema) {
|
|
|
4860
4688
|
return _createClass(KeyOfSchema, [{
|
|
4861
4689
|
key: "describe",
|
|
4862
4690
|
value: function describe(description) {
|
|
4863
|
-
return new KeyOfSchema(this.schema, this.sourcePath, this.opt, this.customValidateFunctions, this.isReadonly, this.isHidden, description !== null && description !== void 0 ? description : undefined);
|
|
4691
|
+
return new KeyOfSchema(this.schema, this.sourcePath, this.opt, this.customValidateFunctions, this.isReadonly, this.isHidden, description !== null && description !== void 0 ? description : undefined);
|
|
4692
|
+
}
|
|
4693
|
+
}, {
|
|
4694
|
+
key: "validate",
|
|
4695
|
+
value: function validate(validationFunction) {
|
|
4696
|
+
return new KeyOfSchema(this.schema, this.sourcePath, this.opt, [].concat(_toConsumableArray(this.customValidateFunctions), [validationFunction]), this.isReadonly, this.isHidden, this.description);
|
|
4697
|
+
}
|
|
4698
|
+
}, {
|
|
4699
|
+
key: "executeValidate",
|
|
4700
|
+
value: function executeValidate(path, src) {
|
|
4701
|
+
var customValidationErrors = this.executeCustomValidateFunctions(src, this.customValidateFunctions, {
|
|
4702
|
+
path: path
|
|
4703
|
+
});
|
|
4704
|
+
if (this.opt && (src === null || src === undefined)) {
|
|
4705
|
+
return customValidationErrors.length > 0 ? _defineProperty({}, path, customValidationErrors) : false;
|
|
4706
|
+
}
|
|
4707
|
+
if (!this.schema) {
|
|
4708
|
+
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
4709
|
+
message: "Schema not found for module. keyOf must be used with a Val Module"
|
|
4710
|
+
}]));
|
|
4711
|
+
}
|
|
4712
|
+
var serializedSchema = this.schema;
|
|
4713
|
+
if (!(serializedSchema.type === "object" || serializedSchema.type === "record")) {
|
|
4714
|
+
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
4715
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4716
|
+
message: "Schema in keyOf must be an 'object' or 'record'. Found '".concat(serializedSchema.type || "unknown", "'")
|
|
4717
|
+
}]));
|
|
4718
|
+
}
|
|
4719
|
+
if (serializedSchema.opt && (src === null || src === undefined)) {
|
|
4720
|
+
return false;
|
|
4721
|
+
}
|
|
4722
|
+
if (serializedSchema.type === "record" && typeof src !== "string") {
|
|
4723
|
+
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
4724
|
+
message: "Type of value in keyof (record) must be 'string'"
|
|
4725
|
+
}]));
|
|
4726
|
+
}
|
|
4727
|
+
if (serializedSchema.type === "object") {
|
|
4728
|
+
var keys = serializedSchema.keys;
|
|
4729
|
+
if (!keys.includes(src)) {
|
|
4730
|
+
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
4731
|
+
message: "Value of keyOf (object) must be: ".concat(keys.join(", "), ". Found: ").concat(src)
|
|
4732
|
+
}]));
|
|
4733
|
+
}
|
|
4734
|
+
}
|
|
4735
|
+
if (serializedSchema.type === "record") {
|
|
4736
|
+
if (typeof src !== "string") {
|
|
4737
|
+
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
4738
|
+
message: "Value of keyOf (record) must be 'string'. Found: ".concat(_typeof(src))
|
|
4739
|
+
}]));
|
|
4740
|
+
}
|
|
4741
|
+
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
4742
|
+
fixes: ["keyof:check-keys"],
|
|
4743
|
+
message: "Did not validate keyOf (record). This error (keyof:check-keys) should typically be processed by Val internally. Seeing this error most likely means you have a Val version mismatch.",
|
|
4744
|
+
value: {
|
|
4745
|
+
key: src,
|
|
4746
|
+
sourcePath: this.sourcePath
|
|
4747
|
+
}
|
|
4748
|
+
}]));
|
|
4749
|
+
}
|
|
4750
|
+
if (customValidationErrors.length > 0) {
|
|
4751
|
+
return _defineProperty({}, path, customValidationErrors);
|
|
4752
|
+
}
|
|
4753
|
+
return false;
|
|
4754
|
+
}
|
|
4755
|
+
}, {
|
|
4756
|
+
key: "executeAssert",
|
|
4757
|
+
value: function executeAssert(path, src) {
|
|
4758
|
+
if (this.opt && src === null) {
|
|
4759
|
+
return {
|
|
4760
|
+
success: true,
|
|
4761
|
+
data: src
|
|
4762
|
+
};
|
|
4763
|
+
}
|
|
4764
|
+
if (src === null) {
|
|
4765
|
+
return {
|
|
4766
|
+
success: false,
|
|
4767
|
+
errors: _defineProperty({}, path, [{
|
|
4768
|
+
message: "Expected 'string', got 'null'",
|
|
4769
|
+
typeError: true
|
|
4770
|
+
}])
|
|
4771
|
+
};
|
|
4772
|
+
}
|
|
4773
|
+
var schema = this.schema;
|
|
4774
|
+
if (!schema) {
|
|
4775
|
+
return {
|
|
4776
|
+
success: false,
|
|
4777
|
+
errors: _defineProperty({}, path, [{
|
|
4778
|
+
message: "Neither key nor schema was found. keyOf is missing an argument.",
|
|
4779
|
+
typeError: true
|
|
4780
|
+
}])
|
|
4781
|
+
};
|
|
4782
|
+
}
|
|
4783
|
+
var serializedSchema = schema;
|
|
4784
|
+
if (!(serializedSchema.type === "object" || serializedSchema.type === "record")) {
|
|
4785
|
+
return {
|
|
4786
|
+
success: false,
|
|
4787
|
+
errors: _defineProperty({}, path, [{
|
|
4788
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4789
|
+
message: "Schema of first argument must be either: 'array', 'object' or 'record'. Found '".concat(serializedSchema.type || "unknown", "'"),
|
|
4790
|
+
typeError: true
|
|
4791
|
+
}])
|
|
4792
|
+
};
|
|
4793
|
+
}
|
|
4794
|
+
if (serializedSchema.type === "record" && typeof src !== "string") {
|
|
4795
|
+
return {
|
|
4796
|
+
success: false,
|
|
4797
|
+
errors: _defineProperty({}, path, [{
|
|
4798
|
+
message: "Value of keyOf (record) must be 'string', got '".concat(_typeof(src), "'"),
|
|
4799
|
+
typeError: true
|
|
4800
|
+
}])
|
|
4801
|
+
};
|
|
4802
|
+
}
|
|
4803
|
+
// We check actual value here, since TypeScript also does this. Literals are used in other types (unions),
|
|
4804
|
+
// and there it also makes sense to check the actual string values (i.e. that it is not just a string) since
|
|
4805
|
+
// missing one would lead to a runtime error. At least this is what we are thinking currently.
|
|
4806
|
+
if (serializedSchema.type === "object") {
|
|
4807
|
+
var keys = serializedSchema.keys;
|
|
4808
|
+
if (!keys.includes(src)) {
|
|
4809
|
+
return {
|
|
4810
|
+
success: false,
|
|
4811
|
+
errors: _defineProperty({}, path, [{
|
|
4812
|
+
message: "Value of keyOf (object) must be: ".concat(keys.join(", "), ". Found: ").concat(src),
|
|
4813
|
+
typeError: true
|
|
4814
|
+
}])
|
|
4815
|
+
};
|
|
4816
|
+
}
|
|
4817
|
+
}
|
|
4818
|
+
return {
|
|
4819
|
+
success: true,
|
|
4820
|
+
data: src
|
|
4821
|
+
};
|
|
4822
|
+
}
|
|
4823
|
+
}, {
|
|
4824
|
+
key: "nullable",
|
|
4825
|
+
value: function nullable() {
|
|
4826
|
+
return new KeyOfSchema(this.schema, this.sourcePath, true, [], this.isReadonly, this.isHidden, this.description);
|
|
4827
|
+
}
|
|
4828
|
+
}, {
|
|
4829
|
+
key: "readonly",
|
|
4830
|
+
value: function readonly() {
|
|
4831
|
+
return new KeyOfSchema(this.schema, this.sourcePath, this.opt, this.customValidateFunctions, true, this.isHidden, this.description);
|
|
4832
|
+
}
|
|
4833
|
+
}, {
|
|
4834
|
+
key: "hidden",
|
|
4835
|
+
value: function hidden() {
|
|
4836
|
+
return new KeyOfSchema(this.schema, this.sourcePath, this.opt, this.customValidateFunctions, this.isReadonly, true, this.description);
|
|
4837
|
+
}
|
|
4838
|
+
}, {
|
|
4839
|
+
key: "executeCustomValidateAt",
|
|
4840
|
+
value: function executeCustomValidateAt(path, src) {
|
|
4841
|
+
return this.executeCustomValidateFunctions(src, this.customValidateFunctions, {
|
|
4842
|
+
path: path
|
|
4843
|
+
});
|
|
4844
|
+
}
|
|
4845
|
+
}, {
|
|
4846
|
+
key: "executeSerialize",
|
|
4847
|
+
value: function executeSerialize() {
|
|
4848
|
+
var _this$customValidateF;
|
|
4849
|
+
var path = this.sourcePath;
|
|
4850
|
+
if (!path) {
|
|
4851
|
+
throw new Error("Cannot serialize keyOf schema with empty selector. TIP: keyOf must be used with a Val Module of record schema.");
|
|
4852
|
+
}
|
|
4853
|
+
var serializedSchema = this.schema;
|
|
4854
|
+
if (!serializedSchema) {
|
|
4855
|
+
throw new Error("Cannot serialize keyOf schema with empty selector.");
|
|
4856
|
+
}
|
|
4857
|
+
var values;
|
|
4858
|
+
switch (serializedSchema.type) {
|
|
4859
|
+
case "record":
|
|
4860
|
+
values = "string";
|
|
4861
|
+
break;
|
|
4862
|
+
case "object":
|
|
4863
|
+
values = serializedSchema.keys;
|
|
4864
|
+
break;
|
|
4865
|
+
default:
|
|
4866
|
+
throw new Error(// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4867
|
+
"Cannot serialize keyOf schema with selector of type '".concat(serializedSchema.type || "unknown", "'"));
|
|
4868
|
+
}
|
|
4869
|
+
return {
|
|
4870
|
+
type: "keyOf",
|
|
4871
|
+
path: path,
|
|
4872
|
+
schema: serializedSchema,
|
|
4873
|
+
opt: this.opt,
|
|
4874
|
+
values: values,
|
|
4875
|
+
customValidate: this.customValidateFunctions && ((_this$customValidateF = this.customValidateFunctions) === null || _this$customValidateF === void 0 ? void 0 : _this$customValidateF.length) > 0,
|
|
4876
|
+
readonly: this.isReadonly,
|
|
4877
|
+
hidden: this.isHidden,
|
|
4878
|
+
description: this.description
|
|
4879
|
+
};
|
|
4880
|
+
}
|
|
4881
|
+
}, {
|
|
4882
|
+
key: "executeRender",
|
|
4883
|
+
value: function executeRender() {
|
|
4884
|
+
return {};
|
|
4885
|
+
}
|
|
4886
|
+
}]);
|
|
4887
|
+
}(Schema);
|
|
4888
|
+
var keyOf = function keyOf(valModule) {
|
|
4889
|
+
var refSchema = valModule === null || valModule === void 0 ? void 0 : valModule[GetSchema];
|
|
4890
|
+
var serializedRefSchema = undefined;
|
|
4891
|
+
if (refSchema instanceof ObjectSchema) {
|
|
4892
|
+
var keys = [];
|
|
4893
|
+
try {
|
|
4894
|
+
keys = Object.keys((refSchema === null || refSchema === void 0 ? void 0 : refSchema["items"]) || {});
|
|
4895
|
+
} catch (e) {
|
|
4896
|
+
// ignore this error here
|
|
4897
|
+
}
|
|
4898
|
+
serializedRefSchema = {
|
|
4899
|
+
type: "object",
|
|
4900
|
+
keys: keys,
|
|
4901
|
+
opt: refSchema === null || refSchema === void 0 ? void 0 : refSchema["opt"]
|
|
4902
|
+
};
|
|
4903
|
+
} else if (refSchema instanceof RecordSchema) {
|
|
4904
|
+
serializedRefSchema = {
|
|
4905
|
+
type: "record",
|
|
4906
|
+
opt: refSchema === null || refSchema === void 0 ? void 0 : refSchema["opt"]
|
|
4907
|
+
};
|
|
4908
|
+
}
|
|
4909
|
+
return new KeyOfSchema(serializedRefSchema, getValPath(valModule));
|
|
4910
|
+
};
|
|
4911
|
+
|
|
4912
|
+
var FileSchema = /*#__PURE__*/function (_Schema) {
|
|
4913
|
+
function FileSchema(options) {
|
|
4914
|
+
var _this;
|
|
4915
|
+
var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
4916
|
+
var isRemote = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
4917
|
+
var customValidateFunctions = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
|
|
4918
|
+
var moduleMetadata = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
|
|
4919
|
+
var isReadonly = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
|
|
4920
|
+
var isHidden = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : false;
|
|
4921
|
+
var description = arguments.length > 7 ? arguments[7] : undefined;
|
|
4922
|
+
_classCallCheck(this, FileSchema);
|
|
4923
|
+
_this = _callSuper(this, FileSchema);
|
|
4924
|
+
_this.options = options;
|
|
4925
|
+
_this.opt = opt;
|
|
4926
|
+
_this.isRemote = isRemote;
|
|
4927
|
+
_this.customValidateFunctions = customValidateFunctions;
|
|
4928
|
+
_this.moduleMetadata = moduleMetadata;
|
|
4929
|
+
_this.isReadonly = isReadonly;
|
|
4930
|
+
_this.isHidden = isHidden;
|
|
4931
|
+
_this.description = description;
|
|
4932
|
+
return _this;
|
|
4933
|
+
}
|
|
4934
|
+
_inherits(FileSchema, _Schema);
|
|
4935
|
+
return _createClass(FileSchema, [{
|
|
4936
|
+
key: "describe",
|
|
4937
|
+
value: function describe(description) {
|
|
4938
|
+
return new FileSchema(this.options, this.opt, this.isRemote, this.customValidateFunctions, this.moduleMetadata, this.isReadonly, this.isHidden, description !== null && description !== void 0 ? description : undefined);
|
|
4939
|
+
}
|
|
4940
|
+
}, {
|
|
4941
|
+
key: "remote",
|
|
4942
|
+
value: function remote() {
|
|
4943
|
+
return new FileSchema(this.options, this.opt, true, this.customValidateFunctions, this.moduleMetadata, this.isReadonly, this.isHidden, this.description);
|
|
4864
4944
|
}
|
|
4865
4945
|
}, {
|
|
4866
4946
|
key: "validate",
|
|
4867
4947
|
value: function validate(validationFunction) {
|
|
4868
|
-
return new
|
|
4948
|
+
return new FileSchema(this.options, this.opt, this.isRemote, [].concat(_toConsumableArray(this.customValidateFunctions), [validationFunction]), this.moduleMetadata, this.isReadonly, this.isHidden, this.description);
|
|
4869
4949
|
}
|
|
4870
4950
|
}, {
|
|
4871
4951
|
key: "executeValidate",
|
|
@@ -4876,53 +4956,131 @@ var KeyOfSchema = /*#__PURE__*/function (_Schema) {
|
|
|
4876
4956
|
if (this.opt && (src === null || src === undefined)) {
|
|
4877
4957
|
return customValidationErrors.length > 0 ? _defineProperty({}, path, customValidationErrors) : false;
|
|
4878
4958
|
}
|
|
4879
|
-
if (
|
|
4959
|
+
if (src === null || src === undefined) {
|
|
4880
4960
|
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
4881
|
-
message: "
|
|
4961
|
+
message: "Non-optional file was null or undefined.",
|
|
4962
|
+
value: src
|
|
4882
4963
|
}]));
|
|
4883
4964
|
}
|
|
4884
|
-
|
|
4885
|
-
if (!(serializedSchema.type === "object" || serializedSchema.type === "record")) {
|
|
4965
|
+
if (typeof src.path !== "string") {
|
|
4886
4966
|
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
4887
|
-
|
|
4888
|
-
|
|
4967
|
+
message: "File did not have a path string. Got: ".concat(_typeof(src.path)),
|
|
4968
|
+
value: src
|
|
4889
4969
|
}]));
|
|
4890
4970
|
}
|
|
4891
|
-
|
|
4892
|
-
|
|
4971
|
+
// Remote-ness is a property of the path, not of a marker on the value:
|
|
4972
|
+
// anything outside /public is remote.
|
|
4973
|
+
var isRemotePath = isRemoteMediaPath(src.path);
|
|
4974
|
+
if (this.isRemote && !isRemotePath) {
|
|
4975
|
+
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
4976
|
+
message: "Expected a remote file, but got a local file.",
|
|
4977
|
+
value: src,
|
|
4978
|
+
fixes: ["file:upload-remote"]
|
|
4979
|
+
}]));
|
|
4893
4980
|
}
|
|
4894
|
-
if (
|
|
4981
|
+
if (this.isRemote && isRemotePath) {
|
|
4895
4982
|
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
4896
|
-
message: "
|
|
4983
|
+
message: "Remote file was not checked.",
|
|
4984
|
+
value: src,
|
|
4985
|
+
fixes: ["file:check-remote"]
|
|
4897
4986
|
}]));
|
|
4898
4987
|
}
|
|
4899
|
-
if (
|
|
4900
|
-
|
|
4901
|
-
|
|
4988
|
+
if (!this.isRemote && isRemotePath) {
|
|
4989
|
+
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
4990
|
+
message: "Expected local file, but found remote.",
|
|
4991
|
+
value: src,
|
|
4992
|
+
fixes: ["file:download-remote"]
|
|
4993
|
+
}]));
|
|
4994
|
+
}
|
|
4995
|
+
var galleryEntries = this.galleryEntries();
|
|
4996
|
+
if (galleryEntries) {
|
|
4997
|
+
if (src.mimeType !== undefined) {
|
|
4902
4998
|
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
4903
|
-
message: "
|
|
4999
|
+
message: "A file from a gallery must not carry its own mimeType: it is stored in the gallery module.",
|
|
5000
|
+
value: src
|
|
4904
5001
|
}]));
|
|
4905
5002
|
}
|
|
4906
|
-
|
|
4907
|
-
if (serializedSchema.type === "record") {
|
|
4908
|
-
if (typeof src !== "string") {
|
|
5003
|
+
if (!(src.path in galleryEntries)) {
|
|
4909
5004
|
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
4910
|
-
message: "
|
|
5005
|
+
message: "The gallery does not have a file at '".concat(src.path, "'."),
|
|
5006
|
+
value: src
|
|
4911
5007
|
}]));
|
|
4912
5008
|
}
|
|
5009
|
+
return customValidationErrors.length > 0 ? _defineProperty({}, path, customValidationErrors) : false;
|
|
5010
|
+
}
|
|
5011
|
+
var _ref0 = this.options || {},
|
|
5012
|
+
accept = _ref0.accept;
|
|
5013
|
+
var mimeType = src.mimeType;
|
|
5014
|
+
if (accept && mimeType && !mimeType.includes("/")) {
|
|
4913
5015
|
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
4914
|
-
|
|
4915
|
-
|
|
4916
|
-
|
|
4917
|
-
|
|
4918
|
-
|
|
5016
|
+
message: "Invalid mime type format. Got: ".concat(mimeType),
|
|
5017
|
+
value: src
|
|
5018
|
+
}]));
|
|
5019
|
+
}
|
|
5020
|
+
if (accept && mimeType && mimeType.includes("/")) {
|
|
5021
|
+
var acceptedTypes = accept.split(",").map(function (type) {
|
|
5022
|
+
return type.trim();
|
|
5023
|
+
});
|
|
5024
|
+
var isValidMimeType = acceptedTypes.some(function (acceptedType) {
|
|
5025
|
+
if (acceptedType === "*/*") {
|
|
5026
|
+
return true;
|
|
5027
|
+
}
|
|
5028
|
+
if (acceptedType.endsWith("/*")) {
|
|
5029
|
+
var baseType = acceptedType.slice(0, -2);
|
|
5030
|
+
return mimeType.startsWith(baseType);
|
|
4919
5031
|
}
|
|
5032
|
+
return acceptedType === mimeType;
|
|
5033
|
+
});
|
|
5034
|
+
if (!isValidMimeType) {
|
|
5035
|
+
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
5036
|
+
message: "Mime type mismatch. Found '".concat(mimeType, "' but schema accepts '").concat(accept, "'"),
|
|
5037
|
+
value: src
|
|
5038
|
+
}]));
|
|
5039
|
+
}
|
|
5040
|
+
}
|
|
5041
|
+
var fileMimeType = Internal.filenameToMimeType(src.path);
|
|
5042
|
+
if (!fileMimeType) {
|
|
5043
|
+
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
5044
|
+
message: "Could not determine mime type from file extension. Got: ".concat(src.path),
|
|
5045
|
+
value: src
|
|
4920
5046
|
}]));
|
|
4921
5047
|
}
|
|
4922
|
-
if (
|
|
4923
|
-
return _defineProperty({}, path, customValidationErrors)
|
|
5048
|
+
if (fileMimeType !== mimeType) {
|
|
5049
|
+
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
5050
|
+
message: "Mime type and file extension not matching. Mime type is '".concat(mimeType, "' but file extension is '").concat(fileMimeType, "'"),
|
|
5051
|
+
value: src
|
|
5052
|
+
}]));
|
|
4924
5053
|
}
|
|
4925
|
-
|
|
5054
|
+
|
|
5055
|
+
// The mime type read so far came from the filename. Whether it matches the
|
|
5056
|
+
// bytes can only be answered by reading the file, which this package
|
|
5057
|
+
// deliberately cannot do — so it is always handed on as a fix.
|
|
5058
|
+
if (mimeType !== undefined) {
|
|
5059
|
+
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
5060
|
+
message: "Found mimeType, but it could not be validated.",
|
|
5061
|
+
value: src,
|
|
5062
|
+
fixes: ["file:check-metadata"]
|
|
5063
|
+
}]));
|
|
5064
|
+
}
|
|
5065
|
+
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
5066
|
+
message: "Missing File mimeType.",
|
|
5067
|
+
value: src,
|
|
5068
|
+
fixes: ["file:add-metadata"]
|
|
5069
|
+
}]));
|
|
5070
|
+
}
|
|
5071
|
+
|
|
5072
|
+
/**
|
|
5073
|
+
* The entries of the gallery this field points at, or null when it is a
|
|
5074
|
+
* standalone field.
|
|
5075
|
+
*/
|
|
5076
|
+
}, {
|
|
5077
|
+
key: "galleryEntries",
|
|
5078
|
+
value: function galleryEntries() {
|
|
5079
|
+
var modulePaths = Object.keys(this.moduleMetadata);
|
|
5080
|
+
if (modulePaths.length === 0) {
|
|
5081
|
+
return null;
|
|
5082
|
+
}
|
|
5083
|
+
return this.moduleMetadata[modulePaths[0]];
|
|
4926
5084
|
}
|
|
4927
5085
|
}, {
|
|
4928
5086
|
key: "executeAssert",
|
|
@@ -4937,56 +5095,29 @@ var KeyOfSchema = /*#__PURE__*/function (_Schema) {
|
|
|
4937
5095
|
return {
|
|
4938
5096
|
success: false,
|
|
4939
5097
|
errors: _defineProperty({}, path, [{
|
|
4940
|
-
message: "Expected '
|
|
4941
|
-
typeError: true
|
|
4942
|
-
}])
|
|
4943
|
-
};
|
|
4944
|
-
}
|
|
4945
|
-
var schema = this.schema;
|
|
4946
|
-
if (!schema) {
|
|
4947
|
-
return {
|
|
4948
|
-
success: false,
|
|
4949
|
-
errors: _defineProperty({}, path, [{
|
|
4950
|
-
message: "Neither key nor schema was found. keyOf is missing an argument.",
|
|
5098
|
+
message: "Expected 'object', got 'null'",
|
|
4951
5099
|
typeError: true
|
|
4952
5100
|
}])
|
|
4953
5101
|
};
|
|
4954
5102
|
}
|
|
4955
|
-
|
|
4956
|
-
if (!(serializedSchema.type === "object" || serializedSchema.type === "record")) {
|
|
5103
|
+
if (_typeof(src) !== "object") {
|
|
4957
5104
|
return {
|
|
4958
5105
|
success: false,
|
|
4959
5106
|
errors: _defineProperty({}, path, [{
|
|
4960
|
-
|
|
4961
|
-
message: "Schema of first argument must be either: 'array', 'object' or 'record'. Found '".concat(serializedSchema.type || "unknown", "'"),
|
|
5107
|
+
message: "Expected object, got '".concat(_typeof(src), "'"),
|
|
4962
5108
|
typeError: true
|
|
4963
5109
|
}])
|
|
4964
5110
|
};
|
|
4965
5111
|
}
|
|
4966
|
-
if (
|
|
5112
|
+
if (!("path" in src) || typeof src.path !== "string") {
|
|
4967
5113
|
return {
|
|
4968
5114
|
success: false,
|
|
4969
5115
|
errors: _defineProperty({}, path, [{
|
|
4970
|
-
message: "
|
|
5116
|
+
message: "A file must be an object with a 'path' (error type: missing_path)",
|
|
4971
5117
|
typeError: true
|
|
4972
5118
|
}])
|
|
4973
5119
|
};
|
|
4974
5120
|
}
|
|
4975
|
-
// We check actual value here, since TypeScript also does this. Literals are used in other types (unions),
|
|
4976
|
-
// and there it also makes sense to check the actual string values (i.e. that it is not just a string) since
|
|
4977
|
-
// missing one would lead to a runtime error. At least this is what we are thinking currently.
|
|
4978
|
-
if (serializedSchema.type === "object") {
|
|
4979
|
-
var keys = serializedSchema.keys;
|
|
4980
|
-
if (!keys.includes(src)) {
|
|
4981
|
-
return {
|
|
4982
|
-
success: false,
|
|
4983
|
-
errors: _defineProperty({}, path, [{
|
|
4984
|
-
message: "Value of keyOf (object) must be: ".concat(keys.join(", "), ". Found: ").concat(src),
|
|
4985
|
-
typeError: true
|
|
4986
|
-
}])
|
|
4987
|
-
};
|
|
4988
|
-
}
|
|
4989
|
-
}
|
|
4990
5121
|
return {
|
|
4991
5122
|
success: true,
|
|
4992
5123
|
data: src
|
|
@@ -4995,17 +5126,17 @@ var KeyOfSchema = /*#__PURE__*/function (_Schema) {
|
|
|
4995
5126
|
}, {
|
|
4996
5127
|
key: "nullable",
|
|
4997
5128
|
value: function nullable() {
|
|
4998
|
-
return new
|
|
5129
|
+
return new FileSchema(this.options, true, this.isRemote, this.customValidateFunctions, this.moduleMetadata, this.isReadonly, this.isHidden, this.description);
|
|
4999
5130
|
}
|
|
5000
5131
|
}, {
|
|
5001
5132
|
key: "readonly",
|
|
5002
5133
|
value: function readonly() {
|
|
5003
|
-
return new
|
|
5134
|
+
return new FileSchema(this.options, this.opt, this.isRemote, this.customValidateFunctions, this.moduleMetadata, true, this.isHidden, this.description);
|
|
5004
5135
|
}
|
|
5005
5136
|
}, {
|
|
5006
5137
|
key: "hidden",
|
|
5007
5138
|
value: function hidden() {
|
|
5008
|
-
return new
|
|
5139
|
+
return new FileSchema(this.options, this.opt, this.isRemote, this.customValidateFunctions, this.moduleMetadata, this.isReadonly, true, this.description);
|
|
5009
5140
|
}
|
|
5010
5141
|
}, {
|
|
5011
5142
|
key: "executeCustomValidateAt",
|
|
@@ -5018,33 +5149,14 @@ var KeyOfSchema = /*#__PURE__*/function (_Schema) {
|
|
|
5018
5149
|
key: "executeSerialize",
|
|
5019
5150
|
value: function executeSerialize() {
|
|
5020
5151
|
var _this$customValidateF;
|
|
5021
|
-
var
|
|
5022
|
-
if (!path) {
|
|
5023
|
-
throw new Error("Cannot serialize keyOf schema with empty selector. TIP: keyOf must be used with a Val Module of record schema.");
|
|
5024
|
-
}
|
|
5025
|
-
var serializedSchema = this.schema;
|
|
5026
|
-
if (!serializedSchema) {
|
|
5027
|
-
throw new Error("Cannot serialize keyOf schema with empty selector.");
|
|
5028
|
-
}
|
|
5029
|
-
var values;
|
|
5030
|
-
switch (serializedSchema.type) {
|
|
5031
|
-
case "record":
|
|
5032
|
-
values = "string";
|
|
5033
|
-
break;
|
|
5034
|
-
case "object":
|
|
5035
|
-
values = serializedSchema.keys;
|
|
5036
|
-
break;
|
|
5037
|
-
default:
|
|
5038
|
-
throw new Error(// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
5039
|
-
"Cannot serialize keyOf schema with selector of type '".concat(serializedSchema.type || "unknown", "'"));
|
|
5040
|
-
}
|
|
5152
|
+
var modulePaths = this.moduleMetadata ? Object.keys(this.moduleMetadata) : [];
|
|
5041
5153
|
return {
|
|
5042
|
-
type: "
|
|
5043
|
-
|
|
5044
|
-
schema: serializedSchema,
|
|
5154
|
+
type: "file",
|
|
5155
|
+
options: this.options,
|
|
5045
5156
|
opt: this.opt,
|
|
5046
|
-
|
|
5157
|
+
remote: this.isRemote,
|
|
5047
5158
|
customValidate: this.customValidateFunctions && ((_this$customValidateF = this.customValidateFunctions) === null || _this$customValidateF === void 0 ? void 0 : _this$customValidateF.length) > 0,
|
|
5159
|
+
referencedModule: modulePaths.length > 0 ? modulePaths[0] : undefined,
|
|
5048
5160
|
readonly: this.isReadonly,
|
|
5049
5161
|
hidden: this.isHidden,
|
|
5050
5162
|
description: this.description
|
|
@@ -5057,29 +5169,30 @@ var KeyOfSchema = /*#__PURE__*/function (_Schema) {
|
|
|
5057
5169
|
}
|
|
5058
5170
|
}]);
|
|
5059
5171
|
}(Schema);
|
|
5060
|
-
|
|
5061
|
-
|
|
5062
|
-
|
|
5063
|
-
|
|
5064
|
-
|
|
5065
|
-
|
|
5066
|
-
|
|
5067
|
-
|
|
5068
|
-
|
|
5172
|
+
|
|
5173
|
+
/**
|
|
5174
|
+
* A file picked from a gallery. Its mime type lives in the gallery, so the
|
|
5175
|
+
* field carries only the path.
|
|
5176
|
+
*/
|
|
5177
|
+
|
|
5178
|
+
/** A file of its own, carrying its own mime type. */
|
|
5179
|
+
|
|
5180
|
+
function file(options) {
|
|
5181
|
+
var isModule = !!options && !!Internal.getValPath(options);
|
|
5182
|
+
if (isModule) {
|
|
5183
|
+
var allModules = {};
|
|
5184
|
+
for (var _i = 0, _arr = [options]; _i < _arr.length; _i++) {
|
|
5185
|
+
var valModule = _arr[_i];
|
|
5186
|
+
var modulePath = getValPath(valModule);
|
|
5187
|
+
if (modulePath === undefined) {
|
|
5188
|
+
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.");
|
|
5189
|
+
}
|
|
5190
|
+
allModules[modulePath] = getSource(valModule);
|
|
5069
5191
|
}
|
|
5070
|
-
|
|
5071
|
-
type: "object",
|
|
5072
|
-
keys: keys,
|
|
5073
|
-
opt: refSchema === null || refSchema === void 0 ? void 0 : refSchema["opt"]
|
|
5074
|
-
};
|
|
5075
|
-
} else if (refSchema instanceof RecordSchema) {
|
|
5076
|
-
serializedRefSchema = {
|
|
5077
|
-
type: "record",
|
|
5078
|
-
opt: refSchema === null || refSchema === void 0 ? void 0 : refSchema["opt"]
|
|
5079
|
-
};
|
|
5192
|
+
return new FileSchema({}, false, false, [], allModules);
|
|
5080
5193
|
}
|
|
5081
|
-
return new
|
|
5082
|
-
}
|
|
5194
|
+
return new FileSchema(options);
|
|
5195
|
+
}
|
|
5083
5196
|
|
|
5084
5197
|
/**
|
|
5085
5198
|
* Options for s.files()
|
|
@@ -6234,88 +6347,6 @@ function initSchema() {
|
|
|
6234
6347
|
};
|
|
6235
6348
|
}
|
|
6236
6349
|
|
|
6237
|
-
/**
|
|
6238
|
-
* A image source represents the path to a (local) image.
|
|
6239
|
-
*
|
|
6240
|
-
*/
|
|
6241
|
-
|
|
6242
|
-
var initImage = function initImage(config) {
|
|
6243
|
-
var _config$files$directo, _config$files;
|
|
6244
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
6245
|
-
(_config$files$directo = config === null || config === void 0 || (_config$files = config.files) === null || _config$files === void 0 ? void 0 : _config$files.directory) !== null && _config$files$directo !== void 0 ? _config$files$directo : "/public/val";
|
|
6246
|
-
|
|
6247
|
-
/**
|
|
6248
|
-
* Define the source of an image file.
|
|
6249
|
-
*
|
|
6250
|
-
* @example
|
|
6251
|
-
* c.image("/public/val/example.png", {
|
|
6252
|
-
* width: 944,
|
|
6253
|
-
* height: 944,
|
|
6254
|
-
* mimeType: "image/png",
|
|
6255
|
-
*})
|
|
6256
|
-
*
|
|
6257
|
-
* @param ref /public/val/example.png
|
|
6258
|
-
* @param metadata Image metadata: width, height, mimeType and optionally a hotspot.
|
|
6259
|
-
*/
|
|
6260
|
-
|
|
6261
|
-
/**
|
|
6262
|
-
* Define the source of an image file.
|
|
6263
|
-
*
|
|
6264
|
-
* NOTE: this will **not** validate since metadata has not been defined.
|
|
6265
|
-
*
|
|
6266
|
-
* Run `npx -p @valbuild/cli val validate --fix` to automatically add metadata.
|
|
6267
|
-
*
|
|
6268
|
-
* @example
|
|
6269
|
-
* c.image("/public/val/example.png")
|
|
6270
|
-
*
|
|
6271
|
-
* @param ref /public/val/example.png
|
|
6272
|
-
* @param metadata Image metadata: width, height, mimeType and optionally a hotspot.
|
|
6273
|
-
*/
|
|
6274
|
-
|
|
6275
|
-
/**
|
|
6276
|
-
* Define the source of an image file.
|
|
6277
|
-
*
|
|
6278
|
-
* @example
|
|
6279
|
-
* c.image("/public/val/example.png", {
|
|
6280
|
-
* width: 944,
|
|
6281
|
-
* height: 944,
|
|
6282
|
-
* mimeType: "image/png",
|
|
6283
|
-
*})
|
|
6284
|
-
*
|
|
6285
|
-
* @param ref /public/val/example.png
|
|
6286
|
-
* @param metadata Image metadata: width, height, mimeType and optionally a hotspot.
|
|
6287
|
-
*/
|
|
6288
|
-
function image(ref, metadata) {
|
|
6289
|
-
return _defineProperty(_defineProperty(_defineProperty(_defineProperty({}, FILE_REF_PROP, ref), VAL_EXTENSION, "file"), FILE_REF_SUBTYPE_TAG, "image"), "metadata", metadata);
|
|
6290
|
-
}
|
|
6291
|
-
return image;
|
|
6292
|
-
};
|
|
6293
|
-
|
|
6294
|
-
/**
|
|
6295
|
-
* A remote source represents data that is not stored locally.
|
|
6296
|
-
*/
|
|
6297
|
-
|
|
6298
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
6299
|
-
var initRemote = function initRemote(config) {
|
|
6300
|
-
function remote(ref, metadata) {
|
|
6301
|
-
return _defineProperty(_defineProperty(_defineProperty({}, FILE_REF_PROP, ref), VAL_EXTENSION, "remote"), "metadata", metadata);
|
|
6302
|
-
}
|
|
6303
|
-
return remote;
|
|
6304
|
-
};
|
|
6305
|
-
|
|
6306
|
-
// NOTE: the segments must match the ref built by createRemoteRef below and the RegEx in splitRemoteRef.
|
|
6307
|
-
|
|
6308
|
-
function createRemoteRef(remoteHost, _ref2) {
|
|
6309
|
-
var publicProjectId = _ref2.publicProjectId,
|
|
6310
|
-
coreVersion = _ref2.coreVersion,
|
|
6311
|
-
validationHash = _ref2.validationHash,
|
|
6312
|
-
fileHash = _ref2.fileHash,
|
|
6313
|
-
filePath = _ref2.filePath,
|
|
6314
|
-
bucket = _ref2.bucket;
|
|
6315
|
-
// NOTE: the core version is part of the validation hash, but it is also in the uri to make it easier to understand which version the remote file was validated against.
|
|
6316
|
-
return "".concat(remoteHost, "/file/p/").concat(publicProjectId, "/b/").concat(bucket, "/v/").concat(coreVersion, "/h/").concat(validationHash, "/f/").concat(fileHash, "/p/").concat(filePath);
|
|
6317
|
-
}
|
|
6318
|
-
|
|
6319
6350
|
// import { i18n, I18n } from "./source/future/i18n";
|
|
6320
6351
|
// import { remote } from "./source/future/remote";
|
|
6321
6352
|
|
|
@@ -6352,9 +6383,6 @@ var initVal = function initVal(config) {
|
|
|
6352
6383
|
},
|
|
6353
6384
|
c: {
|
|
6354
6385
|
define: define,
|
|
6355
|
-
remote: initRemote(),
|
|
6356
|
-
file: initFile(config),
|
|
6357
|
-
image: initImage(config),
|
|
6358
6386
|
json: json
|
|
6359
6387
|
},
|
|
6360
6388
|
s: s,
|
|
@@ -7071,23 +7099,6 @@ function hasRemoteFileSchema(schema) {
|
|
|
7071
7099
|
}
|
|
7072
7100
|
|
|
7073
7101
|
var DEFAULT_VAL_REMOTE_HOST = "https://remote.val.build";
|
|
7074
|
-
function convertRemoteSource(src) {
|
|
7075
|
-
if (src !== null && src !== void 0 && src.patch_id) {
|
|
7076
|
-
var splitRemoteRefDataRes = splitRemoteRef(src[FILE_REF_PROP]);
|
|
7077
|
-
if (splitRemoteRefDataRes.status === "success") {
|
|
7078
|
-
return {
|
|
7079
|
-
url: "/api/val/files/" + splitRemoteRefDataRes.filePath + "?patch_id=".concat(src["patch_id"], "&remote=true&ref=").concat(encodeURIComponent(src[FILE_REF_PROP])),
|
|
7080
|
-
metadata: src.metadata
|
|
7081
|
-
};
|
|
7082
|
-
} else {
|
|
7083
|
-
console.warn("Internal Val error: failed to split remote ref: ".concat(src[FILE_REF_PROP], ". The data format is different than what is expected. Check Val versions for mismatches."), splitRemoteRefDataRes.error);
|
|
7084
|
-
}
|
|
7085
|
-
}
|
|
7086
|
-
return {
|
|
7087
|
-
url: src[FILE_REF_PROP],
|
|
7088
|
-
metadata: src.metadata
|
|
7089
|
-
};
|
|
7090
|
-
}
|
|
7091
7102
|
|
|
7092
7103
|
var PatchError = /*#__PURE__*/_createClass(function PatchError(message) {
|
|
7093
7104
|
_classCallCheck(this, PatchError);
|
|
@@ -7157,14 +7168,15 @@ function derefPatch(patch, document, ops) {
|
|
|
7157
7168
|
var maybeValue = ops.get(document, dereffedPath);
|
|
7158
7169
|
if (isOk(maybeValue)) {
|
|
7159
7170
|
var value = maybeValue.value;
|
|
7160
|
-
|
|
7171
|
+
var mediaPath = mediaPathOf(value);
|
|
7172
|
+
if (mediaPath !== null) {
|
|
7161
7173
|
if (referencedPath.length > 0) {
|
|
7162
7174
|
return err(new PatchError("Cannot sub-reference file reference at path: ".concat(dereffedPath.join("/"))));
|
|
7163
7175
|
}
|
|
7164
7176
|
if (typeof op.value !== "string") {
|
|
7165
7177
|
return err(new PatchError("Expected base64 encoded string value for file reference, got ".concat(JSON.stringify(op.value))));
|
|
7166
7178
|
}
|
|
7167
|
-
fileUpdates[
|
|
7179
|
+
fileUpdates[mediaPath] = op.value;
|
|
7168
7180
|
// } else if (isRemote(value)) {
|
|
7169
7181
|
// if (!remotePatches[value[REMOTE_REF_PROP]]) {
|
|
7170
7182
|
// remotePatches[value[REMOTE_REF_PROP]] = [];
|
|
@@ -7215,6 +7227,21 @@ function derefPatch(patch, document, ops) {
|
|
|
7215
7227
|
});
|
|
7216
7228
|
}
|
|
7217
7229
|
|
|
7230
|
+
/**
|
|
7231
|
+
* The path of a media value, or null when it is not media.
|
|
7232
|
+
*
|
|
7233
|
+
* A `$` deref op names its target explicitly, so there is no schema in hand
|
|
7234
|
+
* here — the shape is all there is to go on. Everywhere a schema IS available,
|
|
7235
|
+
* media is recognised from it instead.
|
|
7236
|
+
*/
|
|
7237
|
+
function mediaPathOf(value) {
|
|
7238
|
+
if (_typeof(value) !== "object" || value === null || Array.isArray(value)) {
|
|
7239
|
+
return null;
|
|
7240
|
+
}
|
|
7241
|
+
var path = value.path;
|
|
7242
|
+
return typeof path === "string" ? path : null;
|
|
7243
|
+
}
|
|
7244
|
+
|
|
7218
7245
|
var EXT_TO_MIME_TYPES = {
|
|
7219
7246
|
x3d: "application/vnd.hzn-3d-crossword",
|
|
7220
7247
|
"3gp": "video/3gpp",
|
|
@@ -7938,6 +7965,19 @@ function filenameToMimeType(filename) {
|
|
|
7938
7965
|
}
|
|
7939
7966
|
}
|
|
7940
7967
|
|
|
7968
|
+
// NOTE: the segments must match the ref built by createRemoteRef below and the RegEx in splitRemoteRef.
|
|
7969
|
+
|
|
7970
|
+
function createRemoteRef(remoteHost, _ref) {
|
|
7971
|
+
var publicProjectId = _ref.publicProjectId,
|
|
7972
|
+
coreVersion = _ref.coreVersion,
|
|
7973
|
+
validationHash = _ref.validationHash,
|
|
7974
|
+
fileHash = _ref.fileHash,
|
|
7975
|
+
filePath = _ref.filePath,
|
|
7976
|
+
bucket = _ref.bucket;
|
|
7977
|
+
// NOTE: the core version is part of the validation hash, but it is also in the uri to make it easier to understand which version the remote file was validated against.
|
|
7978
|
+
return "".concat(remoteHost, "/file/p/").concat(publicProjectId, "/b/").concat(bucket, "/v/").concat(coreVersion, "/h/").concat(validationHash, "/f/").concat(fileHash, "/p/").concat(filePath);
|
|
7979
|
+
}
|
|
7980
|
+
|
|
7941
7981
|
/**
|
|
7942
7982
|
* The validation basis is used in remote refs to determine if the remote content needs to be re-validated.
|
|
7943
7983
|
*
|
|
@@ -8412,8 +8452,12 @@ var Internal = {
|
|
|
8412
8452
|
}
|
|
8413
8453
|
}()
|
|
8414
8454
|
},
|
|
8415
|
-
|
|
8416
|
-
|
|
8455
|
+
mediaUrl: mediaUrl,
|
|
8456
|
+
resolveMedia: resolveMedia,
|
|
8457
|
+
isRemoteMediaPath: isRemoteMediaPath,
|
|
8458
|
+
media: {
|
|
8459
|
+
fillFromGallery: fillFromGallery
|
|
8460
|
+
},
|
|
8417
8461
|
getSchema: getSchema,
|
|
8418
8462
|
getValPath: getValPath,
|
|
8419
8463
|
getSource: getSource,
|
|
@@ -8443,7 +8487,6 @@ var Internal = {
|
|
|
8443
8487
|
return val && ((_getSchema = getSchema(val)) === null || _getSchema === void 0 ? void 0 : _getSchema["executeValidate"](path, src));
|
|
8444
8488
|
},
|
|
8445
8489
|
isVal: isVal,
|
|
8446
|
-
isFile: isFile,
|
|
8447
8490
|
isJson: isJson,
|
|
8448
8491
|
getJsonImport: getJsonImport,
|
|
8449
8492
|
resolveJsonValues: resolveJsonValues,
|
|
@@ -8510,4 +8553,4 @@ function tryJsonParse(str) {
|
|
|
8510
8553
|
}
|
|
8511
8554
|
}
|
|
8512
8555
|
|
|
8513
|
-
export { ArraySchema as A, BooleanSchema as B, ColorSchema as C, 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, extractValModules as f, DEFAULT_VAL_REMOTE_HOST as g, hasRemoteFileSchema as h, initVal as i,
|
|
8556
|
+
export { ArraySchema as A, BooleanSchema as B, ColorSchema as C, 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, extractValModules as f, DEFAULT_VAL_REMOTE_HOST as g, hasRemoteFileSchema as h, initVal as i, derefPatch as j, StringSchema as k, ImageSchema as l, modules as m, FileSchema as n, DateSchema as o, COLOR_FORMATS as p, DEFAULT_COLOR_FORMAT as q, DateTimeSchema as r, splitModuleFilePathAndModulePath as s, RouteSchema as t, RichTextSchema as u, deserializeSchema as v, renderScope as w, getSourcePathFromRoute as x };
|