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
|
@@ -861,6 +861,14 @@ var PutBuilder = class {
|
|
|
861
861
|
returnValues: "NONE"
|
|
862
862
|
};
|
|
863
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
|
+
}
|
|
864
872
|
/**
|
|
865
873
|
* Adds a condition that must be satisfied for the put operation to succeed.
|
|
866
874
|
* Use this method when you need to:
|
|
@@ -1105,10 +1113,6 @@ var DeleteBuilder = class {
|
|
|
1105
1113
|
}
|
|
1106
1114
|
/**
|
|
1107
1115
|
* 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
1116
|
*
|
|
1113
1117
|
* @example
|
|
1114
1118
|
* ```typescript
|
|
@@ -1160,10 +1164,6 @@ var DeleteBuilder = class {
|
|
|
1160
1164
|
}
|
|
1161
1165
|
/**
|
|
1162
1166
|
* 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
1167
|
*
|
|
1168
1168
|
* @example
|
|
1169
1169
|
* ```ts
|
|
@@ -1204,10 +1204,6 @@ var DeleteBuilder = class {
|
|
|
1204
1204
|
}
|
|
1205
1205
|
/**
|
|
1206
1206
|
* 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
1207
|
*
|
|
1212
1208
|
* @example
|
|
1213
1209
|
* ```ts
|
|
@@ -1258,11 +1254,6 @@ var DeleteBuilder = class {
|
|
|
1258
1254
|
/**
|
|
1259
1255
|
* Gets a human-readable representation of the delete command
|
|
1260
1256
|
* 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
1257
|
*
|
|
1267
1258
|
* @example
|
|
1268
1259
|
* ```ts
|
|
@@ -1321,10 +1312,6 @@ var UpdateBuilder = class {
|
|
|
1321
1312
|
}
|
|
1322
1313
|
/**
|
|
1323
1314
|
* 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
1315
|
*
|
|
1329
1316
|
* @example
|
|
1330
1317
|
* ```typescript
|
|
@@ -1351,10 +1338,6 @@ var UpdateBuilder = class {
|
|
|
1351
1338
|
}
|
|
1352
1339
|
/**
|
|
1353
1340
|
* 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
1341
|
*
|
|
1359
1342
|
* @example
|
|
1360
1343
|
* ```typescript
|
|
@@ -1383,10 +1366,6 @@ var UpdateBuilder = class {
|
|
|
1383
1366
|
}
|
|
1384
1367
|
/**
|
|
1385
1368
|
* 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
1369
|
*
|
|
1391
1370
|
* @example
|
|
1392
1371
|
* ```typescript
|
|
@@ -1396,7 +1375,7 @@ var UpdateBuilder = class {
|
|
|
1396
1375
|
* ['JUNGLE', 'COASTAL']
|
|
1397
1376
|
* );
|
|
1398
1377
|
*
|
|
1399
|
-
* // Remove from sets using Set
|
|
1378
|
+
* // Remove from sets using Set DynamoItems
|
|
1400
1379
|
* builder.deleteElementsFromSet(
|
|
1401
1380
|
* 'knownBehaviors',
|
|
1402
1381
|
* new Set(['NOCTURNAL', 'TERRITORIAL'])
|
|
@@ -1429,11 +1408,6 @@ var UpdateBuilder = class {
|
|
|
1429
1408
|
}
|
|
1430
1409
|
/**
|
|
1431
1410
|
* 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
1411
|
*
|
|
1438
1412
|
* @example
|
|
1439
1413
|
* ```typescript
|
|
@@ -1465,7 +1439,7 @@ var UpdateBuilder = class {
|
|
|
1465
1439
|
* );
|
|
1466
1440
|
* ```
|
|
1467
1441
|
*
|
|
1468
|
-
* @param condition - Either a Condition
|
|
1442
|
+
* @param condition - Either a Condition DynamoItem or a callback function that builds the condition
|
|
1469
1443
|
* @returns The builder instance for method chaining
|
|
1470
1444
|
*/
|
|
1471
1445
|
condition(condition) {
|
|
@@ -1494,11 +1468,6 @@ var UpdateBuilder = class {
|
|
|
1494
1468
|
}
|
|
1495
1469
|
/**
|
|
1496
1470
|
* 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
1471
|
*
|
|
1503
1472
|
* Available options:
|
|
1504
1473
|
* - ALL_NEW: All attributes after the update
|
|
@@ -1626,10 +1595,6 @@ var UpdateBuilder = class {
|
|
|
1626
1595
|
}
|
|
1627
1596
|
/**
|
|
1628
1597
|
* 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
1598
|
*
|
|
1634
1599
|
* @example
|
|
1635
1600
|
* ```typescript
|
|
@@ -1659,11 +1624,6 @@ var UpdateBuilder = class {
|
|
|
1659
1624
|
}
|
|
1660
1625
|
/**
|
|
1661
1626
|
* 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
1627
|
*
|
|
1668
1628
|
* @example
|
|
1669
1629
|
* ```typescript
|
|
@@ -1690,10 +1650,6 @@ var UpdateBuilder = class {
|
|
|
1690
1650
|
}
|
|
1691
1651
|
/**
|
|
1692
1652
|
* 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
1653
|
*
|
|
1698
1654
|
* @example
|
|
1699
1655
|
* ```typescript
|
|
@@ -1728,7 +1684,7 @@ var UpdateBuilder = class {
|
|
|
1728
1684
|
* }
|
|
1729
1685
|
* ```
|
|
1730
1686
|
*
|
|
1731
|
-
* @returns A promise that resolves to an
|
|
1687
|
+
* @returns A promise that resolves to an DynamoItem containing the updated item (if returnValues is set)
|
|
1732
1688
|
* @throws {ConditionalCheckFailedException} If the condition check fails
|
|
1733
1689
|
* @throws {Error} If the update operation fails for other reasons
|
|
1734
1690
|
*/
|
|
@@ -1782,7 +1738,7 @@ var TransactionBuilder = class {
|
|
|
1782
1738
|
*/
|
|
1783
1739
|
checkForDuplicateItem(tableName, newItem) {
|
|
1784
1740
|
const pkName = this.indexConfig.partitionKey;
|
|
1785
|
-
const skName = this.indexConfig.sortKey
|
|
1741
|
+
const skName = this.indexConfig.sortKey ?? "";
|
|
1786
1742
|
const pkValue = newItem[pkName];
|
|
1787
1743
|
const skValue = skName ? newItem[skName] : void 0;
|
|
1788
1744
|
if (!pkValue) {
|
|
@@ -1823,6 +1779,18 @@ var TransactionBuilder = class {
|
|
|
1823
1779
|
);
|
|
1824
1780
|
}
|
|
1825
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
|
+
}
|
|
1826
1794
|
/**
|
|
1827
1795
|
* Adds a put operation to the transaction.
|
|
1828
1796
|
* Use this method when you need to:
|
|
@@ -1962,15 +1930,13 @@ var TransactionBuilder = class {
|
|
|
1962
1930
|
* @throws {Error} If a duplicate item is detected in the transaction
|
|
1963
1931
|
*/
|
|
1964
1932
|
delete(tableName, key, condition) {
|
|
1965
|
-
this.
|
|
1933
|
+
const keyCondition = this.createKeyForPrimaryIndex(key);
|
|
1934
|
+
this.checkForDuplicateItem(tableName, keyCondition);
|
|
1966
1935
|
const transactionItem = {
|
|
1967
1936
|
type: "Delete",
|
|
1968
1937
|
params: {
|
|
1969
1938
|
tableName,
|
|
1970
|
-
key:
|
|
1971
|
-
pk: key.pk,
|
|
1972
|
-
sk: key.sk
|
|
1973
|
-
}
|
|
1939
|
+
key: keyCondition
|
|
1974
1940
|
}
|
|
1975
1941
|
};
|
|
1976
1942
|
if (condition) {
|
|
@@ -2012,10 +1978,22 @@ var TransactionBuilder = class {
|
|
|
2012
1978
|
* @see DeleteBuilder for creating delete commands
|
|
2013
1979
|
*/
|
|
2014
1980
|
deleteWithCommand(command) {
|
|
2015
|
-
|
|
1981
|
+
let keyForDuplicateCheck;
|
|
1982
|
+
let keyForTransaction;
|
|
1983
|
+
if (typeof command.key === "object" && command.key !== null && "pk" in command.key) {
|
|
1984
|
+
keyForTransaction = this.createKeyForPrimaryIndex(command.key);
|
|
1985
|
+
keyForDuplicateCheck = keyForTransaction;
|
|
1986
|
+
} else {
|
|
1987
|
+
keyForTransaction = command.key;
|
|
1988
|
+
keyForDuplicateCheck = command.key;
|
|
1989
|
+
}
|
|
1990
|
+
this.checkForDuplicateItem(command.tableName, keyForDuplicateCheck);
|
|
2016
1991
|
const transactionItem = {
|
|
2017
1992
|
type: "Delete",
|
|
2018
|
-
params:
|
|
1993
|
+
params: {
|
|
1994
|
+
...command,
|
|
1995
|
+
key: keyForTransaction
|
|
1996
|
+
}
|
|
2019
1997
|
};
|
|
2020
1998
|
this.items.push(transactionItem);
|
|
2021
1999
|
return this;
|
|
@@ -2075,15 +2053,13 @@ var TransactionBuilder = class {
|
|
|
2075
2053
|
* @throws {Error} If a duplicate item is detected in the transaction
|
|
2076
2054
|
*/
|
|
2077
2055
|
update(tableName, key, updateExpression, expressionAttributeNames, expressionAttributeValues, condition) {
|
|
2078
|
-
this.
|
|
2056
|
+
const keyCondition = this.createKeyForPrimaryIndex(key);
|
|
2057
|
+
this.checkForDuplicateItem(tableName, keyCondition);
|
|
2079
2058
|
const transactionItem = {
|
|
2080
2059
|
type: "Update",
|
|
2081
2060
|
params: {
|
|
2082
2061
|
tableName,
|
|
2083
|
-
key:
|
|
2084
|
-
pk: key.pk,
|
|
2085
|
-
sk: key.sk
|
|
2086
|
-
},
|
|
2062
|
+
key: keyCondition,
|
|
2087
2063
|
updateExpression,
|
|
2088
2064
|
expressionAttributeNames,
|
|
2089
2065
|
expressionAttributeValues
|
|
@@ -2137,10 +2113,22 @@ var TransactionBuilder = class {
|
|
|
2137
2113
|
* @see UpdateBuilder for creating update commands
|
|
2138
2114
|
*/
|
|
2139
2115
|
updateWithCommand(command) {
|
|
2140
|
-
|
|
2116
|
+
let keyForDuplicateCheck;
|
|
2117
|
+
let keyForTransaction;
|
|
2118
|
+
if (typeof command.key === "object" && command.key !== null && "pk" in command.key) {
|
|
2119
|
+
keyForTransaction = this.createKeyForPrimaryIndex(command.key);
|
|
2120
|
+
keyForDuplicateCheck = keyForTransaction;
|
|
2121
|
+
} else {
|
|
2122
|
+
keyForTransaction = command.key;
|
|
2123
|
+
keyForDuplicateCheck = command.key;
|
|
2124
|
+
}
|
|
2125
|
+
this.checkForDuplicateItem(command.tableName, keyForDuplicateCheck);
|
|
2141
2126
|
const transactionItem = {
|
|
2142
2127
|
type: "Update",
|
|
2143
|
-
params:
|
|
2128
|
+
params: {
|
|
2129
|
+
...command,
|
|
2130
|
+
key: keyForTransaction
|
|
2131
|
+
}
|
|
2144
2132
|
};
|
|
2145
2133
|
this.items.push(transactionItem);
|
|
2146
2134
|
return this;
|
|
@@ -2197,7 +2185,8 @@ var TransactionBuilder = class {
|
|
|
2197
2185
|
* @throws {Error} If condition expression generation fails
|
|
2198
2186
|
*/
|
|
2199
2187
|
conditionCheck(tableName, key, condition) {
|
|
2200
|
-
this.
|
|
2188
|
+
const keyCondition = this.createKeyForPrimaryIndex(key);
|
|
2189
|
+
this.checkForDuplicateItem(tableName, keyCondition);
|
|
2201
2190
|
const { expression, names, values } = prepareExpressionParams(condition);
|
|
2202
2191
|
if (!expression) {
|
|
2203
2192
|
throw new Error("Failed to generate condition expression");
|
|
@@ -2206,10 +2195,7 @@ var TransactionBuilder = class {
|
|
|
2206
2195
|
type: "ConditionCheck",
|
|
2207
2196
|
params: {
|
|
2208
2197
|
tableName,
|
|
2209
|
-
key:
|
|
2210
|
-
pk: key.pk,
|
|
2211
|
-
sk: key.sk
|
|
2212
|
-
},
|
|
2198
|
+
key: keyCondition,
|
|
2213
2199
|
conditionExpression: expression,
|
|
2214
2200
|
expressionAttributeNames: names,
|
|
2215
2201
|
expressionAttributeValues: values
|
|
@@ -2249,10 +2235,22 @@ var TransactionBuilder = class {
|
|
|
2249
2235
|
* @see ConditionCheckBuilder for creating condition check commands
|
|
2250
2236
|
*/
|
|
2251
2237
|
conditionCheckWithCommand(command) {
|
|
2252
|
-
|
|
2238
|
+
let keyForDuplicateCheck;
|
|
2239
|
+
let keyForTransaction;
|
|
2240
|
+
if (typeof command.key === "object" && command.key !== null && "pk" in command.key) {
|
|
2241
|
+
keyForTransaction = this.createKeyForPrimaryIndex(command.key);
|
|
2242
|
+
keyForDuplicateCheck = keyForTransaction;
|
|
2243
|
+
} else {
|
|
2244
|
+
keyForTransaction = command.key;
|
|
2245
|
+
keyForDuplicateCheck = command.key;
|
|
2246
|
+
}
|
|
2247
|
+
this.checkForDuplicateItem(command.tableName, keyForDuplicateCheck);
|
|
2253
2248
|
const transactionItem = {
|
|
2254
2249
|
type: "ConditionCheck",
|
|
2255
|
-
params:
|
|
2250
|
+
params: {
|
|
2251
|
+
...command,
|
|
2252
|
+
key: keyForTransaction
|
|
2253
|
+
}
|
|
2256
2254
|
};
|
|
2257
2255
|
this.items.push(transactionItem);
|
|
2258
2256
|
return this;
|
|
@@ -2485,7 +2483,7 @@ var ConditionCheckBuilder = class {
|
|
|
2485
2483
|
* );
|
|
2486
2484
|
* ```
|
|
2487
2485
|
*
|
|
2488
|
-
* @param condition - Either a Condition
|
|
2486
|
+
* @param condition - Either a Condition DynamoItem or a callback function that builds the condition
|
|
2489
2487
|
* @returns The builder instance for method chaining
|
|
2490
2488
|
*/
|
|
2491
2489
|
condition(condition) {
|
|
@@ -2711,18 +2709,15 @@ var GetBuilder = class {
|
|
|
2711
2709
|
* - item: The retrieved dinosaur or undefined if not found
|
|
2712
2710
|
*/
|
|
2713
2711
|
async execute() {
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
this.params.expressionAttributeNames = expressionAttributeNames;
|
|
2724
|
-
}
|
|
2725
|
-
return this.executor(this.params);
|
|
2712
|
+
const expressionParams = {
|
|
2713
|
+
expressionAttributeNames: {}};
|
|
2714
|
+
const projectionExpression = Array.from(this.selectedFields).map((p) => generateAttributeName(expressionParams, p)).join(", ");
|
|
2715
|
+
const { expressionAttributeNames } = expressionParams;
|
|
2716
|
+
return this.executor({
|
|
2717
|
+
...this.params,
|
|
2718
|
+
projectionExpression: projectionExpression.length > 0 ? projectionExpression : void 0,
|
|
2719
|
+
expressionAttributeNames: Object.keys(expressionAttributeNames).length > 0 ? expressionAttributeNames : void 0
|
|
2720
|
+
});
|
|
2726
2721
|
}
|
|
2727
2722
|
};
|
|
2728
2723
|
|
|
@@ -2817,6 +2812,16 @@ var Table = class {
|
|
|
2817
2812
|
this.sortKey = config.indexes.sortKey;
|
|
2818
2813
|
this.gsis = config.indexes.gsis || {};
|
|
2819
2814
|
}
|
|
2815
|
+
createKeyForPrimaryIndex(keyCondition) {
|
|
2816
|
+
const primaryCondition = { [this.partitionKey]: keyCondition.pk };
|
|
2817
|
+
if (this.sortKey) {
|
|
2818
|
+
if (!keyCondition.sk) {
|
|
2819
|
+
throw new Error("Sort key has not been provided but the Table has a sort key");
|
|
2820
|
+
}
|
|
2821
|
+
primaryCondition[this.sortKey] = keyCondition.sk;
|
|
2822
|
+
}
|
|
2823
|
+
return primaryCondition;
|
|
2824
|
+
}
|
|
2820
2825
|
/**
|
|
2821
2826
|
* Creates a new item in the table, it will fail if the item already exists
|
|
2822
2827
|
*
|
|
@@ -2831,7 +2836,7 @@ var Table = class {
|
|
|
2831
2836
|
try {
|
|
2832
2837
|
const result = await this.dynamoClient.get({
|
|
2833
2838
|
TableName: params.tableName,
|
|
2834
|
-
Key:
|
|
2839
|
+
Key: this.createKeyForPrimaryIndex(keyCondition),
|
|
2835
2840
|
ProjectionExpression: params.projectionExpression,
|
|
2836
2841
|
ExpressionAttributeNames: params.expressionAttributeNames,
|
|
2837
2842
|
ConsistentRead: params.consistentRead
|
|
@@ -2866,13 +2871,12 @@ var Table = class {
|
|
|
2866
2871
|
ReturnValues: params.returnValues === "CONSISTENT" ? "NONE" : params.returnValues
|
|
2867
2872
|
});
|
|
2868
2873
|
if (params.returnValues === "CONSISTENT") {
|
|
2869
|
-
const key = {
|
|
2870
|
-
pk: params.item[this.partitionKey],
|
|
2871
|
-
...this.sortKey && { sk: params.item[this.sortKey] }
|
|
2872
|
-
};
|
|
2873
2874
|
const getResult = await this.dynamoClient.get({
|
|
2874
2875
|
TableName: params.tableName,
|
|
2875
|
-
Key:
|
|
2876
|
+
Key: this.createKeyForPrimaryIndex({
|
|
2877
|
+
pk: params.item[this.partitionKey],
|
|
2878
|
+
...this.sortKey && { sk: params.item[this.sortKey] }
|
|
2879
|
+
}),
|
|
2876
2880
|
ConsistentRead: true
|
|
2877
2881
|
});
|
|
2878
2882
|
return getResult.Item;
|
|
@@ -3056,7 +3060,7 @@ var Table = class {
|
|
|
3056
3060
|
try {
|
|
3057
3061
|
const result = await this.dynamoClient.delete({
|
|
3058
3062
|
TableName: params.tableName,
|
|
3059
|
-
Key:
|
|
3063
|
+
Key: this.createKeyForPrimaryIndex(keyCondition),
|
|
3060
3064
|
ConditionExpression: params.conditionExpression,
|
|
3061
3065
|
ExpressionAttributeNames: params.expressionAttributeNames,
|
|
3062
3066
|
ExpressionAttributeValues: params.expressionAttributeValues,
|
|
@@ -3083,7 +3087,7 @@ var Table = class {
|
|
|
3083
3087
|
try {
|
|
3084
3088
|
const result = await this.dynamoClient.update({
|
|
3085
3089
|
TableName: params.tableName,
|
|
3086
|
-
Key:
|
|
3090
|
+
Key: this.createKeyForPrimaryIndex(keyCondition),
|
|
3087
3091
|
UpdateExpression: params.updateExpression,
|
|
3088
3092
|
ConditionExpression: params.conditionExpression,
|
|
3089
3093
|
ExpressionAttributeNames: params.expressionAttributeNames,
|
|
@@ -3211,10 +3215,7 @@ var Table = class {
|
|
|
3211
3215
|
}
|
|
3212
3216
|
return {
|
|
3213
3217
|
DeleteRequest: {
|
|
3214
|
-
Key:
|
|
3215
|
-
[this.partitionKey]: operation.key.pk,
|
|
3216
|
-
...this.sortKey ? { [this.sortKey]: operation.key.sk } : {}
|
|
3217
|
-
}
|
|
3218
|
+
Key: this.createKeyForPrimaryIndex(operation.key)
|
|
3218
3219
|
}
|
|
3219
3220
|
};
|
|
3220
3221
|
});
|
|
@@ -3257,28 +3258,7 @@ var Table = class {
|
|
|
3257
3258
|
};
|
|
3258
3259
|
}
|
|
3259
3260
|
};
|
|
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
|
-
};
|
|
3261
|
+
|
|
3262
|
+
export { Table };
|
|
3263
|
+
//# sourceMappingURL=table.js.map
|
|
3264
|
+
//# sourceMappingURL=table.js.map
|