dyno-table 1.0.0-alpha.1 → 1.1.0
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/README.md +752 -172
- package/dist/builder-types-C_PDZhnP.d.ts +118 -0
- package/dist/builder-types-DtwbqMeF.d.cts +118 -0
- package/dist/builders/condition-check-builder.cjs +394 -0
- package/dist/builders/condition-check-builder.cjs.map +1 -0
- package/dist/builders/condition-check-builder.d.cts +157 -0
- package/dist/builders/condition-check-builder.d.ts +157 -0
- package/dist/builders/condition-check-builder.js +392 -0
- package/dist/builders/condition-check-builder.js.map +1 -0
- package/dist/builders/delete-builder.cjs +405 -0
- package/dist/builders/delete-builder.cjs.map +1 -0
- package/dist/builders/delete-builder.d.cts +166 -0
- package/dist/builders/delete-builder.d.ts +166 -0
- package/dist/builders/delete-builder.js +403 -0
- package/dist/builders/delete-builder.js.map +1 -0
- package/dist/builders/paginator.cjs +199 -0
- package/dist/builders/paginator.cjs.map +1 -0
- package/dist/builders/paginator.d.cts +179 -0
- package/dist/builders/paginator.d.ts +179 -0
- package/dist/builders/paginator.js +197 -0
- package/dist/builders/paginator.js.map +1 -0
- package/dist/builders/put-builder.cjs +476 -0
- package/dist/builders/put-builder.cjs.map +1 -0
- package/dist/builders/put-builder.d.cts +274 -0
- package/dist/builders/put-builder.d.ts +274 -0
- package/dist/builders/put-builder.js +474 -0
- package/dist/builders/put-builder.js.map +1 -0
- package/dist/builders/query-builder.cjs +674 -0
- package/dist/builders/query-builder.cjs.map +1 -0
- package/dist/builders/query-builder.d.cts +6 -0
- package/dist/builders/query-builder.d.ts +6 -0
- package/dist/builders/query-builder.js +672 -0
- package/dist/builders/query-builder.js.map +1 -0
- package/dist/builders/transaction-builder.cjs +918 -0
- package/dist/builders/transaction-builder.cjs.map +1 -0
- package/dist/builders/transaction-builder.d.cts +511 -0
- package/dist/builders/transaction-builder.d.ts +511 -0
- package/dist/builders/transaction-builder.js +916 -0
- package/dist/builders/transaction-builder.js.map +1 -0
- package/dist/builders/update-builder.cjs +627 -0
- package/dist/builders/update-builder.cjs.map +1 -0
- package/dist/builders/update-builder.d.cts +365 -0
- package/dist/builders/update-builder.d.ts +365 -0
- package/dist/builders/update-builder.js +625 -0
- package/dist/builders/update-builder.js.map +1 -0
- package/dist/conditions--ld9a78i.d.ts +331 -0
- package/dist/conditions-ChhQWd6z.d.cts +331 -0
- package/dist/conditions.cjs +59 -0
- package/dist/conditions.cjs.map +1 -0
- package/dist/conditions.d.cts +3 -0
- package/dist/conditions.d.ts +3 -0
- package/dist/conditions.js +43 -0
- package/dist/conditions.js.map +1 -0
- package/dist/entity.cjs +211 -0
- package/dist/entity.cjs.map +1 -0
- package/dist/entity.d.cts +149 -0
- package/dist/entity.d.ts +149 -0
- package/dist/entity.js +207 -0
- package/dist/entity.js.map +1 -0
- package/dist/query-builder-Csror9Iu.d.ts +507 -0
- package/dist/query-builder-D2FM9rsu.d.cts +507 -0
- package/dist/standard-schema.cjs +4 -0
- package/dist/standard-schema.cjs.map +1 -0
- package/dist/standard-schema.d.cts +57 -0
- package/dist/standard-schema.d.ts +57 -0
- package/dist/standard-schema.js +3 -0
- package/dist/standard-schema.js.map +1 -0
- package/dist/table-BEhBPy2G.d.cts +364 -0
- package/dist/table-BW3cmUqr.d.ts +364 -0
- package/dist/{index.cjs → table.cjs} +108 -175
- package/dist/table.cjs.map +1 -0
- package/dist/table.d.cts +12 -0
- package/dist/table.d.ts +12 -0
- package/dist/{index.js → table.js} +107 -127
- package/dist/table.js.map +1 -0
- package/dist/types.cjs +4 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.cts +22 -0
- package/dist/types.d.ts +22 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/partition-key-template.cjs +19 -0
- package/dist/utils/partition-key-template.cjs.map +1 -0
- package/dist/utils/partition-key-template.d.cts +32 -0
- package/dist/utils/partition-key-template.d.ts +32 -0
- package/dist/utils/partition-key-template.js +17 -0
- package/dist/utils/partition-key-template.js.map +1 -0
- package/dist/utils/sort-key-template.cjs +19 -0
- package/dist/utils/sort-key-template.cjs.map +1 -0
- package/dist/utils/sort-key-template.d.cts +35 -0
- package/dist/utils/sort-key-template.d.ts +35 -0
- package/dist/utils/sort-key-template.js +17 -0
- package/dist/utils/sort-key-template.js.map +1 -0
- package/package.json +77 -7
- package/dist/index.d.cts +0 -2971
- package/dist/index.d.ts +0 -2971
|
@@ -1,50 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
ConditionCheckBuilder: () => ConditionCheckBuilder,
|
|
24
|
-
DeleteBuilder: () => DeleteBuilder,
|
|
25
|
-
Paginator: () => Paginator,
|
|
26
|
-
PutBuilder: () => PutBuilder,
|
|
27
|
-
QueryBuilder: () => QueryBuilder,
|
|
28
|
-
Table: () => Table,
|
|
29
|
-
TransactionBuilder: () => TransactionBuilder,
|
|
30
|
-
UpdateBuilder: () => UpdateBuilder,
|
|
31
|
-
and: () => and,
|
|
32
|
-
attributeExists: () => attributeExists,
|
|
33
|
-
attributeNotExists: () => attributeNotExists,
|
|
34
|
-
beginsWith: () => beginsWith,
|
|
35
|
-
between: () => between,
|
|
36
|
-
contains: () => contains,
|
|
37
|
-
createComparisonCondition: () => createComparisonCondition,
|
|
38
|
-
eq: () => eq,
|
|
39
|
-
gt: () => gt,
|
|
40
|
-
gte: () => gte,
|
|
41
|
-
lt: () => lt,
|
|
42
|
-
lte: () => lte,
|
|
43
|
-
ne: () => ne,
|
|
44
|
-
not: () => not,
|
|
45
|
-
or: () => or
|
|
46
|
-
});
|
|
47
|
-
module.exports = __toCommonJS(index_exports);
|
|
1
|
+
'use strict';
|
|
48
2
|
|
|
49
3
|
// src/conditions.ts
|
|
50
4
|
var createComparisonCondition = (type) => (attr, value) => ({
|
|
@@ -909,6 +863,14 @@ var PutBuilder = class {
|
|
|
909
863
|
returnValues: "NONE"
|
|
910
864
|
};
|
|
911
865
|
}
|
|
866
|
+
set(valuesOrPath, value) {
|
|
867
|
+
if (typeof valuesOrPath === "object") {
|
|
868
|
+
Object.assign(this.item, valuesOrPath);
|
|
869
|
+
} else {
|
|
870
|
+
this.item[valuesOrPath] = value;
|
|
871
|
+
}
|
|
872
|
+
return this;
|
|
873
|
+
}
|
|
912
874
|
/**
|
|
913
875
|
* Adds a condition that must be satisfied for the put operation to succeed.
|
|
914
876
|
* Use this method when you need to:
|
|
@@ -1153,10 +1115,6 @@ var DeleteBuilder = class {
|
|
|
1153
1115
|
}
|
|
1154
1116
|
/**
|
|
1155
1117
|
* Adds a condition that must be satisfied for the delete operation to succeed.
|
|
1156
|
-
* Use this method when you need to:
|
|
1157
|
-
* - Ensure safe removal conditions
|
|
1158
|
-
* - Verify habitat status before deletion
|
|
1159
|
-
* - Implement safety protocols
|
|
1160
1118
|
*
|
|
1161
1119
|
* @example
|
|
1162
1120
|
* ```typescript
|
|
@@ -1208,10 +1166,6 @@ var DeleteBuilder = class {
|
|
|
1208
1166
|
}
|
|
1209
1167
|
/**
|
|
1210
1168
|
* Sets whether to return the item's attribute values before deletion.
|
|
1211
|
-
* Use this method when you need to:
|
|
1212
|
-
* - Archive removed dinosaur data
|
|
1213
|
-
* - Track habitat decommissioning history
|
|
1214
|
-
* - Maintain removal audit logs
|
|
1215
1169
|
*
|
|
1216
1170
|
* @example
|
|
1217
1171
|
* ```ts
|
|
@@ -1252,10 +1206,6 @@ var DeleteBuilder = class {
|
|
|
1252
1206
|
}
|
|
1253
1207
|
/**
|
|
1254
1208
|
* Adds this delete operation to a transaction.
|
|
1255
|
-
* Use this method when you need to:
|
|
1256
|
-
* - Coordinate dinosaur transfers
|
|
1257
|
-
* - Manage habitat decommissioning
|
|
1258
|
-
* - Handle species relocations
|
|
1259
1209
|
*
|
|
1260
1210
|
* @example
|
|
1261
1211
|
* ```ts
|
|
@@ -1306,11 +1256,6 @@ var DeleteBuilder = class {
|
|
|
1306
1256
|
/**
|
|
1307
1257
|
* Gets a human-readable representation of the delete command
|
|
1308
1258
|
* with all expression placeholders replaced by their actual values.
|
|
1309
|
-
* Use this method when you need to:
|
|
1310
|
-
* - Debug complex deletion conditions
|
|
1311
|
-
* - Verify safety checks
|
|
1312
|
-
* - Log removal operations
|
|
1313
|
-
* - Troubleshoot failed deletions
|
|
1314
1259
|
*
|
|
1315
1260
|
* @example
|
|
1316
1261
|
* ```ts
|
|
@@ -1369,10 +1314,6 @@ var UpdateBuilder = class {
|
|
|
1369
1314
|
}
|
|
1370
1315
|
/**
|
|
1371
1316
|
* Removes an attribute from the item.
|
|
1372
|
-
* Use this method when you need to:
|
|
1373
|
-
* - Delete attributes completely
|
|
1374
|
-
* - Remove nested attributes
|
|
1375
|
-
* - Clean up deprecated fields
|
|
1376
1317
|
*
|
|
1377
1318
|
* @example
|
|
1378
1319
|
* ```typescript
|
|
@@ -1399,10 +1340,6 @@ var UpdateBuilder = class {
|
|
|
1399
1340
|
}
|
|
1400
1341
|
/**
|
|
1401
1342
|
* Adds a value to a number attribute or adds elements to a set.
|
|
1402
|
-
* Use this method when you need to:
|
|
1403
|
-
* - Increment counters
|
|
1404
|
-
* - Add elements to a set atomically
|
|
1405
|
-
* - Update numerical statistics
|
|
1406
1343
|
*
|
|
1407
1344
|
* @example
|
|
1408
1345
|
* ```typescript
|
|
@@ -1431,10 +1368,6 @@ var UpdateBuilder = class {
|
|
|
1431
1368
|
}
|
|
1432
1369
|
/**
|
|
1433
1370
|
* Removes elements from a set attribute.
|
|
1434
|
-
* Use this method when you need to:
|
|
1435
|
-
* - Remove specific elements from a set
|
|
1436
|
-
* - Update set-based attributes atomically
|
|
1437
|
-
* - Maintain set membership
|
|
1438
1371
|
*
|
|
1439
1372
|
* @example
|
|
1440
1373
|
* ```typescript
|
|
@@ -1444,7 +1377,7 @@ var UpdateBuilder = class {
|
|
|
1444
1377
|
* ['JUNGLE', 'COASTAL']
|
|
1445
1378
|
* );
|
|
1446
1379
|
*
|
|
1447
|
-
* // Remove from sets using Set
|
|
1380
|
+
* // Remove from sets using Set DynamoItems
|
|
1448
1381
|
* builder.deleteElementsFromSet(
|
|
1449
1382
|
* 'knownBehaviors',
|
|
1450
1383
|
* new Set(['NOCTURNAL', 'TERRITORIAL'])
|
|
@@ -1477,11 +1410,6 @@ var UpdateBuilder = class {
|
|
|
1477
1410
|
}
|
|
1478
1411
|
/**
|
|
1479
1412
|
* Adds a condition that must be satisfied for the update to succeed.
|
|
1480
|
-
* Use this method when you need to:
|
|
1481
|
-
* - Implement optimistic locking
|
|
1482
|
-
* - Ensure item state before update
|
|
1483
|
-
* - Validate business rules
|
|
1484
|
-
* - Prevent concurrent modifications
|
|
1485
1413
|
*
|
|
1486
1414
|
* @example
|
|
1487
1415
|
* ```typescript
|
|
@@ -1513,7 +1441,7 @@ var UpdateBuilder = class {
|
|
|
1513
1441
|
* );
|
|
1514
1442
|
* ```
|
|
1515
1443
|
*
|
|
1516
|
-
* @param condition - Either a Condition
|
|
1444
|
+
* @param condition - Either a Condition DynamoItem or a callback function that builds the condition
|
|
1517
1445
|
* @returns The builder instance for method chaining
|
|
1518
1446
|
*/
|
|
1519
1447
|
condition(condition) {
|
|
@@ -1542,11 +1470,6 @@ var UpdateBuilder = class {
|
|
|
1542
1470
|
}
|
|
1543
1471
|
/**
|
|
1544
1472
|
* Sets which item attributes to include in the response.
|
|
1545
|
-
* Use this method when you need to:
|
|
1546
|
-
* - Get the complete updated item
|
|
1547
|
-
* - Track changes to specific attributes
|
|
1548
|
-
* - Compare old and new values
|
|
1549
|
-
* - Monitor attribute modifications
|
|
1550
1473
|
*
|
|
1551
1474
|
* Available options:
|
|
1552
1475
|
* - ALL_NEW: All attributes after the update
|
|
@@ -1674,10 +1597,6 @@ var UpdateBuilder = class {
|
|
|
1674
1597
|
}
|
|
1675
1598
|
/**
|
|
1676
1599
|
* Adds this update operation to a transaction.
|
|
1677
|
-
* Use this method when you need to:
|
|
1678
|
-
* - Update items as part of a larger transaction
|
|
1679
|
-
* - Ensure multiple updates are atomic
|
|
1680
|
-
* - Coordinate updates across multiple items
|
|
1681
1600
|
*
|
|
1682
1601
|
* @example
|
|
1683
1602
|
* ```typescript
|
|
@@ -1707,11 +1626,6 @@ var UpdateBuilder = class {
|
|
|
1707
1626
|
}
|
|
1708
1627
|
/**
|
|
1709
1628
|
* Gets a human-readable representation of the update command.
|
|
1710
|
-
* Use this method when you need to:
|
|
1711
|
-
* - Debug complex update expressions
|
|
1712
|
-
* - Verify attribute names and values
|
|
1713
|
-
* - Log update operations
|
|
1714
|
-
* - Troubleshoot condition expressions
|
|
1715
1629
|
*
|
|
1716
1630
|
* @example
|
|
1717
1631
|
* ```typescript
|
|
@@ -1738,10 +1652,6 @@ var UpdateBuilder = class {
|
|
|
1738
1652
|
}
|
|
1739
1653
|
/**
|
|
1740
1654
|
* Executes the update operation against DynamoDB.
|
|
1741
|
-
* Use this method when you need to:
|
|
1742
|
-
* - Apply updates immediately
|
|
1743
|
-
* - Get the updated item values
|
|
1744
|
-
* - Handle conditional update failures
|
|
1745
1655
|
*
|
|
1746
1656
|
* @example
|
|
1747
1657
|
* ```typescript
|
|
@@ -1776,7 +1686,7 @@ var UpdateBuilder = class {
|
|
|
1776
1686
|
* }
|
|
1777
1687
|
* ```
|
|
1778
1688
|
*
|
|
1779
|
-
* @returns A promise that resolves to an
|
|
1689
|
+
* @returns A promise that resolves to an DynamoItem containing the updated item (if returnValues is set)
|
|
1780
1690
|
* @throws {ConditionalCheckFailedException} If the condition check fails
|
|
1781
1691
|
* @throws {Error} If the update operation fails for other reasons
|
|
1782
1692
|
*/
|
|
@@ -1830,7 +1740,7 @@ var TransactionBuilder = class {
|
|
|
1830
1740
|
*/
|
|
1831
1741
|
checkForDuplicateItem(tableName, newItem) {
|
|
1832
1742
|
const pkName = this.indexConfig.partitionKey;
|
|
1833
|
-
const skName = this.indexConfig.sortKey
|
|
1743
|
+
const skName = this.indexConfig.sortKey ?? "";
|
|
1834
1744
|
const pkValue = newItem[pkName];
|
|
1835
1745
|
const skValue = skName ? newItem[skName] : void 0;
|
|
1836
1746
|
if (!pkValue) {
|
|
@@ -1871,6 +1781,18 @@ var TransactionBuilder = class {
|
|
|
1871
1781
|
);
|
|
1872
1782
|
}
|
|
1873
1783
|
}
|
|
1784
|
+
createKeyForPrimaryIndex(key) {
|
|
1785
|
+
const keyCondition = {
|
|
1786
|
+
[this.indexConfig.partitionKey]: key.pk
|
|
1787
|
+
};
|
|
1788
|
+
if (this.indexConfig.sortKey) {
|
|
1789
|
+
if (key.sk === void 0) {
|
|
1790
|
+
throw new Error("Sort key is required for delete operation");
|
|
1791
|
+
}
|
|
1792
|
+
keyCondition[this.indexConfig.sortKey] = key.sk;
|
|
1793
|
+
}
|
|
1794
|
+
return keyCondition;
|
|
1795
|
+
}
|
|
1874
1796
|
/**
|
|
1875
1797
|
* Adds a put operation to the transaction.
|
|
1876
1798
|
* Use this method when you need to:
|
|
@@ -2010,15 +1932,13 @@ var TransactionBuilder = class {
|
|
|
2010
1932
|
* @throws {Error} If a duplicate item is detected in the transaction
|
|
2011
1933
|
*/
|
|
2012
1934
|
delete(tableName, key, condition) {
|
|
2013
|
-
this.
|
|
1935
|
+
const keyCondition = this.createKeyForPrimaryIndex(key);
|
|
1936
|
+
this.checkForDuplicateItem(tableName, keyCondition);
|
|
2014
1937
|
const transactionItem = {
|
|
2015
1938
|
type: "Delete",
|
|
2016
1939
|
params: {
|
|
2017
1940
|
tableName,
|
|
2018
|
-
key:
|
|
2019
|
-
pk: key.pk,
|
|
2020
|
-
sk: key.sk
|
|
2021
|
-
}
|
|
1941
|
+
key: keyCondition
|
|
2022
1942
|
}
|
|
2023
1943
|
};
|
|
2024
1944
|
if (condition) {
|
|
@@ -2060,10 +1980,22 @@ var TransactionBuilder = class {
|
|
|
2060
1980
|
* @see DeleteBuilder for creating delete commands
|
|
2061
1981
|
*/
|
|
2062
1982
|
deleteWithCommand(command) {
|
|
2063
|
-
|
|
1983
|
+
let keyForDuplicateCheck;
|
|
1984
|
+
let keyForTransaction;
|
|
1985
|
+
if (typeof command.key === "object" && command.key !== null && "pk" in command.key) {
|
|
1986
|
+
keyForTransaction = this.createKeyForPrimaryIndex(command.key);
|
|
1987
|
+
keyForDuplicateCheck = keyForTransaction;
|
|
1988
|
+
} else {
|
|
1989
|
+
keyForTransaction = command.key;
|
|
1990
|
+
keyForDuplicateCheck = command.key;
|
|
1991
|
+
}
|
|
1992
|
+
this.checkForDuplicateItem(command.tableName, keyForDuplicateCheck);
|
|
2064
1993
|
const transactionItem = {
|
|
2065
1994
|
type: "Delete",
|
|
2066
|
-
params:
|
|
1995
|
+
params: {
|
|
1996
|
+
...command,
|
|
1997
|
+
key: keyForTransaction
|
|
1998
|
+
}
|
|
2067
1999
|
};
|
|
2068
2000
|
this.items.push(transactionItem);
|
|
2069
2001
|
return this;
|
|
@@ -2123,15 +2055,13 @@ var TransactionBuilder = class {
|
|
|
2123
2055
|
* @throws {Error} If a duplicate item is detected in the transaction
|
|
2124
2056
|
*/
|
|
2125
2057
|
update(tableName, key, updateExpression, expressionAttributeNames, expressionAttributeValues, condition) {
|
|
2126
|
-
this.
|
|
2058
|
+
const keyCondition = this.createKeyForPrimaryIndex(key);
|
|
2059
|
+
this.checkForDuplicateItem(tableName, keyCondition);
|
|
2127
2060
|
const transactionItem = {
|
|
2128
2061
|
type: "Update",
|
|
2129
2062
|
params: {
|
|
2130
2063
|
tableName,
|
|
2131
|
-
key:
|
|
2132
|
-
pk: key.pk,
|
|
2133
|
-
sk: key.sk
|
|
2134
|
-
},
|
|
2064
|
+
key: keyCondition,
|
|
2135
2065
|
updateExpression,
|
|
2136
2066
|
expressionAttributeNames,
|
|
2137
2067
|
expressionAttributeValues
|
|
@@ -2185,10 +2115,22 @@ var TransactionBuilder = class {
|
|
|
2185
2115
|
* @see UpdateBuilder for creating update commands
|
|
2186
2116
|
*/
|
|
2187
2117
|
updateWithCommand(command) {
|
|
2188
|
-
|
|
2118
|
+
let keyForDuplicateCheck;
|
|
2119
|
+
let keyForTransaction;
|
|
2120
|
+
if (typeof command.key === "object" && command.key !== null && "pk" in command.key) {
|
|
2121
|
+
keyForTransaction = this.createKeyForPrimaryIndex(command.key);
|
|
2122
|
+
keyForDuplicateCheck = keyForTransaction;
|
|
2123
|
+
} else {
|
|
2124
|
+
keyForTransaction = command.key;
|
|
2125
|
+
keyForDuplicateCheck = command.key;
|
|
2126
|
+
}
|
|
2127
|
+
this.checkForDuplicateItem(command.tableName, keyForDuplicateCheck);
|
|
2189
2128
|
const transactionItem = {
|
|
2190
2129
|
type: "Update",
|
|
2191
|
-
params:
|
|
2130
|
+
params: {
|
|
2131
|
+
...command,
|
|
2132
|
+
key: keyForTransaction
|
|
2133
|
+
}
|
|
2192
2134
|
};
|
|
2193
2135
|
this.items.push(transactionItem);
|
|
2194
2136
|
return this;
|
|
@@ -2245,7 +2187,8 @@ var TransactionBuilder = class {
|
|
|
2245
2187
|
* @throws {Error} If condition expression generation fails
|
|
2246
2188
|
*/
|
|
2247
2189
|
conditionCheck(tableName, key, condition) {
|
|
2248
|
-
this.
|
|
2190
|
+
const keyCondition = this.createKeyForPrimaryIndex(key);
|
|
2191
|
+
this.checkForDuplicateItem(tableName, keyCondition);
|
|
2249
2192
|
const { expression, names, values } = prepareExpressionParams(condition);
|
|
2250
2193
|
if (!expression) {
|
|
2251
2194
|
throw new Error("Failed to generate condition expression");
|
|
@@ -2254,10 +2197,7 @@ var TransactionBuilder = class {
|
|
|
2254
2197
|
type: "ConditionCheck",
|
|
2255
2198
|
params: {
|
|
2256
2199
|
tableName,
|
|
2257
|
-
key:
|
|
2258
|
-
pk: key.pk,
|
|
2259
|
-
sk: key.sk
|
|
2260
|
-
},
|
|
2200
|
+
key: keyCondition,
|
|
2261
2201
|
conditionExpression: expression,
|
|
2262
2202
|
expressionAttributeNames: names,
|
|
2263
2203
|
expressionAttributeValues: values
|
|
@@ -2297,10 +2237,22 @@ var TransactionBuilder = class {
|
|
|
2297
2237
|
* @see ConditionCheckBuilder for creating condition check commands
|
|
2298
2238
|
*/
|
|
2299
2239
|
conditionCheckWithCommand(command) {
|
|
2300
|
-
|
|
2240
|
+
let keyForDuplicateCheck;
|
|
2241
|
+
let keyForTransaction;
|
|
2242
|
+
if (typeof command.key === "object" && command.key !== null && "pk" in command.key) {
|
|
2243
|
+
keyForTransaction = this.createKeyForPrimaryIndex(command.key);
|
|
2244
|
+
keyForDuplicateCheck = keyForTransaction;
|
|
2245
|
+
} else {
|
|
2246
|
+
keyForTransaction = command.key;
|
|
2247
|
+
keyForDuplicateCheck = command.key;
|
|
2248
|
+
}
|
|
2249
|
+
this.checkForDuplicateItem(command.tableName, keyForDuplicateCheck);
|
|
2301
2250
|
const transactionItem = {
|
|
2302
2251
|
type: "ConditionCheck",
|
|
2303
|
-
params:
|
|
2252
|
+
params: {
|
|
2253
|
+
...command,
|
|
2254
|
+
key: keyForTransaction
|
|
2255
|
+
}
|
|
2304
2256
|
};
|
|
2305
2257
|
this.items.push(transactionItem);
|
|
2306
2258
|
return this;
|
|
@@ -2533,7 +2485,7 @@ var ConditionCheckBuilder = class {
|
|
|
2533
2485
|
* );
|
|
2534
2486
|
* ```
|
|
2535
2487
|
*
|
|
2536
|
-
* @param condition - Either a Condition
|
|
2488
|
+
* @param condition - Either a Condition DynamoItem or a callback function that builds the condition
|
|
2537
2489
|
* @returns The builder instance for method chaining
|
|
2538
2490
|
*/
|
|
2539
2491
|
condition(condition) {
|
|
@@ -2759,18 +2711,15 @@ var GetBuilder = class {
|
|
|
2759
2711
|
* - item: The retrieved dinosaur or undefined if not found
|
|
2760
2712
|
*/
|
|
2761
2713
|
async execute() {
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
this.params.expressionAttributeNames = expressionAttributeNames;
|
|
2772
|
-
}
|
|
2773
|
-
return this.executor(this.params);
|
|
2714
|
+
const expressionParams = {
|
|
2715
|
+
expressionAttributeNames: {}};
|
|
2716
|
+
const projectionExpression = Array.from(this.selectedFields).map((p) => generateAttributeName(expressionParams, p)).join(", ");
|
|
2717
|
+
const { expressionAttributeNames } = expressionParams;
|
|
2718
|
+
return this.executor({
|
|
2719
|
+
...this.params,
|
|
2720
|
+
projectionExpression: projectionExpression.length > 0 ? projectionExpression : void 0,
|
|
2721
|
+
expressionAttributeNames: Object.keys(expressionAttributeNames).length > 0 ? expressionAttributeNames : void 0
|
|
2722
|
+
});
|
|
2774
2723
|
}
|
|
2775
2724
|
};
|
|
2776
2725
|
|
|
@@ -2865,6 +2814,16 @@ var Table = class {
|
|
|
2865
2814
|
this.sortKey = config.indexes.sortKey;
|
|
2866
2815
|
this.gsis = config.indexes.gsis || {};
|
|
2867
2816
|
}
|
|
2817
|
+
createKeyForPrimaryIndex(keyCondition) {
|
|
2818
|
+
const primaryCondition = { [this.partitionKey]: keyCondition.pk };
|
|
2819
|
+
if (this.sortKey) {
|
|
2820
|
+
if (!keyCondition.sk) {
|
|
2821
|
+
throw new Error("Sort key has not been provided but the Table has a sort key");
|
|
2822
|
+
}
|
|
2823
|
+
primaryCondition[this.sortKey] = keyCondition.sk;
|
|
2824
|
+
}
|
|
2825
|
+
return primaryCondition;
|
|
2826
|
+
}
|
|
2868
2827
|
/**
|
|
2869
2828
|
* Creates a new item in the table, it will fail if the item already exists
|
|
2870
2829
|
*
|
|
@@ -2879,7 +2838,7 @@ var Table = class {
|
|
|
2879
2838
|
try {
|
|
2880
2839
|
const result = await this.dynamoClient.get({
|
|
2881
2840
|
TableName: params.tableName,
|
|
2882
|
-
Key:
|
|
2841
|
+
Key: this.createKeyForPrimaryIndex(keyCondition),
|
|
2883
2842
|
ProjectionExpression: params.projectionExpression,
|
|
2884
2843
|
ExpressionAttributeNames: params.expressionAttributeNames,
|
|
2885
2844
|
ConsistentRead: params.consistentRead
|
|
@@ -2914,13 +2873,12 @@ var Table = class {
|
|
|
2914
2873
|
ReturnValues: params.returnValues === "CONSISTENT" ? "NONE" : params.returnValues
|
|
2915
2874
|
});
|
|
2916
2875
|
if (params.returnValues === "CONSISTENT") {
|
|
2917
|
-
const key = {
|
|
2918
|
-
pk: params.item[this.partitionKey],
|
|
2919
|
-
...this.sortKey && { sk: params.item[this.sortKey] }
|
|
2920
|
-
};
|
|
2921
2876
|
const getResult = await this.dynamoClient.get({
|
|
2922
2877
|
TableName: params.tableName,
|
|
2923
|
-
Key:
|
|
2878
|
+
Key: this.createKeyForPrimaryIndex({
|
|
2879
|
+
pk: params.item[this.partitionKey],
|
|
2880
|
+
...this.sortKey && { sk: params.item[this.sortKey] }
|
|
2881
|
+
}),
|
|
2924
2882
|
ConsistentRead: true
|
|
2925
2883
|
});
|
|
2926
2884
|
return getResult.Item;
|
|
@@ -3104,7 +3062,7 @@ var Table = class {
|
|
|
3104
3062
|
try {
|
|
3105
3063
|
const result = await this.dynamoClient.delete({
|
|
3106
3064
|
TableName: params.tableName,
|
|
3107
|
-
Key:
|
|
3065
|
+
Key: this.createKeyForPrimaryIndex(keyCondition),
|
|
3108
3066
|
ConditionExpression: params.conditionExpression,
|
|
3109
3067
|
ExpressionAttributeNames: params.expressionAttributeNames,
|
|
3110
3068
|
ExpressionAttributeValues: params.expressionAttributeValues,
|
|
@@ -3131,7 +3089,7 @@ var Table = class {
|
|
|
3131
3089
|
try {
|
|
3132
3090
|
const result = await this.dynamoClient.update({
|
|
3133
3091
|
TableName: params.tableName,
|
|
3134
|
-
Key:
|
|
3092
|
+
Key: this.createKeyForPrimaryIndex(keyCondition),
|
|
3135
3093
|
UpdateExpression: params.updateExpression,
|
|
3136
3094
|
ConditionExpression: params.conditionExpression,
|
|
3137
3095
|
ExpressionAttributeNames: params.expressionAttributeNames,
|
|
@@ -3259,10 +3217,7 @@ var Table = class {
|
|
|
3259
3217
|
}
|
|
3260
3218
|
return {
|
|
3261
3219
|
DeleteRequest: {
|
|
3262
|
-
Key:
|
|
3263
|
-
[this.partitionKey]: operation.key.pk,
|
|
3264
|
-
...this.sortKey ? { [this.sortKey]: operation.key.sk } : {}
|
|
3265
|
-
}
|
|
3220
|
+
Key: this.createKeyForPrimaryIndex(operation.key)
|
|
3266
3221
|
}
|
|
3267
3222
|
};
|
|
3268
3223
|
});
|
|
@@ -3305,29 +3260,7 @@ var Table = class {
|
|
|
3305
3260
|
};
|
|
3306
3261
|
}
|
|
3307
3262
|
};
|
|
3308
|
-
|
|
3309
|
-
|
|
3310
|
-
|
|
3311
|
-
|
|
3312
|
-
Paginator,
|
|
3313
|
-
PutBuilder,
|
|
3314
|
-
QueryBuilder,
|
|
3315
|
-
Table,
|
|
3316
|
-
TransactionBuilder,
|
|
3317
|
-
UpdateBuilder,
|
|
3318
|
-
and,
|
|
3319
|
-
attributeExists,
|
|
3320
|
-
attributeNotExists,
|
|
3321
|
-
beginsWith,
|
|
3322
|
-
between,
|
|
3323
|
-
contains,
|
|
3324
|
-
createComparisonCondition,
|
|
3325
|
-
eq,
|
|
3326
|
-
gt,
|
|
3327
|
-
gte,
|
|
3328
|
-
lt,
|
|
3329
|
-
lte,
|
|
3330
|
-
ne,
|
|
3331
|
-
not,
|
|
3332
|
-
or
|
|
3333
|
-
});
|
|
3263
|
+
|
|
3264
|
+
exports.Table = Table;
|
|
3265
|
+
//# sourceMappingURL=table.cjs.map
|
|
3266
|
+
//# sourceMappingURL=table.cjs.map
|