diff --git a/jest.config.js b/jest.config.js index d155baa8..a72ef676 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,9 +1,7 @@ /* eslint-env node */ -const esModules = ['filter-obj'].join('|'); module.exports = { roots: ['/src'], preset: 'ts-jest/presets/js-with-ts', testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$', - transformIgnorePatterns: [`node_modules/(?!${esModules})`], }; diff --git a/package-lock.json b/package-lock.json index 3ee3c49c..85fae3f7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -26,6 +26,7 @@ "@types/uuid": "^9.0.0", "@typescript-eslint/eslint-plugin": "^5.0.0", "@typescript-eslint/parser": "^5.0.0", + "aws-testing-library": "^4.0.6", "chai": "^4.2.0", "eslint": "^8.0.0", "eslint-config-prettier": "^8.0.0", @@ -2085,6 +2086,22 @@ "uuid": "dist/bin/uuid" } }, + "node_modules/aws-testing-library": { + "version": "4.0.6", + "resolved": "https://registry.npmjs.org/aws-testing-library/-/aws-testing-library-4.0.6.tgz", + "integrity": "sha512-D2pMJug6ObLF7WbA/Qv/qRnWlp2CyScGybetZc2ihQ7EoOGE6MFaortXcnk7eLGqb9MDgcpqgsESkzSt81uY4A==", + "dev": true, + "dependencies": { + "aws-sdk": "^2.678.0", + "axios": "^0.27.0", + "filter-obj": "^3.0.0", + "jest-diff": "^29.0.0", + "uuid": "^9.0.0" + }, + "engines": { + "node": ">=16.10.0" + } + }, "node_modules/axios": { "version": "0.27.2", "resolved": "https://registry.npmjs.org/axios/-/axios-0.27.2.tgz", @@ -8441,6 +8458,19 @@ } } }, + "aws-testing-library": { + "version": "4.0.6", + "resolved": "https://registry.npmjs.org/aws-testing-library/-/aws-testing-library-4.0.6.tgz", + "integrity": "sha512-D2pMJug6ObLF7WbA/Qv/qRnWlp2CyScGybetZc2ihQ7EoOGE6MFaortXcnk7eLGqb9MDgcpqgsESkzSt81uY4A==", + "dev": true, + "requires": { + "aws-sdk": "^2.678.0", + "axios": "^0.27.0", + "filter-obj": "^3.0.0", + "jest-diff": "^29.0.0", + "uuid": "^9.0.0" + } + }, "axios": { "version": "0.27.2", "resolved": "https://registry.npmjs.org/axios/-/axios-0.27.2.tgz", diff --git a/package.json b/package.json index e4f6ed78..67f786a4 100644 --- a/package.json +++ b/package.json @@ -65,7 +65,6 @@ "dependencies": { "aws-sdk": "^2.678.0", "axios": "^0.27.0", - "filter-obj": "^3.0.0", "jest-diff": "^29.0.0", "uuid": "^9.0.0" }, diff --git a/src/common/dynamoDb.ts b/src/common/dynamoDb.ts index 157cfa38..8dc8c45e 100644 --- a/src/common/dynamoDb.ts +++ b/src/common/dynamoDb.ts @@ -1,4 +1,3 @@ -import filterObject from 'filter-obj'; import { AttributeMap } from 'aws-sdk/clients/dynamodb'; import { ICommonProps } from './'; @@ -8,6 +7,29 @@ export interface IDynamoDbProps extends ICommonProps { export const expectedProps = ['region', 'table', 'key']; +type predicate = (key: any, value: any, object: any) => boolean | Array + +const filterObject = ( + object: AttributeMap, + predicate: predicate, +) => { + const result = {}; + const isArray = Array.isArray(predicate); + + for (const [key, value] of Object.entries(object)) { + if (isArray ? predicate.includes(key) : predicate(key, value, object)) { + Object.defineProperty(result, key, { + value, + writable: true, + enumerable: true, + configurable: true, + }); + } + } + + return result; +}; + export const removeKeysFromItemForNonStrictComparison = ( received: AttributeMap, expected: AttributeMap,