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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (269) hide show
  1. package/README.md +144 -90
  2. package/app_meta.ts +56 -54
  3. package/config/config.test.ts +47 -13
  4. package/config/config.ts +60 -57
  5. package/config/secrets.ts +47 -50
  6. package/config/value.ts +23 -26
  7. package/cron/mod.test.ts +12 -0
  8. package/cron/mod.ts +37 -22
  9. package/dist/app_meta.d.ts +52 -50
  10. package/dist/app_meta.d.ts.map +1 -1
  11. package/dist/app_meta.js +2 -2
  12. package/dist/app_meta.js.map +1 -1
  13. package/dist/config/config.d.ts +58 -55
  14. package/dist/config/config.d.ts.map +1 -1
  15. package/dist/config/config.js +8 -9
  16. package/dist/config/config.js.map +1 -1
  17. package/dist/config/secrets.d.ts +45 -50
  18. package/dist/config/secrets.d.ts.map +1 -1
  19. package/dist/config/secrets.js +11 -9
  20. package/dist/config/secrets.js.map +1 -1
  21. package/dist/config/value.d.ts +20 -23
  22. package/dist/config/value.d.ts.map +1 -1
  23. package/dist/config/value.js +20 -23
  24. package/dist/config/value.js.map +1 -1
  25. package/dist/cron/mod.d.ts +34 -20
  26. package/dist/cron/mod.d.ts.map +1 -1
  27. package/dist/cron/mod.js +13 -13
  28. package/dist/cron/mod.js.map +1 -1
  29. package/dist/frontends/mod.d.ts +20 -19
  30. package/dist/frontends/mod.d.ts.map +1 -1
  31. package/dist/frontends/mod.js +20 -19
  32. package/dist/frontends/mod.js.map +1 -1
  33. package/dist/gateway/errors.d.ts +28 -30
  34. package/dist/gateway/errors.d.ts.map +1 -1
  35. package/dist/gateway/errors.js +29 -31
  36. package/dist/gateway/errors.js.map +1 -1
  37. package/dist/gateway/match.d.ts +54 -54
  38. package/dist/gateway/match.d.ts.map +1 -1
  39. package/dist/gateway/match.js +56 -56
  40. package/dist/gateway/match.js.map +1 -1
  41. package/dist/gateway/middleware.d.ts +62 -64
  42. package/dist/gateway/middleware.d.ts.map +1 -1
  43. package/dist/gateway/middleware.js +1 -1
  44. package/dist/gateway/middleware.js.map +1 -1
  45. package/dist/gateway/mod.d.ts +64 -67
  46. package/dist/gateway/mod.d.ts.map +1 -1
  47. package/dist/gateway/mod.js +72 -76
  48. package/dist/gateway/mod.js.map +1 -1
  49. package/dist/gateway/request.d.ts +138 -134
  50. package/dist/gateway/request.d.ts.map +1 -1
  51. package/dist/gateway/request.js +117 -108
  52. package/dist/gateway/request.js.map +1 -1
  53. package/dist/gateway/serve.d.ts +29 -34
  54. package/dist/gateway/serve.d.ts.map +1 -1
  55. package/dist/gateway/serve.js +51 -56
  56. package/dist/gateway/serve.js.map +1 -1
  57. package/dist/gateways/mod.d.ts +23 -21
  58. package/dist/gateways/mod.d.ts.map +1 -1
  59. package/dist/gateways/mod.js +25 -23
  60. package/dist/gateways/mod.js.map +1 -1
  61. package/dist/internal/otel/http.d.ts +4 -2
  62. package/dist/internal/otel/http.d.ts.map +1 -1
  63. package/dist/internal/otel/http.js +32 -5
  64. package/dist/internal/otel/http.js.map +1 -1
  65. package/dist/internal/runtime/napi/napi.cjs +6 -5
  66. package/dist/internal/runtime/napi/napi.d.cts +58 -16
  67. package/dist/internal/runtime/shutdown.d.ts +75 -57
  68. package/dist/internal/runtime/shutdown.d.ts.map +1 -1
  69. package/dist/internal/runtime/shutdown.js +88 -84
  70. package/dist/internal/runtime/shutdown.js.map +1 -1
  71. package/dist/log/logger.d.ts +43 -37
  72. package/dist/log/logger.d.ts.map +1 -1
  73. package/dist/log/logger.js +26 -25
  74. package/dist/log/logger.js.map +1 -1
  75. package/dist/metrics/mod.d.ts +133 -114
  76. package/dist/metrics/mod.d.ts.map +1 -1
  77. package/dist/metrics/mod.js +109 -101
  78. package/dist/metrics/mod.js.map +1 -1
  79. package/dist/otel.d.ts +6 -3
  80. package/dist/otel.d.ts.map +1 -1
  81. package/dist/otel.js +6 -3
  82. package/dist/otel.js.map +1 -1
  83. package/dist/pubsub/subscription.d.ts +88 -116
  84. package/dist/pubsub/subscription.d.ts.map +1 -1
  85. package/dist/pubsub/subscription.js +14 -17
  86. package/dist/pubsub/subscription.js.map +1 -1
  87. package/dist/pubsub/topic.d.ts +86 -113
  88. package/dist/pubsub/topic.d.ts.map +1 -1
  89. package/dist/pubsub/topic.js +68 -82
  90. package/dist/pubsub/topic.js.map +1 -1
  91. package/dist/redaction/mod.d.ts +62 -0
  92. package/dist/redaction/mod.d.ts.map +1 -0
  93. package/dist/redaction/mod.js +102 -0
  94. package/dist/redaction/mod.js.map +1 -0
  95. package/dist/reqctx/mod.d.ts +83 -86
  96. package/dist/reqctx/mod.d.ts.map +1 -1
  97. package/dist/reqctx/mod.js +39 -41
  98. package/dist/reqctx/mod.js.map +1 -1
  99. package/dist/services/index.d.ts +76 -75
  100. package/dist/services/index.d.ts.map +1 -1
  101. package/dist/services/index.js +73 -71
  102. package/dist/services/index.js.map +1 -1
  103. package/dist/shutdown/mod.d.ts +26 -25
  104. package/dist/shutdown/mod.d.ts.map +1 -1
  105. package/dist/shutdown/mod.js +26 -25
  106. package/dist/shutdown/mod.js.map +1 -1
  107. package/dist/storage/clickhouse/database.d.ts +113 -115
  108. package/dist/storage/clickhouse/database.d.ts.map +1 -1
  109. package/dist/storage/clickhouse/database.js +65 -79
  110. package/dist/storage/clickhouse/database.js.map +1 -1
  111. package/dist/storage/clickhouse/errors.d.ts +25 -26
  112. package/dist/storage/clickhouse/errors.d.ts.map +1 -1
  113. package/dist/storage/clickhouse/errors.js +15 -17
  114. package/dist/storage/clickhouse/errors.js.map +1 -1
  115. package/dist/storage/clickhouse/mod.d.ts +10 -10
  116. package/dist/storage/clickhouse/mod.js +10 -10
  117. package/dist/storage/objects/bucket.d.ts +230 -203
  118. package/dist/storage/objects/bucket.d.ts.map +1 -1
  119. package/dist/storage/objects/bucket.js +146 -106
  120. package/dist/storage/objects/bucket.js.map +1 -1
  121. package/dist/storage/objects/error.d.ts +4 -4
  122. package/dist/storage/objects/error.js +4 -4
  123. package/dist/storage/objects/mod.d.ts +1 -1
  124. package/dist/storage/objects/mod.d.ts.map +1 -1
  125. package/dist/storage/objects/mod.js.map +1 -1
  126. package/dist/storage/objects/refs.d.ts +2 -5
  127. package/dist/storage/objects/refs.d.ts.map +1 -1
  128. package/dist/storage/objects/refs.js.map +1 -1
  129. package/dist/storage/postgres/database.d.ts +124 -149
  130. package/dist/storage/postgres/database.d.ts.map +1 -1
  131. package/dist/storage/postgres/database.js +98 -135
  132. package/dist/storage/postgres/database.js.map +1 -1
  133. package/dist/storage/postgres/errors.d.ts +42 -48
  134. package/dist/storage/postgres/errors.d.ts.map +1 -1
  135. package/dist/storage/postgres/errors.js +44 -51
  136. package/dist/storage/postgres/errors.js.map +1 -1
  137. package/dist/storage/postgres/interval.d.ts +19 -19
  138. package/dist/storage/postgres/interval.d.ts.map +1 -1
  139. package/dist/storage/postgres/interval.js +21 -21
  140. package/dist/storage/postgres/interval.js.map +1 -1
  141. package/dist/storage/redis/bitfield.d.ts +48 -23
  142. package/dist/storage/redis/bitfield.d.ts.map +1 -1
  143. package/dist/storage/redis/bitfield.js +38 -19
  144. package/dist/storage/redis/bitfield.js.map +1 -1
  145. package/dist/storage/redis/command.d.ts +16 -12
  146. package/dist/storage/redis/command.d.ts.map +1 -1
  147. package/dist/storage/redis/command.js +16 -12
  148. package/dist/storage/redis/command.js.map +1 -1
  149. package/dist/storage/redis/commands.d.ts +99 -100
  150. package/dist/storage/redis/commands.d.ts.map +1 -1
  151. package/dist/storage/redis/commands.js +84 -85
  152. package/dist/storage/redis/commands.js.map +1 -1
  153. package/dist/storage/redis/database.d.ts +138 -122
  154. package/dist/storage/redis/database.d.ts.map +1 -1
  155. package/dist/storage/redis/database.js +120 -101
  156. package/dist/storage/redis/database.js.map +1 -1
  157. package/dist/storage/redis/mod.d.ts +52 -48
  158. package/dist/storage/redis/mod.d.ts.map +1 -1
  159. package/dist/storage/redis/mod.js +52 -48
  160. package/dist/storage/redis/mod.js.map +1 -1
  161. package/dist/storage/redis/options.d.ts +26 -24
  162. package/dist/storage/redis/options.d.ts.map +1 -1
  163. package/dist/storage/redis/options.js.map +1 -1
  164. package/dist/storage/redis/pubsub.d.ts +16 -16
  165. package/dist/storage/redis/pubsub.d.ts.map +1 -1
  166. package/dist/storage/redis/pubsub.js +14 -14
  167. package/dist/storage/redis/pubsub.js.map +1 -1
  168. package/dist/storage/redis/reply.d.ts +80 -72
  169. package/dist/storage/redis/reply.d.ts.map +1 -1
  170. package/dist/storage/redis/reply.js +53 -46
  171. package/dist/storage/redis/reply.js.map +1 -1
  172. package/dist/storage/redis/scan.d.ts +4 -4
  173. package/dist/storage/redis/scan.d.ts.map +1 -1
  174. package/dist/storage/redis/scan.js +6 -6
  175. package/dist/storage/redis/scan.js.map +1 -1
  176. package/dist/storage/redis/script.d.ts +28 -21
  177. package/dist/storage/redis/script.d.ts.map +1 -1
  178. package/dist/storage/redis/script.js +29 -22
  179. package/dist/storage/redis/script.js.map +1 -1
  180. package/dist/storage/redis/target.d.ts +17 -1
  181. package/dist/storage/redis/target.d.ts.map +1 -1
  182. package/dist/storage/redis/target.js +30 -1
  183. package/dist/storage/redis/target.js.map +1 -1
  184. package/dist/storage/redis/wire.d.ts +6 -6
  185. package/dist/storage/redis/wire.d.ts.map +1 -1
  186. package/dist/storage/redis/wire.js +6 -6
  187. package/dist/storage/redis/wire.js.map +1 -1
  188. package/dist/testing/mod.d.ts +83 -88
  189. package/dist/testing/mod.d.ts.map +1 -1
  190. package/dist/testing/mod.js +75 -81
  191. package/dist/testing/mod.js.map +1 -1
  192. package/dist/testing/playwright.d.ts +28 -32
  193. package/dist/testing/playwright.d.ts.map +1 -1
  194. package/dist/testing/playwright.js +22 -27
  195. package/dist/testing/playwright.js.map +1 -1
  196. package/dist/testing/puppeteer.d.ts +11 -12
  197. package/dist/testing/puppeteer.d.ts.map +1 -1
  198. package/dist/testing/puppeteer.js +17 -18
  199. package/dist/testing/puppeteer.js.map +1 -1
  200. package/dist/testing/system.d.ts +72 -90
  201. package/dist/testing/system.d.ts.map +1 -1
  202. package/dist/testing/system.js +90 -107
  203. package/dist/testing/system.js.map +1 -1
  204. package/dist/tracing/http.d.ts +2 -1
  205. package/dist/tracing/http.d.ts.map +1 -1
  206. package/dist/tracing/http.js +2 -1
  207. package/dist/tracing/http.js.map +1 -1
  208. package/dist/tracing/node.d.ts.map +1 -1
  209. package/dist/tracing/node.js +1 -1
  210. package/dist/tracing/node.js.map +1 -1
  211. package/dist/tsconfig.build.tsbuildinfo +1 -1
  212. package/frontends/mod.test.ts +6 -2
  213. package/frontends/mod.ts +20 -19
  214. package/gateway/errors.ts +30 -32
  215. package/gateway/match.ts +61 -57
  216. package/gateway/middleware.ts +62 -64
  217. package/gateway/mod.ts +73 -76
  218. package/gateway/request.ts +143 -140
  219. package/gateway/serve.ts +58 -63
  220. package/gateways/mod.ts +25 -23
  221. package/internal/otel/http.test.ts +50 -0
  222. package/internal/otel/http.ts +40 -5
  223. package/internal/runtime/napi/napi.cjs +6 -5
  224. package/internal/runtime/napi/napi.d.cts +58 -16
  225. package/internal/runtime/shutdown.ts +113 -101
  226. package/log/logger.test.ts +8 -0
  227. package/log/logger.ts +48 -45
  228. package/metrics/mod.ts +138 -122
  229. package/otel.ts +6 -3
  230. package/package.json +6 -1
  231. package/pubsub/subscription.ts +93 -123
  232. package/pubsub/topic.ts +96 -130
  233. package/redaction/bridge.test.ts +99 -0
  234. package/redaction/mod.test.ts +188 -0
  235. package/redaction/mod.ts +226 -0
  236. package/reqctx/mod.ts +83 -86
  237. package/services/index.ts +78 -78
  238. package/shutdown/mod.ts +26 -25
  239. package/storage/clickhouse/database.ts +115 -129
  240. package/storage/clickhouse/errors.ts +27 -29
  241. package/storage/clickhouse/mod.ts +10 -10
  242. package/storage/objects/bucket.test.ts +168 -16
  243. package/storage/objects/bucket.ts +336 -247
  244. package/storage/objects/error.ts +4 -4
  245. package/storage/objects/mod.ts +1 -0
  246. package/storage/objects/refs.ts +2 -5
  247. package/storage/postgres/database.ts +131 -164
  248. package/storage/postgres/errors.ts +45 -52
  249. package/storage/postgres/interval.ts +21 -21
  250. package/storage/redis/bitfield.ts +51 -26
  251. package/storage/redis/command.ts +16 -12
  252. package/storage/redis/commands.ts +99 -100
  253. package/storage/redis/database.ts +145 -123
  254. package/storage/redis/mod.ts +52 -48
  255. package/storage/redis/options.ts +26 -24
  256. package/storage/redis/pubsub.ts +14 -14
  257. package/storage/redis/redis.test.ts +17 -2
  258. package/storage/redis/reply.ts +85 -77
  259. package/storage/redis/scan.ts +6 -6
  260. package/storage/redis/script.ts +29 -22
  261. package/storage/redis/target.ts +34 -1
  262. package/storage/redis/wire.ts +8 -8
  263. package/testing/mod.ts +99 -105
  264. package/testing/playwright.ts +32 -37
  265. package/testing/puppeteer.ts +22 -23
  266. package/testing/system.ts +117 -133
  267. package/tracing/http.ts +2 -1
  268. package/tracing/native.test.ts +158 -8
  269. package/tracing/node.ts +1 -0
@@ -49,12 +49,27 @@ const uploadStream = mock((_options: unknown, _source: unknown): unknown => ({
49
49
  abort,
50
50
  }));
51
51
 
52
- // The native download stream: hands out `chunks` in turn.
52
+ // The native download: says `nativeInfo` of the object, and hands out
53
+ // `chunks` in turn, or all at once.
54
+ const nativeInfo = {
55
+ etag: 'etag-7',
56
+ version: '7',
57
+ size: 10,
58
+ contentType: 'text/plain',
59
+ lastModified: 1_730_000_000_000,
60
+ };
53
61
  let chunks: unknown[] = [];
54
62
  const next = mock(async () => chunks.shift() ?? null);
55
63
  const close = mock(async () => {});
56
- const downloadStream = mock(
64
+ const bytes = mock(async (): Promise<unknown> => {
65
+ const all = Buffer.concat(chunks as Buffer[]);
66
+ chunks = [];
67
+ return all;
68
+ });
69
+ const download = mock(
57
70
  async (_options: unknown, _source: unknown): Promise<unknown> => ({
71
+ info: nativeInfo,
72
+ bytes,
58
73
  next,
59
74
  close,
60
75
  }),
@@ -79,7 +94,7 @@ function nativeObject(bucket: string, name: string) {
79
94
  bucket,
80
95
  name,
81
96
  uploadStream,
82
- downloadStream,
97
+ download,
83
98
  updateAttrs,
84
99
  extendRetention,
85
100
  delete: remove,
@@ -133,7 +148,8 @@ beforeEach(() => {
133
148
  uploadStream,
134
149
  next,
135
150
  close,
136
- downloadStream,
151
+ bytes,
152
+ download,
137
153
  updateAttrs,
138
154
  extendRetention,
139
155
  remove,
@@ -348,34 +364,125 @@ test('an upload the provider refuses cancels the source stream', async () => {
348
364
  expect(finish).not.toHaveBeenCalled();
349
365
  });
350
366
 
351
- test('downloadStream yields the native chunks and cancelling it closes the native stream', async () => {
367
+ test('download says what the provider said of the object, and reads it whole', async () => {
352
368
  const bucket = new Bucket('uploads');
353
- chunks = [Buffer.from('one'), Buffer.from('two')];
354
- const body = await bucket.downloadStream('a', {
355
- range: {offset: 1, length: 5},
356
- });
357
- expect(downloadStream.mock.lastCall).toEqual([
358
- {version: undefined, range: {offset: 1, length: 5}},
369
+ chunks = [Buffer.from('0123'), Buffer.from('456789')];
370
+ const d = await bucket.download('a.txt', {version: '7'});
371
+ expect(download.mock.lastCall).toEqual([
372
+ {version: '7', range: undefined},
359
373
  undefined,
360
374
  ]);
375
+ expect(d.revision).toEqual({etag: 'etag-7', version: '7'});
376
+ expect(d.size).toBe(10);
377
+ expect(d.contentType).toBe('text/plain');
378
+ expect(d.lastModified).toEqual(new Date(1_730_000_000_000));
379
+ // Nothing of the contents is read before the caller reads.
380
+ expect(bytes).not.toHaveBeenCalled();
381
+ expect(next).not.toHaveBeenCalled();
382
+
383
+ expect((await d.bytes()).toString()).toBe('0123456789');
384
+ // Read once: the bytes are not kept.
385
+ await expect(d.bytes()).rejects.toBeInstanceOf(InvalidArgument);
386
+ expect(() => d.stream()).toThrow(InvalidArgument);
387
+ expect(bytes).toHaveBeenCalledTimes(1);
388
+ });
389
+
390
+ test("a download's revision is what uploadIfMatch and removeIfMatch take, and a stale one is refused", async () => {
391
+ const bucket = new Bucket('uploads');
392
+ chunks = [Buffer.from('{"n":1}')];
393
+ const d = await bucket.download('state.json');
394
+ const state = JSON.parse((await d.bytes()).toString());
395
+
396
+ await bucket.uploadIfMatch(
397
+ 'state.json',
398
+ Buffer.from(JSON.stringify({n: state.n + 1})),
399
+ d.revision,
400
+ );
401
+ expect(uploadStream.mock.lastCall?.[0]).toMatchObject({
402
+ preconditions: {ifMatch: {etag: 'etag-7', version: '7'}},
403
+ });
404
+ expect(Buffer.concat(written).toString()).toBe('{"n":2}');
405
+
406
+ // The object has changed since: the provider refuses the revision.
407
+ finish.mockImplementationOnce(
408
+ async () =>
409
+ new TypedObjectError(ObjectErrorKind.PreconditionFailed, 'changed'),
410
+ );
411
+ await expect(
412
+ bucket.uploadIfMatch('state.json', Buffer.from('late'), d.revision),
413
+ ).rejects.toBeInstanceOf(PreconditionFailed);
414
+
415
+ await bucket.removeIfMatch('state.json', d.revision);
416
+ expect(remove.mock.lastCall?.[0]).toEqual({
417
+ ifMatch: {etag: 'etag-7', version: '7'},
418
+ });
419
+ remove.mockImplementationOnce(
420
+ async () =>
421
+ new TypedObjectError(ObjectErrorKind.PreconditionFailed, 'changed'),
422
+ );
423
+ await expect(
424
+ bucket.removeIfMatch('state.json', d.revision),
425
+ ).rejects.toBeInstanceOf(PreconditionFailed);
426
+ });
427
+
428
+ test("a range is an offset and a length, or the last bytes, and the size is the whole object's", async () => {
429
+ const bucket = new Bucket('uploads');
430
+ const ranges = [
431
+ [
432
+ {offset: 1, length: 5},
433
+ {offset: 1, length: 5},
434
+ ],
435
+ [{offset: 1024}, {offset: 1024, length: undefined}],
436
+ [{last: 4}, {last: 4}],
437
+ ] as const;
438
+ for (const [range, native] of ranges) {
439
+ chunks = [Buffer.from('6789')];
440
+ const d = await bucket.download('a', {range});
441
+ expect(download.mock.lastCall?.[0]).toEqual({
442
+ version: undefined,
443
+ range: native,
444
+ });
445
+ // The contents are the range's; the size is the object's.
446
+ expect((await d.bytes()).length).toBe(4);
447
+ expect(d.size).toBe(10);
448
+ }
449
+
450
+ // Neither, or both, is no range. Plain JavaScript can pass them.
451
+ for (const range of [{}, {length: 4}, {offset: 0, last: 4}]) {
452
+ await expect(
453
+ bucket.download('a', {range: range as never}),
454
+ ).rejects.toBeInstanceOf(InvalidArgument);
455
+ }
456
+ expect(download).toHaveBeenCalledTimes(ranges.length);
457
+ });
458
+
459
+ test('stream yields the native chunks and cancelling it closes the native download', async () => {
460
+ const bucket = new Bucket('uploads');
461
+ chunks = [Buffer.from('one'), Buffer.from('two')];
462
+ const d = await bucket.download('a');
463
+ const body = d.stream();
361
464
  // Nothing is read before the consumer reads.
362
465
  expect(next).not.toHaveBeenCalled();
363
466
  const reader = body.getReader();
364
467
  expect(Buffer.from((await reader.read()).value!).toString()).toBe('one');
365
468
  await reader.cancel();
366
469
  expect(close).toHaveBeenCalledTimes(1);
470
+ // Read once, whichever way.
471
+ expect(() => d.stream()).toThrow(InvalidArgument);
472
+ await expect(d.bytes()).rejects.toBeInstanceOf(InvalidArgument);
367
473
 
368
474
  chunks = [Buffer.from('all')];
369
- const whole = await bucket.downloadStream('b');
475
+ const whole = (await bucket.download('b')).stream();
370
476
  expect(await new Response(whole).text()).toBe('all');
477
+ expect(bytes).not.toHaveBeenCalled();
371
478
  });
372
479
 
373
- test('downloadStream throws for a missing object before any bytes, and errors the stream mid-way', async () => {
480
+ test('download throws for a missing object before any bytes, and its contents error mid-way', async () => {
374
481
  const bucket = new Bucket('uploads');
375
- downloadStream.mockImplementationOnce(
482
+ download.mockImplementationOnce(
376
483
  async () => new TypedObjectError(ObjectErrorKind.NotFound, 'not found'),
377
484
  );
378
- await expect(bucket.downloadStream('missing')).rejects.toBeInstanceOf(
485
+ await expect(bucket.download('missing')).rejects.toBeInstanceOf(
379
486
  ObjectNotFound,
380
487
  );
381
488
 
@@ -383,11 +490,17 @@ test('downloadStream throws for a missing object before any bytes, and errors th
383
490
  Buffer.from('x'),
384
491
  new TypedObjectError(ObjectErrorKind.Other, 'connection reset'),
385
492
  ];
386
- const reader = (await bucket.downloadStream('a')).getReader();
493
+ const reader = (await bucket.download('a')).stream().getReader();
387
494
  await reader.read();
388
495
  const err = await reader.read().catch((e: unknown) => e);
389
496
  expect(err).toBeInstanceOf(ObjectsError);
390
497
  expect((err as Error).message).toBe('connection reset');
498
+
499
+ bytes.mockImplementationOnce(
500
+ async () => new TypedObjectError(ObjectErrorKind.Other, 'connection reset'),
501
+ );
502
+ const whole = await bucket.download('a');
503
+ await expect(whole.bytes()).rejects.toThrow('connection reset');
391
504
  });
392
505
 
393
506
  test('errors unwrap to their classes', async () => {
@@ -470,6 +583,40 @@ test('list passes the delimiter and lets go of the native iterator when the loop
470
583
  expect(markDone).toHaveBeenCalledTimes(1);
471
584
  });
472
585
 
586
+ test('list says when each object was written, and a prefix has no time', async () => {
587
+ const bucket = new Bucket('uploads');
588
+ entries = [
589
+ {name: 'users/1/', size: 0, etag: '', isPrefix: true},
590
+ {
591
+ name: 'users/a.txt',
592
+ size: 1,
593
+ etag: 'e',
594
+ lastModified: 1_730_000_000_000,
595
+ isPrefix: false,
596
+ },
597
+ ];
598
+ const listed = [];
599
+ for await (const entry of bucket.list({prefix: 'users/', delimiter: '/'})) {
600
+ listed.push(entry);
601
+ }
602
+ expect(listed).toEqual([
603
+ {
604
+ name: 'users/1/',
605
+ size: 0,
606
+ etag: '',
607
+ lastModified: undefined,
608
+ isPrefix: true,
609
+ },
610
+ {
611
+ name: 'users/a.txt',
612
+ size: 1,
613
+ etag: 'e',
614
+ lastModified: new Date(1_730_000_000_000),
615
+ isPrefix: false,
616
+ },
617
+ ]);
618
+ });
619
+
473
620
  test('listVersions yields versions with dates', async () => {
474
621
  const bucket = new Bucket('uploads');
475
622
  entries = [
@@ -552,7 +699,12 @@ function _refTyping(bucket: InstanceType<typeof Bucket>) {
552
699
 
553
700
  const rw = bucket.ref<ReadWriter>();
554
701
  void rw.updateAttrs('a', {});
702
+ void rw.download('a').then(d => [d.revision, d.size, d.stream()]);
703
+ // @ts-expect-error a download is read with bytes() or stream(), which downloadStream was
555
704
  void rw.downloadStream('a');
705
+ void rw.download('a', {range: {last: 4}});
706
+ // @ts-expect-error a range is an offset or the last bytes, not both
707
+ void rw.download('a', {range: {offset: 0, last: 4}});
556
708
  void rw.uploadIfMatch('a', new ReadableStream<Uint8Array>(), {etag: 'e'});
557
709
  void rw.removeIfMatch('a', {etag: 'e'});
558
710
  // @ts-expect-error a ReadWriter can't make public URLs