@daiso-tech/core 0.48.5 → 0.49.0
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/dist/backoff-policies/_shared.d.ts +0 -3
- package/dist/backoff-policies/_shared.js.map +1 -1
- package/dist/backoff-policies/constant-backoff/constant-backoff.d.ts +0 -1
- package/dist/backoff-policies/constant-backoff/constant-backoff.js.map +1 -1
- package/dist/backoff-policies/exponential-backoff/exponential-backoff.d.ts +0 -1
- package/dist/backoff-policies/exponential-backoff/exponential-backoff.js.map +1 -1
- package/dist/backoff-policies/linear-backoff/linear-backoff.d.ts +0 -1
- package/dist/backoff-policies/linear-backoff/linear-backoff.js.map +1 -1
- package/dist/backoff-policies/polynomial-backoff/polynomial-backoff.d.ts +0 -1
- package/dist/backoff-policies/polynomial-backoff/polynomial-backoff.js.map +1 -1
- package/dist/cache/contracts/cache-adapter.contract.d.ts +6 -6
- package/dist/cache/contracts/cache.contract.d.ts +16 -9
- package/dist/cache/contracts/cache.errors.d.ts +1 -4
- package/dist/cache/contracts/cache.errors.js +1 -3
- package/dist/cache/contracts/cache.errors.js.map +1 -1
- package/dist/cache/contracts/cache.events.d.ts +11 -3
- package/dist/cache/contracts/cache.events.js +1 -1
- package/dist/cache/contracts/cache.events.js.map +1 -1
- package/dist/cache/contracts/database-cache-adapter.contract.d.ts +0 -1
- package/dist/cache/contracts/types.d.ts +0 -2
- package/dist/cache/implementations/adapters/kysely-cache-adapter/kysely-cache-adapter.js +1 -2
- package/dist/cache/implementations/adapters/kysely-cache-adapter/kysely-cache-adapter.js.map +1 -1
- package/dist/cache/implementations/adapters/memory-cache-adapter/memory-cache-adapter.d.ts +1 -1
- package/dist/cache/implementations/adapters/memory-cache-adapter/memory-cache-adapter.js +17 -15
- package/dist/cache/implementations/adapters/memory-cache-adapter/memory-cache-adapter.js.map +1 -1
- package/dist/cache/implementations/adapters/mongodb-cache-adapter/mongodb-cache-adapter.d.ts +0 -2
- package/dist/cache/implementations/adapters/mongodb-cache-adapter/mongodb-cache-adapter.js.map +1 -1
- package/dist/cache/implementations/adapters/no-op-cache-adapter/no-op-cache-adapter.d.ts +1 -1
- package/dist/cache/implementations/adapters/no-op-cache-adapter/no-op-cache-adapter.js +1 -1
- package/dist/cache/implementations/adapters/redis-cache-adapter/redis-cache-adapter.d.ts +0 -1
- package/dist/cache/implementations/adapters/redis-cache-adapter/redis-cache-adapter.js.map +1 -1
- package/dist/cache/implementations/derivables/cache/cache.d.ts +2 -5
- package/dist/cache/implementations/derivables/cache/cache.js +10 -2
- package/dist/cache/implementations/derivables/cache/cache.js.map +1 -1
- package/dist/cache/implementations/derivables/cache/database-cache-adapter.js +1 -1
- package/dist/cache/implementations/derivables/cache/database-cache-adapter.js.map +1 -1
- package/dist/cache/implementations/derivables/cache-factory/cache-factory.d.ts +0 -2
- package/dist/cache/implementations/derivables/cache-factory/cache-factory.js.map +1 -1
- package/dist/cache/implementations/test-utilities/cache-adapter.test-suite.d.ts +0 -1
- package/dist/cache/implementations/test-utilities/cache-adapter.test-suite.js +6 -2
- package/dist/cache/implementations/test-utilities/cache-adapter.test-suite.js.map +1 -1
- package/dist/cache/implementations/test-utilities/cache.test-suite.d.ts +0 -1
- package/dist/cache/implementations/test-utilities/cache.test-suite.js +1772 -1735
- package/dist/cache/implementations/test-utilities/cache.test-suite.js.map +1 -1
- package/dist/cache/implementations/test-utilities/database-cache-dapter.test-suite.js +1 -1
- package/dist/cache/implementations/test-utilities/database-cache-dapter.test-suite.js.map +1 -1
- package/dist/circuit-breaker/contracts/circuit-breaker-provider.contract.d.ts +0 -5
- package/dist/circuit-breaker/contracts/circuit-breaker-provider.contract.js +0 -1
- package/dist/circuit-breaker/contracts/circuit-breaker-provider.contract.js.map +1 -1
- package/dist/circuit-breaker/contracts/circuit-breaker-state.contract.d.ts +0 -2
- package/dist/circuit-breaker/contracts/circuit-breaker-state.contract.js +0 -1
- package/dist/circuit-breaker/contracts/circuit-breaker-state.contract.js.map +1 -1
- package/dist/circuit-breaker/contracts/circuit-breaker.contract.d.ts +3 -4
- package/dist/circuit-breaker/contracts/circuit-breaker.contract.js +2 -3
- package/dist/circuit-breaker/contracts/circuit-breaker.contract.js.map +1 -1
- package/dist/circuit-breaker/contracts/circuit-breaker.errors.d.ts +0 -3
- package/dist/circuit-breaker/contracts/circuit-breaker.errors.js +1 -3
- package/dist/circuit-breaker/contracts/circuit-breaker.errors.js.map +1 -1
- package/dist/circuit-breaker/contracts/circuit-breaker.events.d.ts +0 -2
- package/dist/circuit-breaker/contracts/circuit-breaker.events.js +0 -1
- package/dist/circuit-breaker/contracts/circuit-breaker.events.js.map +1 -1
- package/dist/circuit-breaker/implementations/adapters/kysely-circuit-breaker-storage-adapter/kysely-circuit-breaker-storage-adapter.d.ts +2 -2
- package/dist/circuit-breaker/implementations/adapters/kysely-circuit-breaker-storage-adapter/kysely-circuit-breaker-storage-adapter.js +2 -2
- package/dist/circuit-breaker/implementations/adapters/kysely-circuit-breaker-storage-adapter/kysely-circuit-breaker-storage-adapter.js.map +1 -1
- package/dist/circuit-breaker/implementations/adapters/memory-circuit-breaker-storage-adapter/memory-circuit-breaker-storage-adapter.d.ts +2 -3
- package/dist/circuit-breaker/implementations/adapters/memory-circuit-breaker-storage-adapter/memory-circuit-breaker-storage-adapter.js +8 -10
- package/dist/circuit-breaker/implementations/adapters/memory-circuit-breaker-storage-adapter/memory-circuit-breaker-storage-adapter.js.map +1 -1
- package/dist/circuit-breaker/implementations/adapters/mongodb-circuit-breaker-storage-adapter/mongodb-circuit-breaker-storage-adapter.d.ts +2 -2
- package/dist/circuit-breaker/implementations/adapters/mongodb-circuit-breaker-storage-adapter/mongodb-circuit-breaker-storage-adapter.js +2 -2
- package/dist/circuit-breaker/implementations/adapters/mongodb-circuit-breaker-storage-adapter/mongodb-circuit-breaker-storage-adapter.js.map +1 -1
- package/dist/circuit-breaker/implementations/adapters/no-op-circuit-breaker-adapter/no-op-circuit-breaker-adapter.d.ts +2 -0
- package/dist/circuit-breaker/implementations/adapters/no-op-circuit-breaker-adapter/no-op-circuit-breaker-adapter.js +2 -0
- package/dist/circuit-breaker/implementations/adapters/no-op-circuit-breaker-adapter/no-op-circuit-breaker-adapter.js.map +1 -1
- package/dist/circuit-breaker/implementations/adapters/no-op-circuit-breaker-storage-adapter/no-op-circuit-breaker-storage-adapter.d.ts +2 -0
- package/dist/circuit-breaker/implementations/adapters/no-op-circuit-breaker-storage-adapter/no-op-circuit-breaker-storage-adapter.js +2 -0
- package/dist/circuit-breaker/implementations/adapters/no-op-circuit-breaker-storage-adapter/no-op-circuit-breaker-storage-adapter.js.map +1 -1
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider/circuit-breaker-provider.d.ts +2 -4
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider/circuit-breaker-provider.js.map +1 -1
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider/circuit-breaker.d.ts +1 -1
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider/circuit-breaker.js +2 -2
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider/circuit-breaker.js.map +1 -1
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider-factory/circuit-breaker-provider-factory.d.ts +0 -2
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider-factory/circuit-breaker-provider-factory.js.map +1 -1
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider-factory/database-circuit-breaker-provider-factory.d.ts +0 -2
- package/dist/circuit-breaker/implementations/derivables/circuit-breaker-provider-factory/database-circuit-breaker-provider-factory.js.map +1 -1
- package/dist/circuit-breaker/implementations/test-utilities/circuit-breaker-storage-adapter.test-suite.d.ts +0 -1
- package/dist/circuit-breaker/implementations/test-utilities/circuit-breaker-storage-adapter.test-suite.js +1 -1
- package/dist/circuit-breaker/implementations/test-utilities/circuit-breaker-storage-adapter.test-suite.js.map +1 -1
- package/dist/circuit-breaker/implementations/test-utilities/consecutive-breaker.test-suite.d.ts +0 -1
- package/dist/circuit-breaker/implementations/test-utilities/consecutive-breaker.test-suite.js +1 -1
- package/dist/circuit-breaker/implementations/test-utilities/consecutive-breaker.test-suite.js.map +1 -1
- package/dist/circuit-breaker/implementations/test-utilities/count-breaker.test-suite.d.ts +0 -1
- package/dist/circuit-breaker/implementations/test-utilities/count-breaker.test-suite.js +1 -1
- package/dist/circuit-breaker/implementations/test-utilities/count-breaker.test-suite.js.map +1 -1
- package/dist/circuit-breaker/implementations/test-utilities/sampling-breaker.test-suite.d.ts +0 -1
- package/dist/circuit-breaker/implementations/test-utilities/sampling-breaker.test-suite.js +1 -1
- package/dist/circuit-breaker/implementations/test-utilities/sampling-breaker.test-suite.js.map +1 -1
- package/dist/codec/contracts/_module-exports.d.ts +3 -0
- package/dist/codec/contracts/_module-exports.js +2 -0
- package/dist/codec/contracts/_module-exports.js.map +1 -0
- package/dist/codec/contracts/_module.d.ts +4 -0
- package/dist/codec/contracts/_module.js +2 -0
- package/dist/codec/contracts/_module.js.map +1 -0
- package/dist/codec/contracts/codec.contract.d.ts +12 -0
- package/dist/codec/contracts/codec.contract.js +6 -0
- package/dist/codec/contracts/codec.contract.js.map +1 -0
- package/dist/codec/contracts/codec.errors.d.ts +51 -0
- package/dist/codec/contracts/codec.errors.js +64 -0
- package/dist/codec/contracts/codec.errors.js.map +1 -0
- package/dist/codec/contracts/decoder.contract.d.ts +12 -0
- package/dist/codec/contracts/decoder.contract.js +6 -0
- package/dist/codec/contracts/decoder.contract.js.map +1 -0
- package/dist/codec/contracts/encoder.contract.d.ts +12 -0
- package/dist/codec/contracts/encoder.contract.js +6 -0
- package/dist/codec/contracts/encoder.contract.js.map +1 -0
- package/dist/codec/implementations/base-64-codec/_module-exports.d.ts +1 -0
- package/dist/codec/implementations/base-64-codec/_module-exports.js +2 -0
- package/dist/codec/implementations/base-64-codec/_module-exports.js.map +1 -0
- package/dist/codec/implementations/base-64-codec/_module.d.ts +1 -0
- package/dist/codec/implementations/base-64-codec/_module.js +2 -0
- package/dist/codec/implementations/base-64-codec/_module.js.map +1 -0
- package/dist/codec/implementations/base-64-codec/base-64-codec.d.ts +12 -0
- package/dist/codec/implementations/base-64-codec/base-64-codec.js +27 -0
- package/dist/codec/implementations/base-64-codec/base-64-codec.js.map +1 -0
- package/dist/collection/contracts/_shared/compartor.type.d.ts +0 -1
- package/dist/collection/contracts/_shared/cross-join-result.type.d.ts +0 -1
- package/dist/collection/contracts/_shared/ensure-map.type.d.ts +0 -1
- package/dist/collection/contracts/_shared/ensure-record.type.d.ts +0 -1
- package/dist/collection/contracts/_shared/foreach.type.d.ts +0 -2
- package/dist/collection/contracts/_shared/map.type.d.ts +0 -2
- package/dist/collection/contracts/_shared/modifier.type.d.ts +0 -2
- package/dist/collection/contracts/_shared/predicate.type.d.ts +0 -7
- package/dist/collection/contracts/_shared/reduce.type.d.ts +0 -2
- package/dist/collection/contracts/_shared/tap.type.d.ts +0 -2
- package/dist/collection/contracts/_shared/transform.type.d.ts +0 -2
- package/dist/collection/contracts/async-collection.contract.d.ts +0 -1
- package/dist/collection/contracts/collection.contract.d.ts +0 -2
- package/dist/collection/contracts/collection.errors.d.ts +0 -1
- package/dist/collection/contracts/collection.errors.js +0 -1
- package/dist/collection/contracts/collection.errors.js.map +1 -1
- package/dist/event-bus/contracts/event-bus-adapter.contract.d.ts +0 -4
- package/dist/event-bus/contracts/event-bus.contract.d.ts +0 -4
- package/dist/event-bus/implementations/adapters/memory-event-bus-adapter/memory-event-bus-adapter.d.ts +1 -1
- package/dist/event-bus/implementations/adapters/memory-event-bus-adapter/memory-event-bus-adapter.js +7 -9
- package/dist/event-bus/implementations/adapters/memory-event-bus-adapter/memory-event-bus-adapter.js.map +1 -1
- package/dist/event-bus/implementations/adapters/no-op-event-bus-adapter/no-op-event-bus-adapter.d.ts +1 -1
- package/dist/event-bus/implementations/adapters/no-op-event-bus-adapter/no-op-event-bus-adapter.js +1 -1
- package/dist/event-bus/implementations/adapters/redis-pub-sub-event-bus-adapter/redis-pub-sub-event-bus-adapter.d.ts +0 -1
- package/dist/event-bus/implementations/adapters/redis-pub-sub-event-bus-adapter/redis-pub-sub-event-bus-adapter.js.map +1 -1
- package/dist/event-bus/implementations/derivables/event-bus/event-bus.d.ts +2 -5
- package/dist/event-bus/implementations/derivables/event-bus/event-bus.js.map +1 -1
- package/dist/event-bus/implementations/derivables/event-bus-factory/event-bus-factory.d.ts +0 -2
- package/dist/event-bus/implementations/derivables/event-bus-factory/event-bus-factory.js.map +1 -1
- package/dist/event-bus/implementations/test-utilities/event-bus-adapter.test-suite.d.ts +0 -1
- package/dist/event-bus/implementations/test-utilities/event-bus-adapter.test-suite.js +1 -1
- package/dist/event-bus/implementations/test-utilities/event-bus-adapter.test-suite.js.map +1 -1
- package/dist/event-bus/implementations/test-utilities/event-bus.test-suite.d.ts +0 -1
- package/dist/event-bus/implementations/test-utilities/event-bus.test-suite.js +1 -1
- package/dist/event-bus/implementations/test-utilities/event-bus.test-suite.js.map +1 -1
- package/dist/file-size/contracts/_module-exports.d.ts +1 -0
- package/dist/file-size/contracts/_module-exports.js +2 -0
- package/dist/file-size/contracts/_module-exports.js.map +1 -0
- package/dist/file-size/contracts/_module.d.ts +1 -0
- package/dist/file-size/contracts/_module.js +2 -0
- package/dist/file-size/contracts/_module.js.map +1 -0
- package/dist/file-size/contracts/file-size.contract.d.ts +17 -0
- package/dist/file-size/contracts/file-size.contract.js +9 -0
- package/dist/file-size/contracts/file-size.contract.js.map +1 -0
- package/dist/file-size/implementations/_module-exports.d.ts +1 -0
- package/dist/file-size/implementations/_module-exports.js +2 -0
- package/dist/file-size/implementations/_module-exports.js.map +1 -0
- package/dist/file-size/implementations/_module.d.ts +1 -0
- package/dist/file-size/implementations/_module.js +2 -0
- package/dist/file-size/implementations/_module.js.map +1 -0
- package/dist/file-size/implementations/file-size.d.ts +50 -0
- package/dist/file-size/implementations/file-size.js +89 -0
- package/dist/file-size/implementations/file-size.js.map +1 -0
- package/dist/file-storage/contracts/_module-exports.d.ts +7 -0
- package/dist/file-storage/contracts/_module-exports.js +4 -0
- package/dist/file-storage/contracts/_module-exports.js.map +1 -0
- package/dist/file-storage/contracts/_module.d.ts +7 -0
- package/dist/file-storage/contracts/_module.js +4 -0
- package/dist/file-storage/contracts/_module.js.map +1 -0
- package/dist/file-storage/contracts/file-storage-adapter.contract.d.ts +180 -0
- package/dist/file-storage/contracts/file-storage-adapter.contract.js +13 -0
- package/dist/file-storage/contracts/file-storage-adapter.contract.js.map +1 -0
- package/dist/file-storage/contracts/file-storage-factory.contract.d.ts +19 -0
- package/dist/file-storage/contracts/file-storage-factory.contract.js +10 -0
- package/dist/file-storage/contracts/file-storage-factory.contract.js.map +1 -0
- package/dist/file-storage/contracts/file-storage.contract.d.ts +37 -0
- package/dist/file-storage/contracts/file-storage.contract.js +8 -0
- package/dist/file-storage/contracts/file-storage.contract.js.map +1 -0
- package/dist/file-storage/contracts/file.contract.d.ts +224 -0
- package/dist/file-storage/contracts/file.contract.js +10 -0
- package/dist/file-storage/contracts/file.contract.js.map +1 -0
- package/dist/file-storage/contracts/file.errors.d.ts +68 -0
- package/dist/file-storage/contracts/file.errors.js +86 -0
- package/dist/file-storage/contracts/file.errors.js.map +1 -0
- package/dist/file-storage/contracts/file.events.d.ts +135 -0
- package/dist/file-storage/contracts/file.events.js +23 -0
- package/dist/file-storage/contracts/file.events.js.map +1 -0
- package/dist/file-storage/contracts/types.d.ts +9 -0
- package/dist/file-storage/contracts/types.js +5 -0
- package/dist/file-storage/contracts/types.js.map +1 -0
- package/dist/file-storage/implementations/adapters/fs-file-storage-adapter/_module-exports.d.ts +1 -0
- package/dist/file-storage/implementations/adapters/fs-file-storage-adapter/_module-exports.js +2 -0
- package/dist/file-storage/implementations/adapters/fs-file-storage-adapter/_module-exports.js.map +1 -0
- package/dist/file-storage/implementations/adapters/fs-file-storage-adapter/_module.d.ts +1 -0
- package/dist/file-storage/implementations/adapters/fs-file-storage-adapter/_module.js +2 -0
- package/dist/file-storage/implementations/adapters/fs-file-storage-adapter/_module.js.map +1 -0
- package/dist/file-storage/implementations/adapters/fs-file-storage-adapter/fs-file-storage-adapter.d.ts +82 -0
- package/dist/file-storage/implementations/adapters/fs-file-storage-adapter/fs-file-storage-adapter.js +302 -0
- package/dist/file-storage/implementations/adapters/fs-file-storage-adapter/fs-file-storage-adapter.js.map +1 -0
- package/dist/file-storage/implementations/adapters/memory-file-storage-adapter/_module-exports.d.ts +1 -0
- package/dist/file-storage/implementations/adapters/memory-file-storage-adapter/_module-exports.js +2 -0
- package/dist/file-storage/implementations/adapters/memory-file-storage-adapter/_module-exports.js.map +1 -0
- package/dist/file-storage/implementations/adapters/memory-file-storage-adapter/_module.d.ts +1 -0
- package/dist/file-storage/implementations/adapters/memory-file-storage-adapter/_module.js +2 -0
- package/dist/file-storage/implementations/adapters/memory-file-storage-adapter/_module.js.map +1 -0
- package/dist/file-storage/implementations/adapters/memory-file-storage-adapter/memory-file-storage-adapter.d.ts +58 -0
- package/dist/file-storage/implementations/adapters/memory-file-storage-adapter/memory-file-storage-adapter.js +254 -0
- package/dist/file-storage/implementations/adapters/memory-file-storage-adapter/memory-file-storage-adapter.js.map +1 -0
- package/dist/file-storage/implementations/adapters/no-op-file-storage-adapter/_module-exports.d.ts +1 -0
- package/dist/file-storage/implementations/adapters/no-op-file-storage-adapter/_module-exports.js +2 -0
- package/dist/file-storage/implementations/adapters/no-op-file-storage-adapter/_module-exports.js.map +1 -0
- package/dist/file-storage/implementations/adapters/no-op-file-storage-adapter/_module.d.ts +1 -0
- package/dist/file-storage/implementations/adapters/no-op-file-storage-adapter/_module.js +2 -0
- package/dist/file-storage/implementations/adapters/no-op-file-storage-adapter/_module.js.map +1 -0
- package/dist/file-storage/implementations/adapters/no-op-file-storage-adapter/no-op-file-storage-adapter.d.ts +31 -0
- package/dist/file-storage/implementations/adapters/no-op-file-storage-adapter/no-op-file-storage-adapter.js +70 -0
- package/dist/file-storage/implementations/adapters/no-op-file-storage-adapter/no-op-file-storage-adapter.js.map +1 -0
- package/dist/file-storage/implementations/adapters/s3-file-storage-adapter/_module-exports.d.ts +1 -0
- package/dist/file-storage/implementations/adapters/s3-file-storage-adapter/_module-exports.js +2 -0
- package/dist/file-storage/implementations/adapters/s3-file-storage-adapter/_module-exports.js.map +1 -0
- package/dist/file-storage/implementations/adapters/s3-file-storage-adapter/_module.d.ts +1 -0
- package/dist/file-storage/implementations/adapters/s3-file-storage-adapter/_module.js +2 -0
- package/dist/file-storage/implementations/adapters/s3-file-storage-adapter/_module.js.map +1 -0
- package/dist/file-storage/implementations/adapters/s3-file-storage-adapter/s3-file-storage-adapter.d.ts +137 -0
- package/dist/file-storage/implementations/adapters/s3-file-storage-adapter/s3-file-storage-adapter.js +512 -0
- package/dist/file-storage/implementations/adapters/s3-file-storage-adapter/s3-file-storage-adapter.js.map +1 -0
- package/dist/file-storage/implementations/derivables/_module-exports.d.ts +2 -0
- package/dist/file-storage/implementations/derivables/_module-exports.js +3 -0
- package/dist/file-storage/implementations/derivables/_module-exports.js.map +1 -0
- package/dist/file-storage/implementations/derivables/_module.d.ts +2 -0
- package/dist/file-storage/implementations/derivables/_module.js +3 -0
- package/dist/file-storage/implementations/derivables/_module.js.map +1 -0
- package/dist/file-storage/implementations/derivables/file-storage/_module.d.ts +1 -0
- package/dist/file-storage/implementations/derivables/file-storage/_module.js +2 -0
- package/dist/file-storage/implementations/derivables/file-storage/_module.js.map +1 -0
- package/dist/file-storage/implementations/derivables/file-storage/file-serde-transformer.d.ts +48 -0
- package/dist/file-storage/implementations/derivables/file-storage/file-serde-transformer.js +87 -0
- package/dist/file-storage/implementations/derivables/file-storage/file-serde-transformer.js.map +1 -0
- package/dist/file-storage/implementations/derivables/file-storage/file-storage.d.ts +163 -0
- package/dist/file-storage/implementations/derivables/file-storage/file-storage.js +185 -0
- package/dist/file-storage/implementations/derivables/file-storage/file-storage.js.map +1 -0
- package/dist/file-storage/implementations/derivables/file-storage/file.d.ts +114 -0
- package/dist/file-storage/implementations/derivables/file-storage/file.js +722 -0
- package/dist/file-storage/implementations/derivables/file-storage/file.js.map +1 -0
- package/dist/file-storage/implementations/derivables/file-storage/is-signed-file-storage-adapter.d.ts +8 -0
- package/dist/file-storage/implementations/derivables/file-storage/is-signed-file-storage-adapter.js +62 -0
- package/dist/file-storage/implementations/derivables/file-storage/is-signed-file-storage-adapter.js.map +1 -0
- package/dist/file-storage/implementations/derivables/file-storage/merged-file-url-adapter.d.ts +15 -0
- package/dist/file-storage/implementations/derivables/file-storage/merged-file-url-adapter.js +34 -0
- package/dist/file-storage/implementations/derivables/file-storage/merged-file-url-adapter.js.map +1 -0
- package/dist/file-storage/implementations/derivables/file-storage/no-op-file-url-adapter.d.ts +12 -0
- package/dist/file-storage/implementations/derivables/file-storage/no-op-file-url-adapter.js +19 -0
- package/dist/file-storage/implementations/derivables/file-storage/no-op-file-url-adapter.js.map +1 -0
- package/dist/file-storage/implementations/derivables/file-storage/resolve-file-content.d.ts +8 -0
- package/dist/file-storage/implementations/derivables/file-storage/resolve-file-content.js +18 -0
- package/dist/file-storage/implementations/derivables/file-storage/resolve-file-content.js.map +1 -0
- package/dist/file-storage/implementations/derivables/file-storage/resolve-file-storage-adapter.d.ts +8 -0
- package/dist/file-storage/implementations/derivables/file-storage/resolve-file-storage-adapter.js +16 -0
- package/dist/file-storage/implementations/derivables/file-storage/resolve-file-storage-adapter.js.map +1 -0
- package/dist/file-storage/implementations/derivables/file-storage/resolve-file-stream.d.ts +12 -0
- package/dist/file-storage/implementations/derivables/file-storage/resolve-file-stream.js +20 -0
- package/dist/file-storage/implementations/derivables/file-storage/resolve-file-stream.js.map +1 -0
- package/dist/file-storage/implementations/derivables/file-storage/signed-file-storage-adapter.d.ts +31 -0
- package/dist/file-storage/implementations/derivables/file-storage/signed-file-storage-adapter.js +74 -0
- package/dist/file-storage/implementations/derivables/file-storage/signed-file-storage-adapter.js.map +1 -0
- package/dist/file-storage/implementations/derivables/file-storage-factory/_module.d.ts +1 -0
- package/dist/file-storage/implementations/derivables/file-storage-factory/_module.js +2 -0
- package/dist/file-storage/implementations/derivables/file-storage-factory/_module.js.map +1 -0
- package/dist/file-storage/implementations/derivables/file-storage-factory/file-storage-factory.d.ts +59 -0
- package/dist/file-storage/implementations/derivables/file-storage-factory/file-storage-factory.js +113 -0
- package/dist/file-storage/implementations/derivables/file-storage-factory/file-storage-factory.js.map +1 -0
- package/dist/file-storage/implementations/test-utilities/_module-exports.d.ts +2 -0
- package/dist/file-storage/implementations/test-utilities/_module-exports.js +3 -0
- package/dist/file-storage/implementations/test-utilities/_module-exports.js.map +1 -0
- package/dist/file-storage/implementations/test-utilities/_module.d.ts +2 -0
- package/dist/file-storage/implementations/test-utilities/_module.js +3 -0
- package/dist/file-storage/implementations/test-utilities/_module.js.map +1 -0
- package/dist/file-storage/implementations/test-utilities/file-storage-adapter.test-suite.d.ts +28 -0
- package/dist/file-storage/implementations/test-utilities/file-storage-adapter.test-suite.js +1637 -0
- package/dist/file-storage/implementations/test-utilities/file-storage-adapter.test-suite.js.map +1 -0
- package/dist/file-storage/implementations/test-utilities/file-storage.test-suite.d.ts +36 -0
- package/dist/file-storage/implementations/test-utilities/file-storage.test-suite.js +3109 -0
- package/dist/file-storage/implementations/test-utilities/file-storage.test-suite.js.map +1 -0
- package/dist/hooks/async-hooks.d.ts +0 -8
- package/dist/hooks/async-hooks.js.map +1 -1
- package/dist/hooks/hooks.d.ts +0 -6
- package/dist/hooks/hooks.js.map +1 -1
- package/dist/hooks/types.d.ts +0 -1
- package/dist/lock/contracts/database-lock-adapter.contract.d.ts +0 -3
- package/dist/lock/contracts/lock-provider.contract.d.ts +0 -2
- package/dist/lock/contracts/lock-state.contract.d.ts +0 -6
- package/dist/lock/contracts/lock-state.contract.js +0 -1
- package/dist/lock/contracts/lock-state.contract.js.map +1 -1
- package/dist/lock/contracts/lock.contract.d.ts +3 -6
- package/dist/lock/contracts/lock.contract.js +2 -1
- package/dist/lock/contracts/lock.contract.js.map +1 -1
- package/dist/lock/contracts/lock.errors.d.ts +0 -3
- package/dist/lock/contracts/lock.errors.js +0 -2
- package/dist/lock/contracts/lock.errors.js.map +1 -1
- package/dist/lock/contracts/lock.events.d.ts +0 -3
- package/dist/lock/contracts/lock.events.js +0 -1
- package/dist/lock/contracts/lock.events.js.map +1 -1
- package/dist/lock/contracts/types.d.ts +0 -1
- package/dist/lock/implementations/adapters/kysely-lock-adapter/kysely-lock-adapter.d.ts +0 -3
- package/dist/lock/implementations/adapters/kysely-lock-adapter/kysely-lock-adapter.js.map +1 -1
- package/dist/lock/implementations/adapters/memory-lock-adapter/memory-lock-adapter.d.ts +1 -2
- package/dist/lock/implementations/adapters/memory-lock-adapter/memory-lock-adapter.js +19 -24
- package/dist/lock/implementations/adapters/memory-lock-adapter/memory-lock-adapter.js.map +1 -1
- package/dist/lock/implementations/adapters/mongodb-lock-adapter/mongodb-lock-adapter.d.ts +0 -2
- package/dist/lock/implementations/adapters/mongodb-lock-adapter/mongodb-lock-adapter.js.map +1 -1
- package/dist/lock/implementations/adapters/no-op-lock-adapter/no-op-lock-adapter.d.ts +1 -1
- package/dist/lock/implementations/adapters/no-op-lock-adapter/no-op-lock-adapter.js +1 -1
- package/dist/lock/implementations/derivables/lock-provider/database-lock-adapter.js +0 -1
- package/dist/lock/implementations/derivables/lock-provider/database-lock-adapter.js.map +1 -1
- package/dist/lock/implementations/derivables/lock-provider/lock-provider.d.ts +2 -4
- package/dist/lock/implementations/derivables/lock-provider/lock-provider.js.map +1 -1
- package/dist/lock/implementations/derivables/lock-provider/lock.d.ts +4 -4
- package/dist/lock/implementations/derivables/lock-provider/lock.js +1 -1
- package/dist/lock/implementations/derivables/lock-provider/lock.js.map +1 -1
- package/dist/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.d.ts +0 -2
- package/dist/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.js.map +1 -1
- package/dist/lock/implementations/test-utilities/database-lock-adapter.test-suite.d.ts +0 -1
- package/dist/lock/implementations/test-utilities/database-lock-adapter.test-suite.js +1 -1
- package/dist/lock/implementations/test-utilities/database-lock-adapter.test-suite.js.map +1 -1
- package/dist/lock/implementations/test-utilities/lock-adapter.test-suite.d.ts +0 -1
- package/dist/lock/implementations/test-utilities/lock-adapter.test-suite.js +1 -1
- package/dist/lock/implementations/test-utilities/lock-adapter.test-suite.js.map +1 -1
- package/dist/lock/implementations/test-utilities/lock-provider.test-suite.d.ts +0 -1
- package/dist/lock/implementations/test-utilities/lock-provider.test-suite.js +1 -1
- package/dist/lock/implementations/test-utilities/lock-provider.test-suite.js.map +1 -1
- package/dist/namespace/contracts/namespace.contract.d.ts +19 -2
- package/dist/namespace/contracts/namespace.contract.js +1 -1
- package/dist/namespace/contracts/namespace.contract.js.map +1 -1
- package/dist/namespace/implementations/namespace.js +3 -0
- package/dist/namespace/implementations/namespace.js.map +1 -1
- package/dist/namespace/implementations/no-op-namespace.d.ts +1 -1
- package/dist/namespace/implementations/no-op-namespace.js +4 -1
- package/dist/namespace/implementations/no-op-namespace.js.map +1 -1
- package/dist/rate-limiter/contracts/rate-limiter-adapter.contract.d.ts +0 -1
- package/dist/rate-limiter/contracts/rate-limiter-provider.contract.d.ts +0 -1
- package/dist/rate-limiter/contracts/rate-limiter-state.contract.d.ts +0 -6
- package/dist/rate-limiter/contracts/rate-limiter-state.contract.js +0 -1
- package/dist/rate-limiter/contracts/rate-limiter-state.contract.js.map +1 -1
- package/dist/rate-limiter/contracts/rate-limiter-storage-adapter.contract.d.ts +0 -1
- package/dist/rate-limiter/contracts/rate-limiter.contract.d.ts +3 -4
- package/dist/rate-limiter/contracts/rate-limiter.contract.js +2 -1
- package/dist/rate-limiter/contracts/rate-limiter.contract.js.map +1 -1
- package/dist/rate-limiter/contracts/rate-limiter.errors.d.ts +7 -3
- package/dist/rate-limiter/contracts/rate-limiter.errors.js +9 -2
- package/dist/rate-limiter/contracts/rate-limiter.errors.js.map +1 -1
- package/dist/rate-limiter/contracts/rate-limiter.events.d.ts +0 -2
- package/dist/rate-limiter/contracts/rate-limiter.events.js +0 -1
- package/dist/rate-limiter/contracts/rate-limiter.events.js.map +1 -1
- package/dist/rate-limiter/implementations/adapters/memory-rate-limiter-storage-adapter/memory-rate-limiter-storage-adapter.d.ts +2 -1
- package/dist/rate-limiter/implementations/adapters/memory-rate-limiter-storage-adapter/memory-rate-limiter-storage-adapter.js +13 -12
- package/dist/rate-limiter/implementations/adapters/memory-rate-limiter-storage-adapter/memory-rate-limiter-storage-adapter.js.map +1 -1
- package/dist/rate-limiter/implementations/adapters/mongodb-rate-limiter-storage-adapter/mongodb-rate-limiter-storage-adapter.d.ts +1 -1
- package/dist/rate-limiter/implementations/adapters/mongodb-rate-limiter-storage-adapter/mongodb-rate-limiter-storage-adapter.js +1 -1
- package/dist/rate-limiter/implementations/adapters/mongodb-rate-limiter-storage-adapter/mongodb-rate-limiter-storage-adapter.js.map +1 -1
- package/dist/rate-limiter/implementations/adapters/no-op-rate-limiter-adapter/no-op-rate-limiter-adapter.d.ts +2 -0
- package/dist/rate-limiter/implementations/adapters/no-op-rate-limiter-adapter/no-op-rate-limiter-adapter.js +2 -0
- package/dist/rate-limiter/implementations/adapters/no-op-rate-limiter-adapter/no-op-rate-limiter-adapter.js.map +1 -1
- package/dist/rate-limiter/implementations/adapters/no-op-rate-limiter-storage-adapter/no-op-rate-limiter-storage-adapter.d.ts +2 -0
- package/dist/rate-limiter/implementations/adapters/no-op-rate-limiter-storage-adapter/no-op-rate-limiter-storage-adapter.js +2 -0
- package/dist/rate-limiter/implementations/adapters/no-op-rate-limiter-storage-adapter/no-op-rate-limiter-storage-adapter.js.map +1 -1
- package/dist/rate-limiter/implementations/derivables/rate-limiter-provider/rate-limiter-provider.d.ts +2 -4
- package/dist/rate-limiter/implementations/derivables/rate-limiter-provider/rate-limiter-provider.js.map +1 -1
- package/dist/rate-limiter/implementations/derivables/rate-limiter-provider/rate-limiter.d.ts +1 -1
- package/dist/rate-limiter/implementations/derivables/rate-limiter-provider/rate-limiter.js +6 -6
- package/dist/rate-limiter/implementations/derivables/rate-limiter-provider/rate-limiter.js.map +1 -1
- package/dist/rate-limiter/implementations/derivables/rate-limiter-provider-factory/database-rate-limiter-provider-factory.d.ts +0 -2
- package/dist/rate-limiter/implementations/derivables/rate-limiter-provider-factory/database-rate-limiter-provider-factory.js.map +1 -1
- package/dist/rate-limiter/implementations/derivables/rate-limiter-provider-factory/rate-limiter-provider-factory.d.ts +0 -2
- package/dist/rate-limiter/implementations/derivables/rate-limiter-provider-factory/rate-limiter-provider-factory.js.map +1 -1
- package/dist/rate-limiter/implementations/test-utilities/fixed-window-limiter.test-suite.d.ts +0 -1
- package/dist/rate-limiter/implementations/test-utilities/fixed-window-limiter.test-suite.js +1 -1
- package/dist/rate-limiter/implementations/test-utilities/fixed-window-limiter.test-suite.js.map +1 -1
- package/dist/rate-limiter/implementations/test-utilities/rate-limiter-storage-adapter.test-suite.d.ts +0 -1
- package/dist/rate-limiter/implementations/test-utilities/rate-limiter-storage-adapter.test-suite.js +1 -1
- package/dist/rate-limiter/implementations/test-utilities/rate-limiter-storage-adapter.test-suite.js.map +1 -1
- package/dist/rate-limiter/implementations/test-utilities/sliding-window-limiter.test-suite.d.ts +0 -1
- package/dist/rate-limiter/implementations/test-utilities/sliding-window-limiter.test-suite.js +1 -1
- package/dist/rate-limiter/implementations/test-utilities/sliding-window-limiter.test-suite.js.map +1 -1
- package/dist/resilience/middlewares/fallback/fallback.types.d.ts +0 -4
- package/dist/resilience/middlewares/observe/observe.types.d.ts +0 -9
- package/dist/resilience/middlewares/retry/retry.types.d.ts +0 -6
- package/dist/resilience/middlewares/timeout/timeout.type.d.ts +0 -4
- package/dist/resilience/resilience.errors.d.ts +0 -5
- package/dist/resilience/resilience.errors.js +0 -4
- package/dist/resilience/resilience.errors.js.map +1 -1
- package/dist/semaphore/contracts/semaphore-adapter.contract.d.ts +0 -2
- package/dist/semaphore/contracts/semaphore-provider.contract.d.ts +0 -2
- package/dist/semaphore/contracts/semaphore-state.contract.d.ts +0 -7
- package/dist/semaphore/contracts/semaphore-state.contract.js +0 -1
- package/dist/semaphore/contracts/semaphore-state.contract.js.map +1 -1
- package/dist/semaphore/contracts/semaphore.contract.d.ts +3 -6
- package/dist/semaphore/contracts/semaphore.contract.js +2 -1
- package/dist/semaphore/contracts/semaphore.contract.js.map +1 -1
- package/dist/semaphore/contracts/semaphore.errors.d.ts +0 -3
- package/dist/semaphore/contracts/semaphore.errors.js +0 -2
- package/dist/semaphore/contracts/semaphore.errors.js.map +1 -1
- package/dist/semaphore/contracts/semaphore.events.d.ts +0 -3
- package/dist/semaphore/contracts/semaphore.events.js +0 -1
- package/dist/semaphore/contracts/semaphore.events.js.map +1 -1
- package/dist/semaphore/contracts/types.d.ts +0 -1
- package/dist/semaphore/implementations/adapters/kysely-semaphore-adapter/kysely-semaphore-adapter.d.ts +0 -4
- package/dist/semaphore/implementations/adapters/kysely-semaphore-adapter/kysely-semaphore-adapter.js.map +1 -1
- package/dist/semaphore/implementations/adapters/memory-semaphore-adapter/memory-semaphore-adapter.d.ts +1 -2
- package/dist/semaphore/implementations/adapters/memory-semaphore-adapter/memory-semaphore-adapter.js +18 -23
- package/dist/semaphore/implementations/adapters/memory-semaphore-adapter/memory-semaphore-adapter.js.map +1 -1
- package/dist/semaphore/implementations/adapters/mongodb-semaphore-adapter/mongodb-semaphore-adapter.d.ts +0 -3
- package/dist/semaphore/implementations/adapters/mongodb-semaphore-adapter/mongodb-semaphore-adapter.js.map +1 -1
- package/dist/semaphore/implementations/adapters/no-op-semaphore-adapter/no-op-semaphore-adapter.d.ts +1 -1
- package/dist/semaphore/implementations/adapters/no-op-semaphore-adapter/no-op-semaphore-adapter.js +1 -1
- package/dist/semaphore/implementations/derivables/semaphore-provider/semaphore-provider.d.ts +2 -4
- package/dist/semaphore/implementations/derivables/semaphore-provider/semaphore-provider.js.map +1 -1
- package/dist/semaphore/implementations/derivables/semaphore-provider/semaphore-serde-transformer.js.map +1 -1
- package/dist/semaphore/implementations/derivables/semaphore-provider/semaphore.d.ts +3 -3
- package/dist/semaphore/implementations/derivables/semaphore-provider/semaphore.js +2 -2
- package/dist/semaphore/implementations/derivables/semaphore-provider/semaphore.js.map +1 -1
- package/dist/semaphore/implementations/derivables/semaphore-provider-factory/semaphore-provider-factory.d.ts +0 -2
- package/dist/semaphore/implementations/derivables/semaphore-provider-factory/semaphore-provider-factory.js.map +1 -1
- package/dist/semaphore/implementations/test-utilities/database-semaphore-adapter.test-suite.d.ts +0 -1
- package/dist/semaphore/implementations/test-utilities/database-semaphore-adapter.test-suite.js +1 -1
- package/dist/semaphore/implementations/test-utilities/database-semaphore-adapter.test-suite.js.map +1 -1
- package/dist/semaphore/implementations/test-utilities/semaphore-adapter.test-suite.d.ts +0 -1
- package/dist/semaphore/implementations/test-utilities/semaphore-adapter.test-suite.js +1 -1
- package/dist/semaphore/implementations/test-utilities/semaphore-adapter.test-suite.js.map +1 -1
- package/dist/semaphore/implementations/test-utilities/semaphore-provider.test-suite.d.ts +0 -1
- package/dist/semaphore/implementations/test-utilities/semaphore-provider.test-suite.js +1 -1
- package/dist/semaphore/implementations/test-utilities/semaphore-provider.test-suite.js.map +1 -1
- package/dist/serde/contracts/flexible-serde-adapter.contract.d.ts +0 -1
- package/dist/serde/contracts/flexible-serde.contract.d.ts +0 -2
- package/dist/serde/contracts/serde.errors.d.ts +1 -4
- package/dist/serde/contracts/serde.errors.js +0 -2
- package/dist/serde/contracts/serde.errors.js.map +1 -1
- package/dist/serde/implementations/adapters/no-op-serde-adapter/no-op-serde-adapter.d.ts +1 -1
- package/dist/serde/implementations/adapters/no-op-serde-adapter/no-op-serde-adapter.js +1 -1
- package/dist/serde/implementations/adapters/super-json-serde-adapter/super-json-serde-adapter.d.ts +0 -1
- package/dist/serde/implementations/adapters/super-json-serde-adapter/super-json-serde-adapter.js +0 -1
- package/dist/serde/implementations/adapters/super-json-serde-adapter/super-json-serde-adapter.js.map +1 -1
- package/dist/serde/implementations/derivables/serde-transformers.d.ts +1 -0
- package/dist/serde/implementations/derivables/serde-transformers.js +1 -0
- package/dist/serde/implementations/derivables/serde-transformers.js.map +1 -1
- package/dist/serde/implementations/derivables/serde.d.ts +0 -2
- package/dist/serde/implementations/derivables/serde.js.map +1 -1
- package/dist/serde/implementations/test-utilities/flexible-serde-adapter.test-suite.d.ts +0 -1
- package/dist/serde/implementations/test-utilities/flexible-serde-adapter.test-suite.js.map +1 -1
- package/dist/serde/implementations/test-utilities/flexible-serde.test-suite.d.ts +0 -1
- package/dist/serde/implementations/test-utilities/flexible-serde.test-suite.js +1 -0
- package/dist/serde/implementations/test-utilities/flexible-serde.test-suite.js.map +1 -1
- package/dist/shared-lock/contracts/database-shared-lock-adapter.contract.d.ts +0 -3
- package/dist/shared-lock/contracts/shared-lock-adapter.contract.d.ts +0 -1
- package/dist/shared-lock/contracts/shared-lock-provider.contract.d.ts +0 -2
- package/dist/shared-lock/contracts/shared-lock-state.contract.d.ts +0 -15
- package/dist/shared-lock/contracts/shared-lock-state.contract.js +0 -3
- package/dist/shared-lock/contracts/shared-lock-state.contract.js.map +1 -1
- package/dist/shared-lock/contracts/shared-lock.contract.d.ts +3 -8
- package/dist/shared-lock/contracts/shared-lock.contract.js +2 -1
- package/dist/shared-lock/contracts/shared-lock.contract.js.map +1 -1
- package/dist/shared-lock/contracts/shared-lock.errors.d.ts +0 -9
- package/dist/shared-lock/contracts/shared-lock.errors.js +0 -6
- package/dist/shared-lock/contracts/shared-lock.errors.js.map +1 -1
- package/dist/shared-lock/contracts/shared-lock.events.d.ts +0 -7
- package/dist/shared-lock/contracts/shared-lock.events.js +0 -3
- package/dist/shared-lock/contracts/shared-lock.events.js.map +1 -1
- package/dist/shared-lock/implementations/adapters/kysely-shared-lock-adapter/kysely-shared-lock-adapter.d.ts +0 -5
- package/dist/shared-lock/implementations/adapters/kysely-shared-lock-adapter/kysely-shared-lock-adapter.js.map +1 -1
- package/dist/shared-lock/implementations/adapters/memory-shared-lock-adapter/memory-shared-lock-adapter.d.ts +1 -4
- package/dist/shared-lock/implementations/adapters/memory-shared-lock-adapter/memory-shared-lock-adapter.js +42 -52
- package/dist/shared-lock/implementations/adapters/memory-shared-lock-adapter/memory-shared-lock-adapter.js.map +1 -1
- package/dist/shared-lock/implementations/adapters/mongodb-shared-lock-adapter/mongodb-shared-lock-adapter.d.ts +0 -5
- package/dist/shared-lock/implementations/adapters/mongodb-shared-lock-adapter/mongodb-shared-lock-adapter.js.map +1 -1
- package/dist/shared-lock/implementations/adapters/no-op-shared-lock-adapter/no-op-shared-lock-adapter.d.ts +1 -1
- package/dist/shared-lock/implementations/adapters/no-op-shared-lock-adapter/no-op-shared-lock-adapter.js +1 -1
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/shared-lock-provider.d.ts +2 -4
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/shared-lock-provider.js.map +1 -1
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/shared-lock-serde-transformer.js.map +1 -1
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/shared-lock.d.ts +5 -5
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/shared-lock.js +12 -12
- package/dist/shared-lock/implementations/derivables/shared-lock-provider/shared-lock.js.map +1 -1
- package/dist/shared-lock/implementations/derivables/shared-lock-provider-factory/shared-lock-provider-factory.d.ts +0 -2
- package/dist/shared-lock/implementations/derivables/shared-lock-provider-factory/shared-lock-provider-factory.js.map +1 -1
- package/dist/shared-lock/implementations/test-utilities/database-shared-lock-adapter.test-suite.d.ts +0 -1
- package/dist/shared-lock/implementations/test-utilities/database-shared-lock-adapter.test-suite.js +1 -1
- package/dist/shared-lock/implementations/test-utilities/database-shared-lock-adapter.test-suite.js.map +1 -1
- package/dist/shared-lock/implementations/test-utilities/shared-lock-adapter.test-suite.d.ts +0 -1
- package/dist/shared-lock/implementations/test-utilities/shared-lock-adapter.test-suite.js +1 -1
- package/dist/shared-lock/implementations/test-utilities/shared-lock-adapter.test-suite.js.map +1 -1
- package/dist/shared-lock/implementations/test-utilities/shared-lock-provider.test-suite.d.ts +0 -1
- package/dist/shared-lock/implementations/test-utilities/shared-lock-provider.test-suite.js +1 -1
- package/dist/shared-lock/implementations/test-utilities/shared-lock-provider.test-suite.js.map +1 -1
- package/dist/task/implementations/task.js +0 -1
- package/dist/task/implementations/task.js.map +1 -1
- package/dist/time-span/contracts/time-span.contract.d.ts +0 -1
- package/dist/time-span/contracts/time-span.contract.js +0 -1
- package/dist/time-span/contracts/time-span.contract.js.map +1 -1
- package/dist/time-span/implementations/time-span.d.ts +1 -3
- package/dist/time-span/implementations/time-span.js +1 -1
- package/dist/time-span/implementations/time-span.js.map +1 -1
- package/dist/utilities/contracts/comparable.contract.d.ts +0 -6
- package/dist/utilities/contracts/deinitizable.contract.d.ts +0 -1
- package/dist/utilities/contracts/initizable.contract.d.ts +0 -1
- package/dist/utilities/contracts/prunable.contract.d.ts +0 -1
- package/dist/utilities/contracts/sqlite-database.contract.d.ts +0 -2
- package/dist/utilities/errors.d.ts +0 -1
- package/dist/utilities/errors.js +0 -1
- package/dist/utilities/errors.js.map +1 -1
- package/dist/utilities/functions/error-policy.d.ts +0 -2
- package/dist/utilities/functions/error-policy.js.map +1 -1
- package/dist/utilities/functions/invokable.d.ts +0 -4
- package/dist/utilities/functions/invokable.js.map +1 -1
- package/dist/utilities/functions/is-positive-nbr.d.ts +0 -1
- package/dist/utilities/functions/is-positive-nbr.js +0 -1
- package/dist/utilities/functions/is-positive-nbr.js.map +1 -1
- package/dist/utilities/functions/iterable-to-async-iterable.js +1 -2
- package/dist/utilities/functions/iterable-to-async-iterable.js.map +1 -1
- package/dist/utilities/functions/lazy.d.ts +0 -5
- package/dist/utilities/functions/lazy.js.map +1 -1
- package/dist/utilities/functions/object.js +2 -6
- package/dist/utilities/functions/object.js.map +1 -1
- package/dist/utilities/functions/resolve-one-or-more.d.ts +0 -1
- package/dist/utilities/functions/resolve-one-or-more.js.map +1 -1
- package/dist/utilities/types/async-iterable-value.type.d.ts +0 -2
- package/dist/utilities/types/none-func.type.d.ts +0 -1
- package/dist/utilities/types/promiseable.type.d.ts +0 -1
- package/package.json +15 -1
|
@@ -0,0 +1,3109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module FileStorage
|
|
3
|
+
*/
|
|
4
|
+
import { vi, } from "vitest";
|
|
5
|
+
import { FileSize } from "../../../file-size/implementations/_module.js";
|
|
6
|
+
import { FILE_EVENTS, KeyExistsFileError, KeyNotFoundFileError, } from "../../../file-storage/contracts/_module.js";
|
|
7
|
+
import { resolveFileContent } from "../../../file-storage/implementations/derivables/file-storage/resolve-file-content.js";
|
|
8
|
+
import {} from "../../../serde/contracts/_module.js";
|
|
9
|
+
import {} from "../../../utilities/_module.js";
|
|
10
|
+
function isBinaryData(val) {
|
|
11
|
+
return (val instanceof ArrayBuffer ||
|
|
12
|
+
val instanceof SharedArrayBuffer ||
|
|
13
|
+
ArrayBuffer.isView(val) ||
|
|
14
|
+
(typeof Buffer !== "undefined" && Buffer.isBuffer(val)));
|
|
15
|
+
}
|
|
16
|
+
function isBytesArrayEqualityTester(a, b) {
|
|
17
|
+
if (!isBinaryData(a)) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
if (!isBinaryData(b)) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const uInt8ArrayA = resolveFileContent(a);
|
|
24
|
+
const uInt8ArrayB = resolveFileContent(b);
|
|
25
|
+
if (uInt8ArrayA.length !== uInt8ArrayB.length) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
for (let i = 0; i < uInt8ArrayA.length; i++) {
|
|
29
|
+
if (uInt8ArrayA[i] !== uInt8ArrayB[i]) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
async function resolveStream(stream) {
|
|
36
|
+
if (!stream) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
const chunks = [];
|
|
40
|
+
let totalLength = 0;
|
|
41
|
+
// 1. Collect all chunks and track the total byte length
|
|
42
|
+
for await (const chunk of stream) {
|
|
43
|
+
chunks.push(chunk);
|
|
44
|
+
totalLength += chunk.byteLength;
|
|
45
|
+
}
|
|
46
|
+
// Handle empty streams
|
|
47
|
+
if (chunks.length === 0) {
|
|
48
|
+
return new Uint8Array(0);
|
|
49
|
+
}
|
|
50
|
+
// 2. Optimization: If there's only one chunk, just return it
|
|
51
|
+
if (chunks.length === 1) {
|
|
52
|
+
const chunk = chunks[0];
|
|
53
|
+
if (chunk === undefined) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
return chunk;
|
|
57
|
+
}
|
|
58
|
+
// 3. Allocate the final memory once
|
|
59
|
+
const result = new Uint8Array(totalLength);
|
|
60
|
+
let offset = 0;
|
|
61
|
+
// 4. Copy each chunk into the final array
|
|
62
|
+
for (const chunk of chunks) {
|
|
63
|
+
result.set(chunk, offset);
|
|
64
|
+
offset += chunk.byteLength;
|
|
65
|
+
}
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* The `fileStorageTestSuite` function simplifies the process of testing your custom implementation of {@link IFileStorage | `IFileStorage`} with `vitest`.
|
|
70
|
+
*
|
|
71
|
+
* IMPORT_PATH: `"@daiso-tech/core/file-storage/test-utilities"`
|
|
72
|
+
* @group TestUtilities
|
|
73
|
+
*/
|
|
74
|
+
export function fileStorageTestSuite(settings) {
|
|
75
|
+
const { expect, test, createFileStorage, describe, beforeEach, excludeEventTests = false, excludeSerdeTests = false, } = settings;
|
|
76
|
+
let fileStorage;
|
|
77
|
+
let serde;
|
|
78
|
+
beforeEach(async () => {
|
|
79
|
+
const { fileStorage: fileStorage_, serde: serde_ } = await createFileStorage();
|
|
80
|
+
fileStorage = fileStorage_;
|
|
81
|
+
serde = serde_;
|
|
82
|
+
});
|
|
83
|
+
describe("IFileStorage tests:", () => {
|
|
84
|
+
expect.addEqualityTesters([isBytesArrayEqualityTester]);
|
|
85
|
+
describe("Api tests:", () => {
|
|
86
|
+
describe("method: getText", () => {
|
|
87
|
+
test("Should return null when key does not exists", async () => {
|
|
88
|
+
const noneExistingKey = "a";
|
|
89
|
+
const result = await fileStorage
|
|
90
|
+
.create(noneExistingKey)
|
|
91
|
+
.getText();
|
|
92
|
+
expect(result).toBeNull();
|
|
93
|
+
});
|
|
94
|
+
test("Should return text when key exists", async () => {
|
|
95
|
+
const key = "a";
|
|
96
|
+
const text = "CONTENT";
|
|
97
|
+
const data = new Uint8Array(Buffer.from(text, "utf8"));
|
|
98
|
+
const file = fileStorage.create(key);
|
|
99
|
+
await file.add({ data });
|
|
100
|
+
const result = await file.getText();
|
|
101
|
+
expect(result).toEqual(text);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
describe("method: getTextOrFail", () => {
|
|
105
|
+
test("Should throw KeyNotFoundFileError when key does not exists", async () => {
|
|
106
|
+
const noneExistingKey = "a";
|
|
107
|
+
const result = fileStorage
|
|
108
|
+
.create(noneExistingKey)
|
|
109
|
+
.getTextOrFail();
|
|
110
|
+
await expect(result).rejects.toBeInstanceOf(KeyNotFoundFileError);
|
|
111
|
+
});
|
|
112
|
+
test("Should return text when key exists", async () => {
|
|
113
|
+
const key = "a";
|
|
114
|
+
const text = "CONTENT";
|
|
115
|
+
const data = new Uint8Array(Buffer.from(text, "utf8"));
|
|
116
|
+
const file = fileStorage.create(key);
|
|
117
|
+
await file.add({ data });
|
|
118
|
+
const result = await file.getTextOrFail();
|
|
119
|
+
expect(result).toEqual(text);
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
describe("method: getBytes", () => {
|
|
123
|
+
test("Should return null when key does not exists", async () => {
|
|
124
|
+
const noneExistingKey = "a";
|
|
125
|
+
const result = await fileStorage
|
|
126
|
+
.create(noneExistingKey)
|
|
127
|
+
.getBytes();
|
|
128
|
+
expect(result).toBeNull();
|
|
129
|
+
});
|
|
130
|
+
test("Should return Uint8Array when key exists", async () => {
|
|
131
|
+
const key = "a";
|
|
132
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
133
|
+
const file = fileStorage.create(key);
|
|
134
|
+
await file.add({ data });
|
|
135
|
+
const result = await file.getBytes();
|
|
136
|
+
expect(result).toEqual(data);
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
describe("method: getBytesOrFail", () => {
|
|
140
|
+
test("Should throw KeyNotFoundFileError when key does not exists", async () => {
|
|
141
|
+
const noneExistingKey = "a";
|
|
142
|
+
const result = fileStorage
|
|
143
|
+
.create(noneExistingKey)
|
|
144
|
+
.getBytesOrFail();
|
|
145
|
+
await expect(result).rejects.toBeInstanceOf(KeyNotFoundFileError);
|
|
146
|
+
});
|
|
147
|
+
test("Should return Uint8Array when key exists", async () => {
|
|
148
|
+
const key = "a";
|
|
149
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
150
|
+
const file = fileStorage.create(key);
|
|
151
|
+
await file.add({ data });
|
|
152
|
+
const result = await file.getBytesOrFail();
|
|
153
|
+
expect(result).toEqual(data);
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
describe("method: getBuffer", () => {
|
|
157
|
+
test("Should return null when key does not exists", async () => {
|
|
158
|
+
const noneExistingKey = "a";
|
|
159
|
+
const result = await fileStorage
|
|
160
|
+
.create(noneExistingKey)
|
|
161
|
+
.getBuffer();
|
|
162
|
+
expect(result).toBeNull();
|
|
163
|
+
});
|
|
164
|
+
test("Should return Uint8Array when key exists", async () => {
|
|
165
|
+
const key = "a";
|
|
166
|
+
const buffer = Buffer.from("CONTENT", "utf8");
|
|
167
|
+
const data = new Uint8Array(buffer);
|
|
168
|
+
const file = fileStorage.create(key);
|
|
169
|
+
await file.add({ data });
|
|
170
|
+
const result = await file.getBuffer();
|
|
171
|
+
expect(result).toEqual(buffer);
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
describe("method: getBufferOrFail", () => {
|
|
175
|
+
test("Should throw KeyNotFoundFileError when key does not exists", async () => {
|
|
176
|
+
const noneExistingKey = "a";
|
|
177
|
+
const result = fileStorage
|
|
178
|
+
.create(noneExistingKey)
|
|
179
|
+
.getBufferOrFail();
|
|
180
|
+
await expect(result).rejects.toBeInstanceOf(KeyNotFoundFileError);
|
|
181
|
+
});
|
|
182
|
+
test("Should return Uint8Array when key exists", async () => {
|
|
183
|
+
const key = "a";
|
|
184
|
+
const buffer = Buffer.from("CONTENT", "utf8");
|
|
185
|
+
const data = new Uint8Array(buffer);
|
|
186
|
+
const file = fileStorage.create(key);
|
|
187
|
+
await file.add({ data });
|
|
188
|
+
const result = await file.getBufferOrFail();
|
|
189
|
+
expect(result).toEqual(data);
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
describe("method: getArrayBuffer", () => {
|
|
193
|
+
test("Should return null when key does not exists", async () => {
|
|
194
|
+
const noneExistingKey = "a";
|
|
195
|
+
const result = await fileStorage
|
|
196
|
+
.create(noneExistingKey)
|
|
197
|
+
.getArrayBuffer();
|
|
198
|
+
expect(result).toBeNull();
|
|
199
|
+
});
|
|
200
|
+
test("Should return ArrayBuffer when key exists", async () => {
|
|
201
|
+
const key = "a";
|
|
202
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
203
|
+
const file = fileStorage.create(key);
|
|
204
|
+
await file.add({ data });
|
|
205
|
+
const result = await file.getArrayBuffer();
|
|
206
|
+
expect(result).toEqual(data);
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
describe("method: getArrayBufferOrFail", () => {
|
|
210
|
+
test("Should throw KeyNotFoundFileError when key does not exists", async () => {
|
|
211
|
+
const noneExistingKey = "a";
|
|
212
|
+
const result = fileStorage
|
|
213
|
+
.create(noneExistingKey)
|
|
214
|
+
.getArrayBufferOrFail();
|
|
215
|
+
await expect(result).rejects.toBeInstanceOf(KeyNotFoundFileError);
|
|
216
|
+
});
|
|
217
|
+
test("Should return ArrayBuffer when key exists", async () => {
|
|
218
|
+
const key = "a";
|
|
219
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
220
|
+
const file = fileStorage.create(key);
|
|
221
|
+
await file.add({ data });
|
|
222
|
+
const result = await file.getArrayBufferOrFail();
|
|
223
|
+
expect(result).toEqual(data);
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
describe("method: getReadable", () => {
|
|
227
|
+
test("Should return null when key does not exists", async () => {
|
|
228
|
+
const noneExistingKey = "a";
|
|
229
|
+
const result = await fileStorage
|
|
230
|
+
.create(noneExistingKey)
|
|
231
|
+
.getReadable();
|
|
232
|
+
expect(result).toBeNull();
|
|
233
|
+
});
|
|
234
|
+
test("Should return Readable when key exists", async () => {
|
|
235
|
+
const key = "a";
|
|
236
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
237
|
+
const file = fileStorage.create(key);
|
|
238
|
+
await file.add({ data });
|
|
239
|
+
const result = await resolveStream(await file.getReadable());
|
|
240
|
+
expect(result).toEqual(data);
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
describe("method: getReadableOrFail", () => {
|
|
244
|
+
test("Should throw KeyNotFoundFileError when key does not exists", async () => {
|
|
245
|
+
const noneExistingKey = "a";
|
|
246
|
+
const result = fileStorage
|
|
247
|
+
.create(noneExistingKey)
|
|
248
|
+
.getReadableOrFail();
|
|
249
|
+
await expect(result).rejects.toBeInstanceOf(KeyNotFoundFileError);
|
|
250
|
+
});
|
|
251
|
+
test("Should return Readable when key exists", async () => {
|
|
252
|
+
const key = "a";
|
|
253
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
254
|
+
const file = fileStorage.create(key);
|
|
255
|
+
await file.add({ data });
|
|
256
|
+
const result = await resolveStream(await file.getReadableOrFail());
|
|
257
|
+
expect(result).toEqual(data);
|
|
258
|
+
});
|
|
259
|
+
});
|
|
260
|
+
describe("method: getReadableStream", () => {
|
|
261
|
+
test("Should return null when key does not exists", async () => {
|
|
262
|
+
const noneExistingKey = "a";
|
|
263
|
+
const result = await fileStorage
|
|
264
|
+
.create(noneExistingKey)
|
|
265
|
+
.getReadableStream();
|
|
266
|
+
expect(result).toBeNull();
|
|
267
|
+
});
|
|
268
|
+
test("Should return Readable when key exists", async () => {
|
|
269
|
+
const key = "a";
|
|
270
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
271
|
+
const file = fileStorage.create(key);
|
|
272
|
+
await file.add({ data });
|
|
273
|
+
const result = await resolveStream(await file.getReadableStream());
|
|
274
|
+
expect(result).toEqual(data);
|
|
275
|
+
});
|
|
276
|
+
});
|
|
277
|
+
describe("method: getReadableStreamOrFail", () => {
|
|
278
|
+
test("Should throw KeyNotFoundFileError when key does not exists", async () => {
|
|
279
|
+
const noneExistingKey = "a";
|
|
280
|
+
const result = fileStorage
|
|
281
|
+
.create(noneExistingKey)
|
|
282
|
+
.getReadableStreamOrFail();
|
|
283
|
+
await expect(result).rejects.toBeInstanceOf(KeyNotFoundFileError);
|
|
284
|
+
});
|
|
285
|
+
test("Should return Readable when key exists", async () => {
|
|
286
|
+
const key = "a";
|
|
287
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
288
|
+
const file = fileStorage.create(key);
|
|
289
|
+
await file.add({ data });
|
|
290
|
+
const result = await resolveStream(await file.getReadableStreamOrFail());
|
|
291
|
+
expect(result).toEqual(data);
|
|
292
|
+
});
|
|
293
|
+
});
|
|
294
|
+
describe("method: getMetadata", () => {
|
|
295
|
+
test("Should return null when key does not exists", async () => {
|
|
296
|
+
const result = await fileStorage.create("a").getMetadata();
|
|
297
|
+
expect(result).toBeNull();
|
|
298
|
+
});
|
|
299
|
+
test("Should return initial metadata with a null updatedAt after add method", async () => {
|
|
300
|
+
const file = fileStorage.create("a.json");
|
|
301
|
+
const data = new Uint8Array(Buffer.from(JSON.stringify({ content: "CONTENT" }), "utf8"));
|
|
302
|
+
await file.add({ data });
|
|
303
|
+
const result = await file.getMetadata();
|
|
304
|
+
expect(result).toEqual({
|
|
305
|
+
etag: expect.any(String),
|
|
306
|
+
contentType: "application/json",
|
|
307
|
+
fileSize: FileSize.fromBytes(data.byteLength),
|
|
308
|
+
updatedAt: expect.any(Date),
|
|
309
|
+
});
|
|
310
|
+
});
|
|
311
|
+
test("Should return initial metadata with a null updatedAt after put method", async () => {
|
|
312
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
313
|
+
const file = fileStorage.create("a.txt");
|
|
314
|
+
await file.put({ data });
|
|
315
|
+
const result = await file.getMetadata();
|
|
316
|
+
expect(result).toEqual({
|
|
317
|
+
etag: expect.any(String),
|
|
318
|
+
contentType: "text/plain",
|
|
319
|
+
fileSize: FileSize.fromBytes(data.byteLength),
|
|
320
|
+
updatedAt: expect.any(Date),
|
|
321
|
+
});
|
|
322
|
+
});
|
|
323
|
+
test("Should return metadata with a valid updatedAt after add method followed by update method", async () => {
|
|
324
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
325
|
+
const file = fileStorage.create("a.txt");
|
|
326
|
+
await file.add({ data });
|
|
327
|
+
const newContentType = "application/octet-stream";
|
|
328
|
+
const newData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
329
|
+
await file.update({
|
|
330
|
+
data: newData,
|
|
331
|
+
contentType: newContentType,
|
|
332
|
+
});
|
|
333
|
+
const result = await file.getMetadata();
|
|
334
|
+
expect(result).toEqual({
|
|
335
|
+
etag: expect.any(String),
|
|
336
|
+
contentType: newContentType,
|
|
337
|
+
fileSize: FileSize.fromBytes(data.byteLength),
|
|
338
|
+
updatedAt: expect.any(Date),
|
|
339
|
+
});
|
|
340
|
+
});
|
|
341
|
+
test("Should return metadata with a valid updatedAt after put method followed by update method", async () => {
|
|
342
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
343
|
+
const file = fileStorage.create("a.txt");
|
|
344
|
+
await file.put({ data });
|
|
345
|
+
const newContentType = "application/octet-stream";
|
|
346
|
+
const newData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
347
|
+
await file.update({
|
|
348
|
+
data: newData,
|
|
349
|
+
contentType: newContentType,
|
|
350
|
+
});
|
|
351
|
+
const result = await file.getMetadata();
|
|
352
|
+
expect(result).toEqual({
|
|
353
|
+
etag: expect.any(String),
|
|
354
|
+
contentType: newContentType,
|
|
355
|
+
fileSize: FileSize.fromBytes(data.byteLength),
|
|
356
|
+
updatedAt: expect.any(Date),
|
|
357
|
+
});
|
|
358
|
+
});
|
|
359
|
+
test("Should return metadata with a valid updatedAt after put overwrites an existing file", async () => {
|
|
360
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
361
|
+
const file = fileStorage.create("a.txt");
|
|
362
|
+
await file.put({ data });
|
|
363
|
+
const newContentType = "application/octet-stream";
|
|
364
|
+
const newData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
365
|
+
await file.put({
|
|
366
|
+
data: newData,
|
|
367
|
+
contentType: newContentType,
|
|
368
|
+
});
|
|
369
|
+
const result = await file.getMetadata();
|
|
370
|
+
expect(result).toEqual({
|
|
371
|
+
etag: expect.any(String),
|
|
372
|
+
contentType: newContentType,
|
|
373
|
+
fileSize: FileSize.fromBytes(data.byteLength),
|
|
374
|
+
updatedAt: expect.any(Date),
|
|
375
|
+
});
|
|
376
|
+
});
|
|
377
|
+
test("Should return initial metadata with a null updatedAt after addStream method", async () => {
|
|
378
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
379
|
+
const file = fileStorage.create("a.txt");
|
|
380
|
+
await file.addStream({
|
|
381
|
+
data: {
|
|
382
|
+
async *[Symbol.asyncIterator]() {
|
|
383
|
+
yield Promise.resolve(data);
|
|
384
|
+
},
|
|
385
|
+
},
|
|
386
|
+
});
|
|
387
|
+
const result = await file.getMetadata();
|
|
388
|
+
expect(result).toEqual({
|
|
389
|
+
etag: expect.any(String),
|
|
390
|
+
contentType: "text/plain",
|
|
391
|
+
fileSize: FileSize.fromBytes(data.byteLength),
|
|
392
|
+
updatedAt: expect.any(Date),
|
|
393
|
+
});
|
|
394
|
+
});
|
|
395
|
+
test("Should return initial metadata with a null updatedAt after putStream method", async () => {
|
|
396
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
397
|
+
const file = fileStorage.create("a.txt");
|
|
398
|
+
await file.putStream({
|
|
399
|
+
data: {
|
|
400
|
+
async *[Symbol.asyncIterator]() {
|
|
401
|
+
yield Promise.resolve(data);
|
|
402
|
+
},
|
|
403
|
+
},
|
|
404
|
+
});
|
|
405
|
+
const result = await file.getMetadata();
|
|
406
|
+
expect(result).toEqual({
|
|
407
|
+
etag: expect.any(String),
|
|
408
|
+
contentType: "text/plain",
|
|
409
|
+
fileSize: FileSize.fromBytes(data.byteLength),
|
|
410
|
+
updatedAt: expect.any(Date),
|
|
411
|
+
});
|
|
412
|
+
});
|
|
413
|
+
test("Should return metadata with a valid updatedAt after addStream method followed by updateStream method", async () => {
|
|
414
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
415
|
+
const file = fileStorage.create("a.txt");
|
|
416
|
+
await file.addStream({
|
|
417
|
+
data: {
|
|
418
|
+
async *[Symbol.asyncIterator]() {
|
|
419
|
+
yield Promise.resolve(data);
|
|
420
|
+
},
|
|
421
|
+
},
|
|
422
|
+
});
|
|
423
|
+
const newContentType = "application/octet-stream";
|
|
424
|
+
const newData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
425
|
+
await file.updateStream({
|
|
426
|
+
data: {
|
|
427
|
+
async *[Symbol.asyncIterator]() {
|
|
428
|
+
yield Promise.resolve(newData);
|
|
429
|
+
},
|
|
430
|
+
},
|
|
431
|
+
contentType: newContentType,
|
|
432
|
+
});
|
|
433
|
+
const result = await file.getMetadata();
|
|
434
|
+
expect(result).toEqual({
|
|
435
|
+
etag: expect.any(String),
|
|
436
|
+
contentType: newContentType,
|
|
437
|
+
fileSize: FileSize.fromBytes(data.byteLength),
|
|
438
|
+
updatedAt: expect.any(Date),
|
|
439
|
+
});
|
|
440
|
+
});
|
|
441
|
+
test("Should return metadata with a valid updatedAt after putStream method followed by updateStream method", async () => {
|
|
442
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
443
|
+
const file = fileStorage.create("a.txt");
|
|
444
|
+
await file.putStream({
|
|
445
|
+
data: {
|
|
446
|
+
async *[Symbol.asyncIterator]() {
|
|
447
|
+
yield Promise.resolve(data);
|
|
448
|
+
},
|
|
449
|
+
},
|
|
450
|
+
});
|
|
451
|
+
const newContentType = "application/octet-stream";
|
|
452
|
+
const newData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
453
|
+
await file.updateStream({
|
|
454
|
+
data: {
|
|
455
|
+
async *[Symbol.asyncIterator]() {
|
|
456
|
+
yield Promise.resolve(newData);
|
|
457
|
+
},
|
|
458
|
+
},
|
|
459
|
+
contentType: newContentType,
|
|
460
|
+
});
|
|
461
|
+
const result = await file.getMetadata();
|
|
462
|
+
expect(result).toEqual({
|
|
463
|
+
etag: expect.any(String),
|
|
464
|
+
contentType: newContentType,
|
|
465
|
+
fileSize: FileSize.fromBytes(data.byteLength),
|
|
466
|
+
updatedAt: expect.any(Date),
|
|
467
|
+
});
|
|
468
|
+
});
|
|
469
|
+
test("Should return metadata with a valid updatedAt after putStream overwrites an existing file", async () => {
|
|
470
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
471
|
+
const file = fileStorage.create("a.txt");
|
|
472
|
+
await file.putStream({
|
|
473
|
+
data: {
|
|
474
|
+
async *[Symbol.asyncIterator]() {
|
|
475
|
+
yield Promise.resolve(data);
|
|
476
|
+
},
|
|
477
|
+
},
|
|
478
|
+
});
|
|
479
|
+
const newContentType = "application/octet-stream";
|
|
480
|
+
const newData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
481
|
+
await file.putStream({
|
|
482
|
+
data: {
|
|
483
|
+
async *[Symbol.asyncIterator]() {
|
|
484
|
+
yield Promise.resolve(newData);
|
|
485
|
+
},
|
|
486
|
+
},
|
|
487
|
+
contentType: newContentType,
|
|
488
|
+
});
|
|
489
|
+
const result = await file.getMetadata();
|
|
490
|
+
expect(result).toEqual({
|
|
491
|
+
etag: expect.any(String),
|
|
492
|
+
contentType: newContentType,
|
|
493
|
+
fileSize: FileSize.fromBytes(data.byteLength),
|
|
494
|
+
updatedAt: expect.any(Date),
|
|
495
|
+
});
|
|
496
|
+
});
|
|
497
|
+
});
|
|
498
|
+
describe("method: getMetadataOrFail", () => {
|
|
499
|
+
test("Should throw KeyNotFoundFileError when key does not exists", async () => {
|
|
500
|
+
const result = fileStorage.create("a").getMetadataOrFail();
|
|
501
|
+
await expect(result).rejects.toBeInstanceOf(KeyNotFoundFileError);
|
|
502
|
+
});
|
|
503
|
+
test("Should return initial metadata with a null updatedAt after add method", async () => {
|
|
504
|
+
const file = fileStorage.create("a.json");
|
|
505
|
+
const data = new Uint8Array(Buffer.from(JSON.stringify({ content: "CONTENT" }), "utf8"));
|
|
506
|
+
await file.add({ data });
|
|
507
|
+
const result = await file.getMetadataOrFail();
|
|
508
|
+
expect(result).toEqual({
|
|
509
|
+
etag: expect.any(String),
|
|
510
|
+
contentType: "application/json",
|
|
511
|
+
fileSize: FileSize.fromBytes(data.byteLength),
|
|
512
|
+
updatedAt: expect.any(Date),
|
|
513
|
+
});
|
|
514
|
+
});
|
|
515
|
+
test("Should return initial metadata with a null updatedAt after put method", async () => {
|
|
516
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
517
|
+
const file = fileStorage.create("a.txt");
|
|
518
|
+
await file.put({ data });
|
|
519
|
+
const result = await file.getMetadataOrFail();
|
|
520
|
+
expect(result).toEqual({
|
|
521
|
+
etag: expect.any(String),
|
|
522
|
+
contentType: "text/plain",
|
|
523
|
+
fileSize: FileSize.fromBytes(data.byteLength),
|
|
524
|
+
updatedAt: expect.any(Date),
|
|
525
|
+
});
|
|
526
|
+
});
|
|
527
|
+
test("Should return metadata with a valid updatedAt after add method followed by update method", async () => {
|
|
528
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
529
|
+
const file = fileStorage.create("a.txt");
|
|
530
|
+
await file.add({ data });
|
|
531
|
+
const newContentType = "application/octet-stream";
|
|
532
|
+
const newData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
533
|
+
await file.update({
|
|
534
|
+
data: newData,
|
|
535
|
+
contentType: newContentType,
|
|
536
|
+
});
|
|
537
|
+
const result = await file.getMetadataOrFail();
|
|
538
|
+
expect(result).toEqual({
|
|
539
|
+
etag: expect.any(String),
|
|
540
|
+
contentType: newContentType,
|
|
541
|
+
fileSize: FileSize.fromBytes(data.byteLength),
|
|
542
|
+
updatedAt: expect.any(Date),
|
|
543
|
+
});
|
|
544
|
+
});
|
|
545
|
+
test("Should return metadata with a valid updatedAt after put method followed by update method", async () => {
|
|
546
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
547
|
+
const file = fileStorage.create("a.txt");
|
|
548
|
+
await file.put({ data });
|
|
549
|
+
const newContentType = "application/octet-stream";
|
|
550
|
+
const newData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
551
|
+
await file.update({
|
|
552
|
+
data: newData,
|
|
553
|
+
contentType: newContentType,
|
|
554
|
+
});
|
|
555
|
+
const result = await file.getMetadataOrFail();
|
|
556
|
+
expect(result).toEqual({
|
|
557
|
+
etag: expect.any(String),
|
|
558
|
+
contentType: newContentType,
|
|
559
|
+
fileSize: FileSize.fromBytes(data.byteLength),
|
|
560
|
+
updatedAt: expect.any(Date),
|
|
561
|
+
});
|
|
562
|
+
});
|
|
563
|
+
test("Should return metadata with a valid updatedAt after put overwrites an existing file", async () => {
|
|
564
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
565
|
+
const file = fileStorage.create("a.txt");
|
|
566
|
+
await file.put({ data });
|
|
567
|
+
const newContentType = "application/octet-stream";
|
|
568
|
+
const newData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
569
|
+
await file.put({
|
|
570
|
+
data: newData,
|
|
571
|
+
contentType: newContentType,
|
|
572
|
+
});
|
|
573
|
+
const result = await file.getMetadataOrFail();
|
|
574
|
+
expect(result).toEqual({
|
|
575
|
+
etag: expect.any(String),
|
|
576
|
+
contentType: newContentType,
|
|
577
|
+
fileSize: FileSize.fromBytes(data.byteLength),
|
|
578
|
+
updatedAt: expect.any(Date),
|
|
579
|
+
});
|
|
580
|
+
});
|
|
581
|
+
test("Should return initial metadata with a null updatedAt after addStream method", async () => {
|
|
582
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
583
|
+
const file = fileStorage.create("a.txt");
|
|
584
|
+
await file.addStream({
|
|
585
|
+
data: {
|
|
586
|
+
async *[Symbol.asyncIterator]() {
|
|
587
|
+
yield Promise.resolve(data);
|
|
588
|
+
},
|
|
589
|
+
},
|
|
590
|
+
});
|
|
591
|
+
const result = await file.getMetadataOrFail();
|
|
592
|
+
expect(result).toEqual({
|
|
593
|
+
etag: expect.any(String),
|
|
594
|
+
contentType: "text/plain",
|
|
595
|
+
fileSize: FileSize.fromBytes(data.byteLength),
|
|
596
|
+
updatedAt: expect.any(Date),
|
|
597
|
+
});
|
|
598
|
+
});
|
|
599
|
+
test("Should return initial metadata with a null updatedAt after putStream method", async () => {
|
|
600
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
601
|
+
const file = fileStorage.create("a.txt");
|
|
602
|
+
await file.putStream({
|
|
603
|
+
data: {
|
|
604
|
+
async *[Symbol.asyncIterator]() {
|
|
605
|
+
yield Promise.resolve(data);
|
|
606
|
+
},
|
|
607
|
+
},
|
|
608
|
+
});
|
|
609
|
+
const result = await file.getMetadataOrFail();
|
|
610
|
+
expect(result).toEqual({
|
|
611
|
+
etag: expect.any(String),
|
|
612
|
+
contentType: "text/plain",
|
|
613
|
+
fileSize: FileSize.fromBytes(data.byteLength),
|
|
614
|
+
updatedAt: expect.any(Date),
|
|
615
|
+
});
|
|
616
|
+
});
|
|
617
|
+
test("Should return metadata with a valid updatedAt after addStream method followed by updateStream method", async () => {
|
|
618
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
619
|
+
const file = fileStorage.create("a.txt");
|
|
620
|
+
await file.addStream({
|
|
621
|
+
data: {
|
|
622
|
+
async *[Symbol.asyncIterator]() {
|
|
623
|
+
yield Promise.resolve(data);
|
|
624
|
+
},
|
|
625
|
+
},
|
|
626
|
+
});
|
|
627
|
+
const newContentType = "application/octet-stream";
|
|
628
|
+
const newData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
629
|
+
await file.updateStream({
|
|
630
|
+
data: {
|
|
631
|
+
async *[Symbol.asyncIterator]() {
|
|
632
|
+
yield Promise.resolve(newData);
|
|
633
|
+
},
|
|
634
|
+
},
|
|
635
|
+
contentType: newContentType,
|
|
636
|
+
});
|
|
637
|
+
const result = await file.getMetadataOrFail();
|
|
638
|
+
expect(result).toEqual({
|
|
639
|
+
etag: expect.any(String),
|
|
640
|
+
contentType: newContentType,
|
|
641
|
+
fileSize: FileSize.fromBytes(data.byteLength),
|
|
642
|
+
updatedAt: expect.any(Date),
|
|
643
|
+
});
|
|
644
|
+
});
|
|
645
|
+
test("Should return metadata with a valid updatedAt after putStream method followed by updateStream method", async () => {
|
|
646
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
647
|
+
const file = fileStorage.create("a.txt");
|
|
648
|
+
await file.putStream({
|
|
649
|
+
data: {
|
|
650
|
+
async *[Symbol.asyncIterator]() {
|
|
651
|
+
yield Promise.resolve(data);
|
|
652
|
+
},
|
|
653
|
+
},
|
|
654
|
+
});
|
|
655
|
+
const newContentType = "application/octet-stream";
|
|
656
|
+
const newData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
657
|
+
await file.updateStream({
|
|
658
|
+
data: {
|
|
659
|
+
async *[Symbol.asyncIterator]() {
|
|
660
|
+
yield Promise.resolve(newData);
|
|
661
|
+
},
|
|
662
|
+
},
|
|
663
|
+
contentType: newContentType,
|
|
664
|
+
});
|
|
665
|
+
const result = await file.getMetadataOrFail();
|
|
666
|
+
expect(result).toEqual({
|
|
667
|
+
etag: expect.any(String),
|
|
668
|
+
contentType: newContentType,
|
|
669
|
+
fileSize: FileSize.fromBytes(data.byteLength),
|
|
670
|
+
updatedAt: expect.any(Date),
|
|
671
|
+
});
|
|
672
|
+
});
|
|
673
|
+
test("Should return metadata with a valid updatedAt after putStream overwrites an existing file", async () => {
|
|
674
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
675
|
+
const file = fileStorage.create("a.txt");
|
|
676
|
+
await file.putStream({
|
|
677
|
+
data: {
|
|
678
|
+
async *[Symbol.asyncIterator]() {
|
|
679
|
+
yield Promise.resolve(data);
|
|
680
|
+
},
|
|
681
|
+
},
|
|
682
|
+
});
|
|
683
|
+
const newContentType = "application/octet-stream";
|
|
684
|
+
const newData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
685
|
+
await file.putStream({
|
|
686
|
+
data: {
|
|
687
|
+
async *[Symbol.asyncIterator]() {
|
|
688
|
+
yield Promise.resolve(newData);
|
|
689
|
+
},
|
|
690
|
+
},
|
|
691
|
+
contentType: newContentType,
|
|
692
|
+
});
|
|
693
|
+
const result = await file.getMetadataOrFail();
|
|
694
|
+
expect(result).toEqual({
|
|
695
|
+
etag: expect.any(String),
|
|
696
|
+
contentType: newContentType,
|
|
697
|
+
fileSize: FileSize.fromBytes(data.byteLength),
|
|
698
|
+
updatedAt: expect.any(Date),
|
|
699
|
+
});
|
|
700
|
+
});
|
|
701
|
+
});
|
|
702
|
+
describe("method: exists", () => {
|
|
703
|
+
test("Should return false when key does not exists", async () => {
|
|
704
|
+
const noneExistingKey = "a";
|
|
705
|
+
const result = await fileStorage
|
|
706
|
+
.create(noneExistingKey)
|
|
707
|
+
.exists();
|
|
708
|
+
expect(result).toBe(false);
|
|
709
|
+
});
|
|
710
|
+
test("Should return true when key exists", async () => {
|
|
711
|
+
const key = "a";
|
|
712
|
+
const buffer = Buffer.from("CONTENT", "utf8");
|
|
713
|
+
const data = new Uint8Array(buffer);
|
|
714
|
+
const file = fileStorage.create(key);
|
|
715
|
+
await file.add({ data });
|
|
716
|
+
const result = await file.exists();
|
|
717
|
+
expect(result).toBe(true);
|
|
718
|
+
});
|
|
719
|
+
});
|
|
720
|
+
describe("method: missing", () => {
|
|
721
|
+
test("Should return true when key does not exists", async () => {
|
|
722
|
+
const noneExistingKey = "a";
|
|
723
|
+
const result = await fileStorage
|
|
724
|
+
.create(noneExistingKey)
|
|
725
|
+
.missing();
|
|
726
|
+
expect(result).toBe(true);
|
|
727
|
+
});
|
|
728
|
+
test("Should return false when key exists", async () => {
|
|
729
|
+
const key = "a";
|
|
730
|
+
const buffer = Buffer.from("CONTENT", "utf8");
|
|
731
|
+
const data = new Uint8Array(buffer);
|
|
732
|
+
const file = fileStorage.create(key);
|
|
733
|
+
await file.add({ data });
|
|
734
|
+
const result = await file.missing();
|
|
735
|
+
expect(result).toBe(false);
|
|
736
|
+
});
|
|
737
|
+
});
|
|
738
|
+
describe("method: add", () => {
|
|
739
|
+
test("Should return true when key does not exists", async () => {
|
|
740
|
+
const key = "a";
|
|
741
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
742
|
+
const result = await fileStorage.create(key).add({ data });
|
|
743
|
+
expect(result).toBe(true);
|
|
744
|
+
});
|
|
745
|
+
test("Should return false when key exists", async () => {
|
|
746
|
+
const key = "a";
|
|
747
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
748
|
+
const file = fileStorage.create(key);
|
|
749
|
+
await file.add({ data });
|
|
750
|
+
const newData = new Uint8Array(Buffer.from("NEW_CONTENT", "utf8"));
|
|
751
|
+
const result = await file.add({ data: newData });
|
|
752
|
+
expect(result).toBe(false);
|
|
753
|
+
});
|
|
754
|
+
test("Should persist data when key does not exists", async () => {
|
|
755
|
+
const key = "a";
|
|
756
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
757
|
+
const file = fileStorage.create(key);
|
|
758
|
+
await file.add({ data });
|
|
759
|
+
const result = await file.getBytes();
|
|
760
|
+
expect(result).toEqual(data);
|
|
761
|
+
});
|
|
762
|
+
test("Should not persist data when key exists", async () => {
|
|
763
|
+
const key = "a";
|
|
764
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
765
|
+
const file = fileStorage.create(key);
|
|
766
|
+
await file.add({ data });
|
|
767
|
+
const newData = new Uint8Array(Buffer.from("NEW_CONTENT", "utf8"));
|
|
768
|
+
await file.add({ data: newData });
|
|
769
|
+
const result = await file.getBytes();
|
|
770
|
+
expect(result).toEqual(data);
|
|
771
|
+
});
|
|
772
|
+
});
|
|
773
|
+
describe("method: addOrFail", () => {
|
|
774
|
+
test("Should not throw error when key does not exists", async () => {
|
|
775
|
+
const key = "a";
|
|
776
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
777
|
+
const result = fileStorage.create(key).addOrFail({ data });
|
|
778
|
+
await expect(result).resolves.toBeUndefined();
|
|
779
|
+
});
|
|
780
|
+
test("Should throw KeyExistsFileError when key exists", async () => {
|
|
781
|
+
const key = "a";
|
|
782
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
783
|
+
const file = fileStorage.create(key);
|
|
784
|
+
await file.addOrFail({ data });
|
|
785
|
+
const newData = new Uint8Array(Buffer.from("NEW_CONTENT", "utf8"));
|
|
786
|
+
const result = file.addOrFail({ data: newData });
|
|
787
|
+
await expect(result).rejects.toBeInstanceOf(KeyExistsFileError);
|
|
788
|
+
});
|
|
789
|
+
test("Should persist data when key does not exists", async () => {
|
|
790
|
+
const key = "a";
|
|
791
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
792
|
+
const file = fileStorage.create(key);
|
|
793
|
+
await file.addOrFail({ data });
|
|
794
|
+
const result = await file.getBytes();
|
|
795
|
+
expect(result).toEqual(data);
|
|
796
|
+
});
|
|
797
|
+
test("Should not persist data when key exists", async () => {
|
|
798
|
+
const key = "a";
|
|
799
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
800
|
+
const file = fileStorage.create(key);
|
|
801
|
+
await file.addOrFail({ data });
|
|
802
|
+
const newData = new Uint8Array(Buffer.from("NEW_CONTENT", "utf8"));
|
|
803
|
+
try {
|
|
804
|
+
await file.addOrFail({ data: newData });
|
|
805
|
+
}
|
|
806
|
+
catch {
|
|
807
|
+
/* EMPTY */
|
|
808
|
+
}
|
|
809
|
+
const result = await file.getBytes();
|
|
810
|
+
expect(result).toEqual(data);
|
|
811
|
+
});
|
|
812
|
+
});
|
|
813
|
+
describe("method: addStream", () => {
|
|
814
|
+
test("Should return true when key does not exists", async () => {
|
|
815
|
+
const key = "a";
|
|
816
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
817
|
+
const result = await fileStorage.create(key).addStream({
|
|
818
|
+
data: {
|
|
819
|
+
async *[Symbol.asyncIterator]() {
|
|
820
|
+
yield Promise.resolve(data);
|
|
821
|
+
},
|
|
822
|
+
},
|
|
823
|
+
});
|
|
824
|
+
expect(result).toBe(true);
|
|
825
|
+
});
|
|
826
|
+
test("Should return false when key exists", async () => {
|
|
827
|
+
const key = "a";
|
|
828
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
829
|
+
const file = fileStorage.create(key);
|
|
830
|
+
await file.addStream({
|
|
831
|
+
data: {
|
|
832
|
+
async *[Symbol.asyncIterator]() {
|
|
833
|
+
yield Promise.resolve(data);
|
|
834
|
+
},
|
|
835
|
+
},
|
|
836
|
+
});
|
|
837
|
+
const newData = new Uint8Array(Buffer.from("NEW_CONTENT", "utf8"));
|
|
838
|
+
const result = await file.addStream({
|
|
839
|
+
data: {
|
|
840
|
+
async *[Symbol.asyncIterator]() {
|
|
841
|
+
yield Promise.resolve(newData);
|
|
842
|
+
},
|
|
843
|
+
},
|
|
844
|
+
});
|
|
845
|
+
expect(result).toBe(false);
|
|
846
|
+
});
|
|
847
|
+
test("Should persist data when key does not exists", async () => {
|
|
848
|
+
const key = "a";
|
|
849
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
850
|
+
const file = fileStorage.create(key);
|
|
851
|
+
await file.addStream({
|
|
852
|
+
data: {
|
|
853
|
+
async *[Symbol.asyncIterator]() {
|
|
854
|
+
yield Promise.resolve(data);
|
|
855
|
+
},
|
|
856
|
+
},
|
|
857
|
+
});
|
|
858
|
+
const result = await file.getBytes();
|
|
859
|
+
expect(result).toEqual(data);
|
|
860
|
+
});
|
|
861
|
+
test("Should not persist data when key exists", async () => {
|
|
862
|
+
const key = "a";
|
|
863
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
864
|
+
const file = fileStorage.create(key);
|
|
865
|
+
await file.addStream({
|
|
866
|
+
data: {
|
|
867
|
+
async *[Symbol.asyncIterator]() {
|
|
868
|
+
yield Promise.resolve(data);
|
|
869
|
+
},
|
|
870
|
+
},
|
|
871
|
+
});
|
|
872
|
+
const newData = new Uint8Array(Buffer.from("NEW_CONTENT", "utf8"));
|
|
873
|
+
await file.addStream({
|
|
874
|
+
data: {
|
|
875
|
+
async *[Symbol.asyncIterator]() {
|
|
876
|
+
yield Promise.resolve(newData);
|
|
877
|
+
},
|
|
878
|
+
},
|
|
879
|
+
});
|
|
880
|
+
const result = await file.getBytes();
|
|
881
|
+
expect(result).toEqual(data);
|
|
882
|
+
});
|
|
883
|
+
});
|
|
884
|
+
describe("method: addStreamOrFail", () => {
|
|
885
|
+
test("Should not throw error when key does not exists", async () => {
|
|
886
|
+
const key = "a";
|
|
887
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
888
|
+
const result = fileStorage.create(key).addStreamOrFail({
|
|
889
|
+
data: {
|
|
890
|
+
async *[Symbol.asyncIterator]() {
|
|
891
|
+
yield Promise.resolve(data);
|
|
892
|
+
},
|
|
893
|
+
},
|
|
894
|
+
});
|
|
895
|
+
await expect(result).resolves.toBeUndefined();
|
|
896
|
+
});
|
|
897
|
+
test("Should throw KeyExistsFileError when key exists", async () => {
|
|
898
|
+
const key = "a";
|
|
899
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
900
|
+
const file = fileStorage.create(key);
|
|
901
|
+
await file.addStreamOrFail({
|
|
902
|
+
data: {
|
|
903
|
+
async *[Symbol.asyncIterator]() {
|
|
904
|
+
yield Promise.resolve(data);
|
|
905
|
+
},
|
|
906
|
+
},
|
|
907
|
+
});
|
|
908
|
+
const newData = new Uint8Array(Buffer.from("NEW_CONTENT", "utf8"));
|
|
909
|
+
const result = file.addStreamOrFail({
|
|
910
|
+
data: {
|
|
911
|
+
async *[Symbol.asyncIterator]() {
|
|
912
|
+
yield Promise.resolve(newData);
|
|
913
|
+
},
|
|
914
|
+
},
|
|
915
|
+
});
|
|
916
|
+
await expect(result).rejects.toBeInstanceOf(KeyExistsFileError);
|
|
917
|
+
});
|
|
918
|
+
test("Should persist data when key does not exists", async () => {
|
|
919
|
+
const key = "a";
|
|
920
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
921
|
+
const file = fileStorage.create(key);
|
|
922
|
+
await file.addStreamOrFail({
|
|
923
|
+
data: {
|
|
924
|
+
async *[Symbol.asyncIterator]() {
|
|
925
|
+
yield Promise.resolve(data);
|
|
926
|
+
},
|
|
927
|
+
},
|
|
928
|
+
});
|
|
929
|
+
const result = await file.getBytes();
|
|
930
|
+
expect(result).toEqual(data);
|
|
931
|
+
});
|
|
932
|
+
test("Should not persist data when key exists", async () => {
|
|
933
|
+
const key = "a";
|
|
934
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
935
|
+
const file = fileStorage.create(key);
|
|
936
|
+
await file.addStreamOrFail({
|
|
937
|
+
data: {
|
|
938
|
+
async *[Symbol.asyncIterator]() {
|
|
939
|
+
yield Promise.resolve(data);
|
|
940
|
+
},
|
|
941
|
+
},
|
|
942
|
+
});
|
|
943
|
+
const newData = new Uint8Array(Buffer.from("NEW_CONTENT", "utf8"));
|
|
944
|
+
try {
|
|
945
|
+
await file.addStreamOrFail({
|
|
946
|
+
data: {
|
|
947
|
+
async *[Symbol.asyncIterator]() {
|
|
948
|
+
yield Promise.resolve(newData);
|
|
949
|
+
},
|
|
950
|
+
},
|
|
951
|
+
});
|
|
952
|
+
}
|
|
953
|
+
catch {
|
|
954
|
+
/* EMPTY */
|
|
955
|
+
}
|
|
956
|
+
const result = await file.getBytes();
|
|
957
|
+
expect(result).toEqual(data);
|
|
958
|
+
});
|
|
959
|
+
});
|
|
960
|
+
describe("method: update", () => {
|
|
961
|
+
test("Should return false when key doesnt exist", async () => {
|
|
962
|
+
const key = "a";
|
|
963
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
964
|
+
const result = await fileStorage.create(key).update({
|
|
965
|
+
data,
|
|
966
|
+
});
|
|
967
|
+
expect(result).toBe(false);
|
|
968
|
+
});
|
|
969
|
+
test("Should not persist data when key doesnt exist", async () => {
|
|
970
|
+
const key = "a";
|
|
971
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
972
|
+
const file = fileStorage.create(key);
|
|
973
|
+
await file.update({ data });
|
|
974
|
+
const result = await file.getBytes();
|
|
975
|
+
expect(result).toBeNull();
|
|
976
|
+
});
|
|
977
|
+
test("Should return true when key exist", async () => {
|
|
978
|
+
const key = "a";
|
|
979
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
980
|
+
const file = fileStorage.create(key);
|
|
981
|
+
await file.add({ data });
|
|
982
|
+
const newData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
983
|
+
const result = await file.update({ data: newData });
|
|
984
|
+
expect(result).toBe(true);
|
|
985
|
+
});
|
|
986
|
+
test("Should persist data when key exist", async () => {
|
|
987
|
+
const key = "a";
|
|
988
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
989
|
+
const file = fileStorage.create(key);
|
|
990
|
+
await file.add({ data });
|
|
991
|
+
const newData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
992
|
+
await file.update({ data: newData });
|
|
993
|
+
const result = await file.getBytes();
|
|
994
|
+
expect(result).toEqual(newData);
|
|
995
|
+
});
|
|
996
|
+
});
|
|
997
|
+
describe("method: updateOrFail", () => {
|
|
998
|
+
test("Should throw KeyNotFoundFileError when key doesnt exist", async () => {
|
|
999
|
+
const key = "a";
|
|
1000
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1001
|
+
const result = fileStorage.create(key).updateOrFail({
|
|
1002
|
+
data,
|
|
1003
|
+
});
|
|
1004
|
+
await expect(result).rejects.toBeInstanceOf(KeyNotFoundFileError);
|
|
1005
|
+
});
|
|
1006
|
+
test("Should not persist data when key doesnt exist", async () => {
|
|
1007
|
+
const key = "a";
|
|
1008
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1009
|
+
const file = fileStorage.create(key);
|
|
1010
|
+
try {
|
|
1011
|
+
await file.updateOrFail({ data });
|
|
1012
|
+
}
|
|
1013
|
+
catch {
|
|
1014
|
+
/* EMPTY */
|
|
1015
|
+
}
|
|
1016
|
+
const result = await file.getBytes();
|
|
1017
|
+
expect(result).toBeNull();
|
|
1018
|
+
});
|
|
1019
|
+
test("Should not throw error when key exist", async () => {
|
|
1020
|
+
const key = "a";
|
|
1021
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1022
|
+
const file = fileStorage.create(key);
|
|
1023
|
+
await file.add({ data });
|
|
1024
|
+
const newData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1025
|
+
const result = file.updateOrFail({ data: newData });
|
|
1026
|
+
await expect(result).resolves.toBeUndefined();
|
|
1027
|
+
});
|
|
1028
|
+
test("Should persist data when key exist", async () => {
|
|
1029
|
+
const key = "a";
|
|
1030
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1031
|
+
const file = fileStorage.create(key);
|
|
1032
|
+
await file.add({ data });
|
|
1033
|
+
const newData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1034
|
+
await file.updateOrFail({ data: newData });
|
|
1035
|
+
const result = await file.getBytes();
|
|
1036
|
+
expect(result).toEqual(newData);
|
|
1037
|
+
});
|
|
1038
|
+
});
|
|
1039
|
+
describe("method: updateStream", () => {
|
|
1040
|
+
test("Should return false when key doesnt exist", async () => {
|
|
1041
|
+
const key = "a";
|
|
1042
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1043
|
+
const result = await fileStorage.create(key).updateStream({
|
|
1044
|
+
data: {
|
|
1045
|
+
async *[Symbol.asyncIterator]() {
|
|
1046
|
+
yield Promise.resolve(data);
|
|
1047
|
+
},
|
|
1048
|
+
},
|
|
1049
|
+
});
|
|
1050
|
+
expect(result).toBe(false);
|
|
1051
|
+
});
|
|
1052
|
+
test("Should not persist data when key doesnt exist", async () => {
|
|
1053
|
+
const key = "a";
|
|
1054
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1055
|
+
const file = fileStorage.create(key);
|
|
1056
|
+
await file.updateStream({
|
|
1057
|
+
data: {
|
|
1058
|
+
async *[Symbol.asyncIterator]() {
|
|
1059
|
+
yield Promise.resolve(data);
|
|
1060
|
+
},
|
|
1061
|
+
},
|
|
1062
|
+
});
|
|
1063
|
+
const result = await file.getBytes();
|
|
1064
|
+
expect(result).toBeNull();
|
|
1065
|
+
});
|
|
1066
|
+
test("Should return true when key exist", async () => {
|
|
1067
|
+
const key = "a";
|
|
1068
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1069
|
+
const file = fileStorage.create(key);
|
|
1070
|
+
await file.add({ data });
|
|
1071
|
+
const newData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1072
|
+
const result = await file.updateStream({
|
|
1073
|
+
data: {
|
|
1074
|
+
async *[Symbol.asyncIterator]() {
|
|
1075
|
+
yield Promise.resolve(newData);
|
|
1076
|
+
},
|
|
1077
|
+
},
|
|
1078
|
+
});
|
|
1079
|
+
expect(result).toBe(true);
|
|
1080
|
+
});
|
|
1081
|
+
test("Should persist data when key exist", async () => {
|
|
1082
|
+
const key = "a";
|
|
1083
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1084
|
+
const file = fileStorage.create(key);
|
|
1085
|
+
await file.add({ data });
|
|
1086
|
+
const newData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1087
|
+
await file.updateStream({
|
|
1088
|
+
data: {
|
|
1089
|
+
async *[Symbol.asyncIterator]() {
|
|
1090
|
+
yield Promise.resolve(newData);
|
|
1091
|
+
},
|
|
1092
|
+
},
|
|
1093
|
+
});
|
|
1094
|
+
const result = await file.getBytes();
|
|
1095
|
+
expect(result).toEqual(newData);
|
|
1096
|
+
});
|
|
1097
|
+
});
|
|
1098
|
+
describe("method: updateStreamOrFail", () => {
|
|
1099
|
+
test("Should throw KeyNotFoundFileError when key doesnt exist", async () => {
|
|
1100
|
+
const key = "a";
|
|
1101
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1102
|
+
const result = fileStorage.create(key).updateStreamOrFail({
|
|
1103
|
+
data: {
|
|
1104
|
+
async *[Symbol.asyncIterator]() {
|
|
1105
|
+
yield Promise.resolve(data);
|
|
1106
|
+
},
|
|
1107
|
+
},
|
|
1108
|
+
});
|
|
1109
|
+
await expect(result).rejects.toBeInstanceOf(KeyNotFoundFileError);
|
|
1110
|
+
});
|
|
1111
|
+
test("Should not persist data when key doesnt exist", async () => {
|
|
1112
|
+
const key = "a";
|
|
1113
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1114
|
+
const file = fileStorage.create(key);
|
|
1115
|
+
try {
|
|
1116
|
+
await file.updateStreamOrFail({
|
|
1117
|
+
data: {
|
|
1118
|
+
async *[Symbol.asyncIterator]() {
|
|
1119
|
+
yield Promise.resolve(data);
|
|
1120
|
+
},
|
|
1121
|
+
},
|
|
1122
|
+
});
|
|
1123
|
+
}
|
|
1124
|
+
catch {
|
|
1125
|
+
/* EMPTY */
|
|
1126
|
+
}
|
|
1127
|
+
const result = await file.getBytes();
|
|
1128
|
+
expect(result).toBeNull();
|
|
1129
|
+
});
|
|
1130
|
+
test("Should not throw error when key exist", async () => {
|
|
1131
|
+
const key = "a";
|
|
1132
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1133
|
+
const file = fileStorage.create(key);
|
|
1134
|
+
await file.add({ data });
|
|
1135
|
+
const newData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1136
|
+
const result = file.updateStreamOrFail({
|
|
1137
|
+
data: {
|
|
1138
|
+
async *[Symbol.asyncIterator]() {
|
|
1139
|
+
yield Promise.resolve(newData);
|
|
1140
|
+
},
|
|
1141
|
+
},
|
|
1142
|
+
});
|
|
1143
|
+
await expect(result).resolves.toBeUndefined();
|
|
1144
|
+
});
|
|
1145
|
+
test("Should persist data when key exist", async () => {
|
|
1146
|
+
const key = "a";
|
|
1147
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1148
|
+
const file = fileStorage.create(key);
|
|
1149
|
+
await file.add({ data });
|
|
1150
|
+
const newData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1151
|
+
await file.updateStreamOrFail({
|
|
1152
|
+
data: {
|
|
1153
|
+
async *[Symbol.asyncIterator]() {
|
|
1154
|
+
yield Promise.resolve(newData);
|
|
1155
|
+
},
|
|
1156
|
+
},
|
|
1157
|
+
});
|
|
1158
|
+
const result = await file.getBytes();
|
|
1159
|
+
expect(result).toEqual(newData);
|
|
1160
|
+
});
|
|
1161
|
+
});
|
|
1162
|
+
describe("method: put", () => {
|
|
1163
|
+
test("Should return false when key doesnt exist", async () => {
|
|
1164
|
+
const key = "a";
|
|
1165
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1166
|
+
const result = await fileStorage.create(key).put({ data });
|
|
1167
|
+
expect(result).toBe(false);
|
|
1168
|
+
});
|
|
1169
|
+
test("Should persist data when key doesnt exist", async () => {
|
|
1170
|
+
const key = "a";
|
|
1171
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1172
|
+
const file = fileStorage.create(key);
|
|
1173
|
+
await file.put({ data });
|
|
1174
|
+
const result = await file.getBytes();
|
|
1175
|
+
expect(result).toEqual(data);
|
|
1176
|
+
});
|
|
1177
|
+
test("Should return true when key exist", async () => {
|
|
1178
|
+
const key = "a";
|
|
1179
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1180
|
+
const file = fileStorage.create(key);
|
|
1181
|
+
await file.add({ data });
|
|
1182
|
+
const newData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1183
|
+
const result = await file.put({ data: newData });
|
|
1184
|
+
expect(result).toBe(true);
|
|
1185
|
+
});
|
|
1186
|
+
test("Should persist data when key exist", async () => {
|
|
1187
|
+
const key = "a";
|
|
1188
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1189
|
+
const file = fileStorage.create(key);
|
|
1190
|
+
await file.add({ data });
|
|
1191
|
+
const newData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1192
|
+
await file.put({ data: newData });
|
|
1193
|
+
const result = await file.getBytes();
|
|
1194
|
+
expect(result).toEqual(newData);
|
|
1195
|
+
});
|
|
1196
|
+
});
|
|
1197
|
+
describe("method: putStream", () => {
|
|
1198
|
+
test("Should return false when key doesnt exist", async () => {
|
|
1199
|
+
const key = "a";
|
|
1200
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1201
|
+
const result = await fileStorage.create(key).putStream({
|
|
1202
|
+
data: {
|
|
1203
|
+
async *[Symbol.asyncIterator]() {
|
|
1204
|
+
yield Promise.resolve(data);
|
|
1205
|
+
},
|
|
1206
|
+
},
|
|
1207
|
+
});
|
|
1208
|
+
expect(result).toBe(false);
|
|
1209
|
+
});
|
|
1210
|
+
test("Should persist data when key doesnt exist", async () => {
|
|
1211
|
+
const key = "a";
|
|
1212
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1213
|
+
const file = fileStorage.create(key);
|
|
1214
|
+
await file.putStream({
|
|
1215
|
+
data: {
|
|
1216
|
+
async *[Symbol.asyncIterator]() {
|
|
1217
|
+
yield Promise.resolve(data);
|
|
1218
|
+
},
|
|
1219
|
+
},
|
|
1220
|
+
});
|
|
1221
|
+
const result = await file.getBytes();
|
|
1222
|
+
expect(result).toEqual(data);
|
|
1223
|
+
});
|
|
1224
|
+
test("Should return true when key exist", async () => {
|
|
1225
|
+
const key = "a";
|
|
1226
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1227
|
+
const file = fileStorage.create(key);
|
|
1228
|
+
await file.add({ data });
|
|
1229
|
+
const newData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1230
|
+
const result = await file.putStream({
|
|
1231
|
+
data: {
|
|
1232
|
+
async *[Symbol.asyncIterator]() {
|
|
1233
|
+
yield Promise.resolve(newData);
|
|
1234
|
+
},
|
|
1235
|
+
},
|
|
1236
|
+
});
|
|
1237
|
+
expect(result).toBe(true);
|
|
1238
|
+
});
|
|
1239
|
+
test("Should persist data when key exist", async () => {
|
|
1240
|
+
const key = "a";
|
|
1241
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1242
|
+
const file = fileStorage.create(key);
|
|
1243
|
+
await file.add({ data });
|
|
1244
|
+
const newData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1245
|
+
await file.putStream({
|
|
1246
|
+
data: {
|
|
1247
|
+
async *[Symbol.asyncIterator]() {
|
|
1248
|
+
yield Promise.resolve(newData);
|
|
1249
|
+
},
|
|
1250
|
+
},
|
|
1251
|
+
});
|
|
1252
|
+
const result = await file.getBytes();
|
|
1253
|
+
expect(result).toEqual(newData);
|
|
1254
|
+
});
|
|
1255
|
+
});
|
|
1256
|
+
describe("method: remove", () => {
|
|
1257
|
+
test("Should return false when key doesnt exist", async () => {
|
|
1258
|
+
const key = "a";
|
|
1259
|
+
const result = await fileStorage.create(key).remove();
|
|
1260
|
+
expect(result).toBe(false);
|
|
1261
|
+
});
|
|
1262
|
+
test("Should return true when key exist", async () => {
|
|
1263
|
+
const key = "a";
|
|
1264
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1265
|
+
const file = fileStorage.create(key);
|
|
1266
|
+
await file.add({ data });
|
|
1267
|
+
const result = await file.remove();
|
|
1268
|
+
expect(result).toBe(true);
|
|
1269
|
+
});
|
|
1270
|
+
test("Should persit removal when key exist", async () => {
|
|
1271
|
+
const key = "a";
|
|
1272
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1273
|
+
const file = fileStorage.create(key);
|
|
1274
|
+
await file.add({ data });
|
|
1275
|
+
await file.remove();
|
|
1276
|
+
const result = await file.getBytes();
|
|
1277
|
+
expect(result).toBeNull();
|
|
1278
|
+
});
|
|
1279
|
+
});
|
|
1280
|
+
describe("method: removeOrFail", () => {
|
|
1281
|
+
test("Should throw KeyNotFoundFileError when key doesnt exist", async () => {
|
|
1282
|
+
const key = "a";
|
|
1283
|
+
const result = fileStorage.create(key).removeOrFail();
|
|
1284
|
+
await expect(result).rejects.toBeInstanceOf(KeyNotFoundFileError);
|
|
1285
|
+
});
|
|
1286
|
+
test("Should not throw error when key exist", async () => {
|
|
1287
|
+
const key = "a";
|
|
1288
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1289
|
+
const file = fileStorage.create(key);
|
|
1290
|
+
await file.add({ data });
|
|
1291
|
+
const result = file.removeOrFail();
|
|
1292
|
+
await expect(result).resolves.toBeUndefined();
|
|
1293
|
+
});
|
|
1294
|
+
test("Should persit removal when key exist", async () => {
|
|
1295
|
+
const key = "a";
|
|
1296
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1297
|
+
const file = fileStorage.create(key);
|
|
1298
|
+
await file.add({ data });
|
|
1299
|
+
await file.removeOrFail();
|
|
1300
|
+
const result = await file.getBytes();
|
|
1301
|
+
expect(result).toBeNull();
|
|
1302
|
+
});
|
|
1303
|
+
});
|
|
1304
|
+
describe("method: copy", () => {
|
|
1305
|
+
test("Should return false when source does not exists and destination does not exists", async () => {
|
|
1306
|
+
const noneExistingSource = "a";
|
|
1307
|
+
const noneExistingDestination = "c";
|
|
1308
|
+
const result = await fileStorage
|
|
1309
|
+
.create(noneExistingSource)
|
|
1310
|
+
.copy(noneExistingDestination);
|
|
1311
|
+
expect(result).toBe(false);
|
|
1312
|
+
});
|
|
1313
|
+
test("Should return false when source does not exists and destination exists", async () => {
|
|
1314
|
+
const noneExistingSource = "a";
|
|
1315
|
+
const destination = "c";
|
|
1316
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1317
|
+
await fileStorage.create(destination).add({
|
|
1318
|
+
data,
|
|
1319
|
+
});
|
|
1320
|
+
const result = await fileStorage
|
|
1321
|
+
.create(noneExistingSource)
|
|
1322
|
+
.copy(destination);
|
|
1323
|
+
expect(result).toBe(false);
|
|
1324
|
+
});
|
|
1325
|
+
test("Should return false when source exists and destination exists", async () => {
|
|
1326
|
+
const source = "a";
|
|
1327
|
+
const sourceData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1328
|
+
const sourceFile = fileStorage.create(source);
|
|
1329
|
+
await sourceFile.add({
|
|
1330
|
+
data: sourceData,
|
|
1331
|
+
});
|
|
1332
|
+
const destination = "c";
|
|
1333
|
+
const destinationData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1334
|
+
await fileStorage.create(destination).add({
|
|
1335
|
+
data: destinationData,
|
|
1336
|
+
});
|
|
1337
|
+
const result = await sourceFile.copy(destination);
|
|
1338
|
+
expect(result).toBe(false);
|
|
1339
|
+
});
|
|
1340
|
+
test("Should not persist when source exists and destination exists", async () => {
|
|
1341
|
+
const source = "a";
|
|
1342
|
+
const sourceData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1343
|
+
const sourceFile = fileStorage.create(source);
|
|
1344
|
+
await sourceFile.add({
|
|
1345
|
+
data: sourceData,
|
|
1346
|
+
});
|
|
1347
|
+
const destination = "c";
|
|
1348
|
+
const destinationData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1349
|
+
const destinationFile = fileStorage.create(destination);
|
|
1350
|
+
await destinationFile.add({
|
|
1351
|
+
data: destinationData,
|
|
1352
|
+
});
|
|
1353
|
+
await sourceFile.copy(destination);
|
|
1354
|
+
const result = await destinationFile.getBytes();
|
|
1355
|
+
expect(result).toEqual(destinationData);
|
|
1356
|
+
});
|
|
1357
|
+
test("Should return true when source exists and destination does not exists", async () => {
|
|
1358
|
+
const source = "a";
|
|
1359
|
+
const sourceData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1360
|
+
const sourceFile = fileStorage.create(source);
|
|
1361
|
+
await sourceFile.add({
|
|
1362
|
+
data: sourceData,
|
|
1363
|
+
});
|
|
1364
|
+
const destination = "c";
|
|
1365
|
+
const result = await sourceFile.copy(destination);
|
|
1366
|
+
expect(result).toBe(true);
|
|
1367
|
+
});
|
|
1368
|
+
test("Should persist data when source exists and destination does not exists", async () => {
|
|
1369
|
+
const source = "a";
|
|
1370
|
+
const sourceData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1371
|
+
const sourceFile = fileStorage.create(source);
|
|
1372
|
+
await sourceFile.add({
|
|
1373
|
+
data: sourceData,
|
|
1374
|
+
});
|
|
1375
|
+
const destination = "c";
|
|
1376
|
+
await sourceFile.copy(destination);
|
|
1377
|
+
const result = await fileStorage
|
|
1378
|
+
.create(destination)
|
|
1379
|
+
.getBytes();
|
|
1380
|
+
expect(result).toEqual(sourceData);
|
|
1381
|
+
});
|
|
1382
|
+
});
|
|
1383
|
+
describe("method: copyOrFail", () => {
|
|
1384
|
+
test("Should throw KeyNotFoundFileError when source does not exists and destination does not exists", async () => {
|
|
1385
|
+
const noneExistingSource = "a";
|
|
1386
|
+
const noneExistingDestination = "c";
|
|
1387
|
+
const result = fileStorage
|
|
1388
|
+
.create(noneExistingSource)
|
|
1389
|
+
.copyOrFail(noneExistingDestination);
|
|
1390
|
+
await expect(result).rejects.toBeInstanceOf(KeyNotFoundFileError);
|
|
1391
|
+
});
|
|
1392
|
+
test("Should throw KeyNotFoundFileError when source does not exists and destination exists", async () => {
|
|
1393
|
+
const noneExistingSource = "a";
|
|
1394
|
+
const destination = "c";
|
|
1395
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1396
|
+
await fileStorage.create(destination).add({
|
|
1397
|
+
data,
|
|
1398
|
+
});
|
|
1399
|
+
const result = fileStorage
|
|
1400
|
+
.create(noneExistingSource)
|
|
1401
|
+
.copyOrFail(destination);
|
|
1402
|
+
await expect(result).rejects.toBeInstanceOf(KeyNotFoundFileError);
|
|
1403
|
+
});
|
|
1404
|
+
test("Should throw KeyExistsFileError when source exists and destination exists", async () => {
|
|
1405
|
+
const source = "a";
|
|
1406
|
+
const sourceData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1407
|
+
const sourceFile = fileStorage.create(source);
|
|
1408
|
+
await sourceFile.add({
|
|
1409
|
+
data: sourceData,
|
|
1410
|
+
});
|
|
1411
|
+
const destination = "c";
|
|
1412
|
+
const destinationData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1413
|
+
await fileStorage.create(destination).add({
|
|
1414
|
+
data: destinationData,
|
|
1415
|
+
});
|
|
1416
|
+
const result = sourceFile.copyOrFail(destination);
|
|
1417
|
+
await expect(result).rejects.toBeInstanceOf(KeyExistsFileError);
|
|
1418
|
+
});
|
|
1419
|
+
test("Should not persist when source exists and destination exists", async () => {
|
|
1420
|
+
const source = "a";
|
|
1421
|
+
const sourceData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1422
|
+
const sourceFile = fileStorage.create(source);
|
|
1423
|
+
await sourceFile.add({
|
|
1424
|
+
data: sourceData,
|
|
1425
|
+
});
|
|
1426
|
+
const destination = "c";
|
|
1427
|
+
const destinationData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1428
|
+
const destinationFile = fileStorage.create(destination);
|
|
1429
|
+
await destinationFile.add({
|
|
1430
|
+
data: destinationData,
|
|
1431
|
+
});
|
|
1432
|
+
try {
|
|
1433
|
+
await sourceFile.copyOrFail(destination);
|
|
1434
|
+
}
|
|
1435
|
+
catch {
|
|
1436
|
+
/* EMPTY */
|
|
1437
|
+
}
|
|
1438
|
+
const result = await destinationFile.getBytes();
|
|
1439
|
+
expect(result).toEqual(destinationData);
|
|
1440
|
+
});
|
|
1441
|
+
test("Should not throw error when source exists and destination does not exists", async () => {
|
|
1442
|
+
const source = "a";
|
|
1443
|
+
const sourceData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1444
|
+
const sourceFile = fileStorage.create(source);
|
|
1445
|
+
await sourceFile.add({
|
|
1446
|
+
data: sourceData,
|
|
1447
|
+
});
|
|
1448
|
+
const destination = "c";
|
|
1449
|
+
const result = sourceFile.copyOrFail(destination);
|
|
1450
|
+
await expect(result).resolves.toBeUndefined();
|
|
1451
|
+
});
|
|
1452
|
+
test("Should persist data when source exists and destination does not exists", async () => {
|
|
1453
|
+
const source = "a";
|
|
1454
|
+
const sourceData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1455
|
+
const sourceFile = fileStorage.create(source);
|
|
1456
|
+
await sourceFile.add({
|
|
1457
|
+
data: sourceData,
|
|
1458
|
+
});
|
|
1459
|
+
const destination = "c";
|
|
1460
|
+
await sourceFile.copyOrFail(destination);
|
|
1461
|
+
const result = await fileStorage
|
|
1462
|
+
.create(destination)
|
|
1463
|
+
.getBytes();
|
|
1464
|
+
expect(result).toEqual(sourceData);
|
|
1465
|
+
});
|
|
1466
|
+
});
|
|
1467
|
+
describe("method: copyAndReplace", () => {
|
|
1468
|
+
test("Should return false when source does not exists and destination does not exists", async () => {
|
|
1469
|
+
const noneExistingSource = "a";
|
|
1470
|
+
const noneExistingDestination = "c";
|
|
1471
|
+
const result = await fileStorage
|
|
1472
|
+
.create(noneExistingSource)
|
|
1473
|
+
.copyAndReplace(noneExistingDestination);
|
|
1474
|
+
expect(result).toBe(false);
|
|
1475
|
+
});
|
|
1476
|
+
test("Should return false when source does not exists and destination exists", async () => {
|
|
1477
|
+
const noneExistingSource = "a";
|
|
1478
|
+
const destination = "c";
|
|
1479
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1480
|
+
await fileStorage.create(destination).add({
|
|
1481
|
+
data,
|
|
1482
|
+
});
|
|
1483
|
+
const result = await fileStorage
|
|
1484
|
+
.create(noneExistingSource)
|
|
1485
|
+
.copyAndReplace(destination);
|
|
1486
|
+
expect(result).toBe(false);
|
|
1487
|
+
});
|
|
1488
|
+
test("Should return true when source exists and destination exists", async () => {
|
|
1489
|
+
const source = "a";
|
|
1490
|
+
const sourceData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1491
|
+
const sourceFile = fileStorage.create(source);
|
|
1492
|
+
await sourceFile.add({
|
|
1493
|
+
data: sourceData,
|
|
1494
|
+
});
|
|
1495
|
+
const destination = "c";
|
|
1496
|
+
const destinationData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1497
|
+
await fileStorage.create(destination).add({
|
|
1498
|
+
data: destinationData,
|
|
1499
|
+
});
|
|
1500
|
+
const result = await sourceFile.copyAndReplace(destination);
|
|
1501
|
+
expect(result).toBe(true);
|
|
1502
|
+
});
|
|
1503
|
+
test("Should persist when source exists and destination exists", async () => {
|
|
1504
|
+
const source = "a";
|
|
1505
|
+
const sourceData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1506
|
+
const sourceFile = fileStorage.create(source);
|
|
1507
|
+
await sourceFile.add({
|
|
1508
|
+
data: sourceData,
|
|
1509
|
+
});
|
|
1510
|
+
const destination = "c";
|
|
1511
|
+
const destinationData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1512
|
+
const destinationFile = fileStorage.create(destination);
|
|
1513
|
+
await destinationFile.add({
|
|
1514
|
+
data: destinationData,
|
|
1515
|
+
});
|
|
1516
|
+
await sourceFile.copyAndReplace(destination);
|
|
1517
|
+
const result = await destinationFile.getBytes();
|
|
1518
|
+
expect(result).toEqual(sourceData);
|
|
1519
|
+
});
|
|
1520
|
+
test("Should return true when source exists and destination does not exists", async () => {
|
|
1521
|
+
const source = "a";
|
|
1522
|
+
const sourceData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1523
|
+
const sourceFile = fileStorage.create(source);
|
|
1524
|
+
await sourceFile.add({
|
|
1525
|
+
data: sourceData,
|
|
1526
|
+
});
|
|
1527
|
+
const destination = "c";
|
|
1528
|
+
const result = await sourceFile.copyAndReplace(destination);
|
|
1529
|
+
expect(result).toBe(true);
|
|
1530
|
+
});
|
|
1531
|
+
test("Should persist data when source exists and destination does not exists", async () => {
|
|
1532
|
+
const source = "a";
|
|
1533
|
+
const sourceData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1534
|
+
const sourceFile = fileStorage.create(source);
|
|
1535
|
+
await sourceFile.add({
|
|
1536
|
+
data: sourceData,
|
|
1537
|
+
});
|
|
1538
|
+
const destination = "c";
|
|
1539
|
+
await sourceFile.copyAndReplace(destination);
|
|
1540
|
+
const result = await fileStorage
|
|
1541
|
+
.create(destination)
|
|
1542
|
+
.getBytes();
|
|
1543
|
+
expect(result).toEqual(sourceData);
|
|
1544
|
+
});
|
|
1545
|
+
});
|
|
1546
|
+
describe("method: copyAndReplaceOrFail", () => {
|
|
1547
|
+
test("Should throw KeyNotFoundFileError when source does not exists and destination does not exists", async () => {
|
|
1548
|
+
const noneExistingSource = "a";
|
|
1549
|
+
const noneExistingDestination = "c";
|
|
1550
|
+
const result = fileStorage
|
|
1551
|
+
.create(noneExistingSource)
|
|
1552
|
+
.copyAndReplaceOrFail(noneExistingDestination);
|
|
1553
|
+
await expect(result).rejects.toBeInstanceOf(KeyNotFoundFileError);
|
|
1554
|
+
});
|
|
1555
|
+
test("Should throw KeyNotFoundFileError when source does not exists and destination exists", async () => {
|
|
1556
|
+
const noneExistingSource = "a";
|
|
1557
|
+
const destination = "c";
|
|
1558
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1559
|
+
await fileStorage.create(destination).add({
|
|
1560
|
+
data,
|
|
1561
|
+
});
|
|
1562
|
+
const result = fileStorage
|
|
1563
|
+
.create(noneExistingSource)
|
|
1564
|
+
.copyAndReplaceOrFail(destination);
|
|
1565
|
+
await expect(result).rejects.toBeInstanceOf(KeyNotFoundFileError);
|
|
1566
|
+
});
|
|
1567
|
+
test("Should not throw error when source exists and destination exists", async () => {
|
|
1568
|
+
const source = "a";
|
|
1569
|
+
const sourceData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1570
|
+
const sourceFile = fileStorage.create(source);
|
|
1571
|
+
await sourceFile.add({
|
|
1572
|
+
data: sourceData,
|
|
1573
|
+
});
|
|
1574
|
+
const destination = "c";
|
|
1575
|
+
const destinationData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1576
|
+
await fileStorage.create(destination).add({
|
|
1577
|
+
data: destinationData,
|
|
1578
|
+
});
|
|
1579
|
+
const result = sourceFile.copyAndReplaceOrFail(destination);
|
|
1580
|
+
await expect(result).resolves.toBeUndefined();
|
|
1581
|
+
});
|
|
1582
|
+
test("Should persist when source exists and destination exists", async () => {
|
|
1583
|
+
const source = "a";
|
|
1584
|
+
const sourceData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1585
|
+
const sourceFile = fileStorage.create(source);
|
|
1586
|
+
await sourceFile.add({
|
|
1587
|
+
data: sourceData,
|
|
1588
|
+
});
|
|
1589
|
+
const destination = "c";
|
|
1590
|
+
const destinationData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1591
|
+
const destinationFile = fileStorage.create(destination);
|
|
1592
|
+
await destinationFile.add({
|
|
1593
|
+
data: destinationData,
|
|
1594
|
+
});
|
|
1595
|
+
await sourceFile.copyAndReplaceOrFail(destination);
|
|
1596
|
+
const result = await destinationFile.getBytes();
|
|
1597
|
+
expect(result).toEqual(sourceData);
|
|
1598
|
+
});
|
|
1599
|
+
test("Should not throw error when source exists and destination does not exists", async () => {
|
|
1600
|
+
const source = "a";
|
|
1601
|
+
const sourceData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1602
|
+
const sourceFile = fileStorage.create(source);
|
|
1603
|
+
await sourceFile.add({
|
|
1604
|
+
data: sourceData,
|
|
1605
|
+
});
|
|
1606
|
+
const destination = "c";
|
|
1607
|
+
const result = sourceFile.copyAndReplaceOrFail(destination);
|
|
1608
|
+
await expect(result).resolves.toBeUndefined();
|
|
1609
|
+
});
|
|
1610
|
+
test("Should persist data when source exists and destination does not exists", async () => {
|
|
1611
|
+
const source = "a";
|
|
1612
|
+
const sourceData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1613
|
+
const sourceFile = fileStorage.create(source);
|
|
1614
|
+
await sourceFile.add({
|
|
1615
|
+
data: sourceData,
|
|
1616
|
+
});
|
|
1617
|
+
const destination = "c";
|
|
1618
|
+
await sourceFile.copyAndReplaceOrFail(destination);
|
|
1619
|
+
const result = await fileStorage
|
|
1620
|
+
.create(destination)
|
|
1621
|
+
.getBytes();
|
|
1622
|
+
expect(result).toEqual(sourceData);
|
|
1623
|
+
});
|
|
1624
|
+
});
|
|
1625
|
+
describe("method: move", () => {
|
|
1626
|
+
test("Should return false when source does not exists and destination does not exists", async () => {
|
|
1627
|
+
const noneExistingSource = "a";
|
|
1628
|
+
const noneExistingDestination = "c";
|
|
1629
|
+
const result = await fileStorage
|
|
1630
|
+
.create(noneExistingSource)
|
|
1631
|
+
.move(noneExistingDestination);
|
|
1632
|
+
expect(result).toBe(false);
|
|
1633
|
+
});
|
|
1634
|
+
test("Should return false when source does not exists and destination exists", async () => {
|
|
1635
|
+
const noneExistingSource = "a";
|
|
1636
|
+
const destination = "c";
|
|
1637
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1638
|
+
await fileStorage.create(destination).add({
|
|
1639
|
+
data,
|
|
1640
|
+
});
|
|
1641
|
+
const result = await fileStorage
|
|
1642
|
+
.create(noneExistingSource)
|
|
1643
|
+
.move(destination);
|
|
1644
|
+
expect(result).toBe(false);
|
|
1645
|
+
});
|
|
1646
|
+
test("Should return false when source exists and destination exists", async () => {
|
|
1647
|
+
const source = "a";
|
|
1648
|
+
const sourceData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1649
|
+
const sourceFile = fileStorage.create(source);
|
|
1650
|
+
await sourceFile.add({
|
|
1651
|
+
data: sourceData,
|
|
1652
|
+
});
|
|
1653
|
+
const destination = "c";
|
|
1654
|
+
const destinationData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1655
|
+
await fileStorage.create(destination).add({
|
|
1656
|
+
data: destinationData,
|
|
1657
|
+
});
|
|
1658
|
+
const result = await sourceFile.move(destination);
|
|
1659
|
+
expect(result).toBe(false);
|
|
1660
|
+
});
|
|
1661
|
+
test("Should not persist when source exists and destination exists", async () => {
|
|
1662
|
+
const source = "a";
|
|
1663
|
+
const sourceData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1664
|
+
const sourceFile = fileStorage.create(source);
|
|
1665
|
+
await sourceFile.add({
|
|
1666
|
+
data: sourceData,
|
|
1667
|
+
});
|
|
1668
|
+
const destination = "c";
|
|
1669
|
+
const destinationData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1670
|
+
const destinationFile = fileStorage.create(destination);
|
|
1671
|
+
await destinationFile.add({
|
|
1672
|
+
data: destinationData,
|
|
1673
|
+
});
|
|
1674
|
+
await sourceFile.move(destination);
|
|
1675
|
+
const result = await destinationFile.getBytes();
|
|
1676
|
+
expect(result).toEqual(destinationData);
|
|
1677
|
+
});
|
|
1678
|
+
test("Should return true when source exists and destination does not exists", async () => {
|
|
1679
|
+
const source = "a";
|
|
1680
|
+
const sourceData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1681
|
+
const sourceFile = fileStorage.create(source);
|
|
1682
|
+
await sourceFile.add({
|
|
1683
|
+
data: sourceData,
|
|
1684
|
+
});
|
|
1685
|
+
const destination = "c";
|
|
1686
|
+
const result = await sourceFile.move(destination);
|
|
1687
|
+
expect(result).toBe(true);
|
|
1688
|
+
});
|
|
1689
|
+
test("Should persist data when source exists and destination does not exists", async () => {
|
|
1690
|
+
const source = "a";
|
|
1691
|
+
const sourceData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1692
|
+
const sourceFile = fileStorage.create(source);
|
|
1693
|
+
await sourceFile.add({
|
|
1694
|
+
data: sourceData,
|
|
1695
|
+
});
|
|
1696
|
+
const destination = "c";
|
|
1697
|
+
await sourceFile.move(destination);
|
|
1698
|
+
const result = await fileStorage
|
|
1699
|
+
.create(destination)
|
|
1700
|
+
.getBytes();
|
|
1701
|
+
expect(result).toEqual(sourceData);
|
|
1702
|
+
});
|
|
1703
|
+
test("Should remove source when source exists and destination does not exists", async () => {
|
|
1704
|
+
const source = "a";
|
|
1705
|
+
const sourceData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1706
|
+
const souceFile = fileStorage.create(source);
|
|
1707
|
+
await souceFile.add({
|
|
1708
|
+
data: sourceData,
|
|
1709
|
+
});
|
|
1710
|
+
const destination = "c";
|
|
1711
|
+
await souceFile.move(destination);
|
|
1712
|
+
const result = await souceFile.getBytes();
|
|
1713
|
+
expect(result).toBeNull();
|
|
1714
|
+
});
|
|
1715
|
+
});
|
|
1716
|
+
describe("method: moveOrFail", () => {
|
|
1717
|
+
test("Should throw KeyNotFoundFileError when source does not exists and destination does not exists", async () => {
|
|
1718
|
+
const noneExistingSource = "a";
|
|
1719
|
+
const noneExistingDestination = "c";
|
|
1720
|
+
const result = fileStorage
|
|
1721
|
+
.create(noneExistingSource)
|
|
1722
|
+
.moveOrFail(noneExistingDestination);
|
|
1723
|
+
await expect(result).rejects.toBeInstanceOf(KeyNotFoundFileError);
|
|
1724
|
+
});
|
|
1725
|
+
test("Should throw KeyNotFoundFileError when source does not exists and destination exists", async () => {
|
|
1726
|
+
const noneExistingSource = "a";
|
|
1727
|
+
const destination = "c";
|
|
1728
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1729
|
+
await fileStorage.create(destination).add({
|
|
1730
|
+
data,
|
|
1731
|
+
});
|
|
1732
|
+
const result = fileStorage
|
|
1733
|
+
.create(noneExistingSource)
|
|
1734
|
+
.moveOrFail(destination);
|
|
1735
|
+
await expect(result).rejects.toBeInstanceOf(KeyNotFoundFileError);
|
|
1736
|
+
});
|
|
1737
|
+
test("Should throw KeyExistsFileError when source exists and destination exists", async () => {
|
|
1738
|
+
const source = "a";
|
|
1739
|
+
const sourceData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1740
|
+
const sourceFile = fileStorage.create(source);
|
|
1741
|
+
await sourceFile.add({
|
|
1742
|
+
data: sourceData,
|
|
1743
|
+
});
|
|
1744
|
+
const destination = "c";
|
|
1745
|
+
const destinationData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1746
|
+
await fileStorage.create(destination).add({
|
|
1747
|
+
data: destinationData,
|
|
1748
|
+
});
|
|
1749
|
+
const result = sourceFile.moveOrFail(destination);
|
|
1750
|
+
await expect(result).rejects.toBeInstanceOf(KeyExistsFileError);
|
|
1751
|
+
});
|
|
1752
|
+
test("Should not persist when source exists and destination exists", async () => {
|
|
1753
|
+
const source = "a";
|
|
1754
|
+
const sourceData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1755
|
+
const sourceFile = fileStorage.create(source);
|
|
1756
|
+
await sourceFile.add({
|
|
1757
|
+
data: sourceData,
|
|
1758
|
+
});
|
|
1759
|
+
const destination = "c";
|
|
1760
|
+
const destinationData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1761
|
+
const destinationFile = fileStorage.create(destination);
|
|
1762
|
+
await destinationFile.add({
|
|
1763
|
+
data: destinationData,
|
|
1764
|
+
});
|
|
1765
|
+
try {
|
|
1766
|
+
await sourceFile.moveOrFail(destination);
|
|
1767
|
+
}
|
|
1768
|
+
catch {
|
|
1769
|
+
/* EMPTY */
|
|
1770
|
+
}
|
|
1771
|
+
const result = await destinationFile.getBytes();
|
|
1772
|
+
expect(result).toEqual(destinationData);
|
|
1773
|
+
});
|
|
1774
|
+
test("Should not throw error when source exists and destination does not exists", async () => {
|
|
1775
|
+
const source = "a";
|
|
1776
|
+
const sourceData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1777
|
+
const sourceFile = fileStorage.create(source);
|
|
1778
|
+
await sourceFile.add({
|
|
1779
|
+
data: sourceData,
|
|
1780
|
+
});
|
|
1781
|
+
const destination = "c";
|
|
1782
|
+
const result = sourceFile.moveOrFail(destination);
|
|
1783
|
+
await expect(result).resolves.toBeUndefined();
|
|
1784
|
+
});
|
|
1785
|
+
test("Should persist data when source exists and destination does not exists", async () => {
|
|
1786
|
+
const source = "a";
|
|
1787
|
+
const sourceData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1788
|
+
const sourceFile = fileStorage.create(source);
|
|
1789
|
+
await sourceFile.add({
|
|
1790
|
+
data: sourceData,
|
|
1791
|
+
});
|
|
1792
|
+
const destination = "c";
|
|
1793
|
+
await sourceFile.moveOrFail(destination);
|
|
1794
|
+
const result = await fileStorage
|
|
1795
|
+
.create(destination)
|
|
1796
|
+
.getBytes();
|
|
1797
|
+
expect(result).toEqual(sourceData);
|
|
1798
|
+
});
|
|
1799
|
+
test("Should remove source when source exists and destination does not exists", async () => {
|
|
1800
|
+
const source = "a";
|
|
1801
|
+
const sourceData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1802
|
+
const sourceFile = fileStorage.create(source);
|
|
1803
|
+
await sourceFile.add({
|
|
1804
|
+
data: sourceData,
|
|
1805
|
+
});
|
|
1806
|
+
const destination = "c";
|
|
1807
|
+
await sourceFile.moveOrFail(destination);
|
|
1808
|
+
const result = await sourceFile.getBytes();
|
|
1809
|
+
expect(result).toBeNull();
|
|
1810
|
+
});
|
|
1811
|
+
});
|
|
1812
|
+
describe("method: moveAndReplace", () => {
|
|
1813
|
+
test("Should return false when source does not exists and destination does not exists", async () => {
|
|
1814
|
+
const noneExistingSource = "a";
|
|
1815
|
+
const noneExistingDestination = "c";
|
|
1816
|
+
const result = await fileStorage
|
|
1817
|
+
.create(noneExistingSource)
|
|
1818
|
+
.moveAndReplace(noneExistingDestination);
|
|
1819
|
+
expect(result).toBe(false);
|
|
1820
|
+
});
|
|
1821
|
+
test("Should return false when source does not exists and destination exists", async () => {
|
|
1822
|
+
const noneExistingSource = "a";
|
|
1823
|
+
const destination = "c";
|
|
1824
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1825
|
+
await fileStorage.create(destination).add({
|
|
1826
|
+
data,
|
|
1827
|
+
});
|
|
1828
|
+
const result = await fileStorage
|
|
1829
|
+
.create(noneExistingSource)
|
|
1830
|
+
.moveAndReplace(destination);
|
|
1831
|
+
expect(result).toBe(false);
|
|
1832
|
+
});
|
|
1833
|
+
test("Should return true when source exists and destination exists", async () => {
|
|
1834
|
+
const source = "a";
|
|
1835
|
+
const sourceData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1836
|
+
const sourceFile = fileStorage.create(source);
|
|
1837
|
+
await sourceFile.add({
|
|
1838
|
+
data: sourceData,
|
|
1839
|
+
});
|
|
1840
|
+
const destination = "c";
|
|
1841
|
+
const destinationData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1842
|
+
await fileStorage.create(destination).add({
|
|
1843
|
+
data: destinationData,
|
|
1844
|
+
});
|
|
1845
|
+
const result = await sourceFile.moveAndReplace(destination);
|
|
1846
|
+
expect(result).toBe(true);
|
|
1847
|
+
});
|
|
1848
|
+
test("Should persist when source exists and destination exists", async () => {
|
|
1849
|
+
const source = "a";
|
|
1850
|
+
const sourceData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1851
|
+
const sourceFile = fileStorage.create(source);
|
|
1852
|
+
await sourceFile.add({
|
|
1853
|
+
data: sourceData,
|
|
1854
|
+
});
|
|
1855
|
+
const destination = "c";
|
|
1856
|
+
const destinationData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1857
|
+
const destinationFile = fileStorage.create(destination);
|
|
1858
|
+
await destinationFile.add({
|
|
1859
|
+
data: destinationData,
|
|
1860
|
+
});
|
|
1861
|
+
await sourceFile.moveAndReplace(destination);
|
|
1862
|
+
const result = await destinationFile.getBytes();
|
|
1863
|
+
expect(result).toEqual(sourceData);
|
|
1864
|
+
});
|
|
1865
|
+
test("Should return true when source exists and destination does not exists", async () => {
|
|
1866
|
+
const source = "a";
|
|
1867
|
+
const sourceData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1868
|
+
const sourceFile = fileStorage.create(source);
|
|
1869
|
+
await sourceFile.add({
|
|
1870
|
+
data: sourceData,
|
|
1871
|
+
});
|
|
1872
|
+
const destination = "c";
|
|
1873
|
+
const result = await sourceFile.moveAndReplace(destination);
|
|
1874
|
+
expect(result).toBe(true);
|
|
1875
|
+
});
|
|
1876
|
+
test("Should persist data when source exists and destination does not exists", async () => {
|
|
1877
|
+
const source = "a";
|
|
1878
|
+
const sourceData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1879
|
+
const sourceFile = fileStorage.create(source);
|
|
1880
|
+
await sourceFile.add({
|
|
1881
|
+
data: sourceData,
|
|
1882
|
+
});
|
|
1883
|
+
const destination = "c";
|
|
1884
|
+
await sourceFile.moveAndReplace(destination);
|
|
1885
|
+
const result = await fileStorage
|
|
1886
|
+
.create(destination)
|
|
1887
|
+
.getBytes();
|
|
1888
|
+
expect(result).toEqual(sourceData);
|
|
1889
|
+
});
|
|
1890
|
+
test("Should remove source when source exists and destination does not exists", async () => {
|
|
1891
|
+
const source = "a";
|
|
1892
|
+
const sourceData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1893
|
+
const sourceFile = fileStorage.create(source);
|
|
1894
|
+
await sourceFile.add({
|
|
1895
|
+
data: sourceData,
|
|
1896
|
+
});
|
|
1897
|
+
const destination = "c";
|
|
1898
|
+
await sourceFile.moveAndReplace(destination);
|
|
1899
|
+
const result = await sourceFile.getBytes();
|
|
1900
|
+
expect(result).toBeNull();
|
|
1901
|
+
});
|
|
1902
|
+
});
|
|
1903
|
+
describe("method: moveAndReplaceOrFail", () => {
|
|
1904
|
+
test("Should throw KeyNotFoundFileError when source does not exists and destination does not exists", async () => {
|
|
1905
|
+
const noneExistingSource = "a";
|
|
1906
|
+
const noneExistingDestination = "c";
|
|
1907
|
+
const result = fileStorage
|
|
1908
|
+
.create(noneExistingSource)
|
|
1909
|
+
.moveAndReplaceOrFail(noneExistingDestination);
|
|
1910
|
+
await expect(result).rejects.toBeInstanceOf(KeyNotFoundFileError);
|
|
1911
|
+
});
|
|
1912
|
+
test("Should throw KeyNotFoundFileError when source does not exists and destination exists", async () => {
|
|
1913
|
+
const noneExistingSource = "a";
|
|
1914
|
+
const destination = "c";
|
|
1915
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1916
|
+
await fileStorage.create(destination).add({
|
|
1917
|
+
data,
|
|
1918
|
+
});
|
|
1919
|
+
const result = fileStorage
|
|
1920
|
+
.create(noneExistingSource)
|
|
1921
|
+
.moveAndReplaceOrFail(destination);
|
|
1922
|
+
await expect(result).rejects.toBeInstanceOf(KeyNotFoundFileError);
|
|
1923
|
+
});
|
|
1924
|
+
test("Should not throw error when source exists and destination exists", async () => {
|
|
1925
|
+
const source = "a";
|
|
1926
|
+
const sourceData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1927
|
+
const sourceFile = fileStorage.create(source);
|
|
1928
|
+
await sourceFile.add({
|
|
1929
|
+
data: sourceData,
|
|
1930
|
+
});
|
|
1931
|
+
const destination = "c";
|
|
1932
|
+
const destinationData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1933
|
+
await fileStorage.create(destination).add({
|
|
1934
|
+
data: destinationData,
|
|
1935
|
+
});
|
|
1936
|
+
const result = sourceFile.moveAndReplaceOrFail(destination);
|
|
1937
|
+
await expect(result).resolves.toBeUndefined();
|
|
1938
|
+
});
|
|
1939
|
+
test("Should persist when source exists and destination exists", async () => {
|
|
1940
|
+
const source = "a";
|
|
1941
|
+
const sourceData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1942
|
+
const sourceFile = fileStorage.create(source);
|
|
1943
|
+
await sourceFile.add({
|
|
1944
|
+
data: sourceData,
|
|
1945
|
+
});
|
|
1946
|
+
const destination = "c";
|
|
1947
|
+
const destinationData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1948
|
+
const destinationFile = fileStorage.create(destination);
|
|
1949
|
+
await destinationFile.add({
|
|
1950
|
+
data: destinationData,
|
|
1951
|
+
});
|
|
1952
|
+
await sourceFile.moveAndReplaceOrFail(destination);
|
|
1953
|
+
const result = await destinationFile.getBytes();
|
|
1954
|
+
expect(result).toEqual(sourceData);
|
|
1955
|
+
});
|
|
1956
|
+
test("Should not throw error when source exists and destination does not exists", async () => {
|
|
1957
|
+
const source = "a";
|
|
1958
|
+
const sourceData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1959
|
+
const sourceFile = fileStorage.create(source);
|
|
1960
|
+
await sourceFile.add({
|
|
1961
|
+
data: sourceData,
|
|
1962
|
+
});
|
|
1963
|
+
const destination = "c";
|
|
1964
|
+
const result = sourceFile.moveAndReplaceOrFail(destination);
|
|
1965
|
+
await expect(result).resolves.toBeUndefined();
|
|
1966
|
+
});
|
|
1967
|
+
test("Should persist data when source exists and destination does not exists", async () => {
|
|
1968
|
+
const source = "a";
|
|
1969
|
+
const sourceData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1970
|
+
const sourceFile = fileStorage.create(source);
|
|
1971
|
+
await sourceFile.add({
|
|
1972
|
+
data: sourceData,
|
|
1973
|
+
});
|
|
1974
|
+
const destination = "c";
|
|
1975
|
+
await sourceFile.moveAndReplaceOrFail(destination);
|
|
1976
|
+
const result = await fileStorage
|
|
1977
|
+
.create(destination)
|
|
1978
|
+
.getBytes();
|
|
1979
|
+
expect(result).toEqual(sourceData);
|
|
1980
|
+
});
|
|
1981
|
+
test("Should remove source when source exists and destination does not exists", async () => {
|
|
1982
|
+
const source = "a";
|
|
1983
|
+
const sourceData = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
1984
|
+
const sourceFile = fileStorage.create(source);
|
|
1985
|
+
await sourceFile.add({
|
|
1986
|
+
data: sourceData,
|
|
1987
|
+
});
|
|
1988
|
+
const destination = "c";
|
|
1989
|
+
await sourceFile.moveAndReplaceOrFail(destination);
|
|
1990
|
+
const result = await sourceFile.getBytes();
|
|
1991
|
+
expect(result).toBeNull();
|
|
1992
|
+
});
|
|
1993
|
+
});
|
|
1994
|
+
describe("method: removeMany", () => {
|
|
1995
|
+
test("Should return false when all keys does not exists", async () => {
|
|
1996
|
+
const result = await fileStorage.removeMany([
|
|
1997
|
+
fileStorage.create("a"),
|
|
1998
|
+
fileStorage.create("b"),
|
|
1999
|
+
fileStorage.create("c"),
|
|
2000
|
+
]);
|
|
2001
|
+
expect(result).toBe(false);
|
|
2002
|
+
});
|
|
2003
|
+
test("Should return true when one key exists", async () => {
|
|
2004
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
2005
|
+
const fileA = fileStorage.create("a");
|
|
2006
|
+
await fileA.add({
|
|
2007
|
+
data,
|
|
2008
|
+
});
|
|
2009
|
+
const fileB = fileStorage.create("b");
|
|
2010
|
+
const fileC = fileStorage.create("c");
|
|
2011
|
+
const result = await fileStorage.removeMany([
|
|
2012
|
+
fileA,
|
|
2013
|
+
fileB,
|
|
2014
|
+
fileC,
|
|
2015
|
+
]);
|
|
2016
|
+
expect(result).toBe(true);
|
|
2017
|
+
});
|
|
2018
|
+
test("Should persist removal of the keys that exists", async () => {
|
|
2019
|
+
const fileA = fileStorage.create("a");
|
|
2020
|
+
await fileA.add({
|
|
2021
|
+
data: new Uint8Array(Buffer.from("CONTENT_A", "utf8")),
|
|
2022
|
+
});
|
|
2023
|
+
const fileB = fileStorage.create("b");
|
|
2024
|
+
await fileB.add({
|
|
2025
|
+
data: new Uint8Array(Buffer.from("CONTENT_B", "utf8")),
|
|
2026
|
+
});
|
|
2027
|
+
const dataC = new Uint8Array(Buffer.from("CONTENT_C", "utf8"));
|
|
2028
|
+
const fileC = fileStorage.create("c");
|
|
2029
|
+
await fileC.add({
|
|
2030
|
+
data: dataC,
|
|
2031
|
+
});
|
|
2032
|
+
await fileStorage.removeMany([fileA, fileB]);
|
|
2033
|
+
const result = [
|
|
2034
|
+
await fileA.getBytes(),
|
|
2035
|
+
await fileB.getBytes(),
|
|
2036
|
+
await fileC.getBytes(),
|
|
2037
|
+
];
|
|
2038
|
+
expect(result).toEqual([null, null, dataC]);
|
|
2039
|
+
});
|
|
2040
|
+
});
|
|
2041
|
+
describe("method: clear", () => {
|
|
2042
|
+
test("Should remove all the keys", async () => {
|
|
2043
|
+
const fileA = fileStorage.create("a");
|
|
2044
|
+
await fileA.add({
|
|
2045
|
+
data: new Uint8Array(Buffer.from("CONTENT_A", "utf8")),
|
|
2046
|
+
});
|
|
2047
|
+
const fileB = fileStorage.create("b");
|
|
2048
|
+
await fileB.add({
|
|
2049
|
+
data: new Uint8Array(Buffer.from("CONTENT_B", "utf8")),
|
|
2050
|
+
});
|
|
2051
|
+
const fileC = fileStorage.create("c");
|
|
2052
|
+
await fileC.add({
|
|
2053
|
+
data: new Uint8Array(Buffer.from("CONTENT_c", "utf8")),
|
|
2054
|
+
});
|
|
2055
|
+
const fileD = fileStorage.create("d");
|
|
2056
|
+
await fileD.add({
|
|
2057
|
+
data: new Uint8Array(Buffer.from("CONTENT_d", "utf8")),
|
|
2058
|
+
});
|
|
2059
|
+
await fileStorage.clear();
|
|
2060
|
+
const results = [
|
|
2061
|
+
await fileA.getBytes(),
|
|
2062
|
+
await fileB.getBytes(),
|
|
2063
|
+
await fileC.getBytes(),
|
|
2064
|
+
await fileD.getBytes(),
|
|
2065
|
+
];
|
|
2066
|
+
expect(results).toEqual([null, null, null, null]);
|
|
2067
|
+
});
|
|
2068
|
+
});
|
|
2069
|
+
});
|
|
2070
|
+
describe.skipIf(excludeEventTests)("Event tests:", () => {
|
|
2071
|
+
describe("method: getText", () => {
|
|
2072
|
+
test("Should distpatch FoundFileEvent when key exists", async () => {
|
|
2073
|
+
const file = fileStorage.create("a");
|
|
2074
|
+
await file.add({
|
|
2075
|
+
data: new Uint8Array(Buffer.from("CONTENT", "utf8")),
|
|
2076
|
+
});
|
|
2077
|
+
const listener = vi.fn((_even) => { });
|
|
2078
|
+
await fileStorage.events.addListener(FILE_EVENTS.FOUND, listener);
|
|
2079
|
+
await file.getText();
|
|
2080
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2081
|
+
});
|
|
2082
|
+
test("Should distpatch NotFoundFileEvent when key does not exists", async () => {
|
|
2083
|
+
const file = fileStorage.create("a");
|
|
2084
|
+
const listener = vi.fn((_even) => { });
|
|
2085
|
+
await fileStorage.events.addListener(FILE_EVENTS.NOT_FOUND, listener);
|
|
2086
|
+
await file.getText();
|
|
2087
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2088
|
+
});
|
|
2089
|
+
});
|
|
2090
|
+
describe("method: getTextOrFail", () => {
|
|
2091
|
+
test("Should distpatch FoundFileEvent when key exists", async () => {
|
|
2092
|
+
const file = fileStorage.create("a");
|
|
2093
|
+
await file.add({
|
|
2094
|
+
data: new Uint8Array(Buffer.from("CONTENT", "utf8")),
|
|
2095
|
+
});
|
|
2096
|
+
const listener = vi.fn((_even) => { });
|
|
2097
|
+
await fileStorage.events.addListener(FILE_EVENTS.FOUND, listener);
|
|
2098
|
+
await file.getTextOrFail();
|
|
2099
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2100
|
+
});
|
|
2101
|
+
test("Should distpatch NotFoundFileEvent when key does not exists", async () => {
|
|
2102
|
+
const file = fileStorage.create("a");
|
|
2103
|
+
const listener = vi.fn((_even) => { });
|
|
2104
|
+
await fileStorage.events.addListener(FILE_EVENTS.NOT_FOUND, listener);
|
|
2105
|
+
try {
|
|
2106
|
+
await file.getTextOrFail();
|
|
2107
|
+
}
|
|
2108
|
+
catch {
|
|
2109
|
+
/* EMPTY */
|
|
2110
|
+
}
|
|
2111
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2112
|
+
});
|
|
2113
|
+
});
|
|
2114
|
+
describe("method: getBytes", () => {
|
|
2115
|
+
test("Should distpatch FoundFileEvent when key exists", async () => {
|
|
2116
|
+
const file = fileStorage.create("a");
|
|
2117
|
+
await file.add({
|
|
2118
|
+
data: new Uint8Array(Buffer.from("CONTENT", "utf8")),
|
|
2119
|
+
});
|
|
2120
|
+
const listener = vi.fn((_even) => { });
|
|
2121
|
+
await fileStorage.events.addListener(FILE_EVENTS.FOUND, listener);
|
|
2122
|
+
await file.getBytes();
|
|
2123
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2124
|
+
});
|
|
2125
|
+
test("Should distpatch NotFoundFileEvent when key does not exists", async () => {
|
|
2126
|
+
const file = fileStorage.create("a");
|
|
2127
|
+
const listener = vi.fn((_even) => { });
|
|
2128
|
+
await fileStorage.events.addListener(FILE_EVENTS.NOT_FOUND, listener);
|
|
2129
|
+
await file.getBytes();
|
|
2130
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2131
|
+
});
|
|
2132
|
+
});
|
|
2133
|
+
describe("method: getBytesOrFail", () => {
|
|
2134
|
+
test("Should distpatch FoundFileEvent when key exists", async () => {
|
|
2135
|
+
const file = fileStorage.create("a");
|
|
2136
|
+
await file.add({
|
|
2137
|
+
data: new Uint8Array(Buffer.from("CONTENT", "utf8")),
|
|
2138
|
+
});
|
|
2139
|
+
const listener = vi.fn((_even) => { });
|
|
2140
|
+
await fileStorage.events.addListener(FILE_EVENTS.FOUND, listener);
|
|
2141
|
+
await file.getBytesOrFail();
|
|
2142
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2143
|
+
});
|
|
2144
|
+
test("Should distpatch NotFoundFileEvent when key does not exists", async () => {
|
|
2145
|
+
const file = fileStorage.create("a");
|
|
2146
|
+
const listener = vi.fn((_even) => { });
|
|
2147
|
+
await fileStorage.events.addListener(FILE_EVENTS.NOT_FOUND, listener);
|
|
2148
|
+
try {
|
|
2149
|
+
await file.getBytesOrFail();
|
|
2150
|
+
}
|
|
2151
|
+
catch {
|
|
2152
|
+
/* EMPTY */
|
|
2153
|
+
}
|
|
2154
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2155
|
+
});
|
|
2156
|
+
});
|
|
2157
|
+
describe("method: getBuffer", () => {
|
|
2158
|
+
test("Should distpatch FoundFileEvent when key exists", async () => {
|
|
2159
|
+
const file = fileStorage.create("a");
|
|
2160
|
+
await file.add({
|
|
2161
|
+
data: new Uint8Array(Buffer.from("CONTENT", "utf8")),
|
|
2162
|
+
});
|
|
2163
|
+
const listener = vi.fn((_even) => { });
|
|
2164
|
+
await fileStorage.events.addListener(FILE_EVENTS.FOUND, listener);
|
|
2165
|
+
await file.getBuffer();
|
|
2166
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2167
|
+
});
|
|
2168
|
+
test("Should distpatch NotFoundFileEvent when key does not exists", async () => {
|
|
2169
|
+
const file = fileStorage.create("a");
|
|
2170
|
+
const listener = vi.fn((_even) => { });
|
|
2171
|
+
await fileStorage.events.addListener(FILE_EVENTS.NOT_FOUND, listener);
|
|
2172
|
+
await file.getBuffer();
|
|
2173
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2174
|
+
});
|
|
2175
|
+
});
|
|
2176
|
+
describe("method: getBufferOrFail", () => {
|
|
2177
|
+
test("Should distpatch FoundFileEvent when key exists", async () => {
|
|
2178
|
+
const file = fileStorage.create("a");
|
|
2179
|
+
await file.add({
|
|
2180
|
+
data: new Uint8Array(Buffer.from("CONTENT", "utf8")),
|
|
2181
|
+
});
|
|
2182
|
+
const listener = vi.fn((_even) => { });
|
|
2183
|
+
await fileStorage.events.addListener(FILE_EVENTS.FOUND, listener);
|
|
2184
|
+
await file.getBufferOrFail();
|
|
2185
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2186
|
+
});
|
|
2187
|
+
test("Should distpatch NotFoundFileEvent when key does not exists", async () => {
|
|
2188
|
+
const file = fileStorage.create("a");
|
|
2189
|
+
const listener = vi.fn((_even) => { });
|
|
2190
|
+
await fileStorage.events.addListener(FILE_EVENTS.NOT_FOUND, listener);
|
|
2191
|
+
try {
|
|
2192
|
+
await file.getBufferOrFail();
|
|
2193
|
+
}
|
|
2194
|
+
catch {
|
|
2195
|
+
/* EMPTY */
|
|
2196
|
+
}
|
|
2197
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2198
|
+
});
|
|
2199
|
+
});
|
|
2200
|
+
describe("method: getArrayBuffer", () => {
|
|
2201
|
+
test("Should distpatch FoundFileEvent when key exists", async () => {
|
|
2202
|
+
const file = fileStorage.create("a");
|
|
2203
|
+
await file.add({
|
|
2204
|
+
data: new Uint8Array(Buffer.from("CONTENT", "utf8")),
|
|
2205
|
+
});
|
|
2206
|
+
const listener = vi.fn((_even) => { });
|
|
2207
|
+
await fileStorage.events.addListener(FILE_EVENTS.FOUND, listener);
|
|
2208
|
+
await file.getArrayBuffer();
|
|
2209
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2210
|
+
});
|
|
2211
|
+
test("Should distpatch NotFoundFileEvent when key does not exists", async () => {
|
|
2212
|
+
const file = fileStorage.create("a");
|
|
2213
|
+
const listener = vi.fn((_even) => { });
|
|
2214
|
+
await fileStorage.events.addListener(FILE_EVENTS.NOT_FOUND, listener);
|
|
2215
|
+
await file.getArrayBuffer();
|
|
2216
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2217
|
+
});
|
|
2218
|
+
});
|
|
2219
|
+
describe("method: getArrayBufferOrFail", () => {
|
|
2220
|
+
test("Should distpatch FoundFileEvent when key exists", async () => {
|
|
2221
|
+
const file = fileStorage.create("a");
|
|
2222
|
+
await file.add({
|
|
2223
|
+
data: new Uint8Array(Buffer.from("CONTENT", "utf8")),
|
|
2224
|
+
});
|
|
2225
|
+
const listener = vi.fn((_even) => { });
|
|
2226
|
+
await fileStorage.events.addListener(FILE_EVENTS.FOUND, listener);
|
|
2227
|
+
await file.getArrayBufferOrFail();
|
|
2228
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2229
|
+
});
|
|
2230
|
+
test("Should distpatch NotFoundFileEvent when key does not exists", async () => {
|
|
2231
|
+
const file = fileStorage.create("a");
|
|
2232
|
+
const listener = vi.fn((_even) => { });
|
|
2233
|
+
await fileStorage.events.addListener(FILE_EVENTS.NOT_FOUND, listener);
|
|
2234
|
+
try {
|
|
2235
|
+
await file.getArrayBufferOrFail();
|
|
2236
|
+
}
|
|
2237
|
+
catch {
|
|
2238
|
+
/* EMPTY */
|
|
2239
|
+
}
|
|
2240
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2241
|
+
});
|
|
2242
|
+
});
|
|
2243
|
+
describe("method: getReadable", () => {
|
|
2244
|
+
test("Should distpatch FoundFileEvent when key exists", async () => {
|
|
2245
|
+
const file = fileStorage.create("a");
|
|
2246
|
+
await file.add({
|
|
2247
|
+
data: new Uint8Array(Buffer.from("CONTENT", "utf8")),
|
|
2248
|
+
});
|
|
2249
|
+
const listener = vi.fn((_even) => { });
|
|
2250
|
+
await fileStorage.events.addListener(FILE_EVENTS.FOUND, listener);
|
|
2251
|
+
await file.getReadable();
|
|
2252
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2253
|
+
});
|
|
2254
|
+
test("Should distpatch NotFoundFileEvent when key does not exists", async () => {
|
|
2255
|
+
const file = fileStorage.create("a");
|
|
2256
|
+
const listener = vi.fn((_even) => { });
|
|
2257
|
+
await fileStorage.events.addListener(FILE_EVENTS.NOT_FOUND, listener);
|
|
2258
|
+
await file.getReadable();
|
|
2259
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2260
|
+
});
|
|
2261
|
+
});
|
|
2262
|
+
describe("method: getReadableOrFail", () => {
|
|
2263
|
+
test("Should distpatch FoundFileEvent when key exists", async () => {
|
|
2264
|
+
const file = fileStorage.create("a");
|
|
2265
|
+
await file.add({
|
|
2266
|
+
data: new Uint8Array(Buffer.from("CONTENT", "utf8")),
|
|
2267
|
+
});
|
|
2268
|
+
const listener = vi.fn((_even) => { });
|
|
2269
|
+
await fileStorage.events.addListener(FILE_EVENTS.FOUND, listener);
|
|
2270
|
+
await file.getReadableOrFail();
|
|
2271
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2272
|
+
});
|
|
2273
|
+
test("Should distpatch NotFoundFileEvent when key does not exists", async () => {
|
|
2274
|
+
const file = fileStorage.create("a");
|
|
2275
|
+
const listener = vi.fn((_even) => { });
|
|
2276
|
+
await fileStorage.events.addListener(FILE_EVENTS.NOT_FOUND, listener);
|
|
2277
|
+
try {
|
|
2278
|
+
await file.getReadableOrFail();
|
|
2279
|
+
}
|
|
2280
|
+
catch {
|
|
2281
|
+
/* EMPTY */
|
|
2282
|
+
}
|
|
2283
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2284
|
+
});
|
|
2285
|
+
});
|
|
2286
|
+
describe("method: getReadableStream", () => {
|
|
2287
|
+
test("Should distpatch FoundFileEvent when key exists", async () => {
|
|
2288
|
+
const file = fileStorage.create("a");
|
|
2289
|
+
await file.add({
|
|
2290
|
+
data: new Uint8Array(Buffer.from("CONTENT", "utf8")),
|
|
2291
|
+
});
|
|
2292
|
+
const listener = vi.fn((_even) => { });
|
|
2293
|
+
await fileStorage.events.addListener(FILE_EVENTS.FOUND, listener);
|
|
2294
|
+
await file.getReadableStream();
|
|
2295
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2296
|
+
});
|
|
2297
|
+
test("Should distpatch NotFoundFileEvent when key does not exists", async () => {
|
|
2298
|
+
const file = fileStorage.create("a");
|
|
2299
|
+
const listener = vi.fn((_even) => { });
|
|
2300
|
+
await fileStorage.events.addListener(FILE_EVENTS.NOT_FOUND, listener);
|
|
2301
|
+
await file.getReadableStream();
|
|
2302
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2303
|
+
});
|
|
2304
|
+
});
|
|
2305
|
+
describe("method: getReadableStreamOrFail", () => {
|
|
2306
|
+
test("Should distpatch FoundFileEvent when key exists", async () => {
|
|
2307
|
+
const file = fileStorage.create("a");
|
|
2308
|
+
await file.add({
|
|
2309
|
+
data: new Uint8Array(Buffer.from("CONTENT", "utf8")),
|
|
2310
|
+
});
|
|
2311
|
+
const listener = vi.fn((_even) => { });
|
|
2312
|
+
await fileStorage.events.addListener(FILE_EVENTS.FOUND, listener);
|
|
2313
|
+
await file.getReadableStreamOrFail();
|
|
2314
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2315
|
+
});
|
|
2316
|
+
test("Should distpatch NotFoundFileEvent when key does not exists", async () => {
|
|
2317
|
+
const file = fileStorage.create("a");
|
|
2318
|
+
const listener = vi.fn((_even) => { });
|
|
2319
|
+
await fileStorage.events.addListener(FILE_EVENTS.NOT_FOUND, listener);
|
|
2320
|
+
try {
|
|
2321
|
+
await file.getReadableStreamOrFail();
|
|
2322
|
+
}
|
|
2323
|
+
catch {
|
|
2324
|
+
/* EMPTY */
|
|
2325
|
+
}
|
|
2326
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2327
|
+
});
|
|
2328
|
+
});
|
|
2329
|
+
describe("method: getMetadata", () => {
|
|
2330
|
+
test("Should distpatch FoundFileEvent when key exists", async () => {
|
|
2331
|
+
const file = fileStorage.create("a");
|
|
2332
|
+
await file.add({
|
|
2333
|
+
data: new Uint8Array(Buffer.from("CONTENT", "utf8")),
|
|
2334
|
+
});
|
|
2335
|
+
const listener = vi.fn((_even) => { });
|
|
2336
|
+
await fileStorage.events.addListener(FILE_EVENTS.FOUND, listener);
|
|
2337
|
+
await file.getMetadata();
|
|
2338
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2339
|
+
});
|
|
2340
|
+
test("Should distpatch NotFoundFileEvent when key does not exists", async () => {
|
|
2341
|
+
const file = fileStorage.create("a");
|
|
2342
|
+
const listener = vi.fn((_even) => { });
|
|
2343
|
+
await fileStorage.events.addListener(FILE_EVENTS.NOT_FOUND, listener);
|
|
2344
|
+
await file.getMetadata();
|
|
2345
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2346
|
+
});
|
|
2347
|
+
});
|
|
2348
|
+
describe("method: getMetadataOrFail", () => {
|
|
2349
|
+
test("Should distpatch FoundFileEvent when key exists", async () => {
|
|
2350
|
+
const file = fileStorage.create("a");
|
|
2351
|
+
await file.add({
|
|
2352
|
+
data: new Uint8Array(Buffer.from("CONTENT", "utf8")),
|
|
2353
|
+
});
|
|
2354
|
+
const listener = vi.fn((_even) => { });
|
|
2355
|
+
await fileStorage.events.addListener(FILE_EVENTS.FOUND, listener);
|
|
2356
|
+
await file.getMetadataOrFail();
|
|
2357
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2358
|
+
});
|
|
2359
|
+
test("Should distpatch NotFoundFileEvent when key does not exists", async () => {
|
|
2360
|
+
const file = fileStorage.create("a");
|
|
2361
|
+
const listener = vi.fn((_even) => { });
|
|
2362
|
+
await fileStorage.events.addListener(FILE_EVENTS.NOT_FOUND, listener);
|
|
2363
|
+
try {
|
|
2364
|
+
await file.getMetadataOrFail();
|
|
2365
|
+
}
|
|
2366
|
+
catch {
|
|
2367
|
+
/* EMPTY */
|
|
2368
|
+
}
|
|
2369
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2370
|
+
});
|
|
2371
|
+
});
|
|
2372
|
+
describe("method: exists", () => {
|
|
2373
|
+
test("Should distpatch FoundFileEvent when key exists", async () => {
|
|
2374
|
+
const file = fileStorage.create("a");
|
|
2375
|
+
await file.add({
|
|
2376
|
+
data: new Uint8Array(Buffer.from("CONTENT", "utf8")),
|
|
2377
|
+
});
|
|
2378
|
+
const listener = vi.fn((_even) => { });
|
|
2379
|
+
await fileStorage.events.addListener(FILE_EVENTS.FOUND, listener);
|
|
2380
|
+
await file.exists();
|
|
2381
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2382
|
+
});
|
|
2383
|
+
test("Should distpatch NotFoundFileEvent when key does not exists", async () => {
|
|
2384
|
+
const file = fileStorage.create("a");
|
|
2385
|
+
const listener = vi.fn((_even) => { });
|
|
2386
|
+
await fileStorage.events.addListener(FILE_EVENTS.NOT_FOUND, listener);
|
|
2387
|
+
await file.exists();
|
|
2388
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2389
|
+
});
|
|
2390
|
+
});
|
|
2391
|
+
describe("method: missing", () => {
|
|
2392
|
+
test("Should distpatch FoundFileEvent when key exists", async () => {
|
|
2393
|
+
const file = fileStorage.create("a");
|
|
2394
|
+
await file.add({
|
|
2395
|
+
data: new Uint8Array(Buffer.from("CONTENT", "utf8")),
|
|
2396
|
+
});
|
|
2397
|
+
const listener = vi.fn((_even) => { });
|
|
2398
|
+
await fileStorage.events.addListener(FILE_EVENTS.FOUND, listener);
|
|
2399
|
+
await file.missing();
|
|
2400
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2401
|
+
});
|
|
2402
|
+
test("Should distpatch NotFoundFileEvent when key does not exists", async () => {
|
|
2403
|
+
const file = fileStorage.create("a");
|
|
2404
|
+
const listener = vi.fn((_even) => { });
|
|
2405
|
+
await fileStorage.events.addListener(FILE_EVENTS.NOT_FOUND, listener);
|
|
2406
|
+
await file.missing();
|
|
2407
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2408
|
+
});
|
|
2409
|
+
});
|
|
2410
|
+
describe("method: add", () => {
|
|
2411
|
+
test("Should distpatch KeyExistsFileEvent when key exists", async () => {
|
|
2412
|
+
const file = fileStorage.create("a");
|
|
2413
|
+
await file.add({
|
|
2414
|
+
data: new Uint8Array(Buffer.from("CONTENT", "utf8")),
|
|
2415
|
+
});
|
|
2416
|
+
const listener = vi.fn((_even) => { });
|
|
2417
|
+
await fileStorage.events.addListener(FILE_EVENTS.KEY_EXISTS, listener);
|
|
2418
|
+
await file.add({
|
|
2419
|
+
data: new Uint8Array(Buffer.from("NEW_CONTENT", "utf8")),
|
|
2420
|
+
});
|
|
2421
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2422
|
+
});
|
|
2423
|
+
test("Should distpatch AddedFileEvent when key does not exists", async () => {
|
|
2424
|
+
const file = fileStorage.create("a");
|
|
2425
|
+
const listener = vi.fn((_even) => { });
|
|
2426
|
+
await fileStorage.events.addListener(FILE_EVENTS.ADDED, listener);
|
|
2427
|
+
await file.add({
|
|
2428
|
+
data: new Uint8Array(Buffer.from("NEW_CONTENT", "utf8")),
|
|
2429
|
+
});
|
|
2430
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2431
|
+
});
|
|
2432
|
+
});
|
|
2433
|
+
describe("method: addOrFail", () => {
|
|
2434
|
+
test("Should distpatch KeyExistsFileEvent when key exists", async () => {
|
|
2435
|
+
const file = fileStorage.create("a");
|
|
2436
|
+
await file.add({
|
|
2437
|
+
data: new Uint8Array(Buffer.from("CONTENT", "utf8")),
|
|
2438
|
+
});
|
|
2439
|
+
const listener = vi.fn((_even) => { });
|
|
2440
|
+
await fileStorage.events.addListener(FILE_EVENTS.KEY_EXISTS, listener);
|
|
2441
|
+
try {
|
|
2442
|
+
await file.addOrFail({
|
|
2443
|
+
data: new Uint8Array(Buffer.from("NEW_CONTENT", "utf8")),
|
|
2444
|
+
});
|
|
2445
|
+
}
|
|
2446
|
+
catch {
|
|
2447
|
+
/* EMPTY */
|
|
2448
|
+
}
|
|
2449
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2450
|
+
});
|
|
2451
|
+
test("Should distpatch AddedFileEvent when key does not exists", async () => {
|
|
2452
|
+
const file = fileStorage.create("a");
|
|
2453
|
+
const listener = vi.fn((_even) => { });
|
|
2454
|
+
await fileStorage.events.addListener(FILE_EVENTS.ADDED, listener);
|
|
2455
|
+
await file.addOrFail({
|
|
2456
|
+
data: new Uint8Array(Buffer.from("NEW_CONTENT", "utf8")),
|
|
2457
|
+
});
|
|
2458
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2459
|
+
});
|
|
2460
|
+
});
|
|
2461
|
+
describe("method: addStream", () => {
|
|
2462
|
+
test("Should distpatch KeyExistsFileEvent when key exists", async () => {
|
|
2463
|
+
const file = fileStorage.create("a");
|
|
2464
|
+
await file.add({
|
|
2465
|
+
data: new Uint8Array(Buffer.from("CONTENT", "utf8")),
|
|
2466
|
+
});
|
|
2467
|
+
const listener = vi.fn((_even) => { });
|
|
2468
|
+
await fileStorage.events.addListener(FILE_EVENTS.KEY_EXISTS, listener);
|
|
2469
|
+
await file.addStream({
|
|
2470
|
+
data: {
|
|
2471
|
+
async *[Symbol.asyncIterator]() {
|
|
2472
|
+
yield Promise.resolve(new Uint8Array(Buffer.from("NEW_CONTENT", "utf8")));
|
|
2473
|
+
},
|
|
2474
|
+
},
|
|
2475
|
+
});
|
|
2476
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2477
|
+
});
|
|
2478
|
+
test("Should distpatch AddedFileEvent when key does not exists", async () => {
|
|
2479
|
+
const file = fileStorage.create("a");
|
|
2480
|
+
const listener = vi.fn((_even) => { });
|
|
2481
|
+
await fileStorage.events.addListener(FILE_EVENTS.ADDED, listener);
|
|
2482
|
+
await file.addStream({
|
|
2483
|
+
data: {
|
|
2484
|
+
async *[Symbol.asyncIterator]() {
|
|
2485
|
+
yield Promise.resolve(new Uint8Array(Buffer.from("NEW_CONTENT", "utf8")));
|
|
2486
|
+
},
|
|
2487
|
+
},
|
|
2488
|
+
});
|
|
2489
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2490
|
+
});
|
|
2491
|
+
});
|
|
2492
|
+
describe("method: addStreamOrFail", () => {
|
|
2493
|
+
test("Should distpatch KeyExistsFileEvent when key exists", async () => {
|
|
2494
|
+
const file = fileStorage.create("a");
|
|
2495
|
+
await file.add({
|
|
2496
|
+
data: new Uint8Array(Buffer.from("CONTENT", "utf8")),
|
|
2497
|
+
});
|
|
2498
|
+
const listener = vi.fn((_even) => { });
|
|
2499
|
+
await fileStorage.events.addListener(FILE_EVENTS.KEY_EXISTS, listener);
|
|
2500
|
+
try {
|
|
2501
|
+
await file.addStreamOrFail({
|
|
2502
|
+
data: {
|
|
2503
|
+
async *[Symbol.asyncIterator]() {
|
|
2504
|
+
yield Promise.resolve(new Uint8Array(Buffer.from("NEW_CONTENT", "utf8")));
|
|
2505
|
+
},
|
|
2506
|
+
},
|
|
2507
|
+
});
|
|
2508
|
+
}
|
|
2509
|
+
catch {
|
|
2510
|
+
/* EMPTY */
|
|
2511
|
+
}
|
|
2512
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2513
|
+
});
|
|
2514
|
+
test("Should distpatch AddedFileEvent when key does not exists", async () => {
|
|
2515
|
+
const file = fileStorage.create("a");
|
|
2516
|
+
const listener = vi.fn((_even) => { });
|
|
2517
|
+
await fileStorage.events.addListener(FILE_EVENTS.ADDED, listener);
|
|
2518
|
+
await file.addStreamOrFail({
|
|
2519
|
+
data: {
|
|
2520
|
+
async *[Symbol.asyncIterator]() {
|
|
2521
|
+
yield Promise.resolve(new Uint8Array(Buffer.from("NEW_CONTENT", "utf8")));
|
|
2522
|
+
},
|
|
2523
|
+
},
|
|
2524
|
+
});
|
|
2525
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2526
|
+
});
|
|
2527
|
+
});
|
|
2528
|
+
describe("method: update", () => {
|
|
2529
|
+
test("Should distpatch UpdatedFileEvent when key exists", async () => {
|
|
2530
|
+
const file = fileStorage.create("a");
|
|
2531
|
+
await file.add({
|
|
2532
|
+
data: new Uint8Array(Buffer.from("CONTENT", "utf8")),
|
|
2533
|
+
});
|
|
2534
|
+
const listener = vi.fn((_even) => { });
|
|
2535
|
+
await fileStorage.events.addListener(FILE_EVENTS.UPDATED, listener);
|
|
2536
|
+
await file.update({
|
|
2537
|
+
data: new Uint8Array(Buffer.from("NEW_CONTENT", "utf8")),
|
|
2538
|
+
});
|
|
2539
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2540
|
+
});
|
|
2541
|
+
test("Should distpatch NotFoundFileEvent when key does not exists", async () => {
|
|
2542
|
+
const file = fileStorage.create("a");
|
|
2543
|
+
const listener = vi.fn((_even) => { });
|
|
2544
|
+
await fileStorage.events.addListener(FILE_EVENTS.NOT_FOUND, listener);
|
|
2545
|
+
await file.update({
|
|
2546
|
+
data: new Uint8Array(Buffer.from("NEW_CONTENT", "utf8")),
|
|
2547
|
+
});
|
|
2548
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2549
|
+
});
|
|
2550
|
+
});
|
|
2551
|
+
describe("method: updateOrFail", () => {
|
|
2552
|
+
test("Should distpatch UpdatedFileEvent when key exists", async () => {
|
|
2553
|
+
const file = fileStorage.create("a");
|
|
2554
|
+
await file.add({
|
|
2555
|
+
data: new Uint8Array(Buffer.from("CONTENT", "utf8")),
|
|
2556
|
+
});
|
|
2557
|
+
const listener = vi.fn((_even) => { });
|
|
2558
|
+
await fileStorage.events.addListener(FILE_EVENTS.UPDATED, listener);
|
|
2559
|
+
await file.updateOrFail({
|
|
2560
|
+
data: new Uint8Array(Buffer.from("NEW_CONTENT", "utf8")),
|
|
2561
|
+
});
|
|
2562
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2563
|
+
});
|
|
2564
|
+
test("Should distpatch NotFoundFileEvent when key does not exists", async () => {
|
|
2565
|
+
const file = fileStorage.create("a");
|
|
2566
|
+
const listener = vi.fn((_even) => { });
|
|
2567
|
+
await fileStorage.events.addListener(FILE_EVENTS.NOT_FOUND, listener);
|
|
2568
|
+
try {
|
|
2569
|
+
await file.updateOrFail({
|
|
2570
|
+
data: new Uint8Array(Buffer.from("NEW_CONTENT", "utf8")),
|
|
2571
|
+
});
|
|
2572
|
+
}
|
|
2573
|
+
catch {
|
|
2574
|
+
/* EMPTY */
|
|
2575
|
+
}
|
|
2576
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2577
|
+
});
|
|
2578
|
+
});
|
|
2579
|
+
describe("method: updateStream", () => {
|
|
2580
|
+
test("Should distpatch UpdatedFileEvent when key exists", async () => {
|
|
2581
|
+
const file = fileStorage.create("a");
|
|
2582
|
+
await file.add({
|
|
2583
|
+
data: new Uint8Array(Buffer.from("CONTENT", "utf8")),
|
|
2584
|
+
});
|
|
2585
|
+
const listener = vi.fn((_even) => { });
|
|
2586
|
+
await fileStorage.events.addListener(FILE_EVENTS.UPDATED, listener);
|
|
2587
|
+
await file.updateStream({
|
|
2588
|
+
data: {
|
|
2589
|
+
async *[Symbol.asyncIterator]() {
|
|
2590
|
+
yield Promise.resolve(new Uint8Array(Buffer.from("NEW_CONTENT", "utf8")));
|
|
2591
|
+
},
|
|
2592
|
+
},
|
|
2593
|
+
});
|
|
2594
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2595
|
+
});
|
|
2596
|
+
test("Should distpatch NotFoundFileEvent when key does not exists", async () => {
|
|
2597
|
+
const file = fileStorage.create("a");
|
|
2598
|
+
const listener = vi.fn((_even) => { });
|
|
2599
|
+
await fileStorage.events.addListener(FILE_EVENTS.NOT_FOUND, listener);
|
|
2600
|
+
await file.updateStream({
|
|
2601
|
+
data: {
|
|
2602
|
+
async *[Symbol.asyncIterator]() {
|
|
2603
|
+
yield Promise.resolve(new Uint8Array(Buffer.from("NEW_CONTENT", "utf8")));
|
|
2604
|
+
},
|
|
2605
|
+
},
|
|
2606
|
+
});
|
|
2607
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2608
|
+
});
|
|
2609
|
+
});
|
|
2610
|
+
describe("method: updateStreamOrFail", () => {
|
|
2611
|
+
test("Should distpatch UpdatedFileEvent when key exists", async () => {
|
|
2612
|
+
const file = fileStorage.create("a");
|
|
2613
|
+
await file.add({
|
|
2614
|
+
data: new Uint8Array(Buffer.from("CONTENT", "utf8")),
|
|
2615
|
+
});
|
|
2616
|
+
const listener = vi.fn((_even) => { });
|
|
2617
|
+
await fileStorage.events.addListener(FILE_EVENTS.UPDATED, listener);
|
|
2618
|
+
await file.updateStreamOrFail({
|
|
2619
|
+
data: {
|
|
2620
|
+
async *[Symbol.asyncIterator]() {
|
|
2621
|
+
yield Promise.resolve(new Uint8Array(Buffer.from("NEW_CONTENT", "utf8")));
|
|
2622
|
+
},
|
|
2623
|
+
},
|
|
2624
|
+
});
|
|
2625
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2626
|
+
});
|
|
2627
|
+
test("Should distpatch NotFoundFileEvent when key does not exists", async () => {
|
|
2628
|
+
const file = fileStorage.create("a");
|
|
2629
|
+
const listener = vi.fn((_even) => { });
|
|
2630
|
+
await fileStorage.events.addListener(FILE_EVENTS.NOT_FOUND, listener);
|
|
2631
|
+
try {
|
|
2632
|
+
await file.updateStreamOrFail({
|
|
2633
|
+
data: {
|
|
2634
|
+
async *[Symbol.asyncIterator]() {
|
|
2635
|
+
yield Promise.resolve(new Uint8Array(Buffer.from("NEW_CONTENT", "utf8")));
|
|
2636
|
+
},
|
|
2637
|
+
},
|
|
2638
|
+
});
|
|
2639
|
+
}
|
|
2640
|
+
catch {
|
|
2641
|
+
/* EMPTY */
|
|
2642
|
+
}
|
|
2643
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2644
|
+
});
|
|
2645
|
+
});
|
|
2646
|
+
describe("method: put", () => {
|
|
2647
|
+
test("Should distpatch UpdatedFileEvent when key exists", async () => {
|
|
2648
|
+
const file = fileStorage.create("a");
|
|
2649
|
+
await file.add({
|
|
2650
|
+
data: new Uint8Array(Buffer.from("CONTENT", "utf8")),
|
|
2651
|
+
});
|
|
2652
|
+
const listener = vi.fn((_even) => { });
|
|
2653
|
+
await fileStorage.events.addListener(FILE_EVENTS.UPDATED, listener);
|
|
2654
|
+
await file.put({
|
|
2655
|
+
data: new Uint8Array(Buffer.from("NEW_CONTENT", "utf8")),
|
|
2656
|
+
});
|
|
2657
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2658
|
+
});
|
|
2659
|
+
test("Should distpatch AddedFileEvent when key doesnt exists", async () => {
|
|
2660
|
+
const file = fileStorage.create("a");
|
|
2661
|
+
const listener = vi.fn((_even) => { });
|
|
2662
|
+
await fileStorage.events.addListener(FILE_EVENTS.ADDED, listener);
|
|
2663
|
+
await file.put({
|
|
2664
|
+
data: new Uint8Array(Buffer.from("CONTENT", "utf8")),
|
|
2665
|
+
});
|
|
2666
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2667
|
+
});
|
|
2668
|
+
});
|
|
2669
|
+
describe("method: putStream", () => {
|
|
2670
|
+
test("Should distpatch UpdatedFileEvent when key exists", async () => {
|
|
2671
|
+
const file = fileStorage.create("a");
|
|
2672
|
+
await file.add({
|
|
2673
|
+
data: new Uint8Array(Buffer.from("CONTENT", "utf8")),
|
|
2674
|
+
});
|
|
2675
|
+
const listener = vi.fn((_even) => { });
|
|
2676
|
+
await fileStorage.events.addListener(FILE_EVENTS.UPDATED, listener);
|
|
2677
|
+
await file.putStream({
|
|
2678
|
+
data: {
|
|
2679
|
+
async *[Symbol.asyncIterator]() {
|
|
2680
|
+
yield Promise.resolve(new Uint8Array(Buffer.from("NEW_CONTENT", "utf8")));
|
|
2681
|
+
},
|
|
2682
|
+
},
|
|
2683
|
+
});
|
|
2684
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2685
|
+
});
|
|
2686
|
+
test("Should distpatch AddedFileEvent when key doesnt exists", async () => {
|
|
2687
|
+
const file = fileStorage.create("a");
|
|
2688
|
+
const listener = vi.fn((_even) => { });
|
|
2689
|
+
await fileStorage.events.addListener(FILE_EVENTS.ADDED, listener);
|
|
2690
|
+
await file.putStream({
|
|
2691
|
+
data: {
|
|
2692
|
+
async *[Symbol.asyncIterator]() {
|
|
2693
|
+
yield Promise.resolve(new Uint8Array(Buffer.from("CONTENT", "utf8")));
|
|
2694
|
+
},
|
|
2695
|
+
},
|
|
2696
|
+
});
|
|
2697
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2698
|
+
});
|
|
2699
|
+
});
|
|
2700
|
+
describe("method: remove", () => {
|
|
2701
|
+
test("Should distpatch RemovedFileEvent when key exists", async () => {
|
|
2702
|
+
const file = fileStorage.create("a");
|
|
2703
|
+
await file.add({
|
|
2704
|
+
data: new Uint8Array(Buffer.from("CONTENT", "utf8")),
|
|
2705
|
+
});
|
|
2706
|
+
const listener = vi.fn((_even) => { });
|
|
2707
|
+
await fileStorage.events.addListener(FILE_EVENTS.REMOVED, listener);
|
|
2708
|
+
await file.remove();
|
|
2709
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2710
|
+
});
|
|
2711
|
+
test("Should distpatch NotFoundFileEvent when key does not exists", async () => {
|
|
2712
|
+
const file = fileStorage.create("a");
|
|
2713
|
+
const listener = vi.fn((_even) => { });
|
|
2714
|
+
await fileStorage.events.addListener(FILE_EVENTS.NOT_FOUND, listener);
|
|
2715
|
+
await file.remove();
|
|
2716
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2717
|
+
});
|
|
2718
|
+
});
|
|
2719
|
+
describe("method: removeOrFail", () => {
|
|
2720
|
+
test("Should distpatch RemovedFileEvent when key exists", async () => {
|
|
2721
|
+
const file = fileStorage.create("a");
|
|
2722
|
+
await file.add({
|
|
2723
|
+
data: new Uint8Array(Buffer.from("CONTENT", "utf8")),
|
|
2724
|
+
});
|
|
2725
|
+
const listener = vi.fn((_even) => { });
|
|
2726
|
+
await fileStorage.events.addListener(FILE_EVENTS.REMOVED, listener);
|
|
2727
|
+
await file.removeOrFail();
|
|
2728
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2729
|
+
});
|
|
2730
|
+
test("Should distpatch NotFoundFileEvent when key does not exists", async () => {
|
|
2731
|
+
const file = fileStorage.create("a");
|
|
2732
|
+
const listener = vi.fn((_even) => { });
|
|
2733
|
+
await fileStorage.events.addListener(FILE_EVENTS.NOT_FOUND, listener);
|
|
2734
|
+
try {
|
|
2735
|
+
await file.removeOrFail();
|
|
2736
|
+
}
|
|
2737
|
+
catch {
|
|
2738
|
+
/* EMPTY */
|
|
2739
|
+
}
|
|
2740
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2741
|
+
});
|
|
2742
|
+
});
|
|
2743
|
+
describe("method: copy", () => {
|
|
2744
|
+
test("Should dispatch NotFoundFileEvent when source doesnt exists", async () => {
|
|
2745
|
+
const listener = vi.fn((_event) => { });
|
|
2746
|
+
await fileStorage.events.addListener(FILE_EVENTS.NOT_FOUND, listener);
|
|
2747
|
+
await fileStorage.create("a").copy("b");
|
|
2748
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2749
|
+
});
|
|
2750
|
+
test("Should dispatch DestinationExistsFileEvent when source exists and destination exists", async () => {
|
|
2751
|
+
const listener = vi.fn((_event) => { });
|
|
2752
|
+
await fileStorage.events.addListener(FILE_EVENTS.DESTINATION_EXISTS, listener);
|
|
2753
|
+
const file = fileStorage.create("a");
|
|
2754
|
+
await file.add({
|
|
2755
|
+
data: new Uint8Array(Buffer.from("CONTENT_A", "utf8")),
|
|
2756
|
+
});
|
|
2757
|
+
await fileStorage.create("b").add({
|
|
2758
|
+
data: new Uint8Array(Buffer.from("CONTENT_B", "utf8")),
|
|
2759
|
+
});
|
|
2760
|
+
await file.copy("b");
|
|
2761
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2762
|
+
});
|
|
2763
|
+
test("Should dispatch CopiedFileEvent when source exists and destination doesnt exists", async () => {
|
|
2764
|
+
const listener = vi.fn((_event) => { });
|
|
2765
|
+
await fileStorage.events.addListener(FILE_EVENTS.COPIED, listener);
|
|
2766
|
+
const file = fileStorage.create("a");
|
|
2767
|
+
await file.add({
|
|
2768
|
+
data: new Uint8Array(Buffer.from("CONTENT_A", "utf8")),
|
|
2769
|
+
});
|
|
2770
|
+
await file.copy("b");
|
|
2771
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2772
|
+
});
|
|
2773
|
+
});
|
|
2774
|
+
describe("method: copyOrFail", () => {
|
|
2775
|
+
test("Should dispatch NotFoundFileEvent when source doesnt exists", async () => {
|
|
2776
|
+
const listener = vi.fn((_event) => { });
|
|
2777
|
+
await fileStorage.events.addListener(FILE_EVENTS.NOT_FOUND, listener);
|
|
2778
|
+
try {
|
|
2779
|
+
await fileStorage.create("a").copyOrFail("b");
|
|
2780
|
+
}
|
|
2781
|
+
catch {
|
|
2782
|
+
/* EMPTY */
|
|
2783
|
+
}
|
|
2784
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2785
|
+
});
|
|
2786
|
+
test("Should dispatch DestinationExistsFileEvent when source exists and destination exists", async () => {
|
|
2787
|
+
const listener = vi.fn((_event) => { });
|
|
2788
|
+
await fileStorage.events.addListener(FILE_EVENTS.DESTINATION_EXISTS, listener);
|
|
2789
|
+
const file = fileStorage.create("a");
|
|
2790
|
+
await file.add({
|
|
2791
|
+
data: new Uint8Array(Buffer.from("CONTENT_A", "utf8")),
|
|
2792
|
+
});
|
|
2793
|
+
await fileStorage.create("b").add({
|
|
2794
|
+
data: new Uint8Array(Buffer.from("CONTENT_B", "utf8")),
|
|
2795
|
+
});
|
|
2796
|
+
try {
|
|
2797
|
+
await file.copyOrFail("b");
|
|
2798
|
+
}
|
|
2799
|
+
catch {
|
|
2800
|
+
/* EMPTY */
|
|
2801
|
+
}
|
|
2802
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2803
|
+
});
|
|
2804
|
+
test("Should dispatch CopiedFileEvent when source exists and destination doesnt exists", async () => {
|
|
2805
|
+
const listener = vi.fn((_event) => { });
|
|
2806
|
+
await fileStorage.events.addListener(FILE_EVENTS.COPIED, listener);
|
|
2807
|
+
const file = fileStorage.create("a");
|
|
2808
|
+
await file.add({
|
|
2809
|
+
data: new Uint8Array(Buffer.from("CONTENT_A", "utf8")),
|
|
2810
|
+
});
|
|
2811
|
+
await file.copyOrFail("b");
|
|
2812
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2813
|
+
});
|
|
2814
|
+
});
|
|
2815
|
+
describe("method: copyAndReplace", () => {
|
|
2816
|
+
test("Should dispatch NotFoundFileEvent when source doesnt exists", async () => {
|
|
2817
|
+
const listener = vi.fn((_event) => { });
|
|
2818
|
+
await fileStorage.events.addListener(FILE_EVENTS.NOT_FOUND, listener);
|
|
2819
|
+
await fileStorage.create("a").copyAndReplace("b");
|
|
2820
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2821
|
+
});
|
|
2822
|
+
test("Should dispatch CopiedFileEvent when source exists and destination exists", async () => {
|
|
2823
|
+
const listener = vi.fn((_event) => { });
|
|
2824
|
+
await fileStorage.events.addListener(FILE_EVENTS.COPIED, listener);
|
|
2825
|
+
const file = fileStorage.create("a");
|
|
2826
|
+
await file.add({
|
|
2827
|
+
data: new Uint8Array(Buffer.from("CONTENT_A", "utf8")),
|
|
2828
|
+
});
|
|
2829
|
+
await fileStorage.create("b").add({
|
|
2830
|
+
data: new Uint8Array(Buffer.from("CONTENT_B", "utf8")),
|
|
2831
|
+
});
|
|
2832
|
+
await file.copyAndReplace("b");
|
|
2833
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2834
|
+
});
|
|
2835
|
+
test("Should dispatch CopiedFileEvent when source exists and destination doesnt exists", async () => {
|
|
2836
|
+
const listener = vi.fn((_event) => { });
|
|
2837
|
+
await fileStorage.events.addListener(FILE_EVENTS.COPIED, listener);
|
|
2838
|
+
const file = fileStorage.create("a");
|
|
2839
|
+
await file.add({
|
|
2840
|
+
data: new Uint8Array(Buffer.from("CONTENT_A", "utf8")),
|
|
2841
|
+
});
|
|
2842
|
+
await file.copyAndReplace("b");
|
|
2843
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2844
|
+
});
|
|
2845
|
+
});
|
|
2846
|
+
describe("method: copyAndReplaceOrFail", () => {
|
|
2847
|
+
test("Should dispatch NotFoundFileEvent when source doesnt exists", async () => {
|
|
2848
|
+
const listener = vi.fn((_event) => { });
|
|
2849
|
+
await fileStorage.events.addListener(FILE_EVENTS.NOT_FOUND, listener);
|
|
2850
|
+
try {
|
|
2851
|
+
await fileStorage.create("a").copyAndReplaceOrFail("b");
|
|
2852
|
+
}
|
|
2853
|
+
catch {
|
|
2854
|
+
/* EMPTY */
|
|
2855
|
+
}
|
|
2856
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2857
|
+
});
|
|
2858
|
+
test("Should dispatch CopiedFileEvent when source exists and destination exists", async () => {
|
|
2859
|
+
const listener = vi.fn((_event) => { });
|
|
2860
|
+
await fileStorage.events.addListener(FILE_EVENTS.COPIED, listener);
|
|
2861
|
+
const file = fileStorage.create("a");
|
|
2862
|
+
await file.add({
|
|
2863
|
+
data: new Uint8Array(Buffer.from("CONTENT_A", "utf8")),
|
|
2864
|
+
});
|
|
2865
|
+
await fileStorage.create("b").add({
|
|
2866
|
+
data: new Uint8Array(Buffer.from("CONTENT_B", "utf8")),
|
|
2867
|
+
});
|
|
2868
|
+
await file.copyAndReplaceOrFail("b");
|
|
2869
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2870
|
+
});
|
|
2871
|
+
test("Should dispatch CopiedFileEvent when source exists and destination doesnt exists", async () => {
|
|
2872
|
+
const listener = vi.fn((_event) => { });
|
|
2873
|
+
await fileStorage.events.addListener(FILE_EVENTS.COPIED, listener);
|
|
2874
|
+
const file = fileStorage.create("a");
|
|
2875
|
+
await file.add({
|
|
2876
|
+
data: new Uint8Array(Buffer.from("CONTENT_A", "utf8")),
|
|
2877
|
+
});
|
|
2878
|
+
await file.copyAndReplaceOrFail("b");
|
|
2879
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2880
|
+
});
|
|
2881
|
+
});
|
|
2882
|
+
describe("method: move", () => {
|
|
2883
|
+
test("Should dispatch NotFoundFileEvent when source doesnt exists", async () => {
|
|
2884
|
+
const listener = vi.fn((_event) => { });
|
|
2885
|
+
await fileStorage.events.addListener(FILE_EVENTS.NOT_FOUND, listener);
|
|
2886
|
+
await fileStorage.create("a").move("b");
|
|
2887
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2888
|
+
});
|
|
2889
|
+
test("Should dispatch DestinationExistsFileEvent when source exists and destination exists", async () => {
|
|
2890
|
+
const listener = vi.fn((_event) => { });
|
|
2891
|
+
await fileStorage.events.addListener(FILE_EVENTS.DESTINATION_EXISTS, listener);
|
|
2892
|
+
const file = fileStorage.create("a");
|
|
2893
|
+
await file.add({
|
|
2894
|
+
data: new Uint8Array(Buffer.from("CONTENT_A", "utf8")),
|
|
2895
|
+
});
|
|
2896
|
+
await fileStorage.create("b").add({
|
|
2897
|
+
data: new Uint8Array(Buffer.from("CONTENT_B", "utf8")),
|
|
2898
|
+
});
|
|
2899
|
+
await file.move("b");
|
|
2900
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2901
|
+
});
|
|
2902
|
+
test("Should dispatch MovedFileEvent when source exists and destination doesnt exists", async () => {
|
|
2903
|
+
const listener = vi.fn((_event) => { });
|
|
2904
|
+
await fileStorage.events.addListener(FILE_EVENTS.MOVED, listener);
|
|
2905
|
+
const file = fileStorage.create("a");
|
|
2906
|
+
await file.add({
|
|
2907
|
+
data: new Uint8Array(Buffer.from("CONTENT_A", "utf8")),
|
|
2908
|
+
});
|
|
2909
|
+
await file.move("b");
|
|
2910
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2911
|
+
});
|
|
2912
|
+
});
|
|
2913
|
+
describe("method: moveOrFail", () => {
|
|
2914
|
+
test("Should dispatch NotFoundFileEvent when source doesnt exists", async () => {
|
|
2915
|
+
const listener = vi.fn((_event) => { });
|
|
2916
|
+
await fileStorage.events.addListener(FILE_EVENTS.NOT_FOUND, listener);
|
|
2917
|
+
try {
|
|
2918
|
+
await fileStorage.create("a").moveOrFail("b");
|
|
2919
|
+
}
|
|
2920
|
+
catch {
|
|
2921
|
+
/* EMPTY */
|
|
2922
|
+
}
|
|
2923
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2924
|
+
});
|
|
2925
|
+
test("Should dispatch DestinationExistsFileEvent when source exists and destination exists", async () => {
|
|
2926
|
+
const listener = vi.fn((_event) => { });
|
|
2927
|
+
await fileStorage.events.addListener(FILE_EVENTS.DESTINATION_EXISTS, listener);
|
|
2928
|
+
const file = fileStorage.create("a");
|
|
2929
|
+
await file.add({
|
|
2930
|
+
data: new Uint8Array(Buffer.from("CONTENT_A", "utf8")),
|
|
2931
|
+
});
|
|
2932
|
+
await fileStorage.create("b").add({
|
|
2933
|
+
data: new Uint8Array(Buffer.from("CONTENT_B", "utf8")),
|
|
2934
|
+
});
|
|
2935
|
+
try {
|
|
2936
|
+
await file.moveOrFail("b");
|
|
2937
|
+
}
|
|
2938
|
+
catch {
|
|
2939
|
+
/* EMPTY */
|
|
2940
|
+
}
|
|
2941
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2942
|
+
});
|
|
2943
|
+
test("Should dispatch MovedFileEvent when source exists and destination doesnt exists", async () => {
|
|
2944
|
+
const listener = vi.fn((_event) => { });
|
|
2945
|
+
await fileStorage.events.addListener(FILE_EVENTS.MOVED, listener);
|
|
2946
|
+
const file = fileStorage.create("a");
|
|
2947
|
+
await file.add({
|
|
2948
|
+
data: new Uint8Array(Buffer.from("CONTENT_A", "utf8")),
|
|
2949
|
+
});
|
|
2950
|
+
await file.moveOrFail("b");
|
|
2951
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2952
|
+
});
|
|
2953
|
+
});
|
|
2954
|
+
describe("method: moveAndReplace", () => {
|
|
2955
|
+
test("Should dispatch NotFoundFileEvent when source doesnt exists", async () => {
|
|
2956
|
+
const listener = vi.fn((_event) => { });
|
|
2957
|
+
await fileStorage.events.addListener(FILE_EVENTS.NOT_FOUND, listener);
|
|
2958
|
+
await fileStorage.create("a").moveAndReplace("b");
|
|
2959
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2960
|
+
});
|
|
2961
|
+
test("Should dispatch MovedFileEvent when source exists and destination exists", async () => {
|
|
2962
|
+
const listener = vi.fn((_event) => { });
|
|
2963
|
+
await fileStorage.events.addListener(FILE_EVENTS.MOVED, listener);
|
|
2964
|
+
const file = fileStorage.create("a");
|
|
2965
|
+
await file.add({
|
|
2966
|
+
data: new Uint8Array(Buffer.from("CONTENT_A", "utf8")),
|
|
2967
|
+
});
|
|
2968
|
+
await fileStorage.create("b").add({
|
|
2969
|
+
data: new Uint8Array(Buffer.from("CONTENT_B", "utf8")),
|
|
2970
|
+
});
|
|
2971
|
+
await file.moveAndReplace("b");
|
|
2972
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2973
|
+
});
|
|
2974
|
+
test("Should dispatch MovedFileEvent when source exists and destination doesnt exists", async () => {
|
|
2975
|
+
const listener = vi.fn((_event) => { });
|
|
2976
|
+
await fileStorage.events.addListener(FILE_EVENTS.MOVED, listener);
|
|
2977
|
+
const file = fileStorage.create("a");
|
|
2978
|
+
await file.add({
|
|
2979
|
+
data: new Uint8Array(Buffer.from("CONTENT_A", "utf8")),
|
|
2980
|
+
});
|
|
2981
|
+
await file.moveAndReplace("b");
|
|
2982
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2983
|
+
});
|
|
2984
|
+
});
|
|
2985
|
+
describe("method: moveAndReplaceOrFail", () => {
|
|
2986
|
+
test("Should dispatch NotFoundFileEvent when source doesnt exists", async () => {
|
|
2987
|
+
const listener = vi.fn((_event) => { });
|
|
2988
|
+
await fileStorage.events.addListener(FILE_EVENTS.NOT_FOUND, listener);
|
|
2989
|
+
try {
|
|
2990
|
+
await fileStorage.create("a").moveAndReplaceOrFail("b");
|
|
2991
|
+
}
|
|
2992
|
+
catch {
|
|
2993
|
+
/* EMPTY */
|
|
2994
|
+
}
|
|
2995
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
2996
|
+
});
|
|
2997
|
+
test("Should dispatch MovedFileEvent when source exists and destination exists", async () => {
|
|
2998
|
+
const listener = vi.fn((_event) => { });
|
|
2999
|
+
await fileStorage.events.addListener(FILE_EVENTS.MOVED, listener);
|
|
3000
|
+
const file = fileStorage.create("a");
|
|
3001
|
+
await file.add({
|
|
3002
|
+
data: new Uint8Array(Buffer.from("CONTENT_A", "utf8")),
|
|
3003
|
+
});
|
|
3004
|
+
await fileStorage.create("b").add({
|
|
3005
|
+
data: new Uint8Array(Buffer.from("CONTENT_B", "utf8")),
|
|
3006
|
+
});
|
|
3007
|
+
await file.moveAndReplaceOrFail("b");
|
|
3008
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
3009
|
+
});
|
|
3010
|
+
test("Should dispatch MovedFileEvent when source exists and destination doesnt exists", async () => {
|
|
3011
|
+
const listener = vi.fn((_event) => { });
|
|
3012
|
+
await fileStorage.events.addListener(FILE_EVENTS.MOVED, listener);
|
|
3013
|
+
const file = fileStorage.create("a");
|
|
3014
|
+
await file.add({
|
|
3015
|
+
data: new Uint8Array(Buffer.from("CONTENT_A", "utf8")),
|
|
3016
|
+
});
|
|
3017
|
+
await file.moveAndReplaceOrFail("b");
|
|
3018
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
3019
|
+
});
|
|
3020
|
+
});
|
|
3021
|
+
describe("method: removeMany", () => {
|
|
3022
|
+
test("Should dispatch RemovedFileEvent when one key exists", async () => {
|
|
3023
|
+
const listener = vi.fn((_event) => { });
|
|
3024
|
+
await fileStorage.events.addListener(FILE_EVENTS.REMOVED, listener);
|
|
3025
|
+
const file1 = fileStorage.create("a");
|
|
3026
|
+
await file1.add({
|
|
3027
|
+
data: new Uint8Array(Buffer.from("CONTENT_A", "utf8")),
|
|
3028
|
+
});
|
|
3029
|
+
const file2 = fileStorage.create("b");
|
|
3030
|
+
await file2.add({
|
|
3031
|
+
data: new Uint8Array(Buffer.from("CONTENT_B", "utf8")),
|
|
3032
|
+
});
|
|
3033
|
+
await fileStorage.removeMany([file1, file2]);
|
|
3034
|
+
expect(listener).toHaveBeenCalledTimes(2);
|
|
3035
|
+
});
|
|
3036
|
+
test("Should dispatch NotFoundFileEvent when all keys doesnt exists", async () => {
|
|
3037
|
+
const listeners = vi.fn((_event) => { });
|
|
3038
|
+
await fileStorage.events.addListener(FILE_EVENTS.NOT_FOUND, listeners);
|
|
3039
|
+
const file1 = fileStorage.create("a");
|
|
3040
|
+
const file2 = fileStorage.create("b");
|
|
3041
|
+
await fileStorage.removeMany([file1, file2]);
|
|
3042
|
+
expect(listeners).toHaveBeenCalledTimes(2);
|
|
3043
|
+
});
|
|
3044
|
+
});
|
|
3045
|
+
describe("method: clear", () => {
|
|
3046
|
+
test("Should ClearedFileEvent when clear method is called", async () => {
|
|
3047
|
+
const listener = vi.fn((_event) => { });
|
|
3048
|
+
await fileStorage.events.addListener(FILE_EVENTS.CLEARED, listener);
|
|
3049
|
+
await fileStorage.create("a").add({
|
|
3050
|
+
data: new Uint8Array(Buffer.from("CONTENT_A", "utf8")),
|
|
3051
|
+
});
|
|
3052
|
+
await fileStorage.create("b").add({
|
|
3053
|
+
data: new Uint8Array(Buffer.from("CONTENT_B", "utf8")),
|
|
3054
|
+
});
|
|
3055
|
+
await fileStorage.create("c").add({
|
|
3056
|
+
data: new Uint8Array(Buffer.from("CONTENT_C", "utf8")),
|
|
3057
|
+
});
|
|
3058
|
+
await fileStorage.clear();
|
|
3059
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
3060
|
+
expect(listener).toHaveBeenCalledWith({});
|
|
3061
|
+
});
|
|
3062
|
+
});
|
|
3063
|
+
});
|
|
3064
|
+
describe.skipIf(excludeSerdeTests)("Serde tests:", () => {
|
|
3065
|
+
test("Should allow get data from a deserialized file instance", async () => {
|
|
3066
|
+
const file = fileStorage.create("a.txt");
|
|
3067
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
3068
|
+
await file.add({ data });
|
|
3069
|
+
const deserializedFile = serde.deserialize(serde.serialize(file));
|
|
3070
|
+
const retrievedData = await deserializedFile.getBytes();
|
|
3071
|
+
expect(retrievedData).toEqual(data);
|
|
3072
|
+
});
|
|
3073
|
+
test("Should allow update data on a deserialized file instance", async () => {
|
|
3074
|
+
const file = fileStorage.create("a.txt");
|
|
3075
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
3076
|
+
await file.add({ data });
|
|
3077
|
+
const deserializedFile = serde.deserialize(serde.serialize(file));
|
|
3078
|
+
const newData = new Uint8Array(Buffer.from("NEW_CONTENT", "utf8"));
|
|
3079
|
+
await deserializedFile.update({
|
|
3080
|
+
data: newData,
|
|
3081
|
+
});
|
|
3082
|
+
const retrievedData = await deserializedFile.getBytes();
|
|
3083
|
+
expect(retrievedData).toEqual(newData);
|
|
3084
|
+
});
|
|
3085
|
+
test("Should allow put data on a deserialized file instance", async () => {
|
|
3086
|
+
const file = fileStorage.create("a.txt");
|
|
3087
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
3088
|
+
await file.add({ data });
|
|
3089
|
+
const deserializedFile = serde.deserialize(serde.serialize(file));
|
|
3090
|
+
const newData = new Uint8Array(Buffer.from("NEW_CONTENT", "utf8"));
|
|
3091
|
+
await deserializedFile.put({
|
|
3092
|
+
data: newData,
|
|
3093
|
+
});
|
|
3094
|
+
const retrievedData = await deserializedFile.getBytes();
|
|
3095
|
+
expect(retrievedData).toEqual(newData);
|
|
3096
|
+
});
|
|
3097
|
+
test("Should allow remove data on a deserialized file instance", async () => {
|
|
3098
|
+
const file = fileStorage.create("a.txt");
|
|
3099
|
+
const data = new Uint8Array(Buffer.from("CONTENT", "utf8"));
|
|
3100
|
+
await file.add({ data });
|
|
3101
|
+
const deserializedFile = serde.deserialize(serde.serialize(file));
|
|
3102
|
+
await deserializedFile.remove();
|
|
3103
|
+
const retrievedData = await deserializedFile.getBytes();
|
|
3104
|
+
expect(retrievedData).toBeNull();
|
|
3105
|
+
});
|
|
3106
|
+
});
|
|
3107
|
+
});
|
|
3108
|
+
}
|
|
3109
|
+
//# sourceMappingURL=file-storage.test-suite.js.map
|