@backblaze-labs/b2-sdk 0.1.0 → 0.3.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/CHANGELOG.md +151 -5
- package/README.md +163 -34
- package/dist/_virtual/_b2-sdk-version-json.cjs +4 -0
- package/dist/_virtual/_b2-sdk-version-json.js +4 -0
- package/dist/auth/account-info.d.cts +32 -0
- package/dist/auth/account-info.d.cts.map +1 -1
- package/dist/auth/account-info.d.ts +32 -0
- package/dist/auth/account-info.d.ts.map +1 -1
- package/dist/auth/file.cjs +408 -207
- package/dist/auth/file.cjs.map +1 -1
- package/dist/auth/file.d.cts +77 -3
- package/dist/auth/file.d.cts.map +1 -1
- package/dist/auth/file.d.ts +77 -3
- package/dist/auth/file.d.ts.map +1 -1
- package/dist/auth/file.js +407 -207
- package/dist/auth/file.js.map +1 -1
- package/dist/auth/in-memory.cjs +212 -183
- package/dist/auth/in-memory.cjs.map +1 -1
- package/dist/auth/in-memory.d.cts +8 -0
- package/dist/auth/in-memory.d.cts.map +1 -1
- package/dist/auth/in-memory.d.ts +8 -0
- package/dist/auth/in-memory.d.ts.map +1 -1
- package/dist/auth/in-memory.js +211 -182
- package/dist/auth/in-memory.js.map +1 -1
- package/dist/auth/index.cjs +7 -9
- package/dist/auth/index.d.cts +3 -2
- package/dist/auth/index.d.cts.map +1 -1
- package/dist/auth/index.d.ts +3 -2
- package/dist/auth/index.d.ts.map +1 -1
- package/dist/auth/index.js +2 -8
- package/dist/auth/realms.cjs +80 -7
- package/dist/auth/realms.cjs.map +1 -1
- package/dist/auth/realms.d.cts +27 -4
- package/dist/auth/realms.d.cts.map +1 -1
- package/dist/auth/realms.d.ts +27 -4
- package/dist/auth/realms.d.ts.map +1 -1
- package/dist/auth/realms.js +80 -9
- package/dist/auth/realms.js.map +1 -1
- package/dist/auth/upload-url-pool.cjs +55 -51
- package/dist/auth/upload-url-pool.cjs.map +1 -1
- package/dist/auth/upload-url-pool.js +55 -51
- package/dist/auth/upload-url-pool.js.map +1 -1
- package/dist/backup/client.cjs +206 -0
- package/dist/backup/client.cjs.map +1 -0
- package/dist/backup/client.d.cts +238 -0
- package/dist/backup/client.d.cts.map +1 -0
- package/dist/backup/client.d.ts +238 -0
- package/dist/backup/client.d.ts.map +1 -0
- package/dist/backup/client.js +206 -0
- package/dist/backup/client.js.map +1 -0
- package/dist/backup/index.cjs +15 -0
- package/dist/backup/index.d.cts +22 -0
- package/dist/backup/index.d.cts.map +1 -0
- package/dist/backup/index.d.ts +22 -0
- package/dist/backup/index.d.ts.map +1 -0
- package/dist/backup/index.js +7 -0
- package/dist/backup/raw.cjs +146 -0
- package/dist/backup/raw.cjs.map +1 -0
- package/dist/backup/raw.d.cts +122 -0
- package/dist/backup/raw.d.cts.map +1 -0
- package/dist/backup/raw.d.ts +122 -0
- package/dist/backup/raw.d.ts.map +1 -0
- package/dist/backup/raw.js +146 -0
- package/dist/backup/raw.js.map +1 -0
- package/dist/bucket.cjs +786 -787
- package/dist/bucket.cjs.map +1 -1
- package/dist/bucket.d.cts +35 -47
- package/dist/bucket.d.cts.map +1 -1
- package/dist/bucket.d.ts +35 -47
- package/dist/bucket.d.ts.map +1 -1
- package/dist/bucket.js +781 -782
- package/dist/bucket.js.map +1 -1
- package/dist/client.cjs +246 -228
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +25 -17
- package/dist/client.d.cts.map +1 -1
- package/dist/client.d.ts +25 -17
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +243 -225
- package/dist/client.js.map +1 -1
- package/dist/copy/large.cjs +116 -71
- package/dist/copy/large.cjs.map +1 -1
- package/dist/copy/large.d.cts +6 -0
- package/dist/copy/large.d.cts.map +1 -1
- package/dist/copy/large.d.ts +6 -0
- package/dist/copy/large.d.ts.map +1 -1
- package/dist/copy/large.js +114 -69
- package/dist/copy/large.js.map +1 -1
- package/dist/download/checksum.cjs +93 -0
- package/dist/download/checksum.cjs.map +1 -0
- package/dist/download/checksum.d.cts +40 -0
- package/dist/download/checksum.d.cts.map +1 -0
- package/dist/download/checksum.d.ts +40 -0
- package/dist/download/checksum.d.ts.map +1 -0
- package/dist/download/checksum.js +91 -0
- package/dist/download/checksum.js.map +1 -0
- package/dist/download/parallel.cjs +251 -118
- package/dist/download/parallel.cjs.map +1 -1
- package/dist/download/parallel.d.cts +13 -2
- package/dist/download/parallel.d.cts.map +1 -1
- package/dist/download/parallel.d.ts +13 -2
- package/dist/download/parallel.d.ts.map +1 -1
- package/dist/download/parallel.js +249 -116
- package/dist/download/parallel.js.map +1 -1
- package/dist/download/single.cjs +323 -97
- package/dist/download/single.cjs.map +1 -1
- package/dist/download/single.d.cts +6 -1
- package/dist/download/single.d.cts.map +1 -1
- package/dist/download/single.d.ts +6 -1
- package/dist/download/single.d.ts.map +1 -1
- package/dist/download/single.js +322 -99
- package/dist/download/single.js.map +1 -1
- package/dist/errors/index.cjs +869 -243
- package/dist/errors/index.cjs.map +1 -1
- package/dist/errors/index.d.cts +404 -82
- package/dist/errors/index.d.cts.map +1 -1
- package/dist/errors/index.d.ts +404 -82
- package/dist/errors/index.d.ts.map +1 -1
- package/dist/errors/index.js +835 -261
- package/dist/errors/index.js.map +1 -1
- package/dist/http/retry.cjs +45 -28
- package/dist/http/retry.cjs.map +1 -1
- package/dist/http/retry.d.cts +15 -2
- package/dist/http/retry.d.cts.map +1 -1
- package/dist/http/retry.d.ts +15 -2
- package/dist/http/retry.d.ts.map +1 -1
- package/dist/http/retry.js +46 -31
- package/dist/http/retry.js.map +1 -1
- package/dist/http/transport.cjs +476 -140
- package/dist/http/transport.cjs.map +1 -1
- package/dist/http/transport.d.cts +46 -5
- package/dist/http/transport.d.cts.map +1 -1
- package/dist/http/transport.d.ts +46 -5
- package/dist/http/transport.d.ts.map +1 -1
- package/dist/http/transport.js +474 -140
- package/dist/http/transport.js.map +1 -1
- package/dist/http/url-guard.cjs +154 -89
- package/dist/http/url-guard.cjs.map +1 -1
- package/dist/http/url-guard.d.cts +25 -3
- package/dist/http/url-guard.d.cts.map +1 -1
- package/dist/http/url-guard.d.ts +25 -3
- package/dist/http/url-guard.d.ts.map +1 -1
- package/dist/http/url-guard.js +152 -90
- package/dist/http/url-guard.js.map +1 -1
- package/dist/http/user-agent.cjs +84 -44
- package/dist/http/user-agent.cjs.map +1 -1
- package/dist/http/user-agent.js +84 -46
- package/dist/http/user-agent.js.map +1 -1
- package/dist/index.cjs +124 -77
- package/dist/index.d.cts +29 -21
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +29 -21
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -72
- package/dist/internal/b2-naming.cjs +66 -0
- package/dist/internal/b2-naming.cjs.map +1 -0
- package/dist/internal/b2-naming.d.cts +43 -0
- package/dist/internal/b2-naming.d.cts.map +1 -0
- package/dist/internal/b2-naming.d.ts +43 -0
- package/dist/internal/b2-naming.d.ts.map +1 -0
- package/dist/internal/b2-naming.js +60 -0
- package/dist/internal/b2-naming.js.map +1 -0
- package/dist/internal/upload-retry-options.cjs +21 -0
- package/dist/internal/upload-retry-options.cjs.map +1 -0
- package/dist/internal/upload-retry-options.d.cts +12 -0
- package/dist/internal/upload-retry-options.d.cts.map +1 -0
- package/dist/internal/upload-retry-options.d.ts +12 -0
- package/dist/internal/upload-retry-options.d.ts.map +1 -0
- package/dist/internal/upload-retry-options.js +21 -0
- package/dist/internal/upload-retry-options.js.map +1 -0
- package/dist/internal/url-redaction.cjs +31 -0
- package/dist/internal/url-redaction.cjs.map +1 -0
- package/dist/internal/url-redaction.d.cts +17 -0
- package/dist/internal/url-redaction.d.cts.map +1 -0
- package/dist/internal/url-redaction.d.ts +17 -0
- package/dist/internal/url-redaction.d.ts.map +1 -0
- package/dist/internal/url-redaction.js +31 -0
- package/dist/internal/url-redaction.js.map +1 -0
- package/dist/notifications/index.cjs +4 -6
- package/dist/notifications/index.d.cts +1 -1
- package/dist/notifications/index.d.cts.map +1 -1
- package/dist/notifications/index.d.ts +1 -1
- package/dist/notifications/index.d.ts.map +1 -1
- package/dist/notifications/index.js +1 -6
- package/dist/notifications/webhook.cjs +195 -85
- package/dist/notifications/webhook.cjs.map +1 -1
- package/dist/notifications/webhook.d.cts.map +1 -1
- package/dist/notifications/webhook.d.ts.map +1 -1
- package/dist/notifications/webhook.js +195 -87
- package/dist/notifications/webhook.js.map +1 -1
- package/dist/object.cjs +253 -210
- package/dist/object.cjs.map +1 -1
- package/dist/object.d.cts +13 -57
- package/dist/object.d.cts.map +1 -1
- package/dist/object.d.ts +13 -57
- package/dist/object.d.ts.map +1 -1
- package/dist/object.js +249 -206
- package/dist/object.js.map +1 -1
- package/dist/partner/account-info.d.cts +43 -0
- package/dist/partner/account-info.d.cts.map +1 -0
- package/dist/partner/account-info.d.ts +43 -0
- package/dist/partner/account-info.d.ts.map +1 -0
- package/dist/partner/auth-clone.cjs +64 -0
- package/dist/partner/auth-clone.cjs.map +1 -0
- package/dist/partner/auth-clone.d.cts +27 -0
- package/dist/partner/auth-clone.d.cts.map +1 -0
- package/dist/partner/auth-clone.d.ts +27 -0
- package/dist/partner/auth-clone.d.ts.map +1 -0
- package/dist/partner/auth-clone.js +63 -0
- package/dist/partner/auth-clone.js.map +1 -0
- package/dist/partner/auth-core.cjs +175 -0
- package/dist/partner/auth-core.cjs.map +1 -0
- package/dist/partner/auth-core.d.cts +111 -0
- package/dist/partner/auth-core.d.cts.map +1 -0
- package/dist/partner/auth-core.d.ts +111 -0
- package/dist/partner/auth-core.d.ts.map +1 -0
- package/dist/partner/auth-core.js +175 -0
- package/dist/partner/auth-core.js.map +1 -0
- package/dist/partner/auth-shape.cjs +36 -0
- package/dist/partner/auth-shape.cjs.map +1 -0
- package/dist/partner/auth-shape.d.cts +12 -0
- package/dist/partner/auth-shape.d.cts.map +1 -0
- package/dist/partner/auth-shape.d.ts +12 -0
- package/dist/partner/auth-shape.d.ts.map +1 -0
- package/dist/partner/auth-shape.js +36 -0
- package/dist/partner/auth-shape.js.map +1 -0
- package/dist/partner/client.cjs +255 -0
- package/dist/partner/client.cjs.map +1 -0
- package/dist/partner/client.d.cts +335 -0
- package/dist/partner/client.d.cts.map +1 -0
- package/dist/partner/client.d.ts +335 -0
- package/dist/partner/client.d.ts.map +1 -0
- package/dist/partner/client.js +255 -0
- package/dist/partner/client.js.map +1 -0
- package/dist/partner/endpoint-url.cjs +108 -0
- package/dist/partner/endpoint-url.cjs.map +1 -0
- package/dist/partner/endpoint-url.d.cts +72 -0
- package/dist/partner/endpoint-url.d.cts.map +1 -0
- package/dist/partner/endpoint-url.d.ts +72 -0
- package/dist/partner/endpoint-url.d.ts.map +1 -0
- package/dist/partner/endpoint-url.js +105 -0
- package/dist/partner/endpoint-url.js.map +1 -0
- package/dist/partner/in-memory.cjs +135 -0
- package/dist/partner/in-memory.cjs.map +1 -0
- package/dist/partner/in-memory.d.cts +99 -0
- package/dist/partner/in-memory.d.cts.map +1 -0
- package/dist/partner/in-memory.d.ts +99 -0
- package/dist/partner/in-memory.d.ts.map +1 -0
- package/dist/partner/in-memory.js +135 -0
- package/dist/partner/in-memory.js.map +1 -0
- package/dist/partner/index.cjs +18 -0
- package/dist/partner/index.d.cts +23 -0
- package/dist/partner/index.d.cts.map +1 -0
- package/dist/partner/index.d.ts +23 -0
- package/dist/partner/index.d.ts.map +1 -0
- package/dist/partner/index.js +7 -0
- package/dist/partner/raw.cjs +392 -0
- package/dist/partner/raw.cjs.map +1 -0
- package/dist/partner/raw.d.cts +223 -0
- package/dist/partner/raw.d.cts.map +1 -0
- package/dist/partner/raw.d.ts +223 -0
- package/dist/partner/raw.d.ts.map +1 -0
- package/dist/partner/raw.js +390 -0
- package/dist/partner/raw.js.map +1 -0
- package/dist/partner/redaction-placeholders.cjs +10 -0
- package/dist/partner/redaction-placeholders.cjs.map +1 -0
- package/dist/partner/redaction-placeholders.d.cts +5 -0
- package/dist/partner/redaction-placeholders.d.cts.map +1 -0
- package/dist/partner/redaction-placeholders.d.ts +5 -0
- package/dist/partner/redaction-placeholders.d.ts.map +1 -0
- package/dist/partner/redaction-placeholders.js +9 -0
- package/dist/partner/redaction-placeholders.js.map +1 -0
- package/dist/partner/redaction.cjs +267 -0
- package/dist/partner/redaction.cjs.map +1 -0
- package/dist/partner/redaction.d.cts +124 -0
- package/dist/partner/redaction.d.cts.map +1 -0
- package/dist/partner/redaction.d.ts +124 -0
- package/dist/partner/redaction.d.ts.map +1 -0
- package/dist/partner/redaction.js +257 -0
- package/dist/partner/redaction.js.map +1 -0
- package/dist/raw/encoding.cjs +74 -35
- package/dist/raw/encoding.cjs.map +1 -1
- package/dist/raw/encoding.js +74 -38
- package/dist/raw/encoding.js.map +1 -1
- package/dist/raw/index.cjs +740 -587
- package/dist/raw/index.cjs.map +1 -1
- package/dist/raw/index.d.cts +126 -19
- package/dist/raw/index.d.cts.map +1 -1
- package/dist/raw/index.d.ts +126 -19
- package/dist/raw/index.d.ts.map +1 -1
- package/dist/raw/index.js +736 -589
- package/dist/raw/index.js.map +1 -1
- package/dist/raw/url.cjs +111 -0
- package/dist/raw/url.cjs.map +1 -0
- package/dist/raw/url.d.cts +41 -0
- package/dist/raw/url.d.cts.map +1 -0
- package/dist/raw/url.d.ts +41 -0
- package/dist/raw/url.d.ts.map +1 -0
- package/dist/raw/url.js +110 -0
- package/dist/raw/url.js.map +1 -0
- package/dist/s3/index.cjs +355 -18
- package/dist/s3/index.cjs.map +1 -1
- package/dist/s3/index.d.cts +233 -5
- package/dist/s3/index.d.cts.map +1 -1
- package/dist/s3/index.d.ts +233 -5
- package/dist/s3/index.d.ts.map +1 -1
- package/dist/s3/index.js +351 -22
- package/dist/s3/index.js.map +1 -1
- package/dist/s3/sigv4.cjs +154 -0
- package/dist/s3/sigv4.cjs.map +1 -0
- package/dist/s3/sigv4.d.cts +43 -0
- package/dist/s3/sigv4.d.cts.map +1 -0
- package/dist/s3/sigv4.d.ts +43 -0
- package/dist/s3/sigv4.d.ts.map +1 -0
- package/dist/s3/sigv4.js +153 -0
- package/dist/s3/sigv4.js.map +1 -0
- package/dist/s3/validation.cjs +69 -0
- package/dist/s3/validation.cjs.map +1 -0
- package/dist/s3/validation.d.cts +43 -0
- package/dist/s3/validation.d.cts.map +1 -0
- package/dist/s3/validation.d.ts +43 -0
- package/dist/s3/validation.d.ts.map +1 -0
- package/dist/s3/validation.js +66 -0
- package/dist/s3/validation.js.map +1 -0
- package/dist/simulator/capabilities.cjs +63 -48
- package/dist/simulator/capabilities.cjs.map +1 -1
- package/dist/simulator/capabilities.js +63 -49
- package/dist/simulator/capabilities.js.map +1 -1
- package/dist/simulator/index.cjs +3114 -1547
- package/dist/simulator/index.cjs.map +1 -1
- package/dist/simulator/index.d.cts +186 -20
- package/dist/simulator/index.d.cts.map +1 -1
- package/dist/simulator/index.d.ts +186 -20
- package/dist/simulator/index.d.ts.map +1 -1
- package/dist/simulator/index.js +3098 -1545
- package/dist/simulator/index.js.map +1 -1
- package/dist/simulator/partner.cjs +719 -0
- package/dist/simulator/partner.cjs.map +1 -0
- package/dist/simulator/partner.d.cts +183 -0
- package/dist/simulator/partner.d.cts.map +1 -0
- package/dist/simulator/partner.d.ts +183 -0
- package/dist/simulator/partner.d.ts.map +1 -0
- package/dist/simulator/partner.js +718 -0
- package/dist/simulator/partner.js.map +1 -0
- package/dist/simulator/validation.cjs +772 -157
- package/dist/simulator/validation.cjs.map +1 -1
- package/dist/simulator/validation.d.cts +120 -21
- package/dist/simulator/validation.d.cts.map +1 -1
- package/dist/simulator/validation.d.ts +120 -21
- package/dist/simulator/validation.d.ts.map +1 -1
- package/dist/simulator/validation.js +755 -167
- package/dist/simulator/validation.js.map +1 -1
- package/dist/streams/collect.cjs +74 -24
- package/dist/streams/collect.cjs.map +1 -1
- package/dist/streams/collect.d.cts +14 -1
- package/dist/streams/collect.d.cts.map +1 -1
- package/dist/streams/collect.d.ts +14 -1
- package/dist/streams/collect.d.ts.map +1 -1
- package/dist/streams/collect.js +74 -25
- package/dist/streams/collect.js.map +1 -1
- package/dist/streams/file-source.cjs +287 -0
- package/dist/streams/file-source.cjs.map +1 -0
- package/dist/streams/file-source.d.cts +96 -0
- package/dist/streams/file-source.d.cts.map +1 -0
- package/dist/streams/file-source.d.ts +96 -0
- package/dist/streams/file-source.d.ts.map +1 -0
- package/dist/streams/file-source.js +286 -0
- package/dist/streams/file-source.js.map +1 -0
- package/dist/streams/hash.cjs +207 -115
- package/dist/streams/hash.cjs.map +1 -1
- package/dist/streams/hash.d.cts +5 -4
- package/dist/streams/hash.d.cts.map +1 -1
- package/dist/streams/hash.d.ts +5 -4
- package/dist/streams/hash.d.ts.map +1 -1
- package/dist/streams/hash.js +208 -95
- package/dist/streams/hash.js.map +1 -1
- package/dist/streams/index.cjs +12 -12
- package/dist/streams/index.d.cts +3 -3
- package/dist/streams/index.d.cts.map +1 -1
- package/dist/streams/index.d.ts +3 -3
- package/dist/streams/index.d.ts.map +1 -1
- package/dist/streams/index.js +3 -11
- package/dist/streams/progress.cjs +60 -46
- package/dist/streams/progress.cjs.map +1 -1
- package/dist/streams/progress.js +60 -46
- package/dist/streams/progress.js.map +1 -1
- package/dist/streams/source.cjs +317 -146
- package/dist/streams/source.cjs.map +1 -1
- package/dist/streams/source.d.cts +56 -18
- package/dist/streams/source.d.cts.map +1 -1
- package/dist/streams/source.d.ts +56 -18
- package/dist/streams/source.d.ts.map +1 -1
- package/dist/streams/source.js +313 -149
- package/dist/streams/source.js.map +1 -1
- package/dist/sync/actions/index.cjs +236 -184
- package/dist/sync/actions/index.cjs.map +1 -1
- package/dist/sync/actions/index.d.cts +29 -21
- package/dist/sync/actions/index.d.cts.map +1 -1
- package/dist/sync/actions/index.d.ts +29 -21
- package/dist/sync/actions/index.d.ts.map +1 -1
- package/dist/sync/actions/index.js +236 -190
- package/dist/sync/actions/index.js.map +1 -1
- package/dist/sync/b2-sha1-reader.cjs +152 -0
- package/dist/sync/b2-sha1-reader.cjs.map +1 -0
- package/dist/sync/b2-sha1-reader.d.cts +58 -0
- package/dist/sync/b2-sha1-reader.d.cts.map +1 -0
- package/dist/sync/b2-sha1-reader.d.ts +58 -0
- package/dist/sync/b2-sha1-reader.d.ts.map +1 -0
- package/dist/sync/b2-sha1-reader.js +149 -0
- package/dist/sync/b2-sha1-reader.js.map +1 -0
- package/dist/sync/download-staging.cjs +266 -0
- package/dist/sync/download-staging.cjs.map +1 -0
- package/dist/sync/download-staging.d.cts +55 -0
- package/dist/sync/download-staging.d.cts.map +1 -0
- package/dist/sync/download-staging.d.ts +55 -0
- package/dist/sync/download-staging.d.ts.map +1 -0
- package/dist/sync/download-staging.js +260 -0
- package/dist/sync/download-staging.js.map +1 -0
- package/dist/sync/filesystem-errors.cjs +32 -0
- package/dist/sync/filesystem-errors.cjs.map +1 -0
- package/dist/sync/filesystem-errors.d.cts +8 -0
- package/dist/sync/filesystem-errors.d.cts.map +1 -0
- package/dist/sync/filesystem-errors.d.ts +8 -0
- package/dist/sync/filesystem-errors.d.ts.map +1 -0
- package/dist/sync/filesystem-errors.js +32 -0
- package/dist/sync/filesystem-errors.js.map +1 -0
- package/dist/sync/filters.cjs +217 -0
- package/dist/sync/filters.cjs.map +1 -0
- package/dist/sync/filters.d.cts +51 -0
- package/dist/sync/filters.d.cts.map +1 -0
- package/dist/sync/filters.d.ts +51 -0
- package/dist/sync/filters.d.ts.map +1 -0
- package/dist/sync/filters.js +213 -0
- package/dist/sync/filters.js.map +1 -0
- package/dist/sync/index.cjs +39 -22
- package/dist/sync/index.d.cts +14 -9
- package/dist/sync/index.d.cts.map +1 -1
- package/dist/sync/index.d.ts +14 -9
- package/dist/sync/index.d.ts.map +1 -1
- package/dist/sync/index.js +9 -20
- package/dist/sync/local-file-identity.cjs +61 -0
- package/dist/sync/local-file-identity.cjs.map +1 -0
- package/dist/sync/local-file-identity.d.cts +37 -0
- package/dist/sync/local-file-identity.d.cts.map +1 -0
- package/dist/sync/local-file-identity.d.ts +37 -0
- package/dist/sync/local-file-identity.d.ts.map +1 -0
- package/dist/sync/local-file-identity.js +60 -0
- package/dist/sync/local-file-identity.js.map +1 -0
- package/dist/sync/local-file-io.cjs +369 -0
- package/dist/sync/local-file-io.cjs.map +1 -0
- package/dist/sync/local-file-io.d.cts +76 -0
- package/dist/sync/local-file-io.d.cts.map +1 -0
- package/dist/sync/local-file-io.d.ts +76 -0
- package/dist/sync/local-file-io.d.ts.map +1 -0
- package/dist/sync/local-file-io.js +365 -0
- package/dist/sync/local-file-io.js.map +1 -0
- package/dist/sync/local-filesystem-root.cjs +27 -0
- package/dist/sync/local-filesystem-root.cjs.map +1 -0
- package/dist/sync/local-filesystem-root.d.cts +18 -0
- package/dist/sync/local-filesystem-root.d.cts.map +1 -0
- package/dist/sync/local-filesystem-root.d.ts +18 -0
- package/dist/sync/local-filesystem-root.d.ts.map +1 -0
- package/dist/sync/local-filesystem-root.js +26 -0
- package/dist/sync/local-filesystem-root.js.map +1 -0
- package/dist/sync/local-sha1.cjs +110 -0
- package/dist/sync/local-sha1.cjs.map +1 -0
- package/dist/sync/local-sha1.d.cts +31 -0
- package/dist/sync/local-sha1.d.cts.map +1 -0
- package/dist/sync/local-sha1.d.ts +31 -0
- package/dist/sync/local-sha1.d.ts.map +1 -0
- package/dist/sync/local-sha1.js +109 -0
- package/dist/sync/local-sha1.js.map +1 -0
- package/dist/sync/pairing.cjs +118 -29
- package/dist/sync/pairing.cjs.map +1 -1
- package/dist/sync/pairing.d.cts +7 -2
- package/dist/sync/pairing.d.cts.map +1 -1
- package/dist/sync/pairing.d.ts +7 -2
- package/dist/sync/pairing.d.ts.map +1 -1
- package/dist/sync/pairing.js +120 -31
- package/dist/sync/pairing.js.map +1 -1
- package/dist/sync/path-order.cjs +30 -0
- package/dist/sync/path-order.cjs.map +1 -0
- package/dist/sync/path-order.d.cts +28 -0
- package/dist/sync/path-order.d.cts.map +1 -0
- package/dist/sync/path-order.d.ts +28 -0
- package/dist/sync/path-order.d.ts.map +1 -0
- package/dist/sync/path-order.js +29 -0
- package/dist/sync/path-order.js.map +1 -0
- package/dist/sync/path-safety.cjs +111 -0
- package/dist/sync/path-safety.cjs.map +1 -0
- package/dist/sync/path-safety.d.cts +78 -0
- package/dist/sync/path-safety.d.cts.map +1 -0
- package/dist/sync/path-safety.d.ts +78 -0
- package/dist/sync/path-safety.d.ts.map +1 -0
- package/dist/sync/path-safety.js +105 -0
- package/dist/sync/path-safety.js.map +1 -0
- package/dist/sync/paths.d.cts +19 -0
- package/dist/sync/paths.d.cts.map +1 -0
- package/dist/sync/paths.d.ts +19 -0
- package/dist/sync/paths.d.ts.map +1 -0
- package/dist/sync/policies/compare.cjs +391 -11
- package/dist/sync/policies/compare.cjs.map +1 -1
- package/dist/sync/policies/compare.d.cts +100 -2
- package/dist/sync/policies/compare.d.cts.map +1 -1
- package/dist/sync/policies/compare.d.ts +100 -2
- package/dist/sync/policies/compare.d.ts.map +1 -1
- package/dist/sync/policies/compare.js +389 -13
- package/dist/sync/policies/compare.js.map +1 -1
- package/dist/sync/policies/index.cjs +70 -65
- package/dist/sync/policies/index.cjs.map +1 -1
- package/dist/sync/policies/index.d.cts +35 -6
- package/dist/sync/policies/index.d.cts.map +1 -1
- package/dist/sync/policies/index.d.ts +35 -6
- package/dist/sync/policies/index.d.ts.map +1 -1
- package/dist/sync/policies/index.js +70 -65
- package/dist/sync/policies/index.js.map +1 -1
- package/dist/sync/prefix.cjs +96 -0
- package/dist/sync/prefix.cjs.map +1 -0
- package/dist/sync/prefix.d.cts +55 -0
- package/dist/sync/prefix.d.cts.map +1 -0
- package/dist/sync/prefix.d.ts +55 -0
- package/dist/sync/prefix.d.ts.map +1 -0
- package/dist/sync/prefix.js +92 -0
- package/dist/sync/prefix.js.map +1 -0
- package/dist/sync/regexp-safety.cjs +192 -0
- package/dist/sync/regexp-safety.cjs.map +1 -0
- package/dist/sync/regexp-safety.d.cts +29 -0
- package/dist/sync/regexp-safety.d.cts.map +1 -0
- package/dist/sync/regexp-safety.d.ts +29 -0
- package/dist/sync/regexp-safety.d.ts.map +1 -0
- package/dist/sync/regexp-safety.js +190 -0
- package/dist/sync/regexp-safety.js.map +1 -0
- package/dist/sync/scan-events.cjs +33 -0
- package/dist/sync/scan-events.cjs.map +1 -0
- package/dist/sync/scan-events.d.cts +17 -0
- package/dist/sync/scan-events.d.cts.map +1 -0
- package/dist/sync/scan-events.d.ts +17 -0
- package/dist/sync/scan-events.d.ts.map +1 -0
- package/dist/sync/scan-events.js +32 -0
- package/dist/sync/scan-events.js.map +1 -0
- package/dist/sync/scan-limit.cjs +33 -0
- package/dist/sync/scan-limit.cjs.map +1 -0
- package/dist/sync/scan-limit.d.cts +21 -0
- package/dist/sync/scan-limit.d.cts.map +1 -0
- package/dist/sync/scan-limit.d.ts +21 -0
- package/dist/sync/scan-limit.d.ts.map +1 -0
- package/dist/sync/scan-limit.js +31 -0
- package/dist/sync/scan-limit.js.map +1 -0
- package/dist/sync/scanners/b2.cjs +239 -55
- package/dist/sync/scanners/b2.cjs.map +1 -1
- package/dist/sync/scanners/b2.d.cts +26 -7
- package/dist/sync/scanners/b2.d.cts.map +1 -1
- package/dist/sync/scanners/b2.d.ts +26 -7
- package/dist/sync/scanners/b2.d.ts.map +1 -1
- package/dist/sync/scanners/b2.js +239 -55
- package/dist/sync/scanners/b2.js.map +1 -1
- package/dist/sync/scanners/local.cjs +215 -56
- package/dist/sync/scanners/local.cjs.map +1 -1
- package/dist/sync/scanners/local.d.cts +22 -7
- package/dist/sync/scanners/local.d.cts.map +1 -1
- package/dist/sync/scanners/local.d.ts +22 -7
- package/dist/sync/scanners/local.d.ts.map +1 -1
- package/dist/sync/scanners/local.js +216 -57
- package/dist/sync/scanners/local.js.map +1 -1
- package/dist/sync/sha1-metadata.cjs +94 -0
- package/dist/sync/sha1-metadata.cjs.map +1 -0
- package/dist/sync/sha1-metadata.d.cts +82 -0
- package/dist/sync/sha1-metadata.d.cts.map +1 -0
- package/dist/sync/sha1-metadata.d.ts +82 -0
- package/dist/sync/sha1-metadata.d.ts.map +1 -0
- package/dist/sync/sha1-metadata.js +89 -0
- package/dist/sync/sha1-metadata.js.map +1 -0
- package/dist/sync/sha1-options.cjs +23 -0
- package/dist/sync/sha1-options.cjs.map +1 -0
- package/dist/sync/sha1-options.d.cts +14 -0
- package/dist/sync/sha1-options.d.cts.map +1 -0
- package/dist/sync/sha1-options.d.ts +14 -0
- package/dist/sync/sha1-options.d.ts.map +1 -0
- package/dist/sync/sha1-options.js +21 -0
- package/dist/sync/sha1-options.js.map +1 -0
- package/dist/sync/synchronizer.cjs +783 -197
- package/dist/sync/synchronizer.cjs.map +1 -1
- package/dist/sync/synchronizer.d.cts +47 -1
- package/dist/sync/synchronizer.d.cts.map +1 -1
- package/dist/sync/synchronizer.d.ts +47 -1
- package/dist/sync/synchronizer.d.ts.map +1 -1
- package/dist/sync/synchronizer.js +780 -173
- package/dist/sync/synchronizer.js.map +1 -1
- package/dist/sync/types.d.cts +208 -16
- package/dist/sync/types.d.cts.map +1 -1
- package/dist/sync/types.d.ts +208 -16
- package/dist/sync/types.d.ts.map +1 -1
- package/dist/types/auth.cjs +80 -56
- package/dist/types/auth.cjs.map +1 -1
- package/dist/types/auth.d.cts +71 -9
- package/dist/types/auth.d.cts.map +1 -1
- package/dist/types/auth.d.ts +71 -9
- package/dist/types/auth.d.ts.map +1 -1
- package/dist/types/auth.js +81 -57
- package/dist/types/auth.js.map +1 -1
- package/dist/types/backup.d.cts +80 -0
- package/dist/types/backup.d.cts.map +1 -0
- package/dist/types/backup.d.ts +80 -0
- package/dist/types/backup.d.ts.map +1 -0
- package/dist/types/bucket.cjs +74 -38
- package/dist/types/bucket.cjs.map +1 -1
- package/dist/types/bucket.d.cts +4 -2
- package/dist/types/bucket.d.cts.map +1 -1
- package/dist/types/bucket.d.ts +4 -2
- package/dist/types/bucket.d.ts.map +1 -1
- package/dist/types/bucket.js +75 -41
- package/dist/types/bucket.js.map +1 -1
- package/dist/types/download.cjs +62 -0
- package/dist/types/download.cjs.map +1 -0
- package/dist/types/download.d.cts +98 -0
- package/dist/types/download.d.cts.map +1 -1
- package/dist/types/download.d.ts +98 -0
- package/dist/types/download.d.ts.map +1 -1
- package/dist/types/download.js +61 -0
- package/dist/types/download.js.map +1 -0
- package/dist/types/encryption.cjs +194 -328
- package/dist/types/encryption.cjs.map +1 -1
- package/dist/types/encryption.d.cts +48 -0
- package/dist/types/encryption.d.cts.map +1 -1
- package/dist/types/encryption.d.ts +48 -0
- package/dist/types/encryption.d.ts.map +1 -1
- package/dist/types/encryption.js +192 -311
- package/dist/types/encryption.js.map +1 -1
- package/dist/types/errors.cjs +56 -0
- package/dist/types/errors.cjs.map +1 -0
- package/dist/types/errors.d.cts +13 -4
- package/dist/types/errors.d.cts.map +1 -1
- package/dist/types/errors.d.ts +13 -4
- package/dist/types/errors.d.ts.map +1 -1
- package/dist/types/errors.js +56 -0
- package/dist/types/errors.js.map +1 -0
- package/dist/types/file.cjs +36 -19
- package/dist/types/file.cjs.map +1 -1
- package/dist/types/file.d.cts +17 -4
- package/dist/types/file.d.cts.map +1 -1
- package/dist/types/file.d.ts +17 -4
- package/dist/types/file.d.ts.map +1 -1
- package/dist/types/file.js +37 -21
- package/dist/types/file.js.map +1 -1
- package/dist/types/ids.cjs +83 -9
- package/dist/types/ids.cjs.map +1 -1
- package/dist/types/ids.d.cts +32 -0
- package/dist/types/ids.d.cts.map +1 -1
- package/dist/types/ids.d.ts +32 -0
- package/dist/types/ids.d.ts.map +1 -1
- package/dist/types/ids.js +82 -16
- package/dist/types/ids.js.map +1 -1
- package/dist/types/index.d.cts +18 -13
- package/dist/types/index.d.cts.map +1 -1
- package/dist/types/index.d.ts +18 -13
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/key.d.cts +44 -8
- package/dist/types/key.d.cts.map +1 -1
- package/dist/types/key.d.ts +44 -8
- package/dist/types/key.d.ts.map +1 -1
- package/dist/types/lock.cjs +33 -13
- package/dist/types/lock.cjs.map +1 -1
- package/dist/types/lock.d.cts +14 -0
- package/dist/types/lock.d.cts.map +1 -1
- package/dist/types/lock.d.ts +14 -0
- package/dist/types/lock.d.ts.map +1 -1
- package/dist/types/lock.js +34 -15
- package/dist/types/lock.js.map +1 -1
- package/dist/types/notifications.cjs +44 -22
- package/dist/types/notifications.cjs.map +1 -1
- package/dist/types/notifications.d.cts +5 -3
- package/dist/types/notifications.d.cts.map +1 -1
- package/dist/types/notifications.d.ts +5 -3
- package/dist/types/notifications.d.ts.map +1 -1
- package/dist/types/notifications.js +45 -23
- package/dist/types/notifications.js.map +1 -1
- package/dist/types/partner.cjs +32 -0
- package/dist/types/partner.cjs.map +1 -0
- package/dist/types/partner.d.cts +394 -0
- package/dist/types/partner.d.cts.map +1 -0
- package/dist/types/partner.d.ts +394 -0
- package/dist/types/partner.d.ts.map +1 -0
- package/dist/types/partner.js +29 -0
- package/dist/types/partner.js.map +1 -0
- package/dist/types/upload.d.cts +53 -6
- package/dist/types/upload.d.cts.map +1 -1
- package/dist/types/upload.d.ts +53 -6
- package/dist/types/upload.d.ts.map +1 -1
- package/dist/upload/abort-scope.cjs +46 -0
- package/dist/upload/abort-scope.cjs.map +1 -0
- package/dist/upload/abort-scope.d.cts +26 -0
- package/dist/upload/abort-scope.d.cts.map +1 -0
- package/dist/upload/abort-scope.d.ts +26 -0
- package/dist/upload/abort-scope.d.ts.map +1 -0
- package/dist/upload/abort-scope.js +45 -0
- package/dist/upload/abort-scope.js.map +1 -0
- package/dist/upload/cancel.cjs +183 -8
- package/dist/upload/cancel.cjs.map +1 -1
- package/dist/upload/cancel.d.cts +110 -2
- package/dist/upload/cancel.d.cts.map +1 -1
- package/dist/upload/cancel.d.ts +110 -2
- package/dist/upload/cancel.d.ts.map +1 -1
- package/dist/upload/cancel.js +178 -9
- package/dist/upload/cancel.js.map +1 -1
- package/dist/upload/concurrency.cjs +79 -52
- package/dist/upload/concurrency.cjs.map +1 -1
- package/dist/upload/concurrency.js +79 -53
- package/dist/upload/concurrency.js.map +1 -1
- package/dist/upload/finish.cjs +54 -0
- package/dist/upload/finish.cjs.map +1 -0
- package/dist/upload/finish.d.cts +26 -0
- package/dist/upload/finish.d.cts.map +1 -0
- package/dist/upload/finish.d.ts +26 -0
- package/dist/upload/finish.d.ts.map +1 -0
- package/dist/upload/finish.js +54 -0
- package/dist/upload/finish.js.map +1 -0
- package/dist/upload/large.cjs +305 -218
- package/dist/upload/large.cjs.map +1 -1
- package/dist/upload/large.d.cts +90 -9
- package/dist/upload/large.d.cts.map +1 -1
- package/dist/upload/large.d.ts +90 -9
- package/dist/upload/large.d.ts.map +1 -1
- package/dist/upload/large.js +305 -218
- package/dist/upload/large.js.map +1 -1
- package/dist/upload/options.cjs +28 -0
- package/dist/upload/options.cjs.map +1 -0
- package/dist/upload/options.d.cts +116 -0
- package/dist/upload/options.d.cts.map +1 -0
- package/dist/upload/options.d.ts +116 -0
- package/dist/upload/options.d.ts.map +1 -0
- package/dist/upload/options.js +27 -0
- package/dist/upload/options.js.map +1 -0
- package/dist/upload/resume.cjs +334 -33
- package/dist/upload/resume.cjs.map +1 -1
- package/dist/upload/resume.d.cts +84 -12
- package/dist/upload/resume.d.cts.map +1 -1
- package/dist/upload/resume.d.ts +84 -12
- package/dist/upload/resume.d.ts.map +1 -1
- package/dist/upload/resume.js +331 -33
- package/dist/upload/resume.js.map +1 -1
- package/dist/upload/retry.cjs +191 -0
- package/dist/upload/retry.cjs.map +1 -0
- package/dist/upload/retry.d.cts +127 -0
- package/dist/upload/retry.d.cts.map +1 -0
- package/dist/upload/retry.d.ts +127 -0
- package/dist/upload/retry.d.ts.map +1 -0
- package/dist/upload/retry.js +187 -0
- package/dist/upload/retry.js.map +1 -0
- package/dist/upload/single.cjs +69 -44
- package/dist/upload/single.cjs.map +1 -1
- package/dist/upload/single.d.cts +8 -1
- package/dist/upload/single.d.cts.map +1 -1
- package/dist/upload/single.d.ts +8 -1
- package/dist/upload/single.d.ts.map +1 -1
- package/dist/upload/single.js +69 -44
- package/dist/upload/single.js.map +1 -1
- package/dist/upload/stream.cjs +319 -193
- package/dist/upload/stream.cjs.map +1 -1
- package/dist/upload/stream.d.cts +9 -1
- package/dist/upload/stream.d.cts.map +1 -1
- package/dist/upload/stream.d.ts +9 -1
- package/dist/upload/stream.d.ts.map +1 -1
- package/dist/upload/stream.js +318 -192
- package/dist/upload/stream.js.map +1 -1
- package/dist/util/abort.cjs +114 -0
- package/dist/util/abort.cjs.map +1 -0
- package/dist/util/abort.d.cts +65 -0
- package/dist/util/abort.d.cts.map +1 -0
- package/dist/util/abort.d.ts +65 -0
- package/dist/util/abort.d.ts.map +1 -0
- package/dist/util/abort.js +109 -0
- package/dist/util/abort.js.map +1 -0
- package/dist/util/best-effort.cjs +42 -8
- package/dist/util/best-effort.cjs.map +1 -1
- package/dist/util/best-effort.d.cts +2 -1
- package/dist/util/best-effort.d.cts.map +1 -1
- package/dist/util/best-effort.d.ts +2 -1
- package/dist/util/best-effort.d.ts.map +1 -1
- package/dist/util/best-effort.js +43 -9
- package/dist/util/best-effort.js.map +1 -1
- package/dist/util/bytes.cjs +23 -0
- package/dist/util/bytes.cjs.map +1 -0
- package/dist/util/bytes.d.cts +15 -0
- package/dist/util/bytes.d.cts.map +1 -0
- package/dist/util/bytes.d.ts +15 -0
- package/dist/util/bytes.d.ts.map +1 -0
- package/dist/util/bytes.js +23 -0
- package/dist/util/bytes.js.map +1 -0
- package/dist/util/crypto.cjs +68 -0
- package/dist/util/crypto.cjs.map +1 -0
- package/dist/util/crypto.d.cts +26 -0
- package/dist/util/crypto.d.cts.map +1 -0
- package/dist/util/crypto.d.ts +26 -0
- package/dist/util/crypto.d.ts.map +1 -0
- package/dist/util/crypto.js +66 -0
- package/dist/util/crypto.js.map +1 -0
- package/dist/util/defaults.cjs +28 -9
- package/dist/util/defaults.cjs.map +1 -1
- package/dist/util/defaults.d.cts +2 -0
- package/dist/util/defaults.d.cts.map +1 -1
- package/dist/util/defaults.d.ts +2 -0
- package/dist/util/defaults.d.ts.map +1 -1
- package/dist/util/defaults.js +28 -11
- package/dist/util/defaults.js.map +1 -1
- package/dist/util/error-reason.cjs +41 -0
- package/dist/util/error-reason.cjs.map +1 -0
- package/dist/util/error-reason.d.cts +9 -0
- package/dist/util/error-reason.d.cts.map +1 -0
- package/dist/util/error-reason.d.ts +9 -0
- package/dist/util/error-reason.d.ts.map +1 -0
- package/dist/util/error-reason.js +41 -0
- package/dist/util/error-reason.js.map +1 -0
- package/dist/util/http.cjs +23 -0
- package/dist/util/http.cjs.map +1 -0
- package/dist/util/http.d.cts +13 -0
- package/dist/util/http.d.cts.map +1 -0
- package/dist/util/http.d.ts +13 -0
- package/dist/util/http.d.ts.map +1 -0
- package/dist/util/http.js +23 -0
- package/dist/util/http.js.map +1 -0
- package/dist/util/md5.cjs +211 -0
- package/dist/util/md5.cjs.map +1 -0
- package/dist/util/md5.d.cts +43 -0
- package/dist/util/md5.d.cts.map +1 -0
- package/dist/util/md5.d.ts +43 -0
- package/dist/util/md5.d.ts.map +1 -0
- package/dist/util/md5.js +209 -0
- package/dist/util/md5.js.map +1 -0
- package/dist/util/normalize.cjs +66 -7
- package/dist/util/normalize.cjs.map +1 -1
- package/dist/util/normalize.d.cts +7 -7
- package/dist/util/normalize.d.cts.map +1 -1
- package/dist/util/normalize.d.ts +7 -7
- package/dist/util/normalize.d.ts.map +1 -1
- package/dist/util/normalize.js +67 -10
- package/dist/util/normalize.js.map +1 -1
- package/dist/util/paginator.cjs +69 -14
- package/dist/util/paginator.cjs.map +1 -1
- package/dist/util/paginator.d.cts +3 -1
- package/dist/util/paginator.d.cts.map +1 -1
- package/dist/util/paginator.d.ts +3 -1
- package/dist/util/paginator.d.ts.map +1 -1
- package/dist/util/paginator.js +70 -16
- package/dist/util/paginator.js.map +1 -1
- package/dist/util/plan-ranges.cjs +47 -22
- package/dist/util/plan-ranges.cjs.map +1 -1
- package/dist/util/plan-ranges.js +48 -24
- package/dist/util/plan-ranges.js.map +1 -1
- package/dist/util/sha1.cjs +27 -0
- package/dist/util/sha1.cjs.map +1 -0
- package/dist/util/sha1.d.cts +17 -0
- package/dist/util/sha1.d.cts.map +1 -0
- package/dist/util/sha1.d.ts +17 -0
- package/dist/util/sha1.d.ts.map +1 -0
- package/dist/util/sha1.js +26 -0
- package/dist/util/sha1.js.map +1 -0
- package/dist/util/text-codec.cjs +29 -5
- package/dist/util/text-codec.cjs.map +1 -1
- package/dist/util/text-codec.js +30 -7
- package/dist/util/text-codec.js.map +1 -1
- package/dist/util/to-error.cjs +18 -4
- package/dist/util/to-error.cjs.map +1 -1
- package/dist/util/to-error.js +19 -5
- package/dist/util/to-error.js.map +1 -1
- package/dist/version.cjs +17 -5
- package/dist/version.cjs.map +1 -1
- package/dist/version.d.cts +3 -3
- package/dist/version.d.ts +3 -3
- package/dist/version.js +19 -6
- package/dist/version.js.map +1 -1
- package/package.json +45 -20
- package/dist/auth/index.cjs.map +0 -1
- package/dist/auth/index.js.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/notifications/index.cjs.map +0 -1
- package/dist/notifications/index.js.map +0 -1
- package/dist/package.json.cjs +0 -9
- package/dist/package.json.cjs.map +0 -1
- package/dist/package.json.js +0 -9
- package/dist/package.json.js.map +0 -1
- package/dist/streams/index.cjs.map +0 -1
- package/dist/streams/index.js.map +0 -1
- package/dist/sync/index.cjs.map +0 -1
- package/dist/sync/index.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream.js","sources":["../../src/upload/stream.ts"],"sourcesContent":["import type { AccountInfo } from '../auth/account-info.ts'\nimport type { RawClient } from '../raw/index.ts'\nimport { IncrementalSha1 } from '../streams/hash.ts'\nimport type { ProgressListener } from '../streams/progress.ts'\nimport { ProgressTracker } from '../streams/progress.ts'\nimport type { EncryptionSetting } from '../types/encryption.ts'\nimport type { FileVersion } from '../types/file.ts'\nimport type { BucketId, LargeFileId } from '../types/ids.ts'\nimport { DEFAULT_CONTENT_TYPE, DEFAULT_TRANSFER_CONCURRENCY } from '../util/defaults.ts'\nimport { toError } from '../util/to-error.ts'\nimport { cancelLargeFileBestEffort } from './cancel.ts'\nimport { Semaphore } from './concurrency.ts'\n\n/** Options for creating a streaming multipart upload sink. */\nexport interface CreateWriteStreamOptions {\n /** Target bucket for the upload. */\n readonly bucketId: BucketId\n /** Destination file name in the bucket. */\n readonly fileName: string\n /** MIME type. Defaults to `b2/x-auto`. */\n readonly contentType?: string\n /** Custom file info stored with the file. */\n readonly fileInfo?: Record<string, string>\n /** Server-side encryption applied to each part. */\n readonly serverSideEncryption?: EncryptionSetting\n /**\n * Target part size in bytes. The stream buffers writes until this many bytes\n * are accumulated, then ships a part. Must be at least the account's\n * absolute minimum part size; the implementation will raise it if too small.\n */\n readonly partSize?: number\n /** Maximum number of parts uploaded in parallel. Defaults to 4. */\n readonly concurrency?: number\n /** Callback invoked with upload progress events. `totalBytes` is `null` (size unknown). */\n readonly onProgress?: ProgressListener\n /** Aborts the upload and cancels the unfinished large file. */\n readonly signal?: AbortSignal\n}\n\n/**\n * Handle returned by `B2Object.createWriteStream`: the Web `WritableStream` to\n * pipe data into, plus a promise that resolves with the finished\n * {@link FileVersion} once the stream is closed and all parts have been\n * uploaded.\n */\nexport interface UploadWriteHandle {\n /** Web `WritableStream` sink to pipe data into. */\n readonly writable: WritableStream<Uint8Array>\n /** Resolves with the finalized file version when the stream closes successfully. */\n readonly done: Promise<FileVersion>\n}\n\n/**\n * Creates a {@link WritableStream} that streams data into a B2 multipart upload.\n *\n * Buffers incoming chunks until `partSize` bytes are accumulated, ships each\n * complete part through the standard multipart engine, and finalizes the file\n * once the stream is closed. Honours backpressure via the queue's bounded\n * concurrency. Streaming uploads do not support resume because the total size\n * and per-part hashes aren't known in advance; use {@link uploadLargeFile} with\n * a buffered source when resume is required.\n *\n * @param raw - Low-level B2 API client.\n * @param accountInfo - Authorized account state (tokens, URLs, part URL pool).\n * @param options - Streaming upload parameters.\n *\n * @returns A {@link UploadWriteHandle} with the writable sink and a completion promise.\n */\nexport function createWriteStream(\n raw: RawClient,\n accountInfo: AccountInfo,\n options: CreateWriteStreamOptions,\n): UploadWriteHandle {\n const minPartSize = accountInfo.getAbsoluteMinimumPartSize()\n const recommendedPartSize = accountInfo.getRecommendedPartSize()\n const partSize = Math.max(options.partSize ?? recommendedPartSize, minPartSize)\n const concurrency = options.concurrency ?? DEFAULT_TRANSFER_CONCURRENCY\n const tracker = new ProgressTracker(options.onProgress, null, null)\n const sem = new Semaphore(concurrency)\n\n let largeFileId: LargeFileId | null = null\n let startPromise: Promise<LargeFileId> | null = null\n let nextPartNumber = 1\n let pendingBytes = 0\n const pending: Uint8Array[] = []\n const partSha1s: string[] = []\n const inflight: Promise<void>[] = []\n let errored: Error | null = null\n\n // ES2024 `Promise.withResolvers()` exposes the resolve/reject pair as\n // properties of the returned object, avoiding the `let resolve!:` /\n // `let reject!:` non-null-assertion pattern needed before this API\n // existed. Available in Node 22 (our minimum), Bun, Deno, modern\n // browsers, and Cloudflare Workers.\n const {\n promise: done,\n resolve: resolveDone,\n reject: rejectDone,\n } = Promise.withResolvers<FileVersion>()\n // Attach a no-op rejection handler so a `done` that rejects before the\n // caller observes it never surfaces as a process-level unhandled rejection.\n // The error is not swallowed: `close()`/`abort()` also reject the writable\n // (so `pipeTo`/`getWriter().close()` throw), and any later `await done` /\n // `done.then(onRejected)` the caller attaches still sees the rejection —\n // extra handlers on the same promise all fire. Mirrors the\n // `task.catch(() => {})` pattern used for inflight part uploads below, and\n // keeps the engine well-behaved under Bun and Node's strict\n // unhandled-rejection mode.\n done.catch(() => {})\n\n function ensureStarted(): Promise<LargeFileId> {\n if (largeFileId !== null) return Promise.resolve(largeFileId)\n if (startPromise !== null) return startPromise\n startPromise = (async () => {\n const resp = await raw.startLargeFile(accountInfo.getApiUrl(), accountInfo.getAuthToken(), {\n bucketId: options.bucketId,\n fileName: options.fileName,\n contentType: options.contentType ?? DEFAULT_CONTENT_TYPE,\n fileInfo: options.fileInfo ?? {},\n ...(options.serverSideEncryption !== undefined\n ? { serverSideEncryption: options.serverSideEncryption }\n : {}),\n })\n largeFileId = resp.fileId\n return largeFileId\n })()\n return startPromise\n }\n\n async function shipPart(data: Uint8Array, partNumber: number): Promise<void> {\n const fileId = await ensureStarted()\n\n const sha1 = new IncrementalSha1()\n await sha1.update(data)\n const sha1Hex = await sha1.digest()\n\n let uploadEntry = accountInfo.checkoutPartUploadUrl(fileId)\n if (!uploadEntry) {\n const resp = await raw.getUploadPartUrl(accountInfo.getApiUrl(), accountInfo.getAuthToken(), {\n fileId,\n })\n uploadEntry = { uploadUrl: resp.uploadUrl, authorizationToken: resp.authorizationToken }\n }\n\n try {\n const result = await raw.uploadPart(\n uploadEntry.uploadUrl,\n {\n authorization: uploadEntry.authorizationToken,\n partNumber,\n contentLength: data.byteLength,\n contentSha1: sha1Hex,\n ...(options.serverSideEncryption !== undefined\n ? { serverSideEncryption: options.serverSideEncryption }\n : {}),\n },\n data as BodyInit,\n options.signal,\n )\n accountInfo.returnPartUploadUrl(fileId, uploadEntry)\n partSha1s[partNumber - 1] = result.contentSha1\n tracker.addBytes(data.byteLength)\n tracker.completePart()\n } catch (err) {\n accountInfo.evictPartUploadUrl(fileId, uploadEntry)\n throw err\n }\n }\n\n function dispatchPart(): void {\n if (pending.length === 0) return\n let data: Uint8Array\n if (pending.length === 1) {\n const head = pending[0]\n if (!head) return\n data = head\n } else {\n const total = pending.reduce((sum, chunk) => sum + chunk.byteLength, 0)\n data = new Uint8Array(total)\n let offset = 0\n for (const chunk of pending) {\n data.set(chunk, offset)\n offset += chunk.byteLength\n }\n }\n pending.length = 0\n pendingBytes = 0\n const partNumber = nextPartNumber++\n const task = (async () => {\n await sem.acquire()\n try {\n await shipPart(data, partNumber)\n } catch (err) {\n errored = toError(err)\n throw err\n } finally {\n sem.release()\n }\n })()\n inflight.push(task)\n // Swallow rejection here; we check `errored` later.\n task.catch(() => {})\n }\n\n const writable = new WritableStream<Uint8Array>({\n async write(chunk: Uint8Array): Promise<void> {\n if (errored) throw errored\n options.signal?.throwIfAborted()\n\n pending.push(chunk)\n pendingBytes += chunk.byteLength\n while (pendingBytes >= partSize) {\n // Pull exactly partSize bytes off the front\n const carved = carveExact(pending, partSize)\n const partNumber = nextPartNumber++\n pendingBytes -= partSize\n const task = (async () => {\n await sem.acquire()\n try {\n await shipPart(carved, partNumber)\n } catch (err) {\n errored = toError(err)\n throw err\n } finally {\n sem.release()\n }\n })()\n inflight.push(task)\n task.catch(() => {})\n }\n },\n\n async close(): Promise<void> {\n try {\n if (errored) throw errored\n options.signal?.throwIfAborted()\n\n // Ship any remaining bytes as the last part. If the total fit in one\n // single buffered batch (no parts shipped yet), we have to use the\n // multipart path anyway since we already called startLargeFile lazily.\n if (pendingBytes > 0) {\n dispatchPart()\n }\n\n await Promise.all(inflight)\n if (errored) throw errored\n\n if (largeFileId === null) {\n // Stream closed before any data was written. Start an empty large\n // file? B2 requires at least 2 parts. Reject — callers shouldn't\n // close an empty stream.\n throw new Error('createWriteStream closed without any data written.')\n }\n\n const result = await raw.finishLargeFile(\n accountInfo.getApiUrl(),\n accountInfo.getAuthToken(),\n { fileId: largeFileId, partSha1Array: partSha1s },\n )\n resolveDone(result)\n } catch (err) {\n // Capture into a const so the cancel closure sees a non-null\n // `fileId`; closures don't observe the outer `!== null` narrowing\n // because the variable is mutable across the lambda boundary.\n const fileIdToCancel = largeFileId\n if (fileIdToCancel !== null) {\n await cancelLargeFileBestEffort(raw, accountInfo, fileIdToCancel)\n }\n rejectDone(err)\n throw err\n }\n },\n\n async abort(reason: unknown): Promise<void> {\n const fileIdToCancel = largeFileId\n if (fileIdToCancel !== null) {\n await cancelLargeFileBestEffort(raw, accountInfo, fileIdToCancel)\n }\n rejectDone(toError(reason))\n },\n })\n\n return { writable, done }\n}\n\n/**\n * Removes exactly `size` bytes from the front of `chunks` (mutates) and returns\n * them as a contiguous Uint8Array. Any trailing remainder of the last chunk\n * stays at the front of `chunks` for the next part.\n *\n * @param chunks - Queue of pending chunks. Modified in place.\n * @param size - Number of bytes to carve off the front.\n *\n * @returns A new Uint8Array containing exactly `size` bytes.\n */\nfunction carveExact(chunks: Uint8Array[], size: number): Uint8Array {\n const out = new Uint8Array(size)\n let written = 0\n while (written < size && chunks.length > 0) {\n const head = chunks[0]\n if (!head) break\n const need = size - written\n if (head.byteLength <= need) {\n out.set(head, written)\n written += head.byteLength\n chunks.shift()\n } else {\n out.set(head.subarray(0, need), written)\n chunks[0] = head.subarray(need)\n written += need\n }\n }\n return out\n}\n"],"names":[],"mappings":";;;;;;AAoEO,SAAS,kBACd,KACA,aACA,SACmB;AACnB,QAAM,cAAc,YAAY,2BAAA;AAChC,QAAM,sBAAsB,YAAY,uBAAA;AACxC,QAAM,WAAW,KAAK,IAAI,QAAQ,YAAY,qBAAqB,WAAW;AAC9E,QAAM,cAAc,QAAQ,eAAe;AAC3C,QAAM,UAAU,IAAI,gBAAgB,QAAQ,YAAY,MAAM,IAAI;AAClE,QAAM,MAAM,IAAI,UAAU,WAAW;AAErC,MAAI,cAAkC;AACtC,MAAI,eAA4C;AAChD,MAAI,iBAAiB;AACrB,MAAI,eAAe;AACnB,QAAM,UAAwB,CAAA;AAC9B,QAAM,YAAsB,CAAA;AAC5B,QAAM,WAA4B,CAAA;AAClC,MAAI,UAAwB;AAO5B,QAAM;AAAA,IACJ,SAAS;AAAA,IACT,SAAS;AAAA,IACT,QAAQ;AAAA,EAAA,IACN,QAAQ,cAAA;AAUZ,OAAK,MAAM,MAAM;AAAA,EAAC,CAAC;AAEnB,WAAS,gBAAsC;AAC7C,QAAI,gBAAgB,KAAM,QAAO,QAAQ,QAAQ,WAAW;AAC5D,QAAI,iBAAiB,KAAM,QAAO;AAClC,oBAAgB,YAAY;AAC1B,YAAM,OAAO,MAAM,IAAI,eAAe,YAAY,UAAA,GAAa,YAAY,gBAAgB;AAAA,QACzF,UAAU,QAAQ;AAAA,QAClB,UAAU,QAAQ;AAAA,QAClB,aAAa,QAAQ,eAAe;AAAA,QACpC,UAAU,QAAQ,YAAY,CAAA;AAAA,QAC9B,GAAI,QAAQ,yBAAyB,SACjC,EAA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AQ,IAAI,QAAQ;AAC1B,YAAI,QAAS,OAAM;AAEnB,YAAI,gBAAgB,MAAM;AAIxB,gBAAM,IAAI,MAAM,oDAAoD;AAAA,QACtE;AAEA,cAAM,SAAS,MAAM,IAAI;AAAA,UACvB,YAAY,UAAA;AAAA,UACZ,YAAY,aAAA;AAAA,UACZ,EAAE,QAAQ,aAAa,eAAe,UAAA;AAAA,QAAU;AAElD,oBAAY,MAAM;AAAA,MACpB,SAAS,KAAK;AAIZ,cAAM,iBAAiB;AACvB,YAAI,mBAAmB,MAAM;AAC3B,gBAAM,0BAA0B,KAAK,aAAa,cAAc;AAAA,QAClE;AACA,mBAAW,GAAG;AACd,cAAM;AAAA,MACR;AAAA,IACF;AAAA,IAEA,MAAM,MAAM,QAAgC;AAC1C,YAAM,iBAAiB;AACvB,UAAI,mBAAmB,MAAM;AAC3B,cAAM,0BAA0B,KAAK,aAAa,cAAc;AAAA,MAClE;AACA,iBAAW,QAAQ,MAAM,CAAC;AAAA,IAC5B;AAAA,EAAA,CACD;AAED,SAAO,EAAE,UAAU,KAAA;AACrB;AAYA,SAAS,WAAW,QAAsB,MAA0B;AAClE,QAAM,MAAM,IAAI,WAAW,IAAI;AAC/B,MAAI,UAAU;AACd,SAAO,UAAU,QAAQ,OAAO,SAAS,GAAG;AAC1C,UAAM,OAAO,OAAO,CAAC;AACrB,QAAI,CAAC,KAAM;AACX,UAAM,OAAO,OAAO;AACpB,QAAI,KAAK,cAAc,MAAM;AAC3B,UAAI,IAAI,MAAM,OAAO;AACrB,iBAAW,KAAK;AAChB,aAAO,MAAA;AAAA,IACT,OAAO;AACL,UAAI,IAAI,KAAK,SAAS,GAAG,IAAI,GAAG,OAAO;AACvC,aAAO,CAAC,IAAI,KAAK,SAAS,IAAI;AAC9B,iBAAW;AAAA,IACb;AAAA,EACF;AACA,SAAO;AACT;"}
|
|
1
|
+
{"version":3,"file":"stream.js","names":[],"sources":["../../src/upload/stream.ts"],"sourcesContent":["import type { AccountInfo } from '../auth/account-info.ts'\nimport type { RawClient } from '../raw/index.ts'\nimport { IncrementalSha1 } from '../streams/hash.ts'\nimport type { ProgressListener } from '../streams/progress.ts'\nimport { ProgressTracker } from '../streams/progress.ts'\nimport type { EncryptionSetting } from '../types/encryption.ts'\nimport type { FileVersion } from '../types/file.ts'\nimport type { BucketId, LargeFileId } from '../types/ids.ts'\nimport { abortReason, raceWithAbort } from '../util/abort.ts'\nimport { DEFAULT_CONTENT_TYPE, DEFAULT_TRANSFER_CONCURRENCY } from '../util/defaults.ts'\nimport { toError } from '../util/to-error.ts'\nimport { createAbortScope } from './abort-scope.ts'\nimport {\n type CleanupFailureOptions,\n cancelLargeFileBestEffort,\n DEFAULT_CLEANUP_TIMEOUT_MS,\n resolveLargeFileErrorAfterCleanup,\n} from './cancel.ts'\nimport { Semaphore } from './concurrency.ts'\nimport { finishLargeFileWithAbortReconciliation } from './finish.ts'\nimport {\n resolveRetryResponseBodyFailures,\n type UploadRetryOptions,\n uploadPartWithFreshUrl,\n} from './retry.ts'\n\n/** Options for creating a streaming multipart upload sink. */\nexport interface CreateWriteStreamOptions extends UploadRetryOptions, CleanupFailureOptions {\n /** Target bucket for the upload. */\n readonly bucketId: BucketId\n /** Destination file name in the bucket. */\n readonly fileName: string\n /** MIME type. Defaults to `b2/x-auto`. */\n readonly contentType?: string\n /** Custom file info stored with the file. */\n readonly fileInfo?: Record<string, string>\n /** Server-side encryption applied to each part. */\n readonly serverSideEncryption?: EncryptionSetting\n /**\n * B2 upload timestamp override in milliseconds since epoch.\n * Sets the file version `uploadTimestamp`; distinct from `src_last_modified_millis` metadata.\n * Requires B2 account enablement for Custom Upload Timestamp.\n */\n readonly customUploadTimestamp?: number\n /**\n * Target part size in bytes. The stream buffers writes until this many bytes\n * are accumulated, then ships a part. Must be at least the account's\n * absolute minimum part size; the implementation will raise it if too small.\n */\n readonly partSize?: number\n /** Maximum number of parts uploaded in parallel. Defaults to 4. */\n readonly concurrency?: number\n /** Callback invoked with upload progress events. `totalBytes` is `null` (size unknown). */\n readonly onProgress?: ProgressListener\n /** Aborts the upload and cancels the unfinished large file. */\n readonly signal?: AbortSignal\n}\n\n/**\n * Handle returned by `B2Object.createWriteStream`: the Web `WritableStream` to\n * pipe data into, plus a promise that resolves with the finished\n * {@link FileVersion} once the stream is closed and all parts have been\n * uploaded.\n */\nexport interface UploadWriteHandle {\n /** Web `WritableStream` sink to pipe data into. */\n readonly writable: WritableStream<Uint8Array>\n /** Resolves with the finalized file version when the stream closes successfully. */\n readonly done: Promise<FileVersion>\n}\n\n/**\n * Creates a {@link WritableStream} that streams data into a B2 multipart upload.\n *\n * Buffers incoming chunks until `partSize` bytes are accumulated, ships each\n * complete part through the standard multipart engine, and finalizes the file\n * once the stream is closed. Honours backpressure via the queue's bounded\n * concurrency. Streaming uploads do not support resume because the total size\n * and per-part hashes aren't known in advance; use {@link uploadLargeFile} with\n * a buffered source when resume is required.\n *\n * @param raw - Low-level B2 API client.\n * @param accountInfo - Authorized account state (tokens, URLs, part URL pool).\n * @param options - Streaming upload parameters.\n *\n * @returns A {@link UploadWriteHandle} with the writable sink and a completion promise.\n */\nexport function createWriteStream(\n raw: RawClient,\n accountInfo: AccountInfo,\n options: CreateWriteStreamOptions,\n): UploadWriteHandle {\n const minPartSize = accountInfo.getAbsoluteMinimumPartSize()\n const recommendedPartSize = accountInfo.getRecommendedPartSize()\n const partSize = Math.max(options.partSize ?? recommendedPartSize, minPartSize)\n const concurrency = options.concurrency ?? DEFAULT_TRANSFER_CONCURRENCY\n const tracker = new ProgressTracker(options.onProgress, null, null)\n const sem = new Semaphore(concurrency)\n const abortScope = createAbortScope(options.signal)\n\n let largeFileId: LargeFileId | null = null\n let startPromise: Promise<LargeFileId> | null = null\n let cancelAfterStartScheduled = false\n let nextPartNumber = 1\n let pendingBytes = 0\n const pending: Uint8Array[] = []\n const partSha1s: string[] = []\n const inflight: Promise<void>[] = []\n let errored: Error | null = null\n\n // ES2024 `Promise.withResolvers()` exposes the resolve/reject pair as\n // properties of the returned object, avoiding the `let resolve!:` /\n // `let reject!:` non-null-assertion pattern needed before this API\n // existed. Available in Node 22 (our minimum), Bun, Deno, modern\n // browsers, and Cloudflare Workers.\n const {\n promise: done,\n resolve: resolveDone,\n reject: rejectDone,\n } = Promise.withResolvers<FileVersion>()\n // Attach a no-op rejection handler so a `done` that rejects before the\n // caller observes it never surfaces as a process-level unhandled rejection.\n // The error is not swallowed: `close()`/`abort()` also reject the writable\n // (so `pipeTo`/`getWriter().close()` throw), and any later `await done` /\n // `done.then(onRejected)` the caller attaches still sees the rejection —\n // extra handlers on the same promise all fire. Mirrors the\n // `task.catch(() => {})` pattern used for inflight part uploads below, and\n // keeps the engine well-behaved under Bun and Node's strict\n // unhandled-rejection mode.\n done.catch(() => {})\n\n function ensureStarted(): Promise<LargeFileId> {\n if (largeFileId !== null) return Promise.resolve(largeFileId)\n if (startPromise === null) {\n const rawStart = raw.startLargeFile(\n accountInfo.getApiUrl(),\n accountInfo.getAuthToken(),\n {\n bucketId: options.bucketId,\n fileName: options.fileName,\n contentType: options.contentType ?? DEFAULT_CONTENT_TYPE,\n fileInfo: options.fileInfo ?? {},\n ...(options.customUploadTimestamp !== undefined\n ? { customUploadTimestamp: String(options.customUploadTimestamp) }\n : {}),\n ...(options.serverSideEncryption !== undefined\n ? { serverSideEncryption: options.serverSideEncryption }\n : {}),\n },\n {\n signal: abortScope.signal,\n ...(options.retry !== undefined ? { retry: options.retry } : {}),\n },\n )\n startPromise = rawStart.then((resp) => {\n largeFileId = resp.fileId\n if (abortScope.signal.aborted || errored !== null) {\n cancelStartedLargeFile(largeFileId)\n }\n return largeFileId\n })\n }\n const started = startPromise\n return raceWithAbort(started, abortScope.signal).catch((err) => {\n if (abortScope.signal.aborted) scheduleCancelLargeFileAfterStart(started)\n throw err\n })\n }\n\n async function shipPart(data: Uint8Array, partNumber: number): Promise<void> {\n if (errored !== null) throw errored\n abortScope.signal.throwIfAborted()\n const fileId = await ensureStarted()\n if (errored !== null) throw errored\n abortScope.signal.throwIfAborted()\n\n const sha1 = new IncrementalSha1()\n await sha1.update(data)\n const sha1Hex = await sha1.digest()\n abortScope.signal.throwIfAborted()\n\n const result = await uploadPartWithFreshUrl(raw, accountInfo, fileId, {\n fileName: options.fileName,\n partNumber,\n data: data as BodyInit,\n contentLength: data.byteLength,\n contentSha1: sha1Hex,\n retry: options.retry,\n signal: abortScope.signal,\n onUploadRetry: options.onUploadRetry,\n retryResponseBodyFailures: resolveRetryResponseBodyFailures(\n options.retryResponseBodyFailures,\n ),\n ...(options.serverSideEncryption !== undefined\n ? { serverSideEncryption: options.serverSideEncryption }\n : {}),\n })\n partSha1s[partNumber - 1] = result.contentSha1\n tracker.addBytes(data.byteLength)\n tracker.completePart()\n }\n\n function markErrored(err: unknown): Error {\n const error = toError(err)\n errored = error\n abortScope.abort(error)\n return error\n }\n\n function cancelStartedLargeFile(fileId: LargeFileId): void {\n if (cancelAfterStartScheduled) return\n cancelAfterStartScheduled = true\n void cancelLargeFileBestEffort(raw, accountInfo, fileId, cleanupWriteStreamOptions(options))\n }\n\n function scheduleCancelLargeFileAfterStart(started: Promise<LargeFileId>): void {\n void started\n .then((fileId) => cancelStartedLargeFile(fileId))\n .catch(() => {\n // If start failed, no file ID is available to cancel.\n })\n }\n\n async function settleInflightForClose(): Promise<PromiseSettledResult<void>[]> {\n const settled = Promise.allSettled(inflight)\n if (startPromise === null || largeFileId !== null) return await settled\n\n const abortWaiter = waitForAbort(abortScope.signal)\n try {\n const first = await Promise.race([\n settled.then(() => 'settled' as const),\n startPromise.then(\n () => 'start-settled' as const,\n () => 'start-settled' as const,\n ),\n abortWaiter.promise.then(() => 'aborted' as const),\n ])\n if (first === 'aborted' && largeFileId === null) {\n throw abortReason(abortScope.signal)\n }\n return await settled\n } finally {\n abortWaiter.dispose()\n }\n }\n\n function startPartWithAcquiredSlot(data: Uint8Array, partNumber: number): void {\n const task = (async () => {\n try {\n await shipPart(data, partNumber)\n } catch (err) {\n markErrored(err)\n throw err\n } finally {\n sem.release()\n }\n })()\n inflight.push(task)\n // Swallow rejection here; we check `errored` later.\n task.catch(() => {})\n }\n\n async function acquirePartSlot(): Promise<void> {\n await sem.acquire()\n if (errored !== null) {\n sem.release()\n throw errored\n }\n try {\n abortScope.signal.throwIfAborted()\n } catch (err) {\n sem.release()\n throw err\n }\n }\n\n async function waitForInflightPartsToSettle(\n timeoutMs = DEFAULT_CLEANUP_TIMEOUT_MS,\n ): Promise<void> {\n if (inflight.length === 0) return\n let timeout: ReturnType<typeof setTimeout> | undefined\n try {\n await Promise.race([\n Promise.allSettled(inflight).then(() => undefined),\n new Promise<void>((resolve) => {\n timeout = setTimeout(resolve, timeoutMs)\n }),\n ])\n } finally {\n if (timeout !== undefined) clearTimeout(timeout)\n }\n }\n\n async function dispatchPart(): Promise<void> {\n if (pending.length === 0) return\n await acquirePartSlot()\n let data: Uint8Array\n if (pending.length === 1) {\n const head = pending[0]\n if (!head) {\n sem.release()\n return\n }\n data = head\n } else {\n const total = pending.reduce((sum, chunk) => sum + chunk.byteLength, 0)\n data = new Uint8Array(total)\n let offset = 0\n for (const chunk of pending) {\n data.set(chunk, offset)\n offset += chunk.byteLength\n }\n }\n pending.length = 0\n pendingBytes = 0\n const partNumber = nextPartNumber++\n startPartWithAcquiredSlot(data, partNumber)\n }\n\n const writable = new WritableStream<Uint8Array>({\n async write(chunk: Uint8Array): Promise<void> {\n if (errored) throw errored\n abortScope.signal.throwIfAborted()\n if (chunk.byteLength === 0) return\n\n pending.push(chunk)\n pendingBytes += chunk.byteLength\n while (pendingBytes >= partSize) {\n await acquirePartSlot()\n if (errored) {\n sem.release()\n throw errored\n }\n // Pull exactly partSize bytes off the front\n const carved = carveExact(pending, partSize)\n const partNumber = nextPartNumber++\n pendingBytes -= partSize\n startPartWithAcquiredSlot(carved, partNumber)\n }\n },\n\n async close(): Promise<void> {\n try {\n if (errored) throw errored\n abortScope.signal.throwIfAborted()\n\n // Ship any remaining bytes as the last part. If the total fit in one\n // single buffered batch (no parts shipped yet), we have to use the\n // multipart path anyway since we already called startLargeFile lazily.\n if (pendingBytes > 0) {\n await dispatchPart()\n }\n\n const settled = await settleInflightForClose()\n const rejected = settled.find(\n (result): result is PromiseRejectedResult => result.status === 'rejected',\n )\n if (rejected !== undefined && errored === null) {\n markErrored(rejected.reason)\n }\n if (errored) throw errored\n\n if (largeFileId === null) {\n // Stream closed before any data was written. Start an empty large\n // file? B2 requires at least 2 parts. Reject — callers shouldn't\n // close an empty stream.\n throw new Error('createWriteStream closed without any data written.')\n }\n\n const result = await finishLargeFileWithAbortReconciliation(raw, accountInfo, {\n fileId: largeFileId,\n bucketId: options.bucketId,\n fileName: options.fileName,\n partSha1s,\n signal: abortScope.signal,\n ...(options.retry !== undefined ? { retry: options.retry } : {}),\n })\n abortScope.dispose()\n resolveDone(result)\n } catch (err) {\n const closeError = toError(err)\n if (errored === null) errored = closeError\n abortScope.abort(errored)\n const observedError = errored\n const fileIdToCancel = largeFileId\n if (fileIdToCancel === null && startPromise !== null) {\n // Mirror writer.abort(): close() must not wait for non-abortable\n // b2_start_large_file. If a file ID arrives later, cancel it in the\n // background.\n scheduleCancelLargeFileAfterStart(startPromise)\n abortScope.dispose()\n rejectDone(observedError)\n throw observedError\n }\n await Promise.allSettled(inflight)\n // Capture into a const so the cancel closure sees a non-null\n // `fileId`; closures don't observe the outer `!== null` narrowing\n // because the variable is mutable across the lambda boundary.\n let finalError: unknown = observedError\n if (fileIdToCancel !== null) {\n finalError = await resolveLargeFileErrorAfterCleanup(observedError, raw, accountInfo, {\n fileId: fileIdToCancel,\n bucketId: options.bucketId,\n fileName: options.fileName,\n signal: options.signal,\n onCleanupFailure: options.onCleanupFailure,\n })\n }\n abortScope.dispose()\n rejectDone(finalError)\n throw finalError\n }\n },\n\n async abort(reason: unknown): Promise<void> {\n const abortError = markErrored(reason)\n pending.length = 0\n pendingBytes = 0\n const fileIdToCancel = largeFileId\n if (fileIdToCancel === null && startPromise !== null) {\n // Do not await an in-flight start request here. A stalled\n // b2_start_large_file must not make writer.abort() hang; if it later\n // returns a file ID, cancel it best-effort in the background.\n scheduleCancelLargeFileAfterStart(startPromise)\n }\n if (fileIdToCancel !== null) {\n await waitForInflightPartsToSettle()\n await cancelLargeFileBestEffort(\n raw,\n accountInfo,\n fileIdToCancel,\n cleanupWriteStreamOptions(options),\n )\n }\n abortScope.dispose()\n rejectDone(abortError)\n },\n })\n\n return { writable, done }\n}\n\nfunction cleanupWriteStreamOptions(options: CreateWriteStreamOptions): {\n readonly signal?: AbortSignal\n} & CleanupFailureOptions {\n return {\n ...(options.signal !== undefined ? { signal: options.signal } : {}),\n ...(options.onCleanupFailure !== undefined\n ? { onCleanupFailure: options.onCleanupFailure }\n : {}),\n }\n}\n\n/**\n * Removes exactly `size` bytes from the front of `chunks` (mutates) and returns\n * them as a contiguous Uint8Array. Any trailing remainder of the last chunk\n * stays at the front of `chunks` for the next part.\n *\n * @param chunks - Queue of pending chunks. Modified in place.\n * @param size - Number of bytes to carve off the front.\n *\n * @returns A new Uint8Array containing exactly `size` bytes.\n */\nfunction carveExact(chunks: Uint8Array[], size: number): Uint8Array {\n const out = new Uint8Array(size)\n let written = 0\n while (written < size && chunks.length > 0) {\n const head = chunks[0]\n if (!head) break\n const need = size - written\n if (head.byteLength <= need) {\n out.set(head, written)\n written += head.byteLength\n chunks.shift()\n } else {\n out.set(head.subarray(0, need), written)\n chunks[0] = head.subarray(need)\n written += need\n }\n }\n return out\n}\n\nfunction waitForAbort(signal: AbortSignal): {\n readonly promise: Promise<unknown>\n dispose(): void\n} {\n if (signal.aborted) {\n return {\n promise: Promise.resolve(abortReason(signal)),\n dispose() {},\n }\n }\n\n let onAbort: (() => void) | undefined\n const promise = new Promise<unknown>((resolve) => {\n onAbort = () => resolve(abortReason(signal))\n signal.addEventListener('abort', onAbort, { once: true })\n })\n\n return {\n promise,\n dispose() {\n if (onAbort !== undefined) signal.removeEventListener('abort', onAbort)\n },\n }\n}\n"],"mappings":";;;;;;;;;;;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qBAAqB,KAAA,IAC7B,EAAE,kBAAkB,QAAQ,iBAAiB,IAC7C,CAAC;CACP;AACF;;;;;;;;;;;AAYA,SAAS,WAAW,QAAsB,MAA0B;CAClE,MAAM,MAAM,IAAI,WAAW,IAAI;CAC/B,IAAI,UAAU;CACd,OAAO,UAAU,QAAQ,OAAO,SAAS,GAAG;EAC1C,MAAM,OAAO,OAAO;EACpB,IAAI,CAAC,MAAM;EACX,MAAM,OAAO,OAAO;EACpB,IAAI,KAAK,cAAc,MAAM;GAC3B,IAAI,IAAI,MAAM,OAAO;GACrB,WAAW,KAAK;GAChB,OAAO,MAAM;EACf,OAAO;GACL,IAAI,IAAI,KAAK,SAAS,GAAG,IAAI,GAAG,OAAO;GACvC,OAAO,KAAK,KAAK,SAAS,IAAI;GAC9B,WAAW;EACb;CACF;CACA,OAAO;AACT;AAEA,SAAS,aAAa,QAGpB;CACA,IAAI,OAAO,SACT,OAAO;EACL,SAAS,QAAQ,QAAQ,YAAY,MAAM,CAAC;EAC5C,UAAU,CAAC;CACb;CAGF,IAAI;CAMJ,OAAO;EACL,SAAA,IANkB,SAAkB,YAAY;GAChD,gBAAgB,QAAQ,YAAY,MAAM,CAAC;GAC3C,OAAO,iBAAiB,SAAS,SAAS,EAAE,MAAM,KAAK,CAAC;EAC1D,CAGE;EACA,UAAU;GACR,IAAI,YAAY,KAAA,GAAW,OAAO,oBAAoB,SAAS,OAAO;EACxE;CACF;AACF"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
//#region src/util/abort.ts
|
|
2
|
+
/**
|
|
3
|
+
* Abort-signal and cancellation-error helpers shared across SDK operations.
|
|
4
|
+
*
|
|
5
|
+
* @packageDocumentation
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Resolves the abort reason for a signal, defaulting to a standard `AbortError`.
|
|
9
|
+
*
|
|
10
|
+
* @param signal - The aborted signal whose reason should be resolved.
|
|
11
|
+
*
|
|
12
|
+
* @returns The signal's `reason`, or a fresh `AbortError` DOMException when unset.
|
|
13
|
+
*/
|
|
14
|
+
function abortReason(signal) {
|
|
15
|
+
return signal.reason ?? new DOMException("Aborted", "AbortError");
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Returns whether an error represents an abort.
|
|
19
|
+
*
|
|
20
|
+
* @param err - Unknown thrown value.
|
|
21
|
+
*
|
|
22
|
+
* @returns True for `Error` or `DOMException` instances named `AbortError`.
|
|
23
|
+
*/
|
|
24
|
+
function isAbortError(err) {
|
|
25
|
+
return isNamedError(err, "AbortError");
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Returns whether an error should be treated as the given signal's abort.
|
|
29
|
+
*
|
|
30
|
+
* @param signal - Controlling signal for the operation.
|
|
31
|
+
* @param err - Unknown thrown value.
|
|
32
|
+
*
|
|
33
|
+
* @returns True when the signal is aborted and `err` is either the signal's
|
|
34
|
+
* reason or a trusted `AbortError` instance.
|
|
35
|
+
*/
|
|
36
|
+
function isSignalAbortError(signal, err) {
|
|
37
|
+
if (signal?.aborted !== true) return false;
|
|
38
|
+
if (signal.reason !== void 0 && Object.is(err, signal.reason)) return true;
|
|
39
|
+
return isAbortError(err);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Returns whether an error represents a timeout.
|
|
43
|
+
*
|
|
44
|
+
* @param err - Unknown thrown value.
|
|
45
|
+
*
|
|
46
|
+
* @returns True for `Error` or `DOMException` instances named `TimeoutError`.
|
|
47
|
+
*/
|
|
48
|
+
function isTimeoutError(err) {
|
|
49
|
+
return isNamedError(err, "TimeoutError");
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Throws the abort reason if the signal is already aborted; otherwise returns.
|
|
53
|
+
*
|
|
54
|
+
* @param signal - The signal to check, or undefined to skip the check.
|
|
55
|
+
*
|
|
56
|
+
* @throws The signal's abort reason when the signal is already aborted.
|
|
57
|
+
*/
|
|
58
|
+
function throwIfSignalAborted(signal) {
|
|
59
|
+
if (signal?.aborted === true) throw abortReason(signal);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Races a promise against an abort signal. Rejects with the signal's abort
|
|
63
|
+
* reason if the signal fires first, detaching the listener and suppressing the
|
|
64
|
+
* losing promise's rejection so it never surfaces as an unhandled rejection.
|
|
65
|
+
*
|
|
66
|
+
* The underlying work must still receive the same signal so transports can
|
|
67
|
+
* cancel their network activity. This helper only makes callers stop waiting
|
|
68
|
+
* promptly even when a test double or custom transport ignores the signal.
|
|
69
|
+
*
|
|
70
|
+
* @param promise - The work to await.
|
|
71
|
+
* @param signal - Abort signal, or undefined to await the promise directly.
|
|
72
|
+
*
|
|
73
|
+
* @returns The resolved value of `promise` when it settles before the signal aborts.
|
|
74
|
+
*
|
|
75
|
+
* @throws The abort reason if the signal aborts first, or the promise's rejection.
|
|
76
|
+
*/
|
|
77
|
+
async function raceWithAbort(promise, signal) {
|
|
78
|
+
if (signal === void 0) return promise;
|
|
79
|
+
if (signal.aborted) {
|
|
80
|
+
promise.catch(() => {});
|
|
81
|
+
throw abortReason(signal);
|
|
82
|
+
}
|
|
83
|
+
let removeAbortListener;
|
|
84
|
+
const aborted = new Promise((_, reject) => {
|
|
85
|
+
const onAbort = () => {
|
|
86
|
+
promise.catch(() => {});
|
|
87
|
+
reject(abortReason(signal));
|
|
88
|
+
};
|
|
89
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
90
|
+
removeAbortListener = () => signal.removeEventListener("abort", onAbort);
|
|
91
|
+
if (signal.aborted) onAbort();
|
|
92
|
+
});
|
|
93
|
+
try {
|
|
94
|
+
return await Promise.race([promise, aborted]);
|
|
95
|
+
} finally {
|
|
96
|
+
removeAbortListener?.();
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function isNamedError(err, name) {
|
|
100
|
+
try {
|
|
101
|
+
return (err instanceof DOMException || err instanceof Error) && err.name === name;
|
|
102
|
+
} catch {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
//#endregion
|
|
107
|
+
exports.abortReason = abortReason;
|
|
108
|
+
exports.isAbortError = isAbortError;
|
|
109
|
+
exports.isSignalAbortError = isSignalAbortError;
|
|
110
|
+
exports.isTimeoutError = isTimeoutError;
|
|
111
|
+
exports.raceWithAbort = raceWithAbort;
|
|
112
|
+
exports.throwIfSignalAborted = throwIfSignalAborted;
|
|
113
|
+
|
|
114
|
+
//# sourceMappingURL=abort.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"abort.cjs","names":[],"sources":["../../src/util/abort.ts"],"sourcesContent":["/**\n * Abort-signal and cancellation-error helpers shared across SDK operations.\n *\n * @packageDocumentation\n */\n\n/**\n * Resolves the abort reason for a signal, defaulting to a standard `AbortError`.\n *\n * @param signal - The aborted signal whose reason should be resolved.\n *\n * @returns The signal's `reason`, or a fresh `AbortError` DOMException when unset.\n */\nexport function abortReason(signal: AbortSignal): unknown {\n return signal.reason ?? new DOMException('Aborted', 'AbortError')\n}\n\n/**\n * Returns whether an error represents an abort.\n *\n * @param err - Unknown thrown value.\n *\n * @returns True for `Error` or `DOMException` instances named `AbortError`.\n */\nexport function isAbortError(err: unknown): boolean {\n return isNamedError(err, 'AbortError')\n}\n\n/**\n * Returns whether an error should be treated as the given signal's abort.\n *\n * @param signal - Controlling signal for the operation.\n * @param err - Unknown thrown value.\n *\n * @returns True when the signal is aborted and `err` is either the signal's\n * reason or a trusted `AbortError` instance.\n */\nexport function isSignalAbortError(signal: AbortSignal | undefined, err: unknown): boolean {\n if (signal?.aborted !== true) return false\n if (signal.reason !== undefined && Object.is(err, signal.reason)) return true\n return isAbortError(err)\n}\n\n/**\n * Returns whether an error represents a timeout.\n *\n * @param err - Unknown thrown value.\n *\n * @returns True for `Error` or `DOMException` instances named `TimeoutError`.\n */\nexport function isTimeoutError(err: unknown): boolean {\n return isNamedError(err, 'TimeoutError')\n}\n\n/**\n * Throws the abort reason if the signal is already aborted; otherwise returns.\n *\n * @param signal - The signal to check, or undefined to skip the check.\n *\n * @throws The signal's abort reason when the signal is already aborted.\n */\nexport function throwIfSignalAborted(signal: AbortSignal | undefined): void {\n if (signal?.aborted === true) {\n throw abortReason(signal)\n }\n}\n\n/**\n * Races a promise against an abort signal. Rejects with the signal's abort\n * reason if the signal fires first, detaching the listener and suppressing the\n * losing promise's rejection so it never surfaces as an unhandled rejection.\n *\n * The underlying work must still receive the same signal so transports can\n * cancel their network activity. This helper only makes callers stop waiting\n * promptly even when a test double or custom transport ignores the signal.\n *\n * @param promise - The work to await.\n * @param signal - Abort signal, or undefined to await the promise directly.\n *\n * @returns The resolved value of `promise` when it settles before the signal aborts.\n *\n * @throws The abort reason if the signal aborts first, or the promise's rejection.\n */\nexport async function raceWithAbort<T>(\n promise: Promise<T>,\n signal: AbortSignal | undefined,\n): Promise<T> {\n if (signal === undefined) return promise\n if (signal.aborted) {\n void promise.catch(() => {})\n throw abortReason(signal)\n }\n\n let removeAbortListener: (() => void) | undefined\n const aborted = new Promise<never>((_, reject) => {\n const onAbort = (): void => {\n void promise.catch(() => {})\n reject(abortReason(signal))\n }\n signal.addEventListener('abort', onAbort, { once: true })\n removeAbortListener = () => signal.removeEventListener('abort', onAbort)\n if (signal.aborted) onAbort()\n })\n\n try {\n return await Promise.race([promise, aborted])\n } finally {\n removeAbortListener?.()\n }\n}\n\nfunction isNamedError(err: unknown, name: string): boolean {\n try {\n return (\n (err instanceof DOMException || err instanceof Error) &&\n (err as { readonly name: string }).name === name\n )\n } catch {\n return false\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAaA,SAAgB,YAAY,QAA8B;CACxD,OAAO,OAAO,UAAU,IAAI,aAAa,WAAW,YAAY;AAClE;;;;;;;;AASA,SAAgB,aAAa,KAAuB;CAClD,OAAO,aAAa,KAAK,YAAY;AACvC;;;;;;;;;;AAWA,SAAgB,mBAAmB,QAAiC,KAAuB;CACzF,IAAI,QAAQ,YAAY,MAAM,OAAO;CACrC,IAAI,OAAO,WAAW,KAAA,KAAa,OAAO,GAAG,KAAK,OAAO,MAAM,GAAG,OAAO;CACzE,OAAO,aAAa,GAAG;AACzB;;;;;;;;AASA,SAAgB,eAAe,KAAuB;CACpD,OAAO,aAAa,KAAK,cAAc;AACzC;;;;;;;;AASA,SAAgB,qBAAqB,QAAuC;CAC1E,IAAI,QAAQ,YAAY,MACtB,MAAM,YAAY,MAAM;AAE5B;;;;;;;;;;;;;;;;;AAkBA,eAAsB,cACpB,SACA,QACY;CACZ,IAAI,WAAW,KAAA,GAAW,OAAO;CACjC,IAAI,OAAO,SAAS;EAClB,QAAa,YAAY,CAAC,CAAC;EAC3B,MAAM,YAAY,MAAM;CAC1B;CAEA,IAAI;CACJ,MAAM,UAAU,IAAI,SAAgB,GAAG,WAAW;EAChD,MAAM,gBAAsB;GAC1B,QAAa,YAAY,CAAC,CAAC;GAC3B,OAAO,YAAY,MAAM,CAAC;EAC5B;EACA,OAAO,iBAAiB,SAAS,SAAS,EAAE,MAAM,KAAK,CAAC;EACxD,4BAA4B,OAAO,oBAAoB,SAAS,OAAO;EACvE,IAAI,OAAO,SAAS,QAAQ;CAC9B,CAAC;CAED,IAAI;EACF,OAAO,MAAM,QAAQ,KAAK,CAAC,SAAS,OAAO,CAAC;CAC9C,UAAU;EACR,sBAAsB;CACxB;AACF;AAEA,SAAS,aAAa,KAAc,MAAuB;CACzD,IAAI;EACF,QACG,eAAe,gBAAgB,eAAe,UAC9C,IAAkC,SAAS;CAEhD,QAAQ;EACN,OAAO;CACT;AACF"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Abort-signal and cancellation-error helpers shared across SDK operations.
|
|
3
|
+
*
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Resolves the abort reason for a signal, defaulting to a standard `AbortError`.
|
|
8
|
+
*
|
|
9
|
+
* @param signal - The aborted signal whose reason should be resolved.
|
|
10
|
+
*
|
|
11
|
+
* @returns The signal's `reason`, or a fresh `AbortError` DOMException when unset.
|
|
12
|
+
*/
|
|
13
|
+
export declare function abortReason(signal: AbortSignal): unknown;
|
|
14
|
+
/**
|
|
15
|
+
* Returns whether an error represents an abort.
|
|
16
|
+
*
|
|
17
|
+
* @param err - Unknown thrown value.
|
|
18
|
+
*
|
|
19
|
+
* @returns True for `Error` or `DOMException` instances named `AbortError`.
|
|
20
|
+
*/
|
|
21
|
+
export declare function isAbortError(err: unknown): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Returns whether an error should be treated as the given signal's abort.
|
|
24
|
+
*
|
|
25
|
+
* @param signal - Controlling signal for the operation.
|
|
26
|
+
* @param err - Unknown thrown value.
|
|
27
|
+
*
|
|
28
|
+
* @returns True when the signal is aborted and `err` is either the signal's
|
|
29
|
+
* reason or a trusted `AbortError` instance.
|
|
30
|
+
*/
|
|
31
|
+
export declare function isSignalAbortError(signal: AbortSignal | undefined, err: unknown): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Returns whether an error represents a timeout.
|
|
34
|
+
*
|
|
35
|
+
* @param err - Unknown thrown value.
|
|
36
|
+
*
|
|
37
|
+
* @returns True for `Error` or `DOMException` instances named `TimeoutError`.
|
|
38
|
+
*/
|
|
39
|
+
export declare function isTimeoutError(err: unknown): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Throws the abort reason if the signal is already aborted; otherwise returns.
|
|
42
|
+
*
|
|
43
|
+
* @param signal - The signal to check, or undefined to skip the check.
|
|
44
|
+
*
|
|
45
|
+
* @throws The signal's abort reason when the signal is already aborted.
|
|
46
|
+
*/
|
|
47
|
+
export declare function throwIfSignalAborted(signal: AbortSignal | undefined): void;
|
|
48
|
+
/**
|
|
49
|
+
* Races a promise against an abort signal. Rejects with the signal's abort
|
|
50
|
+
* reason if the signal fires first, detaching the listener and suppressing the
|
|
51
|
+
* losing promise's rejection so it never surfaces as an unhandled rejection.
|
|
52
|
+
*
|
|
53
|
+
* The underlying work must still receive the same signal so transports can
|
|
54
|
+
* cancel their network activity. This helper only makes callers stop waiting
|
|
55
|
+
* promptly even when a test double or custom transport ignores the signal.
|
|
56
|
+
*
|
|
57
|
+
* @param promise - The work to await.
|
|
58
|
+
* @param signal - Abort signal, or undefined to await the promise directly.
|
|
59
|
+
*
|
|
60
|
+
* @returns The resolved value of `promise` when it settles before the signal aborts.
|
|
61
|
+
*
|
|
62
|
+
* @throws The abort reason if the signal aborts first, or the promise's rejection.
|
|
63
|
+
*/
|
|
64
|
+
export declare function raceWithAbort<T>(promise: Promise<T>, signal: AbortSignal | undefined): Promise<T>;
|
|
65
|
+
//# sourceMappingURL=abort.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"abort.d.ts","sourceRoot":"","sources":["../../src/util/abort.js"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAExD;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAElD;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,WAAW,GAAG,SAAS,EAAE,GAAG,EAAE,OAAO,GAAG,OAAO,CAIzF;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAEpD;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,WAAW,GAAG,SAAS,GAAG,IAAI,CAI1E;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,aAAa,CAAC,CAAC,EACnC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EACnB,MAAM,EAAE,WAAW,GAAG,SAAS,GAC9B,OAAO,CAAC,CAAC,CAAC,CAuBZ"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Abort-signal and cancellation-error helpers shared across SDK operations.
|
|
3
|
+
*
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Resolves the abort reason for a signal, defaulting to a standard `AbortError`.
|
|
8
|
+
*
|
|
9
|
+
* @param signal - The aborted signal whose reason should be resolved.
|
|
10
|
+
*
|
|
11
|
+
* @returns The signal's `reason`, or a fresh `AbortError` DOMException when unset.
|
|
12
|
+
*/
|
|
13
|
+
export declare function abortReason(signal: AbortSignal): unknown;
|
|
14
|
+
/**
|
|
15
|
+
* Returns whether an error represents an abort.
|
|
16
|
+
*
|
|
17
|
+
* @param err - Unknown thrown value.
|
|
18
|
+
*
|
|
19
|
+
* @returns True for `Error` or `DOMException` instances named `AbortError`.
|
|
20
|
+
*/
|
|
21
|
+
export declare function isAbortError(err: unknown): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Returns whether an error should be treated as the given signal's abort.
|
|
24
|
+
*
|
|
25
|
+
* @param signal - Controlling signal for the operation.
|
|
26
|
+
* @param err - Unknown thrown value.
|
|
27
|
+
*
|
|
28
|
+
* @returns True when the signal is aborted and `err` is either the signal's
|
|
29
|
+
* reason or a trusted `AbortError` instance.
|
|
30
|
+
*/
|
|
31
|
+
export declare function isSignalAbortError(signal: AbortSignal | undefined, err: unknown): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Returns whether an error represents a timeout.
|
|
34
|
+
*
|
|
35
|
+
* @param err - Unknown thrown value.
|
|
36
|
+
*
|
|
37
|
+
* @returns True for `Error` or `DOMException` instances named `TimeoutError`.
|
|
38
|
+
*/
|
|
39
|
+
export declare function isTimeoutError(err: unknown): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Throws the abort reason if the signal is already aborted; otherwise returns.
|
|
42
|
+
*
|
|
43
|
+
* @param signal - The signal to check, or undefined to skip the check.
|
|
44
|
+
*
|
|
45
|
+
* @throws The signal's abort reason when the signal is already aborted.
|
|
46
|
+
*/
|
|
47
|
+
export declare function throwIfSignalAborted(signal: AbortSignal | undefined): void;
|
|
48
|
+
/**
|
|
49
|
+
* Races a promise against an abort signal. Rejects with the signal's abort
|
|
50
|
+
* reason if the signal fires first, detaching the listener and suppressing the
|
|
51
|
+
* losing promise's rejection so it never surfaces as an unhandled rejection.
|
|
52
|
+
*
|
|
53
|
+
* The underlying work must still receive the same signal so transports can
|
|
54
|
+
* cancel their network activity. This helper only makes callers stop waiting
|
|
55
|
+
* promptly even when a test double or custom transport ignores the signal.
|
|
56
|
+
*
|
|
57
|
+
* @param promise - The work to await.
|
|
58
|
+
* @param signal - Abort signal, or undefined to await the promise directly.
|
|
59
|
+
*
|
|
60
|
+
* @returns The resolved value of `promise` when it settles before the signal aborts.
|
|
61
|
+
*
|
|
62
|
+
* @throws The abort reason if the signal aborts first, or the promise's rejection.
|
|
63
|
+
*/
|
|
64
|
+
export declare function raceWithAbort<T>(promise: Promise<T>, signal: AbortSignal | undefined): Promise<T>;
|
|
65
|
+
//# sourceMappingURL=abort.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"abort.d.ts","sourceRoot":"","sources":["../../src/util/abort.js"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAExD;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAElD;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,WAAW,GAAG,SAAS,EAAE,GAAG,EAAE,OAAO,GAAG,OAAO,CAIzF;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAEpD;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,WAAW,GAAG,SAAS,GAAG,IAAI,CAI1E;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,aAAa,CAAC,CAAC,EACnC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EACnB,MAAM,EAAE,WAAW,GAAG,SAAS,GAC9B,OAAO,CAAC,CAAC,CAAC,CAuBZ"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
//#region src/util/abort.ts
|
|
2
|
+
/**
|
|
3
|
+
* Abort-signal and cancellation-error helpers shared across SDK operations.
|
|
4
|
+
*
|
|
5
|
+
* @packageDocumentation
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Resolves the abort reason for a signal, defaulting to a standard `AbortError`.
|
|
9
|
+
*
|
|
10
|
+
* @param signal - The aborted signal whose reason should be resolved.
|
|
11
|
+
*
|
|
12
|
+
* @returns The signal's `reason`, or a fresh `AbortError` DOMException when unset.
|
|
13
|
+
*/
|
|
14
|
+
function abortReason(signal) {
|
|
15
|
+
return signal.reason ?? new DOMException("Aborted", "AbortError");
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Returns whether an error represents an abort.
|
|
19
|
+
*
|
|
20
|
+
* @param err - Unknown thrown value.
|
|
21
|
+
*
|
|
22
|
+
* @returns True for `Error` or `DOMException` instances named `AbortError`.
|
|
23
|
+
*/
|
|
24
|
+
function isAbortError(err) {
|
|
25
|
+
return isNamedError(err, "AbortError");
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Returns whether an error should be treated as the given signal's abort.
|
|
29
|
+
*
|
|
30
|
+
* @param signal - Controlling signal for the operation.
|
|
31
|
+
* @param err - Unknown thrown value.
|
|
32
|
+
*
|
|
33
|
+
* @returns True when the signal is aborted and `err` is either the signal's
|
|
34
|
+
* reason or a trusted `AbortError` instance.
|
|
35
|
+
*/
|
|
36
|
+
function isSignalAbortError(signal, err) {
|
|
37
|
+
if (signal?.aborted !== true) return false;
|
|
38
|
+
if (signal.reason !== void 0 && Object.is(err, signal.reason)) return true;
|
|
39
|
+
return isAbortError(err);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Returns whether an error represents a timeout.
|
|
43
|
+
*
|
|
44
|
+
* @param err - Unknown thrown value.
|
|
45
|
+
*
|
|
46
|
+
* @returns True for `Error` or `DOMException` instances named `TimeoutError`.
|
|
47
|
+
*/
|
|
48
|
+
function isTimeoutError(err) {
|
|
49
|
+
return isNamedError(err, "TimeoutError");
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Throws the abort reason if the signal is already aborted; otherwise returns.
|
|
53
|
+
*
|
|
54
|
+
* @param signal - The signal to check, or undefined to skip the check.
|
|
55
|
+
*
|
|
56
|
+
* @throws The signal's abort reason when the signal is already aborted.
|
|
57
|
+
*/
|
|
58
|
+
function throwIfSignalAborted(signal) {
|
|
59
|
+
if (signal?.aborted === true) throw abortReason(signal);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Races a promise against an abort signal. Rejects with the signal's abort
|
|
63
|
+
* reason if the signal fires first, detaching the listener and suppressing the
|
|
64
|
+
* losing promise's rejection so it never surfaces as an unhandled rejection.
|
|
65
|
+
*
|
|
66
|
+
* The underlying work must still receive the same signal so transports can
|
|
67
|
+
* cancel their network activity. This helper only makes callers stop waiting
|
|
68
|
+
* promptly even when a test double or custom transport ignores the signal.
|
|
69
|
+
*
|
|
70
|
+
* @param promise - The work to await.
|
|
71
|
+
* @param signal - Abort signal, or undefined to await the promise directly.
|
|
72
|
+
*
|
|
73
|
+
* @returns The resolved value of `promise` when it settles before the signal aborts.
|
|
74
|
+
*
|
|
75
|
+
* @throws The abort reason if the signal aborts first, or the promise's rejection.
|
|
76
|
+
*/
|
|
77
|
+
async function raceWithAbort(promise, signal) {
|
|
78
|
+
if (signal === void 0) return promise;
|
|
79
|
+
if (signal.aborted) {
|
|
80
|
+
promise.catch(() => {});
|
|
81
|
+
throw abortReason(signal);
|
|
82
|
+
}
|
|
83
|
+
let removeAbortListener;
|
|
84
|
+
const aborted = new Promise((_, reject) => {
|
|
85
|
+
const onAbort = () => {
|
|
86
|
+
promise.catch(() => {});
|
|
87
|
+
reject(abortReason(signal));
|
|
88
|
+
};
|
|
89
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
90
|
+
removeAbortListener = () => signal.removeEventListener("abort", onAbort);
|
|
91
|
+
if (signal.aborted) onAbort();
|
|
92
|
+
});
|
|
93
|
+
try {
|
|
94
|
+
return await Promise.race([promise, aborted]);
|
|
95
|
+
} finally {
|
|
96
|
+
removeAbortListener?.();
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function isNamedError(err, name) {
|
|
100
|
+
try {
|
|
101
|
+
return (err instanceof DOMException || err instanceof Error) && err.name === name;
|
|
102
|
+
} catch {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
//#endregion
|
|
107
|
+
export { abortReason, isAbortError, isSignalAbortError, isTimeoutError, raceWithAbort, throwIfSignalAborted };
|
|
108
|
+
|
|
109
|
+
//# sourceMappingURL=abort.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"abort.js","names":[],"sources":["../../src/util/abort.ts"],"sourcesContent":["/**\n * Abort-signal and cancellation-error helpers shared across SDK operations.\n *\n * @packageDocumentation\n */\n\n/**\n * Resolves the abort reason for a signal, defaulting to a standard `AbortError`.\n *\n * @param signal - The aborted signal whose reason should be resolved.\n *\n * @returns The signal's `reason`, or a fresh `AbortError` DOMException when unset.\n */\nexport function abortReason(signal: AbortSignal): unknown {\n return signal.reason ?? new DOMException('Aborted', 'AbortError')\n}\n\n/**\n * Returns whether an error represents an abort.\n *\n * @param err - Unknown thrown value.\n *\n * @returns True for `Error` or `DOMException` instances named `AbortError`.\n */\nexport function isAbortError(err: unknown): boolean {\n return isNamedError(err, 'AbortError')\n}\n\n/**\n * Returns whether an error should be treated as the given signal's abort.\n *\n * @param signal - Controlling signal for the operation.\n * @param err - Unknown thrown value.\n *\n * @returns True when the signal is aborted and `err` is either the signal's\n * reason or a trusted `AbortError` instance.\n */\nexport function isSignalAbortError(signal: AbortSignal | undefined, err: unknown): boolean {\n if (signal?.aborted !== true) return false\n if (signal.reason !== undefined && Object.is(err, signal.reason)) return true\n return isAbortError(err)\n}\n\n/**\n * Returns whether an error represents a timeout.\n *\n * @param err - Unknown thrown value.\n *\n * @returns True for `Error` or `DOMException` instances named `TimeoutError`.\n */\nexport function isTimeoutError(err: unknown): boolean {\n return isNamedError(err, 'TimeoutError')\n}\n\n/**\n * Throws the abort reason if the signal is already aborted; otherwise returns.\n *\n * @param signal - The signal to check, or undefined to skip the check.\n *\n * @throws The signal's abort reason when the signal is already aborted.\n */\nexport function throwIfSignalAborted(signal: AbortSignal | undefined): void {\n if (signal?.aborted === true) {\n throw abortReason(signal)\n }\n}\n\n/**\n * Races a promise against an abort signal. Rejects with the signal's abort\n * reason if the signal fires first, detaching the listener and suppressing the\n * losing promise's rejection so it never surfaces as an unhandled rejection.\n *\n * The underlying work must still receive the same signal so transports can\n * cancel their network activity. This helper only makes callers stop waiting\n * promptly even when a test double or custom transport ignores the signal.\n *\n * @param promise - The work to await.\n * @param signal - Abort signal, or undefined to await the promise directly.\n *\n * @returns The resolved value of `promise` when it settles before the signal aborts.\n *\n * @throws The abort reason if the signal aborts first, or the promise's rejection.\n */\nexport async function raceWithAbort<T>(\n promise: Promise<T>,\n signal: AbortSignal | undefined,\n): Promise<T> {\n if (signal === undefined) return promise\n if (signal.aborted) {\n void promise.catch(() => {})\n throw abortReason(signal)\n }\n\n let removeAbortListener: (() => void) | undefined\n const aborted = new Promise<never>((_, reject) => {\n const onAbort = (): void => {\n void promise.catch(() => {})\n reject(abortReason(signal))\n }\n signal.addEventListener('abort', onAbort, { once: true })\n removeAbortListener = () => signal.removeEventListener('abort', onAbort)\n if (signal.aborted) onAbort()\n })\n\n try {\n return await Promise.race([promise, aborted])\n } finally {\n removeAbortListener?.()\n }\n}\n\nfunction isNamedError(err: unknown, name: string): boolean {\n try {\n return (\n (err instanceof DOMException || err instanceof Error) &&\n (err as { readonly name: string }).name === name\n )\n } catch {\n return false\n }\n}\n"],"mappings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,44 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
async
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
//#region src/util/best-effort.ts
|
|
2
|
+
/**
|
|
3
|
+
* Runs an async cleanup operation and swallows any rejection.
|
|
4
|
+
*
|
|
5
|
+
* Used at error-handling boundaries (e.g. after a multipart upload fails,
|
|
6
|
+
* when trying to `cancelLargeFile` on the orphaned upload). The primary
|
|
7
|
+
* error is what the caller wants to see; a secondary failure during
|
|
8
|
+
* cleanup must not shadow it.
|
|
9
|
+
*
|
|
10
|
+
* Naming the pattern instead of inlining a try/catch with an empty catch
|
|
11
|
+
* makes the intent explicit at the call site: this is best-effort cleanup,
|
|
12
|
+
* not a silent error swallow.
|
|
13
|
+
*
|
|
14
|
+
* @param fn - Cleanup async function. Its return value is ignored; any
|
|
15
|
+
* thrown error or rejected promise is caught and discarded.
|
|
16
|
+
* @param onError - Optional observer called with the swallowed cleanup error.
|
|
17
|
+
*
|
|
18
|
+
* @returns A promise that always resolves, regardless of `fn`'s outcome.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* try {
|
|
23
|
+
* await uploadParts(...)
|
|
24
|
+
* } catch (err) {
|
|
25
|
+
* await bestEffort(() =>
|
|
26
|
+
* raw.cancelLargeFile(apiUrl, authToken, { fileId: largeFileId }),
|
|
27
|
+
* )
|
|
28
|
+
* throw err
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
async function bestEffort(fn, onError) {
|
|
33
|
+
try {
|
|
34
|
+
await fn();
|
|
35
|
+
} catch (error) {
|
|
36
|
+
try {
|
|
37
|
+
onError?.(error);
|
|
38
|
+
} catch {}
|
|
39
|
+
}
|
|
8
40
|
}
|
|
41
|
+
//#endregion
|
|
9
42
|
exports.bestEffort = bestEffort;
|
|
10
|
-
|
|
43
|
+
|
|
44
|
+
//# sourceMappingURL=best-effort.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"best-effort.cjs","sources":["../../src/util/best-effort.ts"],"sourcesContent":["/**\n * Runs an async cleanup operation and swallows any rejection.\n *\n * Used at error-handling boundaries (e.g. after a multipart upload fails,\n * when trying to `cancelLargeFile` on the orphaned upload). The primary\n * error is what the caller wants to see; a secondary failure during\n * cleanup must not shadow it.\n *\n * Naming the pattern instead of inlining a try/catch with an empty catch\n * makes the intent explicit at the call site: this is best-effort cleanup,\n * not a silent error swallow.\n *\n * @param fn - Cleanup async function. Its return value is ignored; any\n * thrown error or rejected promise is caught and discarded.\n *\n * @returns A promise that always resolves, regardless of `fn`'s outcome.\n *\n * @example\n * ```ts\n * try {\n * await uploadParts(...)\n * } catch (err) {\n * await bestEffort(() =>\n * raw.cancelLargeFile(apiUrl, authToken, { fileId: largeFileId }),\n * )\n * throw err\n * }\n * ```\n */\nexport async function bestEffort(fn: () => Promise<unknown
|
|
1
|
+
{"version":3,"file":"best-effort.cjs","names":[],"sources":["../../src/util/best-effort.ts"],"sourcesContent":["/**\n * Runs an async cleanup operation and swallows any rejection.\n *\n * Used at error-handling boundaries (e.g. after a multipart upload fails,\n * when trying to `cancelLargeFile` on the orphaned upload). The primary\n * error is what the caller wants to see; a secondary failure during\n * cleanup must not shadow it.\n *\n * Naming the pattern instead of inlining a try/catch with an empty catch\n * makes the intent explicit at the call site: this is best-effort cleanup,\n * not a silent error swallow.\n *\n * @param fn - Cleanup async function. Its return value is ignored; any\n * thrown error or rejected promise is caught and discarded.\n * @param onError - Optional observer called with the swallowed cleanup error.\n *\n * @returns A promise that always resolves, regardless of `fn`'s outcome.\n *\n * @example\n * ```ts\n * try {\n * await uploadParts(...)\n * } catch (err) {\n * await bestEffort(() =>\n * raw.cancelLargeFile(apiUrl, authToken, { fileId: largeFileId }),\n * )\n * throw err\n * }\n * ```\n */\nexport async function bestEffort(\n fn: () => Promise<unknown>,\n onError?: (error: unknown) => void,\n): Promise<void> {\n try {\n await fn()\n } catch (error) {\n try {\n onError?.(error)\n } catch {\n // Observer failures are also secondary cleanup failures.\n }\n // Intentional swallow: this helper exists for cleanup paths where a\n // secondary failure must not shadow the primary error.\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,eAAsB,WACpB,IACA,SACe;CACf,IAAI;EACF,MAAM,GAAG;CACX,SAAS,OAAO;EACd,IAAI;GACF,UAAU,KAAK;EACjB,QAAQ,CAER;CAGF;AACF"}
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
*
|
|
13
13
|
* @param fn - Cleanup async function. Its return value is ignored; any
|
|
14
14
|
* thrown error or rejected promise is caught and discarded.
|
|
15
|
+
* @param onError - Optional observer called with the swallowed cleanup error.
|
|
15
16
|
*
|
|
16
17
|
* @returns A promise that always resolves, regardless of `fn`'s outcome.
|
|
17
18
|
*
|
|
@@ -27,5 +28,5 @@
|
|
|
27
28
|
* }
|
|
28
29
|
* ```
|
|
29
30
|
*/
|
|
30
|
-
export declare function bestEffort(fn: () => Promise<unknown
|
|
31
|
+
export declare function bestEffort(fn: () => Promise<unknown>, onError?: (error: unknown) => void): Promise<void>;
|
|
31
32
|
//# sourceMappingURL=best-effort.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"best-effort.d.ts","sourceRoot":"","sources":["../../src/util/best-effort.js"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"best-effort.d.ts","sourceRoot":"","sources":["../../src/util/best-effort.js"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAsB,UAAU,CAC9B,EAAE,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,EAC1B,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,GACjC,OAAO,CAAC,IAAI,CAAC,CAYf"}
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
*
|
|
13
13
|
* @param fn - Cleanup async function. Its return value is ignored; any
|
|
14
14
|
* thrown error or rejected promise is caught and discarded.
|
|
15
|
+
* @param onError - Optional observer called with the swallowed cleanup error.
|
|
15
16
|
*
|
|
16
17
|
* @returns A promise that always resolves, regardless of `fn`'s outcome.
|
|
17
18
|
*
|
|
@@ -27,5 +28,5 @@
|
|
|
27
28
|
* }
|
|
28
29
|
* ```
|
|
29
30
|
*/
|
|
30
|
-
export declare function bestEffort(fn: () => Promise<unknown
|
|
31
|
+
export declare function bestEffort(fn: () => Promise<unknown>, onError?: (error: unknown) => void): Promise<void>;
|
|
31
32
|
//# sourceMappingURL=best-effort.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"best-effort.d.ts","sourceRoot":"","sources":["../../src/util/best-effort.js"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"best-effort.d.ts","sourceRoot":"","sources":["../../src/util/best-effort.js"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAsB,UAAU,CAC9B,EAAE,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,EAC1B,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,GACjC,OAAO,CAAC,IAAI,CAAC,CAYf"}
|
package/dist/util/best-effort.js
CHANGED
|
@@ -1,10 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
//#region src/util/best-effort.ts
|
|
2
|
+
/**
|
|
3
|
+
* Runs an async cleanup operation and swallows any rejection.
|
|
4
|
+
*
|
|
5
|
+
* Used at error-handling boundaries (e.g. after a multipart upload fails,
|
|
6
|
+
* when trying to `cancelLargeFile` on the orphaned upload). The primary
|
|
7
|
+
* error is what the caller wants to see; a secondary failure during
|
|
8
|
+
* cleanup must not shadow it.
|
|
9
|
+
*
|
|
10
|
+
* Naming the pattern instead of inlining a try/catch with an empty catch
|
|
11
|
+
* makes the intent explicit at the call site: this is best-effort cleanup,
|
|
12
|
+
* not a silent error swallow.
|
|
13
|
+
*
|
|
14
|
+
* @param fn - Cleanup async function. Its return value is ignored; any
|
|
15
|
+
* thrown error or rejected promise is caught and discarded.
|
|
16
|
+
* @param onError - Optional observer called with the swallowed cleanup error.
|
|
17
|
+
*
|
|
18
|
+
* @returns A promise that always resolves, regardless of `fn`'s outcome.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* try {
|
|
23
|
+
* await uploadParts(...)
|
|
24
|
+
* } catch (err) {
|
|
25
|
+
* await bestEffort(() =>
|
|
26
|
+
* raw.cancelLargeFile(apiUrl, authToken, { fileId: largeFileId }),
|
|
27
|
+
* )
|
|
28
|
+
* throw err
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
async function bestEffort(fn, onError) {
|
|
33
|
+
try {
|
|
34
|
+
await fn();
|
|
35
|
+
} catch (error) {
|
|
36
|
+
try {
|
|
37
|
+
onError?.(error);
|
|
38
|
+
} catch {}
|
|
39
|
+
}
|
|
6
40
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
//# sourceMappingURL=best-effort.js.map
|
|
41
|
+
//#endregion
|
|
42
|
+
export { bestEffort };
|
|
43
|
+
|
|
44
|
+
//# sourceMappingURL=best-effort.js.map
|