@wener/common 2.0.5 → 2.0.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 (206) hide show
  1. package/lib/ai/qwen3vl/index.js +1 -1
  2. package/lib/ai/qwen3vl/utils.js +15 -15
  3. package/lib/ai/vision/DocLayoutElementTypeSchema.js +22 -22
  4. package/lib/ai/vision/ImageAnnotationSchema.js +63 -47
  5. package/lib/ai/vision/index.js +2 -2
  6. package/lib/ai/vision/resolveImageAnnotation.js +81 -95
  7. package/lib/cn/ChineseResidentIdNo.js +55 -41
  8. package/lib/cn/ChineseResidentIdNo.mod.js +6 -1
  9. package/lib/cn/ChineseResidentIdNo.test.js +22 -21
  10. package/lib/cn/DivisionCode.js +220 -235
  11. package/lib/cn/DivisionCode.mod.js +6 -1
  12. package/lib/cn/DivisionCode.test.js +92 -121
  13. package/lib/cn/Mod11.js +18 -37
  14. package/lib/cn/Mod31.js +23 -41
  15. package/lib/cn/UnifiedSocialCreditCode.js +143 -137
  16. package/lib/cn/UnifiedSocialCreditCode.mod.js +6 -1
  17. package/lib/cn/UnifiedSocialCreditCode.test.js +21 -15
  18. package/lib/cn/formatChineseAmount.js +46 -71
  19. package/lib/cn/index.js +6 -6
  20. package/lib/cn/mod.js +5 -3
  21. package/lib/cn/parseChineseNumber.js +81 -85
  22. package/lib/cn/parseChineseNumber.test.js +183 -261
  23. package/lib/cn/pinyin/cartesianProduct.js +19 -19
  24. package/lib/cn/pinyin/cartesianProduct.test.js +78 -178
  25. package/lib/cn/pinyin/loader.js +13 -11
  26. package/lib/cn/pinyin/preload.js +2 -1
  27. package/lib/cn/pinyin/toPinyin.test.js +149 -161
  28. package/lib/cn/pinyin/toPinyinPure.js +28 -23
  29. package/lib/cn/pinyin/transform.js +11 -11
  30. package/lib/cn/types.d.js +2 -2
  31. package/lib/consola/createStandardConsolaReporter.js +14 -15
  32. package/lib/consola/formatLogObject.js +149 -133
  33. package/lib/consola/formatLogObject.test.js +167 -178
  34. package/lib/consola/index.js +2 -2
  35. package/lib/data/formatSort.js +14 -12
  36. package/lib/data/formatSort.test.js +33 -33
  37. package/lib/data/index.js +3 -3
  38. package/lib/data/maybeNumber.js +23 -23
  39. package/lib/data/parseSort.js +75 -68
  40. package/lib/data/parseSort.test.js +196 -187
  41. package/lib/data/resolvePagination.js +38 -39
  42. package/lib/data/resolvePagination.test.js +228 -218
  43. package/lib/data/types.d.js +2 -2
  44. package/lib/dayjs/dayjs.js +20 -20
  45. package/lib/dayjs/formatDuration.js +56 -56
  46. package/lib/dayjs/formatDuration.test.js +63 -77
  47. package/lib/dayjs/index.js +4 -4
  48. package/lib/dayjs/parseDuration.js +21 -26
  49. package/lib/dayjs/parseRelativeTime.js +65 -66
  50. package/lib/dayjs/parseRelativeTime.test.js +227 -243
  51. package/lib/dayjs/resolveRelativeTime.js +73 -72
  52. package/lib/dayjs/resolveRelativeTime.test.js +296 -307
  53. package/lib/decimal/index.js +1 -1
  54. package/lib/decimal/parseDecimal.js +12 -12
  55. package/lib/drain3/Drain.js +303 -338
  56. package/lib/drain3/LogCluster.js +25 -25
  57. package/lib/drain3/Node.js +24 -24
  58. package/lib/drain3/TemplateMiner.js +197 -196
  59. package/lib/drain3/index.js +5 -5
  60. package/lib/drain3/persistence/FilePersistence.js +19 -19
  61. package/lib/drain3/persistence/MemoryPersistence.js +8 -8
  62. package/lib/drain3/persistence/PersistenceHandler.js +2 -2
  63. package/lib/drain3/types.js +2 -2
  64. package/lib/emittery/emitter.js +7 -7
  65. package/lib/emittery/index.js +1 -1
  66. package/lib/foundation/schema/SexType.js +15 -12
  67. package/lib/foundation/schema/index.js +1 -1
  68. package/lib/foundation/schema/parseSexType.js +15 -16
  69. package/lib/foundation/schema/types.js +8 -6
  70. package/lib/fs/FileSystemError.js +18 -18
  71. package/lib/fs/IFileSystem.d.js +2 -2
  72. package/lib/fs/MemoryFileSystem.test.js +172 -181
  73. package/lib/fs/createBrowserFileSystem.js +222 -235
  74. package/lib/fs/createMemoryFileSystem.js +472 -510
  75. package/lib/fs/createSandboxFileSystem.js +102 -101
  76. package/lib/fs/createWebDavFileSystem.js +162 -149
  77. package/lib/fs/createWebFileSystem.js +197 -220
  78. package/lib/fs/findMimeType.js +14 -14
  79. package/lib/fs/index.js +7 -7
  80. package/lib/fs/minio/createMinioFileSystem.js +959 -956
  81. package/lib/fs/minio/index.js +1 -1
  82. package/lib/fs/orpc/FileSystemContract.js +57 -57
  83. package/lib/fs/orpc/createContractClientFileSystem.js +88 -88
  84. package/lib/fs/orpc/index.js +2 -2
  85. package/lib/fs/orpc/server/createFileSystemContractImpl.js +62 -60
  86. package/lib/fs/orpc/server/index.js +1 -1
  87. package/lib/fs/s3/createS3MiniFileSystem.js +756 -737
  88. package/lib/fs/s3/index.js +1 -1
  89. package/lib/fs/s3/s3mini.test.js +524 -553
  90. package/lib/fs/scandir.js +56 -56
  91. package/lib/fs/server/createDatabaseFileSystem.js +834 -741
  92. package/lib/fs/server/createNodeFileSystem.js +407 -405
  93. package/lib/fs/server/dbfs.test.js +201 -214
  94. package/lib/fs/server/index.js +1 -1
  95. package/lib/fs/server/loadTestDatabase.js +40 -43
  96. package/lib/fs/tests/runFileSystemTest.js +352 -316
  97. package/lib/fs/types.js +17 -20
  98. package/lib/fs/utils/getFileUrl.js +24 -30
  99. package/lib/fs/utils.js +17 -17
  100. package/lib/fs/webdav/index.js +1 -1
  101. package/lib/index.js +2 -2
  102. package/lib/jsonschema/JsonSchema.js +216 -155
  103. package/lib/jsonschema/JsonSchema.test.js +123 -124
  104. package/lib/jsonschema/forEachJsonSchema.js +41 -41
  105. package/lib/jsonschema/index.js +2 -2
  106. package/lib/jsonschema/types.d.js +2 -2
  107. package/lib/meta/defineFileType.js +32 -38
  108. package/lib/meta/defineInit.js +39 -35
  109. package/lib/meta/defineMetadata.js +37 -34
  110. package/lib/meta/defineMetadata.test.js +13 -12
  111. package/lib/meta/index.js +3 -3
  112. package/lib/orpc/createOpenApiContractClient.js +26 -24
  113. package/lib/orpc/createRpcContractClient.js +37 -31
  114. package/lib/orpc/index.js +2 -2
  115. package/lib/orpc/resolveLinkPlugins.js +25 -25
  116. package/lib/password/PHC.js +187 -189
  117. package/lib/password/PHC.test.js +517 -535
  118. package/lib/password/Password.js +85 -80
  119. package/lib/password/Password.test.js +330 -364
  120. package/lib/password/createArgon2PasswordAlgorithm.js +50 -51
  121. package/lib/password/createBase64PasswordAlgorithm.js +11 -11
  122. package/lib/password/createBcryptPasswordAlgorithm.js +20 -18
  123. package/lib/password/createPBKDF2PasswordAlgorithm.js +65 -52
  124. package/lib/password/createScryptPasswordAlgorithm.js +74 -63
  125. package/lib/password/index.js +5 -5
  126. package/lib/password/server/index.js +1 -1
  127. package/lib/resource/Identifiable.js +2 -2
  128. package/lib/resource/ListQuery.js +42 -42
  129. package/lib/resource/getTitleOfResource.js +5 -5
  130. package/lib/resource/index.js +2 -2
  131. package/lib/resource/schema/AnyResourceSchema.js +91 -89
  132. package/lib/resource/schema/BaseResourceSchema.js +26 -26
  133. package/lib/resource/schema/ResourceActionType.js +117 -115
  134. package/lib/resource/schema/ResourceStatus.js +94 -92
  135. package/lib/resource/schema/ResourceType.js +25 -23
  136. package/lib/resource/schema/index.js +5 -5
  137. package/lib/resource/schema/types.js +86 -55
  138. package/lib/resource/schema/types.test.js +16 -13
  139. package/lib/s3/formatS3Url.js +60 -60
  140. package/lib/s3/formatS3Url.test.js +238 -261
  141. package/lib/s3/index.js +2 -2
  142. package/lib/s3/parseS3Url.js +61 -60
  143. package/lib/s3/parseS3Url.test.js +270 -269
  144. package/lib/schema/SchemaRegistry.js +41 -42
  145. package/lib/schema/SchemaRegistry.mod.js +1 -1
  146. package/lib/schema/TypeSchema.d.js +2 -2
  147. package/lib/schema/createSchemaData.js +113 -67
  148. package/lib/schema/findJsonSchemaByPath.js +28 -23
  149. package/lib/schema/formatZodError.js +112 -131
  150. package/lib/schema/formatZodError.test.js +192 -195
  151. package/lib/schema/getSchemaCache.js +7 -7
  152. package/lib/schema/getSchemaOptions.js +17 -16
  153. package/lib/schema/index.js +6 -6
  154. package/lib/schema/toJsonSchema.js +195 -189
  155. package/lib/schema/toJsonSchema.test.js +34 -26
  156. package/lib/schema/validate.js +105 -96
  157. package/lib/tools/generateSchema.js +40 -40
  158. package/lib/tools/renderJsonSchemaToMarkdownDoc.js +74 -74
  159. package/lib/utils/buildBaseUrl.js +8 -8
  160. package/lib/utils/buildRedactorFormSchema.js +54 -53
  161. package/lib/utils/getEstimateProcessTime.js +24 -19
  162. package/lib/utils/index.js +3 -3
  163. package/lib/utils/resolveFeatureOptions.js +9 -9
  164. package/package.json +14 -14
  165. package/src/ai/vision/index.ts +2 -2
  166. package/src/cn/index.ts +1 -2
  167. package/src/consola/index.ts +1 -1
  168. package/src/data/index.ts +3 -4
  169. package/src/data/resolvePagination.ts +2 -2
  170. package/src/dayjs/formatDuration.ts +8 -9
  171. package/src/dayjs/index.ts +1 -1
  172. package/src/dayjs/parseRelativeTime.ts +1 -1
  173. package/src/dayjs/resolveRelativeTime.ts +1 -1
  174. package/src/drain3/Drain.test.ts +2 -2
  175. package/src/drain3/index.ts +2 -4
  176. package/src/fs/createWebDavFileSystem.ts +2 -7
  177. package/src/fs/createWebFileSystem.ts +1 -1
  178. package/src/fs/index.ts +4 -4
  179. package/src/fs/minio/createMinioFileSystem.ts +2 -2
  180. package/src/fs/minio/index.ts +1 -1
  181. package/src/fs/s3/createS3MiniFileSystem.ts +1 -1
  182. package/src/fs/server/createDatabaseFileSystem.ts +84 -120
  183. package/src/fs/server/dbfs.test.ts +14 -10
  184. package/src/fs/server/index.ts +1 -0
  185. package/src/fs/server/loadTestDatabase.ts +8 -119
  186. package/src/jsonschema/index.ts +1 -1
  187. package/src/meta/index.ts +2 -3
  188. package/src/orm/createSqliteDialect.ts +17 -0
  189. package/src/orm/index.ts +1 -0
  190. package/src/orpc/createOpenApiContractClient.ts +1 -1
  191. package/src/orpc/index.ts +1 -1
  192. package/src/password/createArgon2PasswordAlgorithm.ts +1 -1
  193. package/src/password/index.ts +2 -2
  194. package/src/resource/index.ts +3 -3
  195. package/src/resource/schema/index.ts +4 -4
  196. package/src/s3/index.ts +1 -1
  197. package/src/schema/SchemaRegistry.ts +1 -1
  198. package/src/schema/createSchemaData.ts +1 -1
  199. package/src/schema/findJsonSchemaByPath.ts +1 -1
  200. package/src/schema/index.ts +5 -5
  201. package/src/schema/validate.ts +1 -1
  202. package/src/utils/buildRedactorFormSchema.ts +1 -1
  203. package/src/utils/formatNumber.ts +18 -0
  204. package/src/utils/formatPercent.ts +17 -0
  205. package/src/utils/index.ts +3 -3
  206. package/src/utils/resolveFeatureOptions.ts +1 -1
@@ -1,196 +1,193 @@
1
- import { describe, expect, it } from "vitest";
2
- import { z } from "zod/v4";
3
- import { formatZodError } from "./formatZodError.js";
4
- describe("formatZodError", function () {
5
- it("should format invalid_type error", function () {
6
- var schema = z.object({
7
- name: z.string(),
8
- age: z.number()
9
- });
10
- var result = schema.safeParse({
11
- name: 123,
12
- age: "not-a-number"
13
- });
14
- expect(result.success).toBe(false);
15
- if (!result.success) {
16
- var formatted = formatZodError(result.error);
17
- expect(formatted).toContain("name");
18
- expect(formatted).toContain("age");
19
- }
20
- });
21
- it("should format required field error", function () {
22
- var schema = z.object({
23
- name: z.string(),
24
- email: z.string().email()
25
- });
26
- var result = schema.safeParse({});
27
- expect(result.success).toBe(false);
28
- if (!result.success) {
29
- var formatted = formatZodError(result.error);
30
- expect(formatted).toContain("\u5FC5\u586B");
31
- }
32
- });
33
- it("should format email validation error", function () {
34
- var schema = z.object({
35
- email: z.string().email()
36
- });
37
- var result = schema.safeParse({
38
- email: "invalid-email"
39
- });
40
- expect(result.success).toBe(false);
41
- if (!result.success) {
42
- var formatted = formatZodError(result.error);
43
- expect(formatted).toContain("\u8BF7\u8F93\u5165\u6709\u6548\u7684\u90AE\u7BB1\u5730\u5740");
44
- }
45
- });
46
- it("should format URL validation error", function () {
47
- var schema = z.object({
48
- url: z.string().url()
49
- });
50
- var result = schema.safeParse({
51
- url: "not-a-url"
52
- });
53
- expect(result.success).toBe(false);
54
- if (!result.success) {
55
- var formatted = formatZodError(result.error);
56
- expect(formatted).toContain("\u8BF7\u8F93\u5165\u6709\u6548\u7684 URL");
57
- }
58
- });
59
- it("should format too_small error for string", function () {
60
- var schema = z.object({
61
- name: z.string().min(5)
62
- });
63
- var result = schema.safeParse({
64
- name: "abc"
65
- });
66
- expect(result.success).toBe(false);
67
- if (!result.success) {
68
- var formatted = formatZodError(result.error);
69
- expect(formatted).toContain("\u81F3\u5C11\u9700\u8981");
70
- }
71
- });
72
- it("should format too_small error for number", function () {
73
- var schema = z.object({
74
- age: z.number().min(18)
75
- });
76
- var result = schema.safeParse({
77
- age: 16
78
- });
79
- expect(result.success).toBe(false);
80
- if (!result.success) {
81
- var formatted = formatZodError(result.error);
82
- expect(formatted).toContain("\u81F3\u5C11\u9700\u8981 18");
83
- }
84
- });
85
- it("should format too_big error for string", function () {
86
- var schema = z.object({
87
- name: z.string().max(10)
88
- });
89
- var result = schema.safeParse({
90
- name: "this is too long"
91
- });
92
- expect(result.success).toBe(false);
93
- if (!result.success) {
94
- var formatted = formatZodError(result.error);
95
- expect(formatted).toContain("\u6700\u591A 10 \u4E2A\u5B57\u7B26");
96
- }
97
- });
98
- it("should format invalid_enum_value error", function () {
99
- var schema = z.object({
100
- status: z.enum([
101
- "active",
102
- "inactive",
103
- "pending"
104
- ])
105
- });
106
- var result = schema.safeParse({
107
- status: "invalid"
108
- });
109
- expect(result.success).toBe(false);
110
- if (!result.success) {
111
- var formatted = formatZodError(result.error);
112
- expect(formatted).toContain("\u5FC5\u987B\u662F\u4EE5\u4E0B\u503C\u4E4B\u4E00");
113
- }
114
- });
115
- it("should format invalid_literal error", function () {
116
- var schema = z.object({
117
- type: z.literal("user")
118
- });
119
- var result = schema.safeParse({
120
- type: "admin"
121
- });
122
- expect(result.success).toBe(false);
123
- if (!result.success) {
124
- var formatted = formatZodError(result.error);
125
- expect(formatted).toContain("\u5FC5\u987B\u662F user");
126
- }
127
- });
128
- it("should format nested object errors", function () {
129
- var schema = z.object({
130
- user: z.object({
131
- name: z.string(),
132
- email: z.string().email()
133
- })
134
- });
135
- var result = schema.safeParse({
136
- user: {
137
- name: "",
138
- email: "invalid"
139
- }
140
- });
141
- expect(result.success).toBe(false);
142
- if (!result.success) {
143
- var formatted = formatZodError(result.error);
144
- expect(formatted).toContain("user");
145
- expect(formatted).toContain("email");
146
- }
147
- });
148
- it("should format array errors", function () {
149
- var schema = z.object({
150
- tags: z.array(z.string()).min(1)
151
- });
152
- var result = schema.safeParse({
153
- tags: []
154
- });
155
- expect(result.success).toBe(false);
156
- if (!result.success) {
157
- var formatted = formatZodError(result.error);
158
- expect(formatted).toContain("\u81F3\u5C11\u9700\u8981 1 \u9879");
159
- }
160
- });
161
- it("should format multiple errors", function () {
162
- var schema = z.object({
163
- name: z.string().min(1),
164
- email: z.string().email(),
165
- age: z.number().min(18)
166
- });
167
- var result = schema.safeParse({
168
- name: "",
169
- email: "invalid",
170
- age: 15
171
- });
172
- expect(result.success).toBe(false);
173
- if (!result.success) {
174
- var formatted = formatZodError(result.error);
175
- // Should contain multiple error messages separated by ';'
176
- var parts = formatted.split("\uFF1B");
177
- expect(parts.length).toBeGreaterThan(1);
178
- }
179
- });
180
- it("should use schema description when available", function () {
181
- var schema = z.object({
182
- name: z.string().describe("\u59D3\u540D"),
183
- email: z.string().email().describe("\u90AE\u7BB1\u5730\u5740")
184
- });
185
- var result = schema.safeParse({
186
- name: "",
187
- email: "invalid"
188
- });
189
- expect(result.success).toBe(false);
190
- if (!result.success) {
191
- var formatted = formatZodError(result.error, schema);
192
- expect(formatted).toContain("\u59D3\u540D");
193
- expect(formatted).toContain("\u90AE\u7BB1\u5730\u5740");
194
- }
195
- });
1
+ import { describe, expect, it } from 'vitest';
2
+ import { z } from 'zod/v4';
3
+ import { formatZodError } from './formatZodError.js';
4
+
5
+ describe('formatZodError', () => {
6
+ it('should format invalid_type error', () => {
7
+ var schema = z.object({
8
+ name: z.string(),
9
+ age: z.number(),
10
+ });
11
+ var result = schema.safeParse({
12
+ name: 123,
13
+ age: 'not-a-number',
14
+ });
15
+ expect(result.success).toBe(false);
16
+ if (!result.success) {
17
+ var formatted = formatZodError(result.error);
18
+ expect(formatted).toContain('name');
19
+ expect(formatted).toContain('age');
20
+ }
21
+ });
22
+ it('should format required field error', () => {
23
+ var schema = z.object({
24
+ name: z.string(),
25
+ email: z.string().email(),
26
+ });
27
+ var result = schema.safeParse({});
28
+ expect(result.success).toBe(false);
29
+ if (!result.success) {
30
+ var formatted = formatZodError(result.error);
31
+ expect(formatted).toContain('\u5FC5\u586B');
32
+ }
33
+ });
34
+ it('should format email validation error', () => {
35
+ var schema = z.object({
36
+ email: z.string().email(),
37
+ });
38
+ var result = schema.safeParse({
39
+ email: 'invalid-email',
40
+ });
41
+ expect(result.success).toBe(false);
42
+ if (!result.success) {
43
+ var formatted = formatZodError(result.error);
44
+ expect(formatted).toContain('\u8BF7\u8F93\u5165\u6709\u6548\u7684\u90AE\u7BB1\u5730\u5740');
45
+ }
46
+ });
47
+ it('should format URL validation error', () => {
48
+ var schema = z.object({
49
+ url: z.string().url(),
50
+ });
51
+ var result = schema.safeParse({
52
+ url: 'not-a-url',
53
+ });
54
+ expect(result.success).toBe(false);
55
+ if (!result.success) {
56
+ var formatted = formatZodError(result.error);
57
+ expect(formatted).toContain('\u8BF7\u8F93\u5165\u6709\u6548\u7684 URL');
58
+ }
59
+ });
60
+ it('should format too_small error for string', () => {
61
+ var schema = z.object({
62
+ name: z.string().min(5),
63
+ });
64
+ var result = schema.safeParse({
65
+ name: 'abc',
66
+ });
67
+ expect(result.success).toBe(false);
68
+ if (!result.success) {
69
+ var formatted = formatZodError(result.error);
70
+ expect(formatted).toContain('\u81F3\u5C11\u9700\u8981');
71
+ }
72
+ });
73
+ it('should format too_small error for number', () => {
74
+ var schema = z.object({
75
+ age: z.number().min(18),
76
+ });
77
+ var result = schema.safeParse({
78
+ age: 16,
79
+ });
80
+ expect(result.success).toBe(false);
81
+ if (!result.success) {
82
+ var formatted = formatZodError(result.error);
83
+ expect(formatted).toContain('\u81F3\u5C11\u9700\u8981 18');
84
+ }
85
+ });
86
+ it('should format too_big error for string', () => {
87
+ var schema = z.object({
88
+ name: z.string().max(10),
89
+ });
90
+ var result = schema.safeParse({
91
+ name: 'this is too long',
92
+ });
93
+ expect(result.success).toBe(false);
94
+ if (!result.success) {
95
+ var formatted = formatZodError(result.error);
96
+ expect(formatted).toContain('\u6700\u591A 10 \u4E2A\u5B57\u7B26');
97
+ }
98
+ });
99
+ it('should format invalid_enum_value error', () => {
100
+ var schema = z.object({
101
+ status: z.enum(['active', 'inactive', 'pending']),
102
+ });
103
+ var result = schema.safeParse({
104
+ status: 'invalid',
105
+ });
106
+ expect(result.success).toBe(false);
107
+ if (!result.success) {
108
+ var formatted = formatZodError(result.error);
109
+ expect(formatted).toContain('\u5FC5\u987B\u662F\u4EE5\u4E0B\u503C\u4E4B\u4E00');
110
+ }
111
+ });
112
+ it('should format invalid_literal error', () => {
113
+ var schema = z.object({
114
+ type: z.literal('user'),
115
+ });
116
+ var result = schema.safeParse({
117
+ type: 'admin',
118
+ });
119
+ expect(result.success).toBe(false);
120
+ if (!result.success) {
121
+ var formatted = formatZodError(result.error);
122
+ expect(formatted).toContain('\u5FC5\u987B\u662F user');
123
+ }
124
+ });
125
+ it('should format nested object errors', () => {
126
+ var schema = z.object({
127
+ user: z.object({
128
+ name: z.string(),
129
+ email: z.string().email(),
130
+ }),
131
+ });
132
+ var result = schema.safeParse({
133
+ user: {
134
+ name: '',
135
+ email: 'invalid',
136
+ },
137
+ });
138
+ expect(result.success).toBe(false);
139
+ if (!result.success) {
140
+ var formatted = formatZodError(result.error);
141
+ expect(formatted).toContain('user');
142
+ expect(formatted).toContain('email');
143
+ }
144
+ });
145
+ it('should format array errors', () => {
146
+ var schema = z.object({
147
+ tags: z.array(z.string()).min(1),
148
+ });
149
+ var result = schema.safeParse({
150
+ tags: [],
151
+ });
152
+ expect(result.success).toBe(false);
153
+ if (!result.success) {
154
+ var formatted = formatZodError(result.error);
155
+ expect(formatted).toContain('\u81F3\u5C11\u9700\u8981 1 \u9879');
156
+ }
157
+ });
158
+ it('should format multiple errors', () => {
159
+ var schema = z.object({
160
+ name: z.string().min(1),
161
+ email: z.string().email(),
162
+ age: z.number().min(18),
163
+ });
164
+ var result = schema.safeParse({
165
+ name: '',
166
+ email: 'invalid',
167
+ age: 15,
168
+ });
169
+ expect(result.success).toBe(false);
170
+ if (!result.success) {
171
+ var formatted = formatZodError(result.error);
172
+ // Should contain multiple error messages separated by ';'
173
+ var parts = formatted.split('\uFF1B');
174
+ expect(parts.length).toBeGreaterThan(1);
175
+ }
176
+ });
177
+ it('should use schema description when available', () => {
178
+ var schema = z.object({
179
+ name: z.string().describe('\u59D3\u540D'),
180
+ email: z.string().email().describe('\u90AE\u7BB1\u5730\u5740'),
181
+ });
182
+ var result = schema.safeParse({
183
+ name: '',
184
+ email: 'invalid',
185
+ });
186
+ expect(result.success).toBe(false);
187
+ if (!result.success) {
188
+ var formatted = formatZodError(result.error, schema);
189
+ expect(formatted).toContain('\u59D3\u540D');
190
+ expect(formatted).toContain('\u90AE\u7BB1\u5730\u5740');
191
+ }
192
+ });
196
193
  });
@@ -1,11 +1,11 @@
1
1
  const _cache = new WeakMap();
2
2
  export function getSchemaCache(obj, key, compute) {
3
- let c = _cache.get(obj);
4
- if (!c) {
5
- c = {};
6
- _cache.set(obj, c);
7
- }
8
- return c[key] ??= compute();
3
+ let c = _cache.get(obj);
4
+ if (!c) {
5
+ c = {};
6
+ _cache.set(obj, c);
7
+ }
8
+ return (c[key] ??= compute());
9
9
  }
10
10
 
11
- //# sourceMappingURL=getSchemaCache.js.map
11
+ //# sourceMappingURL=getSchemaCache.js.map
@@ -1,21 +1,22 @@
1
- import { deepFreeze } from "@wener/utils";
2
- import { getSchemaCache } from "./getSchemaCache.js";
3
- import { SchemaRegistry } from "./SchemaRegistry.js";
1
+ import { deepFreeze } from '@wener/utils';
2
+ import { getSchemaCache } from './getSchemaCache.js';
3
+ import { SchemaRegistry } from './SchemaRegistry.js';
4
4
  export function getSchemaOptions(s) {
5
- let js = SchemaRegistry.get(s);
6
- return getSchemaCache(s, "options", () => {
7
- let out = (js.anyOf || js.oneOf)?.map((v) => {
8
- let value = v.const;
9
- return {
10
- label: String(v.description || v.title || value),
11
- value: value ? String(value) : ""
12
- };
13
- }) || [];
14
- out = deepFreeze(out);
15
- return out;
16
- });
5
+ let js = SchemaRegistry.get(s);
6
+ return getSchemaCache(s, 'options', () => {
7
+ let out =
8
+ (js.anyOf || js.oneOf)?.map((v) => {
9
+ let value = v.const;
10
+ return {
11
+ label: String(v.description || v.title || value),
12
+ value: value ? String(value) : '',
13
+ };
14
+ }) || [];
15
+ out = deepFreeze(out);
16
+ return out;
17
+ });
17
18
  }
18
19
  export function getSchemaOptionLabel(schema, value) {
19
- return getSchemaOptions(schema).find((v) => v.value === value)?.label;
20
+ return getSchemaOptions(schema).find((v) => v.value === value)?.label;
20
21
  }
21
22
  //# sourceMappingURL=getSchemaOptions.js.map
@@ -1,7 +1,7 @@
1
- export { isJsonSchema, isZodSchema, isTypeBoxSchema, validate, parseData } from "./validate.js";
2
- export { getSchemaOptions, getSchemaOptionLabel } from "./getSchemaOptions.js";
3
- export { toJsonSchema } from "./toJsonSchema.js";
4
- export { findJsonSchemaByPath } from "./findJsonSchemaByPath.js";
5
- export { createSchemaData } from "./createSchemaData.js";
6
- export { SchemaRegistry } from "./SchemaRegistry.js";
1
+ export { createSchemaData } from './createSchemaData.js';
2
+ export { findJsonSchemaByPath } from './findJsonSchemaByPath.js';
3
+ export { getSchemaOptionLabel, getSchemaOptions } from './getSchemaOptions.js';
4
+ export { SchemaRegistry } from './SchemaRegistry.js';
5
+ export { toJsonSchema } from './toJsonSchema.js';
6
+ export { isJsonSchema, isTypeBoxSchema, isZodSchema, parseData, validate } from './validate.js';
7
7
  //# sourceMappingURL=index.js.map