@travetto/model-s3 6.0.1 → 7.0.0-rc.0
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 +0 -1
- package/package.json +7 -7
- package/src/config.ts +1 -2
- package/src/service.ts +6 -7
- package/support/service.s3.ts +1 -1
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/model-s3",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0-rc.0",
|
|
4
4
|
"description": "S3 backing for the travetto model module.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"s3",
|
|
@@ -25,12 +25,12 @@
|
|
|
25
25
|
"directory": "module/model-s3"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@aws-sdk/client-s3": "^3.
|
|
29
|
-
"@aws-sdk/credential-provider-ini": "^3.
|
|
30
|
-
"@aws-sdk/s3-request-presigner": "^3.
|
|
31
|
-
"@travetto/cli": "^
|
|
32
|
-
"@travetto/config": "^
|
|
33
|
-
"@travetto/model": "^
|
|
28
|
+
"@aws-sdk/client-s3": "^3.940.0",
|
|
29
|
+
"@aws-sdk/credential-provider-ini": "^3.940.0",
|
|
30
|
+
"@aws-sdk/s3-request-presigner": "^3.940.0",
|
|
31
|
+
"@travetto/cli": "^7.0.0-rc.0",
|
|
32
|
+
"@travetto/config": "^7.0.0-rc.0",
|
|
33
|
+
"@travetto/model": "^7.0.0-rc.0"
|
|
34
34
|
},
|
|
35
35
|
"travetto": {
|
|
36
36
|
"displayName": "S3 Model Support"
|
package/src/config.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { fromIni } from '@aws-sdk/credential-provider-ini';
|
|
|
2
2
|
import type s3 from '@aws-sdk/client-s3';
|
|
3
3
|
|
|
4
4
|
import { Config, EnvVar } from '@travetto/config';
|
|
5
|
-
import {
|
|
5
|
+
import { Required } from '@travetto/schema';
|
|
6
6
|
import { Runtime } from '@travetto/runtime';
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -22,7 +22,6 @@ export class S3ModelConfig {
|
|
|
22
22
|
@EnvVar('AWS_PROFILE')
|
|
23
23
|
profile?: string;
|
|
24
24
|
|
|
25
|
-
@Field(Object)
|
|
26
25
|
@Required(false)
|
|
27
26
|
config: s3.S3ClientConfig; // Additional s3 config
|
|
28
27
|
|
package/src/service.ts
CHANGED
|
@@ -8,9 +8,8 @@ import { NodeHttpHandler } from '@smithy/node-http-handler';
|
|
|
8
8
|
import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
|
|
9
9
|
|
|
10
10
|
import {
|
|
11
|
-
ModelCrudSupport, ModelStorageSupport, ModelType,
|
|
11
|
+
ModelCrudSupport, ModelStorageSupport, ModelType, ModelRegistryIndex, ExistsError, NotFoundError, OptionalId,
|
|
12
12
|
ModelBlobSupport, ModelExpirySupport, ModelBlobUtil, ModelCrudUtil, ModelExpiryUtil, ModelStorageUtil,
|
|
13
|
-
|
|
14
13
|
} from '@travetto/model';
|
|
15
14
|
import { Injectable } from '@travetto/di';
|
|
16
15
|
import { Class, AppError, castTo, asFull, BlobMeta, ByteRange, BinaryInput, BinaryUtil, TimeSpan, TimeUtil } from '@travetto/runtime';
|
|
@@ -65,7 +64,7 @@ export class S3ModelService implements ModelCrudSupport, ModelBlobSupport, Model
|
|
|
65
64
|
}
|
|
66
65
|
|
|
67
66
|
#resolveKey(cls: Class | string, id?: string): string {
|
|
68
|
-
let key = typeof cls === 'string' ? cls :
|
|
67
|
+
let key = typeof cls === 'string' ? cls : ModelRegistryIndex.getStoreName(cls);
|
|
69
68
|
if (id) {
|
|
70
69
|
key = `${key}:${id}`;
|
|
71
70
|
}
|
|
@@ -85,7 +84,7 @@ export class S3ModelService implements ModelCrudSupport, ModelBlobSupport, Model
|
|
|
85
84
|
|
|
86
85
|
|
|
87
86
|
#getExpiryConfig<T extends ModelType>(cls: Class<T>, item: T): { Expires?: Date } {
|
|
88
|
-
if (
|
|
87
|
+
if (ModelRegistryIndex.getConfig(cls).expiresAt) {
|
|
89
88
|
const { expiresAt } = ModelExpiryUtil.getExpiryState(cls, item);
|
|
90
89
|
if (expiresAt) {
|
|
91
90
|
return { Expires: expiresAt };
|
|
@@ -197,8 +196,8 @@ export class S3ModelService implements ModelCrudSupport, ModelBlobSupport, Model
|
|
|
197
196
|
async head<T extends ModelType>(cls: Class<T>, id: string): Promise<boolean> {
|
|
198
197
|
try {
|
|
199
198
|
const result = await this.client.headObject(this.#q(cls, id));
|
|
200
|
-
const { expiresAt } =
|
|
201
|
-
if (expiresAt && result.
|
|
199
|
+
const { expiresAt } = ModelRegistryIndex.getConfig(cls);
|
|
200
|
+
if (expiresAt && result.ExpiresString && Date.parse(result.ExpiresString) < Date.now()) {
|
|
202
201
|
return false;
|
|
203
202
|
}
|
|
204
203
|
return true;
|
|
@@ -219,7 +218,7 @@ export class S3ModelService implements ModelCrudSupport, ModelBlobSupport, Model
|
|
|
219
218
|
const body = await toText(castTo(result.Body));
|
|
220
219
|
const output = await ModelCrudUtil.load(cls, body);
|
|
221
220
|
if (output) {
|
|
222
|
-
const { expiresAt } =
|
|
221
|
+
const { expiresAt } = ModelRegistryIndex.getConfig(cls);
|
|
223
222
|
if (expiresAt) {
|
|
224
223
|
const expiry = ModelExpiryUtil.getExpiryState(cls, output);
|
|
225
224
|
if (!expiry.expired) {
|