@travetto/model-s3 8.0.3 → 8.0.5
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.
- package/README.md +2 -0
- package/package.json +6 -6
- package/src/config.ts +2 -0
- package/src/service.ts +16 -7
- package/support/service.s3.ts +1 -1
package/README.md
CHANGED
|
@@ -91,6 +91,8 @@ export class S3ModelConfig {
|
|
|
91
91
|
const isAws = !this.endpoint || hostname === 'amazonaws.com' || hostname.endsWith('.amazonaws.com');
|
|
92
92
|
|
|
93
93
|
this.config = {
|
|
94
|
+
responseChecksumValidation: 'WHEN_REQUIRED',
|
|
95
|
+
requestChecksumCalculation: 'WHEN_REQUIRED',
|
|
94
96
|
...(this.config ?? {}),
|
|
95
97
|
region: this.region,
|
|
96
98
|
endpoint: this.endpoint || undefined,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/model-s3",
|
|
3
|
-
"version": "8.0.
|
|
3
|
+
"version": "8.0.5",
|
|
4
4
|
"description": "S3 backing for the travetto model module.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"model",
|
|
@@ -29,11 +29,11 @@
|
|
|
29
29
|
"access": "public"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@aws-sdk/client-s3": "^3.
|
|
33
|
-
"@aws-sdk/credential-provider-ini": "^3.973.
|
|
34
|
-
"@aws-sdk/s3-request-presigner": "^3.
|
|
35
|
-
"@travetto/config": "^8.0.
|
|
36
|
-
"@travetto/model": "^8.0.
|
|
32
|
+
"@aws-sdk/client-s3": "^3.1131.0",
|
|
33
|
+
"@aws-sdk/credential-provider-ini": "^3.973.16",
|
|
34
|
+
"@aws-sdk/s3-request-presigner": "^3.1131.0",
|
|
35
|
+
"@travetto/config": "^8.0.3",
|
|
36
|
+
"@travetto/model": "^8.0.4"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
39
|
"@travetto/cli": "^8.0.2"
|
package/src/config.ts
CHANGED
|
@@ -59,6 +59,8 @@ export class S3ModelConfig {
|
|
|
59
59
|
const isAws = !this.endpoint || hostname === 'amazonaws.com' || hostname.endsWith('.amazonaws.com');
|
|
60
60
|
|
|
61
61
|
this.config = {
|
|
62
|
+
responseChecksumValidation: 'WHEN_REQUIRED',
|
|
63
|
+
requestChecksumCalculation: 'WHEN_REQUIRED',
|
|
62
64
|
...(this.config ?? {}),
|
|
63
65
|
region: this.region,
|
|
64
66
|
endpoint: this.endpoint || undefined,
|
package/src/service.ts
CHANGED
|
@@ -45,6 +45,13 @@ function isMetadataBearer(value: unknown): value is MetadataBearer {
|
|
|
45
45
|
return !!value && typeof value === 'object' && '$metadata' in value;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
function isNotFoundError(error: unknown): error is Error | MetadataBearer {
|
|
49
|
+
return (
|
|
50
|
+
(isMetadataBearer(error) && error.$metadata.httpStatusCode === 404) ||
|
|
51
|
+
(error instanceof Error && (error.name === 'NoSuchBucket' || error.name === 'NotFound' || error.name === 'NoSuchKey'))
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
48
55
|
function hasLowerContentType<T>(value: T): value is T & { contenttype?: string } {
|
|
49
56
|
return value !== undefined && value !== null && Object.hasOwn(value, 'contenttype');
|
|
50
57
|
}
|
|
@@ -248,10 +255,8 @@ export class S3ModelService implements ModelCrudSupport, ModelBlobSupport, Model
|
|
|
248
255
|
}
|
|
249
256
|
return true;
|
|
250
257
|
} catch (error) {
|
|
251
|
-
if (
|
|
252
|
-
|
|
253
|
-
return false;
|
|
254
|
-
}
|
|
258
|
+
if (isNotFoundError(error)) {
|
|
259
|
+
return false;
|
|
255
260
|
}
|
|
256
261
|
throw error;
|
|
257
262
|
}
|
|
@@ -277,7 +282,7 @@ export class S3ModelService implements ModelCrudSupport, ModelBlobSupport, Model
|
|
|
277
282
|
}
|
|
278
283
|
throw new NotFoundError(cls, id);
|
|
279
284
|
} catch (error) {
|
|
280
|
-
if (
|
|
285
|
+
if (isNotFoundError(error)) {
|
|
281
286
|
throw new NotFoundError(cls, id);
|
|
282
287
|
}
|
|
283
288
|
throw error;
|
|
@@ -415,7 +420,7 @@ export class S3ModelService implements ModelCrudSupport, ModelBlobSupport, Model
|
|
|
415
420
|
try {
|
|
416
421
|
return await this.client.headObject(query);
|
|
417
422
|
} catch (error) {
|
|
418
|
-
if (
|
|
423
|
+
if (isNotFoundError(error)) {
|
|
419
424
|
throw new NotFoundError('Blob', location);
|
|
420
425
|
}
|
|
421
426
|
throw error;
|
|
@@ -490,6 +495,10 @@ export class S3ModelService implements ModelCrudSupport, ModelBlobSupport, Model
|
|
|
490
495
|
}
|
|
491
496
|
}
|
|
492
497
|
|
|
498
|
+
async deleteModel<T extends ModelType>(model: Class<T>): Promise<void> {
|
|
499
|
+
await ModelStorageUtil.runAndIgnoreNotFound(() => this.truncateModel(model), isNotFoundError);
|
|
500
|
+
}
|
|
501
|
+
|
|
493
502
|
async createStorage(): Promise<void> {
|
|
494
503
|
try {
|
|
495
504
|
await this.client.headBucket({ Bucket: this.config.bucket });
|
|
@@ -504,7 +513,7 @@ export class S3ModelService implements ModelCrudSupport, ModelBlobSupport, Model
|
|
|
504
513
|
await this.#deleteKeys(items);
|
|
505
514
|
}
|
|
506
515
|
} else {
|
|
507
|
-
await this.client.deleteBucket({ Bucket: this.config.bucket });
|
|
516
|
+
await ModelStorageUtil.runAndIgnoreNotFound(() => this.client.deleteBucket({ Bucket: this.config.bucket }), isNotFoundError);
|
|
508
517
|
}
|
|
509
518
|
}
|
|
510
519
|
}
|