@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,42 @@
1
+ import { type S3Options } from 'bun';
2
+ import type { BoundBucket } from './bound-bucket.js';
3
+ import { type PresignGetOptions, type PresignOptions } from './operations/presign.js';
4
+ import { type PresignedPost, type PresignPostOptions } from './operations/presign-post.js';
5
+ import type { BucketDefinition, CallOptions } from './types.js';
6
+ /**
7
+ * Bun's own `S3Options` without `bucket`, plus the bucket's default
8
+ * `timeoutMs` for `put`, `bytes`, `slice`, `text`, `exists`, `stat`, `delete` and
9
+ * `list`. A call's own `timeoutMs` wins. It never reaches the `S3Client`.
10
+ * It bounds a whole `put`, an upload included: give a large one its own.
11
+ */
12
+ export type BindOptions = Omit<S3Options, 'bucket'> & CallOptions & {
13
+ /**
14
+ * The origin browsers reach the service at, when it is not `endpoint`
15
+ * (`https://media.example.com` in front of `http://minio:9000`).
16
+ * `presignGet`, `presignPut` and `presignPost` are signed for it; every
17
+ * other call goes to `endpoint`, so the server does not hairpin through
18
+ * the proxy. Left out, everything uses `endpoint`. It never reaches the
19
+ * `S3Client`. Anything that is not an absolute URL is a `TypeError`.
20
+ */
21
+ publicEndpoint?: string | undefined;
22
+ };
23
+ export type { BoundBucket, PresignedPost, PresignGetOptions, PresignOptions, PresignPostOptions, };
24
+ /**
25
+ * Binds a bucket definition to credentials.
26
+ *
27
+ * ```ts
28
+ * const store = bindBucket(avatars, {
29
+ * endpoint: process.env.S3_ENDPOINT,
30
+ * accessKeyId: process.env.S3_KEY,
31
+ * secretAccessKey: process.env.S3_SECRET,
32
+ * });
33
+ * await store.put({ userId: 'u1' }, png, { type: 'image/png' });
34
+ * ```
35
+ *
36
+ * Given no options, Bun reads its own `S3_*` / `AWS_*` environment variables.
37
+ *
38
+ * Each bound bucket holds an `S3Client` of its own. S3 is stateless HTTP —
39
+ * there is no connection to share, and nothing to close.
40
+ */
41
+ export declare function bindBucket<P>(definition: BucketDefinition<P>, options?: BindOptions): BoundBucket<P>;
42
+ //# sourceMappingURL=bind-bucket.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bind-bucket.d.ts","sourceRoot":"","sources":["../../src/bucket/bind-bucket.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,SAAS,EAAE,MAAM,KAAK,CAAC;AAC/C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAKlD,OAAO,EACN,KAAK,iBAAiB,EACtB,KAAK,cAAc,EAGnB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACN,KAAK,aAAa,EAClB,KAAK,kBAAkB,EAEvB,MAAM,2BAA2B,CAAC;AAUnC,OAAO,KAAK,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE7D;;;;;GAKG;AACH,MAAM,MAAM,WAAW,GAAG,IAAI,CAAC,SAAS,EAAE,QAAQ,CAAC,GAClD,WAAW,GAAG;IACb;;;;;;;OAOG;IACH,cAAc,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACpC,CAAC;AAEH,YAAY,EACX,WAAW,EACX,aAAa,EACb,iBAAiB,EACjB,cAAc,EACd,kBAAkB,GAClB,CAAC;AAKF;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAC3B,UAAU,EAAE,gBAAgB,CAAC,CAAC,CAAC,EAC/B,OAAO,GAAE,WAAgB,GACvB,WAAW,CAAC,CAAC,CAAC,CA2DhB"}
@@ -0,0 +1,119 @@
1
+ import type { S3Client, S3File, S3Stats } from 'bun';
2
+ import type { PresignGetOptions, PresignOptions } from './operations/presign.js';
3
+ import type { PresignedPost, PresignPostOptions } from './operations/presign-post.js';
4
+ import type { ByteRange, CallOptions, ObjectPage, OpenedObject, OpenOptions, PutBody, PutOptions, StreamBody } from './types.js';
5
+ /** A bucket bound to credentials: the definition, with somewhere to put it. */
6
+ export interface BoundBucket<P> {
7
+ /** The client this holds, for anything this package does not wrap. */
8
+ readonly client: S3Client;
9
+ /** The key this would use, for a caller that needs the string itself. */
10
+ keyFor(params: P): string;
11
+ /**
12
+ * The parameters a stored key was built from, or `undefined` when the key
13
+ * does not belong to this bucket's `key` function (the definition's
14
+ * `parseKey` found no match, or what it found does not rebuild the same
15
+ * key). Throws a `TypeError` when the definition has no `parseKey`, and a
16
+ * throw inside the definition's own `parseKey` propagates. When `P` itself
17
+ * includes `undefined`, a miss and a valid key cannot be told apart.
18
+ */
19
+ parseKey(key: string): P | undefined;
20
+ /** Bun's own lazy handle: `.stream()`, `.slice()`, `.writer()` and the rest. */
21
+ file(params: P): S3File;
22
+ /**
23
+ * Writes it, once the bucket's content type and size have accepted it.
24
+ *
25
+ * Beyond `type`, an option here describes **this object** — how it is
26
+ * served back (`contentDisposition`, `contentEncoding`), who may read it
27
+ * (`acl`), what it costs to keep (`storageClass`) — or how a large body is
28
+ * uploaded (`partSize`, `queueSize`, `retry`).
29
+ *
30
+ * With a deadline (`timeoutMs`, or the bucket's) it goes over `fetch` on a
31
+ * URL Bun signs, so no answer in time aborts the request and rejects with
32
+ * `TIMEOUT`. For a body that is not streamed with a `size`, **the deadline
33
+ * covers the whole upload**, so a large `put` wants its own `timeoutMs`;
34
+ * and a body that is not a string, bytes or a `Blob` of known size (a
35
+ * stream) is **read into memory** first, inside the deadline.
36
+ */
37
+ put(params: P, body: PutBody | ReadableStream<Uint8Array>, options?: PutOptions & CallOptions): Promise<void>;
38
+ /**
39
+ * Streams it, never held in memory; `size` is the exact length. `TOO_LARGE`,
40
+ * `SIZE_MISMATCH` and `SOURCE_FAILED` leave nothing stored.
41
+ *
42
+ * The call's own `timeoutMs` is an **idle** deadline: it bounds each wait
43
+ * (the connection, the source's next chunk, the service taking it, its
44
+ * answer after the last byte) and starts over after each, so a slow transfer
45
+ * that keeps moving is never cut. The bucket's default `timeoutMs` does not
46
+ * apply to a streamed put.
47
+ */
48
+ put(params: P, body: StreamBody, options: PutOptions & CallOptions & {
49
+ size: number;
50
+ }): Promise<void>;
51
+ /** The bytes, or `undefined` when there is no such object. */
52
+ bytes(params: P, options?: CallOptions): Promise<Uint8Array | undefined>;
53
+ /**
54
+ * A stream of exactly bytes `[start, end)` of the object (`end` exclusive,
55
+ * like `Blob.slice`), or `undefined` when there is no such object.
56
+ *
57
+ * An `end` past the object is cut at its end, and a `start` at or past it
58
+ * gives an empty stream, as does `start === end`. A range that is not two
59
+ * whole numbers with `0 <= start <= end` is a `WRONG_OPTION`.
60
+ *
61
+ * With a deadline (`timeoutMs`, or the bucket's) it is a signed `fetch`
62
+ * with an HTTP `Range` header, so a stalled service rejects with `TIMEOUT`;
63
+ * the range is then **read into memory** inside the deadline and the
64
+ * stream replays it. Without one it is Bun's `file.slice(start, end)`.
65
+ */
66
+ slice(params: P, range: ByteRange, options?: CallOptions): Promise<ReadableStream<Uint8Array> | undefined>;
67
+ /**
68
+ * The object as a **stream**, with what the service said about it, or
69
+ * `undefined` when there is no such object. Nothing is buffered: the
70
+ * first chunk arrives as the service sends it.
71
+ *
72
+ * `range` asks for one byte range (`{ start, end? }` with `end` exclusive,
73
+ * or `{ suffix }`); the answer carries `contentRange` and a
74
+ * `contentLength` of the range. A range that starts at or past the end is
75
+ * a `RANGE_NOT_SATISFIABLE` (map it to 416; `error.size` is the size).
76
+ *
77
+ * The deadline (`timeoutMs`, or the bucket's) covers the time until the
78
+ * response **headers** only: the body then streams with none, so a slow
79
+ * reader is never cut off. Cancelling `stream` aborts the request.
80
+ */
81
+ open(params: P, options?: OpenOptions): Promise<OpenedObject | undefined>;
82
+ /** The body as text, or `undefined` when there is no such object. */
83
+ text(params: P, options?: CallOptions): Promise<string | undefined>;
84
+ exists(params: P, options?: CallOptions): Promise<boolean>;
85
+ /** What the service knows about it, or `undefined` when it is not there. */
86
+ stat(params: P, options?: CallOptions): Promise<S3Stats | undefined>;
87
+ /** Removes it. S3 does not say whether anything was there, and nor does this. */
88
+ delete(params: P, options?: CallOptions): Promise<void>;
89
+ /**
90
+ * One page of the bucket, in this repository's cursor shape. `startAfter`
91
+ * lists only the keys after that key (ListObjectsV2 `start-after`), to
92
+ * resume from a key already known; later pages follow by `cursor`.
93
+ */
94
+ list(options?: {
95
+ prefix?: string;
96
+ limit?: number;
97
+ cursor?: string | null;
98
+ startAfter?: string;
99
+ } & CallOptions): Promise<ObjectPage>;
100
+ /**
101
+ * A URL that reads this object, signed (for `publicEndpoint` when bound
102
+ * with one). `contentDisposition` signs the header the download is served
103
+ * with, for a link that saves under a name.
104
+ */
105
+ presignGet(params: P, options?: PresignGetOptions): string;
106
+ /**
107
+ * A URL that writes this object, signed. It constrains the key and the
108
+ * deadline, and **nothing else** — not the size, not the content type.
109
+ */
110
+ presignPut(params: P, options?: PresignOptions): string;
111
+ /**
112
+ * The form a browser posts to upload this object, signed. Unlike
113
+ * `presignPut`, the **service** holds the upload to a size range and a
114
+ * content type — by default the bucket's own `maxSize` and single
115
+ * `contentType`. Post `fields` first and the file last.
116
+ */
117
+ presignPost(params: P, options?: PresignPostOptions): PresignedPost;
118
+ }
119
+ //# sourceMappingURL=bound-bucket.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bound-bucket.d.ts","sourceRoot":"","sources":["../../src/bucket/bound-bucket.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AACrD,OAAO,KAAK,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC9E,OAAO,KAAK,EACX,aAAa,EACb,kBAAkB,EAClB,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EACX,SAAS,EACT,WAAW,EACX,UAAU,EACV,YAAY,EACZ,WAAW,EACX,OAAO,EACP,UAAU,EACV,UAAU,EACV,MAAM,SAAS,CAAC;AAEjB,+EAA+E;AAC/E,MAAM,WAAW,WAAW,CAAC,CAAC;IAC7B,sEAAsE;IACtE,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC;IAC1B,yEAAyE;IACzE,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,MAAM,CAAC;IAC1B;;;;;;;OAOG;IACH,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS,CAAC;IACrC,gFAAgF;IAChF,IAAI,CAAC,MAAM,EAAE,CAAC,GAAG,MAAM,CAAC;IACxB;;;;;;;;;;;;;;OAcG;IACH,GAAG,CACF,MAAM,EAAE,CAAC,EACT,IAAI,EAAE,OAAO,GAAG,cAAc,CAAC,UAAU,CAAC,EAC1C,OAAO,CAAC,EAAE,UAAU,GAAG,WAAW,GAChC,OAAO,CAAC,IAAI,CAAC,CAAC;IACjB;;;;;;;;;OASG;IACH,GAAG,CACF,MAAM,EAAE,CAAC,EACT,IAAI,EAAE,UAAU,EAChB,OAAO,EAAE,UAAU,GAAG,WAAW,GAAG;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAClD,OAAO,CAAC,IAAI,CAAC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AAE,CAAC,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,MAAM,CAAC;IAC3D;;;OAGG;IACH,UAAU,CAAC,MAAM,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,MAAM,CAAC;IACxD;;;;;OAKG;IACH,WAAW,CAAC,MAAM,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,aAAa,CAAC;CACpE"}
@@ -0,0 +1,55 @@
1
+ import type { S3Client } from 'bun';
2
+ import type { BucketDefinition } from './types.js';
3
+ /**
4
+ * What every operation of a bound bucket works from, resolved once: the
5
+ * client, the definition, and the accepted content types as a list.
6
+ *
7
+ * It holds **data only**. The operations are plain functions that take it as
8
+ * their first argument, in `guards.ts` and `operations/` — a context of
9
+ * closures would only be the factory this package split up, one size down.
10
+ *
11
+ * It holds no secret either: see `secretOf`.
12
+ */
13
+ export interface BucketContext<P> {
14
+ readonly client: S3Client;
15
+ /**
16
+ * The client that signs presigned URLs and POST forms: `client` itself,
17
+ * or one for the bucket's `publicEndpoint` when it has one.
18
+ */
19
+ readonly presignClient: S3Client;
20
+ readonly definition: BucketDefinition<P>;
21
+ /**
22
+ * The types the definition accepts, always as a list, **as written** —
23
+ * an error message quotes these, and the comparison normalises them.
24
+ * `undefined` when the bucket accepts anything.
25
+ */
26
+ readonly accepted: readonly string[] | undefined;
27
+ /** The bucket's default deadline in ms, checked at bind time. */
28
+ readonly timeoutMs: number | undefined;
29
+ }
30
+ /** The secret this context signs with, or `undefined` when there is none. */
31
+ export declare function secretOf<P>(context: BucketContext<P>): string | undefined;
32
+ /**
33
+ * The context of a bound bucket. The secret is resolved in the order Bun
34
+ * documents — the option, then `S3_SECRET_ACCESS_KEY`, then
35
+ * `AWS_SECRET_ACCESS_KEY` — but from the environment **as it is now**, while
36
+ * Bun uses it as it was when the process started. The two can differ, which
37
+ * is why `signerOf` checks this secret against Bun's own signature before
38
+ * signing anything with it.
39
+ */
40
+ export declare function bucketContext<P>(client: S3Client, definition: BucketDefinition<P>, secretAccessKey?: string, timeoutMs?: number, presignClient?: S3Client): BucketContext<P>;
41
+ /**
42
+ * `put on "avatars"`: the call a consumer wrote and the bucket it was on,
43
+ * which every refusal names — a log line holding one says which of an
44
+ * application's buckets, and which of its calls, produced it.
45
+ */
46
+ export declare function callOf<P>(context: BucketContext<P>, call: string): string;
47
+ /** The key this definition builds for these parameters. */
48
+ export declare function keyOf<P>(context: BucketContext<P>, params: P): string;
49
+ /**
50
+ * The parameters this definition built `key` from, or `undefined` when it did
51
+ * not build it. A parse that does not rebuild the same key is a miss, so a
52
+ * parser that drifted from `key` cannot hand out a key it would not produce.
53
+ */
54
+ export declare function parseKeyOf<P>(context: BucketContext<P>, key: string): P | undefined;
55
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/bucket/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEhD;;;;;;;;;GASG;AACH,MAAM,WAAW,aAAa,CAAC,CAAC;IAC/B,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC;IAC1B;;;OAGG;IACH,QAAQ,CAAC,aAAa,EAAE,QAAQ,CAAC;IACjC,QAAQ,CAAC,UAAU,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC;IACzC;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,CAAC;IACjD,iEAAiE;IACjE,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;CACvC;AAcD,6EAA6E;AAC7E,wBAAgB,QAAQ,CAAC,CAAC,EAAE,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,MAAM,GAAG,SAAS,CAEzE;AAUD;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAC9B,MAAM,EAAE,QAAQ,EAChB,UAAU,EAAE,gBAAgB,CAAC,CAAC,CAAC,EAC/B,eAAe,CAAC,EAAE,MAAM,EACxB,SAAS,CAAC,EAAE,MAAM,EAClB,aAAa,GAAE,QAAiB,GAC9B,aAAa,CAAC,CAAC,CAAC,CAclB;AAED;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAEzE;AAED,2DAA2D;AAC3D,wBAAgB,KAAK,CAAC,CAAC,EAAE,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,MAAM,CAErE;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAC3B,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,EACzB,GAAG,EAAE,MAAM,GACT,CAAC,GAAG,SAAS,CAef"}
@@ -0,0 +1,16 @@
1
+ import type { BucketDefinition } from './types.js';
2
+ /**
3
+ * Describes a bucket. It talks to nothing: `bindBucket` is what needs
4
+ * credentials.
5
+ *
6
+ * ```ts
7
+ * export const avatars = defineBucket({
8
+ * bucket: 'avatars',
9
+ * key: (p: { userId: string }) => `${p.userId}.png`,
10
+ * contentType: ['image/png', 'image/jpeg'],
11
+ * maxSize: 2 * 1024 * 1024,
12
+ * });
13
+ * ```
14
+ */
15
+ export declare function defineBucket<P>(definition: BucketDefinition<P>): BucketDefinition<P>;
16
+ //# sourceMappingURL=define-bucket.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"define-bucket.d.ts","sourceRoot":"","sources":["../../src/bucket/define-bucket.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEhD;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAC7B,UAAU,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAC7B,gBAAgB,CAAC,CAAC,CAAC,CAsBrB"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Refuses a `contentDisposition` that could not be one header value: a
3
+ * non-empty string of printable ASCII. A line break in it would split the
4
+ * header it ends up in, and RFC 6266 spells a non-ASCII filename as
5
+ * `filename*=UTF-8''...`, percent-encoded, so ASCII loses nothing. The value
6
+ * is reported by its shape, never quoted: it may have come off a request.
7
+ */
8
+ export declare function checkDisposition(key: string, value: unknown, where: string): void;
9
+ //# sourceMappingURL=disposition.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"disposition.d.ts","sourceRoot":"","sources":["../../src/bucket/disposition.ts"],"names":[],"mappings":"AAMA;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC/B,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,OAAO,EACd,KAAK,EAAE,MAAM,GACX,IAAI,CAaN"}
@@ -0,0 +1,38 @@
1
+ import type { BucketContext } from './context.js';
2
+ import type { PutBody } from './types.js';
3
+ /**
4
+ * A content type without its parameters, lower-cased: `text/plain` from
5
+ * `text/plain;charset=utf-8`.
6
+ *
7
+ * Both sides of the comparison go through this, because the type a body
8
+ * carries is rarely the bare one a definition names — `Bun.file('a.json')`
9
+ * reports `application/json;charset=utf-8` (measured on bun 1.4.2), and an
10
+ * explicit `IMAGE/PNG` is the same type as `image/png`.
11
+ */
12
+ export declare function essenceOf(type: string): string;
13
+ /**
14
+ * The type a write would carry: the one the caller named, or the one the
15
+ * body knows about itself. One function, so the type `check` approves and
16
+ * the type `put` sends can never be two different answers.
17
+ */
18
+ export declare function effectiveType(body: unknown, named: string | undefined): string | undefined;
19
+ /** The body's size, or `undefined` when it cannot be known before sending. */
20
+ export declare function sizeOf(body: PutBody): number | undefined;
21
+ /**
22
+ * Refuses a type the bucket does not accept. Shared by `put` and
23
+ * `presignPost`; `where` is `callOf`'s, the call and the bucket. The type
24
+ * itself is never quoted: for a presigned POST it came off a request.
25
+ */
26
+ export declare function checkType<P>(context: BucketContext<P>, key: string, type: string | undefined, where: string): void;
27
+ /** Refuses a body the bucket does not accept, before anything is sent. */
28
+ export declare function checkSize<P>(context: BucketContext<P>, key: string, body: PutBody, where: string): void;
29
+ /**
30
+ * Refuses a value the service does not accept for `acl`, `storageClass`,
31
+ * `expiresIn` or `contentDisposition`.
32
+ * Shared by `put` and the three presigned calls, so the same wrong `acl` is
33
+ * the same error whichever one a caller reached for; `where` is `callOf`'s,
34
+ * the call and the bucket. An option with no fixed set passes. The value is
35
+ * reported by its shape, never quoted.
36
+ */
37
+ export declare function checkOption(key: string, name: string, value: unknown, where: string): void;
38
+ //# sourceMappingURL=guards.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guards.d.ts","sourceRoot":"","sources":["../../src/bucket/guards.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAI/C,OAAO,KAAK,EAAE,OAAO,EAAc,MAAM,SAAS,CAAC;AAEnD;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE9C;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAC5B,IAAI,EAAE,OAAO,EACb,KAAK,EAAE,MAAM,GAAG,SAAS,GACvB,MAAM,GAAG,SAAS,CAGpB;AAED,8EAA8E;AAC9E,wBAAgB,MAAM,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAaxD;AAQD;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAC1B,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,EACzB,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,GAAG,SAAS,EACxB,KAAK,EAAE,MAAM,GACX,IAAI,CAoBN;AAED,0EAA0E;AAC1E,wBAAgB,SAAS,CAAC,CAAC,EAC1B,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,EACzB,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,OAAO,EACb,KAAK,EAAE,MAAM,GACX,IAAI,CAqBN;AA4ED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAC1B,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,OAAO,EACd,KAAK,EAAE,MAAM,GACX,IAAI,CAuBN"}
@@ -0,0 +1,26 @@
1
+ import { S3Error } from '../../errors/s3-error.js';
2
+ import type { StreamBody } from '../types.js';
3
+ /** The stream the transfer reads, and the failure it found, if any. */
4
+ export interface Counted {
5
+ body: ReadableStream<Uint8Array>;
6
+ /** Set once the source ended short, ran long or failed; the transfer is aborted. */
7
+ failure(): S3Error | undefined;
8
+ }
9
+ /**
10
+ * The source as a stream that gives exactly `size` bytes, pulled one chunk at
11
+ * a time (nothing is held beyond the chunk in flight and the one read ahead).
12
+ *
13
+ * The last chunk is held back until the source has been read once more and
14
+ * has said it is done: a source with more to give raises `SIZE_MISMATCH`
15
+ * before that chunk is sent, so a body that is too long is never completed.
16
+ * A source that ends short is `SIZE_MISMATCH` too; one that throws, or gives
17
+ * something that is not bytes, is `SOURCE_FAILED` with its error as `cause`.
18
+ * The source is cancelled on any of them, and when the transfer is.
19
+ *
20
+ * `watch(true)` is called whenever the transfer waits on someone else (the
21
+ * source's next chunk, the service taking a chunk, the service's answer after
22
+ * the last one) and `watch(false)` when that wait is over: the caller's idle
23
+ * deadline.
24
+ */
25
+ export declare function countedStream(source: StreamBody, size: number, key: string, where: string, watch?: (waiting: boolean) => void): Counted;
26
+ //# sourceMappingURL=counted-stream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"counted-stream.d.ts","sourceRoot":"","sources":["../../../src/bucket/operations/counted-stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAEhD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAE3C,uEAAuE;AACvE,MAAM,WAAW,OAAO;IACvB,IAAI,EAAE,cAAc,CAAC,UAAU,CAAC,CAAC;IACjC,oFAAoF;IACpF,OAAO,IAAI,OAAO,GAAG,SAAS,CAAC;CAC/B;AAID;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,aAAa,CAC5B,MAAM,EAAE,UAAU,EAClB,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,EACb,KAAK,GAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAe,GAC1C,OAAO,CA6BT"}
@@ -0,0 +1,21 @@
1
+ import { type BucketContext } from '../context.js';
2
+ import type { CallOptions } from '../types.js';
3
+ /** A whole number of milliseconds, 1 or more. */
4
+ export declare function isWholeMs(value: unknown): value is number;
5
+ /**
6
+ * Refuses a `timeoutMs` that is not a whole number of milliseconds, 1 or
7
+ * more. Reports the value by its shape, never quoted. Before anything is sent.
8
+ */
9
+ export declare function checkTimeout(key: string, value: unknown, where: string): number | undefined;
10
+ /**
11
+ * The deadline that applies to a call: its own `timeoutMs` first, then the
12
+ * bucket's, else `undefined` — and the call goes the way it always did.
13
+ */
14
+ export declare function deadlineOf<P>(context: BucketContext<P>, key: string, call: string, options: CallOptions | undefined): number | undefined;
15
+ /**
16
+ * Runs `run` with a signal that aborts after `timeoutMs`, and turns that
17
+ * abort into `S3Error` `TIMEOUT`. The timer is cleared whichever way it
18
+ * ends, so none outlives the call.
19
+ */
20
+ export declare function withDeadline<P, T>(context: BucketContext<P>, key: string, call: string, timeoutMs: number, run: (signal: AbortSignal) => Promise<T>): Promise<T>;
21
+ //# sourceMappingURL=deadline.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deadline.d.ts","sourceRoot":"","sources":["../../../src/bucket/operations/deadline.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,aAAa,EAAU,MAAM,YAAY,CAAC;AAExD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE5C,iDAAiD;AACjD,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAEzD;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAC3B,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,OAAO,EACd,KAAK,EAAE,MAAM,GACX,MAAM,GAAG,SAAS,CAWpB;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAC3B,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,EACzB,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,WAAW,GAAG,SAAS,GAC9B,MAAM,GAAG,SAAS,CAGpB;AAED;;;;GAIG;AACH,wBAAsB,YAAY,CAAC,CAAC,EAAE,CAAC,EACtC,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,EACzB,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC,GACtC,OAAO,CAAC,CAAC,CAAC,CAeZ"}
@@ -0,0 +1,68 @@
1
+ import type { S3Stats } from 'bun';
2
+ import type { BucketContext } from '../context.js';
3
+ import type { PutOptions } from '../types.js';
4
+ /** What Bun names a failed connection, by what `fetch` calls it. */
5
+ export declare const BUN_CODES: Record<string, string>;
6
+ /** An `Error` named `S3Error`, as Bun throws for a failed S3 request. */
7
+ export declare function s3Error(code: string, key: string, message: string): Error;
8
+ /**
9
+ * What a call adds to the bare verb: a URL already signed (a listing's), or
10
+ * the options Bun must **sign** into the query (a PUT's `acl` and
11
+ * `storageClass`), a body and plain request headers.
12
+ */
13
+ type Request = {
14
+ url?: string;
15
+ signed?: {
16
+ acl?: NonNullable<PutOptions['acl']>;
17
+ storageClass?: NonNullable<PutOptions['storageClass']>;
18
+ };
19
+ body?: BodyInit;
20
+ headers?: Record<string, string>;
21
+ };
22
+ /**
23
+ * What a failed connection or a failed body read becomes. The runtime's
24
+ * errors carry the signed URL in their `path`, so nothing of them is kept:
25
+ * the shape Bun gives the same failure, with the key.
26
+ */
27
+ export declare function readFailure(reason: unknown, key: string): Error;
28
+ export type Exchange = {
29
+ status: number;
30
+ ok: boolean;
31
+ headers: Headers;
32
+ body: Uint8Array;
33
+ };
34
+ /** What Bun throws for a failed request: an `Error` named `S3Error`. */
35
+ export declare function failure(response: Exchange, key: string): Error;
36
+ /** HEAD: the stats Bun gives, or `undefined` when there is no such object. */
37
+ export declare function headObject<P>(context: BucketContext<P>, key: string, signal: AbortSignal): Promise<S3Stats | undefined>;
38
+ /** GET: the bytes, or `undefined` when there is no such object. */
39
+ export declare function getObject<P>(context: BucketContext<P>, key: string, signal: AbortSignal): Promise<Uint8Array | undefined>;
40
+ /**
41
+ * GET with a `Range` header: bytes [start, end) as a plain request header
42
+ * (not signed, which the service accepts). `undefined` when there is no such
43
+ * object. A start at or past the object's end (S3 answers 416) is empty, and
44
+ * an end past it is cut by the service. A service that ignores `Range` and
45
+ * answers 200 with the whole object is cut here.
46
+ */
47
+ export declare function getRange<P>(context: BucketContext<P>, key: string, range: {
48
+ start: number;
49
+ end: number;
50
+ }, signal: AbortSignal): Promise<Uint8Array | undefined>;
51
+ /** DELETE: S3 answers the same for an object that was not there. */
52
+ export declare function removeObject<P>(context: BucketContext<P>, key: string, signal: AbortSignal): Promise<void>;
53
+ /** What a listing sends: the request is signed as a whole, as a URL. */
54
+ export declare function getListing<P>(context: BucketContext<P>, url: string, signal: AbortSignal): Promise<string>;
55
+ /** What a PUT carries beyond the key: the body and the headers it is served with. */
56
+ export type PutRequest = {
57
+ body: BodyInit;
58
+ headers: Record<string, string>;
59
+ signed: NonNullable<Request['signed']>;
60
+ };
61
+ /**
62
+ * PUT: stores the body. `acl` and `storageClass` are signed into the URL by
63
+ * Bun; the type, disposition and encoding are plain headers, which SeaweedFS
64
+ * stores although they are not signed (measured on 4.47, see the spec).
65
+ */
66
+ export declare function storeObject<P>(context: BucketContext<P>, key: string, request: PutRequest, signal: AbortSignal): Promise<void>;
67
+ export {};
68
+ //# sourceMappingURL=fetch-object.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch-object.d.ts","sourceRoot":"","sources":["../../../src/bucket/operations/fetch-object.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AACnC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAI3C,oEAAoE;AACpE,eAAO,MAAM,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAS5C,CAAC;AAEF,yEAAyE;AACzE,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,KAAK,CAMzE;AAED;;;;GAIG;AACH,KAAK,OAAO,GAAG;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE;QACR,GAAG,CAAC,EAAE,WAAW,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;QACrC,YAAY,CAAC,EAAE,WAAW,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC,CAAC;KACvD,CAAC;IACF,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACjC,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,GAAG,KAAK,CAO/D;AAED,MAAM,MAAM,QAAQ,GAAG;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,EAAE,EAAE,OAAO,CAAC;IACZ,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE,UAAU,CAAC;CACjB,CAAC;AA8CF,wEAAwE;AACxE,wBAAgB,OAAO,CAAC,QA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AAC,CAAC,CAAC;CACvC,CAAC;AAEF;;;;GAIG;AACH,wBAAsB,WAAW,CAAC,CAAC,EAClC,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,EACzB,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,UAAU,EACnB,MAAM,EAAE,WAAW,GACjB,OAAO,CAAC,IAAI,CAAC,CAGf"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * What a ListObjectsV2 answer says, read without an XML parser: the answer is
3
+ * flat and S3's own, and a key can hold anything, so the text is unescaped
4
+ * once and only after it has been cut out.
5
+ */
6
+ export interface ListedObject {
7
+ key: string;
8
+ size: number | undefined;
9
+ lastModified: string | undefined;
10
+ eTag: string | undefined;
11
+ }
12
+ export interface ListAnswer {
13
+ contents: ListedObject[];
14
+ isTruncated: boolean;
15
+ nextContinuationToken: string | undefined;
16
+ }
17
+ export declare function parseListing(xml: string): ListAnswer;
18
+ //# sourceMappingURL=list-xml.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"list-xml.d.ts","sourceRoot":"","sources":["../../../src/bucket/operations/list-xml.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AAEH,MAAM,WAAW,YAAY;IAC5B,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;CACzB;AAED,MAAM,WAAW,UAAU;IAC1B,QAAQ,EAAE,YAAY,EAAE,CAAC;IACzB,WAAW,EAAE,OAAO,CAAC;IACrB,qBAAqB,EAAE,MAAM,GAAG,SAAS,CAAC;CAC1C;AA0DD,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CA0BpD"}
@@ -0,0 +1,12 @@
1
+ import type { BucketContext } from '../context.js';
2
+ import type { CallOptions, ObjectPage } from '../types.js';
3
+ type ListOptions = {
4
+ prefix?: string;
5
+ limit?: number;
6
+ cursor?: string | null;
7
+ startAfter?: string;
8
+ } & CallOptions;
9
+ /** One page of the bucket, in this repository's cursor shape. */
10
+ export declare function listObjects<P>(context: BucketContext<P>, options?: ListOptions): Promise<ObjectPage>;
11
+ export {};
12
+ //# sourceMappingURL=list.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../../src/bucket/operations/list.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAgB,MAAM,UAAU,CAAC;AAOtE,KAAK,WAAW,GAAG;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,UAAU,CAAC,EAAE,MAAM,CAAC;CACpB,GAAG,WAAW,CAAC;AAEhB,iEAAiE;AACjE,wBAAsB,WAAW,CAAC,CAAC,EAClC,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,EACzB,OAAO,GAAE,WAAgB,GACvB,OAAO,CAAC,UAAU,CAAC,CAgBrB"}
@@ -0,0 +1,5 @@
1
+ import { type BucketContext } from '../context.js';
2
+ import type { OpenedObject } from '../types.js';
3
+ /** Turns an answer with headers into the opened object (or a refusal). */
4
+ export declare function answer(context: BucketContext<unknown>, key: string, range: string | undefined, response: Response, signal: AbortSignal, cancel: AbortController): Promise<OpenedObject | undefined>;
5
+ //# sourceMappingURL=open-answer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"open-answer.d.ts","sourceRoot":"","sources":["../../../src/bucket/operations/open-answer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,aAAa,EAAU,MAAM,YAAY,CAAC;AACxD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAsI7C,0EAA0E;AAC1E,wBAAsB,MAAM,CAC3B,OAAO,EAAE,aAAa,CAAC,OAAO,CAAC,EAC/B,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,GAAG,SAAS,EACzB,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,WAAW,EACnB,MAAM,EAAE,eAAe,GACrB,OAAO,CAAC,YAAY,GAAG,SAAS,CAAC,CA0BnC"}
@@ -0,0 +1,10 @@
1
+ import { type BucketContext } from '../context.js';
2
+ /** The `Range` header for a range, after refusing one that is not whole numbers. */
3
+ export declare function rangeHeader<P>(context: BucketContext<P>, key: string, range: unknown): string;
4
+ /** `bytes a-b/total` to its three numbers, or `undefined`. */
5
+ export declare function parseContentRange(header: string | null): {
6
+ first: number;
7
+ last: number;
8
+ total: number;
9
+ } | undefined;
10
+ //# sourceMappingURL=open-range.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"open-range.d.ts","sourceRoot":"","sources":["../../../src/bucket/operations/open-range.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,aAAa,EAAU,MAAM,YAAY,CAAC;AAMxD,oFAAoF;AACpF,wBAAgB,WAAW,CAAC,CAAC,EAC5B,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,EACzB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,OAAO,GACZ,MAAM,CAgCR;AAED,8DAA8D;AAC9D,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;;;;cAQtD"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * The response body, re-exposed so that a failure reading it is rethrown
3
+ * without the signed URL, and cancelling it aborts the request. `skip` and
4
+ * `take` cut a body from a service that answered a range with the whole
5
+ * object.
6
+ */
7
+ export declare function relay(key: string, body: ReadableStream<Uint8Array> | null, cancel: AbortController, skip?: number, take?: number): ReadableStream<Uint8Array>;
8
+ //# sourceMappingURL=open-relay.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"open-relay.d.ts","sourceRoot":"","sources":["../../../src/bucket/operations/open-relay.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,wBAAgB,KAAK,CACpB,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,cAAc,CAAC,UAAU,CAAC,GAAG,IAAI,EACvC,MAAM,EAAE,eAAe,EACvB,IAAI,SAAI,EACR,IAAI,SAA2B,GAC7B,cAAc,CAAC,UAAU,CAAC,CAsC5B"}
@@ -0,0 +1,4 @@
1
+ import type { BucketContext } from '../context.js';
2
+ import type { OpenedObject, OpenOptions } from '../types.js';
3
+ export declare function openObject<P>(context: BucketContext<P>, params: P, options?: OpenOptions): Promise<OpenedObject | undefined>;
4
+ //# sourceMappingURL=open.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"open.d.ts","sourceRoot":"","sources":["../../../src/bucket/operations/open.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AA0C1D,wBAAsB,UAAU,CAAC,CAAC,EACjC,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,EACzB,MAAM,EAAE,CAAC,EACT,OAAO,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,YAAY,GAAG,SAAS,CAAC,CA2BnC"}
@@ -0,0 +1,77 @@
1
+ /**
2
+ * An S3 POST policy and its SigV4 signature, with nothing but `node:crypto`.
3
+ *
4
+ * Bun's `S3Client` signs a GET, a PUT, a HEAD and a DELETE, and has no POST
5
+ * presigning at all; this file is that one missing signature. It is pure —
6
+ * no client, no clock of its own — so its spec pins it at a fixed date.
7
+ *
8
+ * The algorithm is AWS's "browser-based upload" one: the policy is JSON,
9
+ * base64-encoded, and the signature is the HMAC-SHA256 of **that base64
10
+ * string** under the usual SigV4 signing key. Nothing about the request —
11
+ * not its headers, not its body — is signed; the policy's conditions are
12
+ * what the service holds the form to.
13
+ */
14
+ /** One condition of a policy, in the forms S3 documents. */
15
+ export type PolicyCondition = Readonly<Record<string, string>> | readonly ['eq' | 'starts-with', string, string] | readonly ['content-length-range', number, number];
16
+ /** Who signs, and where the form goes. */
17
+ export interface PostSigner {
18
+ /** The bucket's own URL, which the form is posted to. */
19
+ readonly url: string;
20
+ readonly bucket: string;
21
+ readonly accessKeyId: string;
22
+ readonly secretAccessKey: string;
23
+ /** As Bun signs it: `us-east-1`, `eu-west-3`, or `auto` off AWS. */
24
+ readonly region: string;
25
+ /** Temporary credentials: posted as `x-amz-security-token`. */
26
+ readonly sessionToken?: string | undefined;
27
+ }
28
+ /** What the policy fixes, and until when. */
29
+ export interface PostPolicy {
30
+ /**
31
+ * The form's own fields — `key`, `Content-Type`, `acl` — each one fixed
32
+ * by an `eq` condition, so the browser posts exactly these.
33
+ */
34
+ readonly fields: Readonly<Record<string, string>>;
35
+ /** The rest: `content-length-range`, a `starts-with`. */
36
+ readonly conditions: readonly PolicyCondition[];
37
+ /** Seconds from `now` until the service refuses the form. */
38
+ readonly expiresIn: number;
39
+ readonly now: Date;
40
+ }
41
+ /** The form a browser posts: the file goes **after** every one of `fields`. */
42
+ export interface PresignedPost {
43
+ url: string;
44
+ fields: Record<string, string>;
45
+ }
46
+ /** `20151229T000000Z`: SigV4's own date, with no separators and no millis. */
47
+ export declare function amzDateOf(now: Date): string;
48
+ /**
49
+ * SigV4's signing key: four HMACs, from the secret down to `aws4_request`.
50
+ * The service is a parameter only so the spec can pin this against AWS's
51
+ * own documented vector, which is for `iam`.
52
+ */
53
+ export declare function signingKey(secretAccessKey: string, day: string, region: string, service?: string): Buffer;
54
+ /**
55
+ * The query as it was sent, each value decoded once — or `undefined` when a
56
+ * value is not a valid escape. Not `URLSearchParams`, which reads a `+` as a
57
+ * space: Bun leaves the access key id unencoded, so a key with a `+` in it
58
+ * would come back as another key, and a `%` in it as a malformed escape.
59
+ */
60
+ export declare function rawQueryOf(pairs: readonly string[]): Map<string, string> | undefined;
61
+ /**
62
+ * The signature a SigV4 presigned URL should carry, recomputed with this
63
+ * secret: the one way to tell whether it is the secret the URL was signed
64
+ * with, since the URL never carries the secret itself.
65
+ *
66
+ * The canonical query is the query **as it was sent**, sorted, without
67
+ * `X-Amz-Signature` — not decoded and re-encoded. Measured on bun 1.4.2, Bun
68
+ * writes an access key id into `X-Amz-Credential` unencoded, so a key with a
69
+ * `+` or a `/` re-encodes to other bytes than the ones Bun signed; taken as
70
+ * sent, all eleven shapes tried match Bun's own signature (ports, a base
71
+ * path, virtual-hosted style, a session token, a dotted bucket, such keys).
72
+ * A presigned URL signs no payload, and `host` is its one signed header.
73
+ */
74
+ export declare function presignedSignature(url: URL, method: string, secretAccessKey: string): string;
75
+ /** Signs a policy, and gives back the whole form but the file. */
76
+ export declare function signPostPolicy(signer: PostSigner, policy: PostPolicy): PresignedPost;
77
+ //# sourceMappingURL=post-policy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"post-policy.d.ts","sourceRoot":"","sources":["../../../src/bucket/operations/post-policy.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;GAYG;AAEH,4DAA4D;AAC5D,MAAM,MAAM,eAAe,GACxB,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GAChC,SAAS,CAAC,IAAI,GAAG,aAAa,EAAE,MAAM,EAAE,MAAM,CAAC,GAC/C,SAAS,CAAC,sBAAsB,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAErD,0CAA0C;AAC1C,MAAM,WAAW,UAAU;IAC1B,yDAAyD;IACzD,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,oEAAoE;IACpE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,+DAA+D;IAC/D,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,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