lkd-web-kit 0.4.3 → 0.4.6

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 (140) hide show
  1. package/dist/form/FormButtonSubmit.cjs +6 -2
  2. package/dist/form/FormButtonSubmit.js +6 -2
  3. package/dist/hooks/useZodConfig.cjs +21 -0
  4. package/dist/hooks/useZodConfig.js +17 -0
  5. package/dist/index.cjs +2 -0
  6. package/dist/index.d.ts +5 -4
  7. package/dist/index.js +1 -0
  8. package/dist/node_modules/@tanstack/virtual-core/dist/esm/index.cjs +38 -33
  9. package/dist/node_modules/@tanstack/virtual-core/dist/esm/index.js +38 -33
  10. package/dist/node_modules/@tanstack/virtual-core/dist/esm/utils.cjs +1 -1
  11. package/dist/node_modules/@tanstack/virtual-core/dist/esm/utils.js +1 -1
  12. package/dist/node_modules/zod/v4/classic/coerce.cjs +28 -0
  13. package/dist/node_modules/zod/v4/classic/coerce.js +20 -0
  14. package/dist/node_modules/zod/v4/classic/compat.cjs +37 -0
  15. package/dist/node_modules/zod/v4/classic/compat.js +30 -0
  16. package/dist/node_modules/zod/v4/classic/errors.cjs +49 -0
  17. package/dist/node_modules/zod/v4/classic/errors.js +44 -0
  18. package/dist/node_modules/zod/v4/classic/external.cjs +231 -0
  19. package/dist/node_modules/zod/v4/classic/external.js +28 -0
  20. package/dist/node_modules/zod/v4/classic/index.cjs +10 -0
  21. package/dist/node_modules/zod/v4/classic/index.js +5 -0
  22. package/dist/node_modules/zod/v4/classic/iso.cjs +46 -0
  23. package/dist/node_modules/zod/v4/classic/iso.js +35 -0
  24. package/dist/node_modules/zod/v4/classic/parse.cjs +16 -0
  25. package/dist/node_modules/zod/v4/classic/parse.js +9 -0
  26. package/dist/node_modules/zod/v4/classic/schemas.cjs +1155 -0
  27. package/dist/node_modules/zod/v4/classic/schemas.js +1006 -0
  28. package/dist/node_modules/zod/v4/core/api.cjs +1016 -0
  29. package/dist/node_modules/zod/v4/core/api.js +903 -0
  30. package/dist/node_modules/zod/v4/core/checks.cjs +587 -0
  31. package/dist/node_modules/zod/v4/core/checks.js +562 -0
  32. package/dist/node_modules/zod/v4/core/core.cjs +72 -0
  33. package/dist/node_modules/zod/v4/core/core.js +63 -0
  34. package/dist/node_modules/zod/v4/core/doc.cjs +41 -0
  35. package/dist/node_modules/zod/v4/core/doc.js +37 -0
  36. package/dist/node_modules/zod/v4/core/errors.cjs +204 -0
  37. package/dist/node_modules/zod/v4/core/errors.js +194 -0
  38. package/dist/node_modules/zod/v4/core/function.cjs +81 -0
  39. package/dist/node_modules/zod/v4/core/function.js +76 -0
  40. package/dist/node_modules/zod/v4/core/index.cjs +261 -0
  41. package/dist/node_modules/zod/v4/core/index.js +20 -0
  42. package/dist/node_modules/zod/v4/core/json-schema.cjs +2 -0
  43. package/dist/node_modules/zod/v4/core/json-schema.js +1 -0
  44. package/dist/node_modules/zod/v4/core/parse.cjs +71 -0
  45. package/dist/node_modules/zod/v4/core/parse.js +60 -0
  46. package/dist/node_modules/zod/v4/core/regexes.cjs +139 -0
  47. package/dist/node_modules/zod/v4/core/regexes.js +95 -0
  48. package/dist/node_modules/zod/v4/core/registries.cjs +52 -0
  49. package/dist/node_modules/zod/v4/core/registries.js +44 -0
  50. package/dist/node_modules/zod/v4/core/schemas.cjs +1793 -0
  51. package/dist/node_modules/zod/v4/core/schemas.js +1720 -0
  52. package/dist/node_modules/zod/v4/core/to-json-schema.cjs +823 -0
  53. package/dist/node_modules/zod/v4/core/to-json-schema.js +818 -0
  54. package/dist/node_modules/zod/v4/core/util.cjs +543 -0
  55. package/dist/node_modules/zod/v4/core/util.js +491 -0
  56. package/dist/node_modules/zod/v4/core/versions.cjs +11 -0
  57. package/dist/node_modules/zod/v4/core/versions.js +7 -0
  58. package/dist/node_modules/zod/v4/index.cjs +10 -0
  59. package/dist/node_modules/zod/v4/index.js +5 -0
  60. package/dist/node_modules/zod/v4/locales/ar.cjs +121 -0
  61. package/dist/node_modules/zod/v4/locales/ar.js +119 -0
  62. package/dist/node_modules/zod/v4/locales/az.cjs +120 -0
  63. package/dist/node_modules/zod/v4/locales/az.js +118 -0
  64. package/dist/node_modules/zod/v4/locales/be.cjs +169 -0
  65. package/dist/node_modules/zod/v4/locales/be.js +167 -0
  66. package/dist/node_modules/zod/v4/locales/ca.cjs +123 -0
  67. package/dist/node_modules/zod/v4/locales/ca.js +121 -0
  68. package/dist/node_modules/zod/v4/locales/cs.cjs +140 -0
  69. package/dist/node_modules/zod/v4/locales/cs.js +138 -0
  70. package/dist/node_modules/zod/v4/locales/de.cjs +121 -0
  71. package/dist/node_modules/zod/v4/locales/de.js +119 -0
  72. package/dist/node_modules/zod/v4/locales/en.cjs +125 -0
  73. package/dist/node_modules/zod/v4/locales/en.js +120 -0
  74. package/dist/node_modules/zod/v4/locales/eo.cjs +124 -0
  75. package/dist/node_modules/zod/v4/locales/eo.js +119 -0
  76. package/dist/node_modules/zod/v4/locales/es.cjs +122 -0
  77. package/dist/node_modules/zod/v4/locales/es.js +120 -0
  78. package/dist/node_modules/zod/v4/locales/fa.cjs +127 -0
  79. package/dist/node_modules/zod/v4/locales/fa.js +125 -0
  80. package/dist/node_modules/zod/v4/locales/fi.cjs +127 -0
  81. package/dist/node_modules/zod/v4/locales/fi.js +125 -0
  82. package/dist/node_modules/zod/v4/locales/fr-CA.cjs +122 -0
  83. package/dist/node_modules/zod/v4/locales/fr-CA.js +120 -0
  84. package/dist/node_modules/zod/v4/locales/fr.cjs +121 -0
  85. package/dist/node_modules/zod/v4/locales/fr.js +119 -0
  86. package/dist/node_modules/zod/v4/locales/he.cjs +122 -0
  87. package/dist/node_modules/zod/v4/locales/he.js +120 -0
  88. package/dist/node_modules/zod/v4/locales/hu.cjs +122 -0
  89. package/dist/node_modules/zod/v4/locales/hu.js +120 -0
  90. package/dist/node_modules/zod/v4/locales/id.cjs +121 -0
  91. package/dist/node_modules/zod/v4/locales/id.js +119 -0
  92. package/dist/node_modules/zod/v4/locales/index.cjs +85 -0
  93. package/dist/node_modules/zod/v4/locales/index.js +39 -0
  94. package/dist/node_modules/zod/v4/locales/it.cjs +122 -0
  95. package/dist/node_modules/zod/v4/locales/it.js +120 -0
  96. package/dist/node_modules/zod/v4/locales/ja.cjs +120 -0
  97. package/dist/node_modules/zod/v4/locales/ja.js +118 -0
  98. package/dist/node_modules/zod/v4/locales/kh.cjs +122 -0
  99. package/dist/node_modules/zod/v4/locales/kh.js +120 -0
  100. package/dist/node_modules/zod/v4/locales/ko.cjs +126 -0
  101. package/dist/node_modules/zod/v4/locales/ko.js +124 -0
  102. package/dist/node_modules/zod/v4/locales/mk.cjs +123 -0
  103. package/dist/node_modules/zod/v4/locales/mk.js +121 -0
  104. package/dist/node_modules/zod/v4/locales/ms.cjs +121 -0
  105. package/dist/node_modules/zod/v4/locales/ms.js +119 -0
  106. package/dist/node_modules/zod/v4/locales/nl.cjs +122 -0
  107. package/dist/node_modules/zod/v4/locales/nl.js +120 -0
  108. package/dist/node_modules/zod/v4/locales/no.cjs +121 -0
  109. package/dist/node_modules/zod/v4/locales/no.js +119 -0
  110. package/dist/node_modules/zod/v4/locales/ota.cjs +122 -0
  111. package/dist/node_modules/zod/v4/locales/ota.js +120 -0
  112. package/dist/node_modules/zod/v4/locales/pl.cjs +122 -0
  113. package/dist/node_modules/zod/v4/locales/pl.js +120 -0
  114. package/dist/node_modules/zod/v4/locales/ps.cjs +127 -0
  115. package/dist/node_modules/zod/v4/locales/ps.js +125 -0
  116. package/dist/node_modules/zod/v4/locales/pt.cjs +121 -0
  117. package/dist/node_modules/zod/v4/locales/pt.js +119 -0
  118. package/dist/node_modules/zod/v4/locales/ru.cjs +169 -0
  119. package/dist/node_modules/zod/v4/locales/ru.js +167 -0
  120. package/dist/node_modules/zod/v4/locales/sl.cjs +122 -0
  121. package/dist/node_modules/zod/v4/locales/sl.js +120 -0
  122. package/dist/node_modules/zod/v4/locales/sv.cjs +123 -0
  123. package/dist/node_modules/zod/v4/locales/sv.js +121 -0
  124. package/dist/node_modules/zod/v4/locales/ta.cjs +122 -0
  125. package/dist/node_modules/zod/v4/locales/ta.js +120 -0
  126. package/dist/node_modules/zod/v4/locales/th.cjs +122 -0
  127. package/dist/node_modules/zod/v4/locales/th.js +120 -0
  128. package/dist/node_modules/zod/v4/locales/tr.cjs +123 -0
  129. package/dist/node_modules/zod/v4/locales/tr.js +118 -0
  130. package/dist/node_modules/zod/v4/locales/ua.cjs +122 -0
  131. package/dist/node_modules/zod/v4/locales/ua.js +120 -0
  132. package/dist/node_modules/zod/v4/locales/ur.cjs +122 -0
  133. package/dist/node_modules/zod/v4/locales/ur.js +120 -0
  134. package/dist/node_modules/zod/v4/locales/vi.cjs +121 -0
  135. package/dist/node_modules/zod/v4/locales/vi.js +119 -0
  136. package/dist/node_modules/zod/v4/locales/zh-CN.cjs +121 -0
  137. package/dist/node_modules/zod/v4/locales/zh-CN.js +119 -0
  138. package/dist/node_modules/zod/v4/locales/zh-TW.cjs +122 -0
  139. package/dist/node_modules/zod/v4/locales/zh-TW.js +120 -0
  140. package/package.json +1 -1
@@ -0,0 +1,41 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+
5
+ class Doc {
6
+ constructor(args = []) {
7
+ this.content = [];
8
+ this.indent = 0;
9
+ if (this)
10
+ this.args = args;
11
+ }
12
+ indented(fn) {
13
+ this.indent += 1;
14
+ fn(this);
15
+ this.indent -= 1;
16
+ }
17
+ write(arg) {
18
+ if (typeof arg === "function") {
19
+ arg(this, { execution: "sync" });
20
+ arg(this, { execution: "async" });
21
+ return;
22
+ }
23
+ const content = arg;
24
+ const lines = content.split("\n").filter((x) => x);
25
+ const minIndent = Math.min(...lines.map((x) => x.length - x.trimStart().length));
26
+ const dedented = lines.map((x) => x.slice(minIndent)).map((x) => " ".repeat(this.indent * 2) + x);
27
+ for (const line of dedented) {
28
+ this.content.push(line);
29
+ }
30
+ }
31
+ compile() {
32
+ const F = Function;
33
+ const args = this?.args;
34
+ const content = this?.content ?? [``];
35
+ const lines = [...content.map((x) => ` ${x}`)];
36
+ // console.log(lines.join("\n"));
37
+ return new F(...args, lines.join("\n"));
38
+ }
39
+ }
40
+
41
+ exports.Doc = Doc;
@@ -0,0 +1,37 @@
1
+ class Doc {
2
+ constructor(args = []) {
3
+ this.content = [];
4
+ this.indent = 0;
5
+ if (this)
6
+ this.args = args;
7
+ }
8
+ indented(fn) {
9
+ this.indent += 1;
10
+ fn(this);
11
+ this.indent -= 1;
12
+ }
13
+ write(arg) {
14
+ if (typeof arg === "function") {
15
+ arg(this, { execution: "sync" });
16
+ arg(this, { execution: "async" });
17
+ return;
18
+ }
19
+ const content = arg;
20
+ const lines = content.split("\n").filter((x) => x);
21
+ const minIndent = Math.min(...lines.map((x) => x.length - x.trimStart().length));
22
+ const dedented = lines.map((x) => x.slice(minIndent)).map((x) => " ".repeat(this.indent * 2) + x);
23
+ for (const line of dedented) {
24
+ this.content.push(line);
25
+ }
26
+ }
27
+ compile() {
28
+ const F = Function;
29
+ const args = this?.args;
30
+ const content = this?.content ?? [``];
31
+ const lines = [...content.map((x) => ` ${x}`)];
32
+ // console.log(lines.join("\n"));
33
+ return new F(...args, lines.join("\n"));
34
+ }
35
+ }
36
+
37
+ export { Doc };
@@ -0,0 +1,204 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+
5
+ const core = require('./core.cjs');
6
+ const util = require('./util.cjs');
7
+
8
+ const initializer = (inst, def) => {
9
+ inst.name = "$ZodError";
10
+ Object.defineProperty(inst, "_zod", {
11
+ value: inst._zod,
12
+ enumerable: false,
13
+ });
14
+ Object.defineProperty(inst, "issues", {
15
+ value: def,
16
+ enumerable: false,
17
+ });
18
+ Object.defineProperty(inst, "message", {
19
+ get() {
20
+ return JSON.stringify(def, util.jsonStringifyReplacer, 2);
21
+ },
22
+ enumerable: true,
23
+ // configurable: false,
24
+ });
25
+ };
26
+ const $ZodError = core.$constructor("$ZodError", initializer);
27
+ const $ZodRealError = core.$constructor("$ZodError", initializer, { Parent: Error });
28
+ function flattenError(error, mapper = (issue) => issue.message) {
29
+ const fieldErrors = {};
30
+ const formErrors = [];
31
+ for (const sub of error.issues) {
32
+ if (sub.path.length > 0) {
33
+ fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
34
+ fieldErrors[sub.path[0]].push(mapper(sub));
35
+ }
36
+ else {
37
+ formErrors.push(mapper(sub));
38
+ }
39
+ }
40
+ return { formErrors, fieldErrors };
41
+ }
42
+ function formatError(error, _mapper) {
43
+ const mapper = _mapper ||
44
+ function (issue) {
45
+ return issue.message;
46
+ };
47
+ const fieldErrors = { _errors: [] };
48
+ const processError = (error) => {
49
+ for (const issue of error.issues) {
50
+ if (issue.code === "invalid_union" && issue.errors.length) {
51
+ issue.errors.map((issues) => processError({ issues }));
52
+ }
53
+ else if (issue.code === "invalid_key") {
54
+ processError({ issues: issue.issues });
55
+ }
56
+ else if (issue.code === "invalid_element") {
57
+ processError({ issues: issue.issues });
58
+ }
59
+ else if (issue.path.length === 0) {
60
+ fieldErrors._errors.push(mapper(issue));
61
+ }
62
+ else {
63
+ let curr = fieldErrors;
64
+ let i = 0;
65
+ while (i < issue.path.length) {
66
+ const el = issue.path[i];
67
+ const terminal = i === issue.path.length - 1;
68
+ if (!terminal) {
69
+ curr[el] = curr[el] || { _errors: [] };
70
+ }
71
+ else {
72
+ curr[el] = curr[el] || { _errors: [] };
73
+ curr[el]._errors.push(mapper(issue));
74
+ }
75
+ curr = curr[el];
76
+ i++;
77
+ }
78
+ }
79
+ }
80
+ };
81
+ processError(error);
82
+ return fieldErrors;
83
+ }
84
+ function treeifyError(error, _mapper) {
85
+ const mapper = _mapper ||
86
+ function (issue) {
87
+ return issue.message;
88
+ };
89
+ const result = { errors: [] };
90
+ const processError = (error, path = []) => {
91
+ var _a, _b;
92
+ for (const issue of error.issues) {
93
+ if (issue.code === "invalid_union" && issue.errors.length) {
94
+ // regular union error
95
+ issue.errors.map((issues) => processError({ issues }, issue.path));
96
+ }
97
+ else if (issue.code === "invalid_key") {
98
+ processError({ issues: issue.issues }, issue.path);
99
+ }
100
+ else if (issue.code === "invalid_element") {
101
+ processError({ issues: issue.issues }, issue.path);
102
+ }
103
+ else {
104
+ const fullpath = [...path, ...issue.path];
105
+ if (fullpath.length === 0) {
106
+ result.errors.push(mapper(issue));
107
+ continue;
108
+ }
109
+ let curr = result;
110
+ let i = 0;
111
+ while (i < fullpath.length) {
112
+ const el = fullpath[i];
113
+ const terminal = i === fullpath.length - 1;
114
+ if (typeof el === "string") {
115
+ curr.properties ?? (curr.properties = {});
116
+ (_a = curr.properties)[el] ?? (_a[el] = { errors: [] });
117
+ curr = curr.properties[el];
118
+ }
119
+ else {
120
+ curr.items ?? (curr.items = []);
121
+ (_b = curr.items)[el] ?? (_b[el] = { errors: [] });
122
+ curr = curr.items[el];
123
+ }
124
+ if (terminal) {
125
+ curr.errors.push(mapper(issue));
126
+ }
127
+ i++;
128
+ }
129
+ }
130
+ }
131
+ };
132
+ processError(error);
133
+ return result;
134
+ }
135
+ /** Format a ZodError as a human-readable string in the following form.
136
+ *
137
+ * From
138
+ *
139
+ * ```ts
140
+ * ZodError {
141
+ * issues: [
142
+ * {
143
+ * expected: 'string',
144
+ * code: 'invalid_type',
145
+ * path: [ 'username' ],
146
+ * message: 'Invalid input: expected string'
147
+ * },
148
+ * {
149
+ * expected: 'number',
150
+ * code: 'invalid_type',
151
+ * path: [ 'favoriteNumbers', 1 ],
152
+ * message: 'Invalid input: expected number'
153
+ * }
154
+ * ];
155
+ * }
156
+ * ```
157
+ *
158
+ * to
159
+ *
160
+ * ```
161
+ * username
162
+ * ✖ Expected number, received string at "username
163
+ * favoriteNumbers[0]
164
+ * ✖ Invalid input: expected number
165
+ * ```
166
+ */
167
+ function toDotPath(path) {
168
+ const segs = [];
169
+ for (const seg of path) {
170
+ if (typeof seg === "number")
171
+ segs.push(`[${seg}]`);
172
+ else if (typeof seg === "symbol")
173
+ segs.push(`[${JSON.stringify(String(seg))}]`);
174
+ else if (/[^\w$]/.test(seg))
175
+ segs.push(`[${JSON.stringify(seg)}]`);
176
+ else {
177
+ if (segs.length)
178
+ segs.push(".");
179
+ segs.push(seg);
180
+ }
181
+ }
182
+ return segs.join("");
183
+ }
184
+ function prettifyError(error) {
185
+ const lines = [];
186
+ // sort by path length
187
+ const issues = [...error.issues].sort((a, b) => a.path.length - b.path.length);
188
+ // Process each issue
189
+ for (const issue of issues) {
190
+ lines.push(`✖ ${issue.message}`);
191
+ if (issue.path?.length)
192
+ lines.push(` → at ${toDotPath(issue.path)}`);
193
+ }
194
+ // Convert Map to formatted string
195
+ return lines.join("\n");
196
+ }
197
+
198
+ exports.$ZodError = $ZodError;
199
+ exports.$ZodRealError = $ZodRealError;
200
+ exports.flattenError = flattenError;
201
+ exports.formatError = formatError;
202
+ exports.prettifyError = prettifyError;
203
+ exports.toDotPath = toDotPath;
204
+ exports.treeifyError = treeifyError;
@@ -0,0 +1,194 @@
1
+ import { $constructor } from './core.js';
2
+ import { jsonStringifyReplacer } from './util.js';
3
+
4
+ const initializer = (inst, def) => {
5
+ inst.name = "$ZodError";
6
+ Object.defineProperty(inst, "_zod", {
7
+ value: inst._zod,
8
+ enumerable: false,
9
+ });
10
+ Object.defineProperty(inst, "issues", {
11
+ value: def,
12
+ enumerable: false,
13
+ });
14
+ Object.defineProperty(inst, "message", {
15
+ get() {
16
+ return JSON.stringify(def, jsonStringifyReplacer, 2);
17
+ },
18
+ enumerable: true,
19
+ // configurable: false,
20
+ });
21
+ };
22
+ const $ZodError = $constructor("$ZodError", initializer);
23
+ const $ZodRealError = $constructor("$ZodError", initializer, { Parent: Error });
24
+ function flattenError(error, mapper = (issue) => issue.message) {
25
+ const fieldErrors = {};
26
+ const formErrors = [];
27
+ for (const sub of error.issues) {
28
+ if (sub.path.length > 0) {
29
+ fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
30
+ fieldErrors[sub.path[0]].push(mapper(sub));
31
+ }
32
+ else {
33
+ formErrors.push(mapper(sub));
34
+ }
35
+ }
36
+ return { formErrors, fieldErrors };
37
+ }
38
+ function formatError(error, _mapper) {
39
+ const mapper = _mapper ||
40
+ function (issue) {
41
+ return issue.message;
42
+ };
43
+ const fieldErrors = { _errors: [] };
44
+ const processError = (error) => {
45
+ for (const issue of error.issues) {
46
+ if (issue.code === "invalid_union" && issue.errors.length) {
47
+ issue.errors.map((issues) => processError({ issues }));
48
+ }
49
+ else if (issue.code === "invalid_key") {
50
+ processError({ issues: issue.issues });
51
+ }
52
+ else if (issue.code === "invalid_element") {
53
+ processError({ issues: issue.issues });
54
+ }
55
+ else if (issue.path.length === 0) {
56
+ fieldErrors._errors.push(mapper(issue));
57
+ }
58
+ else {
59
+ let curr = fieldErrors;
60
+ let i = 0;
61
+ while (i < issue.path.length) {
62
+ const el = issue.path[i];
63
+ const terminal = i === issue.path.length - 1;
64
+ if (!terminal) {
65
+ curr[el] = curr[el] || { _errors: [] };
66
+ }
67
+ else {
68
+ curr[el] = curr[el] || { _errors: [] };
69
+ curr[el]._errors.push(mapper(issue));
70
+ }
71
+ curr = curr[el];
72
+ i++;
73
+ }
74
+ }
75
+ }
76
+ };
77
+ processError(error);
78
+ return fieldErrors;
79
+ }
80
+ function treeifyError(error, _mapper) {
81
+ const mapper = _mapper ||
82
+ function (issue) {
83
+ return issue.message;
84
+ };
85
+ const result = { errors: [] };
86
+ const processError = (error, path = []) => {
87
+ var _a, _b;
88
+ for (const issue of error.issues) {
89
+ if (issue.code === "invalid_union" && issue.errors.length) {
90
+ // regular union error
91
+ issue.errors.map((issues) => processError({ issues }, issue.path));
92
+ }
93
+ else if (issue.code === "invalid_key") {
94
+ processError({ issues: issue.issues }, issue.path);
95
+ }
96
+ else if (issue.code === "invalid_element") {
97
+ processError({ issues: issue.issues }, issue.path);
98
+ }
99
+ else {
100
+ const fullpath = [...path, ...issue.path];
101
+ if (fullpath.length === 0) {
102
+ result.errors.push(mapper(issue));
103
+ continue;
104
+ }
105
+ let curr = result;
106
+ let i = 0;
107
+ while (i < fullpath.length) {
108
+ const el = fullpath[i];
109
+ const terminal = i === fullpath.length - 1;
110
+ if (typeof el === "string") {
111
+ curr.properties ?? (curr.properties = {});
112
+ (_a = curr.properties)[el] ?? (_a[el] = { errors: [] });
113
+ curr = curr.properties[el];
114
+ }
115
+ else {
116
+ curr.items ?? (curr.items = []);
117
+ (_b = curr.items)[el] ?? (_b[el] = { errors: [] });
118
+ curr = curr.items[el];
119
+ }
120
+ if (terminal) {
121
+ curr.errors.push(mapper(issue));
122
+ }
123
+ i++;
124
+ }
125
+ }
126
+ }
127
+ };
128
+ processError(error);
129
+ return result;
130
+ }
131
+ /** Format a ZodError as a human-readable string in the following form.
132
+ *
133
+ * From
134
+ *
135
+ * ```ts
136
+ * ZodError {
137
+ * issues: [
138
+ * {
139
+ * expected: 'string',
140
+ * code: 'invalid_type',
141
+ * path: [ 'username' ],
142
+ * message: 'Invalid input: expected string'
143
+ * },
144
+ * {
145
+ * expected: 'number',
146
+ * code: 'invalid_type',
147
+ * path: [ 'favoriteNumbers', 1 ],
148
+ * message: 'Invalid input: expected number'
149
+ * }
150
+ * ];
151
+ * }
152
+ * ```
153
+ *
154
+ * to
155
+ *
156
+ * ```
157
+ * username
158
+ * ✖ Expected number, received string at "username
159
+ * favoriteNumbers[0]
160
+ * ✖ Invalid input: expected number
161
+ * ```
162
+ */
163
+ function toDotPath(path) {
164
+ const segs = [];
165
+ for (const seg of path) {
166
+ if (typeof seg === "number")
167
+ segs.push(`[${seg}]`);
168
+ else if (typeof seg === "symbol")
169
+ segs.push(`[${JSON.stringify(String(seg))}]`);
170
+ else if (/[^\w$]/.test(seg))
171
+ segs.push(`[${JSON.stringify(seg)}]`);
172
+ else {
173
+ if (segs.length)
174
+ segs.push(".");
175
+ segs.push(seg);
176
+ }
177
+ }
178
+ return segs.join("");
179
+ }
180
+ function prettifyError(error) {
181
+ const lines = [];
182
+ // sort by path length
183
+ const issues = [...error.issues].sort((a, b) => a.path.length - b.path.length);
184
+ // Process each issue
185
+ for (const issue of issues) {
186
+ lines.push(`✖ ${issue.message}`);
187
+ if (issue.path?.length)
188
+ lines.push(` → at ${toDotPath(issue.path)}`);
189
+ }
190
+ // Convert Map to formatted string
191
+ return lines.join("\n");
192
+ }
193
+
194
+ export { $ZodError, $ZodRealError, flattenError, formatError, prettifyError, toDotPath, treeifyError };
@@ -0,0 +1,81 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+
5
+ const api = require('./api.cjs');
6
+ const parse = require('./parse.cjs');
7
+ const schemas = require('./schemas.cjs');
8
+
9
+ class $ZodFunction {
10
+ constructor(def) {
11
+ this._def = def;
12
+ this.def = def;
13
+ }
14
+ implement(func) {
15
+ if (typeof func !== "function") {
16
+ throw new Error("implement() must be called with a function");
17
+ }
18
+ const impl = ((...args) => {
19
+ const parsedArgs = this._def.input ? parse.parse(this._def.input, args, undefined, { callee: impl }) : args;
20
+ if (!Array.isArray(parsedArgs)) {
21
+ throw new Error("Invalid arguments schema: not an array or tuple schema.");
22
+ }
23
+ const output = func(...parsedArgs);
24
+ return this._def.output ? parse.parse(this._def.output, output, undefined, { callee: impl }) : output;
25
+ });
26
+ return impl;
27
+ }
28
+ implementAsync(func) {
29
+ if (typeof func !== "function") {
30
+ throw new Error("implement() must be called with a function");
31
+ }
32
+ const impl = (async (...args) => {
33
+ const parsedArgs = this._def.input ? await parse.parseAsync(this._def.input, args, undefined, { callee: impl }) : args;
34
+ if (!Array.isArray(parsedArgs)) {
35
+ throw new Error("Invalid arguments schema: not an array or tuple schema.");
36
+ }
37
+ const output = await func(...parsedArgs);
38
+ return this._def.output ? parse.parseAsync(this._def.output, output, undefined, { callee: impl }) : output;
39
+ });
40
+ return impl;
41
+ }
42
+ input(...args) {
43
+ const F = this.constructor;
44
+ if (Array.isArray(args[0])) {
45
+ return new F({
46
+ type: "function",
47
+ input: new schemas.$ZodTuple({
48
+ type: "tuple",
49
+ items: args[0],
50
+ rest: args[1],
51
+ }),
52
+ output: this._def.output,
53
+ });
54
+ }
55
+ return new F({
56
+ type: "function",
57
+ input: args[0],
58
+ output: this._def.output,
59
+ });
60
+ }
61
+ output(output) {
62
+ const F = this.constructor;
63
+ return new F({
64
+ type: "function",
65
+ input: this._def.input,
66
+ output,
67
+ });
68
+ }
69
+ }
70
+ function _function(params) {
71
+ return new $ZodFunction({
72
+ type: "function",
73
+ input: Array.isArray(params?.input)
74
+ ? api._tuple(schemas.$ZodTuple, params?.input)
75
+ : (params?.input ?? api._array(schemas.$ZodArray, api._unknown(schemas.$ZodUnknown))),
76
+ output: params?.output ?? api._unknown(schemas.$ZodUnknown),
77
+ });
78
+ }
79
+
80
+ exports.$ZodFunction = $ZodFunction;
81
+ exports.function = _function;
@@ -0,0 +1,76 @@
1
+ import { _unknown, _tuple, _array } from './api.js';
2
+ import { parse, parseAsync } from './parse.js';
3
+ import { $ZodTuple, $ZodArray, $ZodUnknown } from './schemas.js';
4
+
5
+ class $ZodFunction {
6
+ constructor(def) {
7
+ this._def = def;
8
+ this.def = def;
9
+ }
10
+ implement(func) {
11
+ if (typeof func !== "function") {
12
+ throw new Error("implement() must be called with a function");
13
+ }
14
+ const impl = ((...args) => {
15
+ const parsedArgs = this._def.input ? parse(this._def.input, args, undefined, { callee: impl }) : args;
16
+ if (!Array.isArray(parsedArgs)) {
17
+ throw new Error("Invalid arguments schema: not an array or tuple schema.");
18
+ }
19
+ const output = func(...parsedArgs);
20
+ return this._def.output ? parse(this._def.output, output, undefined, { callee: impl }) : output;
21
+ });
22
+ return impl;
23
+ }
24
+ implementAsync(func) {
25
+ if (typeof func !== "function") {
26
+ throw new Error("implement() must be called with a function");
27
+ }
28
+ const impl = (async (...args) => {
29
+ const parsedArgs = this._def.input ? await parseAsync(this._def.input, args, undefined, { callee: impl }) : args;
30
+ if (!Array.isArray(parsedArgs)) {
31
+ throw new Error("Invalid arguments schema: not an array or tuple schema.");
32
+ }
33
+ const output = await func(...parsedArgs);
34
+ return this._def.output ? parseAsync(this._def.output, output, undefined, { callee: impl }) : output;
35
+ });
36
+ return impl;
37
+ }
38
+ input(...args) {
39
+ const F = this.constructor;
40
+ if (Array.isArray(args[0])) {
41
+ return new F({
42
+ type: "function",
43
+ input: new $ZodTuple({
44
+ type: "tuple",
45
+ items: args[0],
46
+ rest: args[1],
47
+ }),
48
+ output: this._def.output,
49
+ });
50
+ }
51
+ return new F({
52
+ type: "function",
53
+ input: args[0],
54
+ output: this._def.output,
55
+ });
56
+ }
57
+ output(output) {
58
+ const F = this.constructor;
59
+ return new F({
60
+ type: "function",
61
+ input: this._def.input,
62
+ output,
63
+ });
64
+ }
65
+ }
66
+ function _function(params) {
67
+ return new $ZodFunction({
68
+ type: "function",
69
+ input: Array.isArray(params?.input)
70
+ ? _tuple($ZodTuple, params?.input)
71
+ : (params?.input ?? _array($ZodArray, _unknown($ZodUnknown))),
72
+ output: params?.output ?? _unknown($ZodUnknown),
73
+ });
74
+ }
75
+
76
+ export { $ZodFunction, _function as function };