@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,74 +1,120 @@
1
- import { match, P } from "ts-pattern";
2
- import { toJsonSchema } from "./toJsonSchema.js";
1
+ import { match, P } from 'ts-pattern';
2
+ import { toJsonSchema } from './toJsonSchema.js';
3
3
  export function createSchemaData(ts, options = {}) {
4
- const schema = toJsonSchema(ts);
5
- return createJsonSchemaData(schema, options);
4
+ const schema = toJsonSchema(ts);
5
+ return createJsonSchemaData(schema, options);
6
6
  }
7
7
  function createJsonSchemaData(schema, options) {
8
- let skip = (s, ctx) => Boolean(!ctx.required && s.nullable);
9
- if (options.all) {
10
- skip = () => false;
11
- }
12
- if (options.skip) {
13
- skip = options.skip;
14
- }
15
- return _create(schema, {
16
- skip
17
- }, {
18
- required: false
19
- });
8
+ let skip = (s, ctx) => Boolean(!ctx.required && s.nullable);
9
+ if (options.all) {
10
+ skip = () => false;
11
+ }
12
+ if (options.skip) {
13
+ skip = options.skip;
14
+ }
15
+ return _create(
16
+ schema,
17
+ {
18
+ skip,
19
+ },
20
+ {
21
+ required: false,
22
+ },
23
+ );
20
24
  }
21
25
  function _create(schema, options, ctx) {
22
- const { skip } = options;
23
- if (skip(schema, ctx)) {
24
- return schema.default;
25
- }
26
- if (schema.default !== undefined) {
27
- return schema.default;
28
- }
29
- return match(schema).returnType().with({
30
- default: P.select()
31
- }, (v) => v).with({
32
- const: P.nonNullable
33
- }, (v) => v.const).with({
34
- anyOf: P.nonNullable
35
- }, (schema) => {
36
- return _create(schema.anyOf[0], options, {
37
- required: false
38
- });
39
- }).with({
40
- oneOf: P.nonNullable
41
- }, (schema) => {
42
- return _create(schema.oneOf[0], options, {
43
- required: false
44
- });
45
- }).with({
46
- type: "string"
47
- }, (_schema) => "").with({
48
- type: P.union("number", "integer")
49
- }, (_schema) => 0).with({
50
- type: "object"
51
- }, () => {
52
- const out = {};
53
- let required = Array.isArray(schema.required) ? schema.required : [];
54
- for (const [k, v] of Object.entries(schema.properties || {})) {
55
- const value = _create(v, options, {
56
- required: required.includes(k)
57
- });
58
- if (value === undefined) {
59
- continue;
60
- }
61
- out[k] = value;
62
- }
63
- return out;
64
- }).with({
65
- type: "null"
66
- }, () => null).with({
67
- type: "boolean"
68
- }, (_schema) => false).with({
69
- type: "array"
70
- }, (_schema) => []).otherwise(() => {
71
- return undefined;
72
- });
26
+ const { skip } = options;
27
+ if (skip(schema, ctx)) {
28
+ return schema.default;
29
+ }
30
+ if (schema.default !== undefined) {
31
+ return schema.default;
32
+ }
33
+ return match(schema)
34
+ .returnType()
35
+ .with(
36
+ {
37
+ default: P.select(),
38
+ },
39
+ (v) => v,
40
+ )
41
+ .with(
42
+ {
43
+ const: P.nonNullable,
44
+ },
45
+ (v) => v.const,
46
+ )
47
+ .with(
48
+ {
49
+ anyOf: P.nonNullable,
50
+ },
51
+ (schema) => {
52
+ return _create(schema.anyOf[0], options, {
53
+ required: false,
54
+ });
55
+ },
56
+ )
57
+ .with(
58
+ {
59
+ oneOf: P.nonNullable,
60
+ },
61
+ (schema) => {
62
+ return _create(schema.oneOf[0], options, {
63
+ required: false,
64
+ });
65
+ },
66
+ )
67
+ .with(
68
+ {
69
+ type: 'string',
70
+ },
71
+ (_schema) => '',
72
+ )
73
+ .with(
74
+ {
75
+ type: P.union('number', 'integer'),
76
+ },
77
+ (_schema) => 0,
78
+ )
79
+ .with(
80
+ {
81
+ type: 'object',
82
+ },
83
+ () => {
84
+ const out = {};
85
+ let required = Array.isArray(schema.required) ? schema.required : [];
86
+ for (const [k, v] of Object.entries(schema.properties || {})) {
87
+ const value = _create(v, options, {
88
+ required: required.includes(k),
89
+ });
90
+ if (value === undefined) {
91
+ continue;
92
+ }
93
+ out[k] = value;
94
+ }
95
+ return out;
96
+ },
97
+ )
98
+ .with(
99
+ {
100
+ type: 'null',
101
+ },
102
+ () => null,
103
+ )
104
+ .with(
105
+ {
106
+ type: 'boolean',
107
+ },
108
+ (_schema) => false,
109
+ )
110
+ .with(
111
+ {
112
+ type: 'array',
113
+ },
114
+ (_schema) => [],
115
+ )
116
+ .otherwise(() => {
117
+ return undefined;
118
+ });
73
119
  }
74
120
  //# sourceMappingURL=createSchemaData.js.map
@@ -1,26 +1,31 @@
1
- import { firstOfMaybeArray } from "@wener/utils";
2
- import { toJsonSchema } from "./toJsonSchema.js";
1
+ import { firstOfMaybeArray } from '@wener/utils';
2
+ import { toJsonSchema } from './toJsonSchema.js';
3
3
  export function findJsonSchemaByPath(schema, objectPath) {
4
- schema = toJsonSchema(schema);
5
- if (!objectPath || !schema) {
6
- return undefined;
7
- }
8
- const segments = objectPath.split(".");
9
- let currentSchema = schema;
10
- for (const segment of segments) {
11
- // 检查当前 schema 是否是对象类型且有 properties
12
- if (currentSchema && typeof currentSchema === "object" && currentSchema.properties && currentSchema.properties[segment]) {
13
- currentSchema = currentSchema.properties[segment];
14
- continue;
15
- }
16
- if (/^\d$/.test(segment) || segment === "[]") {
17
- if (currentSchema.items) {
18
- currentSchema = firstOfMaybeArray(currentSchema.items);
19
- continue;
20
- }
21
- }
22
- return undefined;
23
- }
24
- return currentSchema;
4
+ schema = toJsonSchema(schema);
5
+ if (!objectPath || !schema) {
6
+ return undefined;
7
+ }
8
+ const segments = objectPath.split('.');
9
+ let currentSchema = schema;
10
+ for (const segment of segments) {
11
+ // 检查当前 schema 是否是对象类型且有 properties
12
+ if (
13
+ currentSchema &&
14
+ typeof currentSchema === 'object' &&
15
+ currentSchema.properties &&
16
+ currentSchema.properties[segment]
17
+ ) {
18
+ currentSchema = currentSchema.properties[segment];
19
+ continue;
20
+ }
21
+ if (/^\d$/.test(segment) || segment === '[]') {
22
+ if (currentSchema.items) {
23
+ currentSchema = firstOfMaybeArray(currentSchema.items);
24
+ continue;
25
+ }
26
+ }
27
+ return undefined;
28
+ }
29
+ return currentSchema;
25
30
  }
26
31
  //# sourceMappingURL=findJsonSchemaByPath.js.map
@@ -1,138 +1,119 @@
1
- import { findJsonSchemaByPath } from "./findJsonSchemaByPath.js";
1
+ import { findJsonSchemaByPath } from './findJsonSchemaByPath.js';
2
2
  export function formatZodError(error, schema) {
3
- if (!error.issues || error.issues.length === 0) {
4
- return error.message || "\u9A8C\u8BC1\u5931\u8D25";
5
- }
6
- const messages = [];
7
- // Iterate through issues and format each one
8
- // We use manual iteration instead of error.format() to have better control
9
- // over field name formatting with schema descriptions
10
- for (const issue of error.issues) {
11
- const formatted = formatIssueMessage(issue, schema);
12
- if (formatted) {
13
- const path = issue.path.map((p) => typeof p === "symbol" ? String(p) : p);
14
- let fieldName = formatPath(path);
15
- // Try to get field description from schema
16
- if (schema && path.length > 0) {
17
- const fieldPath = path.map(String).join(".");
18
- const fieldSchema = findJsonSchemaByPath(schema, fieldPath);
19
- if (fieldSchema?.description) {
20
- fieldName = fieldSchema.description;
21
- }
22
- }
23
- messages.push(`${fieldName}: ${formatted}`);
24
- }
25
- }
26
- return messages.join("\uFF1B");
3
+ if (!error.issues || error.issues.length === 0) {
4
+ return error.message || '\u9A8C\u8BC1\u5931\u8D25';
5
+ }
6
+ const messages = [];
7
+ // Iterate through issues and format each one
8
+ // We use manual iteration instead of error.format() to have better control
9
+ // over field name formatting with schema descriptions
10
+ for (const issue of error.issues) {
11
+ const formatted = formatIssueMessage(issue, schema);
12
+ if (formatted) {
13
+ const path = issue.path.map((p) => (typeof p === 'symbol' ? String(p) : p));
14
+ let fieldName = formatPath(path);
15
+ // Try to get field description from schema
16
+ if (schema && path.length > 0) {
17
+ const fieldPath = path.map(String).join('.');
18
+ const fieldSchema = findJsonSchemaByPath(schema, fieldPath);
19
+ if (fieldSchema?.description) {
20
+ fieldName = fieldSchema.description;
21
+ }
22
+ }
23
+ messages.push(`${fieldName}: ${formatted}`);
24
+ }
25
+ }
26
+ return messages.join('\uFF1B');
27
27
  }
28
28
  function formatIssueMessage(issue, _schema) {
29
- let message = issue.message;
30
- // 处理常见的错误类型,生成更友好的消息
31
- switch (issue.code) {
32
- case "invalid_type":
33
- {
34
- const i = issue;
35
- // Zod v4 doesn't have 'received' field directly, extract from message
36
- const match = issue.message.match(/received (\w+)/);
37
- const received = match?.[1];
38
- if (received === "undefined") {
39
- message = "\u5FC5\u586B";
40
- }
41
- else if (received === "null") {
42
- message = "\u4E0D\u80FD\u4E3A\u7A7A";
43
- }
44
- else {
45
- message = issue.message || `期望类型 ${i.expected},但收到 ${received}`;
46
- }
47
- break;
48
- }
49
- case "invalid_format":
50
- {
51
- const i = issue;
52
- if (i.format === "email") {
53
- message = "\u8BF7\u8F93\u5165\u6709\u6548\u7684\u90AE\u7BB1\u5730\u5740";
54
- }
55
- else if (i.format === "url") {
56
- message = "\u8BF7\u8F93\u5165\u6709\u6548\u7684 URL";
57
- }
58
- else if (i.format === "uuid") {
59
- message = "\u8BF7\u8F93\u5165\u6709\u6548\u7684 UUID";
60
- }
61
- else if (i.format === "date") {
62
- message = "\u8BF7\u8F93\u5165\u6709\u6548\u7684\u65E5\u671F";
63
- }
64
- break;
65
- }
66
- case "too_small":
67
- {
68
- const i = issue;
69
- if (i.origin === "string" && i.minimum === 1) {
70
- message = "\u4E0D\u80FD\u4E3A\u7A7A";
71
- }
72
- else if (i.origin === "string") {
73
- message = `至少需要 ${i.minimum} 个字符`;
74
- }
75
- else if (i.origin === "number" || i.origin === "int") {
76
- message = `至少需要 ${i.minimum}`;
77
- }
78
- else if (i.origin === "array") {
79
- message = `至少需要 ${i.minimum} 项`;
80
- }
81
- break;
82
- }
83
- case "too_big":
84
- {
85
- const i = issue;
86
- if (i.origin === "string") {
87
- message = `最多 ${i.maximum} 个字符`;
88
- }
89
- else if (i.origin === "number" || i.origin === "int") {
90
- message = `最多 ${i.maximum}`;
91
- }
92
- else if (i.origin === "array") {
93
- message = `最多 ${i.maximum} 项`;
94
- }
95
- break;
96
- }
97
- case "invalid_value":
98
- {
99
- const i = issue;
100
- if (i.values.length === 1) {
101
- // Single value means it's a literal check
102
- message = `必须是 ${String(i.values[0])}`;
103
- }
104
- else {
105
- message = `必须是以下值之一: ${i.values.map(String).join(", ")}`;
106
- }
107
- break;
108
- }
109
- case "unrecognized_keys":
110
- {
111
- const i = issue;
112
- message = `不支持的字段: ${i.keys.join(", ")}`;
113
- break;
114
- }
115
- case "invalid_union":
116
- {
117
- message = "\u4E0D\u7B26\u5408\u4EFB\u4F55\u5141\u8BB8\u7684\u7C7B\u578B";
118
- break;
119
- }
120
- case "custom":
121
- {
122
- // 保留自定义错误消息
123
- message = issue.message;
124
- break;
125
- }
126
- default:
127
- // 保留原始消息
128
- message = issue.message;
129
- }
130
- return message;
29
+ let message = issue.message;
30
+ // 处理常见的错误类型,生成更友好的消息
31
+ switch (issue.code) {
32
+ case 'invalid_type': {
33
+ const i = issue;
34
+ // Zod v4 doesn't have 'received' field directly, extract from message
35
+ const match = issue.message.match(/received (\w+)/);
36
+ const received = match?.[1];
37
+ if (received === 'undefined') {
38
+ message = '\u5FC5\u586B';
39
+ } else if (received === 'null') {
40
+ message = '\u4E0D\u80FD\u4E3A\u7A7A';
41
+ } else {
42
+ message = issue.message || `期望类型 ${i.expected},但收到 ${received}`;
43
+ }
44
+ break;
45
+ }
46
+ case 'invalid_format': {
47
+ const i = issue;
48
+ if (i.format === 'email') {
49
+ message = '\u8BF7\u8F93\u5165\u6709\u6548\u7684\u90AE\u7BB1\u5730\u5740';
50
+ } else if (i.format === 'url') {
51
+ message = '\u8BF7\u8F93\u5165\u6709\u6548\u7684 URL';
52
+ } else if (i.format === 'uuid') {
53
+ message = '\u8BF7\u8F93\u5165\u6709\u6548\u7684 UUID';
54
+ } else if (i.format === 'date') {
55
+ message = '\u8BF7\u8F93\u5165\u6709\u6548\u7684\u65E5\u671F';
56
+ }
57
+ break;
58
+ }
59
+ case 'too_small': {
60
+ const i = issue;
61
+ if (i.origin === 'string' && i.minimum === 1) {
62
+ message = '\u4E0D\u80FD\u4E3A\u7A7A';
63
+ } else if (i.origin === 'string') {
64
+ message = `至少需要 ${i.minimum} 个字符`;
65
+ } else if (i.origin === 'number' || i.origin === 'int') {
66
+ message = `至少需要 ${i.minimum}`;
67
+ } else if (i.origin === 'array') {
68
+ message = `至少需要 ${i.minimum} 项`;
69
+ }
70
+ break;
71
+ }
72
+ case 'too_big': {
73
+ const i = issue;
74
+ if (i.origin === 'string') {
75
+ message = `最多 ${i.maximum} 个字符`;
76
+ } else if (i.origin === 'number' || i.origin === 'int') {
77
+ message = `最多 ${i.maximum}`;
78
+ } else if (i.origin === 'array') {
79
+ message = `最多 ${i.maximum} 项`;
80
+ }
81
+ break;
82
+ }
83
+ case 'invalid_value': {
84
+ const i = issue;
85
+ if (i.values.length === 1) {
86
+ // Single value means it's a literal check
87
+ message = `必须是 ${String(i.values[0])}`;
88
+ } else {
89
+ message = `必须是以下值之一: ${i.values.map(String).join(', ')}`;
90
+ }
91
+ break;
92
+ }
93
+ case 'unrecognized_keys': {
94
+ const i = issue;
95
+ message = `不支持的字段: ${i.keys.join(', ')}`;
96
+ break;
97
+ }
98
+ case 'invalid_union': {
99
+ message = '\u4E0D\u7B26\u5408\u4EFB\u4F55\u5141\u8BB8\u7684\u7C7B\u578B';
100
+ break;
101
+ }
102
+ case 'custom': {
103
+ // 保留自定义错误消息
104
+ message = issue.message;
105
+ break;
106
+ }
107
+ default:
108
+ // 保留原始消息
109
+ message = issue.message;
110
+ }
111
+ return message;
131
112
  }
132
113
  function formatPath(path) {
133
- if (path.length === 0) {
134
- return "\u8868\u5355";
135
- }
136
- return path.map(String).join(".");
114
+ if (path.length === 0) {
115
+ return '\u8868\u5355';
116
+ }
117
+ return path.map(String).join('.');
137
118
  }
138
119
  //# sourceMappingURL=formatZodError.js.map