electrodb 1.11.0 → 1.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -3
- package/src/clauses.js +16 -2
- package/src/client.js +2 -2
- package/src/entity.js +43 -2
- package/src/util.js +8 -0
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "electrodb",
|
|
3
|
-
"version": "1.11.
|
|
3
|
+
"version": "1.11.1",
|
|
4
4
|
"description": "A library to more easily create and interact with multiple entities and heretical relationships in dynamodb",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"test": "npm run test
|
|
8
|
-
"test
|
|
7
|
+
"test": "npm run test:types && npm run test:unit",
|
|
8
|
+
"test:unit": "LOCAL_DYNAMO_ENDPOINT=http://localhost:8000 node ./test/init.js && LOCAL_DYNAMO_ENDPOINT=http://localhost:8000 mocha -r ts-node/register ./test/**.spec.*",
|
|
9
|
+
"test:types": "tsd",
|
|
9
10
|
"coverage": "nyc npm test && nyc report --reporter=text-lcov | coveralls",
|
|
10
11
|
"coverage-coveralls-local": "nyc npm test && nyc report --reporter=text-lcov | coveralls",
|
|
11
12
|
"coverage-html-local": "nyc npm test && nyc report --reporter=html",
|
package/src/clauses.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const { QueryTypes, MethodTypes, ItemOperations, ExpressionTypes, TableIndex, TerminalOperation } = require("./types");
|
|
1
|
+
const { QueryTypes, MethodTypes, ItemOperations, ExpressionTypes, TableIndex, TerminalOperation, KeyTypes } = require("./types");
|
|
2
2
|
const {AttributeOperationProxy, UpdateOperations, FilterOperationNames} = require("./operations");
|
|
3
3
|
const {UpdateExpression} = require("./update");
|
|
4
4
|
const {FilterExpression} = require("./where");
|
|
@@ -403,7 +403,7 @@ let clauses = {
|
|
|
403
403
|
.setType(QueryTypes.is)
|
|
404
404
|
.setPK(entity._expectFacets(facets, attributes.pk))
|
|
405
405
|
.ifSK(() => {
|
|
406
|
-
state.setSK(entity._buildQueryFacets(facets, attributes.sk))
|
|
406
|
+
state.setSK(entity._buildQueryFacets(facets, attributes.sk));
|
|
407
407
|
});
|
|
408
408
|
} catch(err) {
|
|
409
409
|
state.setError(err);
|
|
@@ -635,6 +635,7 @@ class ChainState {
|
|
|
635
635
|
data: {},
|
|
636
636
|
},
|
|
637
637
|
keys: {
|
|
638
|
+
provided: [],
|
|
638
639
|
pk: {},
|
|
639
640
|
sk: [],
|
|
640
641
|
},
|
|
@@ -676,8 +677,20 @@ class ChainState {
|
|
|
676
677
|
return this.query.options;
|
|
677
678
|
}
|
|
678
679
|
|
|
680
|
+
_appendProvided(type, attributes) {
|
|
681
|
+
const newAttributes = Object.keys(attributes).map(attribute => {
|
|
682
|
+
return {
|
|
683
|
+
type,
|
|
684
|
+
attribute
|
|
685
|
+
}
|
|
686
|
+
});
|
|
687
|
+
return u.getUnique(this.query.keys.provided, newAttributes);
|
|
688
|
+
}
|
|
689
|
+
|
|
679
690
|
setPK(attributes) {
|
|
680
691
|
this.query.keys.pk = attributes;
|
|
692
|
+
this.query.keys.provided = this._appendProvided(KeyTypes.pk, attributes);
|
|
693
|
+
|
|
681
694
|
return this;
|
|
682
695
|
}
|
|
683
696
|
|
|
@@ -698,6 +711,7 @@ class ChainState {
|
|
|
698
711
|
type: type,
|
|
699
712
|
facets: attributes
|
|
700
713
|
});
|
|
714
|
+
this.query.keys.provided = this._appendProvided(KeyTypes.sk, attributes);
|
|
701
715
|
}
|
|
702
716
|
return this;
|
|
703
717
|
}
|
package/src/client.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const {isFunction} = require('./validations');
|
|
2
|
-
const {ElectroError, ErrorCodes} = require('./errors');
|
|
1
|
+
const { isFunction } = require('./validations');
|
|
2
|
+
const { ElectroError, ErrorCodes } = require('./errors');
|
|
3
3
|
const lib = require('@aws-sdk/lib-dynamodb');
|
|
4
4
|
|
|
5
5
|
const DocumentClientVersions = {
|
package/src/entity.js
CHANGED
|
@@ -1478,6 +1478,14 @@ class Entity {
|
|
|
1478
1478
|
let parameters = {};
|
|
1479
1479
|
switch (state.query.type) {
|
|
1480
1480
|
case QueryTypes.is:
|
|
1481
|
+
parameters = this._makeIsQueryParams(
|
|
1482
|
+
state.query,
|
|
1483
|
+
state.query.index,
|
|
1484
|
+
state.query.filter[ExpressionTypes.FilterExpression],
|
|
1485
|
+
indexKeys.pk,
|
|
1486
|
+
...indexKeys.sk,
|
|
1487
|
+
);
|
|
1488
|
+
break;
|
|
1481
1489
|
case QueryTypes.begins:
|
|
1482
1490
|
parameters = this._makeBeginsWithQueryParams(
|
|
1483
1491
|
state.query.options,
|
|
@@ -1551,12 +1559,16 @@ class Entity {
|
|
|
1551
1559
|
return params;
|
|
1552
1560
|
}
|
|
1553
1561
|
|
|
1554
|
-
|
|
1562
|
+
_makeInclusiveQueryParams(options, index, filter, pk, sk, type) {
|
|
1555
1563
|
let keyExpressions = this._queryKeyExpressionAttributeBuilder(index, pk, sk);
|
|
1556
1564
|
let KeyConditionExpression = "#pk = :pk";
|
|
1557
1565
|
|
|
1558
1566
|
if (this.model.lookup.indexHasSortKeys[index] && typeof keyExpressions.ExpressionAttributeValues[":sk1"] === "string" && keyExpressions.ExpressionAttributeValues[":sk1"].length > 0) {
|
|
1559
|
-
|
|
1567
|
+
if (type === QueryTypes.is) {
|
|
1568
|
+
KeyConditionExpression = `${KeyConditionExpression} and #sk1 = :sk1`;
|
|
1569
|
+
} else {
|
|
1570
|
+
KeyConditionExpression = `${KeyConditionExpression} and begins_with(#sk1, :sk1)`;
|
|
1571
|
+
}
|
|
1560
1572
|
} else {
|
|
1561
1573
|
delete keyExpressions.ExpressionAttributeNames["#sk1"];
|
|
1562
1574
|
delete keyExpressions.ExpressionAttributeValues[":sk1"];
|
|
@@ -1588,6 +1600,35 @@ class Entity {
|
|
|
1588
1600
|
return params;
|
|
1589
1601
|
}
|
|
1590
1602
|
|
|
1603
|
+
_makeIsQueryParams(query, index, filter, pk, sk) {
|
|
1604
|
+
const { options, keys } = query;
|
|
1605
|
+
|
|
1606
|
+
const providedSks = keys.provided
|
|
1607
|
+
.filter(item => item.type === KeyTypes.sk)
|
|
1608
|
+
.map(item => item.attribute);
|
|
1609
|
+
|
|
1610
|
+
const skDefinition = (this.model.facets.byIndex[index] &&
|
|
1611
|
+
this.model.facets.byIndex[index].sk &&
|
|
1612
|
+
Array.isArray(this.model.facets.byIndex[index].sk) &&
|
|
1613
|
+
this.model.facets.byIndex[index].sk
|
|
1614
|
+
) || [];
|
|
1615
|
+
|
|
1616
|
+
const skCompositeAttributes = new Set(skDefinition);
|
|
1617
|
+
const skIsCompletelyFulfilled = skCompositeAttributes.size === providedSks.length &&
|
|
1618
|
+
skDefinition.every(attr => providedSks.includes(attr));
|
|
1619
|
+
|
|
1620
|
+
if (skIsCompletelyFulfilled) {
|
|
1621
|
+
return this._makeInclusiveQueryParams(options, index, filter, pk, sk, QueryTypes.is);
|
|
1622
|
+
} else {
|
|
1623
|
+
return this._makeBeginsWithQueryParams(options, index, filter, pk, sk);
|
|
1624
|
+
}
|
|
1625
|
+
|
|
1626
|
+
}
|
|
1627
|
+
|
|
1628
|
+
_makeBeginsWithQueryParams(options, index, filter, pk, sk) {
|
|
1629
|
+
return this._makeInclusiveQueryParams(options, index, filter, pk, sk, QueryTypes.begins);
|
|
1630
|
+
}
|
|
1631
|
+
|
|
1591
1632
|
_mergeExpressionsAttributes(...expressionAttributes) {
|
|
1592
1633
|
let merged = {};
|
|
1593
1634
|
for (let obj of expressionAttributes) {
|
package/src/util.js
CHANGED
|
@@ -154,7 +154,15 @@ class BatchGetOrderMaintainer {
|
|
|
154
154
|
}
|
|
155
155
|
}
|
|
156
156
|
|
|
157
|
+
function getUnique(arr1, arr2) {
|
|
158
|
+
return Array.from(new Set([
|
|
159
|
+
...arr1,
|
|
160
|
+
...arr2
|
|
161
|
+
]));
|
|
162
|
+
}
|
|
163
|
+
|
|
157
164
|
module.exports = {
|
|
165
|
+
getUnique,
|
|
158
166
|
batchItems,
|
|
159
167
|
parseJSONPath,
|
|
160
168
|
getInstanceType,
|