dyno-table 0.2.0-0 → 1.0.0-alpha.1
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/README.md +182 -577
- package/dist/{table.cjs → index.cjs} +175 -87
- package/dist/index.d.cts +2971 -0
- package/dist/index.d.ts +2971 -0
- package/dist/{table.js → index.js} +127 -86
- package/package.json +10 -77
- package/dist/builder-types-C_PDZhnP.d.ts +0 -118
- package/dist/builder-types-DtwbqMeF.d.cts +0 -118
- package/dist/builders/condition-check-builder.cjs +0 -394
- package/dist/builders/condition-check-builder.cjs.map +0 -1
- package/dist/builders/condition-check-builder.d.cts +0 -157
- package/dist/builders/condition-check-builder.d.ts +0 -157
- package/dist/builders/condition-check-builder.js +0 -392
- package/dist/builders/condition-check-builder.js.map +0 -1
- package/dist/builders/delete-builder.cjs +0 -405
- package/dist/builders/delete-builder.cjs.map +0 -1
- package/dist/builders/delete-builder.d.cts +0 -166
- package/dist/builders/delete-builder.d.ts +0 -166
- package/dist/builders/delete-builder.js +0 -403
- package/dist/builders/delete-builder.js.map +0 -1
- package/dist/builders/paginator.cjs +0 -199
- package/dist/builders/paginator.cjs.map +0 -1
- package/dist/builders/paginator.d.cts +0 -179
- package/dist/builders/paginator.d.ts +0 -179
- package/dist/builders/paginator.js +0 -197
- package/dist/builders/paginator.js.map +0 -1
- package/dist/builders/put-builder.cjs +0 -476
- package/dist/builders/put-builder.cjs.map +0 -1
- package/dist/builders/put-builder.d.cts +0 -274
- package/dist/builders/put-builder.d.ts +0 -274
- package/dist/builders/put-builder.js +0 -474
- package/dist/builders/put-builder.js.map +0 -1
- package/dist/builders/query-builder.cjs +0 -674
- package/dist/builders/query-builder.cjs.map +0 -1
- package/dist/builders/query-builder.d.cts +0 -6
- package/dist/builders/query-builder.d.ts +0 -6
- package/dist/builders/query-builder.js +0 -672
- package/dist/builders/query-builder.js.map +0 -1
- package/dist/builders/transaction-builder.cjs +0 -894
- package/dist/builders/transaction-builder.cjs.map +0 -1
- package/dist/builders/transaction-builder.d.cts +0 -511
- package/dist/builders/transaction-builder.d.ts +0 -511
- package/dist/builders/transaction-builder.js +0 -892
- package/dist/builders/transaction-builder.js.map +0 -1
- package/dist/builders/update-builder.cjs +0 -627
- package/dist/builders/update-builder.cjs.map +0 -1
- package/dist/builders/update-builder.d.cts +0 -365
- package/dist/builders/update-builder.d.ts +0 -365
- package/dist/builders/update-builder.js +0 -625
- package/dist/builders/update-builder.js.map +0 -1
- package/dist/conditions--ld9a78i.d.ts +0 -331
- package/dist/conditions-ChhQWd6z.d.cts +0 -331
- package/dist/conditions.cjs +0 -59
- package/dist/conditions.cjs.map +0 -1
- package/dist/conditions.d.cts +0 -3
- package/dist/conditions.d.ts +0 -3
- package/dist/conditions.js +0 -43
- package/dist/conditions.js.map +0 -1
- package/dist/entity.cjs +0 -228
- package/dist/entity.cjs.map +0 -1
- package/dist/entity.d.cts +0 -149
- package/dist/entity.d.ts +0 -149
- package/dist/entity.js +0 -224
- package/dist/entity.js.map +0 -1
- package/dist/query-builder-Csror9Iu.d.ts +0 -507
- package/dist/query-builder-D2FM9rsu.d.cts +0 -507
- package/dist/standard-schema.cjs +0 -4
- package/dist/standard-schema.cjs.map +0 -1
- package/dist/standard-schema.d.cts +0 -57
- package/dist/standard-schema.d.ts +0 -57
- package/dist/standard-schema.js +0 -3
- package/dist/standard-schema.js.map +0 -1
- package/dist/table-BEhBPy2G.d.cts +0 -364
- package/dist/table-BW3cmUqr.d.ts +0 -364
- package/dist/table.cjs.map +0 -1
- package/dist/table.d.cts +0 -12
- package/dist/table.d.ts +0 -12
- package/dist/table.js.map +0 -1
- package/dist/types.cjs +0 -4
- package/dist/types.cjs.map +0 -1
- package/dist/types.d.cts +0 -22
- package/dist/types.d.ts +0 -22
- package/dist/types.js +0 -3
- package/dist/types.js.map +0 -1
- package/dist/utils/partition-key-template.cjs +0 -19
- package/dist/utils/partition-key-template.cjs.map +0 -1
- package/dist/utils/partition-key-template.d.cts +0 -32
- package/dist/utils/partition-key-template.d.ts +0 -32
- package/dist/utils/partition-key-template.js +0 -17
- package/dist/utils/partition-key-template.js.map +0 -1
- package/dist/utils/sort-key-template.cjs +0 -19
- package/dist/utils/sort-key-template.cjs.map +0 -1
- package/dist/utils/sort-key-template.d.cts +0 -35
- package/dist/utils/sort-key-template.d.ts +0 -35
- package/dist/utils/sort-key-template.js +0 -17
- package/dist/utils/sort-key-template.js.map +0 -1
|
@@ -1,507 +0,0 @@
|
|
|
1
|
-
import { C as Condition, b as ConditionOperator } from './conditions--ld9a78i.js';
|
|
2
|
-
import { Paginator } from './builders/paginator.js';
|
|
3
|
-
import { DynamoItem, TableConfig, GSINames } from './types.js';
|
|
4
|
-
import { F as FilterBuilderInterface, Q as QueryBuilderInterface } from './builder-types-C_PDZhnP.js';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Configuration options for DynamoDB filter operations.
|
|
8
|
-
* These are common options shared between query and scan operations.
|
|
9
|
-
*/
|
|
10
|
-
interface FilterOptions {
|
|
11
|
-
/** Filter conditions applied to results */
|
|
12
|
-
filter?: Condition;
|
|
13
|
-
/** Maximum number of items to return */
|
|
14
|
-
limit?: number;
|
|
15
|
-
/** Name of the Global Secondary Index to use */
|
|
16
|
-
indexName?: string;
|
|
17
|
-
/** Whether to use strongly consistent reads */
|
|
18
|
-
consistentRead?: boolean;
|
|
19
|
-
/** List of attributes to return in the result */
|
|
20
|
-
projection?: string[];
|
|
21
|
-
/** Token for starting the operation from a specific point */
|
|
22
|
-
lastEvaluatedKey?: DynamoItem;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Abstract base builder for creating DynamoDB filter operations.
|
|
26
|
-
* This class provides common functionality for both Query and Scan operations.
|
|
27
|
-
*
|
|
28
|
-
* The builder supports:
|
|
29
|
-
* - Type-safe GSI selection
|
|
30
|
-
* - Complex filter conditions
|
|
31
|
-
* - Pagination
|
|
32
|
-
* - Consistent reads
|
|
33
|
-
* - Attribute projection
|
|
34
|
-
*
|
|
35
|
-
* @typeParam T - The type of items being filtered
|
|
36
|
-
* @typeParam TConfig - The table configuration type for type-safe GSI selection
|
|
37
|
-
*/
|
|
38
|
-
declare abstract class FilterBuilder<T extends DynamoItem, TConfig extends TableConfig = TableConfig> implements FilterBuilderInterface<T, TConfig> {
|
|
39
|
-
protected options: FilterOptions;
|
|
40
|
-
protected selectedFields: Set<string>;
|
|
41
|
-
/**
|
|
42
|
-
* Sets the maximum number of items to return.
|
|
43
|
-
* Use this method when you need to:
|
|
44
|
-
* - Limit the number of dinosaurs returned
|
|
45
|
-
* - Control the size of habitat reports
|
|
46
|
-
* - Implement manual pagination of security logs
|
|
47
|
-
*
|
|
48
|
-
* Note: This limit applies to the items that match the key condition
|
|
49
|
-
* before any filter expressions are applied.
|
|
50
|
-
*
|
|
51
|
-
* @example
|
|
52
|
-
* ```typescript
|
|
53
|
-
* // Get first 10 dinosaurs
|
|
54
|
-
* const result = await builder
|
|
55
|
-
* .limit(10)
|
|
56
|
-
* .execute();
|
|
57
|
-
* ```
|
|
58
|
-
*
|
|
59
|
-
* @param limit - Maximum number of items to return
|
|
60
|
-
* @returns The builder instance for method chaining
|
|
61
|
-
*/
|
|
62
|
-
limit(limit: number): this;
|
|
63
|
-
/**
|
|
64
|
-
* Gets the current limit set on the operation.
|
|
65
|
-
* This is used internally by the paginator to manage result sets.
|
|
66
|
-
*
|
|
67
|
-
* @returns The current limit or undefined if no limit is set
|
|
68
|
-
*/
|
|
69
|
-
getLimit(): number | undefined;
|
|
70
|
-
/**
|
|
71
|
-
* Specifies a Global Secondary Index (GSI) to use for the operation.
|
|
72
|
-
* Use this method when you need to:
|
|
73
|
-
* - Find dinosaurs by species or status
|
|
74
|
-
* - Search habitats by security level
|
|
75
|
-
* - Find incidents by date
|
|
76
|
-
* - List feeding schedules by time
|
|
77
|
-
*
|
|
78
|
-
* @example
|
|
79
|
-
* ```typescript
|
|
80
|
-
* // Find all dinosaurs of a specific species
|
|
81
|
-
* builder
|
|
82
|
-
* .useIndex('species-status-index')
|
|
83
|
-
* .filter(op => op.eq('status', 'ACTIVE'));
|
|
84
|
-
*
|
|
85
|
-
* // Search high-security habitats
|
|
86
|
-
* builder
|
|
87
|
-
* .useIndex('security-level-index')
|
|
88
|
-
* .filter(op =>
|
|
89
|
-
* op.and([
|
|
90
|
-
* op.gt('securityLevel', 8),
|
|
91
|
-
* op.eq('status', 'OPERATIONAL')
|
|
92
|
-
* ])
|
|
93
|
-
* );
|
|
94
|
-
* ```
|
|
95
|
-
*
|
|
96
|
-
* @param indexName - The name of the GSI to use (type-safe based on table configuration)
|
|
97
|
-
* @returns The builder instance for method chaining
|
|
98
|
-
*/
|
|
99
|
-
useIndex<I extends GSINames<TConfig>>(indexName: I): this;
|
|
100
|
-
/**
|
|
101
|
-
* Sets whether to use strongly consistent reads for the operation.
|
|
102
|
-
* Use this method when you need to:
|
|
103
|
-
* - Get real-time dinosaur status updates
|
|
104
|
-
* - Monitor critical security systems
|
|
105
|
-
* - Track immediate habitat changes
|
|
106
|
-
* - Verify containment protocols
|
|
107
|
-
*
|
|
108
|
-
* Note:
|
|
109
|
-
* - Consistent reads are not available on GSIs
|
|
110
|
-
* - Consistent reads consume twice the throughput
|
|
111
|
-
* - Default is eventually consistent reads
|
|
112
|
-
*
|
|
113
|
-
* @example
|
|
114
|
-
* ```typescript
|
|
115
|
-
* // Check immediate dinosaur status
|
|
116
|
-
* const result = await builder
|
|
117
|
-
* .filter(op => op.eq('status', 'ACTIVE'))
|
|
118
|
-
* .consistentRead()
|
|
119
|
-
* .execute();
|
|
120
|
-
*
|
|
121
|
-
* // Monitor security breaches
|
|
122
|
-
* const result = await builder
|
|
123
|
-
* .useIndex('primary-index')
|
|
124
|
-
* .consistentRead(isEmergencyMode)
|
|
125
|
-
* .execute();
|
|
126
|
-
* ```
|
|
127
|
-
*
|
|
128
|
-
* @param consistentRead - Whether to use consistent reads (defaults to true)
|
|
129
|
-
* @returns The builder instance for method chaining
|
|
130
|
-
*/
|
|
131
|
-
consistentRead(consistentRead?: boolean): this;
|
|
132
|
-
/**
|
|
133
|
-
* Adds a filter expression to refine the operation results.
|
|
134
|
-
* Use this method when you need to:
|
|
135
|
-
* - Filter dinosaurs by behavior patterns
|
|
136
|
-
* - Find habitats with specific conditions
|
|
137
|
-
* - Search for security incidents
|
|
138
|
-
* - Monitor feeding patterns
|
|
139
|
-
*
|
|
140
|
-
* @example
|
|
141
|
-
* ```typescript
|
|
142
|
-
* // Find aggressive carnivores
|
|
143
|
-
* builder.filter(op =>
|
|
144
|
-
* op.and([
|
|
145
|
-
* op.eq('diet', 'CARNIVORE'),
|
|
146
|
-
* op.gt('aggressionLevel', 7),
|
|
147
|
-
* op.eq('status', 'ACTIVE')
|
|
148
|
-
* ])
|
|
149
|
-
* );
|
|
150
|
-
*
|
|
151
|
-
* // Search suitable breeding habitats
|
|
152
|
-
* builder.filter(op =>
|
|
153
|
-
* op.and([
|
|
154
|
-
* op.between('temperature', 25, 30),
|
|
155
|
-
* op.lt('currentOccupants', 3),
|
|
156
|
-
* op.eq('quarantineStatus', 'CLEAR')
|
|
157
|
-
* ])
|
|
158
|
-
* );
|
|
159
|
-
* ```
|
|
160
|
-
*
|
|
161
|
-
* @param condition - Either a Condition object or a callback function that builds the condition
|
|
162
|
-
* @returns The builder instance for method chaining
|
|
163
|
-
*/
|
|
164
|
-
filter(condition: Condition | ((op: ConditionOperator<T>) => Condition)): this;
|
|
165
|
-
/**
|
|
166
|
-
* Specifies which attributes to return in the results.
|
|
167
|
-
* Use this method when you need to:
|
|
168
|
-
* - Get specific dinosaur attributes
|
|
169
|
-
* - Retrieve habitat statistics
|
|
170
|
-
* - Monitor security metrics
|
|
171
|
-
* - Optimize response size
|
|
172
|
-
*
|
|
173
|
-
* @example
|
|
174
|
-
* ```typescript
|
|
175
|
-
* // Get basic dinosaur info
|
|
176
|
-
* builder.select([
|
|
177
|
-
* 'species',
|
|
178
|
-
* 'status',
|
|
179
|
-
* 'stats.health',
|
|
180
|
-
* 'stats.aggressionLevel'
|
|
181
|
-
* ]);
|
|
182
|
-
*
|
|
183
|
-
* // Monitor habitat conditions
|
|
184
|
-
* builder
|
|
185
|
-
* .select('securityStatus')
|
|
186
|
-
* .select([
|
|
187
|
-
* 'currentOccupants',
|
|
188
|
-
* 'temperature',
|
|
189
|
-
* 'lastInspectionDate'
|
|
190
|
-
* ]);
|
|
191
|
-
* ```
|
|
192
|
-
*
|
|
193
|
-
* @param fields - A single field name or an array of field names to return
|
|
194
|
-
* @returns The builder instance for method chaining
|
|
195
|
-
*/
|
|
196
|
-
select(fields: string | string[]): this;
|
|
197
|
-
/**
|
|
198
|
-
* Creates a paginator that handles DynamoDB pagination automatically.
|
|
199
|
-
* The paginator handles:
|
|
200
|
-
* - Tracking the last evaluated key
|
|
201
|
-
* - Managing page boundaries
|
|
202
|
-
* - Respecting overall query limits
|
|
203
|
-
*
|
|
204
|
-
* @example
|
|
205
|
-
* ```typescript
|
|
206
|
-
* // Create a paginator for dinosaur records
|
|
207
|
-
* const paginator = builder
|
|
208
|
-
* .filter(op => op.eq('status', 'ACTIVE'))
|
|
209
|
-
* .paginate(10);
|
|
210
|
-
*
|
|
211
|
-
* // Process pages of dinosaur results
|
|
212
|
-
* while (paginator.hasNextPage()) {
|
|
213
|
-
* const page = await paginator.getNextPage();
|
|
214
|
-
* console.log(`Processing page ${page.page}, count: ${page.items.length}`);
|
|
215
|
-
* // Process dinosaur data
|
|
216
|
-
* }
|
|
217
|
-
* ```
|
|
218
|
-
*
|
|
219
|
-
* @param pageSize - The number of items to return per page
|
|
220
|
-
* @returns A Paginator instance that manages the pagination state
|
|
221
|
-
* @see Paginator for more pagination control options
|
|
222
|
-
*/
|
|
223
|
-
paginate(pageSize: number): Paginator<T, TConfig>;
|
|
224
|
-
/**
|
|
225
|
-
* Sets the starting point using a previous lastEvaluatedKey.
|
|
226
|
-
* Use this method when you need to:
|
|
227
|
-
* - Implement manual dinosaur list pagination
|
|
228
|
-
* - Resume habitat inspection reviews
|
|
229
|
-
* - Continue security incident analysis
|
|
230
|
-
* - Store operation position between sessions
|
|
231
|
-
*
|
|
232
|
-
* Note: This method is typically used for manual pagination.
|
|
233
|
-
* For automatic pagination, use the paginate() method instead.
|
|
234
|
-
*
|
|
235
|
-
* @example
|
|
236
|
-
* ```typescript
|
|
237
|
-
* // First batch of dinosaurs
|
|
238
|
-
* const result1 = await builder
|
|
239
|
-
* .filter(op => op.eq('status', 'ACTIVE'))
|
|
240
|
-
* .limit(5)
|
|
241
|
-
* .execute();
|
|
242
|
-
*
|
|
243
|
-
* if (result1.lastEvaluatedKey) {
|
|
244
|
-
* // Continue listing dinosaurs
|
|
245
|
-
* const result2 = await builder
|
|
246
|
-
* .filter(op => op.eq('status', 'ACTIVE'))
|
|
247
|
-
* .startFrom(result1.lastEvaluatedKey)
|
|
248
|
-
* .limit(5)
|
|
249
|
-
* .execute();
|
|
250
|
-
*
|
|
251
|
-
* console.log('Additional dinosaurs:', result2.items);
|
|
252
|
-
* }
|
|
253
|
-
* ```
|
|
254
|
-
*
|
|
255
|
-
* @param lastEvaluatedKey - The exclusive start key from a previous result
|
|
256
|
-
* @returns The builder instance for method chaining
|
|
257
|
-
*/
|
|
258
|
-
startFrom(lastEvaluatedKey: DynamoItem): this;
|
|
259
|
-
/**
|
|
260
|
-
* Creates a deep clone of this builder instance.
|
|
261
|
-
* Use this method when you need to:
|
|
262
|
-
* - Query different dinosaur statuses
|
|
263
|
-
* - Check multiple habitat conditions
|
|
264
|
-
* - Monitor various security levels
|
|
265
|
-
* - Create report templates
|
|
266
|
-
*
|
|
267
|
-
* This is particularly useful when:
|
|
268
|
-
* - Implementing pagination (used internally by paginate())
|
|
269
|
-
* - Creating operation templates
|
|
270
|
-
* - Running multiple variations of an operation
|
|
271
|
-
*
|
|
272
|
-
* @example
|
|
273
|
-
* ```typescript
|
|
274
|
-
* // Create base dinosaur query
|
|
275
|
-
* const baseBuilder = builder
|
|
276
|
-
* .useIndex('status-index')
|
|
277
|
-
* .select(['id', 'status', 'location']);
|
|
278
|
-
*
|
|
279
|
-
* // Check active dinosaurs
|
|
280
|
-
* const activeRaptors = baseBuilder.clone()
|
|
281
|
-
* .filter(op => op.eq('status', 'HUNTING'))
|
|
282
|
-
* .execute();
|
|
283
|
-
*
|
|
284
|
-
* // Check contained dinosaurs
|
|
285
|
-
* const containedRaptors = baseBuilder.clone()
|
|
286
|
-
* .filter(op => op.eq('status', 'CONTAINED'))
|
|
287
|
-
* .execute();
|
|
288
|
-
* ```
|
|
289
|
-
*
|
|
290
|
-
* @returns A new builder instance with the same configuration
|
|
291
|
-
*/
|
|
292
|
-
abstract clone(): FilterBuilderInterface<T, TConfig>;
|
|
293
|
-
/**
|
|
294
|
-
* Executes the operation against DynamoDB.
|
|
295
|
-
* This method must be implemented by subclasses to handle
|
|
296
|
-
* their specific execution logic.
|
|
297
|
-
*/
|
|
298
|
-
abstract execute(): Promise<{
|
|
299
|
-
items: T[];
|
|
300
|
-
lastEvaluatedKey?: DynamoItem;
|
|
301
|
-
}>;
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
/**
|
|
305
|
-
* Configuration options for DynamoDB query operations.
|
|
306
|
-
* Extends the base FilterOptions with query-specific options.
|
|
307
|
-
*/
|
|
308
|
-
interface QueryOptions extends FilterOptions {
|
|
309
|
-
/** Condition for the sort key in the table or index */
|
|
310
|
-
sortKeyCondition?: Condition;
|
|
311
|
-
/** Direction of sort key traversal (true for ascending, false for descending) */
|
|
312
|
-
scanIndexForward?: boolean;
|
|
313
|
-
}
|
|
314
|
-
/**
|
|
315
|
-
* Function type for executing DynamoDB query operations.
|
|
316
|
-
* @typeParam T - The type of items being queried
|
|
317
|
-
*/
|
|
318
|
-
type QueryExecutor<T extends DynamoItem> = (keyCondition: Condition, options: QueryOptions) => Promise<{
|
|
319
|
-
items: T[];
|
|
320
|
-
lastEvaluatedKey?: Record<string, unknown>;
|
|
321
|
-
}>;
|
|
322
|
-
/**
|
|
323
|
-
* Builder for creating DynamoDB query operations.
|
|
324
|
-
*
|
|
325
|
-
* The builder supports:
|
|
326
|
-
* - Type-safe GSI selection
|
|
327
|
-
* - Complex filter conditions
|
|
328
|
-
* - Automatic pagination handling
|
|
329
|
-
* - Consistent reads
|
|
330
|
-
* - Forward and reverse sorting
|
|
331
|
-
*
|
|
332
|
-
* @example
|
|
333
|
-
* ```typescript
|
|
334
|
-
* // Simple query
|
|
335
|
-
* const result = await new QueryBuilder(executor, eq('userId', '123'))
|
|
336
|
-
* .execute();
|
|
337
|
-
*
|
|
338
|
-
* // Complex query with GSI and filtering
|
|
339
|
-
* const result = await new QueryBuilder(executor, eq('status', 'ACTIVE'))
|
|
340
|
-
* .useIndex('status-index')
|
|
341
|
-
* .filter(op => op.beginsWith('name', 'John'))
|
|
342
|
-
* .select(['id', 'name', 'email'])
|
|
343
|
-
* .sortDescending()
|
|
344
|
-
* .limit(10)
|
|
345
|
-
* .execute();
|
|
346
|
-
*
|
|
347
|
-
* // Query with pagination
|
|
348
|
-
* const paginator = new QueryBuilder(executor, eq('type', 'order'))
|
|
349
|
-
* .paginate(25);
|
|
350
|
-
*
|
|
351
|
-
* while (paginator.hasNextPage()) {
|
|
352
|
-
* const page = await paginator.getNextPage();
|
|
353
|
-
* // Process page.items
|
|
354
|
-
* }
|
|
355
|
-
* ```
|
|
356
|
-
*
|
|
357
|
-
* @typeParam T - The type of items being queried
|
|
358
|
-
* @typeParam TConfig - The table configuration type for type-safe GSI selection
|
|
359
|
-
*/
|
|
360
|
-
declare class QueryBuilder<T extends DynamoItem, TConfig extends TableConfig = TableConfig> extends FilterBuilder<T, TConfig> implements QueryBuilderInterface<T, TConfig> {
|
|
361
|
-
private readonly keyCondition;
|
|
362
|
-
protected options: QueryOptions;
|
|
363
|
-
protected readonly executor: QueryExecutor<T>;
|
|
364
|
-
constructor(executor: QueryExecutor<T>, keyCondition: Condition);
|
|
365
|
-
/**
|
|
366
|
-
* Sets the maximum number of items to return from the query.
|
|
367
|
-
*
|
|
368
|
-
* Note: This is the default behavior if no sort order is specified.
|
|
369
|
-
*
|
|
370
|
-
* @example
|
|
371
|
-
* ```typescript
|
|
372
|
-
* // Get orders in chronological order
|
|
373
|
-
* const result = await new QueryBuilder(executor, eq('userId', '123'))
|
|
374
|
-
* .sortAscending()
|
|
375
|
-
* .execute();
|
|
376
|
-
*
|
|
377
|
-
* // Get events from oldest to newest
|
|
378
|
-
* const result = await new QueryBuilder(executor, eq('entityId', 'order-123'))
|
|
379
|
-
* .useIndex('entity-timestamp-index')
|
|
380
|
-
* .sortAscending()
|
|
381
|
-
* .execute();
|
|
382
|
-
* ```
|
|
383
|
-
*
|
|
384
|
-
* @returns The builder instance for method chaining
|
|
385
|
-
*/
|
|
386
|
-
/**
|
|
387
|
-
* Sets the query to return items in ascending order by sort key.
|
|
388
|
-
*
|
|
389
|
-
* @example
|
|
390
|
-
* ```typescript
|
|
391
|
-
* // List dinosaurs by age
|
|
392
|
-
* const result = await new QueryBuilder(executor, eq('species', 'Velociraptor'))
|
|
393
|
-
* .useIndex('age-index')
|
|
394
|
-
* .sortAscending()
|
|
395
|
-
* .execute();
|
|
396
|
-
*
|
|
397
|
-
* // View incidents chronologically
|
|
398
|
-
* const result = await new QueryBuilder(executor, eq('type', 'SECURITY_BREACH'))
|
|
399
|
-
* .useIndex('date-index')
|
|
400
|
-
* .sortAscending()
|
|
401
|
-
* .execute();
|
|
402
|
-
* ```
|
|
403
|
-
*
|
|
404
|
-
* @returns The builder instance for method chaining
|
|
405
|
-
*/
|
|
406
|
-
sortAscending(): this;
|
|
407
|
-
/**
|
|
408
|
-
* Sets the query to return items in descending order by sort key.
|
|
409
|
-
*
|
|
410
|
-
* @example
|
|
411
|
-
* ```typescript
|
|
412
|
-
* // Get most recent security incidents
|
|
413
|
-
* const result = await new QueryBuilder(executor, eq('type', 'SECURITY_BREACH'))
|
|
414
|
-
* .useIndex('date-index')
|
|
415
|
-
* .sortDescending()
|
|
416
|
-
* .limit(10)
|
|
417
|
-
* .execute();
|
|
418
|
-
*
|
|
419
|
-
* // Check latest dinosaur activities
|
|
420
|
-
* const result = await new QueryBuilder(executor, eq('species', 'Velociraptor'))
|
|
421
|
-
* .useIndex('activity-time-index')
|
|
422
|
-
* .filter(op => op.eq('status', 'ACTIVE'))
|
|
423
|
-
* .sortDescending()
|
|
424
|
-
* .execute();
|
|
425
|
-
* ```
|
|
426
|
-
*
|
|
427
|
-
* @returns The builder instance for method chaining
|
|
428
|
-
*/
|
|
429
|
-
sortDescending(): this;
|
|
430
|
-
/**
|
|
431
|
-
* Creates a deep clone of this QueryBuilder instance.
|
|
432
|
-
*
|
|
433
|
-
* This is particularly useful when:
|
|
434
|
-
* - Implementing pagination (used internally by paginate())
|
|
435
|
-
* - Creating query templates
|
|
436
|
-
* - Running multiple variations of a query
|
|
437
|
-
*
|
|
438
|
-
* @example
|
|
439
|
-
* ```typescript
|
|
440
|
-
* // Create base dinosaur query
|
|
441
|
-
* const baseQuery = new QueryBuilder(executor, eq('species', 'Velociraptor'))
|
|
442
|
-
* .useIndex('status-index')
|
|
443
|
-
* .select(['id', 'status', 'location']);
|
|
444
|
-
*
|
|
445
|
-
* // Check active dinosaurs
|
|
446
|
-
* const activeRaptors = baseQuery.clone()
|
|
447
|
-
* .filter(op => op.eq('status', 'HUNTING'))
|
|
448
|
-
* .execute();
|
|
449
|
-
*
|
|
450
|
-
* // Check contained dinosaurs
|
|
451
|
-
* const containedRaptors = baseQuery.clone()
|
|
452
|
-
* .filter(op => op.eq('status', 'CONTAINED'))
|
|
453
|
-
* .execute();
|
|
454
|
-
*
|
|
455
|
-
* // Check sedated dinosaurs
|
|
456
|
-
* const sedatedRaptors = baseQuery.clone()
|
|
457
|
-
* .filter(op => op.eq('status', 'SEDATED'))
|
|
458
|
-
* .execute();
|
|
459
|
-
* ```
|
|
460
|
-
*
|
|
461
|
-
* @returns A new QueryBuilder instance with the same configuration
|
|
462
|
-
*/
|
|
463
|
-
clone(): QueryBuilder<T, TConfig>;
|
|
464
|
-
/**
|
|
465
|
-
* Executes the query against DynamoDB.
|
|
466
|
-
*
|
|
467
|
-
* The method returns both the matched items and, if there are more results,
|
|
468
|
-
* a lastEvaluatedKey that can be used with startFrom() to continue the query.
|
|
469
|
-
*
|
|
470
|
-
* @example
|
|
471
|
-
* ```typescript
|
|
472
|
-
* try {
|
|
473
|
-
* // Find active carnivores in specific habitat
|
|
474
|
-
* const result = await new QueryBuilder(executor, eq('habitatId', 'PADDOCK-A'))
|
|
475
|
-
* .useIndex('species-status-index')
|
|
476
|
-
* .filter(op =>
|
|
477
|
-
* op.and([
|
|
478
|
-
* op.eq('diet', 'CARNIVORE'),
|
|
479
|
-
* op.eq('status', 'ACTIVE'),
|
|
480
|
-
* op.gt('aggressionLevel', 7)
|
|
481
|
-
* ])
|
|
482
|
-
* )
|
|
483
|
-
* .sortDescending()
|
|
484
|
-
* .limit(5)
|
|
485
|
-
* .execute();
|
|
486
|
-
*
|
|
487
|
-
* console.log(`Found ${result.items.length} dangerous dinosaurs`);
|
|
488
|
-
*
|
|
489
|
-
* if (result.lastEvaluatedKey) {
|
|
490
|
-
* console.log('Additional threats detected');
|
|
491
|
-
* }
|
|
492
|
-
* } catch (error) {
|
|
493
|
-
* console.error('Security scan failed:', error);
|
|
494
|
-
* }
|
|
495
|
-
* ```
|
|
496
|
-
*
|
|
497
|
-
* @returns A promise that resolves to an object containing:
|
|
498
|
-
* - items: Array of items matching the query
|
|
499
|
-
* - lastEvaluatedKey: Token for continuing the query, if more items exist
|
|
500
|
-
*/
|
|
501
|
-
execute(): Promise<{
|
|
502
|
-
items: T[];
|
|
503
|
-
lastEvaluatedKey?: Record<string, unknown>;
|
|
504
|
-
}>;
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
export { FilterBuilder as F, QueryBuilder as Q, type FilterOptions as a, type QueryOptions as b };
|