@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,18 +1,16 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
import addKeywords from
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var ajv = new Ajv(opt);
|
|
1
|
+
import { isNil } from "@wener/utils";
|
|
2
|
+
import Ajv from "ajv";
|
|
3
|
+
import addFormats from "ajv-formats";
|
|
4
|
+
import addKeywords from "ajv-keywords";
|
|
5
|
+
import { match, P } from "ts-pattern";
|
|
6
|
+
function _createValidator(opt) {
|
|
7
|
+
const ajv = new Ajv(opt);
|
|
9
8
|
addKeywords(ajv);
|
|
10
9
|
addFormats(ajv);
|
|
11
10
|
return ajv;
|
|
12
11
|
}
|
|
13
|
-
function validate(
|
|
14
|
-
|
|
15
|
-
var opts = {
|
|
12
|
+
function validate({ schema, data, mutate, clone, validator }) {
|
|
13
|
+
let opts = {
|
|
16
14
|
// strict: 'log',
|
|
17
15
|
strict: true,
|
|
18
16
|
strictSchema: 'log'
|
|
@@ -28,179 +26,155 @@ function validate(param) {
|
|
|
28
26
|
if (clone) {
|
|
29
27
|
data = structuredClone(data);
|
|
30
28
|
}
|
|
31
|
-
if (!
|
|
32
|
-
|
|
29
|
+
if (!validator) {
|
|
30
|
+
validator = JsonSchema.createValidator(opts);
|
|
33
31
|
}
|
|
34
|
-
|
|
32
|
+
const validate = validator.compile(schema);
|
|
35
33
|
// consider reusing validate instance
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
const valid = validate(data);
|
|
35
|
+
const errors = validate.errors;
|
|
38
36
|
// localize(errors);
|
|
39
37
|
return {
|
|
40
|
-
data
|
|
38
|
+
data,
|
|
41
39
|
success: valid,
|
|
42
|
-
message:
|
|
40
|
+
message: validator.errorsText(errors),
|
|
43
41
|
errors: errors
|
|
44
42
|
};
|
|
45
43
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
break;
|
|
63
|
-
case 'throw':
|
|
64
|
-
onConflict = function(old, neo) {
|
|
65
|
-
throw new Error("Schema ".concat(neo.$id, " already exists"));
|
|
66
|
-
};
|
|
67
|
-
break;
|
|
68
|
-
}
|
|
69
|
-
var idx = JsonSchema.schemas.findIndex(function(s) {
|
|
70
|
-
return s.$id === schema.$id;
|
|
71
|
-
});
|
|
72
|
-
if (idx >= 0) {
|
|
73
|
-
JsonSchema.schemas[idx] = onConflict(JsonSchema.schemas[idx], schema);
|
|
74
|
-
} else {
|
|
75
|
-
JsonSchema.schemas.push(schema);
|
|
76
|
-
}
|
|
44
|
+
let schemas = [];
|
|
45
|
+
let createValidator = _createValidator;
|
|
46
|
+
function addSchema(schema, { onConflict = 'throw' } = {}) {
|
|
47
|
+
if (!schema.$id) throw new Error('Schema must have $id');
|
|
48
|
+
switch(onConflict){
|
|
49
|
+
case 'ignore':
|
|
50
|
+
onConflict = (old)=>old;
|
|
51
|
+
break;
|
|
52
|
+
case 'replace':
|
|
53
|
+
onConflict = (_, neo)=>neo;
|
|
54
|
+
break;
|
|
55
|
+
case 'throw':
|
|
56
|
+
onConflict = (old, neo)=>{
|
|
57
|
+
throw new Error(`Schema ${neo.$id} already exists`);
|
|
58
|
+
};
|
|
59
|
+
break;
|
|
77
60
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
mutate: false,
|
|
84
|
-
clone: true
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Check data is valid, will not use default
|
|
89
|
-
*/ JsonSchema.check = check;
|
|
90
|
-
function safeParse(schema, data) {
|
|
91
|
-
return validate({
|
|
92
|
-
schema: schema,
|
|
93
|
-
data: data,
|
|
94
|
-
mutate: true,
|
|
95
|
-
clone: true
|
|
96
|
-
});
|
|
61
|
+
let idx = schemas.findIndex((s)=>s.$id === schema.$id);
|
|
62
|
+
if (idx >= 0) {
|
|
63
|
+
schemas[idx] = onConflict(schemas[idx], schema);
|
|
64
|
+
} else {
|
|
65
|
+
schemas.push(schema);
|
|
97
66
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Check data is valid, will not use default
|
|
70
|
+
*/ function check(schema, data) {
|
|
71
|
+
return validate({
|
|
72
|
+
schema,
|
|
73
|
+
data,
|
|
74
|
+
mutate: false,
|
|
75
|
+
clone: true
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Parse data with default value and coerceTypes
|
|
80
|
+
*/ function safeParse(schema, data) {
|
|
81
|
+
return validate({
|
|
82
|
+
schema,
|
|
83
|
+
data,
|
|
84
|
+
mutate: true,
|
|
85
|
+
clone: true
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
function parse(schema, data) {
|
|
89
|
+
const { data: out, message, errors } = validate({
|
|
90
|
+
schema,
|
|
91
|
+
data,
|
|
92
|
+
mutate: true,
|
|
93
|
+
clone: true
|
|
94
|
+
});
|
|
95
|
+
if (errors) {
|
|
96
|
+
throw new Error(message);
|
|
112
97
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
})
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
98
|
+
return out;
|
|
99
|
+
}
|
|
100
|
+
function create(schema, data) {
|
|
101
|
+
// will not ensure value match the rule
|
|
102
|
+
return match(schema).returnType().with({
|
|
103
|
+
const: P.nonNullable
|
|
104
|
+
}, (v)=>v).with({
|
|
105
|
+
default: P.select()
|
|
106
|
+
}, (v)=>v).with({
|
|
107
|
+
anyOf: P.nonNullable
|
|
108
|
+
}, (schema)=>{
|
|
109
|
+
return create(schema.anyOf[0]);
|
|
110
|
+
}).with({
|
|
111
|
+
oneOf: P.nonNullable
|
|
112
|
+
}, (schema)=>{
|
|
113
|
+
return create(schema.oneOf[0]);
|
|
114
|
+
}).with({
|
|
115
|
+
type: 'string'
|
|
116
|
+
}, (schema)=>'').with({
|
|
117
|
+
type: P.union('number', 'integer')
|
|
118
|
+
}, (schema)=>0).with({
|
|
119
|
+
type: 'object'
|
|
120
|
+
}, (schema)=>{
|
|
121
|
+
let out = validate({
|
|
122
|
+
schema,
|
|
123
|
+
data: data ?? {},
|
|
124
|
+
mutate: true
|
|
125
|
+
});
|
|
126
|
+
if (!out.success) {
|
|
127
|
+
// fallback
|
|
128
|
+
let obj = data || {};
|
|
129
|
+
schema.required?.forEach((key)=>{
|
|
130
|
+
if (!(key in obj)) {
|
|
131
|
+
let last = obj[key];
|
|
132
|
+
let prop = schema.properties?.[key];
|
|
133
|
+
if (prop && isNil(last)) obj[key] = JsonSchema.create(prop, last);
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
out = validate({
|
|
137
|
+
schema,
|
|
138
|
+
data: obj,
|
|
146
139
|
mutate: true
|
|
147
140
|
});
|
|
148
141
|
if (!out.success) {
|
|
149
|
-
|
|
150
|
-
// fallback
|
|
151
|
-
var obj = data || {};
|
|
152
|
-
(_schema_required = schema.required) === null || _schema_required === void 0 ? void 0 : _schema_required.forEach(function(key) {
|
|
153
|
-
if (!(key in obj)) {
|
|
154
|
-
var _schema_properties;
|
|
155
|
-
var last = obj[key];
|
|
156
|
-
var prop = (_schema_properties = schema.properties) === null || _schema_properties === void 0 ? void 0 : _schema_properties[key];
|
|
157
|
-
if (prop && isNil(last)) obj[key] = JsonSchema.create(prop, last);
|
|
158
|
-
}
|
|
159
|
-
});
|
|
160
|
-
out = validate({
|
|
161
|
-
schema: schema,
|
|
162
|
-
data: obj,
|
|
163
|
-
mutate: true
|
|
164
|
-
});
|
|
165
|
-
if (!out.success) {
|
|
166
|
-
console.warn("Failed to create object with schema: ".concat(out.message));
|
|
167
|
-
}
|
|
142
|
+
console.warn(`Failed to create object with schema: ${out.message}`);
|
|
168
143
|
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
export var JsonSchema;
|
|
144
|
+
}
|
|
145
|
+
return out.data;
|
|
146
|
+
}).with({
|
|
147
|
+
type: 'null'
|
|
148
|
+
}, ()=>null).with({
|
|
149
|
+
type: 'boolean'
|
|
150
|
+
}, (schema)=>false).with({
|
|
151
|
+
type: 'array'
|
|
152
|
+
}, (schema)=>[]).otherwise(()=>{
|
|
153
|
+
return undefined;
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
function isPrimitiveType(schema) {
|
|
157
|
+
return match(schema).returnType().with({
|
|
158
|
+
type: P.union('number', 'integer', 'string', 'boolean')
|
|
159
|
+
}, ()=>true).with({
|
|
160
|
+
anyOf: P.nonNullable
|
|
161
|
+
}, (schema)=>{
|
|
162
|
+
return isPrimitiveType(schema.anyOf[0]);
|
|
163
|
+
}).with({
|
|
164
|
+
oneOf: P.nonNullable
|
|
165
|
+
}, (schema)=>{
|
|
166
|
+
return isPrimitiveType(schema.oneOf[0]);
|
|
167
|
+
}).otherwise(()=>false);
|
|
168
|
+
}
|
|
169
|
+
export const JsonSchema = {
|
|
170
|
+
createValidator,
|
|
171
|
+
addSchema,
|
|
172
|
+
schemas,
|
|
173
|
+
check,
|
|
174
|
+
safeParse,
|
|
175
|
+
parse,
|
|
176
|
+
create,
|
|
177
|
+
isPrimitiveType
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
//# sourceMappingURL=JsonSchema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/jsonschema/JsonSchema.ts"],"sourcesContent":["import type { Static, TSchema } from '@sinclair/typebox';\nimport { isNil } from '@wener/utils';\nimport Ajv, { type ErrorObject, type Options } from 'ajv';\nimport addFormats from 'ajv-formats';\nimport addKeywords from 'ajv-keywords';\nimport { match, P } from 'ts-pattern';\nimport type { JsonSchemaDef } from './types';\n\nfunction _createValidator(opt: Options) {\n\tconst ajv = new Ajv(opt);\n\taddKeywords(ajv);\n\taddFormats(ajv);\n\treturn ajv;\n}\n\ntype ValidateOptions = { mutate?: boolean; clone?: boolean; validator?: Ajv };\n\ntype ValidateResult<T> =\n\t| { data: T; success: true; message: undefined }\n\t| { data: undefined; success: false; message: string; errors: ErrorObject[] };\n\nfunction validate({ schema, data, mutate, clone, validator }: ValidateOptions & { schema: any; data: any }) {\n\tlet opts: Options = {\n\t\t// strict: 'log',\n\t\tstrict: true,\n\t\tstrictSchema: 'log', // skip unknown keywords in schema\n\t};\n\n\tif (mutate) {\n\t\tObject.assign(opts, { removeAdditional: true, useDefaults: true, coerceTypes: true, allErrors: true });\n\t}\n\n\tif (clone) {\n\t\tdata = structuredClone(data);\n\t}\n\n\tif (!validator) {\n\t\tvalidator = JsonSchema.createValidator(opts);\n\t}\n\n\tconst validate = validator.compile(schema);\n\n\t// consider reusing validate instance\n\n\tconst valid = validate(data);\n\tconst errors = validate.errors;\n\t// localize(errors);\n\n\treturn { data, success: valid, message: validator.errorsText(errors), errors: errors };\n}\n\ntype TypeOfSchema<S> = S extends TSchema ? Static<S> : any;\n\nlet schemas: JsonSchemaDef[] = [];\n\nlet createValidator = _createValidator;\n\nfunction addSchema(\n\tschema: JsonSchemaDef,\n\t{\n\t\tonConflict = 'throw',\n\t}: {\n\t\tonConflict?: 'throw' | 'ignore' | 'replace' | ((old: JsonSchemaDef, neo: JsonSchemaDef) => JsonSchemaDef);\n\t} = {},\n) {\n\tif (!schema.$id) throw new Error('Schema must have $id');\n\tswitch (onConflict) {\n\t\tcase 'ignore':\n\t\t\tonConflict = (old) => old;\n\t\t\tbreak;\n\t\tcase 'replace':\n\t\t\tonConflict = (_, neo) => neo;\n\t\t\tbreak;\n\t\tcase 'throw':\n\t\t\tonConflict = (old, neo) => {\n\t\t\t\tthrow new Error(`Schema ${neo.$id} already exists`);\n\t\t\t};\n\t\t\tbreak;\n\t}\n\tlet idx = schemas.findIndex((s) => s.$id === schema.$id);\n\tif (idx >= 0) {\n\t\tschemas[idx] = onConflict(schemas[idx], schema);\n\t} else {\n\t\tschemas.push(schema);\n\t}\n}\n\n/**\n * Check data is valid, will not use default\n */\nfunction check<S>(schema: S, data: any): ValidateResult<TypeOfSchema<S>> {\n\treturn validate({ schema, data, mutate: false, clone: true }) as any;\n}\n\n/**\n * Parse data with default value and coerceTypes\n */\nfunction safeParse<S>(schema: S, data: any): ValidateResult<TypeOfSchema<S>> {\n\treturn validate({ schema, data, mutate: true, clone: true }) as any;\n}\n\nfunction parse<S>(schema: S, data: any): TypeOfSchema<S> {\n\tconst { data: out, message, errors } = validate({ schema, data, mutate: true, clone: true });\n\tif (errors) {\n\t\tthrow new Error(message);\n\t}\n\treturn out;\n}\n\nfunction create<S>(schema: S, data?: any): TypeOfSchema<S> {\n\t// will not ensure value match the rule\n\treturn match(schema as JsonSchemaDef)\n\t\t.returnType<any>()\n\t\t.with({ const: P.nonNullable }, (v) => v)\n\t\t.with({ default: P.select() }, (v) => v)\n\t\t.with({ anyOf: P.nonNullable }, (schema) => {\n\t\t\treturn create(schema.anyOf[0]);\n\t\t})\n\t\t.with({ oneOf: P.nonNullable }, (schema) => {\n\t\t\treturn create(schema.oneOf[0]);\n\t\t})\n\t\t.with({ type: 'string' }, (schema) => '')\n\t\t.with({ type: P.union('number', 'integer') }, (schema) => 0)\n\t\t.with({ type: 'object' }, (schema: JsonSchemaDef) => {\n\t\t\tlet out = validate({ schema, data: data ?? {}, mutate: true });\n\t\t\tif (!out.success) {\n\t\t\t\t// fallback\n\t\t\t\tlet obj = data || {};\n\t\t\t\tschema.required?.forEach((key) => {\n\t\t\t\t\tif (!(key in obj)) {\n\t\t\t\t\t\tlet last = obj[key];\n\t\t\t\t\t\tlet prop = schema.properties?.[key];\n\t\t\t\t\t\tif (prop && isNil(last)) obj[key] = JsonSchema.create(prop, last);\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t\tout = validate({ schema, data: obj, mutate: true });\n\t\t\t\tif (!out.success) {\n\t\t\t\t\tconsole.warn(`Failed to create object with schema: ${out.message}`);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn out.data;\n\t\t})\n\t\t.with({ type: 'null' }, () => null)\n\t\t.with({ type: 'boolean' }, (schema) => false)\n\t\t.with({ type: 'array' }, (schema) => [])\n\t\t.otherwise(() => {\n\t\t\treturn undefined;\n\t\t});\n}\n\nfunction isPrimitiveType(schema: any): boolean {\n\treturn match(schema as JsonSchemaDef)\n\t\t.returnType<boolean>()\n\t\t.with({ type: P.union('number', 'integer', 'string', 'boolean') }, () => true)\n\t\t.with({ anyOf: P.nonNullable }, (schema) => {\n\t\t\treturn isPrimitiveType(schema.anyOf[0]);\n\t\t})\n\t\t.with({ oneOf: P.nonNullable }, (schema) => {\n\t\t\treturn isPrimitiveType(schema.oneOf[0]);\n\t\t})\n\t\t.otherwise(() => false);\n}\n\nexport const JsonSchema = {\n\tcreateValidator,\n\taddSchema,\n\tschemas,\n\tcheck,\n\tsafeParse,\n\tparse,\n\tcreate,\n\tisPrimitiveType,\n} as const;\n"],"names":["isNil","Ajv","addFormats","addKeywords","match","P","_createValidator","opt","ajv","validate","schema","data","mutate","clone","validator","opts","strict","strictSchema","Object","assign","removeAdditional","useDefaults","coerceTypes","allErrors","structuredClone","JsonSchema","createValidator","compile","valid","errors","success","message","errorsText","schemas","addSchema","onConflict","$id","Error","old","_","neo","idx","findIndex","s","push","check","safeParse","parse","out","create","returnType","with","const","nonNullable","v","default","select","anyOf","oneOf","type","union","obj","required","forEach","key","last","prop","properties","console","warn","otherwise","undefined","isPrimitiveType"],"mappings":"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"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export function forEachJsonSchema(js, cb) {
|
|
2
|
+
const ctx = {
|
|
3
|
+
path: []
|
|
4
|
+
};
|
|
5
|
+
const _visit = (js, _f, parent, path, k)=>{
|
|
6
|
+
if (!js) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
ctx.path = path;
|
|
10
|
+
ctx.parent = parent;
|
|
11
|
+
_f(js, ctx);
|
|
12
|
+
if (js.properties) {
|
|
13
|
+
for (const [k, v] of Object.entries(js.properties)){
|
|
14
|
+
if (v) {
|
|
15
|
+
_visit(v, _f, js, path.concat(k), 'properties');
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
} else if (js.items) {
|
|
19
|
+
// array should be `key[].subkey` or `key.*.subkey`?
|
|
20
|
+
if (Array.isArray(js.items)) {
|
|
21
|
+
for (const v of js.items){
|
|
22
|
+
_visit(v, _f, js, path, 'items');
|
|
23
|
+
}
|
|
24
|
+
} else {
|
|
25
|
+
_visit(js.items, _f, js, path, 'items');
|
|
26
|
+
}
|
|
27
|
+
} else if (js.anyOf) {
|
|
28
|
+
for (const v of js.anyOf){
|
|
29
|
+
_visit(v, _f, js, path, 'anyOf');
|
|
30
|
+
}
|
|
31
|
+
} else if (js.oneOf) {
|
|
32
|
+
for (const v of js.oneOf){
|
|
33
|
+
_visit(v, _f, js, path, 'oneOf');
|
|
34
|
+
}
|
|
35
|
+
} else if (js.allOf) {
|
|
36
|
+
for (const v of js.allOf){
|
|
37
|
+
_visit(v, _f, js, path, 'allOf');
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
_visit(js, cb, undefined, []);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
//# sourceMappingURL=forEachJsonSchema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/jsonschema/forEachJsonSchema.ts"],"sourcesContent":["import type { JsonSchemaDef } from './types';\n\nexport type VisitJsonSchemaContext = { path: string[]; parent?: JsonSchemaDef };\n\nexport function forEachJsonSchema(js: JsonSchemaDef, cb: (js: JsonSchemaDef, ctx: VisitJsonSchemaContext) => void) {\n\tconst ctx: VisitJsonSchemaContext = { path: [] };\n\tconst _visit = (\n\t\tjs: JsonSchemaDef,\n\t\t_f: (js: JsonSchemaDef, ctx: VisitJsonSchemaContext) => 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\tctx.path = path;\n\t\tctx.parent = parent;\n\t\t_f(js, ctx);\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\t// array should be `key[].subkey` or `key.*.subkey`?\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, cb, undefined, []);\n}\n"],"names":["forEachJsonSchema","js","cb","ctx","path","_visit","_f","parent","k","properties","v","Object","entries","concat","items","Array","isArray","anyOf","oneOf","allOf","undefined"],"mappings":"AAIA,OAAO,SAASA,kBAAkBC,EAAiB,EAAEC,EAA4D;IAChH,MAAMC,MAA8B;QAAEC,MAAM,EAAE;IAAC;IAC/C,MAAMC,SAAS,CACdJ,IACAK,IACAC,QACAH,MACAI;QAEA,IAAI,CAACP,IAAI;YACR;QACD;QACAE,IAAIC,IAAI,GAAGA;QACXD,IAAII,MAAM,GAAGA;QACbD,GAAGL,IAAIE;QACP,IAAIF,GAAGQ,UAAU,EAAE;YAClB,KAAK,MAAM,CAACD,GAAGE,EAAE,IAAIC,OAAOC,OAAO,CAACX,GAAGQ,UAAU,EAAG;gBACnD,IAAIC,GAAG;oBACNL,OAAOK,GAAGJ,IAAIL,IAAIG,KAAKS,MAAM,CAACL,IAAI;gBACnC;YACD;QACD,OAAO,IAAIP,GAAGa,KAAK,EAAE;YACpB,oDAAoD;YACpD,IAAIC,MAAMC,OAAO,CAACf,GAAGa,KAAK,GAAG;gBAC5B,KAAK,MAAMJ,KAAKT,GAAGa,KAAK,CAAE;oBACzBT,OAAOK,GAAGJ,IAAIL,IAAIG,MAAM;gBACzB;YACD,OAAO;gBACNC,OAAOJ,GAAGa,KAAK,EAAER,IAAIL,IAAIG,MAAM;YAChC;QACD,OAAO,IAAIH,GAAGgB,KAAK,EAAE;YACpB,KAAK,MAAMP,KAAKT,GAAGgB,KAAK,CAAE;gBACzBZ,OAAOK,GAAGJ,IAAIL,IAAIG,MAAM;YACzB;QACD,OAAO,IAAIH,GAAGiB,KAAK,EAAE;YACpB,KAAK,MAAMR,KAAKT,GAAGiB,KAAK,CAAE;gBACzBb,OAAOK,GAAGJ,IAAIL,IAAIG,MAAM;YACzB;QACD,OAAO,IAAIH,GAAGkB,KAAK,EAAE;YACpB,KAAK,MAAMT,KAAKT,GAAGkB,KAAK,CAAE;gBACzBd,OAAOK,GAAGJ,IAAIL,IAAIG,MAAM;YACzB;QACD;IACD;IACAC,OAAOJ,IAAIC,IAAIkB,WAAW,EAAE;AAC7B"}
|
package/lib/jsonschema/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/jsonschema/index.ts"],"sourcesContent":["export { JsonSchema } from './JsonSchema';\nexport type { JsonSchemaDef } from './types';\nexport { forEachJsonSchema } from './forEachJsonSchema';\n"],"names":["JsonSchema","forEachJsonSchema"],"mappings":"AAAA,SAASA,UAAU,QAAQ,eAAe;AAE1C,SAASC,iBAAiB,QAAQ,sBAAsB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/jsonschema/types.d.ts"],"sourcesContent":["type JsonSchemaTypeName =\n\t| 'string' //\n\t| 'number'\n\t| 'integer'\n\t| 'boolean'\n\t| 'object'\n\t| 'array'\n\t| 'null'\n\t| undefined;\n\ntype JsonValue =\n\t| string //\n\t| number\n\t| boolean\n\t| { [key: string]: JsonValue }\n\t| JsonValue[]\n\t| null\n\t| undefined; //\n\ntype JsonSchemaVersion =\n\t| 'http://json-schema.org/schema' // latest\n\t//\n\t| 'https://json-schema.org/draft/2020-12/schema'\n\t| 'https://json-schema.org/draft/2019-09/schema'\n\t// draft-07\n\t| 'https://json-schema.org/draft-07/schema'\n\t| 'http://json-schema.org/draft-07/schema'\n\t| 'https://json-schema.org/draft-07/hyper-schema'\n\t| 'http://json-schema.org/draft-07/hyper-schema'\n\t//\n\t| 'https://json-schema.org/draft-04/schema';\ntype JsonSchemaFormatName =\n\t//\n\t| 'date-time'\n\t| 'date'\n\t| 'time'\n\t| 'duration'\n\t//\n\t| 'email'\n\t| 'idn-email'\n\t//\n\t| 'hostname'\n\t| 'idn-hostname'\n\t| 'ipv4'\n\t| 'ipv6'\n\t//\n\t| 'uri'\n\t| 'uri-reference'\n\t| 'iri'\n\t| 'iri-reference'\n\t| 'uuid'\n\t| 'uri-template'\n\t| 'regex'\n\t| 'json-pointer'\n\t| 'relative-json-pointer';\n\n/**\n * JSON Schema Definition\n *\n * @see https://json-schema.org/specification-links.html\n */\nexport type JsonSchemaDef<I = any, O = I> = {\n\t$id?: string;\n\t$ref?: string;\n\t/**\n\t * Meta schema\n\t *\n\t * Recommended values:\n\t * - 'http://json-schema.org/schema#'\n\t * - 'http://json-schema.org/hyper-schema#'\n\t * - 'http://json-schema.org/draft-07/schema#'\n\t * - 'http://json-schema.org/draft-07/hyper-schema#'\n\t *\n\t * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-5\n\t */\n\t$schema?: JsonSchemaVersion | string;\n\t$comment?: string;\n\n\t$defs?: { [key: string]: JsonSchemaDef };\n\n\ttype?: JsonSchemaTypeName | JsonSchemaTypeName[];\n\tenum?: JsonValue;\n\tconst?: JsonValue;\n\n\t//region Numeric Validation\n\n\tmultipleOf?: number;\n\tmaximum?: number;\n\texclusiveMaximum?: number;\n\tminimum?: number;\n\texclusiveMinimum?: number;\n\n\t//endregion\n\n\t//region String Validation\n\n\tmaxLength?: number;\n\tminLength?: number;\n\tpattern?: string;\n\n\t//endregion\n\n\t//region Array Validation\n\n\t/**\n\t * schema for array items\n\t * @see https://json-schema.org/understanding-json-schema/reference/array.html#items\n\t */\n\titems?: JsonSchemaDef | JsonSchemaDef[];\n\tadditionalItems?: JsonSchemaDef | boolean;\n\tmaxItems?: number;\n\tminItems?: number;\n\tuniqueItems?: boolean;\n\tcontains?: JsonSchemaDef;\n\n\t//region Draft 2022-12\n\tminContains?: number;\n\tmaxContains?: number;\n\tprefixItems?: JsonSchemaDef[];\n\t//endregion\n\n\t//endregion\n\n\t//region Object Validation\n\n\tmaxProperties?: number;\n\tminProperties?: number;\n\trequired?: string[];\n\tproperties?: { [key: string]: JsonSchemaDef };\n\tpatternProperties?: { [key: string]: JsonSchemaDef };\n\t/**\n\t * Replaced by {@link unevaluatedProperties} in Draft 2019-09+\n\t */\n\tadditionalProperties?: JsonSchemaDef | boolean; // true = {}\n\t/**\n\t * Superseded by {@link dependentSchemas}, {@link dependentRequired} in Draft 2019-09+\n\t */\n\tdependencies?: { [key: string]: undefined | JsonSchemaDef | string[] };\n\tpropertyNames?: JsonSchemaDef;\n\n\t//region Draft 2019-09+\n\n\tdependentSchemas?: { [key: string]: JsonSchemaDef };\n\tdependentRequired?: { [key: string]: string[] };\n\tunevaluatedProperties?: JsonSchemaDef | boolean;\n\tunevaluatedItems?: JsonSchemaDef | boolean;\n\n\t//endregion\n\n\t//endregion\n\n\t//region Conditional\n\n\tif?: JsonSchemaDef;\n\tthen?: JsonSchemaDef;\n\telse?: JsonSchemaDef;\n\n\t//endregion\n\n\t//region Boolean Logic\n\n\tallOf?: JsonSchemaDef[]; // extends, merge\n\tanyOf?: JsonSchemaDef[];\n\toneOf?: JsonSchemaDef[]; // polymorphism, enum\n\tnot?: JsonSchemaDef;\n\t//endregion\n\n\t//region Semantic\n\n\tformat?: JsonSchemaFormatName | string;\n\n\t//endregion\n\n\t//region String-Encoding Non-JSON Data\n\n\tcontentMediaType?: string;\n\tcontentEncoding?: string;\n\tcontentSchema?: JsonSchemaDef;\n\t//endregion\n\n\t/**\n\t * use {@link $defs} instead\n\t */\n\tdefinitions?: Record<string, JsonSchemaDef>;\n\n\t//region Meta-Data Annotations\n\t/**\n\t * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-10\n\t */\n\n\ttitle?: string;\n\tdescription?: string;\n\tdefault?: JsonValue;\n\treadOnly?: boolean;\n\twriteOnly?: boolean;\n\texamples?: JsonValue;\n\tdeprecated?: boolean;\n\n\t//endregion\n\n\t//region OpenAPI Spec\n\n\tnullable?: boolean;\n\n\tdiscriminator?: {\n\t\tpropertyName: string;\n\t\tmapping?: { [key: string]: string };\n\t};\n\n\t//endregion\n\n\t// [key: `x-${string}`]: JsonValue;\n\t[key: string]: JsonValue;\n};\n"],"names":[],"mappings":"AAwDA;;;;CAIC,GACD,WAwJE"}
|
|
@@ -1,91 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
4
|
-
return arr2;
|
|
5
|
-
}
|
|
6
|
-
function _array_without_holes(arr) {
|
|
7
|
-
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
8
|
-
}
|
|
9
|
-
function _define_property(obj, key, value) {
|
|
10
|
-
if (key in obj) {
|
|
11
|
-
Object.defineProperty(obj, key, {
|
|
12
|
-
value: value,
|
|
13
|
-
enumerable: true,
|
|
14
|
-
configurable: true,
|
|
15
|
-
writable: true
|
|
16
|
-
});
|
|
17
|
-
} else {
|
|
18
|
-
obj[key] = value;
|
|
19
|
-
}
|
|
20
|
-
return obj;
|
|
21
|
-
}
|
|
22
|
-
function _iterable_to_array(iter) {
|
|
23
|
-
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
24
|
-
}
|
|
25
|
-
function _non_iterable_spread() {
|
|
26
|
-
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
27
|
-
}
|
|
28
|
-
function _object_spread(target) {
|
|
29
|
-
for(var i = 1; i < arguments.length; i++){
|
|
30
|
-
var source = arguments[i] != null ? arguments[i] : {};
|
|
31
|
-
var ownKeys = Object.keys(source);
|
|
32
|
-
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
33
|
-
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
34
|
-
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
35
|
-
}));
|
|
36
|
-
}
|
|
37
|
-
ownKeys.forEach(function(key) {
|
|
38
|
-
_define_property(target, key, source[key]);
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
return target;
|
|
42
|
-
}
|
|
43
|
-
function _object_without_properties(source, excluded) {
|
|
44
|
-
if (source == null) return {};
|
|
45
|
-
var target = _object_without_properties_loose(source, excluded);
|
|
46
|
-
var key, i;
|
|
47
|
-
if (Object.getOwnPropertySymbols) {
|
|
48
|
-
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
|
|
49
|
-
for(i = 0; i < sourceSymbolKeys.length; i++){
|
|
50
|
-
key = sourceSymbolKeys[i];
|
|
51
|
-
if (excluded.indexOf(key) >= 0) continue;
|
|
52
|
-
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
|
53
|
-
target[key] = source[key];
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return target;
|
|
57
|
-
}
|
|
58
|
-
function _object_without_properties_loose(source, excluded) {
|
|
59
|
-
if (source == null) return {};
|
|
60
|
-
var target = {};
|
|
61
|
-
var sourceKeys = Object.keys(source);
|
|
62
|
-
var key, i;
|
|
63
|
-
for(i = 0; i < sourceKeys.length; i++){
|
|
64
|
-
key = sourceKeys[i];
|
|
65
|
-
if (excluded.indexOf(key) >= 0) continue;
|
|
66
|
-
target[key] = source[key];
|
|
67
|
-
}
|
|
68
|
-
return target;
|
|
69
|
-
}
|
|
70
|
-
function _to_consumable_array(arr) {
|
|
71
|
-
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
72
|
-
}
|
|
73
|
-
function _unsupported_iterable_to_array(o, minLen) {
|
|
74
|
-
if (!o) return;
|
|
75
|
-
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
76
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
77
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
78
|
-
if (n === "Map" || n === "Set") return Array.from(n);
|
|
79
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
80
|
-
}
|
|
81
|
-
var _all = [];
|
|
82
|
-
export function defineFileType(_param) {
|
|
83
|
-
var _param_type = _param.type, type = _param_type === void 0 ? '' : _param_type, _param_types = _param.types, types = _param_types === void 0 ? [] : _param_types, _param_extension = _param.extension, extension = _param_extension === void 0 ? '' : _param_extension, _param_extensions = _param.extensions, extensions = _param_extensions === void 0 ? [] : _param_extensions, opts = _object_without_properties(_param, [
|
|
84
|
-
"type",
|
|
85
|
-
"types",
|
|
86
|
-
"extension",
|
|
87
|
-
"extensions"
|
|
88
|
-
]);
|
|
1
|
+
let _all = [];
|
|
2
|
+
export function defineFileType({ type = '', types = [], extension = '', extensions = [], ...opts }) {
|
|
89
3
|
if (!type) {
|
|
90
4
|
type = types[0] || '';
|
|
91
5
|
}
|
|
@@ -94,29 +8,30 @@ export function defineFileType(_param) {
|
|
|
94
8
|
}
|
|
95
9
|
if (!types.includes(type)) {
|
|
96
10
|
types = [
|
|
97
|
-
type
|
|
98
|
-
|
|
11
|
+
type,
|
|
12
|
+
...types
|
|
13
|
+
];
|
|
99
14
|
}
|
|
100
15
|
if (!extensions.includes(extension)) {
|
|
101
16
|
extensions = [
|
|
102
|
-
extension
|
|
103
|
-
|
|
17
|
+
extension,
|
|
18
|
+
...extensions
|
|
19
|
+
];
|
|
104
20
|
}
|
|
105
|
-
|
|
21
|
+
const def = {
|
|
106
22
|
title: opts.title || opts.name,
|
|
107
|
-
type
|
|
108
|
-
extension
|
|
109
|
-
types
|
|
110
|
-
extensions
|
|
23
|
+
type,
|
|
24
|
+
extension,
|
|
25
|
+
types,
|
|
26
|
+
extensions,
|
|
111
27
|
tags: [],
|
|
112
|
-
metadata: {}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
});
|
|
28
|
+
metadata: {},
|
|
29
|
+
...opts
|
|
30
|
+
};
|
|
31
|
+
let idx = _all.findIndex((v)=>v.name === def.name);
|
|
117
32
|
if (idx >= 0) {
|
|
118
33
|
_all[idx] = def;
|
|
119
|
-
console.warn(
|
|
34
|
+
console.warn(`File type ${def.name} is redefined`);
|
|
120
35
|
} else {
|
|
121
36
|
_all.push(def);
|
|
122
37
|
}
|
|
@@ -125,3 +40,5 @@ export function defineFileType(_param) {
|
|
|
125
40
|
export function getFileType() {
|
|
126
41
|
return _all;
|
|
127
42
|
}
|
|
43
|
+
|
|
44
|
+
//# sourceMappingURL=defineFileType.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/meta/defineFileType.tsx"],"sourcesContent":["type DefineFileTypeOptions = {\n\tname: string;\n\ttitle?: string;\n\tdescription?: string;\n\ttype?: string;\n\ttypes?: string[];\n\textension?: string;\n\textensions?: string[];\n\ttags?: string[];\n\tmetadata?: Record<string, any>;\n};\nexport type FileTypeDef = {\n\tname: string;\n\ttitle: string;\n\tdescription?: string;\n\ttype: string; // primary type\n\textension: string; // primary extension\n\ttypes: string[];\n\textensions: string[];\n\ttags: string[];\n\tmetadata: Record<string, any>;\n};\n\nlet _all: FileTypeDef[] = [];\n\nexport function defineFileType({\n\ttype = '',\n\ttypes = [],\n\textension = '',\n\textensions = [],\n\t...opts\n}: DefineFileTypeOptions): FileTypeDef {\n\tif (!type) {\n\t\ttype = types[0] || '';\n\t}\n\tif (!extension) {\n\t\textension = extensions[0] || '';\n\t}\n\tif (!types.includes(type)) {\n\t\ttypes = [type, ...types];\n\t}\n\tif (!extensions.includes(extension)) {\n\t\textensions = [extension, ...extensions];\n\t}\n\n\tconst def: FileTypeDef = {\n\t\ttitle: opts.title || opts.name,\n\t\ttype,\n\t\textension,\n\t\ttypes,\n\t\textensions,\n\t\ttags: [],\n\t\tmetadata: {},\n\t\t...opts,\n\t};\n\tlet idx = _all.findIndex((v) => v.name === def.name);\n\tif (idx >= 0) {\n\t\t_all[idx] = def;\n\t\tconsole.warn(`File type ${def.name} is redefined`);\n\t} else {\n\t\t_all.push(def);\n\t}\n\treturn def;\n}\n\nexport function getFileType(): FileTypeDef[] {\n\treturn _all;\n}\n"],"names":["_all","defineFileType","type","types","extension","extensions","opts","includes","def","title","name","tags","metadata","idx","findIndex","v","console","warn","push","getFileType"],"mappings":"AAuBA,IAAIA,OAAsB,EAAE;AAE5B,OAAO,SAASC,eAAe,EAC9BC,OAAO,EAAE,EACTC,QAAQ,EAAE,EACVC,YAAY,EAAE,EACdC,aAAa,EAAE,EACf,GAAGC,MACoB;IACvB,IAAI,CAACJ,MAAM;QACVA,OAAOC,KAAK,CAAC,EAAE,IAAI;IACpB;IACA,IAAI,CAACC,WAAW;QACfA,YAAYC,UAAU,CAAC,EAAE,IAAI;IAC9B;IACA,IAAI,CAACF,MAAMI,QAAQ,CAACL,OAAO;QAC1BC,QAAQ;YAACD;eAASC;SAAM;IACzB;IACA,IAAI,CAACE,WAAWE,QAAQ,CAACH,YAAY;QACpCC,aAAa;YAACD;eAAcC;SAAW;IACxC;IAEA,MAAMG,MAAmB;QACxBC,OAAOH,KAAKG,KAAK,IAAIH,KAAKI,IAAI;QAC9BR;QACAE;QACAD;QACAE;QACAM,MAAM,EAAE;QACRC,UAAU,CAAC;QACX,GAAGN,IAAI;IACR;IACA,IAAIO,MAAMb,KAAKc,SAAS,CAAC,CAACC,IAAMA,EAAEL,IAAI,KAAKF,IAAIE,IAAI;IACnD,IAAIG,OAAO,GAAG;QACbb,IAAI,CAACa,IAAI,GAAGL;QACZQ,QAAQC,IAAI,CAAC,CAAC,UAAU,EAAET,IAAIE,IAAI,CAAC,aAAa,CAAC;IAClD,OAAO;QACNV,KAAKkB,IAAI,CAACV;IACX;IACA,OAAOA;AACR;AAEA,OAAO,SAASW;IACf,OAAOnB;AACR"}
|