@valbuild/core 0.63.6 → 0.65.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/dist/declarations/src/expr/expr.d.ts +2 -2
  2. package/dist/declarations/src/expr/parser.d.ts +2 -2
  3. package/dist/declarations/src/index.d.ts +49 -94
  4. package/dist/declarations/src/initSchema.d.ts +19 -49
  5. package/dist/declarations/src/initVal.d.ts +8 -3
  6. package/dist/declarations/src/mimeType/all.d.ts +4 -0
  7. package/dist/declarations/src/mimeType/convertMimeType.d.ts +3 -0
  8. package/dist/declarations/src/mimeType/index.d.ts +2 -0
  9. package/dist/declarations/src/module.d.ts +6 -2
  10. package/dist/declarations/src/schema/array.d.ts +5 -5
  11. package/dist/declarations/src/schema/boolean.d.ts +2 -2
  12. package/dist/declarations/src/schema/date.d.ts +5 -5
  13. package/dist/declarations/src/schema/file.d.ts +5 -4
  14. package/dist/declarations/src/schema/image.d.ts +4 -4
  15. package/dist/declarations/src/schema/index.d.ts +44 -3
  16. package/dist/declarations/src/schema/keyOf.d.ts +9 -9
  17. package/dist/declarations/src/schema/literal.d.ts +3 -3
  18. package/dist/declarations/src/schema/number.d.ts +3 -3
  19. package/dist/declarations/src/schema/object.d.ts +5 -5
  20. package/dist/declarations/src/schema/record.d.ts +5 -5
  21. package/dist/declarations/src/schema/richtext.d.ts +6 -25
  22. package/dist/declarations/src/schema/string.d.ts +2 -2
  23. package/dist/declarations/src/schema/union.d.ts +18 -19
  24. package/dist/declarations/src/schema/validation/ValidationError.d.ts +2 -1
  25. package/dist/declarations/src/selector/SelectorProxy.d.ts +1 -0
  26. package/dist/declarations/src/source/file.d.ts +7 -4
  27. package/dist/declarations/src/source/richtext.d.ts +7 -0
  28. package/dist/declarations/src/val/index.d.ts +1 -1
  29. package/dist/{index-041f75bd.cjs.prod.js → index-48930c58.cjs.dev.js} +1842 -1050
  30. package/dist/{index-fccba617.esm.js → index-65ec1d74.esm.js} +1840 -1049
  31. package/dist/{index-c67ed8f9.cjs.dev.js → index-f1a23e6c.cjs.prod.js} +1842 -1050
  32. package/dist/{result-a8316efa.esm.js → result-168dfc1d.esm.js} +42 -46
  33. package/dist/{result-26f67b40.cjs.prod.js → result-787e35f6.cjs.prod.js} +41 -45
  34. package/dist/{result-48320acd.cjs.dev.js → result-bb1f436e.cjs.dev.js} +41 -45
  35. package/dist/valbuild-core.cjs.d.ts +2 -2
  36. package/dist/valbuild-core.cjs.dev.js +4 -3
  37. package/dist/valbuild-core.cjs.prod.js +4 -3
  38. package/dist/valbuild-core.esm.js +2 -2
  39. package/expr/dist/valbuild-core-expr.cjs.d.ts +2 -2
  40. package/expr/dist/valbuild-core-expr.cjs.dev.js +2 -2
  41. package/expr/dist/valbuild-core-expr.cjs.prod.js +2 -2
  42. package/expr/dist/valbuild-core-expr.esm.js +2 -2
  43. package/fp/dist/valbuild-core-fp.cjs.d.ts +2 -2
  44. package/fp/dist/valbuild-core-fp.cjs.dev.js +1 -1
  45. package/fp/dist/valbuild-core-fp.cjs.prod.js +1 -1
  46. package/fp/dist/valbuild-core-fp.esm.js +1 -1
  47. package/package.json +1 -1
  48. package/patch/dist/valbuild-core-patch.cjs.d.ts +2 -2
  49. package/patch/dist/valbuild-core-patch.cjs.dev.js +8 -9
  50. package/patch/dist/valbuild-core-patch.cjs.prod.js +8 -9
  51. package/patch/dist/valbuild-core-patch.esm.js +9 -10
  52. package/dist/declarations/src/ValApi.d.ts +0 -54
  53. package/dist/valbuild-core.cjs.d.ts.map +0 -1
  54. package/expr/dist/valbuild-core-expr.cjs.d.ts.map +0 -1
  55. package/fp/dist/valbuild-core-fp.cjs.d.ts.map +0 -1
  56. package/patch/dist/valbuild-core-patch.cjs.d.ts.map +0 -1
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var result = require('./result-26f67b40.cjs.prod.js');
3
+ var result = require('./result-bb1f436e.cjs.dev.js');
4
4
  var marked = require('marked');
5
5
  var core = require('@valbuild/core');
6
6
 
@@ -24,20 +24,60 @@ function _interopNamespace(e) {
24
24
 
25
25
  var marked__namespace = /*#__PURE__*/_interopNamespace(marked);
26
26
 
27
- function _arrayWithoutHoles(arr) {
28
- if (Array.isArray(arr)) return result._arrayLikeToArray(arr);
27
+ function _arrayWithHoles(r) {
28
+ if (Array.isArray(r)) return r;
29
29
  }
30
30
 
31
- function _iterableToArray(iter) {
32
- if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
31
+ function _iterableToArrayLimit(r, l) {
32
+ var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
33
+ if (null != t) {
34
+ var e,
35
+ n,
36
+ i,
37
+ u,
38
+ a = [],
39
+ f = !0,
40
+ o = !1;
41
+ try {
42
+ if (i = (t = t.call(r)).next, 0 === l) {
43
+ if (Object(t) !== t) return;
44
+ f = !1;
45
+ } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
46
+ } catch (r) {
47
+ o = !0, n = r;
48
+ } finally {
49
+ try {
50
+ if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
51
+ } finally {
52
+ if (o) throw n;
53
+ }
54
+ }
55
+ return a;
56
+ }
57
+ }
58
+
59
+ function _nonIterableRest() {
60
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
61
+ }
62
+
63
+ function _slicedToArray(r, e) {
64
+ return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || result._unsupportedIterableToArray(r, e) || _nonIterableRest();
65
+ }
66
+
67
+ function _arrayWithoutHoles(r) {
68
+ if (Array.isArray(r)) return result._arrayLikeToArray(r);
69
+ }
70
+
71
+ function _iterableToArray(r) {
72
+ if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
33
73
  }
34
74
 
35
75
  function _nonIterableSpread() {
36
76
  throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
37
77
  }
38
78
 
39
- function _toConsumableArray(arr) {
40
- return _arrayWithoutHoles(arr) || _iterableToArray(arr) || result._unsupportedIterableToArray(arr) || _nonIterableSpread();
79
+ function _toConsumableArray(r) {
80
+ return _arrayWithoutHoles(r) || _iterableToArray(r) || result._unsupportedIterableToArray(r) || _nonIterableSpread();
41
81
  }
42
82
 
43
83
  function _typeof(o) {
@@ -50,7 +90,7 @@ function _typeof(o) {
50
90
  }, _typeof(o);
51
91
  }
52
92
 
53
- function toPrimitive(t, r) {
93
+ function _toPrimitive(t, r) {
54
94
  if ("object" != typeof t || !t) return t;
55
95
  var e = t[Symbol.toPrimitive];
56
96
  if (void 0 !== e) {
@@ -61,24 +101,18 @@ function toPrimitive(t, r) {
61
101
  return ("string" === r ? String : Number)(t);
62
102
  }
63
103
 
64
- function toPropertyKey(t) {
65
- var i = toPrimitive(t, "string");
66
- return "symbol" == typeof i ? i : String(i);
104
+ function _toPropertyKey(t) {
105
+ var i = _toPrimitive(t, "string");
106
+ return "symbol" == typeof i ? i : i + "";
67
107
  }
68
108
 
69
- function _defineProperty(obj, key, value) {
70
- key = toPropertyKey(key);
71
- if (key in obj) {
72
- Object.defineProperty(obj, key, {
73
- value: value,
74
- enumerable: true,
75
- configurable: true,
76
- writable: true
77
- });
78
- } else {
79
- obj[key] = value;
80
- }
81
- return obj;
109
+ function _defineProperty(e, r, t) {
110
+ return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
111
+ value: t,
112
+ enumerable: !0,
113
+ configurable: !0,
114
+ writable: !0
115
+ }) : e[r] = t, e;
82
116
  }
83
117
 
84
118
  function ownKeys(e, r) {
@@ -103,75 +137,26 @@ function _objectSpread2(e) {
103
137
  return e;
104
138
  }
105
139
 
106
- function _arrayWithHoles(arr) {
107
- if (Array.isArray(arr)) return arr;
140
+ function _classCallCheck(a, n) {
141
+ if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
108
142
  }
109
143
 
110
- function _iterableToArrayLimit(r, l) {
111
- var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
112
- if (null != t) {
113
- var e,
114
- n,
115
- i,
116
- u,
117
- a = [],
118
- f = !0,
119
- o = !1;
120
- try {
121
- if (i = (t = t.call(r)).next, 0 === l) {
122
- if (Object(t) !== t) return;
123
- f = !1;
124
- } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
125
- } catch (r) {
126
- o = !0, n = r;
127
- } finally {
128
- try {
129
- if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
130
- } finally {
131
- if (o) throw n;
132
- }
133
- }
134
- return a;
135
- }
136
- }
137
-
138
- function _nonIterableRest() {
139
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
140
- }
141
-
142
- function _slicedToArray(arr, i) {
143
- return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || result._unsupportedIterableToArray(arr, i) || _nonIterableRest();
144
- }
145
-
146
- function _classCallCheck(instance, Constructor) {
147
- if (!(instance instanceof Constructor)) {
148
- throw new TypeError("Cannot call a class as a function");
144
+ function _defineProperties(e, r) {
145
+ for (var t = 0; t < r.length; t++) {
146
+ var o = r[t];
147
+ o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o);
149
148
  }
150
149
  }
151
-
152
- function _defineProperties(target, props) {
153
- for (var i = 0; i < props.length; i++) {
154
- var descriptor = props[i];
155
- descriptor.enumerable = descriptor.enumerable || false;
156
- descriptor.configurable = true;
157
- if ("value" in descriptor) descriptor.writable = true;
158
- Object.defineProperty(target, toPropertyKey(descriptor.key), descriptor);
159
- }
160
- }
161
- function _createClass(Constructor, protoProps, staticProps) {
162
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
163
- if (staticProps) _defineProperties(Constructor, staticProps);
164
- Object.defineProperty(Constructor, "prototype", {
165
- writable: false
166
- });
167
- return Constructor;
150
+ function _createClass(e, r, t) {
151
+ return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {
152
+ writable: !1
153
+ }), e;
168
154
  }
169
155
 
170
- function _getPrototypeOf(o) {
171
- _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
172
- return o.__proto__ || Object.getPrototypeOf(o);
173
- };
174
- return _getPrototypeOf(o);
156
+ function _getPrototypeOf(t) {
157
+ return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) {
158
+ return t.__proto__ || Object.getPrototypeOf(t);
159
+ }, _getPrototypeOf(t);
175
160
  }
176
161
 
177
162
  function _isNativeReflectConstruct() {
@@ -183,49 +168,38 @@ function _isNativeReflectConstruct() {
183
168
  })();
184
169
  }
185
170
 
186
- function _assertThisInitialized(self) {
187
- if (self === void 0) {
188
- throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
189
- }
190
- return self;
171
+ function _assertThisInitialized(e) {
172
+ if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
173
+ return e;
191
174
  }
192
175
 
193
- function _possibleConstructorReturn(self, call) {
194
- if (call && (typeof call === "object" || typeof call === "function")) {
195
- return call;
196
- } else if (call !== void 0) {
197
- throw new TypeError("Derived constructors may only return object or undefined");
198
- }
199
- return _assertThisInitialized(self);
176
+ function _possibleConstructorReturn(t, e) {
177
+ if (e && ("object" == typeof e || "function" == typeof e)) return e;
178
+ if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined");
179
+ return _assertThisInitialized(t);
200
180
  }
201
181
 
202
182
  function _callSuper(t, o, e) {
203
183
  return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e));
204
184
  }
205
185
 
206
- function _setPrototypeOf(o, p) {
207
- _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
208
- o.__proto__ = p;
209
- return o;
210
- };
211
- return _setPrototypeOf(o, p);
186
+ function _setPrototypeOf(t, e) {
187
+ return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
188
+ return t.__proto__ = e, t;
189
+ }, _setPrototypeOf(t, e);
212
190
  }
213
191
 
214
- function _inherits(subClass, superClass) {
215
- if (typeof superClass !== "function" && superClass !== null) {
216
- throw new TypeError("Super expression must either be null or a function");
217
- }
218
- subClass.prototype = Object.create(superClass && superClass.prototype, {
192
+ function _inherits(t, e) {
193
+ if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function");
194
+ t.prototype = Object.create(e && e.prototype, {
219
195
  constructor: {
220
- value: subClass,
221
- writable: true,
222
- configurable: true
196
+ value: t,
197
+ writable: !0,
198
+ configurable: !0
223
199
  }
224
- });
225
- Object.defineProperty(subClass, "prototype", {
226
- writable: false
227
- });
228
- if (superClass) _setPrototypeOf(subClass, superClass);
200
+ }), Object.defineProperty(t, "prototype", {
201
+ writable: !1
202
+ }), e && _setPrototypeOf(t, e);
229
203
  }
230
204
 
231
205
  // import { RemoteCompatibleSource, RemoteSource } from "../source/remote";
@@ -237,7 +211,7 @@ var Schema = /*#__PURE__*/function () {
237
211
  function Schema() {
238
212
  _classCallCheck(this, Schema);
239
213
  }
240
- _createClass(Schema, [{
214
+ return _createClass(Schema, [{
241
215
  key: "appendValidationError",
242
216
  value:
243
217
  // remote(): Src extends RemoteCompatibleSource
@@ -270,7 +244,6 @@ var Schema = /*#__PURE__*/function () {
270
244
  }
271
245
  }
272
246
  }]);
273
- return Schema;
274
247
  }();
275
248
 
276
249
  // TODO: SourceError<"Could not determine type of Schema">
@@ -317,53 +290,51 @@ var Expr = /*#__PURE__*/_createClass(function Expr(span) {
317
290
  this.span = span;
318
291
  });
319
292
  var StringLiteral = /*#__PURE__*/function (_Expr) {
320
- _inherits(StringLiteral, _Expr);
321
293
  function StringLiteral(value, span) {
322
294
  var _this;
323
295
  _classCallCheck(this, StringLiteral);
324
296
  _this = _callSuper(this, StringLiteral, [span]);
325
- _defineProperty(_assertThisInitialized(_this), "type", "StringLiteral");
297
+ _defineProperty(_this, "type", "StringLiteral");
326
298
  _this.value = value;
327
299
  return _this;
328
300
  }
329
- _createClass(StringLiteral, [{
301
+ _inherits(StringLiteral, _Expr);
302
+ return _createClass(StringLiteral, [{
330
303
  key: "transpile",
331
304
  value: function transpile() {
332
305
  return "'".concat(this.value, "'");
333
306
  }
334
307
  }]);
335
- return StringLiteral;
336
308
  }(Expr);
337
309
  var Sym = /*#__PURE__*/function (_Expr2) {
338
- _inherits(Sym, _Expr2);
339
310
  function Sym(value, span) {
340
311
  var _this2;
341
312
  _classCallCheck(this, Sym);
342
313
  _this2 = _callSuper(this, Sym, [span]);
343
- _defineProperty(_assertThisInitialized(_this2), "type", "Sym");
314
+ _defineProperty(_this2, "type", "Sym");
344
315
  _this2.value = value;
345
316
  return _this2;
346
317
  }
347
- _createClass(Sym, [{
318
+ _inherits(Sym, _Expr2);
319
+ return _createClass(Sym, [{
348
320
  key: "transpile",
349
321
  value: function transpile() {
350
322
  return this.value;
351
323
  }
352
324
  }]);
353
- return Sym;
354
325
  }(Expr);
355
326
  var NilSym = new Sym("()");
356
327
  var StringTemplate = /*#__PURE__*/function (_Expr3) {
357
- _inherits(StringTemplate, _Expr3);
358
328
  function StringTemplate(children, span) {
359
329
  var _this3;
360
330
  _classCallCheck(this, StringTemplate);
361
331
  _this3 = _callSuper(this, StringTemplate, [span]);
362
- _defineProperty(_assertThisInitialized(_this3), "type", "StringTemplate");
332
+ _defineProperty(_this3, "type", "StringTemplate");
363
333
  _this3.children = children;
364
334
  return _this3;
365
335
  }
366
- _createClass(StringTemplate, [{
336
+ _inherits(StringTemplate, _Expr3);
337
+ return _createClass(StringTemplate, [{
367
338
  key: "transpile",
368
339
  value: function transpile() {
369
340
  return "'".concat(this.children.map(function (child) {
@@ -375,20 +346,19 @@ var StringTemplate = /*#__PURE__*/function (_Expr3) {
375
346
  }).join(""), "'");
376
347
  }
377
348
  }]);
378
- return StringTemplate;
379
349
  }(Expr);
380
350
  var Call = /*#__PURE__*/function (_Expr4) {
381
- _inherits(Call, _Expr4);
382
351
  function Call(children, isAnon, span) {
383
352
  var _this4;
384
353
  _classCallCheck(this, Call);
385
354
  _this4 = _callSuper(this, Call, [span]);
386
- _defineProperty(_assertThisInitialized(_this4), "type", "Call");
355
+ _defineProperty(_this4, "type", "Call");
387
356
  _this4.children = children;
388
357
  _this4.isAnon = isAnon;
389
358
  return _this4;
390
359
  }
391
- _createClass(Call, [{
360
+ _inherits(Call, _Expr4);
361
+ return _createClass(Call, [{
392
362
  key: "transpile",
393
363
  value: function transpile() {
394
364
  if (this.isAnon) {
@@ -401,7 +371,6 @@ var Call = /*#__PURE__*/function (_Expr4) {
401
371
  }).join(" "), ")");
402
372
  }
403
373
  }]);
404
- return Call;
405
374
  }(Expr);
406
375
 
407
376
  /* Branded extension types: file, remote, i18n */
@@ -428,15 +397,49 @@ var FILE_REF_SUBTYPE_TAG = "_tag"; // TODO: used earlier by c.rt.image, when we
428
397
  *
429
398
  */
430
399
 
431
- function file$1(ref, metadata) {
432
- return _defineProperty(_defineProperty(_defineProperty({}, FILE_REF_PROP, ref), VAL_EXTENSION, "file"), "metadata", metadata);
433
- }
400
+ var initFile = function initFile(config) {
401
+ var _config$files$directo, _config$files;
402
+ (_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";
403
+ function file(ref, metadata) {
404
+ return _defineProperty(_defineProperty(_defineProperty({}, FILE_REF_PROP, ref), VAL_EXTENSION, "file"), "metadata", metadata);
405
+ }
406
+ return file;
407
+ };
408
+
409
+ // type Directory =
410
+ // | (typeof config extends { files: { directory: infer D } } ? D : never)
411
+ // | `/public/val`;
412
+ // console.log("path", config);
413
+ // const userSpecifiedDirectory: Directory = config ?? "/public/val";
414
+
415
+ // const directory = userSpecifiedDirectory;
416
+
417
+ // export function file<Metadata extends { readonly [key: string]: Json }>(
418
+ // ref: `${typeof directory}/${string}`,
419
+ // metadata: Metadata
420
+ // ): FileSource<Metadata>;
421
+ // export function file(
422
+ // ref: `${typeof directory}/${string}`,
423
+ // metadata?: undefined
424
+ // ): FileSource<undefined>;
425
+ // export function file<
426
+ // Metadata extends { readonly [key: string]: Json } | undefined
427
+ // >(
428
+ // ref: `${typeof directory}/${string}`,
429
+ // metadata?: Metadata
430
+ // ): FileSource<Metadata> {
431
+ // return {
432
+ // [FILE_REF_PROP]: ref,
433
+ // [VAL_EXTENSION]: "file",
434
+ // metadata,
435
+ // } as FileSource<Metadata>;
436
+ // }
437
+
434
438
  function isFile(obj) {
435
439
  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";
436
440
  }
437
441
 
438
442
  var FileSchema = /*#__PURE__*/function (_Schema) {
439
- _inherits(FileSchema, _Schema);
440
443
  function FileSchema(options) {
441
444
  var _this;
442
445
  var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
@@ -446,7 +449,8 @@ var FileSchema = /*#__PURE__*/function (_Schema) {
446
449
  _this.opt = opt;
447
450
  return _this;
448
451
  }
449
- _createClass(FileSchema, [{
452
+ _inherits(FileSchema, _Schema);
453
+ return _createClass(FileSchema, [{
450
454
  key: "validate",
451
455
  value: function validate(path, src) {
452
456
  if (this.opt && (src === null || src === undefined)) {
@@ -470,9 +474,53 @@ var FileSchema = /*#__PURE__*/function (_Schema) {
470
474
  value: src
471
475
  }]);
472
476
  }
477
+ var _ref4 = this.options || {},
478
+ accept = _ref4.accept;
479
+ var _ref5 = src.metadata || {},
480
+ mimeType = _ref5.mimeType;
481
+ if (accept && mimeType && !mimeType.includes("/")) {
482
+ return _defineProperty({}, path, [{
483
+ message: "Invalid mime type format. Got: ".concat(mimeType),
484
+ value: src
485
+ }]);
486
+ }
487
+ if (accept && mimeType && mimeType.includes("/")) {
488
+ var acceptedTypes = accept.split(",").map(function (type) {
489
+ return type.trim();
490
+ });
491
+ var isValidMimeType = acceptedTypes.some(function (acceptedType) {
492
+ if (acceptedType === "*/*") {
493
+ return true;
494
+ }
495
+ if (acceptedType.endsWith("/*")) {
496
+ var baseType = acceptedType.slice(0, -2);
497
+ return mimeType.startsWith(baseType);
498
+ }
499
+ return acceptedType === mimeType;
500
+ });
501
+ if (!isValidMimeType) {
502
+ return _defineProperty({}, path, [{
503
+ message: "Mime type mismatch. Found '".concat(mimeType, "' but schema accepts '").concat(accept, "'"),
504
+ value: src
505
+ }]);
506
+ }
507
+ }
508
+ var fileMimeType = Internal.filenameToMimeType(src[FILE_REF_PROP]);
509
+ if (!fileMimeType) {
510
+ return _defineProperty({}, path, [{
511
+ message: "Could not determine mime type from file extension. Got: ".concat(src[FILE_REF_PROP]),
512
+ value: src
513
+ }]);
514
+ }
515
+ if (fileMimeType !== mimeType) {
516
+ return _defineProperty({}, path, [{
517
+ message: "Mime type and file extension not matching. Mime type is '".concat(mimeType, "' but file extension is '").concat(fileMimeType, "'"),
518
+ value: src
519
+ }]);
520
+ }
473
521
  if (src.metadata) {
474
522
  return _defineProperty({}, path, [{
475
- message: "Found metadata, but it could not be validated. File metadata must be an object with the required props: width (positive number), height (positive number) and sha256 (string of length 64 of the base16 hash).",
523
+ message: "Found metadata, but it could not be validated. File metadata must be an object with the mimeType.",
476
524
  // 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.
477
525
  value: src,
478
526
  fixes: ["file:check-metadata"]
@@ -486,11 +534,53 @@ var FileSchema = /*#__PURE__*/function (_Schema) {
486
534
  }
487
535
  }, {
488
536
  key: "assert",
489
- value: function assert(src) {
490
- if (this.opt && (src === null || src === undefined)) {
491
- return true;
537
+ value: function assert(path, src) {
538
+ if (this.opt && src === null) {
539
+ return {
540
+ success: true,
541
+ data: src
542
+ };
543
+ }
544
+ if (src === null) {
545
+ return {
546
+ success: false,
547
+ errors: _defineProperty({}, path, [{
548
+ message: "Expected 'object', got 'null'",
549
+ typeError: true
550
+ }])
551
+ };
492
552
  }
493
- return (src === null || src === void 0 ? void 0 : src[FILE_REF_PROP]) === "file" && (src === null || src === void 0 ? void 0 : src[VAL_EXTENSION]) === "file";
553
+ if (_typeof(src) !== "object") {
554
+ return {
555
+ success: false,
556
+ errors: _defineProperty({}, path, [{
557
+ message: "Expected object, got '".concat(_typeof(src), "'"),
558
+ typeError: true
559
+ }])
560
+ };
561
+ }
562
+ if (!(FILE_REF_PROP in src)) {
563
+ return {
564
+ success: false,
565
+ errors: _defineProperty({}, path, [{
566
+ message: "Value of this schema must use: 'c.file' (error type: missing_ref_prop)",
567
+ typeError: true
568
+ }])
569
+ };
570
+ }
571
+ if (!(VAL_EXTENSION in src && src[VAL_EXTENSION] === "file")) {
572
+ return {
573
+ success: false,
574
+ errors: _defineProperty({}, path, [{
575
+ message: "Value of this schema must use: 'c.file' (error type: missing_file_extension)",
576
+ typeError: true
577
+ }])
578
+ };
579
+ }
580
+ return {
581
+ success: true,
582
+ data: src
583
+ };
494
584
  }
495
585
  }, {
496
586
  key: "nullable",
@@ -507,25 +597,26 @@ var FileSchema = /*#__PURE__*/function (_Schema) {
507
597
  };
508
598
  }
509
599
  }]);
510
- return FileSchema;
511
600
  }(Schema);
512
601
  var file = function file(options) {
513
602
  return new FileSchema(options);
514
603
  };
515
604
  function convertFileSource(src) {
516
- var _src$metadata4, _src$metadata5, _src$metadata6;
517
605
  // TODO: /public should be configurable
518
606
  if (!src[FILE_REF_PROP].startsWith("/public")) {
519
- var _src$metadata, _src$metadata2, _src$metadata3;
520
607
  return {
521
- url: src[FILE_REF_PROP] + ((_src$metadata = src.metadata) !== null && _src$metadata !== void 0 && _src$metadata.sha256 ? "?sha256=".concat((_src$metadata2 = src.metadata) === null || _src$metadata2 === void 0 ? void 0 : _src$metadata2.sha256) : "") + (
522
- // TODO: remove sha256? we do not need anymore
523
- src.patch_id ? "".concat((_src$metadata3 = src.metadata) !== null && _src$metadata3 !== void 0 && _src$metadata3.sha256 ? "&" : "?", "patch_id=").concat(src["patch_id"]) : ""),
608
+ url: src[FILE_REF_PROP] + (src.patch_id ? "?patch_id=".concat(src["patch_id"]) : ""),
609
+ metadata: src.metadata
610
+ };
611
+ }
612
+ if (src.patch_id) {
613
+ return {
614
+ url: "/api/val/files" + src[FILE_REF_PROP] + "?patch_id=".concat(src["patch_id"]),
524
615
  metadata: src.metadata
525
616
  };
526
617
  }
527
618
  return {
528
- url: src[FILE_REF_PROP].slice("/public".length) + ((_src$metadata4 = src.metadata) !== null && _src$metadata4 !== void 0 && _src$metadata4.sha256 ? "?sha256=".concat((_src$metadata5 = src.metadata) === null || _src$metadata5 === void 0 ? void 0 : _src$metadata5.sha256) : "") + (src.patch_id ? "".concat((_src$metadata6 = src.metadata) !== null && _src$metadata6 !== void 0 && _src$metadata6.sha256 ? "&" : "?", "patch_id=").concat(src["patch_id"]) : ""),
619
+ url: src[FILE_REF_PROP].slice("/public".length),
529
620
  metadata: src.metadata
530
621
  };
531
622
  }
@@ -635,7 +726,7 @@ function newSelectorProxy$1(source, path, moduleSchema) {
635
726
  return newSelectorProxy$1(a, createValPathOfItem(path, i), moduleSchema === null || moduleSchema === void 0 ? void 0 : moduleSchema.item);
636
727
  }).filter(function (a) {
637
728
  if (f && f instanceof Schema) {
638
- return f.assert(unValify$1(a));
729
+ return f.assert(path || "", unValify$1(a)).success;
639
730
  } else {
640
731
  return unValify$1(f(a));
641
732
  }
@@ -702,6 +793,20 @@ function createValPathOfItem(arrayPath, prop) {
702
793
  return "".concat(arrayPath).concat(Internal.ModuleFilePathSep).concat(JSON.stringify(prop));
703
794
  }
704
795
 
796
+ // TODO: replace createValPathOfItem everywhere with this newer implementation (that does not return undefined but throws)
797
+ function unsafeCreateSourcePath(path, itemKey) {
798
+ if (_typeof(itemKey) === "symbol") {
799
+ throw Error("Cannot create val path of array item with symbol prop: ".concat(itemKey.toString()));
800
+ }
801
+ if (!path) {
802
+ throw Error("Cannot create val path of array item of empty or missing path: ".concat(path, ". Item: ").concat(itemKey));
803
+ }
804
+ if (path.includes(Internal.ModuleFilePathSep)) {
805
+ return "".concat(path, ".").concat(JSON.stringify(itemKey));
806
+ }
807
+ return "".concat(path).concat(Internal.ModuleFilePathSep).concat(JSON.stringify(itemKey));
808
+ }
809
+
705
810
  // TODO: could we do .val on the objects instead?
706
811
  function unValify$1(valueOrSelector) {
707
812
  if (_typeof(valueOrSelector) === "object" && (GetSource in valueOrSelector || Path$1 in valueOrSelector)) {
@@ -712,7 +817,6 @@ function unValify$1(valueOrSelector) {
712
817
  }
713
818
 
714
819
  var ObjectSchema = /*#__PURE__*/function (_Schema) {
715
- _inherits(ObjectSchema, _Schema);
716
820
  function ObjectSchema(items) {
717
821
  var _this;
718
822
  var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
@@ -722,7 +826,8 @@ var ObjectSchema = /*#__PURE__*/function (_Schema) {
722
826
  _this.opt = opt;
723
827
  return _this;
724
828
  }
725
- _createClass(ObjectSchema, [{
829
+ _inherits(ObjectSchema, _Schema);
830
+ return _createClass(ObjectSchema, [{
726
831
  key: "validate",
727
832
  value: function validate(path, src) {
728
833
  var _this2 = this;
@@ -732,6 +837,11 @@ var ObjectSchema = /*#__PURE__*/function (_Schema) {
732
837
  if (this.opt && (src === null || src === undefined)) {
733
838
  return false;
734
839
  }
840
+ if (src === null) {
841
+ return _defineProperty({}, path, [{
842
+ message: "Expected 'object', got 'null'"
843
+ }]);
844
+ }
735
845
  if (_typeof(src) !== "object") {
736
846
  return _defineProperty({}, path, [{
737
847
  message: "Expected 'object', got '".concat(_typeof(src), "'")
@@ -741,10 +851,10 @@ var ObjectSchema = /*#__PURE__*/function (_Schema) {
741
851
  message: "Expected 'object', got 'array'"
742
852
  }]);
743
853
  }
744
- Object.entries(this.items).forEach(function (_ref3) {
745
- var _ref4 = _slicedToArray(_ref3, 2),
746
- key = _ref4[0],
747
- schema = _ref4[1];
854
+ Object.entries(this.items).forEach(function (_ref4) {
855
+ var _ref5 = _slicedToArray(_ref4, 2),
856
+ key = _ref5[0],
857
+ schema = _ref5[1];
748
858
  var subPath = createValPathOfItem(path, key);
749
859
  if (!subPath) {
750
860
  error = _this2.appendValidationError(error, path, "Internal error: could not create path at ".concat(!path && typeof path === "string" ? "<empty string>" : path, " at key ").concat(key),
@@ -763,22 +873,66 @@ var ObjectSchema = /*#__PURE__*/function (_Schema) {
763
873
  }
764
874
  }, {
765
875
  key: "assert",
766
- value: function assert(src) {
767
- if (this.opt && (src === null || src === undefined)) {
768
- return true;
876
+ value: function assert(path, src) {
877
+ if (this.opt && src === null) {
878
+ return {
879
+ success: true,
880
+ data: src
881
+ };
769
882
  }
770
- if (!src) {
771
- return false;
883
+ if (src === null) {
884
+ return {
885
+ success: false,
886
+ errors: _defineProperty({}, path, [{
887
+ message: "Expected 'object', got 'null'",
888
+ typeError: true
889
+ }])
890
+ };
772
891
  }
773
- for (var _i = 0, _Object$entries = Object.entries(this.items); _i < _Object$entries.length; _i++) {
774
- var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
775
- _key = _Object$entries$_i[0],
776
- schema = _Object$entries$_i[1];
777
- if (!schema.assert(src[_key])) {
778
- return false;
892
+ if (_typeof(src) !== "object") {
893
+ return {
894
+ success: false,
895
+ errors: _defineProperty({}, path, [{
896
+ message: "Expected 'object', got '".concat(_typeof(src), "'"),
897
+ typeError: true
898
+ }])
899
+ };
900
+ } else if (Array.isArray(src)) {
901
+ return {
902
+ success: false,
903
+ errors: _defineProperty({}, path, [{
904
+ message: "Expected 'object', got 'array'",
905
+ typeError: true
906
+ }])
907
+ };
908
+ }
909
+ var errorsAtPath = [];
910
+ for (var _i = 0, _Object$keys = Object.keys(this.items); _i < _Object$keys.length; _i++) {
911
+ var _key = _Object$keys[_i];
912
+ var subPath = createValPathOfItem(path, _key);
913
+ if (!subPath) {
914
+ errorsAtPath.push({
915
+ message: "Internal error: could not create path at ".concat(!path && typeof path === "string" ? "<empty string>" : path, " at key ").concat(_key),
916
+ // Should! never happen
917
+ internalError: true
918
+ });
919
+ } else if (!(_key in src)) {
920
+ errorsAtPath.push({
921
+ message: "Expected key '".concat(_key, "' not found in object"),
922
+ typeError: true
923
+ });
779
924
  }
780
925
  }
781
- return _typeof(src) === "object" && !Array.isArray(src);
926
+ if (errorsAtPath.length > 0) {
927
+ return {
928
+ success: false,
929
+ errors: _defineProperty({}, path, errorsAtPath)
930
+ };
931
+ }
932
+ return {
933
+ success: true,
934
+ data: src
935
+ };
782
936
  }
783
937
  }, {
784
938
  key: "nullable",
@@ -790,17 +944,16 @@ var ObjectSchema = /*#__PURE__*/function (_Schema) {
790
944
  value: function serialize() {
791
945
  return {
792
946
  type: "object",
793
- items: Object.fromEntries(Object.entries(this.items).map(function (_ref5) {
794
- var _ref6 = _slicedToArray(_ref5, 2),
795
- key = _ref6[0],
796
- schema = _ref6[1];
947
+ items: Object.fromEntries(Object.entries(this.items).map(function (_ref6) {
948
+ var _ref7 = _slicedToArray(_ref6, 2),
949
+ key = _ref7[0],
950
+ schema = _ref7[1];
797
951
  return [key, schema.serialize()];
798
952
  })),
799
953
  opt: this.opt
800
954
  };
801
955
  }
802
956
  }]);
803
- return ObjectSchema;
804
957
  }(Schema);
805
958
  var object = function object(schema) {
806
959
  return new ObjectSchema(schema);
@@ -833,7 +986,7 @@ function tokenize(input) {
833
986
  });
834
987
  cursor++;
835
988
  } else if (_char === "'" || _char === "}") {
836
- var _start = cursor;
989
+ var start = cursor;
837
990
  var value = "";
838
991
  var unescapedValue = "";
839
992
  var escaped = false;
@@ -876,7 +1029,7 @@ function tokenize(input) {
876
1029
  if (value) {
877
1030
  tokens.push(_objectSpread2({
878
1031
  type: "string",
879
- span: [_start + 1, cursor - cursorOffset],
1032
+ span: [start + 1, cursor - cursorOffset],
880
1033
  value: value
881
1034
  }, unescapedValue !== value && {
882
1035
  unescapedValue: unescapedValue
@@ -894,17 +1047,17 @@ function tokenize(input) {
894
1047
  });
895
1048
  }
896
1049
  } else if (WHITE_SPACE.includes(_char)) {
897
- var _start2 = cursor;
1050
+ var _start = cursor;
898
1051
  while (WHITE_SPACE.includes(input[cursor]) && cursor < input.length) {
899
1052
  cursor++;
900
1053
  }
901
1054
  tokens.push({
902
1055
  type: "ws",
903
- span: [_start2, cursor - 1]
1056
+ span: [_start, cursor - 1]
904
1057
  });
905
1058
  } else {
906
1059
  var _value = "";
907
- var _start3 = cursor;
1060
+ var _start2 = cursor;
908
1061
  do {
909
1062
  _char = input[cursor];
910
1063
  peek = input[cursor + 1];
@@ -913,7 +1066,7 @@ function tokenize(input) {
913
1066
  } while (!WHITE_SPACE.includes(peek) && peek !== ")" && peek !== "'" && cursor < input.length);
914
1067
  tokens.push({
915
1068
  type: "token",
916
- span: [_start3, cursor - 1],
1069
+ span: [_start2, cursor - 1],
917
1070
  value: _value
918
1071
  });
919
1072
  }
@@ -1056,7 +1209,7 @@ function parseTokens$1(inputTokens) {
1056
1209
  }
1057
1210
  return res;
1058
1211
  }
1059
- function parse$1(input) {
1212
+ function parse(input) {
1060
1213
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
1061
1214
  var _tokenize = tokenize(input),
1062
1215
  _tokenize2 = _slicedToArray(_tokenize, 2),
@@ -1182,7 +1335,7 @@ function newSelectorProxy(source, path, moduleSchema) {
1182
1335
  return newSelectorProxy(a, createValPathOfItem(path, i), moduleSchema === null || moduleSchema === void 0 ? void 0 : moduleSchema.item);
1183
1336
  }).filter(function (a) {
1184
1337
  if (f && f instanceof Schema) {
1185
- return f.assert(unValify(a));
1338
+ return f.assert(path || "", unValify(a)).success;
1186
1339
  } else {
1187
1340
  return unValify(f(a));
1188
1341
  }
@@ -1252,13 +1405,12 @@ var EvalError = /*#__PURE__*/function () {
1252
1405
  this.message = message;
1253
1406
  this.expr = expr;
1254
1407
  }
1255
- _createClass(EvalError, [{
1408
+ return _createClass(EvalError, [{
1256
1409
  key: "toString",
1257
1410
  value: function toString() {
1258
1411
  return "".concat(this.message, " in: ").concat(this.expr.transpile());
1259
1412
  }
1260
1413
  }]);
1261
- return EvalError;
1262
1414
  }();
1263
1415
  var MAX_STACK_SIZE = 100; // an arbitrary semi-large number
1264
1416
  function evaluateSync(expr, getSource, stack) {
@@ -1277,8 +1429,8 @@ function evaluateSync(expr, getSource, stack) {
1277
1429
  throw new EvalError("cannot call 'val' as anonymous function", expr);
1278
1430
  }
1279
1431
  if (expr.children[1] instanceof StringLiteral) {
1280
- var _path = expr.children[1].value;
1281
- return newSelectorProxy(getSource(_path), _path);
1432
+ var path = expr.children[1].value;
1433
+ return newSelectorProxy(getSource(path), path);
1282
1434
  } else {
1283
1435
  throw new EvalError("argument of 'val' must be a string literal", expr);
1284
1436
  }
@@ -1345,8 +1497,8 @@ function evaluateSync(expr, getSource, stack) {
1345
1497
  if (expr.children[0] instanceof Sym) {
1346
1498
  if (expr.children[0].value === "val") {
1347
1499
  if (expr.children[1] instanceof StringLiteral) {
1348
- var _path2 = expr.children[1].value;
1349
- return newSelectorProxy(getSource(_path2), _path2);
1500
+ var _path = expr.children[1].value;
1501
+ return newSelectorProxy(getSource(_path), _path);
1350
1502
  } else {
1351
1503
  throw new EvalError("argument of 'val' must be a string literal", expr);
1352
1504
  }
@@ -1425,7 +1577,7 @@ function evaluate(expr, source, stack) {
1425
1577
 
1426
1578
  var index = /*#__PURE__*/Object.freeze({
1427
1579
  __proto__: null,
1428
- parse: parse$1,
1580
+ parse: parse,
1429
1581
  Call: Call,
1430
1582
  Expr: Expr,
1431
1583
  NilSym: NilSym,
@@ -1436,7 +1588,6 @@ var index = /*#__PURE__*/Object.freeze({
1436
1588
  });
1437
1589
 
1438
1590
  var ArraySchema = /*#__PURE__*/function (_Schema) {
1439
- _inherits(ArraySchema, _Schema);
1440
1591
  function ArraySchema(item) {
1441
1592
  var _this;
1442
1593
  var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
@@ -1446,60 +1597,73 @@ var ArraySchema = /*#__PURE__*/function (_Schema) {
1446
1597
  _this.opt = opt;
1447
1598
  return _this;
1448
1599
  }
1449
- _createClass(ArraySchema, [{
1600
+ _inherits(ArraySchema, _Schema);
1601
+ return _createClass(ArraySchema, [{
1450
1602
  key: "validate",
1451
1603
  value: function validate(path, src) {
1452
- var _this2 = this;
1453
- var error = false;
1454
- if (this.opt && (src === null || src === undefined)) {
1455
- return false;
1604
+ var assertRes = this.assert(path, src);
1605
+ if (!assertRes.success) {
1606
+ return assertRes.errors;
1456
1607
  }
1457
- if (_typeof(src) !== "object" || !Array.isArray(src)) {
1458
- return _defineProperty({}, path, [{
1459
- message: "Expected 'array', got '".concat(_typeof(src), "'")
1460
- }]);
1608
+ if (assertRes.data === null) {
1609
+ return false;
1461
1610
  }
1462
- src.forEach(function (i, idx) {
1463
- var subPath = createValPathOfItem(path, idx);
1464
- if (!subPath) {
1465
- error = _this2.appendValidationError(error, path, "Internal error: could not create path at ".concat(!path && typeof path === "string" ? "<empty string>" : path, " at index ").concat(idx),
1466
- // Should! never happen
1467
- src);
1468
- } else {
1469
- var subError = _this2.item.validate(subPath, i);
1470
- if (subError && error) {
1471
- error = _objectSpread2(_objectSpread2({}, subError), error);
1472
- } else if (subError) {
1473
- error = subError;
1474
- }
1611
+ var error = {};
1612
+ for (var _i = 0, _Object$entries = Object.entries(assertRes.data); _i < _Object$entries.length; _i++) {
1613
+ var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
1614
+ idx = _Object$entries$_i[0],
1615
+ i = _Object$entries$_i[1];
1616
+ var subPath = unsafeCreateSourcePath(path, Number(idx));
1617
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1618
+ var subError = this.item.validate(subPath, i);
1619
+ if (subError) {
1620
+ error = _objectSpread2(_objectSpread2({}, subError), error);
1475
1621
  }
1476
- });
1622
+ }
1623
+ if (Object.keys(error).length === 0) {
1624
+ return false;
1625
+ }
1477
1626
  return error;
1478
1627
  }
1479
1628
  }, {
1480
1629
  key: "assert",
1481
- value: function assert(src) {
1482
- if (this.opt && (src === null || src === undefined)) {
1483
- return true;
1630
+ value: function assert(path, src) {
1631
+ if (src === null && this.opt) {
1632
+ return {
1633
+ success: true,
1634
+ data: src
1635
+ };
1484
1636
  }
1485
- if (!src) {
1486
- return false;
1637
+ if (src === null) {
1638
+ return {
1639
+ success: false,
1640
+ errors: _defineProperty({}, path, [{
1641
+ message: "Expected 'array', got 'null'",
1642
+ typeError: true
1643
+ }])
1644
+ };
1487
1645
  }
1488
- var _iterator = result._createForOfIteratorHelper(src),
1489
- _step;
1490
- try {
1491
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
1492
- var _item = _step.value;
1493
- if (!this.item.assert(_item)) {
1494
- return false;
1495
- }
1496
- }
1497
- } catch (err) {
1498
- _iterator.e(err);
1499
- } finally {
1500
- _iterator.f();
1646
+ if (_typeof(src) !== "object") {
1647
+ return {
1648
+ success: false,
1649
+ errors: _defineProperty({}, path, [{
1650
+ message: "Expected 'object', got '".concat(_typeof(src), "'"),
1651
+ typeError: true
1652
+ }])
1653
+ };
1654
+ } else if (!Array.isArray(src)) {
1655
+ return {
1656
+ success: false,
1657
+ errors: _defineProperty({}, path, [{
1658
+ message: "Expected object of type 'array'",
1659
+ typeError: true
1660
+ }])
1661
+ };
1501
1662
  }
1502
- return _typeof(src) === "object" && Array.isArray(src);
1663
+ return {
1664
+ success: true,
1665
+ data: src
1666
+ };
1503
1667
  }
1504
1668
  }, {
1505
1669
  key: "nullable",
@@ -1516,14 +1680,12 @@ var ArraySchema = /*#__PURE__*/function (_Schema) {
1516
1680
  };
1517
1681
  }
1518
1682
  }]);
1519
- return ArraySchema;
1520
1683
  }(Schema);
1521
1684
  var array = function array(schema) {
1522
1685
  return new ArraySchema(schema);
1523
1686
  };
1524
1687
 
1525
1688
  var LiteralSchema = /*#__PURE__*/function (_Schema) {
1526
- _inherits(LiteralSchema, _Schema);
1527
1689
  function LiteralSchema(value) {
1528
1690
  var _this;
1529
1691
  var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
@@ -1533,7 +1695,8 @@ var LiteralSchema = /*#__PURE__*/function (_Schema) {
1533
1695
  _this.opt = opt;
1534
1696
  return _this;
1535
1697
  }
1536
- _createClass(LiteralSchema, [{
1698
+ _inherits(LiteralSchema, _Schema);
1699
+ return _createClass(LiteralSchema, [{
1537
1700
  key: "validate",
1538
1701
  value: function validate(path, src) {
1539
1702
  if (this.opt && (src === null || src === undefined)) {
@@ -1555,11 +1718,35 @@ var LiteralSchema = /*#__PURE__*/function (_Schema) {
1555
1718
  }
1556
1719
  }, {
1557
1720
  key: "assert",
1558
- value: function assert(src) {
1559
- if (this.opt && (src === null || src === undefined)) {
1560
- return true;
1721
+ value: function assert(path, src) {
1722
+ if (this.opt && src === null) {
1723
+ return {
1724
+ success: true,
1725
+ data: src
1726
+ };
1727
+ }
1728
+ if (src === null) {
1729
+ return {
1730
+ success: false,
1731
+ errors: _defineProperty({}, path, [{
1732
+ message: "Expected 'string', got 'null'",
1733
+ typeError: true
1734
+ }])
1735
+ };
1561
1736
  }
1562
- return typeof src === "string";
1737
+ if (typeof src === "string" && src === this.value) {
1738
+ return {
1739
+ success: true,
1740
+ data: src
1741
+ };
1742
+ }
1743
+ return {
1744
+ success: false,
1745
+ errors: _defineProperty({}, path, [{
1746
+ message: "Expected literal '".concat(this.value, "', got '").concat(src, "'"),
1747
+ typeError: true
1748
+ }])
1749
+ };
1563
1750
  }
1564
1751
  }, {
1565
1752
  key: "nullable",
@@ -1576,14 +1763,12 @@ var LiteralSchema = /*#__PURE__*/function (_Schema) {
1576
1763
  };
1577
1764
  }
1578
1765
  }]);
1579
- return LiteralSchema;
1580
1766
  }(Schema);
1581
1767
  var literal = function literal(value) {
1582
1768
  return new LiteralSchema(value);
1583
1769
  };
1584
1770
 
1585
1771
  var UnionSchema = /*#__PURE__*/function (_Schema) {
1586
- _inherits(UnionSchema, _Schema);
1587
1772
  function UnionSchema(key, items) {
1588
1773
  var _this;
1589
1774
  var opt = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
@@ -1594,25 +1779,26 @@ var UnionSchema = /*#__PURE__*/function (_Schema) {
1594
1779
  _this.opt = opt;
1595
1780
  return _this;
1596
1781
  }
1597
- _createClass(UnionSchema, [{
1782
+ _inherits(UnionSchema, _Schema);
1783
+ return _createClass(UnionSchema, [{
1598
1784
  key: "validate",
1599
1785
  value: function validate(path, src) {
1600
1786
  var unknownSrc = src;
1601
1787
  var errors = false;
1602
- if (this.opt && (unknownSrc === null || unknownSrc === undefined)) {
1603
- // TODO: src should never be undefined
1788
+ if (this.opt && unknownSrc === null) {
1604
1789
  return false;
1605
1790
  }
1606
1791
  if (!this.key) {
1607
1792
  return _defineProperty({}, path, [{
1608
- message: "Missing required first argument in union"
1793
+ message: "Missing required first argument in union",
1794
+ schemaError: true
1609
1795
  }]);
1610
1796
  }
1611
1797
  var key = this.key;
1612
1798
  if (!Array.isArray(this.items)) {
1613
1799
  return _defineProperty({}, path, [{
1614
1800
  message: "A union schema must take more than 1 schema arguments",
1615
- fatal: true
1801
+ schemaError: true
1616
1802
  }]);
1617
1803
  }
1618
1804
  if (typeof key === "string") {
@@ -1622,7 +1808,7 @@ var UnionSchema = /*#__PURE__*/function (_Schema) {
1622
1808
  })) {
1623
1809
  return _defineProperty({}, path, [{
1624
1810
  message: "Key is a string, so all schema items must be objects",
1625
- fatal: true
1811
+ schemaError: true
1626
1812
  }]);
1627
1813
  }
1628
1814
  var objectSchemas = this.items;
@@ -1635,7 +1821,7 @@ var UnionSchema = /*#__PURE__*/function (_Schema) {
1635
1821
  if (illegalSchemas.length > 0) {
1636
1822
  return _defineProperty({}, path, [{
1637
1823
  message: "All schema items must be objects with a key: ".concat(key, " that is a literal schema. Found: ").concat(JSON.stringify(illegalSchemas, null, 2)),
1638
- fatal: true
1824
+ schemaError: true
1639
1825
  }]);
1640
1826
  }
1641
1827
  var serializedObjectSchemas = serializedSchemas;
@@ -1645,18 +1831,20 @@ var UnionSchema = /*#__PURE__*/function (_Schema) {
1645
1831
  if (optionalLiterals.length > 1) {
1646
1832
  return _defineProperty({}, path, [{
1647
1833
  message: "Schema cannot have an optional keys: ".concat(key),
1648
- fatal: true
1834
+ schemaError: true
1649
1835
  }]);
1650
1836
  }
1651
1837
  if (_typeof(unknownSrc) !== "object") {
1652
1838
  return _defineProperty({}, path, [{
1653
- message: "Expected an object"
1839
+ message: "Expected an object",
1840
+ typeError: true
1654
1841
  }]);
1655
1842
  }
1656
1843
  var objectSrc = unknownSrc;
1657
1844
  if (objectSrc[key] === undefined) {
1658
1845
  return _defineProperty({}, path, [{
1659
- message: "Missing required key: ".concat(key)
1846
+ message: "Missing required key: ".concat(key),
1847
+ typeError: true
1660
1848
  }]);
1661
1849
  }
1662
1850
  var foundSchemaLiterals = [];
@@ -1672,7 +1860,7 @@ var UnionSchema = /*#__PURE__*/function (_Schema) {
1672
1860
  } else {
1673
1861
  return _defineProperty({}, path, [{
1674
1862
  message: "Found duplicate key in schema: ".concat(schemaKey.value),
1675
- fatal: true
1863
+ schemaError: true
1676
1864
  }]);
1677
1865
  }
1678
1866
  }
@@ -1712,7 +1900,7 @@ var UnionSchema = /*#__PURE__*/function (_Schema) {
1712
1900
  })) {
1713
1901
  return _defineProperty({}, path, [{
1714
1902
  message: "Key is a literal schema, so all schema items must be literals",
1715
- fatal: true
1903
+ typeError: true
1716
1904
  }]);
1717
1905
  }
1718
1906
  var literalItems = [key].concat(_toConsumableArray(this.items));
@@ -1737,8 +1925,146 @@ var UnionSchema = /*#__PURE__*/function (_Schema) {
1737
1925
  }
1738
1926
  }, {
1739
1927
  key: "assert",
1740
- value: function assert(src) {
1741
- return true;
1928
+ value: function assert(path, src) {
1929
+ if (this.opt && src === null) {
1930
+ return {
1931
+ success: true,
1932
+ data: src
1933
+ };
1934
+ }
1935
+ if (src === null) {
1936
+ return {
1937
+ success: false,
1938
+ errors: _defineProperty({}, path, [{
1939
+ message: "Expected 'object', got 'null'",
1940
+ typeError: true
1941
+ }])
1942
+ };
1943
+ }
1944
+ if (!this.key) {
1945
+ return {
1946
+ success: false,
1947
+ errors: _defineProperty({}, path, [{
1948
+ message: "Missing required first argument in union schema",
1949
+ schemaError: true
1950
+ }])
1951
+ };
1952
+ }
1953
+ if (!Array.isArray(this.items)) {
1954
+ return {
1955
+ success: false,
1956
+ errors: _defineProperty({}, path, [{
1957
+ message: "The schema of this value is wrong. Schema is neither a union of literals nor a tagged union (of objects)",
1958
+ schemaError: true
1959
+ }])
1960
+ };
1961
+ }
1962
+ if (this.key instanceof LiteralSchema) {
1963
+ var _ref13;
1964
+ var success = false;
1965
+ var errors = {};
1966
+ var _iterator2 = result._createForOfIteratorHelper((_ref13 = [this.key]).concat.apply(_ref13, _toConsumableArray(this.items))),
1967
+ _step2;
1968
+ try {
1969
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
1970
+ var itemSchema = _step2.value;
1971
+ if (!(itemSchema instanceof LiteralSchema)) {
1972
+ return {
1973
+ success: false,
1974
+ errors: _defineProperty({}, path, [{
1975
+ message: "Schema of value is a union of string, so all schema items must be literals",
1976
+ schemaError: true
1977
+ }])
1978
+ };
1979
+ }
1980
+ if (typeof src !== "string") {
1981
+ errors[path] = [{
1982
+ message: "Expected 'string', got '".concat(_typeof(src), "'"),
1983
+ typeError: true
1984
+ }];
1985
+ continue;
1986
+ }
1987
+ var res = itemSchema.assert(path, src);
1988
+ if (res.success) {
1989
+ success = true;
1990
+ break;
1991
+ } else {
1992
+ for (var _i = 0, _Object$entries = Object.entries(res.errors); _i < _Object$entries.length; _i++) {
1993
+ var _errors5;
1994
+ var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
1995
+ _key = _Object$entries$_i[0],
1996
+ value = _Object$entries$_i[1];
1997
+ if (!errors[_key]) {
1998
+ errors[_key] = [];
1999
+ }
2000
+ (_errors5 = errors[_key]).push.apply(_errors5, _toConsumableArray(value));
2001
+ }
2002
+ }
2003
+ }
2004
+ } catch (err) {
2005
+ _iterator2.e(err);
2006
+ } finally {
2007
+ _iterator2.f();
2008
+ }
2009
+ if (!success) {
2010
+ return {
2011
+ success: false,
2012
+ errors: errors
2013
+ };
2014
+ }
2015
+ return {
2016
+ success: true,
2017
+ data: src
2018
+ };
2019
+ } else if (typeof this.key === "string") {
2020
+ var _success = false;
2021
+ var _errors6 = {};
2022
+ var _iterator3 = result._createForOfIteratorHelper(this.items),
2023
+ _step3;
2024
+ try {
2025
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
2026
+ var _itemSchema = _step3.value;
2027
+ var _res = _itemSchema.assert(path, src);
2028
+ if (_res.success) {
2029
+ _success = true;
2030
+ break;
2031
+ } else {
2032
+ for (var _i2 = 0, _Object$entries2 = Object.entries(_res.errors); _i2 < _Object$entries2.length; _i2++) {
2033
+ var _errors7;
2034
+ var _Object$entries2$_i = _slicedToArray(_Object$entries2[_i2], 2),
2035
+ _key2 = _Object$entries2$_i[0],
2036
+ _value = _Object$entries2$_i[1];
2037
+ if (!_errors6[_key2]) {
2038
+ _errors6[_key2] = [];
2039
+ }
2040
+ (_errors7 = _errors6[_key2]).push.apply(_errors7, _toConsumableArray(_value)); // by appending all type errors, we most likely get a lot of duplicate errors. Currently we believe this is correct though, but should probably be handled in when showing the errors to users
2041
+ }
2042
+ }
2043
+ }
2044
+ } catch (err) {
2045
+ _iterator3.e(err);
2046
+ } finally {
2047
+ _iterator3.f();
2048
+ }
2049
+ if (!_success) {
2050
+ return {
2051
+ success: false,
2052
+ errors: _errors6
2053
+ };
2054
+ }
2055
+ return {
2056
+ success: true,
2057
+ data: src
2058
+ };
2059
+ } else {
2060
+ return {
2061
+ success: false,
2062
+ errors: _defineProperty({}, path, [{
2063
+ message: "The schema of this value is wrong. Schema is neither a union of literals nor a tagged union (of objects)",
2064
+ schemaError: true
2065
+ }])
2066
+ };
2067
+ }
1742
2068
  }
1743
2069
  }, {
1744
2070
  key: "nullable",
@@ -1768,17 +2094,15 @@ var UnionSchema = /*#__PURE__*/function (_Schema) {
1768
2094
  };
1769
2095
  }
1770
2096
  }]);
1771
- return UnionSchema;
1772
2097
  }(Schema);
1773
2098
  var union = function union(key) {
1774
- for (var _len = arguments.length, objects = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
1775
- objects[_key - 1] = arguments[_key];
2099
+ for (var _len = arguments.length, objects = new Array(_len > 1 ? _len - 1 : 0), _key3 = 1; _key3 < _len; _key3++) {
2100
+ objects[_key3 - 1] = arguments[_key3];
1776
2101
  }
1777
2102
  return new UnionSchema(key, objects);
1778
2103
  };
1779
2104
 
1780
2105
  var RichTextSchema = /*#__PURE__*/function (_Schema) {
1781
- _inherits(RichTextSchema, _Schema);
1782
2106
  function RichTextSchema(options) {
1783
2107
  var _this;
1784
2108
  var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
@@ -1788,7 +2112,8 @@ var RichTextSchema = /*#__PURE__*/function (_Schema) {
1788
2112
  _this.opt = opt;
1789
2113
  return _this;
1790
2114
  }
1791
- _createClass(RichTextSchema, [{
2115
+ _inherits(RichTextSchema, _Schema);
2116
+ return _createClass(RichTextSchema, [{
1792
2117
  key: "validate",
1793
2118
  value: function validate(path, src) {
1794
2119
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -1799,12 +2124,147 @@ var RichTextSchema = /*#__PURE__*/function (_Schema) {
1799
2124
  fixes: ["fix:deprecated-richtext"]
1800
2125
  }]);
1801
2126
  }
1802
- return false; //TODO
2127
+ var assertRes = this.assert(path, src);
2128
+ if (!assertRes.success) {
2129
+ return _defineProperty({}, path, assertRes.errors[path]);
2130
+ }
2131
+ // TODO validate options
2132
+ return false;
1803
2133
  }
1804
2134
  }, {
1805
2135
  key: "assert",
1806
- value: function assert(src) {
1807
- return true; // TODO
2136
+ value: function assert(path, src) {
2137
+ if (this.opt && src === null) {
2138
+ return {
2139
+ success: true,
2140
+ data: src
2141
+ };
2142
+ }
2143
+ if (!Array.isArray(src)) {
2144
+ return {
2145
+ success: false,
2146
+ errors: _defineProperty({}, path, [{
2147
+ message: "Expected 'array', got '".concat(_typeof(src), "'"),
2148
+ typeError: true
2149
+ }])
2150
+ };
2151
+ }
2152
+ var errors = {};
2153
+ for (var i = 0; i < src.length; i++) {
2154
+ this.recursiveAssert(unsafeCreateSourcePath(path, i), src[i], errors);
2155
+ }
2156
+ if (Object.keys(errors).length > 0) {
2157
+ return {
2158
+ success: false,
2159
+ errors: errors
2160
+ };
2161
+ }
2162
+ // TODO: validate options
2163
+ return {
2164
+ success: true,
2165
+ data: src
2166
+ };
2167
+ }
2168
+ }, {
2169
+ key: "recursiveAssert",
2170
+ value: function recursiveAssert(path, node, errors) {
2171
+ if (_typeof(node) !== "object") {
2172
+ if (!errors[path]) {
2173
+ errors[path] = [];
2174
+ }
2175
+ errors[path].push({
2176
+ message: "Expected 'object', got '".concat(_typeof(node), "'"),
2177
+ typeError: true
2178
+ });
2179
+ return;
2180
+ }
2181
+ if (Array.isArray(node)) {
2182
+ if (!errors[path]) {
2183
+ errors[path] = [];
2184
+ }
2185
+ errors[path].push({
2186
+ message: "Expected 'object', got 'array'",
2187
+ typeError: true
2188
+ });
2189
+ return;
2190
+ }
2191
+ if (node === null) {
2192
+ if (!errors[path]) {
2193
+ errors[path] = [];
2194
+ }
2195
+ errors[path].push({
2196
+ message: "Expected 'object', got 'null'",
2197
+ typeError: true
2198
+ });
2199
+ return;
2200
+ }
2201
+ if ("tag" in node) {
2202
+ if (typeof node.tag !== "string") {
2203
+ if (!errors[path]) {
2204
+ errors[path] = [];
2205
+ }
2206
+ errors[path].push({
2207
+ message: "Expected 'string', got '".concat(_typeof(node.tag), "'"),
2208
+ typeError: true
2209
+ });
2210
+ return;
2211
+ }
2212
+ }
2213
+ if ("children" in node) {
2214
+ if (!Array.isArray(node.children)) {
2215
+ if (!errors[path]) {
2216
+ errors[path] = [];
2217
+ }
2218
+ errors[path].push({
2219
+ message: "Expected 'array', got '".concat(_typeof(node.children), "'"),
2220
+ typeError: true
2221
+ });
2222
+ return;
2223
+ } else {
2224
+ for (var i = 0; i < node.children.length; i++) {
2225
+ var child = node.children[i];
2226
+ var pathAtError = unsafeCreateSourcePath(unsafeCreateSourcePath(path, "children"), i);
2227
+ if (_typeof(child) === "object") {
2228
+ this.recursiveAssert(pathAtError, child, errors);
2229
+ } else if (typeof child === "string") {
2230
+ continue;
2231
+ } else {
2232
+ if (!errors[pathAtError]) {
2233
+ errors[pathAtError] = [];
2234
+ }
2235
+ errors[pathAtError].push({
2236
+ message: "Expected 'object' or 'string', got '".concat(_typeof(child), "'"),
2237
+ typeError: true
2238
+ });
2239
+ }
2240
+ }
2241
+ }
2242
+ }
2243
+ if ("styles" in node) {
2244
+ if (!Array.isArray(node.styles)) {
2245
+ if (!errors[path]) {
2246
+ errors[path] = [];
2247
+ }
2248
+ errors[path].push({
2249
+ message: "Expected 'array', got '".concat(_typeof(node.styles), "'"),
2250
+ typeError: true
2251
+ });
2252
+ } else {
2253
+ for (var _i = 0; _i < node.styles.length; _i++) {
2254
+ var style = node.styles[_i];
2255
+ if (typeof style !== "string") {
2256
+ var _pathAtError = unsafeCreateSourcePath(path, _i);
2257
+ if (!errors[_pathAtError]) {
2258
+ errors[_pathAtError] = [];
2259
+ }
2260
+ errors[_pathAtError].push({
2261
+ message: "Expected 'string', got '".concat(_typeof(style), "'"),
2262
+ typeError: true
2263
+ });
2264
+ }
2265
+ }
2266
+ }
2267
+ }
1808
2268
  }
1809
2269
  }, {
1810
2270
  key: "nullable",
@@ -1821,14 +2281,12 @@ var RichTextSchema = /*#__PURE__*/function (_Schema) {
1821
2281
  };
1822
2282
  }
1823
2283
  }]);
1824
- return RichTextSchema;
1825
2284
  }(Schema);
1826
2285
  var richtext$1 = function richtext(options) {
1827
2286
  return new RichTextSchema(options !== null && options !== void 0 ? options : {});
1828
2287
  };
1829
2288
 
1830
2289
  var ImageSchema = /*#__PURE__*/function (_Schema) {
1831
- _inherits(ImageSchema, _Schema);
1832
2290
  function ImageSchema(options) {
1833
2291
  var _this;
1834
2292
  var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
@@ -1838,7 +2296,8 @@ var ImageSchema = /*#__PURE__*/function (_Schema) {
1838
2296
  _this.opt = opt;
1839
2297
  return _this;
1840
2298
  }
1841
- _createClass(ImageSchema, [{
2299
+ _inherits(ImageSchema, _Schema);
2300
+ return _createClass(ImageSchema, [{
1842
2301
  key: "validate",
1843
2302
  value: function validate(path, src) {
1844
2303
  if (this.opt && (src === null || src === undefined)) {
@@ -1862,9 +2321,53 @@ var ImageSchema = /*#__PURE__*/function (_Schema) {
1862
2321
  value: src
1863
2322
  }]);
1864
2323
  }
2324
+ var _ref4 = this.options || {},
2325
+ accept = _ref4.accept;
2326
+ var _ref5 = src.metadata || {},
2327
+ mimeType = _ref5.mimeType;
2328
+ if (accept && mimeType && !mimeType.includes("/")) {
2329
+ return _defineProperty({}, path, [{
2330
+ message: "Invalid mime type format. Got: '".concat(mimeType, "'"),
2331
+ value: src
2332
+ }]);
2333
+ }
2334
+ if (accept && mimeType && mimeType.includes("/")) {
2335
+ var acceptedTypes = accept.split(",").map(function (type) {
2336
+ return type.trim();
2337
+ });
2338
+ var isValidMimeType = acceptedTypes.some(function (acceptedType) {
2339
+ if (acceptedType === "*/*") {
2340
+ return true;
2341
+ }
2342
+ if (acceptedType.endsWith("/*")) {
2343
+ var baseType = acceptedType.slice(0, -2);
2344
+ return mimeType.startsWith(baseType);
2345
+ }
2346
+ return acceptedType === mimeType;
2347
+ });
2348
+ if (!isValidMimeType) {
2349
+ return _defineProperty({}, path, [{
2350
+ message: "Mime type mismatch. Found '".concat(mimeType, "' but schema accepts '").concat(accept, "'"),
2351
+ value: src
2352
+ }]);
2353
+ }
2354
+ }
2355
+ var fileMimeType = Internal.filenameToMimeType(src[FILE_REF_PROP]);
2356
+ if (!fileMimeType) {
2357
+ return _defineProperty({}, path, [{
2358
+ message: "Could not determine mime type from file extension. Got: ".concat(src[FILE_REF_PROP]),
2359
+ value: src
2360
+ }]);
2361
+ }
2362
+ if (fileMimeType && mimeType && fileMimeType !== mimeType) {
2363
+ return _defineProperty({}, path, [{
2364
+ message: "Mime type and file extension not matching. Mime type is '".concat(mimeType, "' but file extension is '").concat(fileMimeType, "'"),
2365
+ value: src
2366
+ }]);
2367
+ }
1865
2368
  if (src.metadata) {
1866
2369
  return _defineProperty({}, path, [{
1867
- message: "Found metadata, but it could not be validated. Image metadata must be an object with the required props: width (positive number), height (positive number) and sha256 (string of length 64 of the base16 hash).",
2370
+ message: "Found metadata, but it could not be validated. Image metadata must be an object with the required props: width (positive number), height (positive number) and the mime type.",
1868
2371
  // 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.
1869
2372
  value: src,
1870
2373
  fixes: ["image:replace-metadata"]
@@ -1878,11 +2381,53 @@ var ImageSchema = /*#__PURE__*/function (_Schema) {
1878
2381
  }
1879
2382
  }, {
1880
2383
  key: "assert",
1881
- value: function assert(src) {
1882
- if (this.opt && (src === null || src === undefined)) {
1883
- return true;
2384
+ value: function assert(path, src) {
2385
+ if (this.opt && src === null) {
2386
+ return {
2387
+ success: true,
2388
+ data: src
2389
+ };
2390
+ }
2391
+ if (src === null) {
2392
+ return {
2393
+ success: false,
2394
+ errors: _defineProperty({}, path, [{
2395
+ message: "Expected 'object', got 'null'",
2396
+ typeError: true
2397
+ }])
2398
+ };
1884
2399
  }
1885
- return (src === null || src === void 0 ? void 0 : src[FILE_REF_PROP]) === "image" && (src === null || src === void 0 ? void 0 : src[VAL_EXTENSION]) === "file";
2400
+ if (_typeof(src) !== "object") {
2401
+ return {
2402
+ success: false,
2403
+ errors: _defineProperty({}, path, [{
2404
+ message: "Expected 'object', got '".concat(_typeof(src), "'"),
2405
+ typeError: true
2406
+ }])
2407
+ };
2408
+ }
2409
+ if (!(FILE_REF_PROP in src)) {
2410
+ return {
2411
+ success: false,
2412
+ errors: _defineProperty({}, path, [{
2413
+ message: "Value of this schema must use: 'c.image' (error type: missing_ref_prop)",
2414
+ typeError: true
2415
+ }])
2416
+ };
2417
+ }
2418
+ if (!(VAL_EXTENSION in src && src[VAL_EXTENSION] === "file")) {
2419
+ return {
2420
+ success: false,
2421
+ errors: _defineProperty({}, path, [{
2422
+ message: "Value of this schema must use: 'c.image' (error type: missing_file_extension)",
2423
+ typeError: true
2424
+ }])
2425
+ };
2426
+ }
2427
+ return {
2428
+ success: true,
2429
+ data: src
2430
+ };
1886
2431
  }
1887
2432
  }, {
1888
2433
  key: "nullable",
@@ -1899,14 +2444,12 @@ var ImageSchema = /*#__PURE__*/function (_Schema) {
1899
2444
  };
1900
2445
  }
1901
2446
  }]);
1902
- return ImageSchema;
1903
2447
  }(Schema);
1904
2448
  var image$1 = function image(options) {
1905
2449
  return new ImageSchema(options);
1906
2450
  };
1907
2451
 
1908
2452
  var RecordSchema = /*#__PURE__*/function (_Schema) {
1909
- _inherits(RecordSchema, _Schema);
1910
2453
  function RecordSchema(item) {
1911
2454
  var _this;
1912
2455
  var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
@@ -1916,7 +2459,8 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
1916
2459
  _this.opt = opt;
1917
2460
  return _this;
1918
2461
  }
1919
- _createClass(RecordSchema, [{
2462
+ _inherits(RecordSchema, _Schema);
2463
+ return _createClass(RecordSchema, [{
1920
2464
  key: "validate",
1921
2465
  value: function validate(path, src) {
1922
2466
  var _this2 = this;
@@ -1924,6 +2468,11 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
1924
2468
  if (this.opt && (src === null || src === undefined)) {
1925
2469
  return false;
1926
2470
  }
2471
+ if (src === null) {
2472
+ return _defineProperty({}, path, [{
2473
+ message: "Expected 'object', got 'null'"
2474
+ }]);
2475
+ }
1927
2476
  if (_typeof(src) !== "object") {
1928
2477
  return _defineProperty({}, path, [{
1929
2478
  message: "Expected 'object', got '".concat(_typeof(src), "'")
@@ -1934,10 +2483,10 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
1934
2483
  message: "Expected 'object', got 'array'"
1935
2484
  }]);
1936
2485
  }
1937
- Object.entries(src).forEach(function (_ref3) {
1938
- var _ref4 = _slicedToArray(_ref3, 2),
1939
- key = _ref4[0],
1940
- elem = _ref4[1];
2486
+ Object.entries(src).forEach(function (_ref4) {
2487
+ var _ref5 = _slicedToArray(_ref4, 2),
2488
+ key = _ref5[0],
2489
+ elem = _ref5[1];
1941
2490
  var subPath = createValPathOfItem(path, key);
1942
2491
  if (!subPath) {
1943
2492
  error = _this2.appendValidationError(error, path, "Internal error: could not create path at ".concat(!path && typeof path === "string" ? "<empty string>" : path, " at key ").concat(elem),
@@ -1956,21 +2505,35 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
1956
2505
  }
1957
2506
  }, {
1958
2507
  key: "assert",
1959
- value: function assert(src) {
1960
- if (this.opt && (src === null || src === undefined)) {
1961
- return true;
2508
+ value: function assert(path, src) {
2509
+ if (this.opt && src === null) {
2510
+ return {
2511
+ success: true,
2512
+ data: src
2513
+ };
1962
2514
  }
1963
- if (!src) {
1964
- return false;
2515
+ if (_typeof(src) !== "object") {
2516
+ return {
2517
+ success: false,
2518
+ errors: _defineProperty({}, path, [{
2519
+ message: "Expected 'object', got '".concat(_typeof(src), "'"),
2520
+ typeError: true
2521
+ }])
2522
+ };
1965
2523
  }
1966
- for (var _i = 0, _Object$entries = Object.entries(src); _i < _Object$entries.length; _i++) {
1967
- var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
1968
- _item = _Object$entries$_i[1];
1969
- if (!this.item.assert(_item)) {
1970
- return false;
1971
- }
2524
+ if (Array.isArray(src)) {
2525
+ return {
2526
+ success: false,
2527
+ errors: _defineProperty({}, path, [{
2528
+ message: "Expected 'object', got 'array'",
2529
+ typeError: true
2530
+ }])
2531
+ };
1972
2532
  }
1973
- return _typeof(src) === "object" && !Array.isArray(src);
2533
+ return {
2534
+ success: true,
2535
+ data: src
2536
+ };
1974
2537
  }
1975
2538
  }, {
1976
2539
  key: "nullable",
@@ -1987,7 +2550,6 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
1987
2550
  };
1988
2551
  }
1989
2552
  }]);
1990
- return RecordSchema;
1991
2553
  }(Schema);
1992
2554
  var record = function record(schema) {
1993
2555
  return new RecordSchema(schema);
@@ -2018,7 +2580,12 @@ function splitModuleFilePathAndModulePath(path) {
2018
2580
  }
2019
2581
  return [path.slice(0, pathOfSep), path.slice(pathOfSep + ModuleFilePathSep.length)];
2020
2582
  }
2021
- var ModuleFilePathSep = "?p=";
2583
+ function joinModuleFilePathAndModulePath(moduleFilePath, modulePath) {
2584
+ if (modulePath === "") {
2585
+ return moduleFilePath;
2586
+ }
2587
+ return "".concat(moduleFilePath).concat(ModuleFilePathSep).concat(modulePath);
2588
+ }
2022
2589
  function isObjectSchema(schema) {
2023
2590
  return schema instanceof ObjectSchema || _typeof(schema) === "object" && "type" in schema && schema.type === "object";
2024
2591
  }
@@ -2038,7 +2605,9 @@ function isArraySchema(schema) {
2038
2605
  // );
2039
2606
  // }
2040
2607
 
2041
- function isUnionSchema(schema) {
2608
+ function isUnionSchema(schema
2609
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2610
+ ) {
2042
2611
  return schema instanceof UnionSchema || _typeof(schema) === "object" && "type" in schema && schema.type === "union";
2043
2612
  }
2044
2613
 
@@ -2060,7 +2629,7 @@ function isImageSchema(schema) {
2060
2629
  // }
2061
2630
 
2062
2631
  function resolvePath(path, valModule, schema) {
2063
- var parts = parsePath(path);
2632
+ var parts = splitModulePath(path);
2064
2633
  var origParts = _toConsumableArray(parts);
2065
2634
  var resolvedSchema = schema;
2066
2635
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -2077,10 +2646,6 @@ function resolvePath(path, valModule, schema) {
2077
2646
  if (_typeof(resolvedSource) !== "object" && !Array.isArray(resolvedSource)) {
2078
2647
  throw Error("Schema type error: expected source to be type of array, but got ".concat(_typeof(resolvedSource)));
2079
2648
  }
2080
- if (resolvedSource[part] === undefined) {
2081
- var _resolvedSource;
2082
- throw Error("Invalid path: array source (length: ".concat((_resolvedSource = resolvedSource) === null || _resolvedSource === void 0 ? void 0 : _resolvedSource.length, ") did not have index ").concat(part, " from path: ").concat(path));
2083
- }
2084
2649
  resolvedSource = resolvedSource[part];
2085
2650
  resolvedSchema = resolvedSchema.item;
2086
2651
  } else if (isRecordSchema(resolvedSchema)) {
@@ -2099,10 +2664,10 @@ function resolvePath(path, valModule, schema) {
2099
2664
  if (_typeof(resolvedSource) !== "object") {
2100
2665
  throw Error("Schema type error: expected source to be type of object, but got ".concat(_typeof(resolvedSource)));
2101
2666
  }
2102
- if (!resolvedSource[part]) {
2667
+ if (resolvedSource !== null && resolvedSource[part] === undefined) {
2103
2668
  throw Error("Invalid path: object source did not have key ".concat(part, " from path: ").concat(path));
2104
2669
  }
2105
- resolvedSource = resolvedSource[part];
2670
+ resolvedSource = resolvedSource === null ? resolvedSource : resolvedSource[part];
2106
2671
  resolvedSchema = resolvedSchema.items[part];
2107
2672
  // } else if (isI18nSchema(resolvedSchema)) {
2108
2673
  // if (!resolvedSchema.locales.includes(part)) {
@@ -2154,6 +2719,7 @@ function resolvePath(path, valModule, schema) {
2154
2719
  if (!keyValue) {
2155
2720
  throw Error("Invalid path: union source ".concat(resolvedSchema, " did not have required key ").concat(_key, " in path: ").concat(path));
2156
2721
  }
2722
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2157
2723
  var schemaOfUnionKey = resolvedSchema.items.find(
2158
2724
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
2159
2725
  function (child) {
@@ -2201,7 +2767,11 @@ function resolvePath(path, valModule, schema) {
2201
2767
  source: resolvedSource
2202
2768
  };
2203
2769
  }
2204
- function parsePath(input) {
2770
+ function splitModuleFilePath(input) {
2771
+ var parts = input.split("/").slice(1);
2772
+ return parts;
2773
+ }
2774
+ function splitModulePath(input) {
2205
2775
  var result = [];
2206
2776
  var i = 0;
2207
2777
  while (i < input.length) {
@@ -2237,9 +2807,32 @@ function parsePath(input) {
2237
2807
  }
2238
2808
  return result;
2239
2809
  }
2810
+ function splitJoinedSourcePaths(input) {
2811
+ // TODO: This is a very simple implementation that does not handle escaped commas
2812
+ return input.split(",");
2813
+ }
2814
+ function parentOfSourcePath(sourcePath) {
2815
+ var _splitModuleFilePathA = splitModuleFilePathAndModulePath(sourcePath),
2816
+ _splitModuleFilePathA2 = _slicedToArray(_splitModuleFilePathA, 2),
2817
+ moduleFilePath = _splitModuleFilePathA2[0],
2818
+ modulePath = _splitModuleFilePathA2[1];
2819
+ var modulePathParts = splitModulePath(modulePath).slice(0, -1);
2820
+ if (modulePathParts.length > 0) {
2821
+ return joinModuleFilePathAndModulePath(moduleFilePath, patchPathToModulePath(modulePathParts));
2822
+ }
2823
+ return moduleFilePath;
2824
+ }
2825
+ function patchPathToModulePath(patchPath) {
2826
+ return patchPath.map(function (segment) {
2827
+ // TODO: I am worried that something is lost here: what if the segment is a string that happens to be a parsable as a number? We could make those keys illegal?
2828
+ if (Number.isInteger(Number(segment))) {
2829
+ return segment;
2830
+ }
2831
+ return JSON.stringify(segment);
2832
+ }).join(".");
2833
+ }
2240
2834
 
2241
2835
  var NumberSchema = /*#__PURE__*/function (_Schema) {
2242
- _inherits(NumberSchema, _Schema);
2243
2836
  function NumberSchema(options) {
2244
2837
  var _this;
2245
2838
  var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
@@ -2249,7 +2842,8 @@ var NumberSchema = /*#__PURE__*/function (_Schema) {
2249
2842
  _this.opt = opt;
2250
2843
  return _this;
2251
2844
  }
2252
- _createClass(NumberSchema, [{
2845
+ _inherits(NumberSchema, _Schema);
2846
+ return _createClass(NumberSchema, [{
2253
2847
  key: "validate",
2254
2848
  value: function validate(path, src) {
2255
2849
  if (this.opt && (src === null || src === undefined)) {
@@ -2265,11 +2859,35 @@ var NumberSchema = /*#__PURE__*/function (_Schema) {
2265
2859
  }
2266
2860
  }, {
2267
2861
  key: "assert",
2268
- value: function assert(src) {
2269
- if (this.opt && (src === null || src === undefined)) {
2270
- return true;
2862
+ value: function assert(path, src) {
2863
+ if (this.opt && src === null) {
2864
+ return {
2865
+ success: true,
2866
+ data: src
2867
+ };
2868
+ }
2869
+ if (src === null) {
2870
+ return {
2871
+ success: false,
2872
+ errors: _defineProperty({}, path, [{
2873
+ message: "Expected 'number', got 'null'",
2874
+ typeError: true
2875
+ }])
2876
+ };
2877
+ }
2878
+ if (typeof src === "number") {
2879
+ return {
2880
+ success: true,
2881
+ data: src
2882
+ };
2271
2883
  }
2272
- return typeof src === "number";
2884
+ return {
2885
+ success: false,
2886
+ errors: _defineProperty({}, path, [{
2887
+ message: "Expected 'number', got '".concat(_typeof(src), "'"),
2888
+ typeError: true
2889
+ }])
2890
+ };
2273
2891
  }
2274
2892
  }, {
2275
2893
  key: "nullable",
@@ -2286,14 +2904,12 @@ var NumberSchema = /*#__PURE__*/function (_Schema) {
2286
2904
  };
2287
2905
  }
2288
2906
  }]);
2289
- return NumberSchema;
2290
2907
  }(Schema);
2291
2908
  var number = function number(options) {
2292
2909
  return new NumberSchema(options);
2293
2910
  };
2294
2911
 
2295
2912
  var StringSchema = /*#__PURE__*/function (_Schema) {
2296
- _inherits(StringSchema, _Schema);
2297
2913
  function StringSchema(options) {
2298
2914
  var _this;
2299
2915
  var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
@@ -2305,7 +2921,8 @@ var StringSchema = /*#__PURE__*/function (_Schema) {
2305
2921
  _this.isRaw = isRaw;
2306
2922
  return _this;
2307
2923
  }
2308
- _createClass(StringSchema, [{
2924
+ _inherits(StringSchema, _Schema);
2925
+ return _createClass(StringSchema, [{
2309
2926
  key: "min",
2310
2927
  value: function min(minLength) {
2311
2928
  return new StringSchema(_objectSpread2(_objectSpread2({}, this.options), {}, {
@@ -2365,11 +2982,26 @@ var StringSchema = /*#__PURE__*/function (_Schema) {
2365
2982
  }
2366
2983
  }, {
2367
2984
  key: "assert",
2368
- value: function assert(src) {
2369
- if (this.opt && (src === null || src === undefined)) {
2370
- return true;
2985
+ value: function assert(path, src) {
2986
+ if (this.opt && src === null) {
2987
+ return {
2988
+ success: true,
2989
+ data: src
2990
+ };
2991
+ }
2992
+ if (typeof src === "string") {
2993
+ return {
2994
+ success: true,
2995
+ data: src
2996
+ };
2371
2997
  }
2372
- return typeof src === "string";
2998
+ return {
2999
+ success: false,
3000
+ errors: _defineProperty({}, path, [{
3001
+ message: "Expected 'string', got '".concat(_typeof(src), "'"),
3002
+ typeError: true
3003
+ }])
3004
+ };
2373
3005
  }
2374
3006
  }, {
2375
3007
  key: "nullable",
@@ -2400,14 +3032,12 @@ var StringSchema = /*#__PURE__*/function (_Schema) {
2400
3032
  };
2401
3033
  }
2402
3034
  }]);
2403
- return StringSchema;
2404
3035
  }(Schema);
2405
3036
  var string = function string(options) {
2406
3037
  return new StringSchema(options);
2407
3038
  };
2408
3039
 
2409
3040
  var BooleanSchema = /*#__PURE__*/function (_Schema) {
2410
- _inherits(BooleanSchema, _Schema);
2411
3041
  function BooleanSchema() {
2412
3042
  var _this;
2413
3043
  var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
@@ -2416,7 +3046,8 @@ var BooleanSchema = /*#__PURE__*/function (_Schema) {
2416
3046
  _this.opt = opt;
2417
3047
  return _this;
2418
3048
  }
2419
- _createClass(BooleanSchema, [{
3049
+ _inherits(BooleanSchema, _Schema);
3050
+ return _createClass(BooleanSchema, [{
2420
3051
  key: "validate",
2421
3052
  value: function validate(path, src) {
2422
3053
  if (this.opt && (src === null || src === undefined)) {
@@ -2432,11 +3063,35 @@ var BooleanSchema = /*#__PURE__*/function (_Schema) {
2432
3063
  }
2433
3064
  }, {
2434
3065
  key: "assert",
2435
- value: function assert(src) {
2436
- if (this.opt && (src === null || src === undefined)) {
2437
- return true;
3066
+ value: function assert(path, src) {
3067
+ if (this.opt && src === null) {
3068
+ return {
3069
+ success: true,
3070
+ data: src
3071
+ };
3072
+ }
3073
+ if (src === null) {
3074
+ return {
3075
+ success: false,
3076
+ errors: _defineProperty({}, path, [{
3077
+ message: "Expected 'boolean', got 'null'",
3078
+ typeError: true
3079
+ }])
3080
+ };
2438
3081
  }
2439
- return typeof src === "boolean";
3082
+ if (typeof src !== "boolean") {
3083
+ return {
3084
+ success: false,
3085
+ errors: _defineProperty({}, path, [{
3086
+ message: "Expected 'boolean', got '".concat(_typeof(src), "'"),
3087
+ typeError: true
3088
+ }])
3089
+ };
3090
+ }
3091
+ return {
3092
+ success: true,
3093
+ data: src
3094
+ };
2440
3095
  }
2441
3096
  }, {
2442
3097
  key: "nullable",
@@ -2452,14 +3107,12 @@ var BooleanSchema = /*#__PURE__*/function (_Schema) {
2452
3107
  };
2453
3108
  }
2454
3109
  }]);
2455
- return BooleanSchema;
2456
3110
  }(Schema);
2457
3111
  var _boolean = function _boolean() {
2458
3112
  return new BooleanSchema();
2459
3113
  };
2460
3114
 
2461
3115
  var KeyOfSchema = /*#__PURE__*/function (_Schema) {
2462
- _inherits(KeyOfSchema, _Schema);
2463
3116
  function KeyOfSchema(schema, sourcePath) {
2464
3117
  var _this;
2465
3118
  var opt = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
@@ -2470,7 +3123,8 @@ var KeyOfSchema = /*#__PURE__*/function (_Schema) {
2470
3123
  _this.opt = opt;
2471
3124
  return _this;
2472
3125
  }
2473
- _createClass(KeyOfSchema, [{
3126
+ _inherits(KeyOfSchema, _Schema);
3127
+ return _createClass(KeyOfSchema, [{
2474
3128
  key: "validate",
2475
3129
  value: function validate(path, src) {
2476
3130
  if (this.opt && (src === null || src === undefined)) {
@@ -2482,19 +3136,14 @@ var KeyOfSchema = /*#__PURE__*/function (_Schema) {
2482
3136
  }]);
2483
3137
  }
2484
3138
  var serializedSchema = this.schema;
2485
- if (!(serializedSchema.type === "array" || serializedSchema.type === "object" || serializedSchema.type === "record")) {
3139
+ if (!(serializedSchema.type === "object" || serializedSchema.type === "record")) {
2486
3140
  return _defineProperty({}, path, [{
2487
- message: "Schema in keyOf must be an 'array', 'object' or 'record'. Found '".concat(serializedSchema.type, "'")
3141
+ message: "Schema in keyOf must be an 'object' or 'record'. Found '".concat(serializedSchema.type, "'")
2488
3142
  }]);
2489
3143
  }
2490
3144
  if (serializedSchema.opt && (src === null || src === undefined)) {
2491
3145
  return false;
2492
3146
  }
2493
- if (serializedSchema.type === "array" && typeof src !== "number") {
2494
- return _defineProperty({}, path, [{
2495
- message: "Type of value in keyof (array) must be 'number'"
2496
- }]);
2497
- }
2498
3147
  if (serializedSchema.type === "record" && typeof src !== "string") {
2499
3148
  return _defineProperty({}, path, [{
2500
3149
  message: "Type of value in keyof (record) must be 'string'"
@@ -2512,34 +3161,70 @@ var KeyOfSchema = /*#__PURE__*/function (_Schema) {
2512
3161
  }
2513
3162
  }, {
2514
3163
  key: "assert",
2515
- value: function assert(src) {
2516
- if (this.opt && (src === null || src === undefined)) {
2517
- return true;
3164
+ value: function assert(path, src) {
3165
+ if (this.opt && src === null) {
3166
+ return {
3167
+ success: true,
3168
+ data: src
3169
+ };
3170
+ }
3171
+ if (src === null) {
3172
+ return {
3173
+ success: false,
3174
+ errors: _defineProperty({}, path, [{
3175
+ message: "Expected 'string', got 'null'",
3176
+ typeError: true
3177
+ }])
3178
+ };
2518
3179
  }
2519
3180
  var schema = this.schema;
2520
3181
  if (!schema) {
2521
- return false;
3182
+ return {
3183
+ success: false,
3184
+ errors: _defineProperty({}, path, [{
3185
+ message: "Neither key nor schema was found. keyOf is missing an argument.",
3186
+ typeError: true
3187
+ }])
3188
+ };
2522
3189
  }
2523
3190
  var serializedSchema = schema;
2524
- if (!(serializedSchema.type === "array" || serializedSchema.type === "object" || serializedSchema.type === "record")) {
2525
- return false;
2526
- }
2527
- if (serializedSchema.opt && (src === null || src === undefined)) {
2528
- return true;
2529
- }
2530
- if (serializedSchema.type === "array" && typeof src !== "number") {
2531
- return false;
3191
+ if (!(serializedSchema.type === "object" || serializedSchema.type === "record")) {
3192
+ return {
3193
+ success: false,
3194
+ errors: _defineProperty({}, path, [{
3195
+ message: "Schema of first argument must be either: 'array', 'object' or 'record'. Found '".concat(serializedSchema.type, "'"),
3196
+ typeError: true
3197
+ }])
3198
+ };
2532
3199
  }
2533
3200
  if (serializedSchema.type === "record" && typeof src !== "string") {
2534
- return false;
3201
+ return {
3202
+ success: false,
3203
+ errors: _defineProperty({}, path, [{
3204
+ message: "Value of keyOf (record) must be 'string', got '".concat(_typeof(src), "'"),
3205
+ typeError: true
3206
+ }])
3207
+ };
2535
3208
  }
3209
+ // We check actual value here, since TypeScript also does this. Literals are used in other types (unions),
3210
+ // and there it also makes sense to check the actual string values (i.e. that it is not just a string) since
3211
+ // missing one would lead to a runtime error. At least this is what we are thinking currently.
2536
3212
  if (serializedSchema.type === "object") {
2537
3213
  var keys = Object.keys(serializedSchema.items);
2538
3214
  if (!keys.includes(src)) {
2539
- return false;
3215
+ return {
3216
+ success: false,
3217
+ errors: _defineProperty({}, path, [{
3218
+ message: "Value of keyOf (object) must be: ".concat(keys.join(", "), ". Found: ").concat(src),
3219
+ typeError: true
3220
+ }])
3221
+ };
2540
3222
  }
2541
3223
  }
2542
- return true;
3224
+ return {
3225
+ success: true,
3226
+ data: src
3227
+ };
2543
3228
  }
2544
3229
  }, {
2545
3230
  key: "nullable",
@@ -2551,7 +3236,7 @@ var KeyOfSchema = /*#__PURE__*/function (_Schema) {
2551
3236
  value: function serialize() {
2552
3237
  var path = this.sourcePath;
2553
3238
  if (!path) {
2554
- throw new Error("Cannot serialize keyOf schema with empty selector. TIP: keyOf must be used with a Val Module.");
3239
+ throw new Error("Cannot serialize keyOf schema with empty selector. TIP: keyOf must be used with a Val Module of record schema.");
2555
3240
  }
2556
3241
  var serializedSchema = this.schema;
2557
3242
  if (!serializedSchema) {
@@ -2559,9 +3244,6 @@ var KeyOfSchema = /*#__PURE__*/function (_Schema) {
2559
3244
  }
2560
3245
  var values;
2561
3246
  switch (serializedSchema.type) {
2562
- case "array":
2563
- values = "number";
2564
- break;
2565
3247
  case "record":
2566
3248
  values = "string";
2567
3249
  break;
@@ -2580,7 +3262,6 @@ var KeyOfSchema = /*#__PURE__*/function (_Schema) {
2580
3262
  };
2581
3263
  }
2582
3264
  }]);
2583
- return KeyOfSchema;
2584
3265
  }(Schema);
2585
3266
  var keyOf = function keyOf(valModule) {
2586
3267
  var _valModule$GetSchema;
@@ -2588,19 +3269,17 @@ var keyOf = function keyOf(valModule) {
2588
3269
  };
2589
3270
 
2590
3271
  var DateSchema = /*#__PURE__*/function (_Schema) {
2591
- _inherits(DateSchema, _Schema);
2592
3272
  function DateSchema(options) {
2593
3273
  var _this;
2594
3274
  var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
2595
- var isRaw = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
2596
3275
  _classCallCheck(this, DateSchema);
2597
3276
  _this = _callSuper(this, DateSchema);
2598
3277
  _this.options = options;
2599
3278
  _this.opt = opt;
2600
- _this.isRaw = isRaw;
2601
3279
  return _this;
2602
3280
  }
2603
- _createClass(DateSchema, [{
3281
+ _inherits(DateSchema, _Schema);
3282
+ return _createClass(DateSchema, [{
2604
3283
  key: "validate",
2605
3284
  value: function validate(path, src) {
2606
3285
  var _this$options, _this$options2, _this$options3, _this$options4;
@@ -2618,7 +3297,7 @@ var DateSchema = /*#__PURE__*/function (_Schema) {
2618
3297
  return _defineProperty({}, path, [{
2619
3298
  message: "From date ".concat(this.options.from, " is after to date ").concat(this.options.to),
2620
3299
  value: src,
2621
- fatal: true
3300
+ typeError: true
2622
3301
  }]);
2623
3302
  }
2624
3303
  if (src < this.options.from || src > this.options.to) {
@@ -2653,30 +3332,54 @@ var DateSchema = /*#__PURE__*/function (_Schema) {
2653
3332
  }
2654
3333
  }, {
2655
3334
  key: "assert",
2656
- value: function assert(src) {
2657
- if (this.opt && (src === null || src === undefined)) {
2658
- return true;
3335
+ value: function assert(path, src) {
3336
+ if (this.opt && src === null) {
3337
+ return {
3338
+ success: true,
3339
+ data: src
3340
+ };
3341
+ }
3342
+ if (src === null) {
3343
+ return {
3344
+ success: false,
3345
+ errors: _defineProperty({}, path, [{
3346
+ message: "Expected 'string', got 'null'",
3347
+ typeError: true
3348
+ }])
3349
+ };
3350
+ }
3351
+ if (typeof src !== "string") {
3352
+ return {
3353
+ success: false,
3354
+ errors: _defineProperty({}, path, [{
3355
+ message: "Expected 'string', got '".concat(_typeof(src), "'"),
3356
+ typeError: true
3357
+ }])
3358
+ };
2659
3359
  }
2660
- return typeof src === "string";
3360
+ return {
3361
+ success: true,
3362
+ data: src
3363
+ };
2661
3364
  }
2662
3365
  }, {
2663
3366
  key: "from",
2664
3367
  value: function from(_from) {
2665
3368
  return new DateSchema(_objectSpread2(_objectSpread2({}, this.options), {}, {
2666
3369
  from: _from
2667
- }), this.opt, this.isRaw);
3370
+ }), this.opt);
2668
3371
  }
2669
3372
  }, {
2670
3373
  key: "to",
2671
3374
  value: function to(_to) {
2672
3375
  return new DateSchema(_objectSpread2(_objectSpread2({}, this.options), {}, {
2673
3376
  to: _to
2674
- }), this.opt, this.isRaw);
3377
+ }), this.opt);
2675
3378
  }
2676
3379
  }, {
2677
3380
  key: "nullable",
2678
3381
  value: function nullable() {
2679
- return new DateSchema(this.options, true, this.isRaw);
3382
+ return new DateSchema(this.options, true);
2680
3383
  }
2681
3384
  }, {
2682
3385
  key: "serialize",
@@ -2688,7 +3391,6 @@ var DateSchema = /*#__PURE__*/function (_Schema) {
2688
3391
  };
2689
3392
  }
2690
3393
  }]);
2691
- return DateSchema;
2692
3394
  }(Schema);
2693
3395
  var date = function date(options) {
2694
3396
  return new DateSchema(options);
@@ -3012,7 +3714,7 @@ var initVal = function initVal(config) {
3012
3714
  c: {
3013
3715
  define: define,
3014
3716
  // remote,
3015
- file: file$1,
3717
+ file: initFile(config),
3016
3718
  richtext: richtext,
3017
3719
  rt: {
3018
3720
  image: image,
@@ -3379,7 +4081,7 @@ var Hash = /*#__PURE__*/function () {
3379
4081
  this._word = new Int32Array(sharedBuffer, sharedOffset, N.allocWords);
3380
4082
  sharedOffset += N.allocBytes;
3381
4083
  }
3382
- _createClass(Hash, [{
4084
+ return _createClass(Hash, [{
3383
4085
  key: "update",
3384
4086
  value: function update(data) {
3385
4087
  // data: string
@@ -3596,7 +4298,6 @@ var Hash = /*#__PURE__*/function () {
3596
4298
  return _byte.slice(0, 32);
3597
4299
  }
3598
4300
  }]);
3599
- return Hash;
3600
4301
  }();
3601
4302
  var W = new Int32Array(N.workWords);
3602
4303
  var sharedBuffer;
@@ -3637,6 +4338,728 @@ var getSHA256Hash = function getSHA256Hash(bits) {
3637
4338
  return createHash().update(bits).digest("hex");
3638
4339
  };
3639
4340
 
4341
+ var EXT_TO_MIME_TYPES = {
4342
+ x3d: "application/vnd.hzn-3d-crossword",
4343
+ "3gp": "video/3gpp",
4344
+ "3g2": "video/3gpp2",
4345
+ mseq: "application/vnd.mseq",
4346
+ pwn: "application/vnd.3m.post-it-notes",
4347
+ plb: "application/vnd.3gpp.pic-bw-large",
4348
+ psb: "application/vnd.3gpp.pic-bw-small",
4349
+ pvb: "application/vnd.3gpp.pic-bw-var",
4350
+ tcap: "application/vnd.3gpp2.tcap",
4351
+ "7z": "application/x-7z-compressed",
4352
+ abw: "application/x-abiword",
4353
+ ace: "application/x-ace-compressed",
4354
+ acc: "application/vnd.americandynamics.acc",
4355
+ acu: "application/vnd.acucobol",
4356
+ atc: "application/vnd.acucorp",
4357
+ adp: "audio/adpcm",
4358
+ aab: "application/x-authorware-bin",
4359
+ aam: "application/x-authorware-map",
4360
+ aas: "application/x-authorware-seg",
4361
+ air: "application/vnd.adobe.air-application-installer-package+zip",
4362
+ swf: "application/x-shockwave-flash",
4363
+ fxp: "application/vnd.adobe.fxp",
4364
+ pdf: "application/pdf",
4365
+ ppd: "application/vnd.cups-ppd",
4366
+ dir: "application/x-director",
4367
+ xdp: "application/vnd.adobe.xdp+xml",
4368
+ xfdf: "application/vnd.adobe.xfdf",
4369
+ aac: "audio/x-aac",
4370
+ ahead: "application/vnd.ahead.space",
4371
+ azf: "application/vnd.airzip.filesecure.azf",
4372
+ azs: "application/vnd.airzip.filesecure.azs",
4373
+ azw: "application/vnd.amazon.ebook",
4374
+ ami: "application/vnd.amiga.ami",
4375
+ "N/A": "application/andrew-inset",
4376
+ apk: "application/vnd.android.package-archive",
4377
+ cii: "application/vnd.anser-web-certificate-issue-initiation",
4378
+ fti: "application/vnd.anser-web-funds-transfer-initiation",
4379
+ atx: "application/vnd.antix.game-component",
4380
+ dmg: "application/x-apple-diskimage",
4381
+ mpkg: "application/vnd.apple.installer+xml",
4382
+ aw: "application/applixware",
4383
+ mp3: "audio/mpeg",
4384
+ les: "application/vnd.hhe.lesson-player",
4385
+ swi: "application/vnd.aristanetworks.swi",
4386
+ s: "text/x-asm",
4387
+ atomcat: "application/atomcat+xml",
4388
+ atomsvc: "application/atomsvc+xml",
4389
+ atom: "application/atom+xml",
4390
+ ac: "application/pkix-attr-cert",
4391
+ aif: "audio/x-aiff",
4392
+ avi: "video/x-msvideo",
4393
+ aep: "application/vnd.audiograph",
4394
+ dxf: "image/vnd.dxf",
4395
+ dwf: "model/vnd.dwf",
4396
+ par: "text/plain-bas",
4397
+ bcpio: "application/x-bcpio",
4398
+ bin: "application/octet-stream",
4399
+ bmp: "image/bmp",
4400
+ torrent: "application/x-bittorrent",
4401
+ cod: "application/vnd.rim.cod",
4402
+ mpm: "application/vnd.blueice.multipass",
4403
+ bmi: "application/vnd.bmi",
4404
+ sh: "application/x-sh",
4405
+ btif: "image/prs.btif",
4406
+ rep: "application/vnd.businessobjects",
4407
+ bz: "application/x-bzip",
4408
+ bz2: "application/x-bzip2",
4409
+ csh: "application/x-csh",
4410
+ c: "text/x-c",
4411
+ cdxml: "application/vnd.chemdraw+xml",
4412
+ css: "text/css",
4413
+ cdx: "chemical/x-cdx",
4414
+ cml: "chemical/x-cml",
4415
+ csml: "chemical/x-csml",
4416
+ cdbcmsg: "application/vnd.contact.cmsg",
4417
+ cla: "application/vnd.claymore",
4418
+ c4g: "application/vnd.clonk.c4group",
4419
+ sub: "image/vnd.dvb.subtitle",
4420
+ cdmia: "application/cdmi-capability",
4421
+ cdmic: "application/cdmi-container",
4422
+ cdmid: "application/cdmi-domain",
4423
+ cdmio: "application/cdmi-object",
4424
+ cdmiq: "application/cdmi-queue",
4425
+ c11amc: "application/vnd.cluetrust.cartomobile-config",
4426
+ c11amz: "application/vnd.cluetrust.cartomobile-config-pkg",
4427
+ ras: "image/x-cmu-raster",
4428
+ dae: "model/vnd.collada+xml",
4429
+ csv: "text/csv",
4430
+ cpt: "application/mac-compactpro",
4431
+ wmlc: "application/vnd.wap.wmlc",
4432
+ cgm: "image/cgm",
4433
+ ice: "x-conference/x-cooltalk",
4434
+ cmx: "image/x-cmx",
4435
+ xar: "application/vnd.xara",
4436
+ cmc: "application/vnd.cosmocaller",
4437
+ cpio: "application/x-cpio",
4438
+ clkx: "application/vnd.crick.clicker",
4439
+ clkk: "application/vnd.crick.clicker.keyboard",
4440
+ clkp: "application/vnd.crick.clicker.palette",
4441
+ clkt: "application/vnd.crick.clicker.template",
4442
+ clkw: "application/vnd.crick.clicker.wordbank",
4443
+ wbs: "application/vnd.criticaltools.wbs+xml",
4444
+ cryptonote: "application/vnd.rig.cryptonote",
4445
+ cif: "chemical/x-cif",
4446
+ cmdf: "chemical/x-cmdf",
4447
+ cu: "application/cu-seeme",
4448
+ cww: "application/prs.cww",
4449
+ curl: "text/vnd.curl",
4450
+ dcurl: "text/vnd.curl.dcurl",
4451
+ mcurl: "text/vnd.curl.mcurl",
4452
+ scurl: "text/vnd.curl.scurl",
4453
+ car: "application/vnd.curl.car",
4454
+ pcurl: "application/vnd.curl.pcurl",
4455
+ cmp: "application/vnd.yellowriver-custom-menu",
4456
+ dssc: "application/dssc+der",
4457
+ xdssc: "application/dssc+xml",
4458
+ deb: "application/x-debian-package",
4459
+ uva: "audio/vnd.dece.audio",
4460
+ uvi: "image/vnd.dece.graphic",
4461
+ uvh: "video/vnd.dece.hd",
4462
+ uvm: "video/vnd.dece.mobile",
4463
+ uvu: "video/vnd.uvvu.mp4",
4464
+ uvp: "video/vnd.dece.pd",
4465
+ uvs: "video/vnd.dece.sd",
4466
+ uvv: "video/vnd.dece.video",
4467
+ dvi: "application/x-dvi",
4468
+ seed: "application/vnd.fdsn.seed",
4469
+ dtb: "application/x-dtbook+xml",
4470
+ res: "application/x-dtbresource+xml",
4471
+ ait: "application/vnd.dvb.ait",
4472
+ svc: "application/vnd.dvb.service",
4473
+ eol: "audio/vnd.digital-winds",
4474
+ djvu: "image/vnd.djvu",
4475
+ dtd: "application/xml-dtd",
4476
+ mlp: "application/vnd.dolby.mlp",
4477
+ wad: "application/x-doom",
4478
+ dpg: "application/vnd.dpgraph",
4479
+ dra: "audio/vnd.dra",
4480
+ dfac: "application/vnd.dreamfactory",
4481
+ dts: "audio/vnd.dts",
4482
+ dtshd: "audio/vnd.dts.hd",
4483
+ dwg: "image/vnd.dwg",
4484
+ geo: "application/vnd.dynageo",
4485
+ es: "application/ecmascript",
4486
+ mag: "application/vnd.ecowin.chart",
4487
+ mmr: "image/vnd.fujixerox.edmics-mmr",
4488
+ rlc: "image/vnd.fujixerox.edmics-rlc",
4489
+ exi: "application/exi",
4490
+ mgz: "application/vnd.proteus.magazine",
4491
+ epub: "application/epub+zip",
4492
+ eml: "message/rfc822",
4493
+ nml: "application/vnd.enliven",
4494
+ xpr: "application/vnd.is-xpr",
4495
+ xif: "image/vnd.xiff",
4496
+ xfdl: "application/vnd.xfdl",
4497
+ emma: "application/emma+xml",
4498
+ ez2: "application/vnd.ezpix-album",
4499
+ ez3: "application/vnd.ezpix-package",
4500
+ fst: "image/vnd.fst",
4501
+ fvt: "video/vnd.fvt",
4502
+ fbs: "image/vnd.fastbidsheet",
4503
+ fe_launch: "application/vnd.denovo.fcselayout-link",
4504
+ f4v: "video/x-f4v",
4505
+ flv: "video/x-flv",
4506
+ fpx: "image/vnd.fpx",
4507
+ npx: "image/vnd.net-fpx",
4508
+ flx: "text/vnd.fmi.flexstor",
4509
+ fli: "video/x-fli",
4510
+ ftc: "application/vnd.fluxtime.clip",
4511
+ fdf: "application/vnd.fdf",
4512
+ f: "text/x-fortran",
4513
+ mif: "application/vnd.mif",
4514
+ fm: "application/vnd.framemaker",
4515
+ fh: "image/x-freehand",
4516
+ fsc: "application/vnd.fsc.weblaunch",
4517
+ fnc: "application/vnd.frogans.fnc",
4518
+ ltf: "application/vnd.frogans.ltf",
4519
+ ddd: "application/vnd.fujixerox.ddd",
4520
+ xdw: "application/vnd.fujixerox.docuworks",
4521
+ xbd: "application/vnd.fujixerox.docuworks.binder",
4522
+ oas: "application/vnd.fujitsu.oasys",
4523
+ oa2: "application/vnd.fujitsu.oasys2",
4524
+ oa3: "application/vnd.fujitsu.oasys3",
4525
+ fg5: "application/vnd.fujitsu.oasysgp",
4526
+ bh2: "application/vnd.fujitsu.oasysprs",
4527
+ spl: "application/x-futuresplash",
4528
+ fzs: "application/vnd.fuzzysheet",
4529
+ g3: "image/g3fax",
4530
+ gmx: "application/vnd.gmx",
4531
+ gtw: "model/vnd.gtw",
4532
+ txd: "application/vnd.genomatix.tuxedo",
4533
+ ggb: "application/vnd.geogebra.file",
4534
+ ggt: "application/vnd.geogebra.tool",
4535
+ gdl: "model/vnd.gdl",
4536
+ gex: "application/vnd.geometry-explorer",
4537
+ gxt: "application/vnd.geonext",
4538
+ g2w: "application/vnd.geoplan",
4539
+ g3w: "application/vnd.geospace",
4540
+ gsf: "application/x-font-ghostscript",
4541
+ bdf: "application/x-font-bdf",
4542
+ gtar: "application/x-gtar",
4543
+ texinfo: "application/x-texinfo",
4544
+ gnumeric: "application/x-gnumeric",
4545
+ kml: "application/vnd.google-earth.kml+xml",
4546
+ kmz: "application/vnd.google-earth.kmz",
4547
+ gqf: "application/vnd.grafeq",
4548
+ gif: "image/gif",
4549
+ gv: "text/vnd.graphviz",
4550
+ gac: "application/vnd.groove-account",
4551
+ ghf: "application/vnd.groove-help",
4552
+ gim: "application/vnd.groove-identity-message",
4553
+ grv: "application/vnd.groove-injector",
4554
+ gtm: "application/vnd.groove-tool-message",
4555
+ tpl: "application/vnd.groove-tool-template",
4556
+ vcg: "application/vnd.groove-vcard",
4557
+ h261: "video/h261",
4558
+ h263: "video/h263",
4559
+ h264: "video/h264",
4560
+ hpid: "application/vnd.hp-hpid",
4561
+ hps: "application/vnd.hp-hps",
4562
+ hdf: "application/x-hdf",
4563
+ rip: "audio/vnd.rip",
4564
+ hbci: "application/vnd.hbci",
4565
+ jlt: "application/vnd.hp-jlyt",
4566
+ pcl: "application/vnd.hp-pcl",
4567
+ hpgl: "application/vnd.hp-hpgl",
4568
+ hvs: "application/vnd.yamaha.hv-script",
4569
+ hvd: "application/vnd.yamaha.hv-dic",
4570
+ hvp: "application/vnd.yamaha.hv-voice",
4571
+ "sfd-hdstx": "application/vnd.hydrostatix.sof-data",
4572
+ stk: "application/hyperstudio",
4573
+ hal: "application/vnd.hal+xml",
4574
+ html: "text/html",
4575
+ irm: "application/vnd.ibm.rights-management",
4576
+ sc: "application/vnd.ibm.secure-container",
4577
+ ics: "text/calendar",
4578
+ icc: "application/vnd.iccprofile",
4579
+ ico: "image/x-icon",
4580
+ igl: "application/vnd.igloader",
4581
+ ief: "image/ief",
4582
+ ivp: "application/vnd.immervision-ivp",
4583
+ ivu: "application/vnd.immervision-ivu",
4584
+ rif: "application/reginfo+xml",
4585
+ "3dml": "text/vnd.in3d.3dml",
4586
+ spot: "text/vnd.in3d.spot",
4587
+ igs: "model/iges",
4588
+ i2g: "application/vnd.intergeo",
4589
+ cdy: "application/vnd.cinderella",
4590
+ xpw: "application/vnd.intercon.formnet",
4591
+ fcs: "application/vnd.isac.fcs",
4592
+ ipfix: "application/ipfix",
4593
+ cer: "application/pkix-cert",
4594
+ pki: "application/pkixcmp",
4595
+ crl: "application/pkix-crl",
4596
+ pkipath: "application/pkix-pkipath",
4597
+ igm: "application/vnd.insors.igm",
4598
+ rcprofile: "application/vnd.ipunplugged.rcprofile",
4599
+ irp: "application/vnd.irepository.package+xml",
4600
+ jad: "text/vnd.sun.j2me.app-descriptor",
4601
+ jar: "application/java-archive",
4602
+ "class": "application/java-vm",
4603
+ jnlp: "application/x-java-jnlp-file",
4604
+ ser: "application/java-serialized-object",
4605
+ java: "text/x-java-source,java",
4606
+ js: "application/javascript",
4607
+ json: "application/json",
4608
+ joda: "application/vnd.joost.joda-archive",
4609
+ jpm: "video/jpm",
4610
+ jpeg: "image/jpeg",
4611
+ jpg: "image/jpeg",
4612
+ pjpeg: "image/pjpeg",
4613
+ jpgv: "video/jpeg",
4614
+ ktz: "application/vnd.kahootz",
4615
+ mmd: "application/vnd.chipnuts.karaoke-mmd",
4616
+ karbon: "application/vnd.kde.karbon",
4617
+ chrt: "application/vnd.kde.kchart",
4618
+ kfo: "application/vnd.kde.kformula",
4619
+ flw: "application/vnd.kde.kivio",
4620
+ kon: "application/vnd.kde.kontour",
4621
+ kpr: "application/vnd.kde.kpresenter",
4622
+ ksp: "application/vnd.kde.kspread",
4623
+ kwd: "application/vnd.kde.kword",
4624
+ htke: "application/vnd.kenameaapp",
4625
+ kia: "application/vnd.kidspiration",
4626
+ kne: "application/vnd.kinar",
4627
+ sse: "application/vnd.kodak-descriptor",
4628
+ lasxml: "application/vnd.las.las+xml",
4629
+ latex: "application/x-latex",
4630
+ lbd: "application/vnd.llamagraphics.life-balance.desktop",
4631
+ lbe: "application/vnd.llamagraphics.life-balance.exchange+xml",
4632
+ jam: "application/vnd.jam",
4633
+ "123": "application/vnd.lotus-1-2-3",
4634
+ apr: "application/vnd.lotus-approach",
4635
+ pre: "application/vnd.lotus-freelance",
4636
+ nsf: "application/vnd.lotus-notes",
4637
+ org: "application/vnd.lotus-organizer",
4638
+ scm: "application/vnd.lotus-screencam",
4639
+ lwp: "application/vnd.lotus-wordpro",
4640
+ lvp: "audio/vnd.lucent.voice",
4641
+ m3u: "audio/x-mpegurl",
4642
+ m4v: "video/x-m4v",
4643
+ hqx: "application/mac-binhex40",
4644
+ portpkg: "application/vnd.macports.portpkg",
4645
+ mgp: "application/vnd.osgeo.mapguide.package",
4646
+ mrc: "application/marc",
4647
+ mrcx: "application/marcxml+xml",
4648
+ mxf: "application/mxf",
4649
+ nbp: "application/vnd.wolfram.player",
4650
+ ma: "application/mathematica",
4651
+ mathml: "application/mathml+xml",
4652
+ mbox: "application/mbox",
4653
+ mc1: "application/vnd.medcalcdata",
4654
+ mscml: "application/mediaservercontrol+xml",
4655
+ cdkey: "application/vnd.mediastation.cdkey",
4656
+ mwf: "application/vnd.mfer",
4657
+ mfm: "application/vnd.mfmp",
4658
+ msh: "model/mesh",
4659
+ mads: "application/mads+xml",
4660
+ mets: "application/mets+xml",
4661
+ mods: "application/mods+xml",
4662
+ meta4: "application/metalink4+xml",
4663
+ mcd: "application/vnd.mcd",
4664
+ flo: "application/vnd.micrografx.flo",
4665
+ igx: "application/vnd.micrografx.igx",
4666
+ es3: "application/vnd.eszigno3+xml",
4667
+ mdb: "application/x-msaccess",
4668
+ asf: "video/x-ms-asf",
4669
+ exe: "application/x-msdownload",
4670
+ cil: "application/vnd.ms-artgalry",
4671
+ cab: "application/vnd.ms-cab-compressed",
4672
+ ims: "application/vnd.ms-ims",
4673
+ application: "application/x-ms-application",
4674
+ clp: "application/x-msclip",
4675
+ mdi: "image/vnd.ms-modi",
4676
+ eot: "application/vnd.ms-fontobject",
4677
+ xls: "application/vnd.ms-excel",
4678
+ xlam: "application/vnd.ms-excel.addin.macroenabled.12",
4679
+ xlsb: "application/vnd.ms-excel.sheet.binary.macroenabled.12",
4680
+ xltm: "application/vnd.ms-excel.template.macroenabled.12",
4681
+ xlsm: "application/vnd.ms-excel.sheet.macroenabled.12",
4682
+ chm: "application/vnd.ms-htmlhelp",
4683
+ crd: "application/x-mscardfile",
4684
+ lrm: "application/vnd.ms-lrm",
4685
+ mvb: "application/x-msmediaview",
4686
+ mny: "application/x-msmoney",
4687
+ pptx: "application/vnd.openxmlformats-officedocument.presentationml.presentation",
4688
+ sldx: "application/vnd.openxmlformats-officedocument.presentationml.slide",
4689
+ ppsx: "application/vnd.openxmlformats-officedocument.presentationml.slideshow",
4690
+ potx: "application/vnd.openxmlformats-officedocument.presentationml.template",
4691
+ xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
4692
+ xltx: "application/vnd.openxmlformats-officedocument.spreadsheetml.template",
4693
+ docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
4694
+ dotx: "application/vnd.openxmlformats-officedocument.wordprocessingml.template",
4695
+ obd: "application/x-msbinder",
4696
+ thmx: "application/vnd.ms-officetheme",
4697
+ onetoc: "application/onenote",
4698
+ pya: "audio/vnd.ms-playready.media.pya",
4699
+ pyv: "video/vnd.ms-playready.media.pyv",
4700
+ ppt: "application/vnd.ms-powerpoint",
4701
+ ppam: "application/vnd.ms-powerpoint.addin.macroenabled.12",
4702
+ sldm: "application/vnd.ms-powerpoint.slide.macroenabled.12",
4703
+ pptm: "application/vnd.ms-powerpoint.presentation.macroenabled.12",
4704
+ ppsm: "application/vnd.ms-powerpoint.slideshow.macroenabled.12",
4705
+ potm: "application/vnd.ms-powerpoint.template.macroenabled.12",
4706
+ mpp: "application/vnd.ms-project",
4707
+ pub: "application/x-mspublisher",
4708
+ scd: "application/x-msschedule",
4709
+ xap: "application/x-silverlight-app",
4710
+ stl: "application/vnd.ms-pki.stl",
4711
+ cat: "application/vnd.ms-pki.seccat",
4712
+ vsd: "application/vnd.visio",
4713
+ vsdx: "application/vnd.visio2013",
4714
+ wm: "video/x-ms-wm",
4715
+ wma: "audio/x-ms-wma",
4716
+ wax: "audio/x-ms-wax",
4717
+ wmx: "video/x-ms-wmx",
4718
+ wmd: "application/x-ms-wmd",
4719
+ wpl: "application/vnd.ms-wpl",
4720
+ wmz: "application/x-ms-wmz",
4721
+ wmv: "video/x-ms-wmv",
4722
+ wvx: "video/x-ms-wvx",
4723
+ wmf: "application/x-msmetafile",
4724
+ trm: "application/x-msterminal",
4725
+ doc: "application/msword",
4726
+ docm: "application/vnd.ms-word.document.macroenabled.12",
4727
+ dotm: "application/vnd.ms-word.template.macroenabled.12",
4728
+ wri: "application/x-mswrite",
4729
+ wps: "application/vnd.ms-works",
4730
+ xbap: "application/x-ms-xbap",
4731
+ xps: "application/vnd.ms-xpsdocument",
4732
+ mid: "audio/midi",
4733
+ mpy: "application/vnd.ibm.minipay",
4734
+ afp: "application/vnd.ibm.modcap",
4735
+ rms: "application/vnd.jcp.javame.midlet-rms",
4736
+ tmo: "application/vnd.tmobile-livetv",
4737
+ prc: "application/x-mobipocket-ebook",
4738
+ mbk: "application/vnd.mobius.mbk",
4739
+ dis: "application/vnd.mobius.dis",
4740
+ plc: "application/vnd.mobius.plc",
4741
+ mqy: "application/vnd.mobius.mqy",
4742
+ msl: "application/vnd.mobius.msl",
4743
+ txf: "application/vnd.mobius.txf",
4744
+ daf: "application/vnd.mobius.daf",
4745
+ fly: "text/vnd.fly",
4746
+ mpc: "application/vnd.mophun.certificate",
4747
+ mpn: "application/vnd.mophun.application",
4748
+ mj2: "video/mj2",
4749
+ mpga: "audio/mpeg",
4750
+ mxu: "video/vnd.mpegurl",
4751
+ mpeg: "video/mpeg",
4752
+ m21: "application/mp21",
4753
+ mp4a: "audio/mp4",
4754
+ mp4: "video/mp4",
4755
+ m3u8: "application/vnd.apple.mpegurl",
4756
+ mus: "application/vnd.musician",
4757
+ msty: "application/vnd.muvee.style",
4758
+ mxml: "application/xv+xml",
4759
+ ngdat: "application/vnd.nokia.n-gage.data",
4760
+ "n-gage": "application/vnd.nokia.n-gage.symbian.install",
4761
+ ncx: "application/x-dtbncx+xml",
4762
+ nc: "application/x-netcdf",
4763
+ nlu: "application/vnd.neurolanguage.nlu",
4764
+ dna: "application/vnd.dna",
4765
+ nnd: "application/vnd.noblenet-directory",
4766
+ nns: "application/vnd.noblenet-sealer",
4767
+ nnw: "application/vnd.noblenet-web",
4768
+ rpst: "application/vnd.nokia.radio-preset",
4769
+ rpss: "application/vnd.nokia.radio-presets",
4770
+ n3: "text/n3",
4771
+ edm: "application/vnd.novadigm.edm",
4772
+ edx: "application/vnd.novadigm.edx",
4773
+ ext: "application/vnd.novadigm.ext",
4774
+ gph: "application/vnd.flographit",
4775
+ ecelp4800: "audio/vnd.nuera.ecelp4800",
4776
+ ecelp7470: "audio/vnd.nuera.ecelp7470",
4777
+ ecelp9600: "audio/vnd.nuera.ecelp9600",
4778
+ oda: "application/oda",
4779
+ ogx: "application/ogg",
4780
+ oga: "audio/ogg",
4781
+ ogv: "video/ogg",
4782
+ dd2: "application/vnd.oma.dd2+xml",
4783
+ oth: "application/vnd.oasis.opendocument.text-web",
4784
+ opf: "application/oebps-package+xml",
4785
+ qbo: "application/vnd.intu.qbo",
4786
+ oxt: "application/vnd.openofficeorg.extension",
4787
+ osf: "application/vnd.yamaha.openscoreformat",
4788
+ weba: "audio/webm",
4789
+ webm: "video/webm",
4790
+ odc: "application/vnd.oasis.opendocument.chart",
4791
+ otc: "application/vnd.oasis.opendocument.chart-template",
4792
+ odb: "application/vnd.oasis.opendocument.database",
4793
+ odf: "application/vnd.oasis.opendocument.formula",
4794
+ odft: "application/vnd.oasis.opendocument.formula-template",
4795
+ odg: "application/vnd.oasis.opendocument.graphics",
4796
+ otg: "application/vnd.oasis.opendocument.graphics-template",
4797
+ odi: "application/vnd.oasis.opendocument.image",
4798
+ oti: "application/vnd.oasis.opendocument.image-template",
4799
+ odp: "application/vnd.oasis.opendocument.presentation",
4800
+ otp: "application/vnd.oasis.opendocument.presentation-template",
4801
+ ods: "application/vnd.oasis.opendocument.spreadsheet",
4802
+ ots: "application/vnd.oasis.opendocument.spreadsheet-template",
4803
+ odt: "application/vnd.oasis.opendocument.text",
4804
+ odm: "application/vnd.oasis.opendocument.text-master",
4805
+ ott: "application/vnd.oasis.opendocument.text-template",
4806
+ ktx: "image/ktx",
4807
+ sxc: "application/vnd.sun.xml.calc",
4808
+ stc: "application/vnd.sun.xml.calc.template",
4809
+ sxd: "application/vnd.sun.xml.draw",
4810
+ std: "application/vnd.sun.xml.draw.template",
4811
+ sxi: "application/vnd.sun.xml.impress",
4812
+ sti: "application/vnd.sun.xml.impress.template",
4813
+ sxm: "application/vnd.sun.xml.math",
4814
+ sxw: "application/vnd.sun.xml.writer",
4815
+ sxg: "application/vnd.sun.xml.writer.global",
4816
+ stw: "application/vnd.sun.xml.writer.template",
4817
+ otf: "application/x-font-otf",
4818
+ osfpvg: "application/vnd.yamaha.openscoreformat.osfpvg+xml",
4819
+ dp: "application/vnd.osgi.dp",
4820
+ pdb: "application/vnd.palm",
4821
+ p: "text/x-pascal",
4822
+ paw: "application/vnd.pawaafile",
4823
+ pclxl: "application/vnd.hp-pclxl",
4824
+ efif: "application/vnd.picsel",
4825
+ pcx: "image/x-pcx",
4826
+ psd: "image/vnd.adobe.photoshop",
4827
+ prf: "application/pics-rules",
4828
+ pic: "image/x-pict",
4829
+ chat: "application/x-chat",
4830
+ p10: "application/pkcs10",
4831
+ p12: "application/x-pkcs12",
4832
+ p7m: "application/pkcs7-mime",
4833
+ p7s: "application/pkcs7-signature",
4834
+ p7r: "application/x-pkcs7-certreqresp",
4835
+ p7b: "application/x-pkcs7-certificates",
4836
+ p8: "application/pkcs8",
4837
+ plf: "application/vnd.pocketlearn",
4838
+ pnm: "image/x-portable-anymap",
4839
+ pbm: "image/x-portable-bitmap",
4840
+ pcf: "application/x-font-pcf",
4841
+ pfr: "application/font-tdpfr",
4842
+ pgn: "application/x-chess-pgn",
4843
+ pgm: "image/x-portable-graymap",
4844
+ png: "image/png",
4845
+ ppm: "image/x-portable-pixmap",
4846
+ pskcxml: "application/pskc+xml",
4847
+ pml: "application/vnd.ctc-posml",
4848
+ ai: "application/postscript",
4849
+ pfa: "application/x-font-type1",
4850
+ pbd: "application/vnd.powerbuilder6",
4851
+ pgp: "application/pgp-signature",
4852
+ box: "application/vnd.previewsystems.box",
4853
+ ptid: "application/vnd.pvi.ptid1",
4854
+ pls: "application/pls+xml",
4855
+ str: "application/vnd.pg.format",
4856
+ ei6: "application/vnd.pg.osasli",
4857
+ dsc: "text/prs.lines.tag",
4858
+ psf: "application/x-font-linux-psf",
4859
+ qps: "application/vnd.publishare-delta-tree",
4860
+ wg: "application/vnd.pmi.widget",
4861
+ qxd: "application/vnd.quark.quarkxpress",
4862
+ esf: "application/vnd.epson.esf",
4863
+ msf: "application/vnd.epson.msf",
4864
+ ssf: "application/vnd.epson.ssf",
4865
+ qam: "application/vnd.epson.quickanime",
4866
+ qfx: "application/vnd.intu.qfx",
4867
+ qt: "video/quicktime",
4868
+ rar: "application/x-rar-compressed",
4869
+ ram: "audio/x-pn-realaudio",
4870
+ rmp: "audio/x-pn-realaudio-plugin",
4871
+ rsd: "application/rsd+xml",
4872
+ rm: "application/vnd.rn-realmedia",
4873
+ bed: "application/vnd.realvnc.bed",
4874
+ mxl: "application/vnd.recordare.musicxml",
4875
+ musicxml: "application/vnd.recordare.musicxml+xml",
4876
+ rnc: "application/relax-ng-compact-syntax",
4877
+ rdz: "application/vnd.data-vision.rdz",
4878
+ rdf: "application/rdf+xml",
4879
+ rp9: "application/vnd.cloanto.rp9",
4880
+ jisp: "application/vnd.jisp",
4881
+ rtf: "application/rtf",
4882
+ rtx: "text/richtext",
4883
+ link66: "application/vnd.route66.link66+xml",
4884
+ rss: "application/rss+xml",
4885
+ shf: "application/shf+xml",
4886
+ st: "application/vnd.sailingtracker.track",
4887
+ svg: "image/svg+xml",
4888
+ sus: "application/vnd.sus-calendar",
4889
+ sru: "application/sru+xml",
4890
+ setpay: "application/set-payment-initiation",
4891
+ setreg: "application/set-registration-initiation",
4892
+ sema: "application/vnd.sema",
4893
+ semd: "application/vnd.semd",
4894
+ semf: "application/vnd.semf",
4895
+ see: "application/vnd.seemail",
4896
+ snf: "application/x-font-snf",
4897
+ spq: "application/scvp-vp-request",
4898
+ spp: "application/scvp-vp-response",
4899
+ scq: "application/scvp-cv-request",
4900
+ scs: "application/scvp-cv-response",
4901
+ sdp: "application/sdp",
4902
+ etx: "text/x-setext",
4903
+ movie: "video/x-sgi-movie",
4904
+ ifm: "application/vnd.shana.informed.formdata",
4905
+ itp: "application/vnd.shana.informed.formtemplate",
4906
+ iif: "application/vnd.shana.informed.interchange",
4907
+ ipk: "application/vnd.shana.informed.package",
4908
+ tfi: "application/thraud+xml",
4909
+ shar: "application/x-shar",
4910
+ rgb: "image/x-rgb",
4911
+ slt: "application/vnd.epson.salt",
4912
+ aso: "application/vnd.accpac.simply.aso",
4913
+ imp: "application/vnd.accpac.simply.imp",
4914
+ twd: "application/vnd.simtech-mindmapper",
4915
+ csp: "application/vnd.commonspace",
4916
+ saf: "application/vnd.yamaha.smaf-audio",
4917
+ mmf: "application/vnd.smaf",
4918
+ spf: "application/vnd.yamaha.smaf-phrase",
4919
+ teacher: "application/vnd.smart.teacher",
4920
+ svd: "application/vnd.svd",
4921
+ rq: "application/sparql-query",
4922
+ srx: "application/sparql-results+xml",
4923
+ gram: "application/srgs",
4924
+ grxml: "application/srgs+xml",
4925
+ ssml: "application/ssml+xml",
4926
+ skp: "application/vnd.koan",
4927
+ sgml: "text/sgml",
4928
+ sdc: "application/vnd.stardivision.calc",
4929
+ sda: "application/vnd.stardivision.draw",
4930
+ sdd: "application/vnd.stardivision.impress",
4931
+ smf: "application/vnd.stardivision.math",
4932
+ sdw: "application/vnd.stardivision.writer",
4933
+ sgl: "application/vnd.stardivision.writer-global",
4934
+ sm: "application/vnd.stepmania.stepchart",
4935
+ sit: "application/x-stuffit",
4936
+ sitx: "application/x-stuffitx",
4937
+ sdkm: "application/vnd.solent.sdkm+xml",
4938
+ xo: "application/vnd.olpc-sugar",
4939
+ au: "audio/basic",
4940
+ wqd: "application/vnd.wqd",
4941
+ sis: "application/vnd.symbian.install",
4942
+ smi: "application/smil+xml",
4943
+ xsm: "application/vnd.syncml+xml",
4944
+ bdm: "application/vnd.syncml.dm+wbxml",
4945
+ xdm: "application/vnd.syncml.dm+xml",
4946
+ sv4cpio: "application/x-sv4cpio",
4947
+ sv4crc: "application/x-sv4crc",
4948
+ sbml: "application/sbml+xml",
4949
+ tsv: "text/tab-separated-values",
4950
+ tiff: "image/tiff",
4951
+ tao: "application/vnd.tao.intent-module-archive",
4952
+ tar: "application/x-tar",
4953
+ tcl: "application/x-tcl",
4954
+ tex: "application/x-tex",
4955
+ tfm: "application/x-tex-tfm",
4956
+ tei: "application/tei+xml",
4957
+ txt: "text/plain",
4958
+ dxp: "application/vnd.spotfire.dxp",
4959
+ sfs: "application/vnd.spotfire.sfs",
4960
+ tsd: "application/timestamped-data",
4961
+ tpt: "application/vnd.trid.tpt",
4962
+ mxs: "application/vnd.triscape.mxs",
4963
+ t: "text/troff",
4964
+ tra: "application/vnd.trueapp",
4965
+ ttf: "application/x-font-ttf",
4966
+ ttl: "text/turtle",
4967
+ umj: "application/vnd.umajin",
4968
+ uoml: "application/vnd.uoml+xml",
4969
+ unityweb: "application/vnd.unity",
4970
+ ufd: "application/vnd.ufdl",
4971
+ uri: "text/uri-list",
4972
+ utz: "application/vnd.uiq.theme",
4973
+ ustar: "application/x-ustar",
4974
+ uu: "text/x-uuencode",
4975
+ vcs: "text/x-vcalendar",
4976
+ vcf: "text/x-vcard",
4977
+ vcd: "application/x-cdlink",
4978
+ vsf: "application/vnd.vsf",
4979
+ wrl: "model/vrml",
4980
+ vcx: "application/vnd.vcx",
4981
+ mts: "model/vnd.mts",
4982
+ vtu: "model/vnd.vtu",
4983
+ vis: "application/vnd.visionary",
4984
+ viv: "video/vnd.vivo",
4985
+ ccxml: "application/ccxml+xml,",
4986
+ vxml: "application/voicexml+xml",
4987
+ src: "application/x-wais-source",
4988
+ wbxml: "application/vnd.wap.wbxml",
4989
+ wbmp: "image/vnd.wap.wbmp",
4990
+ wav: "audio/x-wav",
4991
+ davmount: "application/davmount+xml",
4992
+ woff: "application/x-font-woff",
4993
+ wspolicy: "application/wspolicy+xml",
4994
+ webp: "image/webp",
4995
+ wtb: "application/vnd.webturbo",
4996
+ wgt: "application/widget",
4997
+ hlp: "application/winhlp",
4998
+ wml: "text/vnd.wap.wml",
4999
+ wmls: "text/vnd.wap.wmlscript",
5000
+ wmlsc: "application/vnd.wap.wmlscriptc",
5001
+ wpd: "application/vnd.wordperfect",
5002
+ stf: "application/vnd.wt.stf",
5003
+ wsdl: "application/wsdl+xml",
5004
+ xbm: "image/x-xbitmap",
5005
+ xpm: "image/x-xpixmap",
5006
+ xwd: "image/x-xwindowdump",
5007
+ der: "application/x-x509-ca-cert",
5008
+ fig: "application/x-xfig",
5009
+ xhtml: "application/xhtml+xml",
5010
+ xml: "application/xml",
5011
+ xdf: "application/xcap-diff+xml",
5012
+ xenc: "application/xenc+xml",
5013
+ xer: "application/patch-ops-error+xml",
5014
+ rl: "application/resource-lists+xml",
5015
+ rs: "application/rls-services+xml",
5016
+ rld: "application/resource-lists-diff+xml",
5017
+ xslt: "application/xslt+xml",
5018
+ xop: "application/xop+xml",
5019
+ xpi: "application/x-xpinstall",
5020
+ xspf: "application/xspf+xml",
5021
+ xul: "application/vnd.mozilla.xul+xml",
5022
+ xyz: "chemical/x-xyz",
5023
+ yaml: "text/yaml",
5024
+ yang: "application/yang",
5025
+ yin: "application/yin+xml",
5026
+ zir: "application/vnd.zul",
5027
+ zip: "application/zip",
5028
+ zmm: "application/vnd.handheld-entertainment+xml",
5029
+ zaz: "application/vnd.zzazz.deck+xml"
5030
+ };
5031
+
5032
+ // TODO: write this out to avoid compute
5033
+ var MIME_TYPES_TO_EXT = Object.fromEntries(Object.entries(EXT_TO_MIME_TYPES).map(function (_ref) {
5034
+ var _ref2 = _slicedToArray(_ref, 2),
5035
+ k = _ref2[0],
5036
+ v = _ref2[1];
5037
+ return [v, k];
5038
+ }));
5039
+
5040
+ var MIME_TYPE_REGEX = /^data:(.*?);base64,/;
5041
+ function getMimeType(base64Url) {
5042
+ var match = MIME_TYPE_REGEX.exec(base64Url);
5043
+ if (match && match[1]) {
5044
+ return match[1];
5045
+ }
5046
+ return;
5047
+ }
5048
+ function mimeTypeToFileExt(mimeType) {
5049
+ var recognizedMimeType = MIME_TYPES_TO_EXT[mimeType];
5050
+ if (recognizedMimeType) {
5051
+ return recognizedMimeType;
5052
+ }
5053
+ return mimeType.split("/")[1];
5054
+ }
5055
+ function filenameToMimeType(filename) {
5056
+ var ext = filename.split(".").pop();
5057
+ var recognizedExt = ext && EXT_TO_MIME_TYPES[ext];
5058
+ if (recognizedExt) {
5059
+ return recognizedExt;
5060
+ }
5061
+ }
5062
+
3640
5063
  function deserializeSchema(serialized) {
3641
5064
  var _serialized$options;
3642
5065
  switch (serialized.type) {
@@ -3660,9 +5083,16 @@ function deserializeSchema(serialized) {
3660
5083
  case "array":
3661
5084
  return new ArraySchema(deserializeSchema(serialized.item), serialized.opt);
3662
5085
  case "union":
3663
- return new UnionSchema(typeof serialized.key === "string" ? serialized.key : deserializeSchema(serialized.key), serialized.items.map(deserializeSchema), serialized.opt);
5086
+ return new UnionSchema(typeof serialized.key === "string" ? serialized.key :
5087
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5088
+ deserializeSchema(serialized.key),
5089
+ // TODO: we do not really need any here - right?
5090
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5091
+ serialized.items.map(deserializeSchema),
5092
+ // TODO: we do not really need any here - right?
5093
+ serialized.opt);
3664
5094
  case "richtext":
3665
- return new RichTextSchema(serialized.options, serialized.opt);
5095
+ return new RichTextSchema(serialized.options || {}, serialized.opt);
3666
5096
  case "record":
3667
5097
  return new RecordSchema(deserializeSchema(serialized.item), serialized.opt);
3668
5098
  case "keyOf":
@@ -3686,671 +5116,7 @@ function deserializeSchema(serialized) {
3686
5116
  }
3687
5117
  }
3688
5118
 
3689
- function _regeneratorRuntime() {
3690
- _regeneratorRuntime = function () {
3691
- return e;
3692
- };
3693
- var t,
3694
- e = {},
3695
- r = Object.prototype,
3696
- n = r.hasOwnProperty,
3697
- o = Object.defineProperty || function (t, e, r) {
3698
- t[e] = r.value;
3699
- },
3700
- i = "function" == typeof Symbol ? Symbol : {},
3701
- a = i.iterator || "@@iterator",
3702
- c = i.asyncIterator || "@@asyncIterator",
3703
- u = i.toStringTag || "@@toStringTag";
3704
- function define(t, e, r) {
3705
- return Object.defineProperty(t, e, {
3706
- value: r,
3707
- enumerable: !0,
3708
- configurable: !0,
3709
- writable: !0
3710
- }), t[e];
3711
- }
3712
- try {
3713
- define({}, "");
3714
- } catch (t) {
3715
- define = function (t, e, r) {
3716
- return t[e] = r;
3717
- };
3718
- }
3719
- function wrap(t, e, r, n) {
3720
- var i = e && e.prototype instanceof Generator ? e : Generator,
3721
- a = Object.create(i.prototype),
3722
- c = new Context(n || []);
3723
- return o(a, "_invoke", {
3724
- value: makeInvokeMethod(t, r, c)
3725
- }), a;
3726
- }
3727
- function tryCatch(t, e, r) {
3728
- try {
3729
- return {
3730
- type: "normal",
3731
- arg: t.call(e, r)
3732
- };
3733
- } catch (t) {
3734
- return {
3735
- type: "throw",
3736
- arg: t
3737
- };
3738
- }
3739
- }
3740
- e.wrap = wrap;
3741
- var h = "suspendedStart",
3742
- l = "suspendedYield",
3743
- f = "executing",
3744
- s = "completed",
3745
- y = {};
3746
- function Generator() {}
3747
- function GeneratorFunction() {}
3748
- function GeneratorFunctionPrototype() {}
3749
- var p = {};
3750
- define(p, a, function () {
3751
- return this;
3752
- });
3753
- var d = Object.getPrototypeOf,
3754
- v = d && d(d(values([])));
3755
- v && v !== r && n.call(v, a) && (p = v);
3756
- var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);
3757
- function defineIteratorMethods(t) {
3758
- ["next", "throw", "return"].forEach(function (e) {
3759
- define(t, e, function (t) {
3760
- return this._invoke(e, t);
3761
- });
3762
- });
3763
- }
3764
- function AsyncIterator(t, e) {
3765
- function invoke(r, o, i, a) {
3766
- var c = tryCatch(t[r], t, o);
3767
- if ("throw" !== c.type) {
3768
- var u = c.arg,
3769
- h = u.value;
3770
- return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) {
3771
- invoke("next", t, i, a);
3772
- }, function (t) {
3773
- invoke("throw", t, i, a);
3774
- }) : e.resolve(h).then(function (t) {
3775
- u.value = t, i(u);
3776
- }, function (t) {
3777
- return invoke("throw", t, i, a);
3778
- });
3779
- }
3780
- a(c.arg);
3781
- }
3782
- var r;
3783
- o(this, "_invoke", {
3784
- value: function (t, n) {
3785
- function callInvokeWithMethodAndArg() {
3786
- return new e(function (e, r) {
3787
- invoke(t, n, e, r);
3788
- });
3789
- }
3790
- return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
3791
- }
3792
- });
3793
- }
3794
- function makeInvokeMethod(e, r, n) {
3795
- var o = h;
3796
- return function (i, a) {
3797
- if (o === f) throw new Error("Generator is already running");
3798
- if (o === s) {
3799
- if ("throw" === i) throw a;
3800
- return {
3801
- value: t,
3802
- done: !0
3803
- };
3804
- }
3805
- for (n.method = i, n.arg = a;;) {
3806
- var c = n.delegate;
3807
- if (c) {
3808
- var u = maybeInvokeDelegate(c, n);
3809
- if (u) {
3810
- if (u === y) continue;
3811
- return u;
3812
- }
3813
- }
3814
- if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) {
3815
- if (o === h) throw o = s, n.arg;
3816
- n.dispatchException(n.arg);
3817
- } else "return" === n.method && n.abrupt("return", n.arg);
3818
- o = f;
3819
- var p = tryCatch(e, r, n);
3820
- if ("normal" === p.type) {
3821
- if (o = n.done ? s : l, p.arg === y) continue;
3822
- return {
3823
- value: p.arg,
3824
- done: n.done
3825
- };
3826
- }
3827
- "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg);
3828
- }
3829
- };
3830
- }
3831
- function maybeInvokeDelegate(e, r) {
3832
- var n = r.method,
3833
- o = e.iterator[n];
3834
- if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y;
3835
- var i = tryCatch(o, e.iterator, r.arg);
3836
- if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y;
3837
- var a = i.arg;
3838
- return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y);
3839
- }
3840
- function pushTryEntry(t) {
3841
- var e = {
3842
- tryLoc: t[0]
3843
- };
3844
- 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e);
3845
- }
3846
- function resetTryEntry(t) {
3847
- var e = t.completion || {};
3848
- e.type = "normal", delete e.arg, t.completion = e;
3849
- }
3850
- function Context(t) {
3851
- this.tryEntries = [{
3852
- tryLoc: "root"
3853
- }], t.forEach(pushTryEntry, this), this.reset(!0);
3854
- }
3855
- function values(e) {
3856
- if (e || "" === e) {
3857
- var r = e[a];
3858
- if (r) return r.call(e);
3859
- if ("function" == typeof e.next) return e;
3860
- if (!isNaN(e.length)) {
3861
- var o = -1,
3862
- i = function next() {
3863
- for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next;
3864
- return next.value = t, next.done = !0, next;
3865
- };
3866
- return i.next = i;
3867
- }
3868
- }
3869
- throw new TypeError(typeof e + " is not iterable");
3870
- }
3871
- return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", {
3872
- value: GeneratorFunctionPrototype,
3873
- configurable: !0
3874
- }), o(GeneratorFunctionPrototype, "constructor", {
3875
- value: GeneratorFunction,
3876
- configurable: !0
3877
- }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) {
3878
- var e = "function" == typeof t && t.constructor;
3879
- return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name));
3880
- }, e.mark = function (t) {
3881
- return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t;
3882
- }, e.awrap = function (t) {
3883
- return {
3884
- __await: t
3885
- };
3886
- }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {
3887
- return this;
3888
- }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {
3889
- void 0 === i && (i = Promise);
3890
- var a = new AsyncIterator(wrap(t, r, n, o), i);
3891
- return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
3892
- return t.done ? t.value : a.next();
3893
- });
3894
- }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () {
3895
- return this;
3896
- }), define(g, "toString", function () {
3897
- return "[object Generator]";
3898
- }), e.keys = function (t) {
3899
- var e = Object(t),
3900
- r = [];
3901
- for (var n in e) r.push(n);
3902
- return r.reverse(), function next() {
3903
- for (; r.length;) {
3904
- var t = r.pop();
3905
- if (t in e) return next.value = t, next.done = !1, next;
3906
- }
3907
- return next.done = !0, next;
3908
- };
3909
- }, e.values = values, Context.prototype = {
3910
- constructor: Context,
3911
- reset: function (e) {
3912
- if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t);
3913
- },
3914
- stop: function () {
3915
- this.done = !0;
3916
- var t = this.tryEntries[0].completion;
3917
- if ("throw" === t.type) throw t.arg;
3918
- return this.rval;
3919
- },
3920
- dispatchException: function (e) {
3921
- if (this.done) throw e;
3922
- var r = this;
3923
- function handle(n, o) {
3924
- return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o;
3925
- }
3926
- for (var o = this.tryEntries.length - 1; o >= 0; --o) {
3927
- var i = this.tryEntries[o],
3928
- a = i.completion;
3929
- if ("root" === i.tryLoc) return handle("end");
3930
- if (i.tryLoc <= this.prev) {
3931
- var c = n.call(i, "catchLoc"),
3932
- u = n.call(i, "finallyLoc");
3933
- if (c && u) {
3934
- if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
3935
- if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
3936
- } else if (c) {
3937
- if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
3938
- } else {
3939
- if (!u) throw new Error("try statement without catch or finally");
3940
- if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
3941
- }
3942
- }
3943
- }
3944
- },
3945
- abrupt: function (t, e) {
3946
- for (var r = this.tryEntries.length - 1; r >= 0; --r) {
3947
- var o = this.tryEntries[r];
3948
- if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) {
3949
- var i = o;
3950
- break;
3951
- }
3952
- }
3953
- i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null);
3954
- var a = i ? i.completion : {};
3955
- return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a);
3956
- },
3957
- complete: function (t, e) {
3958
- if ("throw" === t.type) throw t.arg;
3959
- return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y;
3960
- },
3961
- finish: function (t) {
3962
- for (var e = this.tryEntries.length - 1; e >= 0; --e) {
3963
- var r = this.tryEntries[e];
3964
- if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y;
3965
- }
3966
- },
3967
- catch: function (t) {
3968
- for (var e = this.tryEntries.length - 1; e >= 0; --e) {
3969
- var r = this.tryEntries[e];
3970
- if (r.tryLoc === t) {
3971
- var n = r.completion;
3972
- if ("throw" === n.type) {
3973
- var o = n.arg;
3974
- resetTryEntry(r);
3975
- }
3976
- return o;
3977
- }
3978
- }
3979
- throw new Error("illegal catch attempt");
3980
- },
3981
- delegateYield: function (e, r, n) {
3982
- return this.delegate = {
3983
- iterator: values(e),
3984
- resultName: r,
3985
- nextLoc: n
3986
- }, "next" === this.method && (this.arg = t), y;
3987
- }
3988
- }, e;
3989
- }
3990
-
3991
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
3992
- try {
3993
- var info = gen[key](arg);
3994
- var value = info.value;
3995
- } catch (error) {
3996
- reject(error);
3997
- return;
3998
- }
3999
- if (info.done) {
4000
- resolve(value);
4001
- } else {
4002
- Promise.resolve(value).then(_next, _throw);
4003
- }
4004
- }
4005
- function _asyncToGenerator(fn) {
4006
- return function () {
4007
- var self = this,
4008
- args = arguments;
4009
- return new Promise(function (resolve, reject) {
4010
- var gen = fn.apply(self, args);
4011
- function _next(value) {
4012
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
4013
- }
4014
- function _throw(err) {
4015
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
4016
- }
4017
- _next(undefined);
4018
- });
4019
- };
4020
- }
4021
-
4022
- // TODO: move this to internal, only reason this is here is that react, ui and server all depend on it
4023
- var ValApi = /*#__PURE__*/function () {
4024
- function ValApi(host) {
4025
- _classCallCheck(this, ValApi);
4026
- this.host = host;
4027
- }
4028
- _createClass(ValApi, [{
4029
- key: "getDisableUrl",
4030
- value: function getDisableUrl(redirectTo) {
4031
- return "".concat(this.host, "/disable?redirect_to=").concat(encodeURIComponent(redirectTo));
4032
- }
4033
- }, {
4034
- key: "getLoginUrl",
4035
- value: function getLoginUrl(redirectTo) {
4036
- return "".concat(this.host, "/authorize?redirect_to=").concat(encodeURIComponent(redirectTo));
4037
- }
4038
- }, {
4039
- key: "getEnableUrl",
4040
- value: function getEnableUrl(redirectTo) {
4041
- return "".concat(this.host, "/enable?redirect_to=").concat(encodeURIComponent(redirectTo));
4042
- }
4043
- }, {
4044
- key: "getPatches",
4045
- value: function () {
4046
- var _getPatches = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(filters) {
4047
- var params, _iterator, _step, patchId, _iterator2, _step2, author, _iterator3, _step3, moduleFilePath, searchParams;
4048
- return _regeneratorRuntime().wrap(function _callee$(_context) {
4049
- while (1) switch (_context.prev = _context.next) {
4050
- case 0:
4051
- params = [];
4052
- if (filters) {
4053
- if (filters.patchIds) {
4054
- _iterator = result._createForOfIteratorHelper(filters.patchIds);
4055
- try {
4056
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
4057
- patchId = _step.value;
4058
- params.push(["patch_id", patchId]);
4059
- }
4060
- } catch (err) {
4061
- _iterator.e(err);
4062
- } finally {
4063
- _iterator.f();
4064
- }
4065
- }
4066
- if (filters.authors) {
4067
- _iterator2 = result._createForOfIteratorHelper(filters.authors);
4068
- try {
4069
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
4070
- author = _step2.value;
4071
- params.push(["author", author]);
4072
- }
4073
- } catch (err) {
4074
- _iterator2.e(err);
4075
- } finally {
4076
- _iterator2.f();
4077
- }
4078
- }
4079
- if (filters.moduleFilePaths) {
4080
- _iterator3 = result._createForOfIteratorHelper(filters.moduleFilePaths);
4081
- try {
4082
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
4083
- moduleFilePath = _step3.value;
4084
- params.push(["module_file_path", moduleFilePath]);
4085
- }
4086
- } catch (err) {
4087
- _iterator3.e(err);
4088
- } finally {
4089
- _iterator3.f();
4090
- }
4091
- }
4092
- if (filters.omitPatches) {
4093
- params.push(["omit_patches", "true"]);
4094
- }
4095
- }
4096
- searchParams = new URLSearchParams(params);
4097
- return _context.abrupt("return", fetch("".concat(this.host, "/patches/~").concat(searchParams.size > 0 ? "?".concat(searchParams.toString()) : ""), {
4098
- headers: {
4099
- "Content-Type": "application/json"
4100
- }
4101
- }).then(function (res) {
4102
- return parse(res);
4103
- })["catch"](createError));
4104
- case 4:
4105
- case "end":
4106
- return _context.stop();
4107
- }
4108
- }, _callee, this);
4109
- }));
4110
- function getPatches(_x) {
4111
- return _getPatches.apply(this, arguments);
4112
- }
4113
- return getPatches;
4114
- }()
4115
- }, {
4116
- key: "deletePatches",
4117
- value: function () {
4118
- var _deletePatches = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(ids, headers) {
4119
- var params;
4120
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
4121
- while (1) switch (_context2.prev = _context2.next) {
4122
- case 0:
4123
- params = new URLSearchParams();
4124
- ids.forEach(function (id) {
4125
- return params.append("id", id);
4126
- });
4127
- return _context2.abrupt("return", fetch("".concat(this.host, "/patches/~?").concat(params), {
4128
- method: "DELETE",
4129
- headers: headers || {
4130
- "Content-Type": "application/json"
4131
- }
4132
- }).then(function (res) {
4133
- return parse(res);
4134
- })["catch"](createError));
4135
- case 3:
4136
- case "end":
4137
- return _context2.stop();
4138
- }
4139
- }, _callee2, this);
4140
- }));
4141
- function deletePatches(_x2, _x3) {
4142
- return _deletePatches.apply(this, arguments);
4143
- }
4144
- return deletePatches;
4145
- }()
4146
- }, {
4147
- key: "getEditUrl",
4148
- value: function getEditUrl() {
4149
- // TODO: make route configurable
4150
- return "/val/~";
4151
- }
4152
- }, {
4153
- key: "getSession",
4154
- value: function getSession() {
4155
- return fetch("".concat(this.host, "/session")).then(function (res) {
4156
- return parse(res)["catch"](createError);
4157
- });
4158
- }
4159
- }, {
4160
- key: "getSchema",
4161
- value: function getSchema(_ref) {
4162
- var headers = _ref.headers;
4163
- return fetch("".concat(this.host, "/schema"), {
4164
- method: "GET",
4165
- headers: headers
4166
- }).then(function (res) {
4167
- return parse(res);
4168
- })["catch"](createError);
4169
- }
4170
- }, {
4171
- key: "putTree",
4172
- value: function putTree(_ref2) {
4173
- var _ref2$treePath = _ref2.treePath,
4174
- treePath = _ref2$treePath === void 0 ? "/" : _ref2$treePath,
4175
- patchIds = _ref2.patchIds,
4176
- addPatch = _ref2.addPatch,
4177
- validateAll = _ref2.validateAll,
4178
- validateSource = _ref2.validateSource,
4179
- validateBinaryFiles = _ref2.validateBinaryFiles,
4180
- headers = _ref2.headers;
4181
- var params = new URLSearchParams();
4182
- var textEncoder = new TextEncoder();
4183
- var patchesSha = getSHA256Hash(textEncoder.encode((patchIds || []).concat(JSON.stringify(addPatch || {})).join(";")));
4184
- params.set("patches_sha", patchesSha);
4185
- params.set("validate_all", (validateAll || false).toString());
4186
- params.set("validate_source", (validateSource || false).toString());
4187
- params.set("validate_binary_files", (validateBinaryFiles || false).toString());
4188
- return fetch("".concat(this.host, "/tree/~").concat(treePath, "?").concat(params.toString()), {
4189
- method: "PUT",
4190
- body: JSON.stringify({
4191
- patchIds: patchIds,
4192
- addPatch: addPatch
4193
- }),
4194
- headers: headers
4195
- }).then(function (res) {
4196
- return parse(res);
4197
- })["catch"](createError);
4198
- }
4199
- }, {
4200
- key: "postSave",
4201
- value: function postSave(_ref3) {
4202
- var patchIds = _ref3.patchIds;
4203
- return fetch("".concat(this.host, "/save"), {
4204
- method: "POST",
4205
- body: JSON.stringify({
4206
- patchIds: patchIds
4207
- }),
4208
- headers: {
4209
- "Content-Type": "application/json"
4210
- }
4211
- }).then( /*#__PURE__*/function () {
4212
- var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(res) {
4213
- var jsonRes;
4214
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
4215
- while (1) switch (_context3.prev = _context3.next) {
4216
- case 0:
4217
- if (!res.ok) {
4218
- _context3.next = 4;
4219
- break;
4220
- }
4221
- return _context3.abrupt("return", parse(res));
4222
- case 4:
4223
- if (!(res.status === 400 && res.headers.get("content-type") === "application/json")) {
4224
- _context3.next = 9;
4225
- break;
4226
- }
4227
- _context3.next = 7;
4228
- return res.json();
4229
- case 7:
4230
- jsonRes = _context3.sent;
4231
- alert(JSON.stringify(jsonRes));
4232
- case 9:
4233
- return _context3.abrupt("return", parse(res));
4234
- case 10:
4235
- case "end":
4236
- return _context3.stop();
4237
- }
4238
- }, _callee3);
4239
- }));
4240
- return function (_x4) {
4241
- return _ref4.apply(this, arguments);
4242
- };
4243
- }())["catch"](createError);
4244
- }
4245
- }, {
4246
- key: "postValidate",
4247
- value: function postValidate(_ref5) {
4248
- var patches = _ref5.patches,
4249
- headers = _ref5.headers;
4250
- return fetch("".concat(this.host, "/validate"), {
4251
- method: "POST",
4252
- body: JSON.stringify({
4253
- patches: patches
4254
- }),
4255
- headers: headers || {
4256
- "Content-Type": "application/json"
4257
- }
4258
- }).then( /*#__PURE__*/function () {
4259
- var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(res) {
4260
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
4261
- while (1) switch (_context4.prev = _context4.next) {
4262
- case 0:
4263
- return _context4.abrupt("return", parse(res));
4264
- case 1:
4265
- case "end":
4266
- return _context4.stop();
4267
- }
4268
- }, _callee4);
4269
- }));
4270
- return function (_x5) {
4271
- return _ref6.apply(this, arguments);
4272
- };
4273
- }())["catch"](createError);
4274
- }
4275
- }]);
4276
- return ValApi;
4277
- }();
4278
- function createError(err) {
4279
- return result.err({
4280
- statusCode: 500,
4281
- message: err instanceof Error ? err.message : _typeof(err) === "object" && err && "message" in err && typeof err.message === "string" ? err.message : "Unknown error",
4282
- details: _typeof(err) === "object" && err && "details" in err ? err.details : undefined
4283
- });
4284
- }
4285
-
4286
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
4287
- function formatError(status, json, statusText) {
4288
- return result.err({
4289
- statusCode: status,
4290
- message: json.message || statusText,
4291
- details: json.details || Object.fromEntries(Object.entries(json).filter(function (_ref7) {
4292
- var _ref8 = _slicedToArray(_ref7, 1),
4293
- key = _ref8[0];
4294
- return key !== "message";
4295
- }))
4296
- });
4297
- }
4298
-
4299
- // TODO: validate
4300
- function parse(_x6) {
4301
- return _parse.apply(this, arguments);
4302
- }
4303
- function _parse() {
4304
- _parse = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(res) {
4305
- var json;
4306
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
4307
- while (1) switch (_context5.prev = _context5.next) {
4308
- case 0:
4309
- _context5.prev = 0;
4310
- if (!res.ok) {
4311
- _context5.next = 9;
4312
- break;
4313
- }
4314
- _context5.t0 = result.result;
4315
- _context5.next = 5;
4316
- return res.json();
4317
- case 5:
4318
- _context5.t1 = _context5.sent;
4319
- return _context5.abrupt("return", _context5.t0.ok.call(_context5.t0, _context5.t1));
4320
- case 9:
4321
- _context5.prev = 9;
4322
- _context5.next = 12;
4323
- return res.json();
4324
- case 12:
4325
- json = _context5.sent;
4326
- return _context5.abrupt("return", formatError(res.status, json, res.statusText));
4327
- case 16:
4328
- _context5.prev = 16;
4329
- _context5.t2 = _context5["catch"](9);
4330
- return _context5.abrupt("return", result.err({
4331
- statusCode: res.status,
4332
- message: res.statusText
4333
- }));
4334
- case 19:
4335
- _context5.next = 24;
4336
- break;
4337
- case 21:
4338
- _context5.prev = 21;
4339
- _context5.t3 = _context5["catch"](0);
4340
- return _context5.abrupt("return", result.err({
4341
- message: _context5.t3 instanceof Error ? _context5.t3.message : "Unknown error"
4342
- }));
4343
- case 24:
4344
- case "end":
4345
- return _context5.stop();
4346
- }
4347
- }, _callee5, null, [[0, 21], [9, 16]]);
4348
- }));
4349
- return _parse.apply(this, arguments);
4350
- }
4351
-
4352
- // eslint-disable-next-line @typescript-eslint/ban-types
4353
-
5119
+ var ModuleFilePathSep = "?p=";
4354
5120
  var FATAL_ERROR_TYPES = ["no-schema", "no-source", "invalid-id", "no-module", "invalid-patch"];
4355
5121
  var Internal = {
4356
5122
  VERSION: {
@@ -4370,10 +5136,16 @@ var Internal = {
4370
5136
  getSource: getSource,
4371
5137
  resolvePath: resolvePath,
4372
5138
  splitModuleFilePathAndModulePath: splitModuleFilePathAndModulePath,
5139
+ joinModuleFilePathAndModulePath: joinModuleFilePathAndModulePath,
4373
5140
  isVal: isVal,
4374
5141
  createValPathOfItem: createValPathOfItem,
4375
5142
  getSHA256Hash: getSHA256Hash,
4376
5143
  initSchema: initSchema,
5144
+ getMimeType: getMimeType,
5145
+ mimeTypeToFileExt: mimeTypeToFileExt,
5146
+ filenameToMimeType: filenameToMimeType,
5147
+ EXT_TO_MIME_TYPES: EXT_TO_MIME_TYPES,
5148
+ MIME_TYPES_TO_EXT: MIME_TYPES_TO_EXT,
4377
5149
  ModuleFilePathSep: ModuleFilePathSep,
4378
5150
  notFileOp: function notFileOp(op) {
4379
5151
  return op.op !== "file";
@@ -4387,20 +5159,39 @@ var Internal = {
4387
5159
  }).join("/"));
4388
5160
  },
4389
5161
  createPatchPath: function createPatchPath(modulePath) {
4390
- return parsePath(modulePath);
4391
- },
4392
- patchPathToModulePath: function patchPathToModulePath(patchPath) {
4393
- return patchPath.map(function (segment) {
4394
- // TODO: I am worried that something is lost here: what if the segment is a string that happens to be a parsable as a number? We could make those keys illegal?
4395
- if (Number.isInteger(Number(segment))) {
4396
- return segment;
4397
- }
4398
- return JSON.stringify(segment);
4399
- }).join(".");
5162
+ return splitModulePath(modulePath);
4400
5163
  },
5164
+ splitModulePath: splitModulePath,
5165
+ splitModuleFilePath: splitModuleFilePath,
5166
+ splitJoinedSourcePaths: splitJoinedSourcePaths,
5167
+ parentOfSourcePath: parentOfSourcePath,
5168
+ patchPathToModulePath: patchPathToModulePath,
4401
5169
  VAL_ENABLE_COOKIE_NAME: "val_enable",
4402
5170
  VAL_STATE_COOKIE: "val_state",
4403
- VAL_SESSION_COOKIE: "val_session"
5171
+ VAL_SESSION_COOKIE: "val_session",
5172
+ createFilename: function createFilename(data, filename, metadata, sha256) {
5173
+ var _Internal$getMimeType, _Internal$mimeTypeToF;
5174
+ if (!metadata) {
5175
+ return filename;
5176
+ }
5177
+ if (!data) {
5178
+ return filename;
5179
+ }
5180
+ var shaSuffix = sha256.slice(0, 5);
5181
+ var mimeType = (_Internal$getMimeType = Internal.getMimeType(data)) !== null && _Internal$getMimeType !== void 0 ? _Internal$getMimeType : "unknown";
5182
+ var newExt = (_Internal$mimeTypeToF = Internal.mimeTypeToFileExt(mimeType)) !== null && _Internal$mimeTypeToF !== void 0 ? _Internal$mimeTypeToF : "unknown"; // Don't trust the file extension
5183
+ if (filename) {
5184
+ var cleanFilename = filename.split(".").slice(0, -1).join(".") || filename; // remove extension if it exists
5185
+ var maybeShaSuffixPos = cleanFilename.lastIndexOf("_");
5186
+ var currentShaSuffix = cleanFilename.slice(maybeShaSuffixPos + 1, cleanFilename.length);
5187
+ if (currentShaSuffix === shaSuffix) {
5188
+ cleanFilename = cleanFilename.slice(0, maybeShaSuffixPos);
5189
+ }
5190
+ var escapedFilename = encodeURIComponent(cleanFilename).replace(/%[0-9A-Fa-f]{2}/g, "").toLowerCase();
5191
+ return "".concat(escapedFilename, "_").concat(shaSuffix, ".").concat(newExt);
5192
+ }
5193
+ return "".concat(sha256, ".").concat(newExt);
5194
+ }
4404
5195
  };
4405
5196
  function tryJsonParse(str) {
4406
5197
  try {
@@ -4422,7 +5213,9 @@ exports.FileSchema = FileSchema;
4422
5213
  exports.GenericSelector = GenericSelector;
4423
5214
  exports.ImageSchema = ImageSchema;
4424
5215
  exports.Internal = Internal;
5216
+ exports.KeyOfSchema = KeyOfSchema;
4425
5217
  exports.LiteralSchema = LiteralSchema;
5218
+ exports.ModuleFilePathSep = ModuleFilePathSep;
4426
5219
  exports.NilSym = NilSym;
4427
5220
  exports.NumberSchema = NumberSchema;
4428
5221
  exports.ObjectSchema = ObjectSchema;
@@ -4437,7 +5230,6 @@ exports.StringTemplate = StringTemplate;
4437
5230
  exports.Sym = Sym;
4438
5231
  exports.UnionSchema = UnionSchema;
4439
5232
  exports.VAL_EXTENSION = VAL_EXTENSION;
4440
- exports.ValApi = ValApi;
4441
5233
  exports._classCallCheck = _classCallCheck;
4442
5234
  exports._createClass = _createClass;
4443
5235
  exports._slicedToArray = _slicedToArray;
@@ -4449,5 +5241,5 @@ exports.evaluate = evaluate;
4449
5241
  exports.index = index;
4450
5242
  exports.initVal = initVal;
4451
5243
  exports.modules = modules;
4452
- exports.parse = parse$1;
5244
+ exports.parse = parse;
4453
5245
  exports.splitModuleFilePathAndModulePath = splitModuleFilePathAndModulePath;