@valbuild/core 0.14.0 → 0.16.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 (66) hide show
  1. package/dist/SelectorProxy-2af1b2b8.cjs.prod.js +756 -0
  2. package/dist/SelectorProxy-63c2d0e2.esm.js +722 -0
  3. package/dist/SelectorProxy-873782a5.cjs.dev.js +756 -0
  4. package/dist/declarations/src/index.d.ts +2 -0
  5. package/dist/declarations/src/initVal.d.ts +1 -1
  6. package/dist/declarations/src/patch/index.d.ts +1 -1
  7. package/dist/declarations/src/patch/util.d.ts +2 -0
  8. package/dist/declarations/src/schema/array.d.ts +3 -2
  9. package/dist/declarations/src/schema/boolean.d.ts +3 -2
  10. package/dist/declarations/src/schema/i18n.d.ts +3 -2
  11. package/dist/declarations/src/schema/image.d.ts +3 -2
  12. package/dist/declarations/src/schema/index.d.ts +5 -2
  13. package/dist/declarations/src/schema/literal.d.ts +3 -2
  14. package/dist/declarations/src/schema/number.d.ts +3 -2
  15. package/dist/declarations/src/schema/object.d.ts +3 -2
  16. package/dist/declarations/src/schema/oneOf.d.ts +3 -2
  17. package/dist/declarations/src/schema/richtext.d.ts +3 -2
  18. package/dist/declarations/src/schema/string.d.ts +3 -2
  19. package/dist/declarations/src/schema/union.d.ts +3 -2
  20. package/dist/declarations/src/schema/validation/ValidationError.d.ts +14 -0
  21. package/dist/declarations/src/schema/validation/ValidationFix.d.ts +2 -0
  22. package/dist/index-2fff5ca8.cjs.dev.js +456 -0
  23. package/dist/{index-06df0a5b.esm.js → index-af761363.esm.js} +2 -555
  24. package/dist/index-cac9ecbd.cjs.prod.js +456 -0
  25. package/dist/ops-1b6e0e35.cjs.prod.js +552 -0
  26. package/dist/ops-74661336.esm.js +541 -0
  27. package/dist/ops-ea4827fc.cjs.dev.js +552 -0
  28. package/dist/valbuild-core.cjs.dev.js +151 -531
  29. package/dist/valbuild-core.cjs.prod.js +151 -531
  30. package/dist/valbuild-core.esm.js +65 -445
  31. package/expr/dist/valbuild-core-expr.cjs.dev.js +8 -8
  32. package/expr/dist/valbuild-core-expr.cjs.prod.js +8 -8
  33. package/expr/dist/valbuild-core-expr.esm.js +2 -2
  34. package/package.json +2 -1
  35. package/patch/dist/valbuild-core-patch.cjs.dev.js +30 -21
  36. package/patch/dist/valbuild-core-patch.cjs.prod.js +30 -21
  37. package/patch/dist/valbuild-core-patch.esm.js +12 -4
  38. package/src/expr/repl.ts +2 -2
  39. package/src/index.ts +5 -0
  40. package/src/initVal.ts +1 -1
  41. package/src/patch/index.ts +1 -0
  42. package/src/patch/util.ts +7 -0
  43. package/src/schema/array.ts +45 -4
  44. package/src/schema/boolean.ts +14 -3
  45. package/src/schema/i18n.ts +4 -2
  46. package/src/schema/image.ts +65 -5
  47. package/src/schema/index.ts +23 -2
  48. package/src/schema/literal.ts +24 -3
  49. package/src/schema/number.ts +14 -3
  50. package/src/schema/object.ts +50 -7
  51. package/src/schema/oneOf.ts +3 -2
  52. package/src/schema/richtext.ts +63 -3
  53. package/src/schema/string.ts +14 -3
  54. package/src/schema/union.ts +3 -2
  55. package/src/schema/validation/ValidationError.ts +16 -0
  56. package/src/schema/validation/ValidationFix.ts +6 -0
  57. package/src/schema/validation.test.ts +226 -0
  58. package/src/selector/SelectorProxy.ts +1 -1
  59. package/dist/createClass-012eebbf.esm.js +0 -109
  60. package/dist/createClass-a436dbfe.cjs.dev.js +0 -116
  61. package/dist/createClass-de7426aa.cjs.prod.js +0 -116
  62. package/dist/index-9663f28a.cjs.dev.js +0 -1037
  63. package/dist/index-b2270f8f.cjs.prod.js +0 -1037
  64. package/dist/ops-6fae92a1.esm.js +0 -12
  65. package/dist/ops-87cdbafc.cjs.dev.js +0 -14
  66. package/dist/ops-ae4d1bc2.cjs.prod.js +0 -14
@@ -0,0 +1,552 @@
1
+ 'use strict';
2
+
3
+ var SelectorProxy = require('./SelectorProxy-2af1b2b8.cjs.prod.js');
4
+ var result = require('./result-26f67b40.cjs.prod.js');
5
+
6
+ var ObjectSchema = /*#__PURE__*/function (_Schema) {
7
+ SelectorProxy._inherits(ObjectSchema, _Schema);
8
+ var _super = SelectorProxy._createSuper(ObjectSchema);
9
+ function ObjectSchema(items) {
10
+ var _this;
11
+ var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
12
+ SelectorProxy._classCallCheck(this, ObjectSchema);
13
+ _this = _super.call(this);
14
+ _this.items = items;
15
+ _this.opt = opt;
16
+ return _this;
17
+ }
18
+ SelectorProxy._createClass(ObjectSchema, [{
19
+ key: "validate",
20
+ value: function validate(path, src) {
21
+ var _this2 = this;
22
+ var error = false;
23
+ if (this.opt && (src === null || src === undefined)) {
24
+ return false;
25
+ }
26
+ if (SelectorProxy._typeof(src) !== "object") {
27
+ return SelectorProxy._defineProperty({}, path, [{
28
+ message: "Expected 'object', got '".concat(SelectorProxy._typeof(src), "'")
29
+ }]);
30
+ } else if (Array.isArray(src)) {
31
+ return SelectorProxy._defineProperty({}, path, [{
32
+ message: "Expected 'object', got 'array'"
33
+ }]);
34
+ }
35
+ Object.entries(this.items).forEach(function (_ref3) {
36
+ var _ref4 = SelectorProxy._slicedToArray(_ref3, 2),
37
+ key = _ref4[0],
38
+ schema = _ref4[1];
39
+ var subPath = SelectorProxy.createValPathOfItem(path, key);
40
+ if (!subPath) {
41
+ error = _this2.appendValidationError(error, path, "Internal error: could not create path at ".concat(!path && typeof path === "string" ? "<empty string>" : path, " at key ").concat(key),
42
+ // Should! never happen
43
+ src);
44
+ } else {
45
+ var subError = schema.validate(subPath, src[key]);
46
+ if (subError && error) {
47
+ error = SelectorProxy._objectSpread2(SelectorProxy._objectSpread2({}, subError), error);
48
+ } else if (subError) {
49
+ error = subError;
50
+ }
51
+ }
52
+ });
53
+ return error;
54
+ }
55
+ }, {
56
+ key: "assert",
57
+ value: function assert(src) {
58
+ if (this.opt && (src === null || src === undefined)) {
59
+ return true;
60
+ }
61
+ if (!src) {
62
+ return false;
63
+ }
64
+ for (var _i = 0, _Object$entries = Object.entries(this.items); _i < _Object$entries.length; _i++) {
65
+ var _Object$entries$_i = SelectorProxy._slicedToArray(_Object$entries[_i], 2),
66
+ _key = _Object$entries$_i[0],
67
+ schema = _Object$entries$_i[1];
68
+ if (!schema.assert(src[_key])) {
69
+ return false;
70
+ }
71
+ }
72
+ return SelectorProxy._typeof(src) === "object" && !Array.isArray(src);
73
+ }
74
+ }, {
75
+ key: "optional",
76
+ value: function optional() {
77
+ return new ObjectSchema(this.items, true);
78
+ }
79
+ }, {
80
+ key: "serialize",
81
+ value: function serialize() {
82
+ return {
83
+ type: "object",
84
+ items: Object.fromEntries(Object.entries(this.items).map(function (_ref5) {
85
+ var _ref6 = SelectorProxy._slicedToArray(_ref5, 2),
86
+ key = _ref6[0],
87
+ schema = _ref6[1];
88
+ return [key, schema.serialize()];
89
+ })),
90
+ opt: this.opt
91
+ };
92
+ }
93
+ }]);
94
+ return ObjectSchema;
95
+ }(SelectorProxy.Schema);
96
+ var object = function object(schema) {
97
+ return new ObjectSchema(schema);
98
+ };
99
+
100
+ var ArraySchema = /*#__PURE__*/function (_Schema) {
101
+ SelectorProxy._inherits(ArraySchema, _Schema);
102
+ var _super = SelectorProxy._createSuper(ArraySchema);
103
+ function ArraySchema(item) {
104
+ var _this;
105
+ var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
106
+ SelectorProxy._classCallCheck(this, ArraySchema);
107
+ _this = _super.call(this);
108
+ _this.item = item;
109
+ _this.opt = opt;
110
+ return _this;
111
+ }
112
+ SelectorProxy._createClass(ArraySchema, [{
113
+ key: "validate",
114
+ value: function validate(path, src) {
115
+ var _this2 = this;
116
+ var error = false;
117
+ if (this.opt && (src === null || src === undefined)) {
118
+ return false;
119
+ }
120
+ if (SelectorProxy._typeof(src) !== "object" || !Array.isArray(src)) {
121
+ return SelectorProxy._defineProperty({}, path, [{
122
+ message: "Expected 'array', got '".concat(SelectorProxy._typeof(src), "'")
123
+ }]);
124
+ }
125
+ src.forEach(function (i, idx) {
126
+ var subPath = SelectorProxy.createValPathOfItem(path, idx);
127
+ if (!subPath) {
128
+ error = _this2.appendValidationError(error, path, "Internal error: could not create path at ".concat(!path && typeof path === "string" ? "<empty string>" : path, " at index ").concat(idx),
129
+ // Should! never happen
130
+ src);
131
+ } else {
132
+ var subError = _this2.item.validate(subPath, i);
133
+ if (subError && error) {
134
+ error = SelectorProxy._objectSpread2(SelectorProxy._objectSpread2({}, subError), error);
135
+ } else if (subError) {
136
+ error = subError;
137
+ }
138
+ }
139
+ });
140
+ return error;
141
+ }
142
+ }, {
143
+ key: "assert",
144
+ value: function assert(src) {
145
+ if (this.opt && (src === null || src === undefined)) {
146
+ return true;
147
+ }
148
+ if (!src) {
149
+ return false;
150
+ }
151
+ var _iterator = result._createForOfIteratorHelper(src),
152
+ _step;
153
+ try {
154
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
155
+ var _item = _step.value;
156
+ if (!this.item.assert(_item)) {
157
+ return false;
158
+ }
159
+ }
160
+ } catch (err) {
161
+ _iterator.e(err);
162
+ } finally {
163
+ _iterator.f();
164
+ }
165
+ return SelectorProxy._typeof(src) === "object" && Array.isArray(src);
166
+ }
167
+ }, {
168
+ key: "optional",
169
+ value: function optional() {
170
+ return new ArraySchema(this.item, true);
171
+ }
172
+ }, {
173
+ key: "serialize",
174
+ value: function serialize() {
175
+ return {
176
+ type: "array",
177
+ item: this.item.serialize(),
178
+ opt: this.opt
179
+ };
180
+ }
181
+ }]);
182
+ return ArraySchema;
183
+ }(SelectorProxy.Schema);
184
+ var array = function array(schema) {
185
+ return new ArraySchema(schema);
186
+ };
187
+
188
+ var I18nSchema = /*#__PURE__*/function (_Schema) {
189
+ SelectorProxy._inherits(I18nSchema, _Schema);
190
+ var _super = SelectorProxy._createSuper(I18nSchema);
191
+ function I18nSchema(locales, item) {
192
+ var _this;
193
+ var opt = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
194
+ SelectorProxy._classCallCheck(this, I18nSchema);
195
+ _this = _super.call(this);
196
+ _this.locales = locales;
197
+ _this.item = item;
198
+ _this.opt = opt;
199
+ return _this;
200
+ }
201
+ SelectorProxy._createClass(I18nSchema, [{
202
+ key: "validate",
203
+ value: function validate(path, src) {
204
+ throw new Error("Method not implemented.");
205
+ }
206
+ }, {
207
+ key: "assert",
208
+ value: function assert(src) {
209
+ throw new Error("Method not implemented.");
210
+ }
211
+ }, {
212
+ key: "optional",
213
+ value: function optional() {
214
+ return new I18nSchema(this.locales, this.item, true);
215
+ }
216
+ }, {
217
+ key: "serialize",
218
+ value: function serialize() {
219
+ return {
220
+ type: "i18n",
221
+ item: this.item.serialize(),
222
+ locales: this.locales,
223
+ opt: this.opt
224
+ };
225
+ }
226
+ }]);
227
+ return I18nSchema;
228
+ }(SelectorProxy.Schema);
229
+ var i18n = function i18n(locales) {
230
+ return function (schema) {
231
+ return new I18nSchema(locales, schema);
232
+ };
233
+ };
234
+
235
+ var UnionSchema = /*#__PURE__*/function (_Schema) {
236
+ SelectorProxy._inherits(UnionSchema, _Schema);
237
+ var _super = SelectorProxy._createSuper(UnionSchema);
238
+ function UnionSchema(key, items) {
239
+ var _this;
240
+ var opt = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
241
+ SelectorProxy._classCallCheck(this, UnionSchema);
242
+ _this = _super.call(this);
243
+ _this.key = key;
244
+ _this.items = items;
245
+ _this.opt = opt;
246
+ return _this;
247
+ }
248
+ SelectorProxy._createClass(UnionSchema, [{
249
+ key: "validate",
250
+ value: function validate(path, src) {
251
+ throw new Error("Method not implemented.");
252
+ }
253
+ }, {
254
+ key: "assert",
255
+ value: function assert(src) {
256
+ throw new Error("Method not implemented.");
257
+ }
258
+ }, {
259
+ key: "optional",
260
+ value: function optional() {
261
+ throw new Error("Method not implemented.");
262
+ }
263
+ }, {
264
+ key: "serialize",
265
+ value: function serialize() {
266
+ return {
267
+ type: "union",
268
+ key: this.key,
269
+ items: this.items.map(function (o) {
270
+ return o.serialize();
271
+ }),
272
+ opt: this.opt
273
+ };
274
+ }
275
+ }]);
276
+ return UnionSchema;
277
+ }(SelectorProxy.Schema);
278
+ var union = function union(key) {
279
+ for (var _len = arguments.length, objects = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
280
+ objects[_key - 1] = arguments[_key];
281
+ }
282
+ return new UnionSchema(key, objects);
283
+ };
284
+
285
+ var RichTextSchema = /*#__PURE__*/function (_Schema) {
286
+ SelectorProxy._inherits(RichTextSchema, _Schema);
287
+ var _super = SelectorProxy._createSuper(RichTextSchema);
288
+ function RichTextSchema() {
289
+ var _this;
290
+ var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
291
+ SelectorProxy._classCallCheck(this, RichTextSchema);
292
+ _this = _super.call(this);
293
+ _this.opt = opt;
294
+ return _this;
295
+ }
296
+ SelectorProxy._createClass(RichTextSchema, [{
297
+ key: "validate",
298
+ value: function validate(path, src) {
299
+ if (this.opt && (src === null || src === undefined)) {
300
+ return false;
301
+ }
302
+ if (src === null || src === undefined) {
303
+ return SelectorProxy._defineProperty({}, path, [{
304
+ message: "Expected non-nullable got '".concat(src, "'")
305
+ }]);
306
+ }
307
+ if (SelectorProxy._typeof(src) !== "object" && !Array.isArray(src)) {
308
+ return SelectorProxy._defineProperty({}, path, [{
309
+ message: "Expected 'object' (that is not of an array) or 'string', got '".concat(SelectorProxy._typeof(src), "'"),
310
+ value: src
311
+ }]);
312
+ }
313
+ if (src[SelectorProxy.VAL_EXTENSION] !== "richtext") {
314
+ return SelectorProxy._defineProperty({}, path, [{
315
+ message: "Expected _type key with value 'richtext' got '".concat(src[SelectorProxy.VAL_EXTENSION], "'"),
316
+ value: src
317
+ }]);
318
+ }
319
+ if (src.type !== "root") {
320
+ return SelectorProxy._defineProperty({}, path, [{
321
+ message: "Expected type key with value 'root' got '".concat(src.type, "'"),
322
+ value: src
323
+ }]);
324
+ }
325
+ if (SelectorProxy._typeof(src.children) !== "object" && !Array.isArray(src.children)) {
326
+ return SelectorProxy._defineProperty({}, path, [{
327
+ message: "Expected children to be an array, but got '".concat(src.type, "'"),
328
+ value: src
329
+ }]);
330
+ }
331
+ return false;
332
+ }
333
+ }, {
334
+ key: "assert",
335
+ value: function assert(src) {
336
+ // TODO:
337
+ return true;
338
+ }
339
+ }, {
340
+ key: "optional",
341
+ value: function optional() {
342
+ return new RichTextSchema(true);
343
+ }
344
+ }, {
345
+ key: "serialize",
346
+ value: function serialize() {
347
+ return {
348
+ type: "richtext",
349
+ opt: this.opt
350
+ };
351
+ }
352
+ }]);
353
+ return RichTextSchema;
354
+ }(SelectorProxy.Schema);
355
+ var richtext = function richtext() {
356
+ return new RichTextSchema();
357
+ };
358
+
359
+ function content(
360
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
361
+ id,
362
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
363
+ schema,
364
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
365
+ source) {
366
+ return SelectorProxy.newSelectorProxy(source, id, schema);
367
+ }
368
+ function getRawSource(valModule) {
369
+ var sourceOrExpr = valModule[SelectorProxy.SourceOrExpr];
370
+ if (sourceOrExpr instanceof SelectorProxy.Expr) {
371
+ throw Error("Cannot get raw source of an Expr");
372
+ }
373
+ var source = sourceOrExpr;
374
+ return source;
375
+ }
376
+ function splitModuleIdAndModulePath(path) {
377
+ return [path.slice(0, path.indexOf(".")), path.slice(path.indexOf(".") + 1)];
378
+ }
379
+ function isObjectSchema(schema) {
380
+ return schema instanceof ObjectSchema || SelectorProxy._typeof(schema) === "object" && "type" in schema && schema.type === "object";
381
+ }
382
+ function isArraySchema(schema) {
383
+ return schema instanceof ArraySchema || SelectorProxy._typeof(schema) === "object" && "type" in schema && schema.type === "array";
384
+ }
385
+ function isI18nSchema(schema) {
386
+ return schema instanceof I18nSchema || SelectorProxy._typeof(schema) === "object" && "type" in schema && schema.type === "i18n";
387
+ }
388
+ function isUnionSchema(schema) {
389
+ return schema instanceof UnionSchema || SelectorProxy._typeof(schema) === "object" && "type" in schema && schema.type === "union";
390
+ }
391
+
392
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
393
+ function isRichTextSchema(schema) {
394
+ return schema instanceof RichTextSchema || SelectorProxy._typeof(schema) === "object" && "type" in schema && schema.type === "richtext";
395
+ }
396
+ function isImageSchema(schema) {
397
+ return schema instanceof SelectorProxy.ImageSchema || SelectorProxy._typeof(schema) === "object" && "type" in schema && schema.type === "image";
398
+ }
399
+ function resolvePath(path, valModule, schema) {
400
+ var parts = parsePath(path);
401
+ var origParts = SelectorProxy._toConsumableArray(parts);
402
+ var resolvedSchema = schema;
403
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
404
+ var resolvedSource = valModule;
405
+ var _loop = function _loop() {
406
+ var part = parts.shift();
407
+ if (part === undefined) {
408
+ throw Error("Unexpected undefined part");
409
+ }
410
+ if (isArraySchema(resolvedSchema)) {
411
+ if (Number.isNaN(Number(part))) {
412
+ throw Error("Invalid path: array schema ".concat(resolvedSchema, " must have ").concat(part, " a number as path"));
413
+ }
414
+ if (SelectorProxy._typeof(resolvedSource) !== "object" && !Array.isArray(resolvedSource)) {
415
+ throw Error("Schema type error: expected source to be type of array, but got ".concat(SelectorProxy._typeof(resolvedSource)));
416
+ }
417
+ if (!resolvedSource[part]) {
418
+ var _resolvedSource;
419
+ 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));
420
+ }
421
+ resolvedSource = resolvedSource[part];
422
+ resolvedSchema = resolvedSchema.item;
423
+ } else if (isObjectSchema(resolvedSchema)) {
424
+ if (SelectorProxy._typeof(resolvedSource) !== "object") {
425
+ throw Error("Schema type error: expected source to be type of object, but got ".concat(SelectorProxy._typeof(resolvedSource)));
426
+ }
427
+ if (!resolvedSource[part]) {
428
+ throw Error("Invalid path: object source did not have key ".concat(part, " from path: ").concat(path));
429
+ }
430
+ resolvedSource = resolvedSource[part];
431
+ resolvedSchema = resolvedSchema.items[part];
432
+ } else if (isI18nSchema(resolvedSchema)) {
433
+ if (!resolvedSchema.locales.includes(part)) {
434
+ throw Error("Invalid path: i18n schema ".concat(resolvedSchema, " supports locales ").concat(resolvedSchema.locales.join(", "), ", but found: ").concat(part));
435
+ }
436
+ if (!Object.keys(resolvedSource).includes(part)) {
437
+ throw Error("Schema type error: expected source to be type of i18n with locale ".concat(part, ", but got ").concat(JSON.stringify(Object.keys(resolvedSource))));
438
+ }
439
+ resolvedSource = resolvedSource[part];
440
+ resolvedSchema = resolvedSchema.item;
441
+ } else if (isImageSchema(resolvedSchema)) {
442
+ return {
443
+ v: {
444
+ path: origParts.slice(0, origParts.length - parts.length - 1).map(function (p) {
445
+ return JSON.stringify(p);
446
+ }).join("."),
447
+ // TODO: create a function generate path from parts (not sure if this always works)
448
+ schema: resolvedSchema,
449
+ source: resolvedSource
450
+ }
451
+ };
452
+ } else if (isUnionSchema(resolvedSchema)) {
453
+ var _key = resolvedSchema.key;
454
+ var keyValue = resolvedSource[_key];
455
+ if (!keyValue) {
456
+ throw Error("Invalid path: union source ".concat(resolvedSchema, " did not have required key ").concat(_key, " in path: ").concat(path));
457
+ }
458
+ var schemaOfUnionKey = resolvedSchema.items.find(
459
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
460
+ function (child) {
461
+ var _child$items, _child$items$_key;
462
+ 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;
463
+ });
464
+ if (!schemaOfUnionKey) {
465
+ 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));
466
+ }
467
+ resolvedSchema = schemaOfUnionKey.items[part];
468
+ resolvedSource = resolvedSource[part];
469
+ } else if (isRichTextSchema(resolvedSchema)) {
470
+ return {
471
+ v: {
472
+ path: origParts.slice(0, origParts.length - parts.length - 1).map(function (p) {
473
+ return JSON.stringify(p);
474
+ }).join("."),
475
+ // TODO: create a function generate path from parts (not sure if this always works)
476
+ schema: resolvedSchema,
477
+ source: resolvedSource
478
+ }
479
+ };
480
+ } else {
481
+ throw Error("Invalid path: ".concat(part, " resolved to an unexpected schema ").concat(JSON.stringify(resolvedSchema)));
482
+ }
483
+ };
484
+ while (parts.length > 0) {
485
+ var _ret = _loop();
486
+ if (SelectorProxy._typeof(_ret) === "object") return _ret.v;
487
+ }
488
+ if (parts.length > 0) {
489
+ throw Error("Invalid path: ".concat(parts.join("."), " is not a valid path"));
490
+ }
491
+ return {
492
+ path: path,
493
+ schema: resolvedSchema,
494
+ source: resolvedSource
495
+ };
496
+ }
497
+ function parsePath(input) {
498
+ var result = [];
499
+ var i = 0;
500
+ while (i < input.length) {
501
+ var part = "";
502
+ if (input[i] === '"') {
503
+ // Parse a quoted string
504
+ i++;
505
+ while (i < input.length && input[i] !== '"') {
506
+ if (input[i] === "\\" && input[i + 1] === '"') {
507
+ // Handle escaped double quotes
508
+ part += '"';
509
+ i++;
510
+ } else {
511
+ part += input[i];
512
+ }
513
+ i++;
514
+ }
515
+ if (input[i] !== '"') {
516
+ var _input$i;
517
+ 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, ")"));
518
+ }
519
+ } else {
520
+ // Parse a regular string
521
+ while (i < input.length && input[i] !== ".") {
522
+ part += input[i];
523
+ i++;
524
+ }
525
+ }
526
+ if (part !== "") {
527
+ result.push(part);
528
+ }
529
+ i++;
530
+ }
531
+ return result;
532
+ }
533
+
534
+ var PatchError = /*#__PURE__*/SelectorProxy._createClass(function PatchError(message) {
535
+ SelectorProxy._classCallCheck(this, PatchError);
536
+ this.message = message;
537
+ });
538
+
539
+ /**
540
+ * NOTE: MAY mutate the input document.
541
+ */
542
+
543
+ exports.PatchError = PatchError;
544
+ exports.array = array;
545
+ exports.content = content;
546
+ exports.getRawSource = getRawSource;
547
+ exports.i18n = i18n;
548
+ exports.object = object;
549
+ exports.resolvePath = resolvePath;
550
+ exports.richtext = richtext;
551
+ exports.splitModuleIdAndModulePath = splitModuleIdAndModulePath;
552
+ exports.union = union;