@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.
@@ -758,6 +758,7 @@ export declare const Api: {
758
758
  validate_sources: z.ZodOptional<z.ZodPipe<z.ZodPipe<z.ZodArray<z.ZodString>, z.ZodTransform<string, string[]>> & z.ZodType<"true" | "false", string[], z.core.$ZodTypeInternals<"true" | "false", string[]>>, z.ZodTransform<boolean, "true" | "false">>>;
759
759
  validate_binary_files: z.ZodOptional<z.ZodPipe<z.ZodPipe<z.ZodArray<z.ZodString>, z.ZodTransform<string, string[]>> & z.ZodType<"true" | "false", string[], z.core.$ZodTypeInternals<"true" | "false", string[]>>, z.ZodTransform<boolean, "true" | "false">>>;
760
760
  exclude_patches: z.ZodOptional<z.ZodPipe<z.ZodPipe<z.ZodArray<z.ZodString>, z.ZodTransform<string, string[]>> & z.ZodType<"true" | "false", string[], z.core.$ZodTypeInternals<"true" | "false", string[]>>, z.ZodTransform<boolean, "true" | "false">>>;
761
+ apply_patches: z.ZodOptional<z.ZodPipe<z.ZodPipe<z.ZodArray<z.ZodString>, z.ZodTransform<string, string[]>> & z.ZodType<"true" | "false", string[], z.core.$ZodTypeInternals<"true" | "false", string[]>>, z.ZodTransform<boolean, "true" | "false">>>;
761
762
  };
762
763
  cookies: {
763
764
  val_session: z.ZodOptional<z.ZodString>;
@@ -12,5 +12,6 @@ export * from "./getSitemapTree.js";
12
12
  export * from "./parseRoutePattern.js";
13
13
  export * from "./getNextAppRouterSourceFolder.js";
14
14
  export * from "./routeValidation.js";
15
+ export * from "./resolveSchemaSourceFixes.js";
15
16
  export * from "./getErrorMessageFromUnknownJson.js";
16
17
  export * from "./zod/SerializedSchema.js";
@@ -0,0 +1,42 @@
1
+ import { type Json, type ModuleFilePath, type SerializedSchema, type SourcePath, type ValidationError } from "@valbuild/core";
2
+ export type SchemaSourceSnapshot = {
3
+ schemas: Record<ModuleFilePath, SerializedSchema>;
4
+ sources: Record<ModuleFilePath, Json>;
5
+ };
6
+ export type RouteInfo = {
7
+ route: string;
8
+ moduleFilePath: ModuleFilePath;
9
+ };
10
+ export declare function getRoutesWithModulePaths(schemas: Record<ModuleFilePath, SerializedSchema>, sources: Record<ModuleFilePath, Json>): RouteInfo[];
11
+ export declare function getRoutesOf(schemas: Record<ModuleFilePath, SerializedSchema>, sources: Record<ModuleFilePath, Json>): string[];
12
+ export declare const levenshtein: (a: string, b: string) => number;
13
+ export declare function findSimilar(key: string, targets: string[]): {
14
+ target: string;
15
+ distance: number;
16
+ }[];
17
+ export type ResolvedFix = {
18
+ status: "resolved";
19
+ } | {
20
+ status: "remaining";
21
+ error: ValidationError;
22
+ };
23
+ /**
24
+ * Resolves a single `keyof:check-keys` or `router:check-route` error against
25
+ * the given schema/source snapshot. Returns:
26
+ * - null if the error is not one of these fixes (caller should pass through)
27
+ * - { status: "resolved" } if the referenced key/route is valid (drop error)
28
+ * - { status: "remaining"; error } if invalid (rewritten error to surface)
29
+ */
30
+ export declare function resolveSchemaSourceFixForError(error: ValidationError, snapshot: SchemaSourceSnapshot): ResolvedFix | null;
31
+ /**
32
+ * Apply schema/source fix resolution across a map of validation errors.
33
+ *
34
+ * Errors with `keyof:check-keys` or `router:check-route` are resolved against
35
+ * the in-memory schema/source snapshot — valid references drop the error,
36
+ * invalid ones are rewritten with a "did you mean…" message and have their
37
+ * `fixes` cleared (so downstream code reports them as plain validation errors).
38
+ * All other errors pass through untouched.
39
+ *
40
+ * Source paths with no remaining errors are removed from the result.
41
+ */
42
+ export declare function resolveSchemaSourceFixes(validationErrors: Record<SourcePath, ValidationError[]>, snapshot: SchemaSourceSnapshot): Record<SourcePath, ValidationError[]>;
@@ -1,5 +1,5 @@
1
1
  import { z } from "zod";
2
- import { type SerializedSchema as SerializedSchemaT, type SerializedStringSchema as SerializedStringSchemaT, type SerializedLiteralSchema as SerializedLiteralSchemaT, type SerializedBooleanSchema as SerializedBooleanSchemaT, type SerializedNumberSchema as SerializedNumberSchemaT, type SerializedObjectSchema as SerializedObjectSchemaT, type SerializedArraySchema as SerializedArraySchemaT, type SerializedUnionSchema as SerializedUnionSchemaT, type SerializedRichTextSchema as SerializedRichTextSchemaT, type SerializedRichTextOptions as SerializedRichTextOptionsT, type SerializedRecordSchema as SerializedRecordSchemaT, type SerializedKeyOfSchema as SerializedKeyOfSchemaT, type SerializedRouteSchema as SerializedRouteSchemaT, type SerializedFileSchema as SerializedFileSchemaT, type SerializedDateSchema as SerializedDateSchemaT, type SerializedImageSchema as SerializedImageSchemaT } from "@valbuild/core";
2
+ import { type SerializedSchema as SerializedSchemaT, type SerializedStringSchema as SerializedStringSchemaT, type SerializedLiteralSchema as SerializedLiteralSchemaT, type SerializedBooleanSchema as SerializedBooleanSchemaT, type SerializedNumberSchema as SerializedNumberSchemaT, type SerializedObjectSchema as SerializedObjectSchemaT, type SerializedArraySchema as SerializedArraySchemaT, type SerializedUnionSchema as SerializedUnionSchemaT, type SerializedRichTextSchema as SerializedRichTextSchemaT, type SerializedRichTextOptions as SerializedRichTextOptionsT, type SerializedRecordSchema as SerializedRecordSchemaT, type SerializedKeyOfSchema as SerializedKeyOfSchemaT, type SerializedRouteSchema as SerializedRouteSchemaT, type SerializedFileSchema as SerializedFileSchemaT, type SerializedDateSchema as SerializedDateSchemaT, type SerializedDateTimeSchema as SerializedDateTimeSchemaT, type SerializedImageSchema as SerializedImageSchemaT } from "@valbuild/core";
3
3
  export declare const SerializedStringSchema: z.ZodType<SerializedStringSchemaT>;
4
4
  export declare const SerializedLiteralSchema: z.ZodType<SerializedLiteralSchemaT>;
5
5
  export declare const SerializedBooleanSchema: z.ZodType<SerializedBooleanSchemaT>;
@@ -22,6 +22,11 @@ export declare const FileOptions: z.ZodObject<{
22
22
  accept: z.ZodOptional<z.ZodString>;
23
23
  }, z.core.$strip>;
24
24
  export declare const SerializedFileSchema: z.ZodType<SerializedFileSchemaT>;
25
+ export declare const DateOptions: z.ZodObject<{
26
+ from: z.ZodOptional<z.ZodString>;
27
+ to: z.ZodOptional<z.ZodString>;
28
+ }, z.core.$strip>;
25
29
  export declare const SerializedDateSchema: z.ZodType<SerializedDateSchemaT>;
30
+ export declare const SerializedDateTimeSchema: z.ZodType<SerializedDateTimeSchemaT>;
26
31
  export declare const SerializedRouteSchema: z.ZodType<SerializedRouteSchemaT>;
27
32
  export declare const SerializedSchema: z.ZodType<SerializedSchemaT>;
@@ -1023,16 +1023,22 @@ var SerializedStringSchema = zod.z.object({
1023
1023
  }).optional()
1024
1024
  }).optional(),
1025
1025
  opt: zod.z["boolean"](),
1026
- raw: zod.z["boolean"]()
1026
+ raw: zod.z["boolean"](),
1027
+ readonly: zod.z["boolean"]().optional(),
1028
+ hidden: zod.z["boolean"]().optional()
1027
1029
  });
1028
1030
  var SerializedLiteralSchema = zod.z.object({
1029
1031
  type: zod.z.literal("literal"),
1030
1032
  value: zod.z.string(),
1031
- opt: zod.z["boolean"]()
1033
+ opt: zod.z["boolean"](),
1034
+ readonly: zod.z["boolean"]().optional(),
1035
+ hidden: zod.z["boolean"]().optional()
1032
1036
  });
1033
1037
  var SerializedBooleanSchema = zod.z.object({
1034
1038
  type: zod.z.literal("boolean"),
1035
- opt: zod.z["boolean"]()
1039
+ opt: zod.z["boolean"](),
1040
+ readonly: zod.z["boolean"]().optional(),
1041
+ hidden: zod.z["boolean"]().optional()
1036
1042
  });
1037
1043
  var SerializedNumberSchema = zod.z.object({
1038
1044
  type: zod.z.literal("number"),
@@ -1040,20 +1046,26 @@ var SerializedNumberSchema = zod.z.object({
1040
1046
  max: zod.z.number().optional(),
1041
1047
  min: zod.z.number().optional()
1042
1048
  }).optional(),
1043
- opt: zod.z["boolean"]()
1049
+ opt: zod.z["boolean"](),
1050
+ readonly: zod.z["boolean"]().optional(),
1051
+ hidden: zod.z["boolean"]().optional()
1044
1052
  });
1045
1053
  var SerializedObjectSchema = zod.z.lazy(function () {
1046
1054
  return zod.z.object({
1047
1055
  type: zod.z.literal("object"),
1048
1056
  items: zod.z.record(zod.z.string(), SerializedSchema),
1049
- opt: zod.z["boolean"]()
1057
+ opt: zod.z["boolean"](),
1058
+ readonly: zod.z["boolean"]().optional(),
1059
+ hidden: zod.z["boolean"]().optional()
1050
1060
  });
1051
1061
  });
1052
1062
  var SerializedArraySchema = zod.z.lazy(function () {
1053
1063
  return zod.z.object({
1054
1064
  type: zod.z.literal("array"),
1055
1065
  item: SerializedSchema,
1056
- opt: zod.z["boolean"]()
1066
+ opt: zod.z["boolean"](),
1067
+ readonly: zod.z["boolean"]().optional(),
1068
+ hidden: zod.z["boolean"]().optional()
1057
1069
  });
1058
1070
  });
1059
1071
  var SerializedUnionSchema = zod.z.lazy(function () {
@@ -1061,12 +1073,16 @@ var SerializedUnionSchema = zod.z.lazy(function () {
1061
1073
  type: zod.z.literal("union"),
1062
1074
  key: SerializedLiteralSchema,
1063
1075
  items: zod.z.array(SerializedLiteralSchema),
1064
- opt: zod.z["boolean"]()
1076
+ opt: zod.z["boolean"](),
1077
+ readonly: zod.z["boolean"]().optional(),
1078
+ hidden: zod.z["boolean"]().optional()
1065
1079
  }), zod.z.object({
1066
1080
  type: zod.z.literal("union"),
1067
1081
  key: zod.z.string(),
1068
1082
  items: zod.z.array(SerializedObjectSchema),
1069
- opt: zod.z["boolean"]()
1083
+ opt: zod.z["boolean"](),
1084
+ readonly: zod.z["boolean"]().optional(),
1085
+ hidden: zod.z["boolean"]().optional()
1070
1086
  })]);
1071
1087
  });
1072
1088
  var ImageOptions = zod.z.object({
@@ -1078,7 +1094,9 @@ var ImageOptions = zod.z.object({
1078
1094
  var SerializedImageSchema = zod.z.object({
1079
1095
  type: zod.z.literal("image"),
1080
1096
  options: ImageOptions.optional(),
1081
- opt: zod.z["boolean"]()
1097
+ opt: zod.z["boolean"](),
1098
+ readonly: zod.z["boolean"]().optional(),
1099
+ hidden: zod.z["boolean"]().optional()
1082
1100
  });
1083
1101
  var RichTextOptions = zod.z.lazy(function () {
1084
1102
  return zod.z.object({
@@ -1106,7 +1124,9 @@ var RichTextOptions = zod.z.lazy(function () {
1106
1124
  var SerializedRichTextSchema = zod.z.object({
1107
1125
  type: zod.z.literal("richtext"),
1108
1126
  options: RichTextOptions.optional(),
1109
- opt: zod.z["boolean"]()
1127
+ opt: zod.z["boolean"](),
1128
+ readonly: zod.z["boolean"]().optional(),
1129
+ hidden: zod.z["boolean"]().optional()
1110
1130
  });
1111
1131
  var SerializedRecordSchema = zod.z.lazy(function () {
1112
1132
  return zod.z.object({
@@ -1120,7 +1140,9 @@ var SerializedRecordSchema = zod.z.lazy(function () {
1120
1140
  directory: zod.z.string().optional(),
1121
1141
  remote: zod.z["boolean"]().optional(),
1122
1142
  alt: SerializedSchema.optional(),
1123
- moduleMetadata: zod.z.record(zod.z.string(), zod.z.record(zod.z.string(), zod.z.any())).optional()
1143
+ moduleMetadata: zod.z.record(zod.z.string(), zod.z.record(zod.z.string(), zod.z.any())).optional(),
1144
+ readonly: zod.z["boolean"]().optional(),
1145
+ hidden: zod.z["boolean"]().optional()
1124
1146
  }).passthrough();
1125
1147
  });
1126
1148
  var SerializedKeyOfSchema = zod.z.lazy(function () {
@@ -1136,7 +1158,9 @@ var SerializedKeyOfSchema = zod.z.lazy(function () {
1136
1158
  opt: zod.z["boolean"]().optional()
1137
1159
  })]).optional(),
1138
1160
  values: zod.z.union([zod.z.literal("string"), zod.z.array(zod.z.string())]),
1139
- opt: zod.z["boolean"]()
1161
+ opt: zod.z["boolean"](),
1162
+ readonly: zod.z["boolean"]().optional(),
1163
+ hidden: zod.z["boolean"]().optional()
1140
1164
  });
1141
1165
  });
1142
1166
  var FileOptions = zod.z.object({
@@ -1145,11 +1169,31 @@ var FileOptions = zod.z.object({
1145
1169
  var SerializedFileSchema = zod.z.object({
1146
1170
  type: zod.z.literal("file"),
1147
1171
  options: FileOptions.optional(),
1148
- opt: zod.z["boolean"]()
1172
+ opt: zod.z["boolean"](),
1173
+ readonly: zod.z["boolean"]().optional(),
1174
+ hidden: zod.z["boolean"]().optional()
1175
+ });
1176
+ var DateOptions = zod.z.object({
1177
+ from: zod.z.string().optional(),
1178
+ to: zod.z.string().optional()
1149
1179
  });
1150
1180
  var SerializedDateSchema = zod.z.object({
1151
1181
  type: zod.z.literal("date"),
1152
- opt: zod.z["boolean"]()
1182
+ options: DateOptions.optional(),
1183
+ opt: zod.z["boolean"](),
1184
+ customValidate: zod.z["boolean"]().optional(),
1185
+ readonly: zod.z["boolean"]().optional(),
1186
+ hidden: zod.z["boolean"]().optional(),
1187
+ description: zod.z.string().optional()
1188
+ });
1189
+ var SerializedDateTimeSchema = zod.z.object({
1190
+ type: zod.z.literal("dateTime"),
1191
+ options: DateOptions.optional(),
1192
+ opt: zod.z["boolean"](),
1193
+ customValidate: zod.z["boolean"]().optional(),
1194
+ readonly: zod.z["boolean"]().optional(),
1195
+ hidden: zod.z["boolean"]().optional(),
1196
+ description: zod.z.string().optional()
1153
1197
  });
1154
1198
  var SerializedRouteSchema = zod.z.object({
1155
1199
  type: zod.z.literal("route"),
@@ -1165,9 +1209,11 @@ var SerializedRouteSchema = zod.z.object({
1165
1209
  customValidate: zod.z["boolean"]().optional()
1166
1210
  }).optional(),
1167
1211
  opt: zod.z["boolean"](),
1168
- customValidate: zod.z["boolean"]().optional()
1212
+ customValidate: zod.z["boolean"]().optional(),
1213
+ readonly: zod.z["boolean"]().optional(),
1214
+ hidden: zod.z["boolean"]().optional()
1169
1215
  });
1170
- var SerializedSchema = zod.z.union([SerializedStringSchema, SerializedLiteralSchema, SerializedBooleanSchema, SerializedNumberSchema, SerializedObjectSchema, SerializedArraySchema, SerializedUnionSchema, SerializedRichTextSchema, SerializedRecordSchema, SerializedKeyOfSchema, SerializedRouteSchema, SerializedFileSchema, SerializedDateSchema, SerializedImageSchema]);
1216
+ var SerializedSchema = zod.z.union([SerializedStringSchema, SerializedLiteralSchema, SerializedBooleanSchema, SerializedNumberSchema, SerializedObjectSchema, SerializedArraySchema, SerializedUnionSchema, SerializedRichTextSchema, SerializedRecordSchema, SerializedKeyOfSchema, SerializedRouteSchema, SerializedFileSchema, SerializedDateSchema, SerializedDateTimeSchema, SerializedImageSchema]);
1171
1217
 
1172
1218
  var ValCommit = zod.z.object({
1173
1219
  commitSha: zod.z.string(),
@@ -1795,7 +1841,8 @@ var Api = {
1795
1841
  query: {
1796
1842
  validate_sources: onlyOneBooleanQueryParam.optional(),
1797
1843
  validate_binary_files: onlyOneBooleanQueryParam.optional(),
1798
- exclude_patches: onlyOneBooleanQueryParam.optional()
1844
+ exclude_patches: onlyOneBooleanQueryParam.optional(),
1845
+ apply_patches: onlyOneBooleanQueryParam.optional()
1799
1846
  },
1800
1847
  cookies: {
1801
1848
  val_session: zod.z.string().optional()
@@ -1832,7 +1879,7 @@ var Api = {
1832
1879
  source: zod.z.any().optional(),
1833
1880
  //.optional(), // TODO: Json zod type
1834
1881
  baseSource: zod.z.any().optional(),
1835
- // pre-patch source for compare view; set only when the module has pending patches
1882
+ // pre-patch source for compare view; only set when the server applies patches (apply_patches=true) and the module has pending patches
1836
1883
  patches: zod.z.object({
1837
1884
  applied: zod.z.array(PatchId),
1838
1885
  skipped: zod.z.array(PatchId).optional(),
@@ -2748,8 +2795,384 @@ function createRegExpFromPattern(pattern) {
2748
2795
  }
2749
2796
  }
2750
2797
 
2798
+ var TYPE_ERROR_MESSAGE = "This is most likely a Val version mismatch or Val bug.";
2799
+ function getRoutesWithModulePaths(schemas, sources) {
2800
+ var routeMap = new Map();
2801
+ for (var moduleFilePathS in schemas) {
2802
+ var moduleFilePath = moduleFilePathS;
2803
+ var schema = schemas[moduleFilePath];
2804
+ var source = sources[moduleFilePath];
2805
+ if (schema && schema.type === "record" && schema.router && source && _typeof(source) === "object" && !Array.isArray(source)) {
2806
+ for (var key in source) {
2807
+ if (!routeMap.has(key)) {
2808
+ routeMap.set(key, moduleFilePath);
2809
+ }
2810
+ }
2811
+ }
2812
+ }
2813
+ var routes = Array.from(routeMap.entries()).map(function (_ref) {
2814
+ var _ref2 = _slicedToArray(_ref, 2),
2815
+ route = _ref2[0],
2816
+ moduleFilePath = _ref2[1];
2817
+ return {
2818
+ route: route,
2819
+ moduleFilePath: moduleFilePath
2820
+ };
2821
+ });
2822
+ return routes.sort(function (a, b) {
2823
+ return a.route.localeCompare(b.route);
2824
+ });
2825
+ }
2826
+ function getRoutesOf(schemas, sources) {
2827
+ return getRoutesWithModulePaths(schemas, sources).map(function (r) {
2828
+ return r.route;
2829
+ });
2830
+ }
2831
+
2832
+ // GPT generated levenshtein distance algorithm
2833
+ var levenshtein = function levenshtein(a, b) {
2834
+ var _ref3 = [a.length, b.length],
2835
+ m = _ref3[0],
2836
+ n = _ref3[1];
2837
+ if (!m || !n) return Math.max(m, n);
2838
+ var dp = Array.from({
2839
+ length: m + 1
2840
+ }, function (_, i) {
2841
+ return i;
2842
+ });
2843
+ for (var j = 1; j <= n; j++) {
2844
+ var prev = dp[0];
2845
+ dp[0] = j;
2846
+ for (var i = 1; i <= m; i++) {
2847
+ var temp = dp[i];
2848
+ dp[i] = a[i - 1] === b[j - 1] ? prev : Math.min(prev + 1, dp[i - 1] + 1, dp[i] + 1);
2849
+ prev = temp;
2850
+ }
2851
+ }
2852
+ return dp[m];
2853
+ };
2854
+ function findSimilar(key, targets) {
2855
+ return targets.map(function (target) {
2856
+ return {
2857
+ target: target,
2858
+ distance: levenshtein(key, target)
2859
+ };
2860
+ }).sort(function (a, b) {
2861
+ return a.distance - b.distance;
2862
+ });
2863
+ }
2864
+ function getKeyOfRecordAt(sourcePath, snapshot) {
2865
+ var _Internal$splitModule = core.Internal.splitModuleFilePathAndModulePath(sourcePath),
2866
+ _Internal$splitModule2 = _slicedToArray(_Internal$splitModule, 2),
2867
+ moduleFilePath = _Internal$splitModule2[0],
2868
+ modulePath = _Internal$splitModule2[1];
2869
+ var moduleSource = snapshot.sources[moduleFilePath];
2870
+ var moduleSchema = snapshot.schemas[moduleFilePath];
2871
+ if (!moduleSchema || moduleSource === undefined) {
2872
+ return {
2873
+ source: undefined,
2874
+ schema: undefined
2875
+ };
2876
+ }
2877
+ if (!modulePath) {
2878
+ return {
2879
+ source: moduleSource,
2880
+ schema: moduleSchema
2881
+ };
2882
+ }
2883
+ // Walk both schema and source. This intentionally only follows the
2884
+ // patterns produced by keyOf().sourcePath — typically a top-level record or
2885
+ // an object property pointing at a record. The walk is best-effort and
2886
+ // returns undefined source on any mismatch.
2887
+ var source = moduleSource;
2888
+ var schema = moduleSchema;
2889
+ var _iterator = _createForOfIteratorHelper(core.Internal.splitModulePath(modulePath)),
2890
+ _step;
2891
+ try {
2892
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
2893
+ var part = _step.value;
2894
+ if (source && _typeof(source) === "object" && !Array.isArray(source) && part in source) {
2895
+ source = source[part];
2896
+ } else {
2897
+ source = undefined;
2898
+ }
2899
+ if (schema && schema.type === "object" && schema.items[part]) {
2900
+ schema = schema.items[part];
2901
+ } else if (schema && schema.type === "record") {
2902
+ schema = schema.item;
2903
+ } else {
2904
+ schema = undefined;
2905
+ }
2906
+ }
2907
+ } catch (err) {
2908
+ _iterator.e(err);
2909
+ } finally {
2910
+ _iterator.f();
2911
+ }
2912
+ return {
2913
+ source: source,
2914
+ schema: schema
2915
+ };
2916
+ }
2917
+ function checkKeyIsValid(key, sourcePath, snapshot) {
2918
+ var _getKeyOfRecordAt = getKeyOfRecordAt(sourcePath, snapshot),
2919
+ keyOfModuleSource = _getKeyOfRecordAt.source,
2920
+ keyOfModuleSchema = _getKeyOfRecordAt.schema;
2921
+ if (keyOfModuleSchema && keyOfModuleSchema.type !== "record") {
2922
+ return {
2923
+ error: true,
2924
+ message: "Expected key at ".concat(sourcePath, " to be of type 'record'")
2925
+ };
2926
+ }
2927
+ if (keyOfModuleSource && _typeof(keyOfModuleSource) === "object" && !Array.isArray(keyOfModuleSource) && key in keyOfModuleSource) {
2928
+ return {
2929
+ error: false
2930
+ };
2931
+ }
2932
+ if (!keyOfModuleSource || _typeof(keyOfModuleSource) !== "object" || Array.isArray(keyOfModuleSource)) {
2933
+ return {
2934
+ error: true,
2935
+ message: "Expected ".concat(sourcePath, " to be a truthy object")
2936
+ };
2937
+ }
2938
+ var alternatives = findSimilar(key, Object.keys(keyOfModuleSource));
2939
+ if (alternatives.length === 0) {
2940
+ return {
2941
+ error: true,
2942
+ message: "Key '".concat(key, "' does not exist in ").concat(sourcePath, ".")
2943
+ };
2944
+ }
2945
+ return {
2946
+ error: true,
2947
+ 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) {
2948
+ return "'".concat(a.target, "'");
2949
+ }).join(", ")).concat(alternatives.length > 4 ? ", ..." : "")
2950
+ };
2951
+ }
2952
+ function checkRouteIsValid(route, includePattern, excludePattern, snapshot) {
2953
+ var routerModules = {};
2954
+ for (var moduleFilePathS in snapshot.schemas) {
2955
+ var moduleFilePath = moduleFilePathS;
2956
+ var schema = snapshot.schemas[moduleFilePath];
2957
+ if ((schema === null || schema === void 0 ? void 0 : schema.type) === "record" && schema.router) {
2958
+ var source = snapshot.sources[moduleFilePath];
2959
+ if (source && _typeof(source) === "object" && !Array.isArray(source)) {
2960
+ routerModules[moduleFilePath] = Object.keys(source);
2961
+ }
2962
+ }
2963
+ }
2964
+ var moduleEntries = Object.entries(routerModules);
2965
+ var foundInModule = null;
2966
+ for (var _i = 0, _moduleEntries = moduleEntries; _i < _moduleEntries.length; _i++) {
2967
+ var _moduleEntries$_i = _slicedToArray(_moduleEntries[_i], 2),
2968
+ _moduleFilePath = _moduleEntries$_i[0],
2969
+ routes = _moduleEntries$_i[1];
2970
+ if (routes.includes(route)) {
2971
+ foundInModule = _moduleFilePath;
2972
+ break;
2973
+ }
2974
+ }
2975
+ if (!foundInModule) {
2976
+ var allRoutes = moduleEntries.flatMap(function (_ref4) {
2977
+ var _ref5 = _slicedToArray(_ref4, 2),
2978
+ routes = _ref5[1];
2979
+ return routes;
2980
+ });
2981
+ if (allRoutes.length === 0) {
2982
+ return {
2983
+ error: true,
2984
+ message: "Route '".concat(route, "' could not be validated: No router modules found in the project. Use s.record(...).router(...) to define router modules.")
2985
+ };
2986
+ }
2987
+ allRoutes = filterRoutesByPatterns(allRoutes, includePattern, excludePattern);
2988
+ var alternatives = findSimilar(route, allRoutes);
2989
+ return {
2990
+ error: true,
2991
+ 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) {
2992
+ return "'".concat(a.target, "'");
2993
+ }).join(", ")).concat(alternatives.length > 4 ? ", ..." : "") : "No similar routes found.")
2994
+ };
2995
+ }
2996
+ var patternValidation = validateRoutePatterns(route, includePattern, excludePattern);
2997
+ if (!patternValidation.valid) {
2998
+ return {
2999
+ error: true,
3000
+ message: patternValidation.message
3001
+ };
3002
+ }
3003
+ return {
3004
+ error: false
3005
+ };
3006
+ }
3007
+ /**
3008
+ * Resolves a single `keyof:check-keys` or `router:check-route` error against
3009
+ * the given schema/source snapshot. Returns:
3010
+ * - null if the error is not one of these fixes (caller should pass through)
3011
+ * - { status: "resolved" } if the referenced key/route is valid (drop error)
3012
+ * - { status: "remaining"; error } if invalid (rewritten error to surface)
3013
+ */
3014
+ function resolveSchemaSourceFixForError(error, snapshot) {
3015
+ var _error$fixes;
3016
+ var fixes = (_error$fixes = error.fixes) !== null && _error$fixes !== void 0 ? _error$fixes : [];
3017
+ if (fixes.includes("keyof:check-keys")) {
3018
+ if (!error.value) {
3019
+ return {
3020
+ status: "remaining",
3021
+ error: _objectSpread2(_objectSpread2({}, error), {}, {
3022
+ message: "Could not find a value for keyOf. ".concat(TYPE_ERROR_MESSAGE),
3023
+ typeError: true,
3024
+ fixes: undefined
3025
+ })
3026
+ };
3027
+ }
3028
+ if (_typeof(error.value) !== "object") {
3029
+ return {
3030
+ status: "remaining",
3031
+ error: _objectSpread2(_objectSpread2({}, error), {}, {
3032
+ message: "Expected keyOf validation error to have a 'value' property of type 'object'. Found: ".concat(_typeof(error.value), ". ").concat(TYPE_ERROR_MESSAGE),
3033
+ typeError: true,
3034
+ fixes: undefined
3035
+ })
3036
+ };
3037
+ }
3038
+ var valueObj = error.value;
3039
+ var key = valueObj.key;
3040
+ var valueSourcePath = valueObj.sourcePath;
3041
+ if (typeof key !== "string") {
3042
+ return {
3043
+ status: "remaining",
3044
+ error: _objectSpread2(_objectSpread2({}, error), {}, {
3045
+ message: "Expected keyOf validation error 'value' to have property 'key' of type 'string'. Found: ".concat(_typeof(key), ". ").concat(TYPE_ERROR_MESSAGE),
3046
+ typeError: true,
3047
+ fixes: undefined
3048
+ })
3049
+ };
3050
+ }
3051
+ if (typeof valueSourcePath !== "string") {
3052
+ return {
3053
+ status: "remaining",
3054
+ error: _objectSpread2(_objectSpread2({}, error), {}, {
3055
+ message: "Expected keyOf validation error 'value' to have property 'sourcePath' of type 'string'. Found: ".concat(_typeof(valueSourcePath), ". ").concat(TYPE_ERROR_MESSAGE),
3056
+ typeError: true,
3057
+ fixes: undefined
3058
+ })
3059
+ };
3060
+ }
3061
+ var res = checkKeyIsValid(key, valueSourcePath, snapshot);
3062
+ if (res.error) {
3063
+ return {
3064
+ status: "remaining",
3065
+ error: _objectSpread2(_objectSpread2({}, error), {}, {
3066
+ message: res.message,
3067
+ fixes: undefined
3068
+ })
3069
+ };
3070
+ }
3071
+ return {
3072
+ status: "resolved"
3073
+ };
3074
+ }
3075
+ if (fixes.includes("router:check-route")) {
3076
+ if (!error.value) {
3077
+ return {
3078
+ status: "remaining",
3079
+ error: _objectSpread2(_objectSpread2({}, error), {}, {
3080
+ message: "Could not find a value for route. ".concat(TYPE_ERROR_MESSAGE),
3081
+ typeError: true,
3082
+ fixes: undefined
3083
+ })
3084
+ };
3085
+ }
3086
+ if (_typeof(error.value) !== "object") {
3087
+ return {
3088
+ status: "remaining",
3089
+ error: _objectSpread2(_objectSpread2({}, error), {}, {
3090
+ message: "Expected route validation error to have a 'value' property of type 'object'. Found: ".concat(_typeof(error.value), ". ").concat(TYPE_ERROR_MESSAGE),
3091
+ typeError: true,
3092
+ fixes: undefined
3093
+ })
3094
+ };
3095
+ }
3096
+ var _valueObj = error.value;
3097
+ var route = _valueObj.route;
3098
+ if (typeof route !== "string") {
3099
+ return {
3100
+ status: "remaining",
3101
+ error: _objectSpread2(_objectSpread2({}, error), {}, {
3102
+ message: "Expected route validation error 'value' to have property 'route' of type 'string'. Found: ".concat(_typeof(route), ". ").concat(TYPE_ERROR_MESSAGE),
3103
+ typeError: true,
3104
+ fixes: undefined
3105
+ })
3106
+ };
3107
+ }
3108
+ var include = asRegExpPattern(_valueObj.include);
3109
+ var exclude = asRegExpPattern(_valueObj.exclude);
3110
+ var _res = checkRouteIsValid(route, include, exclude, snapshot);
3111
+ if (_res.error) {
3112
+ return {
3113
+ status: "remaining",
3114
+ error: _objectSpread2(_objectSpread2({}, error), {}, {
3115
+ message: _res.message,
3116
+ fixes: undefined
3117
+ })
3118
+ };
3119
+ }
3120
+ return {
3121
+ status: "resolved"
3122
+ };
3123
+ }
3124
+ return null;
3125
+ }
3126
+ function asRegExpPattern(value) {
3127
+ if (value && _typeof(value) === "object" && "source" in value && "flags" in value && typeof value.source === "string" && typeof value.flags === "string") {
3128
+ return value;
3129
+ }
3130
+ return undefined;
3131
+ }
3132
+
3133
+ /**
3134
+ * Apply schema/source fix resolution across a map of validation errors.
3135
+ *
3136
+ * Errors with `keyof:check-keys` or `router:check-route` are resolved against
3137
+ * the in-memory schema/source snapshot — valid references drop the error,
3138
+ * invalid ones are rewritten with a "did you mean…" message and have their
3139
+ * `fixes` cleared (so downstream code reports them as plain validation errors).
3140
+ * All other errors pass through untouched.
3141
+ *
3142
+ * Source paths with no remaining errors are removed from the result.
3143
+ */
3144
+ function resolveSchemaSourceFixes(validationErrors, snapshot) {
3145
+ var result = {};
3146
+ for (var sourcePathS in validationErrors) {
3147
+ var sourcePath = sourcePathS;
3148
+ var remaining = [];
3149
+ var _iterator2 = _createForOfIteratorHelper(validationErrors[sourcePath]),
3150
+ _step2;
3151
+ try {
3152
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
3153
+ var error = _step2.value;
3154
+ var resolved = resolveSchemaSourceFixForError(error, snapshot);
3155
+ if (resolved === null) {
3156
+ remaining.push(error);
3157
+ } else if (resolved.status === "remaining") {
3158
+ remaining.push(resolved.error);
3159
+ }
3160
+ }
3161
+ } catch (err) {
3162
+ _iterator2.e(err);
3163
+ } finally {
3164
+ _iterator2.f();
3165
+ }
3166
+ if (remaining.length > 0) {
3167
+ result[sourcePath] = remaining;
3168
+ }
3169
+ }
3170
+ return result;
3171
+ }
3172
+
2751
3173
  exports.Api = Api;
2752
3174
  exports.DEFAULT_ERROR_MESSAGE = DEFAULT_ERROR_MESSAGE;
3175
+ exports.DateOptions = DateOptions;
2753
3176
  exports.FileOptions = FileOptions;
2754
3177
  exports.ImageOptions = ImageOptions;
2755
3178
  exports.ParentRef = ParentRef$1;
@@ -2772,6 +3195,7 @@ exports.RichTextOptions = RichTextOptions;
2772
3195
  exports.SerializedArraySchema = SerializedArraySchema;
2773
3196
  exports.SerializedBooleanSchema = SerializedBooleanSchema;
2774
3197
  exports.SerializedDateSchema = SerializedDateSchema;
3198
+ exports.SerializedDateTimeSchema = SerializedDateTimeSchema;
2775
3199
  exports.SerializedFileSchema = SerializedFileSchema;
2776
3200
  exports.SerializedImageSchema = SerializedImageSchema;
2777
3201
  exports.SerializedKeyOfSchema = SerializedKeyOfSchema;
@@ -2795,12 +3219,18 @@ exports.ValDeployment = ValDeployment;
2795
3219
  exports.createRegExpFromPattern = createRegExpFromPattern;
2796
3220
  exports.createValClient = createValClient;
2797
3221
  exports.filterRoutesByPatterns = filterRoutesByPatterns;
3222
+ exports.findSimilar = findSimilar;
2798
3223
  exports.getErrorMessageFromUnknownJson = getErrorMessageFromUnknownJson;
2799
3224
  exports.getNextAppRouterSitemapTree = getNextAppRouterSitemapTree;
2800
3225
  exports.getNextAppRouterSourceFolder = getNextAppRouterSourceFolder;
2801
3226
  exports.getPatternFromModuleFilePath = getPatternFromModuleFilePath;
3227
+ exports.getRoutesOf = getRoutesOf;
3228
+ exports.getRoutesWithModulePaths = getRoutesWithModulePaths;
3229
+ exports.levenshtein = levenshtein;
2802
3230
  exports.parseRoutePattern = parseRoutePattern;
2803
3231
  exports.remirrorToRichTextSource = remirrorToRichTextSource;
3232
+ exports.resolveSchemaSourceFixForError = resolveSchemaSourceFixForError;
3233
+ exports.resolveSchemaSourceFixes = resolveSchemaSourceFixes;
2804
3234
  exports.richTextToRemirror = richTextToRemirror;
2805
3235
  exports.urlOf = urlOf;
2806
3236
  exports.validateRoutePatterns = validateRoutePatterns;