@valbuild/core 0.61.0 → 0.62.1
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.
- package/dist/declarations/src/ValApi.d.ts +18 -15
- package/dist/declarations/src/index.d.ts +36 -42
- package/dist/declarations/src/initVal.d.ts +1 -1
- package/dist/declarations/src/module.d.ts +3 -2
- package/dist/declarations/src/source/file.d.ts +1 -0
- package/dist/declarations/src/val/index.d.ts +4 -4
- package/dist/index-316f5dd8.esm.js +4016 -0
- package/dist/index-3193efd5.cjs.dev.js +4057 -0
- package/dist/index-596f28bb.cjs.prod.js +4057 -0
- package/dist/{result-b96df128.esm.js → result-a8316efa.esm.js} +1 -1
- package/dist/valbuild-core.cjs.dev.js +29 -1844
- package/dist/valbuild-core.cjs.prod.js +29 -1844
- package/dist/valbuild-core.esm.js +2 -1823
- package/expr/dist/valbuild-core-expr.cjs.dev.js +7 -8
- package/expr/dist/valbuild-core-expr.cjs.prod.js +7 -8
- package/expr/dist/valbuild-core-expr.esm.js +2 -3
- package/fp/dist/valbuild-core-fp.esm.js +1 -1
- package/package.json +1 -1
- package/patch/dist/valbuild-core-patch.cjs.dev.js +46 -50
- package/patch/dist/valbuild-core-patch.cjs.prod.js +46 -50
- package/patch/dist/valbuild-core-patch.esm.js +6 -10
- package/dist/index-051c34f3.esm.js +0 -539
- package/dist/index-0df230ef.cjs.dev.js +0 -572
- package/dist/index-2dfaf8f7.cjs.prod.js +0 -643
- package/dist/index-e8ab2166.cjs.dev.js +0 -643
- package/dist/index-ed5767a3.esm.js +0 -639
- package/dist/index-f2552460.cjs.prod.js +0 -572
- package/dist/ops-34737ef0.cjs.dev.js +0 -1068
- package/dist/ops-92570725.cjs.prod.js +0 -1068
- package/dist/ops-9262cf01.esm.js +0 -1044
@@ -1,1068 +0,0 @@
|
|
1
|
-
'use strict';
|
2
|
-
|
3
|
-
var index = require('./index-f2552460.cjs.prod.js');
|
4
|
-
var result = require('./result-26f67b40.cjs.prod.js');
|
5
|
-
|
6
|
-
function hasOwn(obj, prop) {
|
7
|
-
return Object.prototype.hasOwnProperty.call(obj, prop);
|
8
|
-
}
|
9
|
-
function _andThen(f, source, path) {
|
10
|
-
if (source) {
|
11
|
-
return newSelectorProxy(f(newSelectorProxy(source, path)));
|
12
|
-
}
|
13
|
-
return newSelectorProxy(source, path);
|
14
|
-
}
|
15
|
-
function isSelector(source) {
|
16
|
-
return index._typeof(source) === "object" && source !== null && (index.GetSource in source || index.Path in source);
|
17
|
-
}
|
18
|
-
function newSelectorProxy(source, path, moduleSchema) {
|
19
|
-
if (index._typeof(source) === "object") {
|
20
|
-
if (isSelector(source)) {
|
21
|
-
return source;
|
22
|
-
} else if (index.isSerializedVal(source)) {
|
23
|
-
return newSelectorProxy(source.val, source.valPath);
|
24
|
-
}
|
25
|
-
}
|
26
|
-
if (source && source[index.FILE_REF_PROP] && source[index.VAL_EXTENSION] === "file") {
|
27
|
-
var fileRef = source[index.FILE_REF_PROP];
|
28
|
-
if (typeof fileRef !== "string") {
|
29
|
-
throw Error("Invalid file ref: " + fileRef);
|
30
|
-
}
|
31
|
-
return newSelectorProxy(index.convertFileSource(source), path, moduleSchema);
|
32
|
-
}
|
33
|
-
switch (index._typeof(source)) {
|
34
|
-
case "function":
|
35
|
-
case "symbol":
|
36
|
-
throw Error("Invalid selector type: ".concat(index._typeof(source), ": ").concat(source));
|
37
|
-
case "object":
|
38
|
-
// Handles both objects and arrays!
|
39
|
-
if (source !== null) {
|
40
|
-
return new Proxy(source, {
|
41
|
-
// TODO: see proxy docs if we want more traps
|
42
|
-
has: function has(target, prop) {
|
43
|
-
if (prop === index.GetSource) {
|
44
|
-
return true;
|
45
|
-
}
|
46
|
-
if (prop === index.Path) {
|
47
|
-
return true;
|
48
|
-
}
|
49
|
-
if (prop === "andThen") {
|
50
|
-
return true;
|
51
|
-
}
|
52
|
-
if (prop === index.GetSchema) {
|
53
|
-
return true;
|
54
|
-
}
|
55
|
-
return prop in target;
|
56
|
-
},
|
57
|
-
get: function get(target, prop) {
|
58
|
-
if (prop === index.GetSource) {
|
59
|
-
return source;
|
60
|
-
}
|
61
|
-
if (prop === index.Path) {
|
62
|
-
return path;
|
63
|
-
}
|
64
|
-
if (prop === index.GetSchema) {
|
65
|
-
return moduleSchema;
|
66
|
-
}
|
67
|
-
if (prop === "andThen") {
|
68
|
-
return function (f) {
|
69
|
-
return _andThen(f, source, path);
|
70
|
-
};
|
71
|
-
}
|
72
|
-
if (Array.isArray(target)) {
|
73
|
-
if (prop === "filter") {
|
74
|
-
return function (f) {
|
75
|
-
var filtered = target.map(function (a, i) {
|
76
|
-
return newSelectorProxy(a, createValPathOfItem(path, i), moduleSchema === null || moduleSchema === void 0 ? void 0 : moduleSchema.item);
|
77
|
-
}).filter(function (a) {
|
78
|
-
if (f && f instanceof index.Schema) {
|
79
|
-
return f.assert(unValify(a));
|
80
|
-
} else {
|
81
|
-
return unValify(f(a));
|
82
|
-
}
|
83
|
-
});
|
84
|
-
return newSelectorProxy(filtered, path, moduleSchema);
|
85
|
-
};
|
86
|
-
} else if (prop === "map") {
|
87
|
-
return function (f) {
|
88
|
-
var filtered = target.map(function (a, i) {
|
89
|
-
var valueOrSelector = f(newSelectorProxy(a, createValPathOfItem(path, i), moduleSchema === null || moduleSchema === void 0 ? void 0 : moduleSchema.item), newSelectorProxy(i));
|
90
|
-
if (isSelector(valueOrSelector)) {
|
91
|
-
return valueOrSelector;
|
92
|
-
}
|
93
|
-
return newSelectorProxy(valueOrSelector);
|
94
|
-
});
|
95
|
-
return newSelectorProxy(filtered, path, moduleSchema);
|
96
|
-
};
|
97
|
-
}
|
98
|
-
}
|
99
|
-
if (Array.isArray(target) && prop === "length") {
|
100
|
-
return newSelectorProxy(target.length);
|
101
|
-
}
|
102
|
-
var reflectedValue = Reflect.get(target, prop);
|
103
|
-
if (hasOwn(source, prop)) {
|
104
|
-
if (!Number.isNaN(Number(prop))) {
|
105
|
-
return newSelectorProxy(reflectedValue, createValPathOfItem(path, Number(prop)), moduleSchema === null || moduleSchema === void 0 ? void 0 : moduleSchema.item);
|
106
|
-
}
|
107
|
-
return newSelectorProxy(reflectedValue, createValPathOfItem(path, prop), moduleSchema === null || moduleSchema === void 0 ? void 0 : moduleSchema.items[prop]);
|
108
|
-
}
|
109
|
-
return reflectedValue;
|
110
|
-
}
|
111
|
-
});
|
112
|
-
}
|
113
|
-
// intentional fallthrough
|
114
|
-
// eslint-disable-next-line no-fallthrough
|
115
|
-
default:
|
116
|
-
return index._defineProperty(index._defineProperty(index._defineProperty({
|
117
|
-
eq: function eq(other) {
|
118
|
-
var otherValue = other;
|
119
|
-
if (isSelector(other)) {
|
120
|
-
otherValue = other[index.GetSource];
|
121
|
-
if (otherValue instanceof index.Expr) {
|
122
|
-
throw Error("TODO: Cannot evaluate equality with an Expr");
|
123
|
-
}
|
124
|
-
}
|
125
|
-
return newSelectorProxy(source === otherValue, undefined);
|
126
|
-
},
|
127
|
-
andThen: function andThen(f) {
|
128
|
-
return _andThen(f, source === undefined ? null : source, path);
|
129
|
-
}
|
130
|
-
}, index.GetSource, source === undefined ? null : source), index.Path, path), index.GetSchema, moduleSchema);
|
131
|
-
}
|
132
|
-
}
|
133
|
-
function createValPathOfItem(arrayPath, prop) {
|
134
|
-
if (index._typeof(prop) === "symbol") {
|
135
|
-
throw Error("Cannot create val path of array item with symbol prop: ".concat(prop.toString()));
|
136
|
-
}
|
137
|
-
return arrayPath !== undefined ? "".concat(arrayPath, ".").concat(JSON.stringify(prop)) : undefined;
|
138
|
-
}
|
139
|
-
|
140
|
-
// TODO: could we do .val on the objects instead?
|
141
|
-
function unValify(valueOrSelector) {
|
142
|
-
if (index._typeof(valueOrSelector) === "object" && (index.GetSource in valueOrSelector || index.Path in valueOrSelector)) {
|
143
|
-
var selectorValue = valueOrSelector[index.GetSource];
|
144
|
-
return selectorValue;
|
145
|
-
}
|
146
|
-
return valueOrSelector;
|
147
|
-
}
|
148
|
-
|
149
|
-
var ObjectSchema = /*#__PURE__*/function (_Schema) {
|
150
|
-
index._inherits(ObjectSchema, _Schema);
|
151
|
-
function ObjectSchema(items) {
|
152
|
-
var _this;
|
153
|
-
var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
154
|
-
index._classCallCheck(this, ObjectSchema);
|
155
|
-
_this = index._callSuper(this, ObjectSchema);
|
156
|
-
_this.items = items;
|
157
|
-
_this.opt = opt;
|
158
|
-
return _this;
|
159
|
-
}
|
160
|
-
index._createClass(ObjectSchema, [{
|
161
|
-
key: "validate",
|
162
|
-
value: function validate(path, src) {
|
163
|
-
var _this2 = this;
|
164
|
-
var error = false;
|
165
|
-
|
166
|
-
// TODO: src should never be undefined
|
167
|
-
if (this.opt && (src === null || src === undefined)) {
|
168
|
-
return false;
|
169
|
-
}
|
170
|
-
if (index._typeof(src) !== "object") {
|
171
|
-
return index._defineProperty({}, path, [{
|
172
|
-
message: "Expected 'object', got '".concat(index._typeof(src), "'")
|
173
|
-
}]);
|
174
|
-
} else if (Array.isArray(src)) {
|
175
|
-
return index._defineProperty({}, path, [{
|
176
|
-
message: "Expected 'object', got 'array'"
|
177
|
-
}]);
|
178
|
-
}
|
179
|
-
Object.entries(this.items).forEach(function (_ref3) {
|
180
|
-
var _ref4 = index._slicedToArray(_ref3, 2),
|
181
|
-
key = _ref4[0],
|
182
|
-
schema = _ref4[1];
|
183
|
-
var subPath = createValPathOfItem(path, key);
|
184
|
-
if (!subPath) {
|
185
|
-
error = _this2.appendValidationError(error, path, "Internal error: could not create path at ".concat(!path && typeof path === "string" ? "<empty string>" : path, " at key ").concat(key),
|
186
|
-
// Should! never happen
|
187
|
-
src);
|
188
|
-
} else {
|
189
|
-
var subError = schema.validate(subPath, src[key]);
|
190
|
-
if (subError && error) {
|
191
|
-
error = index._objectSpread2(index._objectSpread2({}, subError), error);
|
192
|
-
} else if (subError) {
|
193
|
-
error = subError;
|
194
|
-
}
|
195
|
-
}
|
196
|
-
});
|
197
|
-
return error;
|
198
|
-
}
|
199
|
-
}, {
|
200
|
-
key: "assert",
|
201
|
-
value: function assert(src) {
|
202
|
-
if (this.opt && (src === null || src === undefined)) {
|
203
|
-
return true;
|
204
|
-
}
|
205
|
-
if (!src) {
|
206
|
-
return false;
|
207
|
-
}
|
208
|
-
for (var _i = 0, _Object$entries = Object.entries(this.items); _i < _Object$entries.length; _i++) {
|
209
|
-
var _Object$entries$_i = index._slicedToArray(_Object$entries[_i], 2),
|
210
|
-
_key = _Object$entries$_i[0],
|
211
|
-
schema = _Object$entries$_i[1];
|
212
|
-
if (!schema.assert(src[_key])) {
|
213
|
-
return false;
|
214
|
-
}
|
215
|
-
}
|
216
|
-
return index._typeof(src) === "object" && !Array.isArray(src);
|
217
|
-
}
|
218
|
-
}, {
|
219
|
-
key: "nullable",
|
220
|
-
value: function nullable() {
|
221
|
-
return new ObjectSchema(this.items, true);
|
222
|
-
}
|
223
|
-
}, {
|
224
|
-
key: "serialize",
|
225
|
-
value: function serialize() {
|
226
|
-
return {
|
227
|
-
type: "object",
|
228
|
-
items: Object.fromEntries(Object.entries(this.items).map(function (_ref5) {
|
229
|
-
var _ref6 = index._slicedToArray(_ref5, 2),
|
230
|
-
key = _ref6[0],
|
231
|
-
schema = _ref6[1];
|
232
|
-
return [key, schema.serialize()];
|
233
|
-
})),
|
234
|
-
opt: this.opt
|
235
|
-
};
|
236
|
-
}
|
237
|
-
}]);
|
238
|
-
return ObjectSchema;
|
239
|
-
}(index.Schema);
|
240
|
-
var object = function object(schema) {
|
241
|
-
return new ObjectSchema(schema);
|
242
|
-
};
|
243
|
-
|
244
|
-
var ArraySchema = /*#__PURE__*/function (_Schema) {
|
245
|
-
index._inherits(ArraySchema, _Schema);
|
246
|
-
function ArraySchema(item) {
|
247
|
-
var _this;
|
248
|
-
var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
249
|
-
index._classCallCheck(this, ArraySchema);
|
250
|
-
_this = index._callSuper(this, ArraySchema);
|
251
|
-
_this.item = item;
|
252
|
-
_this.opt = opt;
|
253
|
-
return _this;
|
254
|
-
}
|
255
|
-
index._createClass(ArraySchema, [{
|
256
|
-
key: "validate",
|
257
|
-
value: function validate(path, src) {
|
258
|
-
var _this2 = this;
|
259
|
-
var error = false;
|
260
|
-
if (this.opt && (src === null || src === undefined)) {
|
261
|
-
return false;
|
262
|
-
}
|
263
|
-
if (index._typeof(src) !== "object" || !Array.isArray(src)) {
|
264
|
-
return index._defineProperty({}, path, [{
|
265
|
-
message: "Expected 'array', got '".concat(index._typeof(src), "'")
|
266
|
-
}]);
|
267
|
-
}
|
268
|
-
src.forEach(function (i, idx) {
|
269
|
-
var subPath = createValPathOfItem(path, idx);
|
270
|
-
if (!subPath) {
|
271
|
-
error = _this2.appendValidationError(error, path, "Internal error: could not create path at ".concat(!path && typeof path === "string" ? "<empty string>" : path, " at index ").concat(idx),
|
272
|
-
// Should! never happen
|
273
|
-
src);
|
274
|
-
} else {
|
275
|
-
var subError = _this2.item.validate(subPath, i);
|
276
|
-
if (subError && error) {
|
277
|
-
error = index._objectSpread2(index._objectSpread2({}, subError), error);
|
278
|
-
} else if (subError) {
|
279
|
-
error = subError;
|
280
|
-
}
|
281
|
-
}
|
282
|
-
});
|
283
|
-
return error;
|
284
|
-
}
|
285
|
-
}, {
|
286
|
-
key: "assert",
|
287
|
-
value: function assert(src) {
|
288
|
-
if (this.opt && (src === null || src === undefined)) {
|
289
|
-
return true;
|
290
|
-
}
|
291
|
-
if (!src) {
|
292
|
-
return false;
|
293
|
-
}
|
294
|
-
var _iterator = result._createForOfIteratorHelper(src),
|
295
|
-
_step;
|
296
|
-
try {
|
297
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
298
|
-
var _item = _step.value;
|
299
|
-
if (!this.item.assert(_item)) {
|
300
|
-
return false;
|
301
|
-
}
|
302
|
-
}
|
303
|
-
} catch (err) {
|
304
|
-
_iterator.e(err);
|
305
|
-
} finally {
|
306
|
-
_iterator.f();
|
307
|
-
}
|
308
|
-
return index._typeof(src) === "object" && Array.isArray(src);
|
309
|
-
}
|
310
|
-
}, {
|
311
|
-
key: "nullable",
|
312
|
-
value: function nullable() {
|
313
|
-
return new ArraySchema(this.item, true);
|
314
|
-
}
|
315
|
-
}, {
|
316
|
-
key: "serialize",
|
317
|
-
value: function serialize() {
|
318
|
-
return {
|
319
|
-
type: "array",
|
320
|
-
item: this.item.serialize(),
|
321
|
-
opt: this.opt
|
322
|
-
};
|
323
|
-
}
|
324
|
-
}]);
|
325
|
-
return ArraySchema;
|
326
|
-
}(index.Schema);
|
327
|
-
var array = function array(schema) {
|
328
|
-
return new ArraySchema(schema);
|
329
|
-
};
|
330
|
-
|
331
|
-
var LiteralSchema = /*#__PURE__*/function (_Schema) {
|
332
|
-
index._inherits(LiteralSchema, _Schema);
|
333
|
-
function LiteralSchema(value) {
|
334
|
-
var _this;
|
335
|
-
var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
336
|
-
index._classCallCheck(this, LiteralSchema);
|
337
|
-
_this = index._callSuper(this, LiteralSchema);
|
338
|
-
_this.value = value;
|
339
|
-
_this.opt = opt;
|
340
|
-
return _this;
|
341
|
-
}
|
342
|
-
index._createClass(LiteralSchema, [{
|
343
|
-
key: "validate",
|
344
|
-
value: function validate(path, src) {
|
345
|
-
if (this.opt && (src === null || src === undefined)) {
|
346
|
-
return false;
|
347
|
-
}
|
348
|
-
if (typeof src !== "string") {
|
349
|
-
return index._defineProperty({}, path, [{
|
350
|
-
message: "Expected 'string', got '".concat(index._typeof(src), "'"),
|
351
|
-
value: src
|
352
|
-
}]);
|
353
|
-
}
|
354
|
-
if (src !== this.value) {
|
355
|
-
return index._defineProperty({}, path, [{
|
356
|
-
message: "Expected literal '".concat(this.value, "', got '").concat(src, "'"),
|
357
|
-
value: src
|
358
|
-
}]);
|
359
|
-
}
|
360
|
-
return false;
|
361
|
-
}
|
362
|
-
}, {
|
363
|
-
key: "assert",
|
364
|
-
value: function assert(src) {
|
365
|
-
if (this.opt && (src === null || src === undefined)) {
|
366
|
-
return true;
|
367
|
-
}
|
368
|
-
return typeof src === "string";
|
369
|
-
}
|
370
|
-
}, {
|
371
|
-
key: "nullable",
|
372
|
-
value: function nullable() {
|
373
|
-
return new LiteralSchema(this.value, true);
|
374
|
-
}
|
375
|
-
}, {
|
376
|
-
key: "serialize",
|
377
|
-
value: function serialize() {
|
378
|
-
return {
|
379
|
-
type: "literal",
|
380
|
-
value: this.value,
|
381
|
-
opt: this.opt
|
382
|
-
};
|
383
|
-
}
|
384
|
-
}]);
|
385
|
-
return LiteralSchema;
|
386
|
-
}(index.Schema);
|
387
|
-
var literal = function literal(value) {
|
388
|
-
return new LiteralSchema(value);
|
389
|
-
};
|
390
|
-
|
391
|
-
var UnionSchema = /*#__PURE__*/function (_Schema) {
|
392
|
-
index._inherits(UnionSchema, _Schema);
|
393
|
-
function UnionSchema(key, items) {
|
394
|
-
var _this;
|
395
|
-
var opt = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
396
|
-
index._classCallCheck(this, UnionSchema);
|
397
|
-
_this = index._callSuper(this, UnionSchema);
|
398
|
-
_this.key = key;
|
399
|
-
_this.items = items;
|
400
|
-
_this.opt = opt;
|
401
|
-
return _this;
|
402
|
-
}
|
403
|
-
index._createClass(UnionSchema, [{
|
404
|
-
key: "validate",
|
405
|
-
value: function validate(path, src) {
|
406
|
-
var unknownSrc = src;
|
407
|
-
var errors = false;
|
408
|
-
if (this.opt && (unknownSrc === null || unknownSrc === undefined)) {
|
409
|
-
// TODO: src should never be undefined
|
410
|
-
return false;
|
411
|
-
}
|
412
|
-
if (!this.key) {
|
413
|
-
return index._defineProperty({}, path, [{
|
414
|
-
message: "Missing required first argument in union"
|
415
|
-
}]);
|
416
|
-
}
|
417
|
-
var key = this.key;
|
418
|
-
if (!Array.isArray(this.items)) {
|
419
|
-
return index._defineProperty({}, path, [{
|
420
|
-
message: "A union schema must take more than 1 schema arguments",
|
421
|
-
fatal: true
|
422
|
-
}]);
|
423
|
-
}
|
424
|
-
if (typeof key === "string") {
|
425
|
-
// tagged union
|
426
|
-
if (this.items.some(function (item) {
|
427
|
-
return !(item instanceof ObjectSchema);
|
428
|
-
})) {
|
429
|
-
return index._defineProperty({}, path, [{
|
430
|
-
message: "Key is a string, so all schema items must be objects",
|
431
|
-
fatal: true
|
432
|
-
}]);
|
433
|
-
}
|
434
|
-
var objectSchemas = this.items;
|
435
|
-
var serializedSchemas = objectSchemas.map(function (schema) {
|
436
|
-
return schema.serialize();
|
437
|
-
});
|
438
|
-
var illegalSchemas = serializedSchemas.filter(function (schema) {
|
439
|
-
return !(schema.type === "object") || !(schema.items[key].type === "literal");
|
440
|
-
});
|
441
|
-
if (illegalSchemas.length > 0) {
|
442
|
-
return index._defineProperty({}, path, [{
|
443
|
-
message: "All schema items must be objects with a key: ".concat(key, " that is a literal schema. Found: ").concat(JSON.stringify(illegalSchemas, null, 2)),
|
444
|
-
fatal: true
|
445
|
-
}]);
|
446
|
-
}
|
447
|
-
var serializedObjectSchemas = serializedSchemas;
|
448
|
-
var optionalLiterals = serializedObjectSchemas.filter(function (schema) {
|
449
|
-
return schema.items[key].opt;
|
450
|
-
});
|
451
|
-
if (optionalLiterals.length > 1) {
|
452
|
-
return index._defineProperty({}, path, [{
|
453
|
-
message: "Schema cannot have an optional keys: ".concat(key),
|
454
|
-
fatal: true
|
455
|
-
}]);
|
456
|
-
}
|
457
|
-
if (index._typeof(unknownSrc) !== "object") {
|
458
|
-
return index._defineProperty({}, path, [{
|
459
|
-
message: "Expected an object"
|
460
|
-
}]);
|
461
|
-
}
|
462
|
-
var objectSrc = unknownSrc;
|
463
|
-
if (objectSrc[key] === undefined) {
|
464
|
-
return index._defineProperty({}, path, [{
|
465
|
-
message: "Missing required key: ".concat(key)
|
466
|
-
}]);
|
467
|
-
}
|
468
|
-
var foundSchemaLiterals = [];
|
469
|
-
var _iterator = result._createForOfIteratorHelper(serializedObjectSchemas),
|
470
|
-
_step;
|
471
|
-
try {
|
472
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
473
|
-
var schema = _step.value;
|
474
|
-
var schemaKey = schema.items[key];
|
475
|
-
if (schemaKey.type === "literal") {
|
476
|
-
if (!foundSchemaLiterals.includes(schemaKey.value)) {
|
477
|
-
foundSchemaLiterals.push(schemaKey.value);
|
478
|
-
} else {
|
479
|
-
return index._defineProperty({}, path, [{
|
480
|
-
message: "Found duplicate key in schema: ".concat(schemaKey.value),
|
481
|
-
fatal: true
|
482
|
-
}]);
|
483
|
-
}
|
484
|
-
}
|
485
|
-
}
|
486
|
-
} catch (err) {
|
487
|
-
_iterator.e(err);
|
488
|
-
} finally {
|
489
|
-
_iterator.f();
|
490
|
-
}
|
491
|
-
var objectSchemaAtKey = objectSchemas.find(function (schema) {
|
492
|
-
return !schema.items[key].validate(path, objectSrc[key]);
|
493
|
-
});
|
494
|
-
if (!objectSchemaAtKey) {
|
495
|
-
var keyPath = createValPathOfItem(path, key);
|
496
|
-
if (!keyPath) {
|
497
|
-
throw new Error("Internal error: could not create path at ".concat(!path && typeof path === "string" ? "<empty string>" : path, " at key ").concat(key));
|
498
|
-
}
|
499
|
-
return index._defineProperty({}, keyPath, [{
|
500
|
-
message: "Invalid key: \"".concat(key, "\". Value was: \"").concat(objectSrc[key], "\". Valid values: ").concat(serializedObjectSchemas.map(function (schema) {
|
501
|
-
var keySchema = schema.items[key];
|
502
|
-
if (keySchema.type === "literal" && keySchema.value) {
|
503
|
-
return "\"".concat(keySchema.value, "\"");
|
504
|
-
} else {
|
505
|
-
// should not happen here, we already checked this
|
506
|
-
throw new Error("Expected literal schema, got ".concat(JSON.stringify(keySchema, null, 2)));
|
507
|
-
}
|
508
|
-
}).join(", "))
|
509
|
-
}]);
|
510
|
-
}
|
511
|
-
var error = objectSchemaAtKey.validate(path, objectSrc);
|
512
|
-
if (error) {
|
513
|
-
return error;
|
514
|
-
}
|
515
|
-
} else if (key instanceof LiteralSchema) {
|
516
|
-
if (this.items.some(function (item) {
|
517
|
-
return !(item instanceof LiteralSchema);
|
518
|
-
})) {
|
519
|
-
return index._defineProperty({}, path, [{
|
520
|
-
message: "Key is a literal schema, so all schema items must be literals",
|
521
|
-
fatal: true
|
522
|
-
}]);
|
523
|
-
}
|
524
|
-
var literalItems = [key].concat(index._toConsumableArray(this.items));
|
525
|
-
if (typeof unknownSrc === "string") {
|
526
|
-
var isMatch = literalItems.some(function (item) {
|
527
|
-
return !item.validate(path, unknownSrc);
|
528
|
-
});
|
529
|
-
if (!isMatch) {
|
530
|
-
return index._defineProperty({}, path, [{
|
531
|
-
message: "Union must match one of the following: ".concat(literalItems.map(function (item) {
|
532
|
-
return "\"".concat(item.value, "\"");
|
533
|
-
}).join(", "))
|
534
|
-
}]);
|
535
|
-
}
|
536
|
-
}
|
537
|
-
} else {
|
538
|
-
return index._defineProperty({}, path, [{
|
539
|
-
message: "Expected a string or literal"
|
540
|
-
}]);
|
541
|
-
}
|
542
|
-
return errors;
|
543
|
-
}
|
544
|
-
}, {
|
545
|
-
key: "assert",
|
546
|
-
value: function assert(src) {
|
547
|
-
return true;
|
548
|
-
}
|
549
|
-
}, {
|
550
|
-
key: "nullable",
|
551
|
-
value: function nullable() {
|
552
|
-
return new UnionSchema(this.key, this.items, true);
|
553
|
-
}
|
554
|
-
}, {
|
555
|
-
key: "serialize",
|
556
|
-
value: function serialize() {
|
557
|
-
if (typeof this.key === "string") {
|
558
|
-
return {
|
559
|
-
type: "union",
|
560
|
-
key: this.key,
|
561
|
-
items: this.items.map(function (o) {
|
562
|
-
return o.serialize();
|
563
|
-
}),
|
564
|
-
opt: this.opt
|
565
|
-
};
|
566
|
-
}
|
567
|
-
return {
|
568
|
-
type: "union",
|
569
|
-
key: this.key.serialize(),
|
570
|
-
items: this.items.map(function (o) {
|
571
|
-
return o.serialize();
|
572
|
-
}),
|
573
|
-
opt: this.opt
|
574
|
-
};
|
575
|
-
}
|
576
|
-
}]);
|
577
|
-
return UnionSchema;
|
578
|
-
}(index.Schema);
|
579
|
-
var union = function union(key) {
|
580
|
-
for (var _len = arguments.length, objects = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
581
|
-
objects[_key - 1] = arguments[_key];
|
582
|
-
}
|
583
|
-
return new UnionSchema(key, objects);
|
584
|
-
};
|
585
|
-
|
586
|
-
var RichTextSchema = /*#__PURE__*/function (_Schema) {
|
587
|
-
index._inherits(RichTextSchema, _Schema);
|
588
|
-
function RichTextSchema(options) {
|
589
|
-
var _this;
|
590
|
-
var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
591
|
-
index._classCallCheck(this, RichTextSchema);
|
592
|
-
_this = index._callSuper(this, RichTextSchema);
|
593
|
-
_this.options = options;
|
594
|
-
_this.opt = opt;
|
595
|
-
return _this;
|
596
|
-
}
|
597
|
-
index._createClass(RichTextSchema, [{
|
598
|
-
key: "validate",
|
599
|
-
value: function validate(path, src) {
|
600
|
-
return false; //TODO
|
601
|
-
}
|
602
|
-
}, {
|
603
|
-
key: "assert",
|
604
|
-
value: function assert(src) {
|
605
|
-
return true; // TODO
|
606
|
-
}
|
607
|
-
}, {
|
608
|
-
key: "nullable",
|
609
|
-
value: function nullable() {
|
610
|
-
return new RichTextSchema(this.options, true);
|
611
|
-
}
|
612
|
-
}, {
|
613
|
-
key: "serialize",
|
614
|
-
value: function serialize() {
|
615
|
-
return {
|
616
|
-
type: "richtext",
|
617
|
-
opt: this.opt,
|
618
|
-
options: this.options
|
619
|
-
};
|
620
|
-
}
|
621
|
-
}]);
|
622
|
-
return RichTextSchema;
|
623
|
-
}(index.Schema);
|
624
|
-
var richtext = function richtext(options) {
|
625
|
-
return new RichTextSchema(options !== null && options !== void 0 ? options : {});
|
626
|
-
};
|
627
|
-
|
628
|
-
var ImageSchema = /*#__PURE__*/function (_Schema) {
|
629
|
-
index._inherits(ImageSchema, _Schema);
|
630
|
-
function ImageSchema(options) {
|
631
|
-
var _this;
|
632
|
-
var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
633
|
-
index._classCallCheck(this, ImageSchema);
|
634
|
-
_this = index._callSuper(this, ImageSchema);
|
635
|
-
_this.options = options;
|
636
|
-
_this.opt = opt;
|
637
|
-
return _this;
|
638
|
-
}
|
639
|
-
index._createClass(ImageSchema, [{
|
640
|
-
key: "validate",
|
641
|
-
value: function validate(path, src) {
|
642
|
-
if (this.opt && (src === null || src === undefined)) {
|
643
|
-
return false;
|
644
|
-
}
|
645
|
-
if (src === null || src === undefined) {
|
646
|
-
return index._defineProperty({}, path, [{
|
647
|
-
message: "Non-optional image was null or undefined.",
|
648
|
-
value: src
|
649
|
-
}]);
|
650
|
-
}
|
651
|
-
if (typeof src[index.FILE_REF_PROP] !== "string") {
|
652
|
-
return index._defineProperty({}, path, [{
|
653
|
-
message: "Image did not have a file reference string. Got: ".concat(index._typeof(src[index.FILE_REF_PROP])),
|
654
|
-
value: src
|
655
|
-
}]);
|
656
|
-
}
|
657
|
-
if (src[index.VAL_EXTENSION] !== "file") {
|
658
|
-
return index._defineProperty({}, path, [{
|
659
|
-
message: "Image did not have the valid file extension type. Got: ".concat(src[index.VAL_EXTENSION]),
|
660
|
-
value: src
|
661
|
-
}]);
|
662
|
-
}
|
663
|
-
if (src.metadata) {
|
664
|
-
return index._defineProperty({}, path, [{
|
665
|
-
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).",
|
666
|
-
// 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.
|
667
|
-
value: src,
|
668
|
-
fixes: ["image:replace-metadata"]
|
669
|
-
}]);
|
670
|
-
}
|
671
|
-
return index._defineProperty({}, path, [{
|
672
|
-
message: "Could not validate Image metadata.",
|
673
|
-
value: src,
|
674
|
-
fixes: ["image:add-metadata"]
|
675
|
-
}]);
|
676
|
-
}
|
677
|
-
}, {
|
678
|
-
key: "assert",
|
679
|
-
value: function assert(src) {
|
680
|
-
if (this.opt && (src === null || src === undefined)) {
|
681
|
-
return true;
|
682
|
-
}
|
683
|
-
return (src === null || src === void 0 ? void 0 : src[index.FILE_REF_PROP]) === "image" && (src === null || src === void 0 ? void 0 : src[index.VAL_EXTENSION]) === "file";
|
684
|
-
}
|
685
|
-
}, {
|
686
|
-
key: "nullable",
|
687
|
-
value: function nullable() {
|
688
|
-
return new ImageSchema(this.options, true);
|
689
|
-
}
|
690
|
-
}, {
|
691
|
-
key: "serialize",
|
692
|
-
value: function serialize() {
|
693
|
-
return {
|
694
|
-
type: "image",
|
695
|
-
options: this.options,
|
696
|
-
opt: this.opt
|
697
|
-
};
|
698
|
-
}
|
699
|
-
}]);
|
700
|
-
return ImageSchema;
|
701
|
-
}(index.Schema);
|
702
|
-
var image = function image(options) {
|
703
|
-
return new ImageSchema(options);
|
704
|
-
};
|
705
|
-
|
706
|
-
var RecordSchema = /*#__PURE__*/function (_Schema) {
|
707
|
-
index._inherits(RecordSchema, _Schema);
|
708
|
-
function RecordSchema(item) {
|
709
|
-
var _this;
|
710
|
-
var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
711
|
-
index._classCallCheck(this, RecordSchema);
|
712
|
-
_this = index._callSuper(this, RecordSchema);
|
713
|
-
_this.item = item;
|
714
|
-
_this.opt = opt;
|
715
|
-
return _this;
|
716
|
-
}
|
717
|
-
index._createClass(RecordSchema, [{
|
718
|
-
key: "validate",
|
719
|
-
value: function validate(path, src) {
|
720
|
-
var _this2 = this;
|
721
|
-
var error = false;
|
722
|
-
if (this.opt && (src === null || src === undefined)) {
|
723
|
-
return false;
|
724
|
-
}
|
725
|
-
if (index._typeof(src) !== "object") {
|
726
|
-
return index._defineProperty({}, path, [{
|
727
|
-
message: "Expected 'object', got '".concat(index._typeof(src), "'")
|
728
|
-
}]);
|
729
|
-
}
|
730
|
-
if (Array.isArray(src)) {
|
731
|
-
return index._defineProperty({}, path, [{
|
732
|
-
message: "Expected 'object', got 'array'"
|
733
|
-
}]);
|
734
|
-
}
|
735
|
-
Object.entries(src).forEach(function (_ref3) {
|
736
|
-
var _ref4 = index._slicedToArray(_ref3, 2),
|
737
|
-
key = _ref4[0],
|
738
|
-
elem = _ref4[1];
|
739
|
-
var subPath = createValPathOfItem(path, key);
|
740
|
-
if (!subPath) {
|
741
|
-
error = _this2.appendValidationError(error, path, "Internal error: could not create path at ".concat(!path && typeof path === "string" ? "<empty string>" : path, " at key ").concat(elem),
|
742
|
-
// Should! never happen
|
743
|
-
src);
|
744
|
-
} else {
|
745
|
-
var subError = _this2.item.validate(subPath, elem);
|
746
|
-
if (subError && error) {
|
747
|
-
error = index._objectSpread2(index._objectSpread2({}, subError), error);
|
748
|
-
} else if (subError) {
|
749
|
-
error = subError;
|
750
|
-
}
|
751
|
-
}
|
752
|
-
});
|
753
|
-
return error;
|
754
|
-
}
|
755
|
-
}, {
|
756
|
-
key: "assert",
|
757
|
-
value: function assert(src) {
|
758
|
-
if (this.opt && (src === null || src === undefined)) {
|
759
|
-
return true;
|
760
|
-
}
|
761
|
-
if (!src) {
|
762
|
-
return false;
|
763
|
-
}
|
764
|
-
for (var _i = 0, _Object$entries = Object.entries(src); _i < _Object$entries.length; _i++) {
|
765
|
-
var _Object$entries$_i = index._slicedToArray(_Object$entries[_i], 2),
|
766
|
-
_item = _Object$entries$_i[1];
|
767
|
-
if (!this.item.assert(_item)) {
|
768
|
-
return false;
|
769
|
-
}
|
770
|
-
}
|
771
|
-
return index._typeof(src) === "object" && !Array.isArray(src);
|
772
|
-
}
|
773
|
-
}, {
|
774
|
-
key: "nullable",
|
775
|
-
value: function nullable() {
|
776
|
-
return new RecordSchema(this.item, true);
|
777
|
-
}
|
778
|
-
}, {
|
779
|
-
key: "serialize",
|
780
|
-
value: function serialize() {
|
781
|
-
return {
|
782
|
-
type: "record",
|
783
|
-
item: this.item.serialize(),
|
784
|
-
opt: this.opt
|
785
|
-
};
|
786
|
-
}
|
787
|
-
}]);
|
788
|
-
return RecordSchema;
|
789
|
-
}(index.Schema);
|
790
|
-
var record = function record(schema) {
|
791
|
-
return new RecordSchema(schema);
|
792
|
-
};
|
793
|
-
|
794
|
-
function define(
|
795
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
796
|
-
id,
|
797
|
-
// TODO: `/${string}`
|
798
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
799
|
-
schema,
|
800
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
801
|
-
source) {
|
802
|
-
return index._defineProperty(index._defineProperty(index._defineProperty({}, index.GetSource, source), index.GetSchema, schema), index.Path, id);
|
803
|
-
}
|
804
|
-
function getSource(valModule) {
|
805
|
-
var sourceOrExpr = valModule[index.GetSource];
|
806
|
-
if (sourceOrExpr instanceof index.Expr) {
|
807
|
-
throw Error("Cannot get raw source of an Expr");
|
808
|
-
}
|
809
|
-
var source = sourceOrExpr;
|
810
|
-
return source;
|
811
|
-
}
|
812
|
-
function splitModuleIdAndModulePath(path) {
|
813
|
-
if (path.indexOf(".") === -1) {
|
814
|
-
return [path, ""];
|
815
|
-
}
|
816
|
-
return [path.slice(0, path.indexOf(".")), path.slice(path.indexOf(".") + 1)];
|
817
|
-
}
|
818
|
-
function isObjectSchema(schema) {
|
819
|
-
return schema instanceof ObjectSchema || index._typeof(schema) === "object" && "type" in schema && schema.type === "object";
|
820
|
-
}
|
821
|
-
function isRecordSchema(schema) {
|
822
|
-
return schema instanceof RecordSchema || index._typeof(schema) === "object" && "type" in schema && schema.type === "record";
|
823
|
-
}
|
824
|
-
function isArraySchema(schema) {
|
825
|
-
return schema instanceof ArraySchema || index._typeof(schema) === "object" && "type" in schema && schema.type === "array";
|
826
|
-
}
|
827
|
-
|
828
|
-
// function isI18nSchema(
|
829
|
-
// schema: Schema<SelectorSource> | SerializedSchema
|
830
|
-
// ): schema is I18nSchema<readonly string[]> | SerializedI18nSchema {
|
831
|
-
// return (
|
832
|
-
// schema instanceof I18nSchema ||
|
833
|
-
// (typeof schema === "object" && "type" in schema && schema.type === "i18n")
|
834
|
-
// );
|
835
|
-
// }
|
836
|
-
|
837
|
-
function isUnionSchema(schema) {
|
838
|
-
return schema instanceof UnionSchema || index._typeof(schema) === "object" && "type" in schema && schema.type === "union";
|
839
|
-
}
|
840
|
-
|
841
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
842
|
-
function isRichTextSchema(schema) {
|
843
|
-
return schema instanceof RichTextSchema || index._typeof(schema) === "object" && "type" in schema && schema.type === "richtext";
|
844
|
-
}
|
845
|
-
function isImageSchema(schema) {
|
846
|
-
return schema instanceof ImageSchema || index._typeof(schema) === "object" && "type" in schema && schema.type === "image";
|
847
|
-
}
|
848
|
-
|
849
|
-
// function isOneOfSchema(
|
850
|
-
// schema: Schema<SelectorSource> | SerializedSchema
|
851
|
-
// ): schema is OneOfSchema<GenericSelector<SourceArray>> | SerializedOneOfSchema {
|
852
|
-
// return (
|
853
|
-
// schema instanceof OneOfSchema ||
|
854
|
-
// (typeof schema === "object" && "type" in schema && schema.type === "oneOf")
|
855
|
-
// );
|
856
|
-
// }
|
857
|
-
|
858
|
-
function resolvePath(path, valModule, schema) {
|
859
|
-
var parts = parsePath(path);
|
860
|
-
var origParts = index._toConsumableArray(parts);
|
861
|
-
var resolvedSchema = schema;
|
862
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
863
|
-
var resolvedSource = valModule;
|
864
|
-
var _loop = function _loop() {
|
865
|
-
var part = parts.shift();
|
866
|
-
if (part === undefined) {
|
867
|
-
throw Error("Unexpected undefined part");
|
868
|
-
}
|
869
|
-
if (isArraySchema(resolvedSchema)) {
|
870
|
-
if (Number.isNaN(Number(part))) {
|
871
|
-
throw Error("Invalid path: array schema ".concat(JSON.stringify(resolvedSchema), " must have a number as path, but got ").concat(part, ". Path: ").concat(path));
|
872
|
-
}
|
873
|
-
if (index._typeof(resolvedSource) !== "object" && !Array.isArray(resolvedSource)) {
|
874
|
-
throw Error("Schema type error: expected source to be type of array, but got ".concat(index._typeof(resolvedSource)));
|
875
|
-
}
|
876
|
-
if (resolvedSource[part] === undefined) {
|
877
|
-
var _resolvedSource;
|
878
|
-
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));
|
879
|
-
}
|
880
|
-
resolvedSource = resolvedSource[part];
|
881
|
-
resolvedSchema = resolvedSchema.item;
|
882
|
-
} else if (isRecordSchema(resolvedSchema)) {
|
883
|
-
if (typeof part !== "string") {
|
884
|
-
throw Error("Invalid path: record schema ".concat(resolvedSchema, " must have path: ").concat(part, " as string"));
|
885
|
-
}
|
886
|
-
if (index._typeof(resolvedSource) !== "object" && !Array.isArray(resolvedSource)) {
|
887
|
-
throw Error("Schema type error: expected source to be type of record, but got ".concat(index._typeof(resolvedSource)));
|
888
|
-
}
|
889
|
-
if (!resolvedSource[part]) {
|
890
|
-
throw Error("Invalid path: record source did not have key ".concat(part, " from path: ").concat(path));
|
891
|
-
}
|
892
|
-
resolvedSource = resolvedSource[part];
|
893
|
-
resolvedSchema = resolvedSchema.item;
|
894
|
-
} else if (isObjectSchema(resolvedSchema)) {
|
895
|
-
if (index._typeof(resolvedSource) !== "object") {
|
896
|
-
throw Error("Schema type error: expected source to be type of object, but got ".concat(index._typeof(resolvedSource)));
|
897
|
-
}
|
898
|
-
if (!resolvedSource[part]) {
|
899
|
-
throw Error("Invalid path: object source did not have key ".concat(part, " from path: ").concat(path));
|
900
|
-
}
|
901
|
-
resolvedSource = resolvedSource[part];
|
902
|
-
resolvedSchema = resolvedSchema.items[part];
|
903
|
-
// } else if (isI18nSchema(resolvedSchema)) {
|
904
|
-
// if (!resolvedSchema.locales.includes(part)) {
|
905
|
-
// throw Error(
|
906
|
-
// `Invalid path: i18n schema ${resolvedSchema} supports locales ${resolvedSchema.locales.join(
|
907
|
-
// ", "
|
908
|
-
// )}, but found: ${part}`
|
909
|
-
// );
|
910
|
-
// }
|
911
|
-
// if (!Object.keys(resolvedSource).includes(part)) {
|
912
|
-
// throw Error(
|
913
|
-
// `Schema type error: expected source to be type of i18n with locale ${part}, but got ${JSON.stringify(
|
914
|
-
// Object.keys(resolvedSource)
|
915
|
-
// )}`
|
916
|
-
// );
|
917
|
-
// }
|
918
|
-
// resolvedSource = resolvedSource[part];
|
919
|
-
// resolvedSchema = resolvedSchema.item;
|
920
|
-
} else if (isImageSchema(resolvedSchema)) {
|
921
|
-
return {
|
922
|
-
v: {
|
923
|
-
path: origParts.slice(0, origParts.length - parts.length - 1).map(function (p) {
|
924
|
-
return JSON.stringify(p);
|
925
|
-
}).join("."),
|
926
|
-
// TODO: create a function generate path from parts (not sure if this always works)
|
927
|
-
schema: resolvedSchema,
|
928
|
-
source: resolvedSource
|
929
|
-
}
|
930
|
-
};
|
931
|
-
} else if (isUnionSchema(resolvedSchema)) {
|
932
|
-
var _key = resolvedSchema.key;
|
933
|
-
if (typeof _key !== "string") {
|
934
|
-
return {
|
935
|
-
v: {
|
936
|
-
path: origParts.map(function (p) {
|
937
|
-
if (!Number.isNaN(Number(p))) {
|
938
|
-
return p;
|
939
|
-
} else {
|
940
|
-
return JSON.stringify(p);
|
941
|
-
}
|
942
|
-
}).join("."),
|
943
|
-
// TODO: create a function generate path from parts (not sure if this always works)
|
944
|
-
schema: resolvedSchema,
|
945
|
-
source: resolvedSource
|
946
|
-
}
|
947
|
-
};
|
948
|
-
}
|
949
|
-
var keyValue = resolvedSource[_key];
|
950
|
-
if (!keyValue) {
|
951
|
-
throw Error("Invalid path: union source ".concat(resolvedSchema, " did not have required key ").concat(_key, " in path: ").concat(path));
|
952
|
-
}
|
953
|
-
var schemaOfUnionKey = resolvedSchema.items.find(
|
954
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
955
|
-
function (child) {
|
956
|
-
var _child$items;
|
957
|
-
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;
|
958
|
-
});
|
959
|
-
if (!schemaOfUnionKey) {
|
960
|
-
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));
|
961
|
-
}
|
962
|
-
resolvedSchema = schemaOfUnionKey.items[part];
|
963
|
-
resolvedSource = resolvedSource[part];
|
964
|
-
} else if (isRichTextSchema(resolvedSchema)) {
|
965
|
-
return {
|
966
|
-
v: {
|
967
|
-
path: origParts.slice(0, origParts.length - parts.length - 1).map(function (p) {
|
968
|
-
return JSON.stringify(p);
|
969
|
-
}).join("."),
|
970
|
-
// TODO: create a function generate path from parts (not sure if this always works)
|
971
|
-
schema: resolvedSchema,
|
972
|
-
source: resolvedSource
|
973
|
-
}
|
974
|
-
};
|
975
|
-
} else {
|
976
|
-
throw Error("Invalid path: ".concat(part, " resolved to an unexpected schema ").concat(JSON.stringify(resolvedSchema)));
|
977
|
-
}
|
978
|
-
},
|
979
|
-
_ret;
|
980
|
-
while (parts.length > 0) {
|
981
|
-
_ret = _loop();
|
982
|
-
if (_ret) return _ret.v;
|
983
|
-
}
|
984
|
-
if (parts.length > 0) {
|
985
|
-
throw Error("Invalid path: ".concat(parts.join("."), " is not a valid path"));
|
986
|
-
}
|
987
|
-
return {
|
988
|
-
path: origParts.map(function (p) {
|
989
|
-
if (!Number.isNaN(Number(p))) {
|
990
|
-
return p;
|
991
|
-
} else {
|
992
|
-
return JSON.stringify(p);
|
993
|
-
}
|
994
|
-
}).join("."),
|
995
|
-
// TODO: create a function generate path from parts (not sure if this always works)
|
996
|
-
schema: resolvedSchema,
|
997
|
-
source: resolvedSource
|
998
|
-
};
|
999
|
-
}
|
1000
|
-
function parsePath(input) {
|
1001
|
-
var result = [];
|
1002
|
-
var i = 0;
|
1003
|
-
while (i < input.length) {
|
1004
|
-
var part = "";
|
1005
|
-
if (input[i] === '"') {
|
1006
|
-
// Parse a quoted string
|
1007
|
-
i++;
|
1008
|
-
while (i < input.length && input[i] !== '"') {
|
1009
|
-
if (input[i] === "\\" && input[i + 1] === '"') {
|
1010
|
-
// Handle escaped double quotes
|
1011
|
-
part += '"';
|
1012
|
-
i++;
|
1013
|
-
} else {
|
1014
|
-
part += input[i];
|
1015
|
-
}
|
1016
|
-
i++;
|
1017
|
-
}
|
1018
|
-
if (input[i] !== '"') {
|
1019
|
-
var _input$i;
|
1020
|
-
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, ")"));
|
1021
|
-
}
|
1022
|
-
} else {
|
1023
|
-
// Parse a regular string
|
1024
|
-
while (i < input.length && input[i] !== ".") {
|
1025
|
-
part += input[i];
|
1026
|
-
i++;
|
1027
|
-
}
|
1028
|
-
}
|
1029
|
-
if (part !== "") {
|
1030
|
-
result.push(part);
|
1031
|
-
}
|
1032
|
-
i++;
|
1033
|
-
}
|
1034
|
-
return result;
|
1035
|
-
}
|
1036
|
-
|
1037
|
-
var PatchError = /*#__PURE__*/index._createClass(function PatchError(message) {
|
1038
|
-
index._classCallCheck(this, PatchError);
|
1039
|
-
this.message = message;
|
1040
|
-
});
|
1041
|
-
|
1042
|
-
/**
|
1043
|
-
* NOTE: MAY mutate the input document.
|
1044
|
-
*/
|
1045
|
-
|
1046
|
-
exports.ArraySchema = ArraySchema;
|
1047
|
-
exports.ImageSchema = ImageSchema;
|
1048
|
-
exports.LiteralSchema = LiteralSchema;
|
1049
|
-
exports.ObjectSchema = ObjectSchema;
|
1050
|
-
exports.PatchError = PatchError;
|
1051
|
-
exports.RecordSchema = RecordSchema;
|
1052
|
-
exports.RichTextSchema = RichTextSchema;
|
1053
|
-
exports.UnionSchema = UnionSchema;
|
1054
|
-
exports.array = array;
|
1055
|
-
exports.createValPathOfItem = createValPathOfItem;
|
1056
|
-
exports.define = define;
|
1057
|
-
exports.getSource = getSource;
|
1058
|
-
exports.image = image;
|
1059
|
-
exports.isSelector = isSelector;
|
1060
|
-
exports.literal = literal;
|
1061
|
-
exports.newSelectorProxy = newSelectorProxy;
|
1062
|
-
exports.object = object;
|
1063
|
-
exports.parsePath = parsePath;
|
1064
|
-
exports.record = record;
|
1065
|
-
exports.resolvePath = resolvePath;
|
1066
|
-
exports.richtext = richtext;
|
1067
|
-
exports.splitModuleIdAndModulePath = splitModuleIdAndModulePath;
|
1068
|
-
exports.union = union;
|