@nestm/storage 0.1.0-alpha.2 → 0.1.0-alpha.20
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/CHANGELOG.md +320 -0
- package/README.md +975 -29
- package/SECURITY.md +128 -0
- package/dist/ai-sdk/ai-sdk-file-workflow-tools.d.ts +53 -0
- package/dist/ai-sdk/ai-sdk-file-workflow-tools.d.ts.map +1 -0
- package/dist/ai-sdk/ai-sdk-file-workflow-tools.js +370 -0
- package/dist/ai-sdk/ai-sdk-file-workflow-tools.js.map +1 -0
- package/dist/ai-sdk/ai-sdk-workspace-tools.d.ts +91 -0
- package/dist/ai-sdk/ai-sdk-workspace-tools.d.ts.map +1 -0
- package/dist/ai-sdk/ai-sdk-workspace-tools.js +497 -0
- package/dist/ai-sdk/ai-sdk-workspace-tools.js.map +1 -0
- package/dist/ai-sdk/index.d.ts +3 -0
- package/dist/ai-sdk/index.d.ts.map +1 -0
- package/dist/ai-sdk/index.js +3 -0
- package/dist/ai-sdk/index.js.map +1 -0
- package/dist/bytes/index.d.ts +30 -0
- package/dist/bytes/index.d.ts.map +1 -0
- package/dist/bytes/index.js +96 -0
- package/dist/bytes/index.js.map +1 -0
- package/dist/core/index.d.ts +5 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +5 -0
- package/dist/core/index.js.map +1 -1
- package/dist/core/storage-staged-content.d.ts +39 -0
- package/dist/core/storage-staged-content.d.ts.map +1 -0
- package/dist/core/storage-staged-content.js +109 -0
- package/dist/core/storage-staged-content.js.map +1 -0
- package/dist/core/storage-streams.d.ts +19 -0
- package/dist/core/storage-streams.d.ts.map +1 -0
- package/dist/core/storage-streams.js +95 -0
- package/dist/core/storage-streams.js.map +1 -0
- package/dist/core/storage-text-edit.d.ts +38 -0
- package/dist/core/storage-text-edit.d.ts.map +1 -0
- package/dist/core/storage-text-edit.js +86 -0
- package/dist/core/storage-text-edit.js.map +1 -0
- package/dist/core/storage-text-stream-edit.d.ts +8 -0
- package/dist/core/storage-text-stream-edit.d.ts.map +1 -0
- package/dist/core/storage-text-stream-edit.js +114 -0
- package/dist/core/storage-text-stream-edit.js.map +1 -0
- package/dist/core/storage-text.d.ts +22 -0
- package/dist/core/storage-text.d.ts.map +1 -0
- package/dist/core/storage-text.js +69 -0
- package/dist/core/storage-text.js.map +1 -0
- package/dist/crypto/index.d.ts +2 -0
- package/dist/crypto/index.d.ts.map +1 -0
- package/dist/crypto/index.js +2 -0
- package/dist/crypto/index.js.map +1 -0
- package/dist/crypto/storage-encrypted-content.d.ts +49 -0
- package/dist/crypto/storage-encrypted-content.d.ts.map +1 -0
- package/dist/crypto/storage-encrypted-content.js +212 -0
- package/dist/crypto/storage-encrypted-content.js.map +1 -0
- package/dist/files-sdk/azure/azure-conditional.d.ts +5 -0
- package/dist/files-sdk/azure/azure-conditional.d.ts.map +1 -0
- package/dist/files-sdk/azure/azure-conditional.js +184 -0
- package/dist/files-sdk/azure/azure-conditional.js.map +1 -0
- package/dist/files-sdk/azure/index.d.ts +10 -0
- package/dist/files-sdk/azure/index.d.ts.map +1 -0
- package/dist/files-sdk/azure/index.js +34 -0
- package/dist/files-sdk/azure/index.js.map +1 -0
- package/dist/files-sdk/files-sdk.driver.d.ts +85 -3
- package/dist/files-sdk/files-sdk.driver.d.ts.map +1 -1
- package/dist/files-sdk/files-sdk.driver.js +1437 -37
- package/dist/files-sdk/files-sdk.driver.js.map +1 -1
- package/dist/files-sdk/fs/index.d.ts +42 -0
- package/dist/files-sdk/fs/index.d.ts.map +1 -0
- package/dist/files-sdk/fs/index.js +1117 -0
- package/dist/files-sdk/fs/index.js.map +1 -0
- package/dist/files-sdk/index.d.ts +1 -1
- package/dist/files-sdk/index.d.ts.map +1 -1
- package/dist/files-sdk/index.js.map +1 -1
- package/dist/files-sdk/memory.d.ts +7 -0
- package/dist/files-sdk/memory.d.ts.map +1 -0
- package/dist/files-sdk/memory.js +72 -0
- package/dist/files-sdk/memory.js.map +1 -0
- package/dist/files-sdk/provider/index.d.ts +58 -0
- package/dist/files-sdk/provider/index.d.ts.map +1 -0
- package/dist/files-sdk/provider/index.js +169 -0
- package/dist/files-sdk/provider/index.js.map +1 -0
- package/dist/files-sdk/s3/construction-metadata.d.ts +9 -0
- package/dist/files-sdk/s3/construction-metadata.d.ts.map +1 -0
- package/dist/files-sdk/s3/construction-metadata.js +24 -0
- package/dist/files-sdk/s3/construction-metadata.js.map +1 -0
- package/dist/files-sdk/s3/index.d.ts +54 -0
- package/dist/files-sdk/s3/index.d.ts.map +1 -0
- package/dist/files-sdk/s3/index.js +1505 -0
- package/dist/files-sdk/s3/index.js.map +1 -0
- package/dist/gateway/index.d.ts +1 -1
- package/dist/gateway/index.d.ts.map +1 -1
- package/dist/gateway/index.js.map +1 -1
- package/dist/gateway/storage-gateway-fastify-parser.d.ts.map +1 -1
- package/dist/gateway/storage-gateway-fastify-parser.js.map +1 -1
- package/dist/gateway/storage-gateway.controller.d.ts +12 -11
- package/dist/gateway/storage-gateway.controller.d.ts.map +1 -1
- package/dist/gateway/storage-gateway.controller.js +240 -70
- package/dist/gateway/storage-gateway.controller.js.map +1 -1
- package/dist/gateway/storage-gateway.guard.d.ts.map +1 -1
- package/dist/gateway/storage-gateway.guard.js.map +1 -1
- package/dist/gateway/storage-gateway.module.d.ts.map +1 -1
- package/dist/gateway/storage-gateway.module.js +60 -1
- package/dist/gateway/storage-gateway.module.js.map +1 -1
- package/dist/gateway/storage-gateway.tokens.d.ts +1 -0
- package/dist/gateway/storage-gateway.tokens.d.ts.map +1 -1
- package/dist/gateway/storage-gateway.tokens.js +1 -0
- package/dist/gateway/storage-gateway.tokens.js.map +1 -1
- package/dist/gateway/storage-gateway.types.d.ts +53 -10
- package/dist/gateway/storage-gateway.types.d.ts.map +1 -1
- package/dist/gateway/storage-gateway.types.js.map +1 -1
- package/dist/inject-storage.decorator.js.map +1 -1
- package/dist/storage-etag.d.ts +13 -0
- package/dist/storage-etag.d.ts.map +1 -0
- package/dist/storage-etag.js +31 -0
- package/dist/storage-etag.js.map +1 -0
- package/dist/storage-upload-control.d.ts.map +1 -1
- package/dist/storage.client.d.ts +14 -1
- package/dist/storage.client.d.ts.map +1 -1
- package/dist/storage.client.js +204 -2
- package/dist/storage.client.js.map +1 -1
- package/dist/storage.driver.d.ts +28 -1
- package/dist/storage.driver.d.ts.map +1 -1
- package/dist/storage.driver.js.map +1 -1
- package/dist/storage.error.d.ts +17 -10
- package/dist/storage.error.d.ts.map +1 -1
- package/dist/storage.error.js +47 -1
- package/dist/storage.error.js.map +1 -1
- package/dist/storage.module.d.ts.map +1 -1
- package/dist/storage.module.js.map +1 -1
- package/dist/storage.service.d.ts.map +1 -1
- package/dist/storage.service.js +28 -3
- package/dist/storage.service.js.map +1 -1
- package/dist/storage.tokens.js.map +1 -1
- package/dist/storage.types.d.ts +150 -1
- package/dist/storage.types.d.ts.map +1 -1
- package/dist/storage.types.js.map +1 -1
- package/dist/testing/index.d.ts +1 -0
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js +3 -1
- package/dist/testing/index.js.map +1 -1
- package/dist/testing/provider-conformance.d.ts +65 -0
- package/dist/testing/provider-conformance.d.ts.map +1 -0
- package/dist/testing/provider-conformance.js +869 -0
- package/dist/testing/provider-conformance.js.map +1 -0
- package/dist/workspace/index.d.ts +12 -0
- package/dist/workspace/index.d.ts.map +1 -0
- package/dist/workspace/index.js +10 -0
- package/dist/workspace/index.js.map +1 -0
- package/dist/workspace/storage-catalog-checkout.d.ts +7 -0
- package/dist/workspace/storage-catalog-checkout.d.ts.map +1 -0
- package/dist/workspace/storage-catalog-checkout.js +13 -0
- package/dist/workspace/storage-catalog-checkout.js.map +1 -0
- package/dist/workspace/storage-draft-stream.d.ts +3 -0
- package/dist/workspace/storage-draft-stream.d.ts.map +1 -0
- package/dist/workspace/storage-draft-stream.js +57 -0
- package/dist/workspace/storage-draft-stream.js.map +1 -0
- package/dist/workspace/storage-file-catalog.types.d.ts +73 -0
- package/dist/workspace/storage-file-catalog.types.d.ts.map +1 -0
- package/dist/workspace/storage-file-catalog.types.js +2 -0
- package/dist/workspace/storage-file-catalog.types.js.map +1 -0
- package/dist/workspace/storage-file-workflow.d.ts +7 -0
- package/dist/workspace/storage-file-workflow.d.ts.map +1 -0
- package/dist/workspace/storage-file-workflow.js +657 -0
- package/dist/workspace/storage-file-workflow.js.map +1 -0
- package/dist/workspace/storage-file-workflow.protection.d.ts +31 -0
- package/dist/workspace/storage-file-workflow.protection.d.ts.map +1 -0
- package/dist/workspace/storage-file-workflow.protection.js +339 -0
- package/dist/workspace/storage-file-workflow.protection.js.map +1 -0
- package/dist/workspace/storage-file-workflow.types.d.ts +184 -0
- package/dist/workspace/storage-file-workflow.types.d.ts.map +1 -0
- package/dist/workspace/storage-file-workflow.types.js +10 -0
- package/dist/workspace/storage-file-workflow.types.js.map +1 -0
- package/dist/workspace/storage-text-draft.d.ts +21 -0
- package/dist/workspace/storage-text-draft.d.ts.map +1 -0
- package/dist/workspace/storage-text-draft.js +77 -0
- package/dist/workspace/storage-text-draft.js.map +1 -0
- package/dist/workspace/storage-working-files.d.ts +34 -0
- package/dist/workspace/storage-working-files.d.ts.map +1 -0
- package/dist/workspace/storage-working-files.js +326 -0
- package/dist/workspace/storage-working-files.js.map +1 -0
- package/dist/workspace/storage-workspace.cursor.d.ts +71 -0
- package/dist/workspace/storage-workspace.cursor.d.ts.map +1 -0
- package/dist/workspace/storage-workspace.cursor.js +408 -0
- package/dist/workspace/storage-workspace.cursor.js.map +1 -0
- package/dist/workspace/storage-workspace.d.ts +6 -0
- package/dist/workspace/storage-workspace.d.ts.map +1 -0
- package/dist/workspace/storage-workspace.error.d.ts +32 -0
- package/dist/workspace/storage-workspace.error.d.ts.map +1 -0
- package/dist/workspace/storage-workspace.error.js +75 -0
- package/dist/workspace/storage-workspace.error.js.map +1 -0
- package/dist/workspace/storage-workspace.js +849 -0
- package/dist/workspace/storage-workspace.js.map +1 -0
- package/dist/workspace/storage-workspace.path.d.ts +9 -0
- package/dist/workspace/storage-workspace.path.d.ts.map +1 -0
- package/dist/workspace/storage-workspace.path.js +68 -0
- package/dist/workspace/storage-workspace.path.js.map +1 -0
- package/dist/workspace/storage-workspace.types.d.ts +123 -0
- package/dist/workspace/storage-workspace.types.d.ts.map +1 -0
- package/dist/workspace/storage-workspace.types.js +22 -0
- package/dist/workspace/storage-workspace.types.js.map +1 -0
- package/package.json +99 -20
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** Maximum UTF-8 byte length of a normalized storage ETag. */
|
|
2
|
+
export const MAX_STORAGE_ETAG_BYTES = 1024;
|
|
3
|
+
// Deliberately narrower than RFC 9110's etagc grammar. Commas and backslashes
|
|
4
|
+
// are excluded so a normalized value cannot be confused with an entity-tag
|
|
5
|
+
// list or be interpreted differently by legacy HTTP implementations.
|
|
6
|
+
const canonicalStorageEtag = /^(?!\*$)(?![Ww]\/)[\x21\x23-\x2B\x2D-\x5B\x5D-\x7E]+$/u;
|
|
7
|
+
/** Returns whether a value is the package's canonical bare ETag form. */
|
|
8
|
+
export function isCanonicalStorageEtag(value) {
|
|
9
|
+
return (typeof value === 'string' &&
|
|
10
|
+
value.length <= MAX_STORAGE_ETAG_BYTES &&
|
|
11
|
+
canonicalStorageEtag.test(value));
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Normalizes one provider-returned strong entity tag to the canonical bare
|
|
15
|
+
* form. Providers may return either the HTTP-quoted representation or an
|
|
16
|
+
* already-normalized value; lists, weak tags, and malformed values fail.
|
|
17
|
+
*/
|
|
18
|
+
export function normalizeProviderStorageEtag(value) {
|
|
19
|
+
if (typeof value !== 'string') {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
const opaque = value.startsWith('"') && value.endsWith('"') && value.length >= 3
|
|
23
|
+
? value.slice(1, -1)
|
|
24
|
+
: value;
|
|
25
|
+
return isCanonicalStorageEtag(opaque) ? opaque : undefined;
|
|
26
|
+
}
|
|
27
|
+
/** Serializes one canonical bare ETag as exactly one HTTP entity tag. */
|
|
28
|
+
export function storageEtagHeader(value) {
|
|
29
|
+
return isCanonicalStorageEtag(value) ? `"${value}"` : undefined;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=storage-etag.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage-etag.js","sourceRoot":"","sources":["../src/storage-etag.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAC9D,MAAM,CAAC,MAAM,sBAAsB,GAAG,IAAI,CAAC;AAE3C,8EAA8E;AAC9E,2EAA2E;AAC3E,qEAAqE;AACrE,MAAM,oBAAoB,GACxB,wDAAwD,CAAC;AAE3D,yEAAyE;AACzE,MAAM,UAAU,sBAAsB,CAAC,KAAc;IACnD,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,CAAC,MAAM,IAAI,sBAAsB;QACtC,oBAAoB,CAAC,IAAI,CAAC,KAAK,CAAC,CACjC,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,4BAA4B,CAC1C,KAAc;IAEd,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,MAAM,MAAM,GACV,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,MAAM,IAAI,CAAC;QAC/D,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QACpB,CAAC,CAAC,KAAK,CAAC;IACZ,OAAO,sBAAsB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;AAC7D,CAAC;AAED,yEAAyE;AACzE,MAAM,UAAU,iBAAiB,CAAC,KAAc;IAC9C,OAAO,sBAAsB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC;AAClE,CAAC","sourcesContent":["/** Maximum UTF-8 byte length of a normalized storage ETag. */\nexport const MAX_STORAGE_ETAG_BYTES = 1024;\n\n// Deliberately narrower than RFC 9110's etagc grammar. Commas and backslashes\n// are excluded so a normalized value cannot be confused with an entity-tag\n// list or be interpreted differently by legacy HTTP implementations.\nconst canonicalStorageEtag =\n /^(?!\\*$)(?![Ww]\\/)[\\x21\\x23-\\x2B\\x2D-\\x5B\\x5D-\\x7E]+$/u;\n\n/** Returns whether a value is the package's canonical bare ETag form. */\nexport function isCanonicalStorageEtag(value: unknown): value is string {\n return (\n typeof value === 'string' &&\n value.length <= MAX_STORAGE_ETAG_BYTES &&\n canonicalStorageEtag.test(value)\n );\n}\n\n/**\n * Normalizes one provider-returned strong entity tag to the canonical bare\n * form. Providers may return either the HTTP-quoted representation or an\n * already-normalized value; lists, weak tags, and malformed values fail.\n */\nexport function normalizeProviderStorageEtag(\n value: unknown,\n): string | undefined {\n if (typeof value !== 'string') {\n return undefined;\n }\n const opaque =\n value.startsWith('\"') && value.endsWith('\"') && value.length >= 3\n ? value.slice(1, -1)\n : value;\n return isCanonicalStorageEtag(opaque) ? opaque : undefined;\n}\n\n/** Serializes one canonical bare ETag as exactly one HTTP entity tag. */\nexport function storageEtagHeader(value: unknown): string | undefined {\n return isCanonicalStorageEtag(value) ? `\"${value}\"` : undefined;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage-upload-control.d.ts","sourceRoot":"","sources":["../src/storage-upload-control.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,mBAAmB,GAC7B,MAAM,GAAG,WAAW,GAAG,QAAQ,GAAG,WAAW,GAAG,SAAS,GAAG,OAAO,CAAC;AAEtE;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;IACpB,QAAQ,CAAC,MAAM,EAAE,0BAA0B,CAAC;IAC5C,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B;AAkHD,qBAAa,oBAAoB
|
|
1
|
+
{"version":3,"file":"storage-upload-control.d.ts","sourceRoot":"","sources":["../src/storage-upload-control.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,mBAAmB,GAC7B,MAAM,GAAG,WAAW,GAAG,QAAQ,GAAG,WAAW,GAAG,SAAS,GAAG,OAAO,CAAC;AAEtE;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;IACpB,QAAQ,CAAC,MAAM,EAAE,0BAA0B,CAAC;IAC5C,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B;AAkHD,qBAAa,oBAAoB;IAC/B,cAEC;IAED,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,GAAG,oBAAoB,CAiBhD;IAED,IAAI,MAAM,IAAI,mBAAmB,CAEhC;IAED,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,IAAI,KAAK,IAAI,MAAM,GAAG,SAAS,CAE9B;IAED,KAAK,IAAI,IAAI,CAEZ;IAED,MAAM,IAAI,IAAI,CAEb;IAED,KAAK,CAAC,MAAM,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAErC;IAED,MAAM,IAAI,qBAAqB,GAAG,SAAS,CAW1C;CACF"}
|
package/dist/storage.client.d.ts
CHANGED
|
@@ -1,21 +1,26 @@
|
|
|
1
1
|
import type { StorageDriver } from './storage.driver.js';
|
|
2
|
-
import type { StorageBody, StorageBufferedDownloadOptions, StorageBulkOptions, StorageCapabilities, StorageDeleteManyResult, StorageDownloadManyResult, StorageDownloadOptions, StorageExistsManyResult, StorageHeadManyResult, StorageListOptions, StorageListResult, StorageObject, StorageObjectMetadata, StorageOperationOptions, StoragePlugin, StorageSearchOptions, StorageSignedDownloadOptions, StorageSignedUpload, StorageSignedUploadOptions, StorageUploadManyItem, StorageUploadManyOptions, StorageUploadManyResult, StorageUploadOptions, StorageUploadResult } from './storage.types.js';
|
|
2
|
+
import type { StorageBody, StorageBufferedDownloadOptions, StorageBulkOptions, StorageCapabilities, StorageConditionalDeleteOptions, StorageConditionalReadOptions, StorageConditionalUploadOptions, StorageDeleteManyResult, StorageDownloadManyResult, StorageDownloadOptions, StorageExistsManyResult, StorageHeadManyResult, StorageListOptions, StorageListResult, StorageObject, StorageObjectMetadata, StorageOperationOptions, StoragePlugin, StoragePromotionOptions, StorageSearchOptions, StorageSignedDownloadOptions, StorageSignedUpload, StorageSignedUploadOptions, StorageUploadManyItem, StorageUploadManyOptions, StorageUploadManyResult, StorageUploadOptions, StorageUploadResult } from './storage.types.js';
|
|
3
3
|
export declare const DEFAULT_BUFFER_LIMIT: number;
|
|
4
4
|
type BulkOperationOptions = StorageBulkOptions & StorageOperationOptions;
|
|
5
5
|
type DownloadManyOptions = StorageBulkOptions & StorageDownloadOptions;
|
|
6
6
|
export interface StorageFileHandle {
|
|
7
7
|
readonly key: string;
|
|
8
8
|
upload(body: StorageBody, options?: StorageUploadOptions): Promise<StorageUploadResult>;
|
|
9
|
+
uploadConditional(body: StorageBody, options: StorageConditionalUploadOptions): Promise<StorageUploadResult>;
|
|
9
10
|
download(options?: StorageDownloadOptions): Promise<StorageObject>;
|
|
11
|
+
downloadConditional(options: StorageConditionalReadOptions): Promise<StorageObject>;
|
|
10
12
|
bytes(options?: StorageBufferedDownloadOptions): Promise<Uint8Array>;
|
|
11
13
|
text(options?: StorageBufferedDownloadOptions): Promise<string>;
|
|
12
14
|
head(options?: StorageOperationOptions): Promise<StorageObjectMetadata>;
|
|
13
15
|
exists(options?: StorageOperationOptions): Promise<boolean>;
|
|
14
16
|
delete(options?: StorageOperationOptions): Promise<void>;
|
|
17
|
+
deleteConditional(options: StorageConditionalDeleteOptions): Promise<void>;
|
|
15
18
|
signDownload(options?: StorageSignedDownloadOptions): Promise<string>;
|
|
16
19
|
signUpload(options: StorageSignedUploadOptions): Promise<StorageSignedUpload>;
|
|
17
20
|
copyTo(destinationKey: string, options?: StorageOperationOptions): Promise<void>;
|
|
18
21
|
moveTo(destinationKey: string, options?: StorageOperationOptions): Promise<void>;
|
|
22
|
+
/** Conditionally copies this staged object and deliberately retains it. */
|
|
23
|
+
promoteTo(destinationKey: string, options: StoragePromotionOptions): Promise<void>;
|
|
19
24
|
}
|
|
20
25
|
export declare class StorageClient {
|
|
21
26
|
#private;
|
|
@@ -25,15 +30,23 @@ export declare class StorageClient {
|
|
|
25
30
|
get capabilities(): Readonly<StorageCapabilities>;
|
|
26
31
|
file(key: string): StorageFileHandle;
|
|
27
32
|
upload(key: string, body: StorageBody, options?: StorageUploadOptions): Promise<StorageUploadResult>;
|
|
33
|
+
uploadConditional(key: string, body: StorageBody, options: StorageConditionalUploadOptions): Promise<StorageUploadResult>;
|
|
28
34
|
downloadStream(key: string, options?: StorageDownloadOptions): Promise<StorageObject>;
|
|
35
|
+
downloadConditional(key: string, options: StorageConditionalReadOptions): Promise<StorageObject>;
|
|
29
36
|
downloadBytes(key: string, options?: StorageBufferedDownloadOptions): Promise<Uint8Array>;
|
|
30
37
|
downloadText(key: string, options?: StorageBufferedDownloadOptions): Promise<string>;
|
|
31
38
|
downloadJson<Result = unknown>(key: string, options?: StorageBufferedDownloadOptions): Promise<Result>;
|
|
32
39
|
head(key: string, options?: StorageOperationOptions): Promise<StorageObjectMetadata>;
|
|
33
40
|
exists(key: string, options?: StorageOperationOptions): Promise<boolean>;
|
|
34
41
|
delete(key: string, options?: StorageOperationOptions): Promise<void>;
|
|
42
|
+
deleteConditional(key: string, options: StorageConditionalDeleteOptions): Promise<void>;
|
|
35
43
|
copy(sourceKey: string, destinationKey: string, options?: StorageOperationOptions): Promise<void>;
|
|
36
44
|
move(sourceKey: string, destinationKey: string, options?: StorageOperationOptions): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Conditionally copies a staged object to a final key. This operation does
|
|
47
|
+
* not delete the source; delete it after the application commit succeeds.
|
|
48
|
+
*/
|
|
49
|
+
promote(sourceKey: string, destinationKey: string, options: StoragePromotionOptions): Promise<void>;
|
|
37
50
|
list(options?: StorageListOptions): Promise<StorageListResult>;
|
|
38
51
|
listAll(options?: StorageListOptions): AsyncGenerator<StorageObjectMetadata, void>;
|
|
39
52
|
search(pattern: string | RegExp, options?: StorageSearchOptions): AsyncIterable<StorageObjectMetadata>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage.client.d.ts","sourceRoot":"","sources":["../src/storage.client.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"storage.client.d.ts","sourceRoot":"","sources":["../src/storage.client.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EACV,WAAW,EACX,8BAA8B,EAC9B,kBAAkB,EAClB,mBAAmB,EACnB,+BAA+B,EAC/B,6BAA6B,EAC7B,+BAA+B,EAC/B,uBAAuB,EACvB,yBAAyB,EACzB,sBAAsB,EACtB,uBAAuB,EACvB,qBAAqB,EACrB,kBAAkB,EAClB,iBAAiB,EACjB,aAAa,EACb,qBAAqB,EAErB,uBAAuB,EACvB,aAAa,EACb,uBAAuB,EACvB,oBAAoB,EACpB,4BAA4B,EAC5B,mBAAmB,EACnB,0BAA0B,EAC1B,qBAAqB,EACrB,wBAAwB,EACxB,uBAAuB,EACvB,oBAAoB,EACpB,mBAAmB,EACpB,MAAM,oBAAoB,CAAC;AAE5B,eAAO,MAAM,oBAAoB,QAAmB,CAAC;AAErD,KAAK,oBAAoB,GAAG,kBAAkB,GAAG,uBAAuB,CAAC;AACzE,KAAK,mBAAmB,GAAG,kBAAkB,GAAG,sBAAsB,CAAC;AAyKvE,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,MAAM,CACJ,IAAI,EAAE,WAAW,EACjB,OAAO,CAAC,EAAE,oBAAoB,GAC7B,OAAO,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AK,EAAE,SAAS,qBAAqB,EAAE,EACvC,OAAO,CAAC,EAAE,wBAAwB,GACjC,OAAO,CAAC,uBAAuB,CAAC,CA6BlC;IAEK,YAAY,CAChB,IAAI,EAAE,SAAS,MAAM,EAAE,EACvB,OAAO,CAAC,EAAE,mBAAmB,GAC5B,OAAO,CAAC,yBAAyB,CAAC,CAWpC;IAEK,QAAQ,CACZ,IAAI,EAAE,SAAS,MAAM,EAAE,EACvB,OAAO,CAAC,EAAE,oBAAoB,GAC7B,OAAO,CAAC,qBAAqB,CAAC,CAWhC;IAEK,UAAU,CACd,IAAI,EAAE,SAAS,MAAM,EAAE,EACvB,OAAO,CAAC,EAAE,oBAAoB,GAC7B,OAAO,CAAC,uBAAuB,CAAC,CAiBlC;IAEK,UAAU,CACd,IAAI,EAAE,SAAS,MAAM,EAAE,EACvB,OAAO,CAAC,EAAE,oBAAoB,GAC7B,OAAO,CAAC,uBAAuB,CAAC,CAclC;IAEK,qBAAqB,IAAI,OAAO,CAAC,IAAI,CAAC,CAM3C;CA0DF"}
|
package/dist/storage.client.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { settleMany } from './internal/settle-many.js';
|
|
2
|
+
import { isCanonicalStorageEtag } from './storage-etag.js';
|
|
2
3
|
import { StorageError, StorageErrorCode, normalizeStorageError, } from './storage.error.js';
|
|
3
4
|
export const DEFAULT_BUFFER_LIMIT = 10 * 1024 * 1024;
|
|
4
5
|
function assertKey(key, label = 'key') {
|
|
@@ -146,27 +147,116 @@ export class StorageClient {
|
|
|
146
147
|
return {
|
|
147
148
|
copyTo: (destinationKey, options) => this.copy(key, destinationKey, options),
|
|
148
149
|
delete: (options) => this.delete(key, options),
|
|
150
|
+
deleteConditional: (options) => this.deleteConditional(key, options),
|
|
149
151
|
download: (options) => this.downloadStream(key, options),
|
|
152
|
+
downloadConditional: (options) => this.downloadConditional(key, options),
|
|
150
153
|
exists: (options) => this.exists(key, options),
|
|
151
154
|
head: (options) => this.head(key, options),
|
|
152
155
|
key,
|
|
153
156
|
moveTo: (destinationKey, options) => this.move(key, destinationKey, options),
|
|
157
|
+
promoteTo: (destinationKey, options) => this.promote(key, destinationKey, options),
|
|
154
158
|
signDownload: (options) => this.signDownload(key, options),
|
|
155
159
|
signUpload: (options) => this.signUpload(key, options),
|
|
156
160
|
bytes: (options) => this.downloadBytes(key, options),
|
|
157
161
|
text: (options) => this.downloadText(key, options),
|
|
158
162
|
upload: (body, options) => this.upload(key, body, options),
|
|
163
|
+
uploadConditional: (body, options) => this.uploadConditional(key, body, options),
|
|
159
164
|
};
|
|
160
165
|
}
|
|
161
166
|
upload(key, body, options) {
|
|
162
167
|
assertKey(key);
|
|
163
168
|
return this.#execute({ key, operation: 'upload', store: this.name }, () => this.#driver.upload(key, body, options));
|
|
164
169
|
}
|
|
170
|
+
uploadConditional(key, body, options) {
|
|
171
|
+
assertKey(key);
|
|
172
|
+
const condition = options.condition;
|
|
173
|
+
if (condition === undefined ||
|
|
174
|
+
(condition.type !== 'create' && condition.type !== 'replace')) {
|
|
175
|
+
invalidArgument('condition.type must be "create" or "replace".');
|
|
176
|
+
}
|
|
177
|
+
if (condition.type === 'replace' &&
|
|
178
|
+
!isCanonicalStorageEtag(condition.etag)) {
|
|
179
|
+
invalidArgument('condition.etag must be a canonical storage ETag.');
|
|
180
|
+
}
|
|
181
|
+
const capability = condition.type === 'create'
|
|
182
|
+
? this.#driver.capabilities.conditionalCreate
|
|
183
|
+
: this.#driver.capabilities.conditionalReplace;
|
|
184
|
+
const uploadConditional = this.#driver.uploadConditional;
|
|
185
|
+
const multipartRequested = options.multipart !== undefined && options.multipart !== false;
|
|
186
|
+
const multipartCapability = this.#driver.capabilities.conditionalMultipartCompletion;
|
|
187
|
+
const multipartSupported = !multipartRequested ||
|
|
188
|
+
(condition.type === 'create'
|
|
189
|
+
? multipartCapability?.create === true
|
|
190
|
+
: multipartCapability?.replace === true);
|
|
191
|
+
if (capability === undefined ||
|
|
192
|
+
!multipartSupported ||
|
|
193
|
+
uploadConditional === undefined) {
|
|
194
|
+
throw new StorageError(`Store "${this.name}" does not support the requested conditional upload.`, {
|
|
195
|
+
code: StorageErrorCode.NOT_SUPPORTED,
|
|
196
|
+
key,
|
|
197
|
+
operation: 'upload',
|
|
198
|
+
permanent: true,
|
|
199
|
+
store: this.name,
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
return this.#execute({ key, operation: 'upload', store: this.name }, () => uploadConditional.call(this.#driver, key, body, options), (result) => {
|
|
203
|
+
if (capability.resultEtag && !isCanonicalStorageEtag(result.etag)) {
|
|
204
|
+
throw new StorageError(`Store "${this.name}" committed a conditional upload without the advertised result ETag.`, {
|
|
205
|
+
code: StorageErrorCode.PROVIDER,
|
|
206
|
+
key,
|
|
207
|
+
operation: 'upload',
|
|
208
|
+
permanent: true,
|
|
209
|
+
store: this.name,
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
return {
|
|
213
|
+
...(isCanonicalStorageEtag(result.etag) && {
|
|
214
|
+
appliedEtag: result.etag,
|
|
215
|
+
}),
|
|
216
|
+
};
|
|
217
|
+
});
|
|
218
|
+
}
|
|
165
219
|
downloadStream(key, options) {
|
|
166
220
|
assertKey(key);
|
|
167
221
|
assertDownloadOptions(options);
|
|
168
222
|
return this.#execute({ key, operation: 'download', store: this.name }, () => this.#driver.download(key, options));
|
|
169
223
|
}
|
|
224
|
+
downloadConditional(key, options) {
|
|
225
|
+
assertKey(key);
|
|
226
|
+
assertDownloadOptions(options);
|
|
227
|
+
if (options === undefined ||
|
|
228
|
+
options.condition === undefined ||
|
|
229
|
+
typeof options.condition !== 'object' ||
|
|
230
|
+
options.condition === null) {
|
|
231
|
+
invalidArgument('conditional read requires a condition object.');
|
|
232
|
+
}
|
|
233
|
+
const { etag, version } = options.condition;
|
|
234
|
+
if (etag !== undefined && !isCanonicalStorageEtag(etag)) {
|
|
235
|
+
invalidArgument('condition.etag must be a canonical storage ETag.');
|
|
236
|
+
}
|
|
237
|
+
if (version !== undefined &&
|
|
238
|
+
(typeof version !== 'string' || version.length === 0)) {
|
|
239
|
+
invalidArgument('condition.version must be a non-empty string.');
|
|
240
|
+
}
|
|
241
|
+
if (etag === undefined && version === undefined) {
|
|
242
|
+
invalidArgument('conditional read requires an etag, version, or both.');
|
|
243
|
+
}
|
|
244
|
+
const capability = this.#driver.capabilities.conditionalRead;
|
|
245
|
+
const downloadConditional = this.#driver.downloadConditional;
|
|
246
|
+
if (downloadConditional === undefined ||
|
|
247
|
+
capability === undefined ||
|
|
248
|
+
(etag !== undefined && !capability.etag) ||
|
|
249
|
+
(version !== undefined && !capability.version)) {
|
|
250
|
+
throw new StorageError(`Store "${this.name}" does not support the requested conditional read.`, {
|
|
251
|
+
code: StorageErrorCode.NOT_SUPPORTED,
|
|
252
|
+
key,
|
|
253
|
+
operation: 'download',
|
|
254
|
+
permanent: true,
|
|
255
|
+
store: this.name,
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
return this.#execute({ key, operation: 'download', store: this.name }, () => downloadConditional.call(this.#driver, key, options));
|
|
259
|
+
}
|
|
170
260
|
async downloadBytes(key, options) {
|
|
171
261
|
const { maxBytes = DEFAULT_BUFFER_LIMIT, ...download } = options ?? {};
|
|
172
262
|
const object = await this.downloadStream(key, download);
|
|
@@ -203,6 +293,25 @@ export class StorageClient {
|
|
|
203
293
|
assertKey(key);
|
|
204
294
|
return this.#execute({ key, operation: 'delete', store: this.name }, () => this.#driver.delete(key, options));
|
|
205
295
|
}
|
|
296
|
+
deleteConditional(key, options) {
|
|
297
|
+
assertKey(key);
|
|
298
|
+
if (options.condition === undefined ||
|
|
299
|
+
!isCanonicalStorageEtag(options.condition.etag)) {
|
|
300
|
+
invalidArgument('condition.etag must be a canonical storage ETag.');
|
|
301
|
+
}
|
|
302
|
+
const capability = this.#driver.capabilities.conditionalDelete;
|
|
303
|
+
const deleteConditional = this.#driver.deleteConditional;
|
|
304
|
+
if (capability?.etag !== true || deleteConditional === undefined) {
|
|
305
|
+
throw new StorageError(`Store "${this.name}" does not support conditional delete.`, {
|
|
306
|
+
code: StorageErrorCode.NOT_SUPPORTED,
|
|
307
|
+
key,
|
|
308
|
+
operation: 'delete',
|
|
309
|
+
permanent: true,
|
|
310
|
+
store: this.name,
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
return this.#execute({ key, operation: 'delete', store: this.name }, () => deleteConditional.call(this.#driver, key, options), () => ({}));
|
|
314
|
+
}
|
|
206
315
|
copy(sourceKey, destinationKey, options) {
|
|
207
316
|
assertKey(sourceKey, 'source key');
|
|
208
317
|
assertKey(destinationKey, 'destination key');
|
|
@@ -223,6 +332,73 @@ export class StorageClient {
|
|
|
223
332
|
to: destinationKey,
|
|
224
333
|
}, () => this.#driver.move(sourceKey, destinationKey, options));
|
|
225
334
|
}
|
|
335
|
+
/**
|
|
336
|
+
* Conditionally copies a staged object to a final key. This operation does
|
|
337
|
+
* not delete the source; delete it after the application commit succeeds.
|
|
338
|
+
*/
|
|
339
|
+
promote(sourceKey, destinationKey, options) {
|
|
340
|
+
assertKey(sourceKey, 'source key');
|
|
341
|
+
assertKey(destinationKey, 'destination key');
|
|
342
|
+
const sourceEtag = options.sourceEtag;
|
|
343
|
+
const sourceVersion = options.sourceVersion;
|
|
344
|
+
if (sourceEtag !== undefined && !isCanonicalStorageEtag(sourceEtag)) {
|
|
345
|
+
invalidArgument('sourceEtag must be a canonical storage ETag.');
|
|
346
|
+
}
|
|
347
|
+
if (sourceVersion !== undefined &&
|
|
348
|
+
(typeof sourceVersion !== 'string' || sourceVersion.length === 0)) {
|
|
349
|
+
invalidArgument('sourceVersion must be a non-empty string.');
|
|
350
|
+
}
|
|
351
|
+
const destination = options.destination;
|
|
352
|
+
if (destination !== undefined &&
|
|
353
|
+
(typeof destination !== 'object' ||
|
|
354
|
+
destination === null ||
|
|
355
|
+
(destination.type !== 'create' && destination.type !== 'replace'))) {
|
|
356
|
+
invalidArgument('destination.type must be "create" or "replace".');
|
|
357
|
+
}
|
|
358
|
+
if (sourceEtag === undefined &&
|
|
359
|
+
sourceVersion === undefined &&
|
|
360
|
+
destination === undefined) {
|
|
361
|
+
invalidArgument('promote requires a source or destination precondition.');
|
|
362
|
+
}
|
|
363
|
+
if (destination?.type === 'replace' &&
|
|
364
|
+
!isCanonicalStorageEtag(destination.etag)) {
|
|
365
|
+
invalidArgument('destination.etag must be a canonical storage ETag.');
|
|
366
|
+
}
|
|
367
|
+
const sourceCapability = this.#driver.capabilities.conditionalCopySource;
|
|
368
|
+
const destinationCapability = this.#driver.capabilities.conditionalCopyDestination;
|
|
369
|
+
const promote = this.#driver.promote;
|
|
370
|
+
const hasSourcePredicate = sourceEtag !== undefined || sourceVersion !== undefined;
|
|
371
|
+
if (promote === undefined ||
|
|
372
|
+
(sourceEtag !== undefined && sourceCapability?.etag !== true) ||
|
|
373
|
+
(sourceVersion !== undefined && sourceCapability?.version !== true) ||
|
|
374
|
+
(hasSourcePredicate &&
|
|
375
|
+
destination === undefined &&
|
|
376
|
+
sourceCapability?.requiresDestinationPredicate === true) ||
|
|
377
|
+
(destination?.type === 'create' &&
|
|
378
|
+
destinationCapability?.create !== true) ||
|
|
379
|
+
(destination?.type === 'replace' &&
|
|
380
|
+
destinationCapability?.replace !== true) ||
|
|
381
|
+
(destination !== undefined &&
|
|
382
|
+
!hasSourcePredicate &&
|
|
383
|
+
destinationCapability?.requiresSourcePredicate === true) ||
|
|
384
|
+
(destination !== undefined &&
|
|
385
|
+
hasSourcePredicate &&
|
|
386
|
+
destinationCapability?.atomicWithSource !== true)) {
|
|
387
|
+
throw new StorageError(`Store "${this.name}" does not support the requested conditional promotion.`, {
|
|
388
|
+
code: StorageErrorCode.NOT_SUPPORTED,
|
|
389
|
+
key: sourceKey,
|
|
390
|
+
operation: 'promote',
|
|
391
|
+
permanent: true,
|
|
392
|
+
store: this.name,
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
return this.#execute({
|
|
396
|
+
from: sourceKey,
|
|
397
|
+
operation: 'promote',
|
|
398
|
+
store: this.name,
|
|
399
|
+
to: destinationKey,
|
|
400
|
+
}, () => promote.call(this.#driver, sourceKey, destinationKey, options), () => ({}));
|
|
401
|
+
}
|
|
226
402
|
list(options) {
|
|
227
403
|
assertListOptions(options);
|
|
228
404
|
return this.#execute({ operation: 'list', store: this.name }, () => this.#driver.list(options));
|
|
@@ -363,23 +539,49 @@ export class StorageClient {
|
|
|
363
539
|
this.#closed = true;
|
|
364
540
|
await this.#driver.close?.();
|
|
365
541
|
}
|
|
366
|
-
async #execute(context, operation) {
|
|
542
|
+
async #execute(context, operation, appliedMutation) {
|
|
543
|
+
let appliedSettlement;
|
|
367
544
|
try {
|
|
368
545
|
for (const plugin of this.#plugins) {
|
|
369
546
|
await plugin.beforeOperation?.(context);
|
|
370
547
|
}
|
|
371
548
|
const result = await operation();
|
|
549
|
+
if (appliedMutation !== undefined) {
|
|
550
|
+
// Settle before describing the result so even an unexpected local
|
|
551
|
+
// result-validation failure cannot turn a committed mutation into a
|
|
552
|
+
// safe-to-retry error.
|
|
553
|
+
appliedSettlement = {};
|
|
554
|
+
appliedSettlement = appliedMutation(result);
|
|
555
|
+
}
|
|
372
556
|
for (const plugin of this.#plugins) {
|
|
373
557
|
await plugin.afterOperation?.(context, result);
|
|
374
558
|
}
|
|
375
559
|
return result;
|
|
376
560
|
}
|
|
377
561
|
catch (error) {
|
|
378
|
-
|
|
562
|
+
let normalized = normalizeStorageError(error, {
|
|
379
563
|
...(context.key !== undefined && { key: context.key }),
|
|
380
564
|
operation: context.operation,
|
|
381
565
|
store: this.name,
|
|
382
566
|
});
|
|
567
|
+
if (appliedSettlement !== undefined) {
|
|
568
|
+
normalized = new StorageError(normalized.message, {
|
|
569
|
+
aborted: normalized.aborted,
|
|
570
|
+
applied: true,
|
|
571
|
+
...(isCanonicalStorageEtag(appliedSettlement.appliedEtag) && {
|
|
572
|
+
appliedEtag: appliedSettlement.appliedEtag,
|
|
573
|
+
}),
|
|
574
|
+
cause: normalized.cause,
|
|
575
|
+
code: normalized.code,
|
|
576
|
+
...(normalized.key !== undefined && { key: normalized.key }),
|
|
577
|
+
...(normalized.operation !== undefined && {
|
|
578
|
+
operation: normalized.operation,
|
|
579
|
+
}),
|
|
580
|
+
permanent: normalized.permanent,
|
|
581
|
+
...(normalized.store !== undefined && { store: normalized.store }),
|
|
582
|
+
timedOut: normalized.timedOut,
|
|
583
|
+
});
|
|
584
|
+
}
|
|
383
585
|
for (const plugin of this.#plugins) {
|
|
384
586
|
try {
|
|
385
587
|
await plugin.onError?.(context, normalized);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage.client.js","sourceRoot":"","sources":["../src/storage.client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACvD,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,qBAAqB,GACtB,MAAM,oBAAoB,CAAC;AA8B5B,MAAM,CAAC,MAAM,oBAAoB,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AAKrD,SAAS,SAAS,CAAC,GAAW,EAAE,KAAK,GAAG,KAAK;IAC3C,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAChD,MAAM,IAAI,YAAY,CAAC,GAAG,KAAK,8BAA8B,EAAE;YAC7D,IAAI,EAAE,gBAAgB,CAAC,gBAAgB;YACvC,SAAS,EAAE,IAAI;SAChB,CAAC,CAAC;IACL,CAAC;AACH,CAAC;AAED,SAAS,eAAe,CAAC,OAAe;IACtC,MAAM,IAAI,YAAY,CAAC,OAAO,EAAE;QAC9B,IAAI,EAAE,gBAAgB,CAAC,gBAAgB;QACvC,SAAS,EAAE,IAAI;KAChB,CAAC,CAAC;AACL,CAAC;AAED,SAAS,yBAAyB,CAChC,KAAyB,EACzB,KAAa;IAEb,IAAI,KAAK,KAAK,SAAS,IAAI,CAAC,CAAC,MAAM,CAAC,aAAa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O,EAAE,CAAC;YACjB,OAAO;QACT,CAAC;QACD,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QACpB,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;IAC/B,CAAC;IAED,KAAK,CAAC,QAAQ,CACZ,OAAgC,EAChC,SAAgC;QAEhC,IAAI,CAAC;YACH,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACnC,MAAM,MAAM,CAAC,eAAe,EAAE,CAAC,OAAO,CAAC,CAAC;YAC1C,CAAC;YACD,MAAM,MAAM,GAAG,MAAM,SAAS,EAAE,CAAC;YACjC,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACnC,MAAM,MAAM,CAAC,cAAc,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;YACjD,CAAC;YACD,OAAO,MAAM,CAAC;QAChB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,UAAU,GAAG,qBAAqB,CAAC,KAAK,EAAE;gBAC9C,GAAG,CAAC,OAAO,CAAC,GAAG,KAAK,SAAS,IAAI,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,CAAC;gBACtD,SAAS,EAAE,OAAO,CAAC,SAAS;gBAC5B,KAAK,EAAE,IAAI,CAAC,IAAI;aACjB,CAAC,CAAC;YACH,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACnC,IAAI,CAAC;oBACH,MAAM,MAAM,CAAC,OAAO,EAAE,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;gBAC9C,CAAC;gBAAC,MAAM,CAAC;oBACP,uCAAuC;gBACzC,CAAC;YACH,CAAC;YACD,MAAM,UAAU,CAAC;QACnB,CAAC;IACH,CAAC;CACF","sourcesContent":["import { settleMany } from './internal/settle-many.js';\nimport {\n StorageError,\n StorageErrorCode,\n normalizeStorageError,\n} from './storage.error.js';\nimport type { StorageDriver } from './storage.driver.js';\nimport type {\n StorageBody,\n StorageBufferedDownloadOptions,\n StorageBulkOptions,\n StorageCapabilities,\n StorageDeleteManyResult,\n StorageDownloadManyResult,\n StorageDownloadOptions,\n StorageExistsManyResult,\n StorageHeadManyResult,\n StorageListOptions,\n StorageListResult,\n StorageObject,\n StorageObjectMetadata,\n StorageOperationContext,\n StorageOperationOptions,\n StoragePlugin,\n StorageSearchOptions,\n StorageSignedDownloadOptions,\n StorageSignedUpload,\n StorageSignedUploadOptions,\n StorageUploadManyItem,\n StorageUploadManyOptions,\n StorageUploadManyResult,\n StorageUploadOptions,\n StorageUploadResult,\n} from './storage.types.js';\n\nexport const DEFAULT_BUFFER_LIMIT = 10 * 1024 * 1024;\n\ntype BulkOperationOptions = StorageBulkOptions & StorageOperationOptions;\ntype DownloadManyOptions = StorageBulkOptions & StorageDownloadOptions;\n\nfunction assertKey(key: string, label = 'key'): void {\n if (typeof key !== 'string' || key.length === 0) {\n throw new StorageError(`${label} must be a non-empty string.`, {\n code: StorageErrorCode.INVALID_ARGUMENT,\n permanent: true,\n });\n }\n}\n\nfunction invalidArgument(message: string): never {\n throw new StorageError(message, {\n code: StorageErrorCode.INVALID_ARGUMENT,\n permanent: true,\n });\n}\n\nfunction assertPositiveSafeInteger(\n value: number | undefined,\n label: string,\n): void {\n if (value !== undefined && (!Number.isSafeInteger(value) || value <= 0)) {\n invalidArgument(`${label} must be a positive safe integer.`);\n }\n}\n\nfunction assertDownloadOptions(options?: StorageDownloadOptions): void {\n const range = options?.range;\n if (range === undefined) {\n return;\n }\n if (!Number.isSafeInteger(range.start) || range.start < 0) {\n invalidArgument('range.start must be a non-negative safe integer.');\n }\n if (\n range.end !== undefined &&\n (!Number.isSafeInteger(range.end) || range.end < range.start)\n ) {\n invalidArgument(\n 'range.end must be a safe integer greater than or equal to range.start.',\n );\n }\n}\n\nfunction assertListOptions(options?: StorageListOptions): void {\n if (options?.delimiter !== undefined && options.delimiter.length === 0) {\n invalidArgument('delimiter must be a non-empty string.');\n }\n assertPositiveSafeInteger(options?.limit, 'limit');\n}\n\nfunction assertSearchOptions(options?: StorageSearchOptions): void {\n assertPositiveSafeInteger(options?.limit, 'limit');\n assertPositiveSafeInteger(options?.maxResults, 'maxResults');\n}\n\nfunction assertSignedUploadOptions(options: StorageSignedUploadOptions): void {\n assertPositiveSafeInteger(options.expiresIn, 'expiresIn');\n assertPositiveSafeInteger(options.maxSize, 'maxSize');\n if (\n options.minSize !== undefined &&\n (!Number.isSafeInteger(options.minSize) || options.minSize < 0)\n ) {\n invalidArgument('minSize must be a non-negative safe integer.');\n }\n if (\n options.minSize !== undefined &&\n options.maxSize !== undefined &&\n options.minSize > options.maxSize\n ) {\n invalidArgument('minSize cannot be greater than maxSize.');\n }\n}\n\nfunction operationOptions(\n options?: BulkOperationOptions,\n): StorageOperationOptions | undefined {\n if (options === undefined) {\n return undefined;\n }\n return {\n ...(options.retries !== undefined && { retries: options.retries }),\n ...(options.signal !== undefined && { signal: options.signal }),\n ...(options.timeout !== undefined && { timeout: options.timeout }),\n };\n}\n\nfunction downloadOptions(\n options?: DownloadManyOptions,\n): StorageDownloadOptions | undefined {\n if (options === undefined) {\n return undefined;\n }\n return {\n ...operationOptions(options),\n ...(options.range !== undefined && { range: options.range }),\n };\n}\n\nasync function collectBody(\n object: StorageObject,\n maxBytes: number,\n): Promise<Uint8Array> {\n if (maxBytes !== Infinity && (!Number.isFinite(maxBytes) || maxBytes < 0)) {\n await object.body.cancel().catch(() => undefined);\n throw new StorageError(\n 'maxBytes must be a non-negative finite number or Infinity.',\n {\n code: StorageErrorCode.INVALID_ARGUMENT,\n key: object.key,\n permanent: true,\n },\n );\n }\n\n if (maxBytes !== Infinity && object.size > maxBytes) {\n await object.body.cancel().catch(() => undefined);\n throw new StorageError(\n `Object \"${object.key}\" is ${object.size} bytes, exceeding the ${maxBytes}-byte buffer limit.`,\n {\n code: StorageErrorCode.LIMIT_EXCEEDED,\n key: object.key,\n permanent: true,\n },\n );\n }\n\n const chunks: Uint8Array[] = [];\n let total = 0;\n const reader = object.body.getReader();\n\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) {\n break;\n }\n total += value.byteLength;\n if (maxBytes !== Infinity && total > maxBytes) {\n await reader.cancel().catch(() => undefined);\n throw new StorageError(\n `Object \"${object.key}\" exceeded the ${maxBytes}-byte buffer limit while downloading.`,\n {\n code: StorageErrorCode.LIMIT_EXCEEDED,\n key: object.key,\n permanent: true,\n },\n );\n }\n chunks.push(value);\n }\n } finally {\n reader.releaseLock();\n }\n\n const bytes = new Uint8Array(total);\n let offset = 0;\n for (const chunk of chunks) {\n bytes.set(chunk, offset);\n offset += chunk.byteLength;\n }\n return bytes;\n}\n\nexport interface StorageFileHandle {\n readonly key: string;\n upload(\n body: StorageBody,\n options?: StorageUploadOptions,\n ): Promise<StorageUploadResult>;\n download(options?: StorageDownloadOptions): Promise<StorageObject>;\n bytes(options?: StorageBufferedDownloadOptions): Promise<Uint8Array>;\n text(options?: StorageBufferedDownloadOptions): Promise<string>;\n head(options?: StorageOperationOptions): Promise<StorageObjectMetadata>;\n exists(options?: StorageOperationOptions): Promise<boolean>;\n delete(options?: StorageOperationOptions): Promise<void>;\n signDownload(options?: StorageSignedDownloadOptions): Promise<string>;\n signUpload(options: StorageSignedUploadOptions): Promise<StorageSignedUpload>;\n copyTo(\n destinationKey: string,\n options?: StorageOperationOptions,\n ): Promise<void>;\n moveTo(\n destinationKey: string,\n options?: StorageOperationOptions,\n ): Promise<void>;\n}\n\nexport class StorageClient {\n readonly #driver: StorageDriver;\n readonly #plugins: readonly StoragePlugin[];\n #closed = false;\n\n constructor(\n readonly name: string,\n driver: StorageDriver,\n plugins: readonly StoragePlugin[] = [],\n ) {\n assertKey(name, 'store name');\n this.#driver = driver;\n this.#plugins = [...plugins];\n }\n\n get driverName(): string {\n return this.#driver.name;\n }\n\n get capabilities(): Readonly<StorageCapabilities> {\n return this.#driver.capabilities;\n }\n\n file(key: string): StorageFileHandle {\n assertKey(key);\n return {\n copyTo: (destinationKey, options) =>\n this.copy(key, destinationKey, options),\n delete: (options) => this.delete(key, options),\n download: (options) => this.downloadStream(key, options),\n exists: (options) => this.exists(key, options),\n head: (options) => this.head(key, options),\n key,\n moveTo: (destinationKey, options) =>\n this.move(key, destinationKey, options),\n signDownload: (options) => this.signDownload(key, options),\n signUpload: (options) => this.signUpload(key, options),\n bytes: (options) => this.downloadBytes(key, options),\n text: (options) => this.downloadText(key, options),\n upload: (body, options) => this.upload(key, body, options),\n };\n }\n\n upload(\n key: string,\n body: StorageBody,\n options?: StorageUploadOptions,\n ): Promise<StorageUploadResult> {\n assertKey(key);\n return this.#execute({ key, operation: 'upload', store: this.name }, () =>\n this.#driver.upload(key, body, options),\n );\n }\n\n downloadStream(\n key: string,\n options?: StorageDownloadOptions,\n ): Promise<StorageObject> {\n assertKey(key);\n assertDownloadOptions(options);\n return this.#execute({ key, operation: 'download', store: this.name }, () =>\n this.#driver.download(key, options),\n );\n }\n\n async downloadBytes(\n key: string,\n options?: StorageBufferedDownloadOptions,\n ): Promise<Uint8Array> {\n const { maxBytes = DEFAULT_BUFFER_LIMIT, ...download } = options ?? {};\n const object = await this.downloadStream(key, download);\n return collectBody(object, maxBytes);\n }\n\n async downloadText(\n key: string,\n options?: StorageBufferedDownloadOptions,\n ): Promise<string> {\n return new TextDecoder().decode(await this.downloadBytes(key, options));\n }\n\n async downloadJson<Result = unknown>(\n key: string,\n options?: StorageBufferedDownloadOptions,\n ): Promise<Result> {\n const text = await this.downloadText(key, options);\n try {\n return JSON.parse(text) as Result;\n } catch (error) {\n throw new StorageError(`Object \"${key}\" does not contain valid JSON.`, {\n cause: error,\n code: StorageErrorCode.INVALID_ARGUMENT,\n key,\n operation: 'download',\n permanent: true,\n store: this.name,\n });\n }\n }\n\n head(\n key: string,\n options?: StorageOperationOptions,\n ): Promise<StorageObjectMetadata> {\n assertKey(key);\n return this.#execute({ key, operation: 'head', store: this.name }, () =>\n this.#driver.head(key, options),\n );\n }\n\n exists(key: string, options?: StorageOperationOptions): Promise<boolean> {\n assertKey(key);\n return this.#execute({ key, operation: 'exists', store: this.name }, () =>\n this.#driver.exists(key, options),\n );\n }\n\n delete(key: string, options?: StorageOperationOptions): Promise<void> {\n assertKey(key);\n return this.#execute({ key, operation: 'delete', store: this.name }, () =>\n this.#driver.delete(key, options),\n );\n }\n\n copy(\n sourceKey: string,\n destinationKey: string,\n options?: StorageOperationOptions,\n ): Promise<void> {\n assertKey(sourceKey, 'source key');\n assertKey(destinationKey, 'destination key');\n return this.#execute(\n {\n from: sourceKey,\n operation: 'copy',\n store: this.name,\n to: destinationKey,\n },\n () => this.#driver.copy(sourceKey, destinationKey, options),\n );\n }\n\n move(\n sourceKey: string,\n destinationKey: string,\n options?: StorageOperationOptions,\n ): Promise<void> {\n assertKey(sourceKey, 'source key');\n assertKey(destinationKey, 'destination key');\n return this.#execute(\n {\n from: sourceKey,\n operation: 'move',\n store: this.name,\n to: destinationKey,\n },\n () => this.#driver.move(sourceKey, destinationKey, options),\n );\n }\n\n list(options?: StorageListOptions): Promise<StorageListResult> {\n assertListOptions(options);\n return this.#execute({ operation: 'list', store: this.name }, () =>\n this.#driver.list(options),\n );\n }\n\n async *listAll(\n options?: StorageListOptions,\n ): AsyncGenerator<StorageObjectMetadata, void> {\n const { delimiter: _delimiter, ...walkOptions } = options ?? {};\n void _delimiter;\n let cursor = walkOptions.cursor;\n const seen = new Set<string>();\n\n do {\n const page = await this.list({\n ...walkOptions,\n ...(cursor !== undefined && { cursor }),\n });\n yield* page.items;\n cursor = page.cursor;\n if (cursor !== undefined) {\n if (seen.has(cursor)) {\n throw new StorageError(\n `Store \"${this.name}\" returned a repeated pagination cursor.`,\n {\n code: StorageErrorCode.PROVIDER,\n operation: 'list',\n permanent: true,\n store: this.name,\n },\n );\n }\n seen.add(cursor);\n }\n } while (cursor !== undefined);\n }\n\n search(\n pattern: string | RegExp,\n options?: StorageSearchOptions,\n ): AsyncIterable<StorageObjectMetadata> {\n assertSearchOptions(options);\n return this.#search(pattern, options);\n }\n\n async *#search(\n pattern: string | RegExp,\n options?: StorageSearchOptions,\n ): AsyncGenerator<StorageObjectMetadata, void> {\n const context: StorageOperationContext = {\n operation: 'search',\n store: this.name,\n };\n try {\n for (const plugin of this.#plugins) {\n await plugin.beforeOperation?.(context);\n }\n for await (const object of this.#driver.search(pattern, options)) {\n yield object;\n }\n for (const plugin of this.#plugins) {\n await plugin.afterOperation?.(context, undefined);\n }\n } catch (error) {\n const normalized = normalizeStorageError(error, {\n operation: 'search',\n store: this.name,\n });\n for (const plugin of this.#plugins) {\n try {\n await plugin.onError?.(context, normalized);\n } catch {\n // Preserve the original storage error.\n }\n }\n throw normalized;\n }\n }\n\n signDownload(\n key: string,\n options?: StorageSignedDownloadOptions,\n ): Promise<string> {\n assertKey(key);\n return this.#execute(\n { key, operation: 'signDownload', store: this.name },\n () => this.#driver.signDownload(key, options),\n );\n }\n\n signUpload(\n key: string,\n options: StorageSignedUploadOptions,\n ): Promise<StorageSignedUpload> {\n assertKey(key);\n assertSignedUploadOptions(options);\n return this.#execute(\n { key, operation: 'signUpload', store: this.name },\n () => this.#driver.signUpload(key, options),\n );\n }\n\n async uploadMany(\n items: readonly StorageUploadManyItem[],\n options?: StorageUploadManyOptions,\n ): Promise<StorageUploadManyResult> {\n const settled = await settleMany(\n items,\n (item) => item.key,\n (item) =>\n this.upload(item.key, item.body, {\n ...operationOptions(options),\n ...(item.cacheControl !== undefined && {\n cacheControl: item.cacheControl,\n }),\n ...(item.contentType !== undefined && {\n contentType: item.contentType,\n }),\n ...(item.metadata !== undefined && { metadata: item.metadata }),\n ...(item.multipart !== undefined && {\n multipart: item.multipart,\n }),\n ...(options?.onProgress !== undefined && {\n onProgress: (progress) =>\n options.onProgress?.({ ...progress, key: item.key }),\n }),\n }),\n options,\n );\n\n return {\n uploaded: settled.results,\n ...(settled.errors.length > 0 && { errors: settled.errors }),\n };\n }\n\n async downloadMany(\n keys: readonly string[],\n options?: DownloadManyOptions,\n ): Promise<StorageDownloadManyResult> {\n const settled = await settleMany(\n keys,\n (key) => key,\n (key) => this.downloadStream(key, downloadOptions(options)),\n options,\n );\n return {\n downloaded: settled.results,\n ...(settled.errors.length > 0 && { errors: settled.errors }),\n };\n }\n\n async headMany(\n keys: readonly string[],\n options?: BulkOperationOptions,\n ): Promise<StorageHeadManyResult> {\n const settled = await settleMany(\n keys,\n (key) => key,\n (key) => this.head(key, operationOptions(options)),\n options,\n );\n return {\n objects: settled.results,\n ...(settled.errors.length > 0 && { errors: settled.errors }),\n };\n }\n\n async existsMany(\n keys: readonly string[],\n options?: BulkOperationOptions,\n ): Promise<StorageExistsManyResult> {\n const settled = await settleMany(\n keys,\n (key) => key,\n async (key) => ({ exists: await this.exists(key, options), key }),\n options,\n );\n const existing: string[] = [];\n const missing: string[] = [];\n for (const result of settled.results) {\n (result.exists ? existing : missing).push(result.key);\n }\n return {\n existing,\n missing,\n ...(settled.errors.length > 0 && { errors: settled.errors }),\n };\n }\n\n async deleteMany(\n keys: readonly string[],\n options?: BulkOperationOptions,\n ): Promise<StorageDeleteManyResult> {\n const settled = await settleMany(\n keys,\n (key) => key,\n async (key) => {\n await this.delete(key, operationOptions(options));\n return key;\n },\n options,\n );\n return {\n deleted: settled.results,\n ...(settled.errors.length > 0 && { errors: settled.errors }),\n };\n }\n\n async onApplicationShutdown(): Promise<void> {\n if (this.#closed) {\n return;\n }\n this.#closed = true;\n await this.#driver.close?.();\n }\n\n async #execute<Result>(\n context: StorageOperationContext,\n operation: () => Promise<Result>,\n ): Promise<Result> {\n try {\n for (const plugin of this.#plugins) {\n await plugin.beforeOperation?.(context);\n }\n const result = await operation();\n for (const plugin of this.#plugins) {\n await plugin.afterOperation?.(context, result);\n }\n return result;\n } catch (error) {\n const normalized = normalizeStorageError(error, {\n ...(context.key !== undefined && { key: context.key }),\n operation: context.operation,\n store: this.name,\n });\n for (const plugin of this.#plugins) {\n try {\n await plugin.onError?.(context, normalized);\n } catch {\n // Preserve the original storage error.\n }\n }\n throw normalized;\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"storage.client.js","sourceRoot":"","sources":["../src/storage.client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACvD,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,qBAAqB,GACtB,MAAM,oBAAoB,CAAC;AAkC5B,MAAM,CAAC,MAAM,oBAAoB,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AASrD,SAAS,SAAS,CAAC,GAAW,EAAE,KAAK,GAAG,KAAK;IAC3C,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAChD,MAAM,IAAI,YAAY,CAAC,GAAG,KAAK,8BAA8B,EAAE;YAC7D,IAAI,EAAE,gBAAgB,CAAC,gBAAgB;YACvC,SAAS,EAAE,IAAI;SAChB,CAAC,CAAC;IACL,CAAC;AACH,CAAC;AAED,SAAS,eAAe,CAAC,OAAe;IACtC,MAAM,IAAI,YAAY,CAAC,OAAO,EAAE;QAC9B,IAAI,EAAE,gBAAgB,CAAC,gBAAgB;QACvC,SAAS,EAAE,IAAI;KAChB,CAAC,CAAC;AACL,CAAC;AAED,SAAS,yBAAyB,CAChC,KAAyB,EACzB,KAAa;IAEb,IAAI,KAAK,KAAK,SAAS,IAAI,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC,EAAE,CAAC;QACxE,eAAe,CAAC,GAAG,KAAK,mCAAmC,CAAC,CAAC;IAC/D,CAAC;AACH,CAAC;AAED,SAAS,qBAAqB,CAAC,OAAgC;IAC7D,MAAM,KAAK,GAAG,OAAO,EAAE,KAAK,CAAC;IAC7B,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,OAA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OAAO,CAAC,SAAS;gBAC5B,KAAK,EAAE,IAAI,CAAC,IAAI;aACjB,CAAC,CAAC;YACH,IAAI,iBAAiB,KAAK,SAAS,EAAE,CAAC;gBACpC,UAAU,GAAG,IAAI,YAAY,CAAC,UAAU,CAAC,OAAO,EAAE;oBAChD,OAAO,EAAE,UAAU,CAAC,OAAO;oBAC3B,OAAO,EAAE,IAAI;oBACb,GAAG,CAAC,sBAAsB,CAAC,iBAAiB,CAAC,WAAW,CAAC,IAAI;wBAC3D,WAAW,EAAE,iBAAiB,CAAC,WAAW;qBAC3C,CAAC;oBACF,KAAK,EAAE,UAAU,CAAC,KAAK;oBACvB,IAAI,EAAE,UAAU,CAAC,IAAI;oBACrB,GAAG,CAAC,UAAU,CAAC,GAAG,KAAK,SAAS,IAAI,EAAE,GAAG,EAAE,UAAU,CAAC,GAAG,EAAE,CAAC;oBAC5D,GAAG,CAAC,UAAU,CAAC,SAAS,KAAK,SAAS,IAAI;wBACxC,SAAS,EAAE,UAAU,CAAC,SAAS;qBAChC,CAAC;oBACF,SAAS,EAAE,UAAU,CAAC,SAAS;oBAC/B,GAAG,CAAC,UAAU,CAAC,KAAK,KAAK,SAAS,IAAI,EAAE,KAAK,EAAE,UAAU,CAAC,KAAK,EAAE,CAAC;oBAClE,QAAQ,EAAE,UAAU,CAAC,QAAQ;iBAC9B,CAAC,CAAC;YACL,CAAC;YACD,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACnC,IAAI,CAAC;oBACH,MAAM,MAAM,CAAC,OAAO,EAAE,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;gBAC9C,CAAC;gBAAC,MAAM,CAAC;oBACP,uCAAuC;gBACzC,CAAC;YACH,CAAC;YACD,MAAM,UAAU,CAAC;QACnB,CAAC;IACH,CAAC;CACF","sourcesContent":["import { settleMany } from './internal/settle-many.js';\nimport { isCanonicalStorageEtag } from './storage-etag.js';\nimport {\n StorageError,\n StorageErrorCode,\n normalizeStorageError,\n} from './storage.error.js';\nimport type { StorageDriver } from './storage.driver.js';\nimport type {\n StorageBody,\n StorageBufferedDownloadOptions,\n StorageBulkOptions,\n StorageCapabilities,\n StorageConditionalDeleteOptions,\n StorageConditionalReadOptions,\n StorageConditionalUploadOptions,\n StorageDeleteManyResult,\n StorageDownloadManyResult,\n StorageDownloadOptions,\n StorageExistsManyResult,\n StorageHeadManyResult,\n StorageListOptions,\n StorageListResult,\n StorageObject,\n StorageObjectMetadata,\n StorageOperationContext,\n StorageOperationOptions,\n StoragePlugin,\n StoragePromotionOptions,\n StorageSearchOptions,\n StorageSignedDownloadOptions,\n StorageSignedUpload,\n StorageSignedUploadOptions,\n StorageUploadManyItem,\n StorageUploadManyOptions,\n StorageUploadManyResult,\n StorageUploadOptions,\n StorageUploadResult,\n} from './storage.types.js';\n\nexport const DEFAULT_BUFFER_LIMIT = 10 * 1024 * 1024;\n\ntype BulkOperationOptions = StorageBulkOptions & StorageOperationOptions;\ntype DownloadManyOptions = StorageBulkOptions & StorageDownloadOptions;\n\ninterface AppliedMutationSettlement {\n readonly appliedEtag?: string;\n}\n\nfunction assertKey(key: string, label = 'key'): void {\n if (typeof key !== 'string' || key.length === 0) {\n throw new StorageError(`${label} must be a non-empty string.`, {\n code: StorageErrorCode.INVALID_ARGUMENT,\n permanent: true,\n });\n }\n}\n\nfunction invalidArgument(message: string): never {\n throw new StorageError(message, {\n code: StorageErrorCode.INVALID_ARGUMENT,\n permanent: true,\n });\n}\n\nfunction assertPositiveSafeInteger(\n value: number | undefined,\n label: string,\n): void {\n if (value !== undefined && (!Number.isSafeInteger(value) || value <= 0)) {\n invalidArgument(`${label} must be a positive safe integer.`);\n }\n}\n\nfunction assertDownloadOptions(options?: StorageDownloadOptions): void {\n const range = options?.range;\n if (range === undefined) {\n return;\n }\n if (!Number.isSafeInteger(range.start) || range.start < 0) {\n invalidArgument('range.start must be a non-negative safe integer.');\n }\n if (\n range.end !== undefined &&\n (!Number.isSafeInteger(range.end) || range.end < range.start)\n ) {\n invalidArgument(\n 'range.end must be a safe integer greater than or equal to range.start.',\n );\n }\n}\n\nfunction assertListOptions(options?: StorageListOptions): void {\n if (options?.delimiter !== undefined && options.delimiter.length === 0) {\n invalidArgument('delimiter must be a non-empty string.');\n }\n assertPositiveSafeInteger(options?.limit, 'limit');\n}\n\nfunction assertSearchOptions(options?: StorageSearchOptions): void {\n assertPositiveSafeInteger(options?.limit, 'limit');\n assertPositiveSafeInteger(options?.maxResults, 'maxResults');\n}\n\nfunction assertSignedUploadOptions(options: StorageSignedUploadOptions): void {\n assertPositiveSafeInteger(options.expiresIn, 'expiresIn');\n assertPositiveSafeInteger(options.maxSize, 'maxSize');\n if (\n options.minSize !== undefined &&\n (!Number.isSafeInteger(options.minSize) || options.minSize < 0)\n ) {\n invalidArgument('minSize must be a non-negative safe integer.');\n }\n if (\n options.minSize !== undefined &&\n options.maxSize !== undefined &&\n options.minSize > options.maxSize\n ) {\n invalidArgument('minSize cannot be greater than maxSize.');\n }\n}\n\nfunction operationOptions(\n options?: BulkOperationOptions,\n): StorageOperationOptions | undefined {\n if (options === undefined) {\n return undefined;\n }\n return {\n ...(options.retries !== undefined && { retries: options.retries }),\n ...(options.signal !== undefined && { signal: options.signal }),\n ...(options.timeout !== undefined && { timeout: options.timeout }),\n };\n}\n\nfunction downloadOptions(\n options?: DownloadManyOptions,\n): StorageDownloadOptions | undefined {\n if (options === undefined) {\n return undefined;\n }\n return {\n ...operationOptions(options),\n ...(options.range !== undefined && { range: options.range }),\n };\n}\n\nasync function collectBody(\n object: StorageObject,\n maxBytes: number,\n): Promise<Uint8Array> {\n if (maxBytes !== Infinity && (!Number.isFinite(maxBytes) || maxBytes < 0)) {\n await object.body.cancel().catch(() => undefined);\n throw new StorageError(\n 'maxBytes must be a non-negative finite number or Infinity.',\n {\n code: StorageErrorCode.INVALID_ARGUMENT,\n key: object.key,\n permanent: true,\n },\n );\n }\n\n if (maxBytes !== Infinity && object.size > maxBytes) {\n await object.body.cancel().catch(() => undefined);\n throw new StorageError(\n `Object \"${object.key}\" is ${object.size} bytes, exceeding the ${maxBytes}-byte buffer limit.`,\n {\n code: StorageErrorCode.LIMIT_EXCEEDED,\n key: object.key,\n permanent: true,\n },\n );\n }\n\n const chunks: Uint8Array[] = [];\n let total = 0;\n const reader = object.body.getReader();\n\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) {\n break;\n }\n total += value.byteLength;\n if (maxBytes !== Infinity && total > maxBytes) {\n await reader.cancel().catch(() => undefined);\n throw new StorageError(\n `Object \"${object.key}\" exceeded the ${maxBytes}-byte buffer limit while downloading.`,\n {\n code: StorageErrorCode.LIMIT_EXCEEDED,\n key: object.key,\n permanent: true,\n },\n );\n }\n chunks.push(value);\n }\n } finally {\n reader.releaseLock();\n }\n\n const bytes = new Uint8Array(total);\n let offset = 0;\n for (const chunk of chunks) {\n bytes.set(chunk, offset);\n offset += chunk.byteLength;\n }\n return bytes;\n}\n\nexport interface StorageFileHandle {\n readonly key: string;\n upload(\n body: StorageBody,\n options?: StorageUploadOptions,\n ): Promise<StorageUploadResult>;\n uploadConditional(\n body: StorageBody,\n options: StorageConditionalUploadOptions,\n ): Promise<StorageUploadResult>;\n download(options?: StorageDownloadOptions): Promise<StorageObject>;\n downloadConditional(\n options: StorageConditionalReadOptions,\n ): Promise<StorageObject>;\n bytes(options?: StorageBufferedDownloadOptions): Promise<Uint8Array>;\n text(options?: StorageBufferedDownloadOptions): Promise<string>;\n head(options?: StorageOperationOptions): Promise<StorageObjectMetadata>;\n exists(options?: StorageOperationOptions): Promise<boolean>;\n delete(options?: StorageOperationOptions): Promise<void>;\n deleteConditional(options: StorageConditionalDeleteOptions): Promise<void>;\n signDownload(options?: StorageSignedDownloadOptions): Promise<string>;\n signUpload(options: StorageSignedUploadOptions): Promise<StorageSignedUpload>;\n copyTo(\n destinationKey: string,\n options?: StorageOperationOptions,\n ): Promise<void>;\n moveTo(\n destinationKey: string,\n options?: StorageOperationOptions,\n ): Promise<void>;\n /** Conditionally copies this staged object and deliberately retains it. */\n promoteTo(\n destinationKey: string,\n options: StoragePromotionOptions,\n ): Promise<void>;\n}\n\nexport class StorageClient {\n readonly #driver: StorageDriver;\n readonly #plugins: readonly StoragePlugin[];\n #closed = false;\n\n constructor(\n readonly name: string,\n driver: StorageDriver,\n plugins: readonly StoragePlugin[] = [],\n ) {\n assertKey(name, 'store name');\n this.#driver = driver;\n this.#plugins = [...plugins];\n }\n\n get driverName(): string {\n return this.#driver.name;\n }\n\n get capabilities(): Readonly<StorageCapabilities> {\n return this.#driver.capabilities;\n }\n\n file(key: string): StorageFileHandle {\n assertKey(key);\n return {\n copyTo: (destinationKey, options) =>\n this.copy(key, destinationKey, options),\n delete: (options) => this.delete(key, options),\n deleteConditional: (options) => this.deleteConditional(key, options),\n download: (options) => this.downloadStream(key, options),\n downloadConditional: (options) => this.downloadConditional(key, options),\n exists: (options) => this.exists(key, options),\n head: (options) => this.head(key, options),\n key,\n moveTo: (destinationKey, options) =>\n this.move(key, destinationKey, options),\n promoteTo: (destinationKey, options) =>\n this.promote(key, destinationKey, options),\n signDownload: (options) => this.signDownload(key, options),\n signUpload: (options) => this.signUpload(key, options),\n bytes: (options) => this.downloadBytes(key, options),\n text: (options) => this.downloadText(key, options),\n upload: (body, options) => this.upload(key, body, options),\n uploadConditional: (body, options) =>\n this.uploadConditional(key, body, options),\n };\n }\n\n upload(\n key: string,\n body: StorageBody,\n options?: StorageUploadOptions,\n ): Promise<StorageUploadResult> {\n assertKey(key);\n return this.#execute({ key, operation: 'upload', store: this.name }, () =>\n this.#driver.upload(key, body, options),\n );\n }\n\n uploadConditional(\n key: string,\n body: StorageBody,\n options: StorageConditionalUploadOptions,\n ): Promise<StorageUploadResult> {\n assertKey(key);\n const condition = options.condition;\n if (\n condition === undefined ||\n (condition.type !== 'create' && condition.type !== 'replace')\n ) {\n invalidArgument('condition.type must be \"create\" or \"replace\".');\n }\n if (\n condition.type === 'replace' &&\n !isCanonicalStorageEtag(condition.etag)\n ) {\n invalidArgument('condition.etag must be a canonical storage ETag.');\n }\n\n const capability =\n condition.type === 'create'\n ? this.#driver.capabilities.conditionalCreate\n : this.#driver.capabilities.conditionalReplace;\n const uploadConditional = this.#driver.uploadConditional;\n const multipartRequested =\n options.multipart !== undefined && options.multipart !== false;\n const multipartCapability =\n this.#driver.capabilities.conditionalMultipartCompletion;\n const multipartSupported =\n !multipartRequested ||\n (condition.type === 'create'\n ? multipartCapability?.create === true\n : multipartCapability?.replace === true);\n if (\n capability === undefined ||\n !multipartSupported ||\n uploadConditional === undefined\n ) {\n throw new StorageError(\n `Store \"${this.name}\" does not support the requested conditional upload.`,\n {\n code: StorageErrorCode.NOT_SUPPORTED,\n key,\n operation: 'upload',\n permanent: true,\n store: this.name,\n },\n );\n }\n\n return this.#execute(\n { key, operation: 'upload', store: this.name },\n () => uploadConditional.call(this.#driver, key, body, options),\n (result) => {\n if (capability.resultEtag && !isCanonicalStorageEtag(result.etag)) {\n throw new StorageError(\n `Store \"${this.name}\" committed a conditional upload without the advertised result ETag.`,\n {\n code: StorageErrorCode.PROVIDER,\n key,\n operation: 'upload',\n permanent: true,\n store: this.name,\n },\n );\n }\n return {\n ...(isCanonicalStorageEtag(result.etag) && {\n appliedEtag: result.etag,\n }),\n };\n },\n );\n }\n\n downloadStream(\n key: string,\n options?: StorageDownloadOptions,\n ): Promise<StorageObject> {\n assertKey(key);\n assertDownloadOptions(options);\n return this.#execute({ key, operation: 'download', store: this.name }, () =>\n this.#driver.download(key, options),\n );\n }\n\n downloadConditional(\n key: string,\n options: StorageConditionalReadOptions,\n ): Promise<StorageObject> {\n assertKey(key);\n assertDownloadOptions(options);\n if (\n options === undefined ||\n options.condition === undefined ||\n typeof options.condition !== 'object' ||\n options.condition === null\n ) {\n invalidArgument('conditional read requires a condition object.');\n }\n const { etag, version } = options.condition;\n if (etag !== undefined && !isCanonicalStorageEtag(etag)) {\n invalidArgument('condition.etag must be a canonical storage ETag.');\n }\n if (\n version !== undefined &&\n (typeof version !== 'string' || version.length === 0)\n ) {\n invalidArgument('condition.version must be a non-empty string.');\n }\n if (etag === undefined && version === undefined) {\n invalidArgument('conditional read requires an etag, version, or both.');\n }\n\n const capability = this.#driver.capabilities.conditionalRead;\n const downloadConditional = this.#driver.downloadConditional;\n if (\n downloadConditional === undefined ||\n capability === undefined ||\n (etag !== undefined && !capability.etag) ||\n (version !== undefined && !capability.version)\n ) {\n throw new StorageError(\n `Store \"${this.name}\" does not support the requested conditional read.`,\n {\n code: StorageErrorCode.NOT_SUPPORTED,\n key,\n operation: 'download',\n permanent: true,\n store: this.name,\n },\n );\n }\n\n return this.#execute({ key, operation: 'download', store: this.name }, () =>\n downloadConditional.call(this.#driver, key, options),\n );\n }\n\n async downloadBytes(\n key: string,\n options?: StorageBufferedDownloadOptions,\n ): Promise<Uint8Array> {\n const { maxBytes = DEFAULT_BUFFER_LIMIT, ...download } = options ?? {};\n const object = await this.downloadStream(key, download);\n return collectBody(object, maxBytes);\n }\n\n async downloadText(\n key: string,\n options?: StorageBufferedDownloadOptions,\n ): Promise<string> {\n return new TextDecoder().decode(await this.downloadBytes(key, options));\n }\n\n async downloadJson<Result = unknown>(\n key: string,\n options?: StorageBufferedDownloadOptions,\n ): Promise<Result> {\n const text = await this.downloadText(key, options);\n try {\n return JSON.parse(text) as Result;\n } catch (error) {\n throw new StorageError(`Object \"${key}\" does not contain valid JSON.`, {\n cause: error,\n code: StorageErrorCode.INVALID_ARGUMENT,\n key,\n operation: 'download',\n permanent: true,\n store: this.name,\n });\n }\n }\n\n head(\n key: string,\n options?: StorageOperationOptions,\n ): Promise<StorageObjectMetadata> {\n assertKey(key);\n return this.#execute({ key, operation: 'head', store: this.name }, () =>\n this.#driver.head(key, options),\n );\n }\n\n exists(key: string, options?: StorageOperationOptions): Promise<boolean> {\n assertKey(key);\n return this.#execute({ key, operation: 'exists', store: this.name }, () =>\n this.#driver.exists(key, options),\n );\n }\n\n delete(key: string, options?: StorageOperationOptions): Promise<void> {\n assertKey(key);\n return this.#execute({ key, operation: 'delete', store: this.name }, () =>\n this.#driver.delete(key, options),\n );\n }\n\n deleteConditional(\n key: string,\n options: StorageConditionalDeleteOptions,\n ): Promise<void> {\n assertKey(key);\n if (\n options.condition === undefined ||\n !isCanonicalStorageEtag(options.condition.etag)\n ) {\n invalidArgument('condition.etag must be a canonical storage ETag.');\n }\n\n const capability = this.#driver.capabilities.conditionalDelete;\n const deleteConditional = this.#driver.deleteConditional;\n if (capability?.etag !== true || deleteConditional === undefined) {\n throw new StorageError(\n `Store \"${this.name}\" does not support conditional delete.`,\n {\n code: StorageErrorCode.NOT_SUPPORTED,\n key,\n operation: 'delete',\n permanent: true,\n store: this.name,\n },\n );\n }\n\n return this.#execute(\n { key, operation: 'delete', store: this.name },\n () => deleteConditional.call(this.#driver, key, options),\n () => ({}),\n );\n }\n\n copy(\n sourceKey: string,\n destinationKey: string,\n options?: StorageOperationOptions,\n ): Promise<void> {\n assertKey(sourceKey, 'source key');\n assertKey(destinationKey, 'destination key');\n return this.#execute(\n {\n from: sourceKey,\n operation: 'copy',\n store: this.name,\n to: destinationKey,\n },\n () => this.#driver.copy(sourceKey, destinationKey, options),\n );\n }\n\n move(\n sourceKey: string,\n destinationKey: string,\n options?: StorageOperationOptions,\n ): Promise<void> {\n assertKey(sourceKey, 'source key');\n assertKey(destinationKey, 'destination key');\n return this.#execute(\n {\n from: sourceKey,\n operation: 'move',\n store: this.name,\n to: destinationKey,\n },\n () => this.#driver.move(sourceKey, destinationKey, options),\n );\n }\n\n /**\n * Conditionally copies a staged object to a final key. This operation does\n * not delete the source; delete it after the application commit succeeds.\n */\n promote(\n sourceKey: string,\n destinationKey: string,\n options: StoragePromotionOptions,\n ): Promise<void> {\n assertKey(sourceKey, 'source key');\n assertKey(destinationKey, 'destination key');\n const sourceEtag = options.sourceEtag;\n const sourceVersion = options.sourceVersion;\n if (sourceEtag !== undefined && !isCanonicalStorageEtag(sourceEtag)) {\n invalidArgument('sourceEtag must be a canonical storage ETag.');\n }\n if (\n sourceVersion !== undefined &&\n (typeof sourceVersion !== 'string' || sourceVersion.length === 0)\n ) {\n invalidArgument('sourceVersion must be a non-empty string.');\n }\n const destination = options.destination;\n if (\n destination !== undefined &&\n (typeof destination !== 'object' ||\n destination === null ||\n (destination.type !== 'create' && destination.type !== 'replace'))\n ) {\n invalidArgument('destination.type must be \"create\" or \"replace\".');\n }\n if (\n sourceEtag === undefined &&\n sourceVersion === undefined &&\n destination === undefined\n ) {\n invalidArgument('promote requires a source or destination precondition.');\n }\n if (\n destination?.type === 'replace' &&\n !isCanonicalStorageEtag(destination.etag)\n ) {\n invalidArgument('destination.etag must be a canonical storage ETag.');\n }\n\n const sourceCapability = this.#driver.capabilities.conditionalCopySource;\n const destinationCapability =\n this.#driver.capabilities.conditionalCopyDestination;\n const promote = this.#driver.promote;\n const hasSourcePredicate =\n sourceEtag !== undefined || sourceVersion !== undefined;\n if (\n promote === undefined ||\n (sourceEtag !== undefined && sourceCapability?.etag !== true) ||\n (sourceVersion !== undefined && sourceCapability?.version !== true) ||\n (hasSourcePredicate &&\n destination === undefined &&\n sourceCapability?.requiresDestinationPredicate === true) ||\n (destination?.type === 'create' &&\n destinationCapability?.create !== true) ||\n (destination?.type === 'replace' &&\n destinationCapability?.replace !== true) ||\n (destination !== undefined &&\n !hasSourcePredicate &&\n destinationCapability?.requiresSourcePredicate === true) ||\n (destination !== undefined &&\n hasSourcePredicate &&\n destinationCapability?.atomicWithSource !== true)\n ) {\n throw new StorageError(\n `Store \"${this.name}\" does not support the requested conditional promotion.`,\n {\n code: StorageErrorCode.NOT_SUPPORTED,\n key: sourceKey,\n operation: 'promote',\n permanent: true,\n store: this.name,\n },\n );\n }\n\n return this.#execute(\n {\n from: sourceKey,\n operation: 'promote',\n store: this.name,\n to: destinationKey,\n },\n () => promote.call(this.#driver, sourceKey, destinationKey, options),\n () => ({}),\n );\n }\n\n list(options?: StorageListOptions): Promise<StorageListResult> {\n assertListOptions(options);\n return this.#execute({ operation: 'list', store: this.name }, () =>\n this.#driver.list(options),\n );\n }\n\n async *listAll(\n options?: StorageListOptions,\n ): AsyncGenerator<StorageObjectMetadata, void> {\n const { delimiter: _delimiter, ...walkOptions } = options ?? {};\n void _delimiter;\n let cursor = walkOptions.cursor;\n const seen = new Set<string>();\n\n do {\n const page = await this.list({\n ...walkOptions,\n ...(cursor !== undefined && { cursor }),\n });\n yield* page.items;\n cursor = page.cursor;\n if (cursor !== undefined) {\n if (seen.has(cursor)) {\n throw new StorageError(\n `Store \"${this.name}\" returned a repeated pagination cursor.`,\n {\n code: StorageErrorCode.PROVIDER,\n operation: 'list',\n permanent: true,\n store: this.name,\n },\n );\n }\n seen.add(cursor);\n }\n } while (cursor !== undefined);\n }\n\n search(\n pattern: string | RegExp,\n options?: StorageSearchOptions,\n ): AsyncIterable<StorageObjectMetadata> {\n assertSearchOptions(options);\n return this.#search(pattern, options);\n }\n\n async *#search(\n pattern: string | RegExp,\n options?: StorageSearchOptions,\n ): AsyncGenerator<StorageObjectMetadata, void> {\n const context: StorageOperationContext = {\n operation: 'search',\n store: this.name,\n };\n try {\n for (const plugin of this.#plugins) {\n await plugin.beforeOperation?.(context);\n }\n for await (const object of this.#driver.search(pattern, options)) {\n yield object;\n }\n for (const plugin of this.#plugins) {\n await plugin.afterOperation?.(context, undefined);\n }\n } catch (error) {\n const normalized = normalizeStorageError(error, {\n operation: 'search',\n store: this.name,\n });\n for (const plugin of this.#plugins) {\n try {\n await plugin.onError?.(context, normalized);\n } catch {\n // Preserve the original storage error.\n }\n }\n throw normalized;\n }\n }\n\n signDownload(\n key: string,\n options?: StorageSignedDownloadOptions,\n ): Promise<string> {\n assertKey(key);\n return this.#execute(\n { key, operation: 'signDownload', store: this.name },\n () => this.#driver.signDownload(key, options),\n );\n }\n\n signUpload(\n key: string,\n options: StorageSignedUploadOptions,\n ): Promise<StorageSignedUpload> {\n assertKey(key);\n assertSignedUploadOptions(options);\n return this.#execute(\n { key, operation: 'signUpload', store: this.name },\n () => this.#driver.signUpload(key, options),\n );\n }\n\n async uploadMany(\n items: readonly StorageUploadManyItem[],\n options?: StorageUploadManyOptions,\n ): Promise<StorageUploadManyResult> {\n const settled = await settleMany(\n items,\n (item) => item.key,\n (item) =>\n this.upload(item.key, item.body, {\n ...operationOptions(options),\n ...(item.cacheControl !== undefined && {\n cacheControl: item.cacheControl,\n }),\n ...(item.contentType !== undefined && {\n contentType: item.contentType,\n }),\n ...(item.metadata !== undefined && { metadata: item.metadata }),\n ...(item.multipart !== undefined && {\n multipart: item.multipart,\n }),\n ...(options?.onProgress !== undefined && {\n onProgress: (progress) =>\n options.onProgress?.({ ...progress, key: item.key }),\n }),\n }),\n options,\n );\n\n return {\n uploaded: settled.results,\n ...(settled.errors.length > 0 && { errors: settled.errors }),\n };\n }\n\n async downloadMany(\n keys: readonly string[],\n options?: DownloadManyOptions,\n ): Promise<StorageDownloadManyResult> {\n const settled = await settleMany(\n keys,\n (key) => key,\n (key) => this.downloadStream(key, downloadOptions(options)),\n options,\n );\n return {\n downloaded: settled.results,\n ...(settled.errors.length > 0 && { errors: settled.errors }),\n };\n }\n\n async headMany(\n keys: readonly string[],\n options?: BulkOperationOptions,\n ): Promise<StorageHeadManyResult> {\n const settled = await settleMany(\n keys,\n (key) => key,\n (key) => this.head(key, operationOptions(options)),\n options,\n );\n return {\n objects: settled.results,\n ...(settled.errors.length > 0 && { errors: settled.errors }),\n };\n }\n\n async existsMany(\n keys: readonly string[],\n options?: BulkOperationOptions,\n ): Promise<StorageExistsManyResult> {\n const settled = await settleMany(\n keys,\n (key) => key,\n async (key) => ({ exists: await this.exists(key, options), key }),\n options,\n );\n const existing: string[] = [];\n const missing: string[] = [];\n for (const result of settled.results) {\n (result.exists ? existing : missing).push(result.key);\n }\n return {\n existing,\n missing,\n ...(settled.errors.length > 0 && { errors: settled.errors }),\n };\n }\n\n async deleteMany(\n keys: readonly string[],\n options?: BulkOperationOptions,\n ): Promise<StorageDeleteManyResult> {\n const settled = await settleMany(\n keys,\n (key) => key,\n async (key) => {\n await this.delete(key, operationOptions(options));\n return key;\n },\n options,\n );\n return {\n deleted: settled.results,\n ...(settled.errors.length > 0 && { errors: settled.errors }),\n };\n }\n\n async onApplicationShutdown(): Promise<void> {\n if (this.#closed) {\n return;\n }\n this.#closed = true;\n await this.#driver.close?.();\n }\n\n async #execute<Result>(\n context: StorageOperationContext,\n operation: () => Promise<Result>,\n appliedMutation?: (result: Result) => AppliedMutationSettlement,\n ): Promise<Result> {\n let appliedSettlement: AppliedMutationSettlement | undefined;\n try {\n for (const plugin of this.#plugins) {\n await plugin.beforeOperation?.(context);\n }\n const result = await operation();\n if (appliedMutation !== undefined) {\n // Settle before describing the result so even an unexpected local\n // result-validation failure cannot turn a committed mutation into a\n // safe-to-retry error.\n appliedSettlement = {};\n appliedSettlement = appliedMutation(result);\n }\n for (const plugin of this.#plugins) {\n await plugin.afterOperation?.(context, result);\n }\n return result;\n } catch (error) {\n let normalized = normalizeStorageError(error, {\n ...(context.key !== undefined && { key: context.key }),\n operation: context.operation,\n store: this.name,\n });\n if (appliedSettlement !== undefined) {\n normalized = new StorageError(normalized.message, {\n aborted: normalized.aborted,\n applied: true,\n ...(isCanonicalStorageEtag(appliedSettlement.appliedEtag) && {\n appliedEtag: appliedSettlement.appliedEtag,\n }),\n cause: normalized.cause,\n code: normalized.code,\n ...(normalized.key !== undefined && { key: normalized.key }),\n ...(normalized.operation !== undefined && {\n operation: normalized.operation,\n }),\n permanent: normalized.permanent,\n ...(normalized.store !== undefined && { store: normalized.store }),\n timedOut: normalized.timedOut,\n });\n }\n for (const plugin of this.#plugins) {\n try {\n await plugin.onError?.(context, normalized);\n } catch {\n // Preserve the original storage error.\n }\n }\n throw normalized;\n }\n }\n}\n"]}
|