@valbuild/shared 0.96.3 → 0.97.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/internal/ApiRoutes.d.ts +1 -0
- package/dist/declarations/src/internal/index.d.ts +1 -0
- package/dist/declarations/src/internal/resolveSchemaSourceFixes.d.ts +42 -0
- package/dist/declarations/src/internal/zod/SerializedSchema.d.ts +6 -1
- package/internal/dist/valbuild-shared-internal.cjs.dev.js +448 -18
- package/internal/dist/valbuild-shared-internal.cjs.prod.js +448 -18
- package/internal/dist/valbuild-shared-internal.esm.js +441 -19
- package/package.json +2 -2
|
@@ -1019,16 +1019,22 @@ var SerializedStringSchema = z.object({
|
|
|
1019
1019
|
}).optional()
|
|
1020
1020
|
}).optional(),
|
|
1021
1021
|
opt: z["boolean"](),
|
|
1022
|
-
raw: z["boolean"]()
|
|
1022
|
+
raw: z["boolean"](),
|
|
1023
|
+
readonly: z["boolean"]().optional(),
|
|
1024
|
+
hidden: z["boolean"]().optional()
|
|
1023
1025
|
});
|
|
1024
1026
|
var SerializedLiteralSchema = z.object({
|
|
1025
1027
|
type: z.literal("literal"),
|
|
1026
1028
|
value: z.string(),
|
|
1027
|
-
opt: z["boolean"]()
|
|
1029
|
+
opt: z["boolean"](),
|
|
1030
|
+
readonly: z["boolean"]().optional(),
|
|
1031
|
+
hidden: z["boolean"]().optional()
|
|
1028
1032
|
});
|
|
1029
1033
|
var SerializedBooleanSchema = z.object({
|
|
1030
1034
|
type: z.literal("boolean"),
|
|
1031
|
-
opt: z["boolean"]()
|
|
1035
|
+
opt: z["boolean"](),
|
|
1036
|
+
readonly: z["boolean"]().optional(),
|
|
1037
|
+
hidden: z["boolean"]().optional()
|
|
1032
1038
|
});
|
|
1033
1039
|
var SerializedNumberSchema = z.object({
|
|
1034
1040
|
type: z.literal("number"),
|
|
@@ -1036,20 +1042,26 @@ var SerializedNumberSchema = z.object({
|
|
|
1036
1042
|
max: z.number().optional(),
|
|
1037
1043
|
min: z.number().optional()
|
|
1038
1044
|
}).optional(),
|
|
1039
|
-
opt: z["boolean"]()
|
|
1045
|
+
opt: z["boolean"](),
|
|
1046
|
+
readonly: z["boolean"]().optional(),
|
|
1047
|
+
hidden: z["boolean"]().optional()
|
|
1040
1048
|
});
|
|
1041
1049
|
var SerializedObjectSchema = z.lazy(function () {
|
|
1042
1050
|
return z.object({
|
|
1043
1051
|
type: z.literal("object"),
|
|
1044
1052
|
items: z.record(z.string(), SerializedSchema),
|
|
1045
|
-
opt: z["boolean"]()
|
|
1053
|
+
opt: z["boolean"](),
|
|
1054
|
+
readonly: z["boolean"]().optional(),
|
|
1055
|
+
hidden: z["boolean"]().optional()
|
|
1046
1056
|
});
|
|
1047
1057
|
});
|
|
1048
1058
|
var SerializedArraySchema = z.lazy(function () {
|
|
1049
1059
|
return z.object({
|
|
1050
1060
|
type: z.literal("array"),
|
|
1051
1061
|
item: SerializedSchema,
|
|
1052
|
-
opt: z["boolean"]()
|
|
1062
|
+
opt: z["boolean"](),
|
|
1063
|
+
readonly: z["boolean"]().optional(),
|
|
1064
|
+
hidden: z["boolean"]().optional()
|
|
1053
1065
|
});
|
|
1054
1066
|
});
|
|
1055
1067
|
var SerializedUnionSchema = z.lazy(function () {
|
|
@@ -1057,12 +1069,16 @@ var SerializedUnionSchema = z.lazy(function () {
|
|
|
1057
1069
|
type: z.literal("union"),
|
|
1058
1070
|
key: SerializedLiteralSchema,
|
|
1059
1071
|
items: z.array(SerializedLiteralSchema),
|
|
1060
|
-
opt: z["boolean"]()
|
|
1072
|
+
opt: z["boolean"](),
|
|
1073
|
+
readonly: z["boolean"]().optional(),
|
|
1074
|
+
hidden: z["boolean"]().optional()
|
|
1061
1075
|
}), z.object({
|
|
1062
1076
|
type: z.literal("union"),
|
|
1063
1077
|
key: z.string(),
|
|
1064
1078
|
items: z.array(SerializedObjectSchema),
|
|
1065
|
-
opt: z["boolean"]()
|
|
1079
|
+
opt: z["boolean"](),
|
|
1080
|
+
readonly: z["boolean"]().optional(),
|
|
1081
|
+
hidden: z["boolean"]().optional()
|
|
1066
1082
|
})]);
|
|
1067
1083
|
});
|
|
1068
1084
|
var ImageOptions = z.object({
|
|
@@ -1074,7 +1090,9 @@ var ImageOptions = z.object({
|
|
|
1074
1090
|
var SerializedImageSchema = z.object({
|
|
1075
1091
|
type: z.literal("image"),
|
|
1076
1092
|
options: ImageOptions.optional(),
|
|
1077
|
-
opt: z["boolean"]()
|
|
1093
|
+
opt: z["boolean"](),
|
|
1094
|
+
readonly: z["boolean"]().optional(),
|
|
1095
|
+
hidden: z["boolean"]().optional()
|
|
1078
1096
|
});
|
|
1079
1097
|
var RichTextOptions = z.lazy(function () {
|
|
1080
1098
|
return z.object({
|
|
@@ -1102,7 +1120,9 @@ var RichTextOptions = z.lazy(function () {
|
|
|
1102
1120
|
var SerializedRichTextSchema = z.object({
|
|
1103
1121
|
type: z.literal("richtext"),
|
|
1104
1122
|
options: RichTextOptions.optional(),
|
|
1105
|
-
opt: z["boolean"]()
|
|
1123
|
+
opt: z["boolean"](),
|
|
1124
|
+
readonly: z["boolean"]().optional(),
|
|
1125
|
+
hidden: z["boolean"]().optional()
|
|
1106
1126
|
});
|
|
1107
1127
|
var SerializedRecordSchema = z.lazy(function () {
|
|
1108
1128
|
return z.object({
|
|
@@ -1116,7 +1136,9 @@ var SerializedRecordSchema = z.lazy(function () {
|
|
|
1116
1136
|
directory: z.string().optional(),
|
|
1117
1137
|
remote: z["boolean"]().optional(),
|
|
1118
1138
|
alt: SerializedSchema.optional(),
|
|
1119
|
-
moduleMetadata: z.record(z.string(), z.record(z.string(), z.any())).optional()
|
|
1139
|
+
moduleMetadata: z.record(z.string(), z.record(z.string(), z.any())).optional(),
|
|
1140
|
+
readonly: z["boolean"]().optional(),
|
|
1141
|
+
hidden: z["boolean"]().optional()
|
|
1120
1142
|
}).passthrough();
|
|
1121
1143
|
});
|
|
1122
1144
|
var SerializedKeyOfSchema = z.lazy(function () {
|
|
@@ -1132,7 +1154,9 @@ var SerializedKeyOfSchema = z.lazy(function () {
|
|
|
1132
1154
|
opt: z["boolean"]().optional()
|
|
1133
1155
|
})]).optional(),
|
|
1134
1156
|
values: z.union([z.literal("string"), z.array(z.string())]),
|
|
1135
|
-
opt: z["boolean"]()
|
|
1157
|
+
opt: z["boolean"](),
|
|
1158
|
+
readonly: z["boolean"]().optional(),
|
|
1159
|
+
hidden: z["boolean"]().optional()
|
|
1136
1160
|
});
|
|
1137
1161
|
});
|
|
1138
1162
|
var FileOptions = z.object({
|
|
@@ -1141,11 +1165,31 @@ var FileOptions = z.object({
|
|
|
1141
1165
|
var SerializedFileSchema = z.object({
|
|
1142
1166
|
type: z.literal("file"),
|
|
1143
1167
|
options: FileOptions.optional(),
|
|
1144
|
-
opt: z["boolean"]()
|
|
1168
|
+
opt: z["boolean"](),
|
|
1169
|
+
readonly: z["boolean"]().optional(),
|
|
1170
|
+
hidden: z["boolean"]().optional()
|
|
1171
|
+
});
|
|
1172
|
+
var DateOptions = z.object({
|
|
1173
|
+
from: z.string().optional(),
|
|
1174
|
+
to: z.string().optional()
|
|
1145
1175
|
});
|
|
1146
1176
|
var SerializedDateSchema = z.object({
|
|
1147
1177
|
type: z.literal("date"),
|
|
1148
|
-
|
|
1178
|
+
options: DateOptions.optional(),
|
|
1179
|
+
opt: z["boolean"](),
|
|
1180
|
+
customValidate: z["boolean"]().optional(),
|
|
1181
|
+
readonly: z["boolean"]().optional(),
|
|
1182
|
+
hidden: z["boolean"]().optional(),
|
|
1183
|
+
description: z.string().optional()
|
|
1184
|
+
});
|
|
1185
|
+
var SerializedDateTimeSchema = z.object({
|
|
1186
|
+
type: z.literal("dateTime"),
|
|
1187
|
+
options: DateOptions.optional(),
|
|
1188
|
+
opt: z["boolean"](),
|
|
1189
|
+
customValidate: z["boolean"]().optional(),
|
|
1190
|
+
readonly: z["boolean"]().optional(),
|
|
1191
|
+
hidden: z["boolean"]().optional(),
|
|
1192
|
+
description: z.string().optional()
|
|
1149
1193
|
});
|
|
1150
1194
|
var SerializedRouteSchema = z.object({
|
|
1151
1195
|
type: z.literal("route"),
|
|
@@ -1161,9 +1205,11 @@ var SerializedRouteSchema = z.object({
|
|
|
1161
1205
|
customValidate: z["boolean"]().optional()
|
|
1162
1206
|
}).optional(),
|
|
1163
1207
|
opt: z["boolean"](),
|
|
1164
|
-
customValidate: z["boolean"]().optional()
|
|
1208
|
+
customValidate: z["boolean"]().optional(),
|
|
1209
|
+
readonly: z["boolean"]().optional(),
|
|
1210
|
+
hidden: z["boolean"]().optional()
|
|
1165
1211
|
});
|
|
1166
|
-
var SerializedSchema = z.union([SerializedStringSchema, SerializedLiteralSchema, SerializedBooleanSchema, SerializedNumberSchema, SerializedObjectSchema, SerializedArraySchema, SerializedUnionSchema, SerializedRichTextSchema, SerializedRecordSchema, SerializedKeyOfSchema, SerializedRouteSchema, SerializedFileSchema, SerializedDateSchema, SerializedImageSchema]);
|
|
1212
|
+
var SerializedSchema = z.union([SerializedStringSchema, SerializedLiteralSchema, SerializedBooleanSchema, SerializedNumberSchema, SerializedObjectSchema, SerializedArraySchema, SerializedUnionSchema, SerializedRichTextSchema, SerializedRecordSchema, SerializedKeyOfSchema, SerializedRouteSchema, SerializedFileSchema, SerializedDateSchema, SerializedDateTimeSchema, SerializedImageSchema]);
|
|
1167
1213
|
|
|
1168
1214
|
var ValCommit = z.object({
|
|
1169
1215
|
commitSha: z.string(),
|
|
@@ -1791,7 +1837,8 @@ var Api = {
|
|
|
1791
1837
|
query: {
|
|
1792
1838
|
validate_sources: onlyOneBooleanQueryParam.optional(),
|
|
1793
1839
|
validate_binary_files: onlyOneBooleanQueryParam.optional(),
|
|
1794
|
-
exclude_patches: onlyOneBooleanQueryParam.optional()
|
|
1840
|
+
exclude_patches: onlyOneBooleanQueryParam.optional(),
|
|
1841
|
+
apply_patches: onlyOneBooleanQueryParam.optional()
|
|
1795
1842
|
},
|
|
1796
1843
|
cookies: {
|
|
1797
1844
|
val_session: z.string().optional()
|
|
@@ -1828,7 +1875,7 @@ var Api = {
|
|
|
1828
1875
|
source: z.any().optional(),
|
|
1829
1876
|
//.optional(), // TODO: Json zod type
|
|
1830
1877
|
baseSource: z.any().optional(),
|
|
1831
|
-
// pre-patch source for compare view; set
|
|
1878
|
+
// pre-patch source for compare view; only set when the server applies patches (apply_patches=true) and the module has pending patches
|
|
1832
1879
|
patches: z.object({
|
|
1833
1880
|
applied: z.array(PatchId),
|
|
1834
1881
|
skipped: z.array(PatchId).optional(),
|
|
@@ -2744,4 +2791,379 @@ function createRegExpFromPattern(pattern) {
|
|
|
2744
2791
|
}
|
|
2745
2792
|
}
|
|
2746
2793
|
|
|
2747
|
-
|
|
2794
|
+
var TYPE_ERROR_MESSAGE = "This is most likely a Val version mismatch or Val bug.";
|
|
2795
|
+
function getRoutesWithModulePaths(schemas, sources) {
|
|
2796
|
+
var routeMap = new Map();
|
|
2797
|
+
for (var moduleFilePathS in schemas) {
|
|
2798
|
+
var moduleFilePath = moduleFilePathS;
|
|
2799
|
+
var schema = schemas[moduleFilePath];
|
|
2800
|
+
var source = sources[moduleFilePath];
|
|
2801
|
+
if (schema && schema.type === "record" && schema.router && source && _typeof(source) === "object" && !Array.isArray(source)) {
|
|
2802
|
+
for (var key in source) {
|
|
2803
|
+
if (!routeMap.has(key)) {
|
|
2804
|
+
routeMap.set(key, moduleFilePath);
|
|
2805
|
+
}
|
|
2806
|
+
}
|
|
2807
|
+
}
|
|
2808
|
+
}
|
|
2809
|
+
var routes = Array.from(routeMap.entries()).map(function (_ref) {
|
|
2810
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
|
2811
|
+
route = _ref2[0],
|
|
2812
|
+
moduleFilePath = _ref2[1];
|
|
2813
|
+
return {
|
|
2814
|
+
route: route,
|
|
2815
|
+
moduleFilePath: moduleFilePath
|
|
2816
|
+
};
|
|
2817
|
+
});
|
|
2818
|
+
return routes.sort(function (a, b) {
|
|
2819
|
+
return a.route.localeCompare(b.route);
|
|
2820
|
+
});
|
|
2821
|
+
}
|
|
2822
|
+
function getRoutesOf(schemas, sources) {
|
|
2823
|
+
return getRoutesWithModulePaths(schemas, sources).map(function (r) {
|
|
2824
|
+
return r.route;
|
|
2825
|
+
});
|
|
2826
|
+
}
|
|
2827
|
+
|
|
2828
|
+
// GPT generated levenshtein distance algorithm
|
|
2829
|
+
var levenshtein = function levenshtein(a, b) {
|
|
2830
|
+
var _ref3 = [a.length, b.length],
|
|
2831
|
+
m = _ref3[0],
|
|
2832
|
+
n = _ref3[1];
|
|
2833
|
+
if (!m || !n) return Math.max(m, n);
|
|
2834
|
+
var dp = Array.from({
|
|
2835
|
+
length: m + 1
|
|
2836
|
+
}, function (_, i) {
|
|
2837
|
+
return i;
|
|
2838
|
+
});
|
|
2839
|
+
for (var j = 1; j <= n; j++) {
|
|
2840
|
+
var prev = dp[0];
|
|
2841
|
+
dp[0] = j;
|
|
2842
|
+
for (var i = 1; i <= m; i++) {
|
|
2843
|
+
var temp = dp[i];
|
|
2844
|
+
dp[i] = a[i - 1] === b[j - 1] ? prev : Math.min(prev + 1, dp[i - 1] + 1, dp[i] + 1);
|
|
2845
|
+
prev = temp;
|
|
2846
|
+
}
|
|
2847
|
+
}
|
|
2848
|
+
return dp[m];
|
|
2849
|
+
};
|
|
2850
|
+
function findSimilar(key, targets) {
|
|
2851
|
+
return targets.map(function (target) {
|
|
2852
|
+
return {
|
|
2853
|
+
target: target,
|
|
2854
|
+
distance: levenshtein(key, target)
|
|
2855
|
+
};
|
|
2856
|
+
}).sort(function (a, b) {
|
|
2857
|
+
return a.distance - b.distance;
|
|
2858
|
+
});
|
|
2859
|
+
}
|
|
2860
|
+
function getKeyOfRecordAt(sourcePath, snapshot) {
|
|
2861
|
+
var _Internal$splitModule = Internal.splitModuleFilePathAndModulePath(sourcePath),
|
|
2862
|
+
_Internal$splitModule2 = _slicedToArray(_Internal$splitModule, 2),
|
|
2863
|
+
moduleFilePath = _Internal$splitModule2[0],
|
|
2864
|
+
modulePath = _Internal$splitModule2[1];
|
|
2865
|
+
var moduleSource = snapshot.sources[moduleFilePath];
|
|
2866
|
+
var moduleSchema = snapshot.schemas[moduleFilePath];
|
|
2867
|
+
if (!moduleSchema || moduleSource === undefined) {
|
|
2868
|
+
return {
|
|
2869
|
+
source: undefined,
|
|
2870
|
+
schema: undefined
|
|
2871
|
+
};
|
|
2872
|
+
}
|
|
2873
|
+
if (!modulePath) {
|
|
2874
|
+
return {
|
|
2875
|
+
source: moduleSource,
|
|
2876
|
+
schema: moduleSchema
|
|
2877
|
+
};
|
|
2878
|
+
}
|
|
2879
|
+
// Walk both schema and source. This intentionally only follows the
|
|
2880
|
+
// patterns produced by keyOf().sourcePath — typically a top-level record or
|
|
2881
|
+
// an object property pointing at a record. The walk is best-effort and
|
|
2882
|
+
// returns undefined source on any mismatch.
|
|
2883
|
+
var source = moduleSource;
|
|
2884
|
+
var schema = moduleSchema;
|
|
2885
|
+
var _iterator = _createForOfIteratorHelper(Internal.splitModulePath(modulePath)),
|
|
2886
|
+
_step;
|
|
2887
|
+
try {
|
|
2888
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
2889
|
+
var part = _step.value;
|
|
2890
|
+
if (source && _typeof(source) === "object" && !Array.isArray(source) && part in source) {
|
|
2891
|
+
source = source[part];
|
|
2892
|
+
} else {
|
|
2893
|
+
source = undefined;
|
|
2894
|
+
}
|
|
2895
|
+
if (schema && schema.type === "object" && schema.items[part]) {
|
|
2896
|
+
schema = schema.items[part];
|
|
2897
|
+
} else if (schema && schema.type === "record") {
|
|
2898
|
+
schema = schema.item;
|
|
2899
|
+
} else {
|
|
2900
|
+
schema = undefined;
|
|
2901
|
+
}
|
|
2902
|
+
}
|
|
2903
|
+
} catch (err) {
|
|
2904
|
+
_iterator.e(err);
|
|
2905
|
+
} finally {
|
|
2906
|
+
_iterator.f();
|
|
2907
|
+
}
|
|
2908
|
+
return {
|
|
2909
|
+
source: source,
|
|
2910
|
+
schema: schema
|
|
2911
|
+
};
|
|
2912
|
+
}
|
|
2913
|
+
function checkKeyIsValid(key, sourcePath, snapshot) {
|
|
2914
|
+
var _getKeyOfRecordAt = getKeyOfRecordAt(sourcePath, snapshot),
|
|
2915
|
+
keyOfModuleSource = _getKeyOfRecordAt.source,
|
|
2916
|
+
keyOfModuleSchema = _getKeyOfRecordAt.schema;
|
|
2917
|
+
if (keyOfModuleSchema && keyOfModuleSchema.type !== "record") {
|
|
2918
|
+
return {
|
|
2919
|
+
error: true,
|
|
2920
|
+
message: "Expected key at ".concat(sourcePath, " to be of type 'record'")
|
|
2921
|
+
};
|
|
2922
|
+
}
|
|
2923
|
+
if (keyOfModuleSource && _typeof(keyOfModuleSource) === "object" && !Array.isArray(keyOfModuleSource) && key in keyOfModuleSource) {
|
|
2924
|
+
return {
|
|
2925
|
+
error: false
|
|
2926
|
+
};
|
|
2927
|
+
}
|
|
2928
|
+
if (!keyOfModuleSource || _typeof(keyOfModuleSource) !== "object" || Array.isArray(keyOfModuleSource)) {
|
|
2929
|
+
return {
|
|
2930
|
+
error: true,
|
|
2931
|
+
message: "Expected ".concat(sourcePath, " to be a truthy object")
|
|
2932
|
+
};
|
|
2933
|
+
}
|
|
2934
|
+
var alternatives = findSimilar(key, Object.keys(keyOfModuleSource));
|
|
2935
|
+
if (alternatives.length === 0) {
|
|
2936
|
+
return {
|
|
2937
|
+
error: true,
|
|
2938
|
+
message: "Key '".concat(key, "' does not exist in ").concat(sourcePath, ".")
|
|
2939
|
+
};
|
|
2940
|
+
}
|
|
2941
|
+
return {
|
|
2942
|
+
error: true,
|
|
2943
|
+
message: "Key '".concat(key, "' does not exist in ").concat(sourcePath, ". Closest match: '").concat(alternatives[0].target, "'. Other similar: ").concat(alternatives.slice(1, 4).map(function (a) {
|
|
2944
|
+
return "'".concat(a.target, "'");
|
|
2945
|
+
}).join(", ")).concat(alternatives.length > 4 ? ", ..." : "")
|
|
2946
|
+
};
|
|
2947
|
+
}
|
|
2948
|
+
function checkRouteIsValid(route, includePattern, excludePattern, snapshot) {
|
|
2949
|
+
var routerModules = {};
|
|
2950
|
+
for (var moduleFilePathS in snapshot.schemas) {
|
|
2951
|
+
var moduleFilePath = moduleFilePathS;
|
|
2952
|
+
var schema = snapshot.schemas[moduleFilePath];
|
|
2953
|
+
if ((schema === null || schema === void 0 ? void 0 : schema.type) === "record" && schema.router) {
|
|
2954
|
+
var source = snapshot.sources[moduleFilePath];
|
|
2955
|
+
if (source && _typeof(source) === "object" && !Array.isArray(source)) {
|
|
2956
|
+
routerModules[moduleFilePath] = Object.keys(source);
|
|
2957
|
+
}
|
|
2958
|
+
}
|
|
2959
|
+
}
|
|
2960
|
+
var moduleEntries = Object.entries(routerModules);
|
|
2961
|
+
var foundInModule = null;
|
|
2962
|
+
for (var _i = 0, _moduleEntries = moduleEntries; _i < _moduleEntries.length; _i++) {
|
|
2963
|
+
var _moduleEntries$_i = _slicedToArray(_moduleEntries[_i], 2),
|
|
2964
|
+
_moduleFilePath = _moduleEntries$_i[0],
|
|
2965
|
+
routes = _moduleEntries$_i[1];
|
|
2966
|
+
if (routes.includes(route)) {
|
|
2967
|
+
foundInModule = _moduleFilePath;
|
|
2968
|
+
break;
|
|
2969
|
+
}
|
|
2970
|
+
}
|
|
2971
|
+
if (!foundInModule) {
|
|
2972
|
+
var allRoutes = moduleEntries.flatMap(function (_ref4) {
|
|
2973
|
+
var _ref5 = _slicedToArray(_ref4, 2),
|
|
2974
|
+
routes = _ref5[1];
|
|
2975
|
+
return routes;
|
|
2976
|
+
});
|
|
2977
|
+
if (allRoutes.length === 0) {
|
|
2978
|
+
return {
|
|
2979
|
+
error: true,
|
|
2980
|
+
message: "Route '".concat(route, "' could not be validated: No router modules found in the project. Use s.record(...).router(...) to define router modules.")
|
|
2981
|
+
};
|
|
2982
|
+
}
|
|
2983
|
+
allRoutes = filterRoutesByPatterns(allRoutes, includePattern, excludePattern);
|
|
2984
|
+
var alternatives = findSimilar(route, allRoutes);
|
|
2985
|
+
return {
|
|
2986
|
+
error: true,
|
|
2987
|
+
message: "Route '".concat(route, "' does not exist in any router module. ").concat(alternatives.length > 0 ? "Closest match: '".concat(alternatives[0].target, "'. Other similar: ").concat(alternatives.slice(1, 4).map(function (a) {
|
|
2988
|
+
return "'".concat(a.target, "'");
|
|
2989
|
+
}).join(", ")).concat(alternatives.length > 4 ? ", ..." : "") : "No similar routes found.")
|
|
2990
|
+
};
|
|
2991
|
+
}
|
|
2992
|
+
var patternValidation = validateRoutePatterns(route, includePattern, excludePattern);
|
|
2993
|
+
if (!patternValidation.valid) {
|
|
2994
|
+
return {
|
|
2995
|
+
error: true,
|
|
2996
|
+
message: patternValidation.message
|
|
2997
|
+
};
|
|
2998
|
+
}
|
|
2999
|
+
return {
|
|
3000
|
+
error: false
|
|
3001
|
+
};
|
|
3002
|
+
}
|
|
3003
|
+
/**
|
|
3004
|
+
* Resolves a single `keyof:check-keys` or `router:check-route` error against
|
|
3005
|
+
* the given schema/source snapshot. Returns:
|
|
3006
|
+
* - null if the error is not one of these fixes (caller should pass through)
|
|
3007
|
+
* - { status: "resolved" } if the referenced key/route is valid (drop error)
|
|
3008
|
+
* - { status: "remaining"; error } if invalid (rewritten error to surface)
|
|
3009
|
+
*/
|
|
3010
|
+
function resolveSchemaSourceFixForError(error, snapshot) {
|
|
3011
|
+
var _error$fixes;
|
|
3012
|
+
var fixes = (_error$fixes = error.fixes) !== null && _error$fixes !== void 0 ? _error$fixes : [];
|
|
3013
|
+
if (fixes.includes("keyof:check-keys")) {
|
|
3014
|
+
if (!error.value) {
|
|
3015
|
+
return {
|
|
3016
|
+
status: "remaining",
|
|
3017
|
+
error: _objectSpread2(_objectSpread2({}, error), {}, {
|
|
3018
|
+
message: "Could not find a value for keyOf. ".concat(TYPE_ERROR_MESSAGE),
|
|
3019
|
+
typeError: true,
|
|
3020
|
+
fixes: undefined
|
|
3021
|
+
})
|
|
3022
|
+
};
|
|
3023
|
+
}
|
|
3024
|
+
if (_typeof(error.value) !== "object") {
|
|
3025
|
+
return {
|
|
3026
|
+
status: "remaining",
|
|
3027
|
+
error: _objectSpread2(_objectSpread2({}, error), {}, {
|
|
3028
|
+
message: "Expected keyOf validation error to have a 'value' property of type 'object'. Found: ".concat(_typeof(error.value), ". ").concat(TYPE_ERROR_MESSAGE),
|
|
3029
|
+
typeError: true,
|
|
3030
|
+
fixes: undefined
|
|
3031
|
+
})
|
|
3032
|
+
};
|
|
3033
|
+
}
|
|
3034
|
+
var valueObj = error.value;
|
|
3035
|
+
var key = valueObj.key;
|
|
3036
|
+
var valueSourcePath = valueObj.sourcePath;
|
|
3037
|
+
if (typeof key !== "string") {
|
|
3038
|
+
return {
|
|
3039
|
+
status: "remaining",
|
|
3040
|
+
error: _objectSpread2(_objectSpread2({}, error), {}, {
|
|
3041
|
+
message: "Expected keyOf validation error 'value' to have property 'key' of type 'string'. Found: ".concat(_typeof(key), ". ").concat(TYPE_ERROR_MESSAGE),
|
|
3042
|
+
typeError: true,
|
|
3043
|
+
fixes: undefined
|
|
3044
|
+
})
|
|
3045
|
+
};
|
|
3046
|
+
}
|
|
3047
|
+
if (typeof valueSourcePath !== "string") {
|
|
3048
|
+
return {
|
|
3049
|
+
status: "remaining",
|
|
3050
|
+
error: _objectSpread2(_objectSpread2({}, error), {}, {
|
|
3051
|
+
message: "Expected keyOf validation error 'value' to have property 'sourcePath' of type 'string'. Found: ".concat(_typeof(valueSourcePath), ". ").concat(TYPE_ERROR_MESSAGE),
|
|
3052
|
+
typeError: true,
|
|
3053
|
+
fixes: undefined
|
|
3054
|
+
})
|
|
3055
|
+
};
|
|
3056
|
+
}
|
|
3057
|
+
var res = checkKeyIsValid(key, valueSourcePath, snapshot);
|
|
3058
|
+
if (res.error) {
|
|
3059
|
+
return {
|
|
3060
|
+
status: "remaining",
|
|
3061
|
+
error: _objectSpread2(_objectSpread2({}, error), {}, {
|
|
3062
|
+
message: res.message,
|
|
3063
|
+
fixes: undefined
|
|
3064
|
+
})
|
|
3065
|
+
};
|
|
3066
|
+
}
|
|
3067
|
+
return {
|
|
3068
|
+
status: "resolved"
|
|
3069
|
+
};
|
|
3070
|
+
}
|
|
3071
|
+
if (fixes.includes("router:check-route")) {
|
|
3072
|
+
if (!error.value) {
|
|
3073
|
+
return {
|
|
3074
|
+
status: "remaining",
|
|
3075
|
+
error: _objectSpread2(_objectSpread2({}, error), {}, {
|
|
3076
|
+
message: "Could not find a value for route. ".concat(TYPE_ERROR_MESSAGE),
|
|
3077
|
+
typeError: true,
|
|
3078
|
+
fixes: undefined
|
|
3079
|
+
})
|
|
3080
|
+
};
|
|
3081
|
+
}
|
|
3082
|
+
if (_typeof(error.value) !== "object") {
|
|
3083
|
+
return {
|
|
3084
|
+
status: "remaining",
|
|
3085
|
+
error: _objectSpread2(_objectSpread2({}, error), {}, {
|
|
3086
|
+
message: "Expected route validation error to have a 'value' property of type 'object'. Found: ".concat(_typeof(error.value), ". ").concat(TYPE_ERROR_MESSAGE),
|
|
3087
|
+
typeError: true,
|
|
3088
|
+
fixes: undefined
|
|
3089
|
+
})
|
|
3090
|
+
};
|
|
3091
|
+
}
|
|
3092
|
+
var _valueObj = error.value;
|
|
3093
|
+
var route = _valueObj.route;
|
|
3094
|
+
if (typeof route !== "string") {
|
|
3095
|
+
return {
|
|
3096
|
+
status: "remaining",
|
|
3097
|
+
error: _objectSpread2(_objectSpread2({}, error), {}, {
|
|
3098
|
+
message: "Expected route validation error 'value' to have property 'route' of type 'string'. Found: ".concat(_typeof(route), ". ").concat(TYPE_ERROR_MESSAGE),
|
|
3099
|
+
typeError: true,
|
|
3100
|
+
fixes: undefined
|
|
3101
|
+
})
|
|
3102
|
+
};
|
|
3103
|
+
}
|
|
3104
|
+
var include = asRegExpPattern(_valueObj.include);
|
|
3105
|
+
var exclude = asRegExpPattern(_valueObj.exclude);
|
|
3106
|
+
var _res = checkRouteIsValid(route, include, exclude, snapshot);
|
|
3107
|
+
if (_res.error) {
|
|
3108
|
+
return {
|
|
3109
|
+
status: "remaining",
|
|
3110
|
+
error: _objectSpread2(_objectSpread2({}, error), {}, {
|
|
3111
|
+
message: _res.message,
|
|
3112
|
+
fixes: undefined
|
|
3113
|
+
})
|
|
3114
|
+
};
|
|
3115
|
+
}
|
|
3116
|
+
return {
|
|
3117
|
+
status: "resolved"
|
|
3118
|
+
};
|
|
3119
|
+
}
|
|
3120
|
+
return null;
|
|
3121
|
+
}
|
|
3122
|
+
function asRegExpPattern(value) {
|
|
3123
|
+
if (value && _typeof(value) === "object" && "source" in value && "flags" in value && typeof value.source === "string" && typeof value.flags === "string") {
|
|
3124
|
+
return value;
|
|
3125
|
+
}
|
|
3126
|
+
return undefined;
|
|
3127
|
+
}
|
|
3128
|
+
|
|
3129
|
+
/**
|
|
3130
|
+
* Apply schema/source fix resolution across a map of validation errors.
|
|
3131
|
+
*
|
|
3132
|
+
* Errors with `keyof:check-keys` or `router:check-route` are resolved against
|
|
3133
|
+
* the in-memory schema/source snapshot — valid references drop the error,
|
|
3134
|
+
* invalid ones are rewritten with a "did you mean…" message and have their
|
|
3135
|
+
* `fixes` cleared (so downstream code reports them as plain validation errors).
|
|
3136
|
+
* All other errors pass through untouched.
|
|
3137
|
+
*
|
|
3138
|
+
* Source paths with no remaining errors are removed from the result.
|
|
3139
|
+
*/
|
|
3140
|
+
function resolveSchemaSourceFixes(validationErrors, snapshot) {
|
|
3141
|
+
var result = {};
|
|
3142
|
+
for (var sourcePathS in validationErrors) {
|
|
3143
|
+
var sourcePath = sourcePathS;
|
|
3144
|
+
var remaining = [];
|
|
3145
|
+
var _iterator2 = _createForOfIteratorHelper(validationErrors[sourcePath]),
|
|
3146
|
+
_step2;
|
|
3147
|
+
try {
|
|
3148
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
3149
|
+
var error = _step2.value;
|
|
3150
|
+
var resolved = resolveSchemaSourceFixForError(error, snapshot);
|
|
3151
|
+
if (resolved === null) {
|
|
3152
|
+
remaining.push(error);
|
|
3153
|
+
} else if (resolved.status === "remaining") {
|
|
3154
|
+
remaining.push(resolved.error);
|
|
3155
|
+
}
|
|
3156
|
+
}
|
|
3157
|
+
} catch (err) {
|
|
3158
|
+
_iterator2.e(err);
|
|
3159
|
+
} finally {
|
|
3160
|
+
_iterator2.f();
|
|
3161
|
+
}
|
|
3162
|
+
if (remaining.length > 0) {
|
|
3163
|
+
result[sourcePath] = remaining;
|
|
3164
|
+
}
|
|
3165
|
+
}
|
|
3166
|
+
return result;
|
|
3167
|
+
}
|
|
3168
|
+
|
|
3169
|
+
export { Api, DEFAULT_ERROR_MESSAGE, DateOptions, FileOptions, ImageOptions, ParentRef$1 as ParentRef, Patch, PatchBlock, PatchId, PatchJSON, RemirrorBr, RemirrorBulletList, RemirrorHeading, RemirrorImage, RemirrorJSON, RemirrorLinkMark, RemirrorListItem, RemirrorOrderedList, RemirrorParagraph, RemirrorText, RemirrorTextMark, RichTextOptions, SerializedArraySchema, SerializedBooleanSchema, SerializedDateSchema, SerializedDateTimeSchema, SerializedFileSchema, SerializedImageSchema, SerializedKeyOfSchema, SerializedLiteralSchema, SerializedNumberSchema, SerializedObjectSchema, SerializedRecordSchema, SerializedRichTextSchema, SerializedRouteSchema, SerializedSchema, SerializedStringSchema, SerializedUnionSchema, SharedValConfig, VAL_CONFIG_SESSION_STORAGE_KEY, VAL_ENABLE_COOKIE_NAME, VAL_SESSION_COOKIE, VAL_STATE_COOKIE, VAL_THEME_SESSION_STORAGE_KEY, ValCommit, ValDeployment, createRegExpFromPattern, createValClient, filterRoutesByPatterns, findSimilar, getErrorMessageFromUnknownJson, getNextAppRouterSitemapTree, getNextAppRouterSourceFolder, getPatternFromModuleFilePath, getRoutesOf, getRoutesWithModulePaths, levenshtein, parseRoutePattern, remirrorToRichTextSource, resolveSchemaSourceFixForError, resolveSchemaSourceFixes, richTextToRemirror, urlOf, validateRoutePatterns };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@valbuild/shared",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.97.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Val shared types and utilities",
|
|
6
6
|
"repository": {
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"zod": "^4.3.5",
|
|
33
33
|
"zod-validation-error": "^5.0.0",
|
|
34
|
-
"@valbuild/core": "0.
|
|
34
|
+
"@valbuild/core": "0.97.1"
|
|
35
35
|
},
|
|
36
36
|
"files": [
|
|
37
37
|
"dist",
|