@travetto/model-s3 3.0.0-rc.1 → 3.0.0-rc.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.
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/doc.ts and execute "npx trv doc" to rebuild -->
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#L12) is defined by:
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 * as S3 from '@aws-sdk/client-s3';
38
+ import type s3 from '@aws-sdk/client-s3';
39
39
 
40
- import { EnvUtil } from '@travetto/boot';
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
- accessKeyId: string = EnvUtil.get('AWS_ACCESS_KEY_ID', '');
55
- secretAccessKey: string = EnvUtil.get('AWS_SECRET_ACCESS_KEY', '');
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: S3.S3ClientConfig; // Additional s3 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: EnvUtil.get('AWS_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#L9) annotation, and so these values can be overridden using the
96
- standard [Configuration](https://github.com/travetto/travetto/tree/main/module/config#readme "Environment-aware config management using yaml files")resolution paths.
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
- "displayName": "S3 Model Support",
4
- "version": "3.0.0-rc.1",
3
+ "version": "3.0.0-rc.11",
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
- "index.ts",
18
+ "__index__.ts",
20
19
  "src"
21
20
  ],
22
- "main": "index.ts",
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.160.0",
29
- "@aws-sdk/credential-provider-ini": "^3.160.0",
30
- "@travetto/config": "^3.0.0-rc.1",
31
- "@travetto/model": "^3.0.0-rc.1"
27
+ "@aws-sdk/client-s3": "^3.262.0",
28
+ "@aws-sdk/credential-provider-ini": "^3.218.0",
29
+ "@travetto/config": "^3.0.0-rc.11",
30
+ "@travetto/model": "^3.0.0-rc.11"
31
+ },
32
+ "peerDependencies": {
33
+ "@travetto/command": "^3.0.0-rc.8"
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 * as S3 from '@aws-sdk/client-s3';
2
+ import type s3 from '@aws-sdk/client-s3';
3
3
 
4
- import { EnvUtil } from '@travetto/boot';
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
- accessKeyId: string = EnvUtil.get('AWS_ACCESS_KEY_ID', '');
19
- secretAccessKey: string = EnvUtil.get('AWS_SECRET_ACCESS_KEY', '');
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: S3.S3ClientConfig; // Additional s3 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: EnvUtil.get('AWS_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,18 @@ 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, Util } from '@travetto/base';
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 { ModelStorageUtil } from '@travetto/model/src/internal/service/storage';
17
+ import { ModelUtil } from '@travetto/model/src/internal/util';
17
18
 
18
19
  import { S3ModelConfig } from './config';
19
20
 
@@ -22,10 +23,10 @@ function isMetadataBearer(o: unknown): o is MetadataBearer {
22
23
  }
23
24
 
24
25
  function hasContentType<T>(o: T): o is T & { contenttype?: string } {
25
- return o && 'contenttype' in o;
26
+ return o !== undefined && o !== null && Object.hasOwn(o, 'contenttype');
26
27
  }
27
28
 
28
- const STREAM_SPACE = '@trv:stream';
29
+ const STREAM_SPACE = '@travetto/model-s3:stream';
29
30
 
30
31
  /**
31
32
  * Asset source backed by S3
@@ -147,11 +148,12 @@ export class S3ModelService implements ModelCrudSupport, ModelStreamSupport, Mod
147
148
  }
148
149
 
149
150
  uuid(): string {
150
- return Util.uuid(32);
151
+ return ModelUtil.uuid(32);
151
152
  }
152
153
 
153
154
  async postConstruct(): Promise<void> {
154
155
  this.client = new s3.S3(this.config.config);
156
+ ModelStorageUtil.registerModelChangeListener(this);
155
157
  }
156
158
 
157
159
  async head<T extends ModelType>(cls: Class<T>, id: string): Promise<boolean> {
@@ -176,7 +178,8 @@ export class S3ModelService implements ModelCrudSupport, ModelStreamSupport, Mod
176
178
  try {
177
179
  const result = await this.client.getObject(this.#q(cls, id));
178
180
  if (result.Body) {
179
- const body = (await StreamUtil.streamToBuffer(result.Body)).toString('utf8');
181
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
182
+ const body = (await StreamUtil.streamToBuffer(result.Body as Readable)).toString('utf8');
180
183
  const output = await ModelCrudUtil.load(cls, body);
181
184
  if (output) {
182
185
  const { expiresAt } = ModelRegistry.get(cls);