dyno-table 0.2.0-0 → 1.0.0-alpha.1

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.
Files changed (96) hide show
  1. package/README.md +182 -577
  2. package/dist/{table.cjs → index.cjs} +175 -87
  3. package/dist/index.d.cts +2971 -0
  4. package/dist/index.d.ts +2971 -0
  5. package/dist/{table.js → index.js} +127 -86
  6. package/package.json +10 -77
  7. package/dist/builder-types-C_PDZhnP.d.ts +0 -118
  8. package/dist/builder-types-DtwbqMeF.d.cts +0 -118
  9. package/dist/builders/condition-check-builder.cjs +0 -394
  10. package/dist/builders/condition-check-builder.cjs.map +0 -1
  11. package/dist/builders/condition-check-builder.d.cts +0 -157
  12. package/dist/builders/condition-check-builder.d.ts +0 -157
  13. package/dist/builders/condition-check-builder.js +0 -392
  14. package/dist/builders/condition-check-builder.js.map +0 -1
  15. package/dist/builders/delete-builder.cjs +0 -405
  16. package/dist/builders/delete-builder.cjs.map +0 -1
  17. package/dist/builders/delete-builder.d.cts +0 -166
  18. package/dist/builders/delete-builder.d.ts +0 -166
  19. package/dist/builders/delete-builder.js +0 -403
  20. package/dist/builders/delete-builder.js.map +0 -1
  21. package/dist/builders/paginator.cjs +0 -199
  22. package/dist/builders/paginator.cjs.map +0 -1
  23. package/dist/builders/paginator.d.cts +0 -179
  24. package/dist/builders/paginator.d.ts +0 -179
  25. package/dist/builders/paginator.js +0 -197
  26. package/dist/builders/paginator.js.map +0 -1
  27. package/dist/builders/put-builder.cjs +0 -476
  28. package/dist/builders/put-builder.cjs.map +0 -1
  29. package/dist/builders/put-builder.d.cts +0 -274
  30. package/dist/builders/put-builder.d.ts +0 -274
  31. package/dist/builders/put-builder.js +0 -474
  32. package/dist/builders/put-builder.js.map +0 -1
  33. package/dist/builders/query-builder.cjs +0 -674
  34. package/dist/builders/query-builder.cjs.map +0 -1
  35. package/dist/builders/query-builder.d.cts +0 -6
  36. package/dist/builders/query-builder.d.ts +0 -6
  37. package/dist/builders/query-builder.js +0 -672
  38. package/dist/builders/query-builder.js.map +0 -1
  39. package/dist/builders/transaction-builder.cjs +0 -894
  40. package/dist/builders/transaction-builder.cjs.map +0 -1
  41. package/dist/builders/transaction-builder.d.cts +0 -511
  42. package/dist/builders/transaction-builder.d.ts +0 -511
  43. package/dist/builders/transaction-builder.js +0 -892
  44. package/dist/builders/transaction-builder.js.map +0 -1
  45. package/dist/builders/update-builder.cjs +0 -627
  46. package/dist/builders/update-builder.cjs.map +0 -1
  47. package/dist/builders/update-builder.d.cts +0 -365
  48. package/dist/builders/update-builder.d.ts +0 -365
  49. package/dist/builders/update-builder.js +0 -625
  50. package/dist/builders/update-builder.js.map +0 -1
  51. package/dist/conditions--ld9a78i.d.ts +0 -331
  52. package/dist/conditions-ChhQWd6z.d.cts +0 -331
  53. package/dist/conditions.cjs +0 -59
  54. package/dist/conditions.cjs.map +0 -1
  55. package/dist/conditions.d.cts +0 -3
  56. package/dist/conditions.d.ts +0 -3
  57. package/dist/conditions.js +0 -43
  58. package/dist/conditions.js.map +0 -1
  59. package/dist/entity.cjs +0 -228
  60. package/dist/entity.cjs.map +0 -1
  61. package/dist/entity.d.cts +0 -149
  62. package/dist/entity.d.ts +0 -149
  63. package/dist/entity.js +0 -224
  64. package/dist/entity.js.map +0 -1
  65. package/dist/query-builder-Csror9Iu.d.ts +0 -507
  66. package/dist/query-builder-D2FM9rsu.d.cts +0 -507
  67. package/dist/standard-schema.cjs +0 -4
  68. package/dist/standard-schema.cjs.map +0 -1
  69. package/dist/standard-schema.d.cts +0 -57
  70. package/dist/standard-schema.d.ts +0 -57
  71. package/dist/standard-schema.js +0 -3
  72. package/dist/standard-schema.js.map +0 -1
  73. package/dist/table-BEhBPy2G.d.cts +0 -364
  74. package/dist/table-BW3cmUqr.d.ts +0 -364
  75. package/dist/table.cjs.map +0 -1
  76. package/dist/table.d.cts +0 -12
  77. package/dist/table.d.ts +0 -12
  78. package/dist/table.js.map +0 -1
  79. package/dist/types.cjs +0 -4
  80. package/dist/types.cjs.map +0 -1
  81. package/dist/types.d.cts +0 -22
  82. package/dist/types.d.ts +0 -22
  83. package/dist/types.js +0 -3
  84. package/dist/types.js.map +0 -1
  85. package/dist/utils/partition-key-template.cjs +0 -19
  86. package/dist/utils/partition-key-template.cjs.map +0 -1
  87. package/dist/utils/partition-key-template.d.cts +0 -32
  88. package/dist/utils/partition-key-template.d.ts +0 -32
  89. package/dist/utils/partition-key-template.js +0 -17
  90. package/dist/utils/partition-key-template.js.map +0 -1
  91. package/dist/utils/sort-key-template.cjs +0 -19
  92. package/dist/utils/sort-key-template.cjs.map +0 -1
  93. package/dist/utils/sort-key-template.d.cts +0 -35
  94. package/dist/utils/sort-key-template.d.ts +0 -35
  95. package/dist/utils/sort-key-template.js +0 -17
  96. package/dist/utils/sort-key-template.js.map +0 -1
@@ -1,672 +0,0 @@
1
- // src/conditions.ts
2
- var createComparisonCondition = (type) => (attr, value) => ({
3
- type,
4
- attr,
5
- value
6
- });
7
- var eq = createComparisonCondition("eq");
8
- var ne = createComparisonCondition("ne");
9
- var lt = createComparisonCondition("lt");
10
- var lte = createComparisonCondition("lte");
11
- var gt = createComparisonCondition("gt");
12
- var gte = createComparisonCondition("gte");
13
- var between = (attr, lower, upper) => ({
14
- type: "between",
15
- attr,
16
- value: [lower, upper]
17
- });
18
- var beginsWith = createComparisonCondition("beginsWith");
19
- var contains = createComparisonCondition("contains");
20
- var attributeExists = (attr) => ({
21
- type: "attributeExists",
22
- attr
23
- });
24
- var attributeNotExists = (attr) => ({
25
- type: "attributeNotExists",
26
- attr
27
- });
28
- var and = (...conditions) => ({
29
- type: "and",
30
- conditions
31
- });
32
- var or = (...conditions) => ({
33
- type: "or",
34
- conditions
35
- });
36
- var not = (condition) => ({
37
- type: "not",
38
- condition
39
- });
40
-
41
- // src/builders/paginator.ts
42
- var Paginator = class {
43
- queryBuilder;
44
- pageSize;
45
- currentPage = 0;
46
- lastEvaluatedKey;
47
- hasMorePages = true;
48
- totalItemsRetrieved = 0;
49
- overallLimit;
50
- constructor(queryBuilder, pageSize) {
51
- this.queryBuilder = queryBuilder;
52
- this.pageSize = pageSize;
53
- this.overallLimit = queryBuilder.getLimit();
54
- }
55
- /**
56
- * Gets the current page number (1-indexed).
57
- * Use this method when you need to:
58
- * - Track progress through dinosaur lists
59
- * - Display habitat inspection status
60
- * - Monitor security sweep progress
61
- *
62
- * @example
63
- * ```ts
64
- * const paginator = new QueryBuilder(executor, eq('species', 'Tyrannosaurus'))
65
- * .paginate(5);
66
- *
67
- * await paginator.getNextPage();
68
- * console.log(`Reviewing T-Rex group ${paginator.getCurrentPage()}`);
69
- * ```
70
- *
71
- * @returns The current page number, starting from 1
72
- */
73
- getCurrentPage() {
74
- return this.currentPage;
75
- }
76
- /**
77
- * Checks if there are more pages of dinosaurs or habitats to process.
78
- * Use this method when you need to:
79
- * - Check for more dinosaurs to review
80
- * - Continue habitat inspections
81
- * - Process security incidents
82
- * - Complete feeding schedules
83
- *
84
- * This method takes into account both:
85
- * - DynamoDB's lastEvaluatedKey mechanism
86
- * - Any overall limit set on the query
87
- *
88
- * @example
89
- * ```ts
90
- * // Process all security incidents
91
- * const paginator = new QueryBuilder(executor, eq('type', 'SECURITY_BREACH'))
92
- * .sortDescending()
93
- * .paginate(10);
94
- *
95
- * while (paginator.hasNextPage()) {
96
- * const page = await paginator.getNextPage();
97
- * for (const incident of page.items) {
98
- * await processSecurityBreach(incident);
99
- * }
100
- * console.log(`Processed incidents page ${page.page}`);
101
- * }
102
- * ```
103
- *
104
- * @returns true if there are more pages available, false otherwise
105
- */
106
- hasNextPage() {
107
- if (this.overallLimit !== void 0 && this.totalItemsRetrieved >= this.overallLimit) {
108
- return false;
109
- }
110
- return this.hasMorePages;
111
- }
112
- /**
113
- * Retrieves the next page of dinosaurs or habitats from DynamoDB.
114
- * Use this method when you need to:
115
- * - Process dinosaur groups systematically
116
- * - Review habitat inspections in batches
117
- * - Monitor security incidents in sequence
118
- * - Schedule feeding rotations
119
- *
120
- * This method handles:
121
- * - Automatic continuation between groups
122
- * - Respect for park capacity limits
123
- * - Group size adjustments for safety
124
- *
125
- * @example
126
- * ```ts
127
- * const paginator = new QueryBuilder(executor, eq('species', 'Velociraptor'))
128
- * .filter(op => op.eq('status', 'ACTIVE'))
129
- * .paginate(5);
130
- *
131
- * // Check first raptor group
132
- * const page1 = await paginator.getNextPage();
133
- * console.log(`Found ${page1.items.length} active raptors`);
134
- *
135
- * // Continue inspection if more groups exist
136
- * if (page1.hasNextPage) {
137
- * const page2 = await paginator.getNextPage();
138
- * console.log(`Inspecting raptor group ${page2.page}`);
139
- *
140
- * for (const raptor of page2.items) {
141
- * await performHealthCheck(raptor);
142
- * }
143
- * }
144
- * ```
145
- *
146
- * @returns A promise that resolves to a PaginationResult containing:
147
- * - items: The dinosaurs/habitats for this page
148
- * - hasNextPage: Whether more groups exist
149
- * - page: The current group number
150
- * - lastEvaluatedKey: DynamoDB's continuation token
151
- */
152
- async getNextPage() {
153
- if (!this.hasNextPage()) {
154
- return {
155
- items: [],
156
- hasNextPage: false,
157
- page: this.currentPage
158
- };
159
- }
160
- let effectivePageSize = this.pageSize;
161
- if (this.overallLimit !== void 0) {
162
- const remainingItems = this.overallLimit - this.totalItemsRetrieved;
163
- if (remainingItems <= 0) {
164
- return {
165
- items: [],
166
- hasNextPage: false,
167
- page: this.currentPage
168
- };
169
- }
170
- effectivePageSize = Math.min(effectivePageSize, remainingItems);
171
- }
172
- const query = this.queryBuilder.clone().limit(effectivePageSize);
173
- if (this.lastEvaluatedKey) {
174
- query.startFrom(this.lastEvaluatedKey);
175
- }
176
- const result = await query.execute();
177
- this.currentPage += 1;
178
- this.lastEvaluatedKey = result.lastEvaluatedKey;
179
- this.totalItemsRetrieved += result.items.length;
180
- this.hasMorePages = !!result.lastEvaluatedKey && (this.overallLimit === void 0 || this.totalItemsRetrieved < this.overallLimit);
181
- return {
182
- items: result.items,
183
- lastEvaluatedKey: result.lastEvaluatedKey,
184
- hasNextPage: this.hasNextPage(),
185
- page: this.currentPage
186
- };
187
- }
188
- /**
189
- * Gets all remaining dinosaurs or habitats and combines them into a single array.
190
- * Use this method when you need to:
191
- * - Generate complete park inventory
192
- * - Perform full security audit
193
- * - Create comprehensive feeding schedule
194
- * - Run park-wide health checks
195
- *
196
- * Note: Use with caution! This method:
197
- * - Could overwhelm systems with large dinosaur populations
198
- * - Makes multiple database requests
199
- * - May cause system strain during peak hours
200
- *
201
- * @example
202
- * ```ts
203
- * // Get complete carnivore inventory
204
- * const paginator = new QueryBuilder(executor, eq('diet', 'CARNIVORE'))
205
- * .filter(op => op.eq('status', 'ACTIVE'))
206
- * .paginate(10);
207
- *
208
- * try {
209
- * const allCarnivores = await paginator.getAllPages();
210
- * console.log(`Park contains ${allCarnivores.length} active carnivores`);
211
- *
212
- * // Calculate total threat level
213
- * const totalThreat = allCarnivores.reduce(
214
- * (sum, dino) => sum + dino.stats.threatLevel,
215
- * 0
216
- * );
217
- * console.log(`Total threat level: ${totalThreat}`);
218
- * } catch (error) {
219
- * console.error('Failed to complete carnivore census:', error);
220
- * }
221
- * ```
222
- *
223
- * @returns A promise that resolves to an array containing all remaining items
224
- */
225
- async getAllPages() {
226
- const allItems = [];
227
- while (this.hasNextPage()) {
228
- const result = await this.getNextPage();
229
- allItems.push(...result.items);
230
- }
231
- return allItems;
232
- }
233
- };
234
-
235
- // src/builders/filter-builder.ts
236
- var FilterBuilder = class {
237
- options = {};
238
- selectedFields = /* @__PURE__ */ new Set();
239
- /**
240
- * Sets the maximum number of items to return.
241
- * Use this method when you need to:
242
- * - Limit the number of dinosaurs returned
243
- * - Control the size of habitat reports
244
- * - Implement manual pagination of security logs
245
- *
246
- * Note: This limit applies to the items that match the key condition
247
- * before any filter expressions are applied.
248
- *
249
- * @example
250
- * ```typescript
251
- * // Get first 10 dinosaurs
252
- * const result = await builder
253
- * .limit(10)
254
- * .execute();
255
- * ```
256
- *
257
- * @param limit - Maximum number of items to return
258
- * @returns The builder instance for method chaining
259
- */
260
- limit(limit) {
261
- this.options.limit = limit;
262
- return this;
263
- }
264
- /**
265
- * Gets the current limit set on the operation.
266
- * This is used internally by the paginator to manage result sets.
267
- *
268
- * @returns The current limit or undefined if no limit is set
269
- */
270
- getLimit() {
271
- return this.options.limit;
272
- }
273
- /**
274
- * Specifies a Global Secondary Index (GSI) to use for the operation.
275
- * Use this method when you need to:
276
- * - Find dinosaurs by species or status
277
- * - Search habitats by security level
278
- * - Find incidents by date
279
- * - List feeding schedules by time
280
- *
281
- * @example
282
- * ```typescript
283
- * // Find all dinosaurs of a specific species
284
- * builder
285
- * .useIndex('species-status-index')
286
- * .filter(op => op.eq('status', 'ACTIVE'));
287
- *
288
- * // Search high-security habitats
289
- * builder
290
- * .useIndex('security-level-index')
291
- * .filter(op =>
292
- * op.and([
293
- * op.gt('securityLevel', 8),
294
- * op.eq('status', 'OPERATIONAL')
295
- * ])
296
- * );
297
- * ```
298
- *
299
- * @param indexName - The name of the GSI to use (type-safe based on table configuration)
300
- * @returns The builder instance for method chaining
301
- */
302
- useIndex(indexName) {
303
- this.options.indexName = indexName;
304
- return this;
305
- }
306
- /**
307
- * Sets whether to use strongly consistent reads for the operation.
308
- * Use this method when you need to:
309
- * - Get real-time dinosaur status updates
310
- * - Monitor critical security systems
311
- * - Track immediate habitat changes
312
- * - Verify containment protocols
313
- *
314
- * Note:
315
- * - Consistent reads are not available on GSIs
316
- * - Consistent reads consume twice the throughput
317
- * - Default is eventually consistent reads
318
- *
319
- * @example
320
- * ```typescript
321
- * // Check immediate dinosaur status
322
- * const result = await builder
323
- * .filter(op => op.eq('status', 'ACTIVE'))
324
- * .consistentRead()
325
- * .execute();
326
- *
327
- * // Monitor security breaches
328
- * const result = await builder
329
- * .useIndex('primary-index')
330
- * .consistentRead(isEmergencyMode)
331
- * .execute();
332
- * ```
333
- *
334
- * @param consistentRead - Whether to use consistent reads (defaults to true)
335
- * @returns The builder instance for method chaining
336
- */
337
- consistentRead(consistentRead = true) {
338
- this.options.consistentRead = consistentRead;
339
- return this;
340
- }
341
- /**
342
- * Adds a filter expression to refine the operation results.
343
- * Use this method when you need to:
344
- * - Filter dinosaurs by behavior patterns
345
- * - Find habitats with specific conditions
346
- * - Search for security incidents
347
- * - Monitor feeding patterns
348
- *
349
- * @example
350
- * ```typescript
351
- * // Find aggressive carnivores
352
- * builder.filter(op =>
353
- * op.and([
354
- * op.eq('diet', 'CARNIVORE'),
355
- * op.gt('aggressionLevel', 7),
356
- * op.eq('status', 'ACTIVE')
357
- * ])
358
- * );
359
- *
360
- * // Search suitable breeding habitats
361
- * builder.filter(op =>
362
- * op.and([
363
- * op.between('temperature', 25, 30),
364
- * op.lt('currentOccupants', 3),
365
- * op.eq('quarantineStatus', 'CLEAR')
366
- * ])
367
- * );
368
- * ```
369
- *
370
- * @param condition - Either a Condition object or a callback function that builds the condition
371
- * @returns The builder instance for method chaining
372
- */
373
- filter(condition) {
374
- if (typeof condition === "function") {
375
- const conditionOperator = {
376
- eq,
377
- ne,
378
- lt,
379
- lte,
380
- gt,
381
- gte,
382
- between,
383
- beginsWith,
384
- contains,
385
- attributeExists,
386
- attributeNotExists,
387
- and,
388
- or,
389
- not
390
- };
391
- this.options.filter = condition(conditionOperator);
392
- } else {
393
- this.options.filter = condition;
394
- }
395
- return this;
396
- }
397
- /**
398
- * Specifies which attributes to return in the results.
399
- * Use this method when you need to:
400
- * - Get specific dinosaur attributes
401
- * - Retrieve habitat statistics
402
- * - Monitor security metrics
403
- * - Optimize response size
404
- *
405
- * @example
406
- * ```typescript
407
- * // Get basic dinosaur info
408
- * builder.select([
409
- * 'species',
410
- * 'status',
411
- * 'stats.health',
412
- * 'stats.aggressionLevel'
413
- * ]);
414
- *
415
- * // Monitor habitat conditions
416
- * builder
417
- * .select('securityStatus')
418
- * .select([
419
- * 'currentOccupants',
420
- * 'temperature',
421
- * 'lastInspectionDate'
422
- * ]);
423
- * ```
424
- *
425
- * @param fields - A single field name or an array of field names to return
426
- * @returns The builder instance for method chaining
427
- */
428
- select(fields) {
429
- if (typeof fields === "string") {
430
- this.selectedFields.add(fields);
431
- } else if (Array.isArray(fields)) {
432
- for (const field of fields) {
433
- this.selectedFields.add(field);
434
- }
435
- }
436
- this.options.projection = Array.from(this.selectedFields);
437
- return this;
438
- }
439
- /**
440
- * Creates a paginator that handles DynamoDB pagination automatically.
441
- * The paginator handles:
442
- * - Tracking the last evaluated key
443
- * - Managing page boundaries
444
- * - Respecting overall query limits
445
- *
446
- * @example
447
- * ```typescript
448
- * // Create a paginator for dinosaur records
449
- * const paginator = builder
450
- * .filter(op => op.eq('status', 'ACTIVE'))
451
- * .paginate(10);
452
- *
453
- * // Process pages of dinosaur results
454
- * while (paginator.hasNextPage()) {
455
- * const page = await paginator.getNextPage();
456
- * console.log(`Processing page ${page.page}, count: ${page.items.length}`);
457
- * // Process dinosaur data
458
- * }
459
- * ```
460
- *
461
- * @param pageSize - The number of items to return per page
462
- * @returns A Paginator instance that manages the pagination state
463
- * @see Paginator for more pagination control options
464
- */
465
- paginate(pageSize) {
466
- return new Paginator(this, pageSize);
467
- }
468
- /**
469
- * Sets the starting point using a previous lastEvaluatedKey.
470
- * Use this method when you need to:
471
- * - Implement manual dinosaur list pagination
472
- * - Resume habitat inspection reviews
473
- * - Continue security incident analysis
474
- * - Store operation position between sessions
475
- *
476
- * Note: This method is typically used for manual pagination.
477
- * For automatic pagination, use the paginate() method instead.
478
- *
479
- * @example
480
- * ```typescript
481
- * // First batch of dinosaurs
482
- * const result1 = await builder
483
- * .filter(op => op.eq('status', 'ACTIVE'))
484
- * .limit(5)
485
- * .execute();
486
- *
487
- * if (result1.lastEvaluatedKey) {
488
- * // Continue listing dinosaurs
489
- * const result2 = await builder
490
- * .filter(op => op.eq('status', 'ACTIVE'))
491
- * .startFrom(result1.lastEvaluatedKey)
492
- * .limit(5)
493
- * .execute();
494
- *
495
- * console.log('Additional dinosaurs:', result2.items);
496
- * }
497
- * ```
498
- *
499
- * @param lastEvaluatedKey - The exclusive start key from a previous result
500
- * @returns The builder instance for method chaining
501
- */
502
- startFrom(lastEvaluatedKey) {
503
- this.options.lastEvaluatedKey = lastEvaluatedKey;
504
- return this;
505
- }
506
- };
507
-
508
- // src/builders/query-builder.ts
509
- var QueryBuilder = class _QueryBuilder extends FilterBuilder {
510
- keyCondition;
511
- options = {};
512
- executor;
513
- constructor(executor, keyCondition) {
514
- super();
515
- this.executor = executor;
516
- this.keyCondition = keyCondition;
517
- }
518
- /**
519
- * Sets the maximum number of items to return from the query.
520
- *
521
- * Note: This is the default behavior if no sort order is specified.
522
- *
523
- * @example
524
- * ```typescript
525
- * // Get orders in chronological order
526
- * const result = await new QueryBuilder(executor, eq('userId', '123'))
527
- * .sortAscending()
528
- * .execute();
529
- *
530
- * // Get events from oldest to newest
531
- * const result = await new QueryBuilder(executor, eq('entityId', 'order-123'))
532
- * .useIndex('entity-timestamp-index')
533
- * .sortAscending()
534
- * .execute();
535
- * ```
536
- *
537
- * @returns The builder instance for method chaining
538
- */
539
- /**
540
- * Sets the query to return items in ascending order by sort key.
541
- *
542
- * @example
543
- * ```typescript
544
- * // List dinosaurs by age
545
- * const result = await new QueryBuilder(executor, eq('species', 'Velociraptor'))
546
- * .useIndex('age-index')
547
- * .sortAscending()
548
- * .execute();
549
- *
550
- * // View incidents chronologically
551
- * const result = await new QueryBuilder(executor, eq('type', 'SECURITY_BREACH'))
552
- * .useIndex('date-index')
553
- * .sortAscending()
554
- * .execute();
555
- * ```
556
- *
557
- * @returns The builder instance for method chaining
558
- */
559
- sortAscending() {
560
- this.options.scanIndexForward = true;
561
- return this;
562
- }
563
- /**
564
- * Sets the query to return items in descending order by sort key.
565
- *
566
- * @example
567
- * ```typescript
568
- * // Get most recent security incidents
569
- * const result = await new QueryBuilder(executor, eq('type', 'SECURITY_BREACH'))
570
- * .useIndex('date-index')
571
- * .sortDescending()
572
- * .limit(10)
573
- * .execute();
574
- *
575
- * // Check latest dinosaur activities
576
- * const result = await new QueryBuilder(executor, eq('species', 'Velociraptor'))
577
- * .useIndex('activity-time-index')
578
- * .filter(op => op.eq('status', 'ACTIVE'))
579
- * .sortDescending()
580
- * .execute();
581
- * ```
582
- *
583
- * @returns The builder instance for method chaining
584
- */
585
- sortDescending() {
586
- this.options.scanIndexForward = false;
587
- return this;
588
- }
589
- /**
590
- * Creates a deep clone of this QueryBuilder instance.
591
- *
592
- * This is particularly useful when:
593
- * - Implementing pagination (used internally by paginate())
594
- * - Creating query templates
595
- * - Running multiple variations of a query
596
- *
597
- * @example
598
- * ```typescript
599
- * // Create base dinosaur query
600
- * const baseQuery = new QueryBuilder(executor, eq('species', 'Velociraptor'))
601
- * .useIndex('status-index')
602
- * .select(['id', 'status', 'location']);
603
- *
604
- * // Check active dinosaurs
605
- * const activeRaptors = baseQuery.clone()
606
- * .filter(op => op.eq('status', 'HUNTING'))
607
- * .execute();
608
- *
609
- * // Check contained dinosaurs
610
- * const containedRaptors = baseQuery.clone()
611
- * .filter(op => op.eq('status', 'CONTAINED'))
612
- * .execute();
613
- *
614
- * // Check sedated dinosaurs
615
- * const sedatedRaptors = baseQuery.clone()
616
- * .filter(op => op.eq('status', 'SEDATED'))
617
- * .execute();
618
- * ```
619
- *
620
- * @returns A new QueryBuilder instance with the same configuration
621
- */
622
- clone() {
623
- const clone = new _QueryBuilder(this.executor, this.keyCondition);
624
- clone.options = { ...this.options };
625
- clone.selectedFields = new Set(this.selectedFields);
626
- return clone;
627
- }
628
- /**
629
- * Executes the query against DynamoDB.
630
- *
631
- * The method returns both the matched items and, if there are more results,
632
- * a lastEvaluatedKey that can be used with startFrom() to continue the query.
633
- *
634
- * @example
635
- * ```typescript
636
- * try {
637
- * // Find active carnivores in specific habitat
638
- * const result = await new QueryBuilder(executor, eq('habitatId', 'PADDOCK-A'))
639
- * .useIndex('species-status-index')
640
- * .filter(op =>
641
- * op.and([
642
- * op.eq('diet', 'CARNIVORE'),
643
- * op.eq('status', 'ACTIVE'),
644
- * op.gt('aggressionLevel', 7)
645
- * ])
646
- * )
647
- * .sortDescending()
648
- * .limit(5)
649
- * .execute();
650
- *
651
- * console.log(`Found ${result.items.length} dangerous dinosaurs`);
652
- *
653
- * if (result.lastEvaluatedKey) {
654
- * console.log('Additional threats detected');
655
- * }
656
- * } catch (error) {
657
- * console.error('Security scan failed:', error);
658
- * }
659
- * ```
660
- *
661
- * @returns A promise that resolves to an object containing:
662
- * - items: Array of items matching the query
663
- * - lastEvaluatedKey: Token for continuing the query, if more items exist
664
- */
665
- async execute() {
666
- return this.executor(this.keyCondition, this.options);
667
- }
668
- };
669
-
670
- export { QueryBuilder };
671
- //# sourceMappingURL=query-builder.js.map
672
- //# sourceMappingURL=query-builder.js.map