dyno-table 1.0.0-alpha.1 → 1.1.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 (96) hide show
  1. package/README.md +752 -172
  2. package/dist/builder-types-C_PDZhnP.d.ts +118 -0
  3. package/dist/builder-types-DtwbqMeF.d.cts +118 -0
  4. package/dist/builders/condition-check-builder.cjs +394 -0
  5. package/dist/builders/condition-check-builder.cjs.map +1 -0
  6. package/dist/builders/condition-check-builder.d.cts +157 -0
  7. package/dist/builders/condition-check-builder.d.ts +157 -0
  8. package/dist/builders/condition-check-builder.js +392 -0
  9. package/dist/builders/condition-check-builder.js.map +1 -0
  10. package/dist/builders/delete-builder.cjs +405 -0
  11. package/dist/builders/delete-builder.cjs.map +1 -0
  12. package/dist/builders/delete-builder.d.cts +166 -0
  13. package/dist/builders/delete-builder.d.ts +166 -0
  14. package/dist/builders/delete-builder.js +403 -0
  15. package/dist/builders/delete-builder.js.map +1 -0
  16. package/dist/builders/paginator.cjs +199 -0
  17. package/dist/builders/paginator.cjs.map +1 -0
  18. package/dist/builders/paginator.d.cts +179 -0
  19. package/dist/builders/paginator.d.ts +179 -0
  20. package/dist/builders/paginator.js +197 -0
  21. package/dist/builders/paginator.js.map +1 -0
  22. package/dist/builders/put-builder.cjs +476 -0
  23. package/dist/builders/put-builder.cjs.map +1 -0
  24. package/dist/builders/put-builder.d.cts +274 -0
  25. package/dist/builders/put-builder.d.ts +274 -0
  26. package/dist/builders/put-builder.js +474 -0
  27. package/dist/builders/put-builder.js.map +1 -0
  28. package/dist/builders/query-builder.cjs +674 -0
  29. package/dist/builders/query-builder.cjs.map +1 -0
  30. package/dist/builders/query-builder.d.cts +6 -0
  31. package/dist/builders/query-builder.d.ts +6 -0
  32. package/dist/builders/query-builder.js +672 -0
  33. package/dist/builders/query-builder.js.map +1 -0
  34. package/dist/builders/transaction-builder.cjs +918 -0
  35. package/dist/builders/transaction-builder.cjs.map +1 -0
  36. package/dist/builders/transaction-builder.d.cts +511 -0
  37. package/dist/builders/transaction-builder.d.ts +511 -0
  38. package/dist/builders/transaction-builder.js +916 -0
  39. package/dist/builders/transaction-builder.js.map +1 -0
  40. package/dist/builders/update-builder.cjs +627 -0
  41. package/dist/builders/update-builder.cjs.map +1 -0
  42. package/dist/builders/update-builder.d.cts +365 -0
  43. package/dist/builders/update-builder.d.ts +365 -0
  44. package/dist/builders/update-builder.js +625 -0
  45. package/dist/builders/update-builder.js.map +1 -0
  46. package/dist/conditions--ld9a78i.d.ts +331 -0
  47. package/dist/conditions-ChhQWd6z.d.cts +331 -0
  48. package/dist/conditions.cjs +59 -0
  49. package/dist/conditions.cjs.map +1 -0
  50. package/dist/conditions.d.cts +3 -0
  51. package/dist/conditions.d.ts +3 -0
  52. package/dist/conditions.js +43 -0
  53. package/dist/conditions.js.map +1 -0
  54. package/dist/entity.cjs +211 -0
  55. package/dist/entity.cjs.map +1 -0
  56. package/dist/entity.d.cts +149 -0
  57. package/dist/entity.d.ts +149 -0
  58. package/dist/entity.js +207 -0
  59. package/dist/entity.js.map +1 -0
  60. package/dist/query-builder-Csror9Iu.d.ts +507 -0
  61. package/dist/query-builder-D2FM9rsu.d.cts +507 -0
  62. package/dist/standard-schema.cjs +4 -0
  63. package/dist/standard-schema.cjs.map +1 -0
  64. package/dist/standard-schema.d.cts +57 -0
  65. package/dist/standard-schema.d.ts +57 -0
  66. package/dist/standard-schema.js +3 -0
  67. package/dist/standard-schema.js.map +1 -0
  68. package/dist/table-BEhBPy2G.d.cts +364 -0
  69. package/dist/table-BW3cmUqr.d.ts +364 -0
  70. package/dist/{index.cjs → table.cjs} +108 -175
  71. package/dist/table.cjs.map +1 -0
  72. package/dist/table.d.cts +12 -0
  73. package/dist/table.d.ts +12 -0
  74. package/dist/{index.js → table.js} +107 -127
  75. package/dist/table.js.map +1 -0
  76. package/dist/types.cjs +4 -0
  77. package/dist/types.cjs.map +1 -0
  78. package/dist/types.d.cts +22 -0
  79. package/dist/types.d.ts +22 -0
  80. package/dist/types.js +3 -0
  81. package/dist/types.js.map +1 -0
  82. package/dist/utils/partition-key-template.cjs +19 -0
  83. package/dist/utils/partition-key-template.cjs.map +1 -0
  84. package/dist/utils/partition-key-template.d.cts +32 -0
  85. package/dist/utils/partition-key-template.d.ts +32 -0
  86. package/dist/utils/partition-key-template.js +17 -0
  87. package/dist/utils/partition-key-template.js.map +1 -0
  88. package/dist/utils/sort-key-template.cjs +19 -0
  89. package/dist/utils/sort-key-template.cjs.map +1 -0
  90. package/dist/utils/sort-key-template.d.cts +35 -0
  91. package/dist/utils/sort-key-template.d.ts +35 -0
  92. package/dist/utils/sort-key-template.js +17 -0
  93. package/dist/utils/sort-key-template.js.map +1 -0
  94. package/package.json +77 -7
  95. package/dist/index.d.cts +0 -2971
  96. package/dist/index.d.ts +0 -2971
@@ -0,0 +1,199 @@
1
+ 'use strict';
2
+
3
+ // src/builders/paginator.ts
4
+ var Paginator = class {
5
+ queryBuilder;
6
+ pageSize;
7
+ currentPage = 0;
8
+ lastEvaluatedKey;
9
+ hasMorePages = true;
10
+ totalItemsRetrieved = 0;
11
+ overallLimit;
12
+ constructor(queryBuilder, pageSize) {
13
+ this.queryBuilder = queryBuilder;
14
+ this.pageSize = pageSize;
15
+ this.overallLimit = queryBuilder.getLimit();
16
+ }
17
+ /**
18
+ * Gets the current page number (1-indexed).
19
+ * Use this method when you need to:
20
+ * - Track progress through dinosaur lists
21
+ * - Display habitat inspection status
22
+ * - Monitor security sweep progress
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * const paginator = new QueryBuilder(executor, eq('species', 'Tyrannosaurus'))
27
+ * .paginate(5);
28
+ *
29
+ * await paginator.getNextPage();
30
+ * console.log(`Reviewing T-Rex group ${paginator.getCurrentPage()}`);
31
+ * ```
32
+ *
33
+ * @returns The current page number, starting from 1
34
+ */
35
+ getCurrentPage() {
36
+ return this.currentPage;
37
+ }
38
+ /**
39
+ * Checks if there are more pages of dinosaurs or habitats to process.
40
+ * Use this method when you need to:
41
+ * - Check for more dinosaurs to review
42
+ * - Continue habitat inspections
43
+ * - Process security incidents
44
+ * - Complete feeding schedules
45
+ *
46
+ * This method takes into account both:
47
+ * - DynamoDB's lastEvaluatedKey mechanism
48
+ * - Any overall limit set on the query
49
+ *
50
+ * @example
51
+ * ```ts
52
+ * // Process all security incidents
53
+ * const paginator = new QueryBuilder(executor, eq('type', 'SECURITY_BREACH'))
54
+ * .sortDescending()
55
+ * .paginate(10);
56
+ *
57
+ * while (paginator.hasNextPage()) {
58
+ * const page = await paginator.getNextPage();
59
+ * for (const incident of page.items) {
60
+ * await processSecurityBreach(incident);
61
+ * }
62
+ * console.log(`Processed incidents page ${page.page}`);
63
+ * }
64
+ * ```
65
+ *
66
+ * @returns true if there are more pages available, false otherwise
67
+ */
68
+ hasNextPage() {
69
+ if (this.overallLimit !== void 0 && this.totalItemsRetrieved >= this.overallLimit) {
70
+ return false;
71
+ }
72
+ return this.hasMorePages;
73
+ }
74
+ /**
75
+ * Retrieves the next page of dinosaurs or habitats from DynamoDB.
76
+ * Use this method when you need to:
77
+ * - Process dinosaur groups systematically
78
+ * - Review habitat inspections in batches
79
+ * - Monitor security incidents in sequence
80
+ * - Schedule feeding rotations
81
+ *
82
+ * This method handles:
83
+ * - Automatic continuation between groups
84
+ * - Respect for park capacity limits
85
+ * - Group size adjustments for safety
86
+ *
87
+ * @example
88
+ * ```ts
89
+ * const paginator = new QueryBuilder(executor, eq('species', 'Velociraptor'))
90
+ * .filter(op => op.eq('status', 'ACTIVE'))
91
+ * .paginate(5);
92
+ *
93
+ * // Check first raptor group
94
+ * const page1 = await paginator.getNextPage();
95
+ * console.log(`Found ${page1.items.length} active raptors`);
96
+ *
97
+ * // Continue inspection if more groups exist
98
+ * if (page1.hasNextPage) {
99
+ * const page2 = await paginator.getNextPage();
100
+ * console.log(`Inspecting raptor group ${page2.page}`);
101
+ *
102
+ * for (const raptor of page2.items) {
103
+ * await performHealthCheck(raptor);
104
+ * }
105
+ * }
106
+ * ```
107
+ *
108
+ * @returns A promise that resolves to a PaginationResult containing:
109
+ * - items: The dinosaurs/habitats for this page
110
+ * - hasNextPage: Whether more groups exist
111
+ * - page: The current group number
112
+ * - lastEvaluatedKey: DynamoDB's continuation token
113
+ */
114
+ async getNextPage() {
115
+ if (!this.hasNextPage()) {
116
+ return {
117
+ items: [],
118
+ hasNextPage: false,
119
+ page: this.currentPage
120
+ };
121
+ }
122
+ let effectivePageSize = this.pageSize;
123
+ if (this.overallLimit !== void 0) {
124
+ const remainingItems = this.overallLimit - this.totalItemsRetrieved;
125
+ if (remainingItems <= 0) {
126
+ return {
127
+ items: [],
128
+ hasNextPage: false,
129
+ page: this.currentPage
130
+ };
131
+ }
132
+ effectivePageSize = Math.min(effectivePageSize, remainingItems);
133
+ }
134
+ const query = this.queryBuilder.clone().limit(effectivePageSize);
135
+ if (this.lastEvaluatedKey) {
136
+ query.startFrom(this.lastEvaluatedKey);
137
+ }
138
+ const result = await query.execute();
139
+ this.currentPage += 1;
140
+ this.lastEvaluatedKey = result.lastEvaluatedKey;
141
+ this.totalItemsRetrieved += result.items.length;
142
+ this.hasMorePages = !!result.lastEvaluatedKey && (this.overallLimit === void 0 || this.totalItemsRetrieved < this.overallLimit);
143
+ return {
144
+ items: result.items,
145
+ lastEvaluatedKey: result.lastEvaluatedKey,
146
+ hasNextPage: this.hasNextPage(),
147
+ page: this.currentPage
148
+ };
149
+ }
150
+ /**
151
+ * Gets all remaining dinosaurs or habitats and combines them into a single array.
152
+ * Use this method when you need to:
153
+ * - Generate complete park inventory
154
+ * - Perform full security audit
155
+ * - Create comprehensive feeding schedule
156
+ * - Run park-wide health checks
157
+ *
158
+ * Note: Use with caution! This method:
159
+ * - Could overwhelm systems with large dinosaur populations
160
+ * - Makes multiple database requests
161
+ * - May cause system strain during peak hours
162
+ *
163
+ * @example
164
+ * ```ts
165
+ * // Get complete carnivore inventory
166
+ * const paginator = new QueryBuilder(executor, eq('diet', 'CARNIVORE'))
167
+ * .filter(op => op.eq('status', 'ACTIVE'))
168
+ * .paginate(10);
169
+ *
170
+ * try {
171
+ * const allCarnivores = await paginator.getAllPages();
172
+ * console.log(`Park contains ${allCarnivores.length} active carnivores`);
173
+ *
174
+ * // Calculate total threat level
175
+ * const totalThreat = allCarnivores.reduce(
176
+ * (sum, dino) => sum + dino.stats.threatLevel,
177
+ * 0
178
+ * );
179
+ * console.log(`Total threat level: ${totalThreat}`);
180
+ * } catch (error) {
181
+ * console.error('Failed to complete carnivore census:', error);
182
+ * }
183
+ * ```
184
+ *
185
+ * @returns A promise that resolves to an array containing all remaining items
186
+ */
187
+ async getAllPages() {
188
+ const allItems = [];
189
+ while (this.hasNextPage()) {
190
+ const result = await this.getNextPage();
191
+ allItems.push(...result.items);
192
+ }
193
+ return allItems;
194
+ }
195
+ };
196
+
197
+ exports.Paginator = Paginator;
198
+ //# sourceMappingURL=paginator.cjs.map
199
+ //# sourceMappingURL=paginator.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/builders/paginator.ts"],"names":[],"mappings":";;;AAqCO,IAAM,YAAN,MAAiF;AAAA,EAC9E,YAAA;AAAA,EACS,QAAA;AAAA,EACT,WAAc,GAAA,CAAA;AAAA,EACd,gBAAA;AAAA,EACA,YAAe,GAAA,IAAA;AAAA,EACf,mBAAsB,GAAA,CAAA;AAAA,EACb,YAAA;AAAA,EAEjB,WAAA,CAAY,cAAiD,QAAkB,EAAA;AAC7E,IAAA,IAAA,CAAK,YAAe,GAAA,YAAA;AACpB,IAAA,IAAA,CAAK,QAAW,GAAA,QAAA;AAEhB,IAAK,IAAA,CAAA,YAAA,GAAe,aAAa,QAAS,EAAA;AAAA;AAC5C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAoBO,cAAyB,GAAA;AAC9B,IAAA,OAAO,IAAK,CAAA,WAAA;AAAA;AACd;AAAA;A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ginator.cjs","sourcesContent":["import type { DynamoItem, TableConfig } from \"../types\";\nimport type { PaginationResult, QueryBuilderInterface } from \"./builder-types\";\n\n/**\n * A utility class for handling DynamoDB pagination.\n * Use this class when you need to:\n * - Browse large collections of dinosaurs\n * - Review extensive security logs\n * - Analyze habitat inspection history\n * - Process feeding schedules\n *\n * The paginator maintains internal state and automatically handles:\n * - Page boundaries\n * - Result set limits\n * - Continuation tokens\n *\n * @example\n * ```typescript\n * // List all velociraptors with pagination\n * const paginator = new QueryBuilder(executor, eq('species', 'Velociraptor'))\n * .filter(op => op.eq('status', 'ACTIVE'))\n * .paginate(10);\n *\n * // Process each page of dinosaurs\n * while (paginator.hasNextPage()) {\n * const page = await paginator.getNextPage();\n * console.log(`Processing page ${page.page} of velociraptors`);\n *\n * for (const raptor of page.items) {\n * console.log(`- ${raptor.id}: Health=${raptor.stats.health}`);\n * }\n * }\n * ```\n *\n * @typeParam T - The type of items being paginated\n * @typeParam TConfig - The table configuration type\n */\nexport class Paginator<T extends DynamoItem, TConfig extends TableConfig = TableConfig> {\n private queryBuilder: QueryBuilderInterface<T, TConfig>;\n private readonly pageSize: number;\n private currentPage = 0;\n private lastEvaluatedKey?: DynamoItem;\n private hasMorePages = true;\n private totalItemsRetrieved = 0;\n private readonly overallLimit?: number;\n\n constructor(queryBuilder: QueryBuilderInterface<T, TConfig>, pageSize: number) {\n this.queryBuilder = queryBuilder;\n this.pageSize = pageSize;\n // Store the overall limit from the query builder if it exists\n this.overallLimit = queryBuilder.getLimit();\n }\n\n /**\n * Gets the current page number (1-indexed).\n * Use this method when you need to:\n * - Track progress through dinosaur lists\n * - Display habitat inspection status\n * - Monitor security sweep progress\n *\n * @example\n * ```ts\n * const paginator = new QueryBuilder(executor, eq('species', 'Tyrannosaurus'))\n * .paginate(5);\n *\n * await paginator.getNextPage();\n * console.log(`Reviewing T-Rex group ${paginator.getCurrentPage()}`);\n * ```\n *\n * @returns The current page number, starting from 1\n */\n public getCurrentPage(): number {\n return this.currentPage;\n }\n\n /**\n * Checks if there are more pages of dinosaurs or habitats to process.\n * Use this method when you need to:\n * - Check for more dinosaurs to review\n * - Continue habitat inspections\n * - Process security incidents\n * - Complete feeding schedules\n *\n * This method takes into account both:\n * - DynamoDB's lastEvaluatedKey mechanism\n * - Any overall limit set on the query\n *\n * @example\n * ```ts\n * // Process all security incidents\n * const paginator = new QueryBuilder(executor, eq('type', 'SECURITY_BREACH'))\n * .sortDescending()\n * .paginate(10);\n *\n * while (paginator.hasNextPage()) {\n * const page = await paginator.getNextPage();\n * for (const incident of page.items) {\n * await processSecurityBreach(incident);\n * }\n * console.log(`Processed incidents page ${page.page}`);\n * }\n * ```\n *\n * @returns true if there are more pages available, false otherwise\n */\n public hasNextPage(): boolean {\n // If we have an overall limit and we've already retrieved that many items, there are no more pages\n if (this.overallLimit !== undefined && this.totalItemsRetrieved >= this.overallLimit) {\n return false;\n }\n return this.hasMorePages;\n }\n\n /**\n * Retrieves the next page of dinosaurs or habitats from DynamoDB.\n * Use this method when you need to:\n * - Process dinosaur groups systematically\n * - Review habitat inspections in batches\n * - Monitor security incidents in sequence\n * - Schedule feeding rotations\n *\n * This method handles:\n * - Automatic continuation between groups\n * - Respect for park capacity limits\n * - Group size adjustments for safety\n *\n * @example\n * ```ts\n * const paginator = new QueryBuilder(executor, eq('species', 'Velociraptor'))\n * .filter(op => op.eq('status', 'ACTIVE'))\n * .paginate(5);\n *\n * // Check first raptor group\n * const page1 = await paginator.getNextPage();\n * console.log(`Found ${page1.items.length} active raptors`);\n *\n * // Continue inspection if more groups exist\n * if (page1.hasNextPage) {\n * const page2 = await paginator.getNextPage();\n * console.log(`Inspecting raptor group ${page2.page}`);\n *\n * for (const raptor of page2.items) {\n * await performHealthCheck(raptor);\n * }\n * }\n * ```\n *\n * @returns A promise that resolves to a PaginationResult containing:\n * - items: The dinosaurs/habitats for this page\n * - hasNextPage: Whether more groups exist\n * - page: The current group number\n * - lastEvaluatedKey: DynamoDB's continuation token\n */\n public async getNextPage(): Promise<PaginationResult<T>> {\n if (!this.hasNextPage()) {\n return {\n items: [],\n hasNextPage: false,\n page: this.currentPage,\n };\n }\n\n // Calculate how many items to fetch for this page\n let effectivePageSize = this.pageSize;\n\n // If we have an overall limit, make sure we don't fetch more than what's left\n if (this.overallLimit !== undefined) {\n const remainingItems = this.overallLimit - this.totalItemsRetrieved;\n if (remainingItems <= 0) {\n return {\n items: [],\n hasNextPage: false,\n page: this.currentPage,\n };\n }\n effectivePageSize = Math.min(effectivePageSize, remainingItems);\n }\n\n // Clone the query builder to avoid modifying the original\n const query = this.queryBuilder.clone().limit(effectivePageSize);\n\n // Apply the last evaluated key if we have one\n if (this.lastEvaluatedKey) {\n query.startFrom(this.lastEvaluatedKey);\n }\n\n // Execute the query\n const result = await query.execute();\n\n // Update pagination state\n this.currentPage += 1;\n this.lastEvaluatedKey = result.lastEvaluatedKey;\n this.totalItemsRetrieved += result.items.length;\n\n // Determine if there are more pages\n // We have more pages if:\n // 1. DynamoDB returned a lastEvaluatedKey AND\n // 2. We haven't hit our overall limit (if one exists)\n this.hasMorePages =\n !!result.lastEvaluatedKey && (this.overallLimit === undefined || this.totalItemsRetrieved < this.overallLimit);\n\n return {\n items: result.items,\n lastEvaluatedKey: result.lastEvaluatedKey,\n hasNextPage: this.hasNextPage(),\n page: this.currentPage,\n };\n }\n\n /**\n * Gets all remaining dinosaurs or habitats and combines them into a single array.\n * Use this method when you need to:\n * - Generate complete park inventory\n * - Perform full security audit\n * - Create comprehensive feeding schedule\n * - Run park-wide health checks\n *\n * Note: Use with caution! This method:\n * - Could overwhelm systems with large dinosaur populations\n * - Makes multiple database requests\n * - May cause system strain during peak hours\n *\n * @example\n * ```ts\n * // Get complete carnivore inventory\n * const paginator = new QueryBuilder(executor, eq('diet', 'CARNIVORE'))\n * .filter(op => op.eq('status', 'ACTIVE'))\n * .paginate(10);\n *\n * try {\n * const allCarnivores = await paginator.getAllPages();\n * console.log(`Park contains ${allCarnivores.length} active carnivores`);\n *\n * // Calculate total threat level\n * const totalThreat = allCarnivores.reduce(\n * (sum, dino) => sum + dino.stats.threatLevel,\n * 0\n * );\n * console.log(`Total threat level: ${totalThreat}`);\n * } catch (error) {\n * console.error('Failed to complete carnivore census:', error);\n * }\n * ```\n *\n * @returns A promise that resolves to an array containing all remaining items\n */\n public async getAllPages(): Promise<T[]> {\n const allItems: T[] = [];\n\n while (this.hasNextPage()) {\n const result = await this.getNextPage();\n allItems.push(...result.items);\n }\n\n return allItems;\n }\n}\n"]}
@@ -0,0 +1,179 @@
1
+ import { DynamoItem, TableConfig } from '../types.cjs';
2
+ import { Q as QueryBuilderInterface, P as PaginationResult } from '../builder-types-DtwbqMeF.cjs';
3
+ import '@aws-sdk/lib-dynamodb';
4
+
5
+ /**
6
+ * A utility class for handling DynamoDB pagination.
7
+ * Use this class when you need to:
8
+ * - Browse large collections of dinosaurs
9
+ * - Review extensive security logs
10
+ * - Analyze habitat inspection history
11
+ * - Process feeding schedules
12
+ *
13
+ * The paginator maintains internal state and automatically handles:
14
+ * - Page boundaries
15
+ * - Result set limits
16
+ * - Continuation tokens
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * // List all velociraptors with pagination
21
+ * const paginator = new QueryBuilder(executor, eq('species', 'Velociraptor'))
22
+ * .filter(op => op.eq('status', 'ACTIVE'))
23
+ * .paginate(10);
24
+ *
25
+ * // Process each page of dinosaurs
26
+ * while (paginator.hasNextPage()) {
27
+ * const page = await paginator.getNextPage();
28
+ * console.log(`Processing page ${page.page} of velociraptors`);
29
+ *
30
+ * for (const raptor of page.items) {
31
+ * console.log(`- ${raptor.id}: Health=${raptor.stats.health}`);
32
+ * }
33
+ * }
34
+ * ```
35
+ *
36
+ * @typeParam T - The type of items being paginated
37
+ * @typeParam TConfig - The table configuration type
38
+ */
39
+ declare class Paginator<T extends DynamoItem, TConfig extends TableConfig = TableConfig> {
40
+ private queryBuilder;
41
+ private readonly pageSize;
42
+ private currentPage;
43
+ private lastEvaluatedKey?;
44
+ private hasMorePages;
45
+ private totalItemsRetrieved;
46
+ private readonly overallLimit?;
47
+ constructor(queryBuilder: QueryBuilderInterface<T, TConfig>, pageSize: number);
48
+ /**
49
+ * Gets the current page number (1-indexed).
50
+ * Use this method when you need to:
51
+ * - Track progress through dinosaur lists
52
+ * - Display habitat inspection status
53
+ * - Monitor security sweep progress
54
+ *
55
+ * @example
56
+ * ```ts
57
+ * const paginator = new QueryBuilder(executor, eq('species', 'Tyrannosaurus'))
58
+ * .paginate(5);
59
+ *
60
+ * await paginator.getNextPage();
61
+ * console.log(`Reviewing T-Rex group ${paginator.getCurrentPage()}`);
62
+ * ```
63
+ *
64
+ * @returns The current page number, starting from 1
65
+ */
66
+ getCurrentPage(): number;
67
+ /**
68
+ * Checks if there are more pages of dinosaurs or habitats to process.
69
+ * Use this method when you need to:
70
+ * - Check for more dinosaurs to review
71
+ * - Continue habitat inspections
72
+ * - Process security incidents
73
+ * - Complete feeding schedules
74
+ *
75
+ * This method takes into account both:
76
+ * - DynamoDB's lastEvaluatedKey mechanism
77
+ * - Any overall limit set on the query
78
+ *
79
+ * @example
80
+ * ```ts
81
+ * // Process all security incidents
82
+ * const paginator = new QueryBuilder(executor, eq('type', 'SECURITY_BREACH'))
83
+ * .sortDescending()
84
+ * .paginate(10);
85
+ *
86
+ * while (paginator.hasNextPage()) {
87
+ * const page = await paginator.getNextPage();
88
+ * for (const incident of page.items) {
89
+ * await processSecurityBreach(incident);
90
+ * }
91
+ * console.log(`Processed incidents page ${page.page}`);
92
+ * }
93
+ * ```
94
+ *
95
+ * @returns true if there are more pages available, false otherwise
96
+ */
97
+ hasNextPage(): boolean;
98
+ /**
99
+ * Retrieves the next page of dinosaurs or habitats from DynamoDB.
100
+ * Use this method when you need to:
101
+ * - Process dinosaur groups systematically
102
+ * - Review habitat inspections in batches
103
+ * - Monitor security incidents in sequence
104
+ * - Schedule feeding rotations
105
+ *
106
+ * This method handles:
107
+ * - Automatic continuation between groups
108
+ * - Respect for park capacity limits
109
+ * - Group size adjustments for safety
110
+ *
111
+ * @example
112
+ * ```ts
113
+ * const paginator = new QueryBuilder(executor, eq('species', 'Velociraptor'))
114
+ * .filter(op => op.eq('status', 'ACTIVE'))
115
+ * .paginate(5);
116
+ *
117
+ * // Check first raptor group
118
+ * const page1 = await paginator.getNextPage();
119
+ * console.log(`Found ${page1.items.length} active raptors`);
120
+ *
121
+ * // Continue inspection if more groups exist
122
+ * if (page1.hasNextPage) {
123
+ * const page2 = await paginator.getNextPage();
124
+ * console.log(`Inspecting raptor group ${page2.page}`);
125
+ *
126
+ * for (const raptor of page2.items) {
127
+ * await performHealthCheck(raptor);
128
+ * }
129
+ * }
130
+ * ```
131
+ *
132
+ * @returns A promise that resolves to a PaginationResult containing:
133
+ * - items: The dinosaurs/habitats for this page
134
+ * - hasNextPage: Whether more groups exist
135
+ * - page: The current group number
136
+ * - lastEvaluatedKey: DynamoDB's continuation token
137
+ */
138
+ getNextPage(): Promise<PaginationResult<T>>;
139
+ /**
140
+ * Gets all remaining dinosaurs or habitats and combines them into a single array.
141
+ * Use this method when you need to:
142
+ * - Generate complete park inventory
143
+ * - Perform full security audit
144
+ * - Create comprehensive feeding schedule
145
+ * - Run park-wide health checks
146
+ *
147
+ * Note: Use with caution! This method:
148
+ * - Could overwhelm systems with large dinosaur populations
149
+ * - Makes multiple database requests
150
+ * - May cause system strain during peak hours
151
+ *
152
+ * @example
153
+ * ```ts
154
+ * // Get complete carnivore inventory
155
+ * const paginator = new QueryBuilder(executor, eq('diet', 'CARNIVORE'))
156
+ * .filter(op => op.eq('status', 'ACTIVE'))
157
+ * .paginate(10);
158
+ *
159
+ * try {
160
+ * const allCarnivores = await paginator.getAllPages();
161
+ * console.log(`Park contains ${allCarnivores.length} active carnivores`);
162
+ *
163
+ * // Calculate total threat level
164
+ * const totalThreat = allCarnivores.reduce(
165
+ * (sum, dino) => sum + dino.stats.threatLevel,
166
+ * 0
167
+ * );
168
+ * console.log(`Total threat level: ${totalThreat}`);
169
+ * } catch (error) {
170
+ * console.error('Failed to complete carnivore census:', error);
171
+ * }
172
+ * ```
173
+ *
174
+ * @returns A promise that resolves to an array containing all remaining items
175
+ */
176
+ getAllPages(): Promise<T[]>;
177
+ }
178
+
179
+ export { Paginator };
@@ -0,0 +1,179 @@
1
+ import { DynamoItem, TableConfig } from '../types.js';
2
+ import { Q as QueryBuilderInterface, P as PaginationResult } from '../builder-types-C_PDZhnP.js';
3
+ import '@aws-sdk/lib-dynamodb';
4
+
5
+ /**
6
+ * A utility class for handling DynamoDB pagination.
7
+ * Use this class when you need to:
8
+ * - Browse large collections of dinosaurs
9
+ * - Review extensive security logs
10
+ * - Analyze habitat inspection history
11
+ * - Process feeding schedules
12
+ *
13
+ * The paginator maintains internal state and automatically handles:
14
+ * - Page boundaries
15
+ * - Result set limits
16
+ * - Continuation tokens
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * // List all velociraptors with pagination
21
+ * const paginator = new QueryBuilder(executor, eq('species', 'Velociraptor'))
22
+ * .filter(op => op.eq('status', 'ACTIVE'))
23
+ * .paginate(10);
24
+ *
25
+ * // Process each page of dinosaurs
26
+ * while (paginator.hasNextPage()) {
27
+ * const page = await paginator.getNextPage();
28
+ * console.log(`Processing page ${page.page} of velociraptors`);
29
+ *
30
+ * for (const raptor of page.items) {
31
+ * console.log(`- ${raptor.id}: Health=${raptor.stats.health}`);
32
+ * }
33
+ * }
34
+ * ```
35
+ *
36
+ * @typeParam T - The type of items being paginated
37
+ * @typeParam TConfig - The table configuration type
38
+ */
39
+ declare class Paginator<T extends DynamoItem, TConfig extends TableConfig = TableConfig> {
40
+ private queryBuilder;
41
+ private readonly pageSize;
42
+ private currentPage;
43
+ private lastEvaluatedKey?;
44
+ private hasMorePages;
45
+ private totalItemsRetrieved;
46
+ private readonly overallLimit?;
47
+ constructor(queryBuilder: QueryBuilderInterface<T, TConfig>, pageSize: number);
48
+ /**
49
+ * Gets the current page number (1-indexed).
50
+ * Use this method when you need to:
51
+ * - Track progress through dinosaur lists
52
+ * - Display habitat inspection status
53
+ * - Monitor security sweep progress
54
+ *
55
+ * @example
56
+ * ```ts
57
+ * const paginator = new QueryBuilder(executor, eq('species', 'Tyrannosaurus'))
58
+ * .paginate(5);
59
+ *
60
+ * await paginator.getNextPage();
61
+ * console.log(`Reviewing T-Rex group ${paginator.getCurrentPage()}`);
62
+ * ```
63
+ *
64
+ * @returns The current page number, starting from 1
65
+ */
66
+ getCurrentPage(): number;
67
+ /**
68
+ * Checks if there are more pages of dinosaurs or habitats to process.
69
+ * Use this method when you need to:
70
+ * - Check for more dinosaurs to review
71
+ * - Continue habitat inspections
72
+ * - Process security incidents
73
+ * - Complete feeding schedules
74
+ *
75
+ * This method takes into account both:
76
+ * - DynamoDB's lastEvaluatedKey mechanism
77
+ * - Any overall limit set on the query
78
+ *
79
+ * @example
80
+ * ```ts
81
+ * // Process all security incidents
82
+ * const paginator = new QueryBuilder(executor, eq('type', 'SECURITY_BREACH'))
83
+ * .sortDescending()
84
+ * .paginate(10);
85
+ *
86
+ * while (paginator.hasNextPage()) {
87
+ * const page = await paginator.getNextPage();
88
+ * for (const incident of page.items) {
89
+ * await processSecurityBreach(incident);
90
+ * }
91
+ * console.log(`Processed incidents page ${page.page}`);
92
+ * }
93
+ * ```
94
+ *
95
+ * @returns true if there are more pages available, false otherwise
96
+ */
97
+ hasNextPage(): boolean;
98
+ /**
99
+ * Retrieves the next page of dinosaurs or habitats from DynamoDB.
100
+ * Use this method when you need to:
101
+ * - Process dinosaur groups systematically
102
+ * - Review habitat inspections in batches
103
+ * - Monitor security incidents in sequence
104
+ * - Schedule feeding rotations
105
+ *
106
+ * This method handles:
107
+ * - Automatic continuation between groups
108
+ * - Respect for park capacity limits
109
+ * - Group size adjustments for safety
110
+ *
111
+ * @example
112
+ * ```ts
113
+ * const paginator = new QueryBuilder(executor, eq('species', 'Velociraptor'))
114
+ * .filter(op => op.eq('status', 'ACTIVE'))
115
+ * .paginate(5);
116
+ *
117
+ * // Check first raptor group
118
+ * const page1 = await paginator.getNextPage();
119
+ * console.log(`Found ${page1.items.length} active raptors`);
120
+ *
121
+ * // Continue inspection if more groups exist
122
+ * if (page1.hasNextPage) {
123
+ * const page2 = await paginator.getNextPage();
124
+ * console.log(`Inspecting raptor group ${page2.page}`);
125
+ *
126
+ * for (const raptor of page2.items) {
127
+ * await performHealthCheck(raptor);
128
+ * }
129
+ * }
130
+ * ```
131
+ *
132
+ * @returns A promise that resolves to a PaginationResult containing:
133
+ * - items: The dinosaurs/habitats for this page
134
+ * - hasNextPage: Whether more groups exist
135
+ * - page: The current group number
136
+ * - lastEvaluatedKey: DynamoDB's continuation token
137
+ */
138
+ getNextPage(): Promise<PaginationResult<T>>;
139
+ /**
140
+ * Gets all remaining dinosaurs or habitats and combines them into a single array.
141
+ * Use this method when you need to:
142
+ * - Generate complete park inventory
143
+ * - Perform full security audit
144
+ * - Create comprehensive feeding schedule
145
+ * - Run park-wide health checks
146
+ *
147
+ * Note: Use with caution! This method:
148
+ * - Could overwhelm systems with large dinosaur populations
149
+ * - Makes multiple database requests
150
+ * - May cause system strain during peak hours
151
+ *
152
+ * @example
153
+ * ```ts
154
+ * // Get complete carnivore inventory
155
+ * const paginator = new QueryBuilder(executor, eq('diet', 'CARNIVORE'))
156
+ * .filter(op => op.eq('status', 'ACTIVE'))
157
+ * .paginate(10);
158
+ *
159
+ * try {
160
+ * const allCarnivores = await paginator.getAllPages();
161
+ * console.log(`Park contains ${allCarnivores.length} active carnivores`);
162
+ *
163
+ * // Calculate total threat level
164
+ * const totalThreat = allCarnivores.reduce(
165
+ * (sum, dino) => sum + dino.stats.threatLevel,
166
+ * 0
167
+ * );
168
+ * console.log(`Total threat level: ${totalThreat}`);
169
+ * } catch (error) {
170
+ * console.error('Failed to complete carnivore census:', error);
171
+ * }
172
+ * ```
173
+ *
174
+ * @returns A promise that resolves to an array containing all remaining items
175
+ */
176
+ getAllPages(): Promise<T[]>;
177
+ }
178
+
179
+ export { Paginator };