@valbuild/core 0.61.0 → 0.62.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.
@@ -0,0 +1,4057 @@
1
+ 'use strict';
2
+
3
+ var result = require('./result-48320acd.cjs.dev.js');
4
+
5
+ function _arrayWithoutHoles(arr) {
6
+ if (Array.isArray(arr)) return result._arrayLikeToArray(arr);
7
+ }
8
+
9
+ function _iterableToArray(iter) {
10
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
11
+ }
12
+
13
+ function _nonIterableSpread() {
14
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
15
+ }
16
+
17
+ function _toConsumableArray(arr) {
18
+ return _arrayWithoutHoles(arr) || _iterableToArray(arr) || result._unsupportedIterableToArray(arr) || _nonIterableSpread();
19
+ }
20
+
21
+ function _typeof(o) {
22
+ "@babel/helpers - typeof";
23
+
24
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
25
+ return typeof o;
26
+ } : function (o) {
27
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
28
+ }, _typeof(o);
29
+ }
30
+
31
+ function toPrimitive(t, r) {
32
+ if ("object" != typeof t || !t) return t;
33
+ var e = t[Symbol.toPrimitive];
34
+ if (void 0 !== e) {
35
+ var i = e.call(t, r || "default");
36
+ if ("object" != typeof i) return i;
37
+ throw new TypeError("@@toPrimitive must return a primitive value.");
38
+ }
39
+ return ("string" === r ? String : Number)(t);
40
+ }
41
+
42
+ function toPropertyKey(t) {
43
+ var i = toPrimitive(t, "string");
44
+ return "symbol" == typeof i ? i : String(i);
45
+ }
46
+
47
+ function _defineProperty(obj, key, value) {
48
+ key = toPropertyKey(key);
49
+ if (key in obj) {
50
+ Object.defineProperty(obj, key, {
51
+ value: value,
52
+ enumerable: true,
53
+ configurable: true,
54
+ writable: true
55
+ });
56
+ } else {
57
+ obj[key] = value;
58
+ }
59
+ return obj;
60
+ }
61
+
62
+ function ownKeys(e, r) {
63
+ var t = Object.keys(e);
64
+ if (Object.getOwnPropertySymbols) {
65
+ var o = Object.getOwnPropertySymbols(e);
66
+ r && (o = o.filter(function (r) {
67
+ return Object.getOwnPropertyDescriptor(e, r).enumerable;
68
+ })), t.push.apply(t, o);
69
+ }
70
+ return t;
71
+ }
72
+ function _objectSpread2(e) {
73
+ for (var r = 1; r < arguments.length; r++) {
74
+ var t = null != arguments[r] ? arguments[r] : {};
75
+ r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
76
+ _defineProperty(e, r, t[r]);
77
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
78
+ Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
79
+ });
80
+ }
81
+ return e;
82
+ }
83
+
84
+ function _arrayWithHoles(arr) {
85
+ if (Array.isArray(arr)) return arr;
86
+ }
87
+
88
+ function _iterableToArrayLimit(r, l) {
89
+ var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
90
+ if (null != t) {
91
+ var e,
92
+ n,
93
+ i,
94
+ u,
95
+ a = [],
96
+ f = !0,
97
+ o = !1;
98
+ try {
99
+ if (i = (t = t.call(r)).next, 0 === l) {
100
+ if (Object(t) !== t) return;
101
+ f = !1;
102
+ } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
103
+ } catch (r) {
104
+ o = !0, n = r;
105
+ } finally {
106
+ try {
107
+ if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
108
+ } finally {
109
+ if (o) throw n;
110
+ }
111
+ }
112
+ return a;
113
+ }
114
+ }
115
+
116
+ function _nonIterableRest() {
117
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
118
+ }
119
+
120
+ function _slicedToArray(arr, i) {
121
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || result._unsupportedIterableToArray(arr, i) || _nonIterableRest();
122
+ }
123
+
124
+ function _classCallCheck(instance, Constructor) {
125
+ if (!(instance instanceof Constructor)) {
126
+ throw new TypeError("Cannot call a class as a function");
127
+ }
128
+ }
129
+
130
+ function _defineProperties(target, props) {
131
+ for (var i = 0; i < props.length; i++) {
132
+ var descriptor = props[i];
133
+ descriptor.enumerable = descriptor.enumerable || false;
134
+ descriptor.configurable = true;
135
+ if ("value" in descriptor) descriptor.writable = true;
136
+ Object.defineProperty(target, toPropertyKey(descriptor.key), descriptor);
137
+ }
138
+ }
139
+ function _createClass(Constructor, protoProps, staticProps) {
140
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
141
+ if (staticProps) _defineProperties(Constructor, staticProps);
142
+ Object.defineProperty(Constructor, "prototype", {
143
+ writable: false
144
+ });
145
+ return Constructor;
146
+ }
147
+
148
+ function _getPrototypeOf(o) {
149
+ _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
150
+ return o.__proto__ || Object.getPrototypeOf(o);
151
+ };
152
+ return _getPrototypeOf(o);
153
+ }
154
+
155
+ function _isNativeReflectConstruct() {
156
+ try {
157
+ var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
158
+ } catch (t) {}
159
+ return (_isNativeReflectConstruct = function () {
160
+ return !!t;
161
+ })();
162
+ }
163
+
164
+ function _assertThisInitialized(self) {
165
+ if (self === void 0) {
166
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
167
+ }
168
+ return self;
169
+ }
170
+
171
+ function _possibleConstructorReturn(self, call) {
172
+ if (call && (typeof call === "object" || typeof call === "function")) {
173
+ return call;
174
+ } else if (call !== void 0) {
175
+ throw new TypeError("Derived constructors may only return object or undefined");
176
+ }
177
+ return _assertThisInitialized(self);
178
+ }
179
+
180
+ function _callSuper(t, o, e) {
181
+ return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e));
182
+ }
183
+
184
+ function _setPrototypeOf(o, p) {
185
+ _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
186
+ o.__proto__ = p;
187
+ return o;
188
+ };
189
+ return _setPrototypeOf(o, p);
190
+ }
191
+
192
+ function _inherits(subClass, superClass) {
193
+ if (typeof superClass !== "function" && superClass !== null) {
194
+ throw new TypeError("Super expression must either be null or a function");
195
+ }
196
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
197
+ constructor: {
198
+ value: subClass,
199
+ writable: true,
200
+ configurable: true
201
+ }
202
+ });
203
+ Object.defineProperty(subClass, "prototype", {
204
+ writable: false
205
+ });
206
+ if (superClass) _setPrototypeOf(subClass, superClass);
207
+ }
208
+
209
+ // import { RemoteCompatibleSource, RemoteSource } from "../source/remote";
210
+
211
+ // import { SerializedI18nSchema } from "./future/i18n";
212
+ // import { SerializedOneOfSchema } from "./future/oneOf";
213
+
214
+ var Schema = /*#__PURE__*/function () {
215
+ function Schema() {
216
+ _classCallCheck(this, Schema);
217
+ }
218
+ _createClass(Schema, [{
219
+ key: "appendValidationError",
220
+ value:
221
+ // remote(): Src extends RemoteCompatibleSource
222
+ // ? Schema<RemoteSource<Src>>
223
+ // : never {
224
+ // // TODO: Schema<never, "Cannot create remote schema from non-remote source.">
225
+ // throw new Error("You need Val Ultra to use .remote()");
226
+ // }
227
+
228
+ /** MUTATES! since internal and perf sensitive */
229
+ function appendValidationError(current, path, message, value) {
230
+ if (current) {
231
+ if (current[path]) {
232
+ current[path].push({
233
+ message: message,
234
+ value: value
235
+ });
236
+ } else {
237
+ current[path] = [{
238
+ message: message,
239
+ value: value
240
+ }];
241
+ }
242
+ return current;
243
+ } else {
244
+ return _defineProperty({}, path, [{
245
+ message: message,
246
+ value: value
247
+ }]);
248
+ }
249
+ }
250
+ }]);
251
+ return Schema;
252
+ }();
253
+
254
+ // TODO: SourceError<"Could not determine type of Schema">
255
+
256
+ /**
257
+ * @internal
258
+ */
259
+ var GetSchema$1 = Symbol("GetSchema");
260
+ /**
261
+ /**
262
+ * @internal
263
+ */
264
+ var Path$1 = Symbol("Path");
265
+ /**
266
+ * @internal
267
+ */
268
+ var GetSource = Symbol("GetSource");
269
+ /**
270
+ * @internal
271
+ */
272
+ var ValError = Symbol("ValError");
273
+ var GenericSelector = /*#__PURE__*/_createClass(function GenericSelector(valOrExpr, path, schema, error) {
274
+ _classCallCheck(this, GenericSelector);
275
+ this[Path$1] = path;
276
+ this[GetSource] = valOrExpr;
277
+ this[ValError] = error;
278
+ this[GetSchema$1] = schema;
279
+ });
280
+
281
+ /**
282
+ * Use this type to convert types that accepts both Source and Selectors
283
+ *
284
+ * An example would be where literals are supported like in most higher order functions (e.g. map in array)
285
+ **/
286
+
287
+ function getSchema(selector) {
288
+ return selector[GetSchema$1];
289
+ }
290
+
291
+ /* eslint-disable @typescript-eslint/no-unused-vars */
292
+
293
+ var Expr = /*#__PURE__*/_createClass(function Expr(span) {
294
+ _classCallCheck(this, Expr);
295
+ this.span = span;
296
+ });
297
+ var StringLiteral = /*#__PURE__*/function (_Expr) {
298
+ _inherits(StringLiteral, _Expr);
299
+ function StringLiteral(value, span) {
300
+ var _this;
301
+ _classCallCheck(this, StringLiteral);
302
+ _this = _callSuper(this, StringLiteral, [span]);
303
+ _defineProperty(_assertThisInitialized(_this), "type", "StringLiteral");
304
+ _this.value = value;
305
+ return _this;
306
+ }
307
+ _createClass(StringLiteral, [{
308
+ key: "transpile",
309
+ value: function transpile() {
310
+ return "'".concat(this.value, "'");
311
+ }
312
+ }]);
313
+ return StringLiteral;
314
+ }(Expr);
315
+ var Sym = /*#__PURE__*/function (_Expr2) {
316
+ _inherits(Sym, _Expr2);
317
+ function Sym(value, span) {
318
+ var _this2;
319
+ _classCallCheck(this, Sym);
320
+ _this2 = _callSuper(this, Sym, [span]);
321
+ _defineProperty(_assertThisInitialized(_this2), "type", "Sym");
322
+ _this2.value = value;
323
+ return _this2;
324
+ }
325
+ _createClass(Sym, [{
326
+ key: "transpile",
327
+ value: function transpile() {
328
+ return this.value;
329
+ }
330
+ }]);
331
+ return Sym;
332
+ }(Expr);
333
+ var NilSym = new Sym("()");
334
+ var StringTemplate = /*#__PURE__*/function (_Expr3) {
335
+ _inherits(StringTemplate, _Expr3);
336
+ function StringTemplate(children, span) {
337
+ var _this3;
338
+ _classCallCheck(this, StringTemplate);
339
+ _this3 = _callSuper(this, StringTemplate, [span]);
340
+ _defineProperty(_assertThisInitialized(_this3), "type", "StringTemplate");
341
+ _this3.children = children;
342
+ return _this3;
343
+ }
344
+ _createClass(StringTemplate, [{
345
+ key: "transpile",
346
+ value: function transpile() {
347
+ return "'".concat(this.children.map(function (child) {
348
+ if (child instanceof StringLiteral) {
349
+ return child.value;
350
+ } else {
351
+ return "${".concat(child.transpile(), "}");
352
+ }
353
+ }).join(""), "'");
354
+ }
355
+ }]);
356
+ return StringTemplate;
357
+ }(Expr);
358
+ var Call = /*#__PURE__*/function (_Expr4) {
359
+ _inherits(Call, _Expr4);
360
+ function Call(children, isAnon, span) {
361
+ var _this4;
362
+ _classCallCheck(this, Call);
363
+ _this4 = _callSuper(this, Call, [span]);
364
+ _defineProperty(_assertThisInitialized(_this4), "type", "Call");
365
+ _this4.children = children;
366
+ _this4.isAnon = isAnon;
367
+ return _this4;
368
+ }
369
+ _createClass(Call, [{
370
+ key: "transpile",
371
+ value: function transpile() {
372
+ if (this.isAnon) {
373
+ return "!(".concat(this.children.map(function (child) {
374
+ return child.transpile();
375
+ }).join(" "), ")");
376
+ }
377
+ return "(".concat(this.children.map(function (child) {
378
+ return child.transpile();
379
+ }).join(" "), ")");
380
+ }
381
+ }]);
382
+ return Call;
383
+ }(Expr);
384
+
385
+ /* Branded extension types: file, remote, i18n */
386
+ var VAL_EXTENSION = "_type";
387
+
388
+ /**
389
+ * A phantom type parameter is one that doesn't show up at runtime, but is checked statically (and only) at compile time.
390
+ *
391
+ * An example where this is useful is remote types, where the type of the remote source is known at compile time,
392
+ * but the value is not there before it is fetched.
393
+ *
394
+ * @example
395
+ * type Example<T> = string & PhantomType<T>;
396
+ *
397
+ **/
398
+
399
+ var FILE_REF_PROP = "_ref";
400
+ var FILE_REF_SUBTYPE_TAG = "_tag";
401
+
402
+ /**
403
+ * A file source represents the path to a (local) file.
404
+ *
405
+ * It will be resolved into a Asset object.
406
+ *
407
+ */
408
+
409
+ function file$1(ref, metadata) {
410
+ return _defineProperty(_defineProperty(_defineProperty({}, FILE_REF_PROP, ref), VAL_EXTENSION, "file"), "metadata", metadata);
411
+ }
412
+ function isFile(obj) {
413
+ 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";
414
+ }
415
+
416
+ var FileSchema = /*#__PURE__*/function (_Schema) {
417
+ _inherits(FileSchema, _Schema);
418
+ function FileSchema(options) {
419
+ var _this;
420
+ var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
421
+ _classCallCheck(this, FileSchema);
422
+ _this = _callSuper(this, FileSchema);
423
+ _this.options = options;
424
+ _this.opt = opt;
425
+ return _this;
426
+ }
427
+ _createClass(FileSchema, [{
428
+ key: "validate",
429
+ value: function validate(path, src) {
430
+ if (this.opt && (src === null || src === undefined)) {
431
+ return false;
432
+ }
433
+ if (src === null || src === undefined) {
434
+ return _defineProperty({}, path, [{
435
+ message: "Non-optional file was null or undefined.",
436
+ value: src
437
+ }]);
438
+ }
439
+ if (typeof src[FILE_REF_PROP] !== "string") {
440
+ return _defineProperty({}, path, [{
441
+ message: "File did not have a file reference string. Got: ".concat(_typeof(src[FILE_REF_PROP])),
442
+ value: src
443
+ }]);
444
+ }
445
+ if (src[VAL_EXTENSION] !== "file") {
446
+ return _defineProperty({}, path, [{
447
+ message: "File did not have the valid file extension type. Got: ".concat(src[VAL_EXTENSION]),
448
+ value: src
449
+ }]);
450
+ }
451
+ if (src.metadata) {
452
+ return _defineProperty({}, path, [{
453
+ 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).",
454
+ // 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.
455
+ value: src,
456
+ fixes: ["file:check-metadata"]
457
+ }]);
458
+ }
459
+ return _defineProperty({}, path, [{
460
+ message: "Missing File metadata.",
461
+ value: src,
462
+ fixes: ["file:add-metadata"]
463
+ }]);
464
+ }
465
+ }, {
466
+ key: "assert",
467
+ value: function assert(src) {
468
+ if (this.opt && (src === null || src === undefined)) {
469
+ return true;
470
+ }
471
+ return (src === null || src === void 0 ? void 0 : src[FILE_REF_PROP]) === "file" && (src === null || src === void 0 ? void 0 : src[VAL_EXTENSION]) === "file";
472
+ }
473
+ }, {
474
+ key: "nullable",
475
+ value: function nullable() {
476
+ return new FileSchema(this.options, true);
477
+ }
478
+ }, {
479
+ key: "serialize",
480
+ value: function serialize() {
481
+ return {
482
+ type: "file",
483
+ options: this.options,
484
+ opt: this.opt
485
+ };
486
+ }
487
+ }]);
488
+ return FileSchema;
489
+ }(Schema);
490
+ var file = function file(options) {
491
+ return new FileSchema(options);
492
+ };
493
+ function convertFileSource(src) {
494
+ var _src$metadata4, _src$metadata5, _src$metadata6;
495
+ // TODO: /public should be configurable
496
+ if (!src[FILE_REF_PROP].startsWith("/public")) {
497
+ var _src$metadata, _src$metadata2, _src$metadata3;
498
+ return {
499
+ 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) : "") + (
500
+ // TODO: remove sha256? we do not need anymore
501
+ src.patch_id ? "".concat((_src$metadata3 = src.metadata) !== null && _src$metadata3 !== void 0 && _src$metadata3.sha256 ? "&" : "?", "patch_id=").concat(src["patch_id"]) : ""),
502
+ metadata: src.metadata
503
+ };
504
+ }
505
+ return {
506
+ 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"]) : ""),
507
+ metadata: src.metadata
508
+ };
509
+ }
510
+
511
+ function isSerializedVal(val) {
512
+ return _typeof(val) === "object" && val !== null && val !== undefined && ("val" in val || "valPath" in val);
513
+ }
514
+ function isVal(val) {
515
+ return _typeof(val) === "object" && val !== null && val !== undefined && Path$1 in val && "val" in val;
516
+ }
517
+
518
+ /**
519
+ * The path of the source value.
520
+ *
521
+ * @example
522
+ * '/app/blogs.0.text' // the text property of the first element of the /app/blogs module
523
+ */
524
+
525
+ /**
526
+ * The path inside the module.
527
+ *
528
+ * @example
529
+ * '0."text"' // the text property of the first element of the module
530
+ */
531
+
532
+ /**
533
+ * The path of the module.
534
+ *
535
+ * @example
536
+ * '/app/blogs.val.ts'
537
+ */
538
+
539
+ function getValPath(valOrSelector) {
540
+ return valOrSelector[Path$1];
541
+ }
542
+
543
+ function hasOwn$2(obj, prop) {
544
+ return Object.prototype.hasOwnProperty.call(obj, prop);
545
+ }
546
+ function _andThen$1(f, source, path) {
547
+ if (source) {
548
+ return newSelectorProxy$1(f(newSelectorProxy$1(source, path)));
549
+ }
550
+ return newSelectorProxy$1(source, path);
551
+ }
552
+ function isSelector$1(source) {
553
+ return _typeof(source) === "object" && source !== null && (GetSource in source || Path$1 in source);
554
+ }
555
+ function newSelectorProxy$1(source, path, moduleSchema) {
556
+ if (_typeof(source) === "object") {
557
+ if (isSelector$1(source)) {
558
+ return source;
559
+ } else if (isSerializedVal(source)) {
560
+ return newSelectorProxy$1(source.val, source.valPath);
561
+ }
562
+ }
563
+ if (source && source[FILE_REF_PROP] && source[VAL_EXTENSION] === "file") {
564
+ var fileRef = source[FILE_REF_PROP];
565
+ if (typeof fileRef !== "string") {
566
+ throw Error("Invalid file ref: " + fileRef);
567
+ }
568
+ return newSelectorProxy$1(convertFileSource(source), path, moduleSchema);
569
+ }
570
+ switch (_typeof(source)) {
571
+ case "function":
572
+ case "symbol":
573
+ throw Error("Invalid selector type: ".concat(_typeof(source), ": ").concat(source));
574
+ case "object":
575
+ // Handles both objects and arrays!
576
+ if (source !== null) {
577
+ return new Proxy(source, {
578
+ // TODO: see proxy docs if we want more traps
579
+ has: function has(target, prop) {
580
+ if (prop === GetSource) {
581
+ return true;
582
+ }
583
+ if (prop === Path$1) {
584
+ return true;
585
+ }
586
+ if (prop === "andThen") {
587
+ return true;
588
+ }
589
+ if (prop === GetSchema$1) {
590
+ return true;
591
+ }
592
+ return prop in target;
593
+ },
594
+ get: function get(target, prop) {
595
+ if (prop === GetSource) {
596
+ return source;
597
+ }
598
+ if (prop === Path$1) {
599
+ return path;
600
+ }
601
+ if (prop === GetSchema$1) {
602
+ return moduleSchema;
603
+ }
604
+ if (prop === "andThen") {
605
+ return function (f) {
606
+ return _andThen$1(f, source, path);
607
+ };
608
+ }
609
+ if (Array.isArray(target)) {
610
+ if (prop === "filter") {
611
+ return function (f) {
612
+ var filtered = target.map(function (a, i) {
613
+ return newSelectorProxy$1(a, createValPathOfItem(path, i), moduleSchema === null || moduleSchema === void 0 ? void 0 : moduleSchema.item);
614
+ }).filter(function (a) {
615
+ if (f && f instanceof Schema) {
616
+ return f.assert(unValify$1(a));
617
+ } else {
618
+ return unValify$1(f(a));
619
+ }
620
+ });
621
+ return newSelectorProxy$1(filtered, path, moduleSchema);
622
+ };
623
+ } else if (prop === "map") {
624
+ return function (f) {
625
+ var filtered = target.map(function (a, i) {
626
+ var valueOrSelector = f(newSelectorProxy$1(a, createValPathOfItem(path, i), moduleSchema === null || moduleSchema === void 0 ? void 0 : moduleSchema.item), newSelectorProxy$1(i));
627
+ if (isSelector$1(valueOrSelector)) {
628
+ return valueOrSelector;
629
+ }
630
+ return newSelectorProxy$1(valueOrSelector);
631
+ });
632
+ return newSelectorProxy$1(filtered, path, moduleSchema);
633
+ };
634
+ }
635
+ }
636
+ if (Array.isArray(target) && prop === "length") {
637
+ return newSelectorProxy$1(target.length);
638
+ }
639
+ var reflectedValue = Reflect.get(target, prop);
640
+ if (hasOwn$2(source, prop)) {
641
+ if (!Number.isNaN(Number(prop))) {
642
+ return newSelectorProxy$1(reflectedValue, createValPathOfItem(path, Number(prop)), moduleSchema === null || moduleSchema === void 0 ? void 0 : moduleSchema.item);
643
+ }
644
+ return newSelectorProxy$1(reflectedValue, createValPathOfItem(path, prop), moduleSchema === null || moduleSchema === void 0 ? void 0 : moduleSchema.items[prop]);
645
+ }
646
+ return reflectedValue;
647
+ }
648
+ });
649
+ }
650
+ // intentional fallthrough
651
+ // eslint-disable-next-line no-fallthrough
652
+ default:
653
+ return _defineProperty(_defineProperty(_defineProperty({
654
+ eq: function eq(other) {
655
+ var otherValue = other;
656
+ if (isSelector$1(other)) {
657
+ otherValue = other[GetSource];
658
+ if (otherValue instanceof Expr) {
659
+ throw Error("TODO: Cannot evaluate equality with an Expr");
660
+ }
661
+ }
662
+ return newSelectorProxy$1(source === otherValue, undefined);
663
+ },
664
+ andThen: function andThen(f) {
665
+ return _andThen$1(f, source === undefined ? null : source, path);
666
+ }
667
+ }, GetSource, source === undefined ? null : source), Path$1, path), GetSchema$1, moduleSchema);
668
+ }
669
+ }
670
+ function createValPathOfItem(arrayPath, prop) {
671
+ if (_typeof(prop) === "symbol") {
672
+ throw Error("Cannot create val path of array item with symbol prop: ".concat(prop.toString()));
673
+ }
674
+ if (!arrayPath) {
675
+ return undefined;
676
+ }
677
+ if (arrayPath.includes(Internal.ModuleFilePathSep)) {
678
+ return "".concat(arrayPath, ".").concat(JSON.stringify(prop));
679
+ }
680
+ return "".concat(arrayPath).concat(Internal.ModuleFilePathSep).concat(JSON.stringify(prop));
681
+ }
682
+
683
+ // TODO: could we do .val on the objects instead?
684
+ function unValify$1(valueOrSelector) {
685
+ if (_typeof(valueOrSelector) === "object" && (GetSource in valueOrSelector || Path$1 in valueOrSelector)) {
686
+ var selectorValue = valueOrSelector[GetSource];
687
+ return selectorValue;
688
+ }
689
+ return valueOrSelector;
690
+ }
691
+
692
+ var ObjectSchema = /*#__PURE__*/function (_Schema) {
693
+ _inherits(ObjectSchema, _Schema);
694
+ function ObjectSchema(items) {
695
+ var _this;
696
+ var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
697
+ _classCallCheck(this, ObjectSchema);
698
+ _this = _callSuper(this, ObjectSchema);
699
+ _this.items = items;
700
+ _this.opt = opt;
701
+ return _this;
702
+ }
703
+ _createClass(ObjectSchema, [{
704
+ key: "validate",
705
+ value: function validate(path, src) {
706
+ var _this2 = this;
707
+ var error = false;
708
+
709
+ // TODO: src should never be undefined
710
+ if (this.opt && (src === null || src === undefined)) {
711
+ return false;
712
+ }
713
+ if (_typeof(src) !== "object") {
714
+ return _defineProperty({}, path, [{
715
+ message: "Expected 'object', got '".concat(_typeof(src), "'")
716
+ }]);
717
+ } else if (Array.isArray(src)) {
718
+ return _defineProperty({}, path, [{
719
+ message: "Expected 'object', got 'array'"
720
+ }]);
721
+ }
722
+ Object.entries(this.items).forEach(function (_ref3) {
723
+ var _ref4 = _slicedToArray(_ref3, 2),
724
+ key = _ref4[0],
725
+ schema = _ref4[1];
726
+ var subPath = createValPathOfItem(path, key);
727
+ if (!subPath) {
728
+ error = _this2.appendValidationError(error, path, "Internal error: could not create path at ".concat(!path && typeof path === "string" ? "<empty string>" : path, " at key ").concat(key),
729
+ // Should! never happen
730
+ src);
731
+ } else {
732
+ var subError = schema.validate(subPath, src[key]);
733
+ if (subError && error) {
734
+ error = _objectSpread2(_objectSpread2({}, subError), error);
735
+ } else if (subError) {
736
+ error = subError;
737
+ }
738
+ }
739
+ });
740
+ return error;
741
+ }
742
+ }, {
743
+ key: "assert",
744
+ value: function assert(src) {
745
+ if (this.opt && (src === null || src === undefined)) {
746
+ return true;
747
+ }
748
+ if (!src) {
749
+ return false;
750
+ }
751
+ for (var _i = 0, _Object$entries = Object.entries(this.items); _i < _Object$entries.length; _i++) {
752
+ var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
753
+ _key = _Object$entries$_i[0],
754
+ schema = _Object$entries$_i[1];
755
+ if (!schema.assert(src[_key])) {
756
+ return false;
757
+ }
758
+ }
759
+ return _typeof(src) === "object" && !Array.isArray(src);
760
+ }
761
+ }, {
762
+ key: "nullable",
763
+ value: function nullable() {
764
+ return new ObjectSchema(this.items, true);
765
+ }
766
+ }, {
767
+ key: "serialize",
768
+ value: function serialize() {
769
+ return {
770
+ type: "object",
771
+ items: Object.fromEntries(Object.entries(this.items).map(function (_ref5) {
772
+ var _ref6 = _slicedToArray(_ref5, 2),
773
+ key = _ref6[0],
774
+ schema = _ref6[1];
775
+ return [key, schema.serialize()];
776
+ })),
777
+ opt: this.opt
778
+ };
779
+ }
780
+ }]);
781
+ return ObjectSchema;
782
+ }(Schema);
783
+ var object = function object(schema) {
784
+ return new ObjectSchema(schema);
785
+ };
786
+
787
+ var WHITE_SPACE = ["\n", "\r", "\t", " "];
788
+ function tokenize(input) {
789
+ var tokens = [];
790
+ var cursor = 0;
791
+ while (cursor < input.length) {
792
+ var _char = input[cursor];
793
+ var peek = input[cursor + 1];
794
+ // TODO: remove this not used any more
795
+ if (_char === "!" && peek === "(") {
796
+ tokens.push({
797
+ type: "!(",
798
+ span: [cursor, cursor + 1]
799
+ });
800
+ cursor += 2;
801
+ } else if (_char === "(") {
802
+ tokens.push({
803
+ type: "(",
804
+ span: [cursor, cursor]
805
+ });
806
+ cursor++;
807
+ } else if (_char === ")") {
808
+ tokens.push({
809
+ type: ")",
810
+ span: [cursor, cursor]
811
+ });
812
+ cursor++;
813
+ } else if (_char === "'" || _char === "}") {
814
+ var _start = cursor;
815
+ var value = "";
816
+ var unescapedValue = "";
817
+ var escaped = false;
818
+ if (_char === "}") {
819
+ tokens.push({
820
+ type: "}",
821
+ span: [cursor, cursor]
822
+ });
823
+ } else if (_char === "'") {
824
+ tokens.push({
825
+ type: "'",
826
+ span: [cursor, cursor]
827
+ });
828
+ }
829
+ while (cursor < input.length) {
830
+ if (_char === "\\") {
831
+ escaped = !escaped;
832
+ } else {
833
+ escaped = false;
834
+ }
835
+ if (peek === "'" && !escaped) {
836
+ cursor += 2;
837
+ break;
838
+ } else if (_char === "$" && peek === "{") {
839
+ cursor += 2;
840
+ break;
841
+ }
842
+ cursor++;
843
+ _char = input[cursor];
844
+ peek = input[cursor + 1];
845
+ if (!(_char === "$" && peek === "{") && cursor < input.length) {
846
+ if (!(_char === "\\" && !escaped // counter-intuitive, but escape just became false if this was a backslash we want to escape
847
+ )) {
848
+ value += _char;
849
+ }
850
+ unescapedValue += _char;
851
+ }
852
+ }
853
+ var cursorOffset = peek === "'" && !escaped ? 2 : _char === "$" && peek === "{" ? 3 : 1;
854
+ if (value) {
855
+ tokens.push(_objectSpread2({
856
+ type: "string",
857
+ span: [_start + 1, cursor - cursorOffset],
858
+ value: value
859
+ }, unescapedValue !== value && {
860
+ unescapedValue: unescapedValue
861
+ }));
862
+ }
863
+ if (peek === "'" && !escaped) {
864
+ tokens.push({
865
+ type: "'",
866
+ span: [cursor - 1, cursor - 1]
867
+ });
868
+ } else if (_char === "$" && peek === "{") {
869
+ tokens.push({
870
+ type: "${",
871
+ span: [cursor - cursorOffset + 1, cursor - 1]
872
+ });
873
+ }
874
+ } else if (WHITE_SPACE.includes(_char)) {
875
+ var _start2 = cursor;
876
+ while (WHITE_SPACE.includes(input[cursor]) && cursor < input.length) {
877
+ cursor++;
878
+ }
879
+ tokens.push({
880
+ type: "ws",
881
+ span: [_start2, cursor - 1]
882
+ });
883
+ } else {
884
+ var _value = "";
885
+ var _start3 = cursor;
886
+ do {
887
+ _char = input[cursor];
888
+ peek = input[cursor + 1];
889
+ _value += _char;
890
+ cursor++;
891
+ } while (!WHITE_SPACE.includes(peek) && peek !== ")" && peek !== "'" && cursor < input.length);
892
+ tokens.push({
893
+ type: "token",
894
+ span: [_start3, cursor - 1],
895
+ value: _value
896
+ });
897
+ }
898
+ }
899
+ return [tokens, cursor];
900
+ }
901
+
902
+ var ParserError = /*#__PURE__*/_createClass(function ParserError(message, span) {
903
+ _classCallCheck(this, ParserError);
904
+ this.message = message;
905
+ this.span = span;
906
+ });
907
+ function parseTokens(inputTokens) {
908
+ var tokens = inputTokens.slice();
909
+ function slurpCall(first, isAnon) {
910
+ var _tokens$, _tokens$2, _tokens$3, _tokens$7, _tokens$8, _args$slice$0$span;
911
+ // peek
912
+ if (((_tokens$ = tokens[0]) === null || _tokens$ === void 0 ? void 0 : _tokens$.type) === "ws" && ((_tokens$2 = tokens[1]) === null || _tokens$2 === void 0 ? void 0 : _tokens$2.type) === ")" || ((_tokens$3 = tokens[0]) === null || _tokens$3 === void 0 ? void 0 : _tokens$3.type) === ")") {
913
+ slurpWs();
914
+ tokens.shift();
915
+ return result.ok(new Sym("()", [first.span[0], first.span[1] + 1]));
916
+ }
917
+ var args = [];
918
+ var completed = false;
919
+ while (!completed) {
920
+ var _res = slurp();
921
+ if (result.isOk(_res)) {
922
+ var _tokens$4, _tokens$5, _tokens$6;
923
+ args.push(_res.value);
924
+ completed = ((_tokens$4 = tokens[0]) === null || _tokens$4 === void 0 ? void 0 : _tokens$4.type) !== "ws" || ((_tokens$5 = tokens[0]) === null || _tokens$5 === void 0 ? void 0 : _tokens$5.type) === "ws" && ((_tokens$6 = tokens[1]) === null || _tokens$6 === void 0 ? void 0 : _tokens$6.type) === ")";
925
+ } else {
926
+ return _res;
927
+ }
928
+ }
929
+ if (((_tokens$7 = tokens[0]) === null || _tokens$7 === void 0 ? void 0 : _tokens$7.type) === "ws" && ((_tokens$8 = tokens[1]) === null || _tokens$8 === void 0 ? void 0 : _tokens$8.type) === ")") {
930
+ tokens.shift();
931
+ }
932
+ var last = tokens.shift();
933
+ if ((last === null || last === void 0 ? void 0 : last.type) !== ")") {
934
+ return result.err(new ParserError("unbalanced parens: missing a ')'", [first.span[0], first.span[1] + 1]));
935
+ }
936
+ return result.ok(new Call(args, isAnon, [first.span[0], ((_args$slice$0$span = args.slice(-1)[0].span) === null || _args$slice$0$span === void 0 ? void 0 : _args$slice$0$span[1]) || -1]));
937
+ }
938
+ function slurpWs() {
939
+ while (((_tokens$9 = tokens[0]) === null || _tokens$9 === void 0 ? void 0 : _tokens$9.type) === "ws") {
940
+ var _tokens$9;
941
+ tokens.shift();
942
+ }
943
+ }
944
+ function slurpTemplate(first) {
945
+ var children = [];
946
+ while (tokens.length > 0) {
947
+ var _tokens$10;
948
+ if (((_tokens$10 = tokens[0]) === null || _tokens$10 === void 0 ? void 0 : _tokens$10.type) === "'") {
949
+ break;
950
+ }
951
+ var nextToken = tokens.shift();
952
+ if ((nextToken === null || nextToken === void 0 ? void 0 : nextToken.type) === "${") {
953
+ var _res2 = slurp();
954
+ if (result.isOk(_res2)) {
955
+ children.push(_res2.value);
956
+ var _last = tokens.shift();
957
+ if (!_last) {
958
+ var _children$slice$0$spa;
959
+ return result.err(new ParserError("unbalanced string template: missing a '}'", [first.span[0], (_children$slice$0$spa = children.slice(-1)[0].span) === null || _children$slice$0$spa === void 0 ? void 0 : _children$slice$0$spa[1]]));
960
+ } else if (_last.type !== "}") {
961
+ return result.err(new ParserError("unbalanced string template: expected '}'", _last.span));
962
+ }
963
+ } else {
964
+ return _res2;
965
+ }
966
+ } else if ((nextToken === null || nextToken === void 0 ? void 0 : nextToken.type) === "string") {
967
+ children.push(new StringLiteral(nextToken.unescapedValue || nextToken.value || "", nextToken.span));
968
+ }
969
+ }
970
+ var last = tokens.shift();
971
+ if (!last) {
972
+ var _children$slice$0$spa2;
973
+ return result.err(new ParserError("unbalanced string template: missing a '''", [first.span[0], (_children$slice$0$spa2 = children.slice(-1)[0].span) === null || _children$slice$0$spa2 === void 0 ? void 0 : _children$slice$0$spa2[1]]));
974
+ } else if (last.type !== "'") {
975
+ return result.err(new ParserError("unbalanced string template: expected '''", last.span));
976
+ }
977
+ return result.ok(new StringTemplate(children, [first.span[0], last.span[1]]));
978
+ }
979
+ function slurpString(first) {
980
+ var _tokens$11, _tokens$12, _tokens$13;
981
+ if (((_tokens$11 = tokens[0]) === null || _tokens$11 === void 0 ? void 0 : _tokens$11.type) === "string" && ((_tokens$12 = tokens[1]) === null || _tokens$12 === void 0 ? void 0 : _tokens$12.type) === "'") {
982
+ var stringToken = tokens.shift();
983
+ var last = tokens.shift();
984
+ if (!last || !stringToken) {
985
+ throw Error("Unexpected error: stringToken or last is undefined");
986
+ }
987
+ return result.ok(new StringLiteral(stringToken.unescapedValue || stringToken.value || "", [first.span[0], last.span[1]]));
988
+ } else if (((_tokens$13 = tokens[0]) === null || _tokens$13 === void 0 ? void 0 : _tokens$13.type) === "'") {
989
+ var _last2 = tokens.shift();
990
+ if (!_last2) {
991
+ throw Error("Unexpected error: last is undefined");
992
+ }
993
+ return result.ok(new StringLiteral("", [first.span[0], _last2.span[1]]));
994
+ } else {
995
+ return slurpTemplate(first);
996
+ }
997
+ }
998
+ function slurp() {
999
+ slurpWs();
1000
+ var first = tokens.shift();
1001
+ if (!first) {
1002
+ return result.err(new ParserError("expected '(', '!(', string or literal", [0, 0]));
1003
+ }
1004
+ if (first.type === "(" || first.type === "!(") {
1005
+ return slurpCall(first, first.type === "!(");
1006
+ } else if (first.type === "'") {
1007
+ return slurpString(first);
1008
+ } else if (first.type === "token") {
1009
+ var _first$value, _first$value2, _first$value3, _first$value4, _first$value5, _first$value6;
1010
+ if ((_first$value = first.value) !== null && _first$value !== void 0 && _first$value.includes("(") || (_first$value2 = first.value) !== null && _first$value2 !== void 0 && _first$value2.includes(")")) {
1011
+ return result.err(new ParserError("unexpected token: '(' and ')' are not allowed in tokens", first.span));
1012
+ }
1013
+ if ((_first$value3 = first.value) !== null && _first$value3 !== void 0 && _first$value3.includes("'")) {
1014
+ return result.err(new ParserError('unexpected token: "\'" is not allowed in tokens', first.span));
1015
+ }
1016
+ if ((_first$value4 = first.value) !== null && _first$value4 !== void 0 && _first$value4.includes(".")) {
1017
+ return result.err(new ParserError('unexpected token: "." is not allowed in tokens', first.span));
1018
+ }
1019
+ if ((_first$value5 = first.value) !== null && _first$value5 !== void 0 && _first$value5.includes("{") || (_first$value6 = first.value) !== null && _first$value6 !== void 0 && _first$value6.includes("}")) {
1020
+ return result.err(new ParserError("unexpected token: '{' and '}' are not allowed in tokens", first.span));
1021
+ }
1022
+ return result.ok(new Sym(first.value || "", first.span));
1023
+ } else {
1024
+ return result.err(new ParserError("expected '(', '!(' or literal or token".concat(first.value || first.type ? ", got: '".concat(first.value || first.type, "'") : ""), first.span));
1025
+ }
1026
+ }
1027
+ var res = slurp();
1028
+ slurpWs();
1029
+ if (result.isErr(res)) {
1030
+ return res;
1031
+ }
1032
+ if (tokens.length > 0) {
1033
+ return result.err(new ParserError("expected end of input, superfluous tokens", [tokens[0].span[0], tokens.slice(-1)[0].span[1]]));
1034
+ }
1035
+ return res;
1036
+ }
1037
+ function parse$1(input) {
1038
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1039
+ var _tokenize = tokenize(input),
1040
+ _tokenize2 = _slicedToArray(_tokenize, 2),
1041
+ tokens = _tokenize2[0];
1042
+ _tokenize2[1]; // TODO: we can use cursor to improve error messages / spans
1043
+ return parseTokens(tokens);
1044
+ }
1045
+
1046
+ /* eslint-disable @typescript-eslint/no-unused-vars */
1047
+
1048
+ /**
1049
+ * Selectors can be used to select parts of a Val module.
1050
+ * Unlike queries, joins, aggregates etc is and will not be supported.
1051
+ *
1052
+ * They are designed to be be used as if they were "normal" JSON data,
1053
+ * though some concessions had to be made because of TypeScript limitations.
1054
+ *
1055
+ * Selectors works equally on source content, defined in code, and remote content.
1056
+ *
1057
+ * @example
1058
+ * // Select the title of a document
1059
+ * const titles = useVal(docsVal.map((doc) => doc.title));
1060
+ *
1061
+ * @example
1062
+ * // Match on a union type
1063
+ * const titles = useVal(docsVal.map((doc) => doc.fold("type")({
1064
+ * newsletter: (newsletter) => newsletter.title,
1065
+ * email: (email) => email.subject,
1066
+ * }));
1067
+ *
1068
+ */
1069
+
1070
+ /**
1071
+ * @internal
1072
+ */
1073
+ var GetSchema = Symbol("GetSchema");
1074
+ /**
1075
+ /**
1076
+ * @internal
1077
+ */
1078
+ var Path = Symbol("Path");
1079
+ /**
1080
+ * @internal
1081
+ */
1082
+ var SourceOrExpr = Symbol("SourceOrExpr");
1083
+
1084
+ /**
1085
+ * Use this type to convert types that accepts both Source and Selectors
1086
+ *
1087
+ * An example would be where literals are supported like in most higher order functions (e.g. map in array)
1088
+ **/
1089
+
1090
+ function hasOwn$1(obj, prop) {
1091
+ return Object.prototype.hasOwnProperty.call(obj, prop);
1092
+ }
1093
+ function _andThen(f, source, path) {
1094
+ if (source) {
1095
+ return newSelectorProxy(f(newSelectorProxy(source, path)));
1096
+ }
1097
+ return newSelectorProxy(source, path);
1098
+ }
1099
+ function isSelector(source) {
1100
+ return _typeof(source) === "object" && source !== null && (SourceOrExpr in source || Path in source);
1101
+ }
1102
+ function newSelectorProxy(source, path, moduleSchema) {
1103
+ if (_typeof(source) === "object") {
1104
+ if (isSelector(source)) {
1105
+ return source;
1106
+ } else if (isSerializedVal(source)) {
1107
+ return newSelectorProxy(source.val, source.valPath);
1108
+ }
1109
+ }
1110
+ if (source && source[FILE_REF_PROP] && source[VAL_EXTENSION] === "file") {
1111
+ var fileRef = source[FILE_REF_PROP];
1112
+ if (typeof fileRef !== "string") {
1113
+ throw Error("Invalid file ref: " + fileRef);
1114
+ }
1115
+ return newSelectorProxy(convertFileSource(source), path, moduleSchema);
1116
+ }
1117
+ switch (_typeof(source)) {
1118
+ case "function":
1119
+ case "symbol":
1120
+ throw Error("Invalid selector type: ".concat(_typeof(source), ": ").concat(source));
1121
+ case "object":
1122
+ // Handles both objects and arrays!
1123
+ if (source !== null) {
1124
+ return new Proxy(source, {
1125
+ // TODO: see proxy docs if we want more traps
1126
+ has: function has(target, prop) {
1127
+ if (prop === SourceOrExpr) {
1128
+ return true;
1129
+ }
1130
+ if (prop === Path) {
1131
+ return true;
1132
+ }
1133
+ if (prop === "andThen") {
1134
+ return true;
1135
+ }
1136
+ if (prop === GetSchema) {
1137
+ return true;
1138
+ }
1139
+ return prop in target;
1140
+ },
1141
+ get: function get(target, prop) {
1142
+ if (prop === SourceOrExpr) {
1143
+ return source;
1144
+ }
1145
+ if (prop === Path) {
1146
+ return path;
1147
+ }
1148
+ if (prop === GetSchema) {
1149
+ return moduleSchema;
1150
+ }
1151
+ if (prop === "andThen") {
1152
+ return function (f) {
1153
+ return _andThen(f, source, path);
1154
+ };
1155
+ }
1156
+ if (Array.isArray(target)) {
1157
+ if (prop === "filter") {
1158
+ return function (f) {
1159
+ var filtered = target.map(function (a, i) {
1160
+ return newSelectorProxy(a, createValPathOfItem(path, i), moduleSchema === null || moduleSchema === void 0 ? void 0 : moduleSchema.item);
1161
+ }).filter(function (a) {
1162
+ if (f && f instanceof Schema) {
1163
+ return f.assert(unValify(a));
1164
+ } else {
1165
+ return unValify(f(a));
1166
+ }
1167
+ });
1168
+ return newSelectorProxy(filtered, path, moduleSchema);
1169
+ };
1170
+ } else if (prop === "map") {
1171
+ return function (f) {
1172
+ var filtered = target.map(function (a, i) {
1173
+ var valueOrSelector = f(newSelectorProxy(a, createValPathOfItem(path, i), moduleSchema === null || moduleSchema === void 0 ? void 0 : moduleSchema.item), newSelectorProxy(i));
1174
+ if (isSelector(valueOrSelector)) {
1175
+ return valueOrSelector;
1176
+ }
1177
+ return newSelectorProxy(valueOrSelector);
1178
+ });
1179
+ return newSelectorProxy(filtered, path, moduleSchema);
1180
+ };
1181
+ }
1182
+ }
1183
+ if (Array.isArray(target) && prop === "length") {
1184
+ return newSelectorProxy(target.length);
1185
+ }
1186
+ var reflectedValue = Reflect.get(target, prop);
1187
+ if (hasOwn$1(source, prop)) {
1188
+ if (!Number.isNaN(Number(prop))) {
1189
+ return newSelectorProxy(reflectedValue, createValPathOfItem(path, Number(prop)), moduleSchema === null || moduleSchema === void 0 ? void 0 : moduleSchema.item);
1190
+ }
1191
+ return newSelectorProxy(reflectedValue, createValPathOfItem(path, prop), moduleSchema === null || moduleSchema === void 0 ? void 0 : moduleSchema.items[prop]);
1192
+ }
1193
+ return reflectedValue;
1194
+ }
1195
+ });
1196
+ }
1197
+ // intentional fallthrough
1198
+ // eslint-disable-next-line no-fallthrough
1199
+ default:
1200
+ return _defineProperty(_defineProperty(_defineProperty({
1201
+ eq: function eq(other) {
1202
+ var otherValue = other;
1203
+ if (isSelector(other)) {
1204
+ otherValue = other[SourceOrExpr];
1205
+ if (otherValue instanceof Expr) {
1206
+ throw Error("TODO: Cannot evaluate equality with an Expr");
1207
+ }
1208
+ }
1209
+ return newSelectorProxy(source === otherValue, undefined);
1210
+ },
1211
+ andThen: function andThen(f) {
1212
+ return _andThen(f, source === undefined ? null : source, path);
1213
+ }
1214
+ }, SourceOrExpr, source === undefined ? null : source), Path, path), GetSchema, moduleSchema);
1215
+ }
1216
+ }
1217
+
1218
+ // TODO: could we do .val on the objects instead?
1219
+ function unValify(valueOrSelector) {
1220
+ if (_typeof(valueOrSelector) === "object" && (SourceOrExpr in valueOrSelector || Path in valueOrSelector)) {
1221
+ var selectorValue = valueOrSelector[SourceOrExpr];
1222
+ return selectorValue;
1223
+ }
1224
+ return valueOrSelector;
1225
+ }
1226
+
1227
+ var EvalError = /*#__PURE__*/function () {
1228
+ function EvalError(message, expr) {
1229
+ _classCallCheck(this, EvalError);
1230
+ this.message = message;
1231
+ this.expr = expr;
1232
+ }
1233
+ _createClass(EvalError, [{
1234
+ key: "toString",
1235
+ value: function toString() {
1236
+ return "".concat(this.message, " in: ").concat(this.expr.transpile());
1237
+ }
1238
+ }]);
1239
+ return EvalError;
1240
+ }();
1241
+ var MAX_STACK_SIZE = 100; // an arbitrary semi-large number
1242
+ function evaluateSync(expr, getSource, stack) {
1243
+ // TODO: amount of evaluates should be limited?
1244
+ if (stack.length > MAX_STACK_SIZE) {
1245
+ throw new EvalError("Stack overflow. Final frames: ".concat(stack.slice(-10).map(function (frame, i) {
1246
+ return frame.map(function (s, j) {
1247
+ return "@[".concat(i, ",").concat(j, "]: ").concat(JSON.stringify(s));
1248
+ }).join(", ");
1249
+ }).join(" -> ")), expr);
1250
+ }
1251
+ if (expr instanceof Call) {
1252
+ if (expr.children[0] instanceof Sym) {
1253
+ if (expr.children[0].value === "val") {
1254
+ if (expr.isAnon) {
1255
+ throw new EvalError("cannot call 'val' as anonymous function", expr);
1256
+ }
1257
+ if (expr.children[1] instanceof StringLiteral) {
1258
+ var _path = expr.children[1].value;
1259
+ return newSelectorProxy(getSource(_path), _path);
1260
+ } else {
1261
+ throw new EvalError("argument of 'val' must be a string literal", expr);
1262
+ }
1263
+ } else if (expr.children[0].value === "json") {
1264
+ if (expr.children.length !== 2) {
1265
+ throw new EvalError("must call 'json' with exactly one argument", expr);
1266
+ }
1267
+ var value = evaluateSync(expr.children[1], getSource, stack);
1268
+ var valObj = value[SourceOrExpr];
1269
+ var valPath = value[Path];
1270
+ if (typeof valObj !== "string") {
1271
+ throw new EvalError("cannot parse JSON: ".concat(JSON.stringify(valObj), ", expected string"), expr.children[1]);
1272
+ }
1273
+ try {
1274
+ var serialized = JSON.parse(valObj);
1275
+ if (isSerializedVal(serialized)) {
1276
+ return newSelectorProxy(serialized.val, serialized.valPath);
1277
+ }
1278
+ var parsedValue = newSelectorProxy(JSON.parse(valObj), valPath);
1279
+ return parsedValue;
1280
+ } catch (e) {
1281
+ if (e instanceof SyntaxError) {
1282
+ throw new EvalError("cannot parse JSON: ".concat(valObj, ", ").concat(e.message, " - value: ").concat(JSON.stringify(value)), expr.children[1]);
1283
+ }
1284
+ throw e;
1285
+ }
1286
+ } else if (expr.children[0].value === "stringify") {
1287
+ // TODO: remove stringify
1288
+ if (expr.children.length !== 2) {
1289
+ throw new EvalError("must call 'stringify' with exactly one argument", expr);
1290
+ }
1291
+ var res = evaluateSync(expr.children[1], getSource, stack);
1292
+ return newSelectorProxy(JSON.stringify(res[SourceOrExpr]));
1293
+ }
1294
+ }
1295
+ var prop = evaluateSync(expr.children[0], getSource, stack)[SourceOrExpr];
1296
+ if (expr.children.length === 1) {
1297
+ // TODO: return if literal only?
1298
+ return newSelectorProxy(prop);
1299
+ }
1300
+ var obj = evaluateSync(expr.children[1], getSource, stack);
1301
+ if (typeof prop !== "string" && typeof prop !== "number") {
1302
+ throw new EvalError("cannot access ".concat(JSON.stringify(obj), " with property ").concat(JSON.stringify(prop), ": is not a string or number"), expr);
1303
+ }
1304
+ if (prop in obj) {
1305
+ if (expr.isAnon) {
1306
+ // anon functions:
1307
+ var maybeFunction = obj[prop];
1308
+ if (typeof maybeFunction !== "function") {
1309
+ throw new EvalError("cannot access property ".concat(JSON.stringify(prop), " of ").concat(JSON.stringify(obj), ": required higher ordered function got ").concat(_typeof(obj[prop])), expr);
1310
+ }
1311
+ if (expr.children[0] instanceof Sym) {
1312
+ return maybeFunction(function () {
1313
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
1314
+ args[_key] = arguments[_key];
1315
+ }
1316
+ return evaluateSync(expr.children[2], getSource, stack.concat([args]));
1317
+ });
1318
+ } else {
1319
+ throw new EvalError("cannot call an expression that is not a symbol, got: '".concat(expr.children[0].type, "'"), expr);
1320
+ }
1321
+ } else {
1322
+ // non-anon functions:
1323
+ if (expr.children[0] instanceof Sym) {
1324
+ if (expr.children[0].value === "val") {
1325
+ if (expr.children[1] instanceof StringLiteral) {
1326
+ var _path2 = expr.children[1].value;
1327
+ return newSelectorProxy(getSource(_path2), _path2);
1328
+ } else {
1329
+ throw new EvalError("argument of 'val' must be a string literal", expr);
1330
+ }
1331
+ }
1332
+ }
1333
+ var args = expr.children.slice(2);
1334
+ if (args.length > 0) {
1335
+ var _maybeFunction = obj[prop];
1336
+ if (typeof _maybeFunction !== "function") {
1337
+ throw new EvalError("cannot access property ".concat(JSON.stringify(prop), " of ").concat(JSON.stringify(obj), ": required function got ").concat(_typeof(obj[prop])), expr);
1338
+ }
1339
+ return _maybeFunction.apply(void 0, _toConsumableArray(args.map(function (arg) {
1340
+ return evaluateSync(arg, getSource, stack);
1341
+ })));
1342
+ }
1343
+ var maybeValue = obj[prop];
1344
+ if (typeof maybeValue === "function") {
1345
+ throw new EvalError("cannot access property ".concat(JSON.stringify(prop), " of ").concat(JSON.stringify(obj), ": required value got ").concat(_typeof(obj[prop])), expr);
1346
+ }
1347
+ return maybeValue;
1348
+ }
1349
+ }
1350
+ } else if (expr instanceof Sym) {
1351
+ if (expr.value.startsWith("@")) {
1352
+ var _stack$Number;
1353
+ var _expr$value$slice$spl = expr.value.slice(2, -1).split(","),
1354
+ _expr$value$slice$spl2 = _slicedToArray(_expr$value$slice$spl, 3),
1355
+ i = _expr$value$slice$spl2[0],
1356
+ j = _expr$value$slice$spl2[1],
1357
+ rest = _expr$value$slice$spl2[2];
1358
+ if (rest) {
1359
+ throw new EvalError("cannot access stack: too many indices", expr);
1360
+ }
1361
+ var stackValue = (_stack$Number = stack[Number(i)]) === null || _stack$Number === void 0 ? void 0 : _stack$Number[Number(j)];
1362
+ if (stackValue === undefined) {
1363
+ throw new EvalError("cannot access stack: out of bounds", expr);
1364
+ }
1365
+ return stackValue;
1366
+ } else if (expr.value === "()") {
1367
+ return newSelectorProxy(null);
1368
+ }
1369
+ return newSelectorProxy(expr.value);
1370
+ } else if (expr instanceof StringLiteral) {
1371
+ return newSelectorProxy(expr.value);
1372
+ } else if (expr instanceof StringTemplate) {
1373
+ return newSelectorProxy(expr.children.map(function (child) {
1374
+ if (child instanceof Sym && child.value === "()") {
1375
+ return "null";
1376
+ }
1377
+ var evalRes = evaluateSync(child, getSource, stack);
1378
+ if (child.type === "StringLiteral" || child.type === "StringTemplate") {
1379
+ return evalRes[SourceOrExpr];
1380
+ }
1381
+ if (Path in evalRes) {
1382
+ // a selector, so serialize to Val
1383
+ return JSON.stringify({
1384
+ val: evalRes[SourceOrExpr],
1385
+ valPath: evalRes[Path]
1386
+ });
1387
+ }
1388
+ return JSON.stringify(evalRes[SourceOrExpr]);
1389
+ }).join(""));
1390
+ }
1391
+ throw new EvalError("could not evaluate", expr);
1392
+ }
1393
+ function evaluate(expr, source, stack) {
1394
+ try {
1395
+ return result.ok(evaluateSync(expr, source, stack));
1396
+ } catch (err) {
1397
+ if (err instanceof EvalError) {
1398
+ return result.err(err);
1399
+ }
1400
+ throw err;
1401
+ }
1402
+ }
1403
+
1404
+ var index = /*#__PURE__*/Object.freeze({
1405
+ __proto__: null,
1406
+ parse: parse$1,
1407
+ Call: Call,
1408
+ Expr: Expr,
1409
+ NilSym: NilSym,
1410
+ StringLiteral: StringLiteral,
1411
+ StringTemplate: StringTemplate,
1412
+ Sym: Sym,
1413
+ evaluate: evaluate
1414
+ });
1415
+
1416
+ var ArraySchema = /*#__PURE__*/function (_Schema) {
1417
+ _inherits(ArraySchema, _Schema);
1418
+ function ArraySchema(item) {
1419
+ var _this;
1420
+ var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1421
+ _classCallCheck(this, ArraySchema);
1422
+ _this = _callSuper(this, ArraySchema);
1423
+ _this.item = item;
1424
+ _this.opt = opt;
1425
+ return _this;
1426
+ }
1427
+ _createClass(ArraySchema, [{
1428
+ key: "validate",
1429
+ value: function validate(path, src) {
1430
+ var _this2 = this;
1431
+ var error = false;
1432
+ if (this.opt && (src === null || src === undefined)) {
1433
+ return false;
1434
+ }
1435
+ if (_typeof(src) !== "object" || !Array.isArray(src)) {
1436
+ return _defineProperty({}, path, [{
1437
+ message: "Expected 'array', got '".concat(_typeof(src), "'")
1438
+ }]);
1439
+ }
1440
+ src.forEach(function (i, idx) {
1441
+ var subPath = createValPathOfItem(path, idx);
1442
+ if (!subPath) {
1443
+ error = _this2.appendValidationError(error, path, "Internal error: could not create path at ".concat(!path && typeof path === "string" ? "<empty string>" : path, " at index ").concat(idx),
1444
+ // Should! never happen
1445
+ src);
1446
+ } else {
1447
+ var subError = _this2.item.validate(subPath, i);
1448
+ if (subError && error) {
1449
+ error = _objectSpread2(_objectSpread2({}, subError), error);
1450
+ } else if (subError) {
1451
+ error = subError;
1452
+ }
1453
+ }
1454
+ });
1455
+ return error;
1456
+ }
1457
+ }, {
1458
+ key: "assert",
1459
+ value: function assert(src) {
1460
+ if (this.opt && (src === null || src === undefined)) {
1461
+ return true;
1462
+ }
1463
+ if (!src) {
1464
+ return false;
1465
+ }
1466
+ var _iterator = result._createForOfIteratorHelper(src),
1467
+ _step;
1468
+ try {
1469
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
1470
+ var _item = _step.value;
1471
+ if (!this.item.assert(_item)) {
1472
+ return false;
1473
+ }
1474
+ }
1475
+ } catch (err) {
1476
+ _iterator.e(err);
1477
+ } finally {
1478
+ _iterator.f();
1479
+ }
1480
+ return _typeof(src) === "object" && Array.isArray(src);
1481
+ }
1482
+ }, {
1483
+ key: "nullable",
1484
+ value: function nullable() {
1485
+ return new ArraySchema(this.item, true);
1486
+ }
1487
+ }, {
1488
+ key: "serialize",
1489
+ value: function serialize() {
1490
+ return {
1491
+ type: "array",
1492
+ item: this.item.serialize(),
1493
+ opt: this.opt
1494
+ };
1495
+ }
1496
+ }]);
1497
+ return ArraySchema;
1498
+ }(Schema);
1499
+ var array = function array(schema) {
1500
+ return new ArraySchema(schema);
1501
+ };
1502
+
1503
+ var LiteralSchema = /*#__PURE__*/function (_Schema) {
1504
+ _inherits(LiteralSchema, _Schema);
1505
+ function LiteralSchema(value) {
1506
+ var _this;
1507
+ var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1508
+ _classCallCheck(this, LiteralSchema);
1509
+ _this = _callSuper(this, LiteralSchema);
1510
+ _this.value = value;
1511
+ _this.opt = opt;
1512
+ return _this;
1513
+ }
1514
+ _createClass(LiteralSchema, [{
1515
+ key: "validate",
1516
+ value: function validate(path, src) {
1517
+ if (this.opt && (src === null || src === undefined)) {
1518
+ return false;
1519
+ }
1520
+ if (typeof src !== "string") {
1521
+ return _defineProperty({}, path, [{
1522
+ message: "Expected 'string', got '".concat(_typeof(src), "'"),
1523
+ value: src
1524
+ }]);
1525
+ }
1526
+ if (src !== this.value) {
1527
+ return _defineProperty({}, path, [{
1528
+ message: "Expected literal '".concat(this.value, "', got '").concat(src, "'"),
1529
+ value: src
1530
+ }]);
1531
+ }
1532
+ return false;
1533
+ }
1534
+ }, {
1535
+ key: "assert",
1536
+ value: function assert(src) {
1537
+ if (this.opt && (src === null || src === undefined)) {
1538
+ return true;
1539
+ }
1540
+ return typeof src === "string";
1541
+ }
1542
+ }, {
1543
+ key: "nullable",
1544
+ value: function nullable() {
1545
+ return new LiteralSchema(this.value, true);
1546
+ }
1547
+ }, {
1548
+ key: "serialize",
1549
+ value: function serialize() {
1550
+ return {
1551
+ type: "literal",
1552
+ value: this.value,
1553
+ opt: this.opt
1554
+ };
1555
+ }
1556
+ }]);
1557
+ return LiteralSchema;
1558
+ }(Schema);
1559
+ var literal = function literal(value) {
1560
+ return new LiteralSchema(value);
1561
+ };
1562
+
1563
+ var UnionSchema = /*#__PURE__*/function (_Schema) {
1564
+ _inherits(UnionSchema, _Schema);
1565
+ function UnionSchema(key, items) {
1566
+ var _this;
1567
+ var opt = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
1568
+ _classCallCheck(this, UnionSchema);
1569
+ _this = _callSuper(this, UnionSchema);
1570
+ _this.key = key;
1571
+ _this.items = items;
1572
+ _this.opt = opt;
1573
+ return _this;
1574
+ }
1575
+ _createClass(UnionSchema, [{
1576
+ key: "validate",
1577
+ value: function validate(path, src) {
1578
+ var unknownSrc = src;
1579
+ var errors = false;
1580
+ if (this.opt && (unknownSrc === null || unknownSrc === undefined)) {
1581
+ // TODO: src should never be undefined
1582
+ return false;
1583
+ }
1584
+ if (!this.key) {
1585
+ return _defineProperty({}, path, [{
1586
+ message: "Missing required first argument in union"
1587
+ }]);
1588
+ }
1589
+ var key = this.key;
1590
+ if (!Array.isArray(this.items)) {
1591
+ return _defineProperty({}, path, [{
1592
+ message: "A union schema must take more than 1 schema arguments",
1593
+ fatal: true
1594
+ }]);
1595
+ }
1596
+ if (typeof key === "string") {
1597
+ // tagged union
1598
+ if (this.items.some(function (item) {
1599
+ return !(item instanceof ObjectSchema);
1600
+ })) {
1601
+ return _defineProperty({}, path, [{
1602
+ message: "Key is a string, so all schema items must be objects",
1603
+ fatal: true
1604
+ }]);
1605
+ }
1606
+ var objectSchemas = this.items;
1607
+ var serializedSchemas = objectSchemas.map(function (schema) {
1608
+ return schema.serialize();
1609
+ });
1610
+ var illegalSchemas = serializedSchemas.filter(function (schema) {
1611
+ return !(schema.type === "object") || !(schema.items[key].type === "literal");
1612
+ });
1613
+ if (illegalSchemas.length > 0) {
1614
+ return _defineProperty({}, path, [{
1615
+ message: "All schema items must be objects with a key: ".concat(key, " that is a literal schema. Found: ").concat(JSON.stringify(illegalSchemas, null, 2)),
1616
+ fatal: true
1617
+ }]);
1618
+ }
1619
+ var serializedObjectSchemas = serializedSchemas;
1620
+ var optionalLiterals = serializedObjectSchemas.filter(function (schema) {
1621
+ return schema.items[key].opt;
1622
+ });
1623
+ if (optionalLiterals.length > 1) {
1624
+ return _defineProperty({}, path, [{
1625
+ message: "Schema cannot have an optional keys: ".concat(key),
1626
+ fatal: true
1627
+ }]);
1628
+ }
1629
+ if (_typeof(unknownSrc) !== "object") {
1630
+ return _defineProperty({}, path, [{
1631
+ message: "Expected an object"
1632
+ }]);
1633
+ }
1634
+ var objectSrc = unknownSrc;
1635
+ if (objectSrc[key] === undefined) {
1636
+ return _defineProperty({}, path, [{
1637
+ message: "Missing required key: ".concat(key)
1638
+ }]);
1639
+ }
1640
+ var foundSchemaLiterals = [];
1641
+ var _iterator = result._createForOfIteratorHelper(serializedObjectSchemas),
1642
+ _step;
1643
+ try {
1644
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
1645
+ var schema = _step.value;
1646
+ var schemaKey = schema.items[key];
1647
+ if (schemaKey.type === "literal") {
1648
+ if (!foundSchemaLiterals.includes(schemaKey.value)) {
1649
+ foundSchemaLiterals.push(schemaKey.value);
1650
+ } else {
1651
+ return _defineProperty({}, path, [{
1652
+ message: "Found duplicate key in schema: ".concat(schemaKey.value),
1653
+ fatal: true
1654
+ }]);
1655
+ }
1656
+ }
1657
+ }
1658
+ } catch (err) {
1659
+ _iterator.e(err);
1660
+ } finally {
1661
+ _iterator.f();
1662
+ }
1663
+ var objectSchemaAtKey = objectSchemas.find(function (schema) {
1664
+ return !schema.items[key].validate(path, objectSrc[key]);
1665
+ });
1666
+ if (!objectSchemaAtKey) {
1667
+ var keyPath = createValPathOfItem(path, key);
1668
+ if (!keyPath) {
1669
+ throw new Error("Internal error: could not create path at ".concat(!path && typeof path === "string" ? "<empty string>" : path, " at key ").concat(key));
1670
+ }
1671
+ return _defineProperty({}, keyPath, [{
1672
+ message: "Invalid key: \"".concat(key, "\". Value was: \"").concat(objectSrc[key], "\". Valid values: ").concat(serializedObjectSchemas.map(function (schema) {
1673
+ var keySchema = schema.items[key];
1674
+ if (keySchema.type === "literal" && keySchema.value) {
1675
+ return "\"".concat(keySchema.value, "\"");
1676
+ } else {
1677
+ // should not happen here, we already checked this
1678
+ throw new Error("Expected literal schema, got ".concat(JSON.stringify(keySchema, null, 2)));
1679
+ }
1680
+ }).join(", "))
1681
+ }]);
1682
+ }
1683
+ var error = objectSchemaAtKey.validate(path, objectSrc);
1684
+ if (error) {
1685
+ return error;
1686
+ }
1687
+ } else if (key instanceof LiteralSchema) {
1688
+ if (this.items.some(function (item) {
1689
+ return !(item instanceof LiteralSchema);
1690
+ })) {
1691
+ return _defineProperty({}, path, [{
1692
+ message: "Key is a literal schema, so all schema items must be literals",
1693
+ fatal: true
1694
+ }]);
1695
+ }
1696
+ var literalItems = [key].concat(_toConsumableArray(this.items));
1697
+ if (typeof unknownSrc === "string") {
1698
+ var isMatch = literalItems.some(function (item) {
1699
+ return !item.validate(path, unknownSrc);
1700
+ });
1701
+ if (!isMatch) {
1702
+ return _defineProperty({}, path, [{
1703
+ message: "Union must match one of the following: ".concat(literalItems.map(function (item) {
1704
+ return "\"".concat(item.value, "\"");
1705
+ }).join(", "))
1706
+ }]);
1707
+ }
1708
+ }
1709
+ } else {
1710
+ return _defineProperty({}, path, [{
1711
+ message: "Expected a string or literal"
1712
+ }]);
1713
+ }
1714
+ return errors;
1715
+ }
1716
+ }, {
1717
+ key: "assert",
1718
+ value: function assert(src) {
1719
+ return true;
1720
+ }
1721
+ }, {
1722
+ key: "nullable",
1723
+ value: function nullable() {
1724
+ return new UnionSchema(this.key, this.items, true);
1725
+ }
1726
+ }, {
1727
+ key: "serialize",
1728
+ value: function serialize() {
1729
+ if (typeof this.key === "string") {
1730
+ return {
1731
+ type: "union",
1732
+ key: this.key,
1733
+ items: this.items.map(function (o) {
1734
+ return o.serialize();
1735
+ }),
1736
+ opt: this.opt
1737
+ };
1738
+ }
1739
+ return {
1740
+ type: "union",
1741
+ key: this.key.serialize(),
1742
+ items: this.items.map(function (o) {
1743
+ return o.serialize();
1744
+ }),
1745
+ opt: this.opt
1746
+ };
1747
+ }
1748
+ }]);
1749
+ return UnionSchema;
1750
+ }(Schema);
1751
+ var union = function union(key) {
1752
+ for (var _len = arguments.length, objects = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
1753
+ objects[_key - 1] = arguments[_key];
1754
+ }
1755
+ return new UnionSchema(key, objects);
1756
+ };
1757
+
1758
+ var RichTextSchema = /*#__PURE__*/function (_Schema) {
1759
+ _inherits(RichTextSchema, _Schema);
1760
+ function RichTextSchema(options) {
1761
+ var _this;
1762
+ var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1763
+ _classCallCheck(this, RichTextSchema);
1764
+ _this = _callSuper(this, RichTextSchema);
1765
+ _this.options = options;
1766
+ _this.opt = opt;
1767
+ return _this;
1768
+ }
1769
+ _createClass(RichTextSchema, [{
1770
+ key: "validate",
1771
+ value: function validate(path, src) {
1772
+ return false; //TODO
1773
+ }
1774
+ }, {
1775
+ key: "assert",
1776
+ value: function assert(src) {
1777
+ return true; // TODO
1778
+ }
1779
+ }, {
1780
+ key: "nullable",
1781
+ value: function nullable() {
1782
+ return new RichTextSchema(this.options, true);
1783
+ }
1784
+ }, {
1785
+ key: "serialize",
1786
+ value: function serialize() {
1787
+ return {
1788
+ type: "richtext",
1789
+ opt: this.opt,
1790
+ options: this.options
1791
+ };
1792
+ }
1793
+ }]);
1794
+ return RichTextSchema;
1795
+ }(Schema);
1796
+ var richtext$1 = function richtext(options) {
1797
+ return new RichTextSchema(options !== null && options !== void 0 ? options : {});
1798
+ };
1799
+
1800
+ var ImageSchema = /*#__PURE__*/function (_Schema) {
1801
+ _inherits(ImageSchema, _Schema);
1802
+ function ImageSchema(options) {
1803
+ var _this;
1804
+ var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1805
+ _classCallCheck(this, ImageSchema);
1806
+ _this = _callSuper(this, ImageSchema);
1807
+ _this.options = options;
1808
+ _this.opt = opt;
1809
+ return _this;
1810
+ }
1811
+ _createClass(ImageSchema, [{
1812
+ key: "validate",
1813
+ value: function validate(path, src) {
1814
+ if (this.opt && (src === null || src === undefined)) {
1815
+ return false;
1816
+ }
1817
+ if (src === null || src === undefined) {
1818
+ return _defineProperty({}, path, [{
1819
+ message: "Non-optional image was null or undefined.",
1820
+ value: src
1821
+ }]);
1822
+ }
1823
+ if (typeof src[FILE_REF_PROP] !== "string") {
1824
+ return _defineProperty({}, path, [{
1825
+ message: "Image did not have a file reference string. Got: ".concat(_typeof(src[FILE_REF_PROP])),
1826
+ value: src
1827
+ }]);
1828
+ }
1829
+ if (src[VAL_EXTENSION] !== "file") {
1830
+ return _defineProperty({}, path, [{
1831
+ message: "Image did not have the valid file extension type. Got: ".concat(src[VAL_EXTENSION]),
1832
+ value: src
1833
+ }]);
1834
+ }
1835
+ if (src.metadata) {
1836
+ return _defineProperty({}, path, [{
1837
+ 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).",
1838
+ // 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.
1839
+ value: src,
1840
+ fixes: ["image:replace-metadata"]
1841
+ }]);
1842
+ }
1843
+ return _defineProperty({}, path, [{
1844
+ message: "Could not validate Image metadata.",
1845
+ value: src,
1846
+ fixes: ["image:add-metadata"]
1847
+ }]);
1848
+ }
1849
+ }, {
1850
+ key: "assert",
1851
+ value: function assert(src) {
1852
+ if (this.opt && (src === null || src === undefined)) {
1853
+ return true;
1854
+ }
1855
+ return (src === null || src === void 0 ? void 0 : src[FILE_REF_PROP]) === "image" && (src === null || src === void 0 ? void 0 : src[VAL_EXTENSION]) === "file";
1856
+ }
1857
+ }, {
1858
+ key: "nullable",
1859
+ value: function nullable() {
1860
+ return new ImageSchema(this.options, true);
1861
+ }
1862
+ }, {
1863
+ key: "serialize",
1864
+ value: function serialize() {
1865
+ return {
1866
+ type: "image",
1867
+ options: this.options,
1868
+ opt: this.opt
1869
+ };
1870
+ }
1871
+ }]);
1872
+ return ImageSchema;
1873
+ }(Schema);
1874
+ var image$1 = function image(options) {
1875
+ return new ImageSchema(options);
1876
+ };
1877
+
1878
+ var RecordSchema = /*#__PURE__*/function (_Schema) {
1879
+ _inherits(RecordSchema, _Schema);
1880
+ function RecordSchema(item) {
1881
+ var _this;
1882
+ var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1883
+ _classCallCheck(this, RecordSchema);
1884
+ _this = _callSuper(this, RecordSchema);
1885
+ _this.item = item;
1886
+ _this.opt = opt;
1887
+ return _this;
1888
+ }
1889
+ _createClass(RecordSchema, [{
1890
+ key: "validate",
1891
+ value: function validate(path, src) {
1892
+ var _this2 = this;
1893
+ var error = false;
1894
+ if (this.opt && (src === null || src === undefined)) {
1895
+ return false;
1896
+ }
1897
+ if (_typeof(src) !== "object") {
1898
+ return _defineProperty({}, path, [{
1899
+ message: "Expected 'object', got '".concat(_typeof(src), "'")
1900
+ }]);
1901
+ }
1902
+ if (Array.isArray(src)) {
1903
+ return _defineProperty({}, path, [{
1904
+ message: "Expected 'object', got 'array'"
1905
+ }]);
1906
+ }
1907
+ Object.entries(src).forEach(function (_ref3) {
1908
+ var _ref4 = _slicedToArray(_ref3, 2),
1909
+ key = _ref4[0],
1910
+ elem = _ref4[1];
1911
+ var subPath = createValPathOfItem(path, key);
1912
+ if (!subPath) {
1913
+ error = _this2.appendValidationError(error, path, "Internal error: could not create path at ".concat(!path && typeof path === "string" ? "<empty string>" : path, " at key ").concat(elem),
1914
+ // Should! never happen
1915
+ src);
1916
+ } else {
1917
+ var subError = _this2.item.validate(subPath, elem);
1918
+ if (subError && error) {
1919
+ error = _objectSpread2(_objectSpread2({}, subError), error);
1920
+ } else if (subError) {
1921
+ error = subError;
1922
+ }
1923
+ }
1924
+ });
1925
+ return error;
1926
+ }
1927
+ }, {
1928
+ key: "assert",
1929
+ value: function assert(src) {
1930
+ if (this.opt && (src === null || src === undefined)) {
1931
+ return true;
1932
+ }
1933
+ if (!src) {
1934
+ return false;
1935
+ }
1936
+ for (var _i = 0, _Object$entries = Object.entries(src); _i < _Object$entries.length; _i++) {
1937
+ var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
1938
+ _item = _Object$entries$_i[1];
1939
+ if (!this.item.assert(_item)) {
1940
+ return false;
1941
+ }
1942
+ }
1943
+ return _typeof(src) === "object" && !Array.isArray(src);
1944
+ }
1945
+ }, {
1946
+ key: "nullable",
1947
+ value: function nullable() {
1948
+ return new RecordSchema(this.item, true);
1949
+ }
1950
+ }, {
1951
+ key: "serialize",
1952
+ value: function serialize() {
1953
+ return {
1954
+ type: "record",
1955
+ item: this.item.serialize(),
1956
+ opt: this.opt
1957
+ };
1958
+ }
1959
+ }]);
1960
+ return RecordSchema;
1961
+ }(Schema);
1962
+ var record = function record(schema) {
1963
+ return new RecordSchema(schema);
1964
+ };
1965
+
1966
+ function define(
1967
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1968
+ id,
1969
+ // TODO: `/${string}`
1970
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1971
+ schema,
1972
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1973
+ source) {
1974
+ return _defineProperty(_defineProperty(_defineProperty({}, GetSource, source), GetSchema$1, schema), Path$1, id);
1975
+ }
1976
+ function getSource(valModule) {
1977
+ var sourceOrExpr = valModule[GetSource];
1978
+ if (sourceOrExpr instanceof Expr) {
1979
+ throw Error("Cannot get raw source of an Expr");
1980
+ }
1981
+ var source = sourceOrExpr;
1982
+ return source;
1983
+ }
1984
+ function splitModuleFilePathAndModulePath(path) {
1985
+ var pathOfSep = path.indexOf(ModuleFilePathSep);
1986
+ if (pathOfSep === -1) {
1987
+ return [path, ""];
1988
+ }
1989
+ return [path.slice(0, pathOfSep), path.slice(pathOfSep + ModuleFilePathSep.length)];
1990
+ }
1991
+ var ModuleFilePathSep = "?p=";
1992
+ function isObjectSchema(schema) {
1993
+ return schema instanceof ObjectSchema || _typeof(schema) === "object" && "type" in schema && schema.type === "object";
1994
+ }
1995
+ function isRecordSchema(schema) {
1996
+ return schema instanceof RecordSchema || _typeof(schema) === "object" && "type" in schema && schema.type === "record";
1997
+ }
1998
+ function isArraySchema(schema) {
1999
+ return schema instanceof ArraySchema || _typeof(schema) === "object" && "type" in schema && schema.type === "array";
2000
+ }
2001
+
2002
+ // function isI18nSchema(
2003
+ // schema: Schema<SelectorSource> | SerializedSchema
2004
+ // ): schema is I18nSchema<readonly string[]> | SerializedI18nSchema {
2005
+ // return (
2006
+ // schema instanceof I18nSchema ||
2007
+ // (typeof schema === "object" && "type" in schema && schema.type === "i18n")
2008
+ // );
2009
+ // }
2010
+
2011
+ function isUnionSchema(schema) {
2012
+ return schema instanceof UnionSchema || _typeof(schema) === "object" && "type" in schema && schema.type === "union";
2013
+ }
2014
+
2015
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
2016
+ function isRichTextSchema(schema) {
2017
+ return schema instanceof RichTextSchema || _typeof(schema) === "object" && "type" in schema && schema.type === "richtext";
2018
+ }
2019
+ function isImageSchema(schema) {
2020
+ return schema instanceof ImageSchema || _typeof(schema) === "object" && "type" in schema && schema.type === "image";
2021
+ }
2022
+
2023
+ // function isOneOfSchema(
2024
+ // schema: Schema<SelectorSource> | SerializedSchema
2025
+ // ): schema is OneOfSchema<GenericSelector<SourceArray>> | SerializedOneOfSchema {
2026
+ // return (
2027
+ // schema instanceof OneOfSchema ||
2028
+ // (typeof schema === "object" && "type" in schema && schema.type === "oneOf")
2029
+ // );
2030
+ // }
2031
+
2032
+ function resolvePath(path, valModule, schema) {
2033
+ var parts = parsePath(path);
2034
+ var origParts = _toConsumableArray(parts);
2035
+ var resolvedSchema = schema;
2036
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2037
+ var resolvedSource = valModule;
2038
+ var _loop = function _loop() {
2039
+ var part = parts.shift();
2040
+ if (part === undefined) {
2041
+ throw Error("Unexpected undefined part");
2042
+ }
2043
+ if (isArraySchema(resolvedSchema)) {
2044
+ if (Number.isNaN(Number(part))) {
2045
+ throw Error("Invalid path: array schema ".concat(JSON.stringify(resolvedSchema), " must have a number as path, but got ").concat(part, ". Path: ").concat(path));
2046
+ }
2047
+ if (_typeof(resolvedSource) !== "object" && !Array.isArray(resolvedSource)) {
2048
+ throw Error("Schema type error: expected source to be type of array, but got ".concat(_typeof(resolvedSource)));
2049
+ }
2050
+ if (resolvedSource[part] === undefined) {
2051
+ var _resolvedSource;
2052
+ 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));
2053
+ }
2054
+ resolvedSource = resolvedSource[part];
2055
+ resolvedSchema = resolvedSchema.item;
2056
+ } else if (isRecordSchema(resolvedSchema)) {
2057
+ if (typeof part !== "string") {
2058
+ throw Error("Invalid path: record schema ".concat(resolvedSchema, " must have path: ").concat(part, " as string"));
2059
+ }
2060
+ if (_typeof(resolvedSource) !== "object" && !Array.isArray(resolvedSource)) {
2061
+ throw Error("Schema type error: expected source to be type of record, but got ".concat(_typeof(resolvedSource)));
2062
+ }
2063
+ if (!resolvedSource[part]) {
2064
+ throw Error("Invalid path: record source did not have key ".concat(part, " from path: ").concat(path));
2065
+ }
2066
+ resolvedSource = resolvedSource[part];
2067
+ resolvedSchema = resolvedSchema.item;
2068
+ } else if (isObjectSchema(resolvedSchema)) {
2069
+ if (_typeof(resolvedSource) !== "object") {
2070
+ throw Error("Schema type error: expected source to be type of object, but got ".concat(_typeof(resolvedSource)));
2071
+ }
2072
+ if (!resolvedSource[part]) {
2073
+ throw Error("Invalid path: object source did not have key ".concat(part, " from path: ").concat(path));
2074
+ }
2075
+ resolvedSource = resolvedSource[part];
2076
+ resolvedSchema = resolvedSchema.items[part];
2077
+ // } else if (isI18nSchema(resolvedSchema)) {
2078
+ // if (!resolvedSchema.locales.includes(part)) {
2079
+ // throw Error(
2080
+ // `Invalid path: i18n schema ${resolvedSchema} supports locales ${resolvedSchema.locales.join(
2081
+ // ", "
2082
+ // )}, but found: ${part}`
2083
+ // );
2084
+ // }
2085
+ // if (!Object.keys(resolvedSource).includes(part)) {
2086
+ // throw Error(
2087
+ // `Schema type error: expected source to be type of i18n with locale ${part}, but got ${JSON.stringify(
2088
+ // Object.keys(resolvedSource)
2089
+ // )}`
2090
+ // );
2091
+ // }
2092
+ // resolvedSource = resolvedSource[part];
2093
+ // resolvedSchema = resolvedSchema.item;
2094
+ } else if (isImageSchema(resolvedSchema)) {
2095
+ return {
2096
+ v: {
2097
+ path: origParts.slice(0, origParts.length - parts.length - 1).map(function (p) {
2098
+ return JSON.stringify(p);
2099
+ }).join("."),
2100
+ // TODO: create a function generate path from parts (not sure if this always works)
2101
+ schema: resolvedSchema,
2102
+ source: resolvedSource
2103
+ }
2104
+ };
2105
+ } else if (isUnionSchema(resolvedSchema)) {
2106
+ var _key = resolvedSchema.key;
2107
+ if (typeof _key !== "string") {
2108
+ return {
2109
+ v: {
2110
+ path: origParts.map(function (p) {
2111
+ if (!Number.isNaN(Number(p))) {
2112
+ return p;
2113
+ } else {
2114
+ return JSON.stringify(p);
2115
+ }
2116
+ }).join("."),
2117
+ // TODO: create a function generate path from parts (not sure if this always works)
2118
+ schema: resolvedSchema,
2119
+ source: resolvedSource
2120
+ }
2121
+ };
2122
+ }
2123
+ var keyValue = resolvedSource[_key];
2124
+ if (!keyValue) {
2125
+ throw Error("Invalid path: union source ".concat(resolvedSchema, " did not have required key ").concat(_key, " in path: ").concat(path));
2126
+ }
2127
+ var schemaOfUnionKey = resolvedSchema.items.find(
2128
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2129
+ function (child) {
2130
+ var _child$items;
2131
+ return (child === null || child === void 0 || (_child$items = child.items) === null || _child$items === void 0 || (_child$items = _child$items[_key]) === null || _child$items === void 0 ? void 0 : _child$items.value) === keyValue;
2132
+ });
2133
+ if (!schemaOfUnionKey) {
2134
+ throw Error("Invalid path: union schema ".concat(resolvedSchema, " did not have a child object with ").concat(_key, " of value ").concat(keyValue, " in path: ").concat(path));
2135
+ }
2136
+ resolvedSchema = schemaOfUnionKey.items[part];
2137
+ resolvedSource = resolvedSource[part];
2138
+ } else if (isRichTextSchema(resolvedSchema)) {
2139
+ return {
2140
+ v: {
2141
+ path: origParts.slice(0, origParts.length - parts.length - 1).map(function (p) {
2142
+ return JSON.stringify(p);
2143
+ }).join("."),
2144
+ // TODO: create a function generate path from parts (not sure if this always works)
2145
+ schema: resolvedSchema,
2146
+ source: resolvedSource
2147
+ }
2148
+ };
2149
+ } else {
2150
+ throw Error("Invalid path: ".concat(part, " resolved to an unexpected schema ").concat(JSON.stringify(resolvedSchema)));
2151
+ }
2152
+ },
2153
+ _ret;
2154
+ while (parts.length > 0) {
2155
+ _ret = _loop();
2156
+ if (_ret) return _ret.v;
2157
+ }
2158
+ if (parts.length > 0) {
2159
+ throw Error("Invalid path: ".concat(parts.join("."), " is not a valid path"));
2160
+ }
2161
+ return {
2162
+ path: origParts.map(function (p) {
2163
+ if (!Number.isNaN(Number(p))) {
2164
+ return p;
2165
+ } else {
2166
+ return JSON.stringify(p);
2167
+ }
2168
+ }).join("."),
2169
+ // TODO: create a function generate path from parts (not sure if this always works)
2170
+ schema: resolvedSchema,
2171
+ source: resolvedSource
2172
+ };
2173
+ }
2174
+ function parsePath(input) {
2175
+ var result = [];
2176
+ var i = 0;
2177
+ while (i < input.length) {
2178
+ var part = "";
2179
+ if (input[i] === '"') {
2180
+ // Parse a quoted string
2181
+ i++;
2182
+ while (i < input.length && input[i] !== '"') {
2183
+ if (input[i] === "\\" && input[i + 1] === '"') {
2184
+ // Handle escaped double quotes
2185
+ part += '"';
2186
+ i++;
2187
+ } else {
2188
+ part += input[i];
2189
+ }
2190
+ i++;
2191
+ }
2192
+ if (input[i] !== '"') {
2193
+ var _input$i;
2194
+ throw new Error("Invalid input (".concat(JSON.stringify(input), "): Missing closing double quote: ").concat((_input$i = input[i]) !== null && _input$i !== void 0 ? _input$i : "at end of string", " (char: ").concat(i, "; length: ").concat(input.length, ")"));
2195
+ }
2196
+ } else {
2197
+ // Parse a regular string
2198
+ while (i < input.length && input[i] !== ".") {
2199
+ part += input[i];
2200
+ i++;
2201
+ }
2202
+ }
2203
+ if (part !== "") {
2204
+ result.push(part);
2205
+ }
2206
+ i++;
2207
+ }
2208
+ return result;
2209
+ }
2210
+
2211
+ var NumberSchema = /*#__PURE__*/function (_Schema) {
2212
+ _inherits(NumberSchema, _Schema);
2213
+ function NumberSchema(options) {
2214
+ var _this;
2215
+ var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
2216
+ _classCallCheck(this, NumberSchema);
2217
+ _this = _callSuper(this, NumberSchema);
2218
+ _this.options = options;
2219
+ _this.opt = opt;
2220
+ return _this;
2221
+ }
2222
+ _createClass(NumberSchema, [{
2223
+ key: "validate",
2224
+ value: function validate(path, src) {
2225
+ if (this.opt && (src === null || src === undefined)) {
2226
+ return false;
2227
+ }
2228
+ if (typeof src !== "number") {
2229
+ return _defineProperty({}, path, [{
2230
+ message: "Expected 'number', got '".concat(_typeof(src), "'"),
2231
+ value: src
2232
+ }]);
2233
+ }
2234
+ return false;
2235
+ }
2236
+ }, {
2237
+ key: "assert",
2238
+ value: function assert(src) {
2239
+ if (this.opt && (src === null || src === undefined)) {
2240
+ return true;
2241
+ }
2242
+ return typeof src === "number";
2243
+ }
2244
+ }, {
2245
+ key: "nullable",
2246
+ value: function nullable() {
2247
+ return new NumberSchema(this.options, true);
2248
+ }
2249
+ }, {
2250
+ key: "serialize",
2251
+ value: function serialize() {
2252
+ return {
2253
+ type: "number",
2254
+ options: this.options,
2255
+ opt: this.opt
2256
+ };
2257
+ }
2258
+ }]);
2259
+ return NumberSchema;
2260
+ }(Schema);
2261
+ var number = function number(options) {
2262
+ return new NumberSchema(options);
2263
+ };
2264
+
2265
+ var StringSchema = /*#__PURE__*/function (_Schema) {
2266
+ _inherits(StringSchema, _Schema);
2267
+ function StringSchema(options) {
2268
+ var _this;
2269
+ var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
2270
+ var isRaw = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
2271
+ _classCallCheck(this, StringSchema);
2272
+ _this = _callSuper(this, StringSchema);
2273
+ _this.options = options;
2274
+ _this.opt = opt;
2275
+ _this.isRaw = isRaw;
2276
+ return _this;
2277
+ }
2278
+ _createClass(StringSchema, [{
2279
+ key: "min",
2280
+ value: function min(minLength) {
2281
+ return new StringSchema(_objectSpread2(_objectSpread2({}, this.options), {}, {
2282
+ minLength: minLength
2283
+ }), this.opt, this.isRaw);
2284
+ }
2285
+ }, {
2286
+ key: "max",
2287
+ value: function max(maxLength) {
2288
+ return new StringSchema(_objectSpread2(_objectSpread2({}, this.options), {}, {
2289
+ maxLength: maxLength
2290
+ }), this.opt, this.isRaw);
2291
+ }
2292
+ }, {
2293
+ key: "regexp",
2294
+ value: function regexp(_regexp) {
2295
+ return new StringSchema(_objectSpread2(_objectSpread2({}, this.options), {}, {
2296
+ regexp: _regexp
2297
+ }), this.opt, this.isRaw);
2298
+ }
2299
+ }, {
2300
+ key: "validate",
2301
+ value: function validate(path, src) {
2302
+ var _this$options, _this$options2, _this$options3;
2303
+ if (this.opt && (src === null || src === undefined)) {
2304
+ return false;
2305
+ }
2306
+ if (typeof src !== "string") {
2307
+ return _defineProperty({}, path, [{
2308
+ message: "Expected 'string', got '".concat(_typeof(src), "'"),
2309
+ value: src
2310
+ }]);
2311
+ }
2312
+ var errors = [];
2313
+ if ((_this$options = this.options) !== null && _this$options !== void 0 && _this$options.maxLength && src.length > this.options.maxLength) {
2314
+ errors.push({
2315
+ message: "Expected string to be at most ".concat(this.options.maxLength, " characters long, got ").concat(src.length),
2316
+ value: src
2317
+ });
2318
+ }
2319
+ if ((_this$options2 = this.options) !== null && _this$options2 !== void 0 && _this$options2.minLength && src.length < this.options.minLength) {
2320
+ errors.push({
2321
+ message: "Expected string to be at least ".concat(this.options.minLength, " characters long, got ").concat(src.length),
2322
+ value: src
2323
+ });
2324
+ }
2325
+ if ((_this$options3 = this.options) !== null && _this$options3 !== void 0 && _this$options3.regexp && !this.options.regexp.test(src)) {
2326
+ errors.push({
2327
+ message: "Expected string to match reg exp: ".concat(this.options.regexp.toString(), ", got '").concat(src, "'"),
2328
+ value: src
2329
+ });
2330
+ }
2331
+ if (errors.length > 0) {
2332
+ return _defineProperty({}, path, errors);
2333
+ }
2334
+ return false;
2335
+ }
2336
+ }, {
2337
+ key: "assert",
2338
+ value: function assert(src) {
2339
+ if (this.opt && (src === null || src === undefined)) {
2340
+ return true;
2341
+ }
2342
+ return typeof src === "string";
2343
+ }
2344
+ }, {
2345
+ key: "nullable",
2346
+ value: function nullable() {
2347
+ return new StringSchema(this.options, true, this.isRaw);
2348
+ }
2349
+ }, {
2350
+ key: "raw",
2351
+ value: function raw() {
2352
+ return new StringSchema(this.options, this.opt, true);
2353
+ }
2354
+ }, {
2355
+ key: "serialize",
2356
+ value: function serialize() {
2357
+ var _this$options4, _this$options5, _this$options6;
2358
+ return {
2359
+ type: "string",
2360
+ options: {
2361
+ maxLength: (_this$options4 = this.options) === null || _this$options4 === void 0 ? void 0 : _this$options4.maxLength,
2362
+ minLength: (_this$options5 = this.options) === null || _this$options5 === void 0 ? void 0 : _this$options5.minLength,
2363
+ regexp: ((_this$options6 = this.options) === null || _this$options6 === void 0 ? void 0 : _this$options6.regexp) && {
2364
+ source: this.options.regexp.source,
2365
+ flags: this.options.regexp.flags
2366
+ }
2367
+ },
2368
+ opt: this.opt,
2369
+ raw: this.isRaw
2370
+ };
2371
+ }
2372
+ }]);
2373
+ return StringSchema;
2374
+ }(Schema);
2375
+ var string = function string(options) {
2376
+ return new StringSchema(options);
2377
+ };
2378
+
2379
+ var BooleanSchema = /*#__PURE__*/function (_Schema) {
2380
+ _inherits(BooleanSchema, _Schema);
2381
+ function BooleanSchema() {
2382
+ var _this;
2383
+ var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
2384
+ _classCallCheck(this, BooleanSchema);
2385
+ _this = _callSuper(this, BooleanSchema);
2386
+ _this.opt = opt;
2387
+ return _this;
2388
+ }
2389
+ _createClass(BooleanSchema, [{
2390
+ key: "validate",
2391
+ value: function validate(path, src) {
2392
+ if (this.opt && (src === null || src === undefined)) {
2393
+ return false;
2394
+ }
2395
+ if (typeof src !== "boolean") {
2396
+ return _defineProperty({}, path, [{
2397
+ message: "Expected 'boolean', got '".concat(_typeof(src), "'"),
2398
+ value: src
2399
+ }]);
2400
+ }
2401
+ return false;
2402
+ }
2403
+ }, {
2404
+ key: "assert",
2405
+ value: function assert(src) {
2406
+ if (this.opt && (src === null || src === undefined)) {
2407
+ return true;
2408
+ }
2409
+ return typeof src === "boolean";
2410
+ }
2411
+ }, {
2412
+ key: "nullable",
2413
+ value: function nullable() {
2414
+ return new BooleanSchema(true);
2415
+ }
2416
+ }, {
2417
+ key: "serialize",
2418
+ value: function serialize() {
2419
+ return {
2420
+ type: "boolean",
2421
+ opt: this.opt
2422
+ };
2423
+ }
2424
+ }]);
2425
+ return BooleanSchema;
2426
+ }(Schema);
2427
+ var _boolean = function _boolean() {
2428
+ return new BooleanSchema();
2429
+ };
2430
+
2431
+ var KeyOfSchema = /*#__PURE__*/function (_Schema) {
2432
+ _inherits(KeyOfSchema, _Schema);
2433
+ function KeyOfSchema(schema, sourcePath) {
2434
+ var _this;
2435
+ var opt = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
2436
+ _classCallCheck(this, KeyOfSchema);
2437
+ _this = _callSuper(this, KeyOfSchema);
2438
+ _this.schema = schema;
2439
+ _this.sourcePath = sourcePath;
2440
+ _this.opt = opt;
2441
+ return _this;
2442
+ }
2443
+ _createClass(KeyOfSchema, [{
2444
+ key: "validate",
2445
+ value: function validate(path, src) {
2446
+ if (this.opt && (src === null || src === undefined)) {
2447
+ return false;
2448
+ }
2449
+ if (!this.schema) {
2450
+ return _defineProperty({}, path, [{
2451
+ message: "Schema not found for module. keyOf must be used with a Val Module"
2452
+ }]);
2453
+ }
2454
+ var serializedSchema = this.schema;
2455
+ if (!(serializedSchema.type === "array" || serializedSchema.type === "object" || serializedSchema.type === "record")) {
2456
+ return _defineProperty({}, path, [{
2457
+ message: "Schema in keyOf must be an 'array', 'object' or 'record'. Found '".concat(serializedSchema.type, "'")
2458
+ }]);
2459
+ }
2460
+ if (serializedSchema.opt && (src === null || src === undefined)) {
2461
+ return false;
2462
+ }
2463
+ if (serializedSchema.type === "array" && typeof src !== "number") {
2464
+ return _defineProperty({}, path, [{
2465
+ message: "Type of value in keyof (array) must be 'number'"
2466
+ }]);
2467
+ }
2468
+ if (serializedSchema.type === "record" && typeof src !== "string") {
2469
+ return _defineProperty({}, path, [{
2470
+ message: "Type of value in keyof (record) must be 'string'"
2471
+ }]);
2472
+ }
2473
+ if (serializedSchema.type === "object") {
2474
+ var keys = Object.keys(serializedSchema.items);
2475
+ if (!keys.includes(src)) {
2476
+ return _defineProperty({}, path, [{
2477
+ message: "Value of keyOf (object) must be: ".concat(keys.join(", "), ". Found: ").concat(src)
2478
+ }]);
2479
+ }
2480
+ }
2481
+ return false;
2482
+ }
2483
+ }, {
2484
+ key: "assert",
2485
+ value: function assert(src) {
2486
+ if (this.opt && (src === null || src === undefined)) {
2487
+ return true;
2488
+ }
2489
+ var schema = this.schema;
2490
+ if (!schema) {
2491
+ return false;
2492
+ }
2493
+ var serializedSchema = schema;
2494
+ if (!(serializedSchema.type === "array" || serializedSchema.type === "object" || serializedSchema.type === "record")) {
2495
+ return false;
2496
+ }
2497
+ if (serializedSchema.opt && (src === null || src === undefined)) {
2498
+ return true;
2499
+ }
2500
+ if (serializedSchema.type === "array" && typeof src !== "number") {
2501
+ return false;
2502
+ }
2503
+ if (serializedSchema.type === "record" && typeof src !== "string") {
2504
+ return false;
2505
+ }
2506
+ if (serializedSchema.type === "object") {
2507
+ var keys = Object.keys(serializedSchema.items);
2508
+ if (!keys.includes(src)) {
2509
+ return false;
2510
+ }
2511
+ }
2512
+ return true;
2513
+ }
2514
+ }, {
2515
+ key: "nullable",
2516
+ value: function nullable() {
2517
+ return new KeyOfSchema(this.schema, this.sourcePath, true);
2518
+ }
2519
+ }, {
2520
+ key: "serialize",
2521
+ value: function serialize() {
2522
+ var path = this.sourcePath;
2523
+ if (!path) {
2524
+ throw new Error("Cannot serialize keyOf schema with empty selector. TIP: keyOf must be used with a Val Module.");
2525
+ }
2526
+ var serializedSchema = this.schema;
2527
+ if (!serializedSchema) {
2528
+ throw new Error("Cannot serialize keyOf schema with empty selector.");
2529
+ }
2530
+ var values;
2531
+ switch (serializedSchema.type) {
2532
+ case "array":
2533
+ values = "number";
2534
+ break;
2535
+ case "record":
2536
+ values = "string";
2537
+ break;
2538
+ case "object":
2539
+ values = Object.keys(serializedSchema.items);
2540
+ break;
2541
+ default:
2542
+ throw new Error("Cannot serialize keyOf schema with selector of type '".concat(serializedSchema.type, "'. keyOf must be used with a Val Module."));
2543
+ }
2544
+ return {
2545
+ type: "keyOf",
2546
+ path: path,
2547
+ schema: serializedSchema,
2548
+ opt: this.opt,
2549
+ values: values
2550
+ };
2551
+ }
2552
+ }]);
2553
+ return KeyOfSchema;
2554
+ }(Schema);
2555
+ var keyOf = function keyOf(valModule) {
2556
+ var _valModule$GetSchema;
2557
+ return new KeyOfSchema(valModule === null || valModule === void 0 || (_valModule$GetSchema = valModule[GetSchema$1]) === null || _valModule$GetSchema === void 0 ? void 0 : _valModule$GetSchema.serialize(), getValPath(valModule));
2558
+ };
2559
+
2560
+ // import type { F } from "ts-toolbelt";
2561
+ // import { i18n, I18n } from "./schema/future/i18n";
2562
+ // import { oneOf } from "./schema/future/oneOf";
2563
+
2564
+ // export type InitSchemaLocalized<Locales extends readonly string[]> = {
2565
+ // readonly i18n: I18n<Locales>;
2566
+ // };
2567
+ function initSchema() {
2568
+ // locales: F.Narrow<Locales>
2569
+ return {
2570
+ string: string,
2571
+ "boolean": _boolean,
2572
+ array: array,
2573
+ object: object,
2574
+ number: number,
2575
+ union: union,
2576
+ // oneOf,
2577
+ richtext: richtext$1,
2578
+ image: image$1,
2579
+ literal: literal,
2580
+ keyOf: keyOf,
2581
+ record: record,
2582
+ file: file
2583
+ // i18n: i18n(locales),
2584
+ };
2585
+ }
2586
+
2587
+ // Classes
2588
+
2589
+ /// Paragraph
2590
+
2591
+ /// Break
2592
+
2593
+ /// Span
2594
+
2595
+ /// Image
2596
+
2597
+ /// Link
2598
+
2599
+ /// List
2600
+
2601
+ /// Heading
2602
+
2603
+ /// Root and nodes
2604
+
2605
+ /// Main types
2606
+
2607
+ /**
2608
+ * RichTextSource is defined in ValModules
2609
+ **/
2610
+
2611
+ /**
2612
+ * RichText is accessible by users (after conversion via useVal / fetchVal)
2613
+ * Internally it is a Selector
2614
+ **/
2615
+
2616
+ function richtext(templateStrings) {
2617
+ for (var _len = arguments.length, nodes = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
2618
+ nodes[_key - 1] = arguments[_key];
2619
+ }
2620
+ return _defineProperty(_defineProperty(_defineProperty({}, VAL_EXTENSION, "richtext"), "templateStrings", templateStrings), "exprs", nodes);
2621
+ }
2622
+ var RT_IMAGE_TAG = "rt_image";
2623
+ function image(ref, metadata) {
2624
+ return _defineProperty(_defineProperty(_defineProperty(_defineProperty({}, FILE_REF_PROP, ref), FILE_REF_SUBTYPE_TAG, RT_IMAGE_TAG), VAL_EXTENSION, "file"), "metadata", metadata);
2625
+ }
2626
+
2627
+ function link(text, _ref) {
2628
+ var href = _ref.href;
2629
+ return _defineProperty(_defineProperty(_defineProperty({}, VAL_EXTENSION, "link"), "href", href), "children", [text]);
2630
+ }
2631
+
2632
+ /* eslint-disable @typescript-eslint/ban-types */
2633
+ // import { i18n, I18n } from "./source/future/i18n";
2634
+ // import { remote } from "./source/future/remote";
2635
+
2636
+ // type NarrowStrings<A> =
2637
+ // | (A extends [] ? [] : never)
2638
+ // | (A extends string ? A : never)
2639
+ // | {
2640
+ // [K in keyof A]: NarrowStrings<A[K]>;
2641
+ // };
2642
+
2643
+ // TODO: Rename to createValSystem (only to be used by internal things), we can then export * from '@valbuild/core' in the next package then.
2644
+ var initVal = function initVal(config) {
2645
+ // const locales = options?.locales;
2646
+ var s = initSchema();
2647
+ // if (locales?.required) {
2648
+ // console.error("Locales / i18n currently not implemented");
2649
+ // return {
2650
+ // val: {
2651
+ // content,
2652
+ // i18n,
2653
+ // remote,
2654
+ // getPath,
2655
+ // file,
2656
+ // richtext,
2657
+ // },
2658
+ // s,
2659
+ // config: {},
2660
+ // // eslint-disable-next-line @typescript-eslint/no-explicit-any
2661
+ // } as any;
2662
+ // }
2663
+ return {
2664
+ val: {
2665
+ getPath: getValPath
2666
+ },
2667
+ c: {
2668
+ define: define,
2669
+ // remote,
2670
+ file: file$1,
2671
+ richtext: richtext,
2672
+ rt: {
2673
+ image: image,
2674
+ link: link
2675
+ }
2676
+ },
2677
+ s: s,
2678
+ config: config
2679
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2680
+ };
2681
+ };
2682
+
2683
+ /**
2684
+ * Define the set of modules that can be edited using the Val UI.
2685
+ *
2686
+ * @example
2687
+ * import { modules } from "@valbuild/next";
2688
+ * import { config } from "./val.config";
2689
+ *
2690
+ * export default modules(config, [
2691
+ * { def: () => import("./app/page.val.ts") },
2692
+ * { def: () => import("./app/another/page.val.ts") },
2693
+ * ]);
2694
+ */
2695
+ function modules(config, modules) {
2696
+ return {
2697
+ config: config,
2698
+ modules: modules
2699
+ };
2700
+ }
2701
+
2702
+ var PatchError = /*#__PURE__*/_createClass(function PatchError(message) {
2703
+ _classCallCheck(this, PatchError);
2704
+ this.message = message;
2705
+ });
2706
+
2707
+ /**
2708
+ * NOTE: MAY mutate the input document.
2709
+ */
2710
+
2711
+ function derefPath(path) {
2712
+ var dereffedPath = [];
2713
+ var referencedPath = null;
2714
+ var _iterator = result._createForOfIteratorHelper(path),
2715
+ _step;
2716
+ try {
2717
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
2718
+ var segment = _step.value;
2719
+ if (segment.startsWith("$")) {
2720
+ var dereffedSegment = segment.slice(1);
2721
+ dereffedPath.push(dereffedSegment);
2722
+ referencedPath = [];
2723
+ var _iterator2 = result._createForOfIteratorHelper(path.slice(dereffedPath.length)),
2724
+ _step2;
2725
+ try {
2726
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
2727
+ var _segment = _step2.value;
2728
+ if (_segment.startsWith("$")) {
2729
+ return result.err(new PatchError("Cannot reference within reference: ".concat(_segment, ". Path: ").concat(path.join("/"))));
2730
+ }
2731
+ referencedPath.push(_segment);
2732
+ }
2733
+ } catch (err) {
2734
+ _iterator2.e(err);
2735
+ } finally {
2736
+ _iterator2.f();
2737
+ }
2738
+ break;
2739
+ } else {
2740
+ dereffedPath.push(segment);
2741
+ }
2742
+ }
2743
+ } catch (err) {
2744
+ _iterator.e(err);
2745
+ } finally {
2746
+ _iterator.f();
2747
+ }
2748
+ return result.ok([dereffedPath, referencedPath]);
2749
+ }
2750
+ function derefPatch(patch, document, ops) {
2751
+ var fileUpdates = {};
2752
+ var dereferencedPatch = [];
2753
+ var _iterator3 = result._createForOfIteratorHelper(patch),
2754
+ _step3;
2755
+ try {
2756
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
2757
+ var op = _step3.value;
2758
+ if (op.op === "replace") {
2759
+ var maybeDerefRes = derefPath(op.path);
2760
+ if (result.isErr(maybeDerefRes)) {
2761
+ return maybeDerefRes;
2762
+ }
2763
+ var _maybeDerefRes$value = _slicedToArray(maybeDerefRes.value, 2),
2764
+ dereffedPath = _maybeDerefRes$value[0],
2765
+ referencedPath = _maybeDerefRes$value[1];
2766
+ if (referencedPath) {
2767
+ var maybeValue = ops.get(document, dereffedPath);
2768
+ if (result.isOk(maybeValue)) {
2769
+ var value = maybeValue.value;
2770
+ if (isFile(value)) {
2771
+ if (referencedPath.length > 0) {
2772
+ return result.err(new PatchError("Cannot sub-reference file reference at path: ".concat(dereffedPath.join("/"))));
2773
+ }
2774
+ if (typeof op.value !== "string") {
2775
+ return result.err(new PatchError("Expected base64 encoded string value for file reference, got ".concat(JSON.stringify(op.value))));
2776
+ }
2777
+ fileUpdates[value[FILE_REF_PROP]] = op.value;
2778
+ // } else if (isRemote(value)) {
2779
+ // if (!remotePatches[value[REMOTE_REF_PROP]]) {
2780
+ // remotePatches[value[REMOTE_REF_PROP]] = [];
2781
+ // }
2782
+ // remotePatches[value[REMOTE_REF_PROP]].push({
2783
+ // op: "replace",
2784
+ // path: referencedPath,
2785
+ // value: op.value,
2786
+ // });
2787
+ } else {
2788
+ return result.err(new PatchError("Unknown reference: ".concat(JSON.stringify(op), " at path: ").concat(dereffedPath.join("/"))));
2789
+ }
2790
+ } else {
2791
+ return maybeValue;
2792
+ }
2793
+ } else {
2794
+ dereferencedPatch.push(op);
2795
+ }
2796
+ } else if (op.op === "file") {
2797
+ if (!op.filePath.startsWith("/public")) {
2798
+ return result.err(new PatchError("Path must start with /public"));
2799
+ }
2800
+ if (typeof op.value !== "string") {
2801
+ return result.err(new PatchError("File operation must have a value that is typeof string. Found: ".concat(_typeof(op.value))));
2802
+ }
2803
+ fileUpdates[op.filePath] = op.value;
2804
+ } else {
2805
+ var _maybeDerefRes = derefPath(op.path);
2806
+ if (result.isErr(_maybeDerefRes)) {
2807
+ return _maybeDerefRes;
2808
+ }
2809
+ var _maybeDerefRes$value2 = _slicedToArray(_maybeDerefRes.value, 2),
2810
+ _referencedPath = _maybeDerefRes$value2[1];
2811
+ if (_referencedPath) {
2812
+ throw new Error("Unimplemented operation: ".concat(JSON.stringify(op)));
2813
+ }
2814
+ dereferencedPatch.push(op);
2815
+ }
2816
+ }
2817
+ } catch (err) {
2818
+ _iterator3.e(err);
2819
+ } finally {
2820
+ _iterator3.f();
2821
+ }
2822
+ return result.ok({
2823
+ fileUpdates: fileUpdates,
2824
+ dereferencedPatch: dereferencedPatch
2825
+ });
2826
+ }
2827
+
2828
+ function getVal(selector) {
2829
+ return newValProxy(serializedValOfSelectorSource(selector));
2830
+ }
2831
+
2832
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2833
+ function isArrayOrArraySelector(child) {
2834
+ if (isSelector$1(child)) {
2835
+ return _typeof(child[GetSource]) === "object" && child[GetSource] !== null && Array.isArray(child[GetSource]);
2836
+ }
2837
+ return Array.isArray(child);
2838
+ }
2839
+
2840
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2841
+ function isObjectOrObjectSelector(child) {
2842
+ if (isSelector$1(child)) {
2843
+ return _typeof(child[GetSource]) === "object" && child[GetSource] !== null && !Array.isArray(child[GetSource]);
2844
+ }
2845
+ return _typeof(child) === "object";
2846
+ }
2847
+ function serializedValOfSelectorSource(selector) {
2848
+ var wrappedSelector = newSelectorProxy$1(selector); // NOTE: we do this if call-site uses a literal with selectors inside
2849
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2850
+ function rec(child) {
2851
+ var isArray = isArrayOrArraySelector(child);
2852
+ var isObject = isObjectOrObjectSelector(child);
2853
+ if (isArray) {
2854
+ var array = GetSource in child ? child[GetSource] : child;
2855
+ var valPath = Path$1 in child ? child[Path$1] : undefined;
2856
+ return {
2857
+ val: array.map(function (item, i) {
2858
+ return rec(isSelector$1(item) // NOTE: We do this since selectors currently do not create selectors of items unless specifically required.
2859
+ ? item : newSelectorProxy$1(item, createValPathOfItem(valPath, i)));
2860
+ }),
2861
+ valPath: valPath
2862
+ };
2863
+ } else if (isObject) {
2864
+ var obj = GetSource in child ? child[GetSource] : child;
2865
+ var _valPath = Path$1 in child ? child[Path$1] : undefined;
2866
+ return {
2867
+ val: obj !== null && Object.fromEntries(Object.entries(obj).map(function (_ref) {
2868
+ var _ref2 = _slicedToArray(_ref, 2),
2869
+ key = _ref2[0],
2870
+ value = _ref2[1];
2871
+ return [key, rec(isSelector$1(value) // NOTE: We do this since selectors currently do not create selectors of items unless specifically required.
2872
+ ? value : newSelectorProxy$1(value, createValPathOfItem(_valPath, key)))];
2873
+ })),
2874
+ valPath: _valPath
2875
+ };
2876
+ } else if (isSelector$1(child)) {
2877
+ return {
2878
+ val: rec(child[GetSource]),
2879
+ valPath: child[Path$1]
2880
+ };
2881
+ } else {
2882
+ return child;
2883
+ }
2884
+ }
2885
+ return rec(wrappedSelector);
2886
+ }
2887
+ function strip(value) {
2888
+ var val = isSerializedVal(value) ? value.val : value;
2889
+ switch (_typeof(val)) {
2890
+ case "function":
2891
+ case "symbol":
2892
+ throw Error("Invalid val type: ".concat(_typeof(val)));
2893
+ case "object":
2894
+ if (val === null) {
2895
+ return null;
2896
+ } else if (Array.isArray(val)) {
2897
+ return val.map(strip);
2898
+ } else {
2899
+ return Object.fromEntries(Object.entries(val).map(function (_ref3) {
2900
+ var _ref4 = _slicedToArray(_ref3, 2),
2901
+ key = _ref4[0],
2902
+ value = _ref4[1];
2903
+ return [key, value && strip(value)];
2904
+ }));
2905
+ }
2906
+ // intentional fallthrough
2907
+ // eslint-disable-next-line no-fallthrough
2908
+ default:
2909
+ return val;
2910
+ }
2911
+ }
2912
+ function newValProxy(val) {
2913
+ var source = val.val;
2914
+ switch (_typeof(source)) {
2915
+ case "function":
2916
+ case "symbol":
2917
+ throw Error("Invalid val type: ".concat(_typeof(source)));
2918
+ case "object":
2919
+ if (source !== null) {
2920
+ // Handles both objects and arrays!
2921
+ return new Proxy(source, {
2922
+ has: function has(target, prop) {
2923
+ if (prop === "val") {
2924
+ return true;
2925
+ }
2926
+ if (prop === Path$1) {
2927
+ return true;
2928
+ }
2929
+ return hasOwn(target, prop);
2930
+ },
2931
+ get: function get(target, prop) {
2932
+ if (prop === Path$1) {
2933
+ return val.valPath;
2934
+ }
2935
+ if (prop === "val") {
2936
+ return strip(val);
2937
+ }
2938
+ if (Array.isArray(target) && prop === "length") {
2939
+ return target.length;
2940
+ }
2941
+ if (hasOwn(source, prop)) {
2942
+ var _Reflect$get$valPath, _Reflect$get;
2943
+ return newValProxy({
2944
+ val: Reflect.get(target, prop).val,
2945
+ valPath: (_Reflect$get$valPath = (_Reflect$get = Reflect.get(target, prop)) === null || _Reflect$get === void 0 ? void 0 : _Reflect$get.valPath) !== null && _Reflect$get$valPath !== void 0 ? _Reflect$get$valPath : createValPathOfItem(val.valPath, Array.isArray(target) ? Number(prop) : prop)
2946
+ });
2947
+ }
2948
+ return Reflect.get(target, prop);
2949
+ }
2950
+ });
2951
+ }
2952
+ // intentional fallthrough
2953
+ // eslint-disable-next-line no-fallthrough
2954
+ default:
2955
+ return _defineProperty(_defineProperty({}, Path$1, val.valPath), "val", val.val);
2956
+ }
2957
+ }
2958
+ function hasOwn(obj, prop) {
2959
+ return Object.prototype.hasOwnProperty.call(obj, prop);
2960
+ }
2961
+
2962
+ /**
2963
+ * From: https://github.com/kawanet/sha256-uint8array/commit/a035f83824c319d01ca1e7559fdcf1632c0cd6c4
2964
+ *
2965
+ * LICENSE:
2966
+ *
2967
+ * MIT License
2968
+ * Copyright (c) 2020-2023 Yusuke Kawasaki
2969
+ *
2970
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
2971
+ * of this software and associated documentation files (the "Software"), to deal
2972
+ * in the Software without restriction, including without limitation the rights
2973
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
2974
+ * copies of the Software, and to permit persons to whom the Software is
2975
+ * furnished to do so, subject to the following conditions:
2976
+ *
2977
+ * The above copyright notice and this permission notice shall be included in all
2978
+ * copies or substantial portions of the Software.
2979
+ *
2980
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
2981
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2982
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
2983
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2984
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2985
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2986
+ * SOFTWARE.
2987
+ *
2988
+ * sha256-uint8array.ts
2989
+ */
2990
+
2991
+ // first 32 bits of the fractional parts of the cube roots of the first 64 primes 2..311
2992
+ var K = [0x428a2f98 | 0, 0x71374491 | 0, 0xb5c0fbcf | 0, 0xe9b5dba5 | 0, 0x3956c25b | 0, 0x59f111f1 | 0, 0x923f82a4 | 0, 0xab1c5ed5 | 0, 0xd807aa98 | 0, 0x12835b01 | 0, 0x243185be | 0, 0x550c7dc3 | 0, 0x72be5d74 | 0, 0x80deb1fe | 0, 0x9bdc06a7 | 0, 0xc19bf174 | 0, 0xe49b69c1 | 0, 0xefbe4786 | 0, 0x0fc19dc6 | 0, 0x240ca1cc | 0, 0x2de92c6f | 0, 0x4a7484aa | 0, 0x5cb0a9dc | 0, 0x76f988da | 0, 0x983e5152 | 0, 0xa831c66d | 0, 0xb00327c8 | 0, 0xbf597fc7 | 0, 0xc6e00bf3 | 0, 0xd5a79147 | 0, 0x06ca6351 | 0, 0x14292967 | 0, 0x27b70a85 | 0, 0x2e1b2138 | 0, 0x4d2c6dfc | 0, 0x53380d13 | 0, 0x650a7354 | 0, 0x766a0abb | 0, 0x81c2c92e | 0, 0x92722c85 | 0, 0xa2bfe8a1 | 0, 0xa81a664b | 0, 0xc24b8b70 | 0, 0xc76c51a3 | 0, 0xd192e819 | 0, 0xd6990624 | 0, 0xf40e3585 | 0, 0x106aa070 | 0, 0x19a4c116 | 0, 0x1e376c08 | 0, 0x2748774c | 0, 0x34b0bcb5 | 0, 0x391c0cb3 | 0, 0x4ed8aa4a | 0, 0x5b9cca4f | 0, 0x682e6ff3 | 0, 0x748f82ee | 0, 0x78a5636f | 0, 0x84c87814 | 0, 0x8cc70208 | 0, 0x90befffa | 0, 0xa4506ceb | 0, 0xbef9a3f7 | 0, 0xc67178f2 | 0];
2993
+ var N = /*#__PURE__*/function (N) {
2994
+ N[N["inputBytes"] = 64] = "inputBytes";
2995
+ N[N["inputWords"] = 16] = "inputWords";
2996
+ N[N["highIndex"] = 14] = "highIndex";
2997
+ N[N["lowIndex"] = 15] = "lowIndex";
2998
+ N[N["workWords"] = 64] = "workWords";
2999
+ N[N["allocBytes"] = 80] = "allocBytes";
3000
+ N[N["allocWords"] = 20] = "allocWords";
3001
+ N[N["allocTotal"] = 8000] = "allocTotal";
3002
+ return N;
3003
+ }(N || {});
3004
+ var algorithms = {
3005
+ sha256: 1
3006
+ };
3007
+ function createHash(algorithm) {
3008
+ if (algorithm && !algorithms[algorithm] && !algorithms[algorithm.toLowerCase()]) {
3009
+ throw new Error("Digest method not supported");
3010
+ }
3011
+ return new Hash();
3012
+ }
3013
+ var Hash = /*#__PURE__*/function () {
3014
+ // surrogate pair
3015
+
3016
+ function Hash() {
3017
+ _classCallCheck(this, Hash);
3018
+ // first 32 bits of the fractional parts of the square roots of the first 8 primes 2..19
3019
+ _defineProperty(this, "A", 0x6a09e667 | 0);
3020
+ _defineProperty(this, "B", 0xbb67ae85 | 0);
3021
+ _defineProperty(this, "C", 0x3c6ef372 | 0);
3022
+ _defineProperty(this, "D", 0xa54ff53a | 0);
3023
+ _defineProperty(this, "E", 0x510e527f | 0);
3024
+ _defineProperty(this, "F", 0x9b05688c | 0);
3025
+ _defineProperty(this, "G", 0x1f83d9ab | 0);
3026
+ _defineProperty(this, "H", 0x5be0cd19 | 0);
3027
+ _defineProperty(this, "_size", 0);
3028
+ _defineProperty(this, "_sp", 0);
3029
+ if (!sharedBuffer || sharedOffset >= N.allocTotal) {
3030
+ sharedBuffer = new ArrayBuffer(N.allocTotal);
3031
+ sharedOffset = 0;
3032
+ }
3033
+ this._byte = new Uint8Array(sharedBuffer, sharedOffset, N.allocBytes);
3034
+ this._word = new Int32Array(sharedBuffer, sharedOffset, N.allocWords);
3035
+ sharedOffset += N.allocBytes;
3036
+ }
3037
+ _createClass(Hash, [{
3038
+ key: "update",
3039
+ value: function update(data) {
3040
+ // data: string
3041
+ if ("string" === typeof data) {
3042
+ return this._utf8(data);
3043
+ }
3044
+
3045
+ // data: undefined
3046
+ if (data == null) {
3047
+ throw new TypeError("Invalid type: " + _typeof(data));
3048
+ }
3049
+ var byteOffset = data.byteOffset;
3050
+ var length = data.byteLength;
3051
+ var blocks = length / N.inputBytes | 0;
3052
+ var offset = 0;
3053
+
3054
+ // longer than 1 block
3055
+ if (blocks && !(byteOffset & 3) && !(this._size % N.inputBytes)) {
3056
+ var block = new Int32Array(data.buffer, byteOffset, blocks * N.inputWords);
3057
+ while (blocks--) {
3058
+ this._int32(block, offset >> 2);
3059
+ offset += N.inputBytes;
3060
+ }
3061
+ this._size += offset;
3062
+ }
3063
+
3064
+ // data: TypedArray | DataView
3065
+ var BYTES_PER_ELEMENT = data.BYTES_PER_ELEMENT;
3066
+ if (BYTES_PER_ELEMENT !== 1 && data.buffer) {
3067
+ var rest = new Uint8Array(data.buffer, byteOffset + offset, length - offset);
3068
+ return this._uint8(rest);
3069
+ }
3070
+
3071
+ // no more bytes
3072
+ if (offset === length) return this;
3073
+
3074
+ // data: Uint8Array | Int8Array
3075
+ return this._uint8(data, offset);
3076
+ }
3077
+ }, {
3078
+ key: "_uint8",
3079
+ value: function _uint8(data, offset) {
3080
+ var _byte = this._byte,
3081
+ _word = this._word;
3082
+ var length = data.length;
3083
+ offset = offset | 0;
3084
+ while (offset < length) {
3085
+ var start = this._size % N.inputBytes;
3086
+ var index = start;
3087
+ while (offset < length && index < N.inputBytes) {
3088
+ _byte[index++] = data[offset++];
3089
+ }
3090
+ if (index >= N.inputBytes) {
3091
+ this._int32(_word);
3092
+ }
3093
+ this._size += index - start;
3094
+ }
3095
+ return this;
3096
+ }
3097
+ }, {
3098
+ key: "_utf8",
3099
+ value: function _utf8(text) {
3100
+ var _byte = this._byte,
3101
+ _word = this._word;
3102
+ var length = text.length;
3103
+ var surrogate = this._sp;
3104
+ for (var offset = 0; offset < length;) {
3105
+ var start = this._size % N.inputBytes;
3106
+ var index = start;
3107
+ while (offset < length && index < N.inputBytes) {
3108
+ var code = text.charCodeAt(offset++) | 0;
3109
+ if (code < 0x80) {
3110
+ // ASCII characters
3111
+ _byte[index++] = code;
3112
+ } else if (code < 0x800) {
3113
+ // 2 bytes
3114
+ _byte[index++] = 0xc0 | code >>> 6;
3115
+ _byte[index++] = 0x80 | code & 0x3f;
3116
+ } else if (code < 0xd800 || code > 0xdfff) {
3117
+ // 3 bytes
3118
+ _byte[index++] = 0xe0 | code >>> 12;
3119
+ _byte[index++] = 0x80 | code >>> 6 & 0x3f;
3120
+ _byte[index++] = 0x80 | code & 0x3f;
3121
+ } else if (surrogate) {
3122
+ // 4 bytes - surrogate pair
3123
+ code = ((surrogate & 0x3ff) << 10) + (code & 0x3ff) + 0x10000;
3124
+ _byte[index++] = 0xf0 | code >>> 18;
3125
+ _byte[index++] = 0x80 | code >>> 12 & 0x3f;
3126
+ _byte[index++] = 0x80 | code >>> 6 & 0x3f;
3127
+ _byte[index++] = 0x80 | code & 0x3f;
3128
+ surrogate = 0;
3129
+ } else {
3130
+ surrogate = code;
3131
+ }
3132
+ }
3133
+ if (index >= N.inputBytes) {
3134
+ this._int32(_word);
3135
+ _word[0] = _word[N.inputWords];
3136
+ }
3137
+ this._size += index - start;
3138
+ }
3139
+ this._sp = surrogate;
3140
+ return this;
3141
+ }
3142
+ }, {
3143
+ key: "_int32",
3144
+ value: function _int32(data, offset) {
3145
+ var A = this.A,
3146
+ B = this.B,
3147
+ C = this.C,
3148
+ D = this.D,
3149
+ E = this.E,
3150
+ F = this.F,
3151
+ G = this.G,
3152
+ H = this.H;
3153
+ var i = 0;
3154
+ offset = offset | 0;
3155
+ while (i < N.inputWords) {
3156
+ W[i++] = swap32(data[offset++]);
3157
+ }
3158
+ for (i = N.inputWords; i < N.workWords; i++) {
3159
+ W[i] = gamma1(W[i - 2]) + W[i - 7] + gamma0(W[i - 15]) + W[i - 16] | 0;
3160
+ }
3161
+ for (i = 0; i < N.workWords; i++) {
3162
+ var T1 = H + sigma1(E) + ch(E, F, G) + K[i] + W[i] | 0;
3163
+ var T2 = sigma0(A) + maj(A, B, C) | 0;
3164
+ H = G;
3165
+ G = F;
3166
+ F = E;
3167
+ E = D + T1 | 0;
3168
+ D = C;
3169
+ C = B;
3170
+ B = A;
3171
+ A = T1 + T2 | 0;
3172
+ }
3173
+ this.A = A + this.A | 0;
3174
+ this.B = B + this.B | 0;
3175
+ this.C = C + this.C | 0;
3176
+ this.D = D + this.D | 0;
3177
+ this.E = E + this.E | 0;
3178
+ this.F = F + this.F | 0;
3179
+ this.G = G + this.G | 0;
3180
+ this.H = H + this.H | 0;
3181
+ }
3182
+ }, {
3183
+ key: "digest",
3184
+ value: function digest(encoding) {
3185
+ var _byte = this._byte,
3186
+ _word = this._word;
3187
+ var i = this._size % N.inputBytes | 0;
3188
+ _byte[i++] = 0x80;
3189
+
3190
+ // pad 0 for current word
3191
+ while (i & 3) {
3192
+ _byte[i++] = 0;
3193
+ }
3194
+ i >>= 2;
3195
+ if (i > N.highIndex) {
3196
+ while (i < N.inputWords) {
3197
+ _word[i++] = 0;
3198
+ }
3199
+ i = 0;
3200
+ this._int32(_word);
3201
+ }
3202
+
3203
+ // pad 0 for rest words
3204
+ while (i < N.inputWords) {
3205
+ _word[i++] = 0;
3206
+ }
3207
+
3208
+ // input size
3209
+ var bits64 = this._size * 8;
3210
+ var low32 = (bits64 & 0xffffffff) >>> 0;
3211
+ var high32 = (bits64 - low32) / 0x100000000;
3212
+ if (high32) _word[N.highIndex] = swap32(high32);
3213
+ if (low32) _word[N.lowIndex] = swap32(low32);
3214
+ this._int32(_word);
3215
+ return encoding === "hex" ? this._hex() : this._bin();
3216
+ }
3217
+ }, {
3218
+ key: "_hex",
3219
+ value: function _hex() {
3220
+ var A = this.A,
3221
+ B = this.B,
3222
+ C = this.C,
3223
+ D = this.D,
3224
+ E = this.E,
3225
+ F = this.F,
3226
+ G = this.G,
3227
+ H = this.H;
3228
+ return hex32(A) + hex32(B) + hex32(C) + hex32(D) + hex32(E) + hex32(F) + hex32(G) + hex32(H);
3229
+ }
3230
+ }, {
3231
+ key: "_bin",
3232
+ value: function _bin() {
3233
+ var A = this.A,
3234
+ B = this.B,
3235
+ C = this.C,
3236
+ D = this.D,
3237
+ E = this.E,
3238
+ F = this.F,
3239
+ G = this.G,
3240
+ H = this.H,
3241
+ _byte = this._byte,
3242
+ _word = this._word;
3243
+ _word[0] = swap32(A);
3244
+ _word[1] = swap32(B);
3245
+ _word[2] = swap32(C);
3246
+ _word[3] = swap32(D);
3247
+ _word[4] = swap32(E);
3248
+ _word[5] = swap32(F);
3249
+ _word[6] = swap32(G);
3250
+ _word[7] = swap32(H);
3251
+ return _byte.slice(0, 32);
3252
+ }
3253
+ }]);
3254
+ return Hash;
3255
+ }();
3256
+ var W = new Int32Array(N.workWords);
3257
+ var sharedBuffer;
3258
+ var sharedOffset = 0;
3259
+ var hex32 = function hex32(num) {
3260
+ return (num + 0x100000000).toString(16).substr(-8);
3261
+ };
3262
+ var swapLE = function swapLE(c) {
3263
+ return c << 24 & 0xff000000 | c << 8 & 0xff0000 | c >> 8 & 0xff00 | c >> 24 & 0xff;
3264
+ };
3265
+ var swapBE = function swapBE(c) {
3266
+ return c;
3267
+ };
3268
+ var swap32 = isBE() ? swapBE : swapLE;
3269
+ var ch = function ch(x, y, z) {
3270
+ return z ^ x & (y ^ z);
3271
+ };
3272
+ var maj = function maj(x, y, z) {
3273
+ return x & y | z & (x | y);
3274
+ };
3275
+ var sigma0 = function sigma0(x) {
3276
+ return (x >>> 2 | x << 30) ^ (x >>> 13 | x << 19) ^ (x >>> 22 | x << 10);
3277
+ };
3278
+ var sigma1 = function sigma1(x) {
3279
+ return (x >>> 6 | x << 26) ^ (x >>> 11 | x << 21) ^ (x >>> 25 | x << 7);
3280
+ };
3281
+ var gamma0 = function gamma0(x) {
3282
+ return (x >>> 7 | x << 25) ^ (x >>> 18 | x << 14) ^ x >>> 3;
3283
+ };
3284
+ var gamma1 = function gamma1(x) {
3285
+ return (x >>> 17 | x << 15) ^ (x >>> 19 | x << 13) ^ x >>> 10;
3286
+ };
3287
+ function isBE() {
3288
+ var buf = new Uint8Array(new Uint16Array([0xfeff]).buffer); // BOM
3289
+ return buf[0] === 0xfe;
3290
+ }
3291
+ var getSHA256Hash = function getSHA256Hash(bits) {
3292
+ return createHash().update(bits).digest("hex");
3293
+ };
3294
+
3295
+ function deserializeSchema(serialized) {
3296
+ var _serialized$options;
3297
+ switch (serialized.type) {
3298
+ case "string":
3299
+ return new StringSchema(_objectSpread2(_objectSpread2({}, serialized.options), {}, {
3300
+ regexp: ((_serialized$options = serialized.options) === null || _serialized$options === void 0 ? void 0 : _serialized$options.regexp) && new RegExp(serialized.options.regexp.source, serialized.options.regexp.flags)
3301
+ }), serialized.opt);
3302
+ case "literal":
3303
+ return new LiteralSchema(serialized.value, serialized.opt);
3304
+ case "boolean":
3305
+ return new BooleanSchema(serialized.opt);
3306
+ case "number":
3307
+ return new NumberSchema(serialized.options, serialized.opt);
3308
+ case "object":
3309
+ return new ObjectSchema(Object.fromEntries(Object.entries(serialized.items).map(function (_ref) {
3310
+ var _ref2 = _slicedToArray(_ref, 2),
3311
+ key = _ref2[0],
3312
+ item = _ref2[1];
3313
+ return [key, deserializeSchema(item)];
3314
+ })), serialized.opt);
3315
+ case "array":
3316
+ return new ArraySchema(deserializeSchema(serialized.item), serialized.opt);
3317
+ case "union":
3318
+ return new UnionSchema(typeof serialized.key === "string" ? serialized.key : deserializeSchema(serialized.key), serialized.items.map(deserializeSchema), serialized.opt);
3319
+ case "richtext":
3320
+ return new RichTextSchema(serialized.options, serialized.opt);
3321
+ case "record":
3322
+ return new RecordSchema(deserializeSchema(serialized.item), serialized.opt);
3323
+ case "keyOf":
3324
+ return new KeyOfSchema(serialized.schema, serialized.path, serialized.opt);
3325
+ case "file":
3326
+ return new FileSchema(serialized.options, serialized.opt);
3327
+ case "image":
3328
+ return new ImageSchema(serialized.options, serialized.opt);
3329
+ default:
3330
+ {
3331
+ var exhaustiveCheck = serialized;
3332
+ var unknownSerialized = exhaustiveCheck;
3333
+ if (unknownSerialized && _typeof(unknownSerialized) === "object" && "type" in unknownSerialized) {
3334
+ throw new Error("Unknown schema type: ".concat(unknownSerialized.type));
3335
+ } else {
3336
+ throw new Error("Unknown schema: ".concat(JSON.stringify(unknownSerialized, null, 2)));
3337
+ }
3338
+ }
3339
+ }
3340
+ }
3341
+
3342
+ function _regeneratorRuntime() {
3343
+ _regeneratorRuntime = function () {
3344
+ return e;
3345
+ };
3346
+ var t,
3347
+ e = {},
3348
+ r = Object.prototype,
3349
+ n = r.hasOwnProperty,
3350
+ o = Object.defineProperty || function (t, e, r) {
3351
+ t[e] = r.value;
3352
+ },
3353
+ i = "function" == typeof Symbol ? Symbol : {},
3354
+ a = i.iterator || "@@iterator",
3355
+ c = i.asyncIterator || "@@asyncIterator",
3356
+ u = i.toStringTag || "@@toStringTag";
3357
+ function define(t, e, r) {
3358
+ return Object.defineProperty(t, e, {
3359
+ value: r,
3360
+ enumerable: !0,
3361
+ configurable: !0,
3362
+ writable: !0
3363
+ }), t[e];
3364
+ }
3365
+ try {
3366
+ define({}, "");
3367
+ } catch (t) {
3368
+ define = function (t, e, r) {
3369
+ return t[e] = r;
3370
+ };
3371
+ }
3372
+ function wrap(t, e, r, n) {
3373
+ var i = e && e.prototype instanceof Generator ? e : Generator,
3374
+ a = Object.create(i.prototype),
3375
+ c = new Context(n || []);
3376
+ return o(a, "_invoke", {
3377
+ value: makeInvokeMethod(t, r, c)
3378
+ }), a;
3379
+ }
3380
+ function tryCatch(t, e, r) {
3381
+ try {
3382
+ return {
3383
+ type: "normal",
3384
+ arg: t.call(e, r)
3385
+ };
3386
+ } catch (t) {
3387
+ return {
3388
+ type: "throw",
3389
+ arg: t
3390
+ };
3391
+ }
3392
+ }
3393
+ e.wrap = wrap;
3394
+ var h = "suspendedStart",
3395
+ l = "suspendedYield",
3396
+ f = "executing",
3397
+ s = "completed",
3398
+ y = {};
3399
+ function Generator() {}
3400
+ function GeneratorFunction() {}
3401
+ function GeneratorFunctionPrototype() {}
3402
+ var p = {};
3403
+ define(p, a, function () {
3404
+ return this;
3405
+ });
3406
+ var d = Object.getPrototypeOf,
3407
+ v = d && d(d(values([])));
3408
+ v && v !== r && n.call(v, a) && (p = v);
3409
+ var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);
3410
+ function defineIteratorMethods(t) {
3411
+ ["next", "throw", "return"].forEach(function (e) {
3412
+ define(t, e, function (t) {
3413
+ return this._invoke(e, t);
3414
+ });
3415
+ });
3416
+ }
3417
+ function AsyncIterator(t, e) {
3418
+ function invoke(r, o, i, a) {
3419
+ var c = tryCatch(t[r], t, o);
3420
+ if ("throw" !== c.type) {
3421
+ var u = c.arg,
3422
+ h = u.value;
3423
+ return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) {
3424
+ invoke("next", t, i, a);
3425
+ }, function (t) {
3426
+ invoke("throw", t, i, a);
3427
+ }) : e.resolve(h).then(function (t) {
3428
+ u.value = t, i(u);
3429
+ }, function (t) {
3430
+ return invoke("throw", t, i, a);
3431
+ });
3432
+ }
3433
+ a(c.arg);
3434
+ }
3435
+ var r;
3436
+ o(this, "_invoke", {
3437
+ value: function (t, n) {
3438
+ function callInvokeWithMethodAndArg() {
3439
+ return new e(function (e, r) {
3440
+ invoke(t, n, e, r);
3441
+ });
3442
+ }
3443
+ return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
3444
+ }
3445
+ });
3446
+ }
3447
+ function makeInvokeMethod(e, r, n) {
3448
+ var o = h;
3449
+ return function (i, a) {
3450
+ if (o === f) throw new Error("Generator is already running");
3451
+ if (o === s) {
3452
+ if ("throw" === i) throw a;
3453
+ return {
3454
+ value: t,
3455
+ done: !0
3456
+ };
3457
+ }
3458
+ for (n.method = i, n.arg = a;;) {
3459
+ var c = n.delegate;
3460
+ if (c) {
3461
+ var u = maybeInvokeDelegate(c, n);
3462
+ if (u) {
3463
+ if (u === y) continue;
3464
+ return u;
3465
+ }
3466
+ }
3467
+ if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) {
3468
+ if (o === h) throw o = s, n.arg;
3469
+ n.dispatchException(n.arg);
3470
+ } else "return" === n.method && n.abrupt("return", n.arg);
3471
+ o = f;
3472
+ var p = tryCatch(e, r, n);
3473
+ if ("normal" === p.type) {
3474
+ if (o = n.done ? s : l, p.arg === y) continue;
3475
+ return {
3476
+ value: p.arg,
3477
+ done: n.done
3478
+ };
3479
+ }
3480
+ "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg);
3481
+ }
3482
+ };
3483
+ }
3484
+ function maybeInvokeDelegate(e, r) {
3485
+ var n = r.method,
3486
+ o = e.iterator[n];
3487
+ 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;
3488
+ var i = tryCatch(o, e.iterator, r.arg);
3489
+ if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y;
3490
+ var a = i.arg;
3491
+ 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);
3492
+ }
3493
+ function pushTryEntry(t) {
3494
+ var e = {
3495
+ tryLoc: t[0]
3496
+ };
3497
+ 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e);
3498
+ }
3499
+ function resetTryEntry(t) {
3500
+ var e = t.completion || {};
3501
+ e.type = "normal", delete e.arg, t.completion = e;
3502
+ }
3503
+ function Context(t) {
3504
+ this.tryEntries = [{
3505
+ tryLoc: "root"
3506
+ }], t.forEach(pushTryEntry, this), this.reset(!0);
3507
+ }
3508
+ function values(e) {
3509
+ if (e || "" === e) {
3510
+ var r = e[a];
3511
+ if (r) return r.call(e);
3512
+ if ("function" == typeof e.next) return e;
3513
+ if (!isNaN(e.length)) {
3514
+ var o = -1,
3515
+ i = function next() {
3516
+ for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next;
3517
+ return next.value = t, next.done = !0, next;
3518
+ };
3519
+ return i.next = i;
3520
+ }
3521
+ }
3522
+ throw new TypeError(typeof e + " is not iterable");
3523
+ }
3524
+ return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", {
3525
+ value: GeneratorFunctionPrototype,
3526
+ configurable: !0
3527
+ }), o(GeneratorFunctionPrototype, "constructor", {
3528
+ value: GeneratorFunction,
3529
+ configurable: !0
3530
+ }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) {
3531
+ var e = "function" == typeof t && t.constructor;
3532
+ return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name));
3533
+ }, e.mark = function (t) {
3534
+ return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t;
3535
+ }, e.awrap = function (t) {
3536
+ return {
3537
+ __await: t
3538
+ };
3539
+ }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {
3540
+ return this;
3541
+ }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {
3542
+ void 0 === i && (i = Promise);
3543
+ var a = new AsyncIterator(wrap(t, r, n, o), i);
3544
+ return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
3545
+ return t.done ? t.value : a.next();
3546
+ });
3547
+ }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () {
3548
+ return this;
3549
+ }), define(g, "toString", function () {
3550
+ return "[object Generator]";
3551
+ }), e.keys = function (t) {
3552
+ var e = Object(t),
3553
+ r = [];
3554
+ for (var n in e) r.push(n);
3555
+ return r.reverse(), function next() {
3556
+ for (; r.length;) {
3557
+ var t = r.pop();
3558
+ if (t in e) return next.value = t, next.done = !1, next;
3559
+ }
3560
+ return next.done = !0, next;
3561
+ };
3562
+ }, e.values = values, Context.prototype = {
3563
+ constructor: Context,
3564
+ reset: function (e) {
3565
+ 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);
3566
+ },
3567
+ stop: function () {
3568
+ this.done = !0;
3569
+ var t = this.tryEntries[0].completion;
3570
+ if ("throw" === t.type) throw t.arg;
3571
+ return this.rval;
3572
+ },
3573
+ dispatchException: function (e) {
3574
+ if (this.done) throw e;
3575
+ var r = this;
3576
+ function handle(n, o) {
3577
+ return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o;
3578
+ }
3579
+ for (var o = this.tryEntries.length - 1; o >= 0; --o) {
3580
+ var i = this.tryEntries[o],
3581
+ a = i.completion;
3582
+ if ("root" === i.tryLoc) return handle("end");
3583
+ if (i.tryLoc <= this.prev) {
3584
+ var c = n.call(i, "catchLoc"),
3585
+ u = n.call(i, "finallyLoc");
3586
+ if (c && u) {
3587
+ if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
3588
+ if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
3589
+ } else if (c) {
3590
+ if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
3591
+ } else {
3592
+ if (!u) throw new Error("try statement without catch or finally");
3593
+ if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
3594
+ }
3595
+ }
3596
+ }
3597
+ },
3598
+ abrupt: function (t, e) {
3599
+ for (var r = this.tryEntries.length - 1; r >= 0; --r) {
3600
+ var o = this.tryEntries[r];
3601
+ if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) {
3602
+ var i = o;
3603
+ break;
3604
+ }
3605
+ }
3606
+ i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null);
3607
+ var a = i ? i.completion : {};
3608
+ return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a);
3609
+ },
3610
+ complete: function (t, e) {
3611
+ if ("throw" === t.type) throw t.arg;
3612
+ 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;
3613
+ },
3614
+ finish: function (t) {
3615
+ for (var e = this.tryEntries.length - 1; e >= 0; --e) {
3616
+ var r = this.tryEntries[e];
3617
+ if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y;
3618
+ }
3619
+ },
3620
+ catch: function (t) {
3621
+ for (var e = this.tryEntries.length - 1; e >= 0; --e) {
3622
+ var r = this.tryEntries[e];
3623
+ if (r.tryLoc === t) {
3624
+ var n = r.completion;
3625
+ if ("throw" === n.type) {
3626
+ var o = n.arg;
3627
+ resetTryEntry(r);
3628
+ }
3629
+ return o;
3630
+ }
3631
+ }
3632
+ throw new Error("illegal catch attempt");
3633
+ },
3634
+ delegateYield: function (e, r, n) {
3635
+ return this.delegate = {
3636
+ iterator: values(e),
3637
+ resultName: r,
3638
+ nextLoc: n
3639
+ }, "next" === this.method && (this.arg = t), y;
3640
+ }
3641
+ }, e;
3642
+ }
3643
+
3644
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
3645
+ try {
3646
+ var info = gen[key](arg);
3647
+ var value = info.value;
3648
+ } catch (error) {
3649
+ reject(error);
3650
+ return;
3651
+ }
3652
+ if (info.done) {
3653
+ resolve(value);
3654
+ } else {
3655
+ Promise.resolve(value).then(_next, _throw);
3656
+ }
3657
+ }
3658
+ function _asyncToGenerator(fn) {
3659
+ return function () {
3660
+ var self = this,
3661
+ args = arguments;
3662
+ return new Promise(function (resolve, reject) {
3663
+ var gen = fn.apply(self, args);
3664
+ function _next(value) {
3665
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
3666
+ }
3667
+ function _throw(err) {
3668
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
3669
+ }
3670
+ _next(undefined);
3671
+ });
3672
+ };
3673
+ }
3674
+
3675
+ // TODO: move this to internal, only reason this is here is that react, ui and server all depend on it
3676
+ var ValApi = /*#__PURE__*/function () {
3677
+ function ValApi(host) {
3678
+ _classCallCheck(this, ValApi);
3679
+ this.host = host;
3680
+ }
3681
+ _createClass(ValApi, [{
3682
+ key: "getDisableUrl",
3683
+ value: function getDisableUrl(redirectTo) {
3684
+ return "".concat(this.host, "/disable?redirect_to=").concat(encodeURIComponent(redirectTo));
3685
+ }
3686
+ }, {
3687
+ key: "getLoginUrl",
3688
+ value: function getLoginUrl(redirectTo) {
3689
+ return "".concat(this.host, "/authorize?redirect_to=").concat(encodeURIComponent(redirectTo));
3690
+ }
3691
+ }, {
3692
+ key: "getEnableUrl",
3693
+ value: function getEnableUrl(redirectTo) {
3694
+ return "".concat(this.host, "/enable?redirect_to=").concat(encodeURIComponent(redirectTo));
3695
+ }
3696
+ }, {
3697
+ key: "getPatches",
3698
+ value: function () {
3699
+ var _getPatches = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
3700
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
3701
+ while (1) switch (_context.prev = _context.next) {
3702
+ case 0:
3703
+ return _context.abrupt("return", fetch("".concat(this.host, "/patches/~"), {
3704
+ headers: {
3705
+ "Content-Type": "application/json"
3706
+ }
3707
+ }).then(function (res) {
3708
+ return parse(res);
3709
+ })["catch"](createError));
3710
+ case 1:
3711
+ case "end":
3712
+ return _context.stop();
3713
+ }
3714
+ }, _callee, this);
3715
+ }));
3716
+ function getPatches() {
3717
+ return _getPatches.apply(this, arguments);
3718
+ }
3719
+ return getPatches;
3720
+ }()
3721
+ }, {
3722
+ key: "deletePatches",
3723
+ value: function () {
3724
+ var _deletePatches = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(ids, headers) {
3725
+ var params;
3726
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
3727
+ while (1) switch (_context2.prev = _context2.next) {
3728
+ case 0:
3729
+ params = new URLSearchParams();
3730
+ ids.forEach(function (id) {
3731
+ return params.append("id", id);
3732
+ });
3733
+ return _context2.abrupt("return", fetch("".concat(this.host, "/patches/~?").concat(params), {
3734
+ method: "DELETE",
3735
+ headers: headers || {
3736
+ "Content-Type": "application/json"
3737
+ }
3738
+ }).then(function (res) {
3739
+ return parse(res);
3740
+ })["catch"](createError));
3741
+ case 3:
3742
+ case "end":
3743
+ return _context2.stop();
3744
+ }
3745
+ }, _callee2, this);
3746
+ }));
3747
+ function deletePatches(_x, _x2) {
3748
+ return _deletePatches.apply(this, arguments);
3749
+ }
3750
+ return deletePatches;
3751
+ }()
3752
+ }, {
3753
+ key: "getEditUrl",
3754
+ value: function getEditUrl() {
3755
+ return "/val";
3756
+ }
3757
+ }, {
3758
+ key: "getSession",
3759
+ value: function getSession() {
3760
+ return fetch("".concat(this.host, "/session")).then(function (res) {
3761
+ return parse(res)["catch"](createError);
3762
+ });
3763
+ }
3764
+ }, {
3765
+ key: "getSchema",
3766
+ value: function getSchema(_ref) {
3767
+ var headers = _ref.headers;
3768
+ return fetch("".concat(this.host, "/schema"), {
3769
+ method: "GET",
3770
+ headers: headers
3771
+ }).then(function (res) {
3772
+ return parse(res);
3773
+ })["catch"](createError);
3774
+ }
3775
+ }, {
3776
+ key: "putTree",
3777
+ value: function putTree(_ref2) {
3778
+ var _ref2$treePath = _ref2.treePath,
3779
+ treePath = _ref2$treePath === void 0 ? "/" : _ref2$treePath,
3780
+ patchIds = _ref2.patchIds,
3781
+ addPatch = _ref2.addPatch,
3782
+ validateAll = _ref2.validateAll,
3783
+ validateSource = _ref2.validateSource,
3784
+ validateBinaryFiles = _ref2.validateBinaryFiles,
3785
+ headers = _ref2.headers;
3786
+ var params = new URLSearchParams();
3787
+ var textEncoder = new TextEncoder();
3788
+ var patchesSha = getSHA256Hash(textEncoder.encode((patchIds || []).concat(JSON.stringify(addPatch || {})).join(";")));
3789
+ params.set("patches_sha", patchesSha);
3790
+ params.set("validate_all", (validateAll || false).toString());
3791
+ params.set("validate_source", (validateSource || false).toString());
3792
+ params.set("validate_binary_files", (validateBinaryFiles || false).toString());
3793
+ return fetch("".concat(this.host, "/tree/~").concat(treePath, "?").concat(params.toString()), {
3794
+ method: "PUT",
3795
+ body: JSON.stringify({
3796
+ patchIds: patchIds,
3797
+ addPatch: addPatch
3798
+ }),
3799
+ headers: headers
3800
+ }).then(function (res) {
3801
+ return parse(res);
3802
+ })["catch"](createError);
3803
+ }
3804
+ }, {
3805
+ key: "postSave",
3806
+ value: function postSave(_ref3) {
3807
+ var patchIds = _ref3.patchIds;
3808
+ return fetch("".concat(this.host, "/save"), {
3809
+ method: "POST",
3810
+ body: JSON.stringify({
3811
+ patchIds: patchIds
3812
+ }),
3813
+ headers: {
3814
+ "Content-Type": "application/json"
3815
+ }
3816
+ }).then( /*#__PURE__*/function () {
3817
+ var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(res) {
3818
+ var jsonRes;
3819
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
3820
+ while (1) switch (_context3.prev = _context3.next) {
3821
+ case 0:
3822
+ if (!res.ok) {
3823
+ _context3.next = 4;
3824
+ break;
3825
+ }
3826
+ return _context3.abrupt("return", parse(res));
3827
+ case 4:
3828
+ if (!(res.status === 400 && res.headers.get("content-type") === "application/json")) {
3829
+ _context3.next = 9;
3830
+ break;
3831
+ }
3832
+ _context3.next = 7;
3833
+ return res.json();
3834
+ case 7:
3835
+ jsonRes = _context3.sent;
3836
+ alert(JSON.stringify(jsonRes));
3837
+ case 9:
3838
+ return _context3.abrupt("return", parse(res));
3839
+ case 10:
3840
+ case "end":
3841
+ return _context3.stop();
3842
+ }
3843
+ }, _callee3);
3844
+ }));
3845
+ return function (_x3) {
3846
+ return _ref4.apply(this, arguments);
3847
+ };
3848
+ }())["catch"](createError);
3849
+ }
3850
+ }, {
3851
+ key: "postValidate",
3852
+ value: function postValidate(_ref5) {
3853
+ var patches = _ref5.patches,
3854
+ headers = _ref5.headers;
3855
+ return fetch("".concat(this.host, "/validate"), {
3856
+ method: "POST",
3857
+ body: JSON.stringify({
3858
+ patches: patches
3859
+ }),
3860
+ headers: headers || {
3861
+ "Content-Type": "application/json"
3862
+ }
3863
+ }).then( /*#__PURE__*/function () {
3864
+ var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(res) {
3865
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
3866
+ while (1) switch (_context4.prev = _context4.next) {
3867
+ case 0:
3868
+ return _context4.abrupt("return", parse(res));
3869
+ case 1:
3870
+ case "end":
3871
+ return _context4.stop();
3872
+ }
3873
+ }, _callee4);
3874
+ }));
3875
+ return function (_x4) {
3876
+ return _ref6.apply(this, arguments);
3877
+ };
3878
+ }())["catch"](createError);
3879
+ }
3880
+ }]);
3881
+ return ValApi;
3882
+ }();
3883
+ function createError(err) {
3884
+ return result.err({
3885
+ statusCode: 500,
3886
+ message: err instanceof Error ? err.message : _typeof(err) === "object" && err && "message" in err && typeof err.message === "string" ? err.message : "Unknown error",
3887
+ details: _typeof(err) === "object" && err && "details" in err ? err.details : undefined
3888
+ });
3889
+ }
3890
+
3891
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3892
+ function formatError(status, json, statusText) {
3893
+ return result.err({
3894
+ statusCode: status,
3895
+ message: json.message || statusText,
3896
+ details: json.details || Object.fromEntries(Object.entries(json).filter(function (_ref7) {
3897
+ var _ref8 = _slicedToArray(_ref7, 1),
3898
+ key = _ref8[0];
3899
+ return key !== "message";
3900
+ }))
3901
+ });
3902
+ }
3903
+
3904
+ // TODO: validate
3905
+ function parse(_x5) {
3906
+ return _parse.apply(this, arguments);
3907
+ }
3908
+ function _parse() {
3909
+ _parse = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(res) {
3910
+ var json;
3911
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
3912
+ while (1) switch (_context5.prev = _context5.next) {
3913
+ case 0:
3914
+ _context5.prev = 0;
3915
+ if (!res.ok) {
3916
+ _context5.next = 9;
3917
+ break;
3918
+ }
3919
+ _context5.t0 = result.result;
3920
+ _context5.next = 5;
3921
+ return res.json();
3922
+ case 5:
3923
+ _context5.t1 = _context5.sent;
3924
+ return _context5.abrupt("return", _context5.t0.ok.call(_context5.t0, _context5.t1));
3925
+ case 9:
3926
+ _context5.prev = 9;
3927
+ _context5.next = 12;
3928
+ return res.json();
3929
+ case 12:
3930
+ json = _context5.sent;
3931
+ return _context5.abrupt("return", formatError(res.status, json, res.statusText));
3932
+ case 16:
3933
+ _context5.prev = 16;
3934
+ _context5.t2 = _context5["catch"](9);
3935
+ return _context5.abrupt("return", result.err({
3936
+ statusCode: res.status,
3937
+ message: res.statusText
3938
+ }));
3939
+ case 19:
3940
+ _context5.next = 24;
3941
+ break;
3942
+ case 21:
3943
+ _context5.prev = 21;
3944
+ _context5.t3 = _context5["catch"](0);
3945
+ return _context5.abrupt("return", result.err({
3946
+ message: _context5.t3 instanceof Error ? _context5.t3.message : "Unknown error"
3947
+ }));
3948
+ case 24:
3949
+ case "end":
3950
+ return _context5.stop();
3951
+ }
3952
+ }, _callee5, null, [[0, 21], [9, 16]]);
3953
+ }));
3954
+ return _parse.apply(this, arguments);
3955
+ }
3956
+
3957
+ // eslint-disable-next-line @typescript-eslint/ban-types
3958
+
3959
+ var FATAL_ERROR_TYPES = ["no-schema", "no-source", "invalid-id", "no-module", "invalid-patch"];
3960
+ var Internal = {
3961
+ VERSION: {
3962
+ core: function () {
3963
+ try {
3964
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
3965
+ return require("../package.json").version;
3966
+ } catch (_unused) {
3967
+ return null;
3968
+ }
3969
+ }()
3970
+ },
3971
+ convertFileSource: convertFileSource,
3972
+ getSchema: getSchema,
3973
+ getValPath: getValPath,
3974
+ getVal: getVal,
3975
+ getSource: getSource,
3976
+ resolvePath: resolvePath,
3977
+ splitModuleFilePathAndModulePath: splitModuleFilePathAndModulePath,
3978
+ isVal: isVal,
3979
+ createValPathOfItem: createValPathOfItem,
3980
+ getSHA256Hash: getSHA256Hash,
3981
+ initSchema: initSchema,
3982
+ ModuleFilePathSep: ModuleFilePathSep,
3983
+ notFileOp: function notFileOp(op) {
3984
+ return op.op !== "file";
3985
+ },
3986
+ isFileOp: function isFileOp(op) {
3987
+ return op.op === "file" && typeof op.filePath === "string";
3988
+ },
3989
+ createPatchJSONPath: function createPatchJSONPath(modulePath) {
3990
+ return "/".concat(modulePath.split(".").map(function (segment) {
3991
+ return segment && tryJsonParse(segment);
3992
+ }).join("/"));
3993
+ },
3994
+ createPatchPath: function createPatchPath(modulePath) {
3995
+ return parsePath(modulePath);
3996
+ },
3997
+ patchPathToModulePath: function patchPathToModulePath(patchPath) {
3998
+ return patchPath.map(function (segment) {
3999
+ // 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?
4000
+ if (Number.isInteger(Number(segment))) {
4001
+ return segment;
4002
+ }
4003
+ return JSON.stringify(segment);
4004
+ }).join(".");
4005
+ },
4006
+ VAL_ENABLE_COOKIE_NAME: "val_enable",
4007
+ VAL_STATE_COOKIE: "val_state",
4008
+ VAL_SESSION_COOKIE: "val_session"
4009
+ };
4010
+ function tryJsonParse(str) {
4011
+ try {
4012
+ return JSON.parse(str);
4013
+ } catch (err) {
4014
+ return str;
4015
+ }
4016
+ }
4017
+
4018
+ exports.ArraySchema = ArraySchema;
4019
+ exports.BooleanSchema = BooleanSchema;
4020
+ exports.Call = Call;
4021
+ exports.Expr = Expr;
4022
+ exports.FATAL_ERROR_TYPES = FATAL_ERROR_TYPES;
4023
+ exports.FILE_REF_PROP = FILE_REF_PROP;
4024
+ exports.FILE_REF_SUBTYPE_TAG = FILE_REF_SUBTYPE_TAG;
4025
+ exports.FileSchema = FileSchema;
4026
+ exports.GenericSelector = GenericSelector;
4027
+ exports.ImageSchema = ImageSchema;
4028
+ exports.Internal = Internal;
4029
+ exports.LiteralSchema = LiteralSchema;
4030
+ exports.NilSym = NilSym;
4031
+ exports.NumberSchema = NumberSchema;
4032
+ exports.ObjectSchema = ObjectSchema;
4033
+ exports.PatchError = PatchError;
4034
+ exports.RT_IMAGE_TAG = RT_IMAGE_TAG;
4035
+ exports.RecordSchema = RecordSchema;
4036
+ exports.RichTextSchema = RichTextSchema;
4037
+ exports.Schema = Schema;
4038
+ exports.StringLiteral = StringLiteral;
4039
+ exports.StringSchema = StringSchema;
4040
+ exports.StringTemplate = StringTemplate;
4041
+ exports.Sym = Sym;
4042
+ exports.UnionSchema = UnionSchema;
4043
+ exports.VAL_EXTENSION = VAL_EXTENSION;
4044
+ exports.ValApi = ValApi;
4045
+ exports._classCallCheck = _classCallCheck;
4046
+ exports._createClass = _createClass;
4047
+ exports._slicedToArray = _slicedToArray;
4048
+ exports._toConsumableArray = _toConsumableArray;
4049
+ exports._typeof = _typeof;
4050
+ exports.derefPatch = derefPatch;
4051
+ exports.deserializeSchema = deserializeSchema;
4052
+ exports.evaluate = evaluate;
4053
+ exports.index = index;
4054
+ exports.initVal = initVal;
4055
+ exports.modules = modules;
4056
+ exports.parse = parse$1;
4057
+ exports.splitModuleFilePathAndModulePath = splitModuleFilePathAndModulePath;