@travetto/model-dynamodb 2.0.2 → 2.1.1

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.
Files changed (2) hide show
  1. package/package.json +4 -4
  2. package/src/service.ts +7 -19
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@travetto/model-dynamodb",
3
3
  "displayName": "DynamoDB Model Support",
4
- "version": "2.0.2",
4
+ "version": "2.1.1",
5
5
  "description": "DynamoDB backing for the travetto model module.",
6
6
  "keywords": [
7
7
  "typescript",
@@ -26,9 +26,9 @@
26
26
  "directory": "module/model-dynamodb"
27
27
  },
28
28
  "dependencies": {
29
- "@aws-sdk/client-dynamodb": "^3.18.0",
30
- "@travetto/config": "^2.0.2",
31
- "@travetto/model": "^2.0.2"
29
+ "@aws-sdk/client-dynamodb": "^3.53.0",
30
+ "@travetto/config": "^2.1.1",
31
+ "@travetto/model": "^2.1.1"
32
32
  },
33
33
  "publishConfig": {
34
34
  "access": "public"
package/src/service.ts CHANGED
@@ -5,7 +5,7 @@ import { DeepPartial } from '@travetto/schema';
5
5
  import { Injectable } from '@travetto/di';
6
6
  import {
7
7
  ModelCrudSupport, ModelExpirySupport, ModelRegistry, ModelStorageSupport,
8
- ModelIndexedSupport, ModelType, NotFoundError, ExistsError, SubTypeNotSupportedError,
8
+ ModelIndexedSupport, ModelType, NotFoundError, ExistsError,
9
9
  IndexNotSupported, OptionalId
10
10
  } from '@travetto/model';
11
11
 
@@ -290,9 +290,7 @@ export class DynamoDBModelService implements ModelCrudSupport, ModelExpirySuppor
290
290
  }
291
291
 
292
292
  async update<T extends ModelType>(cls: Class<T>, item: T) {
293
- if (ModelRegistry.get(cls).subType) {
294
- throw new SubTypeNotSupportedError(cls);
295
- }
293
+ ModelCrudUtil.ensureNotSubType(cls);
296
294
  item = await ModelCrudUtil.preStore(cls, item, this);
297
295
  if (ModelRegistry.get(cls).expiresAt) {
298
296
  await this.get(cls, item.id);
@@ -302,18 +300,14 @@ export class DynamoDBModelService implements ModelCrudSupport, ModelExpirySuppor
302
300
  }
303
301
 
304
302
  async upsert<T extends ModelType>(cls: Class<T>, item: OptionalId<T>) {
305
- if (ModelRegistry.get(cls).subType) {
306
- throw new SubTypeNotSupportedError(cls);
307
- }
303
+ ModelCrudUtil.ensureNotSubType(cls);
308
304
  const prepped = await ModelCrudUtil.preStore(cls, item, this);
309
305
  await this.#putItem(cls, prepped.id, prepped, 'upsert');
310
306
  return prepped;
311
307
  }
312
308
 
313
309
  async updatePartial<T extends ModelType>(cls: Class<T>, item: Partial<T> & { id: string }, view?: string) {
314
- if (ModelRegistry.get(cls).subType) {
315
- throw new SubTypeNotSupportedError(cls);
316
- }
310
+ ModelCrudUtil.ensureNotSubType(cls);
317
311
  const id = item.id;
318
312
  item = await ModelCrudUtil.naivePartialUpdate(cls, item, view, () => this.get(cls, id)) as T;
319
313
  await this.#putItem(cls, id, item as T, 'update');
@@ -321,9 +315,7 @@ export class DynamoDBModelService implements ModelCrudSupport, ModelExpirySuppor
321
315
  }
322
316
 
323
317
  async delete<T extends ModelType>(cls: Class<T>, id: string) {
324
- if (ModelRegistry.get(cls).subType) {
325
- throw new SubTypeNotSupportedError(cls);
326
- }
318
+ ModelCrudUtil.ensureNotSubType(cls);
327
319
  const res = await this.client.deleteItem({
328
320
  TableName: this.#resolveTable(cls),
329
321
  ReturnValues: 'ALL_OLD',
@@ -370,9 +362,7 @@ export class DynamoDBModelService implements ModelCrudSupport, ModelExpirySuppor
370
362
 
371
363
  // Indexed
372
364
  async #getIdByIndex<T extends ModelType>(cls: Class<T>, idx: string, body: DeepPartial<T>) {
373
- if (ModelRegistry.get(cls).subType) {
374
- throw new SubTypeNotSupportedError(cls);
375
- }
365
+ ModelCrudUtil.ensureNotSubType(cls);
376
366
 
377
367
  const idxCfg = ModelRegistry.getIndex(cls, idx, ['sorted', 'unsorted']);
378
368
 
@@ -417,9 +407,7 @@ export class DynamoDBModelService implements ModelCrudSupport, ModelExpirySuppor
417
407
  }
418
408
 
419
409
  async * listByIndex<T extends ModelType>(cls: Class<T>, idx: string, body?: DeepPartial<T>) {
420
- if (ModelRegistry.get(cls).subType) {
421
- throw new SubTypeNotSupportedError(cls);
422
- }
410
+ ModelCrudUtil.ensureNotSubType(cls);
423
411
 
424
412
  const cfg = ModelRegistry.getIndex(cls, idx, ['sorted', 'unsorted']);
425
413
  const { key } = ModelIndexedUtil.computeIndexKey(cls, cfg, body, { emptySortValue: null });