@travetto/model-s3 5.0.0-rc.0 → 5.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 CHANGED
@@ -45,7 +45,7 @@ import type s3 from '@aws-sdk/client-s3';
45
45
 
46
46
  import { Config, EnvVar } from '@travetto/config';
47
47
  import { Field, Required } from '@travetto/schema';
48
- import { Env } from '@travetto/base';
48
+ import { Runtime } from '@travetto/runtime';
49
49
 
50
50
  /**
51
51
  * S3 Support as an Asset Source
@@ -100,7 +100,7 @@ export class S3ModelConfig {
100
100
  };
101
101
 
102
102
  // We are in localhost and not in prod, turn on forcePathStyle
103
- if (!Env.production && this.endpoint.includes('localhost')) {
103
+ if (!Runtime.production && this.endpoint.includes('localhost')) {
104
104
  this.config.forcePathStyle ??= true;
105
105
  }
106
106
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/model-s3",
3
- "version": "5.0.0-rc.0",
3
+ "version": "5.0.0-rc.10",
4
4
  "description": "S3 backing for the travetto model module.",
5
5
  "keywords": [
6
6
  "s3",
@@ -27,11 +27,11 @@
27
27
  "dependencies": {
28
28
  "@aws-sdk/client-s3": "^3.609.0",
29
29
  "@aws-sdk/credential-provider-ini": "^3.609.0",
30
- "@travetto/config": "^5.0.0-rc.0",
31
- "@travetto/model": "^5.0.0-rc.0"
30
+ "@travetto/config": "^5.0.0-rc.10",
31
+ "@travetto/model": "^5.0.0-rc.10"
32
32
  },
33
33
  "peerDependencies": {
34
- "@travetto/command": "^5.0.0-rc.0"
34
+ "@travetto/command": "^5.0.0-rc.9"
35
35
  },
36
36
  "peerDependenciesMeta": {
37
37
  "@travetto/command": {
package/src/config.ts CHANGED
@@ -3,7 +3,7 @@ import type s3 from '@aws-sdk/client-s3';
3
3
 
4
4
  import { Config, EnvVar } from '@travetto/config';
5
5
  import { Field, Required } from '@travetto/schema';
6
- import { Env } from '@travetto/base';
6
+ import { Runtime } from '@travetto/runtime';
7
7
 
8
8
  /**
9
9
  * S3 Support as an Asset Source
@@ -58,7 +58,7 @@ export class S3ModelConfig {
58
58
  };
59
59
 
60
60
  // We are in localhost and not in prod, turn on forcePathStyle
61
- if (!Env.production && this.endpoint.includes('localhost')) {
61
+ if (!Runtime.production && this.endpoint.includes('localhost')) {
62
62
  this.config.forcePathStyle ??= true;
63
63
  }
64
64
  }
package/src/service.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Readable } from 'node:stream';
2
- import { buffer as toBuffer } from 'node:stream/consumers';
2
+ import { buffer as toBuffer, text as toText } from 'node:stream/consumers';
3
3
  import { Agent } from 'node:https';
4
4
 
5
5
  import { S3, CompletedPart, type CreateMultipartUploadRequest } from '@aws-sdk/client-s3';
@@ -12,7 +12,7 @@ import {
12
12
  StreamRange
13
13
  } from '@travetto/model';
14
14
  import { Injectable } from '@travetto/di';
15
- import { Class, AppError } from '@travetto/base';
15
+ import { Class, AppError, castTo, asFull } from '@travetto/runtime';
16
16
 
17
17
  import { ModelCrudUtil } from '@travetto/model/src/internal/service/crud';
18
18
  import { ModelExpirySupport } from '@travetto/model/src/service/expiry';
@@ -77,8 +77,7 @@ export class S3ModelService implements ModelCrudSupport, ModelStreamSupport, Mod
77
77
  return key;
78
78
  }
79
79
 
80
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
81
- #q<U extends object>(cls: string | Class, id: string, extra: U = {} as U): (U & { Key: string, Bucket: string }) {
80
+ #q<U extends object>(cls: string | Class, id: string, extra: U = asFull({})): (U & { Key: string, Bucket: string }) {
82
81
  const key = this.#resolveKey(cls, id);
83
82
  return { Key: key, Bucket: this.config.bucket, ...extra };
84
83
  }
@@ -203,8 +202,7 @@ export class S3ModelService implements ModelCrudSupport, ModelStreamSupport, Mod
203
202
  try {
204
203
  const result = await this.client.getObject(this.#q(cls, id));
205
204
  if (result.Body) {
206
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
207
- const body = (await toBuffer(result.Body as Readable)).toString('utf8');
205
+ const body = await toText(castTo(result.Body));
208
206
  const output = await ModelCrudUtil.load(cls, body);
209
207
  if (output) {
210
208
  const { expiresAt } = ModelRegistry.get(cls);
@@ -230,8 +228,7 @@ export class S3ModelService implements ModelCrudSupport, ModelStreamSupport, Mod
230
228
  }
231
229
 
232
230
  async store<T extends ModelType>(cls: Class<T>, item: OptionalId<T>, preStore = true): Promise<T> {
233
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
234
- let prepped: T = item as T;
231
+ let prepped: T = castTo(item);
235
232
  if (preStore) {
236
233
  prepped = await ModelCrudUtil.preStore(cls, item, this);
237
234
  }
@@ -323,13 +320,11 @@ export class S3ModelService implements ModelCrudSupport, ModelStreamSupport, Mod
323
320
  }
324
321
 
325
322
  if (typeof res.Body === 'string') { // string
326
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
327
- return Readable.from(res.Body, { encoding: (res.Body as string).endsWith('=') ? 'base64' : 'utf8' });
323
+ return Readable.from(res.Body, { encoding: castTo<string>(res.Body).endsWith('=') ? 'base64' : 'utf8' });
328
324
  } else if (res.Body instanceof Buffer) { // Buffer
329
325
  return Readable.from(res.Body);
330
326
  } else if ('pipe' in res.Body) { // Stream
331
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
332
- return res.Body as Readable;
327
+ return castTo<Readable>(res.Body);
333
328
  }
334
329
  throw new AppError(`Unable to read type: ${typeof res.Body}`);
335
330
  }
@@ -339,8 +334,7 @@ export class S3ModelService implements ModelCrudSupport, ModelStreamSupport, Mod
339
334
  const meta = await this.describeStream(location);
340
335
  range = enforceRange(range, meta.size);
341
336
  }
342
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
343
- return this.#getObject(location, range as Required<StreamRange>);
337
+ return this.#getObject(location, castTo(range));
344
338
  }
345
339
 
346
340
  async headStream(location: string): Promise<{ Metadata?: Partial<StreamMeta>, ContentLength?: number }> {
@@ -362,10 +356,8 @@ export class S3ModelService implements ModelCrudSupport, ModelStreamSupport, Mod
362
356
 
363
357
  if (obj) {
364
358
  const ret: StreamMeta = {
365
- // @ts-expect-error
366
359
  contentType: '',
367
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
368
- ...obj.Metadata as StreamMeta,
360
+ ...obj.Metadata,
369
361
  size: obj.ContentLength!,
370
362
  };
371
363
  if (hasContentType(ret)) {