@travetto/model-s3 8.0.0-alpha.1 → 8.0.0-alpha.11

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 (2) hide show
  1. package/package.json +7 -7
  2. package/src/service.ts +20 -17
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/model-s3",
3
- "version": "8.0.0-alpha.1",
3
+ "version": "8.0.0-alpha.11",
4
4
  "type": "module",
5
5
  "description": "S3 backing for the travetto model module.",
6
6
  "keywords": [
@@ -26,14 +26,14 @@
26
26
  "directory": "module/model-s3"
27
27
  },
28
28
  "dependencies": {
29
- "@aws-sdk/client-s3": "^3.1004.0",
30
- "@aws-sdk/credential-provider-ini": "^3.972.17",
31
- "@aws-sdk/s3-request-presigner": "^3.1004.0",
32
- "@travetto/config": "^8.0.0-alpha.1",
33
- "@travetto/model": "^8.0.0-alpha.1"
29
+ "@aws-sdk/client-s3": "^3.1024.0",
30
+ "@aws-sdk/credential-provider-ini": "^3.972.28",
31
+ "@aws-sdk/s3-request-presigner": "^3.1024.0",
32
+ "@travetto/config": "^8.0.0-alpha.11",
33
+ "@travetto/model": "^8.0.0-alpha.11"
34
34
  },
35
35
  "peerDependencies": {
36
- "@travetto/cli": "^8.0.0-alpha.1"
36
+ "@travetto/cli": "^8.0.0-alpha.16"
37
37
  },
38
38
  "peerDependenciesMeta": {
39
39
  "@travetto/cli": {
package/src/service.ts CHANGED
@@ -7,7 +7,8 @@ import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
7
7
 
8
8
  import {
9
9
  type ModelCrudSupport, type ModelStorageSupport, type ModelType, ModelRegistryIndex, ExistsError, NotFoundError, type OptionalId,
10
- type ModelBlobSupport, type ModelExpirySupport, ModelCrudUtil, ModelExpiryUtil, ModelStorageUtil
10
+ type ModelBlobSupport, type ModelExpirySupport, ModelCrudUtil, ModelExpiryUtil, ModelStorageUtil,
11
+ type ModelListOptions
11
12
  } from '@travetto/model';
12
13
  import { Injectable, PostConstruct } from '@travetto/di';
13
14
  import {
@@ -93,16 +94,26 @@ export class S3ModelService implements ModelCrudSupport, ModelBlobSupport, Model
93
94
  return {};
94
95
  }
95
96
 
96
- async * #iterateBucket(cls?: string | Class): AsyncIterable<{ Key: string, id: string }[]> {
97
+ async * #iterateBucket(cls?: string | Class, options?: ModelListOptions): AsyncIterable<{ Key: string, id: string }[]> {
97
98
  let Marker: string | undefined;
98
- for (; ;) {
99
+ const batchSize = options?.batchSizeHint ?? 100;
100
+ const maxCount = options?.limit ?? Number.MAX_SAFE_INTEGER;
101
+ let produced = 0;
102
+ for (; !(options?.abort?.aborted) && produced < maxCount;) {
99
103
  const items = await this.client.listObjects({
100
104
  Bucket: this.config.bucket,
101
105
  Prefix: cls ? this.#resolveKey(cls) : this.config.namespace,
102
- Marker
106
+ Marker,
107
+ MaxKeys: batchSize
103
108
  });
104
- if (items.Contents?.length) {
105
- yield items.Contents.map(item => ({ Key: item.Key!, id: item.Key!.split(':').pop()! }));
109
+
110
+ let toSend = items.Contents?.map(item => ({ Key: item.Key!, id: item.Key!.split(':').pop()! }));
111
+ if (toSend) {
112
+ produced += toSend.length;
113
+ if (produced > maxCount) {
114
+ toSend = toSend.slice(0, maxCount - (produced - toSend.length));
115
+ }
116
+ yield toSend;
106
117
  }
107
118
  if (items.NextMarker) {
108
119
  Marker = items.NextMarker;
@@ -293,17 +304,9 @@ export class S3ModelService implements ModelCrudSupport, ModelBlobSupport, Model
293
304
  await this.client.deleteObject(this.#query(cls, id));
294
305
  }
295
306
 
296
- async * list<T extends ModelType>(cls: Class<T>): AsyncIterable<T> {
297
- for await (const batch of this.#iterateBucket(cls)) {
298
- for (const { id } of batch) {
299
- try {
300
- yield await this.get(cls, id);
301
- } catch (error) {
302
- if (!(error instanceof NotFoundError)) {
303
- throw error;
304
- }
305
- }
306
- }
307
+ async * list<T extends ModelType>(cls: Class<T>, options?: ModelListOptions): AsyncIterable<T[]> {
308
+ for await (const batch of this.#iterateBucket(cls, options)) {
309
+ yield ModelCrudUtil.filterOutNotFound(batch.map(item => this.get(cls, item.id)));
307
310
  }
308
311
  }
309
312