dyno-table 1.0.0-alpha.1 → 1.0.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 +751 -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 +894 -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 +892 -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 +228 -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 +224 -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.js → table.cjs} +88 -127
- package/dist/table.cjs.map +1 -0
- package/dist/table.d.cts +12 -0
- package/dist/table.d.ts +12 -0
- package/dist/{index.cjs → table.js} +86 -176
- 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,51 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
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);
|
|
48
|
-
|
|
49
1
|
// src/conditions.ts
|
|
50
2
|
var createComparisonCondition = (type) => (attr, value) => ({
|
|
51
3
|
type,
|
|
@@ -909,6 +861,14 @@ var PutBuilder = class {
|
|
|
909
861
|
returnValues: "NONE"
|
|
910
862
|
};
|
|
911
863
|
}
|
|
864
|
+
set(valuesOrPath, value) {
|
|
865
|
+
if (typeof valuesOrPath === "object") {
|
|
866
|
+
Object.assign(this.item, valuesOrPath);
|
|
867
|
+
} else {
|
|
868
|
+
this.item[valuesOrPath] = value;
|
|
869
|
+
}
|
|
870
|
+
return this;
|
|
871
|
+
}
|
|
912
872
|
/**
|
|
913
873
|
* Adds a condition that must be satisfied for the put operation to succeed.
|
|
914
874
|
* Use this method when you need to:
|
|
@@ -1153,10 +1113,6 @@ var DeleteBuilder = class {
|
|
|
1153
1113
|
}
|
|
1154
1114
|
/**
|
|
1155
1115
|
* 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
1116
|
*
|
|
1161
1117
|
* @example
|
|
1162
1118
|
* ```typescript
|
|
@@ -1208,10 +1164,6 @@ var DeleteBuilder = class {
|
|
|
1208
1164
|
}
|
|
1209
1165
|
/**
|
|
1210
1166
|
* 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
1167
|
*
|
|
1216
1168
|
* @example
|
|
1217
1169
|
* ```ts
|
|
@@ -1252,10 +1204,6 @@ var DeleteBuilder = class {
|
|
|
1252
1204
|
}
|
|
1253
1205
|
/**
|
|
1254
1206
|
* 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
1207
|
*
|
|
1260
1208
|
* @example
|
|
1261
1209
|
* ```ts
|
|
@@ -1306,11 +1254,6 @@ var DeleteBuilder = class {
|
|
|
1306
1254
|
/**
|
|
1307
1255
|
* Gets a human-readable representation of the delete command
|
|
1308
1256
|
* 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
1257
|
*
|
|
1315
1258
|
* @example
|
|
1316
1259
|
* ```ts
|
|
@@ -1369,10 +1312,6 @@ var UpdateBuilder = class {
|
|
|
1369
1312
|
}
|
|
1370
1313
|
/**
|
|
1371
1314
|
* 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
1315
|
*
|
|
1377
1316
|
* @example
|
|
1378
1317
|
* ```typescript
|
|
@@ -1399,10 +1338,6 @@ var UpdateBuilder = class {
|
|
|
1399
1338
|
}
|
|
1400
1339
|
/**
|
|
1401
1340
|
* 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
1341
|
*
|
|
1407
1342
|
* @example
|
|
1408
1343
|
* ```typescript
|
|
@@ -1431,10 +1366,6 @@ var UpdateBuilder = class {
|
|
|
1431
1366
|
}
|
|
1432
1367
|
/**
|
|
1433
1368
|
* 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
1369
|
*
|
|
1439
1370
|
* @example
|
|
1440
1371
|
* ```typescript
|
|
@@ -1444,7 +1375,7 @@ var UpdateBuilder = class {
|
|
|
1444
1375
|
* ['JUNGLE', 'COASTAL']
|
|
1445
1376
|
* );
|
|
1446
1377
|
*
|
|
1447
|
-
* // Remove from sets using Set
|
|
1378
|
+
* // Remove from sets using Set DynamoItems
|
|
1448
1379
|
* builder.deleteElementsFromSet(
|
|
1449
1380
|
* 'knownBehaviors',
|
|
1450
1381
|
* new Set(['NOCTURNAL', 'TERRITORIAL'])
|
|
@@ -1477,11 +1408,6 @@ var UpdateBuilder = class {
|
|
|
1477
1408
|
}
|
|
1478
1409
|
/**
|
|
1479
1410
|
* 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
1411
|
*
|
|
1486
1412
|
* @example
|
|
1487
1413
|
* ```typescript
|
|
@@ -1513,7 +1439,7 @@ var UpdateBuilder = class {
|
|
|
1513
1439
|
* );
|
|
1514
1440
|
* ```
|
|
1515
1441
|
*
|
|
1516
|
-
* @param condition - Either a Condition
|
|
1442
|
+
* @param condition - Either a Condition DynamoItem or a callback function that builds the condition
|
|
1517
1443
|
* @returns The builder instance for method chaining
|
|
1518
1444
|
*/
|
|
1519
1445
|
condition(condition) {
|
|
@@ -1542,11 +1468,6 @@ var UpdateBuilder = class {
|
|
|
1542
1468
|
}
|
|
1543
1469
|
/**
|
|
1544
1470
|
* 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
1471
|
*
|
|
1551
1472
|
* Available options:
|
|
1552
1473
|
* - ALL_NEW: All attributes after the update
|
|
@@ -1674,10 +1595,6 @@ var UpdateBuilder = class {
|
|
|
1674
1595
|
}
|
|
1675
1596
|
/**
|
|
1676
1597
|
* 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
1598
|
*
|
|
1682
1599
|
* @example
|
|
1683
1600
|
* ```typescript
|
|
@@ -1707,11 +1624,6 @@ var UpdateBuilder = class {
|
|
|
1707
1624
|
}
|
|
1708
1625
|
/**
|
|
1709
1626
|
* 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
1627
|
*
|
|
1716
1628
|
* @example
|
|
1717
1629
|
* ```typescript
|
|
@@ -1738,10 +1650,6 @@ var UpdateBuilder = class {
|
|
|
1738
1650
|
}
|
|
1739
1651
|
/**
|
|
1740
1652
|
* 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
1653
|
*
|
|
1746
1654
|
* @example
|
|
1747
1655
|
* ```typescript
|
|
@@ -1776,7 +1684,7 @@ var UpdateBuilder = class {
|
|
|
1776
1684
|
* }
|
|
1777
1685
|
* ```
|
|
1778
1686
|
*
|
|
1779
|
-
* @returns A promise that resolves to an
|
|
1687
|
+
* @returns A promise that resolves to an DynamoItem containing the updated item (if returnValues is set)
|
|
1780
1688
|
* @throws {ConditionalCheckFailedException} If the condition check fails
|
|
1781
1689
|
* @throws {Error} If the update operation fails for other reasons
|
|
1782
1690
|
*/
|
|
@@ -1830,7 +1738,7 @@ var TransactionBuilder = class {
|
|
|
1830
1738
|
*/
|
|
1831
1739
|
checkForDuplicateItem(tableName, newItem) {
|
|
1832
1740
|
const pkName = this.indexConfig.partitionKey;
|
|
1833
|
-
const skName = this.indexConfig.sortKey
|
|
1741
|
+
const skName = this.indexConfig.sortKey ?? "";
|
|
1834
1742
|
const pkValue = newItem[pkName];
|
|
1835
1743
|
const skValue = skName ? newItem[skName] : void 0;
|
|
1836
1744
|
if (!pkValue) {
|
|
@@ -1871,6 +1779,18 @@ var TransactionBuilder = class {
|
|
|
1871
1779
|
);
|
|
1872
1780
|
}
|
|
1873
1781
|
}
|
|
1782
|
+
createKeyForPrimaryIndex(key) {
|
|
1783
|
+
const keyCondition = {
|
|
1784
|
+
[this.indexConfig.partitionKey]: key.pk
|
|
1785
|
+
};
|
|
1786
|
+
if (this.indexConfig.sortKey) {
|
|
1787
|
+
if (key.sk === void 0) {
|
|
1788
|
+
throw new Error("Sort key is required for delete operation");
|
|
1789
|
+
}
|
|
1790
|
+
keyCondition[this.indexConfig.sortKey] = key.sk;
|
|
1791
|
+
}
|
|
1792
|
+
return keyCondition;
|
|
1793
|
+
}
|
|
1874
1794
|
/**
|
|
1875
1795
|
* Adds a put operation to the transaction.
|
|
1876
1796
|
* Use this method when you need to:
|
|
@@ -2010,15 +1930,13 @@ var TransactionBuilder = class {
|
|
|
2010
1930
|
* @throws {Error} If a duplicate item is detected in the transaction
|
|
2011
1931
|
*/
|
|
2012
1932
|
delete(tableName, key, condition) {
|
|
2013
|
-
this.
|
|
1933
|
+
const keyCondition = this.createKeyForPrimaryIndex(key);
|
|
1934
|
+
this.checkForDuplicateItem(tableName, keyCondition);
|
|
2014
1935
|
const transactionItem = {
|
|
2015
1936
|
type: "Delete",
|
|
2016
1937
|
params: {
|
|
2017
1938
|
tableName,
|
|
2018
|
-
key:
|
|
2019
|
-
pk: key.pk,
|
|
2020
|
-
sk: key.sk
|
|
2021
|
-
}
|
|
1939
|
+
key: keyCondition
|
|
2022
1940
|
}
|
|
2023
1941
|
};
|
|
2024
1942
|
if (condition) {
|
|
@@ -2060,10 +1978,14 @@ var TransactionBuilder = class {
|
|
|
2060
1978
|
* @see DeleteBuilder for creating delete commands
|
|
2061
1979
|
*/
|
|
2062
1980
|
deleteWithCommand(command) {
|
|
2063
|
-
this.
|
|
1981
|
+
const keyCondition = this.createKeyForPrimaryIndex(command.key);
|
|
1982
|
+
this.checkForDuplicateItem(command.tableName, keyCondition);
|
|
2064
1983
|
const transactionItem = {
|
|
2065
1984
|
type: "Delete",
|
|
2066
|
-
params:
|
|
1985
|
+
params: {
|
|
1986
|
+
...command,
|
|
1987
|
+
key: keyCondition
|
|
1988
|
+
}
|
|
2067
1989
|
};
|
|
2068
1990
|
this.items.push(transactionItem);
|
|
2069
1991
|
return this;
|
|
@@ -2123,15 +2045,13 @@ var TransactionBuilder = class {
|
|
|
2123
2045
|
* @throws {Error} If a duplicate item is detected in the transaction
|
|
2124
2046
|
*/
|
|
2125
2047
|
update(tableName, key, updateExpression, expressionAttributeNames, expressionAttributeValues, condition) {
|
|
2126
|
-
this.
|
|
2048
|
+
const keyCondition = this.createKeyForPrimaryIndex(key);
|
|
2049
|
+
this.checkForDuplicateItem(tableName, keyCondition);
|
|
2127
2050
|
const transactionItem = {
|
|
2128
2051
|
type: "Update",
|
|
2129
2052
|
params: {
|
|
2130
2053
|
tableName,
|
|
2131
|
-
key:
|
|
2132
|
-
pk: key.pk,
|
|
2133
|
-
sk: key.sk
|
|
2134
|
-
},
|
|
2054
|
+
key: keyCondition,
|
|
2135
2055
|
updateExpression,
|
|
2136
2056
|
expressionAttributeNames,
|
|
2137
2057
|
expressionAttributeValues
|
|
@@ -2185,10 +2105,14 @@ var TransactionBuilder = class {
|
|
|
2185
2105
|
* @see UpdateBuilder for creating update commands
|
|
2186
2106
|
*/
|
|
2187
2107
|
updateWithCommand(command) {
|
|
2188
|
-
this.
|
|
2108
|
+
const keyCondition = this.createKeyForPrimaryIndex(command.key);
|
|
2109
|
+
this.checkForDuplicateItem(command.tableName, keyCondition);
|
|
2189
2110
|
const transactionItem = {
|
|
2190
2111
|
type: "Update",
|
|
2191
|
-
params:
|
|
2112
|
+
params: {
|
|
2113
|
+
...command,
|
|
2114
|
+
key: keyCondition
|
|
2115
|
+
}
|
|
2192
2116
|
};
|
|
2193
2117
|
this.items.push(transactionItem);
|
|
2194
2118
|
return this;
|
|
@@ -2245,7 +2169,8 @@ var TransactionBuilder = class {
|
|
|
2245
2169
|
* @throws {Error} If condition expression generation fails
|
|
2246
2170
|
*/
|
|
2247
2171
|
conditionCheck(tableName, key, condition) {
|
|
2248
|
-
this.
|
|
2172
|
+
const keyCondition = this.createKeyForPrimaryIndex(key);
|
|
2173
|
+
this.checkForDuplicateItem(tableName, keyCondition);
|
|
2249
2174
|
const { expression, names, values } = prepareExpressionParams(condition);
|
|
2250
2175
|
if (!expression) {
|
|
2251
2176
|
throw new Error("Failed to generate condition expression");
|
|
@@ -2254,10 +2179,7 @@ var TransactionBuilder = class {
|
|
|
2254
2179
|
type: "ConditionCheck",
|
|
2255
2180
|
params: {
|
|
2256
2181
|
tableName,
|
|
2257
|
-
key:
|
|
2258
|
-
pk: key.pk,
|
|
2259
|
-
sk: key.sk
|
|
2260
|
-
},
|
|
2182
|
+
key: keyCondition,
|
|
2261
2183
|
conditionExpression: expression,
|
|
2262
2184
|
expressionAttributeNames: names,
|
|
2263
2185
|
expressionAttributeValues: values
|
|
@@ -2297,10 +2219,14 @@ var TransactionBuilder = class {
|
|
|
2297
2219
|
* @see ConditionCheckBuilder for creating condition check commands
|
|
2298
2220
|
*/
|
|
2299
2221
|
conditionCheckWithCommand(command) {
|
|
2300
|
-
this.
|
|
2222
|
+
const keyCondition = this.createKeyForPrimaryIndex(command.key);
|
|
2223
|
+
this.checkForDuplicateItem(command.tableName, keyCondition);
|
|
2301
2224
|
const transactionItem = {
|
|
2302
2225
|
type: "ConditionCheck",
|
|
2303
|
-
params:
|
|
2226
|
+
params: {
|
|
2227
|
+
...command,
|
|
2228
|
+
key: keyCondition
|
|
2229
|
+
}
|
|
2304
2230
|
};
|
|
2305
2231
|
this.items.push(transactionItem);
|
|
2306
2232
|
return this;
|
|
@@ -2533,7 +2459,7 @@ var ConditionCheckBuilder = class {
|
|
|
2533
2459
|
* );
|
|
2534
2460
|
* ```
|
|
2535
2461
|
*
|
|
2536
|
-
* @param condition - Either a Condition
|
|
2462
|
+
* @param condition - Either a Condition DynamoItem or a callback function that builds the condition
|
|
2537
2463
|
* @returns The builder instance for method chaining
|
|
2538
2464
|
*/
|
|
2539
2465
|
condition(condition) {
|
|
@@ -2759,18 +2685,18 @@ var GetBuilder = class {
|
|
|
2759
2685
|
* - item: The retrieved dinosaur or undefined if not found
|
|
2760
2686
|
*/
|
|
2761
2687
|
async execute() {
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
this.params
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2688
|
+
const expressionParams = {
|
|
2689
|
+
expressionAttributeNames: {},
|
|
2690
|
+
expressionAttributeValues: {},
|
|
2691
|
+
valueCounter: { count: 0 }
|
|
2692
|
+
};
|
|
2693
|
+
const projectionExpression = Array.from(this.selectedFields).map((p) => generateAttributeName(expressionParams, p)).join(", ");
|
|
2694
|
+
const { expressionAttributeNames } = expressionParams;
|
|
2695
|
+
return this.executor({
|
|
2696
|
+
...this.params,
|
|
2697
|
+
projectionExpression: projectionExpression.length > 0 ? projectionExpression : void 0,
|
|
2698
|
+
expressionAttributeNames: Object.keys(expressionAttributeNames).length > 0 ? expressionAttributeNames : void 0
|
|
2699
|
+
});
|
|
2774
2700
|
}
|
|
2775
2701
|
};
|
|
2776
2702
|
|
|
@@ -2865,6 +2791,16 @@ var Table = class {
|
|
|
2865
2791
|
this.sortKey = config.indexes.sortKey;
|
|
2866
2792
|
this.gsis = config.indexes.gsis || {};
|
|
2867
2793
|
}
|
|
2794
|
+
createKeyForPrimaryIndex(keyCondition) {
|
|
2795
|
+
const primaryCondition = { [this.partitionKey]: keyCondition.pk };
|
|
2796
|
+
if (this.sortKey) {
|
|
2797
|
+
if (!keyCondition.sk) {
|
|
2798
|
+
throw new Error("Sort key has not been provided but the Table has a sort key");
|
|
2799
|
+
}
|
|
2800
|
+
primaryCondition[this.sortKey] = keyCondition.sk;
|
|
2801
|
+
}
|
|
2802
|
+
return primaryCondition;
|
|
2803
|
+
}
|
|
2868
2804
|
/**
|
|
2869
2805
|
* Creates a new item in the table, it will fail if the item already exists
|
|
2870
2806
|
*
|
|
@@ -2879,7 +2815,7 @@ var Table = class {
|
|
|
2879
2815
|
try {
|
|
2880
2816
|
const result = await this.dynamoClient.get({
|
|
2881
2817
|
TableName: params.tableName,
|
|
2882
|
-
Key:
|
|
2818
|
+
Key: this.createKeyForPrimaryIndex(keyCondition),
|
|
2883
2819
|
ProjectionExpression: params.projectionExpression,
|
|
2884
2820
|
ExpressionAttributeNames: params.expressionAttributeNames,
|
|
2885
2821
|
ConsistentRead: params.consistentRead
|
|
@@ -2914,13 +2850,12 @@ var Table = class {
|
|
|
2914
2850
|
ReturnValues: params.returnValues === "CONSISTENT" ? "NONE" : params.returnValues
|
|
2915
2851
|
});
|
|
2916
2852
|
if (params.returnValues === "CONSISTENT") {
|
|
2917
|
-
const key = {
|
|
2918
|
-
pk: params.item[this.partitionKey],
|
|
2919
|
-
...this.sortKey && { sk: params.item[this.sortKey] }
|
|
2920
|
-
};
|
|
2921
2853
|
const getResult = await this.dynamoClient.get({
|
|
2922
2854
|
TableName: params.tableName,
|
|
2923
|
-
Key:
|
|
2855
|
+
Key: this.createKeyForPrimaryIndex({
|
|
2856
|
+
pk: params.item[this.partitionKey],
|
|
2857
|
+
...this.sortKey && { sk: params.item[this.sortKey] }
|
|
2858
|
+
}),
|
|
2924
2859
|
ConsistentRead: true
|
|
2925
2860
|
});
|
|
2926
2861
|
return getResult.Item;
|
|
@@ -3104,7 +3039,7 @@ var Table = class {
|
|
|
3104
3039
|
try {
|
|
3105
3040
|
const result = await this.dynamoClient.delete({
|
|
3106
3041
|
TableName: params.tableName,
|
|
3107
|
-
Key:
|
|
3042
|
+
Key: this.createKeyForPrimaryIndex(keyCondition),
|
|
3108
3043
|
ConditionExpression: params.conditionExpression,
|
|
3109
3044
|
ExpressionAttributeNames: params.expressionAttributeNames,
|
|
3110
3045
|
ExpressionAttributeValues: params.expressionAttributeValues,
|
|
@@ -3131,7 +3066,7 @@ var Table = class {
|
|
|
3131
3066
|
try {
|
|
3132
3067
|
const result = await this.dynamoClient.update({
|
|
3133
3068
|
TableName: params.tableName,
|
|
3134
|
-
Key:
|
|
3069
|
+
Key: this.createKeyForPrimaryIndex(keyCondition),
|
|
3135
3070
|
UpdateExpression: params.updateExpression,
|
|
3136
3071
|
ConditionExpression: params.conditionExpression,
|
|
3137
3072
|
ExpressionAttributeNames: params.expressionAttributeNames,
|
|
@@ -3259,10 +3194,7 @@ var Table = class {
|
|
|
3259
3194
|
}
|
|
3260
3195
|
return {
|
|
3261
3196
|
DeleteRequest: {
|
|
3262
|
-
Key:
|
|
3263
|
-
[this.partitionKey]: operation.key.pk,
|
|
3264
|
-
...this.sortKey ? { [this.sortKey]: operation.key.sk } : {}
|
|
3265
|
-
}
|
|
3197
|
+
Key: this.createKeyForPrimaryIndex(operation.key)
|
|
3266
3198
|
}
|
|
3267
3199
|
};
|
|
3268
3200
|
});
|
|
@@ -3305,29 +3237,7 @@ var Table = class {
|
|
|
3305
3237
|
};
|
|
3306
3238
|
}
|
|
3307
3239
|
};
|
|
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
|
-
});
|
|
3240
|
+
|
|
3241
|
+
export { Table };
|
|
3242
|
+
//# sourceMappingURL=table.js.map
|
|
3243
|
+
//# sourceMappingURL=table.js.map
|