@squiz/db-lib 1.66.2 → 1.67.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@squiz/db-lib",
3
- "version": "1.66.2",
3
+ "version": "1.67.0",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "private": false,
@@ -20,6 +20,8 @@
20
20
  "@types/jest": "28.1.8",
21
21
  "@types/node": "20.12.4",
22
22
  "@types/pg": "8.6.6",
23
+ "aws-sdk-client-mock": "^4.0.0",
24
+ "aws-sdk-client-mock-jest": "4.0.0",
23
25
  "eslint": "8.33.0",
24
26
  "fs-extra": "11.1.0",
25
27
  "jest": "29.4.1",
@@ -27,13 +29,13 @@
27
29
  "ts-jest": "29.0.5",
28
30
  "ts-loader": "9.3.1",
29
31
  "ts-node": "10.9.2",
30
- "typescript": "4.9.4",
31
- "aws-sdk-client-mock": "^4.0.0",
32
- "aws-sdk-client-mock-jest": "4.0.0"
32
+ "typescript": "4.9.4"
33
33
  },
34
34
  "dependencies": {
35
+ "@aws-sdk/client-dynamodb": "^3.632.0",
35
36
  "@aws-sdk/client-secrets-manager": "3.614.0",
36
- "@squiz/dx-common-lib": "^1.66.3",
37
+ "@aws-sdk/lib-dynamodb": "^3.632.0",
38
+ "@squiz/dx-common-lib": "^1.66.4",
37
39
  "@squiz/dx-logger-lib": "^1.64.0",
38
40
  "dotenv": "16.0.3",
39
41
  "pg": "8.9.0"
@@ -22,7 +22,6 @@ import { MissingKeyValuesError, InvalidDbSchemaError } from '..';
22
22
  import { mockClient } from 'aws-sdk-client-mock';
23
23
  import 'aws-sdk-client-mock-jest';
24
24
  import { DynamoDB } from '@aws-sdk/client-dynamodb';
25
- import { DuplicateItemError } from '../error/DuplicateItemError';
26
25
  import crypto from 'crypto';
27
26
 
28
27
  const ddbClientMock = mockClient(DynamoDBDocumentClient);
@@ -167,23 +166,6 @@ describe('AbstractRepository', () => {
167
166
  await expect(repository.createItem(item)).rejects.toEqual(new Error('Invalid "data"'));
168
167
  });
169
168
 
170
- it('should throw error if item already exists input', async () => {
171
- ddbClientMock.on(PutCommand).rejects(
172
- new ConditionalCheckFailedException({
173
- $metadata: {},
174
- message: 'already exists',
175
- }),
176
- );
177
-
178
- const item = {
179
- name: 'foo',
180
- age: 99,
181
- country: 'au',
182
- data: {},
183
- };
184
- await expect(repository.createItem(item)).rejects.toEqual(new DuplicateItemError('Item already exists'));
185
- });
186
-
187
169
  it('should throw error if excess column in input', async () => {
188
170
  const item = {
189
171
  name: 'foo',
@@ -1,5 +1,3 @@
1
- import { ConditionalCheckFailedException } from '@aws-sdk/client-dynamodb';
2
-
3
1
  import {
4
2
  DynamoDBDocument,
5
3
  QueryCommandInput,
@@ -8,7 +6,7 @@ import {
8
6
  DeleteCommandInput,
9
7
  } from '@aws-sdk/lib-dynamodb';
10
8
 
11
- import { Transaction, DynamoDbManager, MissingKeyValuesError, DuplicateItemError, InvalidDbSchemaError } from '..';
9
+ import { Transaction, DynamoDbManager, MissingKeyValuesError, InvalidDbSchemaError } from '..';
12
10
 
13
11
  interface Reader<T> {
14
12
  queryItems(partialItem: Partial<T>, useSortKey?: boolean, index?: keyof TableIndexes): Promise<T[]>;
@@ -214,8 +212,8 @@ export abstract class AbstractDynamoDbRepository<SHAPE extends object, DATA_CLAS
214
212
  ...updateCommandInput,
215
213
  ReturnValues: 'ALL_NEW',
216
214
  });
217
- } catch (e) {
218
- if (e instanceof ConditionalCheckFailedException) {
215
+ } catch (e: any) {
216
+ if (e && e.name === 'ConditionalCheckFailedException') {
219
217
  return undefined;
220
218
  }
221
219
  throw e;
@@ -275,14 +273,8 @@ export abstract class AbstractDynamoDbRepository<SHAPE extends object, DATA_CLAS
275
273
  return value;
276
274
  }
277
275
 
278
- try {
279
- await this.client.put(putCommandInput);
280
- } catch (e) {
281
- if (e instanceof ConditionalCheckFailedException) {
282
- throw new DuplicateItemError(`Item already exists`);
283
- }
284
- throw e;
285
- }
276
+ await this.client.put(putCommandInput);
277
+
286
278
  return value;
287
279
  }
288
280
 
@@ -315,8 +307,8 @@ export abstract class AbstractDynamoDbRepository<SHAPE extends object, DATA_CLAS
315
307
 
316
308
  try {
317
309
  await this.client.delete(deleteCommandInput);
318
- } catch (e) {
319
- if (e instanceof ConditionalCheckFailedException) {
310
+ } catch (e: any) {
311
+ if (e && e.name === 'ConditionalCheckFailedException') {
320
312
  return 0;
321
313
  }
322
314
  throw e;