@travetto/model-s3 5.0.0 → 5.0.1

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 +5 -5
  2. package/src/service.ts +15 -18
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/model-s3",
3
- "version": "5.0.0",
3
+ "version": "5.0.1",
4
4
  "description": "S3 backing for the travetto model module.",
5
5
  "keywords": [
6
6
  "s3",
@@ -25,13 +25,13 @@
25
25
  "directory": "module/model-s3"
26
26
  },
27
27
  "dependencies": {
28
- "@aws-sdk/client-s3": "^3.631.0",
28
+ "@aws-sdk/client-s3": "^3.637.0",
29
29
  "@aws-sdk/credential-provider-ini": "^3.609.0",
30
- "@travetto/config": "^5.0.0",
31
- "@travetto/model": "^5.0.0"
30
+ "@travetto/config": "^5.0.1",
31
+ "@travetto/model": "^5.0.1"
32
32
  },
33
33
  "peerDependencies": {
34
- "@travetto/command": "^5.0.0"
34
+ "@travetto/command": "^5.0.1"
35
35
  },
36
36
  "peerDependenciesMeta": {
37
37
  "@travetto/command": {
package/src/service.ts CHANGED
@@ -92,9 +92,13 @@ export class S3ModelService implements ModelCrudSupport, ModelBlobSupport, Model
92
92
  async * #iterateBucket(cls?: string | Class): AsyncIterable<{ Key: string, id: string }[]> {
93
93
  let Marker: string | undefined;
94
94
  for (; ;) {
95
- const obs = await this.client.listObjects({ Bucket: this.config.bucket, Prefix: cls ? this.#resolveKey(cls) : undefined, Marker });
96
- if (obs.Contents && obs.Contents.length) {
97
- yield (obs.Contents ?? []).map(o => ({ Key: o.Key!, id: o.Key!.split(':').pop()! }));
95
+ const obs = await this.client.listObjects({
96
+ Bucket: this.config.bucket,
97
+ Prefix: cls ? this.#resolveKey(cls) : this.config.namespace,
98
+ Marker
99
+ });
100
+ if (obs.Contents?.length) {
101
+ yield obs.Contents.map(o => ({ Key: o.Key!, id: o.Key!.split(':').pop()! }));
98
102
  }
99
103
  if (obs.NextMarker) {
100
104
  Marker = obs.NextMarker;
@@ -148,19 +152,12 @@ export class S3ModelService implements ModelCrudSupport, ModelBlobSupport, Model
148
152
  }
149
153
 
150
154
  async #deleteKeys(items: { Key: string }[]): Promise<void> {
151
- if (this.config.endpoint.includes('localhost')) {
152
- await Promise.all(items.map(item => this.client.deleteObject({
153
- Bucket: this.config.bucket,
154
- Key: item.Key
155
- })));
156
- } else {
157
- await this.client.deleteObjects({
158
- Bucket: this.config.bucket,
159
- Delete: {
160
- Objects: items
161
- }
162
- });
163
- }
155
+ await this.client.deleteObjects({
156
+ Bucket: this.config.bucket,
157
+ Delete: {
158
+ Objects: items
159
+ }
160
+ });
164
161
  }
165
162
 
166
163
  async postConstruct(): Promise<void> {
@@ -263,7 +260,7 @@ export class S3ModelService implements ModelCrudSupport, ModelBlobSupport, Model
263
260
  async updatePartial<T extends ModelType>(cls: Class<T>, item: Partial<T> & { id: string }, view?: string): Promise<T> {
264
261
  ModelCrudUtil.ensureNotSubType(cls);
265
262
  const id = item.id;
266
- const prepped = await ModelCrudUtil.naivePartialUpdate(cls, item, view, (): Promise<T> => this.get(cls, id));
263
+ const prepped = await ModelCrudUtil.naivePartialUpdate(cls, () => this.get(cls, id), item, view);
267
264
  return this.store<T>(cls, prepped, false);
268
265
  }
269
266
 
@@ -395,7 +392,7 @@ export class S3ModelService implements ModelCrudSupport, ModelBlobSupport, Model
395
392
 
396
393
  async deleteStorage(): Promise<void> {
397
394
  if (this.config.namespace) {
398
- for await (const items of this.#iterateBucket('')) {
395
+ for await (const items of this.#iterateBucket()) {
399
396
  await this.#deleteKeys(items);
400
397
  }
401
398
  } else {