dyno-table 0.1.7 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +115 -17
  3. package/dist/builders/condition-check-builder.cjs +394 -0
  4. package/dist/builders/condition-check-builder.cjs.map +1 -0
  5. package/dist/builders/condition-check-builder.js +392 -0
  6. package/dist/builders/condition-check-builder.js.map +1 -0
  7. package/dist/builders/delete-builder.cjs +422 -0
  8. package/dist/builders/delete-builder.cjs.map +1 -0
  9. package/dist/builders/delete-builder.js +420 -0
  10. package/dist/builders/delete-builder.js.map +1 -0
  11. package/dist/builders/paginator.cjs +199 -0
  12. package/dist/builders/paginator.cjs.map +1 -0
  13. package/dist/builders/paginator.js +197 -0
  14. package/dist/builders/paginator.js.map +1 -0
  15. package/dist/builders/put-builder.cjs +468 -0
  16. package/dist/builders/put-builder.cjs.map +1 -0
  17. package/dist/builders/put-builder.js +466 -0
  18. package/dist/builders/put-builder.js.map +1 -0
  19. package/dist/builders/query-builder.cjs +674 -0
  20. package/dist/builders/query-builder.cjs.map +1 -0
  21. package/dist/builders/query-builder.js +672 -0
  22. package/dist/builders/query-builder.js.map +1 -0
  23. package/dist/builders/transaction-builder.cjs +876 -0
  24. package/dist/builders/transaction-builder.cjs.map +1 -0
  25. package/dist/builders/transaction-builder.js +874 -0
  26. package/dist/builders/transaction-builder.js.map +1 -0
  27. package/dist/builders/update-builder.cjs +662 -0
  28. package/dist/builders/update-builder.cjs.map +1 -0
  29. package/dist/builders/update-builder.js +660 -0
  30. package/dist/builders/update-builder.js.map +1 -0
  31. package/dist/conditions.cjs +59 -0
  32. package/dist/conditions.cjs.map +1 -0
  33. package/dist/conditions.js +43 -0
  34. package/dist/conditions.js.map +1 -0
  35. package/dist/entity.cjs +169 -0
  36. package/dist/entity.cjs.map +1 -0
  37. package/dist/entity.js +165 -0
  38. package/dist/entity.js.map +1 -0
  39. package/dist/index.cjs +3333 -0
  40. package/dist/index.d.cts +2971 -0
  41. package/dist/index.d.ts +386 -338
  42. package/dist/index.js +247 -232
  43. package/dist/standard-schema.cjs +4 -0
  44. package/dist/standard-schema.cjs.map +1 -0
  45. package/dist/standard-schema.js +3 -0
  46. package/dist/standard-schema.js.map +1 -0
  47. package/dist/table.cjs +3265 -0
  48. package/dist/table.cjs.map +1 -0
  49. package/dist/table.js +3263 -0
  50. package/dist/table.js.map +1 -0
  51. package/dist/types.cjs +4 -0
  52. package/dist/types.cjs.map +1 -0
  53. package/dist/types.js +3 -0
  54. package/dist/types.js.map +1 -0
  55. package/dist/utils/key-template.cjs +19 -0
  56. package/dist/utils/key-template.cjs.map +1 -0
  57. package/dist/utils/key-template.js +17 -0
  58. package/dist/utils/key-template.js.map +1 -0
  59. package/dist/utils/sort-key-template.cjs +19 -0
  60. package/dist/utils/sort-key-template.cjs.map +1 -0
  61. package/dist/utils/sort-key-template.js +17 -0
  62. package/dist/utils/sort-key-template.js.map +1 -0
  63. package/package.json +24 -26
@@ -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,MAA8F;AAAA,EAC3F,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;AA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,IAAA,CAAK,WAAY,EAAA;AACtC,MAAS,QAAA,CAAA,IAAA,CAAK,GAAG,MAAA,CAAO,KAAK,CAAA;AAAA;AAG/B,IAAO,OAAA,QAAA;AAAA;AAEX","file":"paginator.cjs","sourcesContent":["import type { 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 Record<string, unknown>, TConfig extends TableConfig = TableConfig> {\n private queryBuilder: QueryBuilderInterface<T, TConfig>;\n private readonly pageSize: number;\n private currentPage = 0;\n private lastEvaluatedKey?: Record<string, unknown>;\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,197 @@
1
+ // src/builders/paginator.ts
2
+ var Paginator = class {
3
+ queryBuilder;
4
+ pageSize;
5
+ currentPage = 0;
6
+ lastEvaluatedKey;
7
+ hasMorePages = true;
8
+ totalItemsRetrieved = 0;
9
+ overallLimit;
10
+ constructor(queryBuilder, pageSize) {
11
+ this.queryBuilder = queryBuilder;
12
+ this.pageSize = pageSize;
13
+ this.overallLimit = queryBuilder.getLimit();
14
+ }
15
+ /**
16
+ * Gets the current page number (1-indexed).
17
+ * Use this method when you need to:
18
+ * - Track progress through dinosaur lists
19
+ * - Display habitat inspection status
20
+ * - Monitor security sweep progress
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * const paginator = new QueryBuilder(executor, eq('species', 'Tyrannosaurus'))
25
+ * .paginate(5);
26
+ *
27
+ * await paginator.getNextPage();
28
+ * console.log(`Reviewing T-Rex group ${paginator.getCurrentPage()}`);
29
+ * ```
30
+ *
31
+ * @returns The current page number, starting from 1
32
+ */
33
+ getCurrentPage() {
34
+ return this.currentPage;
35
+ }
36
+ /**
37
+ * Checks if there are more pages of dinosaurs or habitats to process.
38
+ * Use this method when you need to:
39
+ * - Check for more dinosaurs to review
40
+ * - Continue habitat inspections
41
+ * - Process security incidents
42
+ * - Complete feeding schedules
43
+ *
44
+ * This method takes into account both:
45
+ * - DynamoDB's lastEvaluatedKey mechanism
46
+ * - Any overall limit set on the query
47
+ *
48
+ * @example
49
+ * ```ts
50
+ * // Process all security incidents
51
+ * const paginator = new QueryBuilder(executor, eq('type', 'SECURITY_BREACH'))
52
+ * .sortDescending()
53
+ * .paginate(10);
54
+ *
55
+ * while (paginator.hasNextPage()) {
56
+ * const page = await paginator.getNextPage();
57
+ * for (const incident of page.items) {
58
+ * await processSecurityBreach(incident);
59
+ * }
60
+ * console.log(`Processed incidents page ${page.page}`);
61
+ * }
62
+ * ```
63
+ *
64
+ * @returns true if there are more pages available, false otherwise
65
+ */
66
+ hasNextPage() {
67
+ if (this.overallLimit !== void 0 && this.totalItemsRetrieved >= this.overallLimit) {
68
+ return false;
69
+ }
70
+ return this.hasMorePages;
71
+ }
72
+ /**
73
+ * Retrieves the next page of dinosaurs or habitats from DynamoDB.
74
+ * Use this method when you need to:
75
+ * - Process dinosaur groups systematically
76
+ * - Review habitat inspections in batches
77
+ * - Monitor security incidents in sequence
78
+ * - Schedule feeding rotations
79
+ *
80
+ * This method handles:
81
+ * - Automatic continuation between groups
82
+ * - Respect for park capacity limits
83
+ * - Group size adjustments for safety
84
+ *
85
+ * @example
86
+ * ```ts
87
+ * const paginator = new QueryBuilder(executor, eq('species', 'Velociraptor'))
88
+ * .filter(op => op.eq('status', 'ACTIVE'))
89
+ * .paginate(5);
90
+ *
91
+ * // Check first raptor group
92
+ * const page1 = await paginator.getNextPage();
93
+ * console.log(`Found ${page1.items.length} active raptors`);
94
+ *
95
+ * // Continue inspection if more groups exist
96
+ * if (page1.hasNextPage) {
97
+ * const page2 = await paginator.getNextPage();
98
+ * console.log(`Inspecting raptor group ${page2.page}`);
99
+ *
100
+ * for (const raptor of page2.items) {
101
+ * await performHealthCheck(raptor);
102
+ * }
103
+ * }
104
+ * ```
105
+ *
106
+ * @returns A promise that resolves to a PaginationResult containing:
107
+ * - items: The dinosaurs/habitats for this page
108
+ * - hasNextPage: Whether more groups exist
109
+ * - page: The current group number
110
+ * - lastEvaluatedKey: DynamoDB's continuation token
111
+ */
112
+ async getNextPage() {
113
+ if (!this.hasNextPage()) {
114
+ return {
115
+ items: [],
116
+ hasNextPage: false,
117
+ page: this.currentPage
118
+ };
119
+ }
120
+ let effectivePageSize = this.pageSize;
121
+ if (this.overallLimit !== void 0) {
122
+ const remainingItems = this.overallLimit - this.totalItemsRetrieved;
123
+ if (remainingItems <= 0) {
124
+ return {
125
+ items: [],
126
+ hasNextPage: false,
127
+ page: this.currentPage
128
+ };
129
+ }
130
+ effectivePageSize = Math.min(effectivePageSize, remainingItems);
131
+ }
132
+ const query = this.queryBuilder.clone().limit(effectivePageSize);
133
+ if (this.lastEvaluatedKey) {
134
+ query.startFrom(this.lastEvaluatedKey);
135
+ }
136
+ const result = await query.execute();
137
+ this.currentPage += 1;
138
+ this.lastEvaluatedKey = result.lastEvaluatedKey;
139
+ this.totalItemsRetrieved += result.items.length;
140
+ this.hasMorePages = !!result.lastEvaluatedKey && (this.overallLimit === void 0 || this.totalItemsRetrieved < this.overallLimit);
141
+ return {
142
+ items: result.items,
143
+ lastEvaluatedKey: result.lastEvaluatedKey,
144
+ hasNextPage: this.hasNextPage(),
145
+ page: this.currentPage
146
+ };
147
+ }
148
+ /**
149
+ * Gets all remaining dinosaurs or habitats and combines them into a single array.
150
+ * Use this method when you need to:
151
+ * - Generate complete park inventory
152
+ * - Perform full security audit
153
+ * - Create comprehensive feeding schedule
154
+ * - Run park-wide health checks
155
+ *
156
+ * Note: Use with caution! This method:
157
+ * - Could overwhelm systems with large dinosaur populations
158
+ * - Makes multiple database requests
159
+ * - May cause system strain during peak hours
160
+ *
161
+ * @example
162
+ * ```ts
163
+ * // Get complete carnivore inventory
164
+ * const paginator = new QueryBuilder(executor, eq('diet', 'CARNIVORE'))
165
+ * .filter(op => op.eq('status', 'ACTIVE'))
166
+ * .paginate(10);
167
+ *
168
+ * try {
169
+ * const allCarnivores = await paginator.getAllPages();
170
+ * console.log(`Park contains ${allCarnivores.length} active carnivores`);
171
+ *
172
+ * // Calculate total threat level
173
+ * const totalThreat = allCarnivores.reduce(
174
+ * (sum, dino) => sum + dino.stats.threatLevel,
175
+ * 0
176
+ * );
177
+ * console.log(`Total threat level: ${totalThreat}`);
178
+ * } catch (error) {
179
+ * console.error('Failed to complete carnivore census:', error);
180
+ * }
181
+ * ```
182
+ *
183
+ * @returns A promise that resolves to an array containing all remaining items
184
+ */
185
+ async getAllPages() {
186
+ const allItems = [];
187
+ while (this.hasNextPage()) {
188
+ const result = await this.getNextPage();
189
+ allItems.push(...result.items);
190
+ }
191
+ return allItems;
192
+ }
193
+ };
194
+
195
+ export { Paginator };
196
+ //# sourceMappingURL=paginator.js.map
197
+ //# sourceMappingURL=paginator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/builders/paginator.ts"],"names":[],"mappings":";AAqCO,IAAM,YAAN,MAA8F;AAAA,EAC3F,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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAA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AAK,gBAAkB,EAAA;AACzB,MAAM,KAAA,CAAA,SAAA,CAAU,KAAK,gBAAgB,CAAA;AAAA;AAIvC,IAAM,MAAA,MAAA,GAAS,MAAM,KAAA,CAAM,OAAQ,EAAA;AAGnC,IAAA,IAAA,CAAK,WAAe,IAAA,CAAA;AACpB,IAAA,IAAA,CAAK,mBAAmB,MAAO,CAAA,gBAAA;AAC/B,IAAK,IAAA,CAAA,mBAAA,IAAuB,OAAO,KAAM,CAAA,MAAA;AAMzC,IAAK,IAAA,CAAA,YAAA,GACH,CAAC,CAAC,MAAO,CAAA,gBAAA,KAAqB,KAAK,YAAiB,KAAA,KAAA,CAAA,IAAa,IAAK,CAAA,mBAAA,GAAsB,IAAK,CAAA,YAAA,CAAA;AAEnG,IAAO,OAAA;AAAA,MACL,OAAO,MAAO,CAAA,KAAA;AAAA,MACd,kBAAkB,MAAO,CAAA,gBAAA;AAAA,MACzB,WAAA,EAAa,KAAK,WAAY,EAAA;AAAA,MAC9B,MAAM,IAAK,CAAA;AAAA,KACb;AAAA;AACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAuCA,MAAa,WAA4B,GAAA;AACvC,IAAA,MAAM,WAAgB,EAAC;AAEvB,IAAO,OAAA,IAAA,CAAK,aAAe,EAAA;AACzB,MAAM,MAAA,MAAA,GAAS,MAAM,IAAA,CAAK,WAAY,EAAA;AACtC,MAAS,QAAA,CAAA,IAAA,CAAK,GAAG,MAAA,CAAO,KAAK,CAAA;AAAA;AAG/B,IAAO,OAAA,QAAA;AAAA;AAEX","file":"paginator.js","sourcesContent":["import type { 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 Record<string, unknown>, TConfig extends TableConfig = TableConfig> {\n private queryBuilder: QueryBuilderInterface<T, TConfig>;\n private readonly pageSize: number;\n private currentPage = 0;\n private lastEvaluatedKey?: Record<string, unknown>;\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"]}