Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/dynamo/expression/condition-expression-builder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,21 @@ describe('expressions', () => {
{},
[],
{ blub: undefined, other: undefined },
{ emptyArr: [] },
new Set(arr),
]

const filteredObj = deepFilter(obj, (item) => item !== undefined)
expect(filteredObj).toEqual([{ street: 'street', zip: 1524 }, [{ age: 25 }], new Set([arr[0], arr[1]])])
expect(filteredObj).toEqual([
{ street: 'street', zip: 1524 },
[{ age: 25 }],
[{}],
{},
[],
{},
{ emptyArr: [] },
new Set([arr[0], arr[1]]),
])
})

it('use property metadata', () => {
Expand Down
6 changes: 3 additions & 3 deletions src/dynamo/expression/condition-expression-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type BuildFilterFn = (
*/

/**
* Will walk the object tree recursively and removes all items which do not satisfy the filterFn
* Will walk the object tree recursively and removes all items that do not satisfy the filterFn
* @param obj
* @param {(value: any) => boolean} filterFn
* @returns {any}
Expand All @@ -56,7 +56,7 @@ export function deepFilter(obj: any, filterFn: (value: any) => boolean): any {
}
})

return returnArr.length ? returnArr : null
return returnArr
} else if (obj instanceof Set) {
const returnArr: any[] = []
Array.from(obj).forEach((i) => {
Expand All @@ -80,7 +80,7 @@ export function deepFilter(obj: any, filterFn: (value: any) => boolean): any {
}
}

return Object.keys(returnObj).length ? returnObj : null
return returnObj
} else {
if (filterFn(obj)) {
return obj
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function prepareAndAddUpdateExpressions(
if (updateDefFns && updateDefFns.length) {
const sortedByActionKeyWord: Map<UpdateActionKeyword, UpdateExpression[]> = updateDefFns
.map((updateDefFn) => {
// TODO v3: investigate on how to remove any
// TODO post-v3:: investigate on how to remove any
// tslint:disable-next-line:no-unnecessary-type-assertion
return updateDefFn(params.ExpressionAttributeNames as any, metadata)
})
Expand Down
14 changes: 13 additions & 1 deletion src/dynamo/expression/update-expression-builder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@ describe('buildUpdateExpression', () => {
})
})

describe('should build set expression for empty collection', () => {
it('array', () => {
const exp = buildUpdateExpression('addresses', op, [[]], [], metaDataU)
expect(exp).toEqual({
attributeNames: { '#addresses': 'addresses' },
attributeValues: { ':addresses': { L: [] } },
statement: '#addresses = :addresses',
type: 'SET',
})
})
})

it('should build set expression for number at document path', () => {
const exp = buildUpdateExpression('numberValues[0]', op, [23], [], metaDataU)
expect(exp).toEqual({
Expand Down Expand Up @@ -144,7 +156,7 @@ describe('buildUpdateExpression', () => {
const op = new UpdateActionDef('DELETE', 'removeFromSet')

it('should build the expression', () => {
const exp = buildUpdateExpression('topics', op, [['val1', 'val2']], [], metaDataU)
const exp = buildUpdateExpression('topics', op, [new Set(['val1', 'val2'])], [], metaDataU)
expect(exp).toEqual({
attributeNames: { '#topics': 'topics' },
attributeValues: { ':topics': { SS: ['val1', 'val2'] } },
Expand Down
2 changes: 1 addition & 1 deletion src/dynamo/expression/update-expression-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function buildUpdateExpression(
existingValueNames: string[] | undefined,
metadata: Metadata<any> | undefined,
): UpdateExpression {
// metadata get rid of undefined values
// get rid of undefined values
values = deepFilter(values, (value) => value !== undefined) || []

// load property metadata if model metadata was provided
Expand Down
2 changes: 1 addition & 1 deletion src/dynamo/request/get/get.request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class GetRequest<T, T2 extends Partial<T> = T> extends StandardRequest<
.getItem(this.params)
.then(promiseTap((response) => this.logger.debug('response', response)))
.then((getItemResponse) => {
// TODO v3: investigate on how to remove any
// TODO post-v3: investigate on how to remove any
// tslint:disable-next-line:no-unnecessary-type-assertion
const response: GetResponse<T2> = { ...(getItemResponse as any) }

Expand Down