dyno-table 0.1.6 → 0.1.8
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/LICENSE +21 -0
- package/README.md +115 -17
- 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.js +392 -0
- package/dist/builders/condition-check-builder.js.map +1 -0
- package/dist/builders/delete-builder.cjs +422 -0
- package/dist/builders/delete-builder.cjs.map +1 -0
- package/dist/builders/delete-builder.js +420 -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.js +197 -0
- package/dist/builders/paginator.js.map +1 -0
- package/dist/builders/put-builder.cjs +468 -0
- package/dist/builders/put-builder.cjs.map +1 -0
- package/dist/builders/put-builder.js +466 -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.js +672 -0
- package/dist/builders/query-builder.js.map +1 -0
- package/dist/builders/transaction-builder.cjs +876 -0
- package/dist/builders/transaction-builder.cjs.map +1 -0
- package/dist/builders/transaction-builder.js +874 -0
- package/dist/builders/transaction-builder.js.map +1 -0
- package/dist/builders/update-builder.cjs +662 -0
- package/dist/builders/update-builder.cjs.map +1 -0
- package/dist/builders/update-builder.js +660 -0
- package/dist/builders/update-builder.js.map +1 -0
- package/dist/conditions.cjs +59 -0
- package/dist/conditions.cjs.map +1 -0
- package/dist/conditions.js +43 -0
- package/dist/conditions.js.map +1 -0
- package/dist/entity.cjs +169 -0
- package/dist/entity.cjs.map +1 -0
- package/dist/entity.js +165 -0
- package/dist/entity.js.map +1 -0
- package/dist/index.cjs +3333 -0
- package/dist/index.d.cts +2971 -0
- package/dist/index.d.ts +1504 -1383
- package/dist/index.js +391 -375
- package/dist/standard-schema.cjs +4 -0
- package/dist/standard-schema.cjs.map +1 -0
- package/dist/standard-schema.js +3 -0
- package/dist/standard-schema.js.map +1 -0
- package/dist/table.cjs +3265 -0
- package/dist/table.cjs.map +1 -0
- package/dist/table.js +3263 -0
- package/dist/table.js.map +1 -0
- package/dist/types.cjs +4 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/key-template.cjs +19 -0
- package/dist/utils/key-template.cjs.map +1 -0
- package/dist/utils/key-template.js +17 -0
- package/dist/utils/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.js +17 -0
- package/dist/utils/sort-key-template.js.map +1 -0
- package/package.json +12 -7
package/dist/index.js
CHANGED
|
@@ -191,16 +191,16 @@ var Paginator = class {
|
|
|
191
191
|
* - Track progress through dinosaur lists
|
|
192
192
|
* - Display habitat inspection status
|
|
193
193
|
* - Monitor security sweep progress
|
|
194
|
-
*
|
|
194
|
+
*
|
|
195
195
|
* @example
|
|
196
196
|
* ```ts
|
|
197
197
|
* const paginator = new QueryBuilder(executor, eq('species', 'Tyrannosaurus'))
|
|
198
198
|
* .paginate(5);
|
|
199
|
-
*
|
|
199
|
+
*
|
|
200
200
|
* await paginator.getNextPage();
|
|
201
201
|
* console.log(`Reviewing T-Rex group ${paginator.getCurrentPage()}`);
|
|
202
202
|
* ```
|
|
203
|
-
*
|
|
203
|
+
*
|
|
204
204
|
* @returns The current page number, starting from 1
|
|
205
205
|
*/
|
|
206
206
|
getCurrentPage() {
|
|
@@ -213,18 +213,18 @@ var Paginator = class {
|
|
|
213
213
|
* - Continue habitat inspections
|
|
214
214
|
* - Process security incidents
|
|
215
215
|
* - Complete feeding schedules
|
|
216
|
-
*
|
|
216
|
+
*
|
|
217
217
|
* This method takes into account both:
|
|
218
218
|
* - DynamoDB's lastEvaluatedKey mechanism
|
|
219
219
|
* - Any overall limit set on the query
|
|
220
|
-
*
|
|
220
|
+
*
|
|
221
221
|
* @example
|
|
222
222
|
* ```ts
|
|
223
223
|
* // Process all security incidents
|
|
224
224
|
* const paginator = new QueryBuilder(executor, eq('type', 'SECURITY_BREACH'))
|
|
225
225
|
* .sortDescending()
|
|
226
226
|
* .paginate(10);
|
|
227
|
-
*
|
|
227
|
+
*
|
|
228
228
|
* while (paginator.hasNextPage()) {
|
|
229
229
|
* const page = await paginator.getNextPage();
|
|
230
230
|
* for (const incident of page.items) {
|
|
@@ -233,7 +233,7 @@ var Paginator = class {
|
|
|
233
233
|
* console.log(`Processed incidents page ${page.page}`);
|
|
234
234
|
* }
|
|
235
235
|
* ```
|
|
236
|
-
*
|
|
236
|
+
*
|
|
237
237
|
* @returns true if there are more pages available, false otherwise
|
|
238
238
|
*/
|
|
239
239
|
hasNextPage() {
|
|
@@ -249,33 +249,33 @@ var Paginator = class {
|
|
|
249
249
|
* - Review habitat inspections in batches
|
|
250
250
|
* - Monitor security incidents in sequence
|
|
251
251
|
* - Schedule feeding rotations
|
|
252
|
-
*
|
|
252
|
+
*
|
|
253
253
|
* This method handles:
|
|
254
254
|
* - Automatic continuation between groups
|
|
255
255
|
* - Respect for park capacity limits
|
|
256
256
|
* - Group size adjustments for safety
|
|
257
|
-
*
|
|
257
|
+
*
|
|
258
258
|
* @example
|
|
259
259
|
* ```ts
|
|
260
260
|
* const paginator = new QueryBuilder(executor, eq('species', 'Velociraptor'))
|
|
261
261
|
* .filter(op => op.eq('status', 'ACTIVE'))
|
|
262
262
|
* .paginate(5);
|
|
263
|
-
*
|
|
263
|
+
*
|
|
264
264
|
* // Check first raptor group
|
|
265
265
|
* const page1 = await paginator.getNextPage();
|
|
266
266
|
* console.log(`Found ${page1.items.length} active raptors`);
|
|
267
|
-
*
|
|
267
|
+
*
|
|
268
268
|
* // Continue inspection if more groups exist
|
|
269
269
|
* if (page1.hasNextPage) {
|
|
270
270
|
* const page2 = await paginator.getNextPage();
|
|
271
271
|
* console.log(`Inspecting raptor group ${page2.page}`);
|
|
272
|
-
*
|
|
272
|
+
*
|
|
273
273
|
* for (const raptor of page2.items) {
|
|
274
274
|
* await performHealthCheck(raptor);
|
|
275
275
|
* }
|
|
276
276
|
* }
|
|
277
277
|
* ```
|
|
278
|
-
*
|
|
278
|
+
*
|
|
279
279
|
* @returns A promise that resolves to a PaginationResult containing:
|
|
280
280
|
* - items: The dinosaurs/habitats for this page
|
|
281
281
|
* - hasNextPage: Whether more groups exist
|
|
@@ -325,23 +325,23 @@ var Paginator = class {
|
|
|
325
325
|
* - Perform full security audit
|
|
326
326
|
* - Create comprehensive feeding schedule
|
|
327
327
|
* - Run park-wide health checks
|
|
328
|
-
*
|
|
328
|
+
*
|
|
329
329
|
* Note: Use with caution! This method:
|
|
330
330
|
* - Could overwhelm systems with large dinosaur populations
|
|
331
331
|
* - Makes multiple database requests
|
|
332
332
|
* - May cause system strain during peak hours
|
|
333
|
-
*
|
|
333
|
+
*
|
|
334
334
|
* @example
|
|
335
335
|
* ```ts
|
|
336
336
|
* // Get complete carnivore inventory
|
|
337
337
|
* const paginator = new QueryBuilder(executor, eq('diet', 'CARNIVORE'))
|
|
338
338
|
* .filter(op => op.eq('status', 'ACTIVE'))
|
|
339
339
|
* .paginate(10);
|
|
340
|
-
*
|
|
340
|
+
*
|
|
341
341
|
* try {
|
|
342
342
|
* const allCarnivores = await paginator.getAllPages();
|
|
343
343
|
* console.log(`Park contains ${allCarnivores.length} active carnivores`);
|
|
344
|
-
*
|
|
344
|
+
*
|
|
345
345
|
* // Calculate total threat level
|
|
346
346
|
* const totalThreat = allCarnivores.reduce(
|
|
347
347
|
* (sum, dino) => sum + dino.stats.threatLevel,
|
|
@@ -352,7 +352,7 @@ var Paginator = class {
|
|
|
352
352
|
* console.error('Failed to complete carnivore census:', error);
|
|
353
353
|
* }
|
|
354
354
|
* ```
|
|
355
|
-
*
|
|
355
|
+
*
|
|
356
356
|
* @returns A promise that resolves to an array containing all remaining items
|
|
357
357
|
*/
|
|
358
358
|
async getAllPages() {
|
|
@@ -365,30 +365,24 @@ var Paginator = class {
|
|
|
365
365
|
}
|
|
366
366
|
};
|
|
367
367
|
|
|
368
|
-
// src/builders/
|
|
369
|
-
var
|
|
370
|
-
keyCondition;
|
|
368
|
+
// src/builders/filter-builder.ts
|
|
369
|
+
var FilterBuilder = class {
|
|
371
370
|
options = {};
|
|
372
371
|
selectedFields = /* @__PURE__ */ new Set();
|
|
373
|
-
executor;
|
|
374
|
-
constructor(executor, keyCondition) {
|
|
375
|
-
this.executor = executor;
|
|
376
|
-
this.keyCondition = keyCondition;
|
|
377
|
-
}
|
|
378
372
|
/**
|
|
379
|
-
* Sets the maximum number of items to return
|
|
373
|
+
* Sets the maximum number of items to return.
|
|
380
374
|
* Use this method when you need to:
|
|
381
|
-
* - Limit the
|
|
382
|
-
* -
|
|
383
|
-
* -
|
|
375
|
+
* - Limit the number of dinosaurs returned
|
|
376
|
+
* - Control the size of habitat reports
|
|
377
|
+
* - Implement manual pagination of security logs
|
|
384
378
|
*
|
|
385
379
|
* Note: This limit applies to the items that match the key condition
|
|
386
380
|
* before any filter expressions are applied.
|
|
387
381
|
*
|
|
388
382
|
* @example
|
|
389
|
-
* ```
|
|
390
|
-
* // Get first 10
|
|
391
|
-
* const result = await
|
|
383
|
+
* ```typescript
|
|
384
|
+
* // Get first 10 dinosaurs
|
|
385
|
+
* const result = await builder
|
|
392
386
|
* .limit(10)
|
|
393
387
|
* .execute();
|
|
394
388
|
* ```
|
|
@@ -401,7 +395,7 @@ var QueryBuilder = class _QueryBuilder {
|
|
|
401
395
|
return this;
|
|
402
396
|
}
|
|
403
397
|
/**
|
|
404
|
-
* Gets the current limit set on the
|
|
398
|
+
* Gets the current limit set on the operation.
|
|
405
399
|
* This is used internally by the paginator to manage result sets.
|
|
406
400
|
*
|
|
407
401
|
* @returns The current limit or undefined if no limit is set
|
|
@@ -410,63 +404,31 @@ var QueryBuilder = class _QueryBuilder {
|
|
|
410
404
|
return this.options.limit;
|
|
411
405
|
}
|
|
412
406
|
/**
|
|
413
|
-
* Specifies a Global Secondary Index (GSI) to use for the
|
|
414
|
-
* Use this method when you need to:
|
|
415
|
-
* - Query data using non-primary key attributes
|
|
416
|
-
* - Access data through alternate access patterns
|
|
417
|
-
* - Optimize query performance for specific access patterns
|
|
418
|
-
*
|
|
419
|
-
* This method provides type safety by only allowing valid GSI names
|
|
420
|
-
* defined in your table configuration.
|
|
421
|
-
*
|
|
422
|
-
* @example
|
|
423
|
-
* ```ts
|
|
424
|
-
* // Query by status using a GSI
|
|
425
|
-
* const result = await new QueryBuilder(executor, eq('status', 'ACTIVE'))
|
|
426
|
-
* .useIndex('status-index')
|
|
427
|
-
* .execute();
|
|
428
|
-
*
|
|
429
|
-
* // Query by category and date range
|
|
430
|
-
* const result = await new QueryBuilder(executor, eq('category', 'books'))
|
|
431
|
-
* .useIndex('category-date-index')
|
|
432
|
-
* .filter(op => op.between('date', startDate, endDate))
|
|
433
|
-
* .execute();
|
|
434
|
-
* ```
|
|
435
|
-
*
|
|
436
|
-
* Note: Be aware that GSIs:
|
|
437
|
-
* - May have different projected attributes
|
|
438
|
-
* - Have eventually consistent reads only
|
|
439
|
-
* - May have different provisioned throughput
|
|
440
|
-
*
|
|
441
|
-
* @param indexName - The name of the GSI to use (type-safe based on table configuration)
|
|
442
|
-
* @returns The builder instance for method chaining
|
|
443
|
-
*/
|
|
444
|
-
/**
|
|
445
|
-
* Specifies a Global Secondary Index (GSI) to use for the query.
|
|
407
|
+
* Specifies a Global Secondary Index (GSI) to use for the operation.
|
|
446
408
|
* Use this method when you need to:
|
|
447
|
-
* -
|
|
409
|
+
* - Find dinosaurs by species or status
|
|
448
410
|
* - Search habitats by security level
|
|
449
411
|
* - Find incidents by date
|
|
450
412
|
* - List feeding schedules by time
|
|
451
|
-
*
|
|
413
|
+
*
|
|
452
414
|
* @example
|
|
453
415
|
* ```typescript
|
|
454
416
|
* // Find all dinosaurs of a specific species
|
|
455
417
|
* builder
|
|
456
418
|
* .useIndex('species-status-index')
|
|
457
419
|
* .filter(op => op.eq('status', 'ACTIVE'));
|
|
458
|
-
*
|
|
420
|
+
*
|
|
459
421
|
* // Search high-security habitats
|
|
460
422
|
* builder
|
|
461
423
|
* .useIndex('security-level-index')
|
|
462
|
-
* .filter(op =>
|
|
424
|
+
* .filter(op =>
|
|
463
425
|
* op.and([
|
|
464
426
|
* op.gt('securityLevel', 8),
|
|
465
427
|
* op.eq('status', 'OPERATIONAL')
|
|
466
428
|
* ])
|
|
467
429
|
* );
|
|
468
430
|
* ```
|
|
469
|
-
*
|
|
431
|
+
*
|
|
470
432
|
* @param indexName - The name of the GSI to use (type-safe based on table configuration)
|
|
471
433
|
* @returns The builder instance for method chaining
|
|
472
434
|
*/
|
|
@@ -475,33 +437,33 @@ var QueryBuilder = class _QueryBuilder {
|
|
|
475
437
|
return this;
|
|
476
438
|
}
|
|
477
439
|
/**
|
|
478
|
-
* Sets whether to use strongly consistent reads for the
|
|
440
|
+
* Sets whether to use strongly consistent reads for the operation.
|
|
479
441
|
* Use this method when you need to:
|
|
480
442
|
* - Get real-time dinosaur status updates
|
|
481
443
|
* - Monitor critical security systems
|
|
482
444
|
* - Track immediate habitat changes
|
|
483
445
|
* - Verify containment protocols
|
|
484
|
-
*
|
|
446
|
+
*
|
|
485
447
|
* Note:
|
|
486
448
|
* - Consistent reads are not available on GSIs
|
|
487
449
|
* - Consistent reads consume twice the throughput
|
|
488
450
|
* - Default is eventually consistent reads
|
|
489
|
-
*
|
|
451
|
+
*
|
|
490
452
|
* @example
|
|
491
|
-
* ```
|
|
453
|
+
* ```typescript
|
|
492
454
|
* // Check immediate dinosaur status
|
|
493
|
-
* const result = await
|
|
455
|
+
* const result = await builder
|
|
494
456
|
* .filter(op => op.eq('status', 'ACTIVE'))
|
|
495
457
|
* .consistentRead()
|
|
496
458
|
* .execute();
|
|
497
|
-
*
|
|
459
|
+
*
|
|
498
460
|
* // Monitor security breaches
|
|
499
|
-
* const result = await
|
|
461
|
+
* const result = await builder
|
|
500
462
|
* .useIndex('primary-index')
|
|
501
463
|
* .consistentRead(isEmergencyMode)
|
|
502
464
|
* .execute();
|
|
503
465
|
* ```
|
|
504
|
-
*
|
|
466
|
+
*
|
|
505
467
|
* @param consistentRead - Whether to use consistent reads (defaults to true)
|
|
506
468
|
* @returns The builder instance for method chaining
|
|
507
469
|
*/
|
|
@@ -510,54 +472,26 @@ var QueryBuilder = class _QueryBuilder {
|
|
|
510
472
|
return this;
|
|
511
473
|
}
|
|
512
474
|
/**
|
|
513
|
-
* Adds a filter expression to the
|
|
514
|
-
* Use this method when you need to:
|
|
515
|
-
* - Filter results based on non-key attributes
|
|
516
|
-
* - Apply complex filtering conditions
|
|
517
|
-
* - Combine multiple filter conditions
|
|
518
|
-
*
|
|
519
|
-
* Note: Filter expressions are applied after the key condition,
|
|
520
|
-
* so they don't reduce the amount of data read from DynamoDB.
|
|
521
|
-
*
|
|
522
|
-
* @example
|
|
523
|
-
* ```ts
|
|
524
|
-
* // Simple filter
|
|
525
|
-
* builder.filter(op => op.eq('status', 'ACTIVE'))
|
|
526
|
-
*
|
|
527
|
-
* // Complex filter with multiple conditions
|
|
528
|
-
* builder.filter(op =>
|
|
529
|
-
* op.and([
|
|
530
|
-
* op.gt('amount', 1000),
|
|
531
|
-
* op.beginsWith('category', 'ELECTRONICS'),
|
|
532
|
-
* op.attributeExists('reviewDate')
|
|
533
|
-
* ])
|
|
534
|
-
* )
|
|
535
|
-
* ```
|
|
536
|
-
*
|
|
537
|
-
* @param condition - Either a Condition object or a callback function that builds the condition
|
|
538
|
-
* @returns The builder instance for method chaining
|
|
539
|
-
*/
|
|
540
|
-
/**
|
|
541
|
-
* Adds a filter expression to refine the query results.
|
|
475
|
+
* Adds a filter expression to refine the operation results.
|
|
542
476
|
* Use this method when you need to:
|
|
543
477
|
* - Filter dinosaurs by behavior patterns
|
|
544
478
|
* - Find habitats with specific conditions
|
|
545
479
|
* - Search for security incidents
|
|
546
480
|
* - Monitor feeding patterns
|
|
547
|
-
*
|
|
481
|
+
*
|
|
548
482
|
* @example
|
|
549
483
|
* ```typescript
|
|
550
484
|
* // Find aggressive carnivores
|
|
551
|
-
* builder.filter(op =>
|
|
485
|
+
* builder.filter(op =>
|
|
552
486
|
* op.and([
|
|
553
487
|
* op.eq('diet', 'CARNIVORE'),
|
|
554
488
|
* op.gt('aggressionLevel', 7),
|
|
555
489
|
* op.eq('status', 'ACTIVE')
|
|
556
490
|
* ])
|
|
557
491
|
* );
|
|
558
|
-
*
|
|
492
|
+
*
|
|
559
493
|
* // Search suitable breeding habitats
|
|
560
|
-
* builder.filter(op =>
|
|
494
|
+
* builder.filter(op =>
|
|
561
495
|
* op.and([
|
|
562
496
|
* op.between('temperature', 25, 30),
|
|
563
497
|
* op.lt('currentOccupants', 3),
|
|
@@ -565,7 +499,7 @@ var QueryBuilder = class _QueryBuilder {
|
|
|
565
499
|
* ])
|
|
566
500
|
* );
|
|
567
501
|
* ```
|
|
568
|
-
*
|
|
502
|
+
*
|
|
569
503
|
* @param condition - Either a Condition object or a callback function that builds the condition
|
|
570
504
|
* @returns The builder instance for method chaining
|
|
571
505
|
*/
|
|
@@ -594,40 +528,13 @@ var QueryBuilder = class _QueryBuilder {
|
|
|
594
528
|
return this;
|
|
595
529
|
}
|
|
596
530
|
/**
|
|
597
|
-
* Specifies which attributes to return in the
|
|
598
|
-
* Use this method when you need to:
|
|
599
|
-
* - Reduce data transfer by selecting specific attributes
|
|
600
|
-
* - Optimize response size
|
|
601
|
-
* - Focus on relevant attributes only
|
|
602
|
-
*
|
|
603
|
-
* Note: Using projection can significantly reduce the amount
|
|
604
|
-
* of data returned and lower your costs.
|
|
605
|
-
*
|
|
606
|
-
* @example
|
|
607
|
-
* ```ts
|
|
608
|
-
* // Select single attribute
|
|
609
|
-
* builder.select('email')
|
|
610
|
-
*
|
|
611
|
-
* // Select multiple attributes
|
|
612
|
-
* builder.select(['id', 'name', 'email'])
|
|
613
|
-
*
|
|
614
|
-
* // Chain multiple select calls
|
|
615
|
-
* builder
|
|
616
|
-
* .select('id')
|
|
617
|
-
* .select(['name', 'email'])
|
|
618
|
-
* ```
|
|
619
|
-
*
|
|
620
|
-
* @param fields - A single field name or an array of field names to return
|
|
621
|
-
* @returns The builder instance for method chaining
|
|
622
|
-
*/
|
|
623
|
-
/**
|
|
624
|
-
* Specifies which attributes to return in the query results.
|
|
531
|
+
* Specifies which attributes to return in the results.
|
|
625
532
|
* Use this method when you need to:
|
|
626
533
|
* - Get specific dinosaur attributes
|
|
627
534
|
* - Retrieve habitat statistics
|
|
628
535
|
* - Monitor security metrics
|
|
629
536
|
* - Optimize response size
|
|
630
|
-
*
|
|
537
|
+
*
|
|
631
538
|
* @example
|
|
632
539
|
* ```typescript
|
|
633
540
|
* // Get basic dinosaur info
|
|
@@ -637,7 +544,7 @@ var QueryBuilder = class _QueryBuilder {
|
|
|
637
544
|
* 'stats.health',
|
|
638
545
|
* 'stats.aggressionLevel'
|
|
639
546
|
* ]);
|
|
640
|
-
*
|
|
547
|
+
*
|
|
641
548
|
* // Monitor habitat conditions
|
|
642
549
|
* builder
|
|
643
550
|
* .select('securityStatus')
|
|
@@ -647,7 +554,7 @@ var QueryBuilder = class _QueryBuilder {
|
|
|
647
554
|
* 'lastInspectionDate'
|
|
648
555
|
* ]);
|
|
649
556
|
* ```
|
|
650
|
-
*
|
|
557
|
+
*
|
|
651
558
|
* @param fields - A single field name or an array of field names to return
|
|
652
559
|
* @returns The builder instance for method chaining
|
|
653
560
|
*/
|
|
@@ -663,11 +570,86 @@ var QueryBuilder = class _QueryBuilder {
|
|
|
663
570
|
return this;
|
|
664
571
|
}
|
|
665
572
|
/**
|
|
666
|
-
*
|
|
573
|
+
* Creates a paginator that handles DynamoDB pagination automatically.
|
|
574
|
+
* The paginator handles:
|
|
575
|
+
* - Tracking the last evaluated key
|
|
576
|
+
* - Managing page boundaries
|
|
577
|
+
* - Respecting overall query limits
|
|
578
|
+
*
|
|
579
|
+
* @example
|
|
580
|
+
* ```typescript
|
|
581
|
+
* // Create a paginator for dinosaur records
|
|
582
|
+
* const paginator = builder
|
|
583
|
+
* .filter(op => op.eq('status', 'ACTIVE'))
|
|
584
|
+
* .paginate(10);
|
|
585
|
+
*
|
|
586
|
+
* // Process pages of dinosaur results
|
|
587
|
+
* while (paginator.hasNextPage()) {
|
|
588
|
+
* const page = await paginator.getNextPage();
|
|
589
|
+
* console.log(`Processing page ${page.page}, count: ${page.items.length}`);
|
|
590
|
+
* // Process dinosaur data
|
|
591
|
+
* }
|
|
592
|
+
* ```
|
|
593
|
+
*
|
|
594
|
+
* @param pageSize - The number of items to return per page
|
|
595
|
+
* @returns A Paginator instance that manages the pagination state
|
|
596
|
+
* @see Paginator for more pagination control options
|
|
597
|
+
*/
|
|
598
|
+
paginate(pageSize) {
|
|
599
|
+
return new Paginator(this, pageSize);
|
|
600
|
+
}
|
|
601
|
+
/**
|
|
602
|
+
* Sets the starting point using a previous lastEvaluatedKey.
|
|
667
603
|
* Use this method when you need to:
|
|
668
|
-
* -
|
|
669
|
-
* -
|
|
670
|
-
* -
|
|
604
|
+
* - Implement manual dinosaur list pagination
|
|
605
|
+
* - Resume habitat inspection reviews
|
|
606
|
+
* - Continue security incident analysis
|
|
607
|
+
* - Store operation position between sessions
|
|
608
|
+
*
|
|
609
|
+
* Note: This method is typically used for manual pagination.
|
|
610
|
+
* For automatic pagination, use the paginate() method instead.
|
|
611
|
+
*
|
|
612
|
+
* @example
|
|
613
|
+
* ```typescript
|
|
614
|
+
* // First batch of dinosaurs
|
|
615
|
+
* const result1 = await builder
|
|
616
|
+
* .filter(op => op.eq('status', 'ACTIVE'))
|
|
617
|
+
* .limit(5)
|
|
618
|
+
* .execute();
|
|
619
|
+
*
|
|
620
|
+
* if (result1.lastEvaluatedKey) {
|
|
621
|
+
* // Continue listing dinosaurs
|
|
622
|
+
* const result2 = await builder
|
|
623
|
+
* .filter(op => op.eq('status', 'ACTIVE'))
|
|
624
|
+
* .startFrom(result1.lastEvaluatedKey)
|
|
625
|
+
* .limit(5)
|
|
626
|
+
* .execute();
|
|
627
|
+
*
|
|
628
|
+
* console.log('Additional dinosaurs:', result2.items);
|
|
629
|
+
* }
|
|
630
|
+
* ```
|
|
631
|
+
*
|
|
632
|
+
* @param lastEvaluatedKey - The exclusive start key from a previous result
|
|
633
|
+
* @returns The builder instance for method chaining
|
|
634
|
+
*/
|
|
635
|
+
startFrom(lastEvaluatedKey) {
|
|
636
|
+
this.options.lastEvaluatedKey = lastEvaluatedKey;
|
|
637
|
+
return this;
|
|
638
|
+
}
|
|
639
|
+
};
|
|
640
|
+
|
|
641
|
+
// src/builders/query-builder.ts
|
|
642
|
+
var QueryBuilder = class _QueryBuilder extends FilterBuilder {
|
|
643
|
+
keyCondition;
|
|
644
|
+
options = {};
|
|
645
|
+
executor;
|
|
646
|
+
constructor(executor, keyCondition) {
|
|
647
|
+
super();
|
|
648
|
+
this.executor = executor;
|
|
649
|
+
this.keyCondition = keyCondition;
|
|
650
|
+
}
|
|
651
|
+
/**
|
|
652
|
+
* Sets the maximum number of items to return from the query.
|
|
671
653
|
*
|
|
672
654
|
* Note: This is the default behavior if no sort order is specified.
|
|
673
655
|
*
|
|
@@ -689,12 +671,7 @@ var QueryBuilder = class _QueryBuilder {
|
|
|
689
671
|
*/
|
|
690
672
|
/**
|
|
691
673
|
* Sets the query to return items in ascending order by sort key.
|
|
692
|
-
*
|
|
693
|
-
* - List dinosaurs by age (youngest first)
|
|
694
|
-
* - View incidents chronologically
|
|
695
|
-
* - Track feeding schedule progression
|
|
696
|
-
* - Monitor habitat inspections
|
|
697
|
-
*
|
|
674
|
+
*
|
|
698
675
|
* @example
|
|
699
676
|
* ```typescript
|
|
700
677
|
* // List dinosaurs by age
|
|
@@ -702,14 +679,14 @@ var QueryBuilder = class _QueryBuilder {
|
|
|
702
679
|
* .useIndex('age-index')
|
|
703
680
|
* .sortAscending()
|
|
704
681
|
* .execute();
|
|
705
|
-
*
|
|
682
|
+
*
|
|
706
683
|
* // View incidents chronologically
|
|
707
684
|
* const result = await new QueryBuilder(executor, eq('type', 'SECURITY_BREACH'))
|
|
708
685
|
* .useIndex('date-index')
|
|
709
686
|
* .sortAscending()
|
|
710
687
|
* .execute();
|
|
711
688
|
* ```
|
|
712
|
-
*
|
|
689
|
+
*
|
|
713
690
|
* @returns The builder instance for method chaining
|
|
714
691
|
*/
|
|
715
692
|
sortAscending() {
|
|
@@ -718,11 +695,6 @@ var QueryBuilder = class _QueryBuilder {
|
|
|
718
695
|
}
|
|
719
696
|
/**
|
|
720
697
|
* Sets the query to return items in descending order by sort key.
|
|
721
|
-
* Use this method when you need to:
|
|
722
|
-
* - Get most recent security breaches
|
|
723
|
-
* - Find oldest dinosaurs first
|
|
724
|
-
* - Check latest habitat modifications
|
|
725
|
-
* - Monitor recent feeding events
|
|
726
698
|
*
|
|
727
699
|
* @example
|
|
728
700
|
* ```typescript
|
|
@@ -732,7 +704,7 @@ var QueryBuilder = class _QueryBuilder {
|
|
|
732
704
|
* .sortDescending()
|
|
733
705
|
* .limit(10)
|
|
734
706
|
* .execute();
|
|
735
|
-
*
|
|
707
|
+
*
|
|
736
708
|
* // Check latest dinosaur activities
|
|
737
709
|
* const result = await new QueryBuilder(executor, eq('species', 'Velociraptor'))
|
|
738
710
|
* .useIndex('activity-time-index')
|
|
@@ -747,121 +719,37 @@ var QueryBuilder = class _QueryBuilder {
|
|
|
747
719
|
this.options.scanIndexForward = false;
|
|
748
720
|
return this;
|
|
749
721
|
}
|
|
750
|
-
/**
|
|
751
|
-
* Creates a paginator that handles DynamoDB pagination automatically.
|
|
752
|
-
* Use this method when you need to:
|
|
753
|
-
* - Browse large dinosaur collections
|
|
754
|
-
* - View habitat inspection history
|
|
755
|
-
* - Monitor security incidents
|
|
756
|
-
* - Track feeding patterns
|
|
757
|
-
*
|
|
758
|
-
* The paginator handles:
|
|
759
|
-
* - Tracking the last evaluated key
|
|
760
|
-
* - Managing page boundaries
|
|
761
|
-
* - Respecting overall query limits
|
|
762
|
-
*
|
|
763
|
-
* @example
|
|
764
|
-
* ```typescript
|
|
765
|
-
* // List dinosaurs by species
|
|
766
|
-
* const paginator = new QueryBuilder(executor, eq('species', 'Velociraptor'))
|
|
767
|
-
* .filter(op => op.eq('status', 'ACTIVE'))
|
|
768
|
-
* .useIndex('species-index')
|
|
769
|
-
* .paginate(10);
|
|
770
|
-
*
|
|
771
|
-
* // Process pages of security incidents
|
|
772
|
-
* const paginator = new QueryBuilder(executor, eq('type', 'SECURITY_BREACH'))
|
|
773
|
-
* .filter(op => op.gt('severityLevel', 7))
|
|
774
|
-
* .sortDescending()
|
|
775
|
-
* .paginate(25);
|
|
776
|
-
*
|
|
777
|
-
* while (paginator.hasNextPage()) {
|
|
778
|
-
* const page = await paginator.getNextPage();
|
|
779
|
-
* console.log(`Processing incidents page ${page.page}, count: ${page.items.length}`);
|
|
780
|
-
* // Handle security incidents
|
|
781
|
-
* }
|
|
782
|
-
* ```
|
|
783
|
-
*
|
|
784
|
-
* @param pageSize - The number of items to return per page
|
|
785
|
-
* @returns A Paginator instance that manages the pagination state
|
|
786
|
-
* @see Paginator for more pagination control options
|
|
787
|
-
*/
|
|
788
|
-
paginate(pageSize) {
|
|
789
|
-
return new Paginator(this, pageSize);
|
|
790
|
-
}
|
|
791
|
-
/**
|
|
792
|
-
* Sets the starting point for the query using a previous lastEvaluatedKey.
|
|
793
|
-
* Use this method when you need to:
|
|
794
|
-
* - Implement manual dinosaur list pagination
|
|
795
|
-
* - Resume habitat inspection reviews
|
|
796
|
-
* - Continue security incident analysis
|
|
797
|
-
* - Store query position between sessions
|
|
798
|
-
*
|
|
799
|
-
* Note: This method is typically used for manual pagination.
|
|
800
|
-
* For automatic pagination, use the paginate() method instead.
|
|
801
|
-
*
|
|
802
|
-
* @example
|
|
803
|
-
* ```typescript
|
|
804
|
-
* // First batch of dinosaurs
|
|
805
|
-
* const result1 = await new QueryBuilder(executor, eq('species', 'Velociraptor'))
|
|
806
|
-
* .filter(op => op.eq('status', 'ACTIVE'))
|
|
807
|
-
* .limit(5)
|
|
808
|
-
* .execute();
|
|
809
|
-
*
|
|
810
|
-
* if (result1.lastEvaluatedKey) {
|
|
811
|
-
* // Continue listing dinosaurs
|
|
812
|
-
* const result2 = await new QueryBuilder(executor, eq('species', 'Velociraptor'))
|
|
813
|
-
* .filter(op => op.eq('status', 'ACTIVE'))
|
|
814
|
-
* .startFrom(result1.lastEvaluatedKey)
|
|
815
|
-
* .limit(5)
|
|
816
|
-
* .execute();
|
|
817
|
-
*
|
|
818
|
-
* console.log('Additional dinosaurs:', result2.items);
|
|
819
|
-
* }
|
|
820
|
-
* ```
|
|
821
|
-
*
|
|
822
|
-
* @param lastEvaluatedKey - The exclusive start key from a previous query result
|
|
823
|
-
* @returns The builder instance for method chaining
|
|
824
|
-
*/
|
|
825
|
-
startFrom(lastEvaluatedKey) {
|
|
826
|
-
this.options.lastEvaluatedKey = lastEvaluatedKey;
|
|
827
|
-
return this;
|
|
828
|
-
}
|
|
829
722
|
/**
|
|
830
723
|
* Creates a deep clone of this QueryBuilder instance.
|
|
831
|
-
*
|
|
832
|
-
* - Query different dinosaur statuses
|
|
833
|
-
* - Check multiple habitat conditions
|
|
834
|
-
* - Monitor various security levels
|
|
835
|
-
* - Create report templates
|
|
836
|
-
*
|
|
724
|
+
*
|
|
837
725
|
* This is particularly useful when:
|
|
838
726
|
* - Implementing pagination (used internally by paginate())
|
|
839
727
|
* - Creating query templates
|
|
840
728
|
* - Running multiple variations of a query
|
|
841
|
-
*
|
|
729
|
+
*
|
|
842
730
|
* @example
|
|
843
731
|
* ```typescript
|
|
844
732
|
* // Create base dinosaur query
|
|
845
733
|
* const baseQuery = new QueryBuilder(executor, eq('species', 'Velociraptor'))
|
|
846
734
|
* .useIndex('status-index')
|
|
847
735
|
* .select(['id', 'status', 'location']);
|
|
848
|
-
*
|
|
736
|
+
*
|
|
849
737
|
* // Check active dinosaurs
|
|
850
738
|
* const activeRaptors = baseQuery.clone()
|
|
851
739
|
* .filter(op => op.eq('status', 'HUNTING'))
|
|
852
740
|
* .execute();
|
|
853
|
-
*
|
|
741
|
+
*
|
|
854
742
|
* // Check contained dinosaurs
|
|
855
743
|
* const containedRaptors = baseQuery.clone()
|
|
856
744
|
* .filter(op => op.eq('status', 'CONTAINED'))
|
|
857
745
|
* .execute();
|
|
858
|
-
*
|
|
746
|
+
*
|
|
859
747
|
* // Check sedated dinosaurs
|
|
860
748
|
* const sedatedRaptors = baseQuery.clone()
|
|
861
749
|
* .filter(op => op.eq('status', 'SEDATED'))
|
|
862
750
|
* .execute();
|
|
863
751
|
* ```
|
|
864
|
-
*
|
|
752
|
+
*
|
|
865
753
|
* @returns A new QueryBuilder instance with the same configuration
|
|
866
754
|
*/
|
|
867
755
|
clone() {
|
|
@@ -872,22 +760,17 @@ var QueryBuilder = class _QueryBuilder {
|
|
|
872
760
|
}
|
|
873
761
|
/**
|
|
874
762
|
* Executes the query against DynamoDB.
|
|
875
|
-
*
|
|
876
|
-
* - Find specific dinosaur groups
|
|
877
|
-
* - Check habitat conditions
|
|
878
|
-
* - Monitor security incidents
|
|
879
|
-
* - Track feeding patterns
|
|
880
|
-
*
|
|
763
|
+
*
|
|
881
764
|
* The method returns both the matched items and, if there are more results,
|
|
882
765
|
* a lastEvaluatedKey that can be used with startFrom() to continue the query.
|
|
883
|
-
*
|
|
766
|
+
*
|
|
884
767
|
* @example
|
|
885
768
|
* ```typescript
|
|
886
769
|
* try {
|
|
887
770
|
* // Find active carnivores in specific habitat
|
|
888
771
|
* const result = await new QueryBuilder(executor, eq('habitatId', 'PADDOCK-A'))
|
|
889
772
|
* .useIndex('species-status-index')
|
|
890
|
-
* .filter(op =>
|
|
773
|
+
* .filter(op =>
|
|
891
774
|
* op.and([
|
|
892
775
|
* op.eq('diet', 'CARNIVORE'),
|
|
893
776
|
* op.eq('status', 'ACTIVE'),
|
|
@@ -897,9 +780,9 @@ var QueryBuilder = class _QueryBuilder {
|
|
|
897
780
|
* .sortDescending()
|
|
898
781
|
* .limit(5)
|
|
899
782
|
* .execute();
|
|
900
|
-
*
|
|
783
|
+
*
|
|
901
784
|
* console.log(`Found ${result.items.length} dangerous dinosaurs`);
|
|
902
|
-
*
|
|
785
|
+
*
|
|
903
786
|
* if (result.lastEvaluatedKey) {
|
|
904
787
|
* console.log('Additional threats detected');
|
|
905
788
|
* }
|
|
@@ -907,7 +790,7 @@ var QueryBuilder = class _QueryBuilder {
|
|
|
907
790
|
* console.error('Security scan failed:', error);
|
|
908
791
|
* }
|
|
909
792
|
* ```
|
|
910
|
-
*
|
|
793
|
+
*
|
|
911
794
|
* @returns A promise that resolves to an object containing:
|
|
912
795
|
* - items: Array of items matching the query
|
|
913
796
|
* - lastEvaluatedKey: Token for continuing the query, if more items exist
|
|
@@ -967,13 +850,16 @@ function debugCommand(command) {
|
|
|
967
850
|
// src/builders/put-builder.ts
|
|
968
851
|
var PutBuilder = class {
|
|
969
852
|
item;
|
|
970
|
-
options
|
|
853
|
+
options;
|
|
971
854
|
executor;
|
|
972
855
|
tableName;
|
|
973
856
|
constructor(executor, item, tableName) {
|
|
974
857
|
this.executor = executor;
|
|
975
858
|
this.item = item;
|
|
976
859
|
this.tableName = tableName;
|
|
860
|
+
this.options = {
|
|
861
|
+
returnValues: "NONE"
|
|
862
|
+
};
|
|
977
863
|
}
|
|
978
864
|
/**
|
|
979
865
|
* Adds a condition that must be satisfied for the put operation to succeed.
|
|
@@ -1002,10 +888,6 @@ var PutBuilder = class {
|
|
|
1002
888
|
*/
|
|
1003
889
|
/**
|
|
1004
890
|
* Adds a condition that must be satisfied for the put operation to succeed.
|
|
1005
|
-
* Use this method when you need to:
|
|
1006
|
-
* - Prevent duplicate dinosaur entries
|
|
1007
|
-
* - Ensure habitat requirements
|
|
1008
|
-
* - Validate security protocols
|
|
1009
891
|
*
|
|
1010
892
|
* @example
|
|
1011
893
|
* ```typescript
|
|
@@ -1062,10 +944,11 @@ var PutBuilder = class {
|
|
|
1062
944
|
}
|
|
1063
945
|
/**
|
|
1064
946
|
* Sets whether to return the item's previous values (if it existed).
|
|
1065
|
-
*
|
|
1066
|
-
*
|
|
1067
|
-
*
|
|
1068
|
-
*
|
|
947
|
+
*
|
|
948
|
+
* @options
|
|
949
|
+
* - NONE: No return value
|
|
950
|
+
* - ALL_OLD: Returns the item's previous state if it existed, no read capacity units are consumed
|
|
951
|
+
* - CONSISTENT: (default) Performs a GET operation after the put to retrieve the item's new state
|
|
1069
952
|
*
|
|
1070
953
|
* @example
|
|
1071
954
|
* ```ts
|
|
@@ -1086,7 +969,7 @@ var PutBuilder = class {
|
|
|
1086
969
|
* }
|
|
1087
970
|
* ```
|
|
1088
971
|
*
|
|
1089
|
-
* @param returnValues - Use 'ALL_OLD' to return previous values, or 'NONE' (default)
|
|
972
|
+
* @param returnValues - Use 'ALL_OLD' to return previous values if the item was overwritten, or 'NONE' (default).
|
|
1090
973
|
* @returns The builder instance for method chaining
|
|
1091
974
|
*/
|
|
1092
975
|
returnValues(returnValues) {
|
|
@@ -1174,11 +1057,6 @@ var PutBuilder = class {
|
|
|
1174
1057
|
/**
|
|
1175
1058
|
* Gets a human-readable representation of the put command
|
|
1176
1059
|
* with all expression placeholders replaced by their actual values.
|
|
1177
|
-
* Use this method when you need to:
|
|
1178
|
-
* - Debug complex dinosaur transfers
|
|
1179
|
-
* - Verify habitat assignments
|
|
1180
|
-
* - Log security protocols
|
|
1181
|
-
* - Troubleshoot breeding program conditions
|
|
1182
1060
|
*
|
|
1183
1061
|
* @example
|
|
1184
1062
|
* ```ts
|
|
@@ -1447,20 +1325,20 @@ var UpdateBuilder = class {
|
|
|
1447
1325
|
* - Delete attributes completely
|
|
1448
1326
|
* - Remove nested attributes
|
|
1449
1327
|
* - Clean up deprecated fields
|
|
1450
|
-
*
|
|
1328
|
+
*
|
|
1451
1329
|
* @example
|
|
1452
1330
|
* ```typescript
|
|
1453
1331
|
* // Remove simple attributes
|
|
1454
1332
|
* builder
|
|
1455
1333
|
* .remove('temporaryTag')
|
|
1456
1334
|
* .remove('previousLocation');
|
|
1457
|
-
*
|
|
1335
|
+
*
|
|
1458
1336
|
* // Remove nested attributes
|
|
1459
1337
|
* builder
|
|
1460
1338
|
* .remove('metadata.testData')
|
|
1461
1339
|
* .remove('stats.experimentalMetrics');
|
|
1462
1340
|
* ```
|
|
1463
|
-
*
|
|
1341
|
+
*
|
|
1464
1342
|
* @param path - The path to the attribute to remove
|
|
1465
1343
|
* @returns The builder instance for method chaining
|
|
1466
1344
|
*/
|
|
@@ -1477,20 +1355,20 @@ var UpdateBuilder = class {
|
|
|
1477
1355
|
* - Increment counters
|
|
1478
1356
|
* - Add elements to a set atomically
|
|
1479
1357
|
* - Update numerical statistics
|
|
1480
|
-
*
|
|
1358
|
+
*
|
|
1481
1359
|
* @example
|
|
1482
1360
|
* ```typescript
|
|
1483
1361
|
* // Increment counters
|
|
1484
1362
|
* builder
|
|
1485
1363
|
* .add('escapeAttempts', 1)
|
|
1486
1364
|
* .add('feedingCount', 1);
|
|
1487
|
-
*
|
|
1365
|
+
*
|
|
1488
1366
|
* // Add to sets
|
|
1489
1367
|
* builder
|
|
1490
1368
|
* .add('knownBehaviors', new Set(['PACK_HUNTING', 'AMBUSH_TACTICS']))
|
|
1491
1369
|
* .add('visitedZones', new Set(['ZONE_A', 'ZONE_B']));
|
|
1492
1370
|
* ```
|
|
1493
|
-
*
|
|
1371
|
+
*
|
|
1494
1372
|
* @param path - The path to the attribute to update
|
|
1495
1373
|
* @param value - The value to add (number or set)
|
|
1496
1374
|
* @returns The builder instance for method chaining
|
|
@@ -1509,7 +1387,7 @@ var UpdateBuilder = class {
|
|
|
1509
1387
|
* - Remove specific elements from a set
|
|
1510
1388
|
* - Update set-based attributes atomically
|
|
1511
1389
|
* - Maintain set membership
|
|
1512
|
-
*
|
|
1390
|
+
*
|
|
1513
1391
|
* @example
|
|
1514
1392
|
* ```typescript
|
|
1515
1393
|
* // Remove from sets using arrays
|
|
@@ -1517,20 +1395,20 @@ var UpdateBuilder = class {
|
|
|
1517
1395
|
* 'allowedHabitats',
|
|
1518
1396
|
* ['JUNGLE', 'COASTAL']
|
|
1519
1397
|
* );
|
|
1520
|
-
*
|
|
1398
|
+
*
|
|
1521
1399
|
* // Remove from sets using Set objects
|
|
1522
1400
|
* builder.deleteElementsFromSet(
|
|
1523
1401
|
* 'knownBehaviors',
|
|
1524
1402
|
* new Set(['NOCTURNAL', 'TERRITORIAL'])
|
|
1525
1403
|
* );
|
|
1526
|
-
*
|
|
1404
|
+
*
|
|
1527
1405
|
* // Remove from nested sets
|
|
1528
1406
|
* builder.deleteElementsFromSet(
|
|
1529
1407
|
* 'stats.compatibleSpecies',
|
|
1530
1408
|
* ['VELOCIRAPTOR', 'DILOPHOSAURUS']
|
|
1531
1409
|
* );
|
|
1532
1410
|
* ```
|
|
1533
|
-
*
|
|
1411
|
+
*
|
|
1534
1412
|
* @param path - The path to the set attribute
|
|
1535
1413
|
* @param value - Elements to remove (array or Set)
|
|
1536
1414
|
* @returns The builder instance for method chaining
|
|
@@ -1556,37 +1434,37 @@ var UpdateBuilder = class {
|
|
|
1556
1434
|
* - Ensure item state before update
|
|
1557
1435
|
* - Validate business rules
|
|
1558
1436
|
* - Prevent concurrent modifications
|
|
1559
|
-
*
|
|
1437
|
+
*
|
|
1560
1438
|
* @example
|
|
1561
1439
|
* ```typescript
|
|
1562
1440
|
* // Simple condition
|
|
1563
|
-
* builder.condition(op =>
|
|
1441
|
+
* builder.condition(op =>
|
|
1564
1442
|
* op.eq('status', 'ACTIVE')
|
|
1565
1443
|
* );
|
|
1566
|
-
*
|
|
1444
|
+
*
|
|
1567
1445
|
* // Health check condition
|
|
1568
|
-
* builder.condition(op =>
|
|
1446
|
+
* builder.condition(op =>
|
|
1569
1447
|
* op.and([
|
|
1570
1448
|
* op.gt('health', 50),
|
|
1571
1449
|
* op.eq('status', 'HUNTING')
|
|
1572
1450
|
* ])
|
|
1573
1451
|
* );
|
|
1574
|
-
*
|
|
1452
|
+
*
|
|
1575
1453
|
* // Complex security condition
|
|
1576
|
-
* builder.condition(op =>
|
|
1454
|
+
* builder.condition(op =>
|
|
1577
1455
|
* op.and([
|
|
1578
1456
|
* op.attributeExists('securitySystem'),
|
|
1579
1457
|
* op.eq('containmentStatus', 'SECURE'),
|
|
1580
1458
|
* op.lt('aggressionLevel', 8)
|
|
1581
1459
|
* ])
|
|
1582
1460
|
* );
|
|
1583
|
-
*
|
|
1461
|
+
*
|
|
1584
1462
|
* // Version check (optimistic locking)
|
|
1585
|
-
* builder.condition(op =>
|
|
1463
|
+
* builder.condition(op =>
|
|
1586
1464
|
* op.eq('version', currentVersion)
|
|
1587
1465
|
* );
|
|
1588
1466
|
* ```
|
|
1589
|
-
*
|
|
1467
|
+
*
|
|
1590
1468
|
* @param condition - Either a Condition object or a callback function that builds the condition
|
|
1591
1469
|
* @returns The builder instance for method chaining
|
|
1592
1470
|
*/
|
|
@@ -1621,14 +1499,14 @@ var UpdateBuilder = class {
|
|
|
1621
1499
|
* - Track changes to specific attributes
|
|
1622
1500
|
* - Compare old and new values
|
|
1623
1501
|
* - Monitor attribute modifications
|
|
1624
|
-
*
|
|
1502
|
+
*
|
|
1625
1503
|
* Available options:
|
|
1626
1504
|
* - ALL_NEW: All attributes after the update
|
|
1627
1505
|
* - UPDATED_NEW: Only updated attributes, new values
|
|
1628
1506
|
* - ALL_OLD: All attributes before the update
|
|
1629
1507
|
* - UPDATED_OLD: Only updated attributes, old values
|
|
1630
1508
|
* - NONE: No attributes returned (default)
|
|
1631
|
-
*
|
|
1509
|
+
*
|
|
1632
1510
|
* @example
|
|
1633
1511
|
* ```typescript
|
|
1634
1512
|
* // Get complete updated dinosaur
|
|
@@ -1636,7 +1514,7 @@ var UpdateBuilder = class {
|
|
|
1636
1514
|
* .set('status', 'SLEEPING')
|
|
1637
1515
|
* .returnValues('ALL_NEW')
|
|
1638
1516
|
* .execute();
|
|
1639
|
-
*
|
|
1517
|
+
*
|
|
1640
1518
|
* // Track specific attribute changes
|
|
1641
1519
|
* const result = await builder
|
|
1642
1520
|
* .set({
|
|
@@ -1645,12 +1523,12 @@ var UpdateBuilder = class {
|
|
|
1645
1523
|
* })
|
|
1646
1524
|
* .returnValues('UPDATED_OLD')
|
|
1647
1525
|
* .execute();
|
|
1648
|
-
*
|
|
1526
|
+
*
|
|
1649
1527
|
* if (result.item) {
|
|
1650
1528
|
* console.log('Previous health:', result.item.stats?.health);
|
|
1651
1529
|
* }
|
|
1652
1530
|
* ```
|
|
1653
|
-
*
|
|
1531
|
+
*
|
|
1654
1532
|
* @param returnValues - Which attributes to return in the response
|
|
1655
1533
|
* @returns The builder instance for method chaining
|
|
1656
1534
|
*/
|
|
@@ -1752,26 +1630,26 @@ var UpdateBuilder = class {
|
|
|
1752
1630
|
* - Update items as part of a larger transaction
|
|
1753
1631
|
* - Ensure multiple updates are atomic
|
|
1754
1632
|
* - Coordinate updates across multiple items
|
|
1755
|
-
*
|
|
1633
|
+
*
|
|
1756
1634
|
* @example
|
|
1757
1635
|
* ```typescript
|
|
1758
1636
|
* const transaction = new TransactionBuilder(executor);
|
|
1759
|
-
*
|
|
1637
|
+
*
|
|
1760
1638
|
* // Update dinosaur status and habitat occupancy atomically
|
|
1761
1639
|
* new UpdateBuilder(executor, 'dinosaurs', { id: 'TREX-001' })
|
|
1762
1640
|
* .set('location', 'PADDOCK_A')
|
|
1763
1641
|
* .set('status', 'CONTAINED')
|
|
1764
1642
|
* .withTransaction(transaction);
|
|
1765
|
-
*
|
|
1643
|
+
*
|
|
1766
1644
|
* new UpdateBuilder(executor, 'habitats', { id: 'PADDOCK-A' })
|
|
1767
1645
|
* .add('occupants', 1)
|
|
1768
1646
|
* .set('lastOccupied', new Date().toISOString())
|
|
1769
1647
|
* .withTransaction(transaction);
|
|
1770
|
-
*
|
|
1648
|
+
*
|
|
1771
1649
|
* // Execute all operations atomically
|
|
1772
1650
|
* await transaction.execute();
|
|
1773
1651
|
* ```
|
|
1774
|
-
*
|
|
1652
|
+
*
|
|
1775
1653
|
* @param transaction - The transaction builder to add this operation to
|
|
1776
1654
|
* @returns The builder instance for method chaining
|
|
1777
1655
|
*/
|
|
@@ -1786,7 +1664,7 @@ var UpdateBuilder = class {
|
|
|
1786
1664
|
* - Verify attribute names and values
|
|
1787
1665
|
* - Log update operations
|
|
1788
1666
|
* - Troubleshoot condition expressions
|
|
1789
|
-
*
|
|
1667
|
+
*
|
|
1790
1668
|
* @example
|
|
1791
1669
|
* ```typescript
|
|
1792
1670
|
* // Create complex update
|
|
@@ -1798,12 +1676,12 @@ var UpdateBuilder = class {
|
|
|
1798
1676
|
* })
|
|
1799
1677
|
* .add('huntingSuccesses', 1)
|
|
1800
1678
|
* .condition(op => op.gt('health', 50));
|
|
1801
|
-
*
|
|
1679
|
+
*
|
|
1802
1680
|
* // Debug the update
|
|
1803
1681
|
* const debugInfo = builder.debug();
|
|
1804
1682
|
* console.log('Update operation:', debugInfo);
|
|
1805
1683
|
* ```
|
|
1806
|
-
*
|
|
1684
|
+
*
|
|
1807
1685
|
* @returns A readable representation of the update command with resolved expressions
|
|
1808
1686
|
*/
|
|
1809
1687
|
debug() {
|
|
@@ -1816,7 +1694,7 @@ var UpdateBuilder = class {
|
|
|
1816
1694
|
* - Apply updates immediately
|
|
1817
1695
|
* - Get the updated item values
|
|
1818
1696
|
* - Handle conditional update failures
|
|
1819
|
-
*
|
|
1697
|
+
*
|
|
1820
1698
|
* @example
|
|
1821
1699
|
* ```typescript
|
|
1822
1700
|
* try {
|
|
@@ -1828,7 +1706,7 @@ var UpdateBuilder = class {
|
|
|
1828
1706
|
* 'stats.hunger': 0
|
|
1829
1707
|
* })
|
|
1830
1708
|
* .add('feedingCount', 1)
|
|
1831
|
-
* .condition(op =>
|
|
1709
|
+
* .condition(op =>
|
|
1832
1710
|
* op.and([
|
|
1833
1711
|
* op.gt('stats.hunger', 80),
|
|
1834
1712
|
* op.eq('status', 'HUNTING')
|
|
@@ -1836,7 +1714,7 @@ var UpdateBuilder = class {
|
|
|
1836
1714
|
* )
|
|
1837
1715
|
* .returnValues('ALL_NEW')
|
|
1838
1716
|
* .execute();
|
|
1839
|
-
*
|
|
1717
|
+
*
|
|
1840
1718
|
* if (result.item) {
|
|
1841
1719
|
* console.log('Updated dinosaur:', result.item);
|
|
1842
1720
|
* }
|
|
@@ -1849,7 +1727,7 @@ var UpdateBuilder = class {
|
|
|
1849
1727
|
* }
|
|
1850
1728
|
* }
|
|
1851
1729
|
* ```
|
|
1852
|
-
*
|
|
1730
|
+
*
|
|
1853
1731
|
* @returns A promise that resolves to an object containing the updated item (if returnValues is set)
|
|
1854
1732
|
* @throws {ConditionalCheckFailedException} If the condition check fails
|
|
1855
1733
|
* @throws {Error} If the update operation fails for other reasons
|
|
@@ -1951,10 +1829,10 @@ var TransactionBuilder = class {
|
|
|
1951
1829
|
* - Insert new items as part of a transaction
|
|
1952
1830
|
* - Replace existing items atomically
|
|
1953
1831
|
* - Ensure items meet certain conditions before insertion
|
|
1954
|
-
*
|
|
1832
|
+
*
|
|
1955
1833
|
* The method automatically checks for duplicate items within the transaction
|
|
1956
1834
|
* to prevent multiple operations on the same item.
|
|
1957
|
-
*
|
|
1835
|
+
*
|
|
1958
1836
|
* @example
|
|
1959
1837
|
* ```typescript
|
|
1960
1838
|
* // Simple put operation
|
|
@@ -1963,14 +1841,14 @@ var TransactionBuilder = class {
|
|
|
1963
1841
|
* status: 'PENDING',
|
|
1964
1842
|
* amount: 100
|
|
1965
1843
|
* });
|
|
1966
|
-
*
|
|
1844
|
+
*
|
|
1967
1845
|
* // Conditional put operation
|
|
1968
1846
|
* transaction.put(
|
|
1969
1847
|
* 'inventory',
|
|
1970
1848
|
* { productId: 'ABC', quantity: 50 },
|
|
1971
1849
|
* op => op.attributeNotExists('productId')
|
|
1972
1850
|
* );
|
|
1973
|
-
*
|
|
1851
|
+
*
|
|
1974
1852
|
* // Put with complex condition
|
|
1975
1853
|
* transaction.put(
|
|
1976
1854
|
* 'users',
|
|
@@ -1981,7 +1859,7 @@ var TransactionBuilder = class {
|
|
|
1981
1859
|
* ])
|
|
1982
1860
|
* );
|
|
1983
1861
|
* ```
|
|
1984
|
-
*
|
|
1862
|
+
*
|
|
1985
1863
|
* @param tableName - The name of the DynamoDB table
|
|
1986
1864
|
* @param item - The item to put into the table
|
|
1987
1865
|
* @param condition - Optional condition that must be satisfied
|
|
@@ -2012,21 +1890,21 @@ var TransactionBuilder = class {
|
|
|
2012
1890
|
* - Reuse put commands from PutBuilder
|
|
2013
1891
|
* - Add complex put operations with pre-configured parameters
|
|
2014
1892
|
* - Integrate with existing put command configurations
|
|
2015
|
-
*
|
|
1893
|
+
*
|
|
2016
1894
|
* This method is particularly useful when working with PutBuilder
|
|
2017
1895
|
* to maintain consistency in put operations across your application.
|
|
2018
|
-
*
|
|
1896
|
+
*
|
|
2019
1897
|
* @example
|
|
2020
1898
|
* ```typescript
|
|
2021
1899
|
* // Create a put command with PutBuilder
|
|
2022
1900
|
* const putCommand = new PutBuilder(executor, newItem, 'users')
|
|
2023
1901
|
* .condition(op => op.attributeNotExists('userId'))
|
|
2024
1902
|
* .toDynamoCommand();
|
|
2025
|
-
*
|
|
1903
|
+
*
|
|
2026
1904
|
* // Add the command to the transaction
|
|
2027
1905
|
* transaction.putWithCommand(putCommand);
|
|
2028
1906
|
* ```
|
|
2029
|
-
*
|
|
1907
|
+
*
|
|
2030
1908
|
* @param command - The complete put command configuration
|
|
2031
1909
|
* @returns The transaction builder for method chaining
|
|
2032
1910
|
* @throws {Error} If a duplicate item is detected in the transaction
|
|
@@ -2047,10 +1925,10 @@ var TransactionBuilder = class {
|
|
|
2047
1925
|
* - Remove items as part of a transaction
|
|
2048
1926
|
* - Conditionally delete items
|
|
2049
1927
|
* - Ensure items exist before deletion
|
|
2050
|
-
*
|
|
1928
|
+
*
|
|
2051
1929
|
* The method automatically checks for duplicate items within the transaction
|
|
2052
1930
|
* to prevent multiple operations on the same item.
|
|
2053
|
-
*
|
|
1931
|
+
*
|
|
2054
1932
|
* @example
|
|
2055
1933
|
* ```typescript
|
|
2056
1934
|
* // Simple delete operation
|
|
@@ -2058,14 +1936,14 @@ var TransactionBuilder = class {
|
|
|
2058
1936
|
* pk: 'ORDER#123',
|
|
2059
1937
|
* sk: 'METADATA'
|
|
2060
1938
|
* });
|
|
2061
|
-
*
|
|
1939
|
+
*
|
|
2062
1940
|
* // Conditional delete operation
|
|
2063
1941
|
* transaction.delete(
|
|
2064
1942
|
* 'users',
|
|
2065
1943
|
* { pk: 'USER#123' },
|
|
2066
1944
|
* op => op.eq('status', 'INACTIVE')
|
|
2067
1945
|
* );
|
|
2068
|
-
*
|
|
1946
|
+
*
|
|
2069
1947
|
* // Delete with complex condition
|
|
2070
1948
|
* transaction.delete(
|
|
2071
1949
|
* 'products',
|
|
@@ -2076,7 +1954,7 @@ var TransactionBuilder = class {
|
|
|
2076
1954
|
* ])
|
|
2077
1955
|
* );
|
|
2078
1956
|
* ```
|
|
2079
|
-
*
|
|
1957
|
+
*
|
|
2080
1958
|
* @param tableName - The name of the DynamoDB table
|
|
2081
1959
|
* @param key - The primary key of the item to delete
|
|
2082
1960
|
* @param condition - Optional condition that must be satisfied
|
|
@@ -2110,10 +1988,10 @@ var TransactionBuilder = class {
|
|
|
2110
1988
|
* - Reuse delete commands from DeleteBuilder
|
|
2111
1989
|
* - Add complex delete operations with pre-configured parameters
|
|
2112
1990
|
* - Integrate with existing delete command configurations
|
|
2113
|
-
*
|
|
1991
|
+
*
|
|
2114
1992
|
* This method is particularly useful when working with DeleteBuilder
|
|
2115
1993
|
* to maintain consistency in delete operations across your application.
|
|
2116
|
-
*
|
|
1994
|
+
*
|
|
2117
1995
|
* @example
|
|
2118
1996
|
* ```typescript
|
|
2119
1997
|
* // Create a delete command with DeleteBuilder
|
|
@@ -2123,11 +2001,11 @@ var TransactionBuilder = class {
|
|
|
2123
2001
|
* op.eq('status', 'INACTIVE')
|
|
2124
2002
|
* ]))
|
|
2125
2003
|
* .toDynamoCommand();
|
|
2126
|
-
*
|
|
2004
|
+
*
|
|
2127
2005
|
* // Add the command to the transaction
|
|
2128
2006
|
* transaction.deleteWithCommand(deleteCommand);
|
|
2129
2007
|
* ```
|
|
2130
|
-
*
|
|
2008
|
+
*
|
|
2131
2009
|
* @param command - The complete delete command configuration
|
|
2132
2010
|
* @returns The transaction builder for method chaining
|
|
2133
2011
|
* @throws {Error} If a duplicate item is detected in the transaction
|
|
@@ -2149,13 +2027,13 @@ var TransactionBuilder = class {
|
|
|
2149
2027
|
* - Update multiple attributes atomically
|
|
2150
2028
|
* - Apply conditional updates
|
|
2151
2029
|
* - Perform complex attribute manipulations
|
|
2152
|
-
*
|
|
2030
|
+
*
|
|
2153
2031
|
* The method supports all DynamoDB update expressions:
|
|
2154
2032
|
* - SET: Modify or add attributes
|
|
2155
2033
|
* - REMOVE: Delete attributes
|
|
2156
2034
|
* - ADD: Update numbers and sets
|
|
2157
2035
|
* - DELETE: Remove elements from a set
|
|
2158
|
-
*
|
|
2036
|
+
*
|
|
2159
2037
|
* @example
|
|
2160
2038
|
* ```typescript
|
|
2161
2039
|
* // Simple update
|
|
@@ -2166,7 +2044,7 @@ var TransactionBuilder = class {
|
|
|
2166
2044
|
* { '#status': 'status' },
|
|
2167
2045
|
* { ':status': 'PROCESSING' }
|
|
2168
2046
|
* );
|
|
2169
|
-
*
|
|
2047
|
+
*
|
|
2170
2048
|
* // Complex update with multiple operations
|
|
2171
2049
|
* transaction.update(
|
|
2172
2050
|
* 'products',
|
|
@@ -2175,7 +2053,7 @@ var TransactionBuilder = class {
|
|
|
2175
2053
|
* { '#qty': 'quantity', '#status': 'status', '#oldAttr': 'deprecated_field' },
|
|
2176
2054
|
* { ':amount': 1, ':status': 'LOW_STOCK' }
|
|
2177
2055
|
* );
|
|
2178
|
-
*
|
|
2056
|
+
*
|
|
2179
2057
|
* // Conditional update
|
|
2180
2058
|
* transaction.update(
|
|
2181
2059
|
* 'users',
|
|
@@ -2186,7 +2064,7 @@ var TransactionBuilder = class {
|
|
|
2186
2064
|
* op => op.attributeExists('pk')
|
|
2187
2065
|
* );
|
|
2188
2066
|
* ```
|
|
2189
|
-
*
|
|
2067
|
+
*
|
|
2190
2068
|
* @param tableName - The name of the DynamoDB table
|
|
2191
2069
|
* @param key - The primary key of the item to update
|
|
2192
2070
|
* @param updateExpression - The update expression (SET, REMOVE, ADD, DELETE)
|
|
@@ -2232,10 +2110,10 @@ var TransactionBuilder = class {
|
|
|
2232
2110
|
* - Reuse update commands from UpdateBuilder
|
|
2233
2111
|
* - Add complex update operations with pre-configured parameters
|
|
2234
2112
|
* - Integrate with existing update command configurations
|
|
2235
|
-
*
|
|
2113
|
+
*
|
|
2236
2114
|
* This method is particularly useful when working with UpdateBuilder
|
|
2237
2115
|
* to maintain consistency in update operations across your application.
|
|
2238
|
-
*
|
|
2116
|
+
*
|
|
2239
2117
|
* @example
|
|
2240
2118
|
* ```typescript
|
|
2241
2119
|
* // Create an update command with UpdateBuilder
|
|
@@ -2248,11 +2126,11 @@ var TransactionBuilder = class {
|
|
|
2248
2126
|
* })
|
|
2249
2127
|
* .condition(op => op.gt('quantity', 0))
|
|
2250
2128
|
* .toDynamoCommand();
|
|
2251
|
-
*
|
|
2129
|
+
*
|
|
2252
2130
|
* // Add the command to the transaction
|
|
2253
2131
|
* transaction.updateWithCommand(updateCommand);
|
|
2254
2132
|
* ```
|
|
2255
|
-
*
|
|
2133
|
+
*
|
|
2256
2134
|
* @param command - The complete update command configuration
|
|
2257
2135
|
* @returns The transaction builder for method chaining
|
|
2258
2136
|
* @throws {Error} If a duplicate item is detected in the transaction
|
|
@@ -2274,12 +2152,12 @@ var TransactionBuilder = class {
|
|
|
2274
2152
|
* - Ensure data consistency across tables
|
|
2275
2153
|
* - Implement complex business rules
|
|
2276
2154
|
* - Verify preconditions for other operations
|
|
2277
|
-
*
|
|
2155
|
+
*
|
|
2278
2156
|
* Condition checks are particularly useful for:
|
|
2279
2157
|
* - Implementing optimistic locking
|
|
2280
2158
|
* - Ensuring referential integrity
|
|
2281
2159
|
* - Validating business rules atomically
|
|
2282
|
-
*
|
|
2160
|
+
*
|
|
2283
2161
|
* @example
|
|
2284
2162
|
* ```typescript
|
|
2285
2163
|
* // Check if order is in correct state
|
|
@@ -2288,7 +2166,7 @@ var TransactionBuilder = class {
|
|
|
2288
2166
|
* { pk: 'ORDER#123' },
|
|
2289
2167
|
* op => op.eq('status', 'PENDING')
|
|
2290
2168
|
* );
|
|
2291
|
-
*
|
|
2169
|
+
*
|
|
2292
2170
|
* // Complex condition check
|
|
2293
2171
|
* transaction.conditionCheck(
|
|
2294
2172
|
* 'inventory',
|
|
@@ -2299,7 +2177,7 @@ var TransactionBuilder = class {
|
|
|
2299
2177
|
* op.attributeExists('lastRestockDate')
|
|
2300
2178
|
* ])
|
|
2301
2179
|
* );
|
|
2302
|
-
*
|
|
2180
|
+
*
|
|
2303
2181
|
* // Check with multiple attributes
|
|
2304
2182
|
* transaction.conditionCheck(
|
|
2305
2183
|
* 'users',
|
|
@@ -2310,7 +2188,7 @@ var TransactionBuilder = class {
|
|
|
2310
2188
|
* ])
|
|
2311
2189
|
* );
|
|
2312
2190
|
* ```
|
|
2313
|
-
*
|
|
2191
|
+
*
|
|
2314
2192
|
* @param tableName - The name of the DynamoDB table
|
|
2315
2193
|
* @param key - The primary key of the item to check
|
|
2316
2194
|
* @param condition - The condition that must be satisfied
|
|
@@ -2346,10 +2224,10 @@ var TransactionBuilder = class {
|
|
|
2346
2224
|
* - Reuse condition checks from ConditionCheckBuilder
|
|
2347
2225
|
* - Add complex condition checks with pre-configured parameters
|
|
2348
2226
|
* - Integrate with existing condition check configurations
|
|
2349
|
-
*
|
|
2227
|
+
*
|
|
2350
2228
|
* This method is particularly useful when working with ConditionCheckBuilder
|
|
2351
2229
|
* to maintain consistency in condition checks across your application.
|
|
2352
|
-
*
|
|
2230
|
+
*
|
|
2353
2231
|
* @example
|
|
2354
2232
|
* ```typescript
|
|
2355
2233
|
* // Create a condition check with ConditionCheckBuilder
|
|
@@ -2360,11 +2238,11 @@ var TransactionBuilder = class {
|
|
|
2360
2238
|
* op.attributeExists('lastAuditDate')
|
|
2361
2239
|
* ]))
|
|
2362
2240
|
* .toDynamoCommand();
|
|
2363
|
-
*
|
|
2241
|
+
*
|
|
2364
2242
|
* // Add the command to the transaction
|
|
2365
2243
|
* transaction.conditionCheckWithCommand(checkCommand);
|
|
2366
2244
|
* ```
|
|
2367
|
-
*
|
|
2245
|
+
*
|
|
2368
2246
|
* @param command - The complete condition check command configuration
|
|
2369
2247
|
* @returns The transaction builder for method chaining
|
|
2370
2248
|
* @throws {Error} If a duplicate item is detected in the transaction
|
|
@@ -2385,7 +2263,7 @@ var TransactionBuilder = class {
|
|
|
2385
2263
|
* - Enable idempotent transactions
|
|
2386
2264
|
* - Track consumed capacity
|
|
2387
2265
|
* - Monitor item collection metrics
|
|
2388
|
-
*
|
|
2266
|
+
*
|
|
2389
2267
|
* @example
|
|
2390
2268
|
* ```typescript
|
|
2391
2269
|
* // Enable idempotency and capacity tracking
|
|
@@ -2393,16 +2271,16 @@ var TransactionBuilder = class {
|
|
|
2393
2271
|
* clientRequestToken: 'unique-request-id-123',
|
|
2394
2272
|
* returnConsumedCapacity: 'TOTAL'
|
|
2395
2273
|
* });
|
|
2396
|
-
*
|
|
2274
|
+
*
|
|
2397
2275
|
* // Track item collection metrics
|
|
2398
2276
|
* transaction.withOptions({
|
|
2399
2277
|
* returnItemCollectionMetrics: 'SIZE'
|
|
2400
2278
|
* });
|
|
2401
2279
|
* ```
|
|
2402
|
-
*
|
|
2280
|
+
*
|
|
2403
2281
|
* Note: ClientRequestToken can be used to make transactions idempotent,
|
|
2404
2282
|
* ensuring the same transaction is not executed multiple times.
|
|
2405
|
-
*
|
|
2283
|
+
*
|
|
2406
2284
|
* @param options - Configuration options for the transaction
|
|
2407
2285
|
* @returns The transaction builder for method chaining
|
|
2408
2286
|
*/
|
|
@@ -2417,27 +2295,27 @@ var TransactionBuilder = class {
|
|
|
2417
2295
|
* - Verify operation parameters
|
|
2418
2296
|
* - Log transaction details
|
|
2419
2297
|
* - Troubleshoot condition expressions
|
|
2420
|
-
*
|
|
2298
|
+
*
|
|
2421
2299
|
* The method resolves all expression placeholders with their actual values,
|
|
2422
2300
|
* making it easier to understand the transaction's operations.
|
|
2423
|
-
*
|
|
2301
|
+
*
|
|
2424
2302
|
* @example
|
|
2425
2303
|
* ```typescript
|
|
2426
2304
|
* // Add multiple operations
|
|
2427
2305
|
* transaction
|
|
2428
2306
|
* .put('orders', { orderId: '123', status: 'PENDING' })
|
|
2429
|
-
* .update('inventory',
|
|
2307
|
+
* .update('inventory',
|
|
2430
2308
|
* { productId: 'ABC' },
|
|
2431
2309
|
* 'SET quantity = quantity - :amount',
|
|
2432
2310
|
* undefined,
|
|
2433
2311
|
* { ':amount': 1 }
|
|
2434
2312
|
* );
|
|
2435
|
-
*
|
|
2313
|
+
*
|
|
2436
2314
|
* // Debug the transaction
|
|
2437
2315
|
* const debugInfo = transaction.debug();
|
|
2438
2316
|
* console.log('Transaction operations:', debugInfo);
|
|
2439
2317
|
* ```
|
|
2440
|
-
*
|
|
2318
|
+
*
|
|
2441
2319
|
* @returns An array of readable representations of the transaction items
|
|
2442
2320
|
*/
|
|
2443
2321
|
debug() {
|
|
@@ -2449,17 +2327,17 @@ var TransactionBuilder = class {
|
|
|
2449
2327
|
* - Perform multiple operations atomically
|
|
2450
2328
|
* - Ensure all-or-nothing execution
|
|
2451
2329
|
* - Maintain data consistency across operations
|
|
2452
|
-
*
|
|
2330
|
+
*
|
|
2453
2331
|
* The transaction will only succeed if all operations succeed.
|
|
2454
2332
|
* If any operation fails, the entire transaction is rolled back.
|
|
2455
|
-
*
|
|
2333
|
+
*
|
|
2456
2334
|
* @example
|
|
2457
2335
|
* ```typescript
|
|
2458
2336
|
* try {
|
|
2459
2337
|
* // Build and execute transaction
|
|
2460
2338
|
* await transaction
|
|
2461
2339
|
* .put('orders', newOrder)
|
|
2462
|
-
* .update('inventory',
|
|
2340
|
+
* .update('inventory',
|
|
2463
2341
|
* { productId: 'ABC' },
|
|
2464
2342
|
* 'SET quantity = quantity - :qty',
|
|
2465
2343
|
* undefined,
|
|
@@ -2470,14 +2348,14 @@ var TransactionBuilder = class {
|
|
|
2470
2348
|
* op => op.eq('status', 'ACTIVE')
|
|
2471
2349
|
* )
|
|
2472
2350
|
* .execute();
|
|
2473
|
-
*
|
|
2351
|
+
*
|
|
2474
2352
|
* console.log('Transaction completed successfully');
|
|
2475
2353
|
* } catch (error) {
|
|
2476
2354
|
* // Handle transaction failure
|
|
2477
2355
|
* console.error('Transaction failed:', error);
|
|
2478
2356
|
* }
|
|
2479
2357
|
* ```
|
|
2480
|
-
*
|
|
2358
|
+
*
|
|
2481
2359
|
* @throws {Error} If no transaction items are specified
|
|
2482
2360
|
* @throws {Error} If any operation in the transaction fails
|
|
2483
2361
|
* @returns A promise that resolves when the transaction completes
|
|
@@ -2576,29 +2454,29 @@ var ConditionCheckBuilder = class {
|
|
|
2576
2454
|
* - Validate complex item states
|
|
2577
2455
|
* - Check multiple attributes together
|
|
2578
2456
|
* - Ensure safety conditions are met
|
|
2579
|
-
*
|
|
2457
|
+
*
|
|
2580
2458
|
* @example
|
|
2581
2459
|
* ```typescript
|
|
2582
2460
|
* // Check dinosaur health and behavior
|
|
2583
|
-
* builder.condition(op =>
|
|
2461
|
+
* builder.condition(op =>
|
|
2584
2462
|
* op.and([
|
|
2585
2463
|
* op.gt('stats.health', 50),
|
|
2586
2464
|
* op.not(op.eq('status', 'SEDATED')),
|
|
2587
2465
|
* op.lt('aggressionLevel', 8)
|
|
2588
2466
|
* ])
|
|
2589
2467
|
* );
|
|
2590
|
-
*
|
|
2468
|
+
*
|
|
2591
2469
|
* // Verify habitat conditions
|
|
2592
|
-
* builder.condition(op =>
|
|
2470
|
+
* builder.condition(op =>
|
|
2593
2471
|
* op.and([
|
|
2594
2472
|
* op.eq('powerStatus', 'ONLINE'),
|
|
2595
2473
|
* op.between('temperature', 20, 30),
|
|
2596
2474
|
* op.attributeExists('lastMaintenance')
|
|
2597
2475
|
* ])
|
|
2598
2476
|
* );
|
|
2599
|
-
*
|
|
2477
|
+
*
|
|
2600
2478
|
* // Check breeding conditions
|
|
2601
|
-
* builder.condition(op =>
|
|
2479
|
+
* builder.condition(op =>
|
|
2602
2480
|
* op.and([
|
|
2603
2481
|
* op.eq('species', 'VELOCIRAPTOR'),
|
|
2604
2482
|
* op.gte('age', 3),
|
|
@@ -2606,7 +2484,7 @@ var ConditionCheckBuilder = class {
|
|
|
2606
2484
|
* ])
|
|
2607
2485
|
* );
|
|
2608
2486
|
* ```
|
|
2609
|
-
*
|
|
2487
|
+
*
|
|
2610
2488
|
* @param condition - Either a Condition object or a callback function that builds the condition
|
|
2611
2489
|
* @returns The builder instance for method chaining
|
|
2612
2490
|
*/
|
|
@@ -2848,14 +2726,89 @@ var GetBuilder = class {
|
|
|
2848
2726
|
}
|
|
2849
2727
|
};
|
|
2850
2728
|
|
|
2729
|
+
// src/builders/scan-builder.ts
|
|
2730
|
+
var ScanBuilder = class _ScanBuilder extends FilterBuilder {
|
|
2731
|
+
executor;
|
|
2732
|
+
constructor(executor) {
|
|
2733
|
+
super();
|
|
2734
|
+
this.executor = executor;
|
|
2735
|
+
}
|
|
2736
|
+
/**
|
|
2737
|
+
* Creates a deep clone of this ScanBuilder instance.
|
|
2738
|
+
* Use this method when you need to:
|
|
2739
|
+
* - Create scan templates
|
|
2740
|
+
* - Run multiple variations of a scan
|
|
2741
|
+
* - Implement pagination (used internally by paginate())
|
|
2742
|
+
*
|
|
2743
|
+
* @returns A new ScanBuilder instance with the same configuration
|
|
2744
|
+
*/
|
|
2745
|
+
clone() {
|
|
2746
|
+
const clone = new _ScanBuilder(this.executor);
|
|
2747
|
+
clone.options = { ...this.options };
|
|
2748
|
+
clone.selectedFields = new Set(this.selectedFields);
|
|
2749
|
+
return clone;
|
|
2750
|
+
}
|
|
2751
|
+
/**
|
|
2752
|
+
* Executes the scan against DynamoDB.
|
|
2753
|
+
* Use this method when you need to:
|
|
2754
|
+
* - Search across the entire table
|
|
2755
|
+
* - Find items matching specific criteria
|
|
2756
|
+
* - Perform full table analysis
|
|
2757
|
+
* - Generate reports across all data
|
|
2758
|
+
*
|
|
2759
|
+
* The method returns both the matched items and, if there are more results,
|
|
2760
|
+
* a lastEvaluatedKey that can be used with startFrom() to continue the scan.
|
|
2761
|
+
*
|
|
2762
|
+
* @example
|
|
2763
|
+
* ```typescript
|
|
2764
|
+
* try {
|
|
2765
|
+
* // Find all dinosaurs with high aggression levels
|
|
2766
|
+
* const result = await new ScanBuilder(executor)
|
|
2767
|
+
* .filter(op =>
|
|
2768
|
+
* op.and([
|
|
2769
|
+
* op.eq('status', 'ACTIVE'),
|
|
2770
|
+
* op.gt('aggressionLevel', 7)
|
|
2771
|
+
* ])
|
|
2772
|
+
* )
|
|
2773
|
+
* .limit(20)
|
|
2774
|
+
* .execute();
|
|
2775
|
+
*
|
|
2776
|
+
* console.log(`Found ${result.items.length} potentially dangerous dinosaurs`);
|
|
2777
|
+
*
|
|
2778
|
+
* if (result.lastEvaluatedKey) {
|
|
2779
|
+
* console.log('More results available');
|
|
2780
|
+
* }
|
|
2781
|
+
* } catch (error) {
|
|
2782
|
+
* console.error('Security scan failed:', error);
|
|
2783
|
+
* }
|
|
2784
|
+
* ```
|
|
2785
|
+
*
|
|
2786
|
+
* @returns A promise that resolves to an object containing:
|
|
2787
|
+
* - items: Array of items matching the scan criteria
|
|
2788
|
+
* - lastEvaluatedKey: Token for continuing the scan, if more items exist
|
|
2789
|
+
*/
|
|
2790
|
+
async execute() {
|
|
2791
|
+
return this.executor(this.options);
|
|
2792
|
+
}
|
|
2793
|
+
};
|
|
2794
|
+
|
|
2851
2795
|
// src/table.ts
|
|
2852
2796
|
var DDB_BATCH_WRITE_LIMIT = 25;
|
|
2853
2797
|
var DDB_BATCH_GET_LIMIT = 100;
|
|
2854
2798
|
var Table = class {
|
|
2855
2799
|
dynamoClient;
|
|
2856
2800
|
tableName;
|
|
2801
|
+
/**
|
|
2802
|
+
* The column name of the partitionKey for the Table
|
|
2803
|
+
*/
|
|
2857
2804
|
partitionKey;
|
|
2805
|
+
/**
|
|
2806
|
+
* The column name of the sortKey for the Table
|
|
2807
|
+
*/
|
|
2858
2808
|
sortKey;
|
|
2809
|
+
/**
|
|
2810
|
+
* The Global Secondary Indexes that are configured on this table
|
|
2811
|
+
*/
|
|
2859
2812
|
gsis;
|
|
2860
2813
|
constructor(config) {
|
|
2861
2814
|
this.dynamoClient = config.client;
|
|
@@ -2902,15 +2855,29 @@ var Table = class {
|
|
|
2902
2855
|
put(item) {
|
|
2903
2856
|
const executor = async (params) => {
|
|
2904
2857
|
try {
|
|
2905
|
-
await this.dynamoClient.put({
|
|
2858
|
+
const result = await this.dynamoClient.put({
|
|
2906
2859
|
TableName: params.tableName,
|
|
2907
2860
|
Item: params.item,
|
|
2908
2861
|
ConditionExpression: params.conditionExpression,
|
|
2909
2862
|
ExpressionAttributeNames: params.expressionAttributeNames,
|
|
2910
2863
|
ExpressionAttributeValues: params.expressionAttributeValues,
|
|
2911
|
-
|
|
2864
|
+
// CONSISTENT is not a valid ReturnValue for DDB, so we set NONE as we are not interested in its
|
|
2865
|
+
// response and will be reloading the item from the DB through a get instead
|
|
2866
|
+
ReturnValues: params.returnValues === "CONSISTENT" ? "NONE" : params.returnValues
|
|
2912
2867
|
});
|
|
2913
|
-
|
|
2868
|
+
if (params.returnValues === "CONSISTENT") {
|
|
2869
|
+
const key = {
|
|
2870
|
+
pk: params.item[this.partitionKey],
|
|
2871
|
+
...this.sortKey && { sk: params.item[this.sortKey] }
|
|
2872
|
+
};
|
|
2873
|
+
const getResult = await this.dynamoClient.get({
|
|
2874
|
+
TableName: params.tableName,
|
|
2875
|
+
Key: key,
|
|
2876
|
+
ConsistentRead: true
|
|
2877
|
+
});
|
|
2878
|
+
return getResult.Item;
|
|
2879
|
+
}
|
|
2880
|
+
return result.Attributes;
|
|
2914
2881
|
} catch (error) {
|
|
2915
2882
|
console.error("Error creating item:", error);
|
|
2916
2883
|
throw error;
|
|
@@ -3036,6 +3003,54 @@ var Table = class {
|
|
|
3036
3003
|
};
|
|
3037
3004
|
return new QueryBuilder(executor, keyConditionExpression);
|
|
3038
3005
|
}
|
|
3006
|
+
/**
|
|
3007
|
+
* Creates a scan builder for scanning the entire table
|
|
3008
|
+
* Use this when you need to:
|
|
3009
|
+
* - Process all items in a table
|
|
3010
|
+
* - Apply filters to a large dataset
|
|
3011
|
+
* - Use a GSI for scanning
|
|
3012
|
+
*
|
|
3013
|
+
* @returns A ScanBuilder instance for chaining operations
|
|
3014
|
+
*/
|
|
3015
|
+
scan() {
|
|
3016
|
+
const executor = async (options) => {
|
|
3017
|
+
const expressionParams = {
|
|
3018
|
+
expressionAttributeNames: {},
|
|
3019
|
+
expressionAttributeValues: {},
|
|
3020
|
+
valueCounter: { count: 0 }
|
|
3021
|
+
};
|
|
3022
|
+
let filterExpression;
|
|
3023
|
+
if (options.filter) {
|
|
3024
|
+
filterExpression = buildExpression(options.filter, expressionParams);
|
|
3025
|
+
}
|
|
3026
|
+
const projectionExpression = options.projection?.map((p) => generateAttributeName(expressionParams, p)).join(", ");
|
|
3027
|
+
const { expressionAttributeNames, expressionAttributeValues } = expressionParams;
|
|
3028
|
+
const { indexName, limit, consistentRead, lastEvaluatedKey } = options;
|
|
3029
|
+
const params = {
|
|
3030
|
+
TableName: this.tableName,
|
|
3031
|
+
FilterExpression: filterExpression,
|
|
3032
|
+
ExpressionAttributeNames: Object.keys(expressionAttributeNames).length > 0 ? expressionAttributeNames : void 0,
|
|
3033
|
+
ExpressionAttributeValues: Object.keys(expressionAttributeValues).length > 0 ? expressionAttributeValues : void 0,
|
|
3034
|
+
IndexName: indexName,
|
|
3035
|
+
Limit: limit,
|
|
3036
|
+
ConsistentRead: consistentRead,
|
|
3037
|
+
ProjectionExpression: projectionExpression,
|
|
3038
|
+
ExclusiveStartKey: lastEvaluatedKey
|
|
3039
|
+
};
|
|
3040
|
+
try {
|
|
3041
|
+
const result = await this.dynamoClient.scan(params);
|
|
3042
|
+
return {
|
|
3043
|
+
items: result.Items,
|
|
3044
|
+
lastEvaluatedKey: result.LastEvaluatedKey
|
|
3045
|
+
};
|
|
3046
|
+
} catch (error) {
|
|
3047
|
+
console.log(debugCommand(params));
|
|
3048
|
+
console.error("Error scanning items:", error);
|
|
3049
|
+
throw error;
|
|
3050
|
+
}
|
|
3051
|
+
};
|
|
3052
|
+
return new ScanBuilder(executor);
|
|
3053
|
+
}
|
|
3039
3054
|
delete(keyCondition) {
|
|
3040
3055
|
const executor = async (params) => {
|
|
3041
3056
|
try {
|
|
@@ -3257,6 +3272,7 @@ export {
|
|
|
3257
3272
|
beginsWith,
|
|
3258
3273
|
between,
|
|
3259
3274
|
contains,
|
|
3275
|
+
createComparisonCondition,
|
|
3260
3276
|
eq,
|
|
3261
3277
|
gt,
|
|
3262
3278
|
gte,
|