Comparing version 1.0.2 to 1.0.3
@@ -12,2 +12,6 @@ "use strict"; | ||
const assertHasValidDynamoDBFieldNames_1 = require("./assertHasValidDynamoDBFieldNames"); | ||
const createFilterExpression = (fieldNames, fields) => fieldNames.reduce((obj, key) => { | ||
obj[`:${key}`] = fields[key]; | ||
return obj; | ||
}, {}); | ||
// hack to retrieve all items until 2.3 arrives with support for async iterators | ||
@@ -21,8 +25,9 @@ // https://github.com/Microsoft/TypeScript/pull/12346 | ||
const fieldNames = Object.keys(fields); | ||
const filterExpression = fieldNames.map(key => `${key} = :${key}`) | ||
.join(' and '); | ||
const expressionAtributeValues = fieldNames.reduce((obj, key) => { | ||
obj[`:${key}`] = fields[key]; | ||
return obj; | ||
}, {}); | ||
const filterExpression = fieldNames.length === 0 | ||
? null | ||
: fieldNames.map(key => `${key} = :${key}`) | ||
.join(' and '); | ||
const expressionAtributeValues = fieldNames.length === 0 | ||
? null | ||
: createFilterExpression(fieldNames, fields); | ||
let result = []; | ||
@@ -29,0 +34,0 @@ let key = null; |
{ | ||
"name": "cruft-ddb", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "A simple optimistic-locking abstraction over Dynamo DB", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
import { assertHasValidDynamoDBFieldNames } from './assertHasValidDynamoDBFieldNames'; | ||
import { IConfiguration, IHasVersion, IHasMetadata } from './index'; | ||
const createFilterExpression = (fieldNames, fields) => | ||
fieldNames.reduce( | ||
(obj, key) => { | ||
obj[`:${key}`] = fields[key]; | ||
return obj; | ||
}, | ||
{} | ||
); | ||
// hack to retrieve all items until 2.3 arrives with support for async iterators | ||
@@ -16,12 +25,10 @@ // https://github.com/Microsoft/TypeScript/pull/12346 | ||
const filterExpression = fieldNames.map(key => `${key} = :${key}`) | ||
.join(' and '); | ||
const filterExpression = fieldNames.length === 0 | ||
? null | ||
: fieldNames.map(key => `${key} = :${key}`) | ||
.join(' and '); | ||
const expressionAtributeValues = fieldNames.reduce( | ||
(obj, key) => { | ||
obj[`:${key}`] = fields[key]; | ||
return obj; | ||
}, | ||
{} | ||
); | ||
const expressionAtributeValues = fieldNames.length === 0 | ||
? null | ||
: createFilterExpression(fieldNames, fields); | ||
@@ -28,0 +35,0 @@ let result: Array<T & IHasVersion & IHasMetadata> = []; |
@@ -171,2 +171,20 @@ import { DynamoDB } from 'aws-sdk'; | ||
describe('__findAll', async () => { | ||
it('should find items without filter', async () => { | ||
await cruft.create({ id: 'foo', bar: 4 }); | ||
const items = await cruft.__findAll({}); | ||
expect(items).to.lengthOf(1, 'Incorrect item count'); | ||
}); | ||
(<any>it)('should find items over many pages', async () => { | ||
for (let i = 0; i < 1000; i++) { | ||
await cruft.create({ id: String(i), bar: 4 }); | ||
} | ||
const items = await cruft.__findAll({ bar: 4 }); | ||
expect(items).to.lengthOf(1000, 'Incorrect item count'); | ||
}, 60000); | ||
}); | ||
describe('truncate', () => { | ||
@@ -173,0 +191,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
128803
765