@encore.dev/sdk 2.0.0-beta.7 → 2.0.0-beta.8

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 (356) hide show
  1. package/README.md +55 -0
  2. package/app_meta.ts +8 -0
  3. package/config/config.test.ts +10 -3
  4. package/config/config.ts +75 -21
  5. package/config/mod.ts +4 -3
  6. package/config/secrets.ts +72 -55
  7. package/cron/mod.ts +32 -0
  8. package/dist/app_meta.d.ts +7 -0
  9. package/dist/app_meta.d.ts.map +1 -0
  10. package/dist/app_meta.js +1 -0
  11. package/dist/app_meta.js.map +1 -1
  12. package/dist/config/config.d.ts +44 -18
  13. package/dist/config/config.d.ts.map +1 -0
  14. package/dist/config/config.js +43 -18
  15. package/dist/config/config.js.map +1 -1
  16. package/dist/config/mod.d.ts +5 -4
  17. package/dist/config/mod.d.ts.map +1 -0
  18. package/dist/config/mod.js +2 -2
  19. package/dist/config/mod.js.map +1 -1
  20. package/dist/config/secrets.d.ts +62 -39
  21. package/dist/config/secrets.d.ts.map +1 -0
  22. package/dist/config/secrets.js +21 -37
  23. package/dist/config/secrets.js.map +1 -1
  24. package/dist/config/value.d.ts +1 -0
  25. package/dist/config/value.d.ts.map +1 -0
  26. package/dist/cron/mod.d.ts +31 -0
  27. package/dist/cron/mod.d.ts.map +1 -0
  28. package/dist/cron/mod.js +23 -0
  29. package/dist/cron/mod.js.map +1 -1
  30. package/dist/gateway/errors.d.ts +101 -0
  31. package/dist/gateway/errors.d.ts.map +1 -0
  32. package/dist/gateway/errors.js +146 -0
  33. package/dist/gateway/errors.js.map +1 -0
  34. package/dist/gateway/match.d.ts +127 -0
  35. package/dist/gateway/match.d.ts.map +1 -0
  36. package/dist/gateway/match.js +206 -0
  37. package/dist/gateway/match.js.map +1 -0
  38. package/dist/gateway/middleware.d.ts +108 -0
  39. package/dist/gateway/middleware.d.ts.map +1 -0
  40. package/dist/gateway/middleware.js +9 -0
  41. package/dist/gateway/middleware.js.map +1 -0
  42. package/dist/gateway/mod.d.ts +129 -0
  43. package/dist/gateway/mod.d.ts.map +1 -0
  44. package/dist/gateway/mod.js +187 -0
  45. package/dist/gateway/mod.js.map +1 -0
  46. package/dist/gateway/request.d.ts +304 -0
  47. package/dist/gateway/request.d.ts.map +1 -0
  48. package/dist/gateway/request.js +403 -0
  49. package/dist/gateway/request.js.map +1 -0
  50. package/dist/gateway/serve.d.ts +114 -0
  51. package/dist/gateway/serve.d.ts.map +1 -0
  52. package/dist/gateway/serve.js +510 -0
  53. package/dist/gateway/serve.js.map +1 -0
  54. package/dist/internal/clients/call.d.ts +147 -0
  55. package/dist/internal/clients/call.d.ts.map +1 -0
  56. package/dist/internal/clients/call.js +274 -0
  57. package/dist/internal/clients/call.js.map +1 -0
  58. package/dist/internal/clients/grpc.d.ts +90 -0
  59. package/dist/internal/clients/grpc.d.ts.map +1 -0
  60. package/dist/internal/clients/grpc.js +355 -0
  61. package/dist/internal/clients/grpc.js.map +1 -0
  62. package/dist/internal/clients/mod.d.ts +81 -0
  63. package/dist/internal/clients/mod.d.ts.map +1 -0
  64. package/dist/internal/clients/mod.js +237 -0
  65. package/dist/internal/clients/mod.js.map +1 -0
  66. package/dist/internal/fetch.d.ts +54 -0
  67. package/dist/internal/fetch.d.ts.map +1 -0
  68. package/dist/internal/fetch.js +240 -0
  69. package/dist/internal/fetch.js.map +1 -0
  70. package/dist/internal/otel/backend.d.ts +2 -0
  71. package/dist/internal/otel/backend.d.ts.map +1 -0
  72. package/dist/internal/otel/context.d.ts +1 -0
  73. package/dist/internal/otel/context.d.ts.map +1 -0
  74. package/dist/internal/otel/context_manager.d.ts +1 -0
  75. package/dist/internal/otel/context_manager.d.ts.map +1 -0
  76. package/dist/internal/otel/encode.d.ts +2 -0
  77. package/dist/internal/otel/encode.d.ts.map +1 -0
  78. package/dist/internal/otel/index.d.ts +2 -2
  79. package/dist/internal/otel/index.d.ts.map +1 -0
  80. package/dist/internal/otel/index.js +1 -2
  81. package/dist/internal/otel/index.js.map +1 -1
  82. package/dist/internal/otel/meter.d.ts +1 -0
  83. package/dist/internal/otel/meter.d.ts.map +1 -0
  84. package/dist/internal/otel/propagator.d.ts +1 -0
  85. package/dist/internal/otel/propagator.d.ts.map +1 -0
  86. package/dist/internal/otel/provider.d.ts +1 -0
  87. package/dist/internal/otel/provider.d.ts.map +1 -0
  88. package/dist/internal/otel/span.d.ts +4 -0
  89. package/dist/internal/otel/span.d.ts.map +1 -0
  90. package/dist/internal/otel/span.js +5 -0
  91. package/dist/internal/otel/span.js.map +1 -1
  92. package/dist/internal/otel/tracer.d.ts +1 -0
  93. package/dist/internal/otel/tracer.d.ts.map +1 -0
  94. package/dist/internal/otel/tracer.js +11 -5
  95. package/dist/internal/otel/tracer.js.map +1 -1
  96. package/dist/internal/reqfields.d.ts +150 -0
  97. package/dist/internal/reqfields.d.ts.map +1 -0
  98. package/dist/internal/reqfields.js +312 -0
  99. package/dist/internal/reqfields.js.map +1 -0
  100. package/dist/internal/runtime/meter.d.ts +1 -0
  101. package/dist/internal/runtime/meter.d.ts.map +1 -0
  102. package/dist/internal/runtime/mod.d.ts +6 -0
  103. package/dist/internal/runtime/mod.d.ts.map +1 -0
  104. package/dist/internal/runtime/mod.js +32 -2
  105. package/dist/internal/runtime/mod.js.map +1 -1
  106. package/dist/internal/runtime/napi/napi.cjs +160 -16
  107. package/dist/internal/runtime/napi/napi.d.cts +474 -29
  108. package/dist/internal/runtime/shutdown.d.ts +5 -0
  109. package/dist/internal/runtime/shutdown.d.ts.map +1 -0
  110. package/dist/internal/runtime/shutdown.js +9 -1
  111. package/dist/internal/runtime/shutdown.js.map +1 -1
  112. package/dist/internal/testing/runner.d.ts +2 -0
  113. package/dist/internal/testing/runner.d.ts.map +1 -0
  114. package/dist/internal/testing/runner.js +10 -0
  115. package/dist/internal/testing/runner.js.map +1 -0
  116. package/dist/internal/testing/scope.d.ts +81 -0
  117. package/dist/internal/testing/scope.d.ts.map +1 -0
  118. package/dist/internal/testing/scope.js +237 -0
  119. package/dist/internal/testing/scope.js.map +1 -0
  120. package/dist/internal/utils/constraints.d.ts +1 -0
  121. package/dist/internal/utils/constraints.d.ts.map +1 -0
  122. package/dist/log/index.d.ts +1 -0
  123. package/dist/log/index.d.ts.map +1 -0
  124. package/dist/log/logger.d.ts +2 -0
  125. package/dist/log/logger.d.ts.map +1 -0
  126. package/dist/log/runtime.d.ts +2 -0
  127. package/dist/log/runtime.d.ts.map +1 -0
  128. package/dist/log/stderr.d.ts +1 -0
  129. package/dist/log/stderr.d.ts.map +1 -0
  130. package/dist/metrics/mod.d.ts +45 -118
  131. package/dist/metrics/mod.d.ts.map +1 -0
  132. package/dist/metrics/mod.js +44 -179
  133. package/dist/metrics/mod.js.map +1 -1
  134. package/dist/mod.d.ts +1 -2
  135. package/dist/mod.d.ts.map +1 -0
  136. package/dist/mod.js +0 -1
  137. package/dist/mod.js.map +1 -1
  138. package/dist/otel.d.ts +1 -0
  139. package/dist/otel.d.ts.map +1 -0
  140. package/dist/pubsub/encoding.d.ts +5 -0
  141. package/dist/pubsub/encoding.d.ts.map +1 -0
  142. package/dist/pubsub/encoding.js +10 -2
  143. package/dist/pubsub/encoding.js.map +1 -1
  144. package/dist/pubsub/mod.d.ts +4 -3
  145. package/dist/pubsub/mod.d.ts.map +1 -0
  146. package/dist/pubsub/mod.js +2 -2
  147. package/dist/pubsub/mod.js.map +1 -1
  148. package/dist/pubsub/refs.d.ts +8 -0
  149. package/dist/pubsub/refs.d.ts.map +1 -0
  150. package/dist/pubsub/refs.js.map +1 -1
  151. package/dist/pubsub/subscription.d.ts +104 -10
  152. package/dist/pubsub/subscription.d.ts.map +1 -0
  153. package/dist/pubsub/subscription.js +98 -16
  154. package/dist/pubsub/subscription.js.map +1 -1
  155. package/dist/pubsub/topic.d.ts +87 -23
  156. package/dist/pubsub/topic.d.ts.map +1 -0
  157. package/dist/pubsub/topic.js +143 -40
  158. package/dist/pubsub/topic.js.map +1 -1
  159. package/dist/reqctx/mod.d.ts +191 -0
  160. package/dist/reqctx/mod.d.ts.map +1 -0
  161. package/dist/reqctx/mod.js +160 -0
  162. package/dist/reqctx/mod.js.map +1 -0
  163. package/dist/services/index.d.ts +145 -4
  164. package/dist/services/index.d.ts.map +1 -0
  165. package/dist/services/index.js +155 -8
  166. package/dist/services/index.js.map +1 -1
  167. package/dist/shutdown/mod.d.ts +1 -0
  168. package/dist/shutdown/mod.d.ts.map +1 -0
  169. package/dist/storage/objects/bucket.d.ts +312 -7
  170. package/dist/storage/objects/bucket.d.ts.map +1 -0
  171. package/dist/storage/objects/bucket.js +305 -15
  172. package/dist/storage/objects/bucket.js.map +1 -1
  173. package/dist/storage/objects/error.d.ts +10 -0
  174. package/dist/storage/objects/error.d.ts.map +1 -0
  175. package/dist/storage/objects/error.js +25 -1
  176. package/dist/storage/objects/error.js.map +1 -1
  177. package/dist/storage/objects/mod.d.ts +4 -3
  178. package/dist/storage/objects/mod.d.ts.map +1 -0
  179. package/dist/storage/objects/mod.js +1 -1
  180. package/dist/storage/objects/mod.js.map +1 -1
  181. package/dist/storage/objects/refs.d.ts +20 -4
  182. package/dist/storage/objects/refs.d.ts.map +1 -0
  183. package/dist/storage/objects/refs.js +6 -0
  184. package/dist/storage/objects/refs.js.map +1 -1
  185. package/dist/storage/postgres/database.d.ts +81 -25
  186. package/dist/storage/postgres/database.d.ts.map +1 -0
  187. package/dist/storage/postgres/database.js +125 -37
  188. package/dist/storage/postgres/database.js.map +1 -1
  189. package/dist/storage/postgres/errors.d.ts +120 -0
  190. package/dist/storage/postgres/errors.d.ts.map +1 -0
  191. package/dist/storage/postgres/errors.js +162 -0
  192. package/dist/storage/postgres/errors.js.map +1 -0
  193. package/dist/storage/postgres/interval.d.ts +44 -0
  194. package/dist/storage/postgres/interval.d.ts.map +1 -0
  195. package/dist/storage/postgres/interval.js +153 -0
  196. package/dist/storage/postgres/interval.js.map +1 -0
  197. package/dist/storage/postgres/mod.d.ts +4 -1
  198. package/dist/storage/postgres/mod.d.ts.map +1 -0
  199. package/dist/storage/postgres/mod.js +2 -0
  200. package/dist/storage/postgres/mod.js.map +1 -1
  201. package/dist/storage/redis/bitfield.d.ts +67 -0
  202. package/dist/storage/redis/bitfield.d.ts.map +1 -0
  203. package/dist/storage/redis/bitfield.js +114 -0
  204. package/dist/storage/redis/bitfield.js.map +1 -0
  205. package/dist/storage/redis/command.d.ts +45 -0
  206. package/dist/storage/redis/command.d.ts.map +1 -0
  207. package/dist/storage/redis/command.js +78 -0
  208. package/dist/storage/redis/command.js.map +1 -0
  209. package/dist/storage/redis/commands.d.ts +223 -139
  210. package/dist/storage/redis/commands.d.ts.map +1 -0
  211. package/dist/storage/redis/commands.js +128 -6
  212. package/dist/storage/redis/commands.js.map +1 -1
  213. package/dist/storage/redis/database.d.ts +56 -22
  214. package/dist/storage/redis/database.d.ts.map +1 -0
  215. package/dist/storage/redis/database.js +62 -0
  216. package/dist/storage/redis/database.js.map +1 -1
  217. package/dist/storage/redis/mod.d.ts +31 -4
  218. package/dist/storage/redis/mod.d.ts.map +1 -0
  219. package/dist/storage/redis/mod.js +26 -1
  220. package/dist/storage/redis/mod.js.map +1 -1
  221. package/dist/storage/redis/native.d.ts +8 -0
  222. package/dist/storage/redis/native.d.ts.map +1 -0
  223. package/dist/storage/redis/native.js +10 -0
  224. package/dist/storage/redis/native.js.map +1 -1
  225. package/dist/storage/redis/options.d.ts +1 -0
  226. package/dist/storage/redis/options.d.ts.map +1 -0
  227. package/dist/storage/redis/pubsub.d.ts +2 -0
  228. package/dist/storage/redis/pubsub.d.ts.map +1 -0
  229. package/dist/storage/redis/reply.d.ts +34 -0
  230. package/dist/storage/redis/reply.d.ts.map +1 -0
  231. package/dist/storage/redis/reply.js +40 -1
  232. package/dist/storage/redis/reply.js.map +1 -1
  233. package/dist/storage/redis/scan.d.ts +1 -0
  234. package/dist/storage/redis/scan.d.ts.map +1 -0
  235. package/dist/storage/redis/script.d.ts +1 -0
  236. package/dist/storage/redis/script.d.ts.map +1 -0
  237. package/dist/storage/redis/target.d.ts +5 -3
  238. package/dist/storage/redis/target.d.ts.map +1 -0
  239. package/dist/storage/redis/target.js +39 -28
  240. package/dist/storage/redis/target.js.map +1 -1
  241. package/dist/storage/redis/wire.d.ts +7 -10
  242. package/dist/storage/redis/wire.d.ts.map +1 -0
  243. package/dist/storage/redis/wire.js +8 -32
  244. package/dist/storage/redis/wire.js.map +1 -1
  245. package/dist/testing/bun.d.ts +8 -0
  246. package/dist/testing/bun.d.ts.map +1 -0
  247. package/dist/testing/bun.js +13 -0
  248. package/dist/testing/bun.js.map +1 -0
  249. package/dist/testing/jest.d.ts +8 -0
  250. package/dist/testing/jest.d.ts.map +1 -0
  251. package/dist/testing/jest.js +11 -0
  252. package/dist/testing/jest.js.map +1 -0
  253. package/dist/testing/mod.d.ts +160 -0
  254. package/dist/testing/mod.d.ts.map +1 -0
  255. package/dist/testing/mod.js +227 -0
  256. package/dist/testing/mod.js.map +1 -0
  257. package/dist/testing/node.d.ts +9 -0
  258. package/dist/testing/node.d.ts.map +1 -0
  259. package/dist/testing/node.js +12 -0
  260. package/dist/testing/node.js.map +1 -0
  261. package/dist/testing/vitest.d.ts +8 -0
  262. package/dist/testing/vitest.d.ts.map +1 -0
  263. package/dist/testing/vitest.js +13 -0
  264. package/dist/testing/vitest.js.map +1 -0
  265. package/dist/tracing/mod.d.ts +19 -0
  266. package/dist/tracing/mod.d.ts.map +1 -0
  267. package/dist/tracing/mod.js +46 -0
  268. package/dist/tracing/mod.js.map +1 -0
  269. package/dist/tsconfig.build.tsbuildinfo +1 -1
  270. package/dist/types/mod.d.ts +1 -0
  271. package/dist/types/mod.d.ts.map +1 -0
  272. package/gateway/errors.ts +172 -0
  273. package/gateway/gateway.e2e.test.ts +297 -0
  274. package/gateway/gateway.test.ts +891 -0
  275. package/gateway/match.ts +239 -0
  276. package/gateway/middleware.ts +134 -0
  277. package/gateway/mod.ts +210 -0
  278. package/gateway/request.ts +578 -0
  279. package/gateway/serve.ts +738 -0
  280. package/internal/clients/call.ts +389 -0
  281. package/internal/clients/grpc.test.ts +368 -0
  282. package/internal/clients/grpc.ts +485 -0
  283. package/internal/clients/mod.test.ts +464 -0
  284. package/internal/clients/mod.ts +337 -0
  285. package/internal/fetch.ts +276 -0
  286. package/internal/otel/index.ts +1 -7
  287. package/internal/otel/span.ts +6 -0
  288. package/internal/otel/tracer.test.ts +43 -15
  289. package/internal/otel/tracer.ts +12 -5
  290. package/internal/reqfields.ts +390 -0
  291. package/internal/runtime/mod.ts +41 -2
  292. package/internal/runtime/napi/napi.cjs +160 -16
  293. package/internal/runtime/napi/napi.d.cts +474 -29
  294. package/internal/runtime/shutdown.ts +11 -1
  295. package/internal/testing/runner.ts +10 -0
  296. package/internal/testing/scope.ts +273 -0
  297. package/metrics/mod.test.ts +13 -16
  298. package/metrics/mod.ts +57 -226
  299. package/mod.ts +0 -8
  300. package/otel.test.ts +13 -6
  301. package/package.json +67 -15
  302. package/pubsub/encoding.ts +11 -1
  303. package/pubsub/mod.ts +10 -3
  304. package/pubsub/pubsub.test.ts +232 -14
  305. package/pubsub/refs.ts +16 -0
  306. package/pubsub/subscription.ts +194 -16
  307. package/pubsub/topic.test.ts +26 -0
  308. package/pubsub/topic.ts +220 -25
  309. package/reqctx/mod.ts +284 -0
  310. package/reqctx/reqctx.test.ts +193 -0
  311. package/scripts/postprocess-docs.test.ts +48 -0
  312. package/services/index.test.ts +341 -1
  313. package/services/index.ts +183 -8
  314. package/storage/objects/bucket.test.ts +573 -0
  315. package/storage/objects/bucket.ts +649 -20
  316. package/storage/objects/error.ts +28 -1
  317. package/storage/objects/mod.ts +15 -0
  318. package/storage/objects/refs.ts +51 -3
  319. package/storage/postgres/database.integration.test.ts +275 -0
  320. package/storage/postgres/database.test.ts +193 -6
  321. package/storage/postgres/database.ts +202 -55
  322. package/storage/postgres/errors.ts +186 -0
  323. package/storage/postgres/interval.test.ts +72 -0
  324. package/storage/postgres/interval.ts +170 -0
  325. package/storage/postgres/mod.ts +4 -0
  326. package/storage/redis/bitfield.ts +162 -0
  327. package/storage/redis/command.ts +84 -0
  328. package/storage/redis/commands.ts +271 -21
  329. package/storage/redis/database.ts +77 -23
  330. package/storage/redis/mod.ts +38 -2
  331. package/storage/redis/native.ts +11 -0
  332. package/storage/redis/redis.test.ts +170 -10
  333. package/storage/redis/reply.ts +76 -1
  334. package/storage/redis/runtime.test.ts +15 -0
  335. package/storage/redis/target.ts +47 -44
  336. package/storage/redis/wire.ts +8 -32
  337. package/testing/bun.ts +13 -0
  338. package/testing/jest.ts +11 -0
  339. package/testing/mod.ts +337 -0
  340. package/testing/node.ts +12 -0
  341. package/testing/vitest.ts +13 -0
  342. package/tracing/mod.ts +82 -0
  343. package/tracing/native.test.ts +170 -0
  344. package/tracing/tracing.test.ts +317 -0
  345. package/dist/internal/otel/request_context.d.ts +0 -11
  346. package/dist/internal/otel/request_context.js +0 -20
  347. package/dist/internal/otel/request_context.js.map +0 -1
  348. package/dist/internal/reqtrack/mod.d.ts +0 -6
  349. package/dist/internal/reqtrack/mod.js +0 -28
  350. package/dist/internal/reqtrack/mod.js.map +0 -1
  351. package/dist/req_meta.d.ts +0 -47
  352. package/dist/req_meta.js +0 -26
  353. package/dist/req_meta.js.map +0 -1
  354. package/internal/otel/request_context.ts +0 -32
  355. package/internal/reqtrack/mod.ts +0 -39
  356. package/req_meta.ts +0 -75
@@ -1,7 +1,8 @@
1
1
  import {activeCtxBytes} from '../../internal/otel/index';
2
2
  import * as runtime from '../../internal/runtime/mod';
3
+ import {currentScope, testMode} from '../../internal/testing/scope';
3
4
  import {StringLiteral} from '../../internal/utils/constraints';
4
- import {unwrapErr} from './error';
5
+ import {InvalidArgument, unwrapErr} from './error';
5
6
  import {
6
7
  BucketPerms,
7
8
  Uploader,
@@ -12,10 +13,31 @@ import {
12
13
  Lister,
13
14
  Remover,
14
15
  PublicUrler,
16
+ AttrsUpdater,
17
+ IfMatchUploader,
18
+ IfMatchRemover,
15
19
  } from './refs';
16
20
 
21
+ /**
22
+ * How often an object is expected to be read, which the cloud provider
23
+ * prices its storage by.
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.
31
+ *
32
+ * Every class can be read immediately.
33
+ */
34
+ export type StorageClass = 'standard' | 'infrequent' | 'cold';
35
+
17
36
  /**
18
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.
19
41
  */
20
42
  export interface BucketConfig {
21
43
  /**
@@ -29,6 +51,93 @@ export interface BucketConfig {
29
51
  * Defaults to false if unset.
30
52
  */
31
53
  versioned?: boolean;
54
+
55
+ /**
56
+ * The storage class of an object uploaded without one.
57
+ * Defaults to `"standard"`.
58
+ *
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.
63
+ */
64
+ storageClass?: StorageClass | 'auto';
65
+
66
+ /**
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.
70
+ */
71
+ lifecycle?: LifecycleRule[];
72
+
73
+ /**
74
+ * Keep every object for at least this long after it was written: it
75
+ * can't be deleted or overwritten sooner.
76
+ */
77
+ retention?: Retention;
78
+
79
+ /**
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.
83
+ */
84
+ objectRetention?: boolean;
85
+
86
+ /**
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.
91
+ */
92
+ tags?: Record<string, string>;
93
+ }
94
+
95
+ /**
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.
99
+ */
100
+ export interface LifecycleRule {
101
+ /** Only objects whose names start with it. Defaults to every object. */
102
+ prefix?: string;
103
+
104
+ /**
105
+ * Move an object to `infrequent` this many days after it was written.
106
+ * At least 30.
107
+ */
108
+ moveToInfrequentAfterDays?: number;
109
+
110
+ /**
111
+ * Move an object to `cold` this many days after it was written. With
112
+ * `moveToInfrequentAfterDays`, at least 30 days after it.
113
+ */
114
+ moveToColdAfterDays?: number;
115
+
116
+ /**
117
+ * Delete an object this many days after it was written. In a versioned
118
+ * bucket it becomes a noncurrent version, as `remove` does.
119
+ */
120
+ deleteAfterDays?: number;
121
+
122
+ /**
123
+ * Versioned buckets: delete a noncurrent version this many days after it
124
+ * was replaced or removed.
125
+ */
126
+ deleteNoncurrentAfterDays?: number;
127
+
128
+ /**
129
+ * Versioned buckets: never delete the newest this many noncurrent
130
+ * versions. On its own, delete the noncurrent versions beyond them.
131
+ */
132
+ keepNoncurrentVersions?: number;
133
+ }
134
+
135
+ /**
136
+ * A bucket's retention period.
137
+ */
138
+ export interface Retention {
139
+ /** The days, from 1 to 36500, an object is kept after it was written. */
140
+ days: number;
32
141
  }
33
142
 
34
143
  /**
@@ -44,9 +153,14 @@ export class Bucket
44
153
  Attrser,
45
154
  Lister,
46
155
  Remover,
47
- PublicUrler
156
+ PublicUrler,
157
+ AttrsUpdater,
158
+ IfMatchUploader,
159
+ IfMatchRemover
48
160
  {
49
- impl: runtime.Bucket;
161
+ private readonly bucketName: string;
162
+ /** The runtime's bucket: made on first use in test mode. */
163
+ private own?: runtime.Bucket;
50
164
 
51
165
  /**
52
166
  * Creates a new bucket with the given name and configuration
@@ -54,7 +168,16 @@ export class Bucket
54
168
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
55
169
  constructor(name: string, cfg?: BucketConfig) {
56
170
  super();
57
- this.impl = runtime.RT.bucket(name);
171
+ this.bucketName = name;
172
+ if (!testMode) this.own = runtime.RT.bucket(name);
173
+ }
174
+
175
+ /** The native bucket: in a test, the test's instance of it. */
176
+ get impl(): runtime.Bucket {
177
+ return (
178
+ currentScope()?.bucket(this.bucketName) ??
179
+ (this.own ??= runtime.RT.bucket(this.bucketName))
180
+ );
58
181
  }
59
182
 
60
183
  /**
@@ -65,16 +188,70 @@ export class Bucket
65
188
  return new Bucket(name, {});
66
189
  }
67
190
 
68
- async *list(options: ListOptions): AsyncGenerator<ListEntry> {
191
+ /**
192
+ * Lists the objects in the bucket, sorted by name.
193
+ *
194
+ * With a `delimiter`, the names that continue past the `prefix` with the
195
+ * delimiter are grouped into one entry per common prefix, with
196
+ * `isPrefix` set, as a directory listing does.
197
+ */
198
+ async *list(options?: ListOptions): AsyncGenerator<ListEntry> {
69
199
  const source = activeCtxBytes();
70
- const iter = unwrapErr(await this.impl.list(options, source));
71
- while (true) {
72
- const entry = await iter.next();
73
- if (entry === null) {
74
- iter.markDone();
75
- break;
200
+ const iter = unwrapErr(
201
+ await this.impl.list(
202
+ {
203
+ prefix: options?.prefix,
204
+ limit: options?.limit,
205
+ delimiter: options?.delimiter,
206
+ },
207
+ source,
208
+ ),
209
+ );
210
+ try {
211
+ while (true) {
212
+ const entry = unwrapErr(await iter.next());
213
+ if (entry === null) {
214
+ break;
215
+ }
216
+ yield entry;
217
+ }
218
+ } finally {
219
+ iter.markDone();
220
+ }
221
+ }
222
+
223
+ /**
224
+ * Lists every stored version of the objects in the bucket, sorted by
225
+ * name and then newest first. A removed object has no `latest` version.
226
+ * An unversioned bucket lists one latest version per object.
227
+ */
228
+ async *listVersions(
229
+ options?: ListVersionsOptions,
230
+ ): AsyncGenerator<ObjectVersion> {
231
+ const source = activeCtxBytes();
232
+ const iter = unwrapErr(
233
+ await this.impl.listVersions(
234
+ {prefix: options?.prefix, limit: options?.limit},
235
+ source,
236
+ ),
237
+ );
238
+ try {
239
+ while (true) {
240
+ const version = unwrapErr(await iter.next());
241
+ if (version === null) {
242
+ break;
243
+ }
244
+ yield {
245
+ name: version.name,
246
+ version: version.version,
247
+ size: version.size,
248
+ etag: version.etag,
249
+ latest: version.latest,
250
+ lastModified: toDate(version.lastModified),
251
+ };
76
252
  }
77
- yield entry;
253
+ } finally {
254
+ iter.markDone();
78
255
  }
79
256
  }
80
257
 
@@ -97,7 +274,7 @@ export class Bucket
97
274
  const source = activeCtxBytes();
98
275
  const impl = this.impl.object(name);
99
276
  const res = await impl.attrs(options, source);
100
- return unwrapErr(res);
277
+ return toAttrs(unwrapErr(res));
101
278
  }
102
279
 
103
280
  /**
@@ -105,13 +282,118 @@ export class Bucket
105
282
  */
106
283
  async upload(
107
284
  name: string,
108
- data: Buffer,
285
+ data: Uint8Array,
286
+ options?: UploadOptions,
287
+ ): Promise<ObjectAttrs> {
288
+ return uploadChunks(
289
+ this.impl.object(name),
290
+ slices(data),
291
+ uploadOptions(options),
292
+ );
293
+ }
294
+
295
+ /**
296
+ * Uploads an object to the bucket from a stream of bytes: a Web
297
+ * `ReadableStream`, a Node.js `Readable`, or any async iterable of
298
+ * `Uint8Array` chunks. The stream is read as fast as the upload takes
299
+ * its bytes.
300
+ *
301
+ * If the stream errors, the upload is aborted and nothing is stored.
302
+ */
303
+ async uploadStream(
304
+ name: string,
305
+ data: AsyncIterable<Uint8Array> | ReadableStream<Uint8Array>,
109
306
  options?: UploadOptions,
307
+ ): Promise<ObjectAttrs> {
308
+ return uploadChunks(
309
+ this.impl.object(name),
310
+ chunks(data, STREAM_EXPECTED),
311
+ uploadOptions(options),
312
+ );
313
+ }
314
+
315
+ /**
316
+ * Uploads an object only if the bucket still holds the given revision of
317
+ * it, as `attrs`, `upload`, `updateAttrs` or a listing returned it, and
318
+ * throws `PreconditionFailed` otherwise, also if the object no longer
319
+ * exists. This makes read-modify-write safe against concurrent writers.
320
+ * A missing revision throws `InvalidArgument`.
321
+ *
322
+ * `data` is bytes or a stream, as `upload` and `uploadStream` take.
323
+ *
324
+ * The match compares the object's contents, not its attributes:
325
+ * `updateAttrs` doesn't break it. Google Cloud Storage matches the
326
+ * revision's `version`, so a revision without one throws
327
+ * `InvalidArgument` there; Amazon S3 and Cloudflare R2 match its `etag`.
328
+ *
329
+ * On Amazon S3 a conditional write also needs read access to the bucket,
330
+ * which Encore grants to the services that call this.
331
+ */
332
+ async uploadIfMatch(
333
+ name: string,
334
+ data: Uint8Array | AsyncIterable<Uint8Array> | ReadableStream<Uint8Array>,
335
+ revision: Revision,
336
+ options?: UploadIfMatchOptions,
337
+ ): Promise<ObjectAttrs> {
338
+ const ifMatch = requiredRevision('uploadIfMatch', revision);
339
+ const body =
340
+ data instanceof Uint8Array ? slices(data) : chunks(data, BODY_EXPECTED);
341
+ return uploadChunks(this.impl.object(name), body, {
342
+ ...uploadOptions(options),
343
+ preconditions: {ifMatch},
344
+ });
345
+ }
346
+
347
+ /**
348
+ * Replaces the given attributes of an object and leaves the others as
349
+ * they are. An empty string clears an attribute (a cleared content type
350
+ * is `application/octet-stream`, as S3 keeps no object without one), and
351
+ * `metadata` replaces the whole map.
352
+ *
353
+ * On S3 this rewrites the object, so a versioned bucket gets a new
354
+ * version, and the object's age for lifecycle rules starts over.
355
+ */
356
+ async updateAttrs(
357
+ name: string,
358
+ attrs: UpdateAttrs,
359
+ options?: UpdateAttrsOptions,
110
360
  ): Promise<ObjectAttrs> {
111
361
  const source = activeCtxBytes();
112
362
  const impl = this.impl.object(name);
113
- const res = await impl.upload(data, options, source);
114
- return unwrapErr(res);
363
+ const res = await impl.updateAttrs(
364
+ {
365
+ contentType: attrs.contentType,
366
+ cacheControl: attrs.cacheControl,
367
+ contentDisposition: attrs.contentDisposition,
368
+ metadata: attrs.metadata,
369
+ },
370
+ {
371
+ version: options?.version,
372
+ ifMatch: toRevision(options?.preconditions?.ifMatch),
373
+ },
374
+ source,
375
+ );
376
+ return toAttrs(unwrapErr(res));
377
+ }
378
+
379
+ /**
380
+ * Keeps the object until `until` at least. Retention can only be
381
+ * extended: a time earlier than the object's current one throws
382
+ * `InvalidArgument`. The bucket must be declared with `objectRetention`.
383
+ */
384
+ async extendRetention(
385
+ name: string,
386
+ until: Date,
387
+ options?: ExtendRetentionOptions,
388
+ ): Promise<ObjectAttrs> {
389
+ const source = activeCtxBytes();
390
+ const impl = this.impl.object(name);
391
+ const res = await impl.extendRetention(
392
+ until.getTime(),
393
+ {version: options?.version},
394
+ source,
395
+ );
396
+ return toAttrs(unwrapErr(res));
115
397
  }
116
398
 
117
399
  /**
@@ -119,6 +401,9 @@ export class Bucket
119
401
  *
120
402
  * Anyone with possession of the URL can write to the given object name
121
403
  * without any additional auth.
404
+ *
405
+ * The URL doesn't carry the bucket's storage class: an object uploaded
406
+ * through it gets the provider's default class for the bucket.
122
407
  */
123
408
  async signedUploadUrl(
124
409
  name: string,
@@ -152,10 +437,45 @@ export class Bucket
152
437
  async download(name: string, options?: DownloadOptions): Promise<Buffer> {
153
438
  const source = activeCtxBytes();
154
439
  const impl = this.impl.object(name);
155
- const res = await impl.downloadAll(options, source);
440
+ const res = await impl.downloadAll(downloadOptions(options), source);
156
441
  return unwrapErr(res);
157
442
  }
158
443
 
444
+ /**
445
+ * Downloads an object from the bucket as a Web `ReadableStream`, read
446
+ * from the provider as the consumer reads it. A missing object throws
447
+ * here, before any bytes. Cancelling the stream stops the download.
448
+ *
449
+ * In Node.js, `Readable.fromWeb` converts it to a Node.js stream.
450
+ */
451
+ async downloadStream(
452
+ name: string,
453
+ options?: DownloadOptions,
454
+ ): Promise<ReadableStream<Uint8Array>> {
455
+ const source = activeCtxBytes();
456
+ const impl = this.impl.object(name);
457
+ const stream = unwrapErr(
458
+ await impl.downloadStream(downloadOptions(options), source),
459
+ );
460
+ return new ReadableStream<Uint8Array>(
461
+ {
462
+ async pull(controller) {
463
+ const chunk = unwrapErr(await stream.next());
464
+ if (chunk === null) {
465
+ controller.close();
466
+ } else {
467
+ controller.enqueue(chunk);
468
+ }
469
+ },
470
+ async cancel() {
471
+ await stream.close();
472
+ },
473
+ },
474
+ // Read ahead of the consumer by nothing.
475
+ {highWaterMark: 0},
476
+ );
477
+ }
478
+
159
479
  /**
160
480
  * Removes an object from the bucket.
161
481
  * Throws an error on network failure.
@@ -163,7 +483,32 @@ export class Bucket
163
483
  async remove(name: string, options?: DeleteOptions): Promise<void> {
164
484
  const source = activeCtxBytes();
165
485
  const impl = this.impl.object(name);
166
- const err = await impl.delete(options, source);
486
+ const err = await impl.delete({version: options?.version}, source);
487
+ if (err) {
488
+ unwrapErr(err);
489
+ }
490
+ }
491
+
492
+ /**
493
+ * Removes an object only if the bucket still holds the given revision of
494
+ * it, as `attrs`, `upload`, `updateAttrs` or a listing returned it, and
495
+ * throws `PreconditionFailed` otherwise, also if the object no longer
496
+ * exists. It compares the latest version, so there is no `version` to
497
+ * remove. A missing revision throws `InvalidArgument`.
498
+ *
499
+ * The match compares the object's contents, not its attributes:
500
+ * `updateAttrs` doesn't break it.
501
+ *
502
+ * On Amazon S3 a conditional delete also needs read access to the
503
+ * bucket, which Encore grants to the services that call this. Cloudflare
504
+ * R2 doesn't support conditional deletes: there it throws
505
+ * `InvalidArgument`.
506
+ */
507
+ async removeIfMatch(name: string, revision: Revision): Promise<void> {
508
+ const ifMatch = requiredRevision('removeIfMatch', revision);
509
+ const source = activeCtxBytes();
510
+ const impl = this.impl.object(name);
511
+ const err = await impl.delete({ifMatch}, source);
167
512
  if (err) {
168
513
  unwrapErr(err);
169
514
  }
@@ -183,6 +528,150 @@ export class Bucket
183
528
  }
184
529
  }
185
530
 
531
+ /** The most bytes handed to the native upload at a time. */
532
+ const CHUNK_SIZE = 64 * 1024;
533
+
534
+ const STREAM_EXPECTED =
535
+ 'uploadStream takes a ReadableStream or an async iterable of Uint8Array chunks';
536
+ const BODY_EXPECTED =
537
+ 'uploadIfMatch takes a Uint8Array, a ReadableStream or an async iterable of Uint8Array chunks';
538
+
539
+ async function uploadChunks(
540
+ obj: runtime.BucketObject,
541
+ data: AsyncIterable<Uint8Array> | Iterable<Uint8Array>,
542
+ options: runtime.UploadOptions | undefined,
543
+ ): Promise<ObjectAttrs> {
544
+ const source = activeCtxBytes();
545
+ const stream = unwrapErr(obj.uploadStream(options, source));
546
+ try {
547
+ for await (const chunk of data) {
548
+ if (!(chunk instanceof Uint8Array)) {
549
+ throw new TypeError('upload data must be Uint8Array chunks');
550
+ }
551
+ for (const slice of slices(chunk)) {
552
+ const err = await stream.write(slice);
553
+ if (err) {
554
+ unwrapErr(err);
555
+ }
556
+ }
557
+ }
558
+ } catch (err) {
559
+ // Nothing is stored unless the upload is finished.
560
+ await stream.abort();
561
+ throw err;
562
+ }
563
+ return toAttrs(unwrapErr(await stream.finish()));
564
+ }
565
+
566
+ /** Views of `data`, of at most CHUNK_SIZE bytes each, as Buffers. */
567
+ function* slices(data: Uint8Array): Generator<Buffer> {
568
+ const buf = Buffer.isBuffer(data)
569
+ ? data
570
+ : Buffer.from(data.buffer, data.byteOffset, data.byteLength);
571
+ for (let offset = 0; offset < buf.byteLength; offset += CHUNK_SIZE) {
572
+ yield buf.subarray(offset, offset + CHUNK_SIZE);
573
+ }
574
+ }
575
+
576
+ function chunks(
577
+ data: AsyncIterable<Uint8Array> | ReadableStream<Uint8Array>,
578
+ expected: string,
579
+ ): AsyncIterable<Uint8Array> {
580
+ if (typeof (data as ReadableStream).getReader === 'function') {
581
+ return readStream(data as ReadableStream<Uint8Array>);
582
+ }
583
+ const iterable = data as AsyncIterable<Uint8Array>;
584
+ if (typeof iterable[Symbol.asyncIterator] !== 'function') {
585
+ throw new TypeError(expected);
586
+ }
587
+ return iterable;
588
+ }
589
+
590
+ async function* readStream(
591
+ stream: ReadableStream<Uint8Array>,
592
+ ): AsyncGenerator<Uint8Array> {
593
+ const reader = stream.getReader();
594
+ let done = false;
595
+ try {
596
+ while (true) {
597
+ const res = await reader.read();
598
+ if (res.done) {
599
+ done = true;
600
+ return;
601
+ }
602
+ yield res.value;
603
+ }
604
+ } finally {
605
+ // An upload that failed doesn't need the rest of the stream.
606
+ if (!done) {
607
+ await reader.cancel().catch(() => {});
608
+ }
609
+ reader.releaseLock();
610
+ }
611
+ }
612
+
613
+ function uploadOptions(
614
+ options: UploadOptions | undefined,
615
+ ): runtime.UploadOptions | undefined {
616
+ return (
617
+ options && {
618
+ contentType: options.contentType,
619
+ cacheControl: options.cacheControl,
620
+ contentDisposition: options.contentDisposition,
621
+ metadata: options.metadata,
622
+ storageClass: options.storageClass,
623
+ retainUntil: options.retainUntil?.getTime(),
624
+ preconditions: options.preconditions && {
625
+ notExists: options.preconditions.notExists,
626
+ },
627
+ }
628
+ );
629
+ }
630
+
631
+ function downloadOptions(
632
+ options: DownloadOptions | undefined,
633
+ ): runtime.DownloadOptions | undefined {
634
+ return options && {version: options.version, range: options.range};
635
+ }
636
+
637
+ function toRevision(rev: Revision | undefined): runtime.Revision | undefined {
638
+ return rev && {etag: rev.etag, version: rev.version};
639
+ }
640
+
641
+ /**
642
+ * The revision a `*IfMatch` method matches. A missing one, which the types
643
+ * forbid but plain JavaScript can pass, is refused: the write or delete would
644
+ * otherwise be unconditional.
645
+ */
646
+ function requiredRevision(method: string, rev: Revision): runtime.Revision {
647
+ if (rev == null || typeof rev.etag !== 'string') {
648
+ throw new InvalidArgument(
649
+ `${method} needs the revision to match: the attributes attrs, upload or updateAttrs returned`,
650
+ );
651
+ }
652
+ return {etag: rev.etag, version: rev.version};
653
+ }
654
+
655
+ function toDate(millis: number | undefined): Date | undefined {
656
+ return millis === undefined ? undefined : new Date(millis);
657
+ }
658
+
659
+ function toAttrs(attrs: runtime.ObjectAttrs): ObjectAttrs {
660
+ return {
661
+ name: attrs.name,
662
+ size: attrs.size,
663
+ version: attrs.version,
664
+ etag: attrs.etag,
665
+ contentType: attrs.contentType,
666
+ cacheControl: attrs.cacheControl,
667
+ contentDisposition: attrs.contentDisposition,
668
+ metadata: attrs.metadata ?? {},
669
+ lastModified: toDate(attrs.lastModified),
670
+ storageClass: attrs.storageClass,
671
+ retainUntil: toDate(attrs.retainUntil),
672
+ };
673
+ }
674
+
186
675
  /**
187
676
  * Options for listing objects in a bucket.
188
677
  */
@@ -193,7 +682,30 @@ export interface ListOptions {
193
682
  */
194
683
  prefix?: string;
195
684
 
196
- /** Maximum number of objects to return. Defaults to no limit. */
685
+ /**
686
+ * Maximum number of entries to return, common prefixes included.
687
+ * Defaults to no limit.
688
+ */
689
+ limit?: number;
690
+
691
+ /**
692
+ * Group the names that continue past the prefix with this delimiter,
693
+ * usually `"/"`, into one entry per common prefix.
694
+ */
695
+ delimiter?: string;
696
+ }
697
+
698
+ /**
699
+ * Options for listing object versions in a bucket.
700
+ */
701
+ export interface ListVersionsOptions {
702
+ /**
703
+ * Only include objects with this prefix in the listing.
704
+ * If unset, all objects are included.
705
+ */
706
+ prefix?: string;
707
+
708
+ /** Maximum number of versions to return. Defaults to no limit. */
197
709
  limit?: number;
198
710
  }
199
711
 
@@ -272,6 +784,27 @@ export interface DownloadOptions {
272
784
  range?: ByteRange;
273
785
  }
274
786
 
787
+ /**
788
+ * One revision of an object: what `uploadIfMatch`, `removeIfMatch` and the
789
+ * `ifMatch` precondition of `updateAttrs` compare. `ObjectAttrs` is one, so
790
+ * the attributes an operation returned can be passed as they are.
791
+ */
792
+ export interface Revision {
793
+ etag: string;
794
+ version?: string;
795
+ }
796
+
797
+ /**
798
+ * Conditions on the object an upload writes.
799
+ */
800
+ export interface Preconditions {
801
+ /**
802
+ * Only write the object if it does not exist yet.
803
+ * Throws `PreconditionFailed` otherwise.
804
+ */
805
+ notExists?: boolean;
806
+ }
807
+
275
808
  /**
276
809
  * Describes the attributes of an object stored in a bucket.
277
810
  */
@@ -282,15 +815,48 @@ export interface ObjectAttrs {
282
815
  version?: string;
283
816
  etag: string;
284
817
  contentType?: string;
818
+ cacheControl?: string;
819
+ contentDisposition?: string;
820
+ /** Custom metadata; empty if the object has none. */
821
+ metadata: Record<string, string>;
822
+ /** When this version of the object was written. */
823
+ lastModified?: Date;
824
+ /**
825
+ * The object's storage class. Every object in a bucket whose class is
826
+ * `"auto"` reads `"auto"`. Undefined for a class Encore doesn't model,
827
+ * set outside Encore.
828
+ */
829
+ storageClass?: StorageClass | 'auto';
830
+ /** The object's own retain-until time, if it has one. */
831
+ retainUntil?: Date;
285
832
  }
286
833
 
287
834
  /**
288
835
  * A single entry returned when listing objects in a bucket.
289
836
  */
290
837
  export interface ListEntry {
838
+ /** The object's name, or a common prefix, ending in the delimiter. */
291
839
  name: string;
292
840
  size: number;
293
841
  etag: string;
842
+ /**
843
+ * Whether the entry is a common prefix of a listing with a delimiter,
844
+ * rather than an object. A prefix has size 0 and an empty etag.
845
+ */
846
+ isPrefix: boolean;
847
+ }
848
+
849
+ /**
850
+ * One stored version of an object, as `listVersions` lists it.
851
+ */
852
+ export interface ObjectVersion {
853
+ name: string;
854
+ version?: string;
855
+ size: number;
856
+ etag: string;
857
+ /** Whether this is the object's current version. */
858
+ latest: boolean;
859
+ lastModified?: Date;
294
860
  }
295
861
 
296
862
  /**
@@ -298,11 +864,74 @@ export interface ListEntry {
298
864
  */
299
865
  export interface UploadOptions {
300
866
  contentType?: string;
867
+
868
+ /** The `Cache-Control` header that downloads of the object get. */
869
+ cacheControl?: string;
870
+
871
+ /** The `Content-Disposition` header that downloads of the object get. */
872
+ contentDisposition?: string;
873
+
874
+ /**
875
+ * Custom metadata. Keys match `[a-z0-9][a-z0-9_-]*` and values are
876
+ * printable ASCII. Keys and values together may take 8 KiB on GCS and
877
+ * 2 KiB on S3.
878
+ */
879
+ metadata?: Record<string, string>;
880
+
881
+ /** The object's storage class. Defaults to the bucket's. */
882
+ storageClass?: StorageClass;
883
+
884
+ /**
885
+ * Keep the object until then: it can't be deleted or overwritten
886
+ * sooner. The bucket must be declared with `objectRetention`.
887
+ */
888
+ retainUntil?: Date;
889
+
890
+ preconditions?: Preconditions;
891
+ }
892
+
893
+ /**
894
+ * Options for `uploadIfMatch`: those of `upload`, without preconditions.
895
+ */
896
+ export type UploadIfMatchOptions = Omit<UploadOptions, 'preconditions'>;
897
+
898
+ /**
899
+ * The attributes `updateAttrs` replaces. An attribute left out stays as it
900
+ * is, and an empty string clears it; a cleared `contentType` is
901
+ * `application/octet-stream`. `metadata` replaces the whole map, so `{}`
902
+ * clears it.
903
+ */
904
+ export interface UpdateAttrs {
905
+ contentType?: string;
906
+ cacheControl?: string;
907
+ contentDisposition?: string;
908
+ metadata?: Record<string, string>;
909
+ }
910
+
911
+ /**
912
+ * Options for updating an object's attributes.
913
+ */
914
+ export interface UpdateAttrsOptions {
915
+ /** The object version to update. Defaults to the latest. */
916
+ version?: string;
917
+
301
918
  preconditions?: {
302
- notExists?: boolean;
919
+ /**
920
+ * Only update the object if it is still this revision.
921
+ * Throws `PreconditionFailed` otherwise.
922
+ */
923
+ ifMatch?: Revision;
303
924
  };
304
925
  }
305
926
 
927
+ /**
928
+ * Options for extending an object's retention.
929
+ */
930
+ export interface ExtendRetentionOptions {
931
+ /** The object version to retain. Defaults to the latest. */
932
+ version?: string;
933
+ }
934
+
306
935
  /**
307
936
  * Options for generating a signed upload URL.
308
937
  */