@travetto/model-s3 3.0.0-rc.1 → 3.0.0-rc.10
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 +14 -11
- package/{index.ts → __index__.ts} +0 -0
- package/package.json +18 -8
- package/src/config.ts +10 -7
- package/src/service.ts +7 -6
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<!-- This file was generated by @travetto/doc and should not be modified directly -->
|
|
2
|
-
<!-- Please modify https://github.com/travetto/travetto/tree/main/module/model-s3/
|
|
2
|
+
<!-- Please modify https://github.com/travetto/travetto/tree/main/module/model-s3/DOC.ts and execute "npx trv doc" to rebuild -->
|
|
3
3
|
# S3 Model Support
|
|
4
4
|
## S3 backing for the travetto model module.
|
|
5
5
|
|
|
@@ -29,16 +29,15 @@ export class Init {
|
|
|
29
29
|
}
|
|
30
30
|
```
|
|
31
31
|
|
|
32
|
-
where the [S3ModelConfig](https://github.com/travetto/travetto/tree/main/module/model-s3/src/config.ts#
|
|
32
|
+
where the [S3ModelConfig](https://github.com/travetto/travetto/tree/main/module/model-s3/src/config.ts#L11) is defined by:
|
|
33
33
|
|
|
34
34
|
|
|
35
35
|
**Code: Structure of S3ModelConfig**
|
|
36
36
|
```typescript
|
|
37
37
|
import { fromIni } from '@aws-sdk/credential-provider-ini';
|
|
38
|
-
import
|
|
38
|
+
import type s3 from '@aws-sdk/client-s3';
|
|
39
39
|
|
|
40
|
-
import {
|
|
41
|
-
import { Config } from '@travetto/config';
|
|
40
|
+
import { Config, EnvVar } from '@travetto/config';
|
|
42
41
|
import { Field, Required } from '@travetto/schema';
|
|
43
42
|
|
|
44
43
|
/**
|
|
@@ -51,12 +50,16 @@ export class S3ModelConfig {
|
|
|
51
50
|
bucket = ''; // S3 bucket
|
|
52
51
|
endpoint = ''; // Endpoint url
|
|
53
52
|
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
@EnvVar('AWS_ACCESS_KEY_ID')
|
|
54
|
+
accessKeyId: string = '';
|
|
55
|
+
@EnvVar('AWS_SECRET_ACCESS_KEY')
|
|
56
|
+
secretAccessKey: string = '';
|
|
57
|
+
@EnvVar('AWS_PROFILE')
|
|
58
|
+
profile?: string;
|
|
56
59
|
|
|
57
60
|
@Field(Object)
|
|
58
61
|
@Required(false)
|
|
59
|
-
config:
|
|
62
|
+
config: s3.S3ClientConfig; // Additional s3 config
|
|
60
63
|
|
|
61
64
|
chunkSize = 5 * 2 ** 20; // Chunk size in bytes
|
|
62
65
|
|
|
@@ -74,7 +77,7 @@ export class S3ModelConfig {
|
|
|
74
77
|
*/
|
|
75
78
|
async postConstruct(): Promise<void> {
|
|
76
79
|
if (!this.accessKeyId && !this.secretAccessKey) {
|
|
77
|
-
const creds = await fromIni({ profile:
|
|
80
|
+
const creds = await fromIni({ profile: this.profile })();
|
|
78
81
|
this.accessKeyId = creds.accessKeyId;
|
|
79
82
|
this.secretAccessKey = creds.secretAccessKey;
|
|
80
83
|
}
|
|
@@ -92,8 +95,8 @@ export class S3ModelConfig {
|
|
|
92
95
|
}
|
|
93
96
|
```
|
|
94
97
|
|
|
95
|
-
Additionally, you can see that the class is registered with the [@Config](https://github.com/travetto/travetto/tree/main/module/config/src/decorator.ts#
|
|
96
|
-
standard [Configuration](https://github.com/travetto/travetto/tree/main/module/config#readme "
|
|
98
|
+
Additionally, you can see that the class is registered with the [@Config](https://github.com/travetto/travetto/tree/main/module/config/src/decorator.ts#L13) annotation, and so these values can be overridden using the
|
|
99
|
+
standard [Configuration](https://github.com/travetto/travetto/tree/main/module/config#readme "Configuration support")resolution paths.
|
|
97
100
|
|
|
98
101
|
|
|
99
102
|
**Note**: Do not commit your `accessKeyId` or `secretAccessKey` values to your source repository, especially if it is public facing. Not only is it a security risk, but Amazon will scan public repos, looking for keys, and if found will react swiftly.
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/model-s3",
|
|
3
|
-
"
|
|
4
|
-
"version": "3.0.0-rc.1",
|
|
3
|
+
"version": "3.0.0-rc.10",
|
|
5
4
|
"description": "S3 backing for the travetto model module.",
|
|
6
5
|
"keywords": [
|
|
7
6
|
"s3",
|
|
@@ -16,19 +15,30 @@
|
|
|
16
15
|
"name": "Travetto Framework"
|
|
17
16
|
},
|
|
18
17
|
"files": [
|
|
19
|
-
"
|
|
18
|
+
"__index__.ts",
|
|
20
19
|
"src"
|
|
21
20
|
],
|
|
22
|
-
"main": "
|
|
21
|
+
"main": "__index__.ts",
|
|
23
22
|
"repository": {
|
|
24
23
|
"url": "https://github.com/travetto/travetto.git",
|
|
25
24
|
"directory": "module/model-s3"
|
|
26
25
|
},
|
|
27
26
|
"dependencies": {
|
|
28
|
-
"@aws-sdk/client-s3": "^3.
|
|
29
|
-
"@aws-sdk/credential-provider-ini": "^3.
|
|
30
|
-
"@travetto/config": "^3.0.0-rc.
|
|
31
|
-
"@travetto/model": "^3.0.0-rc.
|
|
27
|
+
"@aws-sdk/client-s3": "^3.245.0",
|
|
28
|
+
"@aws-sdk/credential-provider-ini": "^3.218.0",
|
|
29
|
+
"@travetto/config": "^3.0.0-rc.10",
|
|
30
|
+
"@travetto/model": "^3.0.0-rc.10"
|
|
31
|
+
},
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"@travetto/command": "^3.0.0-rc.7"
|
|
34
|
+
},
|
|
35
|
+
"peerDependenciesMeta": {
|
|
36
|
+
"@travetto/command": {
|
|
37
|
+
"optional": true
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"travetto": {
|
|
41
|
+
"displayName": "S3 Model Support"
|
|
32
42
|
},
|
|
33
43
|
"publishConfig": {
|
|
34
44
|
"access": "public"
|
package/src/config.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { fromIni } from '@aws-sdk/credential-provider-ini';
|
|
2
|
-
import
|
|
2
|
+
import type s3 from '@aws-sdk/client-s3';
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
import { Config } from '@travetto/config';
|
|
4
|
+
import { Config, EnvVar } from '@travetto/config';
|
|
6
5
|
import { Field, Required } from '@travetto/schema';
|
|
7
6
|
|
|
8
7
|
/**
|
|
@@ -15,12 +14,16 @@ export class S3ModelConfig {
|
|
|
15
14
|
bucket = ''; // S3 bucket
|
|
16
15
|
endpoint = ''; // Endpoint url
|
|
17
16
|
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
@EnvVar('AWS_ACCESS_KEY_ID')
|
|
18
|
+
accessKeyId: string = '';
|
|
19
|
+
@EnvVar('AWS_SECRET_ACCESS_KEY')
|
|
20
|
+
secretAccessKey: string = '';
|
|
21
|
+
@EnvVar('AWS_PROFILE')
|
|
22
|
+
profile?: string;
|
|
20
23
|
|
|
21
24
|
@Field(Object)
|
|
22
25
|
@Required(false)
|
|
23
|
-
config:
|
|
26
|
+
config: s3.S3ClientConfig; // Additional s3 config
|
|
24
27
|
|
|
25
28
|
chunkSize = 5 * 2 ** 20; // Chunk size in bytes
|
|
26
29
|
|
|
@@ -38,7 +41,7 @@ export class S3ModelConfig {
|
|
|
38
41
|
*/
|
|
39
42
|
async postConstruct(): Promise<void> {
|
|
40
43
|
if (!this.accessKeyId && !this.secretAccessKey) {
|
|
41
|
-
const creds = await fromIni({ profile:
|
|
44
|
+
const creds = await fromIni({ profile: this.profile })();
|
|
42
45
|
this.accessKeyId = creds.accessKeyId;
|
|
43
46
|
this.secretAccessKey = creds.secretAccessKey;
|
|
44
47
|
}
|
package/src/service.ts
CHANGED
|
@@ -3,17 +3,17 @@ import { Readable } from 'stream';
|
|
|
3
3
|
import * as s3 from '@aws-sdk/client-s3';
|
|
4
4
|
import type { MetadataBearer } from '@aws-sdk/types';
|
|
5
5
|
|
|
6
|
-
import { StreamUtil } from '@travetto/boot';
|
|
7
6
|
import {
|
|
8
7
|
ModelCrudSupport, ModelStreamSupport, ModelStorageSupport, StreamMeta,
|
|
9
8
|
ModelType, ModelRegistry, ExistsError, NotFoundError, OptionalId
|
|
10
9
|
} from '@travetto/model';
|
|
11
10
|
import { Injectable } from '@travetto/di';
|
|
12
|
-
import { Class, AppError
|
|
11
|
+
import { StreamUtil, Class, AppError } from '@travetto/base';
|
|
13
12
|
|
|
14
13
|
import { ModelCrudUtil } from '@travetto/model/src/internal/service/crud';
|
|
15
14
|
import { ModelExpirySupport } from '@travetto/model/src/service/expiry';
|
|
16
15
|
import { ModelExpiryUtil } from '@travetto/model/src/internal/service/expiry';
|
|
16
|
+
import { ModelUtil } from '@travetto/model/src/internal/util';
|
|
17
17
|
|
|
18
18
|
import { S3ModelConfig } from './config';
|
|
19
19
|
|
|
@@ -22,10 +22,10 @@ function isMetadataBearer(o: unknown): o is MetadataBearer {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
function hasContentType<T>(o: T): o is T & { contenttype?: string } {
|
|
25
|
-
return o && 'contenttype'
|
|
25
|
+
return o !== undefined && o !== null && Object.hasOwn(o, 'contenttype');
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
const STREAM_SPACE = '@
|
|
28
|
+
const STREAM_SPACE = '@travetto/model-s3:stream';
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
31
|
* Asset source backed by S3
|
|
@@ -147,7 +147,7 @@ export class S3ModelService implements ModelCrudSupport, ModelStreamSupport, Mod
|
|
|
147
147
|
}
|
|
148
148
|
|
|
149
149
|
uuid(): string {
|
|
150
|
-
return
|
|
150
|
+
return ModelUtil.uuid(32);
|
|
151
151
|
}
|
|
152
152
|
|
|
153
153
|
async postConstruct(): Promise<void> {
|
|
@@ -176,7 +176,8 @@ export class S3ModelService implements ModelCrudSupport, ModelStreamSupport, Mod
|
|
|
176
176
|
try {
|
|
177
177
|
const result = await this.client.getObject(this.#q(cls, id));
|
|
178
178
|
if (result.Body) {
|
|
179
|
-
|
|
179
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
180
|
+
const body = (await StreamUtil.streamToBuffer(result.Body as Readable)).toString('utf8');
|
|
180
181
|
const output = await ModelCrudUtil.load(cls, body);
|
|
181
182
|
if (output) {
|
|
182
183
|
const { expiresAt } = ModelRegistry.get(cls);
|