@wener/common 2.0.3 → 2.0.5

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 (168) hide show
  1. package/lib/ai/qwen3vl/utils.js.map +1 -1
  2. package/lib/cn/ChineseResidentIdNo.js +1 -1
  3. package/lib/cn/ChineseResidentIdNo.js.map +1 -1
  4. package/lib/cn/Mod11.js +1 -1
  5. package/lib/cn/Mod11.js.map +1 -1
  6. package/lib/consola/formatLogObject.js +5 -5
  7. package/lib/consola/formatLogObject.js.map +1 -1
  8. package/lib/data/maybeNumber.js +1 -1
  9. package/lib/data/maybeNumber.js.map +1 -1
  10. package/lib/data/types.d.js.map +1 -1
  11. package/lib/dayjs/formatDuration.js.map +1 -1
  12. package/lib/dayjs/resolveRelativeTime.js +9 -80
  13. package/lib/dayjs/resolveRelativeTime.js.map +1 -1
  14. package/lib/drain3/Drain.js +356 -0
  15. package/lib/drain3/Drain.js.map +1 -0
  16. package/lib/drain3/LogCluster.js +38 -0
  17. package/lib/drain3/LogCluster.js.map +1 -0
  18. package/lib/drain3/Node.js +39 -0
  19. package/lib/drain3/Node.js.map +1 -0
  20. package/lib/drain3/TemplateMiner.js +204 -0
  21. package/lib/drain3/TemplateMiner.js.map +1 -0
  22. package/lib/drain3/index.js +31 -0
  23. package/lib/drain3/index.js.map +1 -0
  24. package/lib/drain3/persistence/FilePersistence.js +24 -0
  25. package/lib/drain3/persistence/FilePersistence.js.map +1 -0
  26. package/lib/drain3/persistence/MemoryPersistence.js +18 -0
  27. package/lib/drain3/persistence/MemoryPersistence.js.map +1 -0
  28. package/lib/drain3/persistence/PersistenceHandler.js +5 -0
  29. package/lib/drain3/persistence/PersistenceHandler.js.map +1 -0
  30. package/lib/drain3/types.js +7 -0
  31. package/lib/drain3/types.js.map +1 -0
  32. package/lib/fs/IFileSystem.d.js.map +1 -1
  33. package/lib/fs/createBrowserFileSystem.js +4 -2
  34. package/lib/fs/createBrowserFileSystem.js.map +1 -1
  35. package/lib/fs/createMemoryFileSystem.js +7 -6
  36. package/lib/fs/createMemoryFileSystem.js.map +1 -1
  37. package/lib/fs/createSandboxFileSystem.js.map +1 -1
  38. package/lib/fs/createWebDavFileSystem.js +22 -5
  39. package/lib/fs/createWebDavFileSystem.js.map +1 -1
  40. package/lib/fs/createWebFileSystem.js +225 -0
  41. package/lib/fs/createWebFileSystem.js.map +1 -0
  42. package/lib/fs/findMimeType.js +1 -1
  43. package/lib/fs/findMimeType.js.map +1 -1
  44. package/lib/fs/index.js +1 -1
  45. package/lib/fs/index.js.map +1 -1
  46. package/lib/fs/minio/createMinioFileSystem.js +974 -0
  47. package/lib/fs/minio/createMinioFileSystem.js.map +1 -0
  48. package/lib/fs/minio/index.js +2 -0
  49. package/lib/fs/minio/index.js.map +1 -0
  50. package/lib/fs/orpc/createContractClientFileSystem.js +3 -3
  51. package/lib/fs/orpc/createContractClientFileSystem.js.map +1 -1
  52. package/lib/fs/orpc/server/createFileSystemContractImpl.js.map +1 -1
  53. package/lib/fs/s3/createS3MiniFileSystem.js +116 -68
  54. package/lib/fs/s3/createS3MiniFileSystem.js.map +1 -1
  55. package/lib/fs/server/createDatabaseFileSystem.js +7 -7
  56. package/lib/fs/server/createDatabaseFileSystem.js.map +1 -1
  57. package/lib/fs/server/createNodeFileSystem.js +30 -5
  58. package/lib/fs/server/createNodeFileSystem.js.map +1 -1
  59. package/lib/fs/tests/runFileSystemTest.js +27 -26
  60. package/lib/fs/tests/runFileSystemTest.js.map +1 -1
  61. package/lib/fs/utils.js.map +1 -1
  62. package/lib/fs/webdav/index.js +2 -0
  63. package/lib/fs/webdav/index.js.map +1 -0
  64. package/lib/jsonschema/JsonSchema.js +5 -5
  65. package/lib/jsonschema/JsonSchema.js.map +1 -1
  66. package/lib/jsonschema/forEachJsonSchema.js +1 -1
  67. package/lib/jsonschema/forEachJsonSchema.js.map +1 -1
  68. package/lib/jsonschema/types.d.js.map +1 -1
  69. package/lib/meta/defineMetadata.js.map +1 -1
  70. package/lib/orpc/createOpenApiContractClient.js.map +1 -1
  71. package/lib/password/PHC.js +2 -2
  72. package/lib/password/PHC.js.map +1 -1
  73. package/lib/password/createArgon2PasswordAlgorithm.js.map +1 -1
  74. package/lib/password/createBase64PasswordAlgorithm.js +1 -1
  75. package/lib/password/createBase64PasswordAlgorithm.js.map +1 -1
  76. package/lib/password/createBcryptPasswordAlgorithm.js.map +1 -1
  77. package/lib/password/createPBKDF2PasswordAlgorithm.js +1 -1
  78. package/lib/password/createPBKDF2PasswordAlgorithm.js.map +1 -1
  79. package/lib/password/createScryptPasswordAlgorithm.js +3 -3
  80. package/lib/password/createScryptPasswordAlgorithm.js.map +1 -1
  81. package/lib/resource/ListQuery.js.map +1 -1
  82. package/lib/resource/index.js.map +1 -1
  83. package/lib/s3/formatS3Url.js +2 -2
  84. package/lib/s3/formatS3Url.js.map +1 -1
  85. package/lib/s3/parseS3Url.js +1 -1
  86. package/lib/s3/parseS3Url.js.map +1 -1
  87. package/lib/schema/SchemaRegistry.js.map +1 -1
  88. package/lib/schema/TypeSchema.d.js.map +1 -1
  89. package/lib/schema/createSchemaData.js +4 -4
  90. package/lib/schema/createSchemaData.js.map +1 -1
  91. package/lib/schema/findJsonSchemaByPath.js.map +1 -1
  92. package/lib/schema/formatZodError.js +42 -44
  93. package/lib/schema/formatZodError.js.map +1 -1
  94. package/lib/schema/toJsonSchema.js +4 -4
  95. package/lib/schema/toJsonSchema.js.map +1 -1
  96. package/lib/schema/validate.js +1 -1
  97. package/lib/schema/validate.js.map +1 -1
  98. package/lib/utils/buildRedactorFormSchema.js +1 -1
  99. package/lib/utils/buildRedactorFormSchema.js.map +1 -1
  100. package/package.json +32 -13
  101. package/src/ai/qwen3vl/utils.ts +1 -1
  102. package/src/cn/ChineseResidentIdNo.ts +1 -1
  103. package/src/cn/Mod11.ts +1 -1
  104. package/src/cn/__snapshots__/ChineseResidentIdNo.test.ts.snap +1 -1
  105. package/src/cn/__snapshots__/UnifiedSocialCreditCode.test.ts.snap +0 -23
  106. package/src/cn/parseChineseNumber.test.ts +4 -4
  107. package/src/consola/formatLogObject.ts +6 -6
  108. package/src/data/maybeNumber.ts +1 -1
  109. package/src/data/parseSort.test.ts +0 -1
  110. package/src/data/types.d.ts +2 -2
  111. package/src/dayjs/formatDuration.ts +2 -2
  112. package/src/dayjs/resolveRelativeTime.ts +11 -14
  113. package/src/drain3/Drain.test.ts +378 -0
  114. package/src/drain3/Drain.ts +394 -0
  115. package/src/drain3/LogCluster.ts +46 -0
  116. package/src/drain3/Node.ts +53 -0
  117. package/src/drain3/TemplateMiner.ts +246 -0
  118. package/src/drain3/index.ts +36 -0
  119. package/src/drain3/persistence/FilePersistence.ts +24 -0
  120. package/src/drain3/persistence/MemoryPersistence.ts +23 -0
  121. package/src/drain3/persistence/PersistenceHandler.ts +19 -0
  122. package/src/drain3/types.ts +75 -0
  123. package/src/fs/IFileSystem.d.ts +1 -2
  124. package/src/fs/createBrowserFileSystem.ts +7 -5
  125. package/src/fs/createMemoryFileSystem.ts +9 -13
  126. package/src/fs/createSandboxFileSystem.ts +1 -1
  127. package/src/fs/createWebDavFileSystem.ts +28 -10
  128. package/src/fs/createWebFileSystem.ts +242 -0
  129. package/src/fs/findMimeType.ts +1 -4
  130. package/src/fs/index.ts +1 -1
  131. package/src/fs/minio/createMinioFileSystem.ts +1148 -0
  132. package/src/fs/minio/index.ts +1 -0
  133. package/src/fs/orpc/createContractClientFileSystem.ts +5 -5
  134. package/src/fs/orpc/server/createFileSystemContractImpl.ts +1 -1
  135. package/src/fs/s3/createS3MiniFileSystem.ts +119 -78
  136. package/src/fs/s3/s3fs.test.ts +441 -0
  137. package/src/fs/s3/s3mini.test.ts +2 -2
  138. package/src/fs/server/createDatabaseFileSystem.ts +7 -7
  139. package/src/fs/server/createNodeFileSystem.ts +32 -13
  140. package/src/fs/server/dbfs.test.ts +2 -1
  141. package/src/fs/tests/runFileSystemTest.ts +29 -28
  142. package/src/fs/utils.ts +1 -1
  143. package/src/fs/webdav/index.ts +1 -0
  144. package/src/jsonschema/JsonSchema.ts +5 -5
  145. package/src/jsonschema/forEachJsonSchema.ts +1 -1
  146. package/src/jsonschema/types.d.ts +1 -1
  147. package/src/meta/defineMetadata.ts +1 -1
  148. package/src/orpc/createOpenApiContractClient.ts +2 -2
  149. package/src/password/PHC.ts +3 -3
  150. package/src/password/createArgon2PasswordAlgorithm.ts +1 -1
  151. package/src/password/createBase64PasswordAlgorithm.ts +2 -2
  152. package/src/password/createBcryptPasswordAlgorithm.ts +4 -2
  153. package/src/password/createPBKDF2PasswordAlgorithm.ts +2 -2
  154. package/src/password/createScryptPasswordAlgorithm.ts +4 -4
  155. package/src/resource/ListQuery.ts +4 -1
  156. package/src/resource/index.ts +2 -2
  157. package/src/s3/formatS3Url.test.ts +1 -1
  158. package/src/s3/formatS3Url.ts +2 -2
  159. package/src/s3/parseS3Url.ts +1 -1
  160. package/src/schema/SchemaRegistry.ts +1 -1
  161. package/src/schema/TypeSchema.d.ts +6 -6
  162. package/src/schema/createSchemaData.ts +4 -4
  163. package/src/schema/findJsonSchemaByPath.ts +4 -4
  164. package/src/schema/formatZodError.test.ts +2 -1
  165. package/src/schema/formatZodError.ts +50 -62
  166. package/src/schema/toJsonSchema.ts +6 -6
  167. package/src/schema/validate.ts +1 -1
  168. package/src/utils/buildRedactorFormSchema.ts +3 -3
@@ -1,7 +1,16 @@
1
- import { ZodError } from 'zod/v4';
1
+ import type { core, ZodError } from 'zod/v4';
2
2
  import { findJsonSchemaByPath } from './findJsonSchemaByPath';
3
3
  import type { TypeSchema } from './TypeSchema';
4
4
 
5
+ // Zod 4 issue types with proper typing
6
+ type ZodIssue = core.$ZodIssue;
7
+ type ZodIssueInvalidType = core.$ZodIssueInvalidType;
8
+ type ZodIssueTooSmall = core.$ZodIssueTooSmall;
9
+ type ZodIssueTooBig = core.$ZodIssueTooBig;
10
+ type ZodIssueInvalidStringFormat = core.$ZodIssueInvalidStringFormat;
11
+ type ZodIssueInvalidValue = core.$ZodIssueInvalidValue;
12
+ type ZodIssueUnrecognizedKeys = core.$ZodIssueUnrecognizedKeys;
13
+
5
14
  export function formatZodError(error: ZodError, schema?: TypeSchema): string {
6
15
  if (!error.issues || error.issues.length === 0) {
7
16
  return error.message || '验证失败';
@@ -34,102 +43,81 @@ export function formatZodError(error: ZodError, schema?: TypeSchema): string {
34
43
  return messages.join(';');
35
44
  }
36
45
 
37
- function formatIssueMessage(issue: ZodError['issues'][number], schema?: TypeSchema): string {
46
+ function formatIssueMessage(issue: ZodIssue, _schema?: TypeSchema): string {
38
47
  let message = issue.message;
39
48
 
40
49
  // 处理常见的错误类型,生成更友好的消息
41
- // Use string comparison to avoid TypeScript narrowing issues with Zod v4
42
- const code = issue.code as string;
43
- switch (code) {
50
+ switch (issue.code) {
44
51
  case 'invalid_type': {
45
- const invalidTypeIssue = issue as typeof issue & {
46
- expected: string;
47
- received: string;
48
- };
49
- if (invalidTypeIssue.received === 'undefined') {
52
+ const i = issue as ZodIssueInvalidType;
53
+ // Zod v4 doesn't have 'received' field directly, extract from message
54
+ const match = issue.message.match(/received (\w+)/);
55
+ const received = match?.[1];
56
+ if (received === 'undefined') {
50
57
  message = '必填';
51
- } else if (invalidTypeIssue.received === 'null') {
58
+ } else if (received === 'null') {
52
59
  message = '不能为空';
53
60
  } else {
54
- message = issue.message || `期望类型 ${invalidTypeIssue.expected},但收到 ${invalidTypeIssue.received}`;
61
+ message = issue.message || `期望类型 ${i.expected},但收到 ${received}`;
55
62
  }
56
63
  break;
57
64
  }
58
- case 'invalid_string': {
59
- const invalidStringIssue = issue as typeof issue & {
60
- validation?: string;
61
- };
62
- if (invalidStringIssue.validation === 'email') {
65
+ case 'invalid_format': {
66
+ const i = issue as ZodIssueInvalidStringFormat;
67
+ if (i.format === 'email') {
63
68
  message = '请输入有效的邮箱地址';
64
- } else if (invalidStringIssue.validation === 'url') {
69
+ } else if (i.format === 'url') {
65
70
  message = '请输入有效的 URL';
66
- } else if (invalidStringIssue.validation === 'uuid') {
71
+ } else if (i.format === 'uuid') {
67
72
  message = '请输入有效的 UUID';
68
- } else if (invalidStringIssue.validation === 'date') {
73
+ } else if (i.format === 'date') {
69
74
  message = '请输入有效的日期';
70
75
  }
71
76
  break;
72
77
  }
73
78
  case 'too_small': {
74
- const tooSmallIssue = issue as typeof issue & {
75
- type: string;
76
- minimum: number;
77
- };
78
- if (tooSmallIssue.type === 'string' && tooSmallIssue.minimum === 1) {
79
+ const i = issue as ZodIssueTooSmall;
80
+ if (i.origin === 'string' && i.minimum === 1) {
79
81
  message = '不能为空';
80
- } else if (tooSmallIssue.type === 'number') {
81
- message = `至少需要 ${tooSmallIssue.minimum}`;
82
- } else if (tooSmallIssue.type === 'array') {
83
- message = `至少需要 ${tooSmallIssue.minimum} 项`;
82
+ } else if (i.origin === 'string') {
83
+ message = `至少需要 ${i.minimum} 个字符`;
84
+ } else if (i.origin === 'number' || i.origin === 'int') {
85
+ message = `至少需要 ${i.minimum}`;
86
+ } else if (i.origin === 'array') {
87
+ message = `至少需要 ${i.minimum} 项`;
84
88
  }
85
89
  break;
86
90
  }
87
91
  case 'too_big': {
88
- const tooBigIssue = issue as typeof issue & {
89
- type: string;
90
- maximum: number;
91
- };
92
- if (tooBigIssue.type === 'string') {
93
- message = `最多 ${tooBigIssue.maximum} 个字符`;
94
- } else if (tooBigIssue.type === 'number') {
95
- message = `最多 ${tooBigIssue.maximum}`;
96
- } else if (tooBigIssue.type === 'array') {
97
- message = `最多 ${tooBigIssue.maximum} 项`;
92
+ const i = issue as ZodIssueTooBig;
93
+ if (i.origin === 'string') {
94
+ message = `最多 ${i.maximum} 个字符`;
95
+ } else if (i.origin === 'number' || i.origin === 'int') {
96
+ message = `最多 ${i.maximum}`;
97
+ } else if (i.origin === 'array') {
98
+ message = `最多 ${i.maximum} 项`;
98
99
  }
99
100
  break;
100
101
  }
101
- case 'invalid_enum_value': {
102
- const enumIssue = issue as typeof issue & {
103
- options: readonly unknown[];
104
- };
105
- message = `必须是以下值之一: ${enumIssue.options?.map(String).join(', ') || '未知选项'}`;
102
+ case 'invalid_value': {
103
+ const i = issue as ZodIssueInvalidValue;
104
+ if (i.values.length === 1) {
105
+ // Single value means it's a literal check
106
+ message = `必须是 ${String(i.values[0])}`;
107
+ } else {
108
+ message = `必须是以下值之一: ${i.values.map(String).join(', ')}`;
109
+ }
106
110
  break;
107
111
  }
108
112
  case 'unrecognized_keys': {
109
- const unrecognizedIssue = issue as typeof issue & {
110
- keys: readonly string[];
111
- };
112
- message = `不支持的字段: ${unrecognizedIssue.keys?.join(', ') || '未知字段'}`;
113
+ const i = issue as ZodIssueUnrecognizedKeys;
114
+ message = `不支持的字段: ${i.keys.join(', ')}`;
113
115
  break;
114
116
  }
115
117
  case 'invalid_union': {
116
118
  message = '不符合任何允许的类型';
117
119
  break;
118
120
  }
119
- case 'invalid_union_discriminator': {
120
- const discriminatorIssue = issue as typeof issue & {
121
- options: readonly unknown[];
122
- };
123
- message = `必须是以下值之一: ${discriminatorIssue.options?.map(String).join(', ') || '未知选项'}`;
124
- break;
125
- }
126
- case 'invalid_literal': {
127
- const literalIssue = issue as typeof issue & {
128
- expected: unknown;
129
- };
130
- message = `必须是 ${String(literalIssue.expected)}`;
131
- break;
132
- }
133
121
  case 'custom': {
134
122
  // 保留自定义错误消息
135
123
  message = issue.message;
@@ -33,7 +33,7 @@ export function toJsonSchema(schema: TypeSchema): JsonSchemaDef {
33
33
  // prefer nullable
34
34
  match(js)
35
35
  .with({ anyOf: [P.select(), { type: 'null' }] }, (select) => {
36
- delete js['anyOf'];
36
+ delete js.anyOf;
37
37
  Object.assign(js, select);
38
38
  js.nullable = true;
39
39
  })
@@ -70,9 +70,9 @@ function visit(js: JsonSchemaDef, f: (js: JsonSchemaDef) => void) {
70
70
  const _visit = (
71
71
  js: JsonSchemaDef,
72
72
  f: (js: JsonSchemaDef) => void,
73
- parent: JsonSchemaDef | undefined,
73
+ _parent: JsonSchemaDef | undefined,
74
74
  path: string[],
75
- k?: string,
75
+ _k?: string,
76
76
  ) => {
77
77
  if (!js) {
78
78
  return;
@@ -109,9 +109,9 @@ function visit(js: JsonSchemaDef, f: (js: JsonSchemaDef) => void) {
109
109
  _visit(js, f, undefined, []);
110
110
  }
111
111
 
112
- function resolveJsonSchemaDef(
112
+ function _resolveJsonSchemaDef(
113
113
  js: JsonSchemaDef,
114
- ctx?: {
114
+ _ctx?: {
115
115
  parent: JsonSchemaDef;
116
116
  key: string;
117
117
  },
@@ -129,7 +129,7 @@ function resolveJsonSchemaDef(
129
129
  for (const key in schema.properties) {
130
130
  const prop = schema.properties[key];
131
131
  if (prop) {
132
- schema.properties[key] = resolveJsonSchemaDef(prop, { parent: schema, key });
132
+ schema.properties[key] = _resolveJsonSchemaDef(prop, { parent: schema, key });
133
133
  }
134
134
  }
135
135
  return schema;
@@ -107,7 +107,7 @@ export function parseData<S extends TypeSchema>(schema: S, data: unknown): Schem
107
107
  );
108
108
  }
109
109
 
110
- function formatIssues(schema: TypeSchema, issues: Array<ValidationIssue>): string {
110
+ function _formatIssues(_schema: TypeSchema, _issues: Array<ValidationIssue>): string {
111
111
  return '';
112
112
  }
113
113
 
@@ -60,10 +60,10 @@ export function buildRedactorFormSchema(
60
60
  };
61
61
  }
62
62
 
63
- function buildReversibleRedactText({
63
+ function _buildReversibleRedactText({
64
64
  id,
65
- type,
66
- key,
65
+ type: _type,
66
+ key: _key,
67
67
  timestamp,
68
68
  }: {
69
69
  id?: string | number;