@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
|
@@ -0,0 +1,584 @@
|
|
|
1
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
2
|
+
try {
|
|
3
|
+
var info = gen[key](arg);
|
|
4
|
+
var value = info.value;
|
|
5
|
+
} catch (error) {
|
|
6
|
+
reject(error);
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
if (info.done) {
|
|
10
|
+
resolve(value);
|
|
11
|
+
} else {
|
|
12
|
+
Promise.resolve(value).then(_next, _throw);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function _async_to_generator(fn) {
|
|
16
|
+
return function() {
|
|
17
|
+
var self = this, args = arguments;
|
|
18
|
+
return new Promise(function(resolve, reject) {
|
|
19
|
+
var gen = fn.apply(self, args);
|
|
20
|
+
function _next(value) {
|
|
21
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
22
|
+
}
|
|
23
|
+
function _throw(err) {
|
|
24
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
25
|
+
}
|
|
26
|
+
_next(undefined);
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function _ts_generator(thisArg, body) {
|
|
31
|
+
var f, y, t, _ = {
|
|
32
|
+
label: 0,
|
|
33
|
+
sent: function() {
|
|
34
|
+
if (t[0] & 1) throw t[1];
|
|
35
|
+
return t[1];
|
|
36
|
+
},
|
|
37
|
+
trys: [],
|
|
38
|
+
ops: []
|
|
39
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
|
|
40
|
+
return d(g, "next", {
|
|
41
|
+
value: verb(0)
|
|
42
|
+
}), d(g, "throw", {
|
|
43
|
+
value: verb(1)
|
|
44
|
+
}), d(g, "return", {
|
|
45
|
+
value: verb(2)
|
|
46
|
+
}), typeof Symbol === "function" && d(g, Symbol.iterator, {
|
|
47
|
+
value: function() {
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
}), g;
|
|
51
|
+
function verb(n) {
|
|
52
|
+
return function(v) {
|
|
53
|
+
return step([
|
|
54
|
+
n,
|
|
55
|
+
v
|
|
56
|
+
]);
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function step(op) {
|
|
60
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
61
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
62
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
63
|
+
if (y = 0, t) op = [
|
|
64
|
+
op[0] & 2,
|
|
65
|
+
t.value
|
|
66
|
+
];
|
|
67
|
+
switch(op[0]){
|
|
68
|
+
case 0:
|
|
69
|
+
case 1:
|
|
70
|
+
t = op;
|
|
71
|
+
break;
|
|
72
|
+
case 4:
|
|
73
|
+
_.label++;
|
|
74
|
+
return {
|
|
75
|
+
value: op[1],
|
|
76
|
+
done: false
|
|
77
|
+
};
|
|
78
|
+
case 5:
|
|
79
|
+
_.label++;
|
|
80
|
+
y = op[1];
|
|
81
|
+
op = [
|
|
82
|
+
0
|
|
83
|
+
];
|
|
84
|
+
continue;
|
|
85
|
+
case 7:
|
|
86
|
+
op = _.ops.pop();
|
|
87
|
+
_.trys.pop();
|
|
88
|
+
continue;
|
|
89
|
+
default:
|
|
90
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
91
|
+
_ = 0;
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
95
|
+
_.label = op[1];
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
99
|
+
_.label = t[1];
|
|
100
|
+
t = op;
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
if (t && _.label < t[2]) {
|
|
104
|
+
_.label = t[2];
|
|
105
|
+
_.ops.push(op);
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
if (t[2]) _.ops.pop();
|
|
109
|
+
_.trys.pop();
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
op = body.call(thisArg, _);
|
|
113
|
+
} catch (e) {
|
|
114
|
+
op = [
|
|
115
|
+
6,
|
|
116
|
+
e
|
|
117
|
+
];
|
|
118
|
+
y = 0;
|
|
119
|
+
} finally{
|
|
120
|
+
f = t = 0;
|
|
121
|
+
}
|
|
122
|
+
if (op[0] & 5) throw op[1];
|
|
123
|
+
return {
|
|
124
|
+
value: op[0] ? op[1] : void 0,
|
|
125
|
+
done: true
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
import { S3mini } from 's3mini';
|
|
130
|
+
import { afterAll, beforeAll, describe, expect, test } from 'vitest';
|
|
131
|
+
/**
|
|
132
|
+
* Tests for s3mini and S3 filesystem behavior
|
|
133
|
+
*
|
|
134
|
+
* Uses MinIO Play server for integration testing:
|
|
135
|
+
* - Endpoint: play.min.io
|
|
136
|
+
* - Access Key: Q3AM3UQ867SPQQA43P2F
|
|
137
|
+
* - Secret Key: zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG
|
|
138
|
+
*
|
|
139
|
+
* Note: s3mini expects bucket name to be part of the endpoint URL.
|
|
140
|
+
* e.g., https://play.min.io/bucket-name
|
|
141
|
+
*
|
|
142
|
+
* s3mini does not support anonymous access to public S3 buckets.
|
|
143
|
+
*/ // Set to true to run network tests
|
|
144
|
+
var RUN_NETWORK_TESTS = process.env.RUN_S3_NETWORK_TESTS === 'true';
|
|
145
|
+
// Generate unique bucket name for this test run
|
|
146
|
+
var TEST_BUCKET = "s3mini-test-".concat(Date.now());
|
|
147
|
+
describe('s3mini with MinIO Play', function() {
|
|
148
|
+
var client;
|
|
149
|
+
beforeAll(function() {
|
|
150
|
+
return _async_to_generator(function() {
|
|
151
|
+
var e;
|
|
152
|
+
return _ts_generator(this, function(_state) {
|
|
153
|
+
switch(_state.label){
|
|
154
|
+
case 0:
|
|
155
|
+
if (!RUN_NETWORK_TESTS) return [
|
|
156
|
+
2
|
|
157
|
+
];
|
|
158
|
+
// s3mini expects bucket name in the endpoint URL
|
|
159
|
+
client = new S3mini({
|
|
160
|
+
endpoint: "https://play.min.io/".concat(TEST_BUCKET),
|
|
161
|
+
accessKeyId: 'Q3AM3UQ867SPQQA43P2F',
|
|
162
|
+
secretAccessKey: 'zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG',
|
|
163
|
+
region: 'us-east-1'
|
|
164
|
+
});
|
|
165
|
+
_state.label = 1;
|
|
166
|
+
case 1:
|
|
167
|
+
_state.trys.push([
|
|
168
|
+
1,
|
|
169
|
+
3,
|
|
170
|
+
,
|
|
171
|
+
4
|
|
172
|
+
]);
|
|
173
|
+
return [
|
|
174
|
+
4,
|
|
175
|
+
client.createBucket()
|
|
176
|
+
];
|
|
177
|
+
case 2:
|
|
178
|
+
_state.sent();
|
|
179
|
+
console.log("Created bucket: ".concat(TEST_BUCKET));
|
|
180
|
+
return [
|
|
181
|
+
3,
|
|
182
|
+
4
|
|
183
|
+
];
|
|
184
|
+
case 3:
|
|
185
|
+
e = _state.sent();
|
|
186
|
+
console.log('Bucket creation error:', e);
|
|
187
|
+
return [
|
|
188
|
+
3,
|
|
189
|
+
4
|
|
190
|
+
];
|
|
191
|
+
case 4:
|
|
192
|
+
return [
|
|
193
|
+
2
|
|
194
|
+
];
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
})();
|
|
198
|
+
});
|
|
199
|
+
afterAll(function() {
|
|
200
|
+
return _async_to_generator(function() {
|
|
201
|
+
var objects, keys, e;
|
|
202
|
+
return _ts_generator(this, function(_state) {
|
|
203
|
+
switch(_state.label){
|
|
204
|
+
case 0:
|
|
205
|
+
if (!RUN_NETWORK_TESTS || !client) return [
|
|
206
|
+
2
|
|
207
|
+
];
|
|
208
|
+
_state.label = 1;
|
|
209
|
+
case 1:
|
|
210
|
+
_state.trys.push([
|
|
211
|
+
1,
|
|
212
|
+
5,
|
|
213
|
+
,
|
|
214
|
+
6
|
|
215
|
+
]);
|
|
216
|
+
return [
|
|
217
|
+
4,
|
|
218
|
+
client.listObjects('/', '', 1000)
|
|
219
|
+
];
|
|
220
|
+
case 2:
|
|
221
|
+
objects = _state.sent();
|
|
222
|
+
if (!(objects && objects.length > 0)) return [
|
|
223
|
+
3,
|
|
224
|
+
4
|
|
225
|
+
];
|
|
226
|
+
keys = objects.map(function(o) {
|
|
227
|
+
return o.Key;
|
|
228
|
+
}).filter(Boolean);
|
|
229
|
+
if (!(keys.length > 0)) return [
|
|
230
|
+
3,
|
|
231
|
+
4
|
|
232
|
+
];
|
|
233
|
+
return [
|
|
234
|
+
4,
|
|
235
|
+
client.deleteObjects(keys)
|
|
236
|
+
];
|
|
237
|
+
case 3:
|
|
238
|
+
_state.sent();
|
|
239
|
+
_state.label = 4;
|
|
240
|
+
case 4:
|
|
241
|
+
return [
|
|
242
|
+
3,
|
|
243
|
+
6
|
|
244
|
+
];
|
|
245
|
+
case 5:
|
|
246
|
+
e = _state.sent();
|
|
247
|
+
console.log('Cleanup error:', e);
|
|
248
|
+
return [
|
|
249
|
+
3,
|
|
250
|
+
6
|
|
251
|
+
];
|
|
252
|
+
case 6:
|
|
253
|
+
return [
|
|
254
|
+
2
|
|
255
|
+
];
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
})();
|
|
259
|
+
});
|
|
260
|
+
describe.skipIf(!RUN_NETWORK_TESTS)('listObjects with delimiter', function() {
|
|
261
|
+
test('should list objects and detect directories', function() {
|
|
262
|
+
return _async_to_generator(function() {
|
|
263
|
+
var objects, dirs, files, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, dir, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, file;
|
|
264
|
+
return _ts_generator(this, function(_state) {
|
|
265
|
+
switch(_state.label){
|
|
266
|
+
case 0:
|
|
267
|
+
// Create test structure
|
|
268
|
+
return [
|
|
269
|
+
4,
|
|
270
|
+
client.putObject('file1.txt', 'content1')
|
|
271
|
+
];
|
|
272
|
+
case 1:
|
|
273
|
+
_state.sent();
|
|
274
|
+
return [
|
|
275
|
+
4,
|
|
276
|
+
client.putObject('file2.txt', 'content2')
|
|
277
|
+
];
|
|
278
|
+
case 2:
|
|
279
|
+
_state.sent();
|
|
280
|
+
return [
|
|
281
|
+
4,
|
|
282
|
+
client.putObject('dir1/', '')
|
|
283
|
+
];
|
|
284
|
+
case 3:
|
|
285
|
+
_state.sent(); // Directory marker
|
|
286
|
+
return [
|
|
287
|
+
4,
|
|
288
|
+
client.putObject('dir1/nested.txt', 'nested content')
|
|
289
|
+
];
|
|
290
|
+
case 4:
|
|
291
|
+
_state.sent();
|
|
292
|
+
return [
|
|
293
|
+
4,
|
|
294
|
+
client.putObject('dir2/', '')
|
|
295
|
+
];
|
|
296
|
+
case 5:
|
|
297
|
+
_state.sent(); // Another directory marker
|
|
298
|
+
return [
|
|
299
|
+
4,
|
|
300
|
+
client.listObjects('/', '', 100, {
|
|
301
|
+
delimiter: '/'
|
|
302
|
+
})
|
|
303
|
+
];
|
|
304
|
+
case 6:
|
|
305
|
+
objects = _state.sent();
|
|
306
|
+
console.log('MinIO Play listing with delimiter:', JSON.stringify(objects, null, 2));
|
|
307
|
+
expect(objects).toBeDefined();
|
|
308
|
+
expect(Array.isArray(objects)).toBe(true);
|
|
309
|
+
if (objects && objects.length > 0) {
|
|
310
|
+
// Check for files and directories
|
|
311
|
+
dirs = objects.filter(function(o) {
|
|
312
|
+
var _o_Key;
|
|
313
|
+
return (_o_Key = o.Key) === null || _o_Key === void 0 ? void 0 : _o_Key.endsWith('/');
|
|
314
|
+
});
|
|
315
|
+
files = objects.filter(function(o) {
|
|
316
|
+
var _o_Key;
|
|
317
|
+
return !((_o_Key = o.Key) === null || _o_Key === void 0 ? void 0 : _o_Key.endsWith('/'));
|
|
318
|
+
});
|
|
319
|
+
console.log("Found ".concat(dirs.length, " directories and ").concat(files.length, " files"));
|
|
320
|
+
console.log('Directories:', dirs.map(function(d) {
|
|
321
|
+
return d.Key;
|
|
322
|
+
}));
|
|
323
|
+
console.log('Files:', files.map(function(f) {
|
|
324
|
+
return f.Key;
|
|
325
|
+
}));
|
|
326
|
+
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
327
|
+
try {
|
|
328
|
+
// Directories should have Size: 0
|
|
329
|
+
for(_iterator = dirs[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
330
|
+
dir = _step.value;
|
|
331
|
+
expect(Number(dir.Size)).toBe(0);
|
|
332
|
+
expect(dir.Key).toMatch(/\/$/);
|
|
333
|
+
}
|
|
334
|
+
} catch (err) {
|
|
335
|
+
_didIteratorError = true;
|
|
336
|
+
_iteratorError = err;
|
|
337
|
+
} finally{
|
|
338
|
+
try {
|
|
339
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
340
|
+
_iterator.return();
|
|
341
|
+
}
|
|
342
|
+
} finally{
|
|
343
|
+
if (_didIteratorError) {
|
|
344
|
+
throw _iteratorError;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
_iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
|
|
349
|
+
try {
|
|
350
|
+
// Files should have Size > 0
|
|
351
|
+
for(_iterator1 = files[Symbol.iterator](); !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
|
|
352
|
+
file = _step1.value;
|
|
353
|
+
expect(Number(file.Size)).toBeGreaterThan(0);
|
|
354
|
+
expect(file.Key).not.toMatch(/\/$/);
|
|
355
|
+
}
|
|
356
|
+
} catch (err) {
|
|
357
|
+
_didIteratorError1 = true;
|
|
358
|
+
_iteratorError1 = err;
|
|
359
|
+
} finally{
|
|
360
|
+
try {
|
|
361
|
+
if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
|
|
362
|
+
_iterator1.return();
|
|
363
|
+
}
|
|
364
|
+
} finally{
|
|
365
|
+
if (_didIteratorError1) {
|
|
366
|
+
throw _iteratorError1;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
return [
|
|
372
|
+
2
|
|
373
|
+
];
|
|
374
|
+
}
|
|
375
|
+
});
|
|
376
|
+
})();
|
|
377
|
+
});
|
|
378
|
+
test('should list nested directory contents', function() {
|
|
379
|
+
return _async_to_generator(function() {
|
|
380
|
+
var objects, files;
|
|
381
|
+
return _ts_generator(this, function(_state) {
|
|
382
|
+
switch(_state.label){
|
|
383
|
+
case 0:
|
|
384
|
+
return [
|
|
385
|
+
4,
|
|
386
|
+
client.listObjects('/', 'dir1/', 100, {
|
|
387
|
+
delimiter: '/'
|
|
388
|
+
})
|
|
389
|
+
];
|
|
390
|
+
case 1:
|
|
391
|
+
objects = _state.sent();
|
|
392
|
+
console.log('MinIO Play dir1/ listing:', JSON.stringify(objects, null, 2));
|
|
393
|
+
expect(objects).toBeDefined();
|
|
394
|
+
expect(Array.isArray(objects)).toBe(true);
|
|
395
|
+
// Should find nested.txt
|
|
396
|
+
files = (objects === null || objects === void 0 ? void 0 : objects.filter(function(o) {
|
|
397
|
+
var _o_Key;
|
|
398
|
+
return !((_o_Key = o.Key) === null || _o_Key === void 0 ? void 0 : _o_Key.endsWith('/'));
|
|
399
|
+
})) || [];
|
|
400
|
+
expect(files.some(function(f) {
|
|
401
|
+
var _f_Key;
|
|
402
|
+
return (_f_Key = f.Key) === null || _f_Key === void 0 ? void 0 : _f_Key.includes('nested.txt');
|
|
403
|
+
})).toBe(true);
|
|
404
|
+
return [
|
|
405
|
+
2
|
|
406
|
+
];
|
|
407
|
+
}
|
|
408
|
+
});
|
|
409
|
+
})();
|
|
410
|
+
});
|
|
411
|
+
});
|
|
412
|
+
});
|
|
413
|
+
/**
|
|
414
|
+
* Unit tests for S3 directory detection logic (no network required)
|
|
415
|
+
*
|
|
416
|
+
* When using delimiter: '/' with listObjects, S3 returns:
|
|
417
|
+
* - Files: Key without trailing /, Size > 0
|
|
418
|
+
* - Directories: Key with trailing /, Size: 0
|
|
419
|
+
*/ describe('s3mini listObjects behavior', function() {
|
|
420
|
+
test('directory detection logic - directories end with / and have Size: 0', function() {
|
|
421
|
+
// Mock response similar to user's example
|
|
422
|
+
var mockResponse = [
|
|
423
|
+
{
|
|
424
|
+
Key: 'fusion/README.md',
|
|
425
|
+
LastModified: '2025-12-18T01:51:09.000Z',
|
|
426
|
+
ETag: '"adc69293e8fd256b2609664f1e11cb53"',
|
|
427
|
+
Size: 6,
|
|
428
|
+
StorageClass: 'STANDARD'
|
|
429
|
+
},
|
|
430
|
+
{
|
|
431
|
+
Key: 'fusion/home/',
|
|
432
|
+
Size: 0,
|
|
433
|
+
LastModified: new Date('1970-01-01T00:00:00.000Z'),
|
|
434
|
+
ETag: '',
|
|
435
|
+
StorageClass: ''
|
|
436
|
+
},
|
|
437
|
+
{
|
|
438
|
+
Key: 'fusion/mcp/',
|
|
439
|
+
Size: 0,
|
|
440
|
+
LastModified: new Date('1970-01-01T00:00:00.000Z'),
|
|
441
|
+
ETag: '',
|
|
442
|
+
StorageClass: ''
|
|
443
|
+
}
|
|
444
|
+
];
|
|
445
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
446
|
+
try {
|
|
447
|
+
// Test directory detection logic
|
|
448
|
+
for(var _iterator = mockResponse[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
449
|
+
var obj = _step.value;
|
|
450
|
+
var isDir = obj.Key.endsWith('/');
|
|
451
|
+
if (isDir) {
|
|
452
|
+
expect(obj.Size).toBe(0);
|
|
453
|
+
expect(obj.Key).toMatch(/\/$/);
|
|
454
|
+
} else {
|
|
455
|
+
expect(obj.Size).toBeGreaterThan(0);
|
|
456
|
+
expect(obj.Key).not.toMatch(/\/$/);
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
} catch (err) {
|
|
460
|
+
_didIteratorError = true;
|
|
461
|
+
_iteratorError = err;
|
|
462
|
+
} finally{
|
|
463
|
+
try {
|
|
464
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
465
|
+
_iterator.return();
|
|
466
|
+
}
|
|
467
|
+
} finally{
|
|
468
|
+
if (_didIteratorError) {
|
|
469
|
+
throw _iteratorError;
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
// Count directories and files
|
|
474
|
+
var dirs = mockResponse.filter(function(o) {
|
|
475
|
+
return o.Key.endsWith('/');
|
|
476
|
+
});
|
|
477
|
+
var files = mockResponse.filter(function(o) {
|
|
478
|
+
return !o.Key.endsWith('/');
|
|
479
|
+
});
|
|
480
|
+
expect(dirs).toHaveLength(2);
|
|
481
|
+
expect(files).toHaveLength(1);
|
|
482
|
+
});
|
|
483
|
+
test('readdir should properly identify directories from S3 response', function() {
|
|
484
|
+
var s3Response = [
|
|
485
|
+
{
|
|
486
|
+
Key: 'fusion/README.md',
|
|
487
|
+
Size: 6,
|
|
488
|
+
LastModified: new Date(),
|
|
489
|
+
ETag: '"abc"'
|
|
490
|
+
},
|
|
491
|
+
{
|
|
492
|
+
Key: 'fusion/home/',
|
|
493
|
+
Size: 0,
|
|
494
|
+
LastModified: new Date(0),
|
|
495
|
+
ETag: ''
|
|
496
|
+
},
|
|
497
|
+
{
|
|
498
|
+
Key: 'fusion/mcp/',
|
|
499
|
+
Size: 0,
|
|
500
|
+
LastModified: new Date(0),
|
|
501
|
+
ETag: ''
|
|
502
|
+
}
|
|
503
|
+
];
|
|
504
|
+
var results = s3Response.map(function(obj) {
|
|
505
|
+
var key = obj.Key;
|
|
506
|
+
var isDir = key.endsWith('/');
|
|
507
|
+
var name = isDir ? key.slice(0, -1).split('/').pop() : key.split('/').pop();
|
|
508
|
+
return {
|
|
509
|
+
name: name,
|
|
510
|
+
kind: isDir ? 'directory' : 'file',
|
|
511
|
+
size: obj.Size
|
|
512
|
+
};
|
|
513
|
+
});
|
|
514
|
+
expect(results).toEqual([
|
|
515
|
+
{
|
|
516
|
+
name: 'README.md',
|
|
517
|
+
kind: 'file',
|
|
518
|
+
size: 6
|
|
519
|
+
},
|
|
520
|
+
{
|
|
521
|
+
name: 'home',
|
|
522
|
+
kind: 'directory',
|
|
523
|
+
size: 0
|
|
524
|
+
},
|
|
525
|
+
{
|
|
526
|
+
name: 'mcp',
|
|
527
|
+
kind: 'directory',
|
|
528
|
+
size: 0
|
|
529
|
+
}
|
|
530
|
+
]);
|
|
531
|
+
});
|
|
532
|
+
test('should handle nested paths correctly', function() {
|
|
533
|
+
var s3Response = [
|
|
534
|
+
{
|
|
535
|
+
Key: 'data/2024/01/file.csv',
|
|
536
|
+
Size: 1024
|
|
537
|
+
},
|
|
538
|
+
{
|
|
539
|
+
Key: 'data/2024/02/',
|
|
540
|
+
Size: 0
|
|
541
|
+
},
|
|
542
|
+
{
|
|
543
|
+
Key: 'data/config.json',
|
|
544
|
+
Size: 256
|
|
545
|
+
}
|
|
546
|
+
];
|
|
547
|
+
var prefix = 'data/';
|
|
548
|
+
var results = s3Response.map(function(obj) {
|
|
549
|
+
var key = obj.Key;
|
|
550
|
+
var relativeKey = key.startsWith(prefix) ? key.slice(prefix.length) : key;
|
|
551
|
+
var isDir = key.endsWith('/');
|
|
552
|
+
var parts = relativeKey.split('/').filter(Boolean);
|
|
553
|
+
var name = parts[0];
|
|
554
|
+
return {
|
|
555
|
+
key: key,
|
|
556
|
+
relativeKey: relativeKey,
|
|
557
|
+
name: name,
|
|
558
|
+
isDir: isDir
|
|
559
|
+
};
|
|
560
|
+
});
|
|
561
|
+
// For non-recursive listing, only want immediate children
|
|
562
|
+
var immediateChildren = results.filter(function(r) {
|
|
563
|
+
var keyWithoutTrailingSlash = r.relativeKey.replace(/\/$/, '');
|
|
564
|
+
return !keyWithoutTrailingSlash.includes('/');
|
|
565
|
+
});
|
|
566
|
+
expect(immediateChildren).toHaveLength(1);
|
|
567
|
+
expect(immediateChildren[0].name).toBe('config.json');
|
|
568
|
+
});
|
|
569
|
+
test('should correctly strip prefix and build file stat', function() {
|
|
570
|
+
var prefix = 'myapp/data';
|
|
571
|
+
var normalizedPrefix = prefix.replace(/^\/+/, '').replace(/\/+$/, '');
|
|
572
|
+
var stripPrefix = function(key) {
|
|
573
|
+
if (!normalizedPrefix || !key.startsWith(normalizedPrefix + '/')) {
|
|
574
|
+
return key.startsWith('/') ? key : '/' + key;
|
|
575
|
+
}
|
|
576
|
+
var withoutPrefix = key.slice(normalizedPrefix.length);
|
|
577
|
+
return withoutPrefix || '/';
|
|
578
|
+
};
|
|
579
|
+
expect(stripPrefix('myapp/data/file.txt')).toBe('/file.txt');
|
|
580
|
+
expect(stripPrefix('myapp/data/subdir/')).toBe('/subdir/');
|
|
581
|
+
expect(stripPrefix('myapp/data/')).toBe('/');
|
|
582
|
+
expect(stripPrefix('other/path')).toBe('/other/path');
|
|
583
|
+
});
|
|
584
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import pathe from "pathe";
|
|
2
|
+
export async function* scandir(options) {
|
|
3
|
+
const { readdir, path: startPath, signal, depth = 1, limit, strategy = 'depth', filter = ()=>true } = options;
|
|
4
|
+
let cursor = options.cursor;
|
|
5
|
+
if (cursor && !cursor.startsWith('/')) {
|
|
6
|
+
cursor = pathe.join(startPath, cursor);
|
|
7
|
+
}
|
|
8
|
+
if (cursor && !cursor.startsWith(startPath)) {
|
|
9
|
+
throw new Error(`Cursor path "${cursor}" is not within the start path "${startPath}"`);
|
|
10
|
+
}
|
|
11
|
+
if (signal?.aborted) return;
|
|
12
|
+
// Collection to manage which directories to visit next.
|
|
13
|
+
// For 'depth'-first, it acts as a Stack (LIFO).
|
|
14
|
+
// For 'breadth'-first, it acts as a Queue (FIFO).
|
|
15
|
+
const collection = [
|
|
16
|
+
{
|
|
17
|
+
path: startPath,
|
|
18
|
+
level: 1
|
|
19
|
+
}
|
|
20
|
+
];
|
|
21
|
+
let yielded = 0;
|
|
22
|
+
let cursorFound = !cursor; // If no cursor is provided, we can start yielding immediately.
|
|
23
|
+
while(collection.length > 0){
|
|
24
|
+
if (signal?.aborted) return;
|
|
25
|
+
if (limit && yielded >= limit) return;
|
|
26
|
+
// Get the next directory to process based on the strategy.
|
|
27
|
+
const { path: currentPath, level: currentLevel } = strategy === 'depth' ? collection.pop() : collection.shift(); // FIFO for breadth-first
|
|
28
|
+
let entries;
|
|
29
|
+
try {
|
|
30
|
+
entries = await readdir(currentPath);
|
|
31
|
+
} catch (error) {
|
|
32
|
+
// Could not read directory, skip it. You might want to log this error.
|
|
33
|
+
console.warn(`scandir: Could not read directory ${currentPath}`, error);
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
for (const file of entries){
|
|
37
|
+
if (signal?.aborted) return;
|
|
38
|
+
if (!cursorFound) {
|
|
39
|
+
if (file.path === cursor) {
|
|
40
|
+
cursorFound = true;
|
|
41
|
+
}
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (filter(file)) {
|
|
45
|
+
yield file;
|
|
46
|
+
yielded++;
|
|
47
|
+
if (limit && yielded >= limit) return;
|
|
48
|
+
}
|
|
49
|
+
if (file.kind === 'directory' && currentLevel < depth) {
|
|
50
|
+
collection.push({
|
|
51
|
+
path: file.path,
|
|
52
|
+
level: currentLevel + 1
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
//# sourceMappingURL=scandir.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/fs/scandir.ts"],"sourcesContent":["import pathe from 'pathe';\nimport type { IFileStat } from './IFileSystem';\n\nexport type ScandirOptions = {\n\treaddir: (path: string) => Promise<IFileStat[]>;\n\tpath: string;\n\tsignal?: AbortSignal;\n\tcursor?: string;\n\tdepth?: number;\n\tlimit?: number;\n\tstrategy?: 'depth' | 'breadth';\n\tfilter?: (file: IFileStat) => boolean;\n};\n\nexport async function* scandir(options: ScandirOptions): AsyncGenerator<IFileStat> {\n\tconst { readdir, path: startPath, signal, depth = 1, limit, strategy = 'depth', filter = () => true } = options;\n\tlet cursor = options.cursor;\n\tif (cursor && !cursor.startsWith('/')) {\n\t\tcursor = pathe.join(startPath, cursor);\n\t}\n\tif (cursor && !cursor.startsWith(startPath)) {\n\t\tthrow new Error(`Cursor path \"${cursor}\" is not within the start path \"${startPath}\"`);\n\t}\n\n\tif (signal?.aborted) return;\n\n\t// Collection to manage which directories to visit next.\n\t// For 'depth'-first, it acts as a Stack (LIFO).\n\t// For 'breadth'-first, it acts as a Queue (FIFO).\n\tconst collection: { path: string; level: number }[] = [{ path: startPath, level: 1 }];\n\n\tlet yielded = 0;\n\tlet cursorFound = !cursor; // If no cursor is provided, we can start yielding immediately.\n\n\twhile (collection.length > 0) {\n\t\tif (signal?.aborted) return;\n\t\tif (limit && yielded >= limit) return;\n\n\t\t// Get the next directory to process based on the strategy.\n\t\tconst { path: currentPath, level: currentLevel } =\n\t\t\tstrategy === 'depth'\n\t\t\t\t? collection.pop()! // LIFO for depth-first\n\t\t\t\t: collection.shift()!; // FIFO for breadth-first\n\n\t\tlet entries: IFileStat[];\n\t\ttry {\n\t\t\tentries = await readdir(currentPath);\n\t\t} catch (error) {\n\t\t\t// Could not read directory, skip it. You might want to log this error.\n\t\t\tconsole.warn(`scandir: Could not read directory ${currentPath}`, error);\n\t\t\tcontinue;\n\t\t}\n\n\t\tfor (const file of entries) {\n\t\t\tif (signal?.aborted) return;\n\n\t\t\tif (!cursorFound) {\n\t\t\t\tif (file.path === cursor) {\n\t\t\t\t\tcursorFound = true;\n\t\t\t\t}\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (filter(file)) {\n\t\t\t\tyield file;\n\t\t\t\tyielded++;\n\t\t\t\tif (limit && yielded >= limit) return;\n\t\t\t}\n\n\t\t\tif (file.kind === 'directory' && currentLevel < depth) {\n\t\t\t\tcollection.push({ path: file.path, level: currentLevel + 1 });\n\t\t\t}\n\t\t}\n\t}\n}\n"],"names":["pathe","scandir","options","readdir","path","startPath","signal","depth","limit","strategy","filter","cursor","startsWith","join","Error","aborted","collection","level","yielded","cursorFound","length","currentPath","currentLevel","pop","shift","entries","error","console","warn","file","kind","push"],"mappings":"AAAA,OAAOA,WAAW,QAAQ;AAc1B,OAAO,gBAAgBC,QAAQC,OAAuB;IACrD,MAAM,EAAEC,OAAO,EAAEC,MAAMC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,CAAC,EAAEC,KAAK,EAAEC,WAAW,OAAO,EAAEC,SAAS,IAAM,IAAI,EAAE,GAAGR;IACxG,IAAIS,SAAST,QAAQS,MAAM;IAC3B,IAAIA,UAAU,CAACA,OAAOC,UAAU,CAAC,MAAM;QACtCD,SAASX,MAAMa,IAAI,CAACR,WAAWM;IAChC;IACA,IAAIA,UAAU,CAACA,OAAOC,UAAU,CAACP,YAAY;QAC5C,MAAM,IAAIS,MAAM,CAAC,aAAa,EAAEH,OAAO,gCAAgC,EAAEN,UAAU,CAAC,CAAC;IACtF;IAEA,IAAIC,QAAQS,SAAS;IAErB,wDAAwD;IACxD,gDAAgD;IAChD,kDAAkD;IAClD,MAAMC,aAAgD;QAAC;YAAEZ,MAAMC;YAAWY,OAAO;QAAE;KAAE;IAErF,IAAIC,UAAU;IACd,IAAIC,cAAc,CAACR,QAAQ,+DAA+D;IAE1F,MAAOK,WAAWI,MAAM,GAAG,EAAG;QAC7B,IAAId,QAAQS,SAAS;QACrB,IAAIP,SAASU,WAAWV,OAAO;QAE/B,2DAA2D;QAC3D,MAAM,EAAEJ,MAAMiB,WAAW,EAAEJ,OAAOK,YAAY,EAAE,GAC/Cb,aAAa,UACVO,WAAWO,GAAG,KACdP,WAAWQ,KAAK,IAAK,yBAAyB;QAElD,IAAIC;QACJ,IAAI;YACHA,UAAU,MAAMtB,QAAQkB;QACzB,EAAE,OAAOK,OAAO;YACf,uEAAuE;YACvEC,QAAQC,IAAI,CAAC,CAAC,kCAAkC,EAAEP,aAAa,EAAEK;YACjE;QACD;QAEA,KAAK,MAAMG,QAAQJ,QAAS;YAC3B,IAAInB,QAAQS,SAAS;YAErB,IAAI,CAACI,aAAa;gBACjB,IAAIU,KAAKzB,IAAI,KAAKO,QAAQ;oBACzBQ,cAAc;gBACf;gBACA;YACD;YAEA,IAAIT,OAAOmB,OAAO;gBACjB,MAAMA;gBACNX;gBACA,IAAIV,SAASU,WAAWV,OAAO;YAChC;YAEA,IAAIqB,KAAKC,IAAI,KAAK,eAAeR,eAAef,OAAO;gBACtDS,WAAWe,IAAI,CAAC;oBAAE3B,MAAMyB,KAAKzB,IAAI;oBAAEa,OAAOK,eAAe;gBAAE;YAC5D;QACD;IACD;AACD"}
|