lkd-web-kit 0.4.7 → 0.4.9

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 (138) hide show
  1. package/dist/components/EmptyState/index.cjs +24 -12
  2. package/dist/components/EmptyState/index.js +24 -12
  3. package/dist/components/Icon.cjs +2 -3
  4. package/dist/components/Icon.js +2 -3
  5. package/dist/components/SelectInfinity/index.cjs +7 -4
  6. package/dist/components/SelectInfinity/index.js +7 -4
  7. package/dist/hooks/useZodConfig.cjs +2 -2
  8. package/dist/hooks/useZodConfig.js +2 -2
  9. package/dist/index.d.ts +4 -4
  10. package/package.json +7 -7
  11. package/dist/node_modules/zod/v4/classic/coerce.cjs +0 -28
  12. package/dist/node_modules/zod/v4/classic/coerce.js +0 -20
  13. package/dist/node_modules/zod/v4/classic/compat.cjs +0 -37
  14. package/dist/node_modules/zod/v4/classic/compat.js +0 -30
  15. package/dist/node_modules/zod/v4/classic/errors.cjs +0 -49
  16. package/dist/node_modules/zod/v4/classic/errors.js +0 -44
  17. package/dist/node_modules/zod/v4/classic/external.cjs +0 -231
  18. package/dist/node_modules/zod/v4/classic/external.js +0 -28
  19. package/dist/node_modules/zod/v4/classic/index.cjs +0 -10
  20. package/dist/node_modules/zod/v4/classic/index.js +0 -5
  21. package/dist/node_modules/zod/v4/classic/iso.cjs +0 -46
  22. package/dist/node_modules/zod/v4/classic/iso.js +0 -35
  23. package/dist/node_modules/zod/v4/classic/parse.cjs +0 -16
  24. package/dist/node_modules/zod/v4/classic/parse.js +0 -9
  25. package/dist/node_modules/zod/v4/classic/schemas.cjs +0 -1155
  26. package/dist/node_modules/zod/v4/classic/schemas.js +0 -1006
  27. package/dist/node_modules/zod/v4/core/api.cjs +0 -1016
  28. package/dist/node_modules/zod/v4/core/api.js +0 -903
  29. package/dist/node_modules/zod/v4/core/checks.cjs +0 -587
  30. package/dist/node_modules/zod/v4/core/checks.js +0 -562
  31. package/dist/node_modules/zod/v4/core/core.cjs +0 -72
  32. package/dist/node_modules/zod/v4/core/core.js +0 -63
  33. package/dist/node_modules/zod/v4/core/doc.cjs +0 -41
  34. package/dist/node_modules/zod/v4/core/doc.js +0 -37
  35. package/dist/node_modules/zod/v4/core/errors.cjs +0 -204
  36. package/dist/node_modules/zod/v4/core/errors.js +0 -194
  37. package/dist/node_modules/zod/v4/core/function.cjs +0 -81
  38. package/dist/node_modules/zod/v4/core/function.js +0 -76
  39. package/dist/node_modules/zod/v4/core/index.cjs +0 -261
  40. package/dist/node_modules/zod/v4/core/index.js +0 -20
  41. package/dist/node_modules/zod/v4/core/json-schema.cjs +0 -2
  42. package/dist/node_modules/zod/v4/core/json-schema.js +0 -1
  43. package/dist/node_modules/zod/v4/core/parse.cjs +0 -71
  44. package/dist/node_modules/zod/v4/core/parse.js +0 -60
  45. package/dist/node_modules/zod/v4/core/regexes.cjs +0 -139
  46. package/dist/node_modules/zod/v4/core/regexes.js +0 -95
  47. package/dist/node_modules/zod/v4/core/registries.cjs +0 -52
  48. package/dist/node_modules/zod/v4/core/registries.js +0 -44
  49. package/dist/node_modules/zod/v4/core/schemas.cjs +0 -1793
  50. package/dist/node_modules/zod/v4/core/schemas.js +0 -1720
  51. package/dist/node_modules/zod/v4/core/to-json-schema.cjs +0 -823
  52. package/dist/node_modules/zod/v4/core/to-json-schema.js +0 -818
  53. package/dist/node_modules/zod/v4/core/util.cjs +0 -543
  54. package/dist/node_modules/zod/v4/core/util.js +0 -491
  55. package/dist/node_modules/zod/v4/core/versions.cjs +0 -11
  56. package/dist/node_modules/zod/v4/core/versions.js +0 -7
  57. package/dist/node_modules/zod/v4/index.cjs +0 -10
  58. package/dist/node_modules/zod/v4/index.js +0 -5
  59. package/dist/node_modules/zod/v4/locales/ar.cjs +0 -121
  60. package/dist/node_modules/zod/v4/locales/ar.js +0 -119
  61. package/dist/node_modules/zod/v4/locales/az.cjs +0 -120
  62. package/dist/node_modules/zod/v4/locales/az.js +0 -118
  63. package/dist/node_modules/zod/v4/locales/be.cjs +0 -169
  64. package/dist/node_modules/zod/v4/locales/be.js +0 -167
  65. package/dist/node_modules/zod/v4/locales/ca.cjs +0 -123
  66. package/dist/node_modules/zod/v4/locales/ca.js +0 -121
  67. package/dist/node_modules/zod/v4/locales/cs.cjs +0 -140
  68. package/dist/node_modules/zod/v4/locales/cs.js +0 -138
  69. package/dist/node_modules/zod/v4/locales/de.cjs +0 -121
  70. package/dist/node_modules/zod/v4/locales/de.js +0 -119
  71. package/dist/node_modules/zod/v4/locales/en.cjs +0 -125
  72. package/dist/node_modules/zod/v4/locales/en.js +0 -120
  73. package/dist/node_modules/zod/v4/locales/eo.cjs +0 -124
  74. package/dist/node_modules/zod/v4/locales/eo.js +0 -119
  75. package/dist/node_modules/zod/v4/locales/es.cjs +0 -122
  76. package/dist/node_modules/zod/v4/locales/es.js +0 -120
  77. package/dist/node_modules/zod/v4/locales/fa.cjs +0 -127
  78. package/dist/node_modules/zod/v4/locales/fa.js +0 -125
  79. package/dist/node_modules/zod/v4/locales/fi.cjs +0 -127
  80. package/dist/node_modules/zod/v4/locales/fi.js +0 -125
  81. package/dist/node_modules/zod/v4/locales/fr-CA.cjs +0 -122
  82. package/dist/node_modules/zod/v4/locales/fr-CA.js +0 -120
  83. package/dist/node_modules/zod/v4/locales/fr.cjs +0 -121
  84. package/dist/node_modules/zod/v4/locales/fr.js +0 -119
  85. package/dist/node_modules/zod/v4/locales/he.cjs +0 -122
  86. package/dist/node_modules/zod/v4/locales/he.js +0 -120
  87. package/dist/node_modules/zod/v4/locales/hu.cjs +0 -122
  88. package/dist/node_modules/zod/v4/locales/hu.js +0 -120
  89. package/dist/node_modules/zod/v4/locales/id.cjs +0 -121
  90. package/dist/node_modules/zod/v4/locales/id.js +0 -119
  91. package/dist/node_modules/zod/v4/locales/index.cjs +0 -85
  92. package/dist/node_modules/zod/v4/locales/index.js +0 -39
  93. package/dist/node_modules/zod/v4/locales/it.cjs +0 -122
  94. package/dist/node_modules/zod/v4/locales/it.js +0 -120
  95. package/dist/node_modules/zod/v4/locales/ja.cjs +0 -120
  96. package/dist/node_modules/zod/v4/locales/ja.js +0 -118
  97. package/dist/node_modules/zod/v4/locales/kh.cjs +0 -122
  98. package/dist/node_modules/zod/v4/locales/kh.js +0 -120
  99. package/dist/node_modules/zod/v4/locales/ko.cjs +0 -126
  100. package/dist/node_modules/zod/v4/locales/ko.js +0 -124
  101. package/dist/node_modules/zod/v4/locales/mk.cjs +0 -123
  102. package/dist/node_modules/zod/v4/locales/mk.js +0 -121
  103. package/dist/node_modules/zod/v4/locales/ms.cjs +0 -121
  104. package/dist/node_modules/zod/v4/locales/ms.js +0 -119
  105. package/dist/node_modules/zod/v4/locales/nl.cjs +0 -122
  106. package/dist/node_modules/zod/v4/locales/nl.js +0 -120
  107. package/dist/node_modules/zod/v4/locales/no.cjs +0 -121
  108. package/dist/node_modules/zod/v4/locales/no.js +0 -119
  109. package/dist/node_modules/zod/v4/locales/ota.cjs +0 -122
  110. package/dist/node_modules/zod/v4/locales/ota.js +0 -120
  111. package/dist/node_modules/zod/v4/locales/pl.cjs +0 -122
  112. package/dist/node_modules/zod/v4/locales/pl.js +0 -120
  113. package/dist/node_modules/zod/v4/locales/ps.cjs +0 -127
  114. package/dist/node_modules/zod/v4/locales/ps.js +0 -125
  115. package/dist/node_modules/zod/v4/locales/pt.cjs +0 -121
  116. package/dist/node_modules/zod/v4/locales/pt.js +0 -119
  117. package/dist/node_modules/zod/v4/locales/ru.cjs +0 -169
  118. package/dist/node_modules/zod/v4/locales/ru.js +0 -167
  119. package/dist/node_modules/zod/v4/locales/sl.cjs +0 -122
  120. package/dist/node_modules/zod/v4/locales/sl.js +0 -120
  121. package/dist/node_modules/zod/v4/locales/sv.cjs +0 -123
  122. package/dist/node_modules/zod/v4/locales/sv.js +0 -121
  123. package/dist/node_modules/zod/v4/locales/ta.cjs +0 -122
  124. package/dist/node_modules/zod/v4/locales/ta.js +0 -120
  125. package/dist/node_modules/zod/v4/locales/th.cjs +0 -122
  126. package/dist/node_modules/zod/v4/locales/th.js +0 -120
  127. package/dist/node_modules/zod/v4/locales/tr.cjs +0 -123
  128. package/dist/node_modules/zod/v4/locales/tr.js +0 -118
  129. package/dist/node_modules/zod/v4/locales/ua.cjs +0 -122
  130. package/dist/node_modules/zod/v4/locales/ua.js +0 -120
  131. package/dist/node_modules/zod/v4/locales/ur.cjs +0 -122
  132. package/dist/node_modules/zod/v4/locales/ur.js +0 -120
  133. package/dist/node_modules/zod/v4/locales/vi.cjs +0 -121
  134. package/dist/node_modules/zod/v4/locales/vi.js +0 -119
  135. package/dist/node_modules/zod/v4/locales/zh-CN.cjs +0 -121
  136. package/dist/node_modules/zod/v4/locales/zh-CN.js +0 -119
  137. package/dist/node_modules/zod/v4/locales/zh-TW.cjs +0 -122
  138. package/dist/node_modules/zod/v4/locales/zh-TW.js +0 -120
@@ -1,41 +0,0 @@
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;
@@ -1,37 +0,0 @@
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 };
@@ -1,204 +0,0 @@
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;
@@ -1,194 +0,0 @@
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 };
@@ -1,81 +0,0 @@
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;
@@ -1,76 +0,0 @@
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 };