@valbuild/core 0.79.0 → 0.79.2
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/index.d.ts +2 -1
- package/dist/declarations/src/module.d.ts +12 -0
- package/dist/{index-8324579e.cjs.dev.js → index-041f7675.cjs.dev.js} +228 -0
- package/dist/{index-67e35487.esm.js → index-1d5e4912.esm.js} +228 -0
- package/dist/{index-1e9b5668.cjs.prod.js → index-3ecf0ca6.cjs.prod.js} +228 -0
- package/dist/valbuild-core.cjs.dev.js +1 -1
- package/dist/valbuild-core.cjs.prod.js +1 -1
- package/dist/valbuild-core.esm.js +1 -1
- package/package.json +1 -1
- package/patch/dist/valbuild-core-patch.cjs.dev.js +1 -1
- package/patch/dist/valbuild-core-patch.cjs.prod.js +1 -1
- package/patch/dist/valbuild-core-patch.esm.js +2 -2
@@ -20,7 +20,7 @@ export { FILE_REF_PROP, FILE_REF_SUBTYPE_TAG } from "./source/file.js";
|
|
20
20
|
export { VAL_EXTENSION, type SourceArray } from "./source/index.js";
|
21
21
|
export { derefPatch } from "./patch/deref.js";
|
22
22
|
export { type SelectorSource, type SelectorOf, GenericSelector, } from "./selector/index.js";
|
23
|
-
import { getSource, splitModulePath, splitModuleFilePath, resolvePath, splitModuleFilePathAndModulePath, joinModuleFilePathAndModulePath, parentOfSourcePath, patchPathToModulePath, splitJoinedSourcePaths } from "./module.js";
|
23
|
+
import { getSource, splitModulePath, splitModuleFilePath, resolvePath, safeResolvePath, splitModuleFilePathAndModulePath, joinModuleFilePathAndModulePath, parentOfSourcePath, patchPathToModulePath, splitJoinedSourcePaths } from "./module.js";
|
24
24
|
declare const ModuleFilePathSep = "?p=";
|
25
25
|
export { ModuleFilePathSep };
|
26
26
|
import { getSchema } from "./selector/index.js";
|
@@ -67,6 +67,7 @@ declare const Internal: {
|
|
67
67
|
getValPath: typeof getValPath;
|
68
68
|
getSource: typeof getSource;
|
69
69
|
resolvePath: typeof resolvePath;
|
70
|
+
safeResolvePath: typeof safeResolvePath;
|
70
71
|
splitModuleFilePathAndModulePath: typeof splitModuleFilePathAndModulePath;
|
71
72
|
joinModuleFilePathAndModulePath: typeof joinModuleFilePathAndModulePath;
|
72
73
|
remote: {
|
@@ -28,6 +28,18 @@ export declare function resolvePath<Src extends ValModule<SelectorSource> | Sour
|
|
28
28
|
schema: Sch;
|
29
29
|
source: Src;
|
30
30
|
};
|
31
|
+
export declare function safeResolvePath<Src extends ValModule<SelectorSource> | Source, Sch extends Schema<SelectorSource> | SerializedSchema>(path: ModulePath, valModule: Src, schema: Sch): {
|
32
|
+
status: "ok";
|
33
|
+
path: SourcePath;
|
34
|
+
schema: Sch;
|
35
|
+
source: Src;
|
36
|
+
} | {
|
37
|
+
status: "source-undefined";
|
38
|
+
path: SourcePath;
|
39
|
+
} | {
|
40
|
+
status: "error";
|
41
|
+
message: string;
|
42
|
+
};
|
31
43
|
export declare function splitModuleFilePath(input: ModuleFilePath): string[];
|
32
44
|
export declare function splitModulePath(input: ModulePath): string[];
|
33
45
|
export declare function splitJoinedSourcePaths(input: string): SourcePath[];
|
@@ -2438,6 +2438,233 @@ function resolvePath(path, valModule, schema) {
|
|
2438
2438
|
source: resolvedSource
|
2439
2439
|
};
|
2440
2440
|
}
|
2441
|
+
|
2442
|
+
// TODO: replace all usages of resolvePath with safeResolvePath
|
2443
|
+
function safeResolvePath(path, valModule, schema) {
|
2444
|
+
var parts = splitModulePath(path);
|
2445
|
+
var origParts = _toConsumableArray(parts);
|
2446
|
+
var resolvedSchema = schema;
|
2447
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
2448
|
+
var resolvedSource = valModule;
|
2449
|
+
var _loop2 = function _loop2() {
|
2450
|
+
var part = parts.shift();
|
2451
|
+
if (part === undefined) {
|
2452
|
+
return {
|
2453
|
+
v: {
|
2454
|
+
status: "error",
|
2455
|
+
message: "Unexpected undefined part"
|
2456
|
+
}
|
2457
|
+
};
|
2458
|
+
}
|
2459
|
+
if (isArraySchema(resolvedSchema)) {
|
2460
|
+
if (Number.isNaN(Number(part))) {
|
2461
|
+
return {
|
2462
|
+
v: {
|
2463
|
+
status: "error",
|
2464
|
+
message: "Invalid path: array schema ".concat(JSON.stringify(resolvedSchema), " must have a number as path, but got ").concat(part, ". Path: ").concat(path)
|
2465
|
+
}
|
2466
|
+
};
|
2467
|
+
}
|
2468
|
+
if (resolvedSource === undefined) {
|
2469
|
+
return {
|
2470
|
+
v: {
|
2471
|
+
status: "source-undefined",
|
2472
|
+
path: origParts.slice(0, origParts.length - parts.length - 1).map(function (p) {
|
2473
|
+
return JSON.stringify(p);
|
2474
|
+
}).join(".") // TODO: create a function generate path from parts (not sure if this always works)
|
2475
|
+
}
|
2476
|
+
};
|
2477
|
+
}
|
2478
|
+
if (_typeof(resolvedSource) !== "object" && !Array.isArray(resolvedSource)) {
|
2479
|
+
return {
|
2480
|
+
v: {
|
2481
|
+
status: "error",
|
2482
|
+
message: "Schema type error: expected source to be type of array, but got ".concat(_typeof(resolvedSource))
|
2483
|
+
}
|
2484
|
+
};
|
2485
|
+
}
|
2486
|
+
resolvedSource = resolvedSource[part];
|
2487
|
+
resolvedSchema = resolvedSchema.item;
|
2488
|
+
} else if (isRecordSchema(resolvedSchema)) {
|
2489
|
+
if (typeof part !== "string") {
|
2490
|
+
return {
|
2491
|
+
v: {
|
2492
|
+
status: "error",
|
2493
|
+
message: "Invalid path: record schema ".concat(resolvedSchema, " must have path: ").concat(part, " as string")
|
2494
|
+
}
|
2495
|
+
};
|
2496
|
+
}
|
2497
|
+
if (resolvedSource === undefined) {
|
2498
|
+
return {
|
2499
|
+
v: {
|
2500
|
+
status: "source-undefined",
|
2501
|
+
path: origParts.slice(0, origParts.length - parts.length - 1).map(function (p) {
|
2502
|
+
return JSON.stringify(p);
|
2503
|
+
}).join(".") // TODO: create a function generate path from parts (not sure if this always works)
|
2504
|
+
}
|
2505
|
+
};
|
2506
|
+
}
|
2507
|
+
if (_typeof(resolvedSource) !== "object" && !Array.isArray(resolvedSource)) {
|
2508
|
+
return {
|
2509
|
+
v: {
|
2510
|
+
status: "error",
|
2511
|
+
message: "Schema type error: expected source to be type of record, but got ".concat(_typeof(resolvedSource))
|
2512
|
+
}
|
2513
|
+
};
|
2514
|
+
}
|
2515
|
+
if (!resolvedSource[part]) {
|
2516
|
+
return {
|
2517
|
+
v: {
|
2518
|
+
status: "error",
|
2519
|
+
message: "Invalid path: record source did not have key ".concat(part, " from path: ").concat(path)
|
2520
|
+
}
|
2521
|
+
};
|
2522
|
+
}
|
2523
|
+
resolvedSource = resolvedSource[part];
|
2524
|
+
resolvedSchema = resolvedSchema.item;
|
2525
|
+
} else if (isObjectSchema(resolvedSchema)) {
|
2526
|
+
if (resolvedSource === undefined) {
|
2527
|
+
return {
|
2528
|
+
v: {
|
2529
|
+
status: "source-undefined",
|
2530
|
+
path: origParts.slice(0, origParts.length - parts.length - 1).map(function (p) {
|
2531
|
+
return JSON.stringify(p);
|
2532
|
+
}).join(".") // TODO: create a function generate path from parts (not sure if this always works)
|
2533
|
+
}
|
2534
|
+
};
|
2535
|
+
}
|
2536
|
+
if (_typeof(resolvedSource) !== "object") {
|
2537
|
+
return {
|
2538
|
+
v: {
|
2539
|
+
status: "error",
|
2540
|
+
message: "Schema type error: expected source to be type of object, but got ".concat(_typeof(resolvedSource))
|
2541
|
+
}
|
2542
|
+
};
|
2543
|
+
}
|
2544
|
+
if (resolvedSource !== null && resolvedSource[part] === undefined) {
|
2545
|
+
return {
|
2546
|
+
v: {
|
2547
|
+
status: "error",
|
2548
|
+
message: "Invalid path: object source did not have key ".concat(part, " from path: ").concat(path)
|
2549
|
+
}
|
2550
|
+
};
|
2551
|
+
}
|
2552
|
+
resolvedSource = resolvedSource === null ? resolvedSource : resolvedSource[part];
|
2553
|
+
resolvedSchema = resolvedSchema.items[part];
|
2554
|
+
// } else if (isI18nSchema(resolvedSchema)) {
|
2555
|
+
// if (!resolvedSchema.locales.includes(part)) {
|
2556
|
+
// throw Error(
|
2557
|
+
// `Invalid path: i18n schema ${resolvedSchema} supports locales ${resolvedSchema.locales.join(
|
2558
|
+
// ", "
|
2559
|
+
// )}, but found: ${part}`
|
2560
|
+
// );
|
2561
|
+
// }
|
2562
|
+
// if (!Object.keys(resolvedSource).includes(part)) {
|
2563
|
+
// throw Error(
|
2564
|
+
// `Schema type error: expected source to be type of i18n with locale ${part}, but got ${JSON.stringify(
|
2565
|
+
// Object.keys(resolvedSource)
|
2566
|
+
// )}`
|
2567
|
+
// );
|
2568
|
+
// }
|
2569
|
+
// resolvedSource = resolvedSource[part];
|
2570
|
+
// resolvedSchema = resolvedSchema.item;
|
2571
|
+
} else if (isImageSchema(resolvedSchema)) {
|
2572
|
+
return {
|
2573
|
+
v: {
|
2574
|
+
status: "ok",
|
2575
|
+
path: origParts.slice(0, origParts.length - parts.length - 1).map(function (p) {
|
2576
|
+
return JSON.stringify(p);
|
2577
|
+
}).join("."),
|
2578
|
+
// TODO: create a function generate path from parts (not sure if this always works)
|
2579
|
+
schema: resolvedSchema,
|
2580
|
+
source: resolvedSource
|
2581
|
+
}
|
2582
|
+
};
|
2583
|
+
} else if (isUnionSchema(resolvedSchema)) {
|
2584
|
+
var _key2 = resolvedSchema.key;
|
2585
|
+
if (typeof _key2 !== "string") {
|
2586
|
+
return {
|
2587
|
+
v: {
|
2588
|
+
status: "ok",
|
2589
|
+
path: origParts.map(function (p) {
|
2590
|
+
if (!Number.isNaN(Number(p))) {
|
2591
|
+
return p;
|
2592
|
+
} else {
|
2593
|
+
return JSON.stringify(p);
|
2594
|
+
}
|
2595
|
+
}).join("."),
|
2596
|
+
// TODO: create a function generate path from parts (not sure if this always works)
|
2597
|
+
schema: resolvedSchema,
|
2598
|
+
source: resolvedSource
|
2599
|
+
}
|
2600
|
+
};
|
2601
|
+
}
|
2602
|
+
var keyValue = resolvedSource[_key2];
|
2603
|
+
if (!keyValue) {
|
2604
|
+
return {
|
2605
|
+
v: {
|
2606
|
+
status: "error",
|
2607
|
+
message: "Invalid path: union source ".concat(resolvedSchema, " did not have required key ").concat(_key2, " in path: ").concat(path)
|
2608
|
+
}
|
2609
|
+
};
|
2610
|
+
}
|
2611
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
2612
|
+
var schemaOfUnionKey = resolvedSchema.items.find(
|
2613
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
2614
|
+
function (child) {
|
2615
|
+
var _child$items2;
|
2616
|
+
return (child === null || child === void 0 || (_child$items2 = child.items) === null || _child$items2 === void 0 || (_child$items2 = _child$items2[_key2]) === null || _child$items2 === void 0 ? void 0 : _child$items2.value) === keyValue;
|
2617
|
+
});
|
2618
|
+
if (!schemaOfUnionKey) {
|
2619
|
+
return {
|
2620
|
+
v: {
|
2621
|
+
status: "error",
|
2622
|
+
message: "Invalid path: union schema ".concat(resolvedSchema, " did not have a child object with ").concat(_key2, " of value ").concat(keyValue, " in path: ").concat(path)
|
2623
|
+
}
|
2624
|
+
};
|
2625
|
+
}
|
2626
|
+
resolvedSchema = schemaOfUnionKey.items[part];
|
2627
|
+
resolvedSource = resolvedSource[part];
|
2628
|
+
} else if (isRichTextSchema(resolvedSchema)) {
|
2629
|
+
if ("src" in resolvedSource && "tag" in resolvedSource && resolvedSource.tag === "img" && parts.length === 0) {
|
2630
|
+
var _resolvedSchema$optio3, _resolvedSchema$optio4;
|
2631
|
+
resolvedSchema = (_resolvedSchema$optio3 = resolvedSchema.options) !== null && _resolvedSchema$optio3 !== void 0 && (_resolvedSchema$optio3 = _resolvedSchema$optio3.inline) !== null && _resolvedSchema$optio3 !== void 0 && _resolvedSchema$optio3.img && typeof ((_resolvedSchema$optio4 = resolvedSchema.options) === null || _resolvedSchema$optio4 === void 0 || (_resolvedSchema$optio4 = _resolvedSchema$optio4.inline) === null || _resolvedSchema$optio4 === void 0 ? void 0 : _resolvedSchema$optio4.img) !== "boolean" ? resolvedSchema.options.inline.img : resolvedSchema;
|
2632
|
+
}
|
2633
|
+
resolvedSource = resolvedSource[part];
|
2634
|
+
} else {
|
2635
|
+
return {
|
2636
|
+
v: {
|
2637
|
+
status: "error",
|
2638
|
+
message: "Invalid path: ".concat(part, " resolved to an unexpected schema ").concat(JSON.stringify(resolvedSchema))
|
2639
|
+
}
|
2640
|
+
};
|
2641
|
+
}
|
2642
|
+
},
|
2643
|
+
_ret2;
|
2644
|
+
while (parts.length > 0) {
|
2645
|
+
_ret2 = _loop2();
|
2646
|
+
if (_ret2) return _ret2.v;
|
2647
|
+
}
|
2648
|
+
if (parts.length > 0) {
|
2649
|
+
return {
|
2650
|
+
status: "error",
|
2651
|
+
message: "Invalid path: ".concat(parts.join("."), " is not a valid path")
|
2652
|
+
};
|
2653
|
+
}
|
2654
|
+
return {
|
2655
|
+
status: "ok",
|
2656
|
+
path: origParts.map(function (p) {
|
2657
|
+
if (!Number.isNaN(Number(p))) {
|
2658
|
+
return p;
|
2659
|
+
} else {
|
2660
|
+
return JSON.stringify(p);
|
2661
|
+
}
|
2662
|
+
}).join("."),
|
2663
|
+
// TODO: create a function generate path from parts (not sure if this always works)
|
2664
|
+
schema: resolvedSchema,
|
2665
|
+
source: resolvedSource
|
2666
|
+
};
|
2667
|
+
}
|
2441
2668
|
function splitModuleFilePath(input) {
|
2442
2669
|
var parts = input.split("/").slice(1);
|
2443
2670
|
return parts;
|
@@ -4639,6 +4866,7 @@ var Internal = {
|
|
4639
4866
|
getValPath: getValPath,
|
4640
4867
|
getSource: getSource,
|
4641
4868
|
resolvePath: resolvePath,
|
4869
|
+
safeResolvePath: safeResolvePath,
|
4642
4870
|
splitModuleFilePathAndModulePath: splitModuleFilePathAndModulePath,
|
4643
4871
|
joinModuleFilePathAndModulePath: joinModuleFilePathAndModulePath,
|
4644
4872
|
remote: {
|
@@ -2436,6 +2436,233 @@ function resolvePath(path, valModule, schema) {
|
|
2436
2436
|
source: resolvedSource
|
2437
2437
|
};
|
2438
2438
|
}
|
2439
|
+
|
2440
|
+
// TODO: replace all usages of resolvePath with safeResolvePath
|
2441
|
+
function safeResolvePath(path, valModule, schema) {
|
2442
|
+
var parts = splitModulePath(path);
|
2443
|
+
var origParts = _toConsumableArray(parts);
|
2444
|
+
var resolvedSchema = schema;
|
2445
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
2446
|
+
var resolvedSource = valModule;
|
2447
|
+
var _loop2 = function _loop2() {
|
2448
|
+
var part = parts.shift();
|
2449
|
+
if (part === undefined) {
|
2450
|
+
return {
|
2451
|
+
v: {
|
2452
|
+
status: "error",
|
2453
|
+
message: "Unexpected undefined part"
|
2454
|
+
}
|
2455
|
+
};
|
2456
|
+
}
|
2457
|
+
if (isArraySchema(resolvedSchema)) {
|
2458
|
+
if (Number.isNaN(Number(part))) {
|
2459
|
+
return {
|
2460
|
+
v: {
|
2461
|
+
status: "error",
|
2462
|
+
message: "Invalid path: array schema ".concat(JSON.stringify(resolvedSchema), " must have a number as path, but got ").concat(part, ". Path: ").concat(path)
|
2463
|
+
}
|
2464
|
+
};
|
2465
|
+
}
|
2466
|
+
if (resolvedSource === undefined) {
|
2467
|
+
return {
|
2468
|
+
v: {
|
2469
|
+
status: "source-undefined",
|
2470
|
+
path: origParts.slice(0, origParts.length - parts.length - 1).map(function (p) {
|
2471
|
+
return JSON.stringify(p);
|
2472
|
+
}).join(".") // TODO: create a function generate path from parts (not sure if this always works)
|
2473
|
+
}
|
2474
|
+
};
|
2475
|
+
}
|
2476
|
+
if (_typeof(resolvedSource) !== "object" && !Array.isArray(resolvedSource)) {
|
2477
|
+
return {
|
2478
|
+
v: {
|
2479
|
+
status: "error",
|
2480
|
+
message: "Schema type error: expected source to be type of array, but got ".concat(_typeof(resolvedSource))
|
2481
|
+
}
|
2482
|
+
};
|
2483
|
+
}
|
2484
|
+
resolvedSource = resolvedSource[part];
|
2485
|
+
resolvedSchema = resolvedSchema.item;
|
2486
|
+
} else if (isRecordSchema(resolvedSchema)) {
|
2487
|
+
if (typeof part !== "string") {
|
2488
|
+
return {
|
2489
|
+
v: {
|
2490
|
+
status: "error",
|
2491
|
+
message: "Invalid path: record schema ".concat(resolvedSchema, " must have path: ").concat(part, " as string")
|
2492
|
+
}
|
2493
|
+
};
|
2494
|
+
}
|
2495
|
+
if (resolvedSource === undefined) {
|
2496
|
+
return {
|
2497
|
+
v: {
|
2498
|
+
status: "source-undefined",
|
2499
|
+
path: origParts.slice(0, origParts.length - parts.length - 1).map(function (p) {
|
2500
|
+
return JSON.stringify(p);
|
2501
|
+
}).join(".") // TODO: create a function generate path from parts (not sure if this always works)
|
2502
|
+
}
|
2503
|
+
};
|
2504
|
+
}
|
2505
|
+
if (_typeof(resolvedSource) !== "object" && !Array.isArray(resolvedSource)) {
|
2506
|
+
return {
|
2507
|
+
v: {
|
2508
|
+
status: "error",
|
2509
|
+
message: "Schema type error: expected source to be type of record, but got ".concat(_typeof(resolvedSource))
|
2510
|
+
}
|
2511
|
+
};
|
2512
|
+
}
|
2513
|
+
if (!resolvedSource[part]) {
|
2514
|
+
return {
|
2515
|
+
v: {
|
2516
|
+
status: "error",
|
2517
|
+
message: "Invalid path: record source did not have key ".concat(part, " from path: ").concat(path)
|
2518
|
+
}
|
2519
|
+
};
|
2520
|
+
}
|
2521
|
+
resolvedSource = resolvedSource[part];
|
2522
|
+
resolvedSchema = resolvedSchema.item;
|
2523
|
+
} else if (isObjectSchema(resolvedSchema)) {
|
2524
|
+
if (resolvedSource === undefined) {
|
2525
|
+
return {
|
2526
|
+
v: {
|
2527
|
+
status: "source-undefined",
|
2528
|
+
path: origParts.slice(0, origParts.length - parts.length - 1).map(function (p) {
|
2529
|
+
return JSON.stringify(p);
|
2530
|
+
}).join(".") // TODO: create a function generate path from parts (not sure if this always works)
|
2531
|
+
}
|
2532
|
+
};
|
2533
|
+
}
|
2534
|
+
if (_typeof(resolvedSource) !== "object") {
|
2535
|
+
return {
|
2536
|
+
v: {
|
2537
|
+
status: "error",
|
2538
|
+
message: "Schema type error: expected source to be type of object, but got ".concat(_typeof(resolvedSource))
|
2539
|
+
}
|
2540
|
+
};
|
2541
|
+
}
|
2542
|
+
if (resolvedSource !== null && resolvedSource[part] === undefined) {
|
2543
|
+
return {
|
2544
|
+
v: {
|
2545
|
+
status: "error",
|
2546
|
+
message: "Invalid path: object source did not have key ".concat(part, " from path: ").concat(path)
|
2547
|
+
}
|
2548
|
+
};
|
2549
|
+
}
|
2550
|
+
resolvedSource = resolvedSource === null ? resolvedSource : resolvedSource[part];
|
2551
|
+
resolvedSchema = resolvedSchema.items[part];
|
2552
|
+
// } else if (isI18nSchema(resolvedSchema)) {
|
2553
|
+
// if (!resolvedSchema.locales.includes(part)) {
|
2554
|
+
// throw Error(
|
2555
|
+
// `Invalid path: i18n schema ${resolvedSchema} supports locales ${resolvedSchema.locales.join(
|
2556
|
+
// ", "
|
2557
|
+
// )}, but found: ${part}`
|
2558
|
+
// );
|
2559
|
+
// }
|
2560
|
+
// if (!Object.keys(resolvedSource).includes(part)) {
|
2561
|
+
// throw Error(
|
2562
|
+
// `Schema type error: expected source to be type of i18n with locale ${part}, but got ${JSON.stringify(
|
2563
|
+
// Object.keys(resolvedSource)
|
2564
|
+
// )}`
|
2565
|
+
// );
|
2566
|
+
// }
|
2567
|
+
// resolvedSource = resolvedSource[part];
|
2568
|
+
// resolvedSchema = resolvedSchema.item;
|
2569
|
+
} else if (isImageSchema(resolvedSchema)) {
|
2570
|
+
return {
|
2571
|
+
v: {
|
2572
|
+
status: "ok",
|
2573
|
+
path: origParts.slice(0, origParts.length - parts.length - 1).map(function (p) {
|
2574
|
+
return JSON.stringify(p);
|
2575
|
+
}).join("."),
|
2576
|
+
// TODO: create a function generate path from parts (not sure if this always works)
|
2577
|
+
schema: resolvedSchema,
|
2578
|
+
source: resolvedSource
|
2579
|
+
}
|
2580
|
+
};
|
2581
|
+
} else if (isUnionSchema(resolvedSchema)) {
|
2582
|
+
var _key2 = resolvedSchema.key;
|
2583
|
+
if (typeof _key2 !== "string") {
|
2584
|
+
return {
|
2585
|
+
v: {
|
2586
|
+
status: "ok",
|
2587
|
+
path: origParts.map(function (p) {
|
2588
|
+
if (!Number.isNaN(Number(p))) {
|
2589
|
+
return p;
|
2590
|
+
} else {
|
2591
|
+
return JSON.stringify(p);
|
2592
|
+
}
|
2593
|
+
}).join("."),
|
2594
|
+
// TODO: create a function generate path from parts (not sure if this always works)
|
2595
|
+
schema: resolvedSchema,
|
2596
|
+
source: resolvedSource
|
2597
|
+
}
|
2598
|
+
};
|
2599
|
+
}
|
2600
|
+
var keyValue = resolvedSource[_key2];
|
2601
|
+
if (!keyValue) {
|
2602
|
+
return {
|
2603
|
+
v: {
|
2604
|
+
status: "error",
|
2605
|
+
message: "Invalid path: union source ".concat(resolvedSchema, " did not have required key ").concat(_key2, " in path: ").concat(path)
|
2606
|
+
}
|
2607
|
+
};
|
2608
|
+
}
|
2609
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
2610
|
+
var schemaOfUnionKey = resolvedSchema.items.find(
|
2611
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
2612
|
+
function (child) {
|
2613
|
+
var _child$items2;
|
2614
|
+
return (child === null || child === void 0 || (_child$items2 = child.items) === null || _child$items2 === void 0 || (_child$items2 = _child$items2[_key2]) === null || _child$items2 === void 0 ? void 0 : _child$items2.value) === keyValue;
|
2615
|
+
});
|
2616
|
+
if (!schemaOfUnionKey) {
|
2617
|
+
return {
|
2618
|
+
v: {
|
2619
|
+
status: "error",
|
2620
|
+
message: "Invalid path: union schema ".concat(resolvedSchema, " did not have a child object with ").concat(_key2, " of value ").concat(keyValue, " in path: ").concat(path)
|
2621
|
+
}
|
2622
|
+
};
|
2623
|
+
}
|
2624
|
+
resolvedSchema = schemaOfUnionKey.items[part];
|
2625
|
+
resolvedSource = resolvedSource[part];
|
2626
|
+
} else if (isRichTextSchema(resolvedSchema)) {
|
2627
|
+
if ("src" in resolvedSource && "tag" in resolvedSource && resolvedSource.tag === "img" && parts.length === 0) {
|
2628
|
+
var _resolvedSchema$optio3, _resolvedSchema$optio4;
|
2629
|
+
resolvedSchema = (_resolvedSchema$optio3 = resolvedSchema.options) !== null && _resolvedSchema$optio3 !== void 0 && (_resolvedSchema$optio3 = _resolvedSchema$optio3.inline) !== null && _resolvedSchema$optio3 !== void 0 && _resolvedSchema$optio3.img && typeof ((_resolvedSchema$optio4 = resolvedSchema.options) === null || _resolvedSchema$optio4 === void 0 || (_resolvedSchema$optio4 = _resolvedSchema$optio4.inline) === null || _resolvedSchema$optio4 === void 0 ? void 0 : _resolvedSchema$optio4.img) !== "boolean" ? resolvedSchema.options.inline.img : resolvedSchema;
|
2630
|
+
}
|
2631
|
+
resolvedSource = resolvedSource[part];
|
2632
|
+
} else {
|
2633
|
+
return {
|
2634
|
+
v: {
|
2635
|
+
status: "error",
|
2636
|
+
message: "Invalid path: ".concat(part, " resolved to an unexpected schema ").concat(JSON.stringify(resolvedSchema))
|
2637
|
+
}
|
2638
|
+
};
|
2639
|
+
}
|
2640
|
+
},
|
2641
|
+
_ret2;
|
2642
|
+
while (parts.length > 0) {
|
2643
|
+
_ret2 = _loop2();
|
2644
|
+
if (_ret2) return _ret2.v;
|
2645
|
+
}
|
2646
|
+
if (parts.length > 0) {
|
2647
|
+
return {
|
2648
|
+
status: "error",
|
2649
|
+
message: "Invalid path: ".concat(parts.join("."), " is not a valid path")
|
2650
|
+
};
|
2651
|
+
}
|
2652
|
+
return {
|
2653
|
+
status: "ok",
|
2654
|
+
path: origParts.map(function (p) {
|
2655
|
+
if (!Number.isNaN(Number(p))) {
|
2656
|
+
return p;
|
2657
|
+
} else {
|
2658
|
+
return JSON.stringify(p);
|
2659
|
+
}
|
2660
|
+
}).join("."),
|
2661
|
+
// TODO: create a function generate path from parts (not sure if this always works)
|
2662
|
+
schema: resolvedSchema,
|
2663
|
+
source: resolvedSource
|
2664
|
+
};
|
2665
|
+
}
|
2439
2666
|
function splitModuleFilePath(input) {
|
2440
2667
|
var parts = input.split("/").slice(1);
|
2441
2668
|
return parts;
|
@@ -4637,6 +4864,7 @@ var Internal = {
|
|
4637
4864
|
getValPath: getValPath,
|
4638
4865
|
getSource: getSource,
|
4639
4866
|
resolvePath: resolvePath,
|
4867
|
+
safeResolvePath: safeResolvePath,
|
4640
4868
|
splitModuleFilePathAndModulePath: splitModuleFilePathAndModulePath,
|
4641
4869
|
joinModuleFilePathAndModulePath: joinModuleFilePathAndModulePath,
|
4642
4870
|
remote: {
|
@@ -2438,6 +2438,233 @@ function resolvePath(path, valModule, schema) {
|
|
2438
2438
|
source: resolvedSource
|
2439
2439
|
};
|
2440
2440
|
}
|
2441
|
+
|
2442
|
+
// TODO: replace all usages of resolvePath with safeResolvePath
|
2443
|
+
function safeResolvePath(path, valModule, schema) {
|
2444
|
+
var parts = splitModulePath(path);
|
2445
|
+
var origParts = _toConsumableArray(parts);
|
2446
|
+
var resolvedSchema = schema;
|
2447
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
2448
|
+
var resolvedSource = valModule;
|
2449
|
+
var _loop2 = function _loop2() {
|
2450
|
+
var part = parts.shift();
|
2451
|
+
if (part === undefined) {
|
2452
|
+
return {
|
2453
|
+
v: {
|
2454
|
+
status: "error",
|
2455
|
+
message: "Unexpected undefined part"
|
2456
|
+
}
|
2457
|
+
};
|
2458
|
+
}
|
2459
|
+
if (isArraySchema(resolvedSchema)) {
|
2460
|
+
if (Number.isNaN(Number(part))) {
|
2461
|
+
return {
|
2462
|
+
v: {
|
2463
|
+
status: "error",
|
2464
|
+
message: "Invalid path: array schema ".concat(JSON.stringify(resolvedSchema), " must have a number as path, but got ").concat(part, ". Path: ").concat(path)
|
2465
|
+
}
|
2466
|
+
};
|
2467
|
+
}
|
2468
|
+
if (resolvedSource === undefined) {
|
2469
|
+
return {
|
2470
|
+
v: {
|
2471
|
+
status: "source-undefined",
|
2472
|
+
path: origParts.slice(0, origParts.length - parts.length - 1).map(function (p) {
|
2473
|
+
return JSON.stringify(p);
|
2474
|
+
}).join(".") // TODO: create a function generate path from parts (not sure if this always works)
|
2475
|
+
}
|
2476
|
+
};
|
2477
|
+
}
|
2478
|
+
if (_typeof(resolvedSource) !== "object" && !Array.isArray(resolvedSource)) {
|
2479
|
+
return {
|
2480
|
+
v: {
|
2481
|
+
status: "error",
|
2482
|
+
message: "Schema type error: expected source to be type of array, but got ".concat(_typeof(resolvedSource))
|
2483
|
+
}
|
2484
|
+
};
|
2485
|
+
}
|
2486
|
+
resolvedSource = resolvedSource[part];
|
2487
|
+
resolvedSchema = resolvedSchema.item;
|
2488
|
+
} else if (isRecordSchema(resolvedSchema)) {
|
2489
|
+
if (typeof part !== "string") {
|
2490
|
+
return {
|
2491
|
+
v: {
|
2492
|
+
status: "error",
|
2493
|
+
message: "Invalid path: record schema ".concat(resolvedSchema, " must have path: ").concat(part, " as string")
|
2494
|
+
}
|
2495
|
+
};
|
2496
|
+
}
|
2497
|
+
if (resolvedSource === undefined) {
|
2498
|
+
return {
|
2499
|
+
v: {
|
2500
|
+
status: "source-undefined",
|
2501
|
+
path: origParts.slice(0, origParts.length - parts.length - 1).map(function (p) {
|
2502
|
+
return JSON.stringify(p);
|
2503
|
+
}).join(".") // TODO: create a function generate path from parts (not sure if this always works)
|
2504
|
+
}
|
2505
|
+
};
|
2506
|
+
}
|
2507
|
+
if (_typeof(resolvedSource) !== "object" && !Array.isArray(resolvedSource)) {
|
2508
|
+
return {
|
2509
|
+
v: {
|
2510
|
+
status: "error",
|
2511
|
+
message: "Schema type error: expected source to be type of record, but got ".concat(_typeof(resolvedSource))
|
2512
|
+
}
|
2513
|
+
};
|
2514
|
+
}
|
2515
|
+
if (!resolvedSource[part]) {
|
2516
|
+
return {
|
2517
|
+
v: {
|
2518
|
+
status: "error",
|
2519
|
+
message: "Invalid path: record source did not have key ".concat(part, " from path: ").concat(path)
|
2520
|
+
}
|
2521
|
+
};
|
2522
|
+
}
|
2523
|
+
resolvedSource = resolvedSource[part];
|
2524
|
+
resolvedSchema = resolvedSchema.item;
|
2525
|
+
} else if (isObjectSchema(resolvedSchema)) {
|
2526
|
+
if (resolvedSource === undefined) {
|
2527
|
+
return {
|
2528
|
+
v: {
|
2529
|
+
status: "source-undefined",
|
2530
|
+
path: origParts.slice(0, origParts.length - parts.length - 1).map(function (p) {
|
2531
|
+
return JSON.stringify(p);
|
2532
|
+
}).join(".") // TODO: create a function generate path from parts (not sure if this always works)
|
2533
|
+
}
|
2534
|
+
};
|
2535
|
+
}
|
2536
|
+
if (_typeof(resolvedSource) !== "object") {
|
2537
|
+
return {
|
2538
|
+
v: {
|
2539
|
+
status: "error",
|
2540
|
+
message: "Schema type error: expected source to be type of object, but got ".concat(_typeof(resolvedSource))
|
2541
|
+
}
|
2542
|
+
};
|
2543
|
+
}
|
2544
|
+
if (resolvedSource !== null && resolvedSource[part] === undefined) {
|
2545
|
+
return {
|
2546
|
+
v: {
|
2547
|
+
status: "error",
|
2548
|
+
message: "Invalid path: object source did not have key ".concat(part, " from path: ").concat(path)
|
2549
|
+
}
|
2550
|
+
};
|
2551
|
+
}
|
2552
|
+
resolvedSource = resolvedSource === null ? resolvedSource : resolvedSource[part];
|
2553
|
+
resolvedSchema = resolvedSchema.items[part];
|
2554
|
+
// } else if (isI18nSchema(resolvedSchema)) {
|
2555
|
+
// if (!resolvedSchema.locales.includes(part)) {
|
2556
|
+
// throw Error(
|
2557
|
+
// `Invalid path: i18n schema ${resolvedSchema} supports locales ${resolvedSchema.locales.join(
|
2558
|
+
// ", "
|
2559
|
+
// )}, but found: ${part}`
|
2560
|
+
// );
|
2561
|
+
// }
|
2562
|
+
// if (!Object.keys(resolvedSource).includes(part)) {
|
2563
|
+
// throw Error(
|
2564
|
+
// `Schema type error: expected source to be type of i18n with locale ${part}, but got ${JSON.stringify(
|
2565
|
+
// Object.keys(resolvedSource)
|
2566
|
+
// )}`
|
2567
|
+
// );
|
2568
|
+
// }
|
2569
|
+
// resolvedSource = resolvedSource[part];
|
2570
|
+
// resolvedSchema = resolvedSchema.item;
|
2571
|
+
} else if (isImageSchema(resolvedSchema)) {
|
2572
|
+
return {
|
2573
|
+
v: {
|
2574
|
+
status: "ok",
|
2575
|
+
path: origParts.slice(0, origParts.length - parts.length - 1).map(function (p) {
|
2576
|
+
return JSON.stringify(p);
|
2577
|
+
}).join("."),
|
2578
|
+
// TODO: create a function generate path from parts (not sure if this always works)
|
2579
|
+
schema: resolvedSchema,
|
2580
|
+
source: resolvedSource
|
2581
|
+
}
|
2582
|
+
};
|
2583
|
+
} else if (isUnionSchema(resolvedSchema)) {
|
2584
|
+
var _key2 = resolvedSchema.key;
|
2585
|
+
if (typeof _key2 !== "string") {
|
2586
|
+
return {
|
2587
|
+
v: {
|
2588
|
+
status: "ok",
|
2589
|
+
path: origParts.map(function (p) {
|
2590
|
+
if (!Number.isNaN(Number(p))) {
|
2591
|
+
return p;
|
2592
|
+
} else {
|
2593
|
+
return JSON.stringify(p);
|
2594
|
+
}
|
2595
|
+
}).join("."),
|
2596
|
+
// TODO: create a function generate path from parts (not sure if this always works)
|
2597
|
+
schema: resolvedSchema,
|
2598
|
+
source: resolvedSource
|
2599
|
+
}
|
2600
|
+
};
|
2601
|
+
}
|
2602
|
+
var keyValue = resolvedSource[_key2];
|
2603
|
+
if (!keyValue) {
|
2604
|
+
return {
|
2605
|
+
v: {
|
2606
|
+
status: "error",
|
2607
|
+
message: "Invalid path: union source ".concat(resolvedSchema, " did not have required key ").concat(_key2, " in path: ").concat(path)
|
2608
|
+
}
|
2609
|
+
};
|
2610
|
+
}
|
2611
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
2612
|
+
var schemaOfUnionKey = resolvedSchema.items.find(
|
2613
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
2614
|
+
function (child) {
|
2615
|
+
var _child$items2;
|
2616
|
+
return (child === null || child === void 0 || (_child$items2 = child.items) === null || _child$items2 === void 0 || (_child$items2 = _child$items2[_key2]) === null || _child$items2 === void 0 ? void 0 : _child$items2.value) === keyValue;
|
2617
|
+
});
|
2618
|
+
if (!schemaOfUnionKey) {
|
2619
|
+
return {
|
2620
|
+
v: {
|
2621
|
+
status: "error",
|
2622
|
+
message: "Invalid path: union schema ".concat(resolvedSchema, " did not have a child object with ").concat(_key2, " of value ").concat(keyValue, " in path: ").concat(path)
|
2623
|
+
}
|
2624
|
+
};
|
2625
|
+
}
|
2626
|
+
resolvedSchema = schemaOfUnionKey.items[part];
|
2627
|
+
resolvedSource = resolvedSource[part];
|
2628
|
+
} else if (isRichTextSchema(resolvedSchema)) {
|
2629
|
+
if ("src" in resolvedSource && "tag" in resolvedSource && resolvedSource.tag === "img" && parts.length === 0) {
|
2630
|
+
var _resolvedSchema$optio3, _resolvedSchema$optio4;
|
2631
|
+
resolvedSchema = (_resolvedSchema$optio3 = resolvedSchema.options) !== null && _resolvedSchema$optio3 !== void 0 && (_resolvedSchema$optio3 = _resolvedSchema$optio3.inline) !== null && _resolvedSchema$optio3 !== void 0 && _resolvedSchema$optio3.img && typeof ((_resolvedSchema$optio4 = resolvedSchema.options) === null || _resolvedSchema$optio4 === void 0 || (_resolvedSchema$optio4 = _resolvedSchema$optio4.inline) === null || _resolvedSchema$optio4 === void 0 ? void 0 : _resolvedSchema$optio4.img) !== "boolean" ? resolvedSchema.options.inline.img : resolvedSchema;
|
2632
|
+
}
|
2633
|
+
resolvedSource = resolvedSource[part];
|
2634
|
+
} else {
|
2635
|
+
return {
|
2636
|
+
v: {
|
2637
|
+
status: "error",
|
2638
|
+
message: "Invalid path: ".concat(part, " resolved to an unexpected schema ").concat(JSON.stringify(resolvedSchema))
|
2639
|
+
}
|
2640
|
+
};
|
2641
|
+
}
|
2642
|
+
},
|
2643
|
+
_ret2;
|
2644
|
+
while (parts.length > 0) {
|
2645
|
+
_ret2 = _loop2();
|
2646
|
+
if (_ret2) return _ret2.v;
|
2647
|
+
}
|
2648
|
+
if (parts.length > 0) {
|
2649
|
+
return {
|
2650
|
+
status: "error",
|
2651
|
+
message: "Invalid path: ".concat(parts.join("."), " is not a valid path")
|
2652
|
+
};
|
2653
|
+
}
|
2654
|
+
return {
|
2655
|
+
status: "ok",
|
2656
|
+
path: origParts.map(function (p) {
|
2657
|
+
if (!Number.isNaN(Number(p))) {
|
2658
|
+
return p;
|
2659
|
+
} else {
|
2660
|
+
return JSON.stringify(p);
|
2661
|
+
}
|
2662
|
+
}).join("."),
|
2663
|
+
// TODO: create a function generate path from parts (not sure if this always works)
|
2664
|
+
schema: resolvedSchema,
|
2665
|
+
source: resolvedSource
|
2666
|
+
};
|
2667
|
+
}
|
2441
2668
|
function splitModuleFilePath(input) {
|
2442
2669
|
var parts = input.split("/").slice(1);
|
2443
2670
|
return parts;
|
@@ -4639,6 +4866,7 @@ var Internal = {
|
|
4639
4866
|
getValPath: getValPath,
|
4640
4867
|
getSource: getSource,
|
4641
4868
|
resolvePath: resolvePath,
|
4869
|
+
safeResolvePath: safeResolvePath,
|
4642
4870
|
splitModuleFilePathAndModulePath: splitModuleFilePathAndModulePath,
|
4643
4871
|
joinModuleFilePathAndModulePath: joinModuleFilePathAndModulePath,
|
4644
4872
|
remote: {
|
@@ -1,2 +1,2 @@
|
|
1
|
-
export { A as ArraySchema, B as BooleanSchema, e as DEFAULT_APP_HOST, D as DEFAULT_CONTENT_HOST, f as DEFAULT_VAL_REMOTE_HOST, o as DateSchema, F as FATAL_ERROR_TYPES, g as FILE_REF_PROP, h as FILE_REF_SUBTYPE_TAG, n as FileSchema, G as GenericSelector, l as ImageSchema, I as Internal, K as KeyOfSchema, L as LiteralSchema, M as ModuleFilePathSep, N as NumberSchema, O as ObjectSchema, R as RecordSchema, p as RichTextSchema, S as Schema, k as StringSchema, U as UnionSchema, V as VAL_EXTENSION, j as derefPatch, q as deserializeSchema, i as initVal, m as modules } from './index-
|
1
|
+
export { A as ArraySchema, B as BooleanSchema, e as DEFAULT_APP_HOST, D as DEFAULT_CONTENT_HOST, f as DEFAULT_VAL_REMOTE_HOST, o as DateSchema, F as FATAL_ERROR_TYPES, g as FILE_REF_PROP, h as FILE_REF_SUBTYPE_TAG, n as FileSchema, G as GenericSelector, l as ImageSchema, I as Internal, K as KeyOfSchema, L as LiteralSchema, M as ModuleFilePathSep, N as NumberSchema, O as ObjectSchema, R as RecordSchema, p as RichTextSchema, S as Schema, k as StringSchema, U as UnionSchema, V as VAL_EXTENSION, j as derefPatch, q as deserializeSchema, i as initVal, m as modules } from './index-1d5e4912.esm.js';
|
2
2
|
import './result-daff1cae.esm.js';
|
package/package.json
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
4
4
|
|
5
|
-
var dist_valbuildCore = require('../../dist/index-
|
5
|
+
var dist_valbuildCore = require('../../dist/index-041f7675.cjs.dev.js');
|
6
6
|
var result = require('../../dist/result-bb1f436e.cjs.dev.js');
|
7
7
|
var util = require('../../dist/util-b213092b.cjs.dev.js');
|
8
8
|
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
4
4
|
|
5
|
-
var dist_valbuildCore = require('../../dist/index-
|
5
|
+
var dist_valbuildCore = require('../../dist/index-3ecf0ca6.cjs.prod.js');
|
6
6
|
var result = require('../../dist/result-787e35f6.cjs.prod.js');
|
7
7
|
var util = require('../../dist/util-030d8a1f.cjs.prod.js');
|
8
8
|
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import { _ as _typeof, a as _slicedToArray, P as PatchError, s as splitModuleFilePathAndModulePath, b as _createClass, c as _classCallCheck, d as _toConsumableArray } from '../../dist/index-
|
2
|
-
export { P as PatchError } from '../../dist/index-
|
1
|
+
import { _ as _typeof, a as _slicedToArray, P as PatchError, s as splitModuleFilePathAndModulePath, b as _createClass, c as _classCallCheck, d as _toConsumableArray } from '../../dist/index-1d5e4912.esm.js';
|
2
|
+
export { P as PatchError } from '../../dist/index-1d5e4912.esm.js';
|
3
3
|
import { f as isNonEmpty, e as err, o as ok, m as map, g as flatMap, i as isErr, h as flatMapReduce, j as filterOrElse, k as mapErr, l as map$1, n as all, p as flatten, q as allT } from '../../dist/result-daff1cae.esm.js';
|
4
4
|
import { p as pipe } from '../../dist/util-18613e99.esm.js';
|
5
5
|
|