@valbuild/core 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/CHANGELOG.md +0 -0
  2. package/README.md +537 -0
  3. package/dist/createClass-012eebbf.esm.js +109 -0
  4. package/dist/createClass-a436dbfe.cjs.dev.js +116 -0
  5. package/dist/createClass-de7426aa.cjs.prod.js +116 -0
  6. package/dist/declarations/src/Json.d.ts +6 -0
  7. package/dist/declarations/src/expr/eval.d.ts +19 -0
  8. package/dist/declarations/src/expr/expr.d.ts +32 -0
  9. package/dist/declarations/src/expr/index.d.ts +3 -0
  10. package/dist/declarations/src/expr/parser.d.ts +8 -0
  11. package/dist/declarations/src/expr/tokenizer.d.ts +7 -0
  12. package/dist/declarations/src/fetchVal.d.ts +5 -0
  13. package/dist/declarations/src/fp/array.d.ts +8 -0
  14. package/dist/declarations/src/fp/index.d.ts +3 -0
  15. package/dist/declarations/src/fp/result.d.ts +67 -0
  16. package/dist/declarations/src/fp/util.d.ts +12 -0
  17. package/dist/declarations/src/index.d.ts +32 -0
  18. package/dist/declarations/src/initSchema.d.ts +57 -0
  19. package/dist/declarations/src/initVal.d.ts +39 -0
  20. package/dist/declarations/src/module.d.ts +38 -0
  21. package/dist/declarations/src/patch/deref.d.ts +13 -0
  22. package/dist/declarations/src/patch/index.d.ts +6 -0
  23. package/dist/declarations/src/patch/json.d.ts +11 -0
  24. package/dist/declarations/src/patch/operation.d.ts +59 -0
  25. package/dist/declarations/src/patch/ops.d.ts +40 -0
  26. package/dist/declarations/src/patch/parse.d.ts +19 -0
  27. package/dist/declarations/src/patch/patch.d.ts +6 -0
  28. package/dist/declarations/src/patch/util.d.ts +6 -0
  29. package/dist/declarations/src/schema/array.d.ts +18 -0
  30. package/dist/declarations/src/schema/boolean.d.ts +15 -0
  31. package/dist/declarations/src/schema/i18n.d.ts +21 -0
  32. package/dist/declarations/src/schema/image.d.ts +32 -0
  33. package/dist/declarations/src/schema/index.d.ts +23 -0
  34. package/dist/declarations/src/schema/literal.d.ts +17 -0
  35. package/dist/declarations/src/schema/number.d.ts +22 -0
  36. package/dist/declarations/src/schema/object.d.ts +25 -0
  37. package/dist/declarations/src/schema/oneOf.d.ts +22 -0
  38. package/dist/declarations/src/schema/richtext.d.ts +76 -0
  39. package/dist/declarations/src/schema/string.d.ts +22 -0
  40. package/dist/declarations/src/schema/union.d.ts +36 -0
  41. package/dist/declarations/src/selector/SelectorProxy.d.ts +7 -0
  42. package/dist/declarations/src/selector/array.d.ts +17 -0
  43. package/dist/declarations/src/selector/boolean.d.ts +2 -0
  44. package/dist/declarations/src/selector/file.d.ts +9 -0
  45. package/dist/declarations/src/selector/i18n.d.ts +11 -0
  46. package/dist/declarations/src/selector/index.d.ts +81 -0
  47. package/dist/declarations/src/selector/number.d.ts +2 -0
  48. package/dist/declarations/src/selector/object.d.ts +10 -0
  49. package/dist/declarations/src/selector/primitive.d.ts +9 -0
  50. package/dist/declarations/src/selector/remote.d.ts +7 -0
  51. package/dist/declarations/src/selector/string.d.ts +2 -0
  52. package/dist/declarations/src/source/file.d.ts +23 -0
  53. package/dist/declarations/src/source/i18n.d.ts +29 -0
  54. package/dist/declarations/src/source/index.d.ts +33 -0
  55. package/dist/declarations/src/source/remote.d.ts +29 -0
  56. package/dist/declarations/src/val/array.d.ts +9 -0
  57. package/dist/declarations/src/val/index.d.ts +53 -0
  58. package/dist/declarations/src/val/object.d.ts +9 -0
  59. package/dist/declarations/src/val/primitive.d.ts +7 -0
  60. package/dist/index-2f1631cf.cjs.prod.js +1031 -0
  61. package/dist/index-55916dcd.esm.js +1000 -0
  62. package/dist/index-b49a2c60.cjs.dev.js +1031 -0
  63. package/dist/ops-6fae92a1.esm.js +12 -0
  64. package/dist/ops-87cdbafc.cjs.dev.js +14 -0
  65. package/dist/ops-ae4d1bc2.cjs.prod.js +14 -0
  66. package/dist/result-26f67b40.cjs.prod.js +299 -0
  67. package/dist/result-48320acd.cjs.dev.js +299 -0
  68. package/dist/result-b96df128.esm.js +279 -0
  69. package/dist/util-030d8a1f.cjs.prod.js +29 -0
  70. package/dist/util-18613e99.esm.js +26 -0
  71. package/dist/util-b213092b.cjs.dev.js +29 -0
  72. package/dist/valbuild-core.cjs.d.ts +2 -0
  73. package/dist/valbuild-core.cjs.d.ts.map +1 -0
  74. package/dist/valbuild-core.cjs.dev.js +1276 -0
  75. package/dist/valbuild-core.cjs.js +7 -0
  76. package/dist/valbuild-core.cjs.prod.js +1276 -0
  77. package/dist/valbuild-core.esm.js +1265 -0
  78. package/expr/dist/valbuild-core-expr.cjs.d.ts +2 -0
  79. package/expr/dist/valbuild-core-expr.cjs.d.ts.map +1 -0
  80. package/expr/dist/valbuild-core-expr.cjs.dev.js +18 -0
  81. package/expr/dist/valbuild-core-expr.cjs.js +7 -0
  82. package/expr/dist/valbuild-core-expr.cjs.prod.js +18 -0
  83. package/expr/dist/valbuild-core-expr.esm.js +3 -0
  84. package/expr/package.json +4 -0
  85. package/fp/dist/valbuild-core-fp.cjs.d.ts +2 -0
  86. package/fp/dist/valbuild-core-fp.cjs.d.ts.map +1 -0
  87. package/fp/dist/valbuild-core-fp.cjs.dev.js +13 -0
  88. package/fp/dist/valbuild-core-fp.cjs.js +7 -0
  89. package/fp/dist/valbuild-core-fp.cjs.prod.js +13 -0
  90. package/fp/dist/valbuild-core-fp.esm.js +2 -0
  91. package/fp/package.json +4 -0
  92. package/package.json +43 -0
  93. package/patch/dist/valbuild-core-patch.cjs.d.ts +2 -0
  94. package/patch/dist/valbuild-core-patch.cjs.d.ts.map +1 -0
  95. package/patch/dist/valbuild-core-patch.cjs.dev.js +443 -0
  96. package/patch/dist/valbuild-core-patch.cjs.js +7 -0
  97. package/patch/dist/valbuild-core-patch.cjs.prod.js +443 -0
  98. package/patch/dist/valbuild-core-patch.esm.js +431 -0
  99. package/patch/package.json +4 -0
  100. package/tsconfig.json +7 -0
@@ -0,0 +1,1276 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var expr_dist_valbuildCoreExpr = require('./index-2f1631cf.cjs.prod.js');
6
+ var createClass = require('./createClass-de7426aa.cjs.prod.js');
7
+ var result = require('./result-26f67b40.cjs.prod.js');
8
+ var ops = require('./ops-ae4d1bc2.cjs.prod.js');
9
+
10
+ var ObjectSchema = /*#__PURE__*/function (_Schema) {
11
+ expr_dist_valbuildCoreExpr._inherits(ObjectSchema, _Schema);
12
+ var _super = expr_dist_valbuildCoreExpr._createSuper(ObjectSchema);
13
+ function ObjectSchema(items) {
14
+ var _this;
15
+ var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
16
+ createClass._classCallCheck(this, ObjectSchema);
17
+ _this = _super.call(this);
18
+ _this.items = items;
19
+ _this.opt = opt;
20
+ return _this;
21
+ }
22
+ createClass._createClass(ObjectSchema, [{
23
+ key: "validate",
24
+ value: function validate(src) {
25
+ throw new Error("Method not implemented.");
26
+ }
27
+ }, {
28
+ key: "match",
29
+ value: function match(src) {
30
+ if (this.opt && (src === null || src === undefined)) {
31
+ return true;
32
+ }
33
+ if (!src) {
34
+ return false;
35
+ }
36
+
37
+ // TODO: checks all props
38
+
39
+ return createClass._typeof(src) === "object" && !Array.isArray(src);
40
+ }
41
+ }, {
42
+ key: "optional",
43
+ value: function optional() {
44
+ return new ObjectSchema(this.items, true);
45
+ }
46
+ }, {
47
+ key: "serialize",
48
+ value: function serialize() {
49
+ return {
50
+ type: "object",
51
+ items: Object.fromEntries(Object.entries(this.items).map(function (_ref) {
52
+ var _ref2 = createClass._slicedToArray(_ref, 2),
53
+ key = _ref2[0],
54
+ schema = _ref2[1];
55
+ return [key, schema.serialize()];
56
+ })),
57
+ opt: this.opt
58
+ };
59
+ }
60
+ }]);
61
+ return ObjectSchema;
62
+ }(expr_dist_valbuildCoreExpr.Schema);
63
+ var object = function object(schema) {
64
+ return new ObjectSchema(schema);
65
+ };
66
+
67
+ var ArraySchema = /*#__PURE__*/function (_Schema) {
68
+ expr_dist_valbuildCoreExpr._inherits(ArraySchema, _Schema);
69
+ var _super = expr_dist_valbuildCoreExpr._createSuper(ArraySchema);
70
+ function ArraySchema(item) {
71
+ var _this;
72
+ var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
73
+ createClass._classCallCheck(this, ArraySchema);
74
+ _this = _super.call(this);
75
+ _this.item = item;
76
+ _this.opt = opt;
77
+ return _this;
78
+ }
79
+ createClass._createClass(ArraySchema, [{
80
+ key: "validate",
81
+ value: function validate(src) {
82
+ throw new Error("Method not implemented.");
83
+ }
84
+ }, {
85
+ key: "match",
86
+ value: function match(src) {
87
+ if (this.opt && (src === null || src === undefined)) {
88
+ return true;
89
+ }
90
+ if (!src) {
91
+ return false;
92
+ }
93
+
94
+ // TODO: checks all items
95
+ return createClass._typeof(src) === "object" && Array.isArray(src);
96
+ }
97
+ }, {
98
+ key: "optional",
99
+ value: function optional() {
100
+ return new ArraySchema(this.item, true);
101
+ }
102
+ }, {
103
+ key: "serialize",
104
+ value: function serialize() {
105
+ return {
106
+ type: "array",
107
+ item: this.item.serialize(),
108
+ opt: this.opt
109
+ };
110
+ }
111
+ }]);
112
+ return ArraySchema;
113
+ }(expr_dist_valbuildCoreExpr.Schema);
114
+ var array = function array(schema) {
115
+ return new ArraySchema(schema);
116
+ };
117
+
118
+ var I18nSchema = /*#__PURE__*/function (_Schema) {
119
+ expr_dist_valbuildCoreExpr._inherits(I18nSchema, _Schema);
120
+ var _super = expr_dist_valbuildCoreExpr._createSuper(I18nSchema);
121
+ function I18nSchema(locales, item) {
122
+ var _this;
123
+ var opt = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
124
+ createClass._classCallCheck(this, I18nSchema);
125
+ _this = _super.call(this);
126
+ _this.locales = locales;
127
+ _this.item = item;
128
+ _this.opt = opt;
129
+ return _this;
130
+ }
131
+ createClass._createClass(I18nSchema, [{
132
+ key: "validate",
133
+ value: function validate(src) {
134
+ throw new Error("Method not implemented.");
135
+ }
136
+ }, {
137
+ key: "match",
138
+ value: function match(src) {
139
+ throw new Error("Method not implemented.");
140
+ }
141
+ }, {
142
+ key: "optional",
143
+ value: function optional() {
144
+ return new I18nSchema(this.locales, this.item, true);
145
+ }
146
+ }, {
147
+ key: "serialize",
148
+ value: function serialize() {
149
+ return {
150
+ type: "i18n",
151
+ item: this.item.serialize(),
152
+ locales: this.locales,
153
+ opt: this.opt
154
+ };
155
+ }
156
+ }]);
157
+ return I18nSchema;
158
+ }(expr_dist_valbuildCoreExpr.Schema);
159
+ var i18n$1 = function i18n(locales) {
160
+ return function (schema) {
161
+ return new I18nSchema(locales, schema);
162
+ };
163
+ };
164
+
165
+ var UnionSchema = /*#__PURE__*/function (_Schema) {
166
+ expr_dist_valbuildCoreExpr._inherits(UnionSchema, _Schema);
167
+ var _super = expr_dist_valbuildCoreExpr._createSuper(UnionSchema);
168
+ function UnionSchema(key, items) {
169
+ var _this;
170
+ var opt = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
171
+ createClass._classCallCheck(this, UnionSchema);
172
+ _this = _super.call(this);
173
+ _this.key = key;
174
+ _this.items = items;
175
+ _this.opt = opt;
176
+ return _this;
177
+ }
178
+ createClass._createClass(UnionSchema, [{
179
+ key: "validate",
180
+ value: function validate(src) {
181
+ throw new Error("Method not implemented.");
182
+ }
183
+ }, {
184
+ key: "match",
185
+ value: function match(src) {
186
+ throw new Error("Method not implemented.");
187
+ }
188
+ }, {
189
+ key: "optional",
190
+ value: function optional() {
191
+ throw new Error("Method not implemented.");
192
+ }
193
+ }, {
194
+ key: "serialize",
195
+ value: function serialize() {
196
+ return {
197
+ type: "union",
198
+ key: this.key,
199
+ items: this.items.map(function (o) {
200
+ return o.serialize();
201
+ }),
202
+ opt: this.opt
203
+ };
204
+ }
205
+ }]);
206
+ return UnionSchema;
207
+ }(expr_dist_valbuildCoreExpr.Schema);
208
+ var union = function union(key) {
209
+ for (var _len = arguments.length, objects = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
210
+ objects[_key - 1] = arguments[_key];
211
+ }
212
+ return new UnionSchema(key, objects);
213
+ };
214
+
215
+ var OneOfSchema = /*#__PURE__*/function (_Schema) {
216
+ expr_dist_valbuildCoreExpr._inherits(OneOfSchema, _Schema);
217
+ var _super = expr_dist_valbuildCoreExpr._createSuper(OneOfSchema);
218
+ function OneOfSchema(selector) {
219
+ var _this;
220
+ var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
221
+ createClass._classCallCheck(this, OneOfSchema);
222
+ _this = _super.call(this);
223
+ _this.selector = selector;
224
+ _this.opt = opt;
225
+ return _this;
226
+ }
227
+ createClass._createClass(OneOfSchema, [{
228
+ key: "validate",
229
+ value: function validate(src) {
230
+ throw new Error("Method not implemented.");
231
+ }
232
+ }, {
233
+ key: "match",
234
+ value: function match(src) {
235
+ throw new Error("Method not implemented.");
236
+ }
237
+ }, {
238
+ key: "optional",
239
+ value: function optional() {
240
+ return new OneOfSchema(this.selector, true);
241
+ }
242
+ }, {
243
+ key: "serialize",
244
+ value: function serialize() {
245
+ var path = expr_dist_valbuildCoreExpr.getValPath(this.selector);
246
+ if (!path) {
247
+ throw new Error("Cannot serialize oneOf schema with empty selector. Make sure a Val module is used.");
248
+ }
249
+ return {
250
+ type: "oneOf",
251
+ selector: path,
252
+ opt: this.opt
253
+ };
254
+ }
255
+ }]);
256
+ return OneOfSchema;
257
+ }(expr_dist_valbuildCoreExpr.Schema);
258
+ var oneOf = function oneOf(valModule) {
259
+ return new OneOfSchema(valModule);
260
+ };
261
+
262
+ var RichTextSchema = /*#__PURE__*/function (_Schema) {
263
+ expr_dist_valbuildCoreExpr._inherits(RichTextSchema, _Schema);
264
+ var _super = expr_dist_valbuildCoreExpr._createSuper(RichTextSchema);
265
+ function RichTextSchema() {
266
+ var _this;
267
+ var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
268
+ createClass._classCallCheck(this, RichTextSchema);
269
+ _this = _super.call(this);
270
+ _this.opt = opt;
271
+ return _this;
272
+ }
273
+ createClass._createClass(RichTextSchema, [{
274
+ key: "validate",
275
+ value: function validate(src) {
276
+ throw new Error("Method not implemented.");
277
+ }
278
+ }, {
279
+ key: "match",
280
+ value: function match(src) {
281
+ // TODO:
282
+ return true;
283
+ }
284
+ }, {
285
+ key: "optional",
286
+ value: function optional() {
287
+ return new RichTextSchema(true);
288
+ }
289
+ }, {
290
+ key: "serialize",
291
+ value: function serialize() {
292
+ return {
293
+ type: "richtext",
294
+ opt: this.opt
295
+ };
296
+ }
297
+ }]);
298
+ return RichTextSchema;
299
+ }(expr_dist_valbuildCoreExpr.Schema);
300
+ var richtext = function richtext() {
301
+ return new RichTextSchema();
302
+ };
303
+ {
304
+ content("/test/richtext1", richtext(), {
305
+ children: [{
306
+ children: [{
307
+ detail: 0,
308
+ format: 0,
309
+ mode: "normal",
310
+ style: "",
311
+ text: "Heading 1",
312
+ type: "text",
313
+ version: 1
314
+ }],
315
+ direction: "ltr",
316
+ format: "",
317
+ indent: 0,
318
+ type: "heading",
319
+ version: 1,
320
+ tag: "h1"
321
+ }, {
322
+ children: [{
323
+ detail: 0,
324
+ format: 0,
325
+ mode: "normal",
326
+ style: "",
327
+ text: "Heading 2",
328
+ type: "text",
329
+ version: 1
330
+ }],
331
+ direction: "ltr",
332
+ format: "",
333
+ indent: 0,
334
+ type: "heading",
335
+ version: 1,
336
+ tag: "h2"
337
+ }, {
338
+ children: [],
339
+ direction: "ltr",
340
+ format: "",
341
+ indent: 0,
342
+ type: "paragraph",
343
+ version: 1
344
+ }, {
345
+ children: [{
346
+ detail: 0,
347
+ format: 0,
348
+ mode: "normal",
349
+ style: "",
350
+ text: "Normal",
351
+ type: "text",
352
+ version: 1
353
+ }],
354
+ direction: "ltr",
355
+ format: "",
356
+ indent: 0,
357
+ type: "paragraph",
358
+ version: 1
359
+ }, {
360
+ children: [{
361
+ detail: 0,
362
+ format: 0,
363
+ mode: "normal",
364
+ style: "font-size: 20px;",
365
+ text: "Normal Font size 20",
366
+ type: "text",
367
+ version: 1
368
+ }],
369
+ direction: "ltr",
370
+ format: "",
371
+ indent: 0,
372
+ type: "paragraph",
373
+ version: 1
374
+ }, {
375
+ children: [{
376
+ detail: 0,
377
+ format: 0,
378
+ mode: "normal",
379
+ style: "font-family: serif;",
380
+ text: "Normal font type serif",
381
+ type: "text",
382
+ version: 1
383
+ }],
384
+ direction: "ltr",
385
+ format: "",
386
+ indent: 0,
387
+ type: "paragraph",
388
+ version: 1
389
+ }, {
390
+ children: [{
391
+ detail: 0,
392
+ format: 1,
393
+ mode: "normal",
394
+ style: "font-family: serif;",
395
+ text: "Serif and bold",
396
+ type: "text",
397
+ version: 1
398
+ }],
399
+ direction: "ltr",
400
+ format: "",
401
+ indent: 0,
402
+ type: "paragraph",
403
+ version: 1
404
+ }, {
405
+ children: [{
406
+ detail: 0,
407
+ format: 2,
408
+ mode: "normal",
409
+ style: "",
410
+ text: "Arial and italic",
411
+ type: "text",
412
+ version: 1
413
+ }],
414
+ direction: "ltr",
415
+ format: "",
416
+ indent: 0,
417
+ type: "paragraph",
418
+ version: 1
419
+ }, {
420
+ children: [],
421
+ direction: null,
422
+ format: "",
423
+ indent: 0,
424
+ type: "paragraph",
425
+ version: 1
426
+ }, {
427
+ children: [{
428
+ children: [{
429
+ detail: 0,
430
+ format: 0,
431
+ mode: "normal",
432
+ style: "",
433
+ text: "Num list 1",
434
+ type: "text",
435
+ version: 1
436
+ }],
437
+ direction: "ltr",
438
+ format: "",
439
+ indent: 0,
440
+ type: "listitem",
441
+ version: 1,
442
+ value: 1
443
+ }, {
444
+ children: [{
445
+ detail: 0,
446
+ format: 0,
447
+ mode: "normal",
448
+ style: "",
449
+ text: "Num list 2",
450
+ type: "text",
451
+ version: 1
452
+ }
453
+ // TODO: image
454
+ // {
455
+ // altText: "",
456
+ // height: 0,
457
+ // maxWidth: 0,
458
+ // src: "https://picsum.photos/id/237/200/300",
459
+ // type: "image",
460
+ // version: 1,
461
+ // width: 0,
462
+ // },
463
+ ],
464
+
465
+ direction: "ltr",
466
+ format: "",
467
+ indent: 0,
468
+ type: "listitem",
469
+ version: 1,
470
+ value: 2
471
+ }],
472
+ direction: "ltr",
473
+ format: "",
474
+ indent: 0,
475
+ type: "list",
476
+ version: 1,
477
+ listType: "number",
478
+ start: 1,
479
+ tag: "ol"
480
+ }, {
481
+ children: [],
482
+ direction: null,
483
+ format: "",
484
+ indent: 0,
485
+ type: "paragraph",
486
+ version: 1
487
+ }, {
488
+ children: [{
489
+ children: [{
490
+ detail: 0,
491
+ format: 0,
492
+ mode: "normal",
493
+ style: "",
494
+ text: "Bullet list 1",
495
+ type: "text",
496
+ version: 1
497
+ }],
498
+ direction: "ltr",
499
+ format: "",
500
+ indent: 0,
501
+ type: "listitem",
502
+ version: 1,
503
+ value: 1
504
+ }, {
505
+ children: [{
506
+ detail: 0,
507
+ format: 0,
508
+ mode: "normal",
509
+ style: "",
510
+ text: "Bullet list 2",
511
+ type: "text",
512
+ version: 1
513
+ }],
514
+ direction: "ltr",
515
+ format: "",
516
+ indent: 0,
517
+ type: "listitem",
518
+ version: 1,
519
+ value: 2
520
+ }],
521
+ direction: "ltr",
522
+ format: "",
523
+ indent: 0,
524
+ type: "list",
525
+ version: 1,
526
+ listType: "bullet",
527
+ start: 1,
528
+ tag: "ul"
529
+ }, {
530
+ children: [],
531
+ direction: null,
532
+ format: "",
533
+ indent: 0,
534
+ type: "paragraph",
535
+ version: 1
536
+ }, {
537
+ children: [],
538
+ direction: "ltr",
539
+ format: "",
540
+ indent: 0,
541
+ type: "paragraph",
542
+ version: 1
543
+ }, {
544
+ children: [],
545
+ direction: null,
546
+ format: "",
547
+ indent: 0,
548
+ type: "paragraph",
549
+ version: 1
550
+ }],
551
+ direction: "ltr",
552
+ format: "",
553
+ indent: 0,
554
+ type: "root",
555
+ version: 1
556
+ });
557
+ }
558
+
559
+ function content(
560
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
561
+ id,
562
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
563
+ schema,
564
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
565
+ source) {
566
+ return expr_dist_valbuildCoreExpr.newSelectorProxy(source, id, schema);
567
+ }
568
+ function getRawSource(valModule) {
569
+ var sourceOrExpr = valModule[expr_dist_valbuildCoreExpr.SourceOrExpr];
570
+ if (sourceOrExpr instanceof expr_dist_valbuildCoreExpr.Expr) {
571
+ throw Error("Cannot get raw source of an Expr");
572
+ }
573
+ var source = sourceOrExpr;
574
+ return source;
575
+ }
576
+ function splitModuleIdAndModulePath(path) {
577
+ return [path.slice(0, path.indexOf(".")), path.slice(path.indexOf(".") + 1)];
578
+ }
579
+ function isObjectSchema(schema) {
580
+ return schema instanceof ObjectSchema || createClass._typeof(schema) === "object" && "type" in schema && schema.type === "object";
581
+ }
582
+ function isArraySchema(schema) {
583
+ return schema instanceof ArraySchema || createClass._typeof(schema) === "object" && "type" in schema && schema.type === "array";
584
+ }
585
+ function isI18nSchema(schema) {
586
+ return schema instanceof I18nSchema || createClass._typeof(schema) === "object" && "type" in schema && schema.type === "i18n";
587
+ }
588
+ function isUnionSchema(schema) {
589
+ return schema instanceof UnionSchema || createClass._typeof(schema) === "object" && "type" in schema && schema.type === "union";
590
+ }
591
+
592
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
593
+ function isRichTextSchema(schema) {
594
+ return schema instanceof RichTextSchema || createClass._typeof(schema) === "object" && "type" in schema && schema.type === "richtext";
595
+ }
596
+ function isImageSchema(schema) {
597
+ return schema instanceof expr_dist_valbuildCoreExpr.ImageSchema || createClass._typeof(schema) === "object" && "type" in schema && schema.type === "image";
598
+ }
599
+ function resolvePath(path, valModule, schema) {
600
+ var parts = parsePath(path);
601
+ var origParts = createClass._toConsumableArray(parts);
602
+ var resolvedSchema = schema;
603
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
604
+ var resolvedSource = valModule;
605
+ var _loop = function _loop() {
606
+ var part = parts.shift();
607
+ if (part === undefined) {
608
+ throw Error("Unexpected undefined part");
609
+ }
610
+ if (isArraySchema(resolvedSchema)) {
611
+ if (Number.isNaN(Number(part))) {
612
+ throw Error("Invalid path: array schema ".concat(resolvedSchema, " must have ").concat(part, " a number as path"));
613
+ }
614
+ if (createClass._typeof(resolvedSource) !== "object" && !Array.isArray(resolvedSource)) {
615
+ throw Error("Schema type error: expected source to be type of array, but got ".concat(createClass._typeof(resolvedSource)));
616
+ }
617
+ if (!resolvedSource[part]) {
618
+ var _resolvedSource;
619
+ 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));
620
+ }
621
+ resolvedSource = resolvedSource[part];
622
+ resolvedSchema = resolvedSchema.item;
623
+ } else if (isObjectSchema(resolvedSchema)) {
624
+ if (createClass._typeof(resolvedSource) !== "object") {
625
+ throw Error("Schema type error: expected source to be type of object, but got ".concat(createClass._typeof(resolvedSource)));
626
+ }
627
+ if (!resolvedSource[part]) {
628
+ throw Error("Invalid path: object source did not have key ".concat(part, " from path: ").concat(path));
629
+ }
630
+ resolvedSource = resolvedSource[part];
631
+ resolvedSchema = resolvedSchema.items[part];
632
+ } else if (isI18nSchema(resolvedSchema)) {
633
+ if (!resolvedSchema.locales.includes(part)) {
634
+ throw Error("Invalid path: i18n schema ".concat(resolvedSchema, " supports locales ").concat(resolvedSchema.locales.join(", "), ", but found: ").concat(part));
635
+ }
636
+ if (!Object.keys(resolvedSource).includes(part)) {
637
+ throw Error("Schema type error: expected source to be type of i18n with locale ".concat(part, ", but got ").concat(JSON.stringify(Object.keys(resolvedSource))));
638
+ }
639
+ resolvedSource = resolvedSource[part];
640
+ resolvedSchema = resolvedSchema.item;
641
+ } else if (isImageSchema(resolvedSchema)) {
642
+ return {
643
+ v: {
644
+ path: origParts.slice(0, origParts.length - parts.length - 1).map(function (p) {
645
+ return JSON.stringify(p);
646
+ }).join("."),
647
+ // TODO: create a function generate path from parts (not sure if this always works)
648
+ schema: resolvedSchema,
649
+ source: resolvedSource
650
+ }
651
+ };
652
+ } else if (isUnionSchema(resolvedSchema)) {
653
+ var _key = resolvedSchema.key;
654
+ var keyValue = resolvedSource[_key];
655
+ if (!keyValue) {
656
+ throw Error("Invalid path: union source ".concat(resolvedSchema, " did not have required key ").concat(_key, " in path: ").concat(path));
657
+ }
658
+ var schemaOfUnionKey = resolvedSchema.items.find(
659
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
660
+ function (child) {
661
+ var _child$items, _child$items$_key;
662
+ return (child === null || child === void 0 ? void 0 : (_child$items = child.items) === null || _child$items === void 0 ? void 0 : (_child$items$_key = _child$items[_key]) === null || _child$items$_key === void 0 ? void 0 : _child$items$_key.value) === keyValue;
663
+ });
664
+ if (!schemaOfUnionKey) {
665
+ 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));
666
+ }
667
+ resolvedSchema = schemaOfUnionKey.items[part];
668
+ resolvedSource = resolvedSource[part];
669
+ } else if (isRichTextSchema(resolvedSchema)) {
670
+ return {
671
+ v: {
672
+ path: origParts.slice(0, origParts.length - parts.length - 1).map(function (p) {
673
+ return JSON.stringify(p);
674
+ }).join("."),
675
+ // TODO: create a function generate path from parts (not sure if this always works)
676
+ schema: resolvedSchema,
677
+ source: resolvedSource
678
+ }
679
+ };
680
+ } else {
681
+ throw Error("Invalid path: ".concat(part, " resolved to an unexpected schema ").concat(JSON.stringify(resolvedSchema)));
682
+ }
683
+ };
684
+ while (parts.length > 0) {
685
+ var _ret = _loop();
686
+ if (createClass._typeof(_ret) === "object") return _ret.v;
687
+ }
688
+ if (parts.length > 0) {
689
+ throw Error("Invalid path: ".concat(parts.join("."), " is not a valid path"));
690
+ }
691
+ return {
692
+ path: path,
693
+ schema: resolvedSchema,
694
+ source: resolvedSource
695
+ };
696
+ }
697
+ function parsePath(input) {
698
+ var result = [];
699
+ var i = 0;
700
+ while (i < input.length) {
701
+ var part = "";
702
+ if (input[i] === '"') {
703
+ // Parse a quoted string
704
+ i++;
705
+ while (i < input.length && input[i] !== '"') {
706
+ if (input[i] === "\\" && input[i + 1] === '"') {
707
+ // Handle escaped double quotes
708
+ part += '"';
709
+ i++;
710
+ } else {
711
+ part += input[i];
712
+ }
713
+ i++;
714
+ }
715
+ if (input[i] !== '"') {
716
+ var _input$i;
717
+ 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, ")"));
718
+ }
719
+ } else {
720
+ // Parse a regular string
721
+ while (i < input.length && input[i] !== ".") {
722
+ part += input[i];
723
+ i++;
724
+ }
725
+ }
726
+ if (part !== "") {
727
+ result.push(part);
728
+ }
729
+ i++;
730
+ }
731
+ return result;
732
+ }
733
+
734
+ /**
735
+ * I18n sources cannot have nested remote sources.
736
+ */
737
+
738
+ /**
739
+ * An i18n source is a map of locales to sources.
740
+ *
741
+ * Its selector will default to the underlying source. It is possible to call `.all` on i18n sources, which returns an object with all the locales
742
+ *
743
+ */
744
+
745
+ function i18n(
746
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
747
+ locales) {
748
+ return function (source) {
749
+ return expr_dist_valbuildCoreExpr._objectSpread2(expr_dist_valbuildCoreExpr._objectSpread2({}, source), {}, expr_dist_valbuildCoreExpr._defineProperty({}, expr_dist_valbuildCoreExpr.VAL_EXTENSION, "i18n"));
750
+ };
751
+ }
752
+
753
+ var NumberSchema = /*#__PURE__*/function (_Schema) {
754
+ expr_dist_valbuildCoreExpr._inherits(NumberSchema, _Schema);
755
+ var _super = expr_dist_valbuildCoreExpr._createSuper(NumberSchema);
756
+ function NumberSchema(options) {
757
+ var _this;
758
+ var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
759
+ createClass._classCallCheck(this, NumberSchema);
760
+ _this = _super.call(this);
761
+ _this.options = options;
762
+ _this.opt = opt;
763
+ return _this;
764
+ }
765
+ createClass._createClass(NumberSchema, [{
766
+ key: "validate",
767
+ value: function validate(src) {
768
+ throw new Error("Method not implemented.");
769
+ }
770
+ }, {
771
+ key: "match",
772
+ value: function match(src) {
773
+ if (this.opt && (src === null || src === undefined)) {
774
+ return true;
775
+ }
776
+ return typeof src === "number";
777
+ }
778
+ }, {
779
+ key: "optional",
780
+ value: function optional() {
781
+ return new NumberSchema(this.options, true);
782
+ }
783
+ }, {
784
+ key: "serialize",
785
+ value: function serialize() {
786
+ return {
787
+ type: "number",
788
+ options: this.options,
789
+ opt: this.opt
790
+ };
791
+ }
792
+ }]);
793
+ return NumberSchema;
794
+ }(expr_dist_valbuildCoreExpr.Schema);
795
+ var number = function number(options) {
796
+ return new NumberSchema(options);
797
+ };
798
+
799
+ var StringSchema = /*#__PURE__*/function (_Schema) {
800
+ expr_dist_valbuildCoreExpr._inherits(StringSchema, _Schema);
801
+ var _super = expr_dist_valbuildCoreExpr._createSuper(StringSchema);
802
+ function StringSchema(options) {
803
+ var _this;
804
+ var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
805
+ createClass._classCallCheck(this, StringSchema);
806
+ _this = _super.call(this);
807
+ _this.options = options;
808
+ _this.opt = opt;
809
+ return _this;
810
+ }
811
+ createClass._createClass(StringSchema, [{
812
+ key: "validate",
813
+ value: function validate(src) {
814
+ throw new Error("Method not implemented.");
815
+ }
816
+ }, {
817
+ key: "match",
818
+ value: function match(src) {
819
+ if (this.opt && (src === null || src === undefined)) {
820
+ return true;
821
+ }
822
+ return typeof src === "string";
823
+ }
824
+ }, {
825
+ key: "optional",
826
+ value: function optional() {
827
+ return new StringSchema(this.options, true);
828
+ }
829
+ }, {
830
+ key: "serialize",
831
+ value: function serialize() {
832
+ return {
833
+ type: "string",
834
+ options: this.options,
835
+ opt: this.opt
836
+ };
837
+ }
838
+ }]);
839
+ return StringSchema;
840
+ }(expr_dist_valbuildCoreExpr.Schema);
841
+ var string = function string(options) {
842
+ return new StringSchema(options);
843
+ };
844
+
845
+ var BooleanSchema = /*#__PURE__*/function (_Schema) {
846
+ expr_dist_valbuildCoreExpr._inherits(BooleanSchema, _Schema);
847
+ var _super = expr_dist_valbuildCoreExpr._createSuper(BooleanSchema);
848
+ function BooleanSchema() {
849
+ var _this;
850
+ var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
851
+ createClass._classCallCheck(this, BooleanSchema);
852
+ _this = _super.call(this);
853
+ _this.opt = opt;
854
+ return _this;
855
+ }
856
+ createClass._createClass(BooleanSchema, [{
857
+ key: "validate",
858
+ value: function validate(src) {
859
+ throw new Error("Method not implemented.");
860
+ }
861
+ }, {
862
+ key: "match",
863
+ value: function match(src) {
864
+ if (this.opt && (src === null || src === undefined)) {
865
+ return true;
866
+ }
867
+ return typeof src === "boolean";
868
+ }
869
+ }, {
870
+ key: "optional",
871
+ value: function optional() {
872
+ return new BooleanSchema(true);
873
+ }
874
+ }, {
875
+ key: "serialize",
876
+ value: function serialize() {
877
+ return {
878
+ type: "boolean",
879
+ opt: this.opt
880
+ };
881
+ }
882
+ }]);
883
+ return BooleanSchema;
884
+ }(expr_dist_valbuildCoreExpr.Schema);
885
+ var _boolean = function _boolean() {
886
+ return new BooleanSchema();
887
+ };
888
+
889
+ var LiteralSchema = /*#__PURE__*/function (_Schema) {
890
+ expr_dist_valbuildCoreExpr._inherits(LiteralSchema, _Schema);
891
+ var _super = expr_dist_valbuildCoreExpr._createSuper(LiteralSchema);
892
+ function LiteralSchema(value) {
893
+ var _this;
894
+ var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
895
+ createClass._classCallCheck(this, LiteralSchema);
896
+ _this = _super.call(this);
897
+ _this.value = value;
898
+ _this.opt = opt;
899
+ return _this;
900
+ }
901
+ createClass._createClass(LiteralSchema, [{
902
+ key: "validate",
903
+ value: function validate(src) {
904
+ throw new Error("Method not implemented.");
905
+ }
906
+ }, {
907
+ key: "match",
908
+ value: function match(src) {
909
+ if (this.opt && (src === null || src === undefined)) {
910
+ return true;
911
+ }
912
+ return typeof src === "string";
913
+ }
914
+ }, {
915
+ key: "optional",
916
+ value: function optional() {
917
+ return new LiteralSchema(this.value, true);
918
+ }
919
+ }, {
920
+ key: "serialize",
921
+ value: function serialize() {
922
+ return {
923
+ type: "literal",
924
+ value: this.value,
925
+ opt: this.opt
926
+ };
927
+ }
928
+ }]);
929
+ return LiteralSchema;
930
+ }(expr_dist_valbuildCoreExpr.Schema);
931
+ var literal = function literal(value) {
932
+ return new LiteralSchema(value);
933
+ };
934
+
935
+ function initSchema(locales) {
936
+ return {
937
+ string: string,
938
+ "boolean": _boolean,
939
+ array: array,
940
+ object: object,
941
+ number: number,
942
+ union: union,
943
+ oneOf: oneOf,
944
+ richtext: richtext,
945
+ image: expr_dist_valbuildCoreExpr.image,
946
+ literal: literal,
947
+ i18n: i18n$1(locales)
948
+ };
949
+ }
950
+
951
+ function fetchVal(selector, locale) {
952
+ return Promise.resolve(getVal(selector));
953
+ }
954
+ function getVal(selector,
955
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
956
+ locale) {
957
+ return newValProxy(serializedValOfSelectorSource(selector));
958
+ }
959
+
960
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
961
+ function isArrayOrArraySelector(child) {
962
+ if (expr_dist_valbuildCoreExpr.isSelector(child)) {
963
+ return createClass._typeof(child[expr_dist_valbuildCoreExpr.SourceOrExpr]) === "object" && createClass._typeof(child[expr_dist_valbuildCoreExpr.SourceOrExpr]) !== null && Array.isArray(child[expr_dist_valbuildCoreExpr.SourceOrExpr]);
964
+ }
965
+ return Array.isArray(child);
966
+ }
967
+
968
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
969
+ function isObjectOrObjectSelector(child) {
970
+ if (expr_dist_valbuildCoreExpr.isSelector(child)) {
971
+ return createClass._typeof(child[expr_dist_valbuildCoreExpr.SourceOrExpr]) === "object" && createClass._typeof(child[expr_dist_valbuildCoreExpr.SourceOrExpr]) !== null && !Array.isArray(child[expr_dist_valbuildCoreExpr.SourceOrExpr]);
972
+ }
973
+ return createClass._typeof(child) === "object";
974
+ }
975
+ function serializedValOfSelectorSource(selector) {
976
+ var wrappedSelector = expr_dist_valbuildCoreExpr.newSelectorProxy(selector); // NOTE: we do this if call-site uses a literal with selectors inside
977
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
978
+ function rec(child) {
979
+ var isArray = isArrayOrArraySelector(child);
980
+ var isObject = isObjectOrObjectSelector(child);
981
+ if (isArray) {
982
+ var array = expr_dist_valbuildCoreExpr.SourceOrExpr in child ? child[expr_dist_valbuildCoreExpr.SourceOrExpr] : child;
983
+ var valPath = expr_dist_valbuildCoreExpr.Path in child ? child[expr_dist_valbuildCoreExpr.Path] : undefined;
984
+ return {
985
+ val: array.map(function (item, i) {
986
+ return rec(expr_dist_valbuildCoreExpr.isSelector(item) // NOTE: We do this since selectors currently do not create selectors of items unless specifically required.
987
+ ? item : expr_dist_valbuildCoreExpr.newSelectorProxy(item, expr_dist_valbuildCoreExpr.createValPathOfItem(valPath, i)));
988
+ }),
989
+ valPath: valPath
990
+ };
991
+ } else if (isObject) {
992
+ var obj = expr_dist_valbuildCoreExpr.SourceOrExpr in child ? child[expr_dist_valbuildCoreExpr.SourceOrExpr] : child;
993
+ var _valPath = expr_dist_valbuildCoreExpr.Path in child ? child[expr_dist_valbuildCoreExpr.Path] : undefined;
994
+ return {
995
+ val: obj !== null && Object.fromEntries(Object.entries(obj).map(function (_ref) {
996
+ var _ref2 = createClass._slicedToArray(_ref, 2),
997
+ key = _ref2[0],
998
+ value = _ref2[1];
999
+ return [key, rec(expr_dist_valbuildCoreExpr.isSelector(value) // NOTE: We do this since selectors currently do not create selectors of items unless specifically required.
1000
+ ? value : expr_dist_valbuildCoreExpr.newSelectorProxy(value, expr_dist_valbuildCoreExpr.createValPathOfItem(_valPath, key)))];
1001
+ })),
1002
+ valPath: _valPath
1003
+ };
1004
+ } else if (expr_dist_valbuildCoreExpr.isSelector(child)) {
1005
+ return {
1006
+ val: rec(child[expr_dist_valbuildCoreExpr.SourceOrExpr]),
1007
+ valPath: child[expr_dist_valbuildCoreExpr.Path]
1008
+ };
1009
+ } else {
1010
+ return child;
1011
+ }
1012
+ }
1013
+ return rec(wrappedSelector);
1014
+ }
1015
+ function strip(value) {
1016
+ var val = expr_dist_valbuildCoreExpr.isSerializedVal(value) ? value.val : value;
1017
+ switch (createClass._typeof(val)) {
1018
+ case "function":
1019
+ case "symbol":
1020
+ throw Error("Invalid val type: ".concat(createClass._typeof(val)));
1021
+ case "object":
1022
+ if (val === null) {
1023
+ return null;
1024
+ } else if (Array.isArray(val)) {
1025
+ return val.map(strip);
1026
+ } else {
1027
+ return Object.fromEntries(Object.entries(val).map(function (_ref3) {
1028
+ var _ref4 = createClass._slicedToArray(_ref3, 2),
1029
+ key = _ref4[0],
1030
+ value = _ref4[1];
1031
+ return [key, value && strip(value)];
1032
+ }));
1033
+ }
1034
+ // intentional fallthrough
1035
+ // eslint-disable-next-line no-fallthrough
1036
+ default:
1037
+ return val;
1038
+ }
1039
+ }
1040
+ function newValProxy(val) {
1041
+ var _ref5;
1042
+ var source = val.val;
1043
+ switch (createClass._typeof(source)) {
1044
+ case "function":
1045
+ case "symbol":
1046
+ throw Error("Invalid val type: ".concat(createClass._typeof(source)));
1047
+ case "object":
1048
+ if (source !== null) {
1049
+ // Handles both objects and arrays!
1050
+ return new Proxy(source, {
1051
+ has: function has(target, prop) {
1052
+ if (prop === "val") {
1053
+ return true;
1054
+ }
1055
+ if (prop === expr_dist_valbuildCoreExpr.Path) {
1056
+ return true;
1057
+ }
1058
+ return hasOwn(target, prop);
1059
+ },
1060
+ get: function get(target, prop) {
1061
+ if (prop === expr_dist_valbuildCoreExpr.Path) {
1062
+ return val.valPath;
1063
+ }
1064
+ if (prop === "val") {
1065
+ return strip(val);
1066
+ }
1067
+ if (Array.isArray(target) && prop === "length") {
1068
+ return target.length;
1069
+ }
1070
+ if (hasOwn(source, prop)) {
1071
+ var _Reflect$get$valPath, _Reflect$get;
1072
+ return newValProxy({
1073
+ val: Reflect.get(target, prop).val,
1074
+ 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 : expr_dist_valbuildCoreExpr.createValPathOfItem(val.valPath, Array.isArray(target) ? Number(prop) : prop)
1075
+ });
1076
+ }
1077
+ return Reflect.get(target, prop);
1078
+ }
1079
+ });
1080
+ }
1081
+ // intentional fallthrough
1082
+ // eslint-disable-next-line no-fallthrough
1083
+ default:
1084
+ return _ref5 = {}, expr_dist_valbuildCoreExpr._defineProperty(_ref5, expr_dist_valbuildCoreExpr.Path, val.valPath), expr_dist_valbuildCoreExpr._defineProperty(_ref5, "val", val.val), _ref5;
1085
+ }
1086
+ }
1087
+ function hasOwn(obj, prop) {
1088
+ return Object.prototype.hasOwnProperty.call(obj, prop);
1089
+ }
1090
+
1091
+ /**
1092
+ * Remote sources cannot include other remote sources.
1093
+ */
1094
+
1095
+ var REMOTE_REF_PROP = "_ref"; // TODO: same as FILE_REF_PROP so use same prop?
1096
+
1097
+ /**
1098
+ * A remote source is a hash that represents a remote object.
1099
+ *
1100
+ * It will be resolved into a ValRemote object.
1101
+ */
1102
+
1103
+ function remote(ref) {
1104
+ var _ref;
1105
+ return _ref = {}, expr_dist_valbuildCoreExpr._defineProperty(_ref, REMOTE_REF_PROP, ref), expr_dist_valbuildCoreExpr._defineProperty(_ref, expr_dist_valbuildCoreExpr.VAL_EXTENSION, "remote"), _ref;
1106
+ }
1107
+ function isRemote(obj) {
1108
+ return createClass._typeof(obj) === "object" && obj !== null && expr_dist_valbuildCoreExpr.VAL_EXTENSION in obj && obj[expr_dist_valbuildCoreExpr.VAL_EXTENSION] === "remote" && REMOTE_REF_PROP in obj && typeof obj[REMOTE_REF_PROP] === "string";
1109
+ }
1110
+
1111
+ var initVal = function initVal(options) {
1112
+ var locales = options === null || options === void 0 ? void 0 : options.locales;
1113
+ var s = initSchema(locales === null || locales === void 0 ? void 0 : locales.required);
1114
+ if (locales !== null && locales !== void 0 && locales.required) {
1115
+ console.error("Locales / i18n currently not implemented");
1116
+ return {
1117
+ val: {
1118
+ content: content,
1119
+ i18n: i18n,
1120
+ remote: remote,
1121
+ getPath: expr_dist_valbuildCoreExpr.getValPath,
1122
+ key: expr_dist_valbuildCoreExpr.getValPath,
1123
+ file: expr_dist_valbuildCoreExpr.file
1124
+ },
1125
+ fetchVal: fetchVal,
1126
+ s: s
1127
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1128
+ };
1129
+ }
1130
+
1131
+ return {
1132
+ val: {
1133
+ content: content,
1134
+ remote: remote,
1135
+ getPath: expr_dist_valbuildCoreExpr.getValPath,
1136
+ key: expr_dist_valbuildCoreExpr.getValPath,
1137
+ file: expr_dist_valbuildCoreExpr.file
1138
+ },
1139
+ fetchVal: fetchVal,
1140
+ s: expr_dist_valbuildCoreExpr._objectSpread2(expr_dist_valbuildCoreExpr._objectSpread2({}, s), {}, {
1141
+ i18n: undefined
1142
+ })
1143
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1144
+ };
1145
+ };
1146
+
1147
+ function derefPath(path) {
1148
+ var dereffedPath = [];
1149
+ var referencedPath = null;
1150
+ var _iterator = result._createForOfIteratorHelper(path),
1151
+ _step;
1152
+ try {
1153
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
1154
+ var segment = _step.value;
1155
+ if (segment.startsWith("$")) {
1156
+ var dereffedSegment = segment.slice(1);
1157
+ dereffedPath.push(dereffedSegment);
1158
+ referencedPath = [];
1159
+ var _iterator2 = result._createForOfIteratorHelper(path.slice(dereffedPath.length)),
1160
+ _step2;
1161
+ try {
1162
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
1163
+ var _segment = _step2.value;
1164
+ if (_segment.startsWith("$")) {
1165
+ return result.err(new ops.PatchError("Cannot reference within reference: ".concat(_segment, ". Path: ").concat(path.join("/"))));
1166
+ }
1167
+ referencedPath.push(_segment);
1168
+ }
1169
+ } catch (err) {
1170
+ _iterator2.e(err);
1171
+ } finally {
1172
+ _iterator2.f();
1173
+ }
1174
+ break;
1175
+ } else {
1176
+ dereffedPath.push(segment);
1177
+ }
1178
+ }
1179
+ } catch (err) {
1180
+ _iterator.e(err);
1181
+ } finally {
1182
+ _iterator.f();
1183
+ }
1184
+ return result.ok([dereffedPath, referencedPath]);
1185
+ }
1186
+ function derefPatch(patch, document, ops$1) {
1187
+ var remotePatches = {};
1188
+ var fileUpdates = {};
1189
+ var dereferencedPatch = [];
1190
+ var _iterator3 = result._createForOfIteratorHelper(patch),
1191
+ _step3;
1192
+ try {
1193
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
1194
+ var op = _step3.value;
1195
+ if (op.op === "replace") {
1196
+ var maybeDerefRes = derefPath(op.path);
1197
+ if (result.isErr(maybeDerefRes)) {
1198
+ return maybeDerefRes;
1199
+ }
1200
+ var _maybeDerefRes$value = createClass._slicedToArray(maybeDerefRes.value, 2),
1201
+ dereffedPath = _maybeDerefRes$value[0],
1202
+ referencedPath = _maybeDerefRes$value[1];
1203
+ if (referencedPath) {
1204
+ var maybeValue = ops$1.get(document, dereffedPath);
1205
+ if (result.isOk(maybeValue)) {
1206
+ var value = maybeValue.value;
1207
+ if (expr_dist_valbuildCoreExpr.isFile(value)) {
1208
+ if (referencedPath.length > 0) {
1209
+ return result.err(new ops.PatchError("Cannot sub-reference file reference at path: ".concat(dereffedPath.join("/"))));
1210
+ }
1211
+ if (typeof op.value !== "string") {
1212
+ return result.err(new ops.PatchError("Expected base64 encoded string value for file reference, got ".concat(JSON.stringify(op.value))));
1213
+ }
1214
+ fileUpdates[value[expr_dist_valbuildCoreExpr.FILE_REF_PROP]] = op.value;
1215
+ } else if (isRemote(value)) {
1216
+ if (!remotePatches[value[REMOTE_REF_PROP]]) {
1217
+ remotePatches[value[REMOTE_REF_PROP]] = [];
1218
+ }
1219
+ remotePatches[value[REMOTE_REF_PROP]].push({
1220
+ op: "replace",
1221
+ path: referencedPath,
1222
+ value: op.value
1223
+ });
1224
+ } else {
1225
+ return result.err(new ops.PatchError("Unknown reference: ".concat(JSON.stringify(op), " at path: ").concat(dereffedPath.join("/"))));
1226
+ }
1227
+ } else {
1228
+ return maybeValue;
1229
+ }
1230
+ } else {
1231
+ dereferencedPatch.push(op);
1232
+ }
1233
+ } else {
1234
+ var _maybeDerefRes = derefPath(op.path);
1235
+ if (result.isErr(_maybeDerefRes)) {
1236
+ return _maybeDerefRes;
1237
+ }
1238
+ var _maybeDerefRes$value2 = createClass._slicedToArray(_maybeDerefRes.value, 2),
1239
+ _referencedPath = _maybeDerefRes$value2[1];
1240
+ if (_referencedPath) {
1241
+ throw new Error("Unimplemented operation: ".concat(JSON.stringify(op)));
1242
+ }
1243
+ dereferencedPatch.push(op);
1244
+ }
1245
+ }
1246
+ } catch (err) {
1247
+ _iterator3.e(err);
1248
+ } finally {
1249
+ _iterator3.f();
1250
+ }
1251
+ return result.ok({
1252
+ remotePatches: remotePatches,
1253
+ fileUpdates: fileUpdates,
1254
+ dereferencedPatch: dereferencedPatch
1255
+ });
1256
+ }
1257
+
1258
+ var Internal = {
1259
+ convertImageSource: expr_dist_valbuildCoreExpr.convertImageSource,
1260
+ getSchema: expr_dist_valbuildCoreExpr.getSchema,
1261
+ getValPath: expr_dist_valbuildCoreExpr.getValPath,
1262
+ getVal: getVal,
1263
+ getRawSource: getRawSource,
1264
+ resolvePath: resolvePath,
1265
+ splitModuleIdAndModulePath: splitModuleIdAndModulePath
1266
+ };
1267
+
1268
+ exports.FILE_REF_PROP = expr_dist_valbuildCoreExpr.FILE_REF_PROP;
1269
+ exports.GenericSelector = expr_dist_valbuildCoreExpr.GenericSelector;
1270
+ exports.Schema = expr_dist_valbuildCoreExpr.Schema;
1271
+ exports.VAL_EXTENSION = expr_dist_valbuildCoreExpr.VAL_EXTENSION;
1272
+ exports.expr = expr_dist_valbuildCoreExpr.index;
1273
+ exports.Internal = Internal;
1274
+ exports.derefPatch = derefPatch;
1275
+ exports.fetchVal = fetchVal;
1276
+ exports.initVal = initVal;