@backblaze-labs/b2-sdk 0.1.0 → 0.2.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 +110 -5
- package/README.md +144 -33
- 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/bucket.cjs +785 -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 +780 -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 +114 -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 +112 -69
- package/dist/copy/large.js.map +1 -1
- package/dist/download/checksum.cjs +89 -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 +87 -0
- package/dist/download/checksum.js.map +1 -0
- package/dist/download/parallel.cjs +214 -118
- package/dist/download/parallel.cjs.map +1 -1
- package/dist/download/parallel.d.cts +5 -1
- package/dist/download/parallel.d.cts.map +1 -1
- package/dist/download/parallel.d.ts +5 -1
- package/dist/download/parallel.d.ts.map +1 -1
- package/dist/download/parallel.js +212 -116
- package/dist/download/parallel.js.map +1 -1
- package/dist/download/single.cjs +188 -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 +186 -98
- package/dist/download/single.js.map +1 -1
- package/dist/errors/index.cjs +699 -243
- package/dist/errors/index.cjs.map +1 -1
- package/dist/errors/index.d.cts +285 -82
- package/dist/errors/index.d.cts.map +1 -1
- package/dist/errors/index.d.ts +285 -82
- package/dist/errors/index.d.ts.map +1 -1
- package/dist/errors/index.js +678 -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 +438 -140
- package/dist/http/transport.cjs.map +1 -1
- package/dist/http/transport.d.cts +21 -2
- package/dist/http/transport.d.cts.map +1 -1
- package/dist/http/transport.d.ts +21 -2
- package/dist/http/transport.d.ts.map +1 -1
- package/dist/http/transport.js +437 -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 +101 -77
- package/dist/index.d.cts +27 -21
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +27 -21
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -71
- 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 +9 -55
- package/dist/object.d.cts.map +1 -1
- package/dist/object.d.ts +9 -55
- package/dist/object.d.ts.map +1 -1
- package/dist/object.js +249 -206
- package/dist/object.js.map +1 -1
- 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 +678 -587
- package/dist/raw/index.cjs.map +1 -1
- package/dist/raw/index.d.cts +121 -18
- package/dist/raw/index.d.cts.map +1 -1
- package/dist/raw/index.d.ts +121 -18
- package/dist/raw/index.d.ts.map +1 -1
- package/dist/raw/index.js +674 -589
- package/dist/raw/index.js.map +1 -1
- 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 +149 -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 +148 -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 +2124 -1548
- package/dist/simulator/index.cjs.map +1 -1
- package/dist/simulator/index.d.cts +79 -11
- package/dist/simulator/index.d.cts.map +1 -1
- package/dist/simulator/index.d.ts +79 -11
- package/dist/simulator/index.d.ts.map +1 -1
- package/dist/simulator/index.js +2112 -1546
- package/dist/simulator/index.js.map +1 -1
- package/dist/simulator/validation.cjs +191 -153
- package/dist/simulator/validation.cjs.map +1 -1
- package/dist/simulator/validation.d.cts +3 -21
- package/dist/simulator/validation.d.cts.map +1 -1
- package/dist/simulator/validation.d.ts +3 -21
- package/dist/simulator/validation.d.ts.map +1 -1
- package/dist/simulator/validation.js +188 -162
- 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 +2 -10
- 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 +316 -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 +312 -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 +148 -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 +145 -0
- package/dist/sync/b2-sha1-reader.js.map +1 -0
- package/dist/sync/download-staging.cjs +265 -0
- package/dist/sync/download-staging.cjs.map +1 -0
- package/dist/sync/download-staging.d.cts +54 -0
- package/dist/sync/download-staging.d.cts.map +1 -0
- package/dist/sync/download-staging.d.ts +54 -0
- package/dist/sync/download-staging.d.ts.map +1 -0
- package/dist/sync/download-staging.js +259 -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 +364 -0
- package/dist/sync/local-file-io.cjs.map +1 -0
- package/dist/sync/local-file-io.d.cts +75 -0
- package/dist/sync/local-file-io.d.cts.map +1 -0
- package/dist/sync/local-file-io.d.ts +75 -0
- package/dist/sync/local-file-io.d.ts.map +1 -0
- package/dist/sync/local-file-io.js +360 -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 +119 -0
- package/dist/sync/local-sha1.cjs.map +1 -0
- package/dist/sync/local-sha1.d.cts +39 -0
- package/dist/sync/local-sha1.d.cts.map +1 -0
- package/dist/sync/local-sha1.d.ts +39 -0
- package/dist/sync/local-sha1.d.ts.map +1 -0
- package/dist/sync/local-sha1.js +117 -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 +389 -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 +387 -13
- package/dist/sync/policies/compare.js.map +1 -1
- package/dist/sync/policies/index.cjs +76 -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 +76 -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 +782 -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 +779 -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 +76 -56
- package/dist/types/auth.cjs.map +1 -1
- package/dist/types/auth.d.cts +67 -9
- package/dist/types/auth.d.cts.map +1 -1
- package/dist/types/auth.d.ts +67 -9
- package/dist/types/auth.d.ts.map +1 -1
- package/dist/types/auth.js +77 -57
- package/dist/types/auth.js.map +1 -1
- package/dist/types/bucket.cjs +74 -38
- package/dist/types/bucket.cjs.map +1 -1
- package/dist/types/bucket.js +75 -41
- package/dist/types/bucket.js.map +1 -1
- package/dist/types/encryption.cjs +364 -327
- package/dist/types/encryption.cjs.map +1 -1
- package/dist/types/encryption.d.cts +16 -0
- package/dist/types/encryption.d.cts.map +1 -1
- package/dist/types/encryption.d.ts +16 -0
- package/dist/types/encryption.d.ts.map +1 -1
- package/dist/types/encryption.js +364 -310
- package/dist/types/encryption.js.map +1 -1
- package/dist/types/errors.cjs +47 -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 +47 -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 +2 -2
- package/dist/types/file.d.cts.map +1 -1
- package/dist/types/file.d.ts +2 -2
- 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 +53 -9
- package/dist/types/ids.cjs.map +1 -1
- package/dist/types/ids.js +54 -15
- package/dist/types/ids.js.map +1 -1
- package/dist/types/index.d.cts +12 -11
- package/dist/types/index.d.cts.map +1 -1
- package/dist/types/index.d.ts +12 -11
- 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.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.js +45 -23
- package/dist/types/notifications.js.map +1 -1
- package/dist/types/upload.d.cts +39 -5
- package/dist/types/upload.d.cts.map +1 -1
- package/dist/types/upload.d.ts +39 -5
- package/dist/types/upload.d.ts.map +1 -1
- package/dist/upload/abort-scope.cjs +91 -0
- package/dist/upload/abort-scope.cjs.map +1 -0
- package/dist/upload/abort-scope.d.cts +48 -0
- package/dist/upload/abort-scope.d.cts.map +1 -0
- package/dist/upload/abort-scope.d.ts +48 -0
- package/dist/upload/abort-scope.d.ts.map +1 -0
- package/dist/upload/abort-scope.js +88 -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 +59 -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 +59 -0
- package/dist/upload/finish.js.map +1 -0
- package/dist/upload/large.cjs +301 -218
- package/dist/upload/large.cjs.map +1 -1
- package/dist/upload/large.d.cts +76 -9
- package/dist/upload/large.d.cts.map +1 -1
- package/dist/upload/large.d.ts +76 -9
- package/dist/upload/large.d.ts.map +1 -1
- package/dist/upload/large.js +301 -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 +104 -0
- package/dist/upload/options.d.cts.map +1 -0
- package/dist/upload/options.d.ts +104 -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 +333 -33
- package/dist/upload/resume.cjs.map +1 -1
- package/dist/upload/resume.d.cts +82 -12
- package/dist/upload/resume.d.cts.map +1 -1
- package/dist/upload/resume.d.ts +82 -12
- package/dist/upload/resume.d.ts.map +1 -1
- package/dist/upload/resume.js +330 -33
- package/dist/upload/resume.js.map +1 -1
- package/dist/upload/retry.cjs +186 -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 +182 -0
- package/dist/upload/retry.js.map +1 -0
- package/dist/upload/single.cjs +68 -44
- package/dist/upload/single.cjs.map +1 -1
- package/dist/upload/single.d.cts +2 -1
- package/dist/upload/single.d.cts.map +1 -1
- package/dist/upload/single.d.ts +2 -1
- package/dist/upload/single.d.ts.map +1 -1
- package/dist/upload/single.js +68 -44
- package/dist/upload/single.js.map +1 -1
- package/dist/upload/stream.cjs +317 -193
- package/dist/upload/stream.cjs.map +1 -1
- package/dist/upload/stream.d.cts +3 -1
- package/dist/upload/stream.d.cts.map +1 -1
- package/dist/upload/stream.d.ts +3 -1
- package/dist/upload/stream.d.ts.map +1 -1
- package/dist/upload/stream.js +316 -192
- package/dist/upload/stream.js.map +1 -1
- 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 +25 -9
- package/dist/util/defaults.cjs.map +1 -1
- package/dist/util/defaults.js +26 -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/normalize.cjs +66 -7
- package/dist/util/normalize.cjs.map +1 -1
- package/dist/util/normalize.js +67 -10
- package/dist/util/normalize.js.map +1 -1
- package/dist/util/paginator.cjs +63 -14
- package/dist/util/paginator.cjs.map +1 -1
- package/dist/util/paginator.js +64 -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 +19 -16
- 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":"cancel.d.ts","sourceRoot":"","sources":["../../src/upload/cancel.js"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAChD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"cancel.d.ts","sourceRoot":"","sources":["../../src/upload/cancel.js"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,EAAE,gCAAgC,EAAE,MAAM,oBAAoB,CAAA;AACrE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAChD,OAAO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";
|
|
1
2
|
import { bestEffort } from "../util/best-effort.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
//#region src/upload/cancel.ts
|
|
4
|
+
/** Default wall-clock bound for best-effort cleanup calls after upload failure. */
|
|
5
|
+
var DEFAULT_CLEANUP_TIMEOUT_MS = 3e4;
|
|
6
|
+
var fallbackCleanupDisposers = /* @__PURE__ */ new WeakMap();
|
|
7
|
+
/**
|
|
8
|
+
* Cancels an unfinished large file on a best-effort basis. Used at every
|
|
9
|
+
* error-handling boundary in the multipart upload, write-stream, and
|
|
10
|
+
* server-side copy paths to roll back in-progress uploads without
|
|
11
|
+
* letting a cancellation failure mask the underlying error the caller
|
|
12
|
+
* is about to see.
|
|
13
|
+
*
|
|
14
|
+
* Centralising the call removes a five-line `bestEffort` block that
|
|
15
|
+
* recurred at six sites with identical shape — the only thing that
|
|
16
|
+
* changed was the captured `fileId` and the surrounding error trail.
|
|
17
|
+
*
|
|
18
|
+
* @param raw - Low-level B2 API client.
|
|
19
|
+
* @param accountInfo - Authorized account state for the API URL + token.
|
|
20
|
+
* @param fileId - The in-progress large file ID to cancel.
|
|
21
|
+
* @param options - Optional request controls and cleanup-failure observer.
|
|
22
|
+
*
|
|
23
|
+
* @returns A promise that always resolves, regardless of the cancel
|
|
24
|
+
* call's outcome.
|
|
25
|
+
*/
|
|
26
|
+
async function cancelLargeFileBestEffort(raw, accountInfo, fileId, options) {
|
|
27
|
+
await bestEffort(async () => {
|
|
28
|
+
const requestOptions = cleanupRequestOptions(options?.signal);
|
|
29
|
+
await waitForCleanup(raw.cancelLargeFile(accountInfo.getApiUrl(), accountInfo.getAuthToken(), { fileId }, requestOptions), requestOptions.signal);
|
|
30
|
+
}, (error) => options?.onCleanupFailure?.({
|
|
31
|
+
fileId,
|
|
32
|
+
error,
|
|
33
|
+
reason: "cancel-failed"
|
|
34
|
+
}));
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Returns cleanup request controls with a live timeout signal.
|
|
38
|
+
*
|
|
39
|
+
* @param signal - Caller-provided abort signal, if any.
|
|
40
|
+
* @param timeoutMs - Maximum time to spend waiting for cleanup.
|
|
41
|
+
*
|
|
42
|
+
* @returns Request controls with a signal independent of an already-aborted caller signal.
|
|
43
|
+
*/
|
|
44
|
+
function cleanupRequestOptions(signal, timeoutMs = DEFAULT_CLEANUP_TIMEOUT_MS) {
|
|
45
|
+
return { signal: createCleanupSignal(signal, timeoutMs) };
|
|
46
|
+
}
|
|
47
|
+
function createCleanupSignal(signal, timeoutMs) {
|
|
48
|
+
if (typeof AbortSignal.timeout === "function") {
|
|
49
|
+
if (signal === void 0 || signal.aborted) return AbortSignal.timeout(timeoutMs);
|
|
50
|
+
if (typeof AbortSignal.any === "function") return AbortSignal.any([signal, AbortSignal.timeout(timeoutMs)]);
|
|
51
|
+
}
|
|
52
|
+
return createFallbackCleanupSignal(signal, timeoutMs);
|
|
53
|
+
}
|
|
54
|
+
function createFallbackCleanupSignal(signal, timeoutMs) {
|
|
55
|
+
const controller = new AbortController();
|
|
56
|
+
const timeout = setTimeout(() => {
|
|
57
|
+
abortFallbackCleanup(controller, cleanupTimeoutReason(), cleanup);
|
|
58
|
+
}, timeoutMs);
|
|
59
|
+
const onAbort = () => {
|
|
60
|
+
const reason = signal === void 0 ? cleanupDomException("Cleanup aborted", "AbortError") : cleanupAbortReason(signal);
|
|
61
|
+
abortFallbackCleanup(controller, reason, cleanup);
|
|
62
|
+
};
|
|
63
|
+
const cleanup = () => {
|
|
64
|
+
clearTimeout(timeout);
|
|
65
|
+
signal?.removeEventListener("abort", onAbort);
|
|
66
|
+
fallbackCleanupDisposers.delete(controller.signal);
|
|
67
|
+
};
|
|
68
|
+
fallbackCleanupDisposers.set(controller.signal, cleanup);
|
|
69
|
+
if (signal === void 0 || signal.aborted) return controller.signal;
|
|
70
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
71
|
+
controller.signal.addEventListener("abort", cleanup, { once: true });
|
|
72
|
+
return controller.signal;
|
|
73
|
+
}
|
|
74
|
+
function abortFallbackCleanup(controller, reason, cleanup) {
|
|
75
|
+
if (!controller.signal.aborted) controller.abort(reason);
|
|
76
|
+
cleanup();
|
|
77
|
+
}
|
|
78
|
+
async function waitForCleanup(request, signal) {
|
|
79
|
+
if (signal.aborted) throw cleanupAbortReason(signal);
|
|
80
|
+
let removeAbortListener;
|
|
81
|
+
const aborted = new Promise((_resolve, reject) => {
|
|
82
|
+
const onAbort = () => reject(cleanupAbortReason(signal));
|
|
83
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
84
|
+
removeAbortListener = () => signal.removeEventListener("abort", onAbort);
|
|
85
|
+
});
|
|
86
|
+
try {
|
|
87
|
+
await Promise.race([request, aborted]);
|
|
88
|
+
} finally {
|
|
89
|
+
removeAbortListener?.();
|
|
90
|
+
fallbackCleanupDisposers.get(signal)?.();
|
|
91
|
+
request.catch(() => {});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function cleanupAbortReason(signal) {
|
|
95
|
+
return signal.reason ?? cleanupDomException("Cleanup aborted", "AbortError");
|
|
96
|
+
}
|
|
97
|
+
function cleanupTimeoutReason() {
|
|
98
|
+
return cleanupDomException("Cleanup timed out", "TimeoutError");
|
|
99
|
+
}
|
|
100
|
+
function cleanupDomException(message, name) {
|
|
101
|
+
if (typeof DOMException === "function") return new DOMException(message, name);
|
|
102
|
+
const error = new Error(message);
|
|
103
|
+
error.name = name;
|
|
104
|
+
return error;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Emits an observable cleanup event when cancellation is deliberately skipped
|
|
108
|
+
* because `b2_finish_large_file` may already have committed the file.
|
|
109
|
+
* @param fileId - Large file whose final state is ambiguous.
|
|
110
|
+
* @param error - Ambiguous finish error that will be thrown to the caller.
|
|
111
|
+
* @param onCleanupFailure - Optional observer for cleanup-related events.
|
|
112
|
+
*/
|
|
113
|
+
function notifyAmbiguousLargeFileCleanupSkipped(fileId, error, onCleanupFailure) {
|
|
114
|
+
try {
|
|
115
|
+
onCleanupFailure?.({
|
|
116
|
+
fileId,
|
|
117
|
+
error,
|
|
118
|
+
reason: "finish-ambiguous"
|
|
119
|
+
});
|
|
120
|
+
} catch {}
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Adds high-level reconciliation metadata to an ambiguous finish response-body
|
|
124
|
+
* error and notifies the cleanup observer that cancellation was skipped.
|
|
125
|
+
*
|
|
126
|
+
* @param err - Raw finish response-body error from the low-level client.
|
|
127
|
+
* @param options - Large-file context used for reconciliation.
|
|
128
|
+
*
|
|
129
|
+
* @returns The enriched {@link FinishLargeFileResponseBodyError}.
|
|
130
|
+
*/
|
|
131
|
+
function handleAmbiguousFinishLargeFileResponseBodyError(err, options) {
|
|
132
|
+
const enriched = err.fileId === options.fileId && err.bucketId === options.bucketId && err.fileName === options.fileName ? err : new FinishLargeFileResponseBodyError(err.message, {
|
|
133
|
+
cause: err.cause ?? err,
|
|
134
|
+
fileId: options.fileId,
|
|
135
|
+
bucketId: options.bucketId,
|
|
136
|
+
fileName: options.fileName
|
|
137
|
+
});
|
|
138
|
+
notifyAmbiguousLargeFileCleanupSkipped(options.fileId, enriched, options.onCleanupFailure);
|
|
139
|
+
return enriched;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Performs the shared large-file failure policy: ambiguous finish-body errors
|
|
143
|
+
* are enriched and left uncancelled, while all pre-finish errors trigger
|
|
144
|
+
* best-effort cancellation.
|
|
145
|
+
*
|
|
146
|
+
* @param err - Error from a multipart upload/copy/write-stream path.
|
|
147
|
+
* @param raw - Low-level B2 API client.
|
|
148
|
+
* @param accountInfo - Authorized account state.
|
|
149
|
+
* @param context - Large file metadata used for cleanup and diagnostics.
|
|
150
|
+
* @param options - Cleanup policy controls.
|
|
151
|
+
*
|
|
152
|
+
* @returns The error that should be surfaced to the caller.
|
|
153
|
+
*/
|
|
154
|
+
async function resolveLargeFileErrorAfterCleanup(err, raw, accountInfo, context, options = {}) {
|
|
155
|
+
if (err instanceof FinishLargeFileResponseBodyError) return handleAmbiguousFinishLargeFileResponseBodyError(err, context);
|
|
156
|
+
if (options.cancelOnError ?? true) await cancelLargeFileBestEffort(raw, accountInfo, context.fileId, {
|
|
157
|
+
...context.signal !== void 0 ? { signal: context.signal } : {},
|
|
158
|
+
...context.onCleanupFailure !== void 0 ? { onCleanupFailure: context.onCleanupFailure } : {}
|
|
159
|
+
});
|
|
160
|
+
return err;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Throwing wrapper around {@link resolveLargeFileErrorAfterCleanup} for paths
|
|
164
|
+
* that can surface the error directly.
|
|
165
|
+
* @param err - Error from a multipart upload/copy/write-stream path.
|
|
166
|
+
* @param raw - Low-level B2 API client.
|
|
167
|
+
* @param accountInfo - Authorized account state.
|
|
168
|
+
* @param context - Large file metadata used for cleanup and diagnostics.
|
|
169
|
+
* @param options - Cleanup policy controls.
|
|
170
|
+
*
|
|
171
|
+
* @throws The resolved large-file error after cleanup policy is applied.
|
|
172
|
+
*/
|
|
173
|
+
async function cleanupAfterLargeFileError(err, raw, accountInfo, context, options) {
|
|
174
|
+
throw await resolveLargeFileErrorAfterCleanup(err, raw, accountInfo, context, options);
|
|
175
|
+
}
|
|
176
|
+
//#endregion
|
|
177
|
+
export { DEFAULT_CLEANUP_TIMEOUT_MS, cancelLargeFileBestEffort, cleanupAfterLargeFileError, cleanupRequestOptions, handleAmbiguousFinishLargeFileResponseBodyError, notifyAmbiguousLargeFileCleanupSkipped, resolveLargeFileErrorAfterCleanup };
|
|
178
|
+
|
|
179
|
+
//# sourceMappingURL=cancel.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cancel.js","sources":["../../src/upload/cancel.ts"],"sourcesContent":["import type { AccountInfo } from '../auth/account-info.ts'\nimport type { RawClient } from '../raw/index.ts'\nimport type { LargeFileId } from '../types/ids.ts'\nimport { bestEffort } from '../util/best-effort.ts'\n\n/**\n * Cancels an unfinished large file on a best-effort basis. Used at every\n * error-handling boundary in the multipart upload, write-stream, and\n * server-side copy paths to roll back in-progress uploads without\n * letting a cancellation failure mask the underlying error the caller\n * is about to see.\n *\n * Centralising the call removes a five-line `bestEffort` block that\n * recurred at six sites with identical shape — the only thing that\n * changed was the captured `fileId` and the surrounding error trail.\n *\n * @param raw - Low-level B2 API client.\n * @param accountInfo - Authorized account state for the API URL + token.\n * @param fileId - The in-progress large file ID to cancel.\n *\n * @returns A promise that always resolves, regardless of the cancel\n * call's outcome.\n */\nexport async function cancelLargeFileBestEffort(\n raw: RawClient,\n accountInfo: AccountInfo,\n fileId: LargeFileId,\n): Promise<void> {\n await bestEffort(() =>\n raw.cancelLargeFile(accountInfo.getApiUrl(), accountInfo.getAuthToken(), { fileId }),\n )\n}\n"],"names":[],"mappings":";AAuBA,eAAsB,0BACpB,KACA,aACA,QACe;AACf,QAAM;AAAA,IAAW,MACf,IAAI,gBAAgB,YAAY,UAAA,GAAa,YAAY,gBAAgB,EAAE,OAAA,CAAQ;AAAA,EAAA;AAEvF;"}
|
|
1
|
+
{"version":3,"file":"cancel.js","names":[],"sources":["../../src/upload/cancel.ts"],"sourcesContent":["import type { AccountInfo } from '../auth/account-info.ts'\nimport { FinishLargeFileResponseBodyError } from '../errors/index.ts'\nimport type { RawClient } from '../raw/index.ts'\nimport type { BucketId, LargeFileId } from '../types/ids.ts'\nimport { bestEffort } from '../util/best-effort.ts'\n\n/** Event emitted when best-effort `b2_cancel_large_file` cleanup fails. */\nexport interface CancelLargeFileCleanupFailureEvent {\n /** Unfinished large file that may remain orphaned. */\n readonly fileId: LargeFileId\n /** Error thrown by `b2_cancel_large_file`. */\n readonly error: unknown\n /** Cleanup phase that produced the observable event. */\n readonly reason: 'cancel-failed'\n}\n\n/** Event emitted when cleanup is skipped because finish may have committed. */\nexport interface AmbiguousFinishCleanupFailureEvent {\n /** Large file whose final server-side state is ambiguous. */\n readonly fileId: LargeFileId\n /** Error thrown to the caller with reconciliation metadata. */\n readonly error: FinishLargeFileResponseBodyError\n /** Cleanup phase that produced the observable event. */\n readonly reason: 'finish-ambiguous'\n}\n\n/** Event emitted when large-file cleanup fails or is deliberately skipped. */\nexport type CleanupFailureEvent =\n | CancelLargeFileCleanupFailureEvent\n | AmbiguousFinishCleanupFailureEvent\n\n/** Callback invoked when best-effort cancellation fails or finish cleanup is skipped. */\nexport type CleanupFailureListener = (event: CleanupFailureEvent) => void\n\n/** Shared option for observing large-file cleanup failures or skipped cleanup. */\nexport interface CleanupFailureOptions {\n /**\n * Callback invoked if best-effort cancellation fails, or if cancellation is\n * skipped because `b2_finish_large_file` may already have committed.\n */\n readonly onCleanupFailure?: CleanupFailureListener\n}\n\n/** Default wall-clock bound for best-effort cleanup calls after upload failure. */\nexport const DEFAULT_CLEANUP_TIMEOUT_MS = 30_000\n\nconst fallbackCleanupDisposers = new WeakMap<AbortSignal, () => void>()\n\n/** Context needed to reconcile or cancel an unfinished large file after an error. */\nexport interface LargeFileCleanupContext {\n readonly fileId: LargeFileId\n readonly bucketId: BucketId\n readonly fileName: string\n readonly signal?: AbortSignal | undefined\n readonly onCleanupFailure?: CleanupFailureListener | undefined\n}\n\n/** Options for applying the shared large-file cleanup policy. */\nexport interface LargeFileCleanupPolicyOptions {\n /**\n * Whether non-ambiguous failures should cancel the unfinished large file.\n * Defaults to true. Explicit resume callers can disable this so the SDK does\n * not cancel a large file that it did not create.\n */\n readonly cancelOnError?: boolean\n}\n\n/**\n * Cancels an unfinished large file on a best-effort basis. Used at every\n * error-handling boundary in the multipart upload, write-stream, and\n * server-side copy paths to roll back in-progress uploads without\n * letting a cancellation failure mask the underlying error the caller\n * is about to see.\n *\n * Centralising the call removes a five-line `bestEffort` block that\n * recurred at six sites with identical shape — the only thing that\n * changed was the captured `fileId` and the surrounding error trail.\n *\n * @param raw - Low-level B2 API client.\n * @param accountInfo - Authorized account state for the API URL + token.\n * @param fileId - The in-progress large file ID to cancel.\n * @param options - Optional request controls and cleanup-failure observer.\n *\n * @returns A promise that always resolves, regardless of the cancel\n * call's outcome.\n */\nexport async function cancelLargeFileBestEffort(\n raw: RawClient,\n accountInfo: AccountInfo,\n fileId: LargeFileId,\n options?: { readonly signal?: AbortSignal } & CleanupFailureOptions,\n): Promise<void> {\n await bestEffort(\n async () => {\n const requestOptions = cleanupRequestOptions(options?.signal)\n const request = raw.cancelLargeFile(\n accountInfo.getApiUrl(),\n accountInfo.getAuthToken(),\n { fileId },\n requestOptions,\n )\n await waitForCleanup(request, requestOptions.signal)\n },\n (error) => options?.onCleanupFailure?.({ fileId, error, reason: 'cancel-failed' }),\n )\n}\n\n/**\n * Returns cleanup request controls with a live timeout signal.\n *\n * @param signal - Caller-provided abort signal, if any.\n * @param timeoutMs - Maximum time to spend waiting for cleanup.\n *\n * @returns Request controls with a signal independent of an already-aborted caller signal.\n */\nexport function cleanupRequestOptions(\n signal: AbortSignal | undefined,\n timeoutMs = DEFAULT_CLEANUP_TIMEOUT_MS,\n): { readonly signal: AbortSignal } {\n return { signal: createCleanupSignal(signal, timeoutMs) }\n}\n\nfunction createCleanupSignal(signal: AbortSignal | undefined, timeoutMs: number): AbortSignal {\n if (typeof AbortSignal.timeout === 'function') {\n if (signal === undefined || signal.aborted) return AbortSignal.timeout(timeoutMs)\n if (typeof AbortSignal.any === 'function') {\n return AbortSignal.any([signal, AbortSignal.timeout(timeoutMs)])\n }\n }\n\n return createFallbackCleanupSignal(signal, timeoutMs)\n}\n\nfunction createFallbackCleanupSignal(\n signal: AbortSignal | undefined,\n timeoutMs: number,\n): AbortSignal {\n const controller = new AbortController()\n const timeout = setTimeout(() => {\n abortFallbackCleanup(controller, cleanupTimeoutReason(), cleanup)\n }, timeoutMs)\n\n const onAbort = () => {\n const reason =\n signal === undefined\n ? cleanupDomException('Cleanup aborted', 'AbortError')\n : cleanupAbortReason(signal)\n abortFallbackCleanup(controller, reason, cleanup)\n }\n const cleanup = () => {\n clearTimeout(timeout)\n signal?.removeEventListener('abort', onAbort)\n fallbackCleanupDisposers.delete(controller.signal)\n }\n fallbackCleanupDisposers.set(controller.signal, cleanup)\n\n if (signal === undefined || signal.aborted) {\n return controller.signal\n }\n\n signal.addEventListener('abort', onAbort, { once: true })\n controller.signal.addEventListener('abort', cleanup, { once: true })\n return controller.signal\n}\n\nfunction abortFallbackCleanup(\n controller: AbortController,\n reason: unknown,\n cleanup: () => void,\n): void {\n if (!controller.signal.aborted) controller.abort(reason)\n cleanup()\n}\n\nasync function waitForCleanup(request: Promise<unknown>, signal: AbortSignal): Promise<void> {\n if (signal.aborted) throw cleanupAbortReason(signal)\n\n let removeAbortListener: (() => void) | undefined\n const aborted = new Promise<never>((_resolve, reject) => {\n const onAbort = () => reject(cleanupAbortReason(signal))\n signal.addEventListener('abort', onAbort, { once: true })\n removeAbortListener = () => signal.removeEventListener('abort', onAbort)\n })\n\n try {\n await Promise.race([request, aborted])\n } finally {\n removeAbortListener?.()\n fallbackCleanupDisposers.get(signal)?.()\n void request.catch(() => {})\n }\n}\n\nfunction cleanupAbortReason(signal: AbortSignal): unknown {\n return signal.reason ?? cleanupDomException('Cleanup aborted', 'AbortError')\n}\n\nfunction cleanupTimeoutReason(): unknown {\n return cleanupDomException('Cleanup timed out', 'TimeoutError')\n}\n\nfunction cleanupDomException(message: string, name: string): Error {\n if (typeof DOMException === 'function') return new DOMException(message, name)\n const error = new Error(message)\n error.name = name\n return error\n}\n\n/**\n * Emits an observable cleanup event when cancellation is deliberately skipped\n * because `b2_finish_large_file` may already have committed the file.\n * @param fileId - Large file whose final state is ambiguous.\n * @param error - Ambiguous finish error that will be thrown to the caller.\n * @param onCleanupFailure - Optional observer for cleanup-related events.\n */\nexport function notifyAmbiguousLargeFileCleanupSkipped(\n fileId: LargeFileId,\n error: FinishLargeFileResponseBodyError,\n onCleanupFailure?: CleanupFailureListener,\n): void {\n try {\n onCleanupFailure?.({ fileId, error, reason: 'finish-ambiguous' })\n } catch {\n // Observer failures are secondary and must not hide the finish ambiguity.\n }\n}\n\n/**\n * Adds high-level reconciliation metadata to an ambiguous finish response-body\n * error and notifies the cleanup observer that cancellation was skipped.\n *\n * @param err - Raw finish response-body error from the low-level client.\n * @param options - Large-file context used for reconciliation.\n *\n * @returns The enriched {@link FinishLargeFileResponseBodyError}.\n */\nexport function handleAmbiguousFinishLargeFileResponseBodyError(\n err: FinishLargeFileResponseBodyError,\n options: LargeFileCleanupContext,\n): FinishLargeFileResponseBodyError {\n const enriched =\n err.fileId === options.fileId &&\n err.bucketId === options.bucketId &&\n err.fileName === options.fileName\n ? err\n : new FinishLargeFileResponseBodyError(err.message, {\n cause: err.cause ?? err,\n fileId: options.fileId,\n bucketId: options.bucketId,\n fileName: options.fileName,\n })\n notifyAmbiguousLargeFileCleanupSkipped(options.fileId, enriched, options.onCleanupFailure)\n return enriched\n}\n\n/**\n * Performs the shared large-file failure policy: ambiguous finish-body errors\n * are enriched and left uncancelled, while all pre-finish errors trigger\n * best-effort cancellation.\n *\n * @param err - Error from a multipart upload/copy/write-stream path.\n * @param raw - Low-level B2 API client.\n * @param accountInfo - Authorized account state.\n * @param context - Large file metadata used for cleanup and diagnostics.\n * @param options - Cleanup policy controls.\n *\n * @returns The error that should be surfaced to the caller.\n */\nexport async function resolveLargeFileErrorAfterCleanup(\n err: unknown,\n raw: RawClient,\n accountInfo: AccountInfo,\n context: LargeFileCleanupContext,\n options: LargeFileCleanupPolicyOptions = {},\n): Promise<unknown> {\n if (err instanceof FinishLargeFileResponseBodyError) {\n return handleAmbiguousFinishLargeFileResponseBodyError(err, context)\n }\n if (options.cancelOnError ?? true) {\n await cancelLargeFileBestEffort(raw, accountInfo, context.fileId, {\n ...(context.signal !== undefined ? { signal: context.signal } : {}),\n ...(context.onCleanupFailure !== undefined\n ? { onCleanupFailure: context.onCleanupFailure }\n : {}),\n })\n }\n return err\n}\n\n/**\n * Throwing wrapper around {@link resolveLargeFileErrorAfterCleanup} for paths\n * that can surface the error directly.\n * @param err - Error from a multipart upload/copy/write-stream path.\n * @param raw - Low-level B2 API client.\n * @param accountInfo - Authorized account state.\n * @param context - Large file metadata used for cleanup and diagnostics.\n * @param options - Cleanup policy controls.\n *\n * @throws The resolved large-file error after cleanup policy is applied.\n */\nexport async function cleanupAfterLargeFileError(\n err: unknown,\n raw: RawClient,\n accountInfo: AccountInfo,\n context: LargeFileCleanupContext,\n options?: LargeFileCleanupPolicyOptions,\n): Promise<never> {\n throw await resolveLargeFileErrorAfterCleanup(err, raw, accountInfo, context, options)\n}\n"],"mappings":";;;;AA4CA,IAAa,6BAA6B;AAE1C,IAAM,2CAA2B,IAAI,QAAiC;;;;;;;;;;;;;;;;;;;;AAwCtE,eAAsB,0BACpB,KACA,aACA,QACA,SACe;CACf,MAAM,WACJ,YAAY;EACV,MAAM,iBAAiB,sBAAsB,SAAS,MAAM;EAO5D,MAAM,eANU,IAAI,gBAClB,YAAY,UAAU,GACtB,YAAY,aAAa,GACzB,EAAE,OAAO,GACT,cAEmB,GAAS,eAAe,MAAM;CACrD,IACC,UAAU,SAAS,mBAAmB;EAAE;EAAQ;EAAO,QAAQ;CAAgB,CAAC,CACnF;AACF;;;;;;;;;AAUA,SAAgB,sBACd,QACA,YAAY,4BACsB;CAClC,OAAO,EAAE,QAAQ,oBAAoB,QAAQ,SAAS,EAAE;AAC1D;AAEA,SAAS,oBAAoB,QAAiC,WAAgC;CAC5F,IAAI,OAAO,YAAY,YAAY,YAAY;EAC7C,IAAI,WAAW,KAAA,KAAa,OAAO,SAAS,OAAO,YAAY,QAAQ,SAAS;EAChF,IAAI,OAAO,YAAY,QAAQ,YAC7B,OAAO,YAAY,IAAI,CAAC,QAAQ,YAAY,QAAQ,SAAS,CAAC,CAAC;CAEnE;CAEA,OAAO,4BAA4B,QAAQ,SAAS;AACtD;AAEA,SAAS,4BACP,QACA,WACa;CACb,MAAM,aAAa,IAAI,gBAAgB;CACvC,MAAM,UAAU,iBAAiB;EAC/B,qB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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
1
|
+
//#region src/upload/concurrency.ts
|
|
2
|
+
/**
|
|
3
|
+
* Bounded concurrency primitive.
|
|
4
|
+
*
|
|
5
|
+
* Limits the number of concurrent operations to a fixed maximum. Callers
|
|
6
|
+
* {@link acquire} a slot before starting work and {@link release} it when done.
|
|
7
|
+
* If all slots are taken, `acquire` returns a promise that resolves when a slot
|
|
8
|
+
* becomes available.
|
|
9
|
+
*/
|
|
10
|
+
var Semaphore = class {
|
|
11
|
+
limit;
|
|
12
|
+
current = 0;
|
|
13
|
+
queue = [];
|
|
14
|
+
/**
|
|
15
|
+
* @param limit - Maximum number of concurrent acquisitions. Must be a
|
|
16
|
+
* positive integer; values `<= 0` would create a semaphore that
|
|
17
|
+
* never lets anything through (all `acquire()` calls would queue
|
|
18
|
+
* forever), so the constructor throws fast instead.
|
|
19
|
+
*
|
|
20
|
+
* @throws `RangeError` when `limit` is not a positive integer.
|
|
21
|
+
*/
|
|
22
|
+
constructor(limit) {
|
|
23
|
+
this.limit = limit;
|
|
24
|
+
if (!Number.isInteger(limit) || limit <= 0) throw new RangeError(`Semaphore limit must be a positive integer; received ${limit}. A non-positive limit produces a deadlocked semaphore — fail fast at construction instead.`);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Acquires a slot, waiting if the limit has been reached.
|
|
28
|
+
* @returns A promise that resolves when a slot is available.
|
|
29
|
+
*/
|
|
30
|
+
async acquire() {
|
|
31
|
+
if (this.current < this.limit) {
|
|
32
|
+
this.current++;
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
return new Promise((resolve) => {
|
|
36
|
+
this.queue.push(resolve);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
/** Releases a slot, unblocking the next queued caller if any. */
|
|
40
|
+
release() {
|
|
41
|
+
const next = this.queue.shift();
|
|
42
|
+
if (next) next();
|
|
43
|
+
else this.current--;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Number of slots currently available.
|
|
47
|
+
*
|
|
48
|
+
* @returns The count of free concurrency slots.
|
|
49
|
+
*/
|
|
50
|
+
get available() {
|
|
51
|
+
return this.limit - this.current;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Maps over an array with bounded concurrency.
|
|
56
|
+
*
|
|
57
|
+
* @param items - Input items to process.
|
|
58
|
+
* @param concurrency - Maximum number of items processed in parallel.
|
|
59
|
+
* @param fn - Async function applied to each item.
|
|
60
|
+
*
|
|
61
|
+
* @returns Results in the same order as the input items.
|
|
62
|
+
*/
|
|
63
|
+
async function mapConcurrent(items, concurrency, fn) {
|
|
64
|
+
const sem = new Semaphore(concurrency);
|
|
65
|
+
const results = new Array(items.length);
|
|
66
|
+
const tasks = items.map(async (item, i) => {
|
|
67
|
+
await sem.acquire();
|
|
68
|
+
try {
|
|
69
|
+
results[i] = await fn(item, i);
|
|
70
|
+
} finally {
|
|
71
|
+
sem.release();
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
await Promise.all(tasks);
|
|
75
|
+
return results;
|
|
52
76
|
}
|
|
77
|
+
//#endregion
|
|
53
78
|
exports.Semaphore = Semaphore;
|
|
54
|
-
|
|
79
|
+
exports.mapConcurrent = mapConcurrent;
|
|
80
|
+
|
|
81
|
+
//# sourceMappingURL=concurrency.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"concurrency.cjs","sources":["../../src/upload/concurrency.ts"],"sourcesContent":["/**\n * Bounded concurrency primitive.\n *\n * Limits the number of concurrent operations to a fixed maximum. Callers\n * {@link acquire} a slot before starting work and {@link release} it when done.\n * If all slots are taken, `acquire` returns a promise that resolves when a slot\n * becomes available.\n */\nexport class Semaphore {\n private current = 0\n private readonly queue: (() => void)[] = []\n\n /**\n * @param limit - Maximum number of concurrent acquisitions. Must be a\n * positive integer; values `<= 0` would create a semaphore that\n * never lets anything through (all `acquire()` calls would queue\n * forever), so the constructor throws fast instead.\n *\n * @throws `RangeError` when `limit` is not a positive integer.\n */\n constructor(private readonly limit: number) {\n if (!Number.isInteger(limit) || limit <= 0) {\n throw new RangeError(\n `Semaphore limit must be a positive integer; received ${limit}. A non-positive limit produces a deadlocked semaphore — fail fast at construction instead.`,\n )\n }\n }\n\n /**\n * Acquires a slot, waiting if the limit has been reached.\n * @returns A promise that resolves when a slot is available.\n */\n async acquire(): Promise<void> {\n if (this.current < this.limit) {\n this.current++\n return\n }\n return new Promise<void>((resolve) => {\n this.queue.push(resolve)\n })\n }\n\n /** Releases a slot, unblocking the next queued caller if any. */\n release(): void {\n const next = this.queue.shift()\n if (next) {\n next()\n } else {\n this.current--\n }\n }\n\n /**\n * Number of slots currently available.\n *\n * @returns The count of free concurrency slots.\n */\n get available(): number {\n return this.limit - this.current\n }\n}\n\n/**\n * Maps over an array with bounded concurrency.\n *\n * @param items - Input items to process.\n * @param concurrency - Maximum number of items processed in parallel.\n * @param fn - Async function applied to each item.\n *\n * @returns Results in the same order as the input items.\n */\nexport async function mapConcurrent<T, R>(\n items: readonly T[],\n concurrency: number,\n fn: (item: T, index: number) => Promise<R>,\n): Promise<R[]> {\n const sem = new Semaphore(concurrency)\n const results: R[] = new Array(items.length)\n const tasks = items.map(async (item, i) => {\n await sem.acquire()\n try {\n results[i] = await fn(item, i)\n } finally {\n sem.release()\n }\n })\n await Promise.all(tasks)\n return results\n}\n"],"
|
|
1
|
+
{"version":3,"file":"concurrency.cjs","names":[],"sources":["../../src/upload/concurrency.ts"],"sourcesContent":["/**\n * Bounded concurrency primitive.\n *\n * Limits the number of concurrent operations to a fixed maximum. Callers\n * {@link acquire} a slot before starting work and {@link release} it when done.\n * If all slots are taken, `acquire` returns a promise that resolves when a slot\n * becomes available.\n */\nexport class Semaphore {\n private current = 0\n private readonly queue: (() => void)[] = []\n\n /**\n * @param limit - Maximum number of concurrent acquisitions. Must be a\n * positive integer; values `<= 0` would create a semaphore that\n * never lets anything through (all `acquire()` calls would queue\n * forever), so the constructor throws fast instead.\n *\n * @throws `RangeError` when `limit` is not a positive integer.\n */\n constructor(private readonly limit: number) {\n if (!Number.isInteger(limit) || limit <= 0) {\n throw new RangeError(\n `Semaphore limit must be a positive integer; received ${limit}. A non-positive limit produces a deadlocked semaphore — fail fast at construction instead.`,\n )\n }\n }\n\n /**\n * Acquires a slot, waiting if the limit has been reached.\n * @returns A promise that resolves when a slot is available.\n */\n async acquire(): Promise<void> {\n if (this.current < this.limit) {\n this.current++\n return\n }\n return new Promise<void>((resolve) => {\n this.queue.push(resolve)\n })\n }\n\n /** Releases a slot, unblocking the next queued caller if any. */\n release(): void {\n const next = this.queue.shift()\n if (next) {\n next()\n } else {\n this.current--\n }\n }\n\n /**\n * Number of slots currently available.\n *\n * @returns The count of free concurrency slots.\n */\n get available(): number {\n return this.limit - this.current\n }\n}\n\n/**\n * Maps over an array with bounded concurrency.\n *\n * @param items - Input items to process.\n * @param concurrency - Maximum number of items processed in parallel.\n * @param fn - Async function applied to each item.\n *\n * @returns Results in the same order as the input items.\n */\nexport async function mapConcurrent<T, R>(\n items: readonly T[],\n concurrency: number,\n fn: (item: T, index: number) => Promise<R>,\n): Promise<R[]> {\n const sem = new Semaphore(concurrency)\n const results: R[] = new Array(items.length)\n const tasks = items.map(async (item, i) => {\n await sem.acquire()\n try {\n results[i] = await fn(item, i)\n } finally {\n sem.release()\n }\n })\n await Promise.all(tasks)\n return results\n}\n"],"mappings":";;;;;;;;;AAQA,IAAa,YAAb,MAAuB;CAYQ;CAX7B,UAAkB;CAClB,QAAyC,CAAC;;;;;;;;;CAU1C,YAAY,OAAgC;EAAf,KAAA,QAAA;EAC3B,IAAI,CAAC,OAAO,UAAU,KAAK,KAAK,SAAS,GACvC,MAAM,IAAI,WACR,wDAAwD,MAAM,4FAChE;CAEJ;;;;;CAMA,MAAM,UAAyB;EAC7B,IAAI,KAAK,UAAU,KAAK,OAAO;GAC7B,KAAK;GACL;EACF;EACA,OAAO,IAAI,SAAe,YAAY;GACpC,KAAK,MAAM,KAAK,OAAO;EACzB,CAAC;CACH;;CAGA,UAAgB;EACd,MAAM,OAAO,KAAK,MAAM,MAAM;EAC9B,IAAI,MACF,KAAK;OAEL,KAAK;CAET;;;;;;CAOA,IAAI,YAAoB;EACtB,OAAO,KAAK,QAAQ,KAAK;CAC3B;AACF;;;;;;;;;;AAWA,eAAsB,cACpB,OACA,aACA,IACc;CACd,MAAM,MAAM,IAAI,UAAU,WAAW;CACrC,MAAM,UAAe,IAAI,MAAM,MAAM,MAAM;CAC3C,MAAM,QAAQ,MAAM,IAAI,OAAO,MAAM,MAAM;EACzC,MAAM,IAAI,QAAQ;EAClB,IAAI;GACF,QAAQ,KAAK,MAAM,GAAG,MAAM,CAAC;EAC/B,UAAU;GACR,IAAI,QAAQ;EACd;CACF,CAAC;CACD,MAAM,QAAQ,IAAI,KAAK;CACvB,OAAO;AACT"}
|
|
@@ -1,54 +1,80 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
1
|
+
//#region src/upload/concurrency.ts
|
|
2
|
+
/**
|
|
3
|
+
* Bounded concurrency primitive.
|
|
4
|
+
*
|
|
5
|
+
* Limits the number of concurrent operations to a fixed maximum. Callers
|
|
6
|
+
* {@link acquire} a slot before starting work and {@link release} it when done.
|
|
7
|
+
* If all slots are taken, `acquire` returns a promise that resolves when a slot
|
|
8
|
+
* becomes available.
|
|
9
|
+
*/
|
|
10
|
+
var Semaphore = class {
|
|
11
|
+
limit;
|
|
12
|
+
current = 0;
|
|
13
|
+
queue = [];
|
|
14
|
+
/**
|
|
15
|
+
* @param limit - Maximum number of concurrent acquisitions. Must be a
|
|
16
|
+
* positive integer; values `<= 0` would create a semaphore that
|
|
17
|
+
* never lets anything through (all `acquire()` calls would queue
|
|
18
|
+
* forever), so the constructor throws fast instead.
|
|
19
|
+
*
|
|
20
|
+
* @throws `RangeError` when `limit` is not a positive integer.
|
|
21
|
+
*/
|
|
22
|
+
constructor(limit) {
|
|
23
|
+
this.limit = limit;
|
|
24
|
+
if (!Number.isInteger(limit) || limit <= 0) throw new RangeError(`Semaphore limit must be a positive integer; received ${limit}. A non-positive limit produces a deadlocked semaphore — fail fast at construction instead.`);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Acquires a slot, waiting if the limit has been reached.
|
|
28
|
+
* @returns A promise that resolves when a slot is available.
|
|
29
|
+
*/
|
|
30
|
+
async acquire() {
|
|
31
|
+
if (this.current < this.limit) {
|
|
32
|
+
this.current++;
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
return new Promise((resolve) => {
|
|
36
|
+
this.queue.push(resolve);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
/** Releases a slot, unblocking the next queued caller if any. */
|
|
40
|
+
release() {
|
|
41
|
+
const next = this.queue.shift();
|
|
42
|
+
if (next) next();
|
|
43
|
+
else this.current--;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Number of slots currently available.
|
|
47
|
+
*
|
|
48
|
+
* @returns The count of free concurrency slots.
|
|
49
|
+
*/
|
|
50
|
+
get available() {
|
|
51
|
+
return this.limit - this.current;
|
|
52
|
+
}
|
|
53
53
|
};
|
|
54
|
-
|
|
54
|
+
/**
|
|
55
|
+
* Maps over an array with bounded concurrency.
|
|
56
|
+
*
|
|
57
|
+
* @param items - Input items to process.
|
|
58
|
+
* @param concurrency - Maximum number of items processed in parallel.
|
|
59
|
+
* @param fn - Async function applied to each item.
|
|
60
|
+
*
|
|
61
|
+
* @returns Results in the same order as the input items.
|
|
62
|
+
*/
|
|
63
|
+
async function mapConcurrent(items, concurrency, fn) {
|
|
64
|
+
const sem = new Semaphore(concurrency);
|
|
65
|
+
const results = new Array(items.length);
|
|
66
|
+
const tasks = items.map(async (item, i) => {
|
|
67
|
+
await sem.acquire();
|
|
68
|
+
try {
|
|
69
|
+
results[i] = await fn(item, i);
|
|
70
|
+
} finally {
|
|
71
|
+
sem.release();
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
await Promise.all(tasks);
|
|
75
|
+
return results;
|
|
76
|
+
}
|
|
77
|
+
//#endregion
|
|
78
|
+
export { Semaphore, mapConcurrent };
|
|
79
|
+
|
|
80
|
+
//# sourceMappingURL=concurrency.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"concurrency.js","sources":["../../src/upload/concurrency.ts"],"sourcesContent":["/**\n * Bounded concurrency primitive.\n *\n * Limits the number of concurrent operations to a fixed maximum. Callers\n * {@link acquire} a slot before starting work and {@link release} it when done.\n * If all slots are taken, `acquire` returns a promise that resolves when a slot\n * becomes available.\n */\nexport class Semaphore {\n private current = 0\n private readonly queue: (() => void)[] = []\n\n /**\n * @param limit - Maximum number of concurrent acquisitions. Must be a\n * positive integer; values `<= 0` would create a semaphore that\n * never lets anything through (all `acquire()` calls would queue\n * forever), so the constructor throws fast instead.\n *\n * @throws `RangeError` when `limit` is not a positive integer.\n */\n constructor(private readonly limit: number) {\n if (!Number.isInteger(limit) || limit <= 0) {\n throw new RangeError(\n `Semaphore limit must be a positive integer; received ${limit}. A non-positive limit produces a deadlocked semaphore — fail fast at construction instead.`,\n )\n }\n }\n\n /**\n * Acquires a slot, waiting if the limit has been reached.\n * @returns A promise that resolves when a slot is available.\n */\n async acquire(): Promise<void> {\n if (this.current < this.limit) {\n this.current++\n return\n }\n return new Promise<void>((resolve) => {\n this.queue.push(resolve)\n })\n }\n\n /** Releases a slot, unblocking the next queued caller if any. */\n release(): void {\n const next = this.queue.shift()\n if (next) {\n next()\n } else {\n this.current--\n }\n }\n\n /**\n * Number of slots currently available.\n *\n * @returns The count of free concurrency slots.\n */\n get available(): number {\n return this.limit - this.current\n }\n}\n\n/**\n * Maps over an array with bounded concurrency.\n *\n * @param items - Input items to process.\n * @param concurrency - Maximum number of items processed in parallel.\n * @param fn - Async function applied to each item.\n *\n * @returns Results in the same order as the input items.\n */\nexport async function mapConcurrent<T, R>(\n items: readonly T[],\n concurrency: number,\n fn: (item: T, index: number) => Promise<R>,\n): Promise<R[]> {\n const sem = new Semaphore(concurrency)\n const results: R[] = new Array(items.length)\n const tasks = items.map(async (item, i) => {\n await sem.acquire()\n try {\n results[i] = await fn(item, i)\n } finally {\n sem.release()\n }\n })\n await Promise.all(tasks)\n return results\n}\n"],"
|
|
1
|
+
{"version":3,"file":"concurrency.js","names":[],"sources":["../../src/upload/concurrency.ts"],"sourcesContent":["/**\n * Bounded concurrency primitive.\n *\n * Limits the number of concurrent operations to a fixed maximum. Callers\n * {@link acquire} a slot before starting work and {@link release} it when done.\n * If all slots are taken, `acquire` returns a promise that resolves when a slot\n * becomes available.\n */\nexport class Semaphore {\n private current = 0\n private readonly queue: (() => void)[] = []\n\n /**\n * @param limit - Maximum number of concurrent acquisitions. Must be a\n * positive integer; values `<= 0` would create a semaphore that\n * never lets anything through (all `acquire()` calls would queue\n * forever), so the constructor throws fast instead.\n *\n * @throws `RangeError` when `limit` is not a positive integer.\n */\n constructor(private readonly limit: number) {\n if (!Number.isInteger(limit) || limit <= 0) {\n throw new RangeError(\n `Semaphore limit must be a positive integer; received ${limit}. A non-positive limit produces a deadlocked semaphore — fail fast at construction instead.`,\n )\n }\n }\n\n /**\n * Acquires a slot, waiting if the limit has been reached.\n * @returns A promise that resolves when a slot is available.\n */\n async acquire(): Promise<void> {\n if (this.current < this.limit) {\n this.current++\n return\n }\n return new Promise<void>((resolve) => {\n this.queue.push(resolve)\n })\n }\n\n /** Releases a slot, unblocking the next queued caller if any. */\n release(): void {\n const next = this.queue.shift()\n if (next) {\n next()\n } else {\n this.current--\n }\n }\n\n /**\n * Number of slots currently available.\n *\n * @returns The count of free concurrency slots.\n */\n get available(): number {\n return this.limit - this.current\n }\n}\n\n/**\n * Maps over an array with bounded concurrency.\n *\n * @param items - Input items to process.\n * @param concurrency - Maximum number of items processed in parallel.\n * @param fn - Async function applied to each item.\n *\n * @returns Results in the same order as the input items.\n */\nexport async function mapConcurrent<T, R>(\n items: readonly T[],\n concurrency: number,\n fn: (item: T, index: number) => Promise<R>,\n): Promise<R[]> {\n const sem = new Semaphore(concurrency)\n const results: R[] = new Array(items.length)\n const tasks = items.map(async (item, i) => {\n await sem.acquire()\n try {\n results[i] = await fn(item, i)\n } finally {\n sem.release()\n }\n })\n await Promise.all(tasks)\n return results\n}\n"],"mappings":";;;;;;;;;AAQA,IAAa,YAAb,MAAuB;CAYQ;CAX7B,UAAkB;CAClB,QAAyC,CAAC;;;;;;;;;CAU1C,YAAY,OAAgC;EAAf,KAAA,QAAA;EAC3B,IAAI,CAAC,OAAO,UAAU,KAAK,KAAK,SAAS,GACvC,MAAM,IAAI,WACR,wDAAwD,MAAM,4FAChE;CAEJ;;;;;CAMA,MAAM,UAAyB;EAC7B,IAAI,KAAK,UAAU,KAAK,OAAO;GAC7B,KAAK;GACL;EACF;EACA,OAAO,IAAI,SAAe,YAAY;GACpC,KAAK,MAAM,KAAK,OAAO;EACzB,CAAC;CACH;;CAGA,UAAgB;EACd,MAAM,OAAO,KAAK,MAAM,MAAM;EAC9B,IAAI,MACF,KAAK;OAEL,KAAK;CAET;;;;;;CAOA,IAAI,YAAoB;EACtB,OAAO,KAAK,QAAQ,KAAK;CAC3B;AACF;;;;;;;;;;AAWA,eAAsB,cACpB,OACA,aACA,IACc;CACd,MAAM,MAAM,IAAI,UAAU,WAAW;CACrC,MAAM,UAAe,IAAI,MAAM,MAAM,MAAM;CAC3C,MAAM,QAAQ,MAAM,IAAI,OAAO,MAAM,MAAM;EACzC,MAAM,IAAI,QAAQ;EAClB,IAAI;GACF,QAAQ,KAAK,MAAM,GAAG,MAAM,CAAC;EAC/B,UAAU;GACR,IAAI,QAAQ;EACd;CACF,CAAC;CACD,MAAM,QAAQ,IAAI,KAAK;CACvB,OAAO;AACT"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
const require_errors_index = require("../errors/index.cjs");
|
|
2
|
+
//#region src/upload/finish.ts
|
|
3
|
+
/**
|
|
4
|
+
* Calls `b2_finish_large_file` and classifies failures after dispatch that can
|
|
5
|
+
* hide an already-committed file as ambiguous finish failures.
|
|
6
|
+
*
|
|
7
|
+
* @param raw - Low-level B2 API client.
|
|
8
|
+
* @param accountInfo - Authorized account state.
|
|
9
|
+
* @param context - Finish request data and reconciliation metadata.
|
|
10
|
+
*
|
|
11
|
+
* @returns The completed file version metadata.
|
|
12
|
+
*/
|
|
13
|
+
async function finishLargeFileWithAbortReconciliation(raw, accountInfo, context) {
|
|
14
|
+
context.signal?.throwIfAborted();
|
|
15
|
+
try {
|
|
16
|
+
return await raw.finishLargeFile(accountInfo.getApiUrl(), accountInfo.getAuthToken(), {
|
|
17
|
+
fileId: context.fileId,
|
|
18
|
+
partSha1Array: context.partSha1s
|
|
19
|
+
}, context.signal === void 0 && context.retry === void 0 ? void 0 : {
|
|
20
|
+
...context.signal !== void 0 ? { signal: context.signal } : {},
|
|
21
|
+
...context.retry !== void 0 ? { retry: context.retry } : {}
|
|
22
|
+
});
|
|
23
|
+
} catch (err) {
|
|
24
|
+
if (err instanceof require_errors_index.FinishLargeFileResponseBodyError) throw finishLargeFileResponseBodyErrorWithContext(err, context);
|
|
25
|
+
if (isAmbiguousFinishDispatchFailure(err, context.signal)) throw new require_errors_index.FinishLargeFileResponseBodyError("b2_finish_large_file failed after dispatch; final file state is ambiguous.", {
|
|
26
|
+
cause: err,
|
|
27
|
+
fileId: context.fileId,
|
|
28
|
+
bucketId: context.bucketId,
|
|
29
|
+
fileName: context.fileName
|
|
30
|
+
});
|
|
31
|
+
throw err;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function finishLargeFileResponseBodyErrorWithContext(err, context) {
|
|
35
|
+
if (err.fileId === context.fileId && err.bucketId === context.bucketId && err.fileName === context.fileName) return err;
|
|
36
|
+
return new require_errors_index.FinishLargeFileResponseBodyError(err.message, {
|
|
37
|
+
cause: err.cause ?? err,
|
|
38
|
+
fileId: context.fileId,
|
|
39
|
+
bucketId: context.bucketId,
|
|
40
|
+
fileName: context.fileName
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
function isAmbiguousFinishDispatchFailure(err, signal) {
|
|
44
|
+
if (err instanceof require_errors_index.NetworkError) return true;
|
|
45
|
+
if (isTimeoutError(err)) return true;
|
|
46
|
+
if (signal?.aborted !== true) return false;
|
|
47
|
+
if (signal.reason !== void 0 && Object.is(err, signal.reason)) return true;
|
|
48
|
+
return isAbortError(err);
|
|
49
|
+
}
|
|
50
|
+
function isAbortError(err) {
|
|
51
|
+
return err instanceof DOMException && err.name === "AbortError" || err instanceof Error && err.name === "AbortError";
|
|
52
|
+
}
|
|
53
|
+
function isTimeoutError(err) {
|
|
54
|
+
return err instanceof DOMException && err.name === "TimeoutError" || err instanceof Error && err.name === "TimeoutError";
|
|
55
|
+
}
|
|
56
|
+
//#endregion
|
|
57
|
+
exports.finishLargeFileWithAbortReconciliation = finishLargeFileWithAbortReconciliation;
|
|
58
|
+
|
|
59
|
+
//# sourceMappingURL=finish.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"finish.cjs","names":[],"sources":["../../src/upload/finish.ts"],"sourcesContent":["import type { AccountInfo } from '../auth/account-info.ts'\nimport { FinishLargeFileResponseBodyError, NetworkError } from '../errors/index.ts'\nimport type { RetryOptions } from '../http/retry.ts'\nimport type { RawClient } from '../raw/index.ts'\nimport type { FileVersion } from '../types/file.ts'\nimport type { BucketId, LargeFileId } from '../types/ids.ts'\n\n/** Context for safely finalizing a large file. */\nexport interface FinishLargeFileContext {\n readonly fileId: LargeFileId\n readonly bucketId: BucketId\n readonly fileName: string\n readonly partSha1s: readonly string[]\n readonly signal?: AbortSignal\n readonly retry?: Partial<RetryOptions>\n}\n\n/**\n * Calls `b2_finish_large_file` and classifies failures after dispatch that can\n * hide an already-committed file as ambiguous finish failures.\n *\n * @param raw - Low-level B2 API client.\n * @param accountInfo - Authorized account state.\n * @param context - Finish request data and reconciliation metadata.\n *\n * @returns The completed file version metadata.\n */\nexport async function finishLargeFileWithAbortReconciliation(\n raw: RawClient,\n accountInfo: AccountInfo,\n context: FinishLargeFileContext,\n): Promise<FileVersion> {\n context.signal?.throwIfAborted()\n try {\n return await raw.finishLargeFile(\n accountInfo.getApiUrl(),\n accountInfo.getAuthToken(),\n {\n fileId: context.fileId,\n partSha1Array: context.partSha1s,\n },\n context.signal === undefined && context.retry === undefined\n ? undefined\n : {\n ...(context.signal !== undefined ? { signal: context.signal } : {}),\n ...(context.retry !== undefined ? { retry: context.retry } : {}),\n },\n )\n } catch (err) {\n if (err instanceof FinishLargeFileResponseBodyError) {\n throw finishLargeFileResponseBodyErrorWithContext(err, context)\n }\n if (isAmbiguousFinishDispatchFailure(err, context.signal)) {\n throw new FinishLargeFileResponseBodyError(\n 'b2_finish_large_file failed after dispatch; final file state is ambiguous.',\n {\n cause: err,\n fileId: context.fileId,\n bucketId: context.bucketId,\n fileName: context.fileName,\n },\n )\n }\n throw err\n }\n}\n\nfunction finishLargeFileResponseBodyErrorWithContext(\n err: FinishLargeFileResponseBodyError,\n context: FinishLargeFileContext,\n): FinishLargeFileResponseBodyError {\n if (\n err.fileId === context.fileId &&\n err.bucketId === context.bucketId &&\n err.fileName === context.fileName\n ) {\n return err\n }\n return new FinishLargeFileResponseBodyError(err.message, {\n cause: err.cause ?? err,\n fileId: context.fileId,\n bucketId: context.bucketId,\n fileName: context.fileName,\n })\n}\n\nfunction isAmbiguousFinishDispatchFailure(err: unknown, signal: AbortSignal | undefined): boolean {\n if (err instanceof NetworkError) return true\n if (isTimeoutError(err)) return true\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\nfunction isAbortError(err: unknown): boolean {\n return (\n (err instanceof DOMException && err.name === 'AbortError') ||\n (err instanceof Error && err.name === 'AbortError')\n )\n}\n\nfunction isTimeoutError(err: unknown): boolean {\n return (\n (err instanceof DOMException && err.name === 'TimeoutError') ||\n (err instanceof Error && err.name === 'TimeoutError')\n )\n}\n"],"mappings":";;;;;;;;;;;;AA2BA,eAAsB,uCACpB,KACA,aACA,SACsB;CACtB,QAAQ,QAAQ,eAAe;CAC/B,IAAI;EACF,OAAO,MAAM,IAAI,gBACf,YAAY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