dyno-table 0.2.0-0 → 1.0.0-alpha.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/README.md +182 -577
- package/dist/{table.cjs → index.cjs} +175 -87
- package/dist/index.d.cts +2971 -0
- package/dist/index.d.ts +2971 -0
- package/dist/{table.js → index.js} +127 -86
- package/package.json +10 -77
- package/dist/builder-types-C_PDZhnP.d.ts +0 -118
- package/dist/builder-types-DtwbqMeF.d.cts +0 -118
- package/dist/builders/condition-check-builder.cjs +0 -394
- package/dist/builders/condition-check-builder.cjs.map +0 -1
- package/dist/builders/condition-check-builder.d.cts +0 -157
- package/dist/builders/condition-check-builder.d.ts +0 -157
- package/dist/builders/condition-check-builder.js +0 -392
- package/dist/builders/condition-check-builder.js.map +0 -1
- package/dist/builders/delete-builder.cjs +0 -405
- package/dist/builders/delete-builder.cjs.map +0 -1
- package/dist/builders/delete-builder.d.cts +0 -166
- package/dist/builders/delete-builder.d.ts +0 -166
- package/dist/builders/delete-builder.js +0 -403
- package/dist/builders/delete-builder.js.map +0 -1
- package/dist/builders/paginator.cjs +0 -199
- package/dist/builders/paginator.cjs.map +0 -1
- package/dist/builders/paginator.d.cts +0 -179
- package/dist/builders/paginator.d.ts +0 -179
- package/dist/builders/paginator.js +0 -197
- package/dist/builders/paginator.js.map +0 -1
- package/dist/builders/put-builder.cjs +0 -476
- package/dist/builders/put-builder.cjs.map +0 -1
- package/dist/builders/put-builder.d.cts +0 -274
- package/dist/builders/put-builder.d.ts +0 -274
- package/dist/builders/put-builder.js +0 -474
- package/dist/builders/put-builder.js.map +0 -1
- package/dist/builders/query-builder.cjs +0 -674
- package/dist/builders/query-builder.cjs.map +0 -1
- package/dist/builders/query-builder.d.cts +0 -6
- package/dist/builders/query-builder.d.ts +0 -6
- package/dist/builders/query-builder.js +0 -672
- package/dist/builders/query-builder.js.map +0 -1
- package/dist/builders/transaction-builder.cjs +0 -894
- package/dist/builders/transaction-builder.cjs.map +0 -1
- package/dist/builders/transaction-builder.d.cts +0 -511
- package/dist/builders/transaction-builder.d.ts +0 -511
- package/dist/builders/transaction-builder.js +0 -892
- package/dist/builders/transaction-builder.js.map +0 -1
- package/dist/builders/update-builder.cjs +0 -627
- package/dist/builders/update-builder.cjs.map +0 -1
- package/dist/builders/update-builder.d.cts +0 -365
- package/dist/builders/update-builder.d.ts +0 -365
- package/dist/builders/update-builder.js +0 -625
- package/dist/builders/update-builder.js.map +0 -1
- package/dist/conditions--ld9a78i.d.ts +0 -331
- package/dist/conditions-ChhQWd6z.d.cts +0 -331
- package/dist/conditions.cjs +0 -59
- package/dist/conditions.cjs.map +0 -1
- package/dist/conditions.d.cts +0 -3
- package/dist/conditions.d.ts +0 -3
- package/dist/conditions.js +0 -43
- package/dist/conditions.js.map +0 -1
- package/dist/entity.cjs +0 -228
- package/dist/entity.cjs.map +0 -1
- package/dist/entity.d.cts +0 -149
- package/dist/entity.d.ts +0 -149
- package/dist/entity.js +0 -224
- package/dist/entity.js.map +0 -1
- package/dist/query-builder-Csror9Iu.d.ts +0 -507
- package/dist/query-builder-D2FM9rsu.d.cts +0 -507
- package/dist/standard-schema.cjs +0 -4
- package/dist/standard-schema.cjs.map +0 -1
- package/dist/standard-schema.d.cts +0 -57
- package/dist/standard-schema.d.ts +0 -57
- package/dist/standard-schema.js +0 -3
- package/dist/standard-schema.js.map +0 -1
- package/dist/table-BEhBPy2G.d.cts +0 -364
- package/dist/table-BW3cmUqr.d.ts +0 -364
- package/dist/table.cjs.map +0 -1
- package/dist/table.d.cts +0 -12
- package/dist/table.d.ts +0 -12
- package/dist/table.js.map +0 -1
- package/dist/types.cjs +0 -4
- package/dist/types.cjs.map +0 -1
- package/dist/types.d.cts +0 -22
- package/dist/types.d.ts +0 -22
- package/dist/types.js +0 -3
- package/dist/types.js.map +0 -1
- package/dist/utils/partition-key-template.cjs +0 -19
- package/dist/utils/partition-key-template.cjs.map +0 -1
- package/dist/utils/partition-key-template.d.cts +0 -32
- package/dist/utils/partition-key-template.d.ts +0 -32
- package/dist/utils/partition-key-template.js +0 -17
- package/dist/utils/partition-key-template.js.map +0 -1
- package/dist/utils/sort-key-template.cjs +0 -19
- package/dist/utils/sort-key-template.cjs.map +0 -1
- package/dist/utils/sort-key-template.d.cts +0 -35
- package/dist/utils/sort-key-template.d.ts +0 -35
- package/dist/utils/sort-key-template.js +0 -17
- package/dist/utils/sort-key-template.js.map +0 -1
|
@@ -1,4 +1,50 @@
|
|
|
1
|
-
|
|
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);
|
|
2
48
|
|
|
3
49
|
// src/conditions.ts
|
|
4
50
|
var createComparisonCondition = (type) => (attr, value) => ({
|
|
@@ -863,14 +909,6 @@ var PutBuilder = class {
|
|
|
863
909
|
returnValues: "NONE"
|
|
864
910
|
};
|
|
865
911
|
}
|
|
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
|
-
}
|
|
874
912
|
/**
|
|
875
913
|
* Adds a condition that must be satisfied for the put operation to succeed.
|
|
876
914
|
* Use this method when you need to:
|
|
@@ -1115,6 +1153,10 @@ var DeleteBuilder = class {
|
|
|
1115
1153
|
}
|
|
1116
1154
|
/**
|
|
1117
1155
|
* 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
|
|
1118
1160
|
*
|
|
1119
1161
|
* @example
|
|
1120
1162
|
* ```typescript
|
|
@@ -1166,6 +1208,10 @@ var DeleteBuilder = class {
|
|
|
1166
1208
|
}
|
|
1167
1209
|
/**
|
|
1168
1210
|
* 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
|
|
1169
1215
|
*
|
|
1170
1216
|
* @example
|
|
1171
1217
|
* ```ts
|
|
@@ -1206,6 +1252,10 @@ var DeleteBuilder = class {
|
|
|
1206
1252
|
}
|
|
1207
1253
|
/**
|
|
1208
1254
|
* 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
|
|
1209
1259
|
*
|
|
1210
1260
|
* @example
|
|
1211
1261
|
* ```ts
|
|
@@ -1256,6 +1306,11 @@ var DeleteBuilder = class {
|
|
|
1256
1306
|
/**
|
|
1257
1307
|
* Gets a human-readable representation of the delete command
|
|
1258
1308
|
* 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
|
|
1259
1314
|
*
|
|
1260
1315
|
* @example
|
|
1261
1316
|
* ```ts
|
|
@@ -1314,6 +1369,10 @@ var UpdateBuilder = class {
|
|
|
1314
1369
|
}
|
|
1315
1370
|
/**
|
|
1316
1371
|
* 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
|
|
1317
1376
|
*
|
|
1318
1377
|
* @example
|
|
1319
1378
|
* ```typescript
|
|
@@ -1340,6 +1399,10 @@ var UpdateBuilder = class {
|
|
|
1340
1399
|
}
|
|
1341
1400
|
/**
|
|
1342
1401
|
* 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
|
|
1343
1406
|
*
|
|
1344
1407
|
* @example
|
|
1345
1408
|
* ```typescript
|
|
@@ -1368,6 +1431,10 @@ var UpdateBuilder = class {
|
|
|
1368
1431
|
}
|
|
1369
1432
|
/**
|
|
1370
1433
|
* 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
|
|
1371
1438
|
*
|
|
1372
1439
|
* @example
|
|
1373
1440
|
* ```typescript
|
|
@@ -1377,7 +1444,7 @@ var UpdateBuilder = class {
|
|
|
1377
1444
|
* ['JUNGLE', 'COASTAL']
|
|
1378
1445
|
* );
|
|
1379
1446
|
*
|
|
1380
|
-
* // Remove from sets using Set
|
|
1447
|
+
* // Remove from sets using Set objects
|
|
1381
1448
|
* builder.deleteElementsFromSet(
|
|
1382
1449
|
* 'knownBehaviors',
|
|
1383
1450
|
* new Set(['NOCTURNAL', 'TERRITORIAL'])
|
|
@@ -1410,6 +1477,11 @@ var UpdateBuilder = class {
|
|
|
1410
1477
|
}
|
|
1411
1478
|
/**
|
|
1412
1479
|
* 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
|
|
1413
1485
|
*
|
|
1414
1486
|
* @example
|
|
1415
1487
|
* ```typescript
|
|
@@ -1441,7 +1513,7 @@ var UpdateBuilder = class {
|
|
|
1441
1513
|
* );
|
|
1442
1514
|
* ```
|
|
1443
1515
|
*
|
|
1444
|
-
* @param condition - Either a Condition
|
|
1516
|
+
* @param condition - Either a Condition object or a callback function that builds the condition
|
|
1445
1517
|
* @returns The builder instance for method chaining
|
|
1446
1518
|
*/
|
|
1447
1519
|
condition(condition) {
|
|
@@ -1470,6 +1542,11 @@ var UpdateBuilder = class {
|
|
|
1470
1542
|
}
|
|
1471
1543
|
/**
|
|
1472
1544
|
* 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
|
|
1473
1550
|
*
|
|
1474
1551
|
* Available options:
|
|
1475
1552
|
* - ALL_NEW: All attributes after the update
|
|
@@ -1597,6 +1674,10 @@ var UpdateBuilder = class {
|
|
|
1597
1674
|
}
|
|
1598
1675
|
/**
|
|
1599
1676
|
* 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
|
|
1600
1681
|
*
|
|
1601
1682
|
* @example
|
|
1602
1683
|
* ```typescript
|
|
@@ -1626,6 +1707,11 @@ var UpdateBuilder = class {
|
|
|
1626
1707
|
}
|
|
1627
1708
|
/**
|
|
1628
1709
|
* 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
|
|
1629
1715
|
*
|
|
1630
1716
|
* @example
|
|
1631
1717
|
* ```typescript
|
|
@@ -1652,6 +1738,10 @@ var UpdateBuilder = class {
|
|
|
1652
1738
|
}
|
|
1653
1739
|
/**
|
|
1654
1740
|
* 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
|
|
1655
1745
|
*
|
|
1656
1746
|
* @example
|
|
1657
1747
|
* ```typescript
|
|
@@ -1686,7 +1776,7 @@ var UpdateBuilder = class {
|
|
|
1686
1776
|
* }
|
|
1687
1777
|
* ```
|
|
1688
1778
|
*
|
|
1689
|
-
* @returns A promise that resolves to an
|
|
1779
|
+
* @returns A promise that resolves to an object containing the updated item (if returnValues is set)
|
|
1690
1780
|
* @throws {ConditionalCheckFailedException} If the condition check fails
|
|
1691
1781
|
* @throws {Error} If the update operation fails for other reasons
|
|
1692
1782
|
*/
|
|
@@ -1740,7 +1830,7 @@ var TransactionBuilder = class {
|
|
|
1740
1830
|
*/
|
|
1741
1831
|
checkForDuplicateItem(tableName, newItem) {
|
|
1742
1832
|
const pkName = this.indexConfig.partitionKey;
|
|
1743
|
-
const skName = this.indexConfig.sortKey
|
|
1833
|
+
const skName = this.indexConfig.sortKey || "";
|
|
1744
1834
|
const pkValue = newItem[pkName];
|
|
1745
1835
|
const skValue = skName ? newItem[skName] : void 0;
|
|
1746
1836
|
if (!pkValue) {
|
|
@@ -1781,18 +1871,6 @@ var TransactionBuilder = class {
|
|
|
1781
1871
|
);
|
|
1782
1872
|
}
|
|
1783
1873
|
}
|
|
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
|
-
}
|
|
1796
1874
|
/**
|
|
1797
1875
|
* Adds a put operation to the transaction.
|
|
1798
1876
|
* Use this method when you need to:
|
|
@@ -1932,13 +2010,15 @@ var TransactionBuilder = class {
|
|
|
1932
2010
|
* @throws {Error} If a duplicate item is detected in the transaction
|
|
1933
2011
|
*/
|
|
1934
2012
|
delete(tableName, key, condition) {
|
|
1935
|
-
|
|
1936
|
-
this.checkForDuplicateItem(tableName, keyCondition);
|
|
2013
|
+
this.checkForDuplicateItem(tableName, key);
|
|
1937
2014
|
const transactionItem = {
|
|
1938
2015
|
type: "Delete",
|
|
1939
2016
|
params: {
|
|
1940
2017
|
tableName,
|
|
1941
|
-
key:
|
|
2018
|
+
key: {
|
|
2019
|
+
pk: key.pk,
|
|
2020
|
+
sk: key.sk
|
|
2021
|
+
}
|
|
1942
2022
|
}
|
|
1943
2023
|
};
|
|
1944
2024
|
if (condition) {
|
|
@@ -1980,14 +2060,10 @@ var TransactionBuilder = class {
|
|
|
1980
2060
|
* @see DeleteBuilder for creating delete commands
|
|
1981
2061
|
*/
|
|
1982
2062
|
deleteWithCommand(command) {
|
|
1983
|
-
|
|
1984
|
-
this.checkForDuplicateItem(command.tableName, keyCondition);
|
|
2063
|
+
this.checkForDuplicateItem(command.tableName, command.key);
|
|
1985
2064
|
const transactionItem = {
|
|
1986
2065
|
type: "Delete",
|
|
1987
|
-
params:
|
|
1988
|
-
...command,
|
|
1989
|
-
key: keyCondition
|
|
1990
|
-
}
|
|
2066
|
+
params: command
|
|
1991
2067
|
};
|
|
1992
2068
|
this.items.push(transactionItem);
|
|
1993
2069
|
return this;
|
|
@@ -2047,13 +2123,15 @@ var TransactionBuilder = class {
|
|
|
2047
2123
|
* @throws {Error} If a duplicate item is detected in the transaction
|
|
2048
2124
|
*/
|
|
2049
2125
|
update(tableName, key, updateExpression, expressionAttributeNames, expressionAttributeValues, condition) {
|
|
2050
|
-
|
|
2051
|
-
this.checkForDuplicateItem(tableName, keyCondition);
|
|
2126
|
+
this.checkForDuplicateItem(tableName, key);
|
|
2052
2127
|
const transactionItem = {
|
|
2053
2128
|
type: "Update",
|
|
2054
2129
|
params: {
|
|
2055
2130
|
tableName,
|
|
2056
|
-
key:
|
|
2131
|
+
key: {
|
|
2132
|
+
pk: key.pk,
|
|
2133
|
+
sk: key.sk
|
|
2134
|
+
},
|
|
2057
2135
|
updateExpression,
|
|
2058
2136
|
expressionAttributeNames,
|
|
2059
2137
|
expressionAttributeValues
|
|
@@ -2107,14 +2185,10 @@ var TransactionBuilder = class {
|
|
|
2107
2185
|
* @see UpdateBuilder for creating update commands
|
|
2108
2186
|
*/
|
|
2109
2187
|
updateWithCommand(command) {
|
|
2110
|
-
|
|
2111
|
-
this.checkForDuplicateItem(command.tableName, keyCondition);
|
|
2188
|
+
this.checkForDuplicateItem(command.tableName, command.key);
|
|
2112
2189
|
const transactionItem = {
|
|
2113
2190
|
type: "Update",
|
|
2114
|
-
params:
|
|
2115
|
-
...command,
|
|
2116
|
-
key: keyCondition
|
|
2117
|
-
}
|
|
2191
|
+
params: command
|
|
2118
2192
|
};
|
|
2119
2193
|
this.items.push(transactionItem);
|
|
2120
2194
|
return this;
|
|
@@ -2171,8 +2245,7 @@ var TransactionBuilder = class {
|
|
|
2171
2245
|
* @throws {Error} If condition expression generation fails
|
|
2172
2246
|
*/
|
|
2173
2247
|
conditionCheck(tableName, key, condition) {
|
|
2174
|
-
|
|
2175
|
-
this.checkForDuplicateItem(tableName, keyCondition);
|
|
2248
|
+
this.checkForDuplicateItem(tableName, key);
|
|
2176
2249
|
const { expression, names, values } = prepareExpressionParams(condition);
|
|
2177
2250
|
if (!expression) {
|
|
2178
2251
|
throw new Error("Failed to generate condition expression");
|
|
@@ -2181,7 +2254,10 @@ var TransactionBuilder = class {
|
|
|
2181
2254
|
type: "ConditionCheck",
|
|
2182
2255
|
params: {
|
|
2183
2256
|
tableName,
|
|
2184
|
-
key:
|
|
2257
|
+
key: {
|
|
2258
|
+
pk: key.pk,
|
|
2259
|
+
sk: key.sk
|
|
2260
|
+
},
|
|
2185
2261
|
conditionExpression: expression,
|
|
2186
2262
|
expressionAttributeNames: names,
|
|
2187
2263
|
expressionAttributeValues: values
|
|
@@ -2221,14 +2297,10 @@ var TransactionBuilder = class {
|
|
|
2221
2297
|
* @see ConditionCheckBuilder for creating condition check commands
|
|
2222
2298
|
*/
|
|
2223
2299
|
conditionCheckWithCommand(command) {
|
|
2224
|
-
|
|
2225
|
-
this.checkForDuplicateItem(command.tableName, keyCondition);
|
|
2300
|
+
this.checkForDuplicateItem(command.tableName, command.key);
|
|
2226
2301
|
const transactionItem = {
|
|
2227
2302
|
type: "ConditionCheck",
|
|
2228
|
-
params:
|
|
2229
|
-
...command,
|
|
2230
|
-
key: keyCondition
|
|
2231
|
-
}
|
|
2303
|
+
params: command
|
|
2232
2304
|
};
|
|
2233
2305
|
this.items.push(transactionItem);
|
|
2234
2306
|
return this;
|
|
@@ -2461,7 +2533,7 @@ var ConditionCheckBuilder = class {
|
|
|
2461
2533
|
* );
|
|
2462
2534
|
* ```
|
|
2463
2535
|
*
|
|
2464
|
-
* @param condition - Either a Condition
|
|
2536
|
+
* @param condition - Either a Condition object or a callback function that builds the condition
|
|
2465
2537
|
* @returns The builder instance for method chaining
|
|
2466
2538
|
*/
|
|
2467
2539
|
condition(condition) {
|
|
@@ -2687,18 +2759,18 @@ var GetBuilder = class {
|
|
|
2687
2759
|
* - item: The retrieved dinosaur or undefined if not found
|
|
2688
2760
|
*/
|
|
2689
2761
|
async execute() {
|
|
2690
|
-
|
|
2691
|
-
expressionAttributeNames
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2762
|
+
if (this.selectedFields.size > 0) {
|
|
2763
|
+
const expressionAttributeNames = {};
|
|
2764
|
+
const projectionParts = [];
|
|
2765
|
+
for (const path of this.selectedFields) {
|
|
2766
|
+
const attrName = `#attr${projectionParts.length}`;
|
|
2767
|
+
expressionAttributeNames[attrName] = path;
|
|
2768
|
+
projectionParts.push(attrName);
|
|
2769
|
+
}
|
|
2770
|
+
this.params.projectionExpression = projectionParts.join(", ");
|
|
2771
|
+
this.params.expressionAttributeNames = expressionAttributeNames;
|
|
2772
|
+
}
|
|
2773
|
+
return this.executor(this.params);
|
|
2702
2774
|
}
|
|
2703
2775
|
};
|
|
2704
2776
|
|
|
@@ -2793,16 +2865,6 @@ var Table = class {
|
|
|
2793
2865
|
this.sortKey = config.indexes.sortKey;
|
|
2794
2866
|
this.gsis = config.indexes.gsis || {};
|
|
2795
2867
|
}
|
|
2796
|
-
createKeyForPrimaryIndex(keyCondition) {
|
|
2797
|
-
const primaryCondition = { [this.partitionKey]: keyCondition.pk };
|
|
2798
|
-
if (this.sortKey) {
|
|
2799
|
-
if (!keyCondition.sk) {
|
|
2800
|
-
throw new Error("Sort key has not been provided but the Table has a sort key");
|
|
2801
|
-
}
|
|
2802
|
-
primaryCondition[this.sortKey] = keyCondition.sk;
|
|
2803
|
-
}
|
|
2804
|
-
return primaryCondition;
|
|
2805
|
-
}
|
|
2806
2868
|
/**
|
|
2807
2869
|
* Creates a new item in the table, it will fail if the item already exists
|
|
2808
2870
|
*
|
|
@@ -2817,7 +2879,7 @@ var Table = class {
|
|
|
2817
2879
|
try {
|
|
2818
2880
|
const result = await this.dynamoClient.get({
|
|
2819
2881
|
TableName: params.tableName,
|
|
2820
|
-
Key:
|
|
2882
|
+
Key: params.key,
|
|
2821
2883
|
ProjectionExpression: params.projectionExpression,
|
|
2822
2884
|
ExpressionAttributeNames: params.expressionAttributeNames,
|
|
2823
2885
|
ConsistentRead: params.consistentRead
|
|
@@ -2852,12 +2914,13 @@ var Table = class {
|
|
|
2852
2914
|
ReturnValues: params.returnValues === "CONSISTENT" ? "NONE" : params.returnValues
|
|
2853
2915
|
});
|
|
2854
2916
|
if (params.returnValues === "CONSISTENT") {
|
|
2917
|
+
const key = {
|
|
2918
|
+
pk: params.item[this.partitionKey],
|
|
2919
|
+
...this.sortKey && { sk: params.item[this.sortKey] }
|
|
2920
|
+
};
|
|
2855
2921
|
const getResult = await this.dynamoClient.get({
|
|
2856
2922
|
TableName: params.tableName,
|
|
2857
|
-
Key:
|
|
2858
|
-
pk: params.item[this.partitionKey],
|
|
2859
|
-
...this.sortKey && { sk: params.item[this.sortKey] }
|
|
2860
|
-
}),
|
|
2923
|
+
Key: key,
|
|
2861
2924
|
ConsistentRead: true
|
|
2862
2925
|
});
|
|
2863
2926
|
return getResult.Item;
|
|
@@ -3041,7 +3104,7 @@ var Table = class {
|
|
|
3041
3104
|
try {
|
|
3042
3105
|
const result = await this.dynamoClient.delete({
|
|
3043
3106
|
TableName: params.tableName,
|
|
3044
|
-
Key:
|
|
3107
|
+
Key: params.key,
|
|
3045
3108
|
ConditionExpression: params.conditionExpression,
|
|
3046
3109
|
ExpressionAttributeNames: params.expressionAttributeNames,
|
|
3047
3110
|
ExpressionAttributeValues: params.expressionAttributeValues,
|
|
@@ -3068,7 +3131,7 @@ var Table = class {
|
|
|
3068
3131
|
try {
|
|
3069
3132
|
const result = await this.dynamoClient.update({
|
|
3070
3133
|
TableName: params.tableName,
|
|
3071
|
-
Key:
|
|
3134
|
+
Key: params.key,
|
|
3072
3135
|
UpdateExpression: params.updateExpression,
|
|
3073
3136
|
ConditionExpression: params.conditionExpression,
|
|
3074
3137
|
ExpressionAttributeNames: params.expressionAttributeNames,
|
|
@@ -3196,7 +3259,10 @@ var Table = class {
|
|
|
3196
3259
|
}
|
|
3197
3260
|
return {
|
|
3198
3261
|
DeleteRequest: {
|
|
3199
|
-
Key:
|
|
3262
|
+
Key: {
|
|
3263
|
+
[this.partitionKey]: operation.key.pk,
|
|
3264
|
+
...this.sortKey ? { [this.sortKey]: operation.key.sk } : {}
|
|
3265
|
+
}
|
|
3200
3266
|
}
|
|
3201
3267
|
};
|
|
3202
3268
|
});
|
|
@@ -3239,7 +3305,29 @@ var Table = class {
|
|
|
3239
3305
|
};
|
|
3240
3306
|
}
|
|
3241
3307
|
};
|
|
3242
|
-
|
|
3243
|
-
exports
|
|
3244
|
-
|
|
3245
|
-
|
|
3308
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
3309
|
+
0 && (module.exports = {
|
|
3310
|
+
ConditionCheckBuilder,
|
|
3311
|
+
DeleteBuilder,
|
|
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
|
+
});
|