dyno-table 2.2.0 → 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 (106) 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-CC3NDfUU.d.cts → conditions-CcZL0sR2.d.cts} +1 -1
  17. package/dist/{conditions-DD0bvyHm.d.ts → conditions-D_w7vVYG.d.ts} +1 -1
  18. package/dist/conditions.cjs +67 -62
  19. package/dist/conditions.d.cts +1 -1
  20. package/dist/conditions.d.ts +1 -1
  21. package/dist/conditions.js +1 -48
  22. package/dist/entity.cjs +14 -625
  23. package/dist/entity.d.cts +5 -13
  24. package/dist/entity.d.ts +5 -13
  25. package/dist/entity.js +2 -626
  26. package/dist/index-2cbm07Bi.d.ts +2797 -0
  27. package/dist/index-DlN8G9hd.d.cts +2797 -0
  28. package/dist/index.cjs +111 -4446
  29. package/dist/index.d.cts +3 -11
  30. package/dist/index.d.ts +3 -11
  31. package/dist/index.js +5 -4428
  32. package/dist/standard-schema.cjs +0 -2
  33. package/dist/standard-schema.js +0 -2
  34. package/dist/table.cjs +7 -3782
  35. package/dist/table.d.cts +163 -12
  36. package/dist/table.d.ts +163 -12
  37. package/dist/table.js +3 -3785
  38. package/dist/types.cjs +0 -2
  39. package/dist/types.js +0 -2
  40. package/dist/utils.cjs +10 -30
  41. package/dist/utils.js +1 -31
  42. package/package.json +12 -67
  43. package/dist/batch-builder-BPoHyN_Q.d.cts +0 -398
  44. package/dist/batch-builder-Cdo49C2r.d.ts +0 -398
  45. package/dist/builder-types-BTVhQSHI.d.cts +0 -169
  46. package/dist/builder-types-CzuLR4Th.d.ts +0 -169
  47. package/dist/builders/condition-check-builder.cjs +0 -422
  48. package/dist/builders/condition-check-builder.cjs.map +0 -1
  49. package/dist/builders/condition-check-builder.d.cts +0 -153
  50. package/dist/builders/condition-check-builder.d.ts +0 -153
  51. package/dist/builders/condition-check-builder.js +0 -420
  52. package/dist/builders/condition-check-builder.js.map +0 -1
  53. package/dist/builders/delete-builder.cjs +0 -484
  54. package/dist/builders/delete-builder.cjs.map +0 -1
  55. package/dist/builders/delete-builder.d.cts +0 -211
  56. package/dist/builders/delete-builder.d.ts +0 -211
  57. package/dist/builders/delete-builder.js +0 -482
  58. package/dist/builders/delete-builder.js.map +0 -1
  59. package/dist/builders/paginator.cjs +0 -193
  60. package/dist/builders/paginator.cjs.map +0 -1
  61. package/dist/builders/paginator.d.cts +0 -155
  62. package/dist/builders/paginator.d.ts +0 -155
  63. package/dist/builders/paginator.js +0 -191
  64. package/dist/builders/paginator.js.map +0 -1
  65. package/dist/builders/put-builder.cjs +0 -554
  66. package/dist/builders/put-builder.cjs.map +0 -1
  67. package/dist/builders/put-builder.d.cts +0 -319
  68. package/dist/builders/put-builder.d.ts +0 -319
  69. package/dist/builders/put-builder.js +0 -552
  70. package/dist/builders/put-builder.js.map +0 -1
  71. package/dist/builders/query-builder.cjs +0 -743
  72. package/dist/builders/query-builder.cjs.map +0 -1
  73. package/dist/builders/query-builder.d.cts +0 -6
  74. package/dist/builders/query-builder.d.ts +0 -6
  75. package/dist/builders/query-builder.js +0 -741
  76. package/dist/builders/query-builder.js.map +0 -1
  77. package/dist/builders/transaction-builder.cjs +0 -906
  78. package/dist/builders/transaction-builder.cjs.map +0 -1
  79. package/dist/builders/transaction-builder.d.cts +0 -464
  80. package/dist/builders/transaction-builder.d.ts +0 -464
  81. package/dist/builders/transaction-builder.js +0 -904
  82. package/dist/builders/transaction-builder.js.map +0 -1
  83. package/dist/builders/update-builder.cjs +0 -668
  84. package/dist/builders/update-builder.cjs.map +0 -1
  85. package/dist/builders/update-builder.d.cts +0 -374
  86. package/dist/builders/update-builder.d.ts +0 -374
  87. package/dist/builders/update-builder.js +0 -666
  88. package/dist/builders/update-builder.js.map +0 -1
  89. package/dist/conditions.cjs.map +0 -1
  90. package/dist/conditions.js.map +0 -1
  91. package/dist/entity.cjs.map +0 -1
  92. package/dist/entity.js.map +0 -1
  93. package/dist/index.cjs.map +0 -1
  94. package/dist/index.js.map +0 -1
  95. package/dist/query-builder-CUWdavZw.d.ts +0 -477
  96. package/dist/query-builder-DoZzZz_c.d.cts +0 -477
  97. package/dist/standard-schema.cjs.map +0 -1
  98. package/dist/standard-schema.js.map +0 -1
  99. package/dist/table-CZBMkW2Z.d.ts +0 -276
  100. package/dist/table-f-3wsT7K.d.cts +0 -276
  101. package/dist/table.cjs.map +0 -1
  102. package/dist/table.js.map +0 -1
  103. package/dist/types.cjs.map +0 -1
  104. package/dist/types.js.map +0 -1
  105. package/dist/utils.cjs.map +0 -1
  106. package/dist/utils.js.map +0 -1
@@ -1,743 +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
- this.options.filter = {
360
- type: "and",
361
- conditions: [...this.options.filter.conditions, newCondition]
362
- };
363
- } else {
364
- this.options.filter = and(this.options.filter, newCondition);
365
- }
366
- } else {
367
- this.options.filter = newCondition;
368
- }
369
- return this;
370
- }
371
- getConditionOperator() {
372
- return {
373
- eq,
374
- ne,
375
- lt,
376
- lte,
377
- gt,
378
- gte,
379
- between,
380
- inArray,
381
- beginsWith,
382
- contains,
383
- attributeExists,
384
- attributeNotExists,
385
- and,
386
- or,
387
- not
388
- };
389
- }
390
- /**
391
- * Specifies which attributes to return in the results.
392
- *
393
- * @example
394
- * ```typescript
395
- * // Get basic dinosaur info
396
- * builder.select([
397
- * 'species',
398
- * 'status',
399
- * 'stats.health',
400
- * 'stats.aggressionLevel'
401
- * ]);
402
- *
403
- * // Monitor habitat conditions
404
- * builder
405
- * .select('securityStatus')
406
- * .select([
407
- * 'currentOccupants',
408
- * 'temperature',
409
- * 'lastInspectionDate'
410
- * ]);
411
- * ```
412
- *
413
- * @param fields - A single field name or an array of field names to return
414
- * @returns The builder instance for method chaining
415
- */
416
- select(fields) {
417
- if (typeof fields === "string") {
418
- this.selectedFields.add(fields);
419
- } else if (Array.isArray(fields)) {
420
- for (const field of fields) {
421
- this.selectedFields.add(field);
422
- }
423
- }
424
- this.options.projection = Array.from(this.selectedFields);
425
- return this;
426
- }
427
- /**
428
- * Creates a paginator that handles DynamoDB pagination automatically.
429
- * The paginator handles:
430
- * - Tracking the last evaluated key
431
- * - Managing page boundaries
432
- * - Respecting overall query limits
433
- *
434
- * @example
435
- * ```typescript
436
- * // Create a paginator for dinosaur records with specific page size
437
- * const paginator = builder
438
- * .filter(op => op.eq('status', 'ACTIVE'))
439
- * .paginate(10);
440
- *
441
- * // Create a paginator with automatic DynamoDB paging (no page size limit)
442
- * const autoPaginator = builder
443
- * .filter(op => op.eq('status', 'ACTIVE'))
444
- * .paginate();
445
- *
446
- * // Process pages of dinosaur results
447
- * while (paginator.hasNextPage()) {
448
- * const page = await paginator.getNextPage();
449
- * console.log(`Processing page ${page.page}, count: ${page.items.length}`);
450
- * // Process dinosaur data
451
- * }
452
- * ```
453
- *
454
- * @param pageSize - The number of items to return per page. If not provided, DynamoDB will automatically determine page sizes.
455
- * @returns A Paginator instance that manages the pagination state
456
- * @see Paginator for more pagination control options
457
- */
458
- paginate(pageSize) {
459
- return new Paginator(this, pageSize);
460
- }
461
- /**
462
- * Sets the starting point using a previous lastEvaluatedKey.
463
- *
464
- * Note: This method is typically used for manual pagination.
465
- * For automatic pagination, use the paginate() method instead.
466
- *
467
- * @example
468
- * ```typescript
469
- * // First batch of dinosaurs
470
- * const result1 = await builder
471
- * .filter(op => op.eq('status', 'ACTIVE'))
472
- * .limit(5)
473
- * .execute();
474
- *
475
- * const lastKey = result1.getLastEvaluatedKey();
476
- * if (lastKey) {
477
- * // Continue listing dinosaurs
478
- * const result2 = await builder
479
- * .filter(op => op.eq('status', 'ACTIVE'))
480
- * .startFrom(lastKey)
481
- * .limit(5)
482
- * .execute();
483
- *
484
- * const items = await result2.toArray();
485
- * console.log('Additional dinosaurs:', items);
486
- * }
487
- * ```
488
- *
489
- * @param lastEvaluatedKey - The exclusive start key from a previous result
490
- * @returns The builder instance for method chaining
491
- */
492
- startFrom(lastEvaluatedKey) {
493
- this.options.lastEvaluatedKey = lastEvaluatedKey;
494
- return this;
495
- }
496
- };
497
-
498
- // src/builders/result-iterator.ts
499
- var ResultIterator = class {
500
- constructor(queryBuilder, directExecutor) {
501
- this.queryBuilder = queryBuilder;
502
- this.directExecutor = directExecutor;
503
- this.overallLimit = queryBuilder.getLimit();
504
- }
505
- lastEvaluatedKey;
506
- itemsYielded = 0;
507
- overallLimit;
508
- /**
509
- * Async iterator with automatic pagination
510
- */
511
- async *[Symbol.asyncIterator]() {
512
- let hasMorePages = true;
513
- while (hasMorePages) {
514
- const result = await this.directExecutor();
515
- for (const item of result.items) {
516
- if (this.overallLimit !== void 0 && this.itemsYielded >= this.overallLimit) {
517
- return;
518
- }
519
- yield item;
520
- this.itemsYielded++;
521
- }
522
- if (result.lastEvaluatedKey !== null && result.lastEvaluatedKey !== void 0) {
523
- this.lastEvaluatedKey = result.lastEvaluatedKey;
524
- this.queryBuilder.startFrom(result.lastEvaluatedKey);
525
- } else if (result.lastEvaluatedKey === null) {
526
- if (this.lastEvaluatedKey === void 0) {
527
- this.lastEvaluatedKey = null;
528
- }
529
- }
530
- hasMorePages = !!result.lastEvaluatedKey && (this.overallLimit === void 0 || this.itemsYielded < this.overallLimit);
531
- }
532
- }
533
- /**
534
- * Convert to array (loads all pages).
535
- *
536
- * ```ts
537
- * const result = await table.query({ pk: "foo" }).execute();
538
- * const allItemsFromDynamo = await result.toArray();
539
- * ```
540
- *
541
- * Note: This will load all pages into memory. For large datasets, consider using async iteration instead.
542
- *```ts
543
- * const result = await table.query({ pk: "foo" }).execute();
544
- * for await (const item of result) {
545
- * // Process each item
546
- * }
547
- * ```
548
- */
549
- async toArray() {
550
- const items = [];
551
- for await (const item of this) {
552
- items.push(item);
553
- }
554
- return items;
555
- }
556
- /**
557
- * Get the last evaluated key
558
- */
559
- getLastEvaluatedKey() {
560
- return this.lastEvaluatedKey === null ? void 0 : this.lastEvaluatedKey;
561
- }
562
- };
563
-
564
- // src/builders/query-builder.ts
565
- var QueryBuilder = class _QueryBuilder extends FilterBuilder {
566
- keyCondition;
567
- options = {};
568
- executor;
569
- constructor(executor, keyCondition) {
570
- super();
571
- this.executor = executor;
572
- this.keyCondition = keyCondition;
573
- }
574
- /**
575
- * Sets the maximum number of items to return from the query.
576
- *
577
- * Note: This is the default behavior if no sort order is specified.
578
- *
579
- * @example
580
- * ```typescript
581
- * // Get orders in chronological order
582
- * const result = await new QueryBuilder(executor, eq('userId', '123'))
583
- * .sortAscending()
584
- * .execute();
585
- *
586
- * // Get events from oldest to newest
587
- * const result = await new QueryBuilder(executor, eq('entityId', 'order-123'))
588
- * .useIndex('entity-timestamp-index')
589
- * .sortAscending()
590
- * .execute();
591
- * ```
592
- *
593
- * @returns The builder instance for method chaining
594
- */
595
- /**
596
- * Sets the query to return items in ascending order by sort key.
597
- *
598
- * @example
599
- * ```typescript
600
- * // List dinosaurs by age
601
- * const result = await new QueryBuilder(executor, eq('species', 'Velociraptor'))
602
- * .useIndex('age-index')
603
- * .sortAscending()
604
- * .execute();
605
- *
606
- * // View incidents chronologically
607
- * const result = await new QueryBuilder(executor, eq('type', 'SECURITY_BREACH'))
608
- * .useIndex('date-index')
609
- * .sortAscending()
610
- * .execute();
611
- * ```
612
- *
613
- * @returns The builder instance for method chaining
614
- */
615
- sortAscending() {
616
- this.options.scanIndexForward = true;
617
- return this;
618
- }
619
- /**
620
- * Sets the query to return items in descending order by sort key.
621
- *
622
- * @example
623
- * ```typescript
624
- * // Get most recent security incidents
625
- * const result = await new QueryBuilder(executor, eq('type', 'SECURITY_BREACH'))
626
- * .useIndex('date-index')
627
- * .sortDescending()
628
- * .limit(10)
629
- * .execute();
630
- *
631
- * // Check latest dinosaur activities
632
- * const result = await new QueryBuilder(executor, eq('species', 'Velociraptor'))
633
- * .useIndex('activity-time-index')
634
- * .filter(op => op.eq('status', 'ACTIVE'))
635
- * .sortDescending()
636
- * .execute();
637
- * ```
638
- *
639
- * @returns The builder instance for method chaining
640
- */
641
- sortDescending() {
642
- this.options.scanIndexForward = false;
643
- return this;
644
- }
645
- /**
646
- * Creates a deep clone of this QueryBuilder instance.
647
- *
648
- * This is particularly useful when:
649
- * - Implementing pagination (used internally by paginate())
650
- * - Creating query templates
651
- * - Running multiple variations of a query
652
- *
653
- * @example
654
- * ```typescript
655
- * // Create base dinosaur query
656
- * const baseQuery = new QueryBuilder(executor, eq('species', 'Velociraptor'))
657
- * .useIndex('status-index')
658
- * .select(['id', 'status', 'location']);
659
- *
660
- * // Check active dinosaurs
661
- * const activeRaptors = baseQuery.clone()
662
- * .filter(op => op.eq('status', 'HUNTING'))
663
- * .execute();
664
- *
665
- * // Check contained dinosaurs
666
- * const containedRaptors = baseQuery.clone()
667
- * .filter(op => op.eq('status', 'CONTAINED'))
668
- * .execute();
669
- *
670
- * // Check sedated dinosaurs
671
- * const sedatedRaptors = baseQuery.clone()
672
- * .filter(op => op.eq('status', 'SEDATED'))
673
- * .execute();
674
- * ```
675
- *
676
- * @returns A new QueryBuilder instance with the same configuration
677
- */
678
- clone() {
679
- const clone = new _QueryBuilder(this.executor, this.keyCondition);
680
- clone.options = {
681
- ...this.options,
682
- filter: this.deepCloneFilter(this.options.filter)
683
- };
684
- clone.selectedFields = new Set(this.selectedFields);
685
- return clone;
686
- }
687
- deepCloneFilter(filter) {
688
- if (!filter) return filter;
689
- if (filter.type === "and" || filter.type === "or") {
690
- return {
691
- ...filter,
692
- conditions: filter.conditions?.map((condition) => this.deepCloneFilter(condition)).filter((c) => c !== void 0)
693
- };
694
- }
695
- return { ...filter };
696
- }
697
- /**
698
- * Executes the query against DynamoDB and returns a generator that behaves like an array.
699
- *
700
- * The generator automatically handles pagination and provides array-like methods
701
- * for processing results efficiently without loading everything into memory at once.
702
- *
703
- * @example
704
- * ```typescript
705
- * try {
706
- * // Find active carnivores with automatic pagination
707
- * const results = await new QueryBuilder(executor, eq('habitatId', 'PADDOCK-A'))
708
- * .useIndex('species-status-index')
709
- * .filter(op =>
710
- * op.and([
711
- * op.eq('diet', 'CARNIVORE'),
712
- * op.eq('status', 'ACTIVE'),
713
- * op.gt('aggressionLevel', 7)
714
- * ])
715
- * )
716
- * .sortDescending()
717
- * .execute();
718
- *
719
- * // Use like an array with automatic pagination
720
- * for await (const dinosaur of results) {
721
- * console.log(`Processing ${dinosaur.name}`);
722
- * }
723
- *
724
- * // Or convert to array and use array methods
725
- * const allItems = await results.toArray();
726
- * const dangerousOnes = allItems.filter(dino => dino.aggressionLevel > 9);
727
- * const totalCount = allItems.length;
728
- * } catch (error) {
729
- * console.error('Security scan failed:', error);
730
- * }
731
- * ```
732
- *
733
- * @returns A promise that resolves to a ResultGenerator that behaves like an array
734
- */
735
- async execute() {
736
- const directExecutor = () => this.executor(this.keyCondition, this.options);
737
- return new ResultIterator(this, directExecutor);
738
- }
739
- };
740
-
741
- exports.QueryBuilder = QueryBuilder;
742
- //# sourceMappingURL=query-builder.cjs.map
743
- //# sourceMappingURL=query-builder.cjs.map