@valbuild/core 0.33.0 → 0.35.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.
- package/dist/declarations/src/ValApi.d.ts +7 -3
- package/dist/declarations/src/index.d.ts +4 -11
- package/dist/declarations/src/initVal.d.ts +6 -0
- package/dist/{index-425d164d.cjs.prod.js → index-216627d7.cjs.prod.js} +3 -4
- package/dist/{index-f0475164.esm.js → index-4f821892.esm.js} +3 -4
- package/dist/{index-30eee5ec.cjs.prod.js → index-5bdaa229.cjs.prod.js} +27 -28
- package/dist/{index-a0f36fe3.cjs.dev.js → index-6deb169d.cjs.dev.js} +3 -4
- package/dist/{index-43369070.cjs.dev.js → index-a5295001.cjs.dev.js} +27 -28
- package/dist/{index-499b9e87.esm.js → index-c83918b8.esm.js} +28 -29
- package/dist/{ops-b263963e.cjs.prod.js → ops-6489efeb.cjs.prod.js} +102 -103
- package/dist/{ops-558f07b7.cjs.dev.js → ops-bec039cc.cjs.dev.js} +102 -103
- package/dist/{ops-1225f750.esm.js → ops-ce47df64.esm.js} +102 -103
- package/dist/valbuild-core.cjs.dev.js +69 -47
- package/dist/valbuild-core.cjs.prod.js +69 -47
- package/dist/valbuild-core.esm.js +70 -48
- package/expr/dist/valbuild-core-expr.cjs.dev.js +2 -2
- package/expr/dist/valbuild-core-expr.cjs.prod.js +2 -2
- package/expr/dist/valbuild-core-expr.esm.js +2 -2
- package/package.json +1 -1
- package/patch/dist/valbuild-core-patch.cjs.dev.js +2 -2
- package/patch/dist/valbuild-core-patch.cjs.prod.js +2 -2
- package/patch/dist/valbuild-core-patch.esm.js +3 -3
@@ -1,6 +1,6 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
|
-
var index = require('./index-
|
3
|
+
var index = require('./index-a5295001.cjs.dev.js');
|
4
4
|
var result = require('./result-48320acd.cjs.dev.js');
|
5
5
|
|
6
6
|
function hasOwn(obj, prop) {
|
@@ -16,7 +16,6 @@ function isSelector(source) {
|
|
16
16
|
return index._typeof(source) === "object" && source !== null && (index.GetSource in source || index.Path in source);
|
17
17
|
}
|
18
18
|
function newSelectorProxy(source, path, moduleSchema) {
|
19
|
-
var _ref;
|
20
19
|
if (index._typeof(source) === "object") {
|
21
20
|
if (isSelector(source)) {
|
22
21
|
return source;
|
@@ -114,7 +113,7 @@ function newSelectorProxy(source, path, moduleSchema) {
|
|
114
113
|
// intentional fallthrough
|
115
114
|
// eslint-disable-next-line no-fallthrough
|
116
115
|
default:
|
117
|
-
return
|
116
|
+
return index._defineProperty(index._defineProperty(index._defineProperty({
|
118
117
|
eq: function eq(other) {
|
119
118
|
var otherValue = other;
|
120
119
|
if (isSelector(other)) {
|
@@ -128,7 +127,7 @@ function newSelectorProxy(source, path, moduleSchema) {
|
|
128
127
|
andThen: function andThen(f) {
|
129
128
|
return _andThen(f, source === undefined ? null : source, path);
|
130
129
|
}
|
131
|
-
}, index.
|
130
|
+
}, index.GetSource, source === undefined ? null : source), index.Path, path), index.GetSchema, moduleSchema);
|
132
131
|
}
|
133
132
|
}
|
134
133
|
function createValPathOfItem(arrayPath, prop) {
|
@@ -517,8 +516,7 @@ id,
|
|
517
516
|
schema,
|
518
517
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
519
518
|
source) {
|
520
|
-
|
521
|
-
return _ref = {}, index._defineProperty(_ref, index.GetSource, source), index._defineProperty(_ref, index.GetSchema, schema), index._defineProperty(_ref, index.Path, id), _ref;
|
519
|
+
return index._defineProperty(index._defineProperty(index._defineProperty({}, index.GetSource, source), index.GetSchema, schema), index.Path, id);
|
522
520
|
}
|
523
521
|
function getSource(valModule) {
|
524
522
|
var sourceOrExpr = valModule[index.GetSource];
|
@@ -581,107 +579,108 @@ function resolvePath(path, valModule, schema) {
|
|
581
579
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
582
580
|
var resolvedSource = valModule;
|
583
581
|
var _loop = function _loop() {
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
}
|
588
|
-
if (isArraySchema(resolvedSchema)) {
|
589
|
-
if (Number.isNaN(Number(part))) {
|
590
|
-
throw Error("Invalid path: array schema ".concat(JSON.stringify(resolvedSchema), " must have a number as path, but got ").concat(part, ". Path: ").concat(path));
|
591
|
-
}
|
592
|
-
if (index._typeof(resolvedSource) !== "object" && !Array.isArray(resolvedSource)) {
|
593
|
-
throw Error("Schema type error: expected source to be type of array, but got ".concat(index._typeof(resolvedSource)));
|
594
|
-
}
|
595
|
-
if (!resolvedSource[part]) {
|
596
|
-
var _resolvedSource;
|
597
|
-
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));
|
598
|
-
}
|
599
|
-
resolvedSource = resolvedSource[part];
|
600
|
-
resolvedSchema = resolvedSchema.item;
|
601
|
-
} else if (isRecordSchema(resolvedSchema)) {
|
602
|
-
if (typeof part !== "string") {
|
603
|
-
throw Error("Invalid path: record schema ".concat(resolvedSchema, " must have path: ").concat(part, " as string"));
|
604
|
-
}
|
605
|
-
if (index._typeof(resolvedSource) !== "object" && !Array.isArray(resolvedSource)) {
|
606
|
-
throw Error("Schema type error: expected source to be type of record, but got ".concat(index._typeof(resolvedSource)));
|
607
|
-
}
|
608
|
-
if (!resolvedSource[part]) {
|
609
|
-
throw Error("Invalid path: record source did not have key ".concat(part, " from path: ").concat(path));
|
610
|
-
}
|
611
|
-
resolvedSource = resolvedSource[part];
|
612
|
-
resolvedSchema = resolvedSchema.item;
|
613
|
-
} else if (isObjectSchema(resolvedSchema)) {
|
614
|
-
if (index._typeof(resolvedSource) !== "object") {
|
615
|
-
throw Error("Schema type error: expected source to be type of object, but got ".concat(index._typeof(resolvedSource)));
|
616
|
-
}
|
617
|
-
if (!resolvedSource[part]) {
|
618
|
-
throw Error("Invalid path: object source did not have key ".concat(part, " from path: ").concat(path));
|
582
|
+
var part = parts.shift();
|
583
|
+
if (part === undefined) {
|
584
|
+
throw Error("Unexpected undefined part");
|
619
585
|
}
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
// if (!resolvedSchema.locales.includes(part)) {
|
624
|
-
// throw Error(
|
625
|
-
// `Invalid path: i18n schema ${resolvedSchema} supports locales ${resolvedSchema.locales.join(
|
626
|
-
// ", "
|
627
|
-
// )}, but found: ${part}`
|
628
|
-
// );
|
629
|
-
// }
|
630
|
-
// if (!Object.keys(resolvedSource).includes(part)) {
|
631
|
-
// throw Error(
|
632
|
-
// `Schema type error: expected source to be type of i18n with locale ${part}, but got ${JSON.stringify(
|
633
|
-
// Object.keys(resolvedSource)
|
634
|
-
// )}`
|
635
|
-
// );
|
636
|
-
// }
|
637
|
-
// resolvedSource = resolvedSource[part];
|
638
|
-
// resolvedSchema = resolvedSchema.item;
|
639
|
-
} else if (isImageSchema(resolvedSchema)) {
|
640
|
-
return {
|
641
|
-
v: {
|
642
|
-
path: origParts.slice(0, origParts.length - parts.length - 1).map(function (p) {
|
643
|
-
return JSON.stringify(p);
|
644
|
-
}).join("."),
|
645
|
-
// TODO: create a function generate path from parts (not sure if this always works)
|
646
|
-
schema: resolvedSchema,
|
647
|
-
source: resolvedSource
|
586
|
+
if (isArraySchema(resolvedSchema)) {
|
587
|
+
if (Number.isNaN(Number(part))) {
|
588
|
+
throw Error("Invalid path: array schema ".concat(JSON.stringify(resolvedSchema), " must have a number as path, but got ").concat(part, ". Path: ").concat(path));
|
648
589
|
}
|
649
|
-
|
650
|
-
|
651
|
-
var _key = resolvedSchema.key;
|
652
|
-
var keyValue = resolvedSource[_key];
|
653
|
-
if (!keyValue) {
|
654
|
-
throw Error("Invalid path: union source ".concat(resolvedSchema, " did not have required key ").concat(_key, " in path: ").concat(path));
|
655
|
-
}
|
656
|
-
var schemaOfUnionKey = resolvedSchema.items.find(
|
657
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
658
|
-
function (child) {
|
659
|
-
var _child$items, _child$items$_key;
|
660
|
-
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;
|
661
|
-
});
|
662
|
-
if (!schemaOfUnionKey) {
|
663
|
-
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));
|
664
|
-
}
|
665
|
-
resolvedSchema = schemaOfUnionKey.items[part];
|
666
|
-
resolvedSource = resolvedSource[part];
|
667
|
-
} else if (isRichTextSchema(resolvedSchema)) {
|
668
|
-
return {
|
669
|
-
v: {
|
670
|
-
path: origParts.slice(0, origParts.length - parts.length - 1).map(function (p) {
|
671
|
-
return JSON.stringify(p);
|
672
|
-
}).join("."),
|
673
|
-
// TODO: create a function generate path from parts (not sure if this always works)
|
674
|
-
schema: resolvedSchema,
|
675
|
-
source: resolvedSource
|
590
|
+
if (index._typeof(resolvedSource) !== "object" && !Array.isArray(resolvedSource)) {
|
591
|
+
throw Error("Schema type error: expected source to be type of array, but got ".concat(index._typeof(resolvedSource)));
|
676
592
|
}
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
593
|
+
if (!resolvedSource[part]) {
|
594
|
+
var _resolvedSource;
|
595
|
+
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));
|
596
|
+
}
|
597
|
+
resolvedSource = resolvedSource[part];
|
598
|
+
resolvedSchema = resolvedSchema.item;
|
599
|
+
} else if (isRecordSchema(resolvedSchema)) {
|
600
|
+
if (typeof part !== "string") {
|
601
|
+
throw Error("Invalid path: record schema ".concat(resolvedSchema, " must have path: ").concat(part, " as string"));
|
602
|
+
}
|
603
|
+
if (index._typeof(resolvedSource) !== "object" && !Array.isArray(resolvedSource)) {
|
604
|
+
throw Error("Schema type error: expected source to be type of record, but got ".concat(index._typeof(resolvedSource)));
|
605
|
+
}
|
606
|
+
if (!resolvedSource[part]) {
|
607
|
+
throw Error("Invalid path: record source did not have key ".concat(part, " from path: ").concat(path));
|
608
|
+
}
|
609
|
+
resolvedSource = resolvedSource[part];
|
610
|
+
resolvedSchema = resolvedSchema.item;
|
611
|
+
} else if (isObjectSchema(resolvedSchema)) {
|
612
|
+
if (index._typeof(resolvedSource) !== "object") {
|
613
|
+
throw Error("Schema type error: expected source to be type of object, but got ".concat(index._typeof(resolvedSource)));
|
614
|
+
}
|
615
|
+
if (!resolvedSource[part]) {
|
616
|
+
throw Error("Invalid path: object source did not have key ".concat(part, " from path: ").concat(path));
|
617
|
+
}
|
618
|
+
resolvedSource = resolvedSource[part];
|
619
|
+
resolvedSchema = resolvedSchema.items[part];
|
620
|
+
// } else if (isI18nSchema(resolvedSchema)) {
|
621
|
+
// if (!resolvedSchema.locales.includes(part)) {
|
622
|
+
// throw Error(
|
623
|
+
// `Invalid path: i18n schema ${resolvedSchema} supports locales ${resolvedSchema.locales.join(
|
624
|
+
// ", "
|
625
|
+
// )}, but found: ${part}`
|
626
|
+
// );
|
627
|
+
// }
|
628
|
+
// if (!Object.keys(resolvedSource).includes(part)) {
|
629
|
+
// throw Error(
|
630
|
+
// `Schema type error: expected source to be type of i18n with locale ${part}, but got ${JSON.stringify(
|
631
|
+
// Object.keys(resolvedSource)
|
632
|
+
// )}`
|
633
|
+
// );
|
634
|
+
// }
|
635
|
+
// resolvedSource = resolvedSource[part];
|
636
|
+
// resolvedSchema = resolvedSchema.item;
|
637
|
+
} else if (isImageSchema(resolvedSchema)) {
|
638
|
+
return {
|
639
|
+
v: {
|
640
|
+
path: origParts.slice(0, origParts.length - parts.length - 1).map(function (p) {
|
641
|
+
return JSON.stringify(p);
|
642
|
+
}).join("."),
|
643
|
+
// TODO: create a function generate path from parts (not sure if this always works)
|
644
|
+
schema: resolvedSchema,
|
645
|
+
source: resolvedSource
|
646
|
+
}
|
647
|
+
};
|
648
|
+
} else if (isUnionSchema(resolvedSchema)) {
|
649
|
+
var _key = resolvedSchema.key;
|
650
|
+
var keyValue = resolvedSource[_key];
|
651
|
+
if (!keyValue) {
|
652
|
+
throw Error("Invalid path: union source ".concat(resolvedSchema, " did not have required key ").concat(_key, " in path: ").concat(path));
|
653
|
+
}
|
654
|
+
var schemaOfUnionKey = resolvedSchema.items.find(
|
655
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
656
|
+
function (child) {
|
657
|
+
var _child$items;
|
658
|
+
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;
|
659
|
+
});
|
660
|
+
if (!schemaOfUnionKey) {
|
661
|
+
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));
|
662
|
+
}
|
663
|
+
resolvedSchema = schemaOfUnionKey.items[part];
|
664
|
+
resolvedSource = resolvedSource[part];
|
665
|
+
} else if (isRichTextSchema(resolvedSchema)) {
|
666
|
+
return {
|
667
|
+
v: {
|
668
|
+
path: origParts.slice(0, origParts.length - parts.length - 1).map(function (p) {
|
669
|
+
return JSON.stringify(p);
|
670
|
+
}).join("."),
|
671
|
+
// TODO: create a function generate path from parts (not sure if this always works)
|
672
|
+
schema: resolvedSchema,
|
673
|
+
source: resolvedSource
|
674
|
+
}
|
675
|
+
};
|
676
|
+
} else {
|
677
|
+
throw Error("Invalid path: ".concat(part, " resolved to an unexpected schema ").concat(JSON.stringify(resolvedSchema)));
|
678
|
+
}
|
679
|
+
},
|
680
|
+
_ret;
|
682
681
|
while (parts.length > 0) {
|
683
|
-
|
684
|
-
if (
|
682
|
+
_ret = _loop();
|
683
|
+
if (_ret) return _ret.v;
|
685
684
|
}
|
686
685
|
if (parts.length > 0) {
|
687
686
|
throw Error("Invalid path: ".concat(parts.join("."), " is not a valid path"));
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { e as _typeof,
|
1
|
+
import { e as _typeof, l as isSerializedVal, F as FILE_REF_PROP, V as VAL_EXTENSION, m as convertFileSource, d as _defineProperty, G as GetSchema, k as GetSource, E as Expr, P as Path, S as Schema, _ as _inherits, a as _createSuper, b as _classCallCheck, c as _createClass, h as _slicedToArray, q as _objectSpread2, u as _toConsumableArray, I as ImageSchema } from './index-c83918b8.esm.js';
|
2
2
|
import { _ as _createForOfIteratorHelper } from './result-b96df128.esm.js';
|
3
3
|
|
4
4
|
function hasOwn(obj, prop) {
|
@@ -14,7 +14,6 @@ function isSelector(source) {
|
|
14
14
|
return _typeof(source) === "object" && source !== null && (GetSource in source || Path in source);
|
15
15
|
}
|
16
16
|
function newSelectorProxy(source, path, moduleSchema) {
|
17
|
-
var _ref;
|
18
17
|
if (_typeof(source) === "object") {
|
19
18
|
if (isSelector(source)) {
|
20
19
|
return source;
|
@@ -112,7 +111,7 @@ function newSelectorProxy(source, path, moduleSchema) {
|
|
112
111
|
// intentional fallthrough
|
113
112
|
// eslint-disable-next-line no-fallthrough
|
114
113
|
default:
|
115
|
-
return
|
114
|
+
return _defineProperty(_defineProperty(_defineProperty({
|
116
115
|
eq: function eq(other) {
|
117
116
|
var otherValue = other;
|
118
117
|
if (isSelector(other)) {
|
@@ -126,7 +125,7 @@ function newSelectorProxy(source, path, moduleSchema) {
|
|
126
125
|
andThen: function andThen(f) {
|
127
126
|
return _andThen(f, source === undefined ? null : source, path);
|
128
127
|
}
|
129
|
-
},
|
128
|
+
}, GetSource, source === undefined ? null : source), Path, path), GetSchema, moduleSchema);
|
130
129
|
}
|
131
130
|
}
|
132
131
|
function createValPathOfItem(arrayPath, prop) {
|
@@ -515,8 +514,7 @@ id,
|
|
515
514
|
schema,
|
516
515
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
517
516
|
source) {
|
518
|
-
|
519
|
-
return _ref = {}, _defineProperty(_ref, GetSource, source), _defineProperty(_ref, GetSchema, schema), _defineProperty(_ref, Path, id), _ref;
|
517
|
+
return _defineProperty(_defineProperty(_defineProperty({}, GetSource, source), GetSchema, schema), Path, id);
|
520
518
|
}
|
521
519
|
function getSource(valModule) {
|
522
520
|
var sourceOrExpr = valModule[GetSource];
|
@@ -579,107 +577,108 @@ function resolvePath(path, valModule, schema) {
|
|
579
577
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
580
578
|
var resolvedSource = valModule;
|
581
579
|
var _loop = function _loop() {
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
}
|
586
|
-
if (isArraySchema(resolvedSchema)) {
|
587
|
-
if (Number.isNaN(Number(part))) {
|
588
|
-
throw Error("Invalid path: array schema ".concat(JSON.stringify(resolvedSchema), " must have a number as path, but got ").concat(part, ". Path: ").concat(path));
|
589
|
-
}
|
590
|
-
if (_typeof(resolvedSource) !== "object" && !Array.isArray(resolvedSource)) {
|
591
|
-
throw Error("Schema type error: expected source to be type of array, but got ".concat(_typeof(resolvedSource)));
|
592
|
-
}
|
593
|
-
if (!resolvedSource[part]) {
|
594
|
-
var _resolvedSource;
|
595
|
-
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));
|
596
|
-
}
|
597
|
-
resolvedSource = resolvedSource[part];
|
598
|
-
resolvedSchema = resolvedSchema.item;
|
599
|
-
} else if (isRecordSchema(resolvedSchema)) {
|
600
|
-
if (typeof part !== "string") {
|
601
|
-
throw Error("Invalid path: record schema ".concat(resolvedSchema, " must have path: ").concat(part, " as string"));
|
602
|
-
}
|
603
|
-
if (_typeof(resolvedSource) !== "object" && !Array.isArray(resolvedSource)) {
|
604
|
-
throw Error("Schema type error: expected source to be type of record, but got ".concat(_typeof(resolvedSource)));
|
605
|
-
}
|
606
|
-
if (!resolvedSource[part]) {
|
607
|
-
throw Error("Invalid path: record source did not have key ".concat(part, " from path: ").concat(path));
|
608
|
-
}
|
609
|
-
resolvedSource = resolvedSource[part];
|
610
|
-
resolvedSchema = resolvedSchema.item;
|
611
|
-
} else if (isObjectSchema(resolvedSchema)) {
|
612
|
-
if (_typeof(resolvedSource) !== "object") {
|
613
|
-
throw Error("Schema type error: expected source to be type of object, but got ".concat(_typeof(resolvedSource)));
|
614
|
-
}
|
615
|
-
if (!resolvedSource[part]) {
|
616
|
-
throw Error("Invalid path: object source did not have key ".concat(part, " from path: ").concat(path));
|
580
|
+
var part = parts.shift();
|
581
|
+
if (part === undefined) {
|
582
|
+
throw Error("Unexpected undefined part");
|
617
583
|
}
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
// if (!resolvedSchema.locales.includes(part)) {
|
622
|
-
// throw Error(
|
623
|
-
// `Invalid path: i18n schema ${resolvedSchema} supports locales ${resolvedSchema.locales.join(
|
624
|
-
// ", "
|
625
|
-
// )}, but found: ${part}`
|
626
|
-
// );
|
627
|
-
// }
|
628
|
-
// if (!Object.keys(resolvedSource).includes(part)) {
|
629
|
-
// throw Error(
|
630
|
-
// `Schema type error: expected source to be type of i18n with locale ${part}, but got ${JSON.stringify(
|
631
|
-
// Object.keys(resolvedSource)
|
632
|
-
// )}`
|
633
|
-
// );
|
634
|
-
// }
|
635
|
-
// resolvedSource = resolvedSource[part];
|
636
|
-
// resolvedSchema = resolvedSchema.item;
|
637
|
-
} else if (isImageSchema(resolvedSchema)) {
|
638
|
-
return {
|
639
|
-
v: {
|
640
|
-
path: origParts.slice(0, origParts.length - parts.length - 1).map(function (p) {
|
641
|
-
return JSON.stringify(p);
|
642
|
-
}).join("."),
|
643
|
-
// TODO: create a function generate path from parts (not sure if this always works)
|
644
|
-
schema: resolvedSchema,
|
645
|
-
source: resolvedSource
|
584
|
+
if (isArraySchema(resolvedSchema)) {
|
585
|
+
if (Number.isNaN(Number(part))) {
|
586
|
+
throw Error("Invalid path: array schema ".concat(JSON.stringify(resolvedSchema), " must have a number as path, but got ").concat(part, ". Path: ").concat(path));
|
646
587
|
}
|
647
|
-
|
648
|
-
|
649
|
-
var _key = resolvedSchema.key;
|
650
|
-
var keyValue = resolvedSource[_key];
|
651
|
-
if (!keyValue) {
|
652
|
-
throw Error("Invalid path: union source ".concat(resolvedSchema, " did not have required key ").concat(_key, " in path: ").concat(path));
|
653
|
-
}
|
654
|
-
var schemaOfUnionKey = resolvedSchema.items.find(
|
655
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
656
|
-
function (child) {
|
657
|
-
var _child$items, _child$items$_key;
|
658
|
-
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;
|
659
|
-
});
|
660
|
-
if (!schemaOfUnionKey) {
|
661
|
-
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));
|
662
|
-
}
|
663
|
-
resolvedSchema = schemaOfUnionKey.items[part];
|
664
|
-
resolvedSource = resolvedSource[part];
|
665
|
-
} else if (isRichTextSchema(resolvedSchema)) {
|
666
|
-
return {
|
667
|
-
v: {
|
668
|
-
path: origParts.slice(0, origParts.length - parts.length - 1).map(function (p) {
|
669
|
-
return JSON.stringify(p);
|
670
|
-
}).join("."),
|
671
|
-
// TODO: create a function generate path from parts (not sure if this always works)
|
672
|
-
schema: resolvedSchema,
|
673
|
-
source: resolvedSource
|
588
|
+
if (_typeof(resolvedSource) !== "object" && !Array.isArray(resolvedSource)) {
|
589
|
+
throw Error("Schema type error: expected source to be type of array, but got ".concat(_typeof(resolvedSource)));
|
674
590
|
}
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
591
|
+
if (!resolvedSource[part]) {
|
592
|
+
var _resolvedSource;
|
593
|
+
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));
|
594
|
+
}
|
595
|
+
resolvedSource = resolvedSource[part];
|
596
|
+
resolvedSchema = resolvedSchema.item;
|
597
|
+
} else if (isRecordSchema(resolvedSchema)) {
|
598
|
+
if (typeof part !== "string") {
|
599
|
+
throw Error("Invalid path: record schema ".concat(resolvedSchema, " must have path: ").concat(part, " as string"));
|
600
|
+
}
|
601
|
+
if (_typeof(resolvedSource) !== "object" && !Array.isArray(resolvedSource)) {
|
602
|
+
throw Error("Schema type error: expected source to be type of record, but got ".concat(_typeof(resolvedSource)));
|
603
|
+
}
|
604
|
+
if (!resolvedSource[part]) {
|
605
|
+
throw Error("Invalid path: record source did not have key ".concat(part, " from path: ").concat(path));
|
606
|
+
}
|
607
|
+
resolvedSource = resolvedSource[part];
|
608
|
+
resolvedSchema = resolvedSchema.item;
|
609
|
+
} else if (isObjectSchema(resolvedSchema)) {
|
610
|
+
if (_typeof(resolvedSource) !== "object") {
|
611
|
+
throw Error("Schema type error: expected source to be type of object, but got ".concat(_typeof(resolvedSource)));
|
612
|
+
}
|
613
|
+
if (!resolvedSource[part]) {
|
614
|
+
throw Error("Invalid path: object source did not have key ".concat(part, " from path: ").concat(path));
|
615
|
+
}
|
616
|
+
resolvedSource = resolvedSource[part];
|
617
|
+
resolvedSchema = resolvedSchema.items[part];
|
618
|
+
// } else if (isI18nSchema(resolvedSchema)) {
|
619
|
+
// if (!resolvedSchema.locales.includes(part)) {
|
620
|
+
// throw Error(
|
621
|
+
// `Invalid path: i18n schema ${resolvedSchema} supports locales ${resolvedSchema.locales.join(
|
622
|
+
// ", "
|
623
|
+
// )}, but found: ${part}`
|
624
|
+
// );
|
625
|
+
// }
|
626
|
+
// if (!Object.keys(resolvedSource).includes(part)) {
|
627
|
+
// throw Error(
|
628
|
+
// `Schema type error: expected source to be type of i18n with locale ${part}, but got ${JSON.stringify(
|
629
|
+
// Object.keys(resolvedSource)
|
630
|
+
// )}`
|
631
|
+
// );
|
632
|
+
// }
|
633
|
+
// resolvedSource = resolvedSource[part];
|
634
|
+
// resolvedSchema = resolvedSchema.item;
|
635
|
+
} else if (isImageSchema(resolvedSchema)) {
|
636
|
+
return {
|
637
|
+
v: {
|
638
|
+
path: origParts.slice(0, origParts.length - parts.length - 1).map(function (p) {
|
639
|
+
return JSON.stringify(p);
|
640
|
+
}).join("."),
|
641
|
+
// TODO: create a function generate path from parts (not sure if this always works)
|
642
|
+
schema: resolvedSchema,
|
643
|
+
source: resolvedSource
|
644
|
+
}
|
645
|
+
};
|
646
|
+
} else if (isUnionSchema(resolvedSchema)) {
|
647
|
+
var _key = resolvedSchema.key;
|
648
|
+
var keyValue = resolvedSource[_key];
|
649
|
+
if (!keyValue) {
|
650
|
+
throw Error("Invalid path: union source ".concat(resolvedSchema, " did not have required key ").concat(_key, " in path: ").concat(path));
|
651
|
+
}
|
652
|
+
var schemaOfUnionKey = resolvedSchema.items.find(
|
653
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
654
|
+
function (child) {
|
655
|
+
var _child$items;
|
656
|
+
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;
|
657
|
+
});
|
658
|
+
if (!schemaOfUnionKey) {
|
659
|
+
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));
|
660
|
+
}
|
661
|
+
resolvedSchema = schemaOfUnionKey.items[part];
|
662
|
+
resolvedSource = resolvedSource[part];
|
663
|
+
} else if (isRichTextSchema(resolvedSchema)) {
|
664
|
+
return {
|
665
|
+
v: {
|
666
|
+
path: origParts.slice(0, origParts.length - parts.length - 1).map(function (p) {
|
667
|
+
return JSON.stringify(p);
|
668
|
+
}).join("."),
|
669
|
+
// TODO: create a function generate path from parts (not sure if this always works)
|
670
|
+
schema: resolvedSchema,
|
671
|
+
source: resolvedSource
|
672
|
+
}
|
673
|
+
};
|
674
|
+
} else {
|
675
|
+
throw Error("Invalid path: ".concat(part, " resolved to an unexpected schema ").concat(JSON.stringify(resolvedSchema)));
|
676
|
+
}
|
677
|
+
},
|
678
|
+
_ret;
|
680
679
|
while (parts.length > 0) {
|
681
|
-
|
682
|
-
if (
|
680
|
+
_ret = _loop();
|
681
|
+
if (_ret) return _ret.v;
|
683
682
|
}
|
684
683
|
if (parts.length > 0) {
|
685
684
|
throw Error("Invalid path: ".concat(parts.join("."), " is not a valid path"));
|