@wener/common 2.0.1 → 2.0.3
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 +2 -0
- package/lib/ai/qwen3vl/index.js.map +1 -0
- package/lib/ai/qwen3vl/utils.js +31 -0
- package/lib/ai/qwen3vl/utils.js.map +1 -0
- package/lib/ai/vision/DocLayoutElementTypeSchema.js +28 -0
- package/lib/ai/vision/DocLayoutElementTypeSchema.js.map +1 -0
- package/lib/ai/vision/ImageAnnotationSchema.js +50 -0
- package/lib/ai/vision/ImageAnnotationSchema.js.map +1 -0
- package/lib/ai/vision/index.js +3 -0
- package/lib/ai/vision/index.js.map +1 -0
- package/lib/ai/vision/resolveImageAnnotation.js +105 -0
- package/lib/ai/vision/resolveImageAnnotation.js.map +1 -0
- package/lib/cn/ChineseResidentIdNo.js +48 -0
- package/lib/cn/ChineseResidentIdNo.js.map +1 -0
- package/lib/cn/ChineseResidentIdNo.mod.js +1 -0
- package/lib/cn/{ResidentIdentityCardNumber.test.js → ChineseResidentIdNo.test.js} +7 -6
- package/lib/cn/DivisionCode.js +217 -301
- package/lib/cn/DivisionCode.js.map +1 -0
- package/lib/cn/DivisionCode.mod.js +1 -0
- package/lib/cn/DivisionCode.test.js +9 -15
- package/lib/cn/Mod11.js +43 -0
- package/lib/cn/Mod11.js.map +1 -0
- package/lib/cn/Mod31.js +49 -0
- package/lib/cn/Mod31.js.map +1 -0
- package/lib/cn/UnifiedSocialCreditCode.js +137 -113
- package/lib/cn/UnifiedSocialCreditCode.js.map +1 -0
- package/lib/cn/UnifiedSocialCreditCode.mod.js +1 -0
- package/lib/cn/UnifiedSocialCreditCode.test.js +1 -1
- package/lib/cn/formatChineseAmount.js +77 -0
- package/lib/cn/formatChineseAmount.js.map +1 -0
- package/lib/cn/index.js +6 -2
- package/lib/cn/index.js.map +1 -0
- package/lib/cn/mod.js +6 -0
- package/lib/cn/parseChineseNumber.js +94 -0
- package/lib/cn/parseChineseNumber.js.map +1 -0
- package/lib/cn/parseChineseNumber.test.js +278 -0
- package/lib/cn/pinyin/cartesianProduct.js +22 -0
- package/lib/cn/pinyin/cartesianProduct.js.map +1 -0
- package/lib/cn/pinyin/cartesianProduct.test.js +179 -0
- package/lib/cn/pinyin/data.json +23573 -0
- package/lib/cn/pinyin/loader.js +14 -0
- package/lib/cn/pinyin/loader.js.map +1 -0
- package/lib/cn/pinyin/preload.js +3 -0
- package/lib/cn/pinyin/preload.js.map +1 -0
- package/lib/cn/pinyin/toPinyin.test.js +167 -0
- package/lib/cn/pinyin/toPinyinPure.js +33 -0
- package/lib/cn/pinyin/toPinyinPure.js.map +1 -0
- package/lib/cn/pinyin/transform.js +14 -0
- package/lib/cn/pinyin/transform.js.map +1 -0
- package/lib/cn/types.d.js +2 -0
- package/lib/cn/types.d.js.map +1 -0
- package/lib/consola/createStandardConsolaReporter.js +6 -6
- package/lib/consola/createStandardConsolaReporter.js.map +1 -0
- package/lib/consola/formatLogObject.js +67 -135
- package/lib/consola/formatLogObject.js.map +1 -0
- package/lib/consola/formatLogObject.test.js +184 -0
- package/lib/consola/index.js +1 -0
- package/lib/consola/index.js.map +1 -0
- package/lib/data/formatSort.js +6 -5
- package/lib/data/formatSort.js.map +1 -0
- package/lib/data/index.js +1 -0
- package/lib/data/index.js.map +1 -0
- package/lib/data/maybeNumber.js +5 -7
- package/lib/data/maybeNumber.js.map +1 -0
- package/lib/data/parseSort.js +22 -28
- package/lib/data/parseSort.js.map +1 -0
- package/lib/data/resolvePagination.js +13 -17
- package/lib/data/resolvePagination.js.map +1 -0
- package/lib/data/types.d.js +2 -0
- package/lib/data/types.d.js.map +1 -0
- package/lib/dayjs/dayjs.js +40 -0
- package/lib/dayjs/dayjs.js.map +1 -0
- package/lib/dayjs/formatDuration.js +59 -0
- package/lib/dayjs/formatDuration.js.map +1 -0
- package/lib/dayjs/formatDuration.test.js +90 -0
- package/lib/dayjs/index.js +5 -0
- package/lib/dayjs/index.js.map +1 -0
- package/lib/dayjs/parseDuration.js +29 -0
- package/lib/dayjs/parseDuration.js.map +1 -0
- package/lib/dayjs/parseRelativeTime.js +90 -0
- package/lib/dayjs/parseRelativeTime.js.map +1 -0
- package/lib/dayjs/parseRelativeTime.test.js +247 -0
- package/lib/dayjs/resolveRelativeTime.js +158 -0
- package/lib/dayjs/resolveRelativeTime.js.map +1 -0
- package/lib/dayjs/resolveRelativeTime.test.js +310 -0
- package/lib/decimal/index.js +2 -0
- package/lib/decimal/index.js.map +1 -0
- package/lib/decimal/parseDecimal.js +15 -0
- package/lib/decimal/parseDecimal.js.map +1 -0
- package/lib/emittery/emitter.js +10 -0
- package/lib/emittery/emitter.js.map +1 -0
- package/lib/emittery/index.js +2 -0
- package/lib/emittery/index.js.map +1 -0
- package/lib/foundation/schema/SexType.js +16 -0
- package/lib/foundation/schema/SexType.js.map +1 -0
- package/lib/foundation/schema/index.js +2 -0
- package/lib/foundation/schema/index.js.map +1 -0
- package/lib/foundation/schema/parseSexType.js +19 -0
- package/lib/foundation/schema/parseSexType.js.map +1 -0
- package/lib/foundation/schema/types.js +7 -0
- package/lib/foundation/schema/types.js.map +1 -0
- package/lib/fs/FileSystemError.js +23 -0
- package/lib/fs/FileSystemError.js.map +1 -0
- package/lib/fs/IFileSystem.d.js +3 -0
- package/lib/fs/IFileSystem.d.js.map +1 -0
- package/lib/fs/MemoryFileSystem.test.js +188 -0
- package/lib/fs/createBrowserFileSystem.js +248 -0
- package/lib/fs/createBrowserFileSystem.js.map +1 -0
- package/lib/fs/createMemoryFileSystem.js +516 -0
- package/lib/fs/createMemoryFileSystem.js.map +1 -0
- package/lib/fs/createSandboxFileSystem.js +108 -0
- package/lib/fs/createSandboxFileSystem.js.map +1 -0
- package/lib/fs/createWebDavFileSystem.js +137 -0
- package/lib/fs/createWebDavFileSystem.js.map +1 -0
- package/lib/fs/findMimeType.js +17 -0
- package/lib/fs/findMimeType.js.map +1 -0
- package/lib/fs/index.js +8 -0
- package/lib/fs/index.js.map +1 -0
- package/lib/fs/orpc/FileSystemContract.js +93 -0
- package/lib/fs/orpc/FileSystemContract.js.map +1 -0
- package/lib/fs/orpc/createContractClientFileSystem.js +93 -0
- package/lib/fs/orpc/createContractClientFileSystem.js.map +1 -0
- package/lib/fs/orpc/index.js +3 -0
- package/lib/fs/orpc/index.js.map +1 -0
- package/lib/fs/orpc/server/createFileSystemContractImpl.js +63 -0
- package/lib/fs/orpc/server/createFileSystemContractImpl.js.map +1 -0
- package/lib/fs/orpc/server/index.js +2 -0
- package/lib/fs/orpc/server/index.js.map +1 -0
- package/lib/fs/s3/createS3MiniFileSystem.js +705 -0
- package/lib/fs/s3/createS3MiniFileSystem.js.map +1 -0
- package/lib/fs/s3/index.js +2 -0
- package/lib/fs/s3/index.js.map +1 -0
- package/lib/fs/s3/s3mini.test.js +584 -0
- package/lib/fs/scandir.js +59 -0
- package/lib/fs/scandir.js.map +1 -0
- package/lib/fs/server/createDatabaseFileSystem.js +750 -0
- package/lib/fs/server/createDatabaseFileSystem.js.map +1 -0
- package/lib/fs/server/createNodeFileSystem.js +401 -0
- package/lib/fs/server/createNodeFileSystem.js.map +1 -0
- package/lib/fs/server/dbfs.test.js +221 -0
- package/lib/fs/server/index.js +2 -0
- package/lib/fs/server/index.js.map +1 -0
- package/lib/fs/server/loadTestDatabase.js +127 -0
- package/lib/fs/server/loadTestDatabase.js.map +1 -0
- package/lib/fs/tests/runFileSystemTest.js +318 -0
- package/lib/fs/tests/runFileSystemTest.js.map +1 -0
- package/lib/fs/types.js +27 -0
- package/lib/fs/types.js.map +1 -0
- package/lib/fs/utils/getFileUrl.js +35 -0
- package/lib/fs/utils/getFileUrl.js.map +1 -0
- package/lib/fs/utils.js +22 -0
- package/lib/fs/utils.js.map +1 -0
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -0
- package/lib/jsonschema/JsonSchema.js +146 -172
- package/lib/jsonschema/JsonSchema.js.map +1 -0
- package/lib/jsonschema/forEachJsonSchema.js +44 -0
- package/lib/jsonschema/forEachJsonSchema.js.map +1 -0
- package/lib/jsonschema/index.js +2 -0
- package/lib/jsonschema/index.js.map +1 -0
- package/lib/jsonschema/types.d.js +2 -0
- package/lib/jsonschema/types.d.js.map +1 -0
- package/lib/meta/defineFileType.js +20 -103
- package/lib/meta/defineFileType.js.map +1 -0
- package/lib/meta/defineInit.js +31 -250
- package/lib/meta/defineInit.js.map +1 -0
- package/lib/meta/defineMetadata.js +24 -140
- package/lib/meta/defineMetadata.js.map +1 -0
- package/lib/meta/index.js +1 -0
- package/lib/meta/index.js.map +1 -0
- package/lib/orpc/createOpenApiContractClient.js +27 -0
- package/lib/orpc/createOpenApiContractClient.js.map +1 -0
- package/lib/orpc/createRpcContractClient.js +34 -0
- package/lib/orpc/createRpcContractClient.js.map +1 -0
- package/lib/orpc/index.js +3 -0
- package/lib/orpc/index.js.map +1 -0
- package/lib/orpc/resolveLinkPlugins.js +28 -0
- package/lib/orpc/resolveLinkPlugins.js.map +1 -0
- package/lib/password/PHC.js +63 -87
- package/lib/password/PHC.js.map +1 -0
- package/lib/password/PHC.test.js +11 -3
- package/lib/password/Password.js +30 -292
- package/lib/password/Password.js.map +1 -0
- package/lib/password/Password.test.js +35 -22
- package/lib/password/createArgon2PasswordAlgorithm.js +35 -191
- package/lib/password/createArgon2PasswordAlgorithm.js.map +1 -0
- package/lib/password/createBase64PasswordAlgorithm.js +8 -141
- package/lib/password/createBase64PasswordAlgorithm.js.map +1 -0
- package/lib/password/createBcryptPasswordAlgorithm.js +13 -168
- package/lib/password/createBcryptPasswordAlgorithm.js.map +1 -0
- package/lib/password/createPBKDF2PasswordAlgorithm.js +46 -228
- package/lib/password/createPBKDF2PasswordAlgorithm.js.map +1 -0
- package/lib/password/createScryptPasswordAlgorithm.js +55 -211
- package/lib/password/createScryptPasswordAlgorithm.js.map +1 -0
- package/lib/password/index.js +1 -0
- package/lib/password/index.js.map +1 -0
- package/lib/password/server/index.js +1 -0
- package/lib/password/server/index.js.map +1 -0
- package/lib/resource/Identifiable.js +2 -0
- package/lib/resource/Identifiable.js.map +1 -0
- package/lib/resource/ListQuery.js +47 -0
- package/lib/resource/ListQuery.js.map +1 -0
- package/lib/resource/getTitleOfResource.js +3 -5
- package/lib/resource/getTitleOfResource.js.map +1 -0
- package/lib/resource/index.js +2 -0
- package/lib/resource/index.js.map +1 -0
- package/lib/resource/schema/AnyResourceSchema.js +3 -2
- package/lib/resource/schema/AnyResourceSchema.js.map +1 -0
- package/lib/resource/schema/BaseResourceSchema.js +2 -1
- package/lib/resource/schema/BaseResourceSchema.js.map +1 -0
- package/lib/resource/schema/ResourceActionType.js +6 -4
- package/lib/resource/schema/ResourceActionType.js.map +1 -0
- package/lib/resource/schema/ResourceStatus.js +5 -3
- package/lib/resource/schema/ResourceStatus.js.map +1 -0
- package/lib/resource/schema/ResourceType.js +5 -3
- package/lib/resource/schema/ResourceType.js.map +1 -0
- package/lib/resource/schema/index.js +6 -0
- package/lib/resource/schema/index.js.map +1 -0
- package/lib/resource/schema/types.js +16 -20
- package/lib/resource/schema/types.js.map +1 -0
- package/lib/s3/formatS3Url.js +65 -0
- package/lib/s3/formatS3Url.js.map +1 -0
- package/lib/s3/formatS3Url.test.js +262 -0
- package/lib/s3/index.js +3 -0
- package/lib/s3/index.js.map +1 -0
- package/lib/s3/parseS3Url.js +65 -0
- package/lib/s3/parseS3Url.js.map +1 -0
- package/lib/s3/parseS3Url.test.js +270 -0
- package/lib/schema/SchemaRegistry.js +45 -0
- package/lib/schema/SchemaRegistry.js.map +1 -0
- package/lib/schema/SchemaRegistry.mod.js +2 -0
- package/lib/schema/TypeSchema.d.js +2 -0
- package/lib/schema/TypeSchema.d.js.map +1 -0
- package/lib/schema/createSchemaData.js +26 -125
- package/lib/schema/createSchemaData.js.map +1 -0
- package/lib/schema/findJsonSchemaByPath.js +13 -36
- package/lib/schema/findJsonSchemaByPath.js.map +1 -0
- package/lib/schema/formatZodError.js +140 -0
- package/lib/schema/formatZodError.js.map +1 -0
- package/lib/schema/formatZodError.test.js +196 -0
- package/lib/schema/getSchemaCache.js +5 -5
- package/lib/schema/getSchemaCache.js.map +1 -0
- package/lib/schema/getSchemaOptions.js +8 -11
- package/lib/schema/getSchemaOptions.js.map +1 -0
- package/lib/schema/index.js +2 -0
- package/lib/schema/index.js.map +1 -0
- package/lib/schema/toJsonSchema.js +47 -290
- package/lib/schema/toJsonSchema.js.map +1 -0
- package/lib/schema/validate.js +33 -45
- package/lib/schema/validate.js.map +1 -0
- package/lib/tools/generateSchema.js +39 -197
- package/lib/tools/generateSchema.js.map +1 -0
- package/lib/tools/renderJsonSchemaToMarkdownDoc.js +55 -143
- package/lib/tools/renderJsonSchemaToMarkdownDoc.js.map +1 -0
- package/lib/utils/buildBaseUrl.js +13 -0
- package/lib/utils/buildBaseUrl.js.map +1 -0
- package/lib/utils/buildRedactorFormSchema.js +59 -0
- package/lib/utils/buildRedactorFormSchema.js.map +1 -0
- package/lib/utils/getEstimateProcessTime.js +21 -0
- package/lib/utils/getEstimateProcessTime.js.map +1 -0
- package/lib/utils/index.js +4 -0
- package/lib/utils/index.js.map +1 -0
- package/lib/utils/resolveFeatureOptions.js +12 -0
- package/lib/utils/resolveFeatureOptions.js.map +1 -0
- package/package.json +77 -20
- package/src/ai/qwen3vl/index.ts +1 -0
- package/src/ai/qwen3vl/utils.ts +36 -0
- package/src/ai/vision/DocLayoutElementTypeSchema.ts +30 -0
- package/src/ai/vision/ImageAnnotationSchema.ts +60 -0
- package/src/ai/vision/index.ts +2 -0
- package/src/ai/vision/resolveImageAnnotation.ts +135 -0
- package/src/cn/ChineseResidentIdNo.test.ts +18 -0
- package/src/cn/ChineseResidentIdNo.ts +74 -0
- package/src/cn/DivisionCode.test.ts +3 -13
- package/src/cn/DivisionCode.ts +138 -193
- package/src/cn/{Mod11Checksum.ts → Mod11.ts} +3 -1
- package/src/cn/{Mod31Checksum.ts → Mod31.ts} +2 -0
- package/src/cn/UnifiedSocialCreditCode.test.ts +2 -2
- package/src/cn/UnifiedSocialCreditCode.ts +119 -124
- package/src/cn/__snapshots__/ChineseResidentIdNo.test.ts.snap +14 -0
- package/src/cn/__snapshots__/UnifiedSocialCreditCode.test.ts.snap +41 -12
- package/src/cn/formatChineseAmount.ts +61 -0
- package/src/cn/index.ts +6 -2
- package/src/cn/parseChineseNumber.test.ts +159 -0
- package/src/cn/parseChineseNumber.ts +97 -0
- package/src/cn/pinyin/cartesianProduct.test.ts +64 -0
- package/src/cn/pinyin/cartesianProduct.ts +24 -0
- package/src/cn/pinyin/data.json +23573 -0
- package/src/cn/pinyin/loader.ts +12 -0
- package/src/cn/pinyin/preload.ts +3 -0
- package/src/cn/pinyin/toPinyin.test.ts +12 -0
- package/src/cn/pinyin/toPinyinPure.ts +43 -0
- package/src/cn/pinyin/transform.ts +12 -0
- package/src/consola/formatLogObject.test.ts +27 -0
- package/src/consola/formatLogObject.ts +46 -10
- package/src/dayjs/dayjs.ts +40 -0
- package/src/dayjs/formatDuration.test.ts +14 -0
- package/src/dayjs/formatDuration.ts +86 -0
- package/src/dayjs/index.ts +5 -0
- package/src/dayjs/parseDuration.ts +40 -0
- package/src/dayjs/parseRelativeTime.test.ts +185 -0
- package/src/dayjs/parseRelativeTime.ts +115 -0
- package/src/dayjs/resolveRelativeTime.test.ts +357 -0
- package/src/dayjs/resolveRelativeTime.ts +167 -0
- package/src/decimal/index.ts +1 -0
- package/src/decimal/parseDecimal.ts +16 -0
- package/src/emittery/emitter.ts +9 -0
- package/src/emittery/index.ts +1 -0
- package/src/foundation/schema/SexType.ts +21 -0
- package/src/foundation/schema/index.ts +1 -0
- package/src/foundation/schema/parseSexType.ts +19 -0
- package/src/foundation/schema/types.ts +8 -0
- package/src/fs/FileSystemError.ts +26 -0
- package/src/fs/IFileSystem.d.ts +102 -0
- package/src/fs/MemoryFileSystem.test.ts +37 -0
- package/src/fs/createBrowserFileSystem.ts +291 -0
- package/src/fs/createMemoryFileSystem.ts +604 -0
- package/src/fs/createSandboxFileSystem.ts +136 -0
- package/src/fs/createWebDavFileSystem.ts +172 -0
- package/src/fs/findMimeType.ts +23 -0
- package/src/fs/index.ts +8 -0
- package/src/fs/orpc/FileSystemContract.ts +92 -0
- package/src/fs/orpc/createContractClientFileSystem.ts +115 -0
- package/src/fs/orpc/index.ts +2 -0
- package/src/fs/orpc/server/createFileSystemContractImpl.ts +64 -0
- package/src/fs/orpc/server/index.ts +1 -0
- package/src/fs/s3/createS3MiniFileSystem.ts +830 -0
- package/src/fs/s3/index.ts +1 -0
- package/src/fs/s3/s3mini.test.ts +264 -0
- package/src/fs/scandir.ts +75 -0
- package/src/fs/server/createDatabaseFileSystem.ts +668 -0
- package/src/fs/server/createNodeFileSystem.ts +499 -0
- package/src/fs/server/dbfs.test.ts +47 -0
- package/src/fs/server/index.ts +1 -0
- package/src/fs/server/loadTestDatabase.ts +131 -0
- package/src/fs/tests/runFileSystemTest.ts +288 -0
- package/src/fs/types.ts +29 -0
- package/src/fs/utils/getFileUrl.ts +44 -0
- package/src/fs/utils.ts +23 -0
- package/src/jsonschema/JsonSchema.ts +118 -110
- package/src/jsonschema/forEachJsonSchema.ts +50 -0
- package/src/jsonschema/index.ts +1 -0
- package/src/orpc/createOpenApiContractClient.ts +52 -0
- package/src/orpc/createRpcContractClient.ts +50 -0
- package/src/orpc/index.ts +2 -0
- package/src/orpc/resolveLinkPlugins.ts +29 -0
- package/src/password/PHC.ts +3 -3
- package/src/password/Password.test.ts +1 -1
- package/src/password/Password.ts +2 -2
- package/src/password/createPBKDF2PasswordAlgorithm.ts +2 -2
- package/src/resource/ListQuery.ts +53 -0
- package/src/resource/index.ts +1 -0
- package/src/resource/schema/AnyResourceSchema.ts +17 -3
- package/src/resource/schema/index.ts +5 -0
- package/src/s3/formatS3Url.test.ts +254 -0
- package/src/s3/formatS3Url.ts +84 -0
- package/src/s3/index.ts +2 -0
- package/src/s3/parseS3Url.test.ts +258 -0
- package/src/s3/parseS3Url.ts +88 -0
- package/src/schema/SchemaRegistry.ts +48 -0
- package/src/schema/createSchemaData.ts +1 -1
- package/src/schema/formatZodError.test.ts +196 -0
- package/src/schema/formatZodError.ts +151 -0
- package/src/schema/getSchemaOptions.ts +3 -3
- package/src/schema/index.ts +1 -0
- package/src/utils/buildBaseUrl.ts +12 -0
- package/src/utils/buildRedactorFormSchema.ts +85 -0
- package/src/utils/getEstimateProcessTime.ts +36 -0
- package/src/utils/index.ts +5 -0
- package/src/utils/resolveFeatureOptions.ts +14 -0
- package/lib/cn/Mod11Checksum.js +0 -85
- package/lib/cn/Mod31Checksum.js +0 -97
- package/lib/cn/ResidentIdentityCardNumber.js +0 -50
- package/lib/cn/formatDate.js +0 -13
- package/lib/cn/parseSex.js +0 -20
- package/lib/resource/schema/SchemaRegistry.js +0 -38
- package/lib/resource/schema/SexType.js +0 -10
- package/lib/search/AdvanceSearch.js +0 -9
- package/lib/search/AdvanceSearch.test.js +0 -435
- package/lib/search/formatAdvanceSearch.js +0 -78
- package/lib/search/index.js +0 -1
- package/lib/search/optimizeAdvanceSearch.js +0 -143
- package/lib/search/parseAdvanceSearch.js +0 -20
- package/lib/search/parser.d.js +0 -1
- package/lib/search/parser.js +0 -3088
- package/lib/search/types.d.js +0 -1
- package/src/cn/ResidentIdentityCardNumber.test.ts +0 -17
- package/src/cn/ResidentIdentityCardNumber.ts +0 -96
- package/src/cn/__snapshots__/ResidentIdentityCardNumber.test.ts.snap +0 -15
- package/src/cn/formatDate.ts +0 -12
- package/src/cn/parseSex.ts +0 -13
- package/src/resource/schema/SchemaRegistry.ts +0 -42
- package/src/resource/schema/SexType.ts +0 -13
- package/src/search/AdvanceSearch.test.ts +0 -149
- package/src/search/AdvanceSearch.ts +0 -14
- package/src/search/Makefile +0 -2
- package/src/search/__snapshots__/AdvanceSearch.test.ts.snap +0 -675
- package/src/search/formatAdvanceSearch.ts +0 -52
- package/src/search/index.ts +0 -1
- package/src/search/optimizeAdvanceSearch.ts +0 -77
- package/src/search/parseAdvanceSearch.ts +0 -23
- package/src/search/parser.d.ts +0 -8
- package/src/search/parser.js +0 -2794
- package/src/search/parser.peggy +0 -237
- package/src/search/types.d.ts +0 -45
|
@@ -1,24 +1,21 @@
|
|
|
1
1
|
import { deepFreeze } from "@wener/utils";
|
|
2
2
|
import { getSchemaCache } from "./getSchemaCache.js";
|
|
3
|
-
import {
|
|
3
|
+
import { SchemaRegistry } from "./SchemaRegistry.js";
|
|
4
4
|
export function getSchemaOptions(s) {
|
|
5
|
-
|
|
6
|
-
return getSchemaCache(s, "options",
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
var value = v.const;
|
|
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;
|
|
10
9
|
return {
|
|
11
10
|
label: String(v.description || v.title || value),
|
|
12
11
|
value: value ? String(value) : ""
|
|
13
12
|
};
|
|
14
|
-
})
|
|
13
|
+
}) || [];
|
|
15
14
|
out = deepFreeze(out);
|
|
16
15
|
return out;
|
|
17
16
|
});
|
|
18
17
|
}
|
|
19
18
|
export function getSchemaOptionLabel(schema, value) {
|
|
20
|
-
|
|
21
|
-
return (_getSchemaOptions_find = getSchemaOptions(schema).find(function (v) {
|
|
22
|
-
return v.value === value;
|
|
23
|
-
})) === null || _getSchemaOptions_find === void 0 ? void 0 : _getSchemaOptions_find.label;
|
|
19
|
+
return getSchemaOptions(schema).find((v) => v.value === value)?.label;
|
|
24
20
|
}
|
|
21
|
+
//# sourceMappingURL=getSchemaOptions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/schema/getSchemaOptions.ts"],"sourcesContent":["import { deepFreeze } from '@wener/utils';\nimport { getSchemaCache } from './getSchemaCache';\nimport { SchemaRegistry } from './SchemaRegistry';\nimport type { TypeSchema } from './TypeSchema';\n\nexport function getSchemaOptions(s: TypeSchema): Array<{ value: string; label: string }> {\n\tlet js = SchemaRegistry.get(s);\n\treturn getSchemaCache(s, 'options', () => {\n\t\tlet out =\n\t\t\t(js.anyOf || js.oneOf)?.map((v: any) => {\n\t\t\t\tlet value = v.const;\n\t\t\t\treturn {\n\t\t\t\t\tlabel: String(v.description || v.title || value),\n\t\t\t\t\tvalue: value ? String(value) : '',\n\t\t\t\t};\n\t\t\t}) || [];\n\t\tout = deepFreeze(out);\n\t\treturn out;\n\t});\n}\n\nexport function getSchemaOptionLabel(schema: TypeSchema, value: string | undefined | null): string | undefined {\n\treturn getSchemaOptions(schema).find((v) => v.value === value)?.label;\n}\n"],"names":["deepFreeze","getSchemaCache","SchemaRegistry","getSchemaOptions","s","js","get","out","anyOf","oneOf","map","v","value","const","label","String","description","title","getSchemaOptionLabel","schema","find"],"mappings":"AAAA,SAASA,UAAU,QAAQ,eAAe;AAC1C,SAASC,cAAc,QAAQ,mBAAmB;AAClD,SAASC,cAAc,QAAQ,mBAAmB;AAGlD,OAAO,SAASC,iBAAiBC,CAAa;IAC7C,IAAIC,KAAKH,eAAeI,GAAG,CAACF;IAC5B,OAAOH,eAAeG,GAAG,WAAW;QACnC,IAAIG,MACH,AAACF,CAAAA,GAAGG,KAAK,IAAIH,GAAGI,KAAK,AAAD,GAAIC,IAAI,CAACC;YAC5B,IAAIC,QAAQD,EAAEE,KAAK;YACnB,OAAO;gBACNC,OAAOC,OAAOJ,EAAEK,WAAW,IAAIL,EAAEM,KAAK,IAAIL;gBAC1CA,OAAOA,QAAQG,OAAOH,SAAS;YAChC;QACD,MAAM,EAAE;QACTL,MAAMP,WAAWO;QACjB,OAAOA;IACR;AACD;AAEA,OAAO,SAASW,qBAAqBC,MAAkB,EAAEP,KAAgC;IACxF,OAAOT,iBAAiBgB,QAAQC,IAAI,CAAC,CAACT,IAAMA,EAAEC,KAAK,KAAKA,QAAQE;AACjE"}
|
package/lib/schema/index.js
CHANGED
|
@@ -3,3 +3,5 @@ export { getSchemaOptions, getSchemaOptionLabel } from "./getSchemaOptions.js";
|
|
|
3
3
|
export { toJsonSchema } from "./toJsonSchema.js";
|
|
4
4
|
export { findJsonSchemaByPath } from "./findJsonSchemaByPath.js";
|
|
5
5
|
export { createSchemaData } from "./createSchemaData.js";
|
|
6
|
+
export { SchemaRegistry } from "./SchemaRegistry.js";
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/schema/index.ts"],"sourcesContent":["export type * from './TypeSchema';\nexport { isJsonSchema, isZodSchema, isTypeBoxSchema, validate, parseData, type ValidationResult } from './validate';\nexport { getSchemaOptions, getSchemaOptionLabel } from './getSchemaOptions';\nexport { toJsonSchema } from './toJsonSchema';\nexport { findJsonSchemaByPath } from './findJsonSchemaByPath';\nexport { createSchemaData } from './createSchemaData';\nexport { SchemaRegistry } from './SchemaRegistry';\n"],"names":["isJsonSchema","isZodSchema","isTypeBoxSchema","validate","parseData","getSchemaOptions","getSchemaOptionLabel","toJsonSchema","findJsonSchemaByPath","createSchemaData","SchemaRegistry"],"mappings":"AACA,SAASA,YAAY,EAAEC,WAAW,EAAEC,eAAe,EAAEC,QAAQ,EAAEC,SAAS,QAA+B,aAAa;AACpH,SAASC,gBAAgB,EAAEC,oBAAoB,QAAQ,qBAAqB;AAC5E,SAASC,YAAY,QAAQ,iBAAiB;AAC9C,SAASC,oBAAoB,QAAQ,yBAAyB;AAC9D,SAASC,gBAAgB,QAAQ,qBAAqB;AACtD,SAASC,cAAc,QAAQ,mBAAmB"}
|
|
@@ -1,122 +1,3 @@
|
|
|
1
|
-
function _array_like_to_array(arr, len) {
|
|
2
|
-
if (len == null || len > arr.length)
|
|
3
|
-
len = arr.length;
|
|
4
|
-
for (var i = 0, arr2 = new Array(len); i < len; i++)
|
|
5
|
-
arr2[i] = arr[i];
|
|
6
|
-
return arr2;
|
|
7
|
-
}
|
|
8
|
-
function _array_with_holes(arr) {
|
|
9
|
-
if (Array.isArray(arr))
|
|
10
|
-
return arr;
|
|
11
|
-
}
|
|
12
|
-
function _define_property(obj, key, value) {
|
|
13
|
-
if (key in obj) {
|
|
14
|
-
Object.defineProperty(obj, key, {
|
|
15
|
-
value: value,
|
|
16
|
-
enumerable: true,
|
|
17
|
-
configurable: true,
|
|
18
|
-
writable: true
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
else {
|
|
22
|
-
obj[key] = value;
|
|
23
|
-
}
|
|
24
|
-
return obj;
|
|
25
|
-
}
|
|
26
|
-
function _iterable_to_array_limit(arr, i) {
|
|
27
|
-
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
28
|
-
if (_i == null)
|
|
29
|
-
return;
|
|
30
|
-
var _arr = [];
|
|
31
|
-
var _n = true;
|
|
32
|
-
var _d = false;
|
|
33
|
-
var _s, _e;
|
|
34
|
-
try {
|
|
35
|
-
for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
|
|
36
|
-
_arr.push(_s.value);
|
|
37
|
-
if (i && _arr.length === i)
|
|
38
|
-
break;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
catch (err) {
|
|
42
|
-
_d = true;
|
|
43
|
-
_e = err;
|
|
44
|
-
}
|
|
45
|
-
finally {
|
|
46
|
-
try {
|
|
47
|
-
if (!_n && _i["return"] != null)
|
|
48
|
-
_i["return"]();
|
|
49
|
-
}
|
|
50
|
-
finally {
|
|
51
|
-
if (_d)
|
|
52
|
-
throw _e;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return _arr;
|
|
56
|
-
}
|
|
57
|
-
function _non_iterable_rest() {
|
|
58
|
-
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
59
|
-
}
|
|
60
|
-
function _object_spread(target) {
|
|
61
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
62
|
-
var source = arguments[i] != null ? arguments[i] : {};
|
|
63
|
-
var ownKeys = Object.keys(source);
|
|
64
|
-
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
65
|
-
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {
|
|
66
|
-
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
67
|
-
}));
|
|
68
|
-
}
|
|
69
|
-
ownKeys.forEach(function (key) {
|
|
70
|
-
_define_property(target, key, source[key]);
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
return target;
|
|
74
|
-
}
|
|
75
|
-
function ownKeys(object, enumerableOnly) {
|
|
76
|
-
var keys = Object.keys(object);
|
|
77
|
-
if (Object.getOwnPropertySymbols) {
|
|
78
|
-
var symbols = Object.getOwnPropertySymbols(object);
|
|
79
|
-
if (enumerableOnly) {
|
|
80
|
-
symbols = symbols.filter(function (sym) {
|
|
81
|
-
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
keys.push.apply(keys, symbols);
|
|
85
|
-
}
|
|
86
|
-
return keys;
|
|
87
|
-
}
|
|
88
|
-
function _object_spread_props(target, source) {
|
|
89
|
-
source = source != null ? source : {};
|
|
90
|
-
if (Object.getOwnPropertyDescriptors) {
|
|
91
|
-
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
ownKeys(Object(source)).forEach(function (key) {
|
|
95
|
-
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
return target;
|
|
99
|
-
}
|
|
100
|
-
function _sliced_to_array(arr, i) {
|
|
101
|
-
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
102
|
-
}
|
|
103
|
-
function _type_of(obj) {
|
|
104
|
-
"@swc/helpers - typeof";
|
|
105
|
-
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
106
|
-
}
|
|
107
|
-
function _unsupported_iterable_to_array(o, minLen) {
|
|
108
|
-
if (!o)
|
|
109
|
-
return;
|
|
110
|
-
if (typeof o === "string")
|
|
111
|
-
return _array_like_to_array(o, minLen);
|
|
112
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
113
|
-
if (n === "Object" && o.constructor)
|
|
114
|
-
n = o.constructor.name;
|
|
115
|
-
if (n === "Map" || n === "Set")
|
|
116
|
-
return Array.from(n);
|
|
117
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))
|
|
118
|
-
return _array_like_to_array(o, minLen);
|
|
119
|
-
}
|
|
120
1
|
import { omit, remove } from "es-toolkit";
|
|
121
2
|
import { match, P } from "ts-pattern";
|
|
122
3
|
import { z } from "zod/v4";
|
|
@@ -124,14 +5,13 @@ import { getSchemaCache } from "./getSchemaCache.js";
|
|
|
124
5
|
import { isTypeBoxSchema, isZodSchema } from "./validate.js";
|
|
125
6
|
export function toJsonSchema(schema) {
|
|
126
7
|
if (isZodSchema(schema)) {
|
|
127
|
-
return getSchemaCache(schema, "jsonschema",
|
|
8
|
+
return getSchemaCache(schema, "jsonschema", () => {
|
|
128
9
|
// zod v4
|
|
129
|
-
|
|
10
|
+
let js = z.toJSONSchema(schema, {
|
|
130
11
|
unrepresentable: "any",
|
|
131
|
-
override:
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
var meta = z.globalRegistry.get(zodSchema);
|
|
12
|
+
override: ({ zodSchema, jsonSchema: js }) => {
|
|
13
|
+
const def = zodSchema._zod.def;
|
|
14
|
+
const meta = z.globalRegistry.get(zodSchema);
|
|
135
15
|
if (meta) {
|
|
136
16
|
Object.assign(js, meta);
|
|
137
17
|
}
|
|
@@ -155,11 +35,11 @@ export function toJsonSchema(schema) {
|
|
|
155
35
|
type: "null"
|
|
156
36
|
}
|
|
157
37
|
]
|
|
158
|
-
},
|
|
38
|
+
}, (select) => {
|
|
159
39
|
delete js["anyOf"];
|
|
160
40
|
Object.assign(js, select);
|
|
161
41
|
js.nullable = true;
|
|
162
|
-
}).otherwise(
|
|
42
|
+
}).otherwise((js) => {
|
|
163
43
|
js.nullable = true;
|
|
164
44
|
});
|
|
165
45
|
break;
|
|
@@ -167,7 +47,7 @@ export function toJsonSchema(schema) {
|
|
|
167
47
|
}
|
|
168
48
|
});
|
|
169
49
|
// remove redundant nullable, ensure required is sorted
|
|
170
|
-
visit(js,
|
|
50
|
+
visit(js, (v) => {
|
|
171
51
|
if (v.nullable === false) {
|
|
172
52
|
delete v.nullable;
|
|
173
53
|
}
|
|
@@ -185,62 +65,22 @@ export function toJsonSchema(schema) {
|
|
|
185
65
|
return schema;
|
|
186
66
|
}
|
|
187
67
|
function visit(js, f) {
|
|
188
|
-
|
|
68
|
+
const _visit = (js, f, parent, path, k) => {
|
|
189
69
|
if (!js) {
|
|
190
70
|
return;
|
|
191
71
|
}
|
|
192
72
|
f(js);
|
|
193
73
|
if (js.properties) {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
var _step_value = _sliced_to_array(_step.value, 2), k1 = _step_value[0], v = _step_value[1];
|
|
198
|
-
if (v) {
|
|
199
|
-
_visit(v, f, js, path.concat(k1), "properties");
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
catch (err) {
|
|
204
|
-
_didIteratorError = true;
|
|
205
|
-
_iteratorError = err;
|
|
206
|
-
}
|
|
207
|
-
finally {
|
|
208
|
-
try {
|
|
209
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
210
|
-
_iterator.return();
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
finally {
|
|
214
|
-
if (_didIteratorError) {
|
|
215
|
-
throw _iteratorError;
|
|
216
|
-
}
|
|
74
|
+
for (const [k, v] of Object.entries(js.properties)) {
|
|
75
|
+
if (v) {
|
|
76
|
+
_visit(v, f, js, path.concat(k), "properties");
|
|
217
77
|
}
|
|
218
78
|
}
|
|
219
79
|
}
|
|
220
80
|
else if (js.items) {
|
|
221
81
|
if (Array.isArray(js.items)) {
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
for (var _iterator1 = js.items[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true) {
|
|
225
|
-
var v1 = _step1.value;
|
|
226
|
-
_visit(v1, f, js, path, "items");
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
catch (err) {
|
|
230
|
-
_didIteratorError1 = true;
|
|
231
|
-
_iteratorError1 = err;
|
|
232
|
-
}
|
|
233
|
-
finally {
|
|
234
|
-
try {
|
|
235
|
-
if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
|
|
236
|
-
_iterator1.return();
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
finally {
|
|
240
|
-
if (_didIteratorError1) {
|
|
241
|
-
throw _iteratorError1;
|
|
242
|
-
}
|
|
243
|
-
}
|
|
82
|
+
for (const v of js.items) {
|
|
83
|
+
_visit(v, f, js, path, "items");
|
|
244
84
|
}
|
|
245
85
|
}
|
|
246
86
|
else {
|
|
@@ -248,78 +88,18 @@ function visit(js, f) {
|
|
|
248
88
|
}
|
|
249
89
|
}
|
|
250
90
|
else if (js.anyOf) {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
for (var _iterator2 = js.anyOf[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
|
254
|
-
var v2 = _step2.value;
|
|
255
|
-
_visit(v2, f, js, path, "anyOf");
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
catch (err) {
|
|
259
|
-
_didIteratorError2 = true;
|
|
260
|
-
_iteratorError2 = err;
|
|
261
|
-
}
|
|
262
|
-
finally {
|
|
263
|
-
try {
|
|
264
|
-
if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
|
|
265
|
-
_iterator2.return();
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
finally {
|
|
269
|
-
if (_didIteratorError2) {
|
|
270
|
-
throw _iteratorError2;
|
|
271
|
-
}
|
|
272
|
-
}
|
|
91
|
+
for (const v of js.anyOf) {
|
|
92
|
+
_visit(v, f, js, path, "anyOf");
|
|
273
93
|
}
|
|
274
94
|
}
|
|
275
95
|
else if (js.oneOf) {
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
for (var _iterator3 = js.oneOf[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
|
|
279
|
-
var v3 = _step3.value;
|
|
280
|
-
_visit(v3, f, js, path, "oneOf");
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
catch (err) {
|
|
284
|
-
_didIteratorError3 = true;
|
|
285
|
-
_iteratorError3 = err;
|
|
286
|
-
}
|
|
287
|
-
finally {
|
|
288
|
-
try {
|
|
289
|
-
if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
|
|
290
|
-
_iterator3.return();
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
finally {
|
|
294
|
-
if (_didIteratorError3) {
|
|
295
|
-
throw _iteratorError3;
|
|
296
|
-
}
|
|
297
|
-
}
|
|
96
|
+
for (const v of js.oneOf) {
|
|
97
|
+
_visit(v, f, js, path, "oneOf");
|
|
298
98
|
}
|
|
299
99
|
}
|
|
300
100
|
else if (js.allOf) {
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
for (var _iterator4 = js.allOf[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
|
|
304
|
-
var v4 = _step4.value;
|
|
305
|
-
_visit(v4, f, js, path, "allOf");
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
catch (err) {
|
|
309
|
-
_didIteratorError4 = true;
|
|
310
|
-
_iteratorError4 = err;
|
|
311
|
-
}
|
|
312
|
-
finally {
|
|
313
|
-
try {
|
|
314
|
-
if (!_iteratorNormalCompletion4 && _iterator4.return != null) {
|
|
315
|
-
_iterator4.return();
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
finally {
|
|
319
|
-
if (_didIteratorError4) {
|
|
320
|
-
throw _iteratorError4;
|
|
321
|
-
}
|
|
322
|
-
}
|
|
101
|
+
for (const v of js.allOf) {
|
|
102
|
+
_visit(v, f, js, path, "allOf");
|
|
323
103
|
}
|
|
324
104
|
}
|
|
325
105
|
};
|
|
@@ -333,26 +113,28 @@ function resolveJsonSchemaDef(js, ctx) {
|
|
|
333
113
|
type: "null"
|
|
334
114
|
}
|
|
335
115
|
]
|
|
336
|
-
},
|
|
337
|
-
return
|
|
338
|
-
|
|
339
|
-
|
|
116
|
+
}, (select) => {
|
|
117
|
+
return {
|
|
118
|
+
...omit(js, [
|
|
119
|
+
"anyOf"
|
|
120
|
+
]),
|
|
121
|
+
...select,
|
|
340
122
|
nullable: true
|
|
341
|
-
}
|
|
123
|
+
};
|
|
342
124
|
}).with({
|
|
343
125
|
properties: P.nonNullable
|
|
344
|
-
},
|
|
345
|
-
for (
|
|
346
|
-
|
|
126
|
+
}, (schema) => {
|
|
127
|
+
for (const key in schema.properties) {
|
|
128
|
+
const prop = schema.properties[key];
|
|
347
129
|
if (prop) {
|
|
348
130
|
schema.properties[key] = resolveJsonSchemaDef(prop, {
|
|
349
131
|
parent: schema,
|
|
350
|
-
key
|
|
132
|
+
key
|
|
351
133
|
});
|
|
352
134
|
}
|
|
353
135
|
}
|
|
354
136
|
return schema;
|
|
355
|
-
}).otherwise(
|
|
137
|
+
}).otherwise(() => {
|
|
356
138
|
return js;
|
|
357
139
|
});
|
|
358
140
|
}
|
|
@@ -363,56 +145,35 @@ function resolveDiscriminator(jsd) {
|
|
|
363
145
|
if (jsd.discriminator) {
|
|
364
146
|
return;
|
|
365
147
|
}
|
|
366
|
-
|
|
148
|
+
let names = [];
|
|
367
149
|
{
|
|
368
150
|
// candidate for discriminator
|
|
369
|
-
|
|
151
|
+
const v = jsd.anyOf[0];
|
|
370
152
|
if (v && v.type === "object" && v.properties) {
|
|
371
153
|
if (Array.isArray(v.required)) {
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
var k = _step.value;
|
|
376
|
-
if (v.properties[k].const !== undefined) {
|
|
377
|
-
names.push(k);
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
catch (err) {
|
|
382
|
-
_didIteratorError = true;
|
|
383
|
-
_iteratorError = err;
|
|
384
|
-
}
|
|
385
|
-
finally {
|
|
386
|
-
try {
|
|
387
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
388
|
-
_iterator.return();
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
finally {
|
|
392
|
-
if (_didIteratorError) {
|
|
393
|
-
throw _iteratorError;
|
|
394
|
-
}
|
|
154
|
+
for (const k of v.required) {
|
|
155
|
+
if (v.properties[k].const !== undefined) {
|
|
156
|
+
names.push(k);
|
|
395
157
|
}
|
|
396
158
|
}
|
|
397
159
|
}
|
|
398
160
|
}
|
|
399
161
|
}
|
|
400
162
|
if (names.length >= 1) {
|
|
401
|
-
|
|
163
|
+
for (let i = 0; i < jsd.anyOf.length; i++) {
|
|
402
164
|
if (i === 0) {
|
|
403
|
-
|
|
404
|
-
return "continue";
|
|
165
|
+
continue;
|
|
405
166
|
}
|
|
406
167
|
if (!names.length) {
|
|
407
|
-
|
|
168
|
+
break;
|
|
408
169
|
}
|
|
409
|
-
|
|
170
|
+
const v = jsd.anyOf[i];
|
|
410
171
|
if (v && v.type === "object" && v.properties) {
|
|
411
|
-
|
|
412
|
-
remove(names,
|
|
172
|
+
const props = v.properties;
|
|
173
|
+
remove(names, (k) => {
|
|
413
174
|
// dont care the mapping
|
|
414
|
-
|
|
415
|
-
switch (
|
|
175
|
+
let p = props[k];
|
|
176
|
+
switch (typeof p.const) {
|
|
416
177
|
case "string":
|
|
417
178
|
case "number":
|
|
418
179
|
case "boolean":
|
|
@@ -424,13 +185,8 @@ function resolveDiscriminator(jsd) {
|
|
|
424
185
|
}
|
|
425
186
|
else {
|
|
426
187
|
names = [];
|
|
427
|
-
return "break";
|
|
428
|
-
}
|
|
429
|
-
};
|
|
430
|
-
for (var i = 0; i < jsd.anyOf.length; i++) {
|
|
431
|
-
var _ret = _loop(i);
|
|
432
|
-
if (_ret === "break")
|
|
433
188
|
break;
|
|
189
|
+
}
|
|
434
190
|
}
|
|
435
191
|
}
|
|
436
192
|
if (names.length === 1) {
|
|
@@ -439,3 +195,4 @@ function resolveDiscriminator(jsd) {
|
|
|
439
195
|
};
|
|
440
196
|
}
|
|
441
197
|
}
|
|
198
|
+
//# sourceMappingURL=toJsonSchema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/schema/toJsonSchema.ts"],"sourcesContent":["import { omit, remove } from 'es-toolkit';\nimport { match, P } from 'ts-pattern';\nimport { z } from 'zod/v4';\nimport type { JsonSchemaDef } from '../jsonschema';\nimport { getSchemaCache } from './getSchemaCache';\nimport type { TypeSchema } from './TypeSchema';\nimport { isTypeBoxSchema, isZodSchema } from './validate';\n\nexport function toJsonSchema(schema: TypeSchema): JsonSchemaDef {\n\tif (isZodSchema(schema)) {\n\t\treturn getSchemaCache(schema, 'jsonschema', () => {\n\t\t\t// zod v4\n\t\t\tlet js = z.toJSONSchema(schema, {\n\t\t\t\tunrepresentable: 'any',\n\t\t\t\toverride: ({ zodSchema, jsonSchema: js }) => {\n\t\t\t\t\tconst def = zodSchema._zod.def;\n\t\t\t\t\tconst meta = z.globalRegistry.get(zodSchema);\n\t\t\t\t\tif (meta) {\n\t\t\t\t\t\tObject.assign(js, meta);\n\t\t\t\t\t}\n\t\t\t\t\tswitch (def.type) {\n\t\t\t\t\t\tcase 'union':\n\t\t\t\t\t\t\tif (zodSchema._zod.traits.has('ZodDiscriminatedUnion')) {\n\t\t\t\t\t\t\t\tresolveDiscriminator(js as JsonSchemaDef);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase 'nonoptional':\n\t\t\t\t\t\t\t// js._ref maybe true\n\t\t\t\t\t\t\tjs.nullable = false;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase 'nullable':\n\t\t\t\t\t\tcase 'optional':\n\t\t\t\t\t\t\t// prefer nullable\n\t\t\t\t\t\t\tmatch(js)\n\t\t\t\t\t\t\t\t.with({ anyOf: [P.select(), { type: 'null' }] }, (select) => {\n\t\t\t\t\t\t\t\t\tdelete js['anyOf'];\n\t\t\t\t\t\t\t\t\tObject.assign(js, select);\n\t\t\t\t\t\t\t\t\tjs.nullable = true;\n\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t.otherwise((js) => {\n\t\t\t\t\t\t\t\t\tjs.nullable = true;\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t}) as JsonSchemaDef;\n\n\t\t\t// remove redundant nullable, ensure required is sorted\n\t\t\tvisit(js, (v) => {\n\t\t\t\tif (v.nullable === false) {\n\t\t\t\t\tdelete v.nullable;\n\t\t\t\t}\n\t\t\t\tif (v.required) {\n\t\t\t\t\tv.required.sort();\n\t\t\t\t}\n\t\t\t});\n\t\t\t// maybe freeze\n\t\t\treturn js;\n\t\t});\n\t}\n\n\tif (isTypeBoxSchema(schema)) {\n\t\treturn schema as JsonSchemaDef;\n\t}\n\n\treturn schema as JsonSchemaDef;\n}\n\nfunction visit(js: JsonSchemaDef, f: (js: JsonSchemaDef) => void) {\n\tconst _visit = (\n\t\tjs: JsonSchemaDef,\n\t\tf: (js: JsonSchemaDef) => void,\n\t\tparent: JsonSchemaDef | undefined,\n\t\tpath: string[],\n\t\tk?: string,\n\t) => {\n\t\tif (!js) {\n\t\t\treturn;\n\t\t}\n\t\tf(js);\n\t\tif (js.properties) {\n\t\t\tfor (const [k, v] of Object.entries(js.properties)) {\n\t\t\t\tif (v) {\n\t\t\t\t\t_visit(v, f, js, path.concat(k), 'properties');\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (js.items) {\n\t\t\tif (Array.isArray(js.items)) {\n\t\t\t\tfor (const v of js.items) {\n\t\t\t\t\t_visit(v, f, js, path, 'items');\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t_visit(js.items, f, js, path, 'items');\n\t\t\t}\n\t\t} else if (js.anyOf) {\n\t\t\tfor (const v of js.anyOf) {\n\t\t\t\t_visit(v, f, js, path, 'anyOf');\n\t\t\t}\n\t\t} else if (js.oneOf) {\n\t\t\tfor (const v of js.oneOf) {\n\t\t\t\t_visit(v, f, js, path, 'oneOf');\n\t\t\t}\n\t\t} else if (js.allOf) {\n\t\t\tfor (const v of js.allOf) {\n\t\t\t\t_visit(v, f, js, path, 'allOf');\n\t\t\t}\n\t\t}\n\t};\n\t_visit(js, f, undefined, []);\n}\n\nfunction resolveJsonSchemaDef(\n\tjs: JsonSchemaDef,\n\tctx?: {\n\t\tparent: JsonSchemaDef;\n\t\tkey: string;\n\t},\n) {\n\treturn match(js)\n\t\t.with(\n\t\t\t{\n\t\t\t\tanyOf: [P.select(), { type: 'null' }],\n\t\t\t},\n\t\t\t(select) => {\n\t\t\t\treturn { ...omit(js, ['anyOf']), ...select, nullable: true };\n\t\t\t},\n\t\t)\n\t\t.with({ properties: P.nonNullable }, (schema: JsonSchemaDef) => {\n\t\t\tfor (const key in schema.properties) {\n\t\t\t\tconst prop = schema.properties[key];\n\t\t\t\tif (prop) {\n\t\t\t\t\tschema.properties[key] = resolveJsonSchemaDef(prop, { parent: schema, key });\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn schema;\n\t\t})\n\t\t.otherwise(() => {\n\t\t\treturn js;\n\t\t});\n}\n\nfunction resolveDiscriminator(jsd: JsonSchemaDef) {\n\tif (!(jsd.anyOf && jsd.anyOf.length > 1)) {\n\t\treturn;\n\t}\n\tif (jsd.discriminator) {\n\t\treturn;\n\t}\n\n\tlet names: string[] = [];\n\t{\n\t\t// candidate for discriminator\n\t\tconst v = jsd.anyOf[0];\n\t\tif (v && v.type === 'object' && v.properties) {\n\t\t\tif (Array.isArray(v.required)) {\n\t\t\t\tfor (const k of v.required) {\n\t\t\t\t\tif (v.properties[k].const !== undefined) {\n\t\t\t\t\t\tnames.push(k);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tif (names.length >= 1) {\n\t\tfor (let i = 0; i < jsd.anyOf.length; i++) {\n\t\t\tif (i === 0) {\n\t\t\t\t// skip first\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (!names.length) {\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tconst v = jsd.anyOf[i];\n\t\t\tif (v && v.type === 'object' && v.properties) {\n\t\t\t\tconst props = v.properties;\n\t\t\t\tremove(names, (k) => {\n\t\t\t\t\t// dont care the mapping\n\t\t\t\t\tlet p = props[k];\n\t\t\t\t\tswitch (typeof p.const) {\n\t\t\t\t\t\tcase 'string':\n\t\t\t\t\t\tcase 'number':\n\t\t\t\t\t\tcase 'boolean':\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\treturn true;\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tnames = [];\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\tif (names.length === 1) {\n\t\tjsd.discriminator = {\n\t\t\tpropertyName: names[0],\n\t\t};\n\t}\n}\n"],"names":["omit","remove","match","P","z","getSchemaCache","isTypeBoxSchema","isZodSchema","toJsonSchema","schema","js","toJSONSchema","unrepresentable","override","zodSchema","jsonSchema","def","_zod","meta","globalRegistry","get","Object","assign","type","traits","has","resolveDiscriminator","nullable","with","anyOf","select","otherwise","visit","v","required","sort","f","_visit","parent","path","k","properties","entries","concat","items","Array","isArray","oneOf","allOf","undefined","resolveJsonSchemaDef","ctx","nonNullable","key","prop","jsd","length","discriminator","names","const","push","i","props","p","propertyName"],"mappings":"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"}
|
package/lib/schema/validate.js
CHANGED
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
import { TypeCompiler } from '@sinclair/typebox/compiler';
|
|
8
|
-
import { ifPresent } from '@wener/utils';
|
|
9
|
-
import { Ajv } from 'ajv';
|
|
10
|
-
import addFormats from 'ajv-formats';
|
|
1
|
+
import { Kind as TypeBoxKind } from "@sinclair/typebox";
|
|
2
|
+
import "@sinclair/typebox";
|
|
3
|
+
import { TypeCompiler } from "@sinclair/typebox/compiler";
|
|
4
|
+
import { ifPresent } from "@wener/utils";
|
|
5
|
+
import { Ajv } from "ajv";
|
|
6
|
+
import addFormats from "ajv-formats";
|
|
11
7
|
/*
|
|
12
8
|
https://github.com/react-hook-form/resolvers
|
|
13
9
|
https://github.com/decs/typeschema/tree/main/packages
|
|
14
10
|
*/ export function validate(schema, data) {
|
|
15
11
|
if (isZodSchema(schema)) {
|
|
16
|
-
|
|
12
|
+
const result = schema.safeParse(data);
|
|
17
13
|
if (result.success) {
|
|
18
14
|
return {
|
|
19
15
|
success: true,
|
|
@@ -21,20 +17,17 @@ https://github.com/decs/typeschema/tree/main/packages
|
|
|
21
17
|
};
|
|
22
18
|
}
|
|
23
19
|
return {
|
|
24
|
-
issues: result.error.issues.map(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
code: code
|
|
30
|
-
};
|
|
31
|
-
}),
|
|
20
|
+
issues: result.error.issues.map(({ message, path, code })=>({
|
|
21
|
+
message,
|
|
22
|
+
path,
|
|
23
|
+
code
|
|
24
|
+
})),
|
|
32
25
|
// message: z.prettifyError(result.error),
|
|
33
26
|
success: false
|
|
34
27
|
};
|
|
35
28
|
}
|
|
36
29
|
if (isTypeBoxSchema(schema)) {
|
|
37
|
-
|
|
30
|
+
const checker = TypeCompiler.Compile(schema);
|
|
38
31
|
if (checker.Check(data)) {
|
|
39
32
|
return {
|
|
40
33
|
success: true,
|
|
@@ -42,10 +35,9 @@ https://github.com/decs/typeschema/tree/main/packages
|
|
|
42
35
|
};
|
|
43
36
|
}
|
|
44
37
|
return {
|
|
45
|
-
issues: Array.from(checker.Errors(data)).map(
|
|
46
|
-
var message = param.message, path = param.path;
|
|
38
|
+
issues: Array.from(checker.Errors(data)).map(({ message, path })=>{
|
|
47
39
|
return {
|
|
48
|
-
message
|
|
40
|
+
message,
|
|
49
41
|
path: [
|
|
50
42
|
path
|
|
51
43
|
]
|
|
@@ -56,33 +48,30 @@ https://github.com/decs/typeschema/tree/main/packages
|
|
|
56
48
|
};
|
|
57
49
|
}
|
|
58
50
|
if (isJsonSchema(schema)) {
|
|
59
|
-
|
|
60
|
-
var ajv = new Ajv({
|
|
51
|
+
const ajv = new Ajv({
|
|
61
52
|
allErrors: true,
|
|
62
53
|
validateSchema: true
|
|
63
54
|
});
|
|
64
55
|
addFormats(ajv);
|
|
65
|
-
|
|
56
|
+
const validator = ajv.compile(schema);
|
|
66
57
|
if (validator(data)) {
|
|
67
58
|
return {
|
|
68
59
|
data: data,
|
|
69
60
|
success: true
|
|
70
61
|
};
|
|
71
62
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
return p;
|
|
76
|
-
});
|
|
63
|
+
const issues = validator.errors?.map((error)=>{
|
|
64
|
+
const message = error.message || 'Unknown error';
|
|
65
|
+
const path = error.instancePath.split('/').filter(Boolean).map((p)=>p);
|
|
77
66
|
return {
|
|
78
|
-
message
|
|
79
|
-
path
|
|
67
|
+
message,
|
|
68
|
+
path
|
|
80
69
|
};
|
|
81
|
-
})
|
|
70
|
+
}) || [];
|
|
82
71
|
return {
|
|
83
72
|
success: false,
|
|
84
73
|
// message: 'Invalid data',
|
|
85
|
-
issues
|
|
74
|
+
issues
|
|
86
75
|
};
|
|
87
76
|
}
|
|
88
77
|
return {
|
|
@@ -96,15 +85,12 @@ https://github.com/decs/typeschema/tree/main/packages
|
|
|
96
85
|
};
|
|
97
86
|
}
|
|
98
87
|
export function parseData(schema, data) {
|
|
99
|
-
|
|
88
|
+
let result = validate(schema, data);
|
|
100
89
|
if (result.success) {
|
|
101
90
|
return result.data;
|
|
102
91
|
}
|
|
103
|
-
throw Object.assign(new Error(result.issues.map(
|
|
104
|
-
|
|
105
|
-
return "".concat(ifPresent((_v_path = v.path) === null || _v_path === void 0 ? void 0 : _v_path.join(), function(v) {
|
|
106
|
-
return "[".concat(v, "]");
|
|
107
|
-
}), ": ").concat(v.message);
|
|
92
|
+
throw Object.assign(new Error(result.issues.map((v)=>{
|
|
93
|
+
return `${ifPresent(v.path?.join(), (v)=>`[${v}]`)}: ${v.message}`;
|
|
108
94
|
}).join('; ')), {
|
|
109
95
|
issues: result.issues
|
|
110
96
|
});
|
|
@@ -113,12 +99,14 @@ function formatIssues(schema, issues) {
|
|
|
113
99
|
return '';
|
|
114
100
|
}
|
|
115
101
|
export function isZodSchema(schema) {
|
|
116
|
-
return
|
|
102
|
+
return typeof schema === 'object' && 'parse' in schema;
|
|
117
103
|
}
|
|
118
104
|
export function isTypeBoxSchema(schema) {
|
|
119
|
-
return
|
|
105
|
+
return typeof schema === 'object' && TypeBoxKind in schema;
|
|
120
106
|
}
|
|
121
107
|
export function isJsonSchema(schema) {
|
|
122
|
-
|
|
123
|
-
return
|
|
108
|
+
let sc = schema;
|
|
109
|
+
return typeof schema === 'object' && Boolean(sc.type || sc.properties || sc.anyOf || sc.oneOf || sc.$ref || sc.items);
|
|
124
110
|
}
|
|
111
|
+
|
|
112
|
+
//# sourceMappingURL=validate.js.map
|