@logixjs/form 0.0.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.
Files changed (101) hide show
  1. package/dist/Error-VvknI9Wj.d.cts +37 -0
  2. package/dist/Error-VvknI9Wj.d.ts +37 -0
  3. package/dist/Error.cjs +46 -0
  4. package/dist/Error.cjs.map +1 -0
  5. package/dist/Error.d.cts +1 -0
  6. package/dist/Error.d.ts +1 -0
  7. package/dist/Error.js +14 -0
  8. package/dist/Error.js.map +1 -0
  9. package/dist/Form.cjs +2455 -0
  10. package/dist/Form.cjs.map +1 -0
  11. package/dist/Form.d.cts +64 -0
  12. package/dist/Form.d.ts +64 -0
  13. package/dist/Form.js +25 -0
  14. package/dist/Form.js.map +1 -0
  15. package/dist/FormView-CAg9LVrf.d.cts +17 -0
  16. package/dist/FormView-CAg9LVrf.d.ts +17 -0
  17. package/dist/FormView.cjs +61 -0
  18. package/dist/FormView.cjs.map +1 -0
  19. package/dist/FormView.d.cts +1 -0
  20. package/dist/FormView.d.ts +1 -0
  21. package/dist/FormView.js +8 -0
  22. package/dist/FormView.js.map +1 -0
  23. package/dist/Path-DOjMkAS6.d.cts +42 -0
  24. package/dist/Path-DOjMkAS6.d.ts +42 -0
  25. package/dist/Path.cjs +132 -0
  26. package/dist/Path.cjs.map +1 -0
  27. package/dist/Path.d.cts +1 -0
  28. package/dist/Path.d.ts +1 -0
  29. package/dist/Path.js +22 -0
  30. package/dist/Path.js.map +1 -0
  31. package/dist/Rule-BOAiSVz9.d.cts +202 -0
  32. package/dist/Rule-BOAiSVz9.d.ts +202 -0
  33. package/dist/Rule.cjs +307 -0
  34. package/dist/Rule.cjs.map +1 -0
  35. package/dist/Rule.d.cts +2 -0
  36. package/dist/Rule.d.ts +2 -0
  37. package/dist/Rule.js +34 -0
  38. package/dist/Rule.js.map +1 -0
  39. package/dist/SchemaErrorMapping-Cu5gl7-Z.d.ts +50 -0
  40. package/dist/SchemaErrorMapping-DOrgLzii.d.cts +50 -0
  41. package/dist/SchemaErrorMapping.cjs +305 -0
  42. package/dist/SchemaErrorMapping.cjs.map +1 -0
  43. package/dist/SchemaErrorMapping.d.cts +2 -0
  44. package/dist/SchemaErrorMapping.d.ts +2 -0
  45. package/dist/SchemaErrorMapping.js +17 -0
  46. package/dist/SchemaErrorMapping.js.map +1 -0
  47. package/dist/SchemaPathMapping-BCoUW-_q.d.ts +16 -0
  48. package/dist/SchemaPathMapping-BUq2zm8W.d.cts +20 -0
  49. package/dist/SchemaPathMapping-BUq2zm8W.d.ts +20 -0
  50. package/dist/SchemaPathMapping-DJnExqM3.d.cts +16 -0
  51. package/dist/SchemaPathMapping.cjs +179 -0
  52. package/dist/SchemaPathMapping.cjs.map +1 -0
  53. package/dist/SchemaPathMapping.d.cts +2 -0
  54. package/dist/SchemaPathMapping.d.ts +2 -0
  55. package/dist/SchemaPathMapping.js +12 -0
  56. package/dist/SchemaPathMapping.js.map +1 -0
  57. package/dist/Trait-Bu794ROY.d.cts +49 -0
  58. package/dist/Trait-Bu794ROY.d.ts +49 -0
  59. package/dist/Trait.cjs +48 -0
  60. package/dist/Trait.cjs.map +1 -0
  61. package/dist/Trait.d.cts +2 -0
  62. package/dist/Trait.d.ts +2 -0
  63. package/dist/Trait.js +12 -0
  64. package/dist/Trait.js.map +1 -0
  65. package/dist/chunk-5DRI5UGD.js +105 -0
  66. package/dist/chunk-5DRI5UGD.js.map +1 -0
  67. package/dist/chunk-AD2ZA7KA.js +23 -0
  68. package/dist/chunk-AD2ZA7KA.js.map +1 -0
  69. package/dist/chunk-EOXJRCM6.js +146 -0
  70. package/dist/chunk-EOXJRCM6.js.map +1 -0
  71. package/dist/chunk-JZ5FZKPJ.js +71 -0
  72. package/dist/chunk-JZ5FZKPJ.js.map +1 -0
  73. package/dist/chunk-LNJJPZAG.js +46 -0
  74. package/dist/chunk-LNJJPZAG.js.map +1 -0
  75. package/dist/chunk-NAR5SIFP.js +22 -0
  76. package/dist/chunk-NAR5SIFP.js.map +1 -0
  77. package/dist/chunk-OJVEZKU7.js +117 -0
  78. package/dist/chunk-OJVEZKU7.js.map +1 -0
  79. package/dist/chunk-PZ5AY32C.js +10 -0
  80. package/dist/chunk-PZ5AY32C.js.map +1 -0
  81. package/dist/chunk-S5JTU2CM.js +31 -0
  82. package/dist/chunk-S5JTU2CM.js.map +1 -0
  83. package/dist/chunk-YHDEJ47V.js +1885 -0
  84. package/dist/chunk-YHDEJ47V.js.map +1 -0
  85. package/dist/chunk-YVHXLY63.js +315 -0
  86. package/dist/chunk-YVHXLY63.js.map +1 -0
  87. package/dist/impl-BfSlyM58.d.ts +225 -0
  88. package/dist/impl-Ccdm5eDF.d.cts +225 -0
  89. package/dist/index.cjs +2689 -0
  90. package/dist/index.cjs.map +1 -0
  91. package/dist/index.d.cts +12 -0
  92. package/dist/index.d.ts +12 -0
  93. package/dist/index.js +56 -0
  94. package/dist/index.js.map +1 -0
  95. package/dist/react/index.cjs +332 -0
  96. package/dist/react/index.cjs.map +1 -0
  97. package/dist/react/index.d.cts +43 -0
  98. package/dist/react/index.d.ts +43 -0
  99. package/dist/react/index.js +201 -0
  100. package/dist/react/index.js.map +1 -0
  101. package/package.json +62 -0
@@ -0,0 +1,305 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/SchemaErrorMapping.ts
21
+ var SchemaErrorMapping_exports = {};
22
+ __export(SchemaErrorMapping_exports, {
23
+ SchemaErrorMapping: () => SchemaErrorMapping,
24
+ applySchemaErrorToState: () => applySchemaErrorToState,
25
+ toSchemaErrorTree: () => toSchemaErrorTree,
26
+ toSchemaErrorWrites: () => toSchemaErrorWrites
27
+ });
28
+ module.exports = __toCommonJS(SchemaErrorMapping_exports);
29
+
30
+ // src/internal/schema/SchemaPathMapping.ts
31
+ var isNumericSegment = (seg) => /^[0-9]+$/.test(seg);
32
+ var parseSegmentsFromString = (path) => {
33
+ if (!path) return [];
34
+ return path.split(".").filter(Boolean).map((seg) => isNumericSegment(seg) ? Number(seg) : seg);
35
+ };
36
+ var asSegments = (value) => {
37
+ if (typeof value === "string") return parseSegmentsFromString(value);
38
+ if (Array.isArray(value)) {
39
+ const parts = [];
40
+ for (const x of value) {
41
+ if (typeof x === "number" && Number.isFinite(x)) {
42
+ parts.push(Math.floor(x));
43
+ continue;
44
+ }
45
+ if (typeof x === "string" && x.length > 0) {
46
+ parts.push(isNumericSegment(x) ? Number(x) : x);
47
+ }
48
+ }
49
+ return parts.length ? parts : void 0;
50
+ }
51
+ return void 0;
52
+ };
53
+ var toConcretePath = (segments) => segments.map(String).join(".");
54
+ var toPatternPath = (segments) => {
55
+ const out = [];
56
+ const indices = [];
57
+ for (const seg of segments) {
58
+ if (typeof seg === "number") {
59
+ out.push("[]");
60
+ indices.push(seg);
61
+ } else {
62
+ out.push(seg);
63
+ }
64
+ }
65
+ const pattern = out.join(".").replace(/\.\[\]/g, "[]");
66
+ return { pattern, indices };
67
+ };
68
+ var applyIndicesToPattern = (pattern, indices) => {
69
+ if (!pattern) return pattern;
70
+ const raw = pattern.split(".").filter(Boolean);
71
+ const out = [];
72
+ let cursor = 0;
73
+ for (const part of raw) {
74
+ if (part === "[]") {
75
+ const idx = indices[cursor++];
76
+ if (idx === void 0) return void 0;
77
+ out.push(String(idx));
78
+ continue;
79
+ }
80
+ if (part.endsWith("[]") && part.length > 2) {
81
+ const base = part.slice(0, -2);
82
+ out.push(base);
83
+ const idx = indices[cursor++];
84
+ if (idx === void 0) return void 0;
85
+ out.push(String(idx));
86
+ continue;
87
+ }
88
+ out.push(part);
89
+ }
90
+ return out.join(".");
91
+ };
92
+ var concatPaths = (prefix, rest) => {
93
+ if (!prefix) return rest;
94
+ if (!rest) return prefix;
95
+ return `${prefix}.${rest}`;
96
+ };
97
+ var mapByRename = (segments, rename) => {
98
+ const concrete = toConcretePath(segments);
99
+ const direct = rename[concrete];
100
+ if (direct !== void 0) {
101
+ return direct;
102
+ }
103
+ const { pattern, indices } = toPatternPath(segments);
104
+ const patternDirect = rename[pattern];
105
+ if (patternDirect !== void 0) {
106
+ return applyIndicesToPattern(patternDirect, indices);
107
+ }
108
+ const keys = Object.keys(rename).sort((a, b) => b.length - a.length);
109
+ for (const from of keys) {
110
+ const to = rename[from];
111
+ const isPattern = from.includes("[]");
112
+ const target = isPattern ? pattern : concrete;
113
+ if (target === from || target.startsWith(`${from}.`)) {
114
+ const rawRest = target.slice(from.length);
115
+ const rest = rawRest.startsWith(".") ? rawRest.slice(1) : rawRest;
116
+ const mapped = concatPaths(to, rest);
117
+ return isPattern ? applyIndicesToPattern(mapped, indices) : mapped;
118
+ }
119
+ }
120
+ const segMap = {};
121
+ for (const [from, to] of Object.entries(rename)) {
122
+ if (from.includes(".") || from.includes("[]")) continue;
123
+ if (to.includes(".") || to.includes("[]")) continue;
124
+ if (!to) continue;
125
+ segMap[from] = to;
126
+ }
127
+ if (Object.keys(segMap).length === 0) return void 0;
128
+ const mappedSegments = segments.map((seg) => typeof seg === "string" ? segMap[seg] ?? seg : seg);
129
+ return toConcretePath(mappedSegments);
130
+ };
131
+ var extractRawPaths = (schemaError) => {
132
+ const out = [];
133
+ if (schemaError && typeof schemaError === "object") {
134
+ const anyErr = schemaError;
135
+ if (Array.isArray(anyErr.errors)) {
136
+ for (const e of anyErr.errors) {
137
+ if (e && typeof e === "object" && "path" in e) {
138
+ out.push(e.path);
139
+ }
140
+ }
141
+ }
142
+ if (Array.isArray(anyErr.issues)) {
143
+ for (const e of anyErr.issues) {
144
+ if (e && typeof e === "object" && "path" in e) {
145
+ out.push(e.path);
146
+ }
147
+ }
148
+ }
149
+ if ("path" in anyErr) {
150
+ out.push(anyErr.path);
151
+ }
152
+ }
153
+ return out;
154
+ };
155
+ var mapSchemaErrorToFieldPaths = (schemaError, options) => {
156
+ const fromEscapeHatch = options?.errorMap?.(schemaError);
157
+ if (fromEscapeHatch && fromEscapeHatch.length) {
158
+ return Array.from(new Set(fromEscapeHatch.filter((p) => typeof p === "string" && p.length > 0)));
159
+ }
160
+ const rename = options?.rename;
161
+ const results = [];
162
+ for (const rawPath of extractRawPaths(schemaError)) {
163
+ const segments = asSegments(rawPath);
164
+ if (!segments || segments.length === 0) continue;
165
+ const mapped = rename ? mapByRename(segments, rename) : void 0;
166
+ const path = mapped ?? toConcretePath(segments);
167
+ if (path) results.push(path);
168
+ }
169
+ return Array.from(new Set(results));
170
+ };
171
+
172
+ // src/internal/form/path.ts
173
+ var cloneContainer = (value) => {
174
+ if (Array.isArray(value)) return value.slice();
175
+ if (value && typeof value === "object") return { ...value };
176
+ return void 0;
177
+ };
178
+ var setAtPath = (state, path, value) => {
179
+ if (!path) return value;
180
+ const segments = path.split(".");
181
+ const rootClone = cloneContainer(state) ?? {};
182
+ let current = rootClone;
183
+ let currentSource = state;
184
+ for (let i = 0; i < segments.length - 1; i++) {
185
+ const segment = segments[i];
186
+ const index = Number(segment);
187
+ const isIndex = Number.isInteger(index) && String(index) === segment;
188
+ const nextSource = currentSource == null ? void 0 : isIndex && Array.isArray(currentSource) ? currentSource[index] : currentSource[segment];
189
+ const nextSegment = segments[i + 1];
190
+ const nextIndex = Number(nextSegment);
191
+ const nextIsIndex = Number.isInteger(nextIndex) && String(nextIndex) === nextSegment;
192
+ const nextClone = cloneContainer(nextSource) ?? (nextIsIndex ? [] : {});
193
+ if (isIndex && Array.isArray(current)) {
194
+ current[index] = nextClone;
195
+ } else {
196
+ current[segment] = nextClone;
197
+ }
198
+ current = nextClone;
199
+ currentSource = nextSource;
200
+ }
201
+ const last = segments[segments.length - 1];
202
+ const lastIndex = Number(last);
203
+ const lastIsIndex = Number.isInteger(lastIndex) && String(lastIndex) === last;
204
+ if (lastIsIndex && Array.isArray(current)) {
205
+ current[lastIndex] = value;
206
+ } else {
207
+ current[last] = value;
208
+ }
209
+ return rootClone;
210
+ };
211
+
212
+ // src/Path.ts
213
+ var isNumericSegment2 = (seg) => /^[0-9]+$/.test(seg);
214
+ var splitPath = (path) => {
215
+ if (!path) return [];
216
+ const parts = path.split(".").filter((p) => p.length > 0);
217
+ const segs = [];
218
+ for (const part of parts) {
219
+ if (!part) continue;
220
+ if (part.endsWith("[]")) {
221
+ const base = part.slice(0, -2);
222
+ if (base) segs.push(base);
223
+ segs.push("[]");
224
+ continue;
225
+ }
226
+ const bracket = /^(.+)\[(\d+)\]$/.exec(part);
227
+ if (bracket) {
228
+ const base = bracket[1];
229
+ if (base) segs.push(base);
230
+ segs.push(bracket[2]);
231
+ continue;
232
+ }
233
+ segs.push(part);
234
+ }
235
+ return segs;
236
+ };
237
+ var toErrorsPath = (valuePath) => {
238
+ if (!valuePath) return "errors";
239
+ const segs = splitPath(valuePath);
240
+ const out = [];
241
+ for (const seg of segs) {
242
+ if (isNumericSegment2(seg)) {
243
+ out.push("rows", seg);
244
+ continue;
245
+ }
246
+ if (seg === "[]") {
247
+ continue;
248
+ }
249
+ out.push(seg);
250
+ }
251
+ return `errors.${out.join(".")}`;
252
+ };
253
+ var toSchemaErrorsPath = (valuePath) => {
254
+ const base = toErrorsPath(valuePath);
255
+ return base === "errors" ? "errors.$schema" : base.replace(/^errors\./, "errors.$schema.");
256
+ };
257
+
258
+ // src/internal/schema/SchemaErrorMapping.ts
259
+ var toSchemaErrorWrites = (schemaError, options) => {
260
+ const fieldPaths = mapSchemaErrorToFieldPaths(schemaError, options);
261
+ if (fieldPaths.length === 0) return [];
262
+ const toLeaf = options?.toLeaf ?? ((e) => e);
263
+ const leaf = toLeaf(schemaError);
264
+ return fieldPaths.map((fieldPath) => ({
265
+ fieldPath,
266
+ errorPath: toSchemaErrorsPath(fieldPath),
267
+ error: leaf
268
+ }));
269
+ };
270
+ var toSchemaErrorTree = (schemaError, options) => {
271
+ const writes = toSchemaErrorWrites(schemaError, options);
272
+ if (writes.length === 0) return {};
273
+ let next = {};
274
+ for (const w of writes) {
275
+ const prefix = "errors.$schema.";
276
+ const relative = w.errorPath.startsWith(prefix) ? w.errorPath.slice(prefix.length) : w.errorPath;
277
+ if (!relative) continue;
278
+ next = setAtPath(next, relative, w.error);
279
+ }
280
+ return next;
281
+ };
282
+ var applySchemaErrorToState = (state, schemaError, options) => {
283
+ const writes = toSchemaErrorWrites(schemaError, options);
284
+ if (writes.length === 0) return state;
285
+ let next = state;
286
+ for (const w of writes) {
287
+ next = setAtPath(next, w.errorPath, w.error);
288
+ }
289
+ return next;
290
+ };
291
+
292
+ // src/SchemaErrorMapping.ts
293
+ var SchemaErrorMapping = {
294
+ applySchemaErrorToState,
295
+ toSchemaErrorTree,
296
+ toSchemaErrorWrites
297
+ };
298
+ // Annotate the CommonJS export names for ESM import in node:
299
+ 0 && (module.exports = {
300
+ SchemaErrorMapping,
301
+ applySchemaErrorToState,
302
+ toSchemaErrorTree,
303
+ toSchemaErrorWrites
304
+ });
305
+ //# sourceMappingURL=SchemaErrorMapping.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/SchemaErrorMapping.ts","../src/internal/schema/SchemaPathMapping.ts","../src/internal/form/path.ts","../src/Path.ts","../src/internal/schema/SchemaErrorMapping.ts"],"sourcesContent":["import {\n applySchemaErrorToState,\n toSchemaErrorTree,\n toSchemaErrorWrites,\n} from './internal/schema/SchemaErrorMapping.js'\n\nexport type { SchemaErrorMappingOptions, SchemaErrorWrite } from './internal/schema/SchemaErrorMapping.js'\n\nexport { applySchemaErrorToState, toSchemaErrorTree, toSchemaErrorWrites }\n\nexport const SchemaErrorMapping = {\n applySchemaErrorToState,\n toSchemaErrorTree,\n toSchemaErrorWrites,\n} as const\n","export type FieldPath = string\n\nexport type SchemaError = unknown\n\nexport interface SchemaPathMappingOptions {\n /**\n * errorMap: an escape hatch for complex transform cases (explicitly assigns an error to a set of field paths).\n */\n readonly errorMap?: (schemaError: SchemaError) => ReadonlyArray<FieldPath>\n /**\n * rename: a common rename mapping (domainPath -> viewPath).\n */\n readonly rename?: Readonly<Record<FieldPath, FieldPath>>\n}\n\ntype Segment = string | number\n\nconst isNumericSegment = (seg: string): boolean => /^[0-9]+$/.test(seg)\n\nconst parseSegmentsFromString = (path: string): ReadonlyArray<Segment> => {\n if (!path) return []\n return path\n .split('.')\n .filter(Boolean)\n .map((seg) => (isNumericSegment(seg) ? Number(seg) : seg))\n}\n\nconst asSegments = (value: unknown): ReadonlyArray<Segment> | undefined => {\n if (typeof value === 'string') return parseSegmentsFromString(value)\n if (Array.isArray(value)) {\n const parts: Array<Segment> = []\n for (const x of value) {\n if (typeof x === 'number' && Number.isFinite(x)) {\n parts.push(Math.floor(x))\n continue\n }\n if (typeof x === 'string' && x.length > 0) {\n parts.push(isNumericSegment(x) ? Number(x) : x)\n }\n }\n return parts.length ? parts : undefined\n }\n return undefined\n}\n\nconst toConcretePath = (segments: ReadonlyArray<Segment>): string => segments.map(String).join('.')\n\nconst toPatternPath = (\n segments: ReadonlyArray<Segment>,\n): { readonly pattern: string; readonly indices: ReadonlyArray<number> } => {\n const out: Array<string> = []\n const indices: Array<number> = []\n for (const seg of segments) {\n if (typeof seg === 'number') {\n out.push('[]')\n indices.push(seg)\n } else {\n out.push(seg)\n }\n }\n const pattern = out.join('.').replace(/\\.\\[\\]/g, '[]')\n return { pattern, indices }\n}\n\nconst applyIndicesToPattern = (pattern: string, indices: ReadonlyArray<number>): string | undefined => {\n if (!pattern) return pattern\n const raw = pattern.split('.').filter(Boolean)\n const out: Array<string> = []\n\n let cursor = 0\n for (const part of raw) {\n if (part === '[]') {\n const idx = indices[cursor++]\n if (idx === undefined) return undefined\n out.push(String(idx))\n continue\n }\n if (part.endsWith('[]') && part.length > 2) {\n const base = part.slice(0, -2)\n out.push(base)\n const idx = indices[cursor++]\n if (idx === undefined) return undefined\n out.push(String(idx))\n continue\n }\n out.push(part)\n }\n return out.join('.')\n}\n\nconst concatPaths = (prefix: string, rest: string): string => {\n if (!prefix) return rest\n if (!rest) return prefix\n return `${prefix}.${rest}`\n}\n\nconst mapByRename = (\n segments: ReadonlyArray<Segment>,\n rename: Readonly<Record<FieldPath, FieldPath>>,\n): string | undefined => {\n const concrete = toConcretePath(segments)\n const direct = rename[concrete]\n if (direct !== undefined) {\n return direct\n }\n\n const { pattern, indices } = toPatternPath(segments)\n const patternDirect = rename[pattern]\n if (patternDirect !== undefined) {\n return applyIndicesToPattern(patternDirect, indices)\n }\n\n const keys = Object.keys(rename).sort((a, b) => b.length - a.length)\n for (const from of keys) {\n const to = rename[from]!\n\n const isPattern = from.includes('[]')\n const target = isPattern ? pattern : concrete\n\n if (target === from || target.startsWith(`${from}.`)) {\n const rawRest = target.slice(from.length)\n const rest = rawRest.startsWith('.') ? rawRest.slice(1) : rawRest\n const mapped = concatPaths(to, rest)\n return isPattern ? applyIndicesToPattern(mapped, indices) : mapped\n }\n }\n\n // Segment-level rename: only enabled when both from/to are single segments, to avoid accidental \"path rewrites\".\n const segMap: Record<string, string> = {}\n for (const [from, to] of Object.entries(rename)) {\n if (from.includes('.') || from.includes('[]')) continue\n if (to.includes('.') || to.includes('[]')) continue\n if (!to) continue\n segMap[from] = to\n }\n if (Object.keys(segMap).length === 0) return undefined\n\n const mappedSegments = segments.map((seg) => (typeof seg === 'string' ? (segMap[seg] ?? seg) : seg))\n return toConcretePath(mappedSegments)\n}\n\nconst extractRawPaths = (schemaError: SchemaError): ReadonlyArray<unknown> => {\n const out: Array<unknown> = []\n\n if (schemaError && typeof schemaError === 'object') {\n const anyErr = schemaError as any\n if (Array.isArray(anyErr.errors)) {\n for (const e of anyErr.errors) {\n if (e && typeof e === 'object' && 'path' in (e as any)) {\n out.push((e as any).path)\n }\n }\n }\n if (Array.isArray(anyErr.issues)) {\n for (const e of anyErr.issues) {\n if (e && typeof e === 'object' && 'path' in (e as any)) {\n out.push((e as any).path)\n }\n }\n }\n if ('path' in anyErr) {\n out.push(anyErr.path)\n }\n }\n\n return out\n}\n\n/**\n * mapSchemaErrorToFieldPaths:\n * - Phase 3: provides a minimal, usable default mapping, and allows `errorMap` to override.\n * - In a later phase (US3), we will raise the coverage goal to \">= 80% common mappings\" and fill the test matrix.\n */\nexport const mapSchemaErrorToFieldPaths = (\n schemaError: SchemaError,\n options?: SchemaPathMappingOptions,\n): ReadonlyArray<FieldPath> => {\n const fromEscapeHatch = options?.errorMap?.(schemaError)\n if (fromEscapeHatch && fromEscapeHatch.length) {\n return Array.from(new Set(fromEscapeHatch.filter((p) => typeof p === 'string' && p.length > 0)))\n }\n\n const rename = options?.rename\n const results: Array<string> = []\n\n for (const rawPath of extractRawPaths(schemaError)) {\n const segments = asSegments(rawPath)\n if (!segments || segments.length === 0) continue\n\n const mapped = rename ? mapByRename(segments, rename) : undefined\n\n const path = mapped ?? toConcretePath(segments)\n if (path) results.push(path)\n }\n\n return Array.from(new Set(results))\n}\n","export const getAtPath = (state: unknown, path: string): unknown => {\n if (!path) return state\n\n const segments = path.split('.')\n let current: any = state\n\n for (const segment of segments) {\n if (current == null) return undefined\n const index = Number(segment)\n if (Array.isArray(current) && Number.isInteger(index) && String(index) === segment) {\n current = current[index]\n continue\n }\n current = current[segment]\n }\n\n return current\n}\n\nconst cloneContainer = (value: unknown): any => {\n if (Array.isArray(value)) return value.slice()\n if (value && typeof value === 'object') return { ...(value as any) }\n return undefined\n}\n\nexport const setAtPath = (state: unknown, path: string, value: unknown): unknown => {\n if (!path) return value\n\n const segments = path.split('.')\n const rootClone = cloneContainer(state) ?? {}\n\n let current: any = rootClone\n let currentSource: any = state\n\n for (let i = 0; i < segments.length - 1; i++) {\n const segment = segments[i]!\n const index = Number(segment)\n const isIndex = Number.isInteger(index) && String(index) === segment\n\n const nextSource =\n currentSource == null\n ? undefined\n : isIndex && Array.isArray(currentSource)\n ? currentSource[index]\n : currentSource[segment]\n\n const nextSegment = segments[i + 1]!\n const nextIndex = Number(nextSegment)\n const nextIsIndex = Number.isInteger(nextIndex) && String(nextIndex) === nextSegment\n\n const nextClone = cloneContainer(nextSource) ?? (nextIsIndex ? [] : {})\n\n if (isIndex && Array.isArray(current)) {\n current[index] = nextClone\n } else {\n current[segment] = nextClone\n }\n\n current = nextClone\n currentSource = nextSource\n }\n\n const last = segments[segments.length - 1]!\n const lastIndex = Number(last)\n const lastIsIndex = Number.isInteger(lastIndex) && String(lastIndex) === last\n\n if (lastIsIndex && Array.isArray(current)) {\n current[lastIndex] = value\n } else {\n current[last] = value\n }\n\n return rootClone\n}\n\nexport const unsetAtPath = (state: unknown, path: string): unknown => {\n if (!path) return state\n if (getAtPath(state, path) === undefined) return state\n\n const segments = path.split('.')\n const rootClone = cloneContainer(state)\n if (rootClone === undefined) return state\n\n let current: any = rootClone\n let currentSource: any = state\n\n for (let i = 0; i < segments.length - 1; i++) {\n const segment = segments[i]!\n const index = Number(segment)\n const isIndex = Number.isInteger(index) && String(index) === segment\n\n const nextSource =\n currentSource == null\n ? undefined\n : isIndex && Array.isArray(currentSource)\n ? currentSource[index]\n : currentSource[segment]\n\n const nextClone = cloneContainer(nextSource)\n if (nextClone === undefined) {\n return state\n }\n\n if (isIndex && Array.isArray(current)) {\n current[index] = nextClone\n } else {\n current[segment] = nextClone\n }\n\n current = nextClone\n currentSource = nextSource\n }\n\n const last = segments[segments.length - 1]!\n const lastIndex = Number(last)\n const lastIsIndex = Number.isInteger(lastIndex) && String(lastIndex) === last\n\n if (lastIsIndex && Array.isArray(current)) {\n current[lastIndex] = undefined\n return rootClone\n }\n\n if (current && typeof current === 'object') {\n delete current[last]\n }\n\n return rootClone\n}\n\nexport const updateArrayAtPath = (\n state: unknown,\n path: string,\n update: (items: ReadonlyArray<unknown>) => ReadonlyArray<unknown>,\n): unknown => {\n const current = getAtPath(state, path)\n const items = Array.isArray(current) ? current : []\n const next = update(items)\n return setAtPath(state, path, next)\n}\n","export type ValuePath = string\nexport type PatternPath = string\nexport type ListPath = string\nexport type ErrorsPath = string\nexport type UiPath = string\nexport type FieldPath = ReadonlyArray<string>\n\nconst isNumericSegment = (seg: string): boolean => /^[0-9]+$/.test(seg)\n\nconst splitPath = (path: string): ReadonlyArray<string> => {\n if (!path) return []\n const parts = path.split('.').filter((p) => p.length > 0)\n const segs: Array<string> = []\n\n for (const part of parts) {\n if (!part) continue\n if (part.endsWith('[]')) {\n const base = part.slice(0, -2)\n if (base) segs.push(base)\n segs.push('[]')\n continue\n }\n const bracket = /^(.+)\\[(\\d+)\\]$/.exec(part)\n if (bracket) {\n const base = bracket[1]!\n if (base) segs.push(base)\n segs.push(bracket[2]!)\n continue\n }\n segs.push(part)\n }\n\n return segs\n}\n\nexport const toPatternPath = (valuePath: ValuePath): PatternPath => {\n if (!valuePath) return valuePath\n const segs = splitPath(valuePath)\n const out: Array<string> = []\n\n for (const seg of segs) {\n if (seg === '[]' || isNumericSegment(seg)) {\n if (out.length === 0) continue\n const last = out[out.length - 1]!\n if (!last.endsWith('[]')) out[out.length - 1] = `${last}[]`\n continue\n }\n out.push(seg)\n }\n\n return out.join('.')\n}\n\nexport const toListPath = (valuePath: ValuePath): ListPath | undefined => {\n const segs = splitPath(valuePath)\n const firstIndex = segs.findIndex((seg) => seg === '[]' || isNumericSegment(seg))\n if (firstIndex <= 0) return undefined\n return segs.slice(0, firstIndex).join('.')\n}\n\nexport const toErrorsPath = (valuePath: ValuePath): ErrorsPath => {\n if (!valuePath) return 'errors'\n const segs = splitPath(valuePath)\n const out: Array<string> = []\n\n for (const seg of segs) {\n if (isNumericSegment(seg)) {\n out.push('rows', seg)\n continue\n }\n if (seg === '[]') {\n continue\n }\n out.push(seg)\n }\n\n return `errors.${out.join('.')}`\n}\n\nexport const toManualErrorsPath = (valuePath: ValuePath): ErrorsPath => {\n const base = toErrorsPath(valuePath)\n return base === 'errors' ? 'errors.$manual' : base.replace(/^errors\\./, 'errors.$manual.')\n}\n\nexport const toSchemaErrorsPath = (valuePath: ValuePath): ErrorsPath => {\n const base = toErrorsPath(valuePath)\n return base === 'errors' ? 'errors.$schema' : base.replace(/^errors\\./, 'errors.$schema.')\n}\n\nexport const toUiPath = (valuePath: ValuePath): UiPath => (valuePath ? `ui.${valuePath}` : 'ui')\n\nexport const toFieldPath = (path: ValuePath | PatternPath): FieldPath => {\n const segs = splitPath(path)\n const out: Array<string> = []\n for (const seg of segs) {\n if (seg === '[]' || isNumericSegment(seg)) continue\n out.push(seg)\n }\n return out.length > 0 ? out : ['$root']\n}\n\nexport const Path = {\n toPatternPath,\n toListPath,\n toErrorsPath,\n toManualErrorsPath,\n toSchemaErrorsPath,\n toUiPath,\n toFieldPath,\n} as const\n","import type { FieldPath, SchemaError, SchemaPathMappingOptions } from './SchemaPathMapping.js'\nimport { mapSchemaErrorToFieldPaths } from './SchemaPathMapping.js'\nimport { setAtPath } from '../form/path.js'\nimport { toSchemaErrorsPath } from '../../Path.js'\n\nexport interface SchemaErrorMappingOptions extends SchemaPathMappingOptions {\n /**\n * toLeaf: converts a schemaError into a leaf value that can be written into the error tree.\n * - Default: write the raw schemaError as-is.\n */\n readonly toLeaf?: (schemaError: SchemaError) => unknown\n}\n\nexport type SchemaErrorWrite = {\n /**\n * fieldPath: the field path without the `errors.` prefix (domain-facing).\n */\n readonly fieldPath: FieldPath\n /**\n * errorPath: the actual path written into state (with the `errors.` prefix).\n */\n readonly errorPath: string\n readonly error: unknown\n}\n\nexport const toSchemaErrorWrites = (\n schemaError: SchemaError,\n options?: SchemaErrorMappingOptions,\n): ReadonlyArray<SchemaErrorWrite> => {\n const fieldPaths = mapSchemaErrorToFieldPaths(schemaError, options)\n if (fieldPaths.length === 0) return []\n\n const toLeaf = options?.toLeaf ?? ((e: SchemaError) => e)\n const leaf = toLeaf(schemaError)\n\n return fieldPaths.map((fieldPath) => ({\n fieldPath,\n errorPath: toSchemaErrorsPath(fieldPath),\n error: leaf,\n }))\n}\n\n/**\n * toSchemaErrorTree:\n * - Produces a subtree that can be written directly to `errors.$schema` (without the `errors.$schema` prefix).\n */\nexport const toSchemaErrorTree = (schemaError: SchemaError, options?: SchemaErrorMappingOptions): unknown => {\n const writes = toSchemaErrorWrites(schemaError, options)\n if (writes.length === 0) return {}\n\n let next: unknown = {}\n for (const w of writes) {\n const prefix = 'errors.$schema.'\n const relative = w.errorPath.startsWith(prefix) ? w.errorPath.slice(prefix.length) : w.errorPath\n if (!relative) continue\n next = setAtPath(next, relative, w.error)\n }\n return next\n}\n\n/**\n * applySchemaErrorToState:\n * - Maps a SchemaError and writes it back into state.errors.$schema.*.\n * - Does not clear stale errors that are no longer matched (the caller should clear them within a more explicit scope).\n */\nexport const applySchemaErrorToState = (\n state: unknown,\n schemaError: SchemaError,\n options?: SchemaErrorMappingOptions,\n): unknown => {\n const writes = toSchemaErrorWrites(schemaError, options)\n if (writes.length === 0) return state\n\n let next: unknown = state\n for (const w of writes) {\n next = setAtPath(next, w.errorPath, w.error)\n }\n return next\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACiBA,IAAM,mBAAmB,CAAC,QAAyB,WAAW,KAAK,GAAG;AAEtE,IAAM,0BAA0B,CAAC,SAAyC;AACxE,MAAI,CAAC,KAAM,QAAO,CAAC;AACnB,SAAO,KACJ,MAAM,GAAG,EACT,OAAO,OAAO,EACd,IAAI,CAAC,QAAS,iBAAiB,GAAG,IAAI,OAAO,GAAG,IAAI,GAAI;AAC7D;AAEA,IAAM,aAAa,CAAC,UAAuD;AACzE,MAAI,OAAO,UAAU,SAAU,QAAO,wBAAwB,KAAK;AAC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AA,EAChC;AAAA,EACA;AAAA,EACA;AACF;","names":["isNumericSegment","isNumericSegment"]}
@@ -0,0 +1,2 @@
1
+ export { c as SchemaErrorMapping, d as SchemaErrorMappingOptions, e as SchemaErrorWrite, a as applySchemaErrorToState, t as toSchemaErrorTree, b as toSchemaErrorWrites } from './SchemaErrorMapping-DOrgLzii.cjs';
2
+ import './SchemaPathMapping-BUq2zm8W.cjs';
@@ -0,0 +1,2 @@
1
+ export { c as SchemaErrorMapping, d as SchemaErrorMappingOptions, e as SchemaErrorWrite, a as applySchemaErrorToState, t as toSchemaErrorTree, b as toSchemaErrorWrites } from './SchemaErrorMapping-Cu5gl7-Z.js';
2
+ import './SchemaPathMapping-BUq2zm8W.js';
@@ -0,0 +1,17 @@
1
+ import {
2
+ SchemaErrorMapping,
3
+ applySchemaErrorToState,
4
+ toSchemaErrorTree,
5
+ toSchemaErrorWrites
6
+ } from "./chunk-JZ5FZKPJ.js";
7
+ import "./chunk-5DRI5UGD.js";
8
+ import "./chunk-OJVEZKU7.js";
9
+ import "./chunk-EOXJRCM6.js";
10
+ import "./chunk-PZ5AY32C.js";
11
+ export {
12
+ SchemaErrorMapping,
13
+ applySchemaErrorToState,
14
+ toSchemaErrorTree,
15
+ toSchemaErrorWrites
16
+ };
17
+ //# sourceMappingURL=SchemaErrorMapping.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,16 @@
1
+ import { S as SchemaError, a as SchemaPathMappingOptions, F as FieldPath, m as mapSchemaErrorToFieldPaths } from './SchemaPathMapping-BUq2zm8W.js';
2
+
3
+ declare const SchemaPathMapping: {
4
+ readonly mapSchemaErrorToFieldPaths: (schemaError: SchemaError, options?: SchemaPathMappingOptions) => ReadonlyArray<FieldPath>;
5
+ };
6
+
7
+ declare const SchemaPathMapping$1_FieldPath: typeof FieldPath;
8
+ declare const SchemaPathMapping$1_SchemaError: typeof SchemaError;
9
+ declare const SchemaPathMapping$1_SchemaPathMapping: typeof SchemaPathMapping;
10
+ declare const SchemaPathMapping$1_SchemaPathMappingOptions: typeof SchemaPathMappingOptions;
11
+ declare const SchemaPathMapping$1_mapSchemaErrorToFieldPaths: typeof mapSchemaErrorToFieldPaths;
12
+ declare namespace SchemaPathMapping$1 {
13
+ export { SchemaPathMapping$1_FieldPath as FieldPath, SchemaPathMapping$1_SchemaError as SchemaError, SchemaPathMapping$1_SchemaPathMapping as SchemaPathMapping, SchemaPathMapping$1_SchemaPathMappingOptions as SchemaPathMappingOptions, SchemaPathMapping$1_mapSchemaErrorToFieldPaths as mapSchemaErrorToFieldPaths };
14
+ }
15
+
16
+ export { SchemaPathMapping$1 as S, SchemaPathMapping as a };
@@ -0,0 +1,20 @@
1
+ type FieldPath = string;
2
+ type SchemaError = unknown;
3
+ interface SchemaPathMappingOptions {
4
+ /**
5
+ * errorMap: an escape hatch for complex transform cases (explicitly assigns an error to a set of field paths).
6
+ */
7
+ readonly errorMap?: (schemaError: SchemaError) => ReadonlyArray<FieldPath>;
8
+ /**
9
+ * rename: a common rename mapping (domainPath -> viewPath).
10
+ */
11
+ readonly rename?: Readonly<Record<FieldPath, FieldPath>>;
12
+ }
13
+ /**
14
+ * mapSchemaErrorToFieldPaths:
15
+ * - Phase 3: provides a minimal, usable default mapping, and allows `errorMap` to override.
16
+ * - In a later phase (US3), we will raise the coverage goal to ">= 80% common mappings" and fill the test matrix.
17
+ */
18
+ declare const mapSchemaErrorToFieldPaths: (schemaError: SchemaError, options?: SchemaPathMappingOptions) => ReadonlyArray<FieldPath>;
19
+
20
+ export { type FieldPath as F, type SchemaError as S, type SchemaPathMappingOptions as a, mapSchemaErrorToFieldPaths as m };
@@ -0,0 +1,20 @@
1
+ type FieldPath = string;
2
+ type SchemaError = unknown;
3
+ interface SchemaPathMappingOptions {
4
+ /**
5
+ * errorMap: an escape hatch for complex transform cases (explicitly assigns an error to a set of field paths).
6
+ */
7
+ readonly errorMap?: (schemaError: SchemaError) => ReadonlyArray<FieldPath>;
8
+ /**
9
+ * rename: a common rename mapping (domainPath -> viewPath).
10
+ */
11
+ readonly rename?: Readonly<Record<FieldPath, FieldPath>>;
12
+ }
13
+ /**
14
+ * mapSchemaErrorToFieldPaths:
15
+ * - Phase 3: provides a minimal, usable default mapping, and allows `errorMap` to override.
16
+ * - In a later phase (US3), we will raise the coverage goal to ">= 80% common mappings" and fill the test matrix.
17
+ */
18
+ declare const mapSchemaErrorToFieldPaths: (schemaError: SchemaError, options?: SchemaPathMappingOptions) => ReadonlyArray<FieldPath>;
19
+
20
+ export { type FieldPath as F, type SchemaError as S, type SchemaPathMappingOptions as a, mapSchemaErrorToFieldPaths as m };
@@ -0,0 +1,16 @@
1
+ import { S as SchemaError, a as SchemaPathMappingOptions, F as FieldPath, m as mapSchemaErrorToFieldPaths } from './SchemaPathMapping-BUq2zm8W.cjs';
2
+
3
+ declare const SchemaPathMapping: {
4
+ readonly mapSchemaErrorToFieldPaths: (schemaError: SchemaError, options?: SchemaPathMappingOptions) => ReadonlyArray<FieldPath>;
5
+ };
6
+
7
+ declare const SchemaPathMapping$1_FieldPath: typeof FieldPath;
8
+ declare const SchemaPathMapping$1_SchemaError: typeof SchemaError;
9
+ declare const SchemaPathMapping$1_SchemaPathMapping: typeof SchemaPathMapping;
10
+ declare const SchemaPathMapping$1_SchemaPathMappingOptions: typeof SchemaPathMappingOptions;
11
+ declare const SchemaPathMapping$1_mapSchemaErrorToFieldPaths: typeof mapSchemaErrorToFieldPaths;
12
+ declare namespace SchemaPathMapping$1 {
13
+ export { SchemaPathMapping$1_FieldPath as FieldPath, SchemaPathMapping$1_SchemaError as SchemaError, SchemaPathMapping$1_SchemaPathMapping as SchemaPathMapping, SchemaPathMapping$1_SchemaPathMappingOptions as SchemaPathMappingOptions, SchemaPathMapping$1_mapSchemaErrorToFieldPaths as mapSchemaErrorToFieldPaths };
14
+ }
15
+
16
+ export { SchemaPathMapping$1 as S, SchemaPathMapping as a };
@@ -0,0 +1,179 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/SchemaPathMapping.ts
21
+ var SchemaPathMapping_exports = {};
22
+ __export(SchemaPathMapping_exports, {
23
+ SchemaPathMapping: () => SchemaPathMapping,
24
+ mapSchemaErrorToFieldPaths: () => mapSchemaErrorToFieldPaths
25
+ });
26
+ module.exports = __toCommonJS(SchemaPathMapping_exports);
27
+
28
+ // src/internal/schema/SchemaPathMapping.ts
29
+ var isNumericSegment = (seg) => /^[0-9]+$/.test(seg);
30
+ var parseSegmentsFromString = (path) => {
31
+ if (!path) return [];
32
+ return path.split(".").filter(Boolean).map((seg) => isNumericSegment(seg) ? Number(seg) : seg);
33
+ };
34
+ var asSegments = (value) => {
35
+ if (typeof value === "string") return parseSegmentsFromString(value);
36
+ if (Array.isArray(value)) {
37
+ const parts = [];
38
+ for (const x of value) {
39
+ if (typeof x === "number" && Number.isFinite(x)) {
40
+ parts.push(Math.floor(x));
41
+ continue;
42
+ }
43
+ if (typeof x === "string" && x.length > 0) {
44
+ parts.push(isNumericSegment(x) ? Number(x) : x);
45
+ }
46
+ }
47
+ return parts.length ? parts : void 0;
48
+ }
49
+ return void 0;
50
+ };
51
+ var toConcretePath = (segments) => segments.map(String).join(".");
52
+ var toPatternPath = (segments) => {
53
+ const out = [];
54
+ const indices = [];
55
+ for (const seg of segments) {
56
+ if (typeof seg === "number") {
57
+ out.push("[]");
58
+ indices.push(seg);
59
+ } else {
60
+ out.push(seg);
61
+ }
62
+ }
63
+ const pattern = out.join(".").replace(/\.\[\]/g, "[]");
64
+ return { pattern, indices };
65
+ };
66
+ var applyIndicesToPattern = (pattern, indices) => {
67
+ if (!pattern) return pattern;
68
+ const raw = pattern.split(".").filter(Boolean);
69
+ const out = [];
70
+ let cursor = 0;
71
+ for (const part of raw) {
72
+ if (part === "[]") {
73
+ const idx = indices[cursor++];
74
+ if (idx === void 0) return void 0;
75
+ out.push(String(idx));
76
+ continue;
77
+ }
78
+ if (part.endsWith("[]") && part.length > 2) {
79
+ const base = part.slice(0, -2);
80
+ out.push(base);
81
+ const idx = indices[cursor++];
82
+ if (idx === void 0) return void 0;
83
+ out.push(String(idx));
84
+ continue;
85
+ }
86
+ out.push(part);
87
+ }
88
+ return out.join(".");
89
+ };
90
+ var concatPaths = (prefix, rest) => {
91
+ if (!prefix) return rest;
92
+ if (!rest) return prefix;
93
+ return `${prefix}.${rest}`;
94
+ };
95
+ var mapByRename = (segments, rename) => {
96
+ const concrete = toConcretePath(segments);
97
+ const direct = rename[concrete];
98
+ if (direct !== void 0) {
99
+ return direct;
100
+ }
101
+ const { pattern, indices } = toPatternPath(segments);
102
+ const patternDirect = rename[pattern];
103
+ if (patternDirect !== void 0) {
104
+ return applyIndicesToPattern(patternDirect, indices);
105
+ }
106
+ const keys = Object.keys(rename).sort((a, b) => b.length - a.length);
107
+ for (const from of keys) {
108
+ const to = rename[from];
109
+ const isPattern = from.includes("[]");
110
+ const target = isPattern ? pattern : concrete;
111
+ if (target === from || target.startsWith(`${from}.`)) {
112
+ const rawRest = target.slice(from.length);
113
+ const rest = rawRest.startsWith(".") ? rawRest.slice(1) : rawRest;
114
+ const mapped = concatPaths(to, rest);
115
+ return isPattern ? applyIndicesToPattern(mapped, indices) : mapped;
116
+ }
117
+ }
118
+ const segMap = {};
119
+ for (const [from, to] of Object.entries(rename)) {
120
+ if (from.includes(".") || from.includes("[]")) continue;
121
+ if (to.includes(".") || to.includes("[]")) continue;
122
+ if (!to) continue;
123
+ segMap[from] = to;
124
+ }
125
+ if (Object.keys(segMap).length === 0) return void 0;
126
+ const mappedSegments = segments.map((seg) => typeof seg === "string" ? segMap[seg] ?? seg : seg);
127
+ return toConcretePath(mappedSegments);
128
+ };
129
+ var extractRawPaths = (schemaError) => {
130
+ const out = [];
131
+ if (schemaError && typeof schemaError === "object") {
132
+ const anyErr = schemaError;
133
+ if (Array.isArray(anyErr.errors)) {
134
+ for (const e of anyErr.errors) {
135
+ if (e && typeof e === "object" && "path" in e) {
136
+ out.push(e.path);
137
+ }
138
+ }
139
+ }
140
+ if (Array.isArray(anyErr.issues)) {
141
+ for (const e of anyErr.issues) {
142
+ if (e && typeof e === "object" && "path" in e) {
143
+ out.push(e.path);
144
+ }
145
+ }
146
+ }
147
+ if ("path" in anyErr) {
148
+ out.push(anyErr.path);
149
+ }
150
+ }
151
+ return out;
152
+ };
153
+ var mapSchemaErrorToFieldPaths = (schemaError, options) => {
154
+ const fromEscapeHatch = options?.errorMap?.(schemaError);
155
+ if (fromEscapeHatch && fromEscapeHatch.length) {
156
+ return Array.from(new Set(fromEscapeHatch.filter((p) => typeof p === "string" && p.length > 0)));
157
+ }
158
+ const rename = options?.rename;
159
+ const results = [];
160
+ for (const rawPath of extractRawPaths(schemaError)) {
161
+ const segments = asSegments(rawPath);
162
+ if (!segments || segments.length === 0) continue;
163
+ const mapped = rename ? mapByRename(segments, rename) : void 0;
164
+ const path = mapped ?? toConcretePath(segments);
165
+ if (path) results.push(path);
166
+ }
167
+ return Array.from(new Set(results));
168
+ };
169
+
170
+ // src/SchemaPathMapping.ts
171
+ var SchemaPathMapping = {
172
+ mapSchemaErrorToFieldPaths
173
+ };
174
+ // Annotate the CommonJS export names for ESM import in node:
175
+ 0 && (module.exports = {
176
+ SchemaPathMapping,
177
+ mapSchemaErrorToFieldPaths
178
+ });
179
+ //# sourceMappingURL=SchemaPathMapping.cjs.map