@wener/common 2.0.3 → 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.
- package/lib/ai/qwen3vl/index.js +1 -1
- package/lib/ai/qwen3vl/utils.js +15 -15
- package/lib/ai/qwen3vl/utils.js.map +1 -1
- package/lib/ai/vision/DocLayoutElementTypeSchema.js +22 -22
- package/lib/ai/vision/ImageAnnotationSchema.js +63 -47
- package/lib/ai/vision/index.js +2 -2
- package/lib/ai/vision/resolveImageAnnotation.js +81 -95
- package/lib/cn/ChineseResidentIdNo.js +55 -41
- package/lib/cn/ChineseResidentIdNo.js.map +1 -1
- package/lib/cn/ChineseResidentIdNo.mod.js +6 -1
- package/lib/cn/ChineseResidentIdNo.test.js +22 -21
- package/lib/cn/DivisionCode.js +220 -235
- package/lib/cn/DivisionCode.mod.js +6 -1
- package/lib/cn/DivisionCode.test.js +92 -121
- package/lib/cn/Mod11.js +18 -37
- package/lib/cn/Mod11.js.map +1 -1
- package/lib/cn/Mod31.js +23 -41
- package/lib/cn/UnifiedSocialCreditCode.js +143 -137
- package/lib/cn/UnifiedSocialCreditCode.mod.js +6 -1
- package/lib/cn/UnifiedSocialCreditCode.test.js +21 -15
- package/lib/cn/formatChineseAmount.js +46 -71
- package/lib/cn/index.js +6 -6
- package/lib/cn/mod.js +5 -3
- package/lib/cn/parseChineseNumber.js +81 -85
- package/lib/cn/parseChineseNumber.test.js +183 -261
- package/lib/cn/pinyin/cartesianProduct.js +19 -19
- package/lib/cn/pinyin/cartesianProduct.test.js +78 -178
- package/lib/cn/pinyin/loader.js +13 -11
- package/lib/cn/pinyin/preload.js +2 -1
- package/lib/cn/pinyin/toPinyin.test.js +149 -161
- package/lib/cn/pinyin/toPinyinPure.js +28 -23
- package/lib/cn/pinyin/transform.js +11 -11
- package/lib/cn/types.d.js +2 -2
- package/lib/consola/createStandardConsolaReporter.js +14 -15
- package/lib/consola/formatLogObject.js +149 -133
- package/lib/consola/formatLogObject.js.map +1 -1
- package/lib/consola/formatLogObject.test.js +167 -178
- package/lib/consola/index.js +2 -2
- package/lib/data/formatSort.js +14 -12
- package/lib/data/formatSort.test.js +33 -33
- package/lib/data/index.js +3 -3
- package/lib/data/maybeNumber.js +23 -23
- package/lib/data/maybeNumber.js.map +1 -1
- package/lib/data/parseSort.js +75 -68
- package/lib/data/parseSort.test.js +196 -187
- package/lib/data/resolvePagination.js +38 -39
- package/lib/data/resolvePagination.test.js +228 -218
- package/lib/data/types.d.js +2 -2
- package/lib/data/types.d.js.map +1 -1
- package/lib/dayjs/dayjs.js +20 -20
- package/lib/dayjs/formatDuration.js +56 -56
- package/lib/dayjs/formatDuration.js.map +1 -1
- package/lib/dayjs/formatDuration.test.js +63 -77
- package/lib/dayjs/index.js +4 -4
- package/lib/dayjs/parseDuration.js +21 -26
- package/lib/dayjs/parseRelativeTime.js +65 -66
- package/lib/dayjs/parseRelativeTime.test.js +227 -243
- package/lib/dayjs/resolveRelativeTime.js +74 -144
- package/lib/dayjs/resolveRelativeTime.js.map +1 -1
- package/lib/dayjs/resolveRelativeTime.test.js +296 -307
- package/lib/decimal/index.js +1 -1
- package/lib/decimal/parseDecimal.js +12 -12
- package/lib/drain3/Drain.js +321 -0
- package/lib/drain3/Drain.js.map +1 -0
- package/lib/drain3/LogCluster.js +38 -0
- package/lib/drain3/LogCluster.js.map +1 -0
- package/lib/drain3/Node.js +39 -0
- package/lib/drain3/Node.js.map +1 -0
- package/lib/drain3/TemplateMiner.js +205 -0
- package/lib/drain3/TemplateMiner.js.map +1 -0
- package/lib/drain3/index.js +31 -0
- package/lib/drain3/index.js.map +1 -0
- package/lib/drain3/persistence/FilePersistence.js +24 -0
- package/lib/drain3/persistence/FilePersistence.js.map +1 -0
- package/lib/drain3/persistence/MemoryPersistence.js +18 -0
- package/lib/drain3/persistence/MemoryPersistence.js.map +1 -0
- package/lib/drain3/persistence/PersistenceHandler.js +5 -0
- package/lib/drain3/persistence/PersistenceHandler.js.map +1 -0
- package/lib/drain3/types.js +7 -0
- package/lib/drain3/types.js.map +1 -0
- package/lib/emittery/emitter.js +7 -7
- package/lib/emittery/index.js +1 -1
- package/lib/foundation/schema/SexType.js +15 -12
- package/lib/foundation/schema/index.js +1 -1
- package/lib/foundation/schema/parseSexType.js +15 -16
- package/lib/foundation/schema/types.js +8 -6
- package/lib/fs/FileSystemError.js +18 -18
- package/lib/fs/IFileSystem.d.js +2 -2
- package/lib/fs/IFileSystem.d.js.map +1 -1
- package/lib/fs/MemoryFileSystem.test.js +172 -181
- package/lib/fs/createBrowserFileSystem.js +222 -233
- package/lib/fs/createBrowserFileSystem.js.map +1 -1
- package/lib/fs/createMemoryFileSystem.js +473 -510
- package/lib/fs/createMemoryFileSystem.js.map +1 -1
- package/lib/fs/createSandboxFileSystem.js +102 -101
- package/lib/fs/createSandboxFileSystem.js.map +1 -1
- package/lib/fs/createWebDavFileSystem.js +162 -132
- package/lib/fs/createWebDavFileSystem.js.map +1 -1
- package/lib/fs/createWebFileSystem.js +202 -0
- package/lib/fs/createWebFileSystem.js.map +1 -0
- package/lib/fs/findMimeType.js +14 -14
- package/lib/fs/findMimeType.js.map +1 -1
- package/lib/fs/index.js +7 -7
- package/lib/fs/index.js.map +1 -1
- package/lib/fs/minio/createMinioFileSystem.js +977 -0
- package/lib/fs/minio/createMinioFileSystem.js.map +1 -0
- package/lib/fs/minio/index.js +2 -0
- package/lib/fs/minio/index.js.map +1 -0
- package/lib/fs/orpc/FileSystemContract.js +57 -57
- package/lib/fs/orpc/createContractClientFileSystem.js +88 -88
- package/lib/fs/orpc/createContractClientFileSystem.js.map +1 -1
- package/lib/fs/orpc/index.js +2 -2
- package/lib/fs/orpc/server/createFileSystemContractImpl.js +62 -60
- package/lib/fs/orpc/server/createFileSystemContractImpl.js.map +1 -1
- package/lib/fs/orpc/server/index.js +1 -1
- package/lib/fs/s3/createS3MiniFileSystem.js +756 -689
- package/lib/fs/s3/createS3MiniFileSystem.js.map +1 -1
- package/lib/fs/s3/index.js +1 -1
- package/lib/fs/s3/s3mini.test.js +524 -553
- package/lib/fs/scandir.js +56 -56
- package/lib/fs/server/createDatabaseFileSystem.js +834 -741
- package/lib/fs/server/createDatabaseFileSystem.js.map +1 -1
- package/lib/fs/server/createNodeFileSystem.js +407 -380
- package/lib/fs/server/createNodeFileSystem.js.map +1 -1
- package/lib/fs/server/dbfs.test.js +201 -214
- package/lib/fs/server/index.js +1 -1
- package/lib/fs/server/loadTestDatabase.js +40 -43
- package/lib/fs/tests/runFileSystemTest.js +352 -315
- package/lib/fs/tests/runFileSystemTest.js.map +1 -1
- package/lib/fs/types.js +17 -20
- package/lib/fs/utils/getFileUrl.js +24 -30
- package/lib/fs/utils.js +17 -17
- package/lib/fs/utils.js.map +1 -1
- package/lib/fs/webdav/index.js +2 -0
- package/lib/fs/webdav/index.js.map +1 -0
- package/lib/index.js +2 -2
- package/lib/jsonschema/JsonSchema.js +216 -155
- package/lib/jsonschema/JsonSchema.js.map +1 -1
- package/lib/jsonschema/JsonSchema.test.js +123 -124
- package/lib/jsonschema/forEachJsonSchema.js +41 -41
- package/lib/jsonschema/forEachJsonSchema.js.map +1 -1
- package/lib/jsonschema/index.js +2 -2
- package/lib/jsonschema/types.d.js +2 -2
- package/lib/jsonschema/types.d.js.map +1 -1
- package/lib/meta/defineFileType.js +32 -38
- package/lib/meta/defineInit.js +39 -35
- package/lib/meta/defineMetadata.js +37 -34
- package/lib/meta/defineMetadata.js.map +1 -1
- package/lib/meta/defineMetadata.test.js +13 -12
- package/lib/meta/index.js +3 -3
- package/lib/orpc/createOpenApiContractClient.js +26 -24
- package/lib/orpc/createOpenApiContractClient.js.map +1 -1
- package/lib/orpc/createRpcContractClient.js +37 -31
- package/lib/orpc/index.js +2 -2
- package/lib/orpc/resolveLinkPlugins.js +25 -25
- package/lib/password/PHC.js +187 -189
- package/lib/password/PHC.js.map +1 -1
- package/lib/password/PHC.test.js +517 -535
- package/lib/password/Password.js +85 -80
- package/lib/password/Password.test.js +330 -364
- package/lib/password/createArgon2PasswordAlgorithm.js +50 -51
- package/lib/password/createArgon2PasswordAlgorithm.js.map +1 -1
- package/lib/password/createBase64PasswordAlgorithm.js +11 -11
- package/lib/password/createBase64PasswordAlgorithm.js.map +1 -1
- package/lib/password/createBcryptPasswordAlgorithm.js +20 -18
- package/lib/password/createBcryptPasswordAlgorithm.js.map +1 -1
- package/lib/password/createPBKDF2PasswordAlgorithm.js +65 -52
- package/lib/password/createPBKDF2PasswordAlgorithm.js.map +1 -1
- package/lib/password/createScryptPasswordAlgorithm.js +74 -63
- package/lib/password/createScryptPasswordAlgorithm.js.map +1 -1
- package/lib/password/index.js +5 -5
- package/lib/password/server/index.js +1 -1
- package/lib/resource/Identifiable.js +2 -2
- package/lib/resource/ListQuery.js +42 -42
- package/lib/resource/ListQuery.js.map +1 -1
- package/lib/resource/getTitleOfResource.js +5 -5
- package/lib/resource/index.js +2 -2
- package/lib/resource/index.js.map +1 -1
- package/lib/resource/schema/AnyResourceSchema.js +91 -89
- package/lib/resource/schema/BaseResourceSchema.js +26 -26
- package/lib/resource/schema/ResourceActionType.js +117 -115
- package/lib/resource/schema/ResourceStatus.js +94 -92
- package/lib/resource/schema/ResourceType.js +25 -23
- package/lib/resource/schema/index.js +5 -5
- package/lib/resource/schema/types.js +86 -55
- package/lib/resource/schema/types.test.js +16 -13
- package/lib/s3/formatS3Url.js +60 -60
- package/lib/s3/formatS3Url.js.map +1 -1
- package/lib/s3/formatS3Url.test.js +238 -261
- package/lib/s3/index.js +2 -2
- package/lib/s3/parseS3Url.js +61 -60
- package/lib/s3/parseS3Url.js.map +1 -1
- package/lib/s3/parseS3Url.test.js +270 -269
- package/lib/schema/SchemaRegistry.js +41 -42
- package/lib/schema/SchemaRegistry.js.map +1 -1
- package/lib/schema/SchemaRegistry.mod.js +1 -1
- package/lib/schema/TypeSchema.d.js +2 -2
- package/lib/schema/TypeSchema.d.js.map +1 -1
- package/lib/schema/createSchemaData.js +113 -67
- package/lib/schema/createSchemaData.js.map +1 -1
- package/lib/schema/findJsonSchemaByPath.js +28 -23
- package/lib/schema/findJsonSchemaByPath.js.map +1 -1
- package/lib/schema/formatZodError.js +113 -134
- package/lib/schema/formatZodError.js.map +1 -1
- package/lib/schema/formatZodError.test.js +192 -195
- package/lib/schema/getSchemaCache.js +7 -7
- package/lib/schema/getSchemaOptions.js +17 -16
- package/lib/schema/index.js +6 -6
- package/lib/schema/toJsonSchema.js +196 -190
- package/lib/schema/toJsonSchema.js.map +1 -1
- package/lib/schema/toJsonSchema.test.js +34 -26
- package/lib/schema/validate.js +106 -97
- package/lib/schema/validate.js.map +1 -1
- package/lib/tools/generateSchema.js +40 -40
- package/lib/tools/renderJsonSchemaToMarkdownDoc.js +74 -74
- package/lib/utils/buildBaseUrl.js +8 -8
- package/lib/utils/buildRedactorFormSchema.js +55 -54
- package/lib/utils/buildRedactorFormSchema.js.map +1 -1
- package/lib/utils/getEstimateProcessTime.js +24 -19
- package/lib/utils/index.js +3 -3
- package/lib/utils/resolveFeatureOptions.js +9 -9
- package/package.json +37 -18
- package/src/ai/qwen3vl/utils.ts +1 -1
- package/src/ai/vision/index.ts +2 -2
- package/src/cn/ChineseResidentIdNo.ts +1 -1
- package/src/cn/Mod11.ts +1 -1
- package/src/cn/__snapshots__/ChineseResidentIdNo.test.ts.snap +1 -1
- package/src/cn/__snapshots__/UnifiedSocialCreditCode.test.ts.snap +0 -23
- package/src/cn/index.ts +1 -2
- package/src/cn/parseChineseNumber.test.ts +4 -4
- package/src/consola/formatLogObject.ts +6 -6
- package/src/consola/index.ts +1 -1
- package/src/data/index.ts +3 -4
- package/src/data/maybeNumber.ts +1 -1
- package/src/data/parseSort.test.ts +0 -1
- package/src/data/resolvePagination.ts +2 -2
- package/src/data/types.d.ts +2 -2
- package/src/dayjs/formatDuration.ts +10 -11
- package/src/dayjs/index.ts +1 -1
- package/src/dayjs/parseRelativeTime.ts +1 -1
- package/src/dayjs/resolveRelativeTime.ts +11 -14
- package/src/drain3/Drain.test.ts +378 -0
- package/src/drain3/Drain.ts +394 -0
- package/src/drain3/LogCluster.ts +46 -0
- package/src/drain3/Node.ts +53 -0
- package/src/drain3/TemplateMiner.ts +246 -0
- package/src/drain3/index.ts +34 -0
- package/src/drain3/persistence/FilePersistence.ts +24 -0
- package/src/drain3/persistence/MemoryPersistence.ts +23 -0
- package/src/drain3/persistence/PersistenceHandler.ts +19 -0
- package/src/drain3/types.ts +75 -0
- package/src/fs/IFileSystem.d.ts +1 -2
- package/src/fs/createBrowserFileSystem.ts +7 -5
- package/src/fs/createMemoryFileSystem.ts +9 -13
- package/src/fs/createSandboxFileSystem.ts +1 -1
- package/src/fs/createWebDavFileSystem.ts +30 -17
- package/src/fs/createWebFileSystem.ts +242 -0
- package/src/fs/findMimeType.ts +1 -4
- package/src/fs/index.ts +5 -5
- package/src/fs/minio/createMinioFileSystem.ts +1148 -0
- package/src/fs/minio/index.ts +1 -0
- package/src/fs/orpc/createContractClientFileSystem.ts +5 -5
- package/src/fs/orpc/server/createFileSystemContractImpl.ts +1 -1
- package/src/fs/s3/createS3MiniFileSystem.ts +120 -79
- package/src/fs/s3/s3fs.test.ts +441 -0
- package/src/fs/s3/s3mini.test.ts +2 -2
- package/src/fs/server/createDatabaseFileSystem.ts +78 -114
- package/src/fs/server/createNodeFileSystem.ts +32 -13
- package/src/fs/server/dbfs.test.ts +13 -8
- package/src/fs/server/index.ts +1 -0
- package/src/fs/server/loadTestDatabase.ts +8 -119
- package/src/fs/tests/runFileSystemTest.ts +29 -28
- package/src/fs/utils.ts +1 -1
- package/src/fs/webdav/index.ts +1 -0
- package/src/jsonschema/JsonSchema.ts +5 -5
- package/src/jsonschema/forEachJsonSchema.ts +1 -1
- package/src/jsonschema/index.ts +1 -1
- package/src/jsonschema/types.d.ts +1 -1
- package/src/meta/defineMetadata.ts +1 -1
- package/src/meta/index.ts +2 -3
- package/src/orm/createSqliteDialect.ts +17 -0
- package/src/orm/index.ts +1 -0
- package/src/orpc/createOpenApiContractClient.ts +3 -3
- package/src/orpc/index.ts +1 -1
- package/src/password/PHC.ts +3 -3
- package/src/password/createArgon2PasswordAlgorithm.ts +2 -2
- package/src/password/createBase64PasswordAlgorithm.ts +2 -2
- package/src/password/createBcryptPasswordAlgorithm.ts +4 -2
- package/src/password/createPBKDF2PasswordAlgorithm.ts +2 -2
- package/src/password/createScryptPasswordAlgorithm.ts +4 -4
- package/src/password/index.ts +2 -2
- package/src/resource/ListQuery.ts +4 -1
- package/src/resource/index.ts +3 -3
- package/src/resource/schema/index.ts +4 -4
- package/src/s3/formatS3Url.test.ts +1 -1
- package/src/s3/formatS3Url.ts +2 -2
- package/src/s3/index.ts +1 -1
- package/src/s3/parseS3Url.ts +1 -1
- package/src/schema/SchemaRegistry.ts +2 -2
- package/src/schema/TypeSchema.d.ts +6 -6
- package/src/schema/createSchemaData.ts +5 -5
- package/src/schema/findJsonSchemaByPath.ts +5 -5
- package/src/schema/formatZodError.test.ts +2 -1
- package/src/schema/formatZodError.ts +50 -62
- package/src/schema/index.ts +5 -5
- package/src/schema/toJsonSchema.ts +6 -6
- package/src/schema/validate.ts +2 -2
- package/src/utils/buildRedactorFormSchema.ts +4 -4
- package/src/utils/formatNumber.ts +18 -0
- package/src/utils/formatPercent.ts +17 -0
- package/src/utils/index.ts +3 -3
- package/src/utils/resolveFeatureOptions.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/buildRedactorFormSchema.ts"],"sourcesContent":["import { forEachJsonSchema, type JsonSchemaDef } from '../jsonschema';\nimport { toJsonSchema, type TypeSchema } from '../schema';\n\nexport const RedactedText = '[redacted]';\n\nexport function buildRedactorFormSchema(\n\tts: TypeSchema,\n\t{\n\t\tshouldRedact = (schema) => schema['x-sensitive'] === true,\n\t\treplacer = () => RedactedText,\n\t}: {\n\t\tshouldRedact?: (schema: JsonSchemaDef) => boolean;\n\t\treplacer?: (key: string, value: any) => any;\n\t},\n) {\n\tlet js = toJsonSchema(ts);\n\n\tlet paths: string[][] = [];\n\n\tforEachJsonSchema(js, (js, { path }) => {\n\t\tif (shouldRedact(js)) {\n\t\t\tpaths.push(path);\n\t\t}\n\t});\n\tconst vis = (root: any, path: string[]) => {\n\t\tswitch (root) {\n\t\t\tcase null:\n\t\t\tcase undefined:\n\t\t\t\treturn;\n\t\t}\n\n\t\tlet c = root;\n\t\tfor (let i = 0; i < path.length; i++) {\n\t\t\tlet k = path[i];\n\t\t\tif (c && typeof c === 'object' && k in c) {\n\t\t\t\tlet v = c[k];\n\t\t\t\tif (path.length === 1) {\n\t\t\t\t\tc[k] = replacer(k, v);\n\t\t\t\t} else if (Array.isArray(v)) {\n\t\t\t\t\tfor (let vv of v) {\n\t\t\t\t\t\tvis(vv, path.slice(i + 1));\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tvis(v, path.slice(i + 1));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t};\n\n\treturn (root: any) => {\n\t\tif (!paths.length) {\n\t\t\treturn root;\n\t\t}\n\n\t\tpaths.forEach((path) => {\n\t\t\tvis(root, path);\n\t\t});\n\n\t\treturn root;\n\t};\n}\n\nfunction
|
|
1
|
+
{"version":3,"sources":["../../src/utils/buildRedactorFormSchema.ts"],"sourcesContent":["import { forEachJsonSchema, type JsonSchemaDef } from '../jsonschema';\nimport { toJsonSchema, type TypeSchema } from '../schema';\n\nexport const RedactedText = '[redacted]';\n\nexport function buildRedactorFormSchema(\n\tts: TypeSchema,\n\t{\n\t\tshouldRedact = (schema) => schema['x-sensitive'] === true,\n\t\treplacer = () => RedactedText,\n\t}: {\n\t\tshouldRedact?: (schema: JsonSchemaDef) => boolean;\n\t\treplacer?: (key: string, value: any) => any;\n\t},\n) {\n\tlet js = toJsonSchema(ts);\n\n\tlet paths: string[][] = [];\n\n\tforEachJsonSchema(js, (js, { path }) => {\n\t\tif (shouldRedact(js)) {\n\t\t\tpaths.push(path);\n\t\t}\n\t});\n\tconst vis = (root: any, path: string[]) => {\n\t\tswitch (root) {\n\t\t\tcase null:\n\t\t\tcase undefined:\n\t\t\t\treturn;\n\t\t}\n\n\t\tlet c = root;\n\t\tfor (let i = 0; i < path.length; i++) {\n\t\t\tlet k = path[i];\n\t\t\tif (c && typeof c === 'object' && k in c) {\n\t\t\t\tlet v = c[k];\n\t\t\t\tif (path.length === 1) {\n\t\t\t\t\tc[k] = replacer(k, v);\n\t\t\t\t} else if (Array.isArray(v)) {\n\t\t\t\t\tfor (let vv of v) {\n\t\t\t\t\t\tvis(vv, path.slice(i + 1));\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tvis(v, path.slice(i + 1));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t};\n\n\treturn (root: any) => {\n\t\tif (!paths.length) {\n\t\t\treturn root;\n\t\t}\n\n\t\tpaths.forEach((path) => {\n\t\t\tvis(root, path);\n\t\t});\n\n\t\treturn root;\n\t};\n}\n\nfunction _buildReversibleRedactText({\n\tid,\n\ttype: _type,\n\tkey: _key,\n\ttimestamp,\n}: {\n\tid?: string | number;\n\ttype?: string;\n\tkey?: string;\n\ttimestamp?: number | boolean;\n} = {}) {\n\tif (!id) {\n\t\treturn RedactedText;\n\t}\n\tif (timestamp === true) {\n\t\ttimestamp = Date.now();\n\t}\n\treturn `[redacted ${id}]`;\n}\n\nexport function isRedactedText(v: any) {\n\treturn v === RedactedText || (typeof v === 'string' && v.startsWith('[redacted ') && v.endsWith(']'));\n}\n"],"names":["forEachJsonSchema","toJsonSchema","RedactedText","buildRedactorFormSchema","ts","shouldRedact","schema","replacer","js","paths","path","push","vis","root","undefined","c","i","length","k","v","Array","isArray","vv","slice","forEach","_buildReversibleRedactText","id","type","_type","key","_key","timestamp","Date","now","isRedactedText","startsWith","endsWith"],"mappings":"AAAA,SAASA,iBAAiB,QAA4B,gBAAgB;AACtE,SAASC,YAAY,QAAyB,YAAY;AAE1D,OAAO,MAAMC,eAAe,aAAa;AAEzC,OAAO,SAASC,wBACfC,EAAc,EACd,EACCC,eAAe,CAACC,SAAWA,MAAM,CAAC,cAAc,KAAK,IAAI,EACzDC,WAAW,IAAML,YAAY,EAI7B;IAED,IAAIM,KAAKP,aAAaG;IAEtB,IAAIK,QAAoB,EAAE;IAE1BT,kBAAkBQ,IAAI,CAACA,IAAI,EAAEE,IAAI,EAAE;QAClC,IAAIL,aAAaG,KAAK;YACrBC,MAAME,IAAI,CAACD;QACZ;IACD;IACA,MAAME,MAAM,CAACC,MAAWH;QACvB,OAAQG;YACP,KAAK;YACL,KAAKC;gBACJ;QACF;QAEA,IAAIC,IAAIF;QACR,IAAK,IAAIG,IAAI,GAAGA,IAAIN,KAAKO,MAAM,EAAED,IAAK;YACrC,IAAIE,IAAIR,IAAI,CAACM,EAAE;YACf,IAAID,KAAK,OAAOA,MAAM,YAAYG,KAAKH,GAAG;gBACzC,IAAII,IAAIJ,CAAC,CAACG,EAAE;gBACZ,IAAIR,KAAKO,MAAM,KAAK,GAAG;oBACtBF,CAAC,CAACG,EAAE,GAAGX,SAASW,GAAGC;gBACpB,OAAO,IAAIC,MAAMC,OAAO,CAACF,IAAI;oBAC5B,KAAK,IAAIG,MAAMH,EAAG;wBACjBP,IAAIU,IAAIZ,KAAKa,KAAK,CAACP,IAAI;oBACxB;gBACD,OAAO;oBACNJ,IAAIO,GAAGT,KAAKa,KAAK,CAACP,IAAI;gBACvB;YACD;QACD;IACD;IAEA,OAAO,CAACH;QACP,IAAI,CAACJ,MAAMQ,MAAM,EAAE;YAClB,OAAOJ;QACR;QAEAJ,MAAMe,OAAO,CAAC,CAACd;YACdE,IAAIC,MAAMH;QACX;QAEA,OAAOG;IACR;AACD;AAEA,SAASY,2BAA2B,EACnCC,EAAE,EACFC,MAAMC,KAAK,EACXC,KAAKC,IAAI,EACTC,SAAS,EAMT,GAAG,CAAC,CAAC;IACL,IAAI,CAACL,IAAI;QACR,OAAOxB;IACR;IACA,IAAI6B,cAAc,MAAM;QACvBA,YAAYC,KAAKC,GAAG;IACrB;IACA,OAAO,CAAC,UAAU,EAAEP,GAAG,CAAC,CAAC;AAC1B;AAEA,OAAO,SAASQ,eAAef,CAAM;IACpC,OAAOA,MAAMjB,gBAAiB,OAAOiB,MAAM,YAAYA,EAAEgB,UAAU,CAAC,iBAAiBhB,EAAEiB,QAAQ,CAAC;AACjG"}
|
|
@@ -1,21 +1,26 @@
|
|
|
1
|
-
export function getEstimateProcessTime({
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
export function getEstimateProcessTime({
|
|
2
|
+
total,
|
|
3
|
+
processed,
|
|
4
|
+
startTime,
|
|
5
|
+
elapsed = startTime ? (Date.now() - startTime.getTime()) / 1000 : undefined,
|
|
6
|
+
}) {
|
|
7
|
+
if (typeof total !== 'number' || typeof processed !== 'number' || !elapsed || processed === 0 || processed >= total) {
|
|
8
|
+
return undefined;
|
|
9
|
+
}
|
|
10
|
+
const now = new Date();
|
|
11
|
+
const rate = processed / elapsed;
|
|
12
|
+
if (rate === 0) {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
const remaining = total - processed;
|
|
16
|
+
const eta = Math.round(remaining / rate);
|
|
17
|
+
const endTime = new Date(now.getTime() + eta * 1000);
|
|
18
|
+
return {
|
|
19
|
+
eta,
|
|
20
|
+
elapsed,
|
|
21
|
+
endTime,
|
|
22
|
+
rate,
|
|
23
|
+
};
|
|
19
24
|
}
|
|
20
25
|
|
|
21
|
-
//# sourceMappingURL=getEstimateProcessTime.js.map
|
|
26
|
+
//# sourceMappingURL=getEstimateProcessTime.js.map
|
package/lib/utils/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export { buildRedactorFormSchema } from
|
|
3
|
-
export {
|
|
1
|
+
export { buildBaseUrl } from './buildBaseUrl.js';
|
|
2
|
+
export { buildRedactorFormSchema } from './buildRedactorFormSchema.js';
|
|
3
|
+
export { getEstimateProcessTime } from './getEstimateProcessTime.js';
|
|
4
4
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { maybeFunction } from
|
|
1
|
+
import { maybeFunction } from '@wener/utils';
|
|
2
2
|
export function resolveFeatureOptions(value, defaultValue) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
if (value === false) {
|
|
4
|
+
return undefined;
|
|
5
|
+
}
|
|
6
|
+
if (value === true || value === undefined || value === null) {
|
|
7
|
+
return maybeFunction(defaultValue);
|
|
8
|
+
}
|
|
9
|
+
return value;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
//# sourceMappingURL=resolveFeatureOptions.js.map
|
|
12
|
+
//# sourceMappingURL=resolveFeatureOptions.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wener/common",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Common utils for console & server",
|
|
6
6
|
"repository": {
|
|
@@ -36,26 +36,38 @@
|
|
|
36
36
|
"types": "./src/decimal/index.ts",
|
|
37
37
|
"default": "./lib/decimal/index.js"
|
|
38
38
|
},
|
|
39
|
+
"./drain3": {
|
|
40
|
+
"types": "./src/drain3/index.ts",
|
|
41
|
+
"default": "./lib/drain3/index.js"
|
|
42
|
+
},
|
|
39
43
|
"./fs": {
|
|
40
44
|
"types": "./src/fs/index.ts",
|
|
41
45
|
"default": "./lib/fs/index.js"
|
|
42
46
|
},
|
|
43
|
-
"./fs/
|
|
44
|
-
"types": "./src/fs/
|
|
45
|
-
"default": "./lib/fs/
|
|
47
|
+
"./fs/webdav": {
|
|
48
|
+
"types": "./src/fs/webdav/index.ts",
|
|
49
|
+
"default": "./lib/fs/webdav/index.js"
|
|
46
50
|
},
|
|
47
|
-
"./fs/
|
|
48
|
-
"types": "./src/fs/orpc/server/index.ts",
|
|
49
|
-
"default": "./lib/fs/orpc/server/index.js"
|
|
50
|
-
},
|
|
51
|
-
"./fs/s3": {
|
|
51
|
+
"./fs/s3mini": {
|
|
52
52
|
"types": "./src/fs/s3/index.ts",
|
|
53
53
|
"default": "./lib/fs/s3/index.js"
|
|
54
54
|
},
|
|
55
|
+
"./fs/minio": {
|
|
56
|
+
"types": "./src/fs/minio/index.ts",
|
|
57
|
+
"default": "./lib/fs/minio/index.js"
|
|
58
|
+
},
|
|
55
59
|
"./fs/server": {
|
|
56
60
|
"types": "./src/fs/server/index.ts",
|
|
57
61
|
"default": "./lib/fs/server/index.js"
|
|
58
62
|
},
|
|
63
|
+
"./fs/orpc": {
|
|
64
|
+
"types": "./src/fs/orpc/index.ts",
|
|
65
|
+
"default": "./lib/fs/orpc/index.js"
|
|
66
|
+
},
|
|
67
|
+
"./fs/orpc/server": {
|
|
68
|
+
"types": "./src/fs/orpc/server/index.ts",
|
|
69
|
+
"default": "./lib/fs/orpc/server/index.js"
|
|
70
|
+
},
|
|
59
71
|
"./jsonschema": {
|
|
60
72
|
"types": "./src/jsonschema/index.ts",
|
|
61
73
|
"default": "./lib/jsonschema/index.js"
|
|
@@ -109,15 +121,19 @@
|
|
|
109
121
|
"@standard-schema/spec": "^1.1.0",
|
|
110
122
|
"@wener/utils": "^1.1.58",
|
|
111
123
|
"date-fns": "^4.1.0",
|
|
112
|
-
"es-toolkit": "^1.
|
|
124
|
+
"es-toolkit": "^1.45.1",
|
|
113
125
|
"std-env": "^3.10.0",
|
|
114
126
|
"ts-pattern": "^5.9.0"
|
|
115
127
|
},
|
|
116
128
|
"devDependencies": {
|
|
117
|
-
"@
|
|
118
|
-
"@
|
|
119
|
-
"@
|
|
120
|
-
"@
|
|
129
|
+
"@mikro-orm/core": "^7.0.2",
|
|
130
|
+
"@mikro-orm/decorators": "^7.0.2",
|
|
131
|
+
"@mikro-orm/sql": "^7.0.2",
|
|
132
|
+
"@orpc/client": "^1.13.7",
|
|
133
|
+
"@orpc/contract": "^1.13.7",
|
|
134
|
+
"@orpc/openapi-client": "^1.13.7",
|
|
135
|
+
"@orpc/server": "^1.13.7",
|
|
136
|
+
"@sinclair/typebox": "^0.34.48",
|
|
121
137
|
"@sinclair/typebox-codegen": "^0.11.1",
|
|
122
138
|
"@types/argon2-browser": "^1.18.4",
|
|
123
139
|
"@types/bcrypt": "^6.0.0",
|
|
@@ -132,14 +148,17 @@
|
|
|
132
148
|
"bcryptjs": "^3.0.3",
|
|
133
149
|
"chalk": "^5.6.2",
|
|
134
150
|
"consola": "^3.4.2",
|
|
135
|
-
"dayjs": "^1.11.
|
|
151
|
+
"dayjs": "^1.11.20",
|
|
136
152
|
"decimal.js": "^10.6.0",
|
|
137
|
-
"emittery": "^1.2.
|
|
153
|
+
"emittery": "^1.2.1",
|
|
154
|
+
"kysely": "^0.28.11",
|
|
138
155
|
"micromatch": "^4.0.8",
|
|
139
156
|
"mime-types": "^3.0.2",
|
|
157
|
+
"minio": "^8.0.7",
|
|
140
158
|
"pathe": "^2.0.3",
|
|
141
|
-
"s3mini": "^0.
|
|
142
|
-
"
|
|
159
|
+
"s3mini": "^0.9.1",
|
|
160
|
+
"webdav": "^5.9.0",
|
|
161
|
+
"zod": "^4.3.6"
|
|
143
162
|
},
|
|
144
163
|
"scripts": {
|
|
145
164
|
"test": "echo \"Error: no test specified\" && exit 1"
|
package/src/ai/qwen3vl/utils.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
type Bbox2d = [number, number, number, number];
|
|
3
3
|
type Dimensions = { width: number; height: number };
|
|
4
4
|
// x_center, y_center, z_center, x_size, y_size, z_size, roll, pitch, yaw
|
|
5
|
-
type
|
|
5
|
+
type _Bbox3d = [number, number, number, number, number, number, number, number, number];
|
|
6
6
|
/**
|
|
7
7
|
* Convert Qwen3V format bbox (0-1000 range) to absolute pixel coordinates
|
|
8
8
|
* @param dimensions Image dimensions {width, height}
|
package/src/ai/vision/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export { type ImageAnnotation, ImageAnnotationSchema } from './ImageAnnotationSchema';
|
|
2
|
+
export { type ResolvedImageAnnotation, resolveImageAnnotation } from './resolveImageAnnotation';
|
|
@@ -32,7 +32,7 @@ export function parseChineseResidentIdNo(idNo: string): ParsedChineseResidentIdN
|
|
|
32
32
|
addressCode: division,
|
|
33
33
|
birthDate: `${year}-${month}-${day}`,
|
|
34
34
|
sequence: seq,
|
|
35
|
-
checkDigit: checkDigit.toUpperCase() === 'X' ? 10 : parseInt(checkDigit),
|
|
35
|
+
checkDigit: checkDigit.toUpperCase() === 'X' ? 10 : parseInt(checkDigit, 10),
|
|
36
36
|
sex: seq % 2 === 0 ? SexType.Male : SexType.Female,
|
|
37
37
|
age: new Date().getFullYear() - parseInt(year, 10),
|
|
38
38
|
valid: Mod11.validate(idNo),
|
package/src/cn/Mod11.ts
CHANGED
|
@@ -45,26 +45,3 @@ exports[`UnifiedSocialCreditCode > should parse 2`] = `
|
|
|
45
45
|
"valid": true,
|
|
46
46
|
}
|
|
47
47
|
`;
|
|
48
|
-
|
|
49
|
-
exports[`UnifiedSocialCreditCode > should parse 3`] = `
|
|
50
|
-
{
|
|
51
|
-
"adminDivisionCode": "310120",
|
|
52
|
-
"checkDigit": "0",
|
|
53
|
-
"codes": [
|
|
54
|
-
"9",
|
|
55
|
-
"1",
|
|
56
|
-
"310120",
|
|
57
|
-
"MAEXK9GG9",
|
|
58
|
-
"0",
|
|
59
|
-
],
|
|
60
|
-
"entityCategoryCode": "1",
|
|
61
|
-
"names": [
|
|
62
|
-
"工商",
|
|
63
|
-
"企业",
|
|
64
|
-
],
|
|
65
|
-
"organizationCode": "MAEXK9GG9",
|
|
66
|
-
"raw": "91310120MAEXK9GG90",
|
|
67
|
-
"registrationAuthorityCode": "9",
|
|
68
|
-
"valid": false,
|
|
69
|
-
}
|
|
70
|
-
`;
|
package/src/cn/index.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
export { ChineseResidentIdNo } from './ChineseResidentIdNo';
|
|
2
|
-
export { UnifiedSocialCreditCode } from './UnifiedSocialCreditCode';
|
|
3
2
|
export { DivisionCode } from './DivisionCode';
|
|
4
|
-
|
|
5
3
|
export * from './formatChineseAmount';
|
|
6
4
|
export * from './parseChineseNumber';
|
|
7
5
|
export * from './pinyin/toPinyinPure';
|
|
6
|
+
export { UnifiedSocialCreditCode } from './UnifiedSocialCreditCode';
|
|
@@ -36,7 +36,7 @@ test('parseChineseNumber', () => {
|
|
|
36
36
|
|
|
37
37
|
function formatChineseNumber(v: number): string {
|
|
38
38
|
if (v < 0) {
|
|
39
|
-
return
|
|
39
|
+
return `负${formatChineseNumber(-v)}`;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
// 数字对应的中文表示
|
|
@@ -88,7 +88,7 @@ function formatChineseNumber(v: number): string {
|
|
|
88
88
|
export function formatChineseAmount0(amount: number): string {
|
|
89
89
|
// 检查金额是否合理
|
|
90
90
|
if (amount < 0) {
|
|
91
|
-
return
|
|
91
|
+
return `(负)${formatChineseAmount0(-amount)}`;
|
|
92
92
|
}
|
|
93
93
|
// 大写数字和单位
|
|
94
94
|
const digits = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'];
|
|
@@ -111,10 +111,10 @@ export function formatChineseAmount0(amount: number): string {
|
|
|
111
111
|
integerAmount = Math.floor(integerAmount / 100); // 转为元为单位
|
|
112
112
|
|
|
113
113
|
if (fen > 0) {
|
|
114
|
-
result = digits[fen]
|
|
114
|
+
result = `${digits[fen]}分${result}`;
|
|
115
115
|
}
|
|
116
116
|
if (jiao > 0) {
|
|
117
|
-
result = digits[jiao]
|
|
117
|
+
result = `${digits[jiao]}角${result}`;
|
|
118
118
|
}
|
|
119
119
|
if (cents === 0) {
|
|
120
120
|
result += '整';
|
|
@@ -90,7 +90,7 @@ export function formatLogObject(
|
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
if (type === 'trace') {
|
|
93
|
-
const _err = new Error(
|
|
93
|
+
const _err = new Error(`Trace: ${o.message}`);
|
|
94
94
|
line += formatStack(_err.stack || '', _err.message);
|
|
95
95
|
}
|
|
96
96
|
}
|
|
@@ -139,11 +139,11 @@ function parseStack(stack: string, message: string) {
|
|
|
139
139
|
function formatStack(stack: string, message: string, opts?: FormatOptions) {
|
|
140
140
|
const indent = ' '.repeat((opts?.errorLevel || 0) + 1);
|
|
141
141
|
return (
|
|
142
|
-
`\n${indent}`
|
|
143
|
-
|
|
142
|
+
`\n${indent}` +
|
|
143
|
+
parseStack(stack, message)
|
|
144
144
|
.map(
|
|
145
145
|
(line) =>
|
|
146
|
-
|
|
146
|
+
` ${line.replace(/^at +/, (m) => colors.gray(m)).replace(/\((.+)\)/, (_, m) => `(${colors.cyan(m)})`)}`,
|
|
147
147
|
)
|
|
148
148
|
.join(`\n${indent}`)
|
|
149
149
|
);
|
|
@@ -201,7 +201,7 @@ function formatError(err: any, opts: FormatOptions): string {
|
|
|
201
201
|
|
|
202
202
|
const level = opts?.errorLevel || 0;
|
|
203
203
|
const causedPrefix = level > 0 ? `${' '.repeat(level)}[cause]: ` : '';
|
|
204
|
-
const causedError = err.cause ?
|
|
204
|
+
const causedError = err.cause ? `\n\n${formatError(err.cause, { ...opts, errorLevel: level + 1 })}` : '';
|
|
205
205
|
|
|
206
|
-
return causedPrefix + message
|
|
206
|
+
return `${causedPrefix + message}\n${stack}${causedError}`;
|
|
207
207
|
}
|
package/src/consola/index.ts
CHANGED
package/src/data/index.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
export type * from './types';
|
|
2
|
-
|
|
3
|
-
export { resolvePagination, type PaginationInput, type ResolvedPagination } from './resolvePagination';
|
|
4
|
-
export { parseSort, type SortRule } from './parseSort';
|
|
5
1
|
export { formatSort } from './formatSort';
|
|
2
|
+
export { parseSort, type SortRule } from './parseSort';
|
|
3
|
+
export { type PaginationInput, type ResolvedPagination, resolvePagination } from './resolvePagination';
|
|
4
|
+
export type * from './types';
|
package/src/data/maybeNumber.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type MaybeFunction, maybeFunction } from '@wener/utils';
|
|
2
2
|
import { mapValues, omitBy, pick } from 'es-toolkit';
|
|
3
|
-
import {
|
|
3
|
+
import { type MaybeNumber, maybeNumber } from './maybeNumber';
|
|
4
4
|
|
|
5
5
|
export type PaginationInput = {
|
|
6
6
|
limit?: MaybeNumber;
|
package/src/data/types.d.ts
CHANGED
|
@@ -25,14 +25,14 @@ export type ListQueryInput = {
|
|
|
25
25
|
deleted?: boolean;
|
|
26
26
|
};
|
|
27
27
|
|
|
28
|
-
type
|
|
28
|
+
type _ListResult<T = any> = {
|
|
29
29
|
/** List of items */
|
|
30
30
|
data: T[];
|
|
31
31
|
/** Total number of items */
|
|
32
32
|
total: number;
|
|
33
33
|
};
|
|
34
34
|
|
|
35
|
-
type
|
|
35
|
+
type _PageInfo = {
|
|
36
36
|
/** Whether there are more items */
|
|
37
37
|
hasNextPage: boolean;
|
|
38
38
|
/** Whether there are previous items */
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import type { OpUnitType, UnitTypeLongPlural } from 'dayjs';
|
|
2
|
+
import type { Duration } from 'dayjs/plugin/duration';
|
|
3
|
+
import { formatNumber } from '../utils/formatNumber';
|
|
3
4
|
import { parseDuration } from './parseDuration';
|
|
4
5
|
|
|
5
6
|
type FormatDurationOptions = {
|
|
@@ -29,7 +30,6 @@ export function formatDuration(value: MaybeDuration, o?: FormatDurationOptions):
|
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
let { format, humanize, iso } = o || {};
|
|
32
|
-
// Use local variables instead of modifying o directly
|
|
33
33
|
switch (format) {
|
|
34
34
|
case 'human':
|
|
35
35
|
case 'humanize':
|
|
@@ -56,18 +56,17 @@ export function formatDuration(value: MaybeDuration, o?: FormatDurationOptions):
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
// auto format
|
|
59
|
-
// 1h2m3s
|
|
60
59
|
if (v.asDays() > 1) {
|
|
61
60
|
let s = v.toISOString();
|
|
62
61
|
return s.replace('P', '').replace('T', '').toLowerCase();
|
|
63
62
|
}
|
|
64
63
|
|
|
65
64
|
{
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
65
|
+
const parts: string[] = [];
|
|
66
|
+
const h = v.hours();
|
|
67
|
+
const m = v.minutes();
|
|
68
|
+
const s = v.seconds();
|
|
69
|
+
const ms = v.milliseconds();
|
|
71
70
|
|
|
72
71
|
if (h > 0) {
|
|
73
72
|
parts.push(`${h}h`);
|
|
@@ -78,8 +77,8 @@ export function formatDuration(value: MaybeDuration, o?: FormatDurationOptions):
|
|
|
78
77
|
if (s > 0) {
|
|
79
78
|
parts.push(`${s}s`);
|
|
80
79
|
}
|
|
81
|
-
if (ms > 0 ||
|
|
82
|
-
parts.push(`${ms}ms`);
|
|
80
|
+
if (ms > 0 || parts.length === 0) {
|
|
81
|
+
parts.push(`${formatNumber(ms, 2)}ms`);
|
|
83
82
|
}
|
|
84
83
|
return parts.join('');
|
|
85
84
|
}
|
package/src/dayjs/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { dayjs } from './dayjs';
|
|
2
|
-
export { parseDuration, type MaybeDuration } from './parseDuration';
|
|
3
2
|
export { formatDuration } from './formatDuration';
|
|
3
|
+
export { type MaybeDuration, parseDuration } from './parseDuration';
|
|
4
4
|
|
|
5
5
|
export { resolveRelativeTime } from './resolveRelativeTime';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import dayjs from 'dayjs';
|
|
2
2
|
import type { Duration } from 'dayjs/plugin/duration';
|
|
3
|
-
import { checkDurationUnit,
|
|
3
|
+
import { checkDurationUnit, type RelativeDurationUnit, RelativeDurationUnits } from './resolveRelativeTime';
|
|
4
4
|
|
|
5
5
|
export type TimeOperation =
|
|
6
6
|
| {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type MaybeDate, parseDate } from '@wener/utils';
|
|
1
2
|
import dayjs from 'dayjs';
|
|
2
3
|
import duration from 'dayjs/plugin/duration';
|
|
3
4
|
import quarterOfYear from 'dayjs/plugin/quarterOfYear';
|
|
@@ -75,26 +76,22 @@ dayjs.extend(weekOfYear);
|
|
|
75
76
|
* resolveRelativeTime('now\\d', refDate); // End of reference day
|
|
76
77
|
* ```
|
|
77
78
|
*/
|
|
78
|
-
export function resolveRelativeTime(s: string | Date | number, now?: Date | undefined): Date
|
|
79
|
+
export function resolveRelativeTime(s: string | Date | number, now?: Date | undefined): Date;
|
|
80
|
+
export function resolveRelativeTime(s: MaybeDate, now?: Date | undefined): Date | undefined;
|
|
81
|
+
export function resolveRelativeTime(s: MaybeDate, now?: Date | undefined): Date | undefined {
|
|
79
82
|
{
|
|
80
|
-
let out
|
|
81
|
-
if (!s) {
|
|
82
|
-
} else if (s instanceof Date) {
|
|
83
|
-
out = s;
|
|
84
|
-
} else if (typeof s === 'number') {
|
|
85
|
-
out = new Date(s);
|
|
86
|
-
} else if (!s.startsWith('now')) {
|
|
87
|
-
out = new Date(s);
|
|
88
|
-
}
|
|
83
|
+
let out = parseDate(s);
|
|
89
84
|
if (out) {
|
|
90
|
-
if (isNaN(out.getTime())) {
|
|
91
|
-
throw new Error(`Invalid date: ${s}`);
|
|
92
|
-
}
|
|
93
85
|
return out;
|
|
94
86
|
}
|
|
87
|
+
if (s == null) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
95
90
|
}
|
|
96
91
|
|
|
97
|
-
if (typeof s
|
|
92
|
+
if (typeof s === 'string' && s.startsWith('now')) {
|
|
93
|
+
// valid
|
|
94
|
+
} else {
|
|
98
95
|
throw new Error(`Invalid relative time format: ${s}`);
|
|
99
96
|
}
|
|
100
97
|
|