@travetto/model-dynamodb 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 CHANGED
@@ -36,13 +36,12 @@ export class Init {
36
36
  }
37
37
  ```
38
38
 
39
- where the [DynamoDBModelConfig](https://github.com/travetto/travetto/tree/main/module/model-dynamodb/src/config.ts#L7) is defined by:
39
+ where the [DynamoDBModelConfig](https://github.com/travetto/travetto/tree/main/module/model-dynamodb/src/config.ts#L6) is defined by:
40
40
 
41
41
  **Code: Structure of DynamoDBModelConfig**
42
42
  ```typescript
43
43
  @Config('model.dynamodb')
44
44
  export class DynamoDBModelConfig {
45
- @Field(Object)
46
45
  client: dynamodb.DynamoDBClientConfig = {
47
46
  endpoint: undefined
48
47
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/model-dynamodb",
3
- "version": "6.0.1",
3
+ "version": "7.0.0-rc.0",
4
4
  "description": "DynamoDB backing for the travetto model module.",
5
5
  "keywords": [
6
6
  "typescript",
@@ -25,10 +25,10 @@
25
25
  "directory": "module/model-dynamodb"
26
26
  },
27
27
  "dependencies": {
28
- "@aws-sdk/client-dynamodb": "^3.902.0",
29
- "@travetto/cli": "^6.0.1",
30
- "@travetto/config": "^6.0.1",
31
- "@travetto/model": "^6.0.1"
28
+ "@aws-sdk/client-dynamodb": "^3.940.0",
29
+ "@travetto/cli": "^7.0.0-rc.0",
30
+ "@travetto/config": "^7.0.0-rc.0",
31
+ "@travetto/model": "^7.0.0-rc.0"
32
32
  },
33
33
  "travetto": {
34
34
  "displayName": "DynamoDB Model Support"
package/src/config.ts CHANGED
@@ -1,11 +1,9 @@
1
1
  import type dynamodb from '@aws-sdk/client-dynamodb';
2
2
 
3
3
  import { Config } from '@travetto/config';
4
- import { Field } from '@travetto/schema';
5
4
 
6
5
  @Config('model.dynamodb')
7
6
  export class DynamoDBModelConfig {
8
- @Field(Object)
9
7
  client: dynamodb.DynamoDBClientConfig = {
10
8
  endpoint: undefined
11
9
  };
package/src/service.ts CHANGED
@@ -6,7 +6,7 @@ import {
6
6
  import { ShutdownManager, TimeUtil, type Class, type DeepPartial } from '@travetto/runtime';
7
7
  import { Injectable } from '@travetto/di';
8
8
  import {
9
- ModelCrudSupport, ModelExpirySupport, ModelRegistry, ModelStorageSupport,
9
+ ModelCrudSupport, ModelExpirySupport, ModelRegistryIndex, ModelStorageSupport,
10
10
  ModelIndexedSupport, ModelType, NotFoundError, ExistsError,
11
11
  IndexNotSupported, OptionalId,
12
12
  ModelCrudUtil, ModelExpiryUtil, ModelIndexedUtil, ModelStorageUtil
@@ -37,7 +37,7 @@ function toValue(val: unknown): AttributeValue | undefined {
37
37
 
38
38
  async function loadAndCheckExpiry<T extends ModelType>(cls: Class<T>, doc: string): Promise<T> {
39
39
  const item = await ModelCrudUtil.load(cls, doc);
40
- if (ModelRegistry.get(cls).expiresAt) {
40
+ if (ModelRegistryIndex.getConfig(cls).expiresAt) {
41
41
  const expiry = ModelExpiryUtil.getExpiryState(cls, item);
42
42
  if (!expiry.expired) {
43
43
  return item;
@@ -61,7 +61,7 @@ export class DynamoDBModelService implements ModelCrudSupport, ModelExpirySuppor
61
61
  constructor(config: DynamoDBModelConfig) { this.config = config; }
62
62
 
63
63
  #resolveTable(cls: Class): string {
64
- let table = ModelRegistry.getStore(cls).toLowerCase().replace(/[^A-Za-z0-9_]+/g, '_');
64
+ let table = ModelRegistryIndex.getStoreName(cls).toLowerCase().replace(/[^A-Za-z0-9_]+/g, '_');
65
65
  if (this.config.namespace) {
66
66
  table = `${this.config.namespace}_${table}`;
67
67
  }
@@ -69,7 +69,7 @@ export class DynamoDBModelService implements ModelCrudSupport, ModelExpirySuppor
69
69
  }
70
70
 
71
71
  async #putItem<T extends ModelType>(cls: Class<T>, id: string, item: T, mode: 'create' | 'update' | 'upsert'): Promise<PutItemCommandOutput> {
72
- const config = ModelRegistry.get(cls);
72
+ const config = ModelRegistryIndex.getConfig(cls);
73
73
  let expiry: number | undefined;
74
74
 
75
75
  if (config.expiresAt) {
@@ -147,7 +147,7 @@ export class DynamoDBModelService implements ModelCrudSupport, ModelExpirySuppor
147
147
  }
148
148
 
149
149
  #computeIndexConfig<T extends ModelType>(cls: Class<T>): { indices?: GlobalSecondaryIndex[], attributes: AttributeDefinition[] } {
150
- const config = ModelRegistry.get(cls);
150
+ const config = ModelRegistryIndex.getConfig(cls);
151
151
  const attributes: AttributeDefinition[] = [];
152
152
  const indices: GlobalSecondaryIndex[] = [];
153
153
 
@@ -215,7 +215,7 @@ export class DynamoDBModelService implements ModelCrudSupport, ModelExpirySuppor
215
215
  GlobalSecondaryIndexes: idx.indices
216
216
  });
217
217
 
218
- if (ModelRegistry.get(cls).expiresAt) {
218
+ if (ModelRegistryIndex.getConfig(cls).expiresAt) {
219
219
  await this.client.updateTimeToLive({
220
220
  TableName: table,
221
221
  TimeToLiveSpecification: { AttributeName: EXP_ATTR, Enabled: true }
@@ -259,7 +259,7 @@ export class DynamoDBModelService implements ModelCrudSupport, ModelExpirySuppor
259
259
  }
260
260
 
261
261
  async deleteStorage(): Promise<void> {
262
- for (const model of ModelRegistry.getClasses()) {
262
+ for (const model of ModelRegistryIndex.getClasses()) {
263
263
  await this.client.deleteTable({
264
264
  TableName: this.#resolveTable(model)
265
265
  }).catch(() => { });
@@ -288,7 +288,7 @@ export class DynamoDBModelService implements ModelCrudSupport, ModelExpirySuppor
288
288
  async update<T extends ModelType>(cls: Class<T>, item: T): Promise<T> {
289
289
  ModelCrudUtil.ensureNotSubType(cls);
290
290
  item = await ModelCrudUtil.preStore(cls, item, this);
291
- if (ModelRegistry.get(cls).expiresAt) {
291
+ if (ModelRegistryIndex.getConfig(cls).expiresAt) {
292
292
  await this.get(cls, item.id);
293
293
  }
294
294
  await this.#putItem(cls, item.id, item, 'update');
@@ -360,7 +360,7 @@ export class DynamoDBModelService implements ModelCrudSupport, ModelExpirySuppor
360
360
  async #getIdByIndex<T extends ModelType>(cls: Class<T>, idx: string, body: DeepPartial<T>): Promise<string> {
361
361
  ModelCrudUtil.ensureNotSubType(cls);
362
362
 
363
- const idxCfg = ModelRegistry.getIndex(cls, idx, ['sorted', 'unsorted']);
363
+ const idxCfg = ModelRegistryIndex.getIndex(cls, idx, ['sorted', 'unsorted']);
364
364
 
365
365
  const { key, sort } = ModelIndexedUtil.computeIndexKey(cls, idxCfg, body);
366
366
 
@@ -405,7 +405,7 @@ export class DynamoDBModelService implements ModelCrudSupport, ModelExpirySuppor
405
405
  async * listByIndex<T extends ModelType>(cls: Class<T>, idx: string, body?: DeepPartial<T>): AsyncIterable<T> {
406
406
  ModelCrudUtil.ensureNotSubType(cls);
407
407
 
408
- const cfg = ModelRegistry.getIndex(cls, idx, ['sorted', 'unsorted']);
408
+ const cfg = ModelRegistryIndex.getIndex(cls, idx, ['sorted', 'unsorted']);
409
409
  const { key } = ModelIndexedUtil.computeIndexKey(cls, cfg, body, { emptySortValue: null });
410
410
 
411
411
  const idxName = simpleName(idx);
@@ -1,6 +1,6 @@
1
1
  import type { ServiceDescriptor } from '@travetto/cli';
2
2
 
3
- const version = process.env.DYNAMODB_VERSION || '3.0.0';
3
+ const version = process.env.DYNAMODB_VERSION || '3.1.0';
4
4
 
5
5
  export const service: ServiceDescriptor = {
6
6
  name: 'dynamodb',