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,3 +1,5 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
1
3
|
// src/conditions.ts
|
|
2
4
|
var createComparisonCondition = (type) => (attr, value) => ({
|
|
3
5
|
type,
|
|
@@ -861,6 +863,14 @@ var PutBuilder = class {
|
|
|
861
863
|
returnValues: "NONE"
|
|
862
864
|
};
|
|
863
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
|
+
}
|
|
864
874
|
/**
|
|
865
875
|
* Adds a condition that must be satisfied for the put operation to succeed.
|
|
866
876
|
* Use this method when you need to:
|
|
@@ -1105,10 +1115,6 @@ var DeleteBuilder = class {
|
|
|
1105
1115
|
}
|
|
1106
1116
|
/**
|
|
1107
1117
|
* Adds a condition that must be satisfied for the delete operation to succeed.
|
|
1108
|
-
* Use this method when you need to:
|
|
1109
|
-
* - Ensure safe removal conditions
|
|
1110
|
-
* - Verify habitat status before deletion
|
|
1111
|
-
* - Implement safety protocols
|
|
1112
1118
|
*
|
|
1113
1119
|
* @example
|
|
1114
1120
|
* ```typescript
|
|
@@ -1160,10 +1166,6 @@ var DeleteBuilder = class {
|
|
|
1160
1166
|
}
|
|
1161
1167
|
/**
|
|
1162
1168
|
* Sets whether to return the item's attribute values before deletion.
|
|
1163
|
-
* Use this method when you need to:
|
|
1164
|
-
* - Archive removed dinosaur data
|
|
1165
|
-
* - Track habitat decommissioning history
|
|
1166
|
-
* - Maintain removal audit logs
|
|
1167
1169
|
*
|
|
1168
1170
|
* @example
|
|
1169
1171
|
* ```ts
|
|
@@ -1204,10 +1206,6 @@ var DeleteBuilder = class {
|
|
|
1204
1206
|
}
|
|
1205
1207
|
/**
|
|
1206
1208
|
* Adds this delete operation to a transaction.
|
|
1207
|
-
* Use this method when you need to:
|
|
1208
|
-
* - Coordinate dinosaur transfers
|
|
1209
|
-
* - Manage habitat decommissioning
|
|
1210
|
-
* - Handle species relocations
|
|
1211
1209
|
*
|
|
1212
1210
|
* @example
|
|
1213
1211
|
* ```ts
|
|
@@ -1258,11 +1256,6 @@ var DeleteBuilder = class {
|
|
|
1258
1256
|
/**
|
|
1259
1257
|
* Gets a human-readable representation of the delete command
|
|
1260
1258
|
* with all expression placeholders replaced by their actual values.
|
|
1261
|
-
* Use this method when you need to:
|
|
1262
|
-
* - Debug complex deletion conditions
|
|
1263
|
-
* - Verify safety checks
|
|
1264
|
-
* - Log removal operations
|
|
1265
|
-
* - Troubleshoot failed deletions
|
|
1266
1259
|
*
|
|
1267
1260
|
* @example
|
|
1268
1261
|
* ```ts
|
|
@@ -1321,10 +1314,6 @@ var UpdateBuilder = class {
|
|
|
1321
1314
|
}
|
|
1322
1315
|
/**
|
|
1323
1316
|
* Removes an attribute from the item.
|
|
1324
|
-
* Use this method when you need to:
|
|
1325
|
-
* - Delete attributes completely
|
|
1326
|
-
* - Remove nested attributes
|
|
1327
|
-
* - Clean up deprecated fields
|
|
1328
1317
|
*
|
|
1329
1318
|
* @example
|
|
1330
1319
|
* ```typescript
|
|
@@ -1351,10 +1340,6 @@ var UpdateBuilder = class {
|
|
|
1351
1340
|
}
|
|
1352
1341
|
/**
|
|
1353
1342
|
* Adds a value to a number attribute or adds elements to a set.
|
|
1354
|
-
* Use this method when you need to:
|
|
1355
|
-
* - Increment counters
|
|
1356
|
-
* - Add elements to a set atomically
|
|
1357
|
-
* - Update numerical statistics
|
|
1358
1343
|
*
|
|
1359
1344
|
* @example
|
|
1360
1345
|
* ```typescript
|
|
@@ -1383,10 +1368,6 @@ var UpdateBuilder = class {
|
|
|
1383
1368
|
}
|
|
1384
1369
|
/**
|
|
1385
1370
|
* Removes elements from a set attribute.
|
|
1386
|
-
* Use this method when you need to:
|
|
1387
|
-
* - Remove specific elements from a set
|
|
1388
|
-
* - Update set-based attributes atomically
|
|
1389
|
-
* - Maintain set membership
|
|
1390
1371
|
*
|
|
1391
1372
|
* @example
|
|
1392
1373
|
* ```typescript
|
|
@@ -1396,7 +1377,7 @@ var UpdateBuilder = class {
|
|
|
1396
1377
|
* ['JUNGLE', 'COASTAL']
|
|
1397
1378
|
* );
|
|
1398
1379
|
*
|
|
1399
|
-
* // Remove from sets using Set
|
|
1380
|
+
* // Remove from sets using Set DynamoItems
|
|
1400
1381
|
* builder.deleteElementsFromSet(
|
|
1401
1382
|
* 'knownBehaviors',
|
|
1402
1383
|
* new Set(['NOCTURNAL', 'TERRITORIAL'])
|
|
@@ -1429,11 +1410,6 @@ var UpdateBuilder = class {
|
|
|
1429
1410
|
}
|
|
1430
1411
|
/**
|
|
1431
1412
|
* Adds a condition that must be satisfied for the update to succeed.
|
|
1432
|
-
* Use this method when you need to:
|
|
1433
|
-
* - Implement optimistic locking
|
|
1434
|
-
* - Ensure item state before update
|
|
1435
|
-
* - Validate business rules
|
|
1436
|
-
* - Prevent concurrent modifications
|
|
1437
1413
|
*
|
|
1438
1414
|
* @example
|
|
1439
1415
|
* ```typescript
|
|
@@ -1465,7 +1441,7 @@ var UpdateBuilder = class {
|
|
|
1465
1441
|
* );
|
|
1466
1442
|
* ```
|
|
1467
1443
|
*
|
|
1468
|
-
* @param condition - Either a Condition
|
|
1444
|
+
* @param condition - Either a Condition DynamoItem or a callback function that builds the condition
|
|
1469
1445
|
* @returns The builder instance for method chaining
|
|
1470
1446
|
*/
|
|
1471
1447
|
condition(condition) {
|
|
@@ -1494,11 +1470,6 @@ var UpdateBuilder = class {
|
|
|
1494
1470
|
}
|
|
1495
1471
|
/**
|
|
1496
1472
|
* Sets which item attributes to include in the response.
|
|
1497
|
-
* Use this method when you need to:
|
|
1498
|
-
* - Get the complete updated item
|
|
1499
|
-
* - Track changes to specific attributes
|
|
1500
|
-
* - Compare old and new values
|
|
1501
|
-
* - Monitor attribute modifications
|
|
1502
1473
|
*
|
|
1503
1474
|
* Available options:
|
|
1504
1475
|
* - ALL_NEW: All attributes after the update
|
|
@@ -1626,10 +1597,6 @@ var UpdateBuilder = class {
|
|
|
1626
1597
|
}
|
|
1627
1598
|
/**
|
|
1628
1599
|
* Adds this update operation to a transaction.
|
|
1629
|
-
* Use this method when you need to:
|
|
1630
|
-
* - Update items as part of a larger transaction
|
|
1631
|
-
* - Ensure multiple updates are atomic
|
|
1632
|
-
* - Coordinate updates across multiple items
|
|
1633
1600
|
*
|
|
1634
1601
|
* @example
|
|
1635
1602
|
* ```typescript
|
|
@@ -1659,11 +1626,6 @@ var UpdateBuilder = class {
|
|
|
1659
1626
|
}
|
|
1660
1627
|
/**
|
|
1661
1628
|
* Gets a human-readable representation of the update command.
|
|
1662
|
-
* Use this method when you need to:
|
|
1663
|
-
* - Debug complex update expressions
|
|
1664
|
-
* - Verify attribute names and values
|
|
1665
|
-
* - Log update operations
|
|
1666
|
-
* - Troubleshoot condition expressions
|
|
1667
1629
|
*
|
|
1668
1630
|
* @example
|
|
1669
1631
|
* ```typescript
|
|
@@ -1690,10 +1652,6 @@ var UpdateBuilder = class {
|
|
|
1690
1652
|
}
|
|
1691
1653
|
/**
|
|
1692
1654
|
* Executes the update operation against DynamoDB.
|
|
1693
|
-
* Use this method when you need to:
|
|
1694
|
-
* - Apply updates immediately
|
|
1695
|
-
* - Get the updated item values
|
|
1696
|
-
* - Handle conditional update failures
|
|
1697
1655
|
*
|
|
1698
1656
|
* @example
|
|
1699
1657
|
* ```typescript
|
|
@@ -1728,7 +1686,7 @@ var UpdateBuilder = class {
|
|
|
1728
1686
|
* }
|
|
1729
1687
|
* ```
|
|
1730
1688
|
*
|
|
1731
|
-
* @returns A promise that resolves to an
|
|
1689
|
+
* @returns A promise that resolves to an DynamoItem containing the updated item (if returnValues is set)
|
|
1732
1690
|
* @throws {ConditionalCheckFailedException} If the condition check fails
|
|
1733
1691
|
* @throws {Error} If the update operation fails for other reasons
|
|
1734
1692
|
*/
|
|
@@ -1782,7 +1740,7 @@ var TransactionBuilder = class {
|
|
|
1782
1740
|
*/
|
|
1783
1741
|
checkForDuplicateItem(tableName, newItem) {
|
|
1784
1742
|
const pkName = this.indexConfig.partitionKey;
|
|
1785
|
-
const skName = this.indexConfig.sortKey
|
|
1743
|
+
const skName = this.indexConfig.sortKey ?? "";
|
|
1786
1744
|
const pkValue = newItem[pkName];
|
|
1787
1745
|
const skValue = skName ? newItem[skName] : void 0;
|
|
1788
1746
|
if (!pkValue) {
|
|
@@ -1823,6 +1781,18 @@ var TransactionBuilder = class {
|
|
|
1823
1781
|
);
|
|
1824
1782
|
}
|
|
1825
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
|
+
}
|
|
1826
1796
|
/**
|
|
1827
1797
|
* Adds a put operation to the transaction.
|
|
1828
1798
|
* Use this method when you need to:
|
|
@@ -1962,15 +1932,13 @@ var TransactionBuilder = class {
|
|
|
1962
1932
|
* @throws {Error} If a duplicate item is detected in the transaction
|
|
1963
1933
|
*/
|
|
1964
1934
|
delete(tableName, key, condition) {
|
|
1965
|
-
this.
|
|
1935
|
+
const keyCondition = this.createKeyForPrimaryIndex(key);
|
|
1936
|
+
this.checkForDuplicateItem(tableName, keyCondition);
|
|
1966
1937
|
const transactionItem = {
|
|
1967
1938
|
type: "Delete",
|
|
1968
1939
|
params: {
|
|
1969
1940
|
tableName,
|
|
1970
|
-
key:
|
|
1971
|
-
pk: key.pk,
|
|
1972
|
-
sk: key.sk
|
|
1973
|
-
}
|
|
1941
|
+
key: keyCondition
|
|
1974
1942
|
}
|
|
1975
1943
|
};
|
|
1976
1944
|
if (condition) {
|
|
@@ -2012,10 +1980,14 @@ var TransactionBuilder = class {
|
|
|
2012
1980
|
* @see DeleteBuilder for creating delete commands
|
|
2013
1981
|
*/
|
|
2014
1982
|
deleteWithCommand(command) {
|
|
2015
|
-
this.
|
|
1983
|
+
const keyCondition = this.createKeyForPrimaryIndex(command.key);
|
|
1984
|
+
this.checkForDuplicateItem(command.tableName, keyCondition);
|
|
2016
1985
|
const transactionItem = {
|
|
2017
1986
|
type: "Delete",
|
|
2018
|
-
params:
|
|
1987
|
+
params: {
|
|
1988
|
+
...command,
|
|
1989
|
+
key: keyCondition
|
|
1990
|
+
}
|
|
2019
1991
|
};
|
|
2020
1992
|
this.items.push(transactionItem);
|
|
2021
1993
|
return this;
|
|
@@ -2075,15 +2047,13 @@ var TransactionBuilder = class {
|
|
|
2075
2047
|
* @throws {Error} If a duplicate item is detected in the transaction
|
|
2076
2048
|
*/
|
|
2077
2049
|
update(tableName, key, updateExpression, expressionAttributeNames, expressionAttributeValues, condition) {
|
|
2078
|
-
this.
|
|
2050
|
+
const keyCondition = this.createKeyForPrimaryIndex(key);
|
|
2051
|
+
this.checkForDuplicateItem(tableName, keyCondition);
|
|
2079
2052
|
const transactionItem = {
|
|
2080
2053
|
type: "Update",
|
|
2081
2054
|
params: {
|
|
2082
2055
|
tableName,
|
|
2083
|
-
key:
|
|
2084
|
-
pk: key.pk,
|
|
2085
|
-
sk: key.sk
|
|
2086
|
-
},
|
|
2056
|
+
key: keyCondition,
|
|
2087
2057
|
updateExpression,
|
|
2088
2058
|
expressionAttributeNames,
|
|
2089
2059
|
expressionAttributeValues
|
|
@@ -2137,10 +2107,14 @@ var TransactionBuilder = class {
|
|
|
2137
2107
|
* @see UpdateBuilder for creating update commands
|
|
2138
2108
|
*/
|
|
2139
2109
|
updateWithCommand(command) {
|
|
2140
|
-
this.
|
|
2110
|
+
const keyCondition = this.createKeyForPrimaryIndex(command.key);
|
|
2111
|
+
this.checkForDuplicateItem(command.tableName, keyCondition);
|
|
2141
2112
|
const transactionItem = {
|
|
2142
2113
|
type: "Update",
|
|
2143
|
-
params:
|
|
2114
|
+
params: {
|
|
2115
|
+
...command,
|
|
2116
|
+
key: keyCondition
|
|
2117
|
+
}
|
|
2144
2118
|
};
|
|
2145
2119
|
this.items.push(transactionItem);
|
|
2146
2120
|
return this;
|
|
@@ -2197,7 +2171,8 @@ var TransactionBuilder = class {
|
|
|
2197
2171
|
* @throws {Error} If condition expression generation fails
|
|
2198
2172
|
*/
|
|
2199
2173
|
conditionCheck(tableName, key, condition) {
|
|
2200
|
-
this.
|
|
2174
|
+
const keyCondition = this.createKeyForPrimaryIndex(key);
|
|
2175
|
+
this.checkForDuplicateItem(tableName, keyCondition);
|
|
2201
2176
|
const { expression, names, values } = prepareExpressionParams(condition);
|
|
2202
2177
|
if (!expression) {
|
|
2203
2178
|
throw new Error("Failed to generate condition expression");
|
|
@@ -2206,10 +2181,7 @@ var TransactionBuilder = class {
|
|
|
2206
2181
|
type: "ConditionCheck",
|
|
2207
2182
|
params: {
|
|
2208
2183
|
tableName,
|
|
2209
|
-
key:
|
|
2210
|
-
pk: key.pk,
|
|
2211
|
-
sk: key.sk
|
|
2212
|
-
},
|
|
2184
|
+
key: keyCondition,
|
|
2213
2185
|
conditionExpression: expression,
|
|
2214
2186
|
expressionAttributeNames: names,
|
|
2215
2187
|
expressionAttributeValues: values
|
|
@@ -2249,10 +2221,14 @@ var TransactionBuilder = class {
|
|
|
2249
2221
|
* @see ConditionCheckBuilder for creating condition check commands
|
|
2250
2222
|
*/
|
|
2251
2223
|
conditionCheckWithCommand(command) {
|
|
2252
|
-
this.
|
|
2224
|
+
const keyCondition = this.createKeyForPrimaryIndex(command.key);
|
|
2225
|
+
this.checkForDuplicateItem(command.tableName, keyCondition);
|
|
2253
2226
|
const transactionItem = {
|
|
2254
2227
|
type: "ConditionCheck",
|
|
2255
|
-
params:
|
|
2228
|
+
params: {
|
|
2229
|
+
...command,
|
|
2230
|
+
key: keyCondition
|
|
2231
|
+
}
|
|
2256
2232
|
};
|
|
2257
2233
|
this.items.push(transactionItem);
|
|
2258
2234
|
return this;
|
|
@@ -2485,7 +2461,7 @@ var ConditionCheckBuilder = class {
|
|
|
2485
2461
|
* );
|
|
2486
2462
|
* ```
|
|
2487
2463
|
*
|
|
2488
|
-
* @param condition - Either a Condition
|
|
2464
|
+
* @param condition - Either a Condition DynamoItem or a callback function that builds the condition
|
|
2489
2465
|
* @returns The builder instance for method chaining
|
|
2490
2466
|
*/
|
|
2491
2467
|
condition(condition) {
|
|
@@ -2711,18 +2687,18 @@ var GetBuilder = class {
|
|
|
2711
2687
|
* - item: The retrieved dinosaur or undefined if not found
|
|
2712
2688
|
*/
|
|
2713
2689
|
async execute() {
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
this.params
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
|
|
2690
|
+
const expressionParams = {
|
|
2691
|
+
expressionAttributeNames: {},
|
|
2692
|
+
expressionAttributeValues: {},
|
|
2693
|
+
valueCounter: { count: 0 }
|
|
2694
|
+
};
|
|
2695
|
+
const projectionExpression = Array.from(this.selectedFields).map((p) => generateAttributeName(expressionParams, p)).join(", ");
|
|
2696
|
+
const { expressionAttributeNames } = expressionParams;
|
|
2697
|
+
return this.executor({
|
|
2698
|
+
...this.params,
|
|
2699
|
+
projectionExpression: projectionExpression.length > 0 ? projectionExpression : void 0,
|
|
2700
|
+
expressionAttributeNames: Object.keys(expressionAttributeNames).length > 0 ? expressionAttributeNames : void 0
|
|
2701
|
+
});
|
|
2726
2702
|
}
|
|
2727
2703
|
};
|
|
2728
2704
|
|
|
@@ -2817,6 +2793,16 @@ var Table = class {
|
|
|
2817
2793
|
this.sortKey = config.indexes.sortKey;
|
|
2818
2794
|
this.gsis = config.indexes.gsis || {};
|
|
2819
2795
|
}
|
|
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
|
+
}
|
|
2820
2806
|
/**
|
|
2821
2807
|
* Creates a new item in the table, it will fail if the item already exists
|
|
2822
2808
|
*
|
|
@@ -2831,7 +2817,7 @@ var Table = class {
|
|
|
2831
2817
|
try {
|
|
2832
2818
|
const result = await this.dynamoClient.get({
|
|
2833
2819
|
TableName: params.tableName,
|
|
2834
|
-
Key:
|
|
2820
|
+
Key: this.createKeyForPrimaryIndex(keyCondition),
|
|
2835
2821
|
ProjectionExpression: params.projectionExpression,
|
|
2836
2822
|
ExpressionAttributeNames: params.expressionAttributeNames,
|
|
2837
2823
|
ConsistentRead: params.consistentRead
|
|
@@ -2866,13 +2852,12 @@ var Table = class {
|
|
|
2866
2852
|
ReturnValues: params.returnValues === "CONSISTENT" ? "NONE" : params.returnValues
|
|
2867
2853
|
});
|
|
2868
2854
|
if (params.returnValues === "CONSISTENT") {
|
|
2869
|
-
const key = {
|
|
2870
|
-
pk: params.item[this.partitionKey],
|
|
2871
|
-
...this.sortKey && { sk: params.item[this.sortKey] }
|
|
2872
|
-
};
|
|
2873
2855
|
const getResult = await this.dynamoClient.get({
|
|
2874
2856
|
TableName: params.tableName,
|
|
2875
|
-
Key:
|
|
2857
|
+
Key: this.createKeyForPrimaryIndex({
|
|
2858
|
+
pk: params.item[this.partitionKey],
|
|
2859
|
+
...this.sortKey && { sk: params.item[this.sortKey] }
|
|
2860
|
+
}),
|
|
2876
2861
|
ConsistentRead: true
|
|
2877
2862
|
});
|
|
2878
2863
|
return getResult.Item;
|
|
@@ -3056,7 +3041,7 @@ var Table = class {
|
|
|
3056
3041
|
try {
|
|
3057
3042
|
const result = await this.dynamoClient.delete({
|
|
3058
3043
|
TableName: params.tableName,
|
|
3059
|
-
Key:
|
|
3044
|
+
Key: this.createKeyForPrimaryIndex(keyCondition),
|
|
3060
3045
|
ConditionExpression: params.conditionExpression,
|
|
3061
3046
|
ExpressionAttributeNames: params.expressionAttributeNames,
|
|
3062
3047
|
ExpressionAttributeValues: params.expressionAttributeValues,
|
|
@@ -3083,7 +3068,7 @@ var Table = class {
|
|
|
3083
3068
|
try {
|
|
3084
3069
|
const result = await this.dynamoClient.update({
|
|
3085
3070
|
TableName: params.tableName,
|
|
3086
|
-
Key:
|
|
3071
|
+
Key: this.createKeyForPrimaryIndex(keyCondition),
|
|
3087
3072
|
UpdateExpression: params.updateExpression,
|
|
3088
3073
|
ConditionExpression: params.conditionExpression,
|
|
3089
3074
|
ExpressionAttributeNames: params.expressionAttributeNames,
|
|
@@ -3211,10 +3196,7 @@ var Table = class {
|
|
|
3211
3196
|
}
|
|
3212
3197
|
return {
|
|
3213
3198
|
DeleteRequest: {
|
|
3214
|
-
Key:
|
|
3215
|
-
[this.partitionKey]: operation.key.pk,
|
|
3216
|
-
...this.sortKey ? { [this.sortKey]: operation.key.sk } : {}
|
|
3217
|
-
}
|
|
3199
|
+
Key: this.createKeyForPrimaryIndex(operation.key)
|
|
3218
3200
|
}
|
|
3219
3201
|
};
|
|
3220
3202
|
});
|
|
@@ -3257,28 +3239,7 @@ var Table = class {
|
|
|
3257
3239
|
};
|
|
3258
3240
|
}
|
|
3259
3241
|
};
|
|
3260
|
-
|
|
3261
|
-
|
|
3262
|
-
|
|
3263
|
-
|
|
3264
|
-
PutBuilder,
|
|
3265
|
-
QueryBuilder,
|
|
3266
|
-
Table,
|
|
3267
|
-
TransactionBuilder,
|
|
3268
|
-
UpdateBuilder,
|
|
3269
|
-
and,
|
|
3270
|
-
attributeExists,
|
|
3271
|
-
attributeNotExists,
|
|
3272
|
-
beginsWith,
|
|
3273
|
-
between,
|
|
3274
|
-
contains,
|
|
3275
|
-
createComparisonCondition,
|
|
3276
|
-
eq,
|
|
3277
|
-
gt,
|
|
3278
|
-
gte,
|
|
3279
|
-
lt,
|
|
3280
|
-
lte,
|
|
3281
|
-
ne,
|
|
3282
|
-
not,
|
|
3283
|
-
or
|
|
3284
|
-
};
|
|
3242
|
+
|
|
3243
|
+
exports.Table = Table;
|
|
3244
|
+
//# sourceMappingURL=table.cjs.map
|
|
3245
|
+
//# sourceMappingURL=table.cjs.map
|