@ginger.io/beyonce
Advanced tools
Comparing version 0.0.64 to 0.0.65
@@ -18,3 +18,3 @@ "use strict"; | ||
const { table, client, consistentRead } = params; | ||
const { tableName, partitionKeyName, sortKeyName } = table; | ||
const { tableName } = table; | ||
const results = yield client | ||
@@ -25,6 +25,3 @@ .batchGet({ | ||
ConsistentRead: consistentRead, | ||
Keys: params.keys.map(({ partitionKey, sortKey }) => ({ | ||
[partitionKeyName]: partitionKey, | ||
[sortKeyName]: sortKey | ||
})) | ||
Keys: screenKeysForDuplicates(params.keys, table) | ||
} | ||
@@ -47,2 +44,17 @@ } | ||
exports.batchGetItems = batchGetItems; | ||
function screenKeysForDuplicates(keys, table) { | ||
const dynamoKeyMap = {}; | ||
const uniqueKeys = []; | ||
const { partitionKeyName, sortKeyName } = table; | ||
keys.forEach(({ partitionKey, sortKey }) => { | ||
if (!dynamoKeyMap[`${partitionKey}-${sortKey}`]) { | ||
dynamoKeyMap[`${partitionKey}-${sortKey}`] = true; | ||
uniqueKeys.push({ | ||
[partitionKeyName]: partitionKey, | ||
[sortKeyName]: sortKey | ||
}); | ||
} | ||
}); | ||
return uniqueKeys; | ||
} | ||
//# sourceMappingURL=batchGetItems.js.map |
@@ -25,3 +25,3 @@ "use strict"; | ||
else { | ||
throw new Error(`UnprocessedKeysCollector: you tried to add an unprocesssed key: ${unprocessedKey} that was not inlcuded in the input key set`); | ||
throw new Error(`UnprocessedKeysCollector: you tried to add an unprocessed key: ${unprocessedKey} that was not included in the input key set`); | ||
} | ||
@@ -28,0 +28,0 @@ } |
{ | ||
"name": "@ginger.io/beyonce", | ||
"version": "0.0.64", | ||
"version": "0.0.65", | ||
"description": "Type-safe DynamoDB query builder for TypeScript. Designed with single-table architecture in mind.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -25,3 +25,3 @@ import { DynamoDB } from "aws-sdk" | ||
const { table, client, consistentRead } = params | ||
const { tableName, partitionKeyName, sortKeyName } = table | ||
const { tableName } = table | ||
const results = await client | ||
@@ -32,6 +32,3 @@ .batchGet({ | ||
ConsistentRead: consistentRead, | ||
Keys: params.keys.map(({ partitionKey, sortKey }) => ({ | ||
[partitionKeyName]: partitionKey, | ||
[sortKeyName]: sortKey | ||
})) | ||
Keys: screenKeysForDuplicates(params.keys, table) | ||
} | ||
@@ -53,1 +50,17 @@ } | ||
} | ||
function screenKeysForDuplicates<T extends PartitionAndSortKey<TaggedModel>>(keys: T[], table: Table<string, string>) { | ||
const dynamoKeyMap: Record<string, boolean> = {} | ||
const uniqueKeys: Array<Record<string, string>> = [] | ||
const { partitionKeyName, sortKeyName } = table | ||
keys.forEach(({ partitionKey, sortKey }) => { | ||
if (!dynamoKeyMap[`${partitionKey}-${sortKey}`]) { | ||
dynamoKeyMap[`${partitionKey}-${sortKey}`] = true | ||
uniqueKeys.push({ | ||
[partitionKeyName]: partitionKey, | ||
[sortKeyName]: sortKey | ||
}) | ||
} | ||
}) | ||
return uniqueKeys | ||
} |
@@ -28,3 +28,3 @@ import { DynamoDB } from "aws-sdk" | ||
throw new Error( | ||
`UnprocessedKeysCollector: you tried to add an unprocesssed key: ${unprocessedKey} that was not inlcuded in the input key set` | ||
`UnprocessedKeysCollector: you tried to add an unprocessed key: ${unprocessedKey} that was not included in the input key set` | ||
) | ||
@@ -31,0 +31,0 @@ } |
@@ -134,2 +134,6 @@ import { JayZ } from "@ginger.io/jay-z" | ||
it("should batchGet items with duplicate keys", async () => { | ||
await testBatchGetWithDuplicateKeys() | ||
}) | ||
it("should batchGet more than 100 items by chunking requests", async () => { | ||
@@ -238,2 +242,7 @@ await testChunkedBatchGet() | ||
it("should batchGet items with jayZ: with duplicate keys", async () => { | ||
const jayZ = await createJayZ() | ||
await testBatchGetWithDuplicateKeys(jayZ) | ||
}) | ||
it("should batchGet more than 100 items by chunking requests with jayZ", async () => { | ||
@@ -410,2 +419,26 @@ const jayZ = await createJayZ() | ||
async function testBatchGetWithDuplicateKeys(jayZ?: JayZ) { | ||
const db = await setup(jayZ) | ||
const [musician, song1, song2] = aMusicianWithTwoSongs() | ||
await Promise.all([db.put(musician), db.put(song1), db.put(song2)]) | ||
const results = await db.batchGet({ | ||
keys: [ | ||
MusicianModel.key({ id: musician.id }), | ||
SongModel.key({ musicianId: musician.id, id: song1.id }), | ||
SongModel.key({ musicianId: musician.id, id: song2.id }), | ||
SongModel.key({ musicianId: musician.id, id: song2.id }) | ||
] | ||
}) | ||
sortById(results.items.song) | ||
expect(results.items).toEqual({ | ||
musician: [musician], | ||
song: [song1, song2] | ||
}) | ||
expect(results.unprocessedKeys).toEqual([]) | ||
} | ||
async function testChunkedBatchGet(jayZ?: JayZ) { | ||
@@ -412,0 +445,0 @@ const db = await setup(jayZ) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
2
336472
227
5736
1