Skip to content

Commit

Permalink
Improve test & build definition process (dynamodb-toolbox#324)
Browse files Browse the repository at this point in the history
improve test & build definition process
  • Loading branch information
ThomasAribart authored Sep 3, 2022
1 parent 87e0caf commit d93b8e8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 29 deletions.
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
roots: ['<rootDir>/src'],
testMatch: ['**/__tests__/**/*.+(ts|tsx|js)', '**/?(*.)+(spec|test).+(ts|tsx|js)'],
testMatch: ['**/?(*.)+(unit.test).+(ts|tsx|js)'],
testPathIgnorePatterns: ['/__tests__/entities/*', '/__tests__/tables/*'],
coveragePathIgnorePatterns: ['/__tests__/*'],
transform: {
Expand Down
49 changes: 21 additions & 28 deletions src/classes/Table/Table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,12 @@ import type {
TransactGetParamsMeta,
transactGetParamsOptions,
TransactWriteOptions,
transactWriteParamsOptions,
} from './types';
transactWriteParamsOptions
} from './types'

// Import standard error handler
import { error, conditionError, hasProperty, If } from '../../lib/utils'


// Declare Table class
class Table<Name extends string, PartitionKey extends A.Key, SortKey extends A.Key | null> {
private _execute: boolean = true
Expand Down Expand Up @@ -102,6 +101,7 @@ class Table<Name extends string, PartitionKey extends A.Key, SortKey extends A.K
docClient: (DocumentClient & { options?: { convertEmptyValues: boolean } }) | undefined
) {
// If a valid document client
// @ts-ignore
if (docClient && docClient.get && docClient.put && docClient.delete && docClient.update) {
// Automatically set convertEmptyValues to true, unless false
if (docClient.options!.convertEmptyValues !== false)
Expand Down Expand Up @@ -722,24 +722,23 @@ class Table<Name extends string, PartitionKey extends A.Key, SortKey extends A.K
return Object.assign(
result,
{
Items:
result.Items?.map(item => {
const itemEntityName = item[String(this.Table.entityField)]
const itemEntityInstance = this[itemEntityName];

if (itemEntityInstance != null) {
return itemEntityInstance.parse(
item,
EntityProjections[itemEntityName]
? EntityProjections[itemEntityName]
: TableProjections
? TableProjections
: []
)
} else {
return item
}
})
Items: result.Items?.map(item => {
const itemEntityName = item[String(this.Table.entityField)]
const itemEntityInstance = this[itemEntityName]

if (itemEntityInstance != null) {
return itemEntityInstance.parse(
item,
EntityProjections[itemEntityName]
? EntityProjections[itemEntityName]
: TableProjections
? TableProjections
: []
)
} else {
return item
}
})
},
// If last evaluated key, return a next function
result.LastEvaluatedKey
Expand Down Expand Up @@ -1067,13 +1066,7 @@ class Table<Name extends string, PartitionKey extends A.Key, SortKey extends A.K
const item = items[i]

// Check item for Table reference and key
if (
item &&
item.Table &&
item.Table.Table &&
item.Key &&
item.Key?.constructor === Object
) {
if (item && item.Table && item.Table.Table && item.Key && item.Key?.constructor === Object) {
// Set the table
const table = item.Table.name

Expand Down

0 comments on commit d93b8e8

Please sign in to comment.