@valbuild/core 0.64.0 → 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 (39) 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 +38 -5
  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/module.d.ts +6 -2
  7. package/dist/declarations/src/schema/file.d.ts +0 -1
  8. package/dist/declarations/src/schema/image.d.ts +0 -1
  9. package/dist/declarations/src/schema/keyOf.d.ts +5 -5
  10. package/dist/declarations/src/schema/richtext.d.ts +1 -21
  11. package/dist/declarations/src/schema/union.d.ts +13 -14
  12. package/dist/declarations/src/source/file.d.ts +7 -4
  13. package/dist/{index-41223963.cjs.prod.js → index-48930c58.cjs.dev.js} +267 -243
  14. package/dist/{index-4240c6a6.esm.js → index-65ec1d74.esm.js} +267 -244
  15. package/dist/{index-d384ec25.cjs.dev.js → index-f1a23e6c.cjs.prod.js} +267 -243
  16. package/dist/{result-a8316efa.esm.js → result-168dfc1d.esm.js} +42 -46
  17. package/dist/{result-48320acd.cjs.dev.js → result-787e35f6.cjs.prod.js} +41 -45
  18. package/dist/{result-26f67b40.cjs.prod.js → result-bb1f436e.cjs.dev.js} +41 -45
  19. package/dist/valbuild-core.cjs.d.ts +2 -2
  20. package/dist/valbuild-core.cjs.dev.js +3 -2
  21. package/dist/valbuild-core.cjs.prod.js +3 -2
  22. package/dist/valbuild-core.esm.js +2 -2
  23. package/expr/dist/valbuild-core-expr.cjs.d.ts +2 -2
  24. package/expr/dist/valbuild-core-expr.cjs.dev.js +2 -2
  25. package/expr/dist/valbuild-core-expr.cjs.prod.js +2 -2
  26. package/expr/dist/valbuild-core-expr.esm.js +2 -2
  27. package/fp/dist/valbuild-core-fp.cjs.d.ts +2 -2
  28. package/fp/dist/valbuild-core-fp.cjs.dev.js +1 -1
  29. package/fp/dist/valbuild-core-fp.cjs.prod.js +1 -1
  30. package/fp/dist/valbuild-core-fp.esm.js +1 -1
  31. package/package.json +1 -1
  32. package/patch/dist/valbuild-core-patch.cjs.d.ts +2 -2
  33. package/patch/dist/valbuild-core-patch.cjs.dev.js +8 -9
  34. package/patch/dist/valbuild-core-patch.cjs.prod.js +8 -9
  35. package/patch/dist/valbuild-core-patch.esm.js +9 -10
  36. package/dist/valbuild-core.cjs.d.ts.map +0 -1
  37. package/expr/dist/valbuild-core-expr.cjs.d.ts.map +0 -1
  38. package/fp/dist/valbuild-core-fp.cjs.d.ts.map +0 -1
  39. 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;
108
- }
109
-
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();
140
+ function _classCallCheck(a, n) {
141
+ if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
144
142
  }
145
143
 
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)) {
@@ -516,7 +520,7 @@ var FileSchema = /*#__PURE__*/function (_Schema) {
516
520
  }
517
521
  if (src.metadata) {
518
522
  return _defineProperty({}, path, [{
519
- 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.",
520
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.
521
525
  value: src,
522
526
  fixes: ["file:check-metadata"]
@@ -593,25 +597,26 @@ var FileSchema = /*#__PURE__*/function (_Schema) {
593
597
  };
594
598
  }
595
599
  }]);
596
- return FileSchema;
597
600
  }(Schema);
598
601
  var file = function file(options) {
599
602
  return new FileSchema(options);
600
603
  };
601
604
  function convertFileSource(src) {
602
- var _src$metadata4, _src$metadata5, _src$metadata6;
603
605
  // TODO: /public should be configurable
604
606
  if (!src[FILE_REF_PROP].startsWith("/public")) {
605
- var _src$metadata, _src$metadata2, _src$metadata3;
606
607
  return {
607
- 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) : "") + (
608
- // TODO: remove sha256? we do not need anymore
609
- 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"]),
610
615
  metadata: src.metadata
611
616
  };
612
617
  }
613
618
  return {
614
- 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),
615
620
  metadata: src.metadata
616
621
  };
617
622
  }
@@ -812,7 +817,6 @@ function unValify$1(valueOrSelector) {
812
817
  }
813
818
 
814
819
  var ObjectSchema = /*#__PURE__*/function (_Schema) {
815
- _inherits(ObjectSchema, _Schema);
816
820
  function ObjectSchema(items) {
817
821
  var _this;
818
822
  var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
@@ -822,7 +826,8 @@ var ObjectSchema = /*#__PURE__*/function (_Schema) {
822
826
  _this.opt = opt;
823
827
  return _this;
824
828
  }
825
- _createClass(ObjectSchema, [{
829
+ _inherits(ObjectSchema, _Schema);
830
+ return _createClass(ObjectSchema, [{
826
831
  key: "validate",
827
832
  value: function validate(path, src) {
828
833
  var _this2 = this;
@@ -949,7 +954,6 @@ var ObjectSchema = /*#__PURE__*/function (_Schema) {
949
954
  };
950
955
  }
951
956
  }]);
952
- return ObjectSchema;
953
957
  }(Schema);
954
958
  var object = function object(schema) {
955
959
  return new ObjectSchema(schema);
@@ -982,7 +986,7 @@ function tokenize(input) {
982
986
  });
983
987
  cursor++;
984
988
  } else if (_char === "'" || _char === "}") {
985
- var _start = cursor;
989
+ var start = cursor;
986
990
  var value = "";
987
991
  var unescapedValue = "";
988
992
  var escaped = false;
@@ -1025,7 +1029,7 @@ function tokenize(input) {
1025
1029
  if (value) {
1026
1030
  tokens.push(_objectSpread2({
1027
1031
  type: "string",
1028
- span: [_start + 1, cursor - cursorOffset],
1032
+ span: [start + 1, cursor - cursorOffset],
1029
1033
  value: value
1030
1034
  }, unescapedValue !== value && {
1031
1035
  unescapedValue: unescapedValue
@@ -1043,17 +1047,17 @@ function tokenize(input) {
1043
1047
  });
1044
1048
  }
1045
1049
  } else if (WHITE_SPACE.includes(_char)) {
1046
- var _start2 = cursor;
1050
+ var _start = cursor;
1047
1051
  while (WHITE_SPACE.includes(input[cursor]) && cursor < input.length) {
1048
1052
  cursor++;
1049
1053
  }
1050
1054
  tokens.push({
1051
1055
  type: "ws",
1052
- span: [_start2, cursor - 1]
1056
+ span: [_start, cursor - 1]
1053
1057
  });
1054
1058
  } else {
1055
1059
  var _value = "";
1056
- var _start3 = cursor;
1060
+ var _start2 = cursor;
1057
1061
  do {
1058
1062
  _char = input[cursor];
1059
1063
  peek = input[cursor + 1];
@@ -1062,7 +1066,7 @@ function tokenize(input) {
1062
1066
  } while (!WHITE_SPACE.includes(peek) && peek !== ")" && peek !== "'" && cursor < input.length);
1063
1067
  tokens.push({
1064
1068
  type: "token",
1065
- span: [_start3, cursor - 1],
1069
+ span: [_start2, cursor - 1],
1066
1070
  value: _value
1067
1071
  });
1068
1072
  }
@@ -1401,13 +1405,12 @@ var EvalError = /*#__PURE__*/function () {
1401
1405
  this.message = message;
1402
1406
  this.expr = expr;
1403
1407
  }
1404
- _createClass(EvalError, [{
1408
+ return _createClass(EvalError, [{
1405
1409
  key: "toString",
1406
1410
  value: function toString() {
1407
1411
  return "".concat(this.message, " in: ").concat(this.expr.transpile());
1408
1412
  }
1409
1413
  }]);
1410
- return EvalError;
1411
1414
  }();
1412
1415
  var MAX_STACK_SIZE = 100; // an arbitrary semi-large number
1413
1416
  function evaluateSync(expr, getSource, stack) {
@@ -1426,8 +1429,8 @@ function evaluateSync(expr, getSource, stack) {
1426
1429
  throw new EvalError("cannot call 'val' as anonymous function", expr);
1427
1430
  }
1428
1431
  if (expr.children[1] instanceof StringLiteral) {
1429
- var _path = expr.children[1].value;
1430
- return newSelectorProxy(getSource(_path), _path);
1432
+ var path = expr.children[1].value;
1433
+ return newSelectorProxy(getSource(path), path);
1431
1434
  } else {
1432
1435
  throw new EvalError("argument of 'val' must be a string literal", expr);
1433
1436
  }
@@ -1494,8 +1497,8 @@ function evaluateSync(expr, getSource, stack) {
1494
1497
  if (expr.children[0] instanceof Sym) {
1495
1498
  if (expr.children[0].value === "val") {
1496
1499
  if (expr.children[1] instanceof StringLiteral) {
1497
- var _path2 = expr.children[1].value;
1498
- return newSelectorProxy(getSource(_path2), _path2);
1500
+ var _path = expr.children[1].value;
1501
+ return newSelectorProxy(getSource(_path), _path);
1499
1502
  } else {
1500
1503
  throw new EvalError("argument of 'val' must be a string literal", expr);
1501
1504
  }
@@ -1585,7 +1588,6 @@ var index = /*#__PURE__*/Object.freeze({
1585
1588
  });
1586
1589
 
1587
1590
  var ArraySchema = /*#__PURE__*/function (_Schema) {
1588
- _inherits(ArraySchema, _Schema);
1589
1591
  function ArraySchema(item) {
1590
1592
  var _this;
1591
1593
  var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
@@ -1595,7 +1597,8 @@ var ArraySchema = /*#__PURE__*/function (_Schema) {
1595
1597
  _this.opt = opt;
1596
1598
  return _this;
1597
1599
  }
1598
- _createClass(ArraySchema, [{
1600
+ _inherits(ArraySchema, _Schema);
1601
+ return _createClass(ArraySchema, [{
1599
1602
  key: "validate",
1600
1603
  value: function validate(path, src) {
1601
1604
  var assertRes = this.assert(path, src);
@@ -1677,14 +1680,12 @@ var ArraySchema = /*#__PURE__*/function (_Schema) {
1677
1680
  };
1678
1681
  }
1679
1682
  }]);
1680
- return ArraySchema;
1681
1683
  }(Schema);
1682
1684
  var array = function array(schema) {
1683
1685
  return new ArraySchema(schema);
1684
1686
  };
1685
1687
 
1686
1688
  var LiteralSchema = /*#__PURE__*/function (_Schema) {
1687
- _inherits(LiteralSchema, _Schema);
1688
1689
  function LiteralSchema(value) {
1689
1690
  var _this;
1690
1691
  var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
@@ -1694,7 +1695,8 @@ var LiteralSchema = /*#__PURE__*/function (_Schema) {
1694
1695
  _this.opt = opt;
1695
1696
  return _this;
1696
1697
  }
1697
- _createClass(LiteralSchema, [{
1698
+ _inherits(LiteralSchema, _Schema);
1699
+ return _createClass(LiteralSchema, [{
1698
1700
  key: "validate",
1699
1701
  value: function validate(path, src) {
1700
1702
  if (this.opt && (src === null || src === undefined)) {
@@ -1761,14 +1763,12 @@ var LiteralSchema = /*#__PURE__*/function (_Schema) {
1761
1763
  };
1762
1764
  }
1763
1765
  }]);
1764
- return LiteralSchema;
1765
1766
  }(Schema);
1766
1767
  var literal = function literal(value) {
1767
1768
  return new LiteralSchema(value);
1768
1769
  };
1769
1770
 
1770
1771
  var UnionSchema = /*#__PURE__*/function (_Schema) {
1771
- _inherits(UnionSchema, _Schema);
1772
1772
  function UnionSchema(key, items) {
1773
1773
  var _this;
1774
1774
  var opt = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
@@ -1779,7 +1779,8 @@ var UnionSchema = /*#__PURE__*/function (_Schema) {
1779
1779
  _this.opt = opt;
1780
1780
  return _this;
1781
1781
  }
1782
- _createClass(UnionSchema, [{
1782
+ _inherits(UnionSchema, _Schema);
1783
+ return _createClass(UnionSchema, [{
1783
1784
  key: "validate",
1784
1785
  value: function validate(path, src) {
1785
1786
  var unknownSrc = src;
@@ -2093,7 +2094,6 @@ var UnionSchema = /*#__PURE__*/function (_Schema) {
2093
2094
  };
2094
2095
  }
2095
2096
  }]);
2096
- return UnionSchema;
2097
2097
  }(Schema);
2098
2098
  var union = function union(key) {
2099
2099
  for (var _len = arguments.length, objects = new Array(_len > 1 ? _len - 1 : 0), _key3 = 1; _key3 < _len; _key3++) {
@@ -2103,7 +2103,6 @@ var union = function union(key) {
2103
2103
  };
2104
2104
 
2105
2105
  var RichTextSchema = /*#__PURE__*/function (_Schema) {
2106
- _inherits(RichTextSchema, _Schema);
2107
2106
  function RichTextSchema(options) {
2108
2107
  var _this;
2109
2108
  var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
@@ -2113,7 +2112,8 @@ var RichTextSchema = /*#__PURE__*/function (_Schema) {
2113
2112
  _this.opt = opt;
2114
2113
  return _this;
2115
2114
  }
2116
- _createClass(RichTextSchema, [{
2115
+ _inherits(RichTextSchema, _Schema);
2116
+ return _createClass(RichTextSchema, [{
2117
2117
  key: "validate",
2118
2118
  value: function validate(path, src) {
2119
2119
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -2281,14 +2281,12 @@ var RichTextSchema = /*#__PURE__*/function (_Schema) {
2281
2281
  };
2282
2282
  }
2283
2283
  }]);
2284
- return RichTextSchema;
2285
2284
  }(Schema);
2286
2285
  var richtext$1 = function richtext(options) {
2287
2286
  return new RichTextSchema(options !== null && options !== void 0 ? options : {});
2288
2287
  };
2289
2288
 
2290
2289
  var ImageSchema = /*#__PURE__*/function (_Schema) {
2291
- _inherits(ImageSchema, _Schema);
2292
2290
  function ImageSchema(options) {
2293
2291
  var _this;
2294
2292
  var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
@@ -2298,7 +2296,8 @@ var ImageSchema = /*#__PURE__*/function (_Schema) {
2298
2296
  _this.opt = opt;
2299
2297
  return _this;
2300
2298
  }
2301
- _createClass(ImageSchema, [{
2299
+ _inherits(ImageSchema, _Schema);
2300
+ return _createClass(ImageSchema, [{
2302
2301
  key: "validate",
2303
2302
  value: function validate(path, src) {
2304
2303
  if (this.opt && (src === null || src === undefined)) {
@@ -2368,7 +2367,7 @@ var ImageSchema = /*#__PURE__*/function (_Schema) {
2368
2367
  }
2369
2368
  if (src.metadata) {
2370
2369
  return _defineProperty({}, path, [{
2371
- 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.",
2372
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.
2373
2372
  value: src,
2374
2373
  fixes: ["image:replace-metadata"]
@@ -2445,14 +2444,12 @@ var ImageSchema = /*#__PURE__*/function (_Schema) {
2445
2444
  };
2446
2445
  }
2447
2446
  }]);
2448
- return ImageSchema;
2449
2447
  }(Schema);
2450
2448
  var image$1 = function image(options) {
2451
2449
  return new ImageSchema(options);
2452
2450
  };
2453
2451
 
2454
2452
  var RecordSchema = /*#__PURE__*/function (_Schema) {
2455
- _inherits(RecordSchema, _Schema);
2456
2453
  function RecordSchema(item) {
2457
2454
  var _this;
2458
2455
  var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
@@ -2462,7 +2459,8 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
2462
2459
  _this.opt = opt;
2463
2460
  return _this;
2464
2461
  }
2465
- _createClass(RecordSchema, [{
2462
+ _inherits(RecordSchema, _Schema);
2463
+ return _createClass(RecordSchema, [{
2466
2464
  key: "validate",
2467
2465
  value: function validate(path, src) {
2468
2466
  var _this2 = this;
@@ -2552,7 +2550,6 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
2552
2550
  };
2553
2551
  }
2554
2552
  }]);
2555
- return RecordSchema;
2556
2553
  }(Schema);
2557
2554
  var record = function record(schema) {
2558
2555
  return new RecordSchema(schema);
@@ -2583,7 +2580,12 @@ function splitModuleFilePathAndModulePath(path) {
2583
2580
  }
2584
2581
  return [path.slice(0, pathOfSep), path.slice(pathOfSep + ModuleFilePathSep.length)];
2585
2582
  }
2586
- var ModuleFilePathSep = "?p=";
2583
+ function joinModuleFilePathAndModulePath(moduleFilePath, modulePath) {
2584
+ if (modulePath === "") {
2585
+ return moduleFilePath;
2586
+ }
2587
+ return "".concat(moduleFilePath).concat(ModuleFilePathSep).concat(modulePath);
2588
+ }
2587
2589
  function isObjectSchema(schema) {
2588
2590
  return schema instanceof ObjectSchema || _typeof(schema) === "object" && "type" in schema && schema.type === "object";
2589
2591
  }
@@ -2627,8 +2629,7 @@ function isImageSchema(schema) {
2627
2629
  // }
2628
2630
 
2629
2631
  function resolvePath(path, valModule, schema) {
2630
- // TODO: use schema assert while resolving (and emit errors if any)
2631
- var parts = parsePath(path);
2632
+ var parts = splitModulePath(path);
2632
2633
  var origParts = _toConsumableArray(parts);
2633
2634
  var resolvedSchema = schema;
2634
2635
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -2645,10 +2646,6 @@ function resolvePath(path, valModule, schema) {
2645
2646
  if (_typeof(resolvedSource) !== "object" && !Array.isArray(resolvedSource)) {
2646
2647
  throw Error("Schema type error: expected source to be type of array, but got ".concat(_typeof(resolvedSource)));
2647
2648
  }
2648
- if (resolvedSource[part] === undefined) {
2649
- var _resolvedSource;
2650
- 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));
2651
- }
2652
2649
  resolvedSource = resolvedSource[part];
2653
2650
  resolvedSchema = resolvedSchema.item;
2654
2651
  } else if (isRecordSchema(resolvedSchema)) {
@@ -2667,10 +2664,10 @@ function resolvePath(path, valModule, schema) {
2667
2664
  if (_typeof(resolvedSource) !== "object") {
2668
2665
  throw Error("Schema type error: expected source to be type of object, but got ".concat(_typeof(resolvedSource)));
2669
2666
  }
2670
- if (!resolvedSource[part]) {
2667
+ if (resolvedSource !== null && resolvedSource[part] === undefined) {
2671
2668
  throw Error("Invalid path: object source did not have key ".concat(part, " from path: ").concat(path));
2672
2669
  }
2673
- resolvedSource = resolvedSource[part];
2670
+ resolvedSource = resolvedSource === null ? resolvedSource : resolvedSource[part];
2674
2671
  resolvedSchema = resolvedSchema.items[part];
2675
2672
  // } else if (isI18nSchema(resolvedSchema)) {
2676
2673
  // if (!resolvedSchema.locales.includes(part)) {
@@ -2770,7 +2767,11 @@ function resolvePath(path, valModule, schema) {
2770
2767
  source: resolvedSource
2771
2768
  };
2772
2769
  }
2773
- function parsePath(input) {
2770
+ function splitModuleFilePath(input) {
2771
+ var parts = input.split("/").slice(1);
2772
+ return parts;
2773
+ }
2774
+ function splitModulePath(input) {
2774
2775
  var result = [];
2775
2776
  var i = 0;
2776
2777
  while (i < input.length) {
@@ -2806,9 +2807,32 @@ function parsePath(input) {
2806
2807
  }
2807
2808
  return result;
2808
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
+ }
2809
2834
 
2810
2835
  var NumberSchema = /*#__PURE__*/function (_Schema) {
2811
- _inherits(NumberSchema, _Schema);
2812
2836
  function NumberSchema(options) {
2813
2837
  var _this;
2814
2838
  var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
@@ -2818,7 +2842,8 @@ var NumberSchema = /*#__PURE__*/function (_Schema) {
2818
2842
  _this.opt = opt;
2819
2843
  return _this;
2820
2844
  }
2821
- _createClass(NumberSchema, [{
2845
+ _inherits(NumberSchema, _Schema);
2846
+ return _createClass(NumberSchema, [{
2822
2847
  key: "validate",
2823
2848
  value: function validate(path, src) {
2824
2849
  if (this.opt && (src === null || src === undefined)) {
@@ -2879,14 +2904,12 @@ var NumberSchema = /*#__PURE__*/function (_Schema) {
2879
2904
  };
2880
2905
  }
2881
2906
  }]);
2882
- return NumberSchema;
2883
2907
  }(Schema);
2884
2908
  var number = function number(options) {
2885
2909
  return new NumberSchema(options);
2886
2910
  };
2887
2911
 
2888
2912
  var StringSchema = /*#__PURE__*/function (_Schema) {
2889
- _inherits(StringSchema, _Schema);
2890
2913
  function StringSchema(options) {
2891
2914
  var _this;
2892
2915
  var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
@@ -2898,7 +2921,8 @@ var StringSchema = /*#__PURE__*/function (_Schema) {
2898
2921
  _this.isRaw = isRaw;
2899
2922
  return _this;
2900
2923
  }
2901
- _createClass(StringSchema, [{
2924
+ _inherits(StringSchema, _Schema);
2925
+ return _createClass(StringSchema, [{
2902
2926
  key: "min",
2903
2927
  value: function min(minLength) {
2904
2928
  return new StringSchema(_objectSpread2(_objectSpread2({}, this.options), {}, {
@@ -3008,14 +3032,12 @@ var StringSchema = /*#__PURE__*/function (_Schema) {
3008
3032
  };
3009
3033
  }
3010
3034
  }]);
3011
- return StringSchema;
3012
3035
  }(Schema);
3013
3036
  var string = function string(options) {
3014
3037
  return new StringSchema(options);
3015
3038
  };
3016
3039
 
3017
3040
  var BooleanSchema = /*#__PURE__*/function (_Schema) {
3018
- _inherits(BooleanSchema, _Schema);
3019
3041
  function BooleanSchema() {
3020
3042
  var _this;
3021
3043
  var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
@@ -3024,7 +3046,8 @@ var BooleanSchema = /*#__PURE__*/function (_Schema) {
3024
3046
  _this.opt = opt;
3025
3047
  return _this;
3026
3048
  }
3027
- _createClass(BooleanSchema, [{
3049
+ _inherits(BooleanSchema, _Schema);
3050
+ return _createClass(BooleanSchema, [{
3028
3051
  key: "validate",
3029
3052
  value: function validate(path, src) {
3030
3053
  if (this.opt && (src === null || src === undefined)) {
@@ -3084,14 +3107,12 @@ var BooleanSchema = /*#__PURE__*/function (_Schema) {
3084
3107
  };
3085
3108
  }
3086
3109
  }]);
3087
- return BooleanSchema;
3088
3110
  }(Schema);
3089
3111
  var _boolean = function _boolean() {
3090
3112
  return new BooleanSchema();
3091
3113
  };
3092
3114
 
3093
3115
  var KeyOfSchema = /*#__PURE__*/function (_Schema) {
3094
- _inherits(KeyOfSchema, _Schema);
3095
3116
  function KeyOfSchema(schema, sourcePath) {
3096
3117
  var _this;
3097
3118
  var opt = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
@@ -3102,7 +3123,8 @@ var KeyOfSchema = /*#__PURE__*/function (_Schema) {
3102
3123
  _this.opt = opt;
3103
3124
  return _this;
3104
3125
  }
3105
- _createClass(KeyOfSchema, [{
3126
+ _inherits(KeyOfSchema, _Schema);
3127
+ return _createClass(KeyOfSchema, [{
3106
3128
  key: "validate",
3107
3129
  value: function validate(path, src) {
3108
3130
  if (this.opt && (src === null || src === undefined)) {
@@ -3114,19 +3136,14 @@ var KeyOfSchema = /*#__PURE__*/function (_Schema) {
3114
3136
  }]);
3115
3137
  }
3116
3138
  var serializedSchema = this.schema;
3117
- if (!(serializedSchema.type === "array" || serializedSchema.type === "object" || serializedSchema.type === "record")) {
3139
+ if (!(serializedSchema.type === "object" || serializedSchema.type === "record")) {
3118
3140
  return _defineProperty({}, path, [{
3119
- 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, "'")
3120
3142
  }]);
3121
3143
  }
3122
3144
  if (serializedSchema.opt && (src === null || src === undefined)) {
3123
3145
  return false;
3124
3146
  }
3125
- if (serializedSchema.type === "array" && typeof src !== "number") {
3126
- return _defineProperty({}, path, [{
3127
- message: "Type of value in keyof (array) must be 'number'"
3128
- }]);
3129
- }
3130
3147
  if (serializedSchema.type === "record" && typeof src !== "string") {
3131
3148
  return _defineProperty({}, path, [{
3132
3149
  message: "Type of value in keyof (record) must be 'string'"
@@ -3171,7 +3188,7 @@ var KeyOfSchema = /*#__PURE__*/function (_Schema) {
3171
3188
  };
3172
3189
  }
3173
3190
  var serializedSchema = schema;
3174
- if (!(serializedSchema.type === "array" || serializedSchema.type === "object" || serializedSchema.type === "record")) {
3191
+ if (!(serializedSchema.type === "object" || serializedSchema.type === "record")) {
3175
3192
  return {
3176
3193
  success: false,
3177
3194
  errors: _defineProperty({}, path, [{
@@ -3180,15 +3197,6 @@ var KeyOfSchema = /*#__PURE__*/function (_Schema) {
3180
3197
  }])
3181
3198
  };
3182
3199
  }
3183
- if (serializedSchema.type === "array" && typeof src !== "number") {
3184
- return {
3185
- success: false,
3186
- errors: _defineProperty({}, path, [{
3187
- message: "Value of keyOf (array) must be 'number', got '".concat(_typeof(src), "'"),
3188
- typeError: true
3189
- }])
3190
- };
3191
- }
3192
3200
  if (serializedSchema.type === "record" && typeof src !== "string") {
3193
3201
  return {
3194
3202
  success: false,
@@ -3228,7 +3236,7 @@ var KeyOfSchema = /*#__PURE__*/function (_Schema) {
3228
3236
  value: function serialize() {
3229
3237
  var path = this.sourcePath;
3230
3238
  if (!path) {
3231
- 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.");
3232
3240
  }
3233
3241
  var serializedSchema = this.schema;
3234
3242
  if (!serializedSchema) {
@@ -3236,9 +3244,6 @@ var KeyOfSchema = /*#__PURE__*/function (_Schema) {
3236
3244
  }
3237
3245
  var values;
3238
3246
  switch (serializedSchema.type) {
3239
- case "array":
3240
- values = "number";
3241
- break;
3242
3247
  case "record":
3243
3248
  values = "string";
3244
3249
  break;
@@ -3257,7 +3262,6 @@ var KeyOfSchema = /*#__PURE__*/function (_Schema) {
3257
3262
  };
3258
3263
  }
3259
3264
  }]);
3260
- return KeyOfSchema;
3261
3265
  }(Schema);
3262
3266
  var keyOf = function keyOf(valModule) {
3263
3267
  var _valModule$GetSchema;
@@ -3265,7 +3269,6 @@ var keyOf = function keyOf(valModule) {
3265
3269
  };
3266
3270
 
3267
3271
  var DateSchema = /*#__PURE__*/function (_Schema) {
3268
- _inherits(DateSchema, _Schema);
3269
3272
  function DateSchema(options) {
3270
3273
  var _this;
3271
3274
  var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
@@ -3275,7 +3278,8 @@ var DateSchema = /*#__PURE__*/function (_Schema) {
3275
3278
  _this.opt = opt;
3276
3279
  return _this;
3277
3280
  }
3278
- _createClass(DateSchema, [{
3281
+ _inherits(DateSchema, _Schema);
3282
+ return _createClass(DateSchema, [{
3279
3283
  key: "validate",
3280
3284
  value: function validate(path, src) {
3281
3285
  var _this$options, _this$options2, _this$options3, _this$options4;
@@ -3387,7 +3391,6 @@ var DateSchema = /*#__PURE__*/function (_Schema) {
3387
3391
  };
3388
3392
  }
3389
3393
  }]);
3390
- return DateSchema;
3391
3394
  }(Schema);
3392
3395
  var date = function date(options) {
3393
3396
  return new DateSchema(options);
@@ -3711,7 +3714,7 @@ var initVal = function initVal(config) {
3711
3714
  c: {
3712
3715
  define: define,
3713
3716
  // remote,
3714
- file: file$1,
3717
+ file: initFile(config),
3715
3718
  richtext: richtext,
3716
3719
  rt: {
3717
3720
  image: image,
@@ -4078,7 +4081,7 @@ var Hash = /*#__PURE__*/function () {
4078
4081
  this._word = new Int32Array(sharedBuffer, sharedOffset, N.allocWords);
4079
4082
  sharedOffset += N.allocBytes;
4080
4083
  }
4081
- _createClass(Hash, [{
4084
+ return _createClass(Hash, [{
4082
4085
  key: "update",
4083
4086
  value: function update(data) {
4084
4087
  // data: string
@@ -4295,7 +4298,6 @@ var Hash = /*#__PURE__*/function () {
4295
4298
  return _byte.slice(0, 32);
4296
4299
  }
4297
4300
  }]);
4298
- return Hash;
4299
4301
  }();
4300
4302
  var W = new Int32Array(N.workWords);
4301
4303
  var sharedBuffer;
@@ -5114,6 +5116,7 @@ function deserializeSchema(serialized) {
5114
5116
  }
5115
5117
  }
5116
5118
 
5119
+ var ModuleFilePathSep = "?p=";
5117
5120
  var FATAL_ERROR_TYPES = ["no-schema", "no-source", "invalid-id", "no-module", "invalid-patch"];
5118
5121
  var Internal = {
5119
5122
  VERSION: {
@@ -5133,6 +5136,7 @@ var Internal = {
5133
5136
  getSource: getSource,
5134
5137
  resolvePath: resolvePath,
5135
5138
  splitModuleFilePathAndModulePath: splitModuleFilePathAndModulePath,
5139
+ joinModuleFilePathAndModulePath: joinModuleFilePathAndModulePath,
5136
5140
  isVal: isVal,
5137
5141
  createValPathOfItem: createValPathOfItem,
5138
5142
  getSHA256Hash: getSHA256Hash,
@@ -5155,20 +5159,39 @@ var Internal = {
5155
5159
  }).join("/"));
5156
5160
  },
5157
5161
  createPatchPath: function createPatchPath(modulePath) {
5158
- return parsePath(modulePath);
5159
- },
5160
- patchPathToModulePath: function patchPathToModulePath(patchPath) {
5161
- return patchPath.map(function (segment) {
5162
- // 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?
5163
- if (Number.isInteger(Number(segment))) {
5164
- return segment;
5165
- }
5166
- return JSON.stringify(segment);
5167
- }).join(".");
5162
+ return splitModulePath(modulePath);
5168
5163
  },
5164
+ splitModulePath: splitModulePath,
5165
+ splitModuleFilePath: splitModuleFilePath,
5166
+ splitJoinedSourcePaths: splitJoinedSourcePaths,
5167
+ parentOfSourcePath: parentOfSourcePath,
5168
+ patchPathToModulePath: patchPathToModulePath,
5169
5169
  VAL_ENABLE_COOKIE_NAME: "val_enable",
5170
5170
  VAL_STATE_COOKIE: "val_state",
5171
- 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
+ }
5172
5195
  };
5173
5196
  function tryJsonParse(str) {
5174
5197
  try {
@@ -5192,6 +5215,7 @@ exports.ImageSchema = ImageSchema;
5192
5215
  exports.Internal = Internal;
5193
5216
  exports.KeyOfSchema = KeyOfSchema;
5194
5217
  exports.LiteralSchema = LiteralSchema;
5218
+ exports.ModuleFilePathSep = ModuleFilePathSep;
5195
5219
  exports.NilSym = NilSym;
5196
5220
  exports.NumberSchema = NumberSchema;
5197
5221
  exports.ObjectSchema = ObjectSchema;