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

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