electrodb
Advanced tools
Comparing version 0.9.42 to 0.9.43
{ | ||
"name": "electrodb", | ||
"version": "0.9.42", | ||
"version": "0.9.43", | ||
"description": "A library to more easily create and interact with multiple entities and heretical relationships in dynamodb", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -23,3 +23,3 @@ const { QueryTypes, MethodTypes } = require("./types"); | ||
// }, | ||
children: ["get", "delete", "update", "query", "put", "scan", "collection", "create", "patch", "batchPut", "batchDelete"], | ||
children: ["get", "delete", "update", "query", "put", "scan", "collection", "create", "patch", "batchPut", "batchDelete", "batchGet"], | ||
}, | ||
@@ -68,2 +68,7 @@ collection: { | ||
}, | ||
batchGet: { | ||
name: "batchGet", | ||
action: (entity, state, payload) => batchAction(clauses.get.action, MethodTypes.batchGet, entity, state, payload), | ||
children: ["params", "go"], | ||
}, | ||
batchDelete: { | ||
@@ -361,2 +366,4 @@ name: "batchDelete", | ||
return entity._batchWriteParams(state, options); | ||
} else if (state.query.method === MethodTypes.batchGet) { | ||
return entity._batchGetParams(state, options); | ||
} else { | ||
@@ -363,0 +370,0 @@ return entity._params(state, options); |
@@ -102,3 +102,7 @@ "use strict"; | ||
let index = ""; | ||
return this._makeChain(index, clauses, clauses.index).get(facets); | ||
if (Array.isArray(facets)) { | ||
return this._makeChain(index, this._clausesWithFilters, clauses.index).batchGet(facets); | ||
} else { | ||
return this._makeChain(index, clauses, clauses.index).get(facets); | ||
} | ||
} | ||
@@ -172,3 +176,5 @@ | ||
case MethodTypes.batchWrite: | ||
return this.formatBulkResponse(parameters.IndexName, response, config); | ||
return this.formatBulkWriteResponse(parameters.IndexName, response, config); | ||
case MethodTypes.batchGet: | ||
return this.formatBulkGetResponse(parameters.IndexName, response, config); | ||
default: | ||
@@ -209,10 +215,10 @@ return this.formatResponse(parameters.IndexName, response, config); | ||
formatBulkResponse(index, response = {}, config = {}) { | ||
formatBulkWriteResponse(index, response = {}, config = {}) { | ||
if (!response || !response.UnprocessedItems) { | ||
return response; | ||
} | ||
let table = this._getTableName(); | ||
let unProcessed = response.UnprocessedItems[table]; | ||
if (Array.isArray(unProcessed) && unProcessed.length) { | ||
return unProcessed.map(request => { | ||
let table = config.table || this._getTableName(); | ||
let unprocessed = response.UnprocessedItems[table]; | ||
if (Array.isArray(unprocessed) && unprocessed.length) { | ||
return unprocessed.map(request => { | ||
if (request.PutRequest) { | ||
@@ -229,5 +235,37 @@ return this.formatResponse(index, request.PutRequest, config); | ||
} | ||
} | ||
formatBulkGetResponse(index, response = {}, config = {}) { | ||
let unprocessed = []; | ||
let results = []; | ||
let table = config.table || this._getTableName(); | ||
if (!response.UnprocessedKeys || !response.Responses) { | ||
throw new Error("Unknown response format"); | ||
} | ||
if (response.UnprocessedKeys[table] && response.UnprocessedKeys[table].Keys && Array.isArray(response.UnprocessedKeys[table].Keys)) { | ||
for (let value of response.UnprocessedKeys[table].Keys) { | ||
if (config && config.lastEvaluatedKeyRaw) { | ||
unprocessed.push(value); | ||
} else { | ||
unprocessed.push( | ||
this._formatReturnPager(index, value) | ||
); | ||
} | ||
} | ||
} | ||
if (response.Responses[table] && Array.isArray(response.Responses[table])) { | ||
for (let value of response.Responses[table]) { | ||
results.push( | ||
// Value is added as Item here because formatResponse expects a regular Item/Items response | ||
// typically returned by Gets or Queries. | ||
this.formatResponse(index, {Item: value}, config) | ||
); | ||
} | ||
} | ||
return [results, unprocessed]; | ||
} | ||
formatResponse(index, response, config = {}) { | ||
@@ -538,4 +576,26 @@ let stackTrace = new Error(); | ||
_batchGetParams(state, config = {}) { | ||
let table = config.table || this._getTableName(); | ||
let userDefinedParams = config.params || {}; | ||
let keys = []; | ||
for (let itemState of state.batch.items) { | ||
let method = itemState.query.method; | ||
let params = this._params(itemState, config); | ||
if (method === MethodTypes.get) { | ||
let {Key} = params; | ||
keys.push(Key); | ||
} | ||
} | ||
return { | ||
RequestItems: { | ||
[table]: { | ||
...userDefinedParams, | ||
Keys: keys | ||
} | ||
} | ||
} | ||
} | ||
_batchWriteParams(state, config = {}) { | ||
let table = this._getTableName(); | ||
let table = config.table || this._getTableName(); | ||
let batch = []; | ||
@@ -542,0 +602,0 @@ for (let itemState of state.batch.items) { |
@@ -34,2 +34,3 @@ const KeyTypes = { | ||
create: "create", | ||
batchGet: "batchGet", | ||
batchWrite: "batchWrite" | ||
@@ -36,0 +37,0 @@ }; |
Sorry, the diff of this file is too big to display
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
221393
3638
2986