dyno-table 0.1.2 → 0.1.4
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 +11 -12
- package/dist/index.d.ts +0 -68
- package/dist/index.js +40 -61
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -72,19 +72,19 @@ const client = new DynamoDBClient({ region: "us-west-2" });
|
|
|
72
72
|
const docClient = DynamoDBDocument.from(client);
|
|
73
73
|
|
|
74
74
|
// Initialize table with single-table design schema
|
|
75
|
-
const dinoTable = new Table(
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
75
|
+
const dinoTable = new Table({
|
|
76
|
+
client: docClient,
|
|
77
|
+
tableName: "DinosaurPark",
|
|
78
|
+
indexes: {
|
|
79
|
+
partitionKey: "pk",
|
|
80
|
+
sortKey: "sk",
|
|
81
|
+
gsis: {
|
|
82
|
+
speciesId: {
|
|
83
|
+
partitionKey: "gsi1pk",
|
|
84
|
+
sortKey: "gsi1sk",
|
|
85
85
|
},
|
|
86
86
|
},
|
|
87
|
-
|
|
87
|
+
},
|
|
88
88
|
});
|
|
89
89
|
```
|
|
90
90
|
|
|
@@ -234,7 +234,6 @@ await dinoTable.transaction(
|
|
|
234
234
|
- ✅ All-or-nothing operations (ACID compliance)
|
|
235
235
|
- 🛡️ Prevents race conditions and data inconsistencies
|
|
236
236
|
- 📊 Supports up to 100 actions per transaction
|
|
237
|
-
```
|
|
238
237
|
|
|
239
238
|
### Batch Processing
|
|
240
239
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1551,22 +1551,6 @@ interface DeleteCommandParams extends DynamoCommandWithExpressions {
|
|
|
1551
1551
|
type DeleteExecutor = (params: DeleteCommandParams) => Promise<{
|
|
1552
1552
|
item?: Record<string, unknown>;
|
|
1553
1553
|
}>;
|
|
1554
|
-
/**
|
|
1555
|
-
* Builder for creating DynamoDB delete operations.
|
|
1556
|
-
* Use this builder when you need to:
|
|
1557
|
-
* - Delete items from a DynamoDB table
|
|
1558
|
-
* - Conditionally delete items based on attribute values
|
|
1559
|
-
* - Delete items as part of a transaction
|
|
1560
|
-
* - Retrieve the old item values after deletion
|
|
1561
|
-
*
|
|
1562
|
-
* @example
|
|
1563
|
-
* ```ts
|
|
1564
|
-
* const result = await new DeleteBuilder(executor, 'myTable', { id: '123' })
|
|
1565
|
-
* .condition(op => op.attributeExists('status'))
|
|
1566
|
-
* .returnValues('ALL_OLD')
|
|
1567
|
-
* .execute();
|
|
1568
|
-
* ```
|
|
1569
|
-
*/
|
|
1570
1554
|
/**
|
|
1571
1555
|
* Builder for creating DynamoDB delete operations.
|
|
1572
1556
|
* Use this builder when you need to:
|
|
@@ -1600,30 +1584,6 @@ declare class DeleteBuilder {
|
|
|
1600
1584
|
private readonly tableName;
|
|
1601
1585
|
private readonly key;
|
|
1602
1586
|
constructor(executor: DeleteExecutor, tableName: string, key: PrimaryKeyWithoutExpression);
|
|
1603
|
-
/**
|
|
1604
|
-
* Adds a condition that must be satisfied for the delete operation to succeed.
|
|
1605
|
-
* Use this method when you need to:
|
|
1606
|
-
* - Implement optimistic locking (e.g., version check)
|
|
1607
|
-
* - Ensure item exists before deletion
|
|
1608
|
-
* - Validate item state before deletion
|
|
1609
|
-
*
|
|
1610
|
-
* @example
|
|
1611
|
-
* ```ts
|
|
1612
|
-
* // Simple condition
|
|
1613
|
-
* builder.condition(op => op.attributeExists('id'))
|
|
1614
|
-
*
|
|
1615
|
-
* // Complex condition with version check
|
|
1616
|
-
* builder.condition(op =>
|
|
1617
|
-
* op.and([
|
|
1618
|
-
* op.eq('version', 1),
|
|
1619
|
-
* op.eq('status', 'ACTIVE')
|
|
1620
|
-
* ])
|
|
1621
|
-
* )
|
|
1622
|
-
* ```
|
|
1623
|
-
*
|
|
1624
|
-
* @param condition - Either a Condition object or a callback function that builds the condition
|
|
1625
|
-
* @returns The builder instance for method chaining
|
|
1626
|
-
*/
|
|
1627
1587
|
/**
|
|
1628
1588
|
* Adds a condition that must be satisfied for the delete operation to succeed.
|
|
1629
1589
|
* Use this method when you need to:
|
|
@@ -2437,34 +2397,6 @@ interface PutCommandParams extends DynamoCommandWithExpressions {
|
|
|
2437
2397
|
returnValues?: "ALL_OLD" | "NONE";
|
|
2438
2398
|
}
|
|
2439
2399
|
type PutExecutor<T extends Record<string, unknown>> = (params: PutCommandParams) => Promise<T>;
|
|
2440
|
-
/**
|
|
2441
|
-
* Builder for creating DynamoDB put operations.
|
|
2442
|
-
* Use this builder when you need to:
|
|
2443
|
-
* - Insert new items into a DynamoDB table
|
|
2444
|
-
* - Replace existing items completely
|
|
2445
|
-
* - Conditionally put items based on their current state
|
|
2446
|
-
* - Put items as part of a transaction
|
|
2447
|
-
*
|
|
2448
|
-
* The builder supports:
|
|
2449
|
-
* - Conditional puts with complex conditions
|
|
2450
|
-
* - Retrieving old item values
|
|
2451
|
-
* - Transaction integration
|
|
2452
|
-
*
|
|
2453
|
-
* @example
|
|
2454
|
-
* ```ts
|
|
2455
|
-
* // Simple put
|
|
2456
|
-
* const result = await new PutBuilder(executor, { id: '123', status: 'ACTIVE' }, 'myTable')
|
|
2457
|
-
* .execute();
|
|
2458
|
-
*
|
|
2459
|
-
* // Conditional put with old value retrieval
|
|
2460
|
-
* const result = await new PutBuilder(executor, newItem, 'myTable')
|
|
2461
|
-
* .condition(op => op.attributeNotExists('id'))
|
|
2462
|
-
* .returnValues('ALL_OLD')
|
|
2463
|
-
* .execute();
|
|
2464
|
-
* ```
|
|
2465
|
-
*
|
|
2466
|
-
* @typeParam T - The type of item being put into the table
|
|
2467
|
-
*/
|
|
2468
2400
|
/**
|
|
2469
2401
|
* Builder for creating DynamoDB put operations.
|
|
2470
2402
|
* Use this builder when you need to:
|
package/dist/index.js
CHANGED
|
@@ -1006,25 +1006,25 @@ var PutBuilder = class {
|
|
|
1006
1006
|
* - Prevent duplicate dinosaur entries
|
|
1007
1007
|
* - Ensure habitat requirements
|
|
1008
1008
|
* - Validate security protocols
|
|
1009
|
-
*
|
|
1009
|
+
*
|
|
1010
1010
|
* @example
|
|
1011
1011
|
* ```typescript
|
|
1012
1012
|
* // Ensure unique dinosaur ID
|
|
1013
|
-
* builder.condition(op =>
|
|
1013
|
+
* builder.condition(op =>
|
|
1014
1014
|
* op.attributeNotExists('id')
|
|
1015
1015
|
* );
|
|
1016
|
-
*
|
|
1016
|
+
*
|
|
1017
1017
|
* // Verify habitat requirements
|
|
1018
|
-
* builder.condition(op =>
|
|
1018
|
+
* builder.condition(op =>
|
|
1019
1019
|
* op.and([
|
|
1020
1020
|
* op.eq('securityStatus', 'READY'),
|
|
1021
1021
|
* op.attributeExists('lastInspection'),
|
|
1022
1022
|
* op.gt('securityLevel', 5)
|
|
1023
1023
|
* ])
|
|
1024
1024
|
* );
|
|
1025
|
-
*
|
|
1025
|
+
*
|
|
1026
1026
|
* // Check breeding facility conditions
|
|
1027
|
-
* builder.condition(op =>
|
|
1027
|
+
* builder.condition(op =>
|
|
1028
1028
|
* op.and([
|
|
1029
1029
|
* op.between('temperature', 25, 30),
|
|
1030
1030
|
* op.between('humidity', 60, 80),
|
|
@@ -1032,7 +1032,7 @@ var PutBuilder = class {
|
|
|
1032
1032
|
* ])
|
|
1033
1033
|
* );
|
|
1034
1034
|
* ```
|
|
1035
|
-
*
|
|
1035
|
+
*
|
|
1036
1036
|
* @param condition - Either a Condition object or a callback function that builds the condition
|
|
1037
1037
|
* @returns The builder instance for method chaining
|
|
1038
1038
|
*/
|
|
@@ -1066,14 +1066,14 @@ var PutBuilder = class {
|
|
|
1066
1066
|
* - Track dinosaur profile updates
|
|
1067
1067
|
* - Monitor habitat modifications
|
|
1068
1068
|
* - Maintain change history
|
|
1069
|
-
*
|
|
1069
|
+
*
|
|
1070
1070
|
* @example
|
|
1071
1071
|
* ```ts
|
|
1072
1072
|
* // Get previous dinosaur state
|
|
1073
1073
|
* const result = await builder
|
|
1074
1074
|
* .returnValues('ALL_OLD')
|
|
1075
1075
|
* .execute();
|
|
1076
|
-
*
|
|
1076
|
+
*
|
|
1077
1077
|
* if (result) {
|
|
1078
1078
|
* console.log('Previous profile:', {
|
|
1079
1079
|
* species: result.species,
|
|
@@ -1085,7 +1085,7 @@ var PutBuilder = class {
|
|
|
1085
1085
|
* });
|
|
1086
1086
|
* }
|
|
1087
1087
|
* ```
|
|
1088
|
-
*
|
|
1088
|
+
*
|
|
1089
1089
|
* @param returnValues - Use 'ALL_OLD' to return previous values, or 'NONE' (default)
|
|
1090
1090
|
* @returns The builder instance for method chaining
|
|
1091
1091
|
*/
|
|
@@ -1113,11 +1113,11 @@ var PutBuilder = class {
|
|
|
1113
1113
|
* - Transfer dinosaurs between habitats
|
|
1114
1114
|
* - Initialize new breeding programs
|
|
1115
1115
|
* - Update multiple facility records
|
|
1116
|
-
*
|
|
1116
|
+
*
|
|
1117
1117
|
* @example
|
|
1118
1118
|
* ```ts
|
|
1119
1119
|
* const transaction = new TransactionBuilder();
|
|
1120
|
-
*
|
|
1120
|
+
*
|
|
1121
1121
|
* // Add dinosaur to new habitat
|
|
1122
1122
|
* new PutBuilder(executor, {
|
|
1123
1123
|
* id: 'TREX-002',
|
|
@@ -1126,17 +1126,17 @@ var PutBuilder = class {
|
|
|
1126
1126
|
* transferDate: new Date().toISOString()
|
|
1127
1127
|
* }, 'dinosaurs')
|
|
1128
1128
|
* .withTransaction(transaction);
|
|
1129
|
-
*
|
|
1129
|
+
*
|
|
1130
1130
|
* // Update habitat records
|
|
1131
1131
|
* new UpdateBuilder(executor, 'habitats', { id: 'PADDOCK-B' })
|
|
1132
1132
|
* .add('occupants', 1)
|
|
1133
1133
|
* .set('lastTransfer', new Date().toISOString())
|
|
1134
1134
|
* .withTransaction(transaction);
|
|
1135
|
-
*
|
|
1135
|
+
*
|
|
1136
1136
|
* // Execute transfer atomically
|
|
1137
1137
|
* await transaction.execute();
|
|
1138
1138
|
* ```
|
|
1139
|
-
*
|
|
1139
|
+
*
|
|
1140
1140
|
* @param transaction - The transaction builder to add this operation to
|
|
1141
1141
|
* @returns The builder instance for method chaining
|
|
1142
1142
|
*/
|
|
@@ -1179,7 +1179,7 @@ var PutBuilder = class {
|
|
|
1179
1179
|
* - Verify habitat assignments
|
|
1180
1180
|
* - Log security protocols
|
|
1181
1181
|
* - Troubleshoot breeding program conditions
|
|
1182
|
-
*
|
|
1182
|
+
*
|
|
1183
1183
|
* @example
|
|
1184
1184
|
* ```ts
|
|
1185
1185
|
* const debugInfo = new PutBuilder(executor, {
|
|
@@ -1200,10 +1200,10 @@ var PutBuilder = class {
|
|
|
1200
1200
|
* ])
|
|
1201
1201
|
* )
|
|
1202
1202
|
* .debug();
|
|
1203
|
-
*
|
|
1203
|
+
*
|
|
1204
1204
|
* console.log('Dinosaur transfer command:', debugInfo);
|
|
1205
1205
|
* ```
|
|
1206
|
-
*
|
|
1206
|
+
*
|
|
1207
1207
|
* @returns A readable representation of the put command with resolved expressions
|
|
1208
1208
|
*/
|
|
1209
1209
|
debug() {
|
|
@@ -1225,50 +1225,26 @@ var DeleteBuilder = class {
|
|
|
1225
1225
|
this.tableName = tableName;
|
|
1226
1226
|
this.key = key;
|
|
1227
1227
|
}
|
|
1228
|
-
/**
|
|
1229
|
-
* Adds a condition that must be satisfied for the delete operation to succeed.
|
|
1230
|
-
* Use this method when you need to:
|
|
1231
|
-
* - Implement optimistic locking (e.g., version check)
|
|
1232
|
-
* - Ensure item exists before deletion
|
|
1233
|
-
* - Validate item state before deletion
|
|
1234
|
-
*
|
|
1235
|
-
* @example
|
|
1236
|
-
* ```ts
|
|
1237
|
-
* // Simple condition
|
|
1238
|
-
* builder.condition(op => op.attributeExists('id'))
|
|
1239
|
-
*
|
|
1240
|
-
* // Complex condition with version check
|
|
1241
|
-
* builder.condition(op =>
|
|
1242
|
-
* op.and([
|
|
1243
|
-
* op.eq('version', 1),
|
|
1244
|
-
* op.eq('status', 'ACTIVE')
|
|
1245
|
-
* ])
|
|
1246
|
-
* )
|
|
1247
|
-
* ```
|
|
1248
|
-
*
|
|
1249
|
-
* @param condition - Either a Condition object or a callback function that builds the condition
|
|
1250
|
-
* @returns The builder instance for method chaining
|
|
1251
|
-
*/
|
|
1252
1228
|
/**
|
|
1253
1229
|
* Adds a condition that must be satisfied for the delete operation to succeed.
|
|
1254
1230
|
* Use this method when you need to:
|
|
1255
1231
|
* - Ensure safe removal conditions
|
|
1256
1232
|
* - Verify habitat status before deletion
|
|
1257
1233
|
* - Implement safety protocols
|
|
1258
|
-
*
|
|
1234
|
+
*
|
|
1259
1235
|
* @example
|
|
1260
1236
|
* ```typescript
|
|
1261
1237
|
* // Ensure dinosaur can be safely removed
|
|
1262
|
-
* builder.condition(op =>
|
|
1238
|
+
* builder.condition(op =>
|
|
1263
1239
|
* op.and([
|
|
1264
1240
|
* op.eq('status', 'SEDATED'),
|
|
1265
1241
|
* op.eq('location', 'MEDICAL_BAY'),
|
|
1266
1242
|
* op.attributeExists('lastCheckup')
|
|
1267
1243
|
* ])
|
|
1268
1244
|
* );
|
|
1269
|
-
*
|
|
1245
|
+
*
|
|
1270
1246
|
* // Verify habitat is empty
|
|
1271
|
-
* builder.condition(op =>
|
|
1247
|
+
* builder.condition(op =>
|
|
1272
1248
|
* op.and([
|
|
1273
1249
|
* op.eq('occupants', 0),
|
|
1274
1250
|
* op.eq('maintenanceStatus', 'COMPLETE'),
|
|
@@ -1276,7 +1252,7 @@ var DeleteBuilder = class {
|
|
|
1276
1252
|
* ])
|
|
1277
1253
|
* );
|
|
1278
1254
|
* ```
|
|
1279
|
-
*
|
|
1255
|
+
*
|
|
1280
1256
|
* @param condition - Either a Condition object or a callback function that builds the condition
|
|
1281
1257
|
* @returns The builder instance for method chaining
|
|
1282
1258
|
*/
|
|
@@ -1310,14 +1286,14 @@ var DeleteBuilder = class {
|
|
|
1310
1286
|
* - Archive removed dinosaur data
|
|
1311
1287
|
* - Track habitat decommissioning history
|
|
1312
1288
|
* - Maintain removal audit logs
|
|
1313
|
-
*
|
|
1289
|
+
*
|
|
1314
1290
|
* @example
|
|
1315
1291
|
* ```ts
|
|
1316
1292
|
* // Archive dinosaur data before removal
|
|
1317
1293
|
* const result = await builder
|
|
1318
1294
|
* .returnValues('ALL_OLD')
|
|
1319
1295
|
* .execute();
|
|
1320
|
-
*
|
|
1296
|
+
*
|
|
1321
1297
|
* if (result.item) {
|
|
1322
1298
|
* console.log('Removed dinosaur data:', {
|
|
1323
1299
|
* species: result.item.species,
|
|
@@ -1326,7 +1302,7 @@ var DeleteBuilder = class {
|
|
|
1326
1302
|
* });
|
|
1327
1303
|
* }
|
|
1328
1304
|
* ```
|
|
1329
|
-
*
|
|
1305
|
+
*
|
|
1330
1306
|
* @param returnValues - Use 'ALL_OLD' to return all attributes of the deleted item
|
|
1331
1307
|
* @returns The builder instance for method chaining
|
|
1332
1308
|
*/
|
|
@@ -1409,7 +1385,7 @@ var DeleteBuilder = class {
|
|
|
1409
1385
|
* - Verify safety checks
|
|
1410
1386
|
* - Log removal operations
|
|
1411
1387
|
* - Troubleshoot failed deletions
|
|
1412
|
-
*
|
|
1388
|
+
*
|
|
1413
1389
|
* @example
|
|
1414
1390
|
* ```ts
|
|
1415
1391
|
* const debugInfo = new DeleteBuilder(executor, 'dinosaurs', { id: 'TREX-001' })
|
|
@@ -2947,10 +2923,13 @@ var Table = class {
|
|
|
2947
2923
|
* If useIndex is called on the returned QueryBuilder, it will use the GSI configuration
|
|
2948
2924
|
*/
|
|
2949
2925
|
query(keyCondition) {
|
|
2950
|
-
const pkAttributeName =
|
|
2951
|
-
const skAttributeName =
|
|
2926
|
+
const pkAttributeName = this.partitionKey;
|
|
2927
|
+
const skAttributeName = this.sortKey;
|
|
2952
2928
|
let keyConditionExpression = eq(pkAttributeName, keyCondition.pk);
|
|
2953
2929
|
if (keyCondition.sk) {
|
|
2930
|
+
if (!skAttributeName) {
|
|
2931
|
+
throw new Error("Sort key is not defined for Index");
|
|
2932
|
+
}
|
|
2954
2933
|
const keyConditionOperator = {
|
|
2955
2934
|
eq: (value) => eq(skAttributeName, value),
|
|
2956
2935
|
lt: (value) => lt(skAttributeName, value),
|
|
@@ -3165,8 +3144,8 @@ var Table = class {
|
|
|
3165
3144
|
const allUnprocessedKeys = [];
|
|
3166
3145
|
for (const chunk of chunkArray(keys, DDB_BATCH_GET_LIMIT)) {
|
|
3167
3146
|
const formattedKeys = chunk.map((key) => ({
|
|
3168
|
-
|
|
3169
|
-
|
|
3147
|
+
[this.partitionKey]: key.pk,
|
|
3148
|
+
...this.sortKey ? { [this.sortKey]: key.sk } : {}
|
|
3170
3149
|
}));
|
|
3171
3150
|
const params = {
|
|
3172
3151
|
RequestItems: {
|
|
@@ -3182,8 +3161,8 @@ var Table = class {
|
|
|
3182
3161
|
}
|
|
3183
3162
|
const unprocessedKeysArray = result.UnprocessedKeys?.[this.tableName]?.Keys || [];
|
|
3184
3163
|
const unprocessedKeys = unprocessedKeysArray.map((key) => ({
|
|
3185
|
-
pk: key.
|
|
3186
|
-
sk: key.
|
|
3164
|
+
pk: key[this.partitionKey],
|
|
3165
|
+
sk: this.sortKey ? key[this.sortKey] : void 0
|
|
3187
3166
|
}));
|
|
3188
3167
|
if (unprocessedKeys.length > 0) {
|
|
3189
3168
|
allUnprocessedKeys.push(...unprocessedKeys);
|
|
@@ -3218,8 +3197,8 @@ var Table = class {
|
|
|
3218
3197
|
return {
|
|
3219
3198
|
DeleteRequest: {
|
|
3220
3199
|
Key: {
|
|
3221
|
-
|
|
3222
|
-
|
|
3200
|
+
[this.partitionKey]: operation.key.pk,
|
|
3201
|
+
...this.sortKey ? { [this.sortKey]: operation.key.sk } : {}
|
|
3223
3202
|
}
|
|
3224
3203
|
}
|
|
3225
3204
|
};
|
|
@@ -3244,8 +3223,8 @@ var Table = class {
|
|
|
3244
3223
|
return {
|
|
3245
3224
|
type: "delete",
|
|
3246
3225
|
key: {
|
|
3247
|
-
pk: request.DeleteRequest.Key.
|
|
3248
|
-
sk: request.DeleteRequest.Key.
|
|
3226
|
+
pk: request.DeleteRequest.Key[this.partitionKey],
|
|
3227
|
+
sk: this.sortKey ? request.DeleteRequest.Key[this.sortKey] : void 0
|
|
3249
3228
|
}
|
|
3250
3229
|
};
|
|
3251
3230
|
}
|