dyno-table 2.2.1 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/README.md +200 -1860
  2. package/dist/builders.cjs +55 -0
  3. package/dist/builders.d.cts +4 -0
  4. package/dist/builders.d.ts +4 -0
  5. package/dist/builders.js +2 -0
  6. package/dist/chunk-2EWNZOUK.js +618 -0
  7. package/dist/chunk-2WIBY7PZ.js +46 -0
  8. package/dist/chunk-7UJJ7JXM.cjs +63 -0
  9. package/dist/chunk-DTFJJASK.js +3200 -0
  10. package/dist/chunk-EODPMYPE.js +558 -0
  11. package/dist/chunk-KA3VPIPS.cjs +560 -0
  12. package/dist/chunk-NTA6GDPP.cjs +622 -0
  13. package/dist/chunk-PB7BBCZO.cjs +32 -0
  14. package/dist/chunk-QVRMYGC4.js +29 -0
  15. package/dist/chunk-XYL43FDX.cjs +3217 -0
  16. package/dist/conditions.cjs +67 -62
  17. package/dist/conditions.js +1 -48
  18. package/dist/entity.cjs +14 -625
  19. package/dist/entity.d.cts +2 -10
  20. package/dist/entity.d.ts +2 -10
  21. package/dist/entity.js +2 -626
  22. package/dist/index-2cbm07Bi.d.ts +2797 -0
  23. package/dist/index-DlN8G9hd.d.cts +2797 -0
  24. package/dist/index.cjs +111 -4460
  25. package/dist/index.d.cts +2 -10
  26. package/dist/index.d.ts +2 -10
  27. package/dist/index.js +5 -4442
  28. package/dist/standard-schema.cjs +0 -2
  29. package/dist/standard-schema.js +0 -2
  30. package/dist/table.cjs +7 -3796
  31. package/dist/table.d.cts +163 -12
  32. package/dist/table.d.ts +163 -12
  33. package/dist/table.js +3 -3799
  34. package/dist/types.cjs +0 -2
  35. package/dist/types.js +0 -2
  36. package/dist/utils.cjs +10 -30
  37. package/dist/utils.js +1 -31
  38. package/package.json +6 -66
  39. package/dist/batch-builder-BiQDIZ7p.d.cts +0 -398
  40. package/dist/batch-builder-CNsLS6sR.d.ts +0 -398
  41. package/dist/builder-types-BTVhQSHI.d.cts +0 -169
  42. package/dist/builder-types-CzuLR4Th.d.ts +0 -169
  43. package/dist/builders/condition-check-builder.cjs +0 -422
  44. package/dist/builders/condition-check-builder.cjs.map +0 -1
  45. package/dist/builders/condition-check-builder.d.cts +0 -153
  46. package/dist/builders/condition-check-builder.d.ts +0 -153
  47. package/dist/builders/condition-check-builder.js +0 -420
  48. package/dist/builders/condition-check-builder.js.map +0 -1
  49. package/dist/builders/delete-builder.cjs +0 -484
  50. package/dist/builders/delete-builder.cjs.map +0 -1
  51. package/dist/builders/delete-builder.d.cts +0 -211
  52. package/dist/builders/delete-builder.d.ts +0 -211
  53. package/dist/builders/delete-builder.js +0 -482
  54. package/dist/builders/delete-builder.js.map +0 -1
  55. package/dist/builders/paginator.cjs +0 -193
  56. package/dist/builders/paginator.cjs.map +0 -1
  57. package/dist/builders/paginator.d.cts +0 -155
  58. package/dist/builders/paginator.d.ts +0 -155
  59. package/dist/builders/paginator.js +0 -191
  60. package/dist/builders/paginator.js.map +0 -1
  61. package/dist/builders/put-builder.cjs +0 -554
  62. package/dist/builders/put-builder.cjs.map +0 -1
  63. package/dist/builders/put-builder.d.cts +0 -319
  64. package/dist/builders/put-builder.d.ts +0 -319
  65. package/dist/builders/put-builder.js +0 -552
  66. package/dist/builders/put-builder.js.map +0 -1
  67. package/dist/builders/query-builder.cjs +0 -757
  68. package/dist/builders/query-builder.cjs.map +0 -1
  69. package/dist/builders/query-builder.d.cts +0 -6
  70. package/dist/builders/query-builder.d.ts +0 -6
  71. package/dist/builders/query-builder.js +0 -755
  72. package/dist/builders/query-builder.js.map +0 -1
  73. package/dist/builders/transaction-builder.cjs +0 -906
  74. package/dist/builders/transaction-builder.cjs.map +0 -1
  75. package/dist/builders/transaction-builder.d.cts +0 -464
  76. package/dist/builders/transaction-builder.d.ts +0 -464
  77. package/dist/builders/transaction-builder.js +0 -904
  78. package/dist/builders/transaction-builder.js.map +0 -1
  79. package/dist/builders/update-builder.cjs +0 -668
  80. package/dist/builders/update-builder.cjs.map +0 -1
  81. package/dist/builders/update-builder.d.cts +0 -374
  82. package/dist/builders/update-builder.d.ts +0 -374
  83. package/dist/builders/update-builder.js +0 -666
  84. package/dist/builders/update-builder.js.map +0 -1
  85. package/dist/conditions.cjs.map +0 -1
  86. package/dist/conditions.js.map +0 -1
  87. package/dist/entity.cjs.map +0 -1
  88. package/dist/entity.js.map +0 -1
  89. package/dist/index.cjs.map +0 -1
  90. package/dist/index.js.map +0 -1
  91. package/dist/query-builder-D3URwK9k.d.cts +0 -477
  92. package/dist/query-builder-cfEkU0_w.d.ts +0 -477
  93. package/dist/standard-schema.cjs.map +0 -1
  94. package/dist/standard-schema.js.map +0 -1
  95. package/dist/table-ClST8nkR.d.cts +0 -276
  96. package/dist/table-vE3cGoDy.d.ts +0 -276
  97. package/dist/table.cjs.map +0 -1
  98. package/dist/table.js.map +0 -1
  99. package/dist/types.cjs.map +0 -1
  100. package/dist/types.js.map +0 -1
  101. package/dist/utils.cjs.map +0 -1
  102. package/dist/utils.js.map +0 -1
@@ -1,757 +0,0 @@
1
- 'use strict';
2
-
3
- // src/conditions.ts
4
- var createComparisonCondition = (type) => (attr, value) => ({
5
- type,
6
- attr,
7
- value
8
- });
9
- var eq = createComparisonCondition("eq");
10
- var ne = createComparisonCondition("ne");
11
- var lt = createComparisonCondition("lt");
12
- var lte = createComparisonCondition("lte");
13
- var gt = createComparisonCondition("gt");
14
- var gte = createComparisonCondition("gte");
15
- var between = (attr, lower, upper) => ({
16
- type: "between",
17
- attr,
18
- value: [lower, upper]
19
- });
20
- var inArray = (attr, values) => ({
21
- type: "in",
22
- attr,
23
- value: values
24
- });
25
- var beginsWith = createComparisonCondition("beginsWith");
26
- var contains = createComparisonCondition("contains");
27
- var attributeExists = (attr) => ({
28
- type: "attributeExists",
29
- attr
30
- });
31
- var attributeNotExists = (attr) => ({
32
- type: "attributeNotExists",
33
- attr
34
- });
35
- var and = (...conditions) => ({
36
- type: "and",
37
- conditions
38
- });
39
- var or = (...conditions) => ({
40
- type: "or",
41
- conditions
42
- });
43
- var not = (condition) => ({
44
- type: "not",
45
- condition
46
- });
47
-
48
- // src/builders/paginator.ts
49
- var Paginator = class {
50
- queryBuilder;
51
- pageSize;
52
- currentPage = 0;
53
- lastEvaluatedKey;
54
- hasMorePages = true;
55
- totalItemsRetrieved = 0;
56
- overallLimit;
57
- constructor(queryBuilder, pageSize) {
58
- this.queryBuilder = queryBuilder;
59
- this.pageSize = pageSize;
60
- this.overallLimit = queryBuilder.getLimit();
61
- }
62
- /**
63
- * Gets the current page number (1-indexed).
64
- *
65
- * @example
66
- * ```ts
67
- * const paginator = new QueryBuilder(executor, eq('species', 'Tyrannosaurus'))
68
- * .paginate(5);
69
- *
70
- * await paginator.getNextPage();
71
- * console.log(`Reviewing T-Rex group ${paginator.getCurrentPage()}`);
72
- * ```
73
- *
74
- * @returns The current page number, starting from 1
75
- */
76
- getCurrentPage() {
77
- return this.currentPage;
78
- }
79
- /**
80
- * Checks if there are more pages of dinosaurs or habitats to process.
81
- *
82
- * This method takes into account both:
83
- * - DynamoDB's lastEvaluatedKey mechanism
84
- * - Any overall limit set on the query
85
- *
86
- * @example
87
- * ```ts
88
- * // Process all security incidents
89
- * const paginator = new QueryBuilder(executor, eq('type', 'SECURITY_BREACH'))
90
- * .sortDescending()
91
- * .paginate(10);
92
- *
93
- * while (paginator.hasNextPage()) {
94
- * const page = await paginator.getNextPage();
95
- * for (const incident of page.items) {
96
- * await processSecurityBreach(incident);
97
- * }
98
- * console.log(`Processed incidents page ${page.page}`);
99
- * }
100
- * ```
101
- *
102
- * @returns true if there are more pages available, false otherwise
103
- */
104
- hasNextPage() {
105
- if (this.overallLimit !== void 0 && this.totalItemsRetrieved >= this.overallLimit) {
106
- return false;
107
- }
108
- return this.hasMorePages;
109
- }
110
- /**
111
- * Retrieves the next page of dinosaurs or habitats from DynamoDB.
112
- *
113
- * This method handles:
114
- * - Automatic continuation between groups
115
- * - Respect for park capacity limits
116
- * - Group size adjustments for safety
117
- *
118
- * @example
119
- * ```ts
120
- * const paginator = new QueryBuilder(executor, eq('species', 'Velociraptor'))
121
- * .filter(op => op.eq('status', 'ACTIVE'))
122
- * .paginate(5);
123
- *
124
- * // Check first raptor group
125
- * const page1 = await paginator.getNextPage();
126
- * console.log(`Found ${page1.items.length} active raptors`);
127
- *
128
- * // Continue inspection if more groups exist
129
- * if (page1.hasNextPage) {
130
- * const page2 = await paginator.getNextPage();
131
- * console.log(`Inspecting raptor group ${page2.page}`);
132
- *
133
- * for (const raptor of page2.items) {
134
- * await performHealthCheck(raptor);
135
- * }
136
- * }
137
- * ```
138
- *
139
- * @returns A promise that resolves to a PaginationResult containing:
140
- * - items: The dinosaurs/habitats for this page
141
- * - hasNextPage: Whether more groups exist
142
- * - page: The current group number
143
- * - lastEvaluatedKey: DynamoDB's continuation token
144
- */
145
- async getNextPage() {
146
- if (!this.hasNextPage()) {
147
- return {
148
- items: [],
149
- hasNextPage: false,
150
- page: this.currentPage
151
- };
152
- }
153
- let effectivePageSize = this.pageSize;
154
- if (this.overallLimit !== void 0) {
155
- const remainingItems = this.overallLimit - this.totalItemsRetrieved;
156
- if (remainingItems <= 0) {
157
- return {
158
- items: [],
159
- hasNextPage: false,
160
- page: this.currentPage
161
- };
162
- }
163
- if (effectivePageSize !== void 0) {
164
- effectivePageSize = Math.min(effectivePageSize, remainingItems);
165
- } else {
166
- effectivePageSize = remainingItems;
167
- }
168
- }
169
- const query = this.queryBuilder.clone();
170
- if (effectivePageSize !== void 0) {
171
- query.limit(effectivePageSize);
172
- }
173
- if (this.lastEvaluatedKey) {
174
- query.startFrom(this.lastEvaluatedKey);
175
- }
176
- const generator = await query.execute();
177
- const items = [];
178
- let itemCount = 0;
179
- for await (const item of generator) {
180
- if (effectivePageSize !== void 0 && itemCount >= effectivePageSize) {
181
- break;
182
- }
183
- items.push(item);
184
- itemCount++;
185
- }
186
- const lastEvaluatedKey = generator.getLastEvaluatedKey();
187
- const result = { items, lastEvaluatedKey };
188
- this.currentPage += 1;
189
- this.lastEvaluatedKey = result.lastEvaluatedKey;
190
- this.totalItemsRetrieved += result.items.length;
191
- this.hasMorePages = !!result.lastEvaluatedKey && (this.overallLimit === void 0 || this.totalItemsRetrieved < this.overallLimit);
192
- return {
193
- items: result.items,
194
- lastEvaluatedKey: result.lastEvaluatedKey,
195
- hasNextPage: this.hasNextPage(),
196
- page: this.currentPage
197
- };
198
- }
199
- /**
200
- * Gets all remaining dinosaurs or habitats and combines them into a single array.
201
- *
202
- * @example
203
- * ```ts
204
- * // Get complete carnivore inventory
205
- * const paginator = new QueryBuilder(executor, eq('diet', 'CARNIVORE'))
206
- * .filter(op => op.eq('status', 'ACTIVE'))
207
- * .paginate(10);
208
- *
209
- * try {
210
- * const allCarnivores = await paginator.getAllPages();
211
- * console.log(`Park contains ${allCarnivores.length} active carnivores`);
212
- *
213
- * // Calculate total threat level
214
- * const totalThreat = allCarnivores.reduce(
215
- * (sum, dino) => sum + dino.stats.threatLevel,
216
- * 0
217
- * );
218
- * console.log(`Total threat level: ${totalThreat}`);
219
- * } catch (error) {
220
- * console.error('Failed to complete carnivore census:', error);
221
- * }
222
- * ```
223
- *
224
- * @returns A promise that resolves to an array containing all remaining items
225
- */
226
- async getAllPages() {
227
- const allItems = [];
228
- while (this.hasNextPage()) {
229
- const result = await this.getNextPage();
230
- allItems.push(...result.items);
231
- }
232
- return allItems;
233
- }
234
- };
235
-
236
- // src/builders/filter-builder.ts
237
- var FilterBuilder = class {
238
- options = {};
239
- selectedFields = /* @__PURE__ */ new Set();
240
- /**
241
- * Sets the maximum number of items to return.
242
- *
243
- * Note: This limit applies to the items that match the key condition
244
- * before any filter expressions are applied.
245
- *
246
- * @example
247
- * ```typescript
248
- * // Get first 10 dinosaurs
249
- * const result = await builder
250
- * .limit(10)
251
- * .execute();
252
- * ```
253
- *
254
- * @param limit - Maximum number of items to return
255
- * @returns The builder instance for method chaining
256
- */
257
- limit(limit) {
258
- this.options.limit = limit;
259
- return this;
260
- }
261
- /**
262
- * Gets the current limit set on the operation.
263
- * This is used internally by the paginator to manage result sets.
264
- *
265
- * @returns The current limit or undefined if no limit is set
266
- */
267
- getLimit() {
268
- return this.options.limit;
269
- }
270
- /**
271
- * Specifies a Global Secondary Index (GSI) to use for the operation.
272
- *
273
- * @example
274
- * ```typescript
275
- * // Find all dinosaurs of a specific species
276
- * builder
277
- * .useIndex('species-status-index')
278
- * .filter(op => op.eq('status', 'ACTIVE'));
279
- *
280
- * // Search high-security habitats
281
- * builder
282
- * .useIndex('security-level-index')
283
- * .filter(op =>
284
- * op.and([
285
- * op.gt('securityLevel', 8),
286
- * op.eq('status', 'OPERATIONAL')
287
- * ])
288
- * );
289
- * ```
290
- *
291
- * @param indexName - The name of the GSI to use (type-safe based on table configuration)
292
- * @returns The builder instance for method chaining
293
- */
294
- useIndex(indexName) {
295
- this.options.indexName = indexName;
296
- return this;
297
- }
298
- /**
299
- * Sets whether to use strongly consistent reads for the operation.
300
- *
301
- * Note:
302
- * - Consistent reads are not available on GSIs
303
- * - Consistent reads consume twice the throughput
304
- * - Default is eventually consistent reads
305
- *
306
- * @example
307
- * ```typescript
308
- * // Check immediate dinosaur status
309
- * const result = await builder
310
- * .filter(op => op.eq('status', 'ACTIVE'))
311
- * .consistentRead()
312
- * .execute();
313
- *
314
- * // Monitor security breaches
315
- * const result = await builder
316
- * .useIndex('primary-index')
317
- * .consistentRead(isEmergencyMode)
318
- * .execute();
319
- * ```
320
- *
321
- * @param consistentRead - Whether to use consistent reads (defaults to true)
322
- * @returns The builder instance for method chaining
323
- */
324
- consistentRead(consistentRead = true) {
325
- this.options.consistentRead = consistentRead;
326
- return this;
327
- }
328
- /**
329
- * Adds a filter expression to refine the operation results.
330
- *
331
- * @example
332
- * ```typescript
333
- * // Find aggressive carnivores
334
- * builder.filter(op =>
335
- * op.and([
336
- * op.eq('diet', 'CARNIVORE'),
337
- * op.gt('aggressionLevel', 7),
338
- * op.eq('status', 'ACTIVE')
339
- * ])
340
- * );
341
- *
342
- * // Search suitable breeding habitats
343
- * builder.filter(op =>
344
- * op.and([
345
- * op.between('temperature', 25, 30),
346
- * op.lt('currentOccupants', 3),
347
- * op.eq('quarantineStatus', 'CLEAR')
348
- * ])
349
- * );
350
- * ```
351
- *
352
- * @param condition - Either a Condition object or a callback function that builds the condition
353
- * @returns The builder instance for method chaining
354
- */
355
- filter(condition) {
356
- const newCondition = typeof condition === "function" ? condition(this.getConditionOperator()) : condition;
357
- if (this.options.filter) {
358
- if (this.options.filter.type === "and" && this.options.filter.conditions) {
359
- if (newCondition.type === "and" && newCondition.conditions) {
360
- this.options.filter = {
361
- type: "and",
362
- conditions: [...this.options.filter.conditions, ...newCondition.conditions]
363
- };
364
- } else {
365
- this.options.filter = {
366
- type: "and",
367
- conditions: [...this.options.filter.conditions, newCondition]
368
- };
369
- }
370
- } else {
371
- if (newCondition.type === "and" && newCondition.conditions) {
372
- this.options.filter = {
373
- type: "and",
374
- conditions: [this.options.filter, ...newCondition.conditions]
375
- };
376
- } else {
377
- this.options.filter = and(this.options.filter, newCondition);
378
- }
379
- }
380
- } else {
381
- this.options.filter = newCondition;
382
- }
383
- return this;
384
- }
385
- getConditionOperator() {
386
- return {
387
- eq,
388
- ne,
389
- lt,
390
- lte,
391
- gt,
392
- gte,
393
- between,
394
- inArray,
395
- beginsWith,
396
- contains,
397
- attributeExists,
398
- attributeNotExists,
399
- and,
400
- or,
401
- not
402
- };
403
- }
404
- /**
405
- * Specifies which attributes to return in the results.
406
- *
407
- * @example
408
- * ```typescript
409
- * // Get basic dinosaur info
410
- * builder.select([
411
- * 'species',
412
- * 'status',
413
- * 'stats.health',
414
- * 'stats.aggressionLevel'
415
- * ]);
416
- *
417
- * // Monitor habitat conditions
418
- * builder
419
- * .select('securityStatus')
420
- * .select([
421
- * 'currentOccupants',
422
- * 'temperature',
423
- * 'lastInspectionDate'
424
- * ]);
425
- * ```
426
- *
427
- * @param fields - A single field name or an array of field names to return
428
- * @returns The builder instance for method chaining
429
- */
430
- select(fields) {
431
- if (typeof fields === "string") {
432
- this.selectedFields.add(fields);
433
- } else if (Array.isArray(fields)) {
434
- for (const field of fields) {
435
- this.selectedFields.add(field);
436
- }
437
- }
438
- this.options.projection = Array.from(this.selectedFields);
439
- return this;
440
- }
441
- /**
442
- * Creates a paginator that handles DynamoDB pagination automatically.
443
- * The paginator handles:
444
- * - Tracking the last evaluated key
445
- * - Managing page boundaries
446
- * - Respecting overall query limits
447
- *
448
- * @example
449
- * ```typescript
450
- * // Create a paginator for dinosaur records with specific page size
451
- * const paginator = builder
452
- * .filter(op => op.eq('status', 'ACTIVE'))
453
- * .paginate(10);
454
- *
455
- * // Create a paginator with automatic DynamoDB paging (no page size limit)
456
- * const autoPaginator = builder
457
- * .filter(op => op.eq('status', 'ACTIVE'))
458
- * .paginate();
459
- *
460
- * // Process pages of dinosaur results
461
- * while (paginator.hasNextPage()) {
462
- * const page = await paginator.getNextPage();
463
- * console.log(`Processing page ${page.page}, count: ${page.items.length}`);
464
- * // Process dinosaur data
465
- * }
466
- * ```
467
- *
468
- * @param pageSize - The number of items to return per page. If not provided, DynamoDB will automatically determine page sizes.
469
- * @returns A Paginator instance that manages the pagination state
470
- * @see Paginator for more pagination control options
471
- */
472
- paginate(pageSize) {
473
- return new Paginator(this, pageSize);
474
- }
475
- /**
476
- * Sets the starting point using a previous lastEvaluatedKey.
477
- *
478
- * Note: This method is typically used for manual pagination.
479
- * For automatic pagination, use the paginate() method instead.
480
- *
481
- * @example
482
- * ```typescript
483
- * // First batch of dinosaurs
484
- * const result1 = await builder
485
- * .filter(op => op.eq('status', 'ACTIVE'))
486
- * .limit(5)
487
- * .execute();
488
- *
489
- * const lastKey = result1.getLastEvaluatedKey();
490
- * if (lastKey) {
491
- * // Continue listing dinosaurs
492
- * const result2 = await builder
493
- * .filter(op => op.eq('status', 'ACTIVE'))
494
- * .startFrom(lastKey)
495
- * .limit(5)
496
- * .execute();
497
- *
498
- * const items = await result2.toArray();
499
- * console.log('Additional dinosaurs:', items);
500
- * }
501
- * ```
502
- *
503
- * @param lastEvaluatedKey - The exclusive start key from a previous result
504
- * @returns The builder instance for method chaining
505
- */
506
- startFrom(lastEvaluatedKey) {
507
- this.options.lastEvaluatedKey = lastEvaluatedKey;
508
- return this;
509
- }
510
- };
511
-
512
- // src/builders/result-iterator.ts
513
- var ResultIterator = class {
514
- constructor(queryBuilder, directExecutor) {
515
- this.queryBuilder = queryBuilder;
516
- this.directExecutor = directExecutor;
517
- this.overallLimit = queryBuilder.getLimit();
518
- }
519
- lastEvaluatedKey;
520
- itemsYielded = 0;
521
- overallLimit;
522
- /**
523
- * Async iterator with automatic pagination
524
- */
525
- async *[Symbol.asyncIterator]() {
526
- let hasMorePages = true;
527
- while (hasMorePages) {
528
- const result = await this.directExecutor();
529
- for (const item of result.items) {
530
- if (this.overallLimit !== void 0 && this.itemsYielded >= this.overallLimit) {
531
- return;
532
- }
533
- yield item;
534
- this.itemsYielded++;
535
- }
536
- if (result.lastEvaluatedKey !== null && result.lastEvaluatedKey !== void 0) {
537
- this.lastEvaluatedKey = result.lastEvaluatedKey;
538
- this.queryBuilder.startFrom(result.lastEvaluatedKey);
539
- } else if (result.lastEvaluatedKey === null) {
540
- if (this.lastEvaluatedKey === void 0) {
541
- this.lastEvaluatedKey = null;
542
- }
543
- }
544
- hasMorePages = !!result.lastEvaluatedKey && (this.overallLimit === void 0 || this.itemsYielded < this.overallLimit);
545
- }
546
- }
547
- /**
548
- * Convert to array (loads all pages).
549
- *
550
- * ```ts
551
- * const result = await table.query({ pk: "foo" }).execute();
552
- * const allItemsFromDynamo = await result.toArray();
553
- * ```
554
- *
555
- * Note: This will load all pages into memory. For large datasets, consider using async iteration instead.
556
- *```ts
557
- * const result = await table.query({ pk: "foo" }).execute();
558
- * for await (const item of result) {
559
- * // Process each item
560
- * }
561
- * ```
562
- */
563
- async toArray() {
564
- const items = [];
565
- for await (const item of this) {
566
- items.push(item);
567
- }
568
- return items;
569
- }
570
- /**
571
- * Get the last evaluated key
572
- */
573
- getLastEvaluatedKey() {
574
- return this.lastEvaluatedKey === null ? void 0 : this.lastEvaluatedKey;
575
- }
576
- };
577
-
578
- // src/builders/query-builder.ts
579
- var QueryBuilder = class _QueryBuilder extends FilterBuilder {
580
- keyCondition;
581
- options = {};
582
- executor;
583
- constructor(executor, keyCondition) {
584
- super();
585
- this.executor = executor;
586
- this.keyCondition = keyCondition;
587
- }
588
- /**
589
- * Sets the maximum number of items to return from the query.
590
- *
591
- * Note: This is the default behavior if no sort order is specified.
592
- *
593
- * @example
594
- * ```typescript
595
- * // Get orders in chronological order
596
- * const result = await new QueryBuilder(executor, eq('userId', '123'))
597
- * .sortAscending()
598
- * .execute();
599
- *
600
- * // Get events from oldest to newest
601
- * const result = await new QueryBuilder(executor, eq('entityId', 'order-123'))
602
- * .useIndex('entity-timestamp-index')
603
- * .sortAscending()
604
- * .execute();
605
- * ```
606
- *
607
- * @returns The builder instance for method chaining
608
- */
609
- /**
610
- * Sets the query to return items in ascending order by sort key.
611
- *
612
- * @example
613
- * ```typescript
614
- * // List dinosaurs by age
615
- * const result = await new QueryBuilder(executor, eq('species', 'Velociraptor'))
616
- * .useIndex('age-index')
617
- * .sortAscending()
618
- * .execute();
619
- *
620
- * // View incidents chronologically
621
- * const result = await new QueryBuilder(executor, eq('type', 'SECURITY_BREACH'))
622
- * .useIndex('date-index')
623
- * .sortAscending()
624
- * .execute();
625
- * ```
626
- *
627
- * @returns The builder instance for method chaining
628
- */
629
- sortAscending() {
630
- this.options.scanIndexForward = true;
631
- return this;
632
- }
633
- /**
634
- * Sets the query to return items in descending order by sort key.
635
- *
636
- * @example
637
- * ```typescript
638
- * // Get most recent security incidents
639
- * const result = await new QueryBuilder(executor, eq('type', 'SECURITY_BREACH'))
640
- * .useIndex('date-index')
641
- * .sortDescending()
642
- * .limit(10)
643
- * .execute();
644
- *
645
- * // Check latest dinosaur activities
646
- * const result = await new QueryBuilder(executor, eq('species', 'Velociraptor'))
647
- * .useIndex('activity-time-index')
648
- * .filter(op => op.eq('status', 'ACTIVE'))
649
- * .sortDescending()
650
- * .execute();
651
- * ```
652
- *
653
- * @returns The builder instance for method chaining
654
- */
655
- sortDescending() {
656
- this.options.scanIndexForward = false;
657
- return this;
658
- }
659
- /**
660
- * Creates a deep clone of this QueryBuilder instance.
661
- *
662
- * This is particularly useful when:
663
- * - Implementing pagination (used internally by paginate())
664
- * - Creating query templates
665
- * - Running multiple variations of a query
666
- *
667
- * @example
668
- * ```typescript
669
- * // Create base dinosaur query
670
- * const baseQuery = new QueryBuilder(executor, eq('species', 'Velociraptor'))
671
- * .useIndex('status-index')
672
- * .select(['id', 'status', 'location']);
673
- *
674
- * // Check active dinosaurs
675
- * const activeRaptors = baseQuery.clone()
676
- * .filter(op => op.eq('status', 'HUNTING'))
677
- * .execute();
678
- *
679
- * // Check contained dinosaurs
680
- * const containedRaptors = baseQuery.clone()
681
- * .filter(op => op.eq('status', 'CONTAINED'))
682
- * .execute();
683
- *
684
- * // Check sedated dinosaurs
685
- * const sedatedRaptors = baseQuery.clone()
686
- * .filter(op => op.eq('status', 'SEDATED'))
687
- * .execute();
688
- * ```
689
- *
690
- * @returns A new QueryBuilder instance with the same configuration
691
- */
692
- clone() {
693
- const clone = new _QueryBuilder(this.executor, this.keyCondition);
694
- clone.options = {
695
- ...this.options,
696
- filter: this.deepCloneFilter(this.options.filter)
697
- };
698
- clone.selectedFields = new Set(this.selectedFields);
699
- return clone;
700
- }
701
- deepCloneFilter(filter) {
702
- if (!filter) return filter;
703
- if (filter.type === "and" || filter.type === "or") {
704
- return {
705
- ...filter,
706
- conditions: filter.conditions?.map((condition) => this.deepCloneFilter(condition)).filter((c) => c !== void 0)
707
- };
708
- }
709
- return { ...filter };
710
- }
711
- /**
712
- * Executes the query against DynamoDB and returns a generator that behaves like an array.
713
- *
714
- * The generator automatically handles pagination and provides array-like methods
715
- * for processing results efficiently without loading everything into memory at once.
716
- *
717
- * @example
718
- * ```typescript
719
- * try {
720
- * // Find active carnivores with automatic pagination
721
- * const results = await new QueryBuilder(executor, eq('habitatId', 'PADDOCK-A'))
722
- * .useIndex('species-status-index')
723
- * .filter(op =>
724
- * op.and([
725
- * op.eq('diet', 'CARNIVORE'),
726
- * op.eq('status', 'ACTIVE'),
727
- * op.gt('aggressionLevel', 7)
728
- * ])
729
- * )
730
- * .sortDescending()
731
- * .execute();
732
- *
733
- * // Use like an array with automatic pagination
734
- * for await (const dinosaur of results) {
735
- * console.log(`Processing ${dinosaur.name}`);
736
- * }
737
- *
738
- * // Or convert to array and use array methods
739
- * const allItems = await results.toArray();
740
- * const dangerousOnes = allItems.filter(dino => dino.aggressionLevel > 9);
741
- * const totalCount = allItems.length;
742
- * } catch (error) {
743
- * console.error('Security scan failed:', error);
744
- * }
745
- * ```
746
- *
747
- * @returns A promise that resolves to a ResultGenerator that behaves like an array
748
- */
749
- async execute() {
750
- const directExecutor = () => this.executor(this.keyCondition, this.options);
751
- return new ResultIterator(this, directExecutor);
752
- }
753
- };
754
-
755
- exports.QueryBuilder = QueryBuilder;
756
- //# sourceMappingURL=query-builder.cjs.map
757
- //# sourceMappingURL=query-builder.cjs.map