@softistx/s3 0.0.0-stage → 0.13.2

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.
Files changed (93) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +609 -2
  3. package/dist/bucket/bind-bucket.d.ts +42 -0
  4. package/dist/bucket/bind-bucket.d.ts.map +1 -0
  5. package/dist/bucket/bound-bucket.d.ts +119 -0
  6. package/dist/bucket/bound-bucket.d.ts.map +1 -0
  7. package/dist/bucket/context.d.ts +55 -0
  8. package/dist/bucket/context.d.ts.map +1 -0
  9. package/dist/bucket/define-bucket.d.ts +16 -0
  10. package/dist/bucket/define-bucket.d.ts.map +1 -0
  11. package/dist/bucket/disposition.d.ts +9 -0
  12. package/dist/bucket/disposition.d.ts.map +1 -0
  13. package/dist/bucket/guards.d.ts +38 -0
  14. package/dist/bucket/guards.d.ts.map +1 -0
  15. package/dist/bucket/operations/counted-stream.d.ts +26 -0
  16. package/dist/bucket/operations/counted-stream.d.ts.map +1 -0
  17. package/dist/bucket/operations/deadline.d.ts +21 -0
  18. package/dist/bucket/operations/deadline.d.ts.map +1 -0
  19. package/dist/bucket/operations/fetch-object.d.ts +68 -0
  20. package/dist/bucket/operations/fetch-object.d.ts.map +1 -0
  21. package/dist/bucket/operations/list-xml.d.ts +18 -0
  22. package/dist/bucket/operations/list-xml.d.ts.map +1 -0
  23. package/dist/bucket/operations/list.d.ts +12 -0
  24. package/dist/bucket/operations/list.d.ts.map +1 -0
  25. package/dist/bucket/operations/open-answer.d.ts +5 -0
  26. package/dist/bucket/operations/open-answer.d.ts.map +1 -0
  27. package/dist/bucket/operations/open-range.d.ts +10 -0
  28. package/dist/bucket/operations/open-range.d.ts.map +1 -0
  29. package/dist/bucket/operations/open-relay.d.ts +8 -0
  30. package/dist/bucket/operations/open-relay.d.ts.map +1 -0
  31. package/dist/bucket/operations/open.d.ts +4 -0
  32. package/dist/bucket/operations/open.d.ts.map +1 -0
  33. package/dist/bucket/operations/post-policy.d.ts +77 -0
  34. package/dist/bucket/operations/post-policy.d.ts.map +1 -0
  35. package/dist/bucket/operations/post-signer.d.ts +21 -0
  36. package/dist/bucket/operations/post-signer.d.ts.map +1 -0
  37. package/dist/bucket/operations/presign-post.d.ts +44 -0
  38. package/dist/bucket/operations/presign-post.d.ts.map +1 -0
  39. package/dist/bucket/operations/presign.d.ts +34 -0
  40. package/dist/bucket/operations/presign.d.ts.map +1 -0
  41. package/dist/bucket/operations/put-body.d.ts +13 -0
  42. package/dist/bucket/operations/put-body.d.ts.map +1 -0
  43. package/dist/bucket/operations/query-sign.d.ts +15 -0
  44. package/dist/bucket/operations/query-sign.d.ts.map +1 -0
  45. package/dist/bucket/operations/reads.d.ts +8 -0
  46. package/dist/bucket/operations/reads.d.ts.map +1 -0
  47. package/dist/bucket/operations/sized-body.d.ts +24 -0
  48. package/dist/bucket/operations/sized-body.d.ts.map +1 -0
  49. package/dist/bucket/operations/slice.d.ts +4 -0
  50. package/dist/bucket/operations/slice.d.ts.map +1 -0
  51. package/dist/bucket/operations/writes.d.ts +10 -0
  52. package/dist/bucket/operations/writes.d.ts.map +1 -0
  53. package/dist/bucket/shape.d.ts +6 -0
  54. package/dist/bucket/shape.d.ts.map +1 -0
  55. package/dist/bucket/types.d.ts +164 -0
  56. package/dist/bucket/types.d.ts.map +1 -0
  57. package/dist/chunks/index-jgjey570.js +118 -0
  58. package/dist/chunks/index-jgjey570.js.map +13 -0
  59. package/dist/errors/is-bucket-unavailable.d.ts +18 -0
  60. package/dist/errors/is-bucket-unavailable.d.ts.map +1 -0
  61. package/dist/errors/s3-error.d.ts +80 -0
  62. package/dist/errors/s3-error.d.ts.map +1 -0
  63. package/dist/index.d.ts +8 -0
  64. package/dist/index.d.ts.map +1 -0
  65. package/dist/index.js +1288 -0
  66. package/dist/index.js.map +32 -0
  67. package/dist/testing/fetch-archive.d.ts +8 -0
  68. package/dist/testing/fetch-archive.d.ts.map +1 -0
  69. package/dist/testing/index.d.ts +6 -0
  70. package/dist/testing/index.d.ts.map +1 -0
  71. package/dist/testing/index.js +416 -0
  72. package/dist/testing/index.js.map +16 -0
  73. package/dist/testing/ports.d.ts +15 -0
  74. package/dist/testing/ports.d.ts.map +1 -0
  75. package/dist/testing/ready.d.ts +49 -0
  76. package/dist/testing/ready.d.ts.map +1 -0
  77. package/dist/testing/reaper.d.ts +4 -0
  78. package/dist/testing/reaper.d.ts.map +1 -0
  79. package/dist/testing/seaweedfs.d.ts +64 -0
  80. package/dist/testing/seaweedfs.d.ts.map +1 -0
  81. package/dist/testing/test-s3.d.ts +35 -0
  82. package/dist/testing/test-s3.d.ts.map +1 -0
  83. package/dist/testing/weed.d.ts +17 -0
  84. package/dist/testing/weed.d.ts.map +1 -0
  85. package/docs/README.md +17 -0
  86. package/docs/guide/buckets.md +220 -0
  87. package/docs/guide/presigned-urls.md +403 -0
  88. package/docs/guide/reads.md +417 -0
  89. package/docs/guide/testing.md +151 -0
  90. package/docs/guide/writes.md +374 -0
  91. package/docs/roadmap.md +116 -0
  92. package/docs/troubleshooting.md +982 -0
  93. package/package.json +61 -5
@@ -0,0 +1,21 @@
1
+ import { type BucketContext } from '../context.js';
2
+ import { type PostSigner } from './post-policy.js';
3
+ /**
4
+ * Where Bun would send this bucket's requests, and as whom.
5
+ *
6
+ * Read off a URL Bun itself signs, rather than worked out again here:
7
+ * measured on bun 1.4.2, Bun signs for region `auto` at any endpoint that is
8
+ * not AWS's, reads the region out of an AWS hostname, falls back to
9
+ * `us-east-1`, and puts the bucket in the path or the host by
10
+ * `virtualHostedStyle`. A second copy of those rules would drift from the
11
+ * first; this way a POST goes wherever a presigned PUT goes. The probe key is
12
+ * signed and thrown away — nothing is sent.
13
+ */
14
+ export declare const PROBE = "nxgt-probe";
15
+ /**
16
+ * Who signs and where, for the call named `call` (`presignPost` or `list`):
17
+ * the refusals below name it, so a failed listing does not read as a failed
18
+ * form. The listing signs its own GET with the same signer.
19
+ */
20
+ export declare function signerOf<P>(context: BucketContext<P>, call?: string): PostSigner;
21
+ //# sourceMappingURL=post-signer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"post-signer.d.ts","sourceRoot":"","sources":["../../../src/bucket/operations/post-signer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAoB,MAAM,YAAY,CAAC;AAClE,OAAO,EAAE,KAAK,UAAU,EAAkC,MAAM,eAAe,CAAC;AAEhF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,KAAK,eAAe,CAAC;AAiDlC;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EACzB,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,EACzB,IAAI,SAAgB,GAClB,UAAU,CAgCZ"}
@@ -0,0 +1,44 @@
1
+ import type { S3Options } from 'bun';
2
+ import { type BucketContext } from '../context.js';
3
+ import { type PresignedPost } from './post-policy.js';
4
+ export type { PresignedPost };
5
+ /**
6
+ * How a presigned POST is asked for. Every bound here is one the **service**
7
+ * holds the upload to — measured against SeaweedFS 4.47, a body over
8
+ * `maxSize` is refused with `400 EntityTooLarge` and a wrong type with
9
+ * `403 AccessDenied`.
10
+ */
11
+ export interface PresignPostOptions {
12
+ /** Seconds until the form expires: above 0, at most 604800. A day when left out. */
13
+ expiresIn?: number;
14
+ /**
15
+ * The biggest body, in bytes. Defaults to the bucket's own `maxSize`, and
16
+ * cannot be above it; a bucket without one requires it.
17
+ */
18
+ maxSize?: number;
19
+ /** The smallest body, in bytes. `0` when left out. */
20
+ minSize?: number;
21
+ /**
22
+ * The one content type the form may carry, or a prefix of it. Defaults to
23
+ * the bucket's `contentType` when that is a single type. A prefix is for
24
+ * a bucket that names no type: the page's code then appends its own
25
+ * `Content-Type` field before the file.
26
+ */
27
+ type?: string | {
28
+ startsWith: string;
29
+ };
30
+ /** `public-read` and the rest, fixed by the policy. */
31
+ acl?: S3Options['acl'];
32
+ /**
33
+ * The `Content-Disposition` the object is stored with, fixed by the
34
+ * policy: the browser posts exactly this field. Printable ASCII only.
35
+ */
36
+ contentDisposition?: string | undefined;
37
+ }
38
+ /**
39
+ * The form a browser posts to upload this object: the key fixed, the size
40
+ * held to a range, the content type fixed or held to a prefix — all by the
41
+ * service. `now` is for the spec; a caller never passes it.
42
+ */
43
+ export declare function presignPostForm<P>(context: BucketContext<P>, params: P, options?: PresignPostOptions, now?: Date): PresignedPost;
44
+ //# sourceMappingURL=presign-post.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"presign-post.d.ts","sourceRoot":"","sources":["../../../src/bucket/operations/presign-post.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;AAErC,OAAO,EAAE,KAAK,aAAa,EAAiB,MAAM,YAAY,CAAC;AAG/D,OAAO,EAEN,KAAK,aAAa,EAElB,MAAM,eAAe,CAAC;AAGvB,YAAY,EAAE,aAAa,EAAE,CAAC;AAE9B;;;;;GAKG;AACH,MAAM,WAAW,kBAAkB;IAClC,oFAAoF;IACpF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,sDAAsD;IACtD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;;OAKG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG;QAAE,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC;IACvC,uDAAuD;IACvD,GAAG,CAAC,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC;IACvB;;;OAGG;IACH,kBAAkB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACxC;AA+GD;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAChC,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,EACzB,MAAM,EAAE,CAAC,EACT,OAAO,CAAC,EAAE,kBAAkB,EAC5B,GAAG,GAAE,IAAiB,GACpB,aAAa,CA2Bf"}
@@ -0,0 +1,34 @@
1
+ import type { S3Options } from 'bun';
2
+ import { type BucketContext } from '../context.js';
3
+ /** How a presigned URL is asked for. `expiresIn` is **seconds**, as S3's is. */
4
+ export interface PresignOptions {
5
+ /** Seconds until it expires. Bun's default is a day; give one. */
6
+ expiresIn?: number | undefined;
7
+ /** `public-read` and the rest, when the service honours it. */
8
+ acl?: S3Options['acl'];
9
+ }
10
+ /** What a signed GET may add: how the download is presented. */
11
+ export interface PresignGetOptions extends PresignOptions {
12
+ /**
13
+ * Signs `response-content-disposition`: the service answers this URL with
14
+ * that `Content-Disposition`, whatever the object stored. A download link
15
+ * with a filename: `attachment; filename*=UTF-8''report.pdf`. Printable
16
+ * ASCII only. A `presignPut` takes none: the header would mean nothing
17
+ * to a write.
18
+ */
19
+ contentDisposition?: string | undefined;
20
+ }
21
+ export declare function presignGetUrl<P>(context: BucketContext<P>, params: P, options?: PresignGetOptions): string;
22
+ /**
23
+ * A URL that writes this object, signed.
24
+ *
25
+ * It carries **no content type**, and takes none. Measured on bun 1.4.2:
26
+ * `presign`'s `type` only adds `response-content-type`, S3's override for
27
+ * what a *download* is labelled; `X-Amz-SignedHeaders` stays `host`, so the
28
+ * `Content-Type` the uploader sends is not signed and not constrained. A PUT
29
+ * signed for a `text/csv` bucket stores an `application/zip` body happily —
30
+ * measured against this package's own test service, status 200. Naming a type
31
+ * here would only look like a guarantee.
32
+ */
33
+ export declare function presignPutUrl<P>(context: BucketContext<P>, params: P, options?: PresignOptions): string;
34
+ //# sourceMappingURL=presign.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"presign.d.ts","sourceRoot":"","sources":["../../../src/bucket/operations/presign.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;AACrC,OAAO,EAAE,KAAK,aAAa,EAAiB,MAAM,YAAY,CAAC;AAG/D,gFAAgF;AAChF,MAAM,WAAW,cAAc;IAC9B,kEAAkE;IAClE,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,+DAA+D;IAC/D,GAAG,CAAC,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC;CACvB;AAED,gEAAgE;AAChE,MAAM,WAAW,iBAAkB,SAAQ,cAAc;IACxD;;;;;;OAMG;IACH,kBAAkB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACxC;AA4DD,wBAAgB,aAAa,CAAC,CAAC,EAC9B,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,EACzB,MAAM,EAAE,CAAC,EACT,OAAO,CAAC,EAAE,iBAAiB,GACzB,MAAM,CAMR;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAC9B,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,EACzB,MAAM,EAAE,CAAC,EACT,OAAO,CAAC,EAAE,cAAc,GACtB,MAAM,CAMR"}
@@ -0,0 +1,13 @@
1
+ import type { PutBody } from '../types.js';
2
+ /**
3
+ * The body as `fetch` sends it under a deadline.
4
+ *
5
+ * A string, bytes or a `Blob` of known size go as they are. Anything else —
6
+ * a `ReadableStream`, a `Response`, an `S3File` — is **read into memory
7
+ * first**, inside the deadline: S3 refuses a chunked PUT, which is what
8
+ * `fetch` would send for a stream with no length. A bucket with a `maxSize`
9
+ * has already refused these (`UNMEASURABLE`), so this reaches a bucket
10
+ * without one, and the body's size costs memory there.
11
+ */
12
+ export declare function fetchBody(body: PutBody, signal: AbortSignal): Promise<BodyInit>;
13
+ //# sourceMappingURL=put-body.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"put-body.d.ts","sourceRoot":"","sources":["../../../src/bucket/operations/put-body.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAsFxC;;;;;;;;;GASG;AACH,wBAAsB,SAAS,CAC9B,IAAI,EAAE,OAAO,EACb,MAAM,EAAE,WAAW,GACjB,OAAO,CAAC,QAAQ,CAAC,CAKnB"}
@@ -0,0 +1,15 @@
1
+ import { type PostSigner } from './post-policy.js';
2
+ /**
3
+ * A GET on the bucket's root, signed in its query (SigV4 "presigned URL"),
4
+ * for the one request Bun cannot presign: a bucket-level one, such as a
5
+ * listing.
6
+ *
7
+ * It signs nothing of its own: the URL is written without a signature and
8
+ * `presignedSignature` — the function `signerOf` checks the secret with
9
+ * against Bun's own signature, so it is known to match Bun's canonical form
10
+ * — computes it, and it is appended. The canonical query is the pairs as
11
+ * sent, sorted, so the values are encoded here once, RFC 3986-style, and sent
12
+ * exactly so. `host` is the one signed header and no payload is signed.
13
+ */
14
+ export declare function signedBucketGet(signer: PostSigner, query: Readonly<Record<string, string>>, now?: Date, expiresIn?: number): string;
15
+ //# sourceMappingURL=query-sign.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query-sign.d.ts","sourceRoot":"","sources":["../../../src/bucket/operations/query-sign.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,KAAK,UAAU,EAAsB,MAAM,eAAe,CAAC;AAS/E;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAC9B,MAAM,EAAE,UAAU,EAClB,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EACvC,GAAG,GAAE,IAAiB,EACtB,SAAS,SAAK,GACZ,MAAM,CAmBR"}
@@ -0,0 +1,8 @@
1
+ import type { S3Stats } from 'bun';
2
+ import { type BucketContext } from '../context.js';
3
+ import type { CallOptions } from '../types.js';
4
+ export declare function readBytes<P>(context: BucketContext<P>, params: P, options?: CallOptions): Promise<Uint8Array | undefined>;
5
+ export declare function readText<P>(context: BucketContext<P>, params: P, options?: CallOptions): Promise<string | undefined>;
6
+ export declare function statObject<P>(context: BucketContext<P>, params: P, options?: CallOptions): Promise<S3Stats | undefined>;
7
+ export declare function objectExists<P>(context: BucketContext<P>, params: P, options?: CallOptions): Promise<boolean>;
8
+ //# sourceMappingURL=reads.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reads.d.ts","sourceRoot":"","sources":["../../../src/bucket/operations/reads.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAU,OAAO,EAAE,MAAM,KAAK,CAAC;AAC3C,OAAO,EAAE,KAAK,aAAa,EAAS,MAAM,YAAY,CAAC;AACvD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AA0B5C,wBAAsB,SAAS,CAAC,CAAC,EAChC,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,EACzB,MAAM,EAAE,CAAC,EACT,OAAO,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CASjC;AAED,wBAAsB,QAAQ,CAAC,CAAC,EAC/B,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,EACzB,MAAM,EAAE,CAAC,EACT,OAAO,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAU7B;AAED,wBAAsB,UAAU,CAAC,CAAC,EACjC,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,EACzB,MAAM,EAAE,CAAC,EACT,OAAO,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC,CAS9B;AAED,wBAAsB,YAAY,CAAC,CAAC,EACnC,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,EACzB,MAAM,EAAE,CAAC,EACT,OAAO,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,OAAO,CAAC,CAWlB"}
@@ -0,0 +1,24 @@
1
+ import type { BucketContext } from '../context.js';
2
+ import type { PutBody, StreamBody } from '../types.js';
3
+ /** A body that streams: it needs a `size`, and a `size` needs it. */
4
+ export declare function isStreamBody(body: unknown): body is StreamBody;
5
+ /** A write the caller sized: a stream, and its exact length. */
6
+ export type SizedBody = {
7
+ body: StreamBody;
8
+ size: number;
9
+ };
10
+ /** A write that is not sized: the body goes the way it always did. */
11
+ export type PlainBody = {
12
+ body: PutBody;
13
+ size?: undefined;
14
+ };
15
+ /**
16
+ * Sorts a write into sized or plain, and refuses a `size` that is not a whole
17
+ * number of bytes, 0 or more, or that comes with a body which is not a stream
18
+ * (a string, bytes or a `Blob` know their own length), and an `AsyncIterable`
19
+ * that comes without one. Before anything is sent.
20
+ */
21
+ export declare function classify(key: string, body: PutBody | StreamBody, size: unknown, where: string): SizedBody | PlainBody;
22
+ /** Refuses a declared `size` above the bucket's `maxSize`, before any read. */
23
+ export declare function checkDeclaredSize<P>(context: BucketContext<P>, key: string, size: number, where: string): void;
24
+ //# sourceMappingURL=sized-body.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sized-body.d.ts","sourceRoot":"","sources":["../../../src/bucket/operations/sized-body.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEpD,qEAAqE;AACrE,wBAAgB,YAAY,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,UAAU,CAQ9D;AAED,gEAAgE;AAChE,MAAM,MAAM,SAAS,GAAG;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAC3D,sEAAsE;AACtE,MAAM,MAAM,SAAS,GAAG;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,IAAI,CAAC,EAAE,SAAS,CAAA;CAAE,CAAC;AAE5D;;;;;GAKG;AACH,wBAAgB,QAAQ,CACvB,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,OAAO,GAAG,UAAU,EAC1B,IAAI,EAAE,OAAO,EACb,KAAK,EAAE,MAAM,GACX,SAAS,GAAG,SAAS,CA8BvB;AAED,+EAA+E;AAC/E,wBAAgB,iBAAiB,CAAC,CAAC,EAClC,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,EACzB,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,GACX,IAAI,CAUN"}
@@ -0,0 +1,4 @@
1
+ import { type BucketContext } from '../context.js';
2
+ import type { ByteRange, CallOptions } from '../types.js';
3
+ export declare function sliceObject<P>(context: BucketContext<P>, params: P, range: ByteRange, options?: CallOptions): Promise<ReadableStream<Uint8Array> | undefined>;
4
+ //# sourceMappingURL=slice.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slice.d.ts","sourceRoot":"","sources":["../../../src/bucket/operations/slice.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,aAAa,EAAiB,MAAM,YAAY,CAAC;AAE/D,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAuEvD,wBAAsB,WAAW,CAAC,CAAC,EAClC,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,EACzB,MAAM,EAAE,CAAC,EACT,KAAK,EAAE,SAAS,EAChB,OAAO,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,cAAc,CAAC,UAAU,CAAC,GAAG,SAAS,CAAC,CAcjD"}
@@ -0,0 +1,10 @@
1
+ import { type BucketContext } from '../context.js';
2
+ import type { CallOptions, PutBody, PutOptions, StreamBody, StreamOptions } from '../types.js';
3
+ /**
4
+ * Writes it, once the bucket's content type and size have accepted it. Both
5
+ * guards run before `write` is called, so a refused body is never sent.
6
+ */
7
+ export declare function putObject<P>(context: BucketContext<P>, params: P, body: PutBody | StreamBody, options?: PutOptions & CallOptions & StreamOptions): Promise<void>;
8
+ /** Removes it. S3 does not say whether anything was there, and nor does this. */
9
+ export declare function deleteObject<P>(context: BucketContext<P>, params: P, options?: CallOptions): Promise<void>;
10
+ //# sourceMappingURL=writes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"writes.d.ts","sourceRoot":"","sources":["../../../src/bucket/operations/writes.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,aAAa,EAAiB,MAAM,YAAY,CAAC;AAE/D,OAAO,KAAK,EACX,WAAW,EACX,OAAO,EACP,UAAU,EACV,UAAU,EACV,aAAa,EACb,MAAM,UAAU,CAAC;AAOlB;;;GAGG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAChC,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,EACzB,MAAM,EAAE,CAAC,EACT,IAAI,EAAE,OAAO,GAAG,UAAU,EAC1B,OAAO,GAAE,UAAU,GAAG,WAAW,GAAG,aAAkB,GACpD,OAAO,CAAC,IAAI,CAAC,CAgDf;AAmID,iFAAiF;AACjF,wBAAsB,YAAY,CAAC,CAAC,EACnC,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,EACzB,MAAM,EAAE,CAAC,EACT,OAAO,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,IAAI,CAAC,CAUf"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * A value's shape, for a message: an option can come off a request body,
3
+ * and a message reports what it was, never what it held.
4
+ */
5
+ export declare function shapeOf(value: unknown): string;
6
+ //# sourceMappingURL=shape.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shape.d.ts","sourceRoot":"","sources":["../../src/bucket/shape.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAc9C"}
@@ -0,0 +1,164 @@
1
+ /**
2
+ * One bucket: which one it is, how an object's key is built from the things
3
+ * that identify it, and what this application is willing to put in it.
4
+ *
5
+ * The key is a **function**, not a template, so nothing is spelled by hand at
6
+ * a call site and a renamed parameter is a compile error.
7
+ */
8
+ export interface BucketDefinition<P> {
9
+ /** The bucket's name on the service. */
10
+ readonly bucket: string;
11
+ /** The object's key, from whatever identifies it. */
12
+ readonly key: (params: P) => string;
13
+ /**
14
+ * The way back from `key`: the parameters a stored key was built from, or
15
+ * `undefined` when the key is not one this bucket's `key` builds. Left out,
16
+ * the bound bucket's `parseKey` refuses to answer. Write it as the inverse
17
+ * of `key`, next to it; the bound `parseKey` also checks that
18
+ * `key(parseKey(k)) === k`, so a parser that drifts answers `undefined`.
19
+ *
20
+ * A throw inside this function propagates to the caller of the bound
21
+ * `parseKey`; return `undefined` for a key that is not yours. When `P`
22
+ * itself includes `undefined`, a miss and a valid key cannot be told apart.
23
+ */
24
+ readonly parseKey?: ((key: string) => P | undefined) | undefined;
25
+ /**
26
+ * The content types this bucket accepts. A write of anything else is
27
+ * refused **before it is sent**. Left out, anything goes.
28
+ */
29
+ readonly contentType?: string | readonly string[] | undefined;
30
+ /**
31
+ * The biggest body this bucket accepts, in bytes, refused before it is
32
+ * sent. Left out, anything goes — see the Traps about bodies whose size
33
+ * cannot be known in advance.
34
+ */
35
+ readonly maxSize?: number;
36
+ }
37
+ /** What a listing says about one object. */
38
+ export interface StoredObject {
39
+ key: string;
40
+ /** Bytes, or `undefined` when the service did not say. */
41
+ size: number | undefined;
42
+ lastModified: Date | undefined;
43
+ eTag: string | undefined;
44
+ }
45
+ /**
46
+ * One page of a listing. The same shape as the `CursorPage` of
47
+ * `@softistx/drizzle` and `@softistx/mongo`, so a caller pages the same way here —
48
+ * S3's `continuationToken` is what `nextCursor` carries.
49
+ */
50
+ export interface ObjectPage {
51
+ items: StoredObject[];
52
+ /** Pass it as `cursor` for the next page; `null` on the last one. */
53
+ nextCursor: string | null;
54
+ }
55
+ /** What a definition's `key` takes, so a caller can write its own helper. */
56
+ export type ParamsOf<D> = D extends BucketDefinition<infer P> ? P : never;
57
+ import type { S3Client, S3Options } from 'bun';
58
+ /**
59
+ * Everything Bun's own `write` takes — a string, bytes, a `Blob`, a stream, a
60
+ * `Response`. A bucket with a `maxSize` refuses the ones whose size cannot be
61
+ * known before sending; one without accepts them all.
62
+ */
63
+ export type PutBody = Parameters<S3Client['write']>[1];
64
+ /**
65
+ * What a single write may say about **the object it stores**.
66
+ *
67
+ * Picked out of Bun's own `S3Options` rather than written again here, so a
68
+ * Bun release that changes one of these is a compile error instead of a
69
+ * silent drift.
70
+ *
71
+ * Only what describes the object is here. The credentials, the endpoint, the
72
+ * bucket and the region belong to the bound bucket — naming them per write
73
+ * would let one call store the object somewhere the definition never
74
+ * described. `partSize`, `queueSize` and `retry` are not here either:
75
+ * measured on bun 1.4.2 against a 12 MiB body, a `put` with `partSize` set
76
+ * and one without produce the **same** ETag, with no `-<parts>` suffix — so
77
+ * a single PUT either way, and offering them would promise a multipart
78
+ * upload this package does not do. `bindBucket` still takes them, where they
79
+ * are the client's own.
80
+ *
81
+ * `type` is the one the guards read — see `effectiveType`. The rest reach
82
+ * the service untouched.
83
+ */
84
+ export type PutOptions = Pick<S3Options, 'type' | 'acl' | 'storageClass' | 'contentDisposition' | 'contentEncoding'>;
85
+ /**
86
+ * What a call that waits on the service may say: how long it waits.
87
+ * `undefined` takes the bound bucket's own `timeoutMs`, if it has one, and
88
+ * otherwise Bun's limit, which is 360 s.
89
+ */
90
+ export interface CallOptions {
91
+ /**
92
+ * Whole milliseconds, 1 or more. No answer by then rejects with an
93
+ * `S3Error` coded `TIMEOUT`, and the request is aborted.
94
+ */
95
+ timeoutMs?: number | undefined;
96
+ }
97
+ /**
98
+ * What a streamed `put` adds: the stream's length. With `size`, the body is a
99
+ * `ReadableStream` or an `AsyncIterable` of bytes and goes out as it is read,
100
+ * never held whole; `size` is checked against the bucket's `maxSize` before
101
+ * anything is sent, and against the bytes actually sent.
102
+ */
103
+ export interface StreamOptions {
104
+ /** The exact number of bytes the stream will give: a whole number, 0 or more. */
105
+ size?: number | undefined;
106
+ }
107
+ /** A body `put` streams when it is given a `size`. */
108
+ export type StreamBody = ReadableStream<Uint8Array> | AsyncIterable<Uint8Array>;
109
+ /**
110
+ * A byte range of an object, **end exclusive** like `Blob.slice`: `start`
111
+ * is the first byte read and `end` the first byte not read, so
112
+ * `{ start: 100, end: 200 }` is 100 bytes. Both are whole numbers, `start`
113
+ * from 0 and `end` at or above `start`.
114
+ */
115
+ export interface ByteRange {
116
+ start: number;
117
+ end: number;
118
+ }
119
+ /**
120
+ * One byte range for `open`: `{ start, end }` is bytes `[start, end)` (`end`
121
+ * exclusive, like `slice`), `{ start }` runs to the end of the object, and
122
+ * `{ suffix }` is the last `suffix` bytes.
123
+ */
124
+ export type OpenRange = {
125
+ start: number;
126
+ end?: number | undefined;
127
+ suffix?: never;
128
+ } | {
129
+ suffix: number;
130
+ start?: never;
131
+ end?: never;
132
+ };
133
+ export type OpenOptions = CallOptions & {
134
+ range?: OpenRange | undefined;
135
+ };
136
+ /**
137
+ * What `open` hands back once the service has answered with its headers.
138
+ * The bytes are the ones stored: a `contentEncoding` of `gzip` is not undone.
139
+ */
140
+ export interface OpenedObject {
141
+ /** The body, streamed. Cancelling it aborts the request. */
142
+ stream: ReadableStream<Uint8Array>;
143
+ /**
144
+ * The whole object's size in bytes, even when a range was asked;
145
+ * `undefined` when the service did not say.
146
+ */
147
+ size: number | undefined;
148
+ /**
149
+ * The bytes this stream carries: `size`, or the range's length;
150
+ * `undefined` when the service did not say.
151
+ */
152
+ contentLength: number | undefined;
153
+ contentType: string | undefined;
154
+ /** `Content-Encoding` as stored, such as `gzip`. */
155
+ contentEncoding: string | undefined;
156
+ contentDisposition: string | undefined;
157
+ cacheControl: string | undefined;
158
+ /** The ETag, quoted, as the service sent it. */
159
+ eTag: string | undefined;
160
+ lastModified: Date | undefined;
161
+ /** `bytes 0-9/100` when a range was asked, else `undefined`. */
162
+ contentRange: string | undefined;
163
+ }
164
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/bucket/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,WAAW,gBAAgB,CAAC,CAAC;IAClC,wCAAwC;IACxC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,qDAAqD;IACrD,QAAQ,CAAC,GAAG,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,MAAM,CAAC;IACpC;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAA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0 +1,118 @@
1
+ // src/bucket/context.ts
2
+ var secrets = new WeakMap;
3
+ function secretOf(context) {
4
+ return secrets.get(context);
5
+ }
6
+ function acceptedTypes(contentType) {
7
+ if (contentType === undefined)
8
+ return;
9
+ return typeof contentType === "string" ? [contentType] : contentType;
10
+ }
11
+ function bucketContext(client, definition, secretAccessKey, timeoutMs, presignClient = client) {
12
+ const context = {
13
+ client,
14
+ presignClient,
15
+ definition,
16
+ accepted: acceptedTypes(definition.contentType),
17
+ timeoutMs
18
+ };
19
+ const secret = secretAccessKey || Bun.env["S3_SECRET_ACCESS_KEY"] || Bun.env["AWS_SECRET_ACCESS_KEY"];
20
+ if (secret)
21
+ secrets.set(context, secret);
22
+ return context;
23
+ }
24
+ function callOf(context, call) {
25
+ return `${call} on "${context.definition.bucket}"`;
26
+ }
27
+ function keyOf(context, params) {
28
+ return context.definition.key(params);
29
+ }
30
+ function parseKeyOf(context, key) {
31
+ const { definition } = context;
32
+ if (definition.parseKey === undefined) {
33
+ throw new TypeError(`parseKey on "${definition.bucket}": the definition has no ` + "`parseKey`; add one next to `key`");
34
+ }
35
+ const params = definition.parseKey(key);
36
+ if (params === undefined)
37
+ return;
38
+ try {
39
+ return definition.key(params) === key ? params : undefined;
40
+ } catch {
41
+ return;
42
+ }
43
+ }
44
+
45
+ // src/errors/s3-error.ts
46
+ class S3Error2 extends Error {
47
+ code;
48
+ key;
49
+ constructor(code, key, message, options) {
50
+ super(message, options?.cause === undefined ? undefined : { cause: options.cause });
51
+ if (options?.objectSize !== undefined)
52
+ this.objectSize = options.objectSize;
53
+ this.name = "S3Error";
54
+ this.code = code;
55
+ this.key = key;
56
+ }
57
+ }
58
+
59
+ // src/bucket/shape.ts
60
+ function shapeOf(value) {
61
+ if (value === null)
62
+ return "null";
63
+ if (value === undefined)
64
+ return "undefined";
65
+ if (Array.isArray(value))
66
+ return "an array";
67
+ if (typeof value === "number") {
68
+ if (Number.isNaN(value))
69
+ return "NaN";
70
+ if (!Number.isFinite(value))
71
+ return "an infinite number";
72
+ if (!Number.isInteger(value))
73
+ return "a fraction";
74
+ if (value === 0)
75
+ return "zero";
76
+ if (value < 0)
77
+ return "a negative number";
78
+ return Number.isSafeInteger(value) ? "a number" : "a number too large";
79
+ }
80
+ if (value === "")
81
+ return "an empty string";
82
+ return typeof value === "object" ? "an object" : `a ${typeof value}`;
83
+ }
84
+
85
+ // src/bucket/operations/deadline.ts
86
+ function isWholeMs(value) {
87
+ return typeof value === "number" && Number.isSafeInteger(value) && value >= 1;
88
+ }
89
+ function checkTimeout(key, value, where) {
90
+ if (value === undefined)
91
+ return;
92
+ if (!isWholeMs(value)) {
93
+ throw new S3Error2("WRONG_OPTION", key, `timeoutMs is a whole number of milliseconds, 1 or more; got ` + `${shapeOf(value)} (${where})`);
94
+ }
95
+ return value;
96
+ }
97
+ function deadlineOf(context, key, call, options) {
98
+ const own = checkTimeout(key, options?.timeoutMs, callOf(context, call));
99
+ return own ?? context.timeoutMs;
100
+ }
101
+ async function withDeadline(context, key, call, timeoutMs, run) {
102
+ const controller = new AbortController;
103
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
104
+ try {
105
+ return await run(controller.signal);
106
+ } catch (reason) {
107
+ if (!controller.signal.aborted)
108
+ throw reason;
109
+ throw new S3Error2("TIMEOUT", key, `${callOf(context, call)}: no answer in ${timeoutMs}ms`);
110
+ } finally {
111
+ clearTimeout(timer);
112
+ }
113
+ }
114
+
115
+ export { secretOf, bucketContext, callOf, keyOf, parseKeyOf, S3Error2, shapeOf, isWholeMs, checkTimeout, deadlineOf, withDeadline };
116
+
117
+ //# debugId=783AF73898E6E5BE64756E2164756E21
118
+ //# sourceMappingURL=index-jgjey570.js.map
@@ -0,0 +1,13 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/bucket/context.ts", "../src/errors/s3-error.ts", "../src/bucket/shape.ts", "../src/bucket/operations/deadline.ts"],
4
+ "sourcesContent": [
5
+ "import type { S3Client } from 'bun';\nimport type { BucketDefinition } from './types';\n\n/**\n * What every operation of a bound bucket works from, resolved once: the\n * client, the definition, and the accepted content types as a list.\n *\n * It holds **data only**. The operations are plain functions that take it as\n * their first argument, in `guards.ts` and `operations/` — a context of\n * closures would only be the factory this package split up, one size down.\n *\n * It holds no secret either: see `secretOf`.\n */\nexport interface BucketContext<P> {\n\treadonly client: S3Client;\n\t/**\n\t * The client that signs presigned URLs and POST forms: `client` itself,\n\t * or one for the bucket's `publicEndpoint` when it has one.\n\t */\n\treadonly presignClient: S3Client;\n\treadonly definition: BucketDefinition<P>;\n\t/**\n\t * The types the definition accepts, always as a list, **as written** —\n\t * an error message quotes these, and the comparison normalises them.\n\t * `undefined` when the bucket accepts anything.\n\t */\n\treadonly accepted: readonly string[] | undefined;\n\t/** The bucket's default deadline in ms, checked at bind time. */\n\treadonly timeoutMs: number | undefined;\n}\n\n/**\n * The secret a presigned POST signs its policy with, per context.\n *\n * Bun's client keeps its own and never hands it back — measured, neither\n * `Bun.inspect` nor `JSON.stringify` of an `S3Client` shows it — and a POST\n * policy is the one signature Bun does not make. So it is kept here, beside\n * the context rather than on it: a field on the context is printed by\n * `Bun.inspect(context)` and `JSON.stringify(context)` alike, which is\n * exactly how a secret reaches a log.\n */\nconst secrets = new WeakMap<object, string>();\n\n/** The secret this context signs with, or `undefined` when there is none. */\nexport function secretOf<P>(context: BucketContext<P>): string | undefined {\n\treturn secrets.get(context);\n}\n\n/** The types a definition accepts, as a list. */\nfunction acceptedTypes(\n\tcontentType: string | readonly string[] | undefined,\n): readonly string[] | undefined {\n\tif (contentType === undefined) return undefined;\n\treturn typeof contentType === 'string' ? [contentType] : contentType;\n}\n\n/**\n * The context of a bound bucket. The secret is resolved in the order Bun\n * documents — the option, then `S3_SECRET_ACCESS_KEY`, then\n * `AWS_SECRET_ACCESS_KEY` — but from the environment **as it is now**, while\n * Bun uses it as it was when the process started. The two can differ, which\n * is why `signerOf` checks this secret against Bun's own signature before\n * signing anything with it.\n */\nexport function bucketContext<P>(\n\tclient: S3Client,\n\tdefinition: BucketDefinition<P>,\n\tsecretAccessKey?: string,\n\ttimeoutMs?: number,\n\tpresignClient: S3Client = client,\n): BucketContext<P> {\n\tconst context: BucketContext<P> = {\n\t\tclient,\n\t\tpresignClient,\n\t\tdefinition,\n\t\taccepted: acceptedTypes(definition.contentType),\n\t\ttimeoutMs,\n\t};\n\tconst secret =\n\t\tsecretAccessKey ||\n\t\tBun.env['S3_SECRET_ACCESS_KEY'] ||\n\t\tBun.env['AWS_SECRET_ACCESS_KEY'];\n\tif (secret) secrets.set(context, secret);\n\treturn context;\n}\n\n/**\n * `put on \"avatars\"`: the call a consumer wrote and the bucket it was on,\n * which every refusal names — a log line holding one says which of an\n * application's buckets, and which of its calls, produced it.\n */\nexport function callOf<P>(context: BucketContext<P>, call: string): string {\n\treturn `${call} on \"${context.definition.bucket}\"`;\n}\n\n/** The key this definition builds for these parameters. */\nexport function keyOf<P>(context: BucketContext<P>, params: P): string {\n\treturn context.definition.key(params);\n}\n\n/**\n * The parameters this definition built `key` from, or `undefined` when it did\n * not build it. A parse that does not rebuild the same key is a miss, so a\n * parser that drifted from `key` cannot hand out a key it would not produce.\n */\nexport function parseKeyOf<P>(\n\tcontext: BucketContext<P>,\n\tkey: string,\n): P | undefined {\n\tconst { definition } = context;\n\tif (definition.parseKey === undefined) {\n\t\tthrow new TypeError(\n\t\t\t`parseKey on \"${definition.bucket}\": the definition has no ` +\n\t\t\t\t'`parseKey`; add one next to `key`',\n\t\t);\n\t}\n\tconst params = definition.parseKey(key);\n\tif (params === undefined) return undefined;\n\ttry {\n\t\treturn definition.key(params) === key ? params : undefined;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n",
6
+ "/**\n * What went wrong. Each one is in the README's Errors table, and each\n * message it carries has an entry in `docs/troubleshooting.md`, headed by its\n * text.\n */\nexport type S3ErrorCode =\n\t/**\n\t * The content type is not one this bucket accepts, or none was named where\n\t * the bucket names some — on `put` and on `presignPost`, which also\n\t * refuses a `{ startsWith }` prefix on a bucket that names its types.\n\t */\n\t| 'WRONG_TYPE'\n\t/** The body is bigger than this bucket's `maxSize`. */\n\t| 'TOO_LARGE'\n\t/** The body's size cannot be known before sending, and `maxSize` is set. */\n\t| 'UNMEASURABLE'\n\t/**\n\t * An option's own value is not one the service accepts: `acl` or\n\t * `storageClass` on a write; `acl` or `expiresIn` on `presignGet`,\n\t * `presignPut` and `presignPost`; and on `presignPost`, a `maxSize` or\n\t * `minSize` that is not a whole number of bytes, a `maxSize` above the\n\t * bucket's own or missing on a bucket without one, a `minSize` above the\n\t * `maxSize`, or a `type` that is neither a string nor `{ startsWith }`; and a\n\t * `timeoutMs` that is not a whole number of milliseconds, 1 or more.\n\t */\n\t| 'WRONG_OPTION'\n\t/**\n\t * A streamed `put` sent a different number of bytes than the `size` it\n\t * declared, short or long. The upload was aborted, so no object is stored.\n\t * Raised after the request went out, like `TIMEOUT`.\n\t */\n\t| 'SIZE_MISMATCH'\n\t/**\n\t * The source of a streamed `put` failed or misbehaved after the upload\n\t * started: it threw (a client that disconnected, a file that vanished) or\n\t * gave a chunk that is not bytes. The upload was aborted, nothing is stored,\n\t * and the source's own error is the `cause`. Raised after the request went\n\t * out, like `TIMEOUT`.\n\t */\n\t| 'SOURCE_FAILED'\n\t/**\n\t * A call that names `timeoutMs` (or a bucket bound with one) got no answer\n\t * in time, and its request was aborted. One of the codes raised **after**\n\t * something was sent: the service may still have acted on it.\n\t */\n\t| 'TIMEOUT'\n\t/**\n\t * `open` was given a byte range that starts at or past the end of the\n\t * object (or any range of an empty one): the service answers 416. The\n\t * error's `objectSize` is the object's size in bytes when the service said\n\t * it. Also raised for a `{ suffix }` range when the service ignored `Range` and\n\t * sent no `Content-Length` (no `objectSize`). Raised from the service's answer, so after a request was sent; it is a\n\t * read, so nothing was changed.\n\t */\n\t| 'RANGE_NOT_SATISFIABLE';\n\n/**\n * This package's error class for refusals, and every one of them is thrown\n * **before** anything is sent, except `TIMEOUT`, `SIZE_MISMATCH`, `SOURCE_FAILED`\n * and `RANGE_NOT_SATISFIABLE`, the codes raised after a request went out (the\n * last is the service's own answer to a read, which changed nothing). The\n * package also throws a `TypeError` for a\n * bucket definition that could never work, a `bindBucket` `timeoutMs` default\n * that is not whole milliseconds, or a `presignPost` secret that is not Bun's, and a plain `Error` when the URL Bun signed cannot be read. S3's\n * own failures come back as they are, from Bun's client.\n */\nexport class S3Error extends Error {\n\treadonly code: S3ErrorCode;\n\t/** The object key it was about — the bucket and the key, never the body. */\n\treadonly key: string;\n\t/**\n\t * Only on `RANGE_NOT_SATISFIABLE`, and only when the service said it: the\n\t * object's size in bytes. Absent on every other error.\n\t */\n\tdeclare readonly objectSize?: number;\n\n\tconstructor(\n\t\tcode: S3ErrorCode,\n\t\tkey: string,\n\t\tmessage: string,\n\t\toptions?: { cause?: unknown; objectSize?: number },\n\t) {\n\t\tsuper(\n\t\t\tmessage,\n\t\t\toptions?.cause === undefined ? undefined : { cause: options.cause },\n\t\t);\n\t\tif (options?.objectSize !== undefined) this.objectSize = options.objectSize;\n\t\tthis.name = 'S3Error';\n\t\tthis.code = code;\n\t\tthis.key = key;\n\t}\n}\n",
7
+ "/**\n * A value's shape, for a message: an option can come off a request body,\n * and a message reports what it was, never what it held.\n */\nexport function shapeOf(value: unknown): string {\n\tif (value === null) return 'null';\n\tif (value === undefined) return 'undefined';\n\tif (Array.isArray(value)) return 'an array';\n\tif (typeof value === 'number') {\n\t\tif (Number.isNaN(value)) return 'NaN';\n\t\tif (!Number.isFinite(value)) return 'an infinite number';\n\t\tif (!Number.isInteger(value)) return 'a fraction';\n\t\tif (value === 0) return 'zero';\n\t\tif (value < 0) return 'a negative number';\n\t\treturn Number.isSafeInteger(value) ? 'a number' : 'a number too large';\n\t}\n\tif (value === '') return 'an empty string';\n\treturn typeof value === 'object' ? 'an object' : `a ${typeof value}`;\n}\n",
8
+ "import { S3Error } from '../../errors/s3-error';\nimport { type BucketContext, callOf } from '../context';\nimport { shapeOf } from '../shape';\nimport type { CallOptions } from '../types';\n\n/** A whole number of milliseconds, 1 or more. */\nexport function isWholeMs(value: unknown): value is number {\n\treturn typeof value === 'number' && Number.isSafeInteger(value) && value >= 1;\n}\n\n/**\n * Refuses a `timeoutMs` that is not a whole number of milliseconds, 1 or\n * more. Reports the value by its shape, never quoted. Before anything is sent.\n */\nexport function checkTimeout(\n\tkey: string,\n\tvalue: unknown,\n\twhere: string,\n): number | undefined {\n\tif (value === undefined) return undefined;\n\tif (!isWholeMs(value)) {\n\t\tthrow new S3Error(\n\t\t\t'WRONG_OPTION',\n\t\t\tkey,\n\t\t\t`timeoutMs is a whole number of milliseconds, 1 or more; got ` +\n\t\t\t\t`${shapeOf(value)} (${where})`,\n\t\t);\n\t}\n\treturn value;\n}\n\n/**\n * The deadline that applies to a call: its own `timeoutMs` first, then the\n * bucket's, else `undefined` — and the call goes the way it always did.\n */\nexport function deadlineOf<P>(\n\tcontext: BucketContext<P>,\n\tkey: string,\n\tcall: string,\n\toptions: CallOptions | undefined,\n): number | undefined {\n\tconst own = checkTimeout(key, options?.timeoutMs, callOf(context, call));\n\treturn own ?? context.timeoutMs;\n}\n\n/**\n * Runs `run` with a signal that aborts after `timeoutMs`, and turns that\n * abort into `S3Error` `TIMEOUT`. The timer is cleared whichever way it\n * ends, so none outlives the call.\n */\nexport async function withDeadline<P, T>(\n\tcontext: BucketContext<P>,\n\tkey: string,\n\tcall: string,\n\ttimeoutMs: number,\n\trun: (signal: AbortSignal) => Promise<T>,\n): Promise<T> {\n\tconst controller = new AbortController();\n\tconst timer = setTimeout(() => controller.abort(), timeoutMs);\n\ttry {\n\t\treturn await run(controller.signal);\n\t} catch (reason) {\n\t\tif (!controller.signal.aborted) throw reason;\n\t\tthrow new S3Error(\n\t\t\t'TIMEOUT',\n\t\t\tkey,\n\t\t\t`${callOf(context, call)}: no answer in ${timeoutMs}ms`,\n\t\t);\n\t} finally {\n\t\tclearTimeout(timer);\n\t}\n}\n"
9
+ ],
10
+ "mappings": ";AAyCA,IAAM,UAAU,IAA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AI,CAAC;AAAA,EACvE,OAAO,OAAO,QAAQ;AAAA;AAQhB,eAAe,YAAkB,CACvC,SACA,KACA,MACA,WACA,KACa;AAAA,EACb,MAAM,aAAa,IAAI;AAAA,EACvB,MAAM,QAAQ,WAAW,MAAM,WAAW,MAAM,GAAG,SAAS;AAAA,EAC5D,IAAI;AAAA,IACH,OAAO,MAAM,IAAI,WAAW,MAAM;AAAA,IACjC,OAAO,QAAQ;AAAA,IAChB,IAAI,CAAC,WAAW,OAAO;AAAA,MAAS,MAAM;AAAA,IACtC,MAAM,IAAI,SACT,WACA,KACA,GAAG,OAAO,SAAS,IAAI,mBAAmB,aAC3C;AAAA,IACC,QAAQ;AAAA,IACT,aAAa,KAAK;AAAA;AAAA;",
11
+ "debugId": "783AF73898E6E5BE64756E2164756E21",
12
+ "names": []
13
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Whether a failure means the bucket is unavailable, so a route can answer
3
+ * 503. Reads the `code` of an `Error` only, never its name or message.
4
+ *
5
+ * `true` for: this package's `S3Error` with code `TIMEOUT`; a Bun or Node
6
+ * network code (`ConnectionRefused`, `ECONNREFUSED`, `ETIMEDOUT`, …); and an
7
+ * S3 service code meaning the deployment cannot use the bucket
8
+ * (`AccessDenied`, `InvalidAccessKeyId`, `SignatureDoesNotMatch`,
9
+ * `NoSuchBucket`, `ExpiredToken`, `InternalError`, `ServiceUnavailable`,
10
+ * `SlowDown`).
11
+ *
12
+ * `false` for this package's refusals of the caller's input (`WRONG_TYPE`,
13
+ * `TOO_LARGE`, `UNMEASURABLE`, `WRONG_OPTION`), which stay the caller's
14
+ * (4xx); for per-request codes such as `NoSuchKey`; and for anything that is
15
+ * not an `Error` with a string `code`.
16
+ */
17
+ export declare function isBucketUnavailable(error: unknown): boolean;
18
+ //# sourceMappingURL=is-bucket-unavailable.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-bucket-unavailable.d.ts","sourceRoot":"","sources":["../../src/errors/is-bucket-unavailable.ts"],"names":[],"mappings":"AAkCA;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAI3D"}