@encore.dev/sdk 2.0.0-beta.14 → 2.0.0-beta.16

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 (269) hide show
  1. package/README.md +144 -90
  2. package/app_meta.ts +56 -54
  3. package/config/config.test.ts +47 -13
  4. package/config/config.ts +60 -57
  5. package/config/secrets.ts +47 -50
  6. package/config/value.ts +23 -26
  7. package/cron/mod.test.ts +12 -0
  8. package/cron/mod.ts +37 -22
  9. package/dist/app_meta.d.ts +52 -50
  10. package/dist/app_meta.d.ts.map +1 -1
  11. package/dist/app_meta.js +2 -2
  12. package/dist/app_meta.js.map +1 -1
  13. package/dist/config/config.d.ts +58 -55
  14. package/dist/config/config.d.ts.map +1 -1
  15. package/dist/config/config.js +8 -9
  16. package/dist/config/config.js.map +1 -1
  17. package/dist/config/secrets.d.ts +45 -50
  18. package/dist/config/secrets.d.ts.map +1 -1
  19. package/dist/config/secrets.js +11 -9
  20. package/dist/config/secrets.js.map +1 -1
  21. package/dist/config/value.d.ts +20 -23
  22. package/dist/config/value.d.ts.map +1 -1
  23. package/dist/config/value.js +20 -23
  24. package/dist/config/value.js.map +1 -1
  25. package/dist/cron/mod.d.ts +34 -20
  26. package/dist/cron/mod.d.ts.map +1 -1
  27. package/dist/cron/mod.js +13 -13
  28. package/dist/cron/mod.js.map +1 -1
  29. package/dist/frontends/mod.d.ts +20 -19
  30. package/dist/frontends/mod.d.ts.map +1 -1
  31. package/dist/frontends/mod.js +20 -19
  32. package/dist/frontends/mod.js.map +1 -1
  33. package/dist/gateway/errors.d.ts +28 -30
  34. package/dist/gateway/errors.d.ts.map +1 -1
  35. package/dist/gateway/errors.js +29 -31
  36. package/dist/gateway/errors.js.map +1 -1
  37. package/dist/gateway/match.d.ts +54 -54
  38. package/dist/gateway/match.d.ts.map +1 -1
  39. package/dist/gateway/match.js +56 -56
  40. package/dist/gateway/match.js.map +1 -1
  41. package/dist/gateway/middleware.d.ts +62 -64
  42. package/dist/gateway/middleware.d.ts.map +1 -1
  43. package/dist/gateway/middleware.js +1 -1
  44. package/dist/gateway/middleware.js.map +1 -1
  45. package/dist/gateway/mod.d.ts +64 -67
  46. package/dist/gateway/mod.d.ts.map +1 -1
  47. package/dist/gateway/mod.js +72 -76
  48. package/dist/gateway/mod.js.map +1 -1
  49. package/dist/gateway/request.d.ts +138 -134
  50. package/dist/gateway/request.d.ts.map +1 -1
  51. package/dist/gateway/request.js +117 -108
  52. package/dist/gateway/request.js.map +1 -1
  53. package/dist/gateway/serve.d.ts +29 -34
  54. package/dist/gateway/serve.d.ts.map +1 -1
  55. package/dist/gateway/serve.js +51 -56
  56. package/dist/gateway/serve.js.map +1 -1
  57. package/dist/gateways/mod.d.ts +23 -21
  58. package/dist/gateways/mod.d.ts.map +1 -1
  59. package/dist/gateways/mod.js +25 -23
  60. package/dist/gateways/mod.js.map +1 -1
  61. package/dist/internal/otel/http.d.ts +4 -2
  62. package/dist/internal/otel/http.d.ts.map +1 -1
  63. package/dist/internal/otel/http.js +32 -5
  64. package/dist/internal/otel/http.js.map +1 -1
  65. package/dist/internal/runtime/napi/napi.cjs +6 -5
  66. package/dist/internal/runtime/napi/napi.d.cts +58 -16
  67. package/dist/internal/runtime/shutdown.d.ts +75 -57
  68. package/dist/internal/runtime/shutdown.d.ts.map +1 -1
  69. package/dist/internal/runtime/shutdown.js +88 -84
  70. package/dist/internal/runtime/shutdown.js.map +1 -1
  71. package/dist/log/logger.d.ts +43 -37
  72. package/dist/log/logger.d.ts.map +1 -1
  73. package/dist/log/logger.js +26 -25
  74. package/dist/log/logger.js.map +1 -1
  75. package/dist/metrics/mod.d.ts +133 -114
  76. package/dist/metrics/mod.d.ts.map +1 -1
  77. package/dist/metrics/mod.js +109 -101
  78. package/dist/metrics/mod.js.map +1 -1
  79. package/dist/otel.d.ts +6 -3
  80. package/dist/otel.d.ts.map +1 -1
  81. package/dist/otel.js +6 -3
  82. package/dist/otel.js.map +1 -1
  83. package/dist/pubsub/subscription.d.ts +88 -116
  84. package/dist/pubsub/subscription.d.ts.map +1 -1
  85. package/dist/pubsub/subscription.js +14 -17
  86. package/dist/pubsub/subscription.js.map +1 -1
  87. package/dist/pubsub/topic.d.ts +86 -113
  88. package/dist/pubsub/topic.d.ts.map +1 -1
  89. package/dist/pubsub/topic.js +68 -82
  90. package/dist/pubsub/topic.js.map +1 -1
  91. package/dist/redaction/mod.d.ts +62 -0
  92. package/dist/redaction/mod.d.ts.map +1 -0
  93. package/dist/redaction/mod.js +102 -0
  94. package/dist/redaction/mod.js.map +1 -0
  95. package/dist/reqctx/mod.d.ts +83 -86
  96. package/dist/reqctx/mod.d.ts.map +1 -1
  97. package/dist/reqctx/mod.js +39 -41
  98. package/dist/reqctx/mod.js.map +1 -1
  99. package/dist/services/index.d.ts +76 -75
  100. package/dist/services/index.d.ts.map +1 -1
  101. package/dist/services/index.js +73 -71
  102. package/dist/services/index.js.map +1 -1
  103. package/dist/shutdown/mod.d.ts +26 -25
  104. package/dist/shutdown/mod.d.ts.map +1 -1
  105. package/dist/shutdown/mod.js +26 -25
  106. package/dist/shutdown/mod.js.map +1 -1
  107. package/dist/storage/clickhouse/database.d.ts +113 -115
  108. package/dist/storage/clickhouse/database.d.ts.map +1 -1
  109. package/dist/storage/clickhouse/database.js +65 -79
  110. package/dist/storage/clickhouse/database.js.map +1 -1
  111. package/dist/storage/clickhouse/errors.d.ts +25 -26
  112. package/dist/storage/clickhouse/errors.d.ts.map +1 -1
  113. package/dist/storage/clickhouse/errors.js +15 -17
  114. package/dist/storage/clickhouse/errors.js.map +1 -1
  115. package/dist/storage/clickhouse/mod.d.ts +10 -10
  116. package/dist/storage/clickhouse/mod.js +10 -10
  117. package/dist/storage/objects/bucket.d.ts +230 -203
  118. package/dist/storage/objects/bucket.d.ts.map +1 -1
  119. package/dist/storage/objects/bucket.js +146 -106
  120. package/dist/storage/objects/bucket.js.map +1 -1
  121. package/dist/storage/objects/error.d.ts +4 -4
  122. package/dist/storage/objects/error.js +4 -4
  123. package/dist/storage/objects/mod.d.ts +1 -1
  124. package/dist/storage/objects/mod.d.ts.map +1 -1
  125. package/dist/storage/objects/mod.js.map +1 -1
  126. package/dist/storage/objects/refs.d.ts +2 -5
  127. package/dist/storage/objects/refs.d.ts.map +1 -1
  128. package/dist/storage/objects/refs.js.map +1 -1
  129. package/dist/storage/postgres/database.d.ts +124 -149
  130. package/dist/storage/postgres/database.d.ts.map +1 -1
  131. package/dist/storage/postgres/database.js +98 -135
  132. package/dist/storage/postgres/database.js.map +1 -1
  133. package/dist/storage/postgres/errors.d.ts +42 -48
  134. package/dist/storage/postgres/errors.d.ts.map +1 -1
  135. package/dist/storage/postgres/errors.js +44 -51
  136. package/dist/storage/postgres/errors.js.map +1 -1
  137. package/dist/storage/postgres/interval.d.ts +19 -19
  138. package/dist/storage/postgres/interval.d.ts.map +1 -1
  139. package/dist/storage/postgres/interval.js +21 -21
  140. package/dist/storage/postgres/interval.js.map +1 -1
  141. package/dist/storage/redis/bitfield.d.ts +48 -23
  142. package/dist/storage/redis/bitfield.d.ts.map +1 -1
  143. package/dist/storage/redis/bitfield.js +38 -19
  144. package/dist/storage/redis/bitfield.js.map +1 -1
  145. package/dist/storage/redis/command.d.ts +16 -12
  146. package/dist/storage/redis/command.d.ts.map +1 -1
  147. package/dist/storage/redis/command.js +16 -12
  148. package/dist/storage/redis/command.js.map +1 -1
  149. package/dist/storage/redis/commands.d.ts +99 -100
  150. package/dist/storage/redis/commands.d.ts.map +1 -1
  151. package/dist/storage/redis/commands.js +84 -85
  152. package/dist/storage/redis/commands.js.map +1 -1
  153. package/dist/storage/redis/database.d.ts +138 -122
  154. package/dist/storage/redis/database.d.ts.map +1 -1
  155. package/dist/storage/redis/database.js +120 -101
  156. package/dist/storage/redis/database.js.map +1 -1
  157. package/dist/storage/redis/mod.d.ts +52 -48
  158. package/dist/storage/redis/mod.d.ts.map +1 -1
  159. package/dist/storage/redis/mod.js +52 -48
  160. package/dist/storage/redis/mod.js.map +1 -1
  161. package/dist/storage/redis/options.d.ts +26 -24
  162. package/dist/storage/redis/options.d.ts.map +1 -1
  163. package/dist/storage/redis/options.js.map +1 -1
  164. package/dist/storage/redis/pubsub.d.ts +16 -16
  165. package/dist/storage/redis/pubsub.d.ts.map +1 -1
  166. package/dist/storage/redis/pubsub.js +14 -14
  167. package/dist/storage/redis/pubsub.js.map +1 -1
  168. package/dist/storage/redis/reply.d.ts +80 -72
  169. package/dist/storage/redis/reply.d.ts.map +1 -1
  170. package/dist/storage/redis/reply.js +53 -46
  171. package/dist/storage/redis/reply.js.map +1 -1
  172. package/dist/storage/redis/scan.d.ts +4 -4
  173. package/dist/storage/redis/scan.d.ts.map +1 -1
  174. package/dist/storage/redis/scan.js +6 -6
  175. package/dist/storage/redis/scan.js.map +1 -1
  176. package/dist/storage/redis/script.d.ts +28 -21
  177. package/dist/storage/redis/script.d.ts.map +1 -1
  178. package/dist/storage/redis/script.js +29 -22
  179. package/dist/storage/redis/script.js.map +1 -1
  180. package/dist/storage/redis/target.d.ts +17 -1
  181. package/dist/storage/redis/target.d.ts.map +1 -1
  182. package/dist/storage/redis/target.js +30 -1
  183. package/dist/storage/redis/target.js.map +1 -1
  184. package/dist/storage/redis/wire.d.ts +6 -6
  185. package/dist/storage/redis/wire.d.ts.map +1 -1
  186. package/dist/storage/redis/wire.js +6 -6
  187. package/dist/storage/redis/wire.js.map +1 -1
  188. package/dist/testing/mod.d.ts +83 -88
  189. package/dist/testing/mod.d.ts.map +1 -1
  190. package/dist/testing/mod.js +75 -81
  191. package/dist/testing/mod.js.map +1 -1
  192. package/dist/testing/playwright.d.ts +28 -32
  193. package/dist/testing/playwright.d.ts.map +1 -1
  194. package/dist/testing/playwright.js +22 -27
  195. package/dist/testing/playwright.js.map +1 -1
  196. package/dist/testing/puppeteer.d.ts +11 -12
  197. package/dist/testing/puppeteer.d.ts.map +1 -1
  198. package/dist/testing/puppeteer.js +17 -18
  199. package/dist/testing/puppeteer.js.map +1 -1
  200. package/dist/testing/system.d.ts +72 -90
  201. package/dist/testing/system.d.ts.map +1 -1
  202. package/dist/testing/system.js +90 -107
  203. package/dist/testing/system.js.map +1 -1
  204. package/dist/tracing/http.d.ts +2 -1
  205. package/dist/tracing/http.d.ts.map +1 -1
  206. package/dist/tracing/http.js +2 -1
  207. package/dist/tracing/http.js.map +1 -1
  208. package/dist/tracing/node.d.ts.map +1 -1
  209. package/dist/tracing/node.js +1 -1
  210. package/dist/tracing/node.js.map +1 -1
  211. package/dist/tsconfig.build.tsbuildinfo +1 -1
  212. package/frontends/mod.test.ts +6 -2
  213. package/frontends/mod.ts +20 -19
  214. package/gateway/errors.ts +30 -32
  215. package/gateway/match.ts +61 -57
  216. package/gateway/middleware.ts +62 -64
  217. package/gateway/mod.ts +73 -76
  218. package/gateway/request.ts +143 -140
  219. package/gateway/serve.ts +58 -63
  220. package/gateways/mod.ts +25 -23
  221. package/internal/otel/http.test.ts +50 -0
  222. package/internal/otel/http.ts +40 -5
  223. package/internal/runtime/napi/napi.cjs +6 -5
  224. package/internal/runtime/napi/napi.d.cts +58 -16
  225. package/internal/runtime/shutdown.ts +113 -101
  226. package/log/logger.test.ts +8 -0
  227. package/log/logger.ts +48 -45
  228. package/metrics/mod.ts +138 -122
  229. package/otel.ts +6 -3
  230. package/package.json +6 -1
  231. package/pubsub/subscription.ts +93 -123
  232. package/pubsub/topic.ts +96 -130
  233. package/redaction/bridge.test.ts +99 -0
  234. package/redaction/mod.test.ts +188 -0
  235. package/redaction/mod.ts +226 -0
  236. package/reqctx/mod.ts +83 -86
  237. package/services/index.ts +78 -78
  238. package/shutdown/mod.ts +26 -25
  239. package/storage/clickhouse/database.ts +115 -129
  240. package/storage/clickhouse/errors.ts +27 -29
  241. package/storage/clickhouse/mod.ts +10 -10
  242. package/storage/objects/bucket.test.ts +168 -16
  243. package/storage/objects/bucket.ts +336 -247
  244. package/storage/objects/error.ts +4 -4
  245. package/storage/objects/mod.ts +1 -0
  246. package/storage/objects/refs.ts +2 -5
  247. package/storage/postgres/database.ts +131 -164
  248. package/storage/postgres/errors.ts +45 -52
  249. package/storage/postgres/interval.ts +21 -21
  250. package/storage/redis/bitfield.ts +51 -26
  251. package/storage/redis/command.ts +16 -12
  252. package/storage/redis/commands.ts +99 -100
  253. package/storage/redis/database.ts +145 -123
  254. package/storage/redis/mod.ts +52 -48
  255. package/storage/redis/options.ts +26 -24
  256. package/storage/redis/pubsub.ts +14 -14
  257. package/storage/redis/redis.test.ts +17 -2
  258. package/storage/redis/reply.ts +85 -77
  259. package/storage/redis/scan.ts +6 -6
  260. package/storage/redis/script.ts +29 -22
  261. package/storage/redis/target.ts +34 -1
  262. package/storage/redis/wire.ts +8 -8
  263. package/testing/mod.ts +99 -105
  264. package/testing/playwright.ts +32 -37
  265. package/testing/puppeteer.ts +22 -23
  266. package/testing/system.ts +117 -133
  267. package/tracing/http.ts +2 -1
  268. package/tracing/native.test.ts +158 -8
  269. package/tracing/node.ts +1 -0
@@ -19,129 +19,126 @@ import {
19
19
  } from './refs';
20
20
 
21
21
  /**
22
- * How often an object is expected to be read, which the cloud provider
23
- * prices its storage by.
22
+ * Storage tier indicating how frequently an object is accessed, used by cloud
23
+ * providers to price storage and retrieval:
24
24
  *
25
- * - `standard`: read often. No minimum storage duration and no retrieval fee.
26
- * - `infrequent`: read about once a month or less (GCS Nearline, S3
27
- * Standard-IA). Billed for at least 30 days, with a fee per read.
28
- * - `cold`: read about once a quarter or less (GCS Coldline, S3 Glacier
29
- * Instant Retrieval; Standard-IA on Cloudflare R2). Billed for at least
30
- * 90 days, with a higher fee per read.
25
+ * - `standard`: frequent access; no minimum storage duration or retrieval fee.
26
+ * - `infrequent`: accessed roughly once a month or less (GCS Nearline, S3
27
+ * Standard-IA); billed for at least 30 days with a per-read retrieval fee.
28
+ * - `cold`: accessed roughly once a quarter or less (GCS Coldline, S3 Glacier
29
+ * Instant Retrieval; Standard-IA on Cloudflare R2); billed for at least 90
30
+ * days with a higher per-read retrieval fee.
31
31
  *
32
- * Every class can be read immediately.
32
+ * Objects in every class remain immediately readable.
33
33
  */
34
34
  export type StorageClass = 'standard' | 'infrequent' | 'cold';
35
35
 
36
36
  /**
37
- * Configuration options for declaring a Bucket.
38
- *
39
- * Encore reads the configuration when it builds the app, so its values must
40
- * be literals.
37
+ * Configuration options for declaring a {@link Bucket}. Values must be
38
+ * literals so Encore can inspect them at build time.
41
39
  */
42
40
  export interface BucketConfig {
43
41
  /**
44
- * Whether the objects in the bucket should be publicly
45
- * accessible, via CDN. Defaults to false if unset.
42
+ * Whether objects in the bucket are publicly accessible via CDN.
43
+ * Defaults to `false`.
46
44
  */
47
45
  public?: boolean;
48
46
 
49
47
  /**
50
- * Whether to enable versioning of the objects in the bucket.
51
- * Defaults to false if unset.
48
+ * Whether object versioning is enabled on the bucket.
49
+ * Defaults to `false`.
52
50
  */
53
51
  versioned?: boolean;
54
52
 
55
53
  /**
56
- * The storage class of an object uploaded without one.
57
- * Defaults to `"standard"`.
54
+ * Default storage class for newly uploaded objects. Defaults to `"standard"`.
58
55
  *
59
- * `"auto"` lets the provider move each object between classes by how
60
- * often it is read (GCS Autoclass, S3 Intelligent-Tiering). It is a
61
- * bucket's class only: objects in such a bucket can't name a class, and
62
- * lifecycle rules can't move them.
56
+ * Setting `"auto"` delegates class transitions to the provider based on
57
+ * access patterns (GCS Autoclass, S3 Intelligent-Tiering). When `"auto"` is
58
+ * set, individual uploads cannot override `storageClass` and lifecycle rules
59
+ * cannot transition storage classes.
63
60
  */
64
61
  storageClass?: StorageClass | 'auto';
65
62
 
66
63
  /**
67
- * Rules that move objects to colder storage classes, or delete them, as
68
- * they age. Providers apply them asynchronously, usually within a day,
69
- * to the objects already in the bucket too.
64
+ * Lifecycle rules that automatically transition objects to colder storage
65
+ * classes or delete them as they age. Providers evaluate rules
66
+ * asynchronously (typically within a day), including for existing objects.
70
67
  */
71
68
  lifecycle?: LifecycleRule[];
72
69
 
73
70
  /**
74
- * Keep every object for at least this long after it was written: it
75
- * can't be deleted or overwritten sooner.
71
+ * Minimum retention period applied to every object in the bucket; objects
72
+ * cannot be deleted or overwritten before this period elapses.
76
73
  */
77
74
  retention?: Retention;
78
75
 
79
76
  /**
80
- * Whether objects can be given their own retain-until time, with the
81
- * `retainUntil` upload option and `extendRetention`.
82
- * Defaults to false if unset.
77
+ * Whether individual objects can specify their own `retainUntil` timestamp
78
+ * via upload options and {@link Bucket.extendRetention}. Defaults to `false`.
83
79
  */
84
80
  objectRetention?: boolean;
85
81
 
86
82
  /**
87
- * Tags that classify the bucket, for policies to read: written out as
88
- * string literals, as in `{data: "pci"}`. Keys and values are lowercase
89
- * letters, digits, `_` and `-`, at most 63 characters; a key starts with a
90
- * letter, and not with `encore`, which is reserved. At most 32 tags.
83
+ * Static string-literal tags that classify the bucket for policy checks
84
+ * (e.g. `{data: "pci"}`). Keys and values may contain lowercase letters,
85
+ * digits, `_`, and `-`, up to 63 characters. Keys must start with a letter
86
+ * and cannot start with the reserved prefix `encore`. At most 32 tags.
91
87
  */
92
88
  tags?: Record<string, string>;
93
89
  }
94
90
 
95
91
  /**
96
- * A lifecycle rule: an optional prefix and at least one action. Days are
97
- * whole numbers from 1 to 36500 and count from when an object was written,
98
- * or for the noncurrent fields, from when it was replaced or removed.
92
+ * A lifecycle rule with an optional key prefix and at least one action. Day
93
+ * counts are whole numbers from 1 to 36500 measured from creation time (or
94
+ * from replacement/deletion time for noncurrent version rules).
99
95
  */
100
96
  export interface LifecycleRule {
101
- /** Only objects whose names start with it. Defaults to every object. */
97
+ /** Restrict the rule to objects whose names start with this prefix. Defaults to all objects. */
102
98
  prefix?: string;
103
99
 
104
100
  /**
105
- * Move an object to `infrequent` this many days after it was written.
106
- * At least 30.
101
+ * Transition objects to `infrequent` storage this many days after creation.
102
+ * Must be at least 30.
107
103
  */
108
104
  moveToInfrequentAfterDays?: number;
109
105
 
110
106
  /**
111
- * Move an object to `cold` this many days after it was written. With
112
- * `moveToInfrequentAfterDays`, at least 30 days after it.
107
+ * Transition objects to `cold` storage this many days after creation. When
108
+ * combined with `moveToInfrequentAfterDays`, must be at least 30 days later.
113
109
  */
114
110
  moveToColdAfterDays?: number;
115
111
 
116
112
  /**
117
- * Delete an object this many days after it was written. In a versioned
118
- * bucket it becomes a noncurrent version, as `remove` does.
113
+ * Delete objects this many days after creation. In versioned buckets, the
114
+ * object becomes a noncurrent version (just like {@link Bucket.remove}).
119
115
  */
120
116
  deleteAfterDays?: number;
121
117
 
122
118
  /**
123
- * Versioned buckets: delete a noncurrent version this many days after it
124
- * was replaced or removed.
119
+ * Versioned buckets only: delete noncurrent versions this many days after
120
+ * they were replaced or removed.
125
121
  */
126
122
  deleteNoncurrentAfterDays?: number;
127
123
 
128
124
  /**
129
- * Versioned buckets: never delete the newest this many noncurrent
130
- * versions. On its own, delete the noncurrent versions beyond them.
125
+ * Versioned buckets only: retain at least this many of the newest noncurrent
126
+ * versions (deleting older noncurrent versions beyond this count when used
127
+ * on its own).
131
128
  */
132
129
  keepNoncurrentVersions?: number;
133
130
  }
134
131
 
135
132
  /**
136
- * A bucket's retention period.
133
+ * Bucket-level retention period.
137
134
  */
138
135
  export interface Retention {
139
- /** The days, from 1 to 36500, an object is kept after it was written. */
136
+ /** Number of days (1 to 36500) to retain each object after creation. */
140
137
  days: number;
141
138
  }
142
139
 
143
140
  /**
144
- * Defines a new Object Storage bucket infrastructure resource.
141
+ * Declares an Object Storage bucket infrastructure resource.
145
142
  */
146
143
  export class Bucket
147
144
  extends BucketPerms
@@ -159,11 +156,11 @@ export class Bucket
159
156
  IfMatchRemover
160
157
  {
161
158
  private readonly bucketName: string;
162
- /** The runtime's bucket: made on first use in test mode. */
159
+ /** Native runtime bucket, initialized lazily in test mode. */
163
160
  private own?: runtime.Bucket;
164
161
 
165
162
  /**
166
- * Creates a new bucket with the given name and configuration
163
+ * Declares a new bucket with the given name and configuration.
167
164
  */
168
165
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
169
166
  constructor(name: string, cfg?: BucketConfig) {
@@ -172,8 +169,7 @@ export class Bucket
172
169
  if (!testMode) this.own = runtime.RT.bucket(name);
173
170
  }
174
171
 
175
- /** The native bucket: in a test, the test's instance of it.
176
- * @internal */
172
+ /** Native bucket handle (resolves to the current test's instance in test mode). @internal */
177
173
  get impl(): runtime.Bucket {
178
174
  return (
179
175
  currentScope()?.bucket(this.bucketName) ??
@@ -182,19 +178,19 @@ export class Bucket
182
178
  }
183
179
 
184
180
  /**
185
- * Reference an existing bucket by name.
186
- * To create a new storage bucket, use `new StorageBucket(...)` instead.
181
+ * References an existing bucket by name.
182
+ * To declare a new bucket, use `new Bucket(...)` instead.
187
183
  */
188
184
  static named<name extends string>(name: StringLiteral<name>): Bucket {
189
185
  return new Bucket(name, {});
190
186
  }
191
187
 
192
188
  /**
193
- * Lists the objects in the bucket, sorted by name.
189
+ * Lists objects in the bucket in lexicographical order by name.
194
190
  *
195
- * With a `delimiter`, the names that continue past the `prefix` with the
196
- * delimiter are grouped into one entry per common prefix, with
197
- * `isPrefix` set, as a directory listing does.
191
+ * When `delimiter` is set, keys sharing a common prefix past `options.prefix`
192
+ * up to the delimiter are grouped into a single entry with `isPrefix: true`
193
+ * (similar to a directory listing).
198
194
  */
199
195
  async *list(options?: ListOptions): AsyncGenerator<ListEntry> {
200
196
  const source = activeCtxBytes();
@@ -214,7 +210,13 @@ export class Bucket
214
210
  if (entry === null) {
215
211
  break;
216
212
  }
217
- yield entry;
213
+ yield {
214
+ name: entry.name,
215
+ size: entry.size,
216
+ etag: entry.etag,
217
+ lastModified: toDate(entry.lastModified),
218
+ isPrefix: entry.isPrefix,
219
+ };
218
220
  }
219
221
  } finally {
220
222
  iter.markDone();
@@ -222,9 +224,9 @@ export class Bucket
222
224
  }
223
225
 
224
226
  /**
225
- * Lists every stored version of the objects in the bucket, sorted by
226
- * name and then newest first. A removed object has no `latest` version.
227
- * An unversioned bucket lists one latest version per object.
227
+ * Lists all stored object versions in the bucket, sorted by name and then
228
+ * newest first. Deleted objects have no `latest` version. In unversioned
229
+ * buckets, yields one `latest` version per object.
228
230
  */
229
231
  async *listVersions(
230
232
  options?: ListVersionsOptions,
@@ -269,7 +271,7 @@ export class Bucket
269
271
 
270
272
  /**
271
273
  * Returns the object's attributes.
272
- * Throws an error if the object does not exist.
274
+ * Throws `ObjectNotFound` if the object does not exist.
273
275
  */
274
276
  async attrs(name: string, options?: AttrsOptions): Promise<ObjectAttrs> {
275
277
  const source = activeCtxBytes();
@@ -294,10 +296,9 @@ export class Bucket
294
296
  }
295
297
 
296
298
  /**
297
- * Uploads an object to the bucket from a stream of bytes: a Web
298
- * `ReadableStream`, a Node.js `Readable`, or any async iterable of
299
- * `Uint8Array` chunks. The stream is read as fast as the upload takes
300
- * its bytes.
299
+ * Uploads an object from a byte stream — a Web `ReadableStream`, Node.js
300
+ * `Readable`, or any async iterable of `Uint8Array` chunks — pulling chunks
301
+ * as the upload consumes them.
301
302
  *
302
303
  * If the stream errors, the upload is aborted and nothing is stored.
303
304
  */
@@ -314,21 +315,19 @@ export class Bucket
314
315
  }
315
316
 
316
317
  /**
317
- * Uploads an object only if the bucket still holds the given revision of
318
- * it, as `attrs`, `upload`, `updateAttrs` or a listing returned it, and
319
- * throws `PreconditionFailed` otherwise, also if the object no longer
320
- * exists. This makes read-modify-write safe against concurrent writers.
321
- * A missing revision throws `InvalidArgument`.
318
+ * Conditionally uploads an object only if the bucket still holds `revision`
319
+ * (returned by `download`, `attrs`, `upload`, `updateAttrs`, or `list`),
320
+ * throwing `PreconditionFailed` if the object changed or was deleted. Throws
321
+ * `InvalidArgument` if `revision` is missing.
322
322
  *
323
- * `data` is bytes or a stream, as `upload` and `uploadStream` take.
323
+ * `data` may be a `Uint8Array` or a stream (as in {@link upload} and
324
+ * {@link uploadStream}). Comparisons check object contents rather than
325
+ * metadata, so {@link updateAttrs} does not invalidate a match. GCS matches
326
+ * on `revision.version` (throwing `InvalidArgument` if absent), while S3 and
327
+ * Cloudflare R2 match on `revision.etag`.
324
328
  *
325
- * The match compares the object's contents, not its attributes:
326
- * `updateAttrs` doesn't break it. Google Cloud Storage matches the
327
- * revision's `version`, so a revision without one throws
328
- * `InvalidArgument` there; Amazon S3 and Cloudflare R2 match its `etag`.
329
- *
330
- * On Amazon S3 a conditional write also needs read access to the bucket,
331
- * which Encore grants to the services that call this.
329
+ * On AWS S3, conditional writes also require read permission, which Encore
330
+ * grants automatically to calling services.
332
331
  */
333
332
  async uploadIfMatch(
334
333
  name: string,
@@ -346,13 +345,13 @@ export class Bucket
346
345
  }
347
346
 
348
347
  /**
349
- * Replaces the given attributes of an object and leaves the others as
350
- * they are. An empty string clears an attribute (a cleared content type
351
- * is `application/octet-stream`, as S3 keeps no object without one), and
352
- * `metadata` replaces the whole map.
348
+ * Updates the specified attributes of an object while leaving omitted
349
+ * attributes unchanged. Pass an empty string to clear an attribute (clearing
350
+ * `contentType` resets it to `application/octet-stream`), and pass a new
351
+ * `metadata` object to replace the entire metadata map (`{}` clears it).
353
352
  *
354
- * On S3 this rewrites the object, so a versioned bucket gets a new
355
- * version, and the object's age for lifecycle rules starts over.
353
+ * On AWS S3, updating attributes rewrites the object, creating a new version
354
+ * in versioned buckets and resetting the object's lifecycle age.
356
355
  */
357
356
  async updateAttrs(
358
357
  name: string,
@@ -378,9 +377,9 @@ export class Bucket
378
377
  }
379
378
 
380
379
  /**
381
- * Keeps the object until `until` at least. Retention can only be
382
- * extended: a time earlier than the object's current one throws
383
- * `InvalidArgument`. The bucket must be declared with `objectRetention`.
380
+ * Extends the object's retention until at least `until`. Retention can only
381
+ * be extended — passing a time earlier than the current retention throws
382
+ * `InvalidArgument`. Requires `objectRetention: true` on the bucket.
384
383
  */
385
384
  async extendRetention(
386
385
  name: string,
@@ -398,13 +397,11 @@ export class Bucket
398
397
  }
399
398
 
400
399
  /**
401
- * Generate an external URL to allow uploading an object to the bucket.
402
- *
403
- * Anyone with possession of the URL can write to the given object name
404
- * without any additional auth.
400
+ * Generates a pre-signed URL allowing anyone with the URL to upload to
401
+ * `name` without additional authentication.
405
402
  *
406
- * The URL doesn't carry the bucket's storage class: an object uploaded
407
- * through it gets the provider's default class for the bucket.
403
+ * Note: Pre-signed upload URLs do not enforce the bucket's configured
404
+ * `storageClass`; uploaded objects receive the provider's default class.
408
405
  */
409
406
  async signedUploadUrl(
410
407
  name: string,
@@ -417,10 +414,8 @@ export class Bucket
417
414
  }
418
415
 
419
416
  /**
420
- * Generate an external URL to allow downloading an object from the bucket.
421
- *
422
- * Anyone with possession of the URL can download the given object without
423
- * any additional auth.
417
+ * Generates a pre-signed URL allowing anyone with the URL to download `name`
418
+ * without additional authentication.
424
419
  */
425
420
  async signedDownloadUrl(
426
421
  name: string,
@@ -433,48 +428,23 @@ export class Bucket
433
428
  }
434
429
 
435
430
  /**
436
- * Downloads an object from the bucket and returns its contents.
437
- */
438
- async download(name: string, options?: DownloadOptions): Promise<Buffer> {
439
- const source = activeCtxBytes();
440
- const impl = this.impl.object(name);
441
- const res = await impl.downloadAll(downloadOptions(options), source);
442
- return unwrapErr(res);
443
- }
444
-
445
- /**
446
- * Downloads an object from the bucket as a Web `ReadableStream`, read
447
- * from the provider as the consumer reads it. A missing object throws
448
- * here, before any bytes. Cancelling the stream stops the download.
431
+ * Starts downloading an object from the bucket. Resolves as soon as the
432
+ * provider responds (throwing immediately if the object is missing or the
433
+ * byte range is invalid), returning a {@link Download} with response
434
+ * metadata and one-shot `bytes()` / `stream()` readers.
449
435
  *
450
- * In Node.js, `Readable.fromWeb` converts it to a Node.js stream.
436
+ * ```ts
437
+ * const d = await uploads.download("state.json");
438
+ * const state = JSON.parse((await d.bytes()).toString());
439
+ * // Write only if nobody else updated the object since we read it.
440
+ * await uploads.uploadIfMatch("state.json", next(state), d.revision);
441
+ * ```
451
442
  */
452
- async downloadStream(
453
- name: string,
454
- options?: DownloadOptions,
455
- ): Promise<ReadableStream<Uint8Array>> {
443
+ async download(name: string, options?: DownloadOptions): Promise<Download> {
456
444
  const source = activeCtxBytes();
457
445
  const impl = this.impl.object(name);
458
- const stream = unwrapErr(
459
- await impl.downloadStream(downloadOptions(options), source),
460
- );
461
- return new ReadableStream<Uint8Array>(
462
- {
463
- async pull(controller) {
464
- const chunk = unwrapErr(await stream.next());
465
- if (chunk === null) {
466
- controller.close();
467
- } else {
468
- controller.enqueue(chunk);
469
- }
470
- },
471
- async cancel() {
472
- await stream.close();
473
- },
474
- },
475
- // Read ahead of the consumer by nothing.
476
- {highWaterMark: 0},
477
- );
446
+ const res = await impl.download(downloadOptions(options), source);
447
+ return new NativeDownload(unwrapErr(res));
478
448
  }
479
449
 
480
450
  /**
@@ -491,18 +461,15 @@ export class Bucket
491
461
  }
492
462
 
493
463
  /**
494
- * Removes an object only if the bucket still holds the given revision of
495
- * it, as `attrs`, `upload`, `updateAttrs` or a listing returned it, and
496
- * throws `PreconditionFailed` otherwise, also if the object no longer
497
- * exists. It compares the latest version, so there is no `version` to
498
- * remove. A missing revision throws `InvalidArgument`.
499
- *
500
- * The match compares the object's contents, not its attributes:
501
- * `updateAttrs` doesn't break it.
464
+ * Conditionally removes an object only if its latest version still matches
465
+ * `revision` (returned by `download`, `attrs`, `upload`, `updateAttrs`, or
466
+ * `list`), throwing `PreconditionFailed` if it changed or no longer exists.
467
+ * Throws `InvalidArgument` if `revision` is missing.
502
468
  *
503
- * On Amazon S3 a conditional delete also needs read access to the
504
- * bucket, which Encore grants to the services that call this. Cloudflare
505
- * R2 doesn't support conditional deletes: there it throws
469
+ * Comparisons check object contents rather than metadata, so
470
+ * {@link updateAttrs} does not invalidate a match. On AWS S3, conditional
471
+ * deletes require read permission (granted automatically by Encore).
472
+ * Cloudflare R2 does not support conditional deletes and throws
506
473
  * `InvalidArgument`.
507
474
  */
508
475
  async removeIfMatch(name: string, revision: Revision): Promise<void> {
@@ -516,8 +483,8 @@ export class Bucket
516
483
  }
517
484
 
518
485
  /**
519
- * Returns the public URL for accessing the object with the given name.
520
- * Throws an error if the bucket is not public.
486
+ * Returns the public CDN URL for accessing the object.
487
+ * Throws an error if the bucket is not declared with `public: true`.
521
488
  */
522
489
  publicUrl(name: string): string {
523
490
  const obj = this.impl.object(name);
@@ -529,13 +496,13 @@ export class Bucket
529
496
  }
530
497
  }
531
498
 
532
- /** The most bytes handed to the native upload at a time. */
499
+ /** Maximum chunk size passed to the native upload writer at a time. */
533
500
  const CHUNK_SIZE = 64 * 1024;
534
501
 
535
502
  const STREAM_EXPECTED =
536
- 'uploadStream takes a ReadableStream or an async iterable of Uint8Array chunks';
503
+ 'uploadStream expects a ReadableStream or an async iterable of Uint8Array chunks';
537
504
  const BODY_EXPECTED =
538
- 'uploadIfMatch takes a Uint8Array, a ReadableStream or an async iterable of Uint8Array chunks';
505
+ 'uploadIfMatch expects a Uint8Array, ReadableStream, or async iterable of Uint8Array chunks';
539
506
 
540
507
  async function uploadChunks(
541
508
  obj: runtime.BucketObject,
@@ -547,7 +514,7 @@ async function uploadChunks(
547
514
  try {
548
515
  for await (const chunk of data) {
549
516
  if (!(chunk instanceof Uint8Array)) {
550
- throw new TypeError('upload data must be Uint8Array chunks');
517
+ throw new TypeError('upload data must consist of Uint8Array chunks');
551
518
  }
552
519
  for (const slice of slices(chunk)) {
553
520
  const err = await stream.write(slice);
@@ -564,7 +531,7 @@ async function uploadChunks(
564
531
  return toAttrs(unwrapErr(await stream.finish()));
565
532
  }
566
533
 
567
- /** Views of `data`, of at most CHUNK_SIZE bytes each, as Buffers. */
534
+ /** Yields `Buffer` views of `data`, each at most `CHUNK_SIZE` bytes. */
568
535
  function* slices(data: Uint8Array): Generator<Buffer> {
569
536
  const buf = Buffer.isBuffer(data)
570
537
  ? data
@@ -632,7 +599,84 @@ function uploadOptions(
632
599
  function downloadOptions(
633
600
  options: DownloadOptions | undefined,
634
601
  ): runtime.DownloadOptions | undefined {
635
- return options && {version: options.version, range: options.range};
602
+ return options && {version: options.version, range: byteRange(options.range)};
603
+ }
604
+
605
+ function byteRange(
606
+ range: ByteRange | undefined,
607
+ ): runtime.ByteRange | undefined {
608
+ if (range === undefined) {
609
+ return undefined;
610
+ }
611
+ // What the types forbid, plain JavaScript can pass.
612
+ if (range.last !== undefined) {
613
+ if (range.offset !== undefined || range.length !== undefined) {
614
+ throw new InvalidArgument(
615
+ 'byte range must specify either `offset` (with optional `length`) or `last`, not both',
616
+ );
617
+ }
618
+ return {last: range.last};
619
+ }
620
+ if (typeof range.offset !== 'number') {
621
+ throw new InvalidArgument(
622
+ 'byte range must specify either a numeric `offset` or `last`',
623
+ );
624
+ }
625
+ return {offset: range.offset, length: range.length};
626
+ }
627
+
628
+ /** Wraps a native runtime download handle. */
629
+ class NativeDownload implements Download {
630
+ readonly revision: Revision;
631
+ readonly size: number;
632
+ readonly contentType?: string;
633
+ readonly lastModified?: Date;
634
+ private read = false;
635
+
636
+ constructor(private readonly impl: runtime.Download) {
637
+ const info = impl.info;
638
+ this.revision = {etag: info.etag, version: info.version};
639
+ this.size = info.size;
640
+ this.contentType = info.contentType;
641
+ this.lastModified = toDate(info.lastModified);
642
+ }
643
+
644
+ async bytes(): Promise<Buffer> {
645
+ this.take('bytes');
646
+ return unwrapErr(await this.impl.bytes());
647
+ }
648
+
649
+ stream(): ReadableStream<Uint8Array> {
650
+ this.take('stream');
651
+ const impl = this.impl;
652
+ return new ReadableStream<Uint8Array>(
653
+ {
654
+ async pull(controller) {
655
+ const chunk = unwrapErr(await impl.next());
656
+ if (chunk === null) {
657
+ controller.close();
658
+ } else {
659
+ controller.enqueue(chunk);
660
+ }
661
+ },
662
+ async cancel() {
663
+ await impl.close();
664
+ },
665
+ },
666
+ // Read ahead of the consumer by nothing.
667
+ {highWaterMark: 0},
668
+ );
669
+ }
670
+
671
+ /** Enforces single consumption of the download body. */
672
+ private take(method: string): void {
673
+ if (this.read) {
674
+ throw new InvalidArgument(
675
+ `${method}: download body has already been consumed`,
676
+ );
677
+ }
678
+ this.read = true;
679
+ }
636
680
  }
637
681
 
638
682
  function toRevision(rev: Revision | undefined): runtime.Revision | undefined {
@@ -640,14 +684,13 @@ function toRevision(rev: Revision | undefined): runtime.Revision | undefined {
640
684
  }
641
685
 
642
686
  /**
643
- * The revision a `*IfMatch` method matches. A missing one, which the types
644
- * forbid but plain JavaScript can pass, is refused: the write or delete would
645
- * otherwise be unconditional.
687
+ * Validates that `*IfMatch` callers supplied a revision so writes or deletes
688
+ * cannot silently become unconditional in untyped JS.
646
689
  */
647
690
  function requiredRevision(method: string, rev: Revision): runtime.Revision {
648
691
  if (rev == null || typeof rev.etag !== 'string') {
649
692
  throw new InvalidArgument(
650
- `${method} needs the revision to match: the attributes attrs, upload or updateAttrs returned`,
693
+ `${method} requires a revision (e.g. from download.revision, attrs(), upload(), or updateAttrs())`,
651
694
  );
652
695
  }
653
696
  return {etag: rev.etag, version: rev.version};
@@ -678,20 +721,20 @@ function toAttrs(attrs: runtime.ObjectAttrs): ObjectAttrs {
678
721
  */
679
722
  export interface ListOptions {
680
723
  /**
681
- * Only include objects with this prefix in the listing.
682
- * If unset, all objects are included.
724
+ * Only include objects whose names start with this prefix.
725
+ * Defaults to all objects.
683
726
  */
684
727
  prefix?: string;
685
728
 
686
729
  /**
687
- * Maximum number of entries to return, common prefixes included.
688
- * Defaults to no limit.
730
+ * Maximum number of entries to return (including common prefixes).
731
+ * Unlimited when unset.
689
732
  */
690
733
  limit?: number;
691
734
 
692
735
  /**
693
- * Group the names that continue past the prefix with this delimiter,
694
- * usually `"/"`, into one entry per common prefix.
736
+ * Delimiter (typically `"/"`) used to group object names past `prefix` into
737
+ * single common-prefix entries.
695
738
  */
696
739
  delimiter?: string;
697
740
  }
@@ -701,37 +744,33 @@ export interface ListOptions {
701
744
  */
702
745
  export interface ListVersionsOptions {
703
746
  /**
704
- * Only include objects with this prefix in the listing.
705
- * If unset, all objects are included.
747
+ * Only include objects whose names start with this prefix.
748
+ * Defaults to all objects.
706
749
  */
707
750
  prefix?: string;
708
751
 
709
- /** Maximum number of versions to return. Defaults to no limit. */
752
+ /** Maximum number of versions to return. Unlimited when unset. */
710
753
  limit?: number;
711
754
  }
712
755
 
713
756
  /**
714
- * Options for retrieving the attributes of an object.
757
+ * Options for retrieving an object's attributes.
715
758
  */
716
759
  export interface AttrsOptions {
717
760
  /**
718
- * The object version to retrieve attributes for.
719
- * Defaults to the lastest version if unset.
720
- *
721
- * If bucket versioning is not enabled, this option is ignored.
761
+ * Object version to inspect. Defaults to the latest version.
762
+ * Ignored if bucket versioning is disabled.
722
763
  */
723
764
  version?: string;
724
765
  }
725
766
 
726
767
  /**
727
- * Options for checking the existence of an object.
768
+ * Options for checking whether an object exists.
728
769
  */
729
770
  export interface ExistsOptions {
730
771
  /**
731
- * The object version to check for existence.
732
- * Defaults to the lastest version if unset.
733
- *
734
- * If bucket versioning is not enabled, this option is ignored.
772
+ * Object version to check. Defaults to the latest version.
773
+ * Ignored if bucket versioning is disabled.
735
774
  */
736
775
  version?: string;
737
776
  }
@@ -741,54 +780,102 @@ export interface ExistsOptions {
741
780
  */
742
781
  export interface DeleteOptions {
743
782
  /**
744
- * The object version to delete.
745
- * Defaults to the lastest version if unset.
746
- *
747
- * If bucket versioning is not enabled, this option is ignored.
783
+ * Object version to delete. Defaults to the latest version.
784
+ * Ignored if bucket versioning is disabled.
748
785
  */
749
786
  version?: string;
750
787
  }
751
788
 
752
789
  /**
753
- * A contiguous byte range within an object.
790
+ * A contiguous byte range within an object: either `length` bytes starting at
791
+ * `offset`, or the final `last` bytes of the object.
754
792
  */
755
- export interface ByteRange {
756
- /** The zero-based index of the first byte to read. */
757
- offset: number;
793
+ export type ByteRange =
794
+ | {
795
+ /** Zero-based index of the first byte to read. */
796
+ offset: number;
797
+
798
+ /**
799
+ * Number of bytes to read. Reads through the end of the object when
800
+ * omitted.
801
+ */
802
+ length?: number;
803
+
804
+ last?: never;
805
+ }
806
+ | {
807
+ /**
808
+ * Read the final `last` bytes of the object (or the entire object if it
809
+ * is shorter). Check {@link Download.size} for the object's full length.
810
+ */
811
+ last: number;
758
812
 
759
- /**
760
- * The number of bytes to read.
761
- * Defaults to reading to the end of the object if unset.
762
- */
763
- length?: number;
764
- }
813
+ offset?: never;
814
+ length?: never;
815
+ };
765
816
 
766
817
  /**
767
818
  * Options for downloading an object from a bucket.
768
819
  */
769
820
  export interface DownloadOptions {
770
821
  /**
771
- * The object version to download.
772
- * Defaults to the lastest version if unset.
773
- *
774
- * If bucket versioning is not enabled, this option is ignored.
822
+ * Object version to download. Defaults to the latest version.
823
+ * Ignored if bucket versioning is disabled.
775
824
  */
776
825
  version?: string;
777
826
 
778
827
  /**
779
- * Download only the given byte range of the object, instead of the whole
780
- * object. The returned Buffer contains just the requested bytes.
828
+ * Optional byte range to download instead of the full object. The body
829
+ * contains only the requested slice while {@link Download.size} still
830
+ * reports the full object size.
781
831
  *
782
- * Throws InvalidArgument if the range is empty or lies beyond the end
783
- * of the object.
832
+ * Throws `InvalidArgument` if the range is empty or starts past the end of
833
+ * the object.
784
834
  */
785
835
  range?: ByteRange;
786
836
  }
787
837
 
788
838
  /**
789
- * One revision of an object: what `uploadIfMatch`, `removeIfMatch` and the
790
- * `ifMatch` precondition of `updateAttrs` compare. `ObjectAttrs` is one, so
791
- * the attributes an operation returned can be passed as they are.
839
+ * An in-progress download returned by {@link Bucket.download}, exposing basic
840
+ * response metadata and one-shot body readers (`bytes()` or `stream()`).
841
+ *
842
+ * Includes only the metadata providers send alongside download responses (use
843
+ * {@link Bucket.attrs} for full metadata). An unread download holds its
844
+ * connection open until garbage collected; call `await d.stream().cancel()` to
845
+ * release it early.
846
+ */
847
+ export interface Download {
848
+ /**
849
+ * Revision of the downloaded contents. Pass to {@link Bucket.uploadIfMatch}
850
+ * or {@link Bucket.removeIfMatch} for optimistic concurrency control.
851
+ */
852
+ readonly revision: Revision;
853
+ /** Full object size in bytes, even when downloading a byte range. */
854
+ readonly size: number;
855
+ readonly contentType?: string;
856
+ /** Last modification timestamp, if reported by the provider. */
857
+ readonly lastModified?: Date;
858
+
859
+ /**
860
+ * Buffers and returns the entire download body. Throws `InvalidArgument` if
861
+ * the body has already been consumed.
862
+ */
863
+ bytes(): Promise<Buffer>;
864
+
865
+ /**
866
+ * Streams the download body as a Web `ReadableStream`. Canceling the stream
867
+ * aborts the download. Throws `InvalidArgument` if the body has already been
868
+ * consumed.
869
+ *
870
+ * In Node.js, use `Readable.fromWeb` to convert this into a Node stream.
871
+ */
872
+ stream(): ReadableStream<Uint8Array>;
873
+ }
874
+
875
+ /**
876
+ * Identifies a specific content revision of an object for conditional
877
+ * operations (`uploadIfMatch`, `removeIfMatch`, and `updateAttrs` `ifMatch`).
878
+ * Both {@link ObjectAttrs} and {@link Download.revision} satisfy `Revision`.
792
879
  */
793
880
  export interface Revision {
794
881
  etag: string;
@@ -796,66 +883,67 @@ export interface Revision {
796
883
  }
797
884
 
798
885
  /**
799
- * Conditions on the object an upload writes.
886
+ * Preconditions for an upload.
800
887
  */
801
888
  export interface Preconditions {
802
889
  /**
803
- * Only write the object if it does not exist yet.
804
- * Throws `PreconditionFailed` otherwise.
890
+ * Only write the object if it does not already exist; throws
891
+ * `PreconditionFailed` otherwise.
805
892
  */
806
893
  notExists?: boolean;
807
894
  }
808
895
 
809
896
  /**
810
- * Describes the attributes of an object stored in a bucket.
897
+ * Attributes of an object stored in a bucket.
811
898
  */
812
899
  export interface ObjectAttrs {
813
900
  name: string;
814
901
  size: number;
815
- /** The version of the object, if bucket versioning is enabled. */
902
+ /** Object version identifier, if bucket versioning is enabled. */
816
903
  version?: string;
817
904
  etag: string;
818
905
  contentType?: string;
819
906
  cacheControl?: string;
820
907
  contentDisposition?: string;
821
- /** Custom metadata; empty if the object has none. */
908
+ /** Custom metadata map (empty object if none). */
822
909
  metadata: Record<string, string>;
823
- /** When this version of the object was written. */
910
+ /** Timestamp when this object version was written. */
824
911
  lastModified?: Date;
825
912
  /**
826
- * The object's storage class. Every object in a bucket whose class is
827
- * `"auto"` reads `"auto"`. Undefined for a class Encore doesn't model,
828
- * set outside Encore.
913
+ * Object storage class (`"auto"` for buckets with `storageClass: "auto"`,
914
+ * or `undefined` if a provider-specific class was set outside Encore).
829
915
  */
830
916
  storageClass?: StorageClass | 'auto';
831
- /** The object's own retain-until time, if it has one. */
917
+ /** Per-object retain-until timestamp, if set. */
832
918
  retainUntil?: Date;
833
919
  }
834
920
 
835
921
  /**
836
- * A single entry returned when listing objects in a bucket.
922
+ * A single entry yielded by {@link Bucket.list}.
837
923
  */
838
924
  export interface ListEntry {
839
- /** The object's name, or a common prefix, ending in the delimiter. */
925
+ /** Object key, or common prefix ending with the delimiter. */
840
926
  name: string;
841
927
  size: number;
842
928
  etag: string;
929
+ /** Timestamp when the object was written (unset for common prefixes). */
930
+ lastModified?: Date;
843
931
  /**
844
- * Whether the entry is a common prefix of a listing with a delimiter,
845
- * rather than an object. A prefix has size 0 and an empty etag.
932
+ * `true` when this entry represents a common prefix grouped by a delimiter
933
+ * (with `size: 0` and empty `etag`), rather than an object.
846
934
  */
847
935
  isPrefix: boolean;
848
936
  }
849
937
 
850
938
  /**
851
- * One stored version of an object, as `listVersions` lists it.
939
+ * A single stored object version yielded by {@link Bucket.listVersions}.
852
940
  */
853
941
  export interface ObjectVersion {
854
942
  name: string;
855
943
  version?: string;
856
944
  size: number;
857
945
  etag: string;
858
- /** Whether this is the object's current version. */
946
+ /** Whether this is the object's current (latest) version. */
859
947
  latest: boolean;
860
948
  lastModified?: Date;
861
949
  }
@@ -866,25 +954,25 @@ export interface ObjectVersion {
866
954
  export interface UploadOptions {
867
955
  contentType?: string;
868
956
 
869
- /** The `Cache-Control` header that downloads of the object get. */
957
+ /** `Cache-Control` header returned when downloading the object. */
870
958
  cacheControl?: string;
871
959
 
872
- /** The `Content-Disposition` header that downloads of the object get. */
960
+ /** `Content-Disposition` header returned when downloading the object. */
873
961
  contentDisposition?: string;
874
962
 
875
963
  /**
876
- * Custom metadata. Keys match `[a-z0-9][a-z0-9_-]*` and values are
877
- * printable ASCII. Keys and values together may take 8 KiB on GCS and
964
+ * Custom key-value metadata. Keys must match `[a-z0-9][a-z0-9_-]*` and
965
+ * values must be printable ASCII. Total size is limited to 8 KiB on GCS and
878
966
  * 2 KiB on S3.
879
967
  */
880
968
  metadata?: Record<string, string>;
881
969
 
882
- /** The object's storage class. Defaults to the bucket's. */
970
+ /** Object storage class. Defaults to the bucket's configured storage class. */
883
971
  storageClass?: StorageClass;
884
972
 
885
973
  /**
886
- * Keep the object until then: it can't be deleted or overwritten
887
- * sooner. The bucket must be declared with `objectRetention`.
974
+ * Prevents the object from being deleted or overwritten until this time.
975
+ * Requires `objectRetention: true` on the bucket.
888
976
  */
889
977
  retainUntil?: Date;
890
978
 
@@ -892,15 +980,16 @@ export interface UploadOptions {
892
980
  }
893
981
 
894
982
  /**
895
- * Options for `uploadIfMatch`: those of `upload`, without preconditions.
983
+ * Options for {@link Bucket.uploadIfMatch} (all {@link UploadOptions} except
984
+ * `preconditions`).
896
985
  */
897
986
  export type UploadIfMatchOptions = Omit<UploadOptions, 'preconditions'>;
898
987
 
899
988
  /**
900
- * The attributes `updateAttrs` replaces. An attribute left out stays as it
901
- * is, and an empty string clears it; a cleared `contentType` is
902
- * `application/octet-stream`. `metadata` replaces the whole map, so `{}`
903
- * clears it.
989
+ * Attributes to update via {@link Bucket.updateAttrs}. Omitted fields remain
990
+ * unchanged; an empty string clears a field (clearing `contentType` resets it
991
+ * to `application/octet-stream`). `metadata` replaces the entire map (`{}`
992
+ * clears it).
904
993
  */
905
994
  export interface UpdateAttrs {
906
995
  contentType?: string;
@@ -913,13 +1002,13 @@ export interface UpdateAttrs {
913
1002
  * Options for updating an object's attributes.
914
1003
  */
915
1004
  export interface UpdateAttrsOptions {
916
- /** The object version to update. Defaults to the latest. */
1005
+ /** Object version to update. Defaults to the latest version. */
917
1006
  version?: string;
918
1007
 
919
1008
  preconditions?: {
920
1009
  /**
921
- * Only update the object if it is still this revision.
922
- * Throws `PreconditionFailed` otherwise.
1010
+ * Only update the object if it still matches this revision; throws
1011
+ * `PreconditionFailed` otherwise.
923
1012
  */
924
1013
  ifMatch?: Revision;
925
1014
  };
@@ -929,7 +1018,7 @@ export interface UpdateAttrsOptions {
929
1018
  * Options for extending an object's retention.
930
1019
  */
931
1020
  export interface ExtendRetentionOptions {
932
- /** The object version to retain. Defaults to the latest. */
1021
+ /** Object version to retain. Defaults to the latest version. */
933
1022
  version?: string;
934
1023
  }
935
1024
 
@@ -937,9 +1026,9 @@ export interface ExtendRetentionOptions {
937
1026
  * Options for generating a signed upload URL.
938
1027
  */
939
1028
  export interface UploadUrlOptions {
940
- /** The expiration time of the url, in seconds from signing. The maximum
941
- * value is seven days. If no value is given, a default of one hour is
942
- * used. */
1029
+ /**
1030
+ * URL lifetime in seconds from creation (maximum 7 days; defaults to 1 hour).
1031
+ */
943
1032
  ttl?: number;
944
1033
  }
945
1034
 
@@ -954,9 +1043,9 @@ export interface SignedUploadUrl {
954
1043
  * Options for generating a signed download URL.
955
1044
  */
956
1045
  export interface DownloadUrlOptions {
957
- /** The expiration time of the url, in seconds from signing. The maximum
958
- * value is seven days. If no value is given, a default of one hour is
959
- * used. */
1046
+ /**
1047
+ * URL lifetime in seconds from creation (maximum 7 days; defaults to 1 hour).
1048
+ */
960
1049
  ttl?: number;
961
1050
  }
962
1051