dyno-table 1.7.0 → 2.0.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.
- package/dist/{batch-builder-Dz1yPGrJ.d.ts → batch-builder-BOBwOIUE.d.ts} +1 -1
- package/dist/{batch-builder-DNsz6zvh.d.cts → batch-builder-CKYnMRyz.d.cts} +1 -1
- package/dist/{builder-types-DlaUSc-b.d.cts → builder-types-BTVhQSHI.d.cts} +55 -5
- package/dist/{builder-types-B_tCpn9F.d.ts → builder-types-CzuLR4Th.d.ts} +55 -5
- package/dist/builders/condition-check-builder.d.cts +1 -1
- package/dist/builders/condition-check-builder.d.ts +1 -1
- package/dist/builders/delete-builder.d.cts +2 -2
- package/dist/builders/delete-builder.d.ts +2 -2
- package/dist/builders/paginator.cjs +21 -3
- package/dist/builders/paginator.cjs.map +1 -1
- package/dist/builders/paginator.d.cts +3 -3
- package/dist/builders/paginator.d.ts +3 -3
- package/dist/builders/paginator.js +21 -3
- package/dist/builders/paginator.js.map +1 -1
- package/dist/builders/put-builder.d.cts +2 -2
- package/dist/builders/put-builder.d.ts +2 -2
- package/dist/builders/query-builder.cjs +115 -22
- package/dist/builders/query-builder.cjs.map +1 -1
- package/dist/builders/query-builder.d.cts +2 -2
- package/dist/builders/query-builder.d.ts +2 -2
- package/dist/builders/query-builder.js +115 -22
- package/dist/builders/query-builder.js.map +1 -1
- package/dist/builders/transaction-builder.d.cts +1 -1
- package/dist/builders/transaction-builder.d.ts +1 -1
- package/dist/builders/update-builder.d.cts +1 -1
- package/dist/builders/update-builder.d.ts +1 -1
- package/dist/entity.d.cts +4 -4
- package/dist/entity.d.ts +4 -4
- package/dist/index.cjs +131 -36
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +131 -36
- package/dist/index.js.map +1 -1
- package/dist/{query-builder-C6XjVEFH.d.ts → query-builder-CaHzZmDf.d.ts} +31 -29
- package/dist/{query-builder-BDuHHrb-.d.cts → query-builder-DFkxojBM.d.cts} +31 -29
- package/dist/{table-DAKlzQsK.d.cts → table-CHitMHXE.d.cts} +18 -20
- package/dist/{table-BWa4tx63.d.ts → table-m7DQk5dK.d.ts} +18 -20
- package/dist/table.cjs +131 -36
- package/dist/table.cjs.map +1 -1
- package/dist/table.d.cts +4 -4
- package/dist/table.d.ts +4 -4
- package/dist/table.js +131 -36
- package/dist/table.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DynamoItem } from './types.js';
|
|
2
2
|
import { r as PrimaryKeyWithoutExpression } from './conditions-BtynAviC.js';
|
|
3
|
-
import { a as PutCommandParams, D as DeleteCommandParams } from './builder-types-
|
|
3
|
+
import { a as PutCommandParams, D as DeleteCommandParams } from './builder-types-CzuLR4Th.js';
|
|
4
4
|
|
|
5
5
|
type BatchWriteOperation<T extends Record<string, unknown>> = {
|
|
6
6
|
type: "put";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DynamoItem } from './types.cjs';
|
|
2
2
|
import { r as PrimaryKeyWithoutExpression } from './conditions-3ae5znV_.cjs';
|
|
3
|
-
import { a as PutCommandParams, D as DeleteCommandParams } from './builder-types-
|
|
3
|
+
import { a as PutCommandParams, D as DeleteCommandParams } from './builder-types-BTVhQSHI.cjs';
|
|
4
4
|
|
|
5
5
|
type BatchWriteOperation<T extends Record<string, unknown>> = {
|
|
6
6
|
type: "put";
|
|
@@ -14,6 +14,59 @@ interface DynamoCommandWithExpressions {
|
|
|
14
14
|
[key: string]: unknown;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
/**
|
|
18
|
+
* Function type for executing DynamoDB operations and returning raw results.
|
|
19
|
+
*/
|
|
20
|
+
type DirectExecutor<T extends DynamoItem> = () => Promise<{
|
|
21
|
+
items: T[];
|
|
22
|
+
lastEvaluatedKey?: DynamoItem;
|
|
23
|
+
}>;
|
|
24
|
+
/**
|
|
25
|
+
* Minimal result generator that provides async iteration over DynamoDB results with automatic pagination.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* const results = await queryBuilder.execute();
|
|
30
|
+
*
|
|
31
|
+
* for await (const item of results) {
|
|
32
|
+
* console.log(item);
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
declare class ResultIterator<T extends DynamoItem, TConfig extends TableConfig = TableConfig> {
|
|
37
|
+
private queryBuilder;
|
|
38
|
+
private directExecutor;
|
|
39
|
+
private lastEvaluatedKey?;
|
|
40
|
+
private itemsYielded;
|
|
41
|
+
private readonly overallLimit?;
|
|
42
|
+
constructor(queryBuilder: QueryBuilderInterface<T, TConfig>, directExecutor: DirectExecutor<T>);
|
|
43
|
+
/**
|
|
44
|
+
* Async iterator with automatic pagination
|
|
45
|
+
*/
|
|
46
|
+
[Symbol.asyncIterator](): AsyncIterableIterator<T>;
|
|
47
|
+
/**
|
|
48
|
+
* Convert to array (loads all pages).
|
|
49
|
+
*
|
|
50
|
+
* ```ts
|
|
51
|
+
* const result = await table.query({ pk: "foo" }).execute();
|
|
52
|
+
* const allItemsFromDynamo = await result.toArray();
|
|
53
|
+
* ```
|
|
54
|
+
*
|
|
55
|
+
* Note: This will load all pages into memory. For large datasets, consider using async iteration instead.
|
|
56
|
+
*```ts
|
|
57
|
+
* const result = await table.query({ pk: "foo" }).execute();
|
|
58
|
+
* for await (const item of result) {
|
|
59
|
+
* // Process each item
|
|
60
|
+
* }
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
toArray(): Promise<T[]>;
|
|
64
|
+
/**
|
|
65
|
+
* Get the last evaluated key
|
|
66
|
+
*/
|
|
67
|
+
getLastEvaluatedKey(): DynamoItem | undefined;
|
|
68
|
+
}
|
|
69
|
+
|
|
17
70
|
interface DeleteCommandParams extends DynamoCommandWithExpressions {
|
|
18
71
|
tableName: string;
|
|
19
72
|
key: Record<string, unknown>;
|
|
@@ -77,10 +130,7 @@ interface BaseBuilderInterface<T extends DynamoItem, TConfig extends TableConfig
|
|
|
77
130
|
limit(limit: number): B;
|
|
78
131
|
getLimit(): number | undefined;
|
|
79
132
|
startFrom(lastEvaluatedKey: DynamoItem): B;
|
|
80
|
-
execute(): Promise<
|
|
81
|
-
items: T[];
|
|
82
|
-
lastEvaluatedKey?: DynamoItem;
|
|
83
|
-
}>;
|
|
133
|
+
execute(): Promise<ResultIterator<T, TConfig>>;
|
|
84
134
|
}
|
|
85
135
|
/**
|
|
86
136
|
* Interface for the QueryBuilder class to be used by Paginator
|
|
@@ -116,4 +166,4 @@ interface PaginationResult<T> {
|
|
|
116
166
|
page: number;
|
|
117
167
|
}
|
|
118
168
|
|
|
119
|
-
export type
|
|
169
|
+
export { type ConditionCheckCommandParams as C, type DeleteCommandParams as D, type FilterBuilderInterface as F, type PaginationResult as P, type QueryBuilderInterface as Q, ResultIterator as R, type ScanBuilderInterface as S, type UpdateCommandParams as U, type PutCommandParams as a };
|
|
@@ -14,6 +14,59 @@ interface DynamoCommandWithExpressions {
|
|
|
14
14
|
[key: string]: unknown;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
/**
|
|
18
|
+
* Function type for executing DynamoDB operations and returning raw results.
|
|
19
|
+
*/
|
|
20
|
+
type DirectExecutor<T extends DynamoItem> = () => Promise<{
|
|
21
|
+
items: T[];
|
|
22
|
+
lastEvaluatedKey?: DynamoItem;
|
|
23
|
+
}>;
|
|
24
|
+
/**
|
|
25
|
+
* Minimal result generator that provides async iteration over DynamoDB results with automatic pagination.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* const results = await queryBuilder.execute();
|
|
30
|
+
*
|
|
31
|
+
* for await (const item of results) {
|
|
32
|
+
* console.log(item);
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
declare class ResultIterator<T extends DynamoItem, TConfig extends TableConfig = TableConfig> {
|
|
37
|
+
private queryBuilder;
|
|
38
|
+
private directExecutor;
|
|
39
|
+
private lastEvaluatedKey?;
|
|
40
|
+
private itemsYielded;
|
|
41
|
+
private readonly overallLimit?;
|
|
42
|
+
constructor(queryBuilder: QueryBuilderInterface<T, TConfig>, directExecutor: DirectExecutor<T>);
|
|
43
|
+
/**
|
|
44
|
+
* Async iterator with automatic pagination
|
|
45
|
+
*/
|
|
46
|
+
[Symbol.asyncIterator](): AsyncIterableIterator<T>;
|
|
47
|
+
/**
|
|
48
|
+
* Convert to array (loads all pages).
|
|
49
|
+
*
|
|
50
|
+
* ```ts
|
|
51
|
+
* const result = await table.query({ pk: "foo" }).execute();
|
|
52
|
+
* const allItemsFromDynamo = await result.toArray();
|
|
53
|
+
* ```
|
|
54
|
+
*
|
|
55
|
+
* Note: This will load all pages into memory. For large datasets, consider using async iteration instead.
|
|
56
|
+
*```ts
|
|
57
|
+
* const result = await table.query({ pk: "foo" }).execute();
|
|
58
|
+
* for await (const item of result) {
|
|
59
|
+
* // Process each item
|
|
60
|
+
* }
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
toArray(): Promise<T[]>;
|
|
64
|
+
/**
|
|
65
|
+
* Get the last evaluated key
|
|
66
|
+
*/
|
|
67
|
+
getLastEvaluatedKey(): DynamoItem | undefined;
|
|
68
|
+
}
|
|
69
|
+
|
|
17
70
|
interface DeleteCommandParams extends DynamoCommandWithExpressions {
|
|
18
71
|
tableName: string;
|
|
19
72
|
key: Record<string, unknown>;
|
|
@@ -77,10 +130,7 @@ interface BaseBuilderInterface<T extends DynamoItem, TConfig extends TableConfig
|
|
|
77
130
|
limit(limit: number): B;
|
|
78
131
|
getLimit(): number | undefined;
|
|
79
132
|
startFrom(lastEvaluatedKey: DynamoItem): B;
|
|
80
|
-
execute(): Promise<
|
|
81
|
-
items: T[];
|
|
82
|
-
lastEvaluatedKey?: DynamoItem;
|
|
83
|
-
}>;
|
|
133
|
+
execute(): Promise<ResultIterator<T, TConfig>>;
|
|
84
134
|
}
|
|
85
135
|
/**
|
|
86
136
|
* Interface for the QueryBuilder class to be used by Paginator
|
|
@@ -116,4 +166,4 @@ interface PaginationResult<T> {
|
|
|
116
166
|
page: number;
|
|
117
167
|
}
|
|
118
168
|
|
|
119
|
-
export type
|
|
169
|
+
export { type ConditionCheckCommandParams as C, type DeleteCommandParams as D, type FilterBuilderInterface as F, type PaginationResult as P, type QueryBuilderInterface as Q, ResultIterator as R, type ScanBuilderInterface as S, type UpdateCommandParams as U, type PutCommandParams as a };
|
|
@@ -2,7 +2,7 @@ import { r as PrimaryKeyWithoutExpression, C as Condition, q as ConditionOperato
|
|
|
2
2
|
import { TransactionBuilder } from './transaction-builder.cjs';
|
|
3
3
|
import { DynamoItem } from '../types.cjs';
|
|
4
4
|
import '@aws-sdk/lib-dynamodb';
|
|
5
|
-
import '../builder-types-
|
|
5
|
+
import '../builder-types-BTVhQSHI.cjs';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Builder for creating DynamoDB condition check operations.
|
|
@@ -2,7 +2,7 @@ import { r as PrimaryKeyWithoutExpression, C as Condition, q as ConditionOperato
|
|
|
2
2
|
import { TransactionBuilder } from './transaction-builder.js';
|
|
3
3
|
import { DynamoItem } from '../types.js';
|
|
4
4
|
import '@aws-sdk/lib-dynamodb';
|
|
5
|
-
import '../builder-types-
|
|
5
|
+
import '../builder-types-CzuLR4Th.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Builder for creating DynamoDB condition check operations.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { r as PrimaryKeyWithoutExpression, C as Condition, q as ConditionOperator } from '../conditions-3ae5znV_.cjs';
|
|
2
2
|
import { TransactionBuilder } from './transaction-builder.cjs';
|
|
3
|
-
import { B as BatchBuilder } from '../batch-builder-
|
|
4
|
-
import { D as DeleteCommandParams } from '../builder-types-
|
|
3
|
+
import { B as BatchBuilder } from '../batch-builder-CKYnMRyz.cjs';
|
|
4
|
+
import { D as DeleteCommandParams } from '../builder-types-BTVhQSHI.cjs';
|
|
5
5
|
import { DynamoItem } from '../types.cjs';
|
|
6
6
|
import '@aws-sdk/lib-dynamodb';
|
|
7
7
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { r as PrimaryKeyWithoutExpression, C as Condition, q as ConditionOperator } from '../conditions-BtynAviC.js';
|
|
2
2
|
import { TransactionBuilder } from './transaction-builder.js';
|
|
3
|
-
import { B as BatchBuilder } from '../batch-builder-
|
|
4
|
-
import { D as DeleteCommandParams } from '../builder-types-
|
|
3
|
+
import { B as BatchBuilder } from '../batch-builder-BOBwOIUE.js';
|
|
4
|
+
import { D as DeleteCommandParams } from '../builder-types-CzuLR4Th.js';
|
|
5
5
|
import { DynamoItem } from '../types.js';
|
|
6
6
|
import '@aws-sdk/lib-dynamodb';
|
|
7
7
|
|
|
@@ -115,13 +115,31 @@ var Paginator = class {
|
|
|
115
115
|
page: this.currentPage
|
|
116
116
|
};
|
|
117
117
|
}
|
|
118
|
-
|
|
118
|
+
if (effectivePageSize !== void 0) {
|
|
119
|
+
effectivePageSize = Math.min(effectivePageSize, remainingItems);
|
|
120
|
+
} else {
|
|
121
|
+
effectivePageSize = remainingItems;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
const query = this.queryBuilder.clone();
|
|
125
|
+
if (effectivePageSize !== void 0) {
|
|
126
|
+
query.limit(effectivePageSize);
|
|
119
127
|
}
|
|
120
|
-
const query = this.queryBuilder.clone().limit(effectivePageSize);
|
|
121
128
|
if (this.lastEvaluatedKey) {
|
|
122
129
|
query.startFrom(this.lastEvaluatedKey);
|
|
123
130
|
}
|
|
124
|
-
const
|
|
131
|
+
const generator = await query.execute();
|
|
132
|
+
const items = [];
|
|
133
|
+
let itemCount = 0;
|
|
134
|
+
for await (const item of generator) {
|
|
135
|
+
if (effectivePageSize !== void 0 && itemCount >= effectivePageSize) {
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
items.push(item);
|
|
139
|
+
itemCount++;
|
|
140
|
+
}
|
|
141
|
+
const lastEvaluatedKey = generator.getLastEvaluatedKey();
|
|
142
|
+
const result = { items, lastEvaluatedKey };
|
|
125
143
|
this.currentPage += 1;
|
|
126
144
|
this.lastEvaluatedKey = result.lastEvaluatedKey;
|
|
127
145
|
this.totalItemsRetrieved += result.items.length;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/builders/paginator.ts"],"names":[],"mappings":";;;AAqCO,IAAM,YAAN,MAAiF;AAAA,EAC9E,YAAA;AAAA,EACS,QAAA;AAAA,EACT,WAAA,GAAc,CAAA;AAAA,EACd,gBAAA;AAAA,EACA,YAAA,GAAe,IAAA;AAAA,EACf,mBAAA,GAAsB,CAAA;AAAA,EACb,YAAA;AAAA,EAEjB,WAAA,CAAY,cAAiD,QAAA,EAAkB;AAC7E,IAAA,IAAA,CAAK,YAAA,GAAe,YAAA;AACpB,IAAA,IAAA,CAAK,QAAA,GAAW,QAAA;AAEhB,IAAA,IAAA,CAAK,YAAA,GAAe,aAAa,QAAA,EAAS;AAAA,EAC5C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAgBO,cAAA,GAAyB;AAC9B,IAAA,OAAO,IAAA,CAAK,WAAA;AAAA,EACd;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,EA2BO,WAAA,GAAuB;AAE5B,IAAA,IAAI,KAAK,YAAA,KAAiB,MAAA,IAAa,IAAA,CAAK,mBAAA,IAAuB,KAAK,YAAA,EAAc;AACpF,MAAA,OAAO,KAAA;AAAA,IACT;AACA,IAAA,OAAO,IAAA,CAAK,YAAA;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA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AK,YAAA,GACH,CAAC,CAAC,MAAA,CAAO,gBAAA,KAAqB,KAAK,YAAA,KAAiB,MAAA,IAAa,IAAA,CAAK,mBAAA,GAAsB,IAAA,CAAK,YAAA,CAAA;AAEnG,IAAA,OAAO;AAAA,MACL,OAAO,MAAA,CAAO,KAAA;AAAA,MACd,kBAAkB,MAAA,CAAO,gBAAA;AAAA,MACzB,WAAA,EAAa,KAAK,WAAA,EAAY;AAAA,MAC9B,MAAM,IAAA,CAAK;AAAA,KACb;AAAA,EACF;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,EA6BA,MAAa,WAAA,GAA4B;AACvC,IAAA,MAAM,WAAgB,EAAC;AAEvB,IAAA,OAAO,IAAA,CAAK,aAAY,EAAG;AACzB,MAAA,MAAM,MAAA,GAAS,MAAM,IAAA,CAAK,WAAA,EAAY;AACtC,MAAA,QAAA,CAAS,IAAA,CAAK,GAAG,MAAA,CAAO,KAAK,CAAA;AAAA,IAC/B;AAEA,IAAA,OAAO,QAAA;AAAA,EACT;AACF","file":"paginator.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 *\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 *\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 *\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 *\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"]}
|
|
1
|
+
{"version":3,"sources":["../../src/builders/paginator.ts"],"names":[],"mappings":";;;AAqCO,IAAM,YAAN,MAAiF;AAAA,EAC9E,YAAA;AAAA,EACS,QAAA;AAAA,EACT,WAAA,GAAc,CAAA;AAAA,EACd,gBAAA;AAAA,EACA,YAAA,GAAe,IAAA;AAAA,EACf,mBAAA,GAAsB,CAAA;AAAA,EACb,YAAA;AAAA,EAEjB,WAAA,CAAY,cAAiD,QAAA,EAAmB;AAC9E,IAAA,IAAA,CAAK,YAAA,GAAe,YAAA;AACpB,IAAA,IAAA,CAAK,QAAA,GAAW,QAAA;AAEhB,IAAA,IAAA,CAAK,YAAA,GAAe,aAAa,QAAA,EAAS;AAAA,EAC5C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA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AA,MACd,kBAAkB,MAAA,CAAO,gBAAA;AAAA,MACzB,WAAA,EAAa,KAAK,WAAA,EAAY;AAAA,MAC9B,MAAM,IAAA,CAAK;AAAA,KACb;AAAA,EACF;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,EA6BA,MAAa,WAAA,GAA4B;AACvC,IAAA,MAAM,WAAgB,EAAC;AAEvB,IAAA,OAAO,IAAA,CAAK,aAAY,EAAG;AACzB,MAAA,MAAM,MAAA,GAAS,MAAM,IAAA,CAAK,WAAA,EAAY;AACtC,MAAA,QAAA,CAAS,IAAA,CAAK,GAAG,MAAA,CAAO,KAAK,CAAA;AAAA,IAC/B;AAEA,IAAA,OAAO,QAAA;AAAA,EACT;AACF","file":"paginator.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 *\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 *\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 *\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 if (effectivePageSize !== undefined) {\n effectivePageSize = Math.min(effectivePageSize, remainingItems);\n } else {\n effectivePageSize = remainingItems;\n }\n }\n\n // Clone the query builder to avoid modifying the original\n const query = this.queryBuilder.clone();\n\n // Only set limit if we have an effective page size (not automatic paging)\n if (effectivePageSize !== undefined) {\n query.limit(effectivePageSize);\n }\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 and get the first page from the generator\n const generator = await query.execute();\n const items: T[] = [];\n\n // Take items up to the effective page size\n let itemCount = 0;\n for await (const item of generator) {\n if (effectivePageSize !== undefined && itemCount >= effectivePageSize) {\n break;\n }\n items.push(item);\n itemCount++;\n }\n\n // Get the last evaluated key from the generator\n const lastEvaluatedKey = generator.getLastEvaluatedKey();\n\n const result = { items, lastEvaluatedKey };\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 *\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"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DynamoItem, TableConfig } from '../types.cjs';
|
|
2
|
-
import { Q as QueryBuilderInterface, P as PaginationResult } from '../builder-types-
|
|
2
|
+
import { Q as QueryBuilderInterface, P as PaginationResult } from '../builder-types-BTVhQSHI.cjs';
|
|
3
3
|
import '@aws-sdk/lib-dynamodb';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -38,13 +38,13 @@ import '@aws-sdk/lib-dynamodb';
|
|
|
38
38
|
*/
|
|
39
39
|
declare class Paginator<T extends DynamoItem, TConfig extends TableConfig = TableConfig> {
|
|
40
40
|
private queryBuilder;
|
|
41
|
-
private readonly pageSize
|
|
41
|
+
private readonly pageSize?;
|
|
42
42
|
private currentPage;
|
|
43
43
|
private lastEvaluatedKey?;
|
|
44
44
|
private hasMorePages;
|
|
45
45
|
private totalItemsRetrieved;
|
|
46
46
|
private readonly overallLimit?;
|
|
47
|
-
constructor(queryBuilder: QueryBuilderInterface<T, TConfig>, pageSize
|
|
47
|
+
constructor(queryBuilder: QueryBuilderInterface<T, TConfig>, pageSize?: number);
|
|
48
48
|
/**
|
|
49
49
|
* Gets the current page number (1-indexed).
|
|
50
50
|
*
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DynamoItem, TableConfig } from '../types.js';
|
|
2
|
-
import { Q as QueryBuilderInterface, P as PaginationResult } from '../builder-types-
|
|
2
|
+
import { Q as QueryBuilderInterface, P as PaginationResult } from '../builder-types-CzuLR4Th.js';
|
|
3
3
|
import '@aws-sdk/lib-dynamodb';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -38,13 +38,13 @@ import '@aws-sdk/lib-dynamodb';
|
|
|
38
38
|
*/
|
|
39
39
|
declare class Paginator<T extends DynamoItem, TConfig extends TableConfig = TableConfig> {
|
|
40
40
|
private queryBuilder;
|
|
41
|
-
private readonly pageSize
|
|
41
|
+
private readonly pageSize?;
|
|
42
42
|
private currentPage;
|
|
43
43
|
private lastEvaluatedKey?;
|
|
44
44
|
private hasMorePages;
|
|
45
45
|
private totalItemsRetrieved;
|
|
46
46
|
private readonly overallLimit?;
|
|
47
|
-
constructor(queryBuilder: QueryBuilderInterface<T, TConfig>, pageSize
|
|
47
|
+
constructor(queryBuilder: QueryBuilderInterface<T, TConfig>, pageSize?: number);
|
|
48
48
|
/**
|
|
49
49
|
* Gets the current page number (1-indexed).
|
|
50
50
|
*
|
|
@@ -113,13 +113,31 @@ var Paginator = class {
|
|
|
113
113
|
page: this.currentPage
|
|
114
114
|
};
|
|
115
115
|
}
|
|
116
|
-
|
|
116
|
+
if (effectivePageSize !== void 0) {
|
|
117
|
+
effectivePageSize = Math.min(effectivePageSize, remainingItems);
|
|
118
|
+
} else {
|
|
119
|
+
effectivePageSize = remainingItems;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
const query = this.queryBuilder.clone();
|
|
123
|
+
if (effectivePageSize !== void 0) {
|
|
124
|
+
query.limit(effectivePageSize);
|
|
117
125
|
}
|
|
118
|
-
const query = this.queryBuilder.clone().limit(effectivePageSize);
|
|
119
126
|
if (this.lastEvaluatedKey) {
|
|
120
127
|
query.startFrom(this.lastEvaluatedKey);
|
|
121
128
|
}
|
|
122
|
-
const
|
|
129
|
+
const generator = await query.execute();
|
|
130
|
+
const items = [];
|
|
131
|
+
let itemCount = 0;
|
|
132
|
+
for await (const item of generator) {
|
|
133
|
+
if (effectivePageSize !== void 0 && itemCount >= effectivePageSize) {
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
items.push(item);
|
|
137
|
+
itemCount++;
|
|
138
|
+
}
|
|
139
|
+
const lastEvaluatedKey = generator.getLastEvaluatedKey();
|
|
140
|
+
const result = { items, lastEvaluatedKey };
|
|
123
141
|
this.currentPage += 1;
|
|
124
142
|
this.lastEvaluatedKey = result.lastEvaluatedKey;
|
|
125
143
|
this.totalItemsRetrieved += result.items.length;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/builders/paginator.ts"],"names":[],"mappings":";AAqCO,IAAM,YAAN,MAAiF;AAAA,EAC9E,YAAA;AAAA,EACS,QAAA;AAAA,EACT,WAAA,GAAc,CAAA;AAAA,EACd,gBAAA;AAAA,EACA,YAAA,GAAe,IAAA;AAAA,EACf,mBAAA,GAAsB,CAAA;AAAA,EACb,YAAA;AAAA,EAEjB,WAAA,CAAY,cAAiD,QAAA,EAAkB;AAC7E,IAAA,IAAA,CAAK,YAAA,GAAe,YAAA;AACpB,IAAA,IAAA,CAAK,QAAA,GAAW,QAAA;AAEhB,IAAA,IAAA,CAAK,YAAA,GAAe,aAAa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ACtC,MAAA,QAAA,CAAS,IAAA,CAAK,GAAG,MAAA,CAAO,KAAK,CAAA;AAAA,IAC/B;AAEA,IAAA,OAAO,QAAA;AAAA,EACT;AACF","file":"paginator.js","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 *\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 *\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 *\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 *\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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AAAA,MACF;AACA,MAAA,KAAA,CAAM,KAAK,IAAI,CAAA;AACf,MAAA,SAAA,EAAA;AAAA,IACF;AAGA,IAAA,MAAM,gBAAA,GAAmB,UAAU,mBAAA,EAAoB;AAEvD,IAAA,MAAM,MAAA,GAAS,EAAE,KAAA,EAAO,gBAAA,EAAiB;AAGzC,IAAA,IAAA,CAAK,WAAA,IAAe,CAAA;AACpB,IAAA,IAAA,CAAK,mBAAmB,MAAA,CAAO,gBAAA;AAC/B,IAAA,IAAA,CAAK,mBAAA,IAAuB,OAAO,KAAA,CAAM,MAAA;AAMzC,IAAA,IAAA,CAAK,YAAA,GACH,CAAC,CAAC,MAAA,CAAO,gBAAA,KAAqB,KAAK,YAAA,KAAiB,MAAA,IAAa,IAAA,CAAK,mBAAA,GAAsB,IAAA,CAAK,YAAA,CAAA;AAEnG,IAAA,OAAO;AAAA,MACL,OAAO,MAAA,CAAO,KAAA;AAAA,MACd,kBAAkB,MAAA,CAAO,gBAAA;AAAA,MACzB,WAAA,EAAa,KAAK,WAAA,EAAY;AAAA,MAC9B,MAAM,IAAA,CAAK;AAAA,KACb;AAAA,EACF;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,EA6BA,MAAa,WAAA,GAA4B;AACvC,IAAA,MAAM,WAAgB,EAAC;AAEvB,IAAA,OAAO,IAAA,CAAK,aAAY,EAAG;AACzB,MAAA,MAAM,MAAA,GAAS,MAAM,IAAA,CAAK,WAAA,EAAY;AACtC,MAAA,QAAA,CAAS,IAAA,CAAK,GAAG,MAAA,CAAO,KAAK,CAAA;AAAA,IAC/B;AAEA,IAAA,OAAO,QAAA;AAAA,EACT;AACF","file":"paginator.js","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 *\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 *\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 *\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 if (effectivePageSize !== undefined) {\n effectivePageSize = Math.min(effectivePageSize, remainingItems);\n } else {\n effectivePageSize = remainingItems;\n }\n }\n\n // Clone the query builder to avoid modifying the original\n const query = this.queryBuilder.clone();\n\n // Only set limit if we have an effective page size (not automatic paging)\n if (effectivePageSize !== undefined) {\n query.limit(effectivePageSize);\n }\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 and get the first page from the generator\n const generator = await query.execute();\n const items: T[] = [];\n\n // Take items up to the effective page size\n let itemCount = 0;\n for await (const item of generator) {\n if (effectivePageSize !== undefined && itemCount >= effectivePageSize) {\n break;\n }\n items.push(item);\n itemCount++;\n }\n\n // Get the last evaluated key from the generator\n const lastEvaluatedKey = generator.getLastEvaluatedKey();\n\n const result = { items, lastEvaluatedKey };\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 *\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"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { s as Path, t as PathType, C as Condition, q as ConditionOperator } from '../conditions-3ae5znV_.cjs';
|
|
2
2
|
import { TransactionBuilder } from './transaction-builder.cjs';
|
|
3
|
-
import { B as BatchBuilder } from '../batch-builder-
|
|
4
|
-
import { a as PutCommandParams } from '../builder-types-
|
|
3
|
+
import { B as BatchBuilder } from '../batch-builder-CKYnMRyz.cjs';
|
|
4
|
+
import { a as PutCommandParams } from '../builder-types-BTVhQSHI.cjs';
|
|
5
5
|
import { DynamoItem } from '../types.cjs';
|
|
6
6
|
import '@aws-sdk/lib-dynamodb';
|
|
7
7
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { s as Path, t as PathType, C as Condition, q as ConditionOperator } from '../conditions-BtynAviC.js';
|
|
2
2
|
import { TransactionBuilder } from './transaction-builder.js';
|
|
3
|
-
import { B as BatchBuilder } from '../batch-builder-
|
|
4
|
-
import { a as PutCommandParams } from '../builder-types-
|
|
3
|
+
import { B as BatchBuilder } from '../batch-builder-BOBwOIUE.js';
|
|
4
|
+
import { a as PutCommandParams } from '../builder-types-CzuLR4Th.js';
|
|
5
5
|
import { DynamoItem } from '../types.js';
|
|
6
6
|
import '@aws-sdk/lib-dynamodb';
|
|
7
7
|
|