dyno-table 0.1.8 → 0.2.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 +570 -147
- 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 +1 -1
- package/dist/builders/condition-check-builder.cjs.map +1 -1
- 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 +1 -1
- package/dist/builders/condition-check-builder.js.map +1 -1
- package/dist/builders/delete-builder.cjs +0 -17
- package/dist/builders/delete-builder.cjs.map +1 -1
- package/dist/builders/delete-builder.d.cts +166 -0
- package/dist/builders/delete-builder.d.ts +166 -0
- package/dist/builders/delete-builder.js +0 -17
- package/dist/builders/delete-builder.js.map +1 -1
- package/dist/builders/paginator.cjs.map +1 -1
- package/dist/builders/paginator.d.cts +179 -0
- package/dist/builders/paginator.d.ts +179 -0
- package/dist/builders/paginator.js.map +1 -1
- package/dist/builders/put-builder.cjs +8 -0
- package/dist/builders/put-builder.cjs.map +1 -1
- package/dist/builders/put-builder.d.cts +274 -0
- package/dist/builders/put-builder.d.ts +274 -0
- package/dist/builders/put-builder.js +8 -0
- package/dist/builders/put-builder.js.map +1 -1
- package/dist/builders/query-builder.cjs.map +1 -1
- package/dist/builders/query-builder.d.cts +6 -0
- package/dist/builders/query-builder.d.ts +6 -0
- package/dist/builders/query-builder.js.map +1 -1
- package/dist/builders/transaction-builder.cjs +40 -22
- package/dist/builders/transaction-builder.cjs.map +1 -1
- package/dist/builders/transaction-builder.d.cts +511 -0
- package/dist/builders/transaction-builder.d.ts +511 -0
- package/dist/builders/transaction-builder.js +40 -22
- package/dist/builders/transaction-builder.js.map +1 -1
- package/dist/builders/update-builder.cjs +3 -38
- package/dist/builders/update-builder.cjs.map +1 -1
- package/dist/builders/update-builder.d.cts +365 -0
- package/dist/builders/update-builder.d.ts +365 -0
- package/dist/builders/update-builder.js +3 -38
- package/dist/builders/update-builder.js.map +1 -1
- package/dist/conditions--ld9a78i.d.ts +331 -0
- package/dist/conditions-ChhQWd6z.d.cts +331 -0
- package/dist/conditions.cjs.map +1 -1
- package/dist/conditions.d.cts +3 -0
- package/dist/conditions.d.ts +3 -0
- package/dist/conditions.js.map +1 -1
- package/dist/entity.cjs +156 -97
- package/dist/entity.cjs.map +1 -1
- package/dist/entity.d.cts +149 -0
- package/dist/entity.d.ts +149 -0
- package/dist/entity.js +156 -97
- package/dist/entity.js.map +1 -1
- package/dist/query-builder-Csror9Iu.d.ts +507 -0
- package/dist/query-builder-D2FM9rsu.d.cts +507 -0
- package/dist/standard-schema.d.cts +57 -0
- package/dist/standard-schema.d.ts +57 -0
- package/dist/table-BEhBPy2G.d.cts +364 -0
- package/dist/table-BW3cmUqr.d.ts +364 -0
- package/dist/table.cjs +82 -102
- package/dist/table.cjs.map +1 -1
- package/dist/table.d.cts +12 -0
- package/dist/table.d.ts +12 -0
- package/dist/table.js +82 -102
- package/dist/table.js.map +1 -1
- package/dist/types.d.cts +22 -0
- package/dist/types.d.ts +22 -0
- package/dist/utils/{key-template.cjs → partition-key-template.cjs} +3 -3
- 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/{key-template.js → partition-key-template.js} +3 -3
- package/dist/utils/partition-key-template.js.map +1 -0
- package/dist/utils/sort-key-template.d.cts +35 -0
- package/dist/utils/sort-key-template.d.ts +35 -0
- package/package.json +86 -9
- package/dist/index.cjs +0 -3333
- package/dist/index.d.cts +0 -2971
- package/dist/index.d.ts +0 -2971
- package/dist/index.js +0 -3284
- package/dist/utils/key-template.cjs.map +0 -1
- package/dist/utils/key-template.js.map +0 -1
package/dist/table.d.cts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import './types.cjs';
|
|
2
|
+
import './conditions-ChhQWd6z.cjs';
|
|
3
|
+
import './query-builder-D2FM9rsu.cjs';
|
|
4
|
+
import './builders/put-builder.cjs';
|
|
5
|
+
import './builders/delete-builder.cjs';
|
|
6
|
+
import './builders/update-builder.cjs';
|
|
7
|
+
import './builders/transaction-builder.cjs';
|
|
8
|
+
export { T as Table } from './table-BEhBPy2G.cjs';
|
|
9
|
+
import './builders/condition-check-builder.cjs';
|
|
10
|
+
import '@aws-sdk/lib-dynamodb';
|
|
11
|
+
import './builders/paginator.cjs';
|
|
12
|
+
import './builder-types-DtwbqMeF.cjs';
|
package/dist/table.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import './types.js';
|
|
2
|
+
import './conditions--ld9a78i.js';
|
|
3
|
+
import './query-builder-Csror9Iu.js';
|
|
4
|
+
import './builders/put-builder.js';
|
|
5
|
+
import './builders/delete-builder.js';
|
|
6
|
+
import './builders/update-builder.js';
|
|
7
|
+
import './builders/transaction-builder.js';
|
|
8
|
+
export { T as Table } from './table-BW3cmUqr.js';
|
|
9
|
+
import './builders/condition-check-builder.js';
|
|
10
|
+
import '@aws-sdk/lib-dynamodb';
|
|
11
|
+
import './builders/paginator.js';
|
|
12
|
+
import './builder-types-C_PDZhnP.js';
|
package/dist/table.js
CHANGED
|
@@ -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,14 @@ var TransactionBuilder = class {
|
|
|
2012
1978
|
* @see DeleteBuilder for creating delete commands
|
|
2013
1979
|
*/
|
|
2014
1980
|
deleteWithCommand(command) {
|
|
2015
|
-
this.
|
|
1981
|
+
const keyCondition = this.createKeyForPrimaryIndex(command.key);
|
|
1982
|
+
this.checkForDuplicateItem(command.tableName, keyCondition);
|
|
2016
1983
|
const transactionItem = {
|
|
2017
1984
|
type: "Delete",
|
|
2018
|
-
params:
|
|
1985
|
+
params: {
|
|
1986
|
+
...command,
|
|
1987
|
+
key: keyCondition
|
|
1988
|
+
}
|
|
2019
1989
|
};
|
|
2020
1990
|
this.items.push(transactionItem);
|
|
2021
1991
|
return this;
|
|
@@ -2075,15 +2045,13 @@ var TransactionBuilder = class {
|
|
|
2075
2045
|
* @throws {Error} If a duplicate item is detected in the transaction
|
|
2076
2046
|
*/
|
|
2077
2047
|
update(tableName, key, updateExpression, expressionAttributeNames, expressionAttributeValues, condition) {
|
|
2078
|
-
this.
|
|
2048
|
+
const keyCondition = this.createKeyForPrimaryIndex(key);
|
|
2049
|
+
this.checkForDuplicateItem(tableName, keyCondition);
|
|
2079
2050
|
const transactionItem = {
|
|
2080
2051
|
type: "Update",
|
|
2081
2052
|
params: {
|
|
2082
2053
|
tableName,
|
|
2083
|
-
key:
|
|
2084
|
-
pk: key.pk,
|
|
2085
|
-
sk: key.sk
|
|
2086
|
-
},
|
|
2054
|
+
key: keyCondition,
|
|
2087
2055
|
updateExpression,
|
|
2088
2056
|
expressionAttributeNames,
|
|
2089
2057
|
expressionAttributeValues
|
|
@@ -2137,10 +2105,14 @@ var TransactionBuilder = class {
|
|
|
2137
2105
|
* @see UpdateBuilder for creating update commands
|
|
2138
2106
|
*/
|
|
2139
2107
|
updateWithCommand(command) {
|
|
2140
|
-
this.
|
|
2108
|
+
const keyCondition = this.createKeyForPrimaryIndex(command.key);
|
|
2109
|
+
this.checkForDuplicateItem(command.tableName, keyCondition);
|
|
2141
2110
|
const transactionItem = {
|
|
2142
2111
|
type: "Update",
|
|
2143
|
-
params:
|
|
2112
|
+
params: {
|
|
2113
|
+
...command,
|
|
2114
|
+
key: keyCondition
|
|
2115
|
+
}
|
|
2144
2116
|
};
|
|
2145
2117
|
this.items.push(transactionItem);
|
|
2146
2118
|
return this;
|
|
@@ -2197,7 +2169,8 @@ var TransactionBuilder = class {
|
|
|
2197
2169
|
* @throws {Error} If condition expression generation fails
|
|
2198
2170
|
*/
|
|
2199
2171
|
conditionCheck(tableName, key, condition) {
|
|
2200
|
-
this.
|
|
2172
|
+
const keyCondition = this.createKeyForPrimaryIndex(key);
|
|
2173
|
+
this.checkForDuplicateItem(tableName, keyCondition);
|
|
2201
2174
|
const { expression, names, values } = prepareExpressionParams(condition);
|
|
2202
2175
|
if (!expression) {
|
|
2203
2176
|
throw new Error("Failed to generate condition expression");
|
|
@@ -2206,10 +2179,7 @@ var TransactionBuilder = class {
|
|
|
2206
2179
|
type: "ConditionCheck",
|
|
2207
2180
|
params: {
|
|
2208
2181
|
tableName,
|
|
2209
|
-
key:
|
|
2210
|
-
pk: key.pk,
|
|
2211
|
-
sk: key.sk
|
|
2212
|
-
},
|
|
2182
|
+
key: keyCondition,
|
|
2213
2183
|
conditionExpression: expression,
|
|
2214
2184
|
expressionAttributeNames: names,
|
|
2215
2185
|
expressionAttributeValues: values
|
|
@@ -2249,10 +2219,14 @@ var TransactionBuilder = class {
|
|
|
2249
2219
|
* @see ConditionCheckBuilder for creating condition check commands
|
|
2250
2220
|
*/
|
|
2251
2221
|
conditionCheckWithCommand(command) {
|
|
2252
|
-
this.
|
|
2222
|
+
const keyCondition = this.createKeyForPrimaryIndex(command.key);
|
|
2223
|
+
this.checkForDuplicateItem(command.tableName, keyCondition);
|
|
2253
2224
|
const transactionItem = {
|
|
2254
2225
|
type: "ConditionCheck",
|
|
2255
|
-
params:
|
|
2226
|
+
params: {
|
|
2227
|
+
...command,
|
|
2228
|
+
key: keyCondition
|
|
2229
|
+
}
|
|
2256
2230
|
};
|
|
2257
2231
|
this.items.push(transactionItem);
|
|
2258
2232
|
return this;
|
|
@@ -2485,7 +2459,7 @@ var ConditionCheckBuilder = class {
|
|
|
2485
2459
|
* );
|
|
2486
2460
|
* ```
|
|
2487
2461
|
*
|
|
2488
|
-
* @param condition - Either a Condition
|
|
2462
|
+
* @param condition - Either a Condition DynamoItem or a callback function that builds the condition
|
|
2489
2463
|
* @returns The builder instance for method chaining
|
|
2490
2464
|
*/
|
|
2491
2465
|
condition(condition) {
|
|
@@ -2711,18 +2685,18 @@ var GetBuilder = class {
|
|
|
2711
2685
|
* - item: The retrieved dinosaur or undefined if not found
|
|
2712
2686
|
*/
|
|
2713
2687
|
async execute() {
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
this.params
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
|
|
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
|
+
});
|
|
2726
2700
|
}
|
|
2727
2701
|
};
|
|
2728
2702
|
|
|
@@ -2817,6 +2791,16 @@ var Table = class {
|
|
|
2817
2791
|
this.sortKey = config.indexes.sortKey;
|
|
2818
2792
|
this.gsis = config.indexes.gsis || {};
|
|
2819
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
|
+
}
|
|
2820
2804
|
/**
|
|
2821
2805
|
* Creates a new item in the table, it will fail if the item already exists
|
|
2822
2806
|
*
|
|
@@ -2831,7 +2815,7 @@ var Table = class {
|
|
|
2831
2815
|
try {
|
|
2832
2816
|
const result = await this.dynamoClient.get({
|
|
2833
2817
|
TableName: params.tableName,
|
|
2834
|
-
Key:
|
|
2818
|
+
Key: this.createKeyForPrimaryIndex(keyCondition),
|
|
2835
2819
|
ProjectionExpression: params.projectionExpression,
|
|
2836
2820
|
ExpressionAttributeNames: params.expressionAttributeNames,
|
|
2837
2821
|
ConsistentRead: params.consistentRead
|
|
@@ -2866,13 +2850,12 @@ var Table = class {
|
|
|
2866
2850
|
ReturnValues: params.returnValues === "CONSISTENT" ? "NONE" : params.returnValues
|
|
2867
2851
|
});
|
|
2868
2852
|
if (params.returnValues === "CONSISTENT") {
|
|
2869
|
-
const key = {
|
|
2870
|
-
pk: params.item[this.partitionKey],
|
|
2871
|
-
...this.sortKey && { sk: params.item[this.sortKey] }
|
|
2872
|
-
};
|
|
2873
2853
|
const getResult = await this.dynamoClient.get({
|
|
2874
2854
|
TableName: params.tableName,
|
|
2875
|
-
Key:
|
|
2855
|
+
Key: this.createKeyForPrimaryIndex({
|
|
2856
|
+
pk: params.item[this.partitionKey],
|
|
2857
|
+
...this.sortKey && { sk: params.item[this.sortKey] }
|
|
2858
|
+
}),
|
|
2876
2859
|
ConsistentRead: true
|
|
2877
2860
|
});
|
|
2878
2861
|
return getResult.Item;
|
|
@@ -3056,7 +3039,7 @@ var Table = class {
|
|
|
3056
3039
|
try {
|
|
3057
3040
|
const result = await this.dynamoClient.delete({
|
|
3058
3041
|
TableName: params.tableName,
|
|
3059
|
-
Key:
|
|
3042
|
+
Key: this.createKeyForPrimaryIndex(keyCondition),
|
|
3060
3043
|
ConditionExpression: params.conditionExpression,
|
|
3061
3044
|
ExpressionAttributeNames: params.expressionAttributeNames,
|
|
3062
3045
|
ExpressionAttributeValues: params.expressionAttributeValues,
|
|
@@ -3083,7 +3066,7 @@ var Table = class {
|
|
|
3083
3066
|
try {
|
|
3084
3067
|
const result = await this.dynamoClient.update({
|
|
3085
3068
|
TableName: params.tableName,
|
|
3086
|
-
Key:
|
|
3069
|
+
Key: this.createKeyForPrimaryIndex(keyCondition),
|
|
3087
3070
|
UpdateExpression: params.updateExpression,
|
|
3088
3071
|
ConditionExpression: params.conditionExpression,
|
|
3089
3072
|
ExpressionAttributeNames: params.expressionAttributeNames,
|
|
@@ -3211,10 +3194,7 @@ var Table = class {
|
|
|
3211
3194
|
}
|
|
3212
3195
|
return {
|
|
3213
3196
|
DeleteRequest: {
|
|
3214
|
-
Key:
|
|
3215
|
-
[this.partitionKey]: operation.key.pk,
|
|
3216
|
-
...this.sortKey ? { [this.sortKey]: operation.key.sk } : {}
|
|
3217
|
-
}
|
|
3197
|
+
Key: this.createKeyForPrimaryIndex(operation.key)
|
|
3218
3198
|
}
|
|
3219
3199
|
};
|
|
3220
3200
|
});
|