@valbuild/core 0.101.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/extractValModules.d.ts +1 -1
- package/dist/declarations/src/index.d.ts +13 -11
- package/dist/declarations/src/initSchema.d.ts +28 -15
- 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 +58 -9
- package/dist/declarations/src/schema/array.d.ts +13 -3
- package/dist/declarations/src/schema/file.d.ts +17 -17
- package/dist/declarations/src/schema/files.d.ts +6 -2
- package/dist/declarations/src/schema/hasRemoteFileSchema.d.ts +34 -0
- package/dist/declarations/src/schema/image.d.ts +15 -6
- package/dist/declarations/src/schema/images.d.ts +10 -5
- package/dist/declarations/src/schema/index.d.ts +10 -3
- package/dist/declarations/src/schema/object.d.ts +2 -2
- package/dist/declarations/src/schema/record.d.ts +7 -7
- package/dist/declarations/src/schema/remote.d.ts +0 -10
- package/dist/declarations/src/schema/string.d.ts +4 -2
- package/dist/declarations/src/schema/union.d.ts +2 -2
- 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-a18c24c2.esm.js → index-267a8e9c.esm.js} +1086 -813
- package/dist/{index-3e2d700e.cjs.dev.js → index-2e40f2ae.cjs.dev.js} +1086 -813
- package/dist/{index-049780fa.cjs.prod.js → index-3572060f.cjs.prod.js} +1086 -813
- package/dist/{result-4bd63123.esm.js → result-daff1cae.esm.js} +1 -1
- package/dist/valbuild-core.cjs.dev.js +3 -3
- package/dist/valbuild-core.cjs.prod.js +3 -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,73 +321,6 @@ function getSchema(selector) {
|
|
|
343
321
|
return selector[GetSchema];
|
|
344
322
|
}
|
|
345
323
|
|
|
346
|
-
/* Branded extension types: file, remote, i18n */
|
|
347
|
-
var VAL_EXTENSION = "_type";
|
|
348
|
-
|
|
349
|
-
/**
|
|
350
|
-
* A phantom type parameter is one that doesn't show up at runtime, but is checked statically (and only) at compile time.
|
|
351
|
-
*
|
|
352
|
-
* An example where this is useful is remote types, where the type of the remote source is known at compile time,
|
|
353
|
-
* but the value is not there before it is fetched.
|
|
354
|
-
*
|
|
355
|
-
* @example
|
|
356
|
-
* type Example<T> = string & PhantomType<T>;
|
|
357
|
-
*
|
|
358
|
-
**/
|
|
359
|
-
|
|
360
|
-
var FILE_REF_PROP = "_ref";
|
|
361
|
-
var FILE_REF_SUBTYPE_TAG = "_tag"; // TODO: used earlier by c.rt.image, when we remove c.rt we can remove this
|
|
362
|
-
|
|
363
|
-
/**
|
|
364
|
-
* A file source represents the path to a (local) file.
|
|
365
|
-
*
|
|
366
|
-
* It will be resolved into a Asset object.
|
|
367
|
-
*
|
|
368
|
-
*/
|
|
369
|
-
|
|
370
|
-
var initFile = function initFile(config) {
|
|
371
|
-
var _config$files$directo, _config$files;
|
|
372
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
373
|
-
(_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";
|
|
374
|
-
function file(ref, metadata) {
|
|
375
|
-
return _defineProperty(_defineProperty(_defineProperty({}, FILE_REF_PROP, ref), VAL_EXTENSION, "file"), "metadata", metadata);
|
|
376
|
-
}
|
|
377
|
-
return file;
|
|
378
|
-
};
|
|
379
|
-
|
|
380
|
-
// type Directory =
|
|
381
|
-
// | (typeof config extends { files: { directory: infer D } } ? D : never)
|
|
382
|
-
// | `/public/val`;
|
|
383
|
-
// console.log("path", config);
|
|
384
|
-
// const userSpecifiedDirectory: Directory = config ?? "/public/val";
|
|
385
|
-
|
|
386
|
-
// const directory = userSpecifiedDirectory;
|
|
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
324
|
function isVal(val) {
|
|
414
325
|
return _typeof(val) === "object" && val !== null && val !== undefined && Path in val && "val" in val;
|
|
415
326
|
}
|
|
@@ -443,285 +354,16 @@ function getValPath(valOrSelector) {
|
|
|
443
354
|
return valOrSelector[Path];
|
|
444
355
|
}
|
|
445
356
|
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
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) {
|
|
723
|
-
if (_typeof(prop) === "symbol") {
|
|
724
|
-
throw Error("Cannot create val path of array item with symbol prop: ".concat(prop.toString()));
|
|
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) {
|
|
365
|
+
if (_typeof(prop) === "symbol") {
|
|
366
|
+
throw Error("Cannot create val path of array item with symbol prop: ".concat(prop.toString()));
|
|
725
367
|
}
|
|
726
368
|
if (!arrayPath) {
|
|
727
369
|
return undefined;
|
|
@@ -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;
|
|
@@ -920,6 +584,7 @@ var StringSchema = /*#__PURE__*/function (_Schema) {
|
|
|
920
584
|
var _this$options4, _this$options5, _this$options6, _this$customValidateF, _this$customValidateF2;
|
|
921
585
|
return {
|
|
922
586
|
type: "string",
|
|
587
|
+
render: this.renderInput ? true : undefined,
|
|
923
588
|
options: {
|
|
924
589
|
maxLength: (_this$options4 = this.options) === null || _this$options4 === void 0 ? void 0 : _this$options4.maxLength,
|
|
925
590
|
minLength: (_this$options5 = this.options) === null || _this$options5 === void 0 ? void 0 : _this$options5.minLength,
|
|
@@ -945,7 +610,12 @@ var StringSchema = /*#__PURE__*/function (_Schema) {
|
|
|
945
610
|
}
|
|
946
611
|
}, {
|
|
947
612
|
key: "executeRender",
|
|
948
|
-
value: function executeRender(sourcePath, src
|
|
613
|
+
value: function executeRender(sourcePath, src,
|
|
614
|
+
// Accepted and unused: a string's render is a static layout hint
|
|
615
|
+
// (`{as:"textarea"}` / `{as:"code",language}`) with no closure behind it, so
|
|
616
|
+
// there is nothing a scope could prune. Declared so the signature is uniform
|
|
617
|
+
// across every schema rather than something a reader has to check.
|
|
618
|
+
_scope) {
|
|
949
619
|
if (this.renderInput) {
|
|
950
620
|
if (this.renderInput.as === "code") {
|
|
951
621
|
return _defineProperty({}, sourcePath, {
|
|
@@ -1158,7 +828,7 @@ var ObjectSchema = /*#__PURE__*/function (_Schema) {
|
|
|
1158
828
|
}
|
|
1159
829
|
}, {
|
|
1160
830
|
key: "executeRender",
|
|
1161
|
-
value: function executeRender(sourcePath, src) {
|
|
831
|
+
value: function executeRender(sourcePath, src, scope) {
|
|
1162
832
|
var res = {};
|
|
1163
833
|
if (src === null) {
|
|
1164
834
|
return res;
|
|
@@ -1169,7 +839,13 @@ var ObjectSchema = /*#__PURE__*/function (_Schema) {
|
|
|
1169
839
|
continue;
|
|
1170
840
|
}
|
|
1171
841
|
var subPath = unsafeCreateSourcePath(sourcePath, _key3);
|
|
1172
|
-
|
|
842
|
+
// An object produces no render of its own, so it is pure recursion — and
|
|
843
|
+
// pruning it is the whole contribution: a field deep in one branch stops
|
|
844
|
+
// paying for every sibling branch's renders.
|
|
845
|
+
if (scope !== undefined && !scope.wantsUnder(subPath)) {
|
|
846
|
+
continue;
|
|
847
|
+
}
|
|
848
|
+
var itemResult = this.items[_key3]["executeRender"](subPath, itemSrc, scope);
|
|
1173
849
|
for (var keyS in itemResult) {
|
|
1174
850
|
var _key4 = keyS;
|
|
1175
851
|
res[_key4] = itemResult[_key4];
|
|
@@ -1311,6 +987,7 @@ var ArraySchema = /*#__PURE__*/function (_Schema) {
|
|
|
1311
987
|
type: "array",
|
|
1312
988
|
item: this.item["executeSerialize"](),
|
|
1313
989
|
opt: this.opt,
|
|
990
|
+
render: this.renderInput ? true : undefined,
|
|
1314
991
|
customValidate: this.customValidateFunctions && ((_this$customValidateF = this.customValidateFunctions) === null || _this$customValidateF === void 0 ? void 0 : _this$customValidateF.length) > 0,
|
|
1315
992
|
readonly: this.isReadonly,
|
|
1316
993
|
hidden: this.isHidden,
|
|
@@ -1319,7 +996,7 @@ var ArraySchema = /*#__PURE__*/function (_Schema) {
|
|
|
1319
996
|
}
|
|
1320
997
|
}, {
|
|
1321
998
|
key: "executeRender",
|
|
1322
|
-
value: function executeRender(sourcePath, src) {
|
|
999
|
+
value: function executeRender(sourcePath, src, scope) {
|
|
1323
1000
|
var res = {};
|
|
1324
1001
|
if (src === null) {
|
|
1325
1002
|
return res;
|
|
@@ -1331,7 +1008,10 @@ var ArraySchema = /*#__PURE__*/function (_Schema) {
|
|
|
1331
1008
|
continue;
|
|
1332
1009
|
}
|
|
1333
1010
|
var subPath = unsafeCreateSourcePath(sourcePath, key);
|
|
1334
|
-
|
|
1011
|
+
if (scope !== undefined && !scope.wantsUnder(subPath)) {
|
|
1012
|
+
continue;
|
|
1013
|
+
}
|
|
1014
|
+
var itemResult = this.item["executeRender"](subPath, itemSrc, scope);
|
|
1335
1015
|
for (var keyS in itemResult) {
|
|
1336
1016
|
var _key = keyS;
|
|
1337
1017
|
res[_key] = itemResult[_key];
|
|
@@ -1347,34 +1027,51 @@ var ArraySchema = /*#__PURE__*/function (_Schema) {
|
|
|
1347
1027
|
message: "Unknown layout type: " + layout
|
|
1348
1028
|
};
|
|
1349
1029
|
}
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1030
|
+
// The whole list when the LIST is what is being shown; only the wanted
|
|
1031
|
+
// rows when it is not. `select` is the user's closure and the real expense
|
|
1032
|
+
// — a list view asks for the container and gets every row, a single field
|
|
1033
|
+
// asks for its own path and costs one call.
|
|
1034
|
+
// Non-null once, as a value, rather than a boolean the compiler cannot
|
|
1035
|
+
// tie back to `scope`: no scope and a scope that wants this exact path
|
|
1036
|
+
// both mean the whole list, and anything else is a window.
|
|
1037
|
+
var window = scope !== undefined && !scope.wants(sourcePath) ? scope : null;
|
|
1038
|
+
var items = [];
|
|
1039
|
+
for (var index = 0; index < src.length; index++) {
|
|
1040
|
+
if (window !== null && !window.wantsUnder(unsafeCreateSourcePath(sourcePath, index))) {
|
|
1041
|
+
continue;
|
|
1042
|
+
}
|
|
1043
|
+
// Per ITEM, not per list, matching what `record` already does: `select`
|
|
1044
|
+
// is user code, and one row whose data trips it up must not take out the
|
|
1045
|
+
// whole list. Before scoping, one throwing row produced an error at the
|
|
1046
|
+
// container and no items at all.
|
|
1047
|
+
try {
|
|
1048
|
+
// NB NB: display is actually defined by the user
|
|
1049
|
+
var _select = select({
|
|
1050
|
+
val: src[index]
|
|
1051
|
+
}),
|
|
1052
|
+
title = _select.title,
|
|
1053
|
+
subtitle = _select.subtitle,
|
|
1054
|
+
image = _select.image;
|
|
1055
|
+
items.push([index, {
|
|
1056
|
+
title: title,
|
|
1057
|
+
subtitle: subtitle,
|
|
1058
|
+
image: image
|
|
1059
|
+
}]);
|
|
1060
|
+
} catch (e) {
|
|
1061
|
+
res[unsafeCreateSourcePath(sourcePath, index)] = {
|
|
1062
|
+
status: "error",
|
|
1063
|
+
message: e instanceof Error ? e.message : "Unknown error"
|
|
1064
|
+
};
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
res[sourcePath] = {
|
|
1068
|
+
status: "success",
|
|
1069
|
+
data: {
|
|
1070
|
+
layout: "list",
|
|
1071
|
+
parent: "array",
|
|
1072
|
+
items: items
|
|
1073
|
+
}
|
|
1074
|
+
};
|
|
1378
1075
|
}
|
|
1379
1076
|
return res;
|
|
1380
1077
|
}
|
|
@@ -1948,7 +1645,7 @@ var UnionSchema = /*#__PURE__*/function (_Schema) {
|
|
|
1948
1645
|
}
|
|
1949
1646
|
}, {
|
|
1950
1647
|
key: "executeRender",
|
|
1951
|
-
value: function executeRender(sourcePath, src) {
|
|
1648
|
+
value: function executeRender(sourcePath, src, scope) {
|
|
1952
1649
|
var res = {};
|
|
1953
1650
|
if (src === null) {
|
|
1954
1651
|
return res;
|
|
@@ -1970,7 +1667,7 @@ var UnionSchema = /*#__PURE__*/function (_Schema) {
|
|
|
1970
1667
|
return false;
|
|
1971
1668
|
});
|
|
1972
1669
|
if (thisSchema) {
|
|
1973
|
-
var itemResult = thisSchema["executeRender"](sourcePath, src);
|
|
1670
|
+
var itemResult = thisSchema["executeRender"](sourcePath, src, scope);
|
|
1974
1671
|
for (var keyS in itemResult) {
|
|
1975
1672
|
var _key3 = keyS;
|
|
1976
1673
|
res[_key3] = itemResult[_key3];
|
|
@@ -1997,6 +1694,170 @@ var union = function union(key) {
|
|
|
1997
1694
|
return new UnionSchema(key, objects);
|
|
1998
1695
|
};
|
|
1999
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
|
+
|
|
2000
1861
|
var ImageSchema = /*#__PURE__*/function (_Schema) {
|
|
2001
1862
|
function ImageSchema(options) {
|
|
2002
1863
|
var _this;
|
|
@@ -2038,7 +1899,7 @@ var ImageSchema = /*#__PURE__*/function (_Schema) {
|
|
|
2038
1899
|
}, {
|
|
2039
1900
|
key: "executeValidate",
|
|
2040
1901
|
value: function executeValidate(path, src) {
|
|
2041
|
-
var _src$
|
|
1902
|
+
var _src$mimeType;
|
|
2042
1903
|
var customValidationErrors = this.executeCustomValidateFunctions(src, this.customValidateFunctions, {
|
|
2043
1904
|
path: path
|
|
2044
1905
|
});
|
|
@@ -2051,42 +1912,68 @@ var ImageSchema = /*#__PURE__*/function (_Schema) {
|
|
|
2051
1912
|
value: src
|
|
2052
1913
|
}]));
|
|
2053
1914
|
}
|
|
2054
|
-
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) {
|
|
2055
1925
|
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
2056
1926
|
message: "Expected a remote image, but got a local image.",
|
|
2057
1927
|
value: src,
|
|
2058
1928
|
fixes: ["image:upload-remote"]
|
|
2059
1929
|
}]));
|
|
2060
1930
|
}
|
|
2061
|
-
if (this.isRemote &&
|
|
1931
|
+
if (this.isRemote && isRemotePath) {
|
|
2062
1932
|
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
2063
1933
|
message: "Remote image was not checked.",
|
|
2064
1934
|
value: src,
|
|
2065
1935
|
fixes: ["image:check-remote"]
|
|
2066
1936
|
}]));
|
|
2067
1937
|
}
|
|
2068
|
-
if (!this.isRemote &&
|
|
1938
|
+
if (!this.isRemote && isRemotePath) {
|
|
2069
1939
|
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
2070
|
-
message: "Expected
|
|
1940
|
+
message: "Expected local image, but found remote.",
|
|
2071
1941
|
value: src,
|
|
2072
1942
|
fixes: ["image:download-remote"]
|
|
2073
1943
|
}]));
|
|
2074
1944
|
}
|
|
2075
|
-
if (
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
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
|
+
}
|
|
2080
1952
|
}
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
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;
|
|
2086
1973
|
}
|
|
2087
|
-
var
|
|
2088
|
-
accept =
|
|
2089
|
-
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 : "";
|
|
2090
1977
|
if (accept && mimeType && !mimeType.includes("/")) {
|
|
2091
1978
|
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
2092
1979
|
message: "Invalid mime type format. Got: '".concat(mimeType, "'"),
|
|
@@ -2116,10 +2003,10 @@ var ImageSchema = /*#__PURE__*/function (_Schema) {
|
|
|
2116
2003
|
}]));
|
|
2117
2004
|
}
|
|
2118
2005
|
}
|
|
2119
|
-
var fileMimeType = Internal.filenameToMimeType(src
|
|
2006
|
+
var fileMimeType = Internal.filenameToMimeType(src.path);
|
|
2120
2007
|
if (!fileMimeType) {
|
|
2121
2008
|
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
2122
|
-
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),
|
|
2123
2010
|
value: src,
|
|
2124
2011
|
fixes: ["image:check-metadata"]
|
|
2125
2012
|
}]));
|
|
@@ -2131,35 +2018,37 @@ var ImageSchema = /*#__PURE__*/function (_Schema) {
|
|
|
2131
2018
|
fixes: ["image:check-metadata"]
|
|
2132
2019
|
}]));
|
|
2133
2020
|
}
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
value: src
|
|
2140
|
-
}]));
|
|
2141
|
-
}
|
|
2142
|
-
}
|
|
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) {
|
|
2143
2026
|
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
2144
|
-
message: "Found metadata, but it could not be validated.
|
|
2145
|
-
// 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.",
|
|
2146
2028
|
value: src,
|
|
2147
2029
|
fixes: ["image:check-metadata"]
|
|
2148
2030
|
}]));
|
|
2149
2031
|
}
|
|
2150
|
-
var isReferencedModule = Object.keys(this.moduleMetadata).length > 0;
|
|
2151
|
-
if (src.metadata === undefined && isReferencedModule) {
|
|
2152
|
-
if (customValidationErrors.length === 0) {
|
|
2153
|
-
return false;
|
|
2154
|
-
}
|
|
2155
|
-
return _defineProperty({}, path, _toConsumableArray(customValidationErrors));
|
|
2156
|
-
}
|
|
2157
2032
|
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
2158
2033
|
message: "Could not validate Image metadata.",
|
|
2159
2034
|
value: src,
|
|
2160
2035
|
fixes: ["image:add-metadata"]
|
|
2161
2036
|
}]));
|
|
2162
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
|
+
}
|
|
2163
2052
|
}, {
|
|
2164
2053
|
key: "executeAssert",
|
|
2165
2054
|
value: function executeAssert(path, src) {
|
|
@@ -2187,20 +2076,11 @@ var ImageSchema = /*#__PURE__*/function (_Schema) {
|
|
|
2187
2076
|
}])
|
|
2188
2077
|
};
|
|
2189
2078
|
}
|
|
2190
|
-
if (!(
|
|
2079
|
+
if (!("path" in src) || typeof src.path !== "string") {
|
|
2191
2080
|
return {
|
|
2192
2081
|
success: false,
|
|
2193
2082
|
errors: _defineProperty({}, path, [{
|
|
2194
|
-
message: "
|
|
2195
|
-
typeError: true
|
|
2196
|
-
}])
|
|
2197
|
-
};
|
|
2198
|
-
}
|
|
2199
|
-
if (!(VAL_EXTENSION in src && src[VAL_EXTENSION] === "file")) {
|
|
2200
|
-
return {
|
|
2201
|
-
success: false,
|
|
2202
|
-
errors: _defineProperty({}, path, [{
|
|
2203
|
-
message: "Value of this schema must use: 'c.image' (error type: missing_file_extension)",
|
|
2083
|
+
message: "An image must be an object with a 'path' (error type: missing_path)",
|
|
2204
2084
|
typeError: true
|
|
2205
2085
|
}])
|
|
2206
2086
|
};
|
|
@@ -2256,7 +2136,15 @@ var ImageSchema = /*#__PURE__*/function (_Schema) {
|
|
|
2256
2136
|
}
|
|
2257
2137
|
}]);
|
|
2258
2138
|
}(Schema);
|
|
2259
|
-
|
|
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) {
|
|
2260
2148
|
var isModule = !!options && !!Internal.getValPath(options);
|
|
2261
2149
|
if (isModule) {
|
|
2262
2150
|
var allModules = {};
|
|
@@ -2271,7 +2159,7 @@ var image = function image(options) {
|
|
|
2271
2159
|
return new ImageSchema({}, false, false, [], allModules);
|
|
2272
2160
|
}
|
|
2273
2161
|
return new ImageSchema(options);
|
|
2274
|
-
}
|
|
2162
|
+
}
|
|
2275
2163
|
|
|
2276
2164
|
var RouteSchema = /*#__PURE__*/function (_Schema) {
|
|
2277
2165
|
function RouteSchema(options) {
|
|
@@ -3144,6 +3032,20 @@ function _asyncToGenerator(n) {
|
|
|
3144
3032
|
};
|
|
3145
3033
|
}
|
|
3146
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
|
+
|
|
3147
3049
|
/**
|
|
3148
3050
|
* The string used as the `_type` discriminator of a {@link JsonSource}.
|
|
3149
3051
|
*/
|
|
@@ -3292,47 +3194,6 @@ function _resolveJsonValues() {
|
|
|
3292
3194
|
return _resolveJsonValues.apply(this, arguments);
|
|
3293
3195
|
}
|
|
3294
3196
|
|
|
3295
|
-
var RegEx = /^(https?:\/\/[^/]+)\/file\/p\/([^/]+)\/b\/([^/]+)\/v\/([^/]+)\/h\/([^/]+)\/f\/([^/]+)\/p\/(.+)$/;
|
|
3296
|
-
function splitRemoteRef(ref) {
|
|
3297
|
-
if (ref[0] === "/") {
|
|
3298
|
-
return {
|
|
3299
|
-
status: "error",
|
|
3300
|
-
error: "Not a remote ref: " + ref
|
|
3301
|
-
};
|
|
3302
|
-
}
|
|
3303
|
-
var match = ref.match(RegEx);
|
|
3304
|
-
if (!match) {
|
|
3305
|
-
return {
|
|
3306
|
-
status: "error",
|
|
3307
|
-
error: "Invalid remote ref: " + ref
|
|
3308
|
-
};
|
|
3309
|
-
}
|
|
3310
|
-
if (match[7].indexOf("public/") !== 0) {
|
|
3311
|
-
return {
|
|
3312
|
-
status: "error",
|
|
3313
|
-
error: "Invalid remote ref: " + ref
|
|
3314
|
-
};
|
|
3315
|
-
}
|
|
3316
|
-
if (match[7].split("/").some(function (segment) {
|
|
3317
|
-
return segment === "." || segment === "..";
|
|
3318
|
-
})) {
|
|
3319
|
-
return {
|
|
3320
|
-
status: "error",
|
|
3321
|
-
error: "Invalid remote ref: " + ref
|
|
3322
|
-
};
|
|
3323
|
-
}
|
|
3324
|
-
return {
|
|
3325
|
-
status: "success",
|
|
3326
|
-
remoteHost: match[1],
|
|
3327
|
-
projectId: match[2],
|
|
3328
|
-
bucket: match[3],
|
|
3329
|
-
version: match[4],
|
|
3330
|
-
validationHash: match[5],
|
|
3331
|
-
fileHash: match[6],
|
|
3332
|
-
filePath: match[7]
|
|
3333
|
-
};
|
|
3334
|
-
}
|
|
3335
|
-
|
|
3336
3197
|
/**
|
|
3337
3198
|
* The source type of a `.jsonValues()` record: every entry value is EITHER a
|
|
3338
3199
|
* lazily loaded {@link JsonSource} whose resolved content is the (loosened, see
|
|
@@ -3857,6 +3718,7 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
|
|
|
3857
3718
|
item: this.item["executeSerialize"](),
|
|
3858
3719
|
key: (_this$keySchema = this.keySchema) === null || _this$keySchema === void 0 ? void 0 : _this$keySchema["executeSerialize"](),
|
|
3859
3720
|
opt: this.opt,
|
|
3721
|
+
render: this.renderInput ? true : undefined,
|
|
3860
3722
|
router: (_this$currentRouter = this.currentRouter) === null || _this$currentRouter === void 0 ? void 0 : _this$currentRouter.getRouterId(),
|
|
3861
3723
|
customValidate: this.customValidateFunctions && ((_this$customValidateF = this.customValidateFunctions) === null || _this$customValidateF === void 0 ? void 0 : _this$customValidateF.length) > 0,
|
|
3862
3724
|
jsonValues: this.isJsonValues ? true : undefined,
|
|
@@ -3889,7 +3751,7 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
|
|
|
3889
3751
|
}
|
|
3890
3752
|
}, {
|
|
3891
3753
|
key: "executeRender",
|
|
3892
|
-
value: function executeRender(sourcePath, src) {
|
|
3754
|
+
value: function executeRender(sourcePath, src, scope) {
|
|
3893
3755
|
var res = {};
|
|
3894
3756
|
if (src === null) {
|
|
3895
3757
|
return res;
|
|
@@ -3907,7 +3769,10 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
|
|
|
3907
3769
|
continue;
|
|
3908
3770
|
}
|
|
3909
3771
|
var subPath = unsafeCreateSourcePath(sourcePath, _key);
|
|
3910
|
-
|
|
3772
|
+
if (scope !== undefined && !scope.wantsUnder(subPath)) {
|
|
3773
|
+
continue;
|
|
3774
|
+
}
|
|
3775
|
+
var itemResult = this.item["executeRender"](subPath, itemSrc, scope);
|
|
3911
3776
|
for (var keyS in itemResult) {
|
|
3912
3777
|
var _key2 = keyS;
|
|
3913
3778
|
res[_key2] = itemResult[_key2];
|
|
@@ -3923,6 +3788,9 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
|
|
|
3923
3788
|
message: "Unknown layout type: " + layout
|
|
3924
3789
|
};
|
|
3925
3790
|
}
|
|
3791
|
+
// See the same block in `array`: the whole record when the record is what
|
|
3792
|
+
// is being shown, only the wanted entries when it is not.
|
|
3793
|
+
var window = scope !== undefined && !scope.wants(sourcePath) ? scope : null;
|
|
3926
3794
|
var items = [];
|
|
3927
3795
|
for (var _i = 0, _Object$entries = Object.entries(src); _i < _Object$entries.length; _i++) {
|
|
3928
3796
|
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
@@ -3931,6 +3799,9 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
|
|
|
3931
3799
|
if (isJson(val)) {
|
|
3932
3800
|
continue; // as above: nothing to select from an un-loaded entry
|
|
3933
3801
|
}
|
|
3802
|
+
if (window !== null && !window.wantsUnder(unsafeCreateSourcePath(sourcePath, _key3))) {
|
|
3803
|
+
continue;
|
|
3804
|
+
}
|
|
3934
3805
|
// Per KEY, not per record: `select` is user code, and one entry whose
|
|
3935
3806
|
// data trips it up must not take out the whole list.
|
|
3936
3807
|
try {
|
|
@@ -4838,48 +4709,378 @@ var KeyOfSchema = /*#__PURE__*/function (_Schema) {
|
|
|
4838
4709
|
message: "Schema not found for module. keyOf must be used with a Val Module"
|
|
4839
4710
|
}]));
|
|
4840
4711
|
}
|
|
4841
|
-
var serializedSchema = this.schema;
|
|
4842
|
-
if (!(serializedSchema.type === "object" || serializedSchema.type === "record")) {
|
|
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);
|
|
4944
|
+
}
|
|
4945
|
+
}, {
|
|
4946
|
+
key: "validate",
|
|
4947
|
+
value: function validate(validationFunction) {
|
|
4948
|
+
return new FileSchema(this.options, this.opt, this.isRemote, [].concat(_toConsumableArray(this.customValidateFunctions), [validationFunction]), this.moduleMetadata, this.isReadonly, this.isHidden, this.description);
|
|
4949
|
+
}
|
|
4950
|
+
}, {
|
|
4951
|
+
key: "executeValidate",
|
|
4952
|
+
value: function executeValidate(path, src) {
|
|
4953
|
+
var customValidationErrors = this.executeCustomValidateFunctions(src, this.customValidateFunctions, {
|
|
4954
|
+
path: path
|
|
4955
|
+
});
|
|
4956
|
+
if (this.opt && (src === null || src === undefined)) {
|
|
4957
|
+
return customValidationErrors.length > 0 ? _defineProperty({}, path, customValidationErrors) : false;
|
|
4958
|
+
}
|
|
4959
|
+
if (src === null || src === undefined) {
|
|
4960
|
+
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
4961
|
+
message: "Non-optional file was null or undefined.",
|
|
4962
|
+
value: src
|
|
4963
|
+
}]));
|
|
4964
|
+
}
|
|
4965
|
+
if (typeof src.path !== "string") {
|
|
4966
|
+
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
4967
|
+
message: "File did not have a path string. Got: ".concat(_typeof(src.path)),
|
|
4968
|
+
value: src
|
|
4969
|
+
}]));
|
|
4970
|
+
}
|
|
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
|
+
}]));
|
|
4980
|
+
}
|
|
4981
|
+
if (this.isRemote && isRemotePath) {
|
|
4982
|
+
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
4983
|
+
message: "Remote file was not checked.",
|
|
4984
|
+
value: src,
|
|
4985
|
+
fixes: ["file:check-remote"]
|
|
4986
|
+
}]));
|
|
4987
|
+
}
|
|
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) {
|
|
4998
|
+
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
4999
|
+
message: "A file from a gallery must not carry its own mimeType: it is stored in the gallery module.",
|
|
5000
|
+
value: src
|
|
5001
|
+
}]));
|
|
5002
|
+
}
|
|
5003
|
+
if (!(src.path in galleryEntries)) {
|
|
5004
|
+
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
5005
|
+
message: "The gallery does not have a file at '".concat(src.path, "'."),
|
|
5006
|
+
value: src
|
|
5007
|
+
}]));
|
|
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("/")) {
|
|
5015
|
+
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
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);
|
|
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) {
|
|
4843
5043
|
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
4844
|
-
|
|
4845
|
-
|
|
5044
|
+
message: "Could not determine mime type from file extension. Got: ".concat(src.path),
|
|
5045
|
+
value: src
|
|
4846
5046
|
}]));
|
|
4847
5047
|
}
|
|
4848
|
-
if (
|
|
4849
|
-
return false;
|
|
4850
|
-
}
|
|
4851
|
-
if (serializedSchema.type === "record" && typeof src !== "string") {
|
|
5048
|
+
if (fileMimeType !== mimeType) {
|
|
4852
5049
|
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
4853
|
-
message: "
|
|
5050
|
+
message: "Mime type and file extension not matching. Mime type is '".concat(mimeType, "' but file extension is '").concat(fileMimeType, "'"),
|
|
5051
|
+
value: src
|
|
4854
5052
|
}]));
|
|
4855
5053
|
}
|
|
4856
|
-
|
|
4857
|
-
|
|
4858
|
-
|
|
4859
|
-
|
|
4860
|
-
|
|
4861
|
-
}]));
|
|
4862
|
-
}
|
|
4863
|
-
}
|
|
4864
|
-
if (serializedSchema.type === "record") {
|
|
4865
|
-
if (typeof src !== "string") {
|
|
4866
|
-
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
4867
|
-
message: "Value of keyOf (record) must be 'string'. Found: ".concat(_typeof(src))
|
|
4868
|
-
}]));
|
|
4869
|
-
}
|
|
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) {
|
|
4870
5059
|
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [{
|
|
4871
|
-
|
|
4872
|
-
|
|
4873
|
-
|
|
4874
|
-
key: src,
|
|
4875
|
-
sourcePath: this.sourcePath
|
|
4876
|
-
}
|
|
5060
|
+
message: "Found mimeType, but it could not be validated.",
|
|
5061
|
+
value: src,
|
|
5062
|
+
fixes: ["file:check-metadata"]
|
|
4877
5063
|
}]));
|
|
4878
5064
|
}
|
|
4879
|
-
|
|
4880
|
-
|
|
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;
|
|
4881
5082
|
}
|
|
4882
|
-
return
|
|
5083
|
+
return this.moduleMetadata[modulePaths[0]];
|
|
4883
5084
|
}
|
|
4884
5085
|
}, {
|
|
4885
5086
|
key: "executeAssert",
|
|
@@ -4894,56 +5095,29 @@ var KeyOfSchema = /*#__PURE__*/function (_Schema) {
|
|
|
4894
5095
|
return {
|
|
4895
5096
|
success: false,
|
|
4896
5097
|
errors: _defineProperty({}, path, [{
|
|
4897
|
-
message: "Expected '
|
|
4898
|
-
typeError: true
|
|
4899
|
-
}])
|
|
4900
|
-
};
|
|
4901
|
-
}
|
|
4902
|
-
var schema = this.schema;
|
|
4903
|
-
if (!schema) {
|
|
4904
|
-
return {
|
|
4905
|
-
success: false,
|
|
4906
|
-
errors: _defineProperty({}, path, [{
|
|
4907
|
-
message: "Neither key nor schema was found. keyOf is missing an argument.",
|
|
5098
|
+
message: "Expected 'object', got 'null'",
|
|
4908
5099
|
typeError: true
|
|
4909
5100
|
}])
|
|
4910
5101
|
};
|
|
4911
5102
|
}
|
|
4912
|
-
|
|
4913
|
-
if (!(serializedSchema.type === "object" || serializedSchema.type === "record")) {
|
|
5103
|
+
if (_typeof(src) !== "object") {
|
|
4914
5104
|
return {
|
|
4915
5105
|
success: false,
|
|
4916
5106
|
errors: _defineProperty({}, path, [{
|
|
4917
|
-
|
|
4918
|
-
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), "'"),
|
|
4919
5108
|
typeError: true
|
|
4920
5109
|
}])
|
|
4921
5110
|
};
|
|
4922
5111
|
}
|
|
4923
|
-
if (
|
|
5112
|
+
if (!("path" in src) || typeof src.path !== "string") {
|
|
4924
5113
|
return {
|
|
4925
5114
|
success: false,
|
|
4926
5115
|
errors: _defineProperty({}, path, [{
|
|
4927
|
-
message: "
|
|
5116
|
+
message: "A file must be an object with a 'path' (error type: missing_path)",
|
|
4928
5117
|
typeError: true
|
|
4929
5118
|
}])
|
|
4930
5119
|
};
|
|
4931
5120
|
}
|
|
4932
|
-
// We check actual value here, since TypeScript also does this. Literals are used in other types (unions),
|
|
4933
|
-
// and there it also makes sense to check the actual string values (i.e. that it is not just a string) since
|
|
4934
|
-
// missing one would lead to a runtime error. At least this is what we are thinking currently.
|
|
4935
|
-
if (serializedSchema.type === "object") {
|
|
4936
|
-
var keys = serializedSchema.keys;
|
|
4937
|
-
if (!keys.includes(src)) {
|
|
4938
|
-
return {
|
|
4939
|
-
success: false,
|
|
4940
|
-
errors: _defineProperty({}, path, [{
|
|
4941
|
-
message: "Value of keyOf (object) must be: ".concat(keys.join(", "), ". Found: ").concat(src),
|
|
4942
|
-
typeError: true
|
|
4943
|
-
}])
|
|
4944
|
-
};
|
|
4945
|
-
}
|
|
4946
|
-
}
|
|
4947
5121
|
return {
|
|
4948
5122
|
success: true,
|
|
4949
5123
|
data: src
|
|
@@ -4952,17 +5126,17 @@ var KeyOfSchema = /*#__PURE__*/function (_Schema) {
|
|
|
4952
5126
|
}, {
|
|
4953
5127
|
key: "nullable",
|
|
4954
5128
|
value: function nullable() {
|
|
4955
|
-
return new
|
|
5129
|
+
return new FileSchema(this.options, true, this.isRemote, this.customValidateFunctions, this.moduleMetadata, this.isReadonly, this.isHidden, this.description);
|
|
4956
5130
|
}
|
|
4957
5131
|
}, {
|
|
4958
5132
|
key: "readonly",
|
|
4959
5133
|
value: function readonly() {
|
|
4960
|
-
return new
|
|
5134
|
+
return new FileSchema(this.options, this.opt, this.isRemote, this.customValidateFunctions, this.moduleMetadata, true, this.isHidden, this.description);
|
|
4961
5135
|
}
|
|
4962
5136
|
}, {
|
|
4963
5137
|
key: "hidden",
|
|
4964
5138
|
value: function hidden() {
|
|
4965
|
-
return new
|
|
5139
|
+
return new FileSchema(this.options, this.opt, this.isRemote, this.customValidateFunctions, this.moduleMetadata, this.isReadonly, true, this.description);
|
|
4966
5140
|
}
|
|
4967
5141
|
}, {
|
|
4968
5142
|
key: "executeCustomValidateAt",
|
|
@@ -4975,33 +5149,14 @@ var KeyOfSchema = /*#__PURE__*/function (_Schema) {
|
|
|
4975
5149
|
key: "executeSerialize",
|
|
4976
5150
|
value: function executeSerialize() {
|
|
4977
5151
|
var _this$customValidateF;
|
|
4978
|
-
var
|
|
4979
|
-
if (!path) {
|
|
4980
|
-
throw new Error("Cannot serialize keyOf schema with empty selector. TIP: keyOf must be used with a Val Module of record schema.");
|
|
4981
|
-
}
|
|
4982
|
-
var serializedSchema = this.schema;
|
|
4983
|
-
if (!serializedSchema) {
|
|
4984
|
-
throw new Error("Cannot serialize keyOf schema with empty selector.");
|
|
4985
|
-
}
|
|
4986
|
-
var values;
|
|
4987
|
-
switch (serializedSchema.type) {
|
|
4988
|
-
case "record":
|
|
4989
|
-
values = "string";
|
|
4990
|
-
break;
|
|
4991
|
-
case "object":
|
|
4992
|
-
values = serializedSchema.keys;
|
|
4993
|
-
break;
|
|
4994
|
-
default:
|
|
4995
|
-
throw new Error(// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4996
|
-
"Cannot serialize keyOf schema with selector of type '".concat(serializedSchema.type || "unknown", "'"));
|
|
4997
|
-
}
|
|
5152
|
+
var modulePaths = this.moduleMetadata ? Object.keys(this.moduleMetadata) : [];
|
|
4998
5153
|
return {
|
|
4999
|
-
type: "
|
|
5000
|
-
|
|
5001
|
-
schema: serializedSchema,
|
|
5154
|
+
type: "file",
|
|
5155
|
+
options: this.options,
|
|
5002
5156
|
opt: this.opt,
|
|
5003
|
-
|
|
5157
|
+
remote: this.isRemote,
|
|
5004
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,
|
|
5005
5160
|
readonly: this.isReadonly,
|
|
5006
5161
|
hidden: this.isHidden,
|
|
5007
5162
|
description: this.description
|
|
@@ -5014,29 +5169,30 @@ var KeyOfSchema = /*#__PURE__*/function (_Schema) {
|
|
|
5014
5169
|
}
|
|
5015
5170
|
}]);
|
|
5016
5171
|
}(Schema);
|
|
5017
|
-
|
|
5018
|
-
|
|
5019
|
-
|
|
5020
|
-
|
|
5021
|
-
|
|
5022
|
-
|
|
5023
|
-
|
|
5024
|
-
|
|
5025
|
-
|
|
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);
|
|
5026
5191
|
}
|
|
5027
|
-
|
|
5028
|
-
type: "object",
|
|
5029
|
-
keys: keys,
|
|
5030
|
-
opt: refSchema === null || refSchema === void 0 ? void 0 : refSchema["opt"]
|
|
5031
|
-
};
|
|
5032
|
-
} else if (refSchema instanceof RecordSchema) {
|
|
5033
|
-
serializedRefSchema = {
|
|
5034
|
-
type: "record",
|
|
5035
|
-
opt: refSchema === null || refSchema === void 0 ? void 0 : refSchema["opt"]
|
|
5036
|
-
};
|
|
5192
|
+
return new FileSchema({}, false, false, [], allModules);
|
|
5037
5193
|
}
|
|
5038
|
-
return new
|
|
5039
|
-
}
|
|
5194
|
+
return new FileSchema(options);
|
|
5195
|
+
}
|
|
5040
5196
|
|
|
5041
5197
|
/**
|
|
5042
5198
|
* Options for s.files()
|
|
@@ -5063,8 +5219,8 @@ var keyOf = function keyOf(valModule) {
|
|
|
5063
5219
|
* ```
|
|
5064
5220
|
*/
|
|
5065
5221
|
var files = function files(options) {
|
|
5066
|
-
var _options$
|
|
5067
|
-
var directory =
|
|
5222
|
+
var _options$remote;
|
|
5223
|
+
var directory = options.directory;
|
|
5068
5224
|
var itemSchema = new ObjectSchema({
|
|
5069
5225
|
mimeType: new StringSchema({}, false)
|
|
5070
5226
|
}, false);
|
|
@@ -6117,8 +6273,9 @@ function router(router, keyOrItem, maybeItem) {
|
|
|
6117
6273
|
/**
|
|
6118
6274
|
* Define a collection of images.
|
|
6119
6275
|
*
|
|
6120
|
-
*
|
|
6121
|
-
*
|
|
6276
|
+
* `directory` is required — it decides where uploads land, so it is not something
|
|
6277
|
+
* to be inferred. The rest defaults: any image type (`"image/*"`), nullable alt
|
|
6278
|
+
* text, remote disabled.
|
|
6122
6279
|
*
|
|
6123
6280
|
* @example
|
|
6124
6281
|
* ```typescript
|
|
@@ -6138,9 +6295,9 @@ function router(router, keyOrItem, maybeItem) {
|
|
|
6138
6295
|
* ```
|
|
6139
6296
|
*/
|
|
6140
6297
|
var images = function images(options) {
|
|
6141
|
-
var _options$
|
|
6142
|
-
var directory =
|
|
6143
|
-
var altSchema = (_options$alt = options
|
|
6298
|
+
var _options$alt, _options$accept, _options$remote;
|
|
6299
|
+
var directory = options.directory;
|
|
6300
|
+
var altSchema = (_options$alt = options.alt) !== null && _options$alt !== void 0 ? _options$alt : string().nullable();
|
|
6144
6301
|
var itemSchema = new ObjectSchema({
|
|
6145
6302
|
width: new NumberSchema(undefined, false),
|
|
6146
6303
|
height: new NumberSchema(undefined, false),
|
|
@@ -6149,9 +6306,9 @@ var images = function images(options) {
|
|
|
6149
6306
|
}, false);
|
|
6150
6307
|
return new RecordSchema(itemSchema, false, [], null, null, {
|
|
6151
6308
|
type: "images",
|
|
6152
|
-
accept: (_options$accept = options
|
|
6309
|
+
accept: (_options$accept = options.accept) !== null && _options$accept !== void 0 ? _options$accept : "image/*",
|
|
6153
6310
|
directory: directory,
|
|
6154
|
-
remote: (_options$remote = options
|
|
6311
|
+
remote: (_options$remote = options.remote) !== null && _options$remote !== void 0 ? _options$remote : false,
|
|
6155
6312
|
altSchema: altSchema
|
|
6156
6313
|
});
|
|
6157
6314
|
};
|
|
@@ -6190,88 +6347,6 @@ function initSchema() {
|
|
|
6190
6347
|
};
|
|
6191
6348
|
}
|
|
6192
6349
|
|
|
6193
|
-
/**
|
|
6194
|
-
* A image source represents the path to a (local) image.
|
|
6195
|
-
*
|
|
6196
|
-
*/
|
|
6197
|
-
|
|
6198
|
-
var initImage = function initImage(config) {
|
|
6199
|
-
var _config$files$directo, _config$files;
|
|
6200
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
6201
|
-
(_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";
|
|
6202
|
-
|
|
6203
|
-
/**
|
|
6204
|
-
* Define the source of an image file.
|
|
6205
|
-
*
|
|
6206
|
-
* @example
|
|
6207
|
-
* c.image("/public/val/example.png", {
|
|
6208
|
-
* width: 944,
|
|
6209
|
-
* height: 944,
|
|
6210
|
-
* mimeType: "image/png",
|
|
6211
|
-
*})
|
|
6212
|
-
*
|
|
6213
|
-
* @param ref /public/val/example.png
|
|
6214
|
-
* @param metadata Image metadata: width, height, mimeType and optionally a hotspot.
|
|
6215
|
-
*/
|
|
6216
|
-
|
|
6217
|
-
/**
|
|
6218
|
-
* Define the source of an image file.
|
|
6219
|
-
*
|
|
6220
|
-
* NOTE: this will **not** validate since metadata has not been defined.
|
|
6221
|
-
*
|
|
6222
|
-
* Run `npx -p @valbuild/cli val validate --fix` to automatically add metadata.
|
|
6223
|
-
*
|
|
6224
|
-
* @example
|
|
6225
|
-
* c.image("/public/val/example.png")
|
|
6226
|
-
*
|
|
6227
|
-
* @param ref /public/val/example.png
|
|
6228
|
-
* @param metadata Image metadata: width, height, mimeType and optionally a hotspot.
|
|
6229
|
-
*/
|
|
6230
|
-
|
|
6231
|
-
/**
|
|
6232
|
-
* Define the source of an image file.
|
|
6233
|
-
*
|
|
6234
|
-
* @example
|
|
6235
|
-
* c.image("/public/val/example.png", {
|
|
6236
|
-
* width: 944,
|
|
6237
|
-
* height: 944,
|
|
6238
|
-
* mimeType: "image/png",
|
|
6239
|
-
*})
|
|
6240
|
-
*
|
|
6241
|
-
* @param ref /public/val/example.png
|
|
6242
|
-
* @param metadata Image metadata: width, height, mimeType and optionally a hotspot.
|
|
6243
|
-
*/
|
|
6244
|
-
function image(ref, metadata) {
|
|
6245
|
-
return _defineProperty(_defineProperty(_defineProperty(_defineProperty({}, FILE_REF_PROP, ref), VAL_EXTENSION, "file"), FILE_REF_SUBTYPE_TAG, "image"), "metadata", metadata);
|
|
6246
|
-
}
|
|
6247
|
-
return image;
|
|
6248
|
-
};
|
|
6249
|
-
|
|
6250
|
-
/**
|
|
6251
|
-
* A remote source represents data that is not stored locally.
|
|
6252
|
-
*/
|
|
6253
|
-
|
|
6254
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
6255
|
-
var initRemote = function initRemote(config) {
|
|
6256
|
-
function remote(ref, metadata) {
|
|
6257
|
-
return _defineProperty(_defineProperty(_defineProperty({}, FILE_REF_PROP, ref), VAL_EXTENSION, "remote"), "metadata", metadata);
|
|
6258
|
-
}
|
|
6259
|
-
return remote;
|
|
6260
|
-
};
|
|
6261
|
-
|
|
6262
|
-
// NOTE: the segments must match the ref built by createRemoteRef below and the RegEx in splitRemoteRef.
|
|
6263
|
-
|
|
6264
|
-
function createRemoteRef(remoteHost, _ref2) {
|
|
6265
|
-
var publicProjectId = _ref2.publicProjectId,
|
|
6266
|
-
coreVersion = _ref2.coreVersion,
|
|
6267
|
-
validationHash = _ref2.validationHash,
|
|
6268
|
-
fileHash = _ref2.fileHash,
|
|
6269
|
-
filePath = _ref2.filePath,
|
|
6270
|
-
bucket = _ref2.bucket;
|
|
6271
|
-
// 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.
|
|
6272
|
-
return "".concat(remoteHost, "/file/p/").concat(publicProjectId, "/b/").concat(bucket, "/v/").concat(coreVersion, "/h/").concat(validationHash, "/f/").concat(fileHash, "/p/").concat(filePath);
|
|
6273
|
-
}
|
|
6274
|
-
|
|
6275
6350
|
// import { i18n, I18n } from "./source/future/i18n";
|
|
6276
6351
|
// import { remote } from "./source/future/remote";
|
|
6277
6352
|
|
|
@@ -6308,9 +6383,6 @@ var initVal = function initVal(config) {
|
|
|
6308
6383
|
},
|
|
6309
6384
|
c: {
|
|
6310
6385
|
define: define,
|
|
6311
|
-
remote: initRemote(),
|
|
6312
|
-
file: initFile(config),
|
|
6313
|
-
image: initImage(config),
|
|
6314
6386
|
json: json
|
|
6315
6387
|
},
|
|
6316
6388
|
s: s,
|
|
@@ -6752,7 +6824,7 @@ function collectObjectRecursive(item, collector) {
|
|
|
6752
6824
|
* Extracts schemas and sources from a ValModules registry and computes the
|
|
6753
6825
|
* deterministic SHAs that the server and client both use to detect changes.
|
|
6754
6826
|
*
|
|
6755
|
-
* Used by ValOps on the server and by
|
|
6827
|
+
* Used by ValOps on the server and by `HostStore` on the client so the
|
|
6756
6828
|
* hash algorithm has a single source of truth.
|
|
6757
6829
|
*/
|
|
6758
6830
|
function extractValModules(_x) {
|
|
@@ -6928,25 +7000,106 @@ function _extractValModules() {
|
|
|
6928
7000
|
return _extractValModules.apply(this, arguments);
|
|
6929
7001
|
}
|
|
6930
7002
|
|
|
6931
|
-
|
|
6932
|
-
|
|
6933
|
-
|
|
6934
|
-
|
|
6935
|
-
|
|
6936
|
-
|
|
6937
|
-
|
|
6938
|
-
|
|
6939
|
-
|
|
6940
|
-
|
|
6941
|
-
|
|
7003
|
+
/**
|
|
7004
|
+
* Does this schema store any file remotely?
|
|
7005
|
+
*
|
|
7006
|
+
* The one answer to that question. There used to be two — `hasRemoteFileSchema`
|
|
7007
|
+
* in the server, gating whether `/save` demands remote credentials, and
|
|
7008
|
+
* `findRequiredRemoteFiles` in the Studio, gating the `/remote/settings` fetch —
|
|
7009
|
+
* and they disagreed about `s.images({ remote: true })`: the Studio's counted a
|
|
7010
|
+
* remote media record, the server's did not, because a media collection
|
|
7011
|
+
* serializes as a `record` of metadata rather than as an image schema.
|
|
7012
|
+
*
|
|
7013
|
+
* The server's answer was the wrong one, and silently so. With it false,
|
|
7014
|
+
* `/save` runs `saveOrUploadFiles` in `skip-remote` mode, and that mode does not
|
|
7015
|
+
* merely skip the upload — it drops every remote descriptor without an error. The
|
|
7016
|
+
* commit then lands a remote ref with no bytes behind it: a broken image, in the
|
|
7017
|
+
* repository, with nothing anywhere saying why.
|
|
7018
|
+
*
|
|
7019
|
+
* ## Why it stays a walk over the SERIALIZED schema
|
|
7020
|
+
*
|
|
7021
|
+
* Both callers have a `SerializedSchema` and not a `Schema`: the server reads
|
|
7022
|
+
* them out of `getSchemas()`, and the Studio is handed them by `host.receive`.
|
|
7023
|
+
* Asking the schema classes directly would mean a method on every one of them,
|
|
7024
|
+
* and the two places that need the answer cannot call it.
|
|
7025
|
+
*
|
|
7026
|
+
* ## Throwing
|
|
7027
|
+
*
|
|
7028
|
+
* The `never` assignment at the end is the point of the default branch: adding a
|
|
7029
|
+
* schema type without teaching this function about it must not compile. The throw
|
|
7030
|
+
* is what happens if one arrives anyway — which for a caller reading schemas out
|
|
7031
|
+
* of its own process should be impossible. A caller that cannot afford to throw
|
|
7032
|
+
* (the Studio, whose whole UI is downstream of this) catches it; returning `false`
|
|
7033
|
+
* instead would reintroduce exactly the silent skip described above.
|
|
7034
|
+
*/
|
|
7035
|
+
function hasRemoteFileSchema(schema) {
|
|
7036
|
+
if (schema.type === "file" || schema.type === "image") {
|
|
7037
|
+
return !!schema.remote;
|
|
7038
|
+
} else if (schema.type === "richtext") {
|
|
7039
|
+
var _schema$options;
|
|
7040
|
+
if (_typeof((_schema$options = schema.options) === null || _schema$options === void 0 || (_schema$options = _schema$options.inline) === null || _schema$options === void 0 ? void 0 : _schema$options.img) === "object") {
|
|
7041
|
+
return hasRemoteFileSchema(schema.options.inline.img);
|
|
7042
|
+
}
|
|
7043
|
+
return false;
|
|
7044
|
+
} else if (schema.type === "array") {
|
|
7045
|
+
return hasRemoteFileSchema(schema.item);
|
|
7046
|
+
} else if (schema.type === "record") {
|
|
7047
|
+
/**
|
|
7048
|
+
* A media collection — `s.images()` / `s.files()` — is the case both of the
|
|
7049
|
+
* old functions were written around, and the one they disagreed on.
|
|
7050
|
+
*
|
|
7051
|
+
* It has no file or image schema inside it to find: `item` is an object of
|
|
7052
|
+
* width/height/mimeType/alt, and the file itself is named by the record's
|
|
7053
|
+
* KEY. So `remote` on the record is the only place the answer is written
|
|
7054
|
+
* down, and recursing into `item` can only ever say no.
|
|
7055
|
+
*/
|
|
7056
|
+
if (schema.mediaType && schema.remote) {
|
|
7057
|
+
return true;
|
|
7058
|
+
}
|
|
7059
|
+
return hasRemoteFileSchema(schema.item);
|
|
7060
|
+
} else if (schema.type === "object") {
|
|
7061
|
+
for (var key in schema.items) {
|
|
7062
|
+
var hasRemoteFile = hasRemoteFileSchema(schema.items[key]);
|
|
7063
|
+
if (hasRemoteFile) {
|
|
7064
|
+
return true;
|
|
7065
|
+
}
|
|
7066
|
+
}
|
|
7067
|
+
return false;
|
|
7068
|
+
} else if (schema.type === "union") {
|
|
7069
|
+
var unionStringSchema = _typeof(schema.key) === "object" && schema.key.type === "literal" ? schema : undefined;
|
|
7070
|
+
var unionObjectSchema = typeof schema.key === "string" ? schema : undefined;
|
|
7071
|
+
if (unionStringSchema) {
|
|
7072
|
+
// A string union's items are literals, so there is nothing to look inside.
|
|
7073
|
+
return false;
|
|
7074
|
+
}
|
|
7075
|
+
if (unionObjectSchema) {
|
|
7076
|
+
var _iterator = _createForOfIteratorHelper(unionObjectSchema.items),
|
|
7077
|
+
_step;
|
|
7078
|
+
try {
|
|
7079
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
7080
|
+
var item = _step.value;
|
|
7081
|
+
var _hasRemoteFile = hasRemoteFileSchema(item);
|
|
7082
|
+
if (_hasRemoteFile) {
|
|
7083
|
+
return true;
|
|
7084
|
+
}
|
|
7085
|
+
}
|
|
7086
|
+
} catch (err) {
|
|
7087
|
+
_iterator.e(err);
|
|
7088
|
+
} finally {
|
|
7089
|
+
_iterator.f();
|
|
7090
|
+
}
|
|
6942
7091
|
}
|
|
7092
|
+
return false;
|
|
7093
|
+
} else if (schema.type === "boolean" || schema.type === "number" || schema.type === "string" || schema.type === "literal" || schema.type === "date" || schema.type === "dateTime" || schema.type === "color" || schema.type === "keyOf" || schema.type === "route") {
|
|
7094
|
+
return false;
|
|
7095
|
+
} else {
|
|
7096
|
+
var exhaustiveCheck = schema;
|
|
7097
|
+
throw new Error("Unexpected schema: ".concat(JSON.stringify(exhaustiveCheck)));
|
|
6943
7098
|
}
|
|
6944
|
-
return {
|
|
6945
|
-
url: src[FILE_REF_PROP],
|
|
6946
|
-
metadata: src.metadata
|
|
6947
|
-
};
|
|
6948
7099
|
}
|
|
6949
7100
|
|
|
7101
|
+
var DEFAULT_VAL_REMOTE_HOST = "https://remote.val.build";
|
|
7102
|
+
|
|
6950
7103
|
var PatchError = /*#__PURE__*/_createClass(function PatchError(message) {
|
|
6951
7104
|
_classCallCheck(this, PatchError);
|
|
6952
7105
|
this.message = message;
|
|
@@ -7015,14 +7168,15 @@ function derefPatch(patch, document, ops) {
|
|
|
7015
7168
|
var maybeValue = ops.get(document, dereffedPath);
|
|
7016
7169
|
if (isOk(maybeValue)) {
|
|
7017
7170
|
var value = maybeValue.value;
|
|
7018
|
-
|
|
7171
|
+
var mediaPath = mediaPathOf(value);
|
|
7172
|
+
if (mediaPath !== null) {
|
|
7019
7173
|
if (referencedPath.length > 0) {
|
|
7020
7174
|
return err(new PatchError("Cannot sub-reference file reference at path: ".concat(dereffedPath.join("/"))));
|
|
7021
7175
|
}
|
|
7022
7176
|
if (typeof op.value !== "string") {
|
|
7023
7177
|
return err(new PatchError("Expected base64 encoded string value for file reference, got ".concat(JSON.stringify(op.value))));
|
|
7024
7178
|
}
|
|
7025
|
-
fileUpdates[
|
|
7179
|
+
fileUpdates[mediaPath] = op.value;
|
|
7026
7180
|
// } else if (isRemote(value)) {
|
|
7027
7181
|
// if (!remotePatches[value[REMOTE_REF_PROP]]) {
|
|
7028
7182
|
// remotePatches[value[REMOTE_REF_PROP]] = [];
|
|
@@ -7073,6 +7227,21 @@ function derefPatch(patch, document, ops) {
|
|
|
7073
7227
|
});
|
|
7074
7228
|
}
|
|
7075
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
|
+
|
|
7076
7245
|
var EXT_TO_MIME_TYPES = {
|
|
7077
7246
|
x3d: "application/vnd.hzn-3d-crossword",
|
|
7078
7247
|
"3gp": "video/3gpp",
|
|
@@ -7796,6 +7965,19 @@ function filenameToMimeType(filename) {
|
|
|
7796
7965
|
}
|
|
7797
7966
|
}
|
|
7798
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
|
+
|
|
7799
7981
|
/**
|
|
7800
7982
|
* The validation basis is used in remote refs to determine if the remote content needs to be re-validated.
|
|
7801
7983
|
*
|
|
@@ -7920,6 +8102,94 @@ function deserializeSchemaImpl(serialized) {
|
|
|
7920
8102
|
}
|
|
7921
8103
|
}
|
|
7922
8104
|
|
|
8105
|
+
// TODO: we want to change layout -> as to be more consistent across the board
|
|
8106
|
+
|
|
8107
|
+
// Main render type:
|
|
8108
|
+
|
|
8109
|
+
//
|
|
8110
|
+
|
|
8111
|
+
/**
|
|
8112
|
+
* Which paths a render is being computed FOR.
|
|
8113
|
+
*
|
|
8114
|
+
* `executeRender` takes a whole module, so one request has always walked every
|
|
8115
|
+
* node in it and run every `select` closure — for `handboka`, with `select` at
|
|
8116
|
+
* two nested array levels, that is every chapter and every section to serve one
|
|
8117
|
+
* visible row. A scope is what makes the walk proportional to what is being
|
|
8118
|
+
* looked at instead of to the project.
|
|
8119
|
+
*
|
|
8120
|
+
* Two questions, because a container and its items need different answers:
|
|
8121
|
+
*
|
|
8122
|
+
* - {@link RenderScope.wants} — is a render AT this exact path wanted? A
|
|
8123
|
+
* container answers `true` here when the whole of it is being shown, and its
|
|
8124
|
+
* list render is then computed in full.
|
|
8125
|
+
* - {@link RenderScope.wantsUnder} — could anything at or below this path be
|
|
8126
|
+
* wanted? Recursion is pruned where this is `false`, and a container whose own
|
|
8127
|
+
* path is not wanted but which has wanted descendants renders a WINDOW: only
|
|
8128
|
+
* the items that were asked for. That is the case a single visible row is, and
|
|
8129
|
+
* it is why {@link ListArrayRender} carries indices.
|
|
8130
|
+
*
|
|
8131
|
+
* Absent scope means the whole module, which is what every existing caller
|
|
8132
|
+
* passes and what every existing caller got.
|
|
8133
|
+
*/
|
|
8134
|
+
|
|
8135
|
+
/**
|
|
8136
|
+
* A scope covering exactly `paths` and their subtrees.
|
|
8137
|
+
*
|
|
8138
|
+
* Compares SEGMENTS rather than string prefixes. A source path's module path is
|
|
8139
|
+
* a quoted, dot-joined encoding (`?p="a".1."b"`), so `startsWith` gets the
|
|
8140
|
+
* ancestor test wrong wherever a key is a prefix of a sibling key or contains a
|
|
8141
|
+
* dot or a quote — `"title"` against `"titles"` being the cheapest example.
|
|
8142
|
+
* Segments are parsed once here, not per comparison.
|
|
8143
|
+
*/
|
|
8144
|
+
function renderScope(paths) {
|
|
8145
|
+
var wanted = paths.map(function (path) {
|
|
8146
|
+
var _splitModuleFilePathA = splitModuleFilePathAndModulePath(path),
|
|
8147
|
+
_splitModuleFilePathA2 = _slicedToArray(_splitModuleFilePathA, 2),
|
|
8148
|
+
moduleFilePath = _splitModuleFilePathA2[0],
|
|
8149
|
+
modulePath = _splitModuleFilePathA2[1];
|
|
8150
|
+
return {
|
|
8151
|
+
moduleFilePath: moduleFilePath,
|
|
8152
|
+
segments: modulePath === "" ? [] : splitModulePath(modulePath)
|
|
8153
|
+
};
|
|
8154
|
+
});
|
|
8155
|
+
var parse = function parse(path) {
|
|
8156
|
+
var _splitModuleFilePathA3 = splitModuleFilePathAndModulePath(path),
|
|
8157
|
+
_splitModuleFilePathA4 = _slicedToArray(_splitModuleFilePathA3, 2),
|
|
8158
|
+
moduleFilePath = _splitModuleFilePathA4[0],
|
|
8159
|
+
modulePath = _splitModuleFilePathA4[1];
|
|
8160
|
+
return {
|
|
8161
|
+
moduleFilePath: moduleFilePath,
|
|
8162
|
+
segments: modulePath === "" ? [] : splitModulePath(modulePath)
|
|
8163
|
+
};
|
|
8164
|
+
};
|
|
8165
|
+
var isPrefix = function isPrefix(prefix, of) {
|
|
8166
|
+
if (prefix.length > of.length) return false;
|
|
8167
|
+
for (var i = 0; i < prefix.length; i++) {
|
|
8168
|
+
if (prefix[i] !== of[i]) return false;
|
|
8169
|
+
}
|
|
8170
|
+
return true;
|
|
8171
|
+
};
|
|
8172
|
+
return {
|
|
8173
|
+
wants: function wants(path) {
|
|
8174
|
+
var at = parse(path);
|
|
8175
|
+
return wanted.some(function (entry) {
|
|
8176
|
+
return entry.moduleFilePath === at.moduleFilePath && entry.segments.length === at.segments.length && isPrefix(entry.segments, at.segments);
|
|
8177
|
+
});
|
|
8178
|
+
},
|
|
8179
|
+
wantsUnder: function wantsUnder(path) {
|
|
8180
|
+
var at = parse(path);
|
|
8181
|
+
return wanted.some(function (entry) {
|
|
8182
|
+
return entry.moduleFilePath === at.moduleFilePath && (
|
|
8183
|
+
// Either direction: a wanted path below `path` means recurse into it,
|
|
8184
|
+
// and a wanted path ABOVE it means the whole subtree was asked for.
|
|
8185
|
+
isPrefix(at.segments, entry.segments) || isPrefix(entry.segments, at.segments));
|
|
8186
|
+
});
|
|
8187
|
+
}
|
|
8188
|
+
};
|
|
8189
|
+
}
|
|
8190
|
+
|
|
8191
|
+
// TODO: improve this so that we do not get RawString and string, only string. Are there other things?
|
|
8192
|
+
|
|
7923
8193
|
var externalPageRouter = {
|
|
7924
8194
|
getRouterId: function getRouterId() {
|
|
7925
8195
|
return "external-url-router";
|
|
@@ -8182,8 +8452,12 @@ var Internal = {
|
|
|
8182
8452
|
}
|
|
8183
8453
|
}()
|
|
8184
8454
|
},
|
|
8185
|
-
|
|
8186
|
-
|
|
8455
|
+
mediaUrl: mediaUrl,
|
|
8456
|
+
resolveMedia: resolveMedia,
|
|
8457
|
+
isRemoteMediaPath: isRemoteMediaPath,
|
|
8458
|
+
media: {
|
|
8459
|
+
fillFromGallery: fillFromGallery
|
|
8460
|
+
},
|
|
8187
8461
|
getSchema: getSchema,
|
|
8188
8462
|
getValPath: getValPath,
|
|
8189
8463
|
getSource: getSource,
|
|
@@ -8213,7 +8487,6 @@ var Internal = {
|
|
|
8213
8487
|
return val && ((_getSchema = getSchema(val)) === null || _getSchema === void 0 ? void 0 : _getSchema["executeValidate"](path, src));
|
|
8214
8488
|
},
|
|
8215
8489
|
isVal: isVal,
|
|
8216
|
-
isFile: isFile,
|
|
8217
8490
|
isJson: isJson,
|
|
8218
8491
|
getJsonImport: getJsonImport,
|
|
8219
8492
|
resolveJsonValues: resolveJsonValues,
|
|
@@ -8280,4 +8553,4 @@ function tryJsonParse(str) {
|
|
|
8280
8553
|
}
|
|
8281
8554
|
}
|
|
8282
8555
|
|
|
8283
|
-
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,
|
|
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 };
|