dyno-table 2.5.2 → 2.6.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.
Files changed (76) hide show
  1. package/dist/builders/batch-builder.d.ts +249 -0
  2. package/dist/builders/builder-types.d.ts +123 -0
  3. package/dist/builders/condition-check-builder.d.ts +149 -0
  4. package/dist/builders/delete-builder.d.ts +208 -0
  5. package/dist/builders/entity-aware-builders.d.ts +127 -0
  6. package/dist/builders/filter-builder.d.ts +294 -0
  7. package/dist/builders/get-builder.d.ts +191 -0
  8. package/dist/builders/index.d.ts +14 -0
  9. package/dist/builders/paginator.d.ts +151 -0
  10. package/dist/builders/put-builder.d.ts +317 -0
  11. package/dist/builders/query-builder.d.ts +218 -0
  12. package/dist/builders/result-iterator.d.ts +55 -0
  13. package/dist/builders/scan-builder.d.ts +109 -0
  14. package/dist/builders/transaction-builder.d.ts +462 -0
  15. package/dist/builders/types.d.ts +25 -0
  16. package/dist/builders/update-builder.d.ts +372 -0
  17. package/dist/builders.cjs +3648 -43
  18. package/dist/builders.d.ts +1 -4
  19. package/dist/builders.js +3648 -3
  20. package/dist/conditions.cjs +60 -67
  21. package/dist/conditions.d.ts +705 -3
  22. package/dist/conditions.js +46 -1
  23. package/dist/entity/ddb-indexing.d.ts +45 -0
  24. package/dist/entity/entity.d.ts +188 -0
  25. package/dist/entity/index-utils.d.ts +24 -0
  26. package/dist/entity.cjs +1126 -15
  27. package/dist/entity.d.ts +1 -261
  28. package/dist/entity.js +1127 -3
  29. package/dist/errors.d.ts +212 -0
  30. package/dist/expression.d.ts +9 -0
  31. package/dist/index-definition.d.ts +10 -0
  32. package/dist/index.cjs +5388 -270
  33. package/dist/index.d.ts +16 -273
  34. package/dist/index.js +5332 -6
  35. package/dist/operation-types.d.ts +8 -0
  36. package/dist/standard-schema.d.ts +2 -4
  37. package/dist/table.cjs +4311 -7
  38. package/dist/table.d.ts +13 -8
  39. package/dist/table.js +4315 -4
  40. package/dist/types.d.ts +6 -9
  41. package/dist/utils/chunk-array.d.ts +9 -0
  42. package/dist/utils/debug-expression.d.ts +32 -0
  43. package/dist/utils/debug-transaction.d.ts +17 -0
  44. package/dist/utils/error-factory.d.ts +162 -0
  45. package/dist/utils/error-utils.d.ts +170 -0
  46. package/dist/utils/index.d.ts +7 -0
  47. package/dist/utils/partition-key-template.d.ts +30 -0
  48. package/dist/utils/sort-key-template.d.ts +33 -0
  49. package/dist/utils.cjs +28 -10
  50. package/dist/utils.d.ts +1 -66
  51. package/dist/utils.js +29 -1
  52. package/package.json +53 -66
  53. package/dist/builders.d.cts +0 -4
  54. package/dist/chunk-2WIBY7PZ.js +0 -46
  55. package/dist/chunk-3DR6VOFW.cjs +0 -3349
  56. package/dist/chunk-42LH2UEM.js +0 -577
  57. package/dist/chunk-7UJJ7JXM.cjs +0 -63
  58. package/dist/chunk-ELULXDSB.cjs +0 -564
  59. package/dist/chunk-FF7FYGDH.js +0 -543
  60. package/dist/chunk-G5ERTQFX.cjs +0 -843
  61. package/dist/chunk-NYJGW3XH.js +0 -3334
  62. package/dist/chunk-PB7BBCZO.cjs +0 -32
  63. package/dist/chunk-QVRMYGC4.js +0 -29
  64. package/dist/chunk-RNX2DAHA.js +0 -818
  65. package/dist/chunk-ZUBCW3LA.cjs +0 -579
  66. package/dist/conditions-BSAcZswY.d.ts +0 -731
  67. package/dist/conditions-C8bM__Pn.d.cts +0 -731
  68. package/dist/conditions.d.cts +0 -3
  69. package/dist/entity.d.cts +0 -261
  70. package/dist/index-Bc-ra0im.d.ts +0 -3042
  71. package/dist/index-CPCmWsEv.d.cts +0 -3042
  72. package/dist/index.d.cts +0 -273
  73. package/dist/standard-schema.d.cts +0 -57
  74. package/dist/table.d.cts +0 -165
  75. package/dist/types.d.cts +0 -29
  76. package/dist/utils.d.cts +0 -66
@@ -0,0 +1,218 @@
1
+ import type { Condition } from "../conditions";
2
+ import type { DynamoItem, TableConfig } from "../types";
3
+ import type { QueryBuilderInterface } from "./builder-types";
4
+ import { FilterBuilder, type FilterOptions } from "./filter-builder";
5
+ import { ResultIterator } from "./result-iterator";
6
+ import type { Path } from "./types";
7
+ /**
8
+ * Configuration options for DynamoDB query operations.
9
+ * Extends the base FilterOptions with query-specific options.
10
+ */
11
+ export interface QueryOptions extends FilterOptions {
12
+ /** Condition for the sort key in the table or index */
13
+ sortKeyCondition?: Condition;
14
+ /** Direction of sort key traversal (true for ascending, false for descending) */
15
+ scanIndexForward?: boolean;
16
+ }
17
+ /**
18
+ * Function type for executing DynamoDB query operations.
19
+ * @typeParam T - The type of items being queried
20
+ */
21
+ type QueryExecutor<T extends DynamoItem> = (keyCondition: Condition, options: QueryOptions) => Promise<{
22
+ items: T[];
23
+ lastEvaluatedKey?: Record<string, unknown>;
24
+ }>;
25
+ /**
26
+ * Builder for creating DynamoDB query operations.
27
+ *
28
+ * The builder supports:
29
+ * - Type-safe GSI selection
30
+ * - Complex filter conditions
31
+ * - Automatic pagination handling
32
+ * - Consistent reads
33
+ * - Forward and reverse sorting
34
+ *
35
+ * @example
36
+ * ```typescript
37
+ * // Simple query
38
+ * const result = await new QueryBuilder(executor, eq('userId', '123'))
39
+ * .execute();
40
+ *
41
+ * // Complex query with GSI and filtering
42
+ * const result = await new QueryBuilder(executor, eq('status', 'ACTIVE'))
43
+ * .useIndex('status-index')
44
+ * .filter(op => op.beginsWith('name', 'John'))
45
+ * .select(['id', 'name', 'email'])
46
+ * .sortDescending()
47
+ * .limit(10)
48
+ * .execute();
49
+ *
50
+ * // Query with pagination
51
+ * const paginator = new QueryBuilder(executor, eq('type', 'order'))
52
+ * .paginate(25);
53
+ *
54
+ * while (paginator.hasNextPage()) {
55
+ * const page = await paginator.getNextPage();
56
+ * // Process page.items
57
+ * }
58
+ * ```
59
+ *
60
+ * @typeParam T - The type of items being queried
61
+ * @typeParam TConfig - The table configuration type for type-safe GSI selection
62
+ */
63
+ export declare class QueryBuilder<T extends DynamoItem, TConfig extends TableConfig = TableConfig> extends FilterBuilder<T, TConfig> implements QueryBuilderInterface<T, TConfig> {
64
+ private readonly keyCondition;
65
+ protected options: QueryOptions;
66
+ protected readonly executor: QueryExecutor<T>;
67
+ private includeIndexAttributes;
68
+ private readonly indexAttributeNames;
69
+ constructor(executor: QueryExecutor<T>, keyCondition: Condition, indexAttributeNames?: string[]);
70
+ /**
71
+ * Sets the maximum number of items to return from the query.
72
+ *
73
+ * Note: This is the default behavior if no sort order is specified.
74
+ *
75
+ * @example
76
+ * ```typescript
77
+ * // Get orders in chronological order
78
+ * const result = await new QueryBuilder(executor, eq('userId', '123'))
79
+ * .sortAscending()
80
+ * .execute();
81
+ *
82
+ * // Get events from oldest to newest
83
+ * const result = await new QueryBuilder(executor, eq('entityId', 'order-123'))
84
+ * .useIndex('entity-timestamp-index')
85
+ * .sortAscending()
86
+ * .execute();
87
+ * ```
88
+ *
89
+ * @returns The builder instance for method chaining
90
+ */
91
+ /**
92
+ * Sets the query to return items in ascending order by sort key.
93
+ *
94
+ * @example
95
+ * ```typescript
96
+ * // List dinosaurs by age
97
+ * const result = await new QueryBuilder(executor, eq('species', 'Velociraptor'))
98
+ * .useIndex('age-index')
99
+ * .sortAscending()
100
+ * .execute();
101
+ *
102
+ * // View incidents chronologically
103
+ * const result = await new QueryBuilder(executor, eq('type', 'SECURITY_BREACH'))
104
+ * .useIndex('date-index')
105
+ * .sortAscending()
106
+ * .execute();
107
+ * ```
108
+ *
109
+ * @returns The builder instance for method chaining
110
+ */
111
+ sortAscending(): this;
112
+ /**
113
+ * Sets the query to return items in descending order by sort key.
114
+ *
115
+ * @example
116
+ * ```typescript
117
+ * // Get most recent security incidents
118
+ * const result = await new QueryBuilder(executor, eq('type', 'SECURITY_BREACH'))
119
+ * .useIndex('date-index')
120
+ * .sortDescending()
121
+ * .limit(10)
122
+ * .execute();
123
+ *
124
+ * // Check latest dinosaur activities
125
+ * const result = await new QueryBuilder(executor, eq('species', 'Velociraptor'))
126
+ * .useIndex('activity-time-index')
127
+ * .filter(op => op.eq('status', 'ACTIVE'))
128
+ * .sortDescending()
129
+ * .execute();
130
+ * ```
131
+ *
132
+ * @returns The builder instance for method chaining
133
+ */
134
+ sortDescending(): this;
135
+ /**
136
+ * Ensures index attributes are included in the result.
137
+ * By default, index attributes are removed from query responses.
138
+ */
139
+ includeIndexes(): this;
140
+ select<K extends Path<T>>(fields: K | K[]): this;
141
+ /**
142
+ * Creates a deep clone of this QueryBuilder instance.
143
+ *
144
+ * This is particularly useful when:
145
+ * - Implementing pagination (used internally by paginate())
146
+ * - Creating query templates
147
+ * - Running multiple variations of a query
148
+ *
149
+ * @example
150
+ * ```typescript
151
+ * // Create base dinosaur query
152
+ * const baseQuery = new QueryBuilder(executor, eq('species', 'Velociraptor'))
153
+ * .useIndex('status-index')
154
+ * .select(['id', 'status', 'location']);
155
+ *
156
+ * // Check active dinosaurs
157
+ * const activeRaptors = baseQuery.clone()
158
+ * .filter(op => op.eq('status', 'HUNTING'))
159
+ * .execute();
160
+ *
161
+ * // Check contained dinosaurs
162
+ * const containedRaptors = baseQuery.clone()
163
+ * .filter(op => op.eq('status', 'CONTAINED'))
164
+ * .execute();
165
+ *
166
+ * // Check sedated dinosaurs
167
+ * const sedatedRaptors = baseQuery.clone()
168
+ * .filter(op => op.eq('status', 'SEDATED'))
169
+ * .execute();
170
+ * ```
171
+ *
172
+ * @returns A new QueryBuilder instance with the same configuration
173
+ */
174
+ clone(): QueryBuilder<T, TConfig>;
175
+ private deepCloneFilter;
176
+ /**
177
+ * Executes the query against DynamoDB and returns a generator that behaves like an array.
178
+ *
179
+ * The generator automatically handles pagination and provides array-like methods
180
+ * for processing results efficiently without loading everything into memory at once.
181
+ *
182
+ * @example
183
+ * ```typescript
184
+ * try {
185
+ * // Find active carnivores with automatic pagination
186
+ * const results = await new QueryBuilder(executor, eq('habitatId', 'PADDOCK-A'))
187
+ * .useIndex('species-status-index')
188
+ * .filter(op =>
189
+ * op.and([
190
+ * op.eq('diet', 'CARNIVORE'),
191
+ * op.eq('status', 'ACTIVE'),
192
+ * op.gt('aggressionLevel', 7)
193
+ * ])
194
+ * )
195
+ * .sortDescending()
196
+ * .execute();
197
+ *
198
+ * // Use like an array with automatic pagination
199
+ * for await (const dinosaur of results) {
200
+ * console.log(`Processing ${dinosaur.name}`);
201
+ * }
202
+ *
203
+ * // Or convert to array and use array methods
204
+ * const allItems = await results.toArray();
205
+ * const dangerousOnes = allItems.filter(dino => dino.aggressionLevel > 9);
206
+ * const totalCount = allItems.length;
207
+ * } catch (error) {
208
+ * console.error('Security scan failed:', error);
209
+ * }
210
+ * ```
211
+ *
212
+ * @returns A promise that resolves to a ResultGenerator that behaves like an array
213
+ */
214
+ execute(): Promise<ResultIterator<T, TConfig>>;
215
+ private addIndexAttributesToSelection;
216
+ private omitIndexAttributes;
217
+ }
218
+ export {};
@@ -0,0 +1,55 @@
1
+ import type { DynamoItem, TableConfig } from "../types";
2
+ import type { QueryBuilderInterface } from "./builder-types";
3
+ /**
4
+ * Function type for executing DynamoDB operations and returning raw results.
5
+ */
6
+ type DirectExecutor<T extends DynamoItem> = () => Promise<{
7
+ items: T[];
8
+ lastEvaluatedKey?: DynamoItem;
9
+ }>;
10
+ /**
11
+ * Minimal result generator that provides async iteration over DynamoDB results with automatic pagination.
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * const results = await queryBuilder.execute();
16
+ *
17
+ * for await (const item of results) {
18
+ * console.log(item);
19
+ * }
20
+ * ```
21
+ */
22
+ export declare class ResultIterator<T extends DynamoItem, TConfig extends TableConfig = TableConfig> {
23
+ private queryBuilder;
24
+ private directExecutor;
25
+ private lastEvaluatedKey?;
26
+ private itemsYielded;
27
+ private readonly overallLimit?;
28
+ constructor(queryBuilder: QueryBuilderInterface<T, TConfig>, directExecutor: DirectExecutor<T>);
29
+ /**
30
+ * Async iterator with automatic pagination
31
+ */
32
+ [Symbol.asyncIterator](): AsyncIterableIterator<T>;
33
+ /**
34
+ * Convert to array (loads all pages).
35
+ *
36
+ * ```ts
37
+ * const result = await table.query({ pk: "foo" }).execute();
38
+ * const allItemsFromDynamo = await result.toArray();
39
+ * ```
40
+ *
41
+ * Note: This will load all pages into memory. For large datasets, consider using async iteration instead.
42
+ *```ts
43
+ * const result = await table.query({ pk: "foo" }).execute();
44
+ * for await (const item of result) {
45
+ * // Process each item
46
+ * }
47
+ * ```
48
+ */
49
+ toArray(): Promise<T[]>;
50
+ /**
51
+ * Get the last evaluated key
52
+ */
53
+ getLastEvaluatedKey(): DynamoItem | undefined;
54
+ }
55
+ export {};
@@ -0,0 +1,109 @@
1
+ import type { DynamoItem, TableConfig } from "../types";
2
+ import type { ScanBuilderInterface } from "./builder-types";
3
+ import { FilterBuilder, type FilterOptions } from "./filter-builder";
4
+ import { ResultIterator } from "./result-iterator";
5
+ /**
6
+ * Configuration options for DynamoDB scan operations.
7
+ * Extends the base FilterOptions.
8
+ */
9
+ export type ScanOptions = FilterOptions;
10
+ /**
11
+ * Function type for executing DynamoDB filter operations.
12
+ * @typeParam T - The type of items being filtered
13
+ */
14
+ export type ScanExecutor<T extends DynamoItem> = (options: ScanOptions) => Promise<{
15
+ items: T[];
16
+ lastEvaluatedKey?: DynamoItem;
17
+ }>;
18
+ /**
19
+ * Builder for creating DynamoDB scan operations.
20
+ * Use this builder when you need to:
21
+ * - Scan all items in a table
22
+ * - Filter results based on non-key attributes
23
+ * - Scan items on a Secondary Index (GSI)
24
+ * - Implement pagination
25
+ * - Project specific attributes
26
+ *
27
+ * The builder supports:
28
+ * - Type-safe GSI selection
29
+ * - Complex filter conditions
30
+ * - Automatic pagination handling
31
+ * - Consistent reads
32
+ * - Attribute projection
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * // Simple scan with filtering
37
+ * const result = await new ScanBuilder(executor)
38
+ * .filter(op => op.eq('status', 'ACTIVE'))
39
+ * .execute();
40
+ *
41
+ * // Scan with GSI and filtering
42
+ * const result = await new ScanBuilder(executor)
43
+ * .useIndex('status-index')
44
+ * .filter(op => op.gt('securityLevel', 8))
45
+ * .select(['id', 'capacity', 'currentOccupants'])
46
+ * .limit(10)
47
+ * .execute();
48
+ *
49
+ * // Scan with pagination
50
+ * const paginator = new ScanBuilder(executor)
51
+ * .filter(op => op.eq('type', 'INCIDENT'))
52
+ * .paginate(25);
53
+ *
54
+ * while (paginator.hasNextPage()) {
55
+ * const page = await paginator.getNextPage();
56
+ * // Process page.items
57
+ * }
58
+ * ```
59
+ *
60
+ * @typeParam T - The type of items being scanned
61
+ * @typeParam TConfig - The table configuration type for type-safe GSI selection
62
+ */
63
+ export declare class ScanBuilder<T extends DynamoItem, TConfig extends TableConfig = TableConfig> extends FilterBuilder<T, TConfig> implements ScanBuilderInterface<T, TConfig> {
64
+ protected readonly executor: ScanExecutor<T>;
65
+ constructor(executor: ScanExecutor<T>);
66
+ /**
67
+ * Creates a deep clone of this ScanBuilder instance.
68
+ *
69
+ * @returns A new ScanBuilder instance with the same configuration
70
+ */
71
+ clone(): ScanBuilder<T, TConfig>;
72
+ private deepCloneFilter;
73
+ /**
74
+ * Executes the scan against DynamoDB and returns a generator that behaves like an array.
75
+ *
76
+ * The generator automatically handles pagination and provides array-like methods
77
+ * for processing results efficiently without loading everything into memory at once.
78
+ *
79
+ * @example
80
+ * ```typescript
81
+ * try {
82
+ * // Find all dinosaurs with high aggression levels with automatic pagination
83
+ * const results = await new ScanBuilder(executor)
84
+ * .filter(op =>
85
+ * op.and([
86
+ * op.eq('status', 'ACTIVE'),
87
+ * op.gt('aggressionLevel', 7)
88
+ * ])
89
+ * )
90
+ * .execute();
91
+ *
92
+ * // Use like an array with automatic pagination
93
+ * for await (const dinosaur of results) {
94
+ * console.log(`Processing dangerous dinosaur: ${dinosaur.name}`);
95
+ * }
96
+ *
97
+ * // Or convert to array and use array methods
98
+ * const allItems = await results.toArray();
99
+ * const criticalThreats = allItems.filter(dino => dino.aggressionLevel > 9);
100
+ * const totalCount = allItems.length;
101
+ * } catch (error) {
102
+ * console.error('Security scan failed:', error);
103
+ * }
104
+ * ```
105
+ *
106
+ * @returns A promise that resolves to a ResultGenerator that behaves like an array
107
+ */
108
+ execute(): Promise<ResultIterator<T, TConfig>>;
109
+ }