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
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,2971 @@
|
|
|
1
|
+
import { DynamoDBDocument, TransactWriteCommandInput } from '@aws-sdk/lib-dynamodb';
|
|
2
|
+
|
|
3
|
+
interface Index {
|
|
4
|
+
partitionKey: string;
|
|
5
|
+
sortKey?: string;
|
|
6
|
+
}
|
|
7
|
+
interface IndexConfig$1 {
|
|
8
|
+
partitionKey: string;
|
|
9
|
+
sortKey?: string;
|
|
10
|
+
gsis?: Record<string, Index>;
|
|
11
|
+
}
|
|
12
|
+
interface TableConfig {
|
|
13
|
+
client: DynamoDBDocument;
|
|
14
|
+
tableName: string;
|
|
15
|
+
indexes: IndexConfig$1;
|
|
16
|
+
}
|
|
17
|
+
type GSINames<T extends TableConfig> = keyof NonNullable<T["indexes"]["gsis"]>;
|
|
18
|
+
interface EntityConfig<T> {
|
|
19
|
+
name: string;
|
|
20
|
+
partitionKeyPrefix?: string;
|
|
21
|
+
sortKeyPrefix?: string;
|
|
22
|
+
timestamps?: boolean;
|
|
23
|
+
discriminator?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
type Primitive = null | undefined | string | number | boolean | symbol | bigint;
|
|
27
|
+
type IsEqual<T1, T2> = T1 extends T2 ? (<G>() => G extends T1 ? 1 : 2) extends <G>() => G extends T2 ? 1 : 2 ? true : false : false;
|
|
28
|
+
interface File extends Blob {
|
|
29
|
+
readonly lastModified: number;
|
|
30
|
+
readonly name: string;
|
|
31
|
+
}
|
|
32
|
+
interface FileList {
|
|
33
|
+
readonly length: number;
|
|
34
|
+
item(index: number): File | null;
|
|
35
|
+
[index: number]: File;
|
|
36
|
+
}
|
|
37
|
+
type BrowserNativeObject = Date | FileList | File;
|
|
38
|
+
type IsTuple<T extends ReadonlyArray<any>> = number extends T["length"] ? false : true;
|
|
39
|
+
type TupleKeys<T extends ReadonlyArray<any>> = Exclude<keyof T, keyof any[]>;
|
|
40
|
+
type AnyIsEqual<T1, T2> = T1 extends T2 ? (IsEqual<T1, T2> extends true ? true : never) : never;
|
|
41
|
+
type PathImpl<K extends string | number, V, TraversedTypes> = V extends Primitive | BrowserNativeObject ? `${K}` : true extends AnyIsEqual<TraversedTypes, V> ? `${K}` : `${K}` | `${K}.${PathInternal<V, TraversedTypes | V>}`;
|
|
42
|
+
type ArrayKey = number;
|
|
43
|
+
type PathInternal<T, TraversedTypes = T> = T extends ReadonlyArray<infer V> ? IsTuple<T> extends true ? {
|
|
44
|
+
[K in TupleKeys<T>]-?: PathImpl<K & string, T[K], TraversedTypes>;
|
|
45
|
+
}[TupleKeys<T>] : PathImpl<ArrayKey, V, TraversedTypes> : {
|
|
46
|
+
[K in keyof T]-?: PathImpl<K & string, T[K], TraversedTypes>;
|
|
47
|
+
}[keyof T];
|
|
48
|
+
type Path<T> = T extends any ? PathInternal<T> : never;
|
|
49
|
+
type PathType<T, K extends keyof any> = K extends `${infer Key}.${infer Rest}` ? Key extends keyof T ? Rest extends keyof any ? PathType<T[Key], Rest> : never : never : K extends keyof T ? T[K] : never;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Supported comparison operators for DynamoDB conditions.
|
|
53
|
+
* @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html AWS DynamoDB - Comparison Operator Reference}
|
|
54
|
+
*
|
|
55
|
+
* - eq: Equals (=)
|
|
56
|
+
* - ne: Not equals (≠ / <>)
|
|
57
|
+
* - lt: Less than (<)
|
|
58
|
+
* - lte: Less than or equal to (≤)
|
|
59
|
+
* - gt: Greater than (>)
|
|
60
|
+
* - gte: Greater than or equal to (≥)
|
|
61
|
+
* - between: Between two values (inclusive)
|
|
62
|
+
* - beginsWith: Checks if string attribute begins with specified substring
|
|
63
|
+
* - contains: Checks if string/set attribute contains specified value
|
|
64
|
+
* - attributeExists: Checks if attribute exists
|
|
65
|
+
* - attributeNotExists: Checks if attribute does not exist
|
|
66
|
+
*/
|
|
67
|
+
type ComparisonOperator = "eq" | "ne" | "lt" | "lte" | "gt" | "gte" | "between" | "beginsWith" | "contains" | "attributeExists" | "attributeNotExists";
|
|
68
|
+
/**
|
|
69
|
+
* Logical operators for combining multiple conditions.
|
|
70
|
+
* @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Logical AWS DynamoDB - Logical Operator Reference}
|
|
71
|
+
*
|
|
72
|
+
* - and: Evaluates to true if all conditions are true
|
|
73
|
+
* - or: Evaluates to true if any condition is true
|
|
74
|
+
* - not: Negate the result of a condition
|
|
75
|
+
*/
|
|
76
|
+
type LogicalOperator = "and" | "or" | "not";
|
|
77
|
+
/**
|
|
78
|
+
* Represents a DynamoDB condition expression.
|
|
79
|
+
* Can be either a comparison condition or a logical combination of conditions.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* // Simple comparison condition
|
|
83
|
+
* const condition: Condition = {
|
|
84
|
+
* type: "eq",
|
|
85
|
+
* attr: "status",
|
|
86
|
+
* value: "ACTIVE"
|
|
87
|
+
* };
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* // Logical combination of conditions
|
|
91
|
+
* const condition: Condition = {
|
|
92
|
+
* type: "and",
|
|
93
|
+
* conditions: [
|
|
94
|
+
* { type: "eq", attr: "status", value: "ACTIVE" },
|
|
95
|
+
* { type: "gt", attr: "age", value: 5 }
|
|
96
|
+
* ]
|
|
97
|
+
* };
|
|
98
|
+
*/
|
|
99
|
+
interface Condition {
|
|
100
|
+
/** The type of condition (comparison or logical operator) */
|
|
101
|
+
type: ComparisonOperator | LogicalOperator;
|
|
102
|
+
/** The attribute name for comparison conditions */
|
|
103
|
+
attr?: string;
|
|
104
|
+
/** The value to compare against for comparison conditions */
|
|
105
|
+
value?: unknown;
|
|
106
|
+
/** Array of conditions for logical operators (and/or) */
|
|
107
|
+
conditions?: Condition[];
|
|
108
|
+
/** Single condition for the 'not' operator */
|
|
109
|
+
condition?: Condition;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Parameters used to build DynamoDB expression strings.
|
|
113
|
+
* @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.ExpressionAttributeNames.html Expression Attribute Names}
|
|
114
|
+
* @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.ExpressionAttributeValues.html Expression Attribute Values}
|
|
115
|
+
*/
|
|
116
|
+
interface ExpressionParams {
|
|
117
|
+
/** Map of attribute name placeholders to actual attribute names */
|
|
118
|
+
expressionAttributeNames: Record<string, string>;
|
|
119
|
+
/** Map of value placeholders to actual values */
|
|
120
|
+
expressionAttributeValues: Record<string, unknown>;
|
|
121
|
+
/** Counter for generating unique value placeholders */
|
|
122
|
+
valueCounter: {
|
|
123
|
+
count: number;
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Creates a comparison condition builder function for the specified operator.
|
|
128
|
+
* @internal
|
|
129
|
+
*/
|
|
130
|
+
declare const createComparisonCondition: (type: ComparisonOperator) => (attr: string, value: unknown) => Condition;
|
|
131
|
+
/**
|
|
132
|
+
* Creates an equals (=) condition
|
|
133
|
+
* @example
|
|
134
|
+
* eq("status", "ACTIVE") // status = "ACTIVE"
|
|
135
|
+
* @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html}
|
|
136
|
+
*/
|
|
137
|
+
declare const eq: (attr: string, value: unknown) => Condition;
|
|
138
|
+
/**
|
|
139
|
+
* Creates a not equals (≠) condition
|
|
140
|
+
* @example
|
|
141
|
+
* ne("status", "DELETED") // status <> "DELETED"
|
|
142
|
+
* @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html}
|
|
143
|
+
*/
|
|
144
|
+
declare const ne: (attr: string, value: unknown) => Condition;
|
|
145
|
+
/**
|
|
146
|
+
* Creates a less than (<) condition
|
|
147
|
+
* @example
|
|
148
|
+
* lt("age", 18) // age < 18
|
|
149
|
+
* @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html}
|
|
150
|
+
*/
|
|
151
|
+
declare const lt: (attr: string, value: unknown) => Condition;
|
|
152
|
+
/**
|
|
153
|
+
* Creates a less than or equal to (≤) condition
|
|
154
|
+
* @example
|
|
155
|
+
* lte("age", 18) // age <= 18
|
|
156
|
+
* @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html}
|
|
157
|
+
*/
|
|
158
|
+
declare const lte: (attr: string, value: unknown) => Condition;
|
|
159
|
+
/**
|
|
160
|
+
* Creates a greater than (>) condition
|
|
161
|
+
* @example
|
|
162
|
+
* gt("price", 100) // price > 100
|
|
163
|
+
* @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html}
|
|
164
|
+
*/
|
|
165
|
+
declare const gt: (attr: string, value: unknown) => Condition;
|
|
166
|
+
/**
|
|
167
|
+
* Creates a greater than or equal to (≥) condition
|
|
168
|
+
* @example
|
|
169
|
+
* gte("price", 100) // price >= 100
|
|
170
|
+
* @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html}
|
|
171
|
+
*/
|
|
172
|
+
declare const gte: (attr: string, value: unknown) => Condition;
|
|
173
|
+
/**
|
|
174
|
+
* Creates a between condition that checks if a value is within a range (inclusive)
|
|
175
|
+
* @example
|
|
176
|
+
* between("age", 18, 65) // age BETWEEN 18 AND 65
|
|
177
|
+
* @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Comparators AWS DynamoDB - BETWEEN}
|
|
178
|
+
*/
|
|
179
|
+
declare const between: (attr: string, lower: unknown, upper: unknown) => Condition;
|
|
180
|
+
/**
|
|
181
|
+
* Creates a begins_with condition that checks if a string attribute starts with a substring
|
|
182
|
+
* @example
|
|
183
|
+
* beginsWith("email", "@example.com") // begins_with(email, "@example.com")
|
|
184
|
+
* @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions AWS DynamoDB - begins_with}
|
|
185
|
+
*/
|
|
186
|
+
declare const beginsWith: (attr: string, value: unknown) => Condition;
|
|
187
|
+
/**
|
|
188
|
+
* Creates a contains condition that checks if a string contains a substring or if a set contains an element
|
|
189
|
+
* @example
|
|
190
|
+
* contains("tags", "important") // contains(tags, "important")
|
|
191
|
+
* @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions AWS DynamoDB - contains}
|
|
192
|
+
*/
|
|
193
|
+
declare const contains: (attr: string, value: unknown) => Condition;
|
|
194
|
+
/**
|
|
195
|
+
* Creates a condition that checks if an attribute exists
|
|
196
|
+
* @example
|
|
197
|
+
* attributeExists("email") // attribute_exists(email)
|
|
198
|
+
* @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions AWS DynamoDB - attribute_exists}
|
|
199
|
+
*/
|
|
200
|
+
declare const attributeExists: (attr: string) => Condition;
|
|
201
|
+
/**
|
|
202
|
+
* Creates a condition that checks if an attribute does not exist
|
|
203
|
+
* @example
|
|
204
|
+
* attributeNotExists("deletedAt") // attribute_not_exists(deletedAt)
|
|
205
|
+
* @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions AWS DynamoDB - attribute_not_exists}
|
|
206
|
+
*/
|
|
207
|
+
declare const attributeNotExists: (attr: string) => Condition;
|
|
208
|
+
/**
|
|
209
|
+
* Combines multiple conditions with AND operator
|
|
210
|
+
* @example
|
|
211
|
+
* and(
|
|
212
|
+
* eq("status", "ACTIVE"),
|
|
213
|
+
* gt("age", 18)
|
|
214
|
+
* ) // status = "ACTIVE" AND age > 18
|
|
215
|
+
* @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Logical AWS DynamoDB - AND}
|
|
216
|
+
*/
|
|
217
|
+
declare const and: (...conditions: Condition[]) => Condition;
|
|
218
|
+
/**
|
|
219
|
+
* Combines multiple conditions with OR operator
|
|
220
|
+
* @example
|
|
221
|
+
* or(
|
|
222
|
+
* eq("status", "PENDING"),
|
|
223
|
+
* eq("status", "PROCESSING")
|
|
224
|
+
* ) // status = "PENDING" OR status = "PROCESSING"
|
|
225
|
+
* @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Logical AWS DynamoDB - OR}
|
|
226
|
+
*/
|
|
227
|
+
declare const or: (...conditions: Condition[]) => Condition;
|
|
228
|
+
/**
|
|
229
|
+
* Negates a condition
|
|
230
|
+
* @example
|
|
231
|
+
* not(eq("status", "DELETED")) // NOT status = "DELETED"
|
|
232
|
+
* @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Logical AWS DynamoDB - NOT}
|
|
233
|
+
*/
|
|
234
|
+
declare const not: (condition: Condition) => Condition;
|
|
235
|
+
/**
|
|
236
|
+
* Type-safe operators for building key conditions in DynamoDB queries.
|
|
237
|
+
* Only includes operators that are valid for key conditions.
|
|
238
|
+
* @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Query.html#Query.KeyConditionExpressions AWS DynamoDB - Key Condition Expressions}
|
|
239
|
+
*
|
|
240
|
+
* @example
|
|
241
|
+
* // Using with sort key conditions
|
|
242
|
+
* table.query({
|
|
243
|
+
* pk: "USER#123",
|
|
244
|
+
* sk: op => op.beginsWith("ORDER#")
|
|
245
|
+
* })
|
|
246
|
+
*/
|
|
247
|
+
type KeyConditionOperator = {
|
|
248
|
+
/** Equals comparison for key attributes */
|
|
249
|
+
eq: (value: unknown) => Condition;
|
|
250
|
+
/** Less than comparison for key attributes */
|
|
251
|
+
lt: (value: unknown) => Condition;
|
|
252
|
+
/** Less than or equal comparison for key attributes */
|
|
253
|
+
lte: (value: unknown) => Condition;
|
|
254
|
+
/** Greater than comparison for key attributes */
|
|
255
|
+
gt: (value: unknown) => Condition;
|
|
256
|
+
/** Greater than or equal comparison for key attributes */
|
|
257
|
+
gte: (value: unknown) => Condition;
|
|
258
|
+
/** Between range comparison for key attributes */
|
|
259
|
+
between: (lower: unknown, upper: unknown) => Condition;
|
|
260
|
+
/** Begins with comparison for key attributes */
|
|
261
|
+
beginsWith: (value: unknown) => Condition;
|
|
262
|
+
/** Combines multiple key conditions with AND */
|
|
263
|
+
and: (...conditions: Condition[]) => Condition;
|
|
264
|
+
};
|
|
265
|
+
/**
|
|
266
|
+
* Type-safe operators for building conditions in DynamoDB operations.
|
|
267
|
+
* Includes all available condition operators with proper type inference.
|
|
268
|
+
* @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html AWS DynamoDB - Condition Expressions}
|
|
269
|
+
*
|
|
270
|
+
* @example
|
|
271
|
+
* // Using with type-safe conditions
|
|
272
|
+
* interface User {
|
|
273
|
+
* status: string;
|
|
274
|
+
* age: number;
|
|
275
|
+
* email?: string;
|
|
276
|
+
* }
|
|
277
|
+
*
|
|
278
|
+
* table.scan<User>()
|
|
279
|
+
* .where(op => op.and(
|
|
280
|
+
* op.eq("status", "ACTIVE"),
|
|
281
|
+
* op.gt("age", 18),
|
|
282
|
+
* op.attributeExists("email")
|
|
283
|
+
* ))
|
|
284
|
+
*
|
|
285
|
+
* @template T The type of the item being operated on
|
|
286
|
+
*/
|
|
287
|
+
type ConditionOperator<T extends Record<string, unknown>> = {
|
|
288
|
+
eq: <K extends Path<T>>(attr: K, value: PathType<T, K>) => Condition;
|
|
289
|
+
ne: <K extends Path<T>>(attr: K, value: PathType<T, K>) => Condition;
|
|
290
|
+
lt: <K extends Path<T>>(attr: K, value: PathType<T, K>) => Condition;
|
|
291
|
+
lte: <K extends Path<T>>(attr: K, value: PathType<T, K>) => Condition;
|
|
292
|
+
gt: <K extends Path<T>>(attr: K, value: PathType<T, K>) => Condition;
|
|
293
|
+
gte: <K extends Path<T>>(attr: K, value: PathType<T, K>) => Condition;
|
|
294
|
+
between: <K extends Path<T>>(attr: K, lower: PathType<T, K>, upper: PathType<T, K>) => Condition;
|
|
295
|
+
beginsWith: <K extends Path<T>>(attr: K, value: PathType<T, K>) => Condition;
|
|
296
|
+
contains: <K extends Path<T>>(attr: K, value: PathType<T, K>) => Condition;
|
|
297
|
+
attributeExists: <K extends Path<T>>(attr: K) => Condition;
|
|
298
|
+
attributeNotExists: <K extends Path<T>>(attr: K) => Condition;
|
|
299
|
+
and: (...conditions: Condition[]) => Condition;
|
|
300
|
+
or: (...conditions: Condition[]) => Condition;
|
|
301
|
+
not: (condition: Condition) => Condition;
|
|
302
|
+
};
|
|
303
|
+
/**
|
|
304
|
+
* Primary key type for QUERY operations.
|
|
305
|
+
* Allows building complex key conditions for the sort key.
|
|
306
|
+
* @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Query.html AWS DynamoDB - Query Operations}
|
|
307
|
+
*
|
|
308
|
+
* @example
|
|
309
|
+
* // Query items with a specific partition key and sort key prefix
|
|
310
|
+
* table.query({
|
|
311
|
+
* pk: "USER#123",
|
|
312
|
+
* sk: op => op.beginsWith("ORDER#2023")
|
|
313
|
+
* })
|
|
314
|
+
*
|
|
315
|
+
* @example
|
|
316
|
+
* // Query items within a specific sort key range
|
|
317
|
+
* table.query({
|
|
318
|
+
* pk: "USER#123",
|
|
319
|
+
* sk: op => op.between("ORDER#2023-01", "ORDER#2023-12")
|
|
320
|
+
* })
|
|
321
|
+
*/
|
|
322
|
+
type PrimaryKey = {
|
|
323
|
+
/** Partition key value */
|
|
324
|
+
pk: string;
|
|
325
|
+
/** Optional sort key condition builder */
|
|
326
|
+
sk?: (op: KeyConditionOperator) => Condition;
|
|
327
|
+
};
|
|
328
|
+
/**
|
|
329
|
+
* Primary key type for GET and DELETE operations.
|
|
330
|
+
* Used when you need to specify exact key values without conditions.
|
|
331
|
+
* @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/WorkingWithItems.html AWS DynamoDB - Working with Items}
|
|
332
|
+
*
|
|
333
|
+
* @example
|
|
334
|
+
* // Get a specific item by its complete primary key
|
|
335
|
+
* table.get({
|
|
336
|
+
* pk: "USER#123",
|
|
337
|
+
* sk: "PROFILE#123"
|
|
338
|
+
* })
|
|
339
|
+
*
|
|
340
|
+
* @example
|
|
341
|
+
* // Delete a specific item by its complete primary key
|
|
342
|
+
* table.delete({
|
|
343
|
+
* pk: "USER#123",
|
|
344
|
+
* sk: "ORDER#456"
|
|
345
|
+
* })
|
|
346
|
+
*/
|
|
347
|
+
type PrimaryKeyWithoutExpression = {
|
|
348
|
+
/** Partition key value */
|
|
349
|
+
pk: string;
|
|
350
|
+
/** Optional sort key value */
|
|
351
|
+
sk?: string;
|
|
352
|
+
};
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Interface for DynamoDB command objects that can contain expressions
|
|
356
|
+
*/
|
|
357
|
+
interface DynamoCommandWithExpressions {
|
|
358
|
+
conditionExpression?: string;
|
|
359
|
+
updateExpression?: string;
|
|
360
|
+
filterExpression?: string;
|
|
361
|
+
keyConditionExpression?: string;
|
|
362
|
+
projectionExpression?: string;
|
|
363
|
+
expressionAttributeNames?: Record<string, string>;
|
|
364
|
+
expressionAttributeValues?: Record<string, unknown>;
|
|
365
|
+
[key: string]: unknown;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
interface DeleteCommandParams extends DynamoCommandWithExpressions {
|
|
369
|
+
tableName: string;
|
|
370
|
+
key: PrimaryKeyWithoutExpression;
|
|
371
|
+
conditionExpression?: string;
|
|
372
|
+
expressionAttributeNames?: Record<string, string>;
|
|
373
|
+
expressionAttributeValues?: Record<string, unknown>;
|
|
374
|
+
returnValues?: "ALL_OLD";
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Parameters for the DynamoDB put command.
|
|
378
|
+
*
|
|
379
|
+
* These parameters are used when executing the operation against DynamoDB.
|
|
380
|
+
*
|
|
381
|
+
* The `returnValues` property can be:
|
|
382
|
+
* - `"ALL_OLD"`: Return the attributes of the item as they were before the operation
|
|
383
|
+
* - `"NONE"`: Return nothing
|
|
384
|
+
* - `"CONSISTENT"`: Triggers a GET operation after the put to retrieve the updated item state
|
|
385
|
+
*/
|
|
386
|
+
interface PutCommandParams extends DynamoCommandWithExpressions {
|
|
387
|
+
tableName: string;
|
|
388
|
+
item: Record<string, unknown>;
|
|
389
|
+
conditionExpression?: string;
|
|
390
|
+
expressionAttributeNames?: Record<string, string>;
|
|
391
|
+
expressionAttributeValues?: Record<string, unknown>;
|
|
392
|
+
returnValues?: "ALL_OLD" | "NONE" | "CONSISTENT";
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* Parameters for the DynamoDB update command.
|
|
396
|
+
* These parameters are used when executing the operation against DynamoDB.
|
|
397
|
+
*/
|
|
398
|
+
interface UpdateCommandParams extends DynamoCommandWithExpressions {
|
|
399
|
+
/** The name of the DynamoDB table */
|
|
400
|
+
tableName: string;
|
|
401
|
+
/** The primary key of the item to update */
|
|
402
|
+
key: PrimaryKeyWithoutExpression;
|
|
403
|
+
/** The update expression (SET, REMOVE, ADD, DELETE clauses) */
|
|
404
|
+
updateExpression: string;
|
|
405
|
+
/** Optional condition expression that must be satisfied */
|
|
406
|
+
conditionExpression?: string;
|
|
407
|
+
/** Map of expression attribute name placeholders to actual names */
|
|
408
|
+
expressionAttributeNames?: Record<string, string>;
|
|
409
|
+
/** Map of expression attribute value placeholders to actual values */
|
|
410
|
+
expressionAttributeValues?: Record<string, unknown>;
|
|
411
|
+
/** Which item attributes to include in the response */
|
|
412
|
+
returnValues?: "ALL_NEW" | "UPDATED_NEW" | "ALL_OLD" | "UPDATED_OLD" | "NONE";
|
|
413
|
+
}
|
|
414
|
+
interface ConditionCheckCommandParams extends DynamoCommandWithExpressions {
|
|
415
|
+
tableName: string;
|
|
416
|
+
key: PrimaryKeyWithoutExpression;
|
|
417
|
+
conditionExpression: string;
|
|
418
|
+
expressionAttributeNames?: Record<string, string>;
|
|
419
|
+
expressionAttributeValues?: Record<string, unknown>;
|
|
420
|
+
}
|
|
421
|
+
/**
|
|
422
|
+
* Base interface for all builder classes that support pagination
|
|
423
|
+
* to be used by Paginator without creating circular dependencies.
|
|
424
|
+
*/
|
|
425
|
+
interface BaseBuilderInterface<T extends Record<string, unknown>, TConfig extends TableConfig = TableConfig, B = unknown> {
|
|
426
|
+
clone(): B;
|
|
427
|
+
limit(limit: number): B;
|
|
428
|
+
getLimit(): number | undefined;
|
|
429
|
+
startFrom(lastEvaluatedKey: Record<string, unknown>): B;
|
|
430
|
+
execute(): Promise<{
|
|
431
|
+
items: T[];
|
|
432
|
+
lastEvaluatedKey?: Record<string, unknown>;
|
|
433
|
+
}>;
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* Interface for the QueryBuilder class to be used by Paginator
|
|
437
|
+
* without creating a circular dependency.
|
|
438
|
+
*/
|
|
439
|
+
interface QueryBuilderInterface<T extends Record<string, unknown>, TConfig extends TableConfig = TableConfig> extends BaseBuilderInterface<T, TConfig, QueryBuilderInterface<T, TConfig>> {
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Interface for the ScanBuilder class to be used by Paginator
|
|
443
|
+
* without creating a circular dependency.
|
|
444
|
+
*/
|
|
445
|
+
interface ScanBuilderInterface<T extends Record<string, unknown>, TConfig extends TableConfig = TableConfig> extends BaseBuilderInterface<T, TConfig, ScanBuilderInterface<T, TConfig>> {
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* Interface for the FilterBuilder class to be used by Paginator
|
|
449
|
+
* without creating a circular dependency.
|
|
450
|
+
*/
|
|
451
|
+
interface FilterBuilderInterface<T extends Record<string, unknown>, TConfig extends TableConfig = TableConfig> extends BaseBuilderInterface<T, TConfig, FilterBuilderInterface<T, TConfig>> {
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* Represents the result of a single page query operation.
|
|
455
|
+
* This interface provides all necessary information about the current page
|
|
456
|
+
* and the availability of subsequent pages.
|
|
457
|
+
*/
|
|
458
|
+
interface PaginationResult<T> {
|
|
459
|
+
/** The items (dinosaurs, habitats, etc.) retrieved for the current page */
|
|
460
|
+
items: T[];
|
|
461
|
+
/** DynamoDB's last evaluated key, used internally for pagination */
|
|
462
|
+
lastEvaluatedKey?: Record<string, unknown>;
|
|
463
|
+
/** Indicates whether there are more pages available */
|
|
464
|
+
hasNextPage: boolean;
|
|
465
|
+
/** The current page number (1-indexed) */
|
|
466
|
+
page: number;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
/**
|
|
470
|
+
* A utility class for handling DynamoDB pagination.
|
|
471
|
+
* Use this class when you need to:
|
|
472
|
+
* - Browse large collections of dinosaurs
|
|
473
|
+
* - Review extensive security logs
|
|
474
|
+
* - Analyze habitat inspection history
|
|
475
|
+
* - Process feeding schedules
|
|
476
|
+
*
|
|
477
|
+
* The paginator maintains internal state and automatically handles:
|
|
478
|
+
* - Page boundaries
|
|
479
|
+
* - Result set limits
|
|
480
|
+
* - Continuation tokens
|
|
481
|
+
*
|
|
482
|
+
* @example
|
|
483
|
+
* ```typescript
|
|
484
|
+
* // List all velociraptors with pagination
|
|
485
|
+
* const paginator = new QueryBuilder(executor, eq('species', 'Velociraptor'))
|
|
486
|
+
* .filter(op => op.eq('status', 'ACTIVE'))
|
|
487
|
+
* .paginate(10);
|
|
488
|
+
*
|
|
489
|
+
* // Process each page of dinosaurs
|
|
490
|
+
* while (paginator.hasNextPage()) {
|
|
491
|
+
* const page = await paginator.getNextPage();
|
|
492
|
+
* console.log(`Processing page ${page.page} of velociraptors`);
|
|
493
|
+
*
|
|
494
|
+
* for (const raptor of page.items) {
|
|
495
|
+
* console.log(`- ${raptor.id}: Health=${raptor.stats.health}`);
|
|
496
|
+
* }
|
|
497
|
+
* }
|
|
498
|
+
* ```
|
|
499
|
+
*
|
|
500
|
+
* @typeParam T - The type of items being paginated
|
|
501
|
+
* @typeParam TConfig - The table configuration type
|
|
502
|
+
*/
|
|
503
|
+
declare class Paginator<T extends Record<string, unknown>, TConfig extends TableConfig = TableConfig> {
|
|
504
|
+
private queryBuilder;
|
|
505
|
+
private readonly pageSize;
|
|
506
|
+
private currentPage;
|
|
507
|
+
private lastEvaluatedKey?;
|
|
508
|
+
private hasMorePages;
|
|
509
|
+
private totalItemsRetrieved;
|
|
510
|
+
private readonly overallLimit?;
|
|
511
|
+
constructor(queryBuilder: QueryBuilderInterface<T, TConfig>, pageSize: number);
|
|
512
|
+
/**
|
|
513
|
+
* Gets the current page number (1-indexed).
|
|
514
|
+
* Use this method when you need to:
|
|
515
|
+
* - Track progress through dinosaur lists
|
|
516
|
+
* - Display habitat inspection status
|
|
517
|
+
* - Monitor security sweep progress
|
|
518
|
+
*
|
|
519
|
+
* @example
|
|
520
|
+
* ```ts
|
|
521
|
+
* const paginator = new QueryBuilder(executor, eq('species', 'Tyrannosaurus'))
|
|
522
|
+
* .paginate(5);
|
|
523
|
+
*
|
|
524
|
+
* await paginator.getNextPage();
|
|
525
|
+
* console.log(`Reviewing T-Rex group ${paginator.getCurrentPage()}`);
|
|
526
|
+
* ```
|
|
527
|
+
*
|
|
528
|
+
* @returns The current page number, starting from 1
|
|
529
|
+
*/
|
|
530
|
+
getCurrentPage(): number;
|
|
531
|
+
/**
|
|
532
|
+
* Checks if there are more pages of dinosaurs or habitats to process.
|
|
533
|
+
* Use this method when you need to:
|
|
534
|
+
* - Check for more dinosaurs to review
|
|
535
|
+
* - Continue habitat inspections
|
|
536
|
+
* - Process security incidents
|
|
537
|
+
* - Complete feeding schedules
|
|
538
|
+
*
|
|
539
|
+
* This method takes into account both:
|
|
540
|
+
* - DynamoDB's lastEvaluatedKey mechanism
|
|
541
|
+
* - Any overall limit set on the query
|
|
542
|
+
*
|
|
543
|
+
* @example
|
|
544
|
+
* ```ts
|
|
545
|
+
* // Process all security incidents
|
|
546
|
+
* const paginator = new QueryBuilder(executor, eq('type', 'SECURITY_BREACH'))
|
|
547
|
+
* .sortDescending()
|
|
548
|
+
* .paginate(10);
|
|
549
|
+
*
|
|
550
|
+
* while (paginator.hasNextPage()) {
|
|
551
|
+
* const page = await paginator.getNextPage();
|
|
552
|
+
* for (const incident of page.items) {
|
|
553
|
+
* await processSecurityBreach(incident);
|
|
554
|
+
* }
|
|
555
|
+
* console.log(`Processed incidents page ${page.page}`);
|
|
556
|
+
* }
|
|
557
|
+
* ```
|
|
558
|
+
*
|
|
559
|
+
* @returns true if there are more pages available, false otherwise
|
|
560
|
+
*/
|
|
561
|
+
hasNextPage(): boolean;
|
|
562
|
+
/**
|
|
563
|
+
* Retrieves the next page of dinosaurs or habitats from DynamoDB.
|
|
564
|
+
* Use this method when you need to:
|
|
565
|
+
* - Process dinosaur groups systematically
|
|
566
|
+
* - Review habitat inspections in batches
|
|
567
|
+
* - Monitor security incidents in sequence
|
|
568
|
+
* - Schedule feeding rotations
|
|
569
|
+
*
|
|
570
|
+
* This method handles:
|
|
571
|
+
* - Automatic continuation between groups
|
|
572
|
+
* - Respect for park capacity limits
|
|
573
|
+
* - Group size adjustments for safety
|
|
574
|
+
*
|
|
575
|
+
* @example
|
|
576
|
+
* ```ts
|
|
577
|
+
* const paginator = new QueryBuilder(executor, eq('species', 'Velociraptor'))
|
|
578
|
+
* .filter(op => op.eq('status', 'ACTIVE'))
|
|
579
|
+
* .paginate(5);
|
|
580
|
+
*
|
|
581
|
+
* // Check first raptor group
|
|
582
|
+
* const page1 = await paginator.getNextPage();
|
|
583
|
+
* console.log(`Found ${page1.items.length} active raptors`);
|
|
584
|
+
*
|
|
585
|
+
* // Continue inspection if more groups exist
|
|
586
|
+
* if (page1.hasNextPage) {
|
|
587
|
+
* const page2 = await paginator.getNextPage();
|
|
588
|
+
* console.log(`Inspecting raptor group ${page2.page}`);
|
|
589
|
+
*
|
|
590
|
+
* for (const raptor of page2.items) {
|
|
591
|
+
* await performHealthCheck(raptor);
|
|
592
|
+
* }
|
|
593
|
+
* }
|
|
594
|
+
* ```
|
|
595
|
+
*
|
|
596
|
+
* @returns A promise that resolves to a PaginationResult containing:
|
|
597
|
+
* - items: The dinosaurs/habitats for this page
|
|
598
|
+
* - hasNextPage: Whether more groups exist
|
|
599
|
+
* - page: The current group number
|
|
600
|
+
* - lastEvaluatedKey: DynamoDB's continuation token
|
|
601
|
+
*/
|
|
602
|
+
getNextPage(): Promise<PaginationResult<T>>;
|
|
603
|
+
/**
|
|
604
|
+
* Gets all remaining dinosaurs or habitats and combines them into a single array.
|
|
605
|
+
* Use this method when you need to:
|
|
606
|
+
* - Generate complete park inventory
|
|
607
|
+
* - Perform full security audit
|
|
608
|
+
* - Create comprehensive feeding schedule
|
|
609
|
+
* - Run park-wide health checks
|
|
610
|
+
*
|
|
611
|
+
* Note: Use with caution! This method:
|
|
612
|
+
* - Could overwhelm systems with large dinosaur populations
|
|
613
|
+
* - Makes multiple database requests
|
|
614
|
+
* - May cause system strain during peak hours
|
|
615
|
+
*
|
|
616
|
+
* @example
|
|
617
|
+
* ```ts
|
|
618
|
+
* // Get complete carnivore inventory
|
|
619
|
+
* const paginator = new QueryBuilder(executor, eq('diet', 'CARNIVORE'))
|
|
620
|
+
* .filter(op => op.eq('status', 'ACTIVE'))
|
|
621
|
+
* .paginate(10);
|
|
622
|
+
*
|
|
623
|
+
* try {
|
|
624
|
+
* const allCarnivores = await paginator.getAllPages();
|
|
625
|
+
* console.log(`Park contains ${allCarnivores.length} active carnivores`);
|
|
626
|
+
*
|
|
627
|
+
* // Calculate total threat level
|
|
628
|
+
* const totalThreat = allCarnivores.reduce(
|
|
629
|
+
* (sum, dino) => sum + dino.stats.threatLevel,
|
|
630
|
+
* 0
|
|
631
|
+
* );
|
|
632
|
+
* console.log(`Total threat level: ${totalThreat}`);
|
|
633
|
+
* } catch (error) {
|
|
634
|
+
* console.error('Failed to complete carnivore census:', error);
|
|
635
|
+
* }
|
|
636
|
+
* ```
|
|
637
|
+
*
|
|
638
|
+
* @returns A promise that resolves to an array containing all remaining items
|
|
639
|
+
*/
|
|
640
|
+
getAllPages(): Promise<T[]>;
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
/**
|
|
644
|
+
* Configuration options for DynamoDB filter operations.
|
|
645
|
+
* These are common options shared between query and scan operations.
|
|
646
|
+
*/
|
|
647
|
+
interface FilterOptions {
|
|
648
|
+
/** Filter conditions applied to results */
|
|
649
|
+
filter?: Condition;
|
|
650
|
+
/** Maximum number of items to return */
|
|
651
|
+
limit?: number;
|
|
652
|
+
/** Name of the Global Secondary Index to use */
|
|
653
|
+
indexName?: string;
|
|
654
|
+
/** Whether to use strongly consistent reads */
|
|
655
|
+
consistentRead?: boolean;
|
|
656
|
+
/** List of attributes to return in the result */
|
|
657
|
+
projection?: string[];
|
|
658
|
+
/** Token for starting the operation from a specific point */
|
|
659
|
+
lastEvaluatedKey?: Record<string, unknown>;
|
|
660
|
+
}
|
|
661
|
+
/**
|
|
662
|
+
* Abstract base builder for creating DynamoDB filter operations.
|
|
663
|
+
* This class provides common functionality for both Query and Scan operations.
|
|
664
|
+
*
|
|
665
|
+
* The builder supports:
|
|
666
|
+
* - Type-safe GSI selection
|
|
667
|
+
* - Complex filter conditions
|
|
668
|
+
* - Pagination
|
|
669
|
+
* - Consistent reads
|
|
670
|
+
* - Attribute projection
|
|
671
|
+
*
|
|
672
|
+
* @typeParam T - The type of items being filtered
|
|
673
|
+
* @typeParam TConfig - The table configuration type for type-safe GSI selection
|
|
674
|
+
*/
|
|
675
|
+
declare abstract class FilterBuilder<T extends Record<string, unknown>, TConfig extends TableConfig = TableConfig> implements FilterBuilderInterface<T, TConfig> {
|
|
676
|
+
protected options: FilterOptions;
|
|
677
|
+
protected selectedFields: Set<string>;
|
|
678
|
+
/**
|
|
679
|
+
* Sets the maximum number of items to return.
|
|
680
|
+
* Use this method when you need to:
|
|
681
|
+
* - Limit the number of dinosaurs returned
|
|
682
|
+
* - Control the size of habitat reports
|
|
683
|
+
* - Implement manual pagination of security logs
|
|
684
|
+
*
|
|
685
|
+
* Note: This limit applies to the items that match the key condition
|
|
686
|
+
* before any filter expressions are applied.
|
|
687
|
+
*
|
|
688
|
+
* @example
|
|
689
|
+
* ```typescript
|
|
690
|
+
* // Get first 10 dinosaurs
|
|
691
|
+
* const result = await builder
|
|
692
|
+
* .limit(10)
|
|
693
|
+
* .execute();
|
|
694
|
+
* ```
|
|
695
|
+
*
|
|
696
|
+
* @param limit - Maximum number of items to return
|
|
697
|
+
* @returns The builder instance for method chaining
|
|
698
|
+
*/
|
|
699
|
+
limit(limit: number): this;
|
|
700
|
+
/**
|
|
701
|
+
* Gets the current limit set on the operation.
|
|
702
|
+
* This is used internally by the paginator to manage result sets.
|
|
703
|
+
*
|
|
704
|
+
* @returns The current limit or undefined if no limit is set
|
|
705
|
+
*/
|
|
706
|
+
getLimit(): number | undefined;
|
|
707
|
+
/**
|
|
708
|
+
* Specifies a Global Secondary Index (GSI) to use for the operation.
|
|
709
|
+
* Use this method when you need to:
|
|
710
|
+
* - Find dinosaurs by species or status
|
|
711
|
+
* - Search habitats by security level
|
|
712
|
+
* - Find incidents by date
|
|
713
|
+
* - List feeding schedules by time
|
|
714
|
+
*
|
|
715
|
+
* @example
|
|
716
|
+
* ```typescript
|
|
717
|
+
* // Find all dinosaurs of a specific species
|
|
718
|
+
* builder
|
|
719
|
+
* .useIndex('species-status-index')
|
|
720
|
+
* .filter(op => op.eq('status', 'ACTIVE'));
|
|
721
|
+
*
|
|
722
|
+
* // Search high-security habitats
|
|
723
|
+
* builder
|
|
724
|
+
* .useIndex('security-level-index')
|
|
725
|
+
* .filter(op =>
|
|
726
|
+
* op.and([
|
|
727
|
+
* op.gt('securityLevel', 8),
|
|
728
|
+
* op.eq('status', 'OPERATIONAL')
|
|
729
|
+
* ])
|
|
730
|
+
* );
|
|
731
|
+
* ```
|
|
732
|
+
*
|
|
733
|
+
* @param indexName - The name of the GSI to use (type-safe based on table configuration)
|
|
734
|
+
* @returns The builder instance for method chaining
|
|
735
|
+
*/
|
|
736
|
+
useIndex<I extends GSINames<TConfig>>(indexName: I): this;
|
|
737
|
+
/**
|
|
738
|
+
* Sets whether to use strongly consistent reads for the operation.
|
|
739
|
+
* Use this method when you need to:
|
|
740
|
+
* - Get real-time dinosaur status updates
|
|
741
|
+
* - Monitor critical security systems
|
|
742
|
+
* - Track immediate habitat changes
|
|
743
|
+
* - Verify containment protocols
|
|
744
|
+
*
|
|
745
|
+
* Note:
|
|
746
|
+
* - Consistent reads are not available on GSIs
|
|
747
|
+
* - Consistent reads consume twice the throughput
|
|
748
|
+
* - Default is eventually consistent reads
|
|
749
|
+
*
|
|
750
|
+
* @example
|
|
751
|
+
* ```typescript
|
|
752
|
+
* // Check immediate dinosaur status
|
|
753
|
+
* const result = await builder
|
|
754
|
+
* .filter(op => op.eq('status', 'ACTIVE'))
|
|
755
|
+
* .consistentRead()
|
|
756
|
+
* .execute();
|
|
757
|
+
*
|
|
758
|
+
* // Monitor security breaches
|
|
759
|
+
* const result = await builder
|
|
760
|
+
* .useIndex('primary-index')
|
|
761
|
+
* .consistentRead(isEmergencyMode)
|
|
762
|
+
* .execute();
|
|
763
|
+
* ```
|
|
764
|
+
*
|
|
765
|
+
* @param consistentRead - Whether to use consistent reads (defaults to true)
|
|
766
|
+
* @returns The builder instance for method chaining
|
|
767
|
+
*/
|
|
768
|
+
consistentRead(consistentRead?: boolean): this;
|
|
769
|
+
/**
|
|
770
|
+
* Adds a filter expression to refine the operation results.
|
|
771
|
+
* Use this method when you need to:
|
|
772
|
+
* - Filter dinosaurs by behavior patterns
|
|
773
|
+
* - Find habitats with specific conditions
|
|
774
|
+
* - Search for security incidents
|
|
775
|
+
* - Monitor feeding patterns
|
|
776
|
+
*
|
|
777
|
+
* @example
|
|
778
|
+
* ```typescript
|
|
779
|
+
* // Find aggressive carnivores
|
|
780
|
+
* builder.filter(op =>
|
|
781
|
+
* op.and([
|
|
782
|
+
* op.eq('diet', 'CARNIVORE'),
|
|
783
|
+
* op.gt('aggressionLevel', 7),
|
|
784
|
+
* op.eq('status', 'ACTIVE')
|
|
785
|
+
* ])
|
|
786
|
+
* );
|
|
787
|
+
*
|
|
788
|
+
* // Search suitable breeding habitats
|
|
789
|
+
* builder.filter(op =>
|
|
790
|
+
* op.and([
|
|
791
|
+
* op.between('temperature', 25, 30),
|
|
792
|
+
* op.lt('currentOccupants', 3),
|
|
793
|
+
* op.eq('quarantineStatus', 'CLEAR')
|
|
794
|
+
* ])
|
|
795
|
+
* );
|
|
796
|
+
* ```
|
|
797
|
+
*
|
|
798
|
+
* @param condition - Either a Condition object or a callback function that builds the condition
|
|
799
|
+
* @returns The builder instance for method chaining
|
|
800
|
+
*/
|
|
801
|
+
filter(condition: Condition | ((op: ConditionOperator<T>) => Condition)): this;
|
|
802
|
+
/**
|
|
803
|
+
* Specifies which attributes to return in the results.
|
|
804
|
+
* Use this method when you need to:
|
|
805
|
+
* - Get specific dinosaur attributes
|
|
806
|
+
* - Retrieve habitat statistics
|
|
807
|
+
* - Monitor security metrics
|
|
808
|
+
* - Optimize response size
|
|
809
|
+
*
|
|
810
|
+
* @example
|
|
811
|
+
* ```typescript
|
|
812
|
+
* // Get basic dinosaur info
|
|
813
|
+
* builder.select([
|
|
814
|
+
* 'species',
|
|
815
|
+
* 'status',
|
|
816
|
+
* 'stats.health',
|
|
817
|
+
* 'stats.aggressionLevel'
|
|
818
|
+
* ]);
|
|
819
|
+
*
|
|
820
|
+
* // Monitor habitat conditions
|
|
821
|
+
* builder
|
|
822
|
+
* .select('securityStatus')
|
|
823
|
+
* .select([
|
|
824
|
+
* 'currentOccupants',
|
|
825
|
+
* 'temperature',
|
|
826
|
+
* 'lastInspectionDate'
|
|
827
|
+
* ]);
|
|
828
|
+
* ```
|
|
829
|
+
*
|
|
830
|
+
* @param fields - A single field name or an array of field names to return
|
|
831
|
+
* @returns The builder instance for method chaining
|
|
832
|
+
*/
|
|
833
|
+
select(fields: string | string[]): this;
|
|
834
|
+
/**
|
|
835
|
+
* Creates a paginator that handles DynamoDB pagination automatically.
|
|
836
|
+
* The paginator handles:
|
|
837
|
+
* - Tracking the last evaluated key
|
|
838
|
+
* - Managing page boundaries
|
|
839
|
+
* - Respecting overall query limits
|
|
840
|
+
*
|
|
841
|
+
* @example
|
|
842
|
+
* ```typescript
|
|
843
|
+
* // Create a paginator for dinosaur records
|
|
844
|
+
* const paginator = builder
|
|
845
|
+
* .filter(op => op.eq('status', 'ACTIVE'))
|
|
846
|
+
* .paginate(10);
|
|
847
|
+
*
|
|
848
|
+
* // Process pages of dinosaur results
|
|
849
|
+
* while (paginator.hasNextPage()) {
|
|
850
|
+
* const page = await paginator.getNextPage();
|
|
851
|
+
* console.log(`Processing page ${page.page}, count: ${page.items.length}`);
|
|
852
|
+
* // Process dinosaur data
|
|
853
|
+
* }
|
|
854
|
+
* ```
|
|
855
|
+
*
|
|
856
|
+
* @param pageSize - The number of items to return per page
|
|
857
|
+
* @returns A Paginator instance that manages the pagination state
|
|
858
|
+
* @see Paginator for more pagination control options
|
|
859
|
+
*/
|
|
860
|
+
paginate(pageSize: number): Paginator<T, TConfig>;
|
|
861
|
+
/**
|
|
862
|
+
* Sets the starting point using a previous lastEvaluatedKey.
|
|
863
|
+
* Use this method when you need to:
|
|
864
|
+
* - Implement manual dinosaur list pagination
|
|
865
|
+
* - Resume habitat inspection reviews
|
|
866
|
+
* - Continue security incident analysis
|
|
867
|
+
* - Store operation position between sessions
|
|
868
|
+
*
|
|
869
|
+
* Note: This method is typically used for manual pagination.
|
|
870
|
+
* For automatic pagination, use the paginate() method instead.
|
|
871
|
+
*
|
|
872
|
+
* @example
|
|
873
|
+
* ```typescript
|
|
874
|
+
* // First batch of dinosaurs
|
|
875
|
+
* const result1 = await builder
|
|
876
|
+
* .filter(op => op.eq('status', 'ACTIVE'))
|
|
877
|
+
* .limit(5)
|
|
878
|
+
* .execute();
|
|
879
|
+
*
|
|
880
|
+
* if (result1.lastEvaluatedKey) {
|
|
881
|
+
* // Continue listing dinosaurs
|
|
882
|
+
* const result2 = await builder
|
|
883
|
+
* .filter(op => op.eq('status', 'ACTIVE'))
|
|
884
|
+
* .startFrom(result1.lastEvaluatedKey)
|
|
885
|
+
* .limit(5)
|
|
886
|
+
* .execute();
|
|
887
|
+
*
|
|
888
|
+
* console.log('Additional dinosaurs:', result2.items);
|
|
889
|
+
* }
|
|
890
|
+
* ```
|
|
891
|
+
*
|
|
892
|
+
* @param lastEvaluatedKey - The exclusive start key from a previous result
|
|
893
|
+
* @returns The builder instance for method chaining
|
|
894
|
+
*/
|
|
895
|
+
startFrom(lastEvaluatedKey: Record<string, unknown>): this;
|
|
896
|
+
/**
|
|
897
|
+
* Creates a deep clone of this builder instance.
|
|
898
|
+
* Use this method when you need to:
|
|
899
|
+
* - Query different dinosaur statuses
|
|
900
|
+
* - Check multiple habitat conditions
|
|
901
|
+
* - Monitor various security levels
|
|
902
|
+
* - Create report templates
|
|
903
|
+
*
|
|
904
|
+
* This is particularly useful when:
|
|
905
|
+
* - Implementing pagination (used internally by paginate())
|
|
906
|
+
* - Creating operation templates
|
|
907
|
+
* - Running multiple variations of an operation
|
|
908
|
+
*
|
|
909
|
+
* @example
|
|
910
|
+
* ```typescript
|
|
911
|
+
* // Create base dinosaur query
|
|
912
|
+
* const baseBuilder = builder
|
|
913
|
+
* .useIndex('status-index')
|
|
914
|
+
* .select(['id', 'status', 'location']);
|
|
915
|
+
*
|
|
916
|
+
* // Check active dinosaurs
|
|
917
|
+
* const activeRaptors = baseBuilder.clone()
|
|
918
|
+
* .filter(op => op.eq('status', 'HUNTING'))
|
|
919
|
+
* .execute();
|
|
920
|
+
*
|
|
921
|
+
* // Check contained dinosaurs
|
|
922
|
+
* const containedRaptors = baseBuilder.clone()
|
|
923
|
+
* .filter(op => op.eq('status', 'CONTAINED'))
|
|
924
|
+
* .execute();
|
|
925
|
+
* ```
|
|
926
|
+
*
|
|
927
|
+
* @returns A new builder instance with the same configuration
|
|
928
|
+
*/
|
|
929
|
+
abstract clone(): FilterBuilderInterface<T, TConfig>;
|
|
930
|
+
/**
|
|
931
|
+
* Executes the operation against DynamoDB.
|
|
932
|
+
* This method must be implemented by subclasses to handle
|
|
933
|
+
* their specific execution logic.
|
|
934
|
+
*/
|
|
935
|
+
abstract execute(): Promise<{
|
|
936
|
+
items: T[];
|
|
937
|
+
lastEvaluatedKey?: Record<string, unknown>;
|
|
938
|
+
}>;
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
/**
|
|
942
|
+
* Configuration options for DynamoDB query operations.
|
|
943
|
+
* Extends the base FilterOptions with query-specific options.
|
|
944
|
+
*/
|
|
945
|
+
interface QueryOptions extends FilterOptions {
|
|
946
|
+
/** Condition for the sort key in the table or index */
|
|
947
|
+
sortKeyCondition?: Condition;
|
|
948
|
+
/** Direction of sort key traversal (true for ascending, false for descending) */
|
|
949
|
+
scanIndexForward?: boolean;
|
|
950
|
+
}
|
|
951
|
+
/**
|
|
952
|
+
* Function type for executing DynamoDB query operations.
|
|
953
|
+
* @typeParam T - The type of items being queried
|
|
954
|
+
*/
|
|
955
|
+
type QueryExecutor<T extends Record<string, unknown>> = (keyCondition: Condition, options: QueryOptions) => Promise<{
|
|
956
|
+
items: T[];
|
|
957
|
+
lastEvaluatedKey?: Record<string, unknown>;
|
|
958
|
+
}>;
|
|
959
|
+
/**
|
|
960
|
+
* Builder for creating DynamoDB query operations.
|
|
961
|
+
*
|
|
962
|
+
* The builder supports:
|
|
963
|
+
* - Type-safe GSI selection
|
|
964
|
+
* - Complex filter conditions
|
|
965
|
+
* - Automatic pagination handling
|
|
966
|
+
* - Consistent reads
|
|
967
|
+
* - Forward and reverse sorting
|
|
968
|
+
*
|
|
969
|
+
* @example
|
|
970
|
+
* ```typescript
|
|
971
|
+
* // Simple query
|
|
972
|
+
* const result = await new QueryBuilder(executor, eq('userId', '123'))
|
|
973
|
+
* .execute();
|
|
974
|
+
*
|
|
975
|
+
* // Complex query with GSI and filtering
|
|
976
|
+
* const result = await new QueryBuilder(executor, eq('status', 'ACTIVE'))
|
|
977
|
+
* .useIndex('status-index')
|
|
978
|
+
* .filter(op => op.beginsWith('name', 'John'))
|
|
979
|
+
* .select(['id', 'name', 'email'])
|
|
980
|
+
* .sortDescending()
|
|
981
|
+
* .limit(10)
|
|
982
|
+
* .execute();
|
|
983
|
+
*
|
|
984
|
+
* // Query with pagination
|
|
985
|
+
* const paginator = new QueryBuilder(executor, eq('type', 'order'))
|
|
986
|
+
* .paginate(25);
|
|
987
|
+
*
|
|
988
|
+
* while (paginator.hasNextPage()) {
|
|
989
|
+
* const page = await paginator.getNextPage();
|
|
990
|
+
* // Process page.items
|
|
991
|
+
* }
|
|
992
|
+
* ```
|
|
993
|
+
*
|
|
994
|
+
* @typeParam T - The type of items being queried
|
|
995
|
+
* @typeParam TConfig - The table configuration type for type-safe GSI selection
|
|
996
|
+
*/
|
|
997
|
+
declare class QueryBuilder<T extends Record<string, unknown>, TConfig extends TableConfig = TableConfig> extends FilterBuilder<T, TConfig> implements QueryBuilderInterface<T, TConfig> {
|
|
998
|
+
private readonly keyCondition;
|
|
999
|
+
protected options: QueryOptions;
|
|
1000
|
+
protected readonly executor: QueryExecutor<T>;
|
|
1001
|
+
constructor(executor: QueryExecutor<T>, keyCondition: Condition);
|
|
1002
|
+
/**
|
|
1003
|
+
* Sets the maximum number of items to return from the query.
|
|
1004
|
+
*
|
|
1005
|
+
* Note: This is the default behavior if no sort order is specified.
|
|
1006
|
+
*
|
|
1007
|
+
* @example
|
|
1008
|
+
* ```typescript
|
|
1009
|
+
* // Get orders in chronological order
|
|
1010
|
+
* const result = await new QueryBuilder(executor, eq('userId', '123'))
|
|
1011
|
+
* .sortAscending()
|
|
1012
|
+
* .execute();
|
|
1013
|
+
*
|
|
1014
|
+
* // Get events from oldest to newest
|
|
1015
|
+
* const result = await new QueryBuilder(executor, eq('entityId', 'order-123'))
|
|
1016
|
+
* .useIndex('entity-timestamp-index')
|
|
1017
|
+
* .sortAscending()
|
|
1018
|
+
* .execute();
|
|
1019
|
+
* ```
|
|
1020
|
+
*
|
|
1021
|
+
* @returns The builder instance for method chaining
|
|
1022
|
+
*/
|
|
1023
|
+
/**
|
|
1024
|
+
* Sets the query to return items in ascending order by sort key.
|
|
1025
|
+
*
|
|
1026
|
+
* @example
|
|
1027
|
+
* ```typescript
|
|
1028
|
+
* // List dinosaurs by age
|
|
1029
|
+
* const result = await new QueryBuilder(executor, eq('species', 'Velociraptor'))
|
|
1030
|
+
* .useIndex('age-index')
|
|
1031
|
+
* .sortAscending()
|
|
1032
|
+
* .execute();
|
|
1033
|
+
*
|
|
1034
|
+
* // View incidents chronologically
|
|
1035
|
+
* const result = await new QueryBuilder(executor, eq('type', 'SECURITY_BREACH'))
|
|
1036
|
+
* .useIndex('date-index')
|
|
1037
|
+
* .sortAscending()
|
|
1038
|
+
* .execute();
|
|
1039
|
+
* ```
|
|
1040
|
+
*
|
|
1041
|
+
* @returns The builder instance for method chaining
|
|
1042
|
+
*/
|
|
1043
|
+
sortAscending(): QueryBuilder<T>;
|
|
1044
|
+
/**
|
|
1045
|
+
* Sets the query to return items in descending order by sort key.
|
|
1046
|
+
*
|
|
1047
|
+
* @example
|
|
1048
|
+
* ```typescript
|
|
1049
|
+
* // Get most recent security incidents
|
|
1050
|
+
* const result = await new QueryBuilder(executor, eq('type', 'SECURITY_BREACH'))
|
|
1051
|
+
* .useIndex('date-index')
|
|
1052
|
+
* .sortDescending()
|
|
1053
|
+
* .limit(10)
|
|
1054
|
+
* .execute();
|
|
1055
|
+
*
|
|
1056
|
+
* // Check latest dinosaur activities
|
|
1057
|
+
* const result = await new QueryBuilder(executor, eq('species', 'Velociraptor'))
|
|
1058
|
+
* .useIndex('activity-time-index')
|
|
1059
|
+
* .filter(op => op.eq('status', 'ACTIVE'))
|
|
1060
|
+
* .sortDescending()
|
|
1061
|
+
* .execute();
|
|
1062
|
+
* ```
|
|
1063
|
+
*
|
|
1064
|
+
* @returns The builder instance for method chaining
|
|
1065
|
+
*/
|
|
1066
|
+
sortDescending(): QueryBuilder<T>;
|
|
1067
|
+
/**
|
|
1068
|
+
* Creates a deep clone of this QueryBuilder instance.
|
|
1069
|
+
*
|
|
1070
|
+
* This is particularly useful when:
|
|
1071
|
+
* - Implementing pagination (used internally by paginate())
|
|
1072
|
+
* - Creating query templates
|
|
1073
|
+
* - Running multiple variations of a query
|
|
1074
|
+
*
|
|
1075
|
+
* @example
|
|
1076
|
+
* ```typescript
|
|
1077
|
+
* // Create base dinosaur query
|
|
1078
|
+
* const baseQuery = new QueryBuilder(executor, eq('species', 'Velociraptor'))
|
|
1079
|
+
* .useIndex('status-index')
|
|
1080
|
+
* .select(['id', 'status', 'location']);
|
|
1081
|
+
*
|
|
1082
|
+
* // Check active dinosaurs
|
|
1083
|
+
* const activeRaptors = baseQuery.clone()
|
|
1084
|
+
* .filter(op => op.eq('status', 'HUNTING'))
|
|
1085
|
+
* .execute();
|
|
1086
|
+
*
|
|
1087
|
+
* // Check contained dinosaurs
|
|
1088
|
+
* const containedRaptors = baseQuery.clone()
|
|
1089
|
+
* .filter(op => op.eq('status', 'CONTAINED'))
|
|
1090
|
+
* .execute();
|
|
1091
|
+
*
|
|
1092
|
+
* // Check sedated dinosaurs
|
|
1093
|
+
* const sedatedRaptors = baseQuery.clone()
|
|
1094
|
+
* .filter(op => op.eq('status', 'SEDATED'))
|
|
1095
|
+
* .execute();
|
|
1096
|
+
* ```
|
|
1097
|
+
*
|
|
1098
|
+
* @returns A new QueryBuilder instance with the same configuration
|
|
1099
|
+
*/
|
|
1100
|
+
clone(): QueryBuilder<T, TConfig>;
|
|
1101
|
+
/**
|
|
1102
|
+
* Executes the query against DynamoDB.
|
|
1103
|
+
*
|
|
1104
|
+
* The method returns both the matched items and, if there are more results,
|
|
1105
|
+
* a lastEvaluatedKey that can be used with startFrom() to continue the query.
|
|
1106
|
+
*
|
|
1107
|
+
* @example
|
|
1108
|
+
* ```typescript
|
|
1109
|
+
* try {
|
|
1110
|
+
* // Find active carnivores in specific habitat
|
|
1111
|
+
* const result = await new QueryBuilder(executor, eq('habitatId', 'PADDOCK-A'))
|
|
1112
|
+
* .useIndex('species-status-index')
|
|
1113
|
+
* .filter(op =>
|
|
1114
|
+
* op.and([
|
|
1115
|
+
* op.eq('diet', 'CARNIVORE'),
|
|
1116
|
+
* op.eq('status', 'ACTIVE'),
|
|
1117
|
+
* op.gt('aggressionLevel', 7)
|
|
1118
|
+
* ])
|
|
1119
|
+
* )
|
|
1120
|
+
* .sortDescending()
|
|
1121
|
+
* .limit(5)
|
|
1122
|
+
* .execute();
|
|
1123
|
+
*
|
|
1124
|
+
* console.log(`Found ${result.items.length} dangerous dinosaurs`);
|
|
1125
|
+
*
|
|
1126
|
+
* if (result.lastEvaluatedKey) {
|
|
1127
|
+
* console.log('Additional threats detected');
|
|
1128
|
+
* }
|
|
1129
|
+
* } catch (error) {
|
|
1130
|
+
* console.error('Security scan failed:', error);
|
|
1131
|
+
* }
|
|
1132
|
+
* ```
|
|
1133
|
+
*
|
|
1134
|
+
* @returns A promise that resolves to an object containing:
|
|
1135
|
+
* - items: Array of items matching the query
|
|
1136
|
+
* - lastEvaluatedKey: Token for continuing the query, if more items exist
|
|
1137
|
+
*/
|
|
1138
|
+
execute(): Promise<{
|
|
1139
|
+
items: T[];
|
|
1140
|
+
lastEvaluatedKey?: Record<string, unknown>;
|
|
1141
|
+
}>;
|
|
1142
|
+
}
|
|
1143
|
+
|
|
1144
|
+
/**
|
|
1145
|
+
* Configuration options for DynamoDB transactions.
|
|
1146
|
+
*/
|
|
1147
|
+
interface TransactionOptions {
|
|
1148
|
+
/** Unique identifier for the transaction request (idempotency token) */
|
|
1149
|
+
clientRequestToken?: string;
|
|
1150
|
+
/** Level of consumed capacity details to return */
|
|
1151
|
+
returnConsumedCapacity?: "INDEXES" | "TOTAL" | "NONE";
|
|
1152
|
+
/** Whether to return item collection metrics */
|
|
1153
|
+
returnItemCollectionMetrics?: "SIZE" | "NONE";
|
|
1154
|
+
}
|
|
1155
|
+
/**
|
|
1156
|
+
* Configuration for table indexes used in duplicate detection.
|
|
1157
|
+
* Defines the key structure for checking uniqueness constraints.
|
|
1158
|
+
*/
|
|
1159
|
+
interface IndexConfig {
|
|
1160
|
+
/** The partition key attribute name */
|
|
1161
|
+
partitionKey: string;
|
|
1162
|
+
/** Optional sort key attribute name */
|
|
1163
|
+
sortKey?: string;
|
|
1164
|
+
}
|
|
1165
|
+
/**
|
|
1166
|
+
* Function type for executing DynamoDB transaction operations.
|
|
1167
|
+
* @param params - The complete transaction command input
|
|
1168
|
+
* @returns A promise that resolves when the transaction completes
|
|
1169
|
+
*/
|
|
1170
|
+
type TransactionExecutor = (params: TransactWriteCommandInput) => Promise<void>;
|
|
1171
|
+
/**
|
|
1172
|
+
* Builder for creating and executing DynamoDB transactions.
|
|
1173
|
+
* Use this builder when you need to:
|
|
1174
|
+
* - Perform multiple operations atomically
|
|
1175
|
+
* - Ensure data consistency across operations
|
|
1176
|
+
* - Implement complex business logic that requires atomic updates
|
|
1177
|
+
* - Prevent duplicate items across tables
|
|
1178
|
+
*
|
|
1179
|
+
* The builder supports:
|
|
1180
|
+
* - Put operations (insert/replace items)
|
|
1181
|
+
* - Delete operations
|
|
1182
|
+
* - Update operations
|
|
1183
|
+
* - Condition checks
|
|
1184
|
+
* - Duplicate detection
|
|
1185
|
+
* - Transaction-wide options
|
|
1186
|
+
*
|
|
1187
|
+
* @example
|
|
1188
|
+
* ```typescript
|
|
1189
|
+
* // Create a transaction with multiple operations
|
|
1190
|
+
* const transaction = new TransactionBuilder(executor, {
|
|
1191
|
+
* partitionKey: 'id',
|
|
1192
|
+
* sortKey: 'type'
|
|
1193
|
+
* });
|
|
1194
|
+
*
|
|
1195
|
+
* // Add a new order
|
|
1196
|
+
* transaction.put('orders', {
|
|
1197
|
+
* orderId: '123',
|
|
1198
|
+
* status: 'PENDING'
|
|
1199
|
+
* });
|
|
1200
|
+
*
|
|
1201
|
+
* // Update inventory with condition
|
|
1202
|
+
* transaction.update(
|
|
1203
|
+
* 'inventory',
|
|
1204
|
+
* { productId: 'ABC' },
|
|
1205
|
+
* 'set quantity = quantity - :amount',
|
|
1206
|
+
* { ':amount': 1 },
|
|
1207
|
+
* op => op.gte('quantity', 1)
|
|
1208
|
+
* );
|
|
1209
|
+
*
|
|
1210
|
+
* // Execute the transaction atomically
|
|
1211
|
+
* await transaction.execute();
|
|
1212
|
+
* ```
|
|
1213
|
+
*
|
|
1214
|
+
* Note: DynamoDB transactions have some limitations:
|
|
1215
|
+
* - Maximum 25 operations per transaction
|
|
1216
|
+
* - All operations must be in the same AWS region
|
|
1217
|
+
* - Cannot include table scans or queries
|
|
1218
|
+
*/
|
|
1219
|
+
declare class TransactionBuilder {
|
|
1220
|
+
private items;
|
|
1221
|
+
private options;
|
|
1222
|
+
private indexConfig;
|
|
1223
|
+
private readonly executor;
|
|
1224
|
+
constructor(executor: TransactionExecutor, indexConfig: IndexConfig);
|
|
1225
|
+
/**
|
|
1226
|
+
* Checks if an item with the same primary key already exists in the transaction
|
|
1227
|
+
* @private
|
|
1228
|
+
*/
|
|
1229
|
+
private checkForDuplicateItem;
|
|
1230
|
+
/**
|
|
1231
|
+
* Adds a put operation to the transaction.
|
|
1232
|
+
* Use this method when you need to:
|
|
1233
|
+
* - Insert new items as part of a transaction
|
|
1234
|
+
* - Replace existing items atomically
|
|
1235
|
+
* - Ensure items meet certain conditions before insertion
|
|
1236
|
+
*
|
|
1237
|
+
* The method automatically checks for duplicate items within the transaction
|
|
1238
|
+
* to prevent multiple operations on the same item.
|
|
1239
|
+
*
|
|
1240
|
+
* @example
|
|
1241
|
+
* ```typescript
|
|
1242
|
+
* // Simple put operation
|
|
1243
|
+
* transaction.put('orders', {
|
|
1244
|
+
* orderId: '123',
|
|
1245
|
+
* status: 'PENDING',
|
|
1246
|
+
* amount: 100
|
|
1247
|
+
* });
|
|
1248
|
+
*
|
|
1249
|
+
* // Conditional put operation
|
|
1250
|
+
* transaction.put(
|
|
1251
|
+
* 'inventory',
|
|
1252
|
+
* { productId: 'ABC', quantity: 50 },
|
|
1253
|
+
* op => op.attributeNotExists('productId')
|
|
1254
|
+
* );
|
|
1255
|
+
*
|
|
1256
|
+
* // Put with complex condition
|
|
1257
|
+
* transaction.put(
|
|
1258
|
+
* 'users',
|
|
1259
|
+
* { userId: '123', status: 'ACTIVE' },
|
|
1260
|
+
* op => op.and([
|
|
1261
|
+
* op.attributeNotExists('userId'),
|
|
1262
|
+
* op.beginsWith('status', 'ACTIVE')
|
|
1263
|
+
* ])
|
|
1264
|
+
* );
|
|
1265
|
+
* ```
|
|
1266
|
+
*
|
|
1267
|
+
* @param tableName - The name of the DynamoDB table
|
|
1268
|
+
* @param item - The item to put into the table
|
|
1269
|
+
* @param condition - Optional condition that must be satisfied
|
|
1270
|
+
* @returns The transaction builder for method chaining
|
|
1271
|
+
* @throws {Error} If a duplicate item is detected in the transaction
|
|
1272
|
+
*/
|
|
1273
|
+
put<T extends Record<string, unknown>>(tableName: string, item: T, condition?: Condition): TransactionBuilder;
|
|
1274
|
+
/**
|
|
1275
|
+
* Adds a pre-configured put operation to the transaction.
|
|
1276
|
+
* Use this method when you need to:
|
|
1277
|
+
* - Reuse put commands from PutBuilder
|
|
1278
|
+
* - Add complex put operations with pre-configured parameters
|
|
1279
|
+
* - Integrate with existing put command configurations
|
|
1280
|
+
*
|
|
1281
|
+
* This method is particularly useful when working with PutBuilder
|
|
1282
|
+
* to maintain consistency in put operations across your application.
|
|
1283
|
+
*
|
|
1284
|
+
* @example
|
|
1285
|
+
* ```typescript
|
|
1286
|
+
* // Create a put command with PutBuilder
|
|
1287
|
+
* const putCommand = new PutBuilder(executor, newItem, 'users')
|
|
1288
|
+
* .condition(op => op.attributeNotExists('userId'))
|
|
1289
|
+
* .toDynamoCommand();
|
|
1290
|
+
*
|
|
1291
|
+
* // Add the command to the transaction
|
|
1292
|
+
* transaction.putWithCommand(putCommand);
|
|
1293
|
+
* ```
|
|
1294
|
+
*
|
|
1295
|
+
* @param command - The complete put command configuration
|
|
1296
|
+
* @returns The transaction builder for method chaining
|
|
1297
|
+
* @throws {Error} If a duplicate item is detected in the transaction
|
|
1298
|
+
* @see PutBuilder for creating put commands
|
|
1299
|
+
*/
|
|
1300
|
+
putWithCommand(command: PutCommandParams): TransactionBuilder;
|
|
1301
|
+
/**
|
|
1302
|
+
* Adds a delete operation to the transaction.
|
|
1303
|
+
* Use this method when you need to:
|
|
1304
|
+
* - Remove items as part of a transaction
|
|
1305
|
+
* - Conditionally delete items
|
|
1306
|
+
* - Ensure items exist before deletion
|
|
1307
|
+
*
|
|
1308
|
+
* The method automatically checks for duplicate items within the transaction
|
|
1309
|
+
* to prevent multiple operations on the same item.
|
|
1310
|
+
*
|
|
1311
|
+
* @example
|
|
1312
|
+
* ```typescript
|
|
1313
|
+
* // Simple delete operation
|
|
1314
|
+
* transaction.delete('orders', {
|
|
1315
|
+
* pk: 'ORDER#123',
|
|
1316
|
+
* sk: 'METADATA'
|
|
1317
|
+
* });
|
|
1318
|
+
*
|
|
1319
|
+
* // Conditional delete operation
|
|
1320
|
+
* transaction.delete(
|
|
1321
|
+
* 'users',
|
|
1322
|
+
* { pk: 'USER#123' },
|
|
1323
|
+
* op => op.eq('status', 'INACTIVE')
|
|
1324
|
+
* );
|
|
1325
|
+
*
|
|
1326
|
+
* // Delete with complex condition
|
|
1327
|
+
* transaction.delete(
|
|
1328
|
+
* 'products',
|
|
1329
|
+
* { pk: 'PROD#ABC' },
|
|
1330
|
+
* op => op.and([
|
|
1331
|
+
* op.eq('status', 'DRAFT'),
|
|
1332
|
+
* op.lt('version', 5)
|
|
1333
|
+
* ])
|
|
1334
|
+
* );
|
|
1335
|
+
* ```
|
|
1336
|
+
*
|
|
1337
|
+
* @param tableName - The name of the DynamoDB table
|
|
1338
|
+
* @param key - The primary key of the item to delete
|
|
1339
|
+
* @param condition - Optional condition that must be satisfied
|
|
1340
|
+
* @returns The transaction builder for method chaining
|
|
1341
|
+
* @throws {Error} If a duplicate item is detected in the transaction
|
|
1342
|
+
*/
|
|
1343
|
+
delete(tableName: string, key: PrimaryKeyWithoutExpression, condition?: Condition): TransactionBuilder;
|
|
1344
|
+
/**
|
|
1345
|
+
* Adds a pre-configured delete operation to the transaction.
|
|
1346
|
+
* Use this method when you need to:
|
|
1347
|
+
* - Reuse delete commands from DeleteBuilder
|
|
1348
|
+
* - Add complex delete operations with pre-configured parameters
|
|
1349
|
+
* - Integrate with existing delete command configurations
|
|
1350
|
+
*
|
|
1351
|
+
* This method is particularly useful when working with DeleteBuilder
|
|
1352
|
+
* to maintain consistency in delete operations across your application.
|
|
1353
|
+
*
|
|
1354
|
+
* @example
|
|
1355
|
+
* ```typescript
|
|
1356
|
+
* // Create a delete command with DeleteBuilder
|
|
1357
|
+
* const deleteCommand = new DeleteBuilder(executor, 'users', { pk: 'USER#123' })
|
|
1358
|
+
* .condition(op => op.and([
|
|
1359
|
+
* op.attributeExists('pk'),
|
|
1360
|
+
* op.eq('status', 'INACTIVE')
|
|
1361
|
+
* ]))
|
|
1362
|
+
* .toDynamoCommand();
|
|
1363
|
+
*
|
|
1364
|
+
* // Add the command to the transaction
|
|
1365
|
+
* transaction.deleteWithCommand(deleteCommand);
|
|
1366
|
+
* ```
|
|
1367
|
+
*
|
|
1368
|
+
* @param command - The complete delete command configuration
|
|
1369
|
+
* @returns The transaction builder for method chaining
|
|
1370
|
+
* @throws {Error} If a duplicate item is detected in the transaction
|
|
1371
|
+
* @see DeleteBuilder for creating delete commands
|
|
1372
|
+
*/
|
|
1373
|
+
deleteWithCommand(command: DeleteCommandParams): TransactionBuilder;
|
|
1374
|
+
/**
|
|
1375
|
+
* Adds an update operation to the transaction.
|
|
1376
|
+
* Use this method when you need to:
|
|
1377
|
+
* - Modify existing items as part of a transaction
|
|
1378
|
+
* - Update multiple attributes atomically
|
|
1379
|
+
* - Apply conditional updates
|
|
1380
|
+
* - Perform complex attribute manipulations
|
|
1381
|
+
*
|
|
1382
|
+
* The method supports all DynamoDB update expressions:
|
|
1383
|
+
* - SET: Modify or add attributes
|
|
1384
|
+
* - REMOVE: Delete attributes
|
|
1385
|
+
* - ADD: Update numbers and sets
|
|
1386
|
+
* - DELETE: Remove elements from a set
|
|
1387
|
+
*
|
|
1388
|
+
* @example
|
|
1389
|
+
* ```typescript
|
|
1390
|
+
* // Simple update
|
|
1391
|
+
* transaction.update(
|
|
1392
|
+
* 'orders',
|
|
1393
|
+
* { pk: 'ORDER#123' },
|
|
1394
|
+
* 'SET #status = :status',
|
|
1395
|
+
* { '#status': 'status' },
|
|
1396
|
+
* { ':status': 'PROCESSING' }
|
|
1397
|
+
* );
|
|
1398
|
+
*
|
|
1399
|
+
* // Complex update with multiple operations
|
|
1400
|
+
* transaction.update(
|
|
1401
|
+
* 'products',
|
|
1402
|
+
* { pk: 'PROD#ABC' },
|
|
1403
|
+
* 'SET #qty = #qty - :amount, #status = :status REMOVE #oldAttr',
|
|
1404
|
+
* { '#qty': 'quantity', '#status': 'status', '#oldAttr': 'deprecated_field' },
|
|
1405
|
+
* { ':amount': 1, ':status': 'LOW_STOCK' }
|
|
1406
|
+
* );
|
|
1407
|
+
*
|
|
1408
|
+
* // Conditional update
|
|
1409
|
+
* transaction.update(
|
|
1410
|
+
* 'users',
|
|
1411
|
+
* { pk: 'USER#123' },
|
|
1412
|
+
* 'SET #lastLogin = :now',
|
|
1413
|
+
* { '#lastLogin': 'lastLoginDate' },
|
|
1414
|
+
* { ':now': new Date().toISOString() },
|
|
1415
|
+
* op => op.attributeExists('pk')
|
|
1416
|
+
* );
|
|
1417
|
+
* ```
|
|
1418
|
+
*
|
|
1419
|
+
* @param tableName - The name of the DynamoDB table
|
|
1420
|
+
* @param key - The primary key of the item to update
|
|
1421
|
+
* @param updateExpression - The update expression (SET, REMOVE, ADD, DELETE)
|
|
1422
|
+
* @param expressionAttributeNames - Map of attribute name placeholders to actual names
|
|
1423
|
+
* @param expressionAttributeValues - Map of value placeholders to actual values
|
|
1424
|
+
* @param condition - Optional condition that must be satisfied
|
|
1425
|
+
* @returns The transaction builder for method chaining
|
|
1426
|
+
* @throws {Error} If a duplicate item is detected in the transaction
|
|
1427
|
+
*/
|
|
1428
|
+
update<T extends Record<string, unknown>>(tableName: string, key: PrimaryKeyWithoutExpression, updateExpression: string, expressionAttributeNames?: Record<string, string>, expressionAttributeValues?: Record<string, unknown>, condition?: Condition): TransactionBuilder;
|
|
1429
|
+
/**
|
|
1430
|
+
* Adds a pre-configured update operation to the transaction.
|
|
1431
|
+
* Use this method when you need to:
|
|
1432
|
+
* - Reuse update commands from UpdateBuilder
|
|
1433
|
+
* - Add complex update operations with pre-configured parameters
|
|
1434
|
+
* - Integrate with existing update command configurations
|
|
1435
|
+
*
|
|
1436
|
+
* This method is particularly useful when working with UpdateBuilder
|
|
1437
|
+
* to maintain consistency in update operations across your application.
|
|
1438
|
+
*
|
|
1439
|
+
* @example
|
|
1440
|
+
* ```typescript
|
|
1441
|
+
* // Create an update command with UpdateBuilder
|
|
1442
|
+
* const updateCommand = new UpdateBuilder(executor, 'inventory', { pk: 'PROD#ABC' })
|
|
1443
|
+
* .set('quantity', ':qty')
|
|
1444
|
+
* .set('lastUpdated', ':now')
|
|
1445
|
+
* .values({
|
|
1446
|
+
* ':qty': 100,
|
|
1447
|
+
* ':now': new Date().toISOString()
|
|
1448
|
+
* })
|
|
1449
|
+
* .condition(op => op.gt('quantity', 0))
|
|
1450
|
+
* .toDynamoCommand();
|
|
1451
|
+
*
|
|
1452
|
+
* // Add the command to the transaction
|
|
1453
|
+
* transaction.updateWithCommand(updateCommand);
|
|
1454
|
+
* ```
|
|
1455
|
+
*
|
|
1456
|
+
* @param command - The complete update command configuration
|
|
1457
|
+
* @returns The transaction builder for method chaining
|
|
1458
|
+
* @throws {Error} If a duplicate item is detected in the transaction
|
|
1459
|
+
* @see UpdateBuilder for creating update commands
|
|
1460
|
+
*/
|
|
1461
|
+
updateWithCommand(command: UpdateCommandParams): TransactionBuilder;
|
|
1462
|
+
/**
|
|
1463
|
+
* Adds a condition check operation to the transaction.
|
|
1464
|
+
* Use this method when you need to:
|
|
1465
|
+
* - Validate item state without modifying it
|
|
1466
|
+
* - Ensure data consistency across tables
|
|
1467
|
+
* - Implement complex business rules
|
|
1468
|
+
* - Verify preconditions for other operations
|
|
1469
|
+
*
|
|
1470
|
+
* Condition checks are particularly useful for:
|
|
1471
|
+
* - Implementing optimistic locking
|
|
1472
|
+
* - Ensuring referential integrity
|
|
1473
|
+
* - Validating business rules atomically
|
|
1474
|
+
*
|
|
1475
|
+
* @example
|
|
1476
|
+
* ```typescript
|
|
1477
|
+
* // Check if order is in correct state
|
|
1478
|
+
* transaction.conditionCheck(
|
|
1479
|
+
* 'orders',
|
|
1480
|
+
* { pk: 'ORDER#123' },
|
|
1481
|
+
* op => op.eq('status', 'PENDING')
|
|
1482
|
+
* );
|
|
1483
|
+
*
|
|
1484
|
+
* // Complex condition check
|
|
1485
|
+
* transaction.conditionCheck(
|
|
1486
|
+
* 'inventory',
|
|
1487
|
+
* { pk: 'PROD#ABC' },
|
|
1488
|
+
* op => op.and([
|
|
1489
|
+
* op.gt('quantity', 0),
|
|
1490
|
+
* op.eq('status', 'ACTIVE'),
|
|
1491
|
+
* op.attributeExists('lastRestockDate')
|
|
1492
|
+
* ])
|
|
1493
|
+
* );
|
|
1494
|
+
*
|
|
1495
|
+
* // Check with multiple attributes
|
|
1496
|
+
* transaction.conditionCheck(
|
|
1497
|
+
* 'users',
|
|
1498
|
+
* { pk: 'USER#123' },
|
|
1499
|
+
* op => op.or([
|
|
1500
|
+
* op.eq('status', 'PREMIUM'),
|
|
1501
|
+
* op.gte('credits', 100)
|
|
1502
|
+
* ])
|
|
1503
|
+
* );
|
|
1504
|
+
* ```
|
|
1505
|
+
*
|
|
1506
|
+
* @param tableName - The name of the DynamoDB table
|
|
1507
|
+
* @param key - The primary key of the item to check
|
|
1508
|
+
* @param condition - The condition that must be satisfied
|
|
1509
|
+
* @returns The transaction builder for method chaining
|
|
1510
|
+
* @throws {Error} If a duplicate item is detected in the transaction
|
|
1511
|
+
* @throws {Error} If condition expression generation fails
|
|
1512
|
+
*/
|
|
1513
|
+
conditionCheck(tableName: string, key: PrimaryKeyWithoutExpression, condition: Condition): TransactionBuilder;
|
|
1514
|
+
/**
|
|
1515
|
+
* Adds a pre-configured condition check operation to the transaction.
|
|
1516
|
+
* Use this method when you need to:
|
|
1517
|
+
* - Reuse condition checks from ConditionCheckBuilder
|
|
1518
|
+
* - Add complex condition checks with pre-configured parameters
|
|
1519
|
+
* - Integrate with existing condition check configurations
|
|
1520
|
+
*
|
|
1521
|
+
* This method is particularly useful when working with ConditionCheckBuilder
|
|
1522
|
+
* to maintain consistency in condition checks across your application.
|
|
1523
|
+
*
|
|
1524
|
+
* @example
|
|
1525
|
+
* ```typescript
|
|
1526
|
+
* // Create a condition check with ConditionCheckBuilder
|
|
1527
|
+
* const checkCommand = new ConditionCheckBuilder('inventory', { pk: 'PROD#ABC' })
|
|
1528
|
+
* .condition(op => op.and([
|
|
1529
|
+
* op.between('quantity', 10, 100),
|
|
1530
|
+
* op.beginsWith('category', 'ELECTRONICS'),
|
|
1531
|
+
* op.attributeExists('lastAuditDate')
|
|
1532
|
+
* ]))
|
|
1533
|
+
* .toDynamoCommand();
|
|
1534
|
+
*
|
|
1535
|
+
* // Add the command to the transaction
|
|
1536
|
+
* transaction.conditionCheckWithCommand(checkCommand);
|
|
1537
|
+
* ```
|
|
1538
|
+
*
|
|
1539
|
+
* @param command - The complete condition check command configuration
|
|
1540
|
+
* @returns The transaction builder for method chaining
|
|
1541
|
+
* @throws {Error} If a duplicate item is detected in the transaction
|
|
1542
|
+
* @see ConditionCheckBuilder for creating condition check commands
|
|
1543
|
+
*/
|
|
1544
|
+
conditionCheckWithCommand(command: ConditionCheckCommandParams): TransactionBuilder;
|
|
1545
|
+
/**
|
|
1546
|
+
* Sets options for the transaction execution.
|
|
1547
|
+
* Use this method when you need to:
|
|
1548
|
+
* - Enable idempotent transactions
|
|
1549
|
+
* - Track consumed capacity
|
|
1550
|
+
* - Monitor item collection metrics
|
|
1551
|
+
*
|
|
1552
|
+
* @example
|
|
1553
|
+
* ```typescript
|
|
1554
|
+
* // Enable idempotency and capacity tracking
|
|
1555
|
+
* transaction.withOptions({
|
|
1556
|
+
* clientRequestToken: 'unique-request-id-123',
|
|
1557
|
+
* returnConsumedCapacity: 'TOTAL'
|
|
1558
|
+
* });
|
|
1559
|
+
*
|
|
1560
|
+
* // Track item collection metrics
|
|
1561
|
+
* transaction.withOptions({
|
|
1562
|
+
* returnItemCollectionMetrics: 'SIZE'
|
|
1563
|
+
* });
|
|
1564
|
+
* ```
|
|
1565
|
+
*
|
|
1566
|
+
* Note: ClientRequestToken can be used to make transactions idempotent,
|
|
1567
|
+
* ensuring the same transaction is not executed multiple times.
|
|
1568
|
+
*
|
|
1569
|
+
* @param options - Configuration options for the transaction
|
|
1570
|
+
* @returns The transaction builder for method chaining
|
|
1571
|
+
*/
|
|
1572
|
+
withOptions(options: TransactionOptions): TransactionBuilder;
|
|
1573
|
+
/**
|
|
1574
|
+
* Gets a human-readable representation of the transaction items.
|
|
1575
|
+
* Use this method when you need to:
|
|
1576
|
+
* - Debug complex transactions
|
|
1577
|
+
* - Verify operation parameters
|
|
1578
|
+
* - Log transaction details
|
|
1579
|
+
* - Troubleshoot condition expressions
|
|
1580
|
+
*
|
|
1581
|
+
* The method resolves all expression placeholders with their actual values,
|
|
1582
|
+
* making it easier to understand the transaction's operations.
|
|
1583
|
+
*
|
|
1584
|
+
* @example
|
|
1585
|
+
* ```typescript
|
|
1586
|
+
* // Add multiple operations
|
|
1587
|
+
* transaction
|
|
1588
|
+
* .put('orders', { orderId: '123', status: 'PENDING' })
|
|
1589
|
+
* .update('inventory',
|
|
1590
|
+
* { productId: 'ABC' },
|
|
1591
|
+
* 'SET quantity = quantity - :amount',
|
|
1592
|
+
* undefined,
|
|
1593
|
+
* { ':amount': 1 }
|
|
1594
|
+
* );
|
|
1595
|
+
*
|
|
1596
|
+
* // Debug the transaction
|
|
1597
|
+
* const debugInfo = transaction.debug();
|
|
1598
|
+
* console.log('Transaction operations:', debugInfo);
|
|
1599
|
+
* ```
|
|
1600
|
+
*
|
|
1601
|
+
* @returns An array of readable representations of the transaction items
|
|
1602
|
+
*/
|
|
1603
|
+
debug(): Record<string, unknown>[];
|
|
1604
|
+
/**
|
|
1605
|
+
* Executes all operations in the transaction atomically.
|
|
1606
|
+
* Use this method when you need to:
|
|
1607
|
+
* - Perform multiple operations atomically
|
|
1608
|
+
* - Ensure all-or-nothing execution
|
|
1609
|
+
* - Maintain data consistency across operations
|
|
1610
|
+
*
|
|
1611
|
+
* The transaction will only succeed if all operations succeed.
|
|
1612
|
+
* If any operation fails, the entire transaction is rolled back.
|
|
1613
|
+
*
|
|
1614
|
+
* @example
|
|
1615
|
+
* ```typescript
|
|
1616
|
+
* try {
|
|
1617
|
+
* // Build and execute transaction
|
|
1618
|
+
* await transaction
|
|
1619
|
+
* .put('orders', newOrder)
|
|
1620
|
+
* .update('inventory',
|
|
1621
|
+
* { productId: 'ABC' },
|
|
1622
|
+
* 'SET quantity = quantity - :qty',
|
|
1623
|
+
* undefined,
|
|
1624
|
+
* { ':qty': 1 }
|
|
1625
|
+
* )
|
|
1626
|
+
* .conditionCheck('products',
|
|
1627
|
+
* { productId: 'ABC' },
|
|
1628
|
+
* op => op.eq('status', 'ACTIVE')
|
|
1629
|
+
* )
|
|
1630
|
+
* .execute();
|
|
1631
|
+
*
|
|
1632
|
+
* console.log('Transaction completed successfully');
|
|
1633
|
+
* } catch (error) {
|
|
1634
|
+
* // Handle transaction failure
|
|
1635
|
+
* console.error('Transaction failed:', error);
|
|
1636
|
+
* }
|
|
1637
|
+
* ```
|
|
1638
|
+
*
|
|
1639
|
+
* @throws {Error} If no transaction items are specified
|
|
1640
|
+
* @throws {Error} If any operation in the transaction fails
|
|
1641
|
+
* @returns A promise that resolves when the transaction completes
|
|
1642
|
+
*/
|
|
1643
|
+
execute(): Promise<void>;
|
|
1644
|
+
}
|
|
1645
|
+
|
|
1646
|
+
/**
|
|
1647
|
+
* Configuration options for DynamoDB put operations.
|
|
1648
|
+
*/
|
|
1649
|
+
interface PutOptions {
|
|
1650
|
+
/** Optional condition that must be satisfied for the put operation to succeed */
|
|
1651
|
+
condition?: Condition;
|
|
1652
|
+
/** Determines how to handle the return value of the put operation
|
|
1653
|
+
* @options
|
|
1654
|
+
* - NONE: No return value
|
|
1655
|
+
* - ALL_OLD: Returns the item's previous state if it existed
|
|
1656
|
+
* - CONSISTENT: (default) Performs a GET operation after the put to retrieve the item's new state
|
|
1657
|
+
*/
|
|
1658
|
+
returnValues?: "ALL_OLD" | "NONE" | "CONSISTENT";
|
|
1659
|
+
}
|
|
1660
|
+
type PutExecutor<T extends Record<string, unknown>> = (params: PutCommandParams) => Promise<T>;
|
|
1661
|
+
/**
|
|
1662
|
+
* Builder for creating DynamoDB put operations.
|
|
1663
|
+
*
|
|
1664
|
+
* @example
|
|
1665
|
+
* ```typescript
|
|
1666
|
+
* // Add new dinosaur
|
|
1667
|
+
* const result = await new PutBuilder(executor, {
|
|
1668
|
+
* id: 'RAPTOR-001',
|
|
1669
|
+
* species: 'Velociraptor',
|
|
1670
|
+
* status: 'ACTIVE',
|
|
1671
|
+
* stats: {
|
|
1672
|
+
* health: 100,
|
|
1673
|
+
* age: 5,
|
|
1674
|
+
* threatLevel: 8
|
|
1675
|
+
* }
|
|
1676
|
+
* }, 'dinosaurs').execute();
|
|
1677
|
+
*
|
|
1678
|
+
* // Create new habitat with conditions
|
|
1679
|
+
* const result = await new PutBuilder(executor, {
|
|
1680
|
+
* id: 'PADDOCK-C',
|
|
1681
|
+
* type: 'CARNIVORE',
|
|
1682
|
+
* securityLevel: 'MAXIMUM',
|
|
1683
|
+
* capacity: 3,
|
|
1684
|
+
* environmentType: 'TROPICAL'
|
|
1685
|
+
* }, 'habitats')
|
|
1686
|
+
* .condition(op => op.attributeNotExists('id'))
|
|
1687
|
+
* .execute();
|
|
1688
|
+
* ```
|
|
1689
|
+
*
|
|
1690
|
+
* @typeParam T - The type of item being put into the table
|
|
1691
|
+
*/
|
|
1692
|
+
declare class PutBuilder<T extends Record<string, unknown>> {
|
|
1693
|
+
private readonly item;
|
|
1694
|
+
private options;
|
|
1695
|
+
private readonly executor;
|
|
1696
|
+
private readonly tableName;
|
|
1697
|
+
constructor(executor: PutExecutor<T>, item: T, tableName: string);
|
|
1698
|
+
/**
|
|
1699
|
+
* Adds a condition that must be satisfied for the put operation to succeed.
|
|
1700
|
+
* Use this method when you need to:
|
|
1701
|
+
* - Prevent overwriting existing items (optimistic locking)
|
|
1702
|
+
* - Ensure items meet certain criteria before replacement
|
|
1703
|
+
* - Implement complex business rules for item updates
|
|
1704
|
+
*
|
|
1705
|
+
* @example
|
|
1706
|
+
* ```ts
|
|
1707
|
+
* // Ensure item doesn't exist (insert only)
|
|
1708
|
+
* builder.condition(op => op.attributeNotExists('id'))
|
|
1709
|
+
*
|
|
1710
|
+
* // Complex condition with version check
|
|
1711
|
+
* builder.condition(op =>
|
|
1712
|
+
* op.and([
|
|
1713
|
+
* op.attributeExists('id'),
|
|
1714
|
+
* op.eq('version', currentVersion),
|
|
1715
|
+
* op.eq('status', 'ACTIVE')
|
|
1716
|
+
* ])
|
|
1717
|
+
* )
|
|
1718
|
+
* ```
|
|
1719
|
+
*
|
|
1720
|
+
* @param condition - Either a Condition object or a callback function that builds the condition
|
|
1721
|
+
* @returns The builder instance for method chaining
|
|
1722
|
+
*/
|
|
1723
|
+
/**
|
|
1724
|
+
* Adds a condition that must be satisfied for the put operation to succeed.
|
|
1725
|
+
*
|
|
1726
|
+
* @example
|
|
1727
|
+
* ```typescript
|
|
1728
|
+
* // Ensure unique dinosaur ID
|
|
1729
|
+
* builder.condition(op =>
|
|
1730
|
+
* op.attributeNotExists('id')
|
|
1731
|
+
* );
|
|
1732
|
+
*
|
|
1733
|
+
* // Verify habitat requirements
|
|
1734
|
+
* builder.condition(op =>
|
|
1735
|
+
* op.and([
|
|
1736
|
+
* op.eq('securityStatus', 'READY'),
|
|
1737
|
+
* op.attributeExists('lastInspection'),
|
|
1738
|
+
* op.gt('securityLevel', 5)
|
|
1739
|
+
* ])
|
|
1740
|
+
* );
|
|
1741
|
+
*
|
|
1742
|
+
* // Check breeding facility conditions
|
|
1743
|
+
* builder.condition(op =>
|
|
1744
|
+
* op.and([
|
|
1745
|
+
* op.between('temperature', 25, 30),
|
|
1746
|
+
* op.between('humidity', 60, 80),
|
|
1747
|
+
* op.eq('quarantineStatus', 'CLEAR')
|
|
1748
|
+
* ])
|
|
1749
|
+
* );
|
|
1750
|
+
* ```
|
|
1751
|
+
*
|
|
1752
|
+
* @param condition - Either a Condition object or a callback function that builds the condition
|
|
1753
|
+
* @returns The builder instance for method chaining
|
|
1754
|
+
*/
|
|
1755
|
+
condition(condition: Condition | ((op: ConditionOperator<T>) => Condition)): this;
|
|
1756
|
+
/**
|
|
1757
|
+
* Sets whether to return the item's previous values (if it existed).
|
|
1758
|
+
*
|
|
1759
|
+
* @options
|
|
1760
|
+
* - NONE: No return value
|
|
1761
|
+
* - ALL_OLD: Returns the item's previous state if it existed, no read capacity units are consumed
|
|
1762
|
+
* - CONSISTENT: (default) Performs a GET operation after the put to retrieve the item's new state
|
|
1763
|
+
*
|
|
1764
|
+
* @example
|
|
1765
|
+
* ```ts
|
|
1766
|
+
* // Get previous dinosaur state
|
|
1767
|
+
* const result = await builder
|
|
1768
|
+
* .returnValues('ALL_OLD')
|
|
1769
|
+
* .execute();
|
|
1770
|
+
*
|
|
1771
|
+
* if (result) {
|
|
1772
|
+
* console.log('Previous profile:', {
|
|
1773
|
+
* species: result.species,
|
|
1774
|
+
* status: result.status,
|
|
1775
|
+
* stats: {
|
|
1776
|
+
* health: result.stats.health,
|
|
1777
|
+
* threatLevel: result.stats.threatLevel
|
|
1778
|
+
* }
|
|
1779
|
+
* });
|
|
1780
|
+
* }
|
|
1781
|
+
* ```
|
|
1782
|
+
*
|
|
1783
|
+
* @param returnValues - Use 'ALL_OLD' to return previous values if the item was overwritten, or 'NONE' (default).
|
|
1784
|
+
* @returns The builder instance for method chaining
|
|
1785
|
+
*/
|
|
1786
|
+
returnValues(returnValues: "ALL_OLD" | "NONE" | "CONSISTENT"): this;
|
|
1787
|
+
/**
|
|
1788
|
+
* Generate the DynamoDB command parameters
|
|
1789
|
+
*/
|
|
1790
|
+
private toDynamoCommand;
|
|
1791
|
+
/**
|
|
1792
|
+
* Adds this put operation to a transaction.
|
|
1793
|
+
* Use this method when you need to:
|
|
1794
|
+
* - Transfer dinosaurs between habitats
|
|
1795
|
+
* - Initialize new breeding programs
|
|
1796
|
+
* - Update multiple facility records
|
|
1797
|
+
*
|
|
1798
|
+
* @example
|
|
1799
|
+
* ```ts
|
|
1800
|
+
* const transaction = new TransactionBuilder();
|
|
1801
|
+
*
|
|
1802
|
+
* // Add dinosaur to new habitat
|
|
1803
|
+
* new PutBuilder(executor, {
|
|
1804
|
+
* id: 'TREX-002',
|
|
1805
|
+
* location: 'PADDOCK-B',
|
|
1806
|
+
* status: 'ACTIVE',
|
|
1807
|
+
* transferDate: new Date().toISOString()
|
|
1808
|
+
* }, 'dinosaurs')
|
|
1809
|
+
* .withTransaction(transaction);
|
|
1810
|
+
*
|
|
1811
|
+
* // Update habitat records
|
|
1812
|
+
* new UpdateBuilder(executor, 'habitats', { id: 'PADDOCK-B' })
|
|
1813
|
+
* .add('occupants', 1)
|
|
1814
|
+
* .set('lastTransfer', new Date().toISOString())
|
|
1815
|
+
* .withTransaction(transaction);
|
|
1816
|
+
*
|
|
1817
|
+
* // Execute transfer atomically
|
|
1818
|
+
* await transaction.execute();
|
|
1819
|
+
* ```
|
|
1820
|
+
*
|
|
1821
|
+
* @param transaction - The transaction builder to add this operation to
|
|
1822
|
+
* @returns The builder instance for method chaining
|
|
1823
|
+
*/
|
|
1824
|
+
withTransaction(transaction: TransactionBuilder): this;
|
|
1825
|
+
/**
|
|
1826
|
+
* Executes the put operation against DynamoDB.
|
|
1827
|
+
*
|
|
1828
|
+
* @example
|
|
1829
|
+
* ```ts
|
|
1830
|
+
* try {
|
|
1831
|
+
* // Put with condition and return old values
|
|
1832
|
+
* const result = await new PutBuilder(executor, newItem, 'myTable')
|
|
1833
|
+
* .condition(op => op.eq('version', 1))
|
|
1834
|
+
* .returnValues('ALL_OLD')
|
|
1835
|
+
* .execute();
|
|
1836
|
+
*
|
|
1837
|
+
* console.log('Put successful, old item:', result);
|
|
1838
|
+
* } catch (error) {
|
|
1839
|
+
* // Handle condition check failure or other errors
|
|
1840
|
+
* console.error('Put failed:', error);
|
|
1841
|
+
* }
|
|
1842
|
+
* ```
|
|
1843
|
+
*
|
|
1844
|
+
* @returns A promise that resolves to the operation result (type depends on returnValues setting)
|
|
1845
|
+
* @throws Will throw an error if the condition check fails or other DynamoDB errors occur
|
|
1846
|
+
*/
|
|
1847
|
+
execute(): Promise<T | undefined>;
|
|
1848
|
+
/**
|
|
1849
|
+
* Gets a human-readable representation of the put command
|
|
1850
|
+
* with all expression placeholders replaced by their actual values.
|
|
1851
|
+
*
|
|
1852
|
+
* @example
|
|
1853
|
+
* ```ts
|
|
1854
|
+
* const debugInfo = new PutBuilder(executor, {
|
|
1855
|
+
* id: 'RAPTOR-003',
|
|
1856
|
+
* species: 'Velociraptor',
|
|
1857
|
+
* status: 'QUARANTINE',
|
|
1858
|
+
* stats: {
|
|
1859
|
+
* health: 100,
|
|
1860
|
+
* aggressionLevel: 7,
|
|
1861
|
+
* age: 2
|
|
1862
|
+
* }
|
|
1863
|
+
* }, 'dinosaurs')
|
|
1864
|
+
* .condition(op =>
|
|
1865
|
+
* op.and([
|
|
1866
|
+
* op.attributeNotExists('id'),
|
|
1867
|
+
* op.eq('quarantineStatus', 'READY'),
|
|
1868
|
+
* op.gt('securityLevel', 8)
|
|
1869
|
+
* ])
|
|
1870
|
+
* )
|
|
1871
|
+
* .debug();
|
|
1872
|
+
*
|
|
1873
|
+
* console.log('Dinosaur transfer command:', debugInfo);
|
|
1874
|
+
* ```
|
|
1875
|
+
*
|
|
1876
|
+
* @returns A readable representation of the put command with resolved expressions
|
|
1877
|
+
*/
|
|
1878
|
+
debug(): Record<string, unknown>;
|
|
1879
|
+
}
|
|
1880
|
+
|
|
1881
|
+
interface DeleteOptions {
|
|
1882
|
+
condition?: Condition;
|
|
1883
|
+
returnValues?: "ALL_OLD";
|
|
1884
|
+
}
|
|
1885
|
+
type DeleteExecutor = (params: DeleteCommandParams) => Promise<{
|
|
1886
|
+
item?: Record<string, unknown>;
|
|
1887
|
+
}>;
|
|
1888
|
+
/**
|
|
1889
|
+
* Builder for creating DynamoDB delete operations.
|
|
1890
|
+
* Use this builder when you need to:
|
|
1891
|
+
* - Remove dinosaurs from the registry
|
|
1892
|
+
* - Clean up abandoned habitats
|
|
1893
|
+
* - Delete historical tracking data
|
|
1894
|
+
* - Remove deprecated classifications
|
|
1895
|
+
*
|
|
1896
|
+
* @example
|
|
1897
|
+
* ```typescript
|
|
1898
|
+
* // Simple delete
|
|
1899
|
+
* const result = await new DeleteBuilder(executor, 'dinosaurs', { id: 'TREX-001' })
|
|
1900
|
+
* .execute();
|
|
1901
|
+
*
|
|
1902
|
+
* // Conditional delete with old value retrieval
|
|
1903
|
+
* const result = await new DeleteBuilder(executor, 'habitats', { id: 'PADDOCK-A' })
|
|
1904
|
+
* .condition(op =>
|
|
1905
|
+
* op.and([
|
|
1906
|
+
* op.eq('status', 'DECOMMISSIONED'),
|
|
1907
|
+
* op.eq('occupants', 0),
|
|
1908
|
+
* op.lt('securityIncidents', 1)
|
|
1909
|
+
* ])
|
|
1910
|
+
* )
|
|
1911
|
+
* .returnValues('ALL_OLD')
|
|
1912
|
+
* .execute();
|
|
1913
|
+
* ```
|
|
1914
|
+
*/
|
|
1915
|
+
declare class DeleteBuilder {
|
|
1916
|
+
private options;
|
|
1917
|
+
private readonly executor;
|
|
1918
|
+
private readonly tableName;
|
|
1919
|
+
private readonly key;
|
|
1920
|
+
constructor(executor: DeleteExecutor, tableName: string, key: PrimaryKeyWithoutExpression);
|
|
1921
|
+
/**
|
|
1922
|
+
* Adds a condition that must be satisfied for the delete operation to succeed.
|
|
1923
|
+
* Use this method when you need to:
|
|
1924
|
+
* - Ensure safe removal conditions
|
|
1925
|
+
* - Verify habitat status before deletion
|
|
1926
|
+
* - Implement safety protocols
|
|
1927
|
+
*
|
|
1928
|
+
* @example
|
|
1929
|
+
* ```typescript
|
|
1930
|
+
* // Ensure dinosaur can be safely removed
|
|
1931
|
+
* builder.condition(op =>
|
|
1932
|
+
* op.and([
|
|
1933
|
+
* op.eq('status', 'SEDATED'),
|
|
1934
|
+
* op.eq('location', 'MEDICAL_BAY'),
|
|
1935
|
+
* op.attributeExists('lastCheckup')
|
|
1936
|
+
* ])
|
|
1937
|
+
* );
|
|
1938
|
+
*
|
|
1939
|
+
* // Verify habitat is empty
|
|
1940
|
+
* builder.condition(op =>
|
|
1941
|
+
* op.and([
|
|
1942
|
+
* op.eq('occupants', 0),
|
|
1943
|
+
* op.eq('maintenanceStatus', 'COMPLETE'),
|
|
1944
|
+
* op.not(op.attributeExists('activeAlerts'))
|
|
1945
|
+
* ])
|
|
1946
|
+
* );
|
|
1947
|
+
* ```
|
|
1948
|
+
*
|
|
1949
|
+
* @param condition - Either a Condition object or a callback function that builds the condition
|
|
1950
|
+
* @returns The builder instance for method chaining
|
|
1951
|
+
*/
|
|
1952
|
+
condition<T extends Record<string, unknown>>(condition: Condition | ((op: ConditionOperator<T>) => Condition)): DeleteBuilder;
|
|
1953
|
+
/**
|
|
1954
|
+
* Sets whether to return the item's attribute values before deletion.
|
|
1955
|
+
* Use this method when you need to:
|
|
1956
|
+
* - Archive removed dinosaur data
|
|
1957
|
+
* - Track habitat decommissioning history
|
|
1958
|
+
* - Maintain removal audit logs
|
|
1959
|
+
*
|
|
1960
|
+
* @example
|
|
1961
|
+
* ```ts
|
|
1962
|
+
* // Archive dinosaur data before removal
|
|
1963
|
+
* const result = await builder
|
|
1964
|
+
* .returnValues('ALL_OLD')
|
|
1965
|
+
* .execute();
|
|
1966
|
+
*
|
|
1967
|
+
* if (result.item) {
|
|
1968
|
+
* console.log('Removed dinosaur data:', {
|
|
1969
|
+
* species: result.item.species,
|
|
1970
|
+
* age: result.item.age,
|
|
1971
|
+
* lastLocation: result.item.location
|
|
1972
|
+
* });
|
|
1973
|
+
* }
|
|
1974
|
+
* ```
|
|
1975
|
+
*
|
|
1976
|
+
* @param returnValues - Use 'ALL_OLD' to return all attributes of the deleted item
|
|
1977
|
+
* @returns The builder instance for method chaining
|
|
1978
|
+
*/
|
|
1979
|
+
returnValues(returnValues: "ALL_OLD"): DeleteBuilder;
|
|
1980
|
+
/**
|
|
1981
|
+
* Generate the DynamoDB command parameters
|
|
1982
|
+
*/
|
|
1983
|
+
private toDynamoCommand;
|
|
1984
|
+
/**
|
|
1985
|
+
* Adds this delete operation to a transaction.
|
|
1986
|
+
* Use this method when you need to:
|
|
1987
|
+
* - Coordinate dinosaur transfers
|
|
1988
|
+
* - Manage habitat decommissioning
|
|
1989
|
+
* - Handle species relocations
|
|
1990
|
+
*
|
|
1991
|
+
* @example
|
|
1992
|
+
* ```ts
|
|
1993
|
+
* const transaction = new TransactionBuilder();
|
|
1994
|
+
*
|
|
1995
|
+
* // Remove dinosaur from old habitat
|
|
1996
|
+
* new DeleteBuilder(executor, 'dinosaurs', { id: 'RAPTOR-001' })
|
|
1997
|
+
* .condition(op => op.eq('status', 'SEDATED'))
|
|
1998
|
+
* .withTransaction(transaction);
|
|
1999
|
+
*
|
|
2000
|
+
* // Update old habitat occupancy
|
|
2001
|
+
* new UpdateBuilder(executor, 'habitats', { id: 'PADDOCK-A' })
|
|
2002
|
+
* .add('occupants', -1)
|
|
2003
|
+
* .withTransaction(transaction);
|
|
2004
|
+
*
|
|
2005
|
+
* // Execute transfer atomically
|
|
2006
|
+
* await transaction.execute();
|
|
2007
|
+
* ```
|
|
2008
|
+
*
|
|
2009
|
+
* @param transaction - The transaction builder to add this operation to
|
|
2010
|
+
*/
|
|
2011
|
+
withTransaction(transaction: TransactionBuilder): void;
|
|
2012
|
+
/**
|
|
2013
|
+
* Executes the delete operation against DynamoDB.
|
|
2014
|
+
*
|
|
2015
|
+
* @example
|
|
2016
|
+
* ```ts
|
|
2017
|
+
* // Delete with condition and retrieve old values
|
|
2018
|
+
* const result = await new DeleteBuilder(executor, 'myTable', { id: '123' })
|
|
2019
|
+
* .condition(op => op.eq('status', 'INACTIVE'))
|
|
2020
|
+
* .returnValues('ALL_OLD')
|
|
2021
|
+
* .execute();
|
|
2022
|
+
*
|
|
2023
|
+
* if (result.item) {
|
|
2024
|
+
* console.log('Deleted item:', result.item);
|
|
2025
|
+
* }
|
|
2026
|
+
* ```
|
|
2027
|
+
*
|
|
2028
|
+
* @returns A promise that resolves to an object containing the deleted item's attributes (if returnValues is 'ALL_OLD')
|
|
2029
|
+
*/
|
|
2030
|
+
execute(): Promise<{
|
|
2031
|
+
item?: Record<string, unknown>;
|
|
2032
|
+
}>;
|
|
2033
|
+
/**
|
|
2034
|
+
* Gets a human-readable representation of the delete command
|
|
2035
|
+
* with all expression placeholders replaced by their actual values.
|
|
2036
|
+
* Use this method when you need to:
|
|
2037
|
+
* - Debug complex deletion conditions
|
|
2038
|
+
* - Verify safety checks
|
|
2039
|
+
* - Log removal operations
|
|
2040
|
+
* - Troubleshoot failed deletions
|
|
2041
|
+
*
|
|
2042
|
+
* @example
|
|
2043
|
+
* ```ts
|
|
2044
|
+
* const debugInfo = new DeleteBuilder(executor, 'dinosaurs', { id: 'TREX-001' })
|
|
2045
|
+
* .condition(op => op.and([
|
|
2046
|
+
* op.eq('status', 'SEDATED'),
|
|
2047
|
+
* op.eq('location', 'MEDICAL_BAY'),
|
|
2048
|
+
* op.gt('sedationLevel', 8)
|
|
2049
|
+
* op.eq('version', 1),
|
|
2050
|
+
* op.attributeExists('status')
|
|
2051
|
+
* ]))
|
|
2052
|
+
* .debug();
|
|
2053
|
+
*
|
|
2054
|
+
* console.log('Delete command:', debugInfo);
|
|
2055
|
+
* ```
|
|
2056
|
+
*
|
|
2057
|
+
* @returns A readable representation of the delete command with resolved expressions
|
|
2058
|
+
*/
|
|
2059
|
+
debug(): Record<string, unknown>;
|
|
2060
|
+
}
|
|
2061
|
+
|
|
2062
|
+
/**
|
|
2063
|
+
* Configuration options for DynamoDB update operations.
|
|
2064
|
+
*/
|
|
2065
|
+
interface UpdateOptions {
|
|
2066
|
+
/** Optional condition that must be satisfied for the update to succeed */
|
|
2067
|
+
condition?: Condition;
|
|
2068
|
+
/** Determines which item attributes to include in the response */
|
|
2069
|
+
returnValues?: "ALL_NEW" | "UPDATED_NEW" | "ALL_OLD" | "UPDATED_OLD" | "NONE";
|
|
2070
|
+
}
|
|
2071
|
+
/**
|
|
2072
|
+
* Function type for executing DynamoDB update operations.
|
|
2073
|
+
* @typeParam T - The type of the item being updated
|
|
2074
|
+
*/
|
|
2075
|
+
type UpdateExecutor<T extends Record<string, unknown>> = (params: UpdateCommandParams) => Promise<{
|
|
2076
|
+
item?: T;
|
|
2077
|
+
}>;
|
|
2078
|
+
/**
|
|
2079
|
+
* Represents a single update action within an update operation.
|
|
2080
|
+
* Each action modifies the item in a specific way:
|
|
2081
|
+
* - SET: Modify or add attributes
|
|
2082
|
+
* - REMOVE: Delete attributes
|
|
2083
|
+
* - ADD: Update numbers and sets
|
|
2084
|
+
* - DELETE: Remove elements from a set
|
|
2085
|
+
*/
|
|
2086
|
+
type UpdateAction = {
|
|
2087
|
+
/** The type of update action */
|
|
2088
|
+
type: "SET" | "REMOVE" | "ADD" | "DELETE";
|
|
2089
|
+
/** The attribute path to update */
|
|
2090
|
+
path: string;
|
|
2091
|
+
/** The value to use in the update (not used for REMOVE actions) */
|
|
2092
|
+
value?: unknown;
|
|
2093
|
+
};
|
|
2094
|
+
/**
|
|
2095
|
+
* Type utility to get the element type of a set.
|
|
2096
|
+
* Extracts the element type from either a Set or Array type.
|
|
2097
|
+
* @typeParam T - The set or array type
|
|
2098
|
+
*/
|
|
2099
|
+
type SetElementType<T> = T extends Set<infer U> ? U : T extends Array<infer U> ? U : never;
|
|
2100
|
+
/**
|
|
2101
|
+
* Type utility to get the element type from a path that points to a set.
|
|
2102
|
+
* Combines PathType and SetElementType to get the element type at a specific path.
|
|
2103
|
+
* @typeParam T - The type of the item
|
|
2104
|
+
* @typeParam K - The path within the item
|
|
2105
|
+
*/
|
|
2106
|
+
type PathSetElementType<T, K extends Path<T>> = SetElementType<PathType<T, K>>;
|
|
2107
|
+
/**
|
|
2108
|
+
* Builder for creating DynamoDB update operations.
|
|
2109
|
+
* Use this builder when you need to:
|
|
2110
|
+
* - Modify existing items in DynamoDB
|
|
2111
|
+
* - Update multiple attributes atomically
|
|
2112
|
+
* - Perform conditional updates
|
|
2113
|
+
* - Work with nested attributes
|
|
2114
|
+
* - Update sets and lists
|
|
2115
|
+
*
|
|
2116
|
+
* The builder supports all DynamoDB update operations:
|
|
2117
|
+
* - SET: Modify or add attributes
|
|
2118
|
+
* - REMOVE: Delete attributes
|
|
2119
|
+
* - ADD: Update numbers and sets
|
|
2120
|
+
* - DELETE: Remove elements from a set
|
|
2121
|
+
*
|
|
2122
|
+
* @example
|
|
2123
|
+
* ```typescript
|
|
2124
|
+
* // Simple update
|
|
2125
|
+
* const result = await new UpdateBuilder(executor, 'dinosaurs', { id: 'TREX-001' })
|
|
2126
|
+
* .set('status', 'HUNTING')
|
|
2127
|
+
* .set('lastFed', new Date().toISOString())
|
|
2128
|
+
* .execute();
|
|
2129
|
+
*
|
|
2130
|
+
* // Complex update with multiple operations
|
|
2131
|
+
* const result = await new UpdateBuilder(executor, 'habitats', { id: 'PADDOCK-A' })
|
|
2132
|
+
* .set({
|
|
2133
|
+
* status: 'OCCUPIED',
|
|
2134
|
+
* occupants: 3,
|
|
2135
|
+
* 'metadata.lastInspection': new Date().toISOString()
|
|
2136
|
+
* })
|
|
2137
|
+
* .add('securityBreaches', 1)
|
|
2138
|
+
* .deleteElementsFromSet('suitableDinosaurs', ['VELOCIRAPTOR'])
|
|
2139
|
+
* .condition(op => op.gt('securityLevel', 8))
|
|
2140
|
+
* .returnValues('ALL_NEW')
|
|
2141
|
+
* .execute();
|
|
2142
|
+
* ```
|
|
2143
|
+
*
|
|
2144
|
+
* @typeParam T - The type of item being updated
|
|
2145
|
+
*/
|
|
2146
|
+
declare class UpdateBuilder<T extends Record<string, unknown>> {
|
|
2147
|
+
private updates;
|
|
2148
|
+
private options;
|
|
2149
|
+
private readonly executor;
|
|
2150
|
+
private readonly tableName;
|
|
2151
|
+
private readonly key;
|
|
2152
|
+
constructor(executor: UpdateExecutor<T>, tableName: string, key: PrimaryKeyWithoutExpression);
|
|
2153
|
+
/**
|
|
2154
|
+
* Sets multiple attributes of an item using an object.
|
|
2155
|
+
* Use this method when you need to:
|
|
2156
|
+
* - Update multiple attributes at once
|
|
2157
|
+
* - Set nested attribute values
|
|
2158
|
+
* - Modify complex data structures
|
|
2159
|
+
*
|
|
2160
|
+
* @example
|
|
2161
|
+
* ```typescript
|
|
2162
|
+
* // Update multiple attributes
|
|
2163
|
+
* builder.set({
|
|
2164
|
+
* species: 'Tyrannosaurus Rex',
|
|
2165
|
+
* height: 20,
|
|
2166
|
+
* diet: 'CARNIVORE',
|
|
2167
|
+
* 'stats.threatLevel': 10
|
|
2168
|
+
* });
|
|
2169
|
+
* ```
|
|
2170
|
+
*/
|
|
2171
|
+
set(values: Partial<T>): UpdateBuilder<T>;
|
|
2172
|
+
/**
|
|
2173
|
+
* Sets a single attribute to a specific value.
|
|
2174
|
+
* Use this method when you need to:
|
|
2175
|
+
* - Update one attribute at a time
|
|
2176
|
+
* - Set values with type safety
|
|
2177
|
+
* - Update nested attributes
|
|
2178
|
+
*
|
|
2179
|
+
* @example
|
|
2180
|
+
* ```typescript
|
|
2181
|
+
* // Set simple attributes
|
|
2182
|
+
* builder
|
|
2183
|
+
* .set('status', 'SLEEPING')
|
|
2184
|
+
* .set('lastFeeding', new Date().toISOString());
|
|
2185
|
+
*
|
|
2186
|
+
* // Set nested attributes
|
|
2187
|
+
* builder
|
|
2188
|
+
* .set('location.zone', 'RESTRICTED')
|
|
2189
|
+
* .set('stats.health', 100);
|
|
2190
|
+
* ```
|
|
2191
|
+
*/
|
|
2192
|
+
set<K extends Path<T>>(path: K, value: PathType<T, K>): UpdateBuilder<T>;
|
|
2193
|
+
/**
|
|
2194
|
+
* Removes an attribute from the item.
|
|
2195
|
+
* Use this method when you need to:
|
|
2196
|
+
* - Delete attributes completely
|
|
2197
|
+
* - Remove nested attributes
|
|
2198
|
+
* - Clean up deprecated fields
|
|
2199
|
+
*
|
|
2200
|
+
* @example
|
|
2201
|
+
* ```typescript
|
|
2202
|
+
* // Remove simple attributes
|
|
2203
|
+
* builder
|
|
2204
|
+
* .remove('temporaryTag')
|
|
2205
|
+
* .remove('previousLocation');
|
|
2206
|
+
*
|
|
2207
|
+
* // Remove nested attributes
|
|
2208
|
+
* builder
|
|
2209
|
+
* .remove('metadata.testData')
|
|
2210
|
+
* .remove('stats.experimentalMetrics');
|
|
2211
|
+
* ```
|
|
2212
|
+
*
|
|
2213
|
+
* @param path - The path to the attribute to remove
|
|
2214
|
+
* @returns The builder instance for method chaining
|
|
2215
|
+
*/
|
|
2216
|
+
remove<K extends Path<T>>(path: K): UpdateBuilder<T>;
|
|
2217
|
+
/**
|
|
2218
|
+
* Adds a value to a number attribute or adds elements to a set.
|
|
2219
|
+
* Use this method when you need to:
|
|
2220
|
+
* - Increment counters
|
|
2221
|
+
* - Add elements to a set atomically
|
|
2222
|
+
* - Update numerical statistics
|
|
2223
|
+
*
|
|
2224
|
+
* @example
|
|
2225
|
+
* ```typescript
|
|
2226
|
+
* // Increment counters
|
|
2227
|
+
* builder
|
|
2228
|
+
* .add('escapeAttempts', 1)
|
|
2229
|
+
* .add('feedingCount', 1);
|
|
2230
|
+
*
|
|
2231
|
+
* // Add to sets
|
|
2232
|
+
* builder
|
|
2233
|
+
* .add('knownBehaviors', new Set(['PACK_HUNTING', 'AMBUSH_TACTICS']))
|
|
2234
|
+
* .add('visitedZones', new Set(['ZONE_A', 'ZONE_B']));
|
|
2235
|
+
* ```
|
|
2236
|
+
*
|
|
2237
|
+
* @param path - The path to the attribute to update
|
|
2238
|
+
* @param value - The value to add (number or set)
|
|
2239
|
+
* @returns The builder instance for method chaining
|
|
2240
|
+
*/
|
|
2241
|
+
add<K extends Path<T>>(path: K, value: PathType<T, K>): UpdateBuilder<T>;
|
|
2242
|
+
/**
|
|
2243
|
+
* Removes elements from a set attribute.
|
|
2244
|
+
* Use this method when you need to:
|
|
2245
|
+
* - Remove specific elements from a set
|
|
2246
|
+
* - Update set-based attributes atomically
|
|
2247
|
+
* - Maintain set membership
|
|
2248
|
+
*
|
|
2249
|
+
* @example
|
|
2250
|
+
* ```typescript
|
|
2251
|
+
* // Remove from sets using arrays
|
|
2252
|
+
* builder.deleteElementsFromSet(
|
|
2253
|
+
* 'allowedHabitats',
|
|
2254
|
+
* ['JUNGLE', 'COASTAL']
|
|
2255
|
+
* );
|
|
2256
|
+
*
|
|
2257
|
+
* // Remove from sets using Set objects
|
|
2258
|
+
* builder.deleteElementsFromSet(
|
|
2259
|
+
* 'knownBehaviors',
|
|
2260
|
+
* new Set(['NOCTURNAL', 'TERRITORIAL'])
|
|
2261
|
+
* );
|
|
2262
|
+
*
|
|
2263
|
+
* // Remove from nested sets
|
|
2264
|
+
* builder.deleteElementsFromSet(
|
|
2265
|
+
* 'stats.compatibleSpecies',
|
|
2266
|
+
* ['VELOCIRAPTOR', 'DILOPHOSAURUS']
|
|
2267
|
+
* );
|
|
2268
|
+
* ```
|
|
2269
|
+
*
|
|
2270
|
+
* @param path - The path to the set attribute
|
|
2271
|
+
* @param value - Elements to remove (array or Set)
|
|
2272
|
+
* @returns The builder instance for method chaining
|
|
2273
|
+
*/
|
|
2274
|
+
deleteElementsFromSet<K extends Path<T>>(path: K, value: PathSetElementType<T, K>[] | Set<PathSetElementType<T, K>>): UpdateBuilder<T>;
|
|
2275
|
+
/**
|
|
2276
|
+
* Adds a condition that must be satisfied for the update to succeed.
|
|
2277
|
+
* Use this method when you need to:
|
|
2278
|
+
* - Implement optimistic locking
|
|
2279
|
+
* - Ensure item state before update
|
|
2280
|
+
* - Validate business rules
|
|
2281
|
+
* - Prevent concurrent modifications
|
|
2282
|
+
*
|
|
2283
|
+
* @example
|
|
2284
|
+
* ```typescript
|
|
2285
|
+
* // Simple condition
|
|
2286
|
+
* builder.condition(op =>
|
|
2287
|
+
* op.eq('status', 'ACTIVE')
|
|
2288
|
+
* );
|
|
2289
|
+
*
|
|
2290
|
+
* // Health check condition
|
|
2291
|
+
* builder.condition(op =>
|
|
2292
|
+
* op.and([
|
|
2293
|
+
* op.gt('health', 50),
|
|
2294
|
+
* op.eq('status', 'HUNTING')
|
|
2295
|
+
* ])
|
|
2296
|
+
* );
|
|
2297
|
+
*
|
|
2298
|
+
* // Complex security condition
|
|
2299
|
+
* builder.condition(op =>
|
|
2300
|
+
* op.and([
|
|
2301
|
+
* op.attributeExists('securitySystem'),
|
|
2302
|
+
* op.eq('containmentStatus', 'SECURE'),
|
|
2303
|
+
* op.lt('aggressionLevel', 8)
|
|
2304
|
+
* ])
|
|
2305
|
+
* );
|
|
2306
|
+
*
|
|
2307
|
+
* // Version check (optimistic locking)
|
|
2308
|
+
* builder.condition(op =>
|
|
2309
|
+
* op.eq('version', currentVersion)
|
|
2310
|
+
* );
|
|
2311
|
+
* ```
|
|
2312
|
+
*
|
|
2313
|
+
* @param condition - Either a Condition object or a callback function that builds the condition
|
|
2314
|
+
* @returns The builder instance for method chaining
|
|
2315
|
+
*/
|
|
2316
|
+
condition(condition: Condition | ((op: ConditionOperator<T>) => Condition)): UpdateBuilder<T>;
|
|
2317
|
+
/**
|
|
2318
|
+
* Sets which item attributes to include in the response.
|
|
2319
|
+
* Use this method when you need to:
|
|
2320
|
+
* - Get the complete updated item
|
|
2321
|
+
* - Track changes to specific attributes
|
|
2322
|
+
* - Compare old and new values
|
|
2323
|
+
* - Monitor attribute modifications
|
|
2324
|
+
*
|
|
2325
|
+
* Available options:
|
|
2326
|
+
* - ALL_NEW: All attributes after the update
|
|
2327
|
+
* - UPDATED_NEW: Only updated attributes, new values
|
|
2328
|
+
* - ALL_OLD: All attributes before the update
|
|
2329
|
+
* - UPDATED_OLD: Only updated attributes, old values
|
|
2330
|
+
* - NONE: No attributes returned (default)
|
|
2331
|
+
*
|
|
2332
|
+
* @example
|
|
2333
|
+
* ```typescript
|
|
2334
|
+
* // Get complete updated dinosaur
|
|
2335
|
+
* const result = await builder
|
|
2336
|
+
* .set('status', 'SLEEPING')
|
|
2337
|
+
* .returnValues('ALL_NEW')
|
|
2338
|
+
* .execute();
|
|
2339
|
+
*
|
|
2340
|
+
* // Track specific attribute changes
|
|
2341
|
+
* const result = await builder
|
|
2342
|
+
* .set({
|
|
2343
|
+
* 'stats.health': 100,
|
|
2344
|
+
* 'stats.energy': 95
|
|
2345
|
+
* })
|
|
2346
|
+
* .returnValues('UPDATED_OLD')
|
|
2347
|
+
* .execute();
|
|
2348
|
+
*
|
|
2349
|
+
* if (result.item) {
|
|
2350
|
+
* console.log('Previous health:', result.item.stats?.health);
|
|
2351
|
+
* }
|
|
2352
|
+
* ```
|
|
2353
|
+
*
|
|
2354
|
+
* @param returnValues - Which attributes to return in the response
|
|
2355
|
+
* @returns The builder instance for method chaining
|
|
2356
|
+
*/
|
|
2357
|
+
returnValues(returnValues: "ALL_NEW" | "UPDATED_NEW" | "ALL_OLD" | "UPDATED_OLD" | "NONE"): UpdateBuilder<T>;
|
|
2358
|
+
/**
|
|
2359
|
+
* Generate the DynamoDB command parameters
|
|
2360
|
+
*/
|
|
2361
|
+
toDynamoCommand(): UpdateCommandParams;
|
|
2362
|
+
/**
|
|
2363
|
+
* Adds this update operation to a transaction.
|
|
2364
|
+
* Use this method when you need to:
|
|
2365
|
+
* - Update items as part of a larger transaction
|
|
2366
|
+
* - Ensure multiple updates are atomic
|
|
2367
|
+
* - Coordinate updates across multiple items
|
|
2368
|
+
*
|
|
2369
|
+
* @example
|
|
2370
|
+
* ```typescript
|
|
2371
|
+
* const transaction = new TransactionBuilder(executor);
|
|
2372
|
+
*
|
|
2373
|
+
* // Update dinosaur status and habitat occupancy atomically
|
|
2374
|
+
* new UpdateBuilder(executor, 'dinosaurs', { id: 'TREX-001' })
|
|
2375
|
+
* .set('location', 'PADDOCK_A')
|
|
2376
|
+
* .set('status', 'CONTAINED')
|
|
2377
|
+
* .withTransaction(transaction);
|
|
2378
|
+
*
|
|
2379
|
+
* new UpdateBuilder(executor, 'habitats', { id: 'PADDOCK-A' })
|
|
2380
|
+
* .add('occupants', 1)
|
|
2381
|
+
* .set('lastOccupied', new Date().toISOString())
|
|
2382
|
+
* .withTransaction(transaction);
|
|
2383
|
+
*
|
|
2384
|
+
* // Execute all operations atomically
|
|
2385
|
+
* await transaction.execute();
|
|
2386
|
+
* ```
|
|
2387
|
+
*
|
|
2388
|
+
* @param transaction - The transaction builder to add this operation to
|
|
2389
|
+
* @returns The builder instance for method chaining
|
|
2390
|
+
*/
|
|
2391
|
+
withTransaction(transaction: TransactionBuilder): void;
|
|
2392
|
+
/**
|
|
2393
|
+
* Gets a human-readable representation of the update command.
|
|
2394
|
+
* Use this method when you need to:
|
|
2395
|
+
* - Debug complex update expressions
|
|
2396
|
+
* - Verify attribute names and values
|
|
2397
|
+
* - Log update operations
|
|
2398
|
+
* - Troubleshoot condition expressions
|
|
2399
|
+
*
|
|
2400
|
+
* @example
|
|
2401
|
+
* ```typescript
|
|
2402
|
+
* // Create complex update
|
|
2403
|
+
* const builder = new UpdateBuilder(executor, 'dinosaurs', { id: 'RAPTOR-001' })
|
|
2404
|
+
* .set({
|
|
2405
|
+
* status: 'HUNTING',
|
|
2406
|
+
* 'stats.health': 95,
|
|
2407
|
+
* 'behavior.lastObserved': new Date().toISOString()
|
|
2408
|
+
* })
|
|
2409
|
+
* .add('huntingSuccesses', 1)
|
|
2410
|
+
* .condition(op => op.gt('health', 50));
|
|
2411
|
+
*
|
|
2412
|
+
* // Debug the update
|
|
2413
|
+
* const debugInfo = builder.debug();
|
|
2414
|
+
* console.log('Update operation:', debugInfo);
|
|
2415
|
+
* ```
|
|
2416
|
+
*
|
|
2417
|
+
* @returns A readable representation of the update command with resolved expressions
|
|
2418
|
+
*/
|
|
2419
|
+
debug(): Record<string, unknown>;
|
|
2420
|
+
/**
|
|
2421
|
+
* Executes the update operation against DynamoDB.
|
|
2422
|
+
* Use this method when you need to:
|
|
2423
|
+
* - Apply updates immediately
|
|
2424
|
+
* - Get the updated item values
|
|
2425
|
+
* - Handle conditional update failures
|
|
2426
|
+
*
|
|
2427
|
+
* @example
|
|
2428
|
+
* ```typescript
|
|
2429
|
+
* try {
|
|
2430
|
+
* // Update dinosaur status with conditions
|
|
2431
|
+
* const result = await new UpdateBuilder(executor, 'dinosaurs', { id: 'TREX-001' })
|
|
2432
|
+
* .set({
|
|
2433
|
+
* status: 'FEEDING',
|
|
2434
|
+
* lastMeal: new Date().toISOString(),
|
|
2435
|
+
* 'stats.hunger': 0
|
|
2436
|
+
* })
|
|
2437
|
+
* .add('feedingCount', 1)
|
|
2438
|
+
* .condition(op =>
|
|
2439
|
+
* op.and([
|
|
2440
|
+
* op.gt('stats.hunger', 80),
|
|
2441
|
+
* op.eq('status', 'HUNTING')
|
|
2442
|
+
* ])
|
|
2443
|
+
* )
|
|
2444
|
+
* .returnValues('ALL_NEW')
|
|
2445
|
+
* .execute();
|
|
2446
|
+
*
|
|
2447
|
+
* if (result.item) {
|
|
2448
|
+
* console.log('Updated dinosaur:', result.item);
|
|
2449
|
+
* }
|
|
2450
|
+
* } catch (error) {
|
|
2451
|
+
* // Handle condition check failure
|
|
2452
|
+
* console.error('Failed to update dinosaur:', error);
|
|
2453
|
+
* // Check if dinosaur wasn't hungry enough
|
|
2454
|
+
* if (error.name === 'ConditionalCheckFailedException') {
|
|
2455
|
+
* console.log('Dinosaur not ready for feeding');
|
|
2456
|
+
* }
|
|
2457
|
+
* }
|
|
2458
|
+
* ```
|
|
2459
|
+
*
|
|
2460
|
+
* @returns A promise that resolves to an object containing the updated item (if returnValues is set)
|
|
2461
|
+
* @throws {ConditionalCheckFailedException} If the condition check fails
|
|
2462
|
+
* @throws {Error} If the update operation fails for other reasons
|
|
2463
|
+
*/
|
|
2464
|
+
execute(): Promise<{
|
|
2465
|
+
item?: T;
|
|
2466
|
+
}>;
|
|
2467
|
+
}
|
|
2468
|
+
|
|
2469
|
+
type BatchWriteOperation<T extends Record<string, unknown>> = {
|
|
2470
|
+
type: "put";
|
|
2471
|
+
item: T;
|
|
2472
|
+
} | {
|
|
2473
|
+
type: "delete";
|
|
2474
|
+
key: PrimaryKeyWithoutExpression;
|
|
2475
|
+
};
|
|
2476
|
+
|
|
2477
|
+
/**
|
|
2478
|
+
* Builder for creating DynamoDB condition check operations.
|
|
2479
|
+
* Use this builder when you need to:
|
|
2480
|
+
* - Verify item state without modifying it
|
|
2481
|
+
* - Ensure preconditions in transactions
|
|
2482
|
+
* - Implement optimistic locking patterns
|
|
2483
|
+
* - Validate business rules
|
|
2484
|
+
*
|
|
2485
|
+
* @example
|
|
2486
|
+
* ```typescript
|
|
2487
|
+
* // Check if dinosaur is ready for feeding
|
|
2488
|
+
* const check = new ConditionCheckBuilder('dinosaurs', { id: 'TREX-001' })
|
|
2489
|
+
* .condition(op =>
|
|
2490
|
+
* op.and([
|
|
2491
|
+
* op.eq('status', 'HUNTING'),
|
|
2492
|
+
* op.gt('stats.hunger', 80),
|
|
2493
|
+
* op.lt('stats.health', 100)
|
|
2494
|
+
* ])
|
|
2495
|
+
* )
|
|
2496
|
+
* .toDynamoCommand();
|
|
2497
|
+
*
|
|
2498
|
+
* // Check habitat security status
|
|
2499
|
+
* const securityCheck = new ConditionCheckBuilder('habitats', { id: 'PADDOCK-A' })
|
|
2500
|
+
* .condition(op =>
|
|
2501
|
+
* op.and([
|
|
2502
|
+
* op.eq('securityStatus', 'ACTIVE'),
|
|
2503
|
+
* op.attributeExists('lastInspection'),
|
|
2504
|
+
* op.lt('threatLevel', 5)
|
|
2505
|
+
* ])
|
|
2506
|
+
* )
|
|
2507
|
+
* .toDynamoCommand();
|
|
2508
|
+
* ```
|
|
2509
|
+
*/
|
|
2510
|
+
declare class ConditionCheckBuilder {
|
|
2511
|
+
private readonly key;
|
|
2512
|
+
private readonly tableName;
|
|
2513
|
+
private conditionExpression?;
|
|
2514
|
+
constructor(tableName: string, key: PrimaryKeyWithoutExpression);
|
|
2515
|
+
/**
|
|
2516
|
+
* Adds a condition that must be satisfied for the check to succeed.
|
|
2517
|
+
* Use this method when you need to:
|
|
2518
|
+
* - Validate complex item states
|
|
2519
|
+
* - Check multiple attributes together
|
|
2520
|
+
* - Ensure safety conditions are met
|
|
2521
|
+
*
|
|
2522
|
+
* @example
|
|
2523
|
+
* ```typescript
|
|
2524
|
+
* // Check dinosaur health and behavior
|
|
2525
|
+
* builder.condition(op =>
|
|
2526
|
+
* op.and([
|
|
2527
|
+
* op.gt('stats.health', 50),
|
|
2528
|
+
* op.not(op.eq('status', 'SEDATED')),
|
|
2529
|
+
* op.lt('aggressionLevel', 8)
|
|
2530
|
+
* ])
|
|
2531
|
+
* );
|
|
2532
|
+
*
|
|
2533
|
+
* // Verify habitat conditions
|
|
2534
|
+
* builder.condition(op =>
|
|
2535
|
+
* op.and([
|
|
2536
|
+
* op.eq('powerStatus', 'ONLINE'),
|
|
2537
|
+
* op.between('temperature', 20, 30),
|
|
2538
|
+
* op.attributeExists('lastMaintenance')
|
|
2539
|
+
* ])
|
|
2540
|
+
* );
|
|
2541
|
+
*
|
|
2542
|
+
* // Check breeding conditions
|
|
2543
|
+
* builder.condition(op =>
|
|
2544
|
+
* op.and([
|
|
2545
|
+
* op.eq('species', 'VELOCIRAPTOR'),
|
|
2546
|
+
* op.gte('age', 3),
|
|
2547
|
+
* op.eq('geneticPurity', 100)
|
|
2548
|
+
* ])
|
|
2549
|
+
* );
|
|
2550
|
+
* ```
|
|
2551
|
+
*
|
|
2552
|
+
* @param condition - Either a Condition object or a callback function that builds the condition
|
|
2553
|
+
* @returns The builder instance for method chaining
|
|
2554
|
+
*/
|
|
2555
|
+
condition<T extends Record<string, unknown>>(condition: Condition | ((op: ConditionOperator<T>) => Condition)): ConditionCheckBuilder;
|
|
2556
|
+
/**
|
|
2557
|
+
* Generates the DynamoDB command parameters for direct execution.
|
|
2558
|
+
* Use this method when you want to:
|
|
2559
|
+
* - Execute the condition check as a standalone operation
|
|
2560
|
+
* - Get the raw DynamoDB command for custom execution
|
|
2561
|
+
* - Inspect the generated command parameters
|
|
2562
|
+
*
|
|
2563
|
+
* @example
|
|
2564
|
+
* ```ts
|
|
2565
|
+
* const command = new ConditionCheckBuilder('myTable', { id: '123' })
|
|
2566
|
+
* .condition(op => op.attributeExists('status'))
|
|
2567
|
+
* .toDynamoCommand();
|
|
2568
|
+
* // Use command with DynamoDB client
|
|
2569
|
+
* ```
|
|
2570
|
+
*
|
|
2571
|
+
* @throws {Error} If no condition has been set
|
|
2572
|
+
* @returns The DynamoDB command parameters
|
|
2573
|
+
*/
|
|
2574
|
+
private toDynamoCommand;
|
|
2575
|
+
/**
|
|
2576
|
+
* Adds this condition check operation to a transaction.
|
|
2577
|
+
* Use this method when you need to:
|
|
2578
|
+
* - Verify habitat safety before transfers
|
|
2579
|
+
* - Ensure proper feeding conditions
|
|
2580
|
+
* - Validate security protocols
|
|
2581
|
+
*
|
|
2582
|
+
* @example
|
|
2583
|
+
* ```ts
|
|
2584
|
+
* const transaction = new TransactionBuilder();
|
|
2585
|
+
* new ConditionCheckBuilder('habitats', { id: 'PADDOCK-B' })
|
|
2586
|
+
* .condition(op => op.and([
|
|
2587
|
+
* op.eq('securityStatus', 'ACTIVE'),
|
|
2588
|
+
* op.lt('currentOccupants', 3),
|
|
2589
|
+
* op.eq('habitatType', 'CARNIVORE')
|
|
2590
|
+
* ]))
|
|
2591
|
+
* .withTransaction(transaction);
|
|
2592
|
+
* // Add dinosaur transfer operations
|
|
2593
|
+
* ```
|
|
2594
|
+
*
|
|
2595
|
+
* @param transaction - The transaction builder to add this operation to
|
|
2596
|
+
* @throws {Error} If no condition has been set
|
|
2597
|
+
* @returns The builder instance for method chaining
|
|
2598
|
+
*/
|
|
2599
|
+
withTransaction(transaction: TransactionBuilder): ConditionCheckBuilder;
|
|
2600
|
+
/**
|
|
2601
|
+
* Gets a human-readable representation of the condition check command
|
|
2602
|
+
* with all expression placeholders replaced by their actual values.
|
|
2603
|
+
* Use this method when you need to:
|
|
2604
|
+
* - Debug complex condition expressions
|
|
2605
|
+
* - Verify condition parameters
|
|
2606
|
+
* - Log safety checks
|
|
2607
|
+
* - Troubleshoot condition failures
|
|
2608
|
+
*
|
|
2609
|
+
* @example
|
|
2610
|
+
* ```ts
|
|
2611
|
+
* const debugInfo = new ConditionCheckBuilder('dinosaurs', { id: 'TREX-001' })
|
|
2612
|
+
* .condition(op => op.and([
|
|
2613
|
+
* op.between('stats.health', 50, 100),
|
|
2614
|
+
* op.not(op.eq('status', 'SEDATED')),
|
|
2615
|
+
* op.attributeExists('lastFeedingTime')
|
|
2616
|
+
* op.eq('version', 1)
|
|
2617
|
+
* ]))
|
|
2618
|
+
* .debug();
|
|
2619
|
+
* console.log(debugInfo);
|
|
2620
|
+
* ```
|
|
2621
|
+
*
|
|
2622
|
+
* @returns A readable representation of the condition check command with resolved expressions
|
|
2623
|
+
*/
|
|
2624
|
+
debug(): Record<string, unknown>;
|
|
2625
|
+
}
|
|
2626
|
+
|
|
2627
|
+
/**
|
|
2628
|
+
* Parameters for the DynamoDB get command.
|
|
2629
|
+
*/
|
|
2630
|
+
interface GetCommandParams {
|
|
2631
|
+
/** The name of the DynamoDB table */
|
|
2632
|
+
tableName: string;
|
|
2633
|
+
/** The primary key of the item to get */
|
|
2634
|
+
key: PrimaryKeyWithoutExpression;
|
|
2635
|
+
/** Comma-separated list of attributes to return */
|
|
2636
|
+
projectionExpression?: string;
|
|
2637
|
+
/** Map of expression attribute name placeholders to actual names */
|
|
2638
|
+
expressionAttributeNames?: Record<string, string>;
|
|
2639
|
+
/** Whether to use strongly consistent reads */
|
|
2640
|
+
consistentRead?: boolean;
|
|
2641
|
+
}
|
|
2642
|
+
/**
|
|
2643
|
+
* Function type for executing DynamoDB get operations.
|
|
2644
|
+
* @typeParam T - The type of item being retrieved
|
|
2645
|
+
*/
|
|
2646
|
+
type GetExecutor<T extends Record<string, unknown>> = (params: GetCommandParams) => Promise<{
|
|
2647
|
+
item: T | undefined;
|
|
2648
|
+
}>;
|
|
2649
|
+
/**
|
|
2650
|
+
* Builder for creating DynamoDB get operations.
|
|
2651
|
+
* Use this builder when you need to:
|
|
2652
|
+
* - Retrieve a single dinosaur by its primary key
|
|
2653
|
+
* - Project specific dinosaur attributes
|
|
2654
|
+
* - Use consistent reads for critical dinosaur data
|
|
2655
|
+
*
|
|
2656
|
+
* @example
|
|
2657
|
+
* ```typescript
|
|
2658
|
+
* // Simple get
|
|
2659
|
+
* const result = await new GetBuilder(executor, { pk: 'dinosaur#123', sk: 'profile' })
|
|
2660
|
+
* .execute();
|
|
2661
|
+
*
|
|
2662
|
+
* // Get with projection and consistent read
|
|
2663
|
+
* const result = await new GetBuilder(executor, { pk: 'dinosaur#123', sk: 'profile' })
|
|
2664
|
+
* .select(['species', 'name', 'diet'])
|
|
2665
|
+
* .consistentRead()
|
|
2666
|
+
* .execute();
|
|
2667
|
+
* ```
|
|
2668
|
+
*
|
|
2669
|
+
* @typeParam T - The type of item being retrieved
|
|
2670
|
+
*/
|
|
2671
|
+
declare class GetBuilder<T extends Record<string, unknown>> {
|
|
2672
|
+
private readonly executor;
|
|
2673
|
+
private readonly params;
|
|
2674
|
+
private options;
|
|
2675
|
+
private selectedFields;
|
|
2676
|
+
/**
|
|
2677
|
+
* Creates a new GetBuilder instance.
|
|
2678
|
+
*
|
|
2679
|
+
* @param executor - Function that executes the get operation
|
|
2680
|
+
* @param key - Primary key of the item to retrieve
|
|
2681
|
+
* @param tableName - Name of the DynamoDB table
|
|
2682
|
+
*/
|
|
2683
|
+
constructor(executor: GetExecutor<T>, key: PrimaryKeyWithoutExpression, tableName: string);
|
|
2684
|
+
/**
|
|
2685
|
+
* Specifies which attributes to return in the get results.
|
|
2686
|
+
* Use this method when you need to:
|
|
2687
|
+
* - Reduce data transfer by selecting specific dinosaur attributes
|
|
2688
|
+
* - Optimize response size for dinosaur records
|
|
2689
|
+
* - Focus on relevant dinosaur characteristics only
|
|
2690
|
+
*
|
|
2691
|
+
* @example
|
|
2692
|
+
* ```typescript
|
|
2693
|
+
* // Select single attribute
|
|
2694
|
+
* builder.select('species')
|
|
2695
|
+
*
|
|
2696
|
+
* // Select multiple attributes
|
|
2697
|
+
* builder.select(['id', 'species', 'diet'])
|
|
2698
|
+
*
|
|
2699
|
+
* // Chain multiple select calls
|
|
2700
|
+
* builder
|
|
2701
|
+
* .select('id')
|
|
2702
|
+
* .select(['species', 'diet'])
|
|
2703
|
+
* ```
|
|
2704
|
+
*
|
|
2705
|
+
* @param fields - A single field name or an array of field names to return
|
|
2706
|
+
* @returns The builder instance for method chaining
|
|
2707
|
+
*/
|
|
2708
|
+
select(fields: string | string[]): GetBuilder<T>;
|
|
2709
|
+
/**
|
|
2710
|
+
* Sets whether to use strongly consistent reads for the get operation.
|
|
2711
|
+
* Use this method when you need:
|
|
2712
|
+
* - The most up-to-date dinosaur data
|
|
2713
|
+
* - To ensure you're reading the latest dinosaur status
|
|
2714
|
+
* - Critical safety information about dangerous species
|
|
2715
|
+
*
|
|
2716
|
+
* Note: Consistent reads consume twice the throughput
|
|
2717
|
+
*
|
|
2718
|
+
* @example
|
|
2719
|
+
* ```typescript
|
|
2720
|
+
* // Get the latest T-Rex data
|
|
2721
|
+
* const result = await new GetBuilder(executor, { pk: 'dinosaur#123', sk: 'profile' })
|
|
2722
|
+
* .consistentRead()
|
|
2723
|
+
* .execute();
|
|
2724
|
+
* ```
|
|
2725
|
+
*
|
|
2726
|
+
* @param consistentRead - Whether to use consistent reads (defaults to true)
|
|
2727
|
+
* @returns The builder instance for method chaining
|
|
2728
|
+
*/
|
|
2729
|
+
consistentRead(consistentRead?: boolean): GetBuilder<T>;
|
|
2730
|
+
/**
|
|
2731
|
+
* Executes the get operation against DynamoDB.
|
|
2732
|
+
*
|
|
2733
|
+
* @example
|
|
2734
|
+
* ```typescript
|
|
2735
|
+
* try {
|
|
2736
|
+
* const result = await new GetBuilder(executor, { pk: 'dinosaur#123', sk: 'profile' })
|
|
2737
|
+
* .select(['species', 'name', 'diet'])
|
|
2738
|
+
* .consistentRead()
|
|
2739
|
+
* .execute();
|
|
2740
|
+
*
|
|
2741
|
+
* if (result.item) {
|
|
2742
|
+
* console.log('Dinosaur found:', result.item);
|
|
2743
|
+
* } else {
|
|
2744
|
+
* console.log('Dinosaur not found');
|
|
2745
|
+
* }
|
|
2746
|
+
* } catch (error) {
|
|
2747
|
+
* console.error('Error getting dinosaur:', error);
|
|
2748
|
+
* }
|
|
2749
|
+
* ```
|
|
2750
|
+
*
|
|
2751
|
+
* @returns A promise that resolves to an object containing:
|
|
2752
|
+
* - item: The retrieved dinosaur or undefined if not found
|
|
2753
|
+
*/
|
|
2754
|
+
execute(): Promise<{
|
|
2755
|
+
item: T | undefined;
|
|
2756
|
+
}>;
|
|
2757
|
+
}
|
|
2758
|
+
|
|
2759
|
+
/**
|
|
2760
|
+
* Configuration options for DynamoDB scan operations.
|
|
2761
|
+
* Extends the base FilterOptions.
|
|
2762
|
+
*/
|
|
2763
|
+
type ScanOptions = FilterOptions;
|
|
2764
|
+
/**
|
|
2765
|
+
* Function type for executing DynamoDB filter operations.
|
|
2766
|
+
* @typeParam T - The type of items being filtered
|
|
2767
|
+
*/
|
|
2768
|
+
type ScanExecutor<T extends Record<string, unknown>> = (options: ScanOptions) => Promise<{
|
|
2769
|
+
items: T[];
|
|
2770
|
+
lastEvaluatedKey?: Record<string, unknown>;
|
|
2771
|
+
}>;
|
|
2772
|
+
/**
|
|
2773
|
+
* Builder for creating DynamoDB scan operations.
|
|
2774
|
+
* Use this builder when you need to:
|
|
2775
|
+
* - Scan all items in a table
|
|
2776
|
+
* - Filter results based on non-key attributes
|
|
2777
|
+
* - Scan items on a Secondary Index (GSI)
|
|
2778
|
+
* - Implement pagination
|
|
2779
|
+
* - Project specific attributes
|
|
2780
|
+
*
|
|
2781
|
+
* The builder supports:
|
|
2782
|
+
* - Type-safe GSI selection
|
|
2783
|
+
* - Complex filter conditions
|
|
2784
|
+
* - Automatic pagination handling
|
|
2785
|
+
* - Consistent reads
|
|
2786
|
+
* - Attribute projection
|
|
2787
|
+
*
|
|
2788
|
+
* @example
|
|
2789
|
+
* ```typescript
|
|
2790
|
+
* // Simple scan with filtering
|
|
2791
|
+
* const result = await new ScanBuilder(executor)
|
|
2792
|
+
* .filter(op => op.eq('status', 'ACTIVE'))
|
|
2793
|
+
* .execute();
|
|
2794
|
+
*
|
|
2795
|
+
* // Scan with GSI and filtering
|
|
2796
|
+
* const result = await new ScanBuilder(executor)
|
|
2797
|
+
* .useIndex('status-index')
|
|
2798
|
+
* .filter(op => op.gt('securityLevel', 8))
|
|
2799
|
+
* .select(['id', 'capacity', 'currentOccupants'])
|
|
2800
|
+
* .limit(10)
|
|
2801
|
+
* .execute();
|
|
2802
|
+
*
|
|
2803
|
+
* // Scan with pagination
|
|
2804
|
+
* const paginator = new ScanBuilder(executor)
|
|
2805
|
+
* .filter(op => op.eq('type', 'INCIDENT'))
|
|
2806
|
+
* .paginate(25);
|
|
2807
|
+
*
|
|
2808
|
+
* while (paginator.hasNextPage()) {
|
|
2809
|
+
* const page = await paginator.getNextPage();
|
|
2810
|
+
* // Process page.items
|
|
2811
|
+
* }
|
|
2812
|
+
* ```
|
|
2813
|
+
*
|
|
2814
|
+
* @typeParam T - The type of items being scanned
|
|
2815
|
+
* @typeParam TConfig - The table configuration type for type-safe GSI selection
|
|
2816
|
+
*/
|
|
2817
|
+
declare class ScanBuilder<T extends Record<string, unknown>, TConfig extends TableConfig = TableConfig> extends FilterBuilder<T, TConfig> implements ScanBuilderInterface<T, TConfig> {
|
|
2818
|
+
protected readonly executor: ScanExecutor<T>;
|
|
2819
|
+
constructor(executor: ScanExecutor<T>);
|
|
2820
|
+
/**
|
|
2821
|
+
* Creates a deep clone of this ScanBuilder instance.
|
|
2822
|
+
* Use this method when you need to:
|
|
2823
|
+
* - Create scan templates
|
|
2824
|
+
* - Run multiple variations of a scan
|
|
2825
|
+
* - Implement pagination (used internally by paginate())
|
|
2826
|
+
*
|
|
2827
|
+
* @returns A new ScanBuilder instance with the same configuration
|
|
2828
|
+
*/
|
|
2829
|
+
clone(): ScanBuilder<T, TConfig>;
|
|
2830
|
+
/**
|
|
2831
|
+
* Executes the scan against DynamoDB.
|
|
2832
|
+
* Use this method when you need to:
|
|
2833
|
+
* - Search across the entire table
|
|
2834
|
+
* - Find items matching specific criteria
|
|
2835
|
+
* - Perform full table analysis
|
|
2836
|
+
* - Generate reports across all data
|
|
2837
|
+
*
|
|
2838
|
+
* The method returns both the matched items and, if there are more results,
|
|
2839
|
+
* a lastEvaluatedKey that can be used with startFrom() to continue the scan.
|
|
2840
|
+
*
|
|
2841
|
+
* @example
|
|
2842
|
+
* ```typescript
|
|
2843
|
+
* try {
|
|
2844
|
+
* // Find all dinosaurs with high aggression levels
|
|
2845
|
+
* const result = await new ScanBuilder(executor)
|
|
2846
|
+
* .filter(op =>
|
|
2847
|
+
* op.and([
|
|
2848
|
+
* op.eq('status', 'ACTIVE'),
|
|
2849
|
+
* op.gt('aggressionLevel', 7)
|
|
2850
|
+
* ])
|
|
2851
|
+
* )
|
|
2852
|
+
* .limit(20)
|
|
2853
|
+
* .execute();
|
|
2854
|
+
*
|
|
2855
|
+
* console.log(`Found ${result.items.length} potentially dangerous dinosaurs`);
|
|
2856
|
+
*
|
|
2857
|
+
* if (result.lastEvaluatedKey) {
|
|
2858
|
+
* console.log('More results available');
|
|
2859
|
+
* }
|
|
2860
|
+
* } catch (error) {
|
|
2861
|
+
* console.error('Security scan failed:', error);
|
|
2862
|
+
* }
|
|
2863
|
+
* ```
|
|
2864
|
+
*
|
|
2865
|
+
* @returns A promise that resolves to an object containing:
|
|
2866
|
+
* - items: Array of items matching the scan criteria
|
|
2867
|
+
* - lastEvaluatedKey: Token for continuing the scan, if more items exist
|
|
2868
|
+
*/
|
|
2869
|
+
execute(): Promise<{
|
|
2870
|
+
items: T[];
|
|
2871
|
+
lastEvaluatedKey?: Record<string, unknown>;
|
|
2872
|
+
}>;
|
|
2873
|
+
}
|
|
2874
|
+
|
|
2875
|
+
declare class Table<TConfig extends TableConfig = TableConfig> {
|
|
2876
|
+
private readonly dynamoClient;
|
|
2877
|
+
readonly tableName: string;
|
|
2878
|
+
/**
|
|
2879
|
+
* The column name of the partitionKey for the Table
|
|
2880
|
+
*/
|
|
2881
|
+
readonly partitionKey: string;
|
|
2882
|
+
/**
|
|
2883
|
+
* The column name of the sortKey for the Table
|
|
2884
|
+
*/
|
|
2885
|
+
readonly sortKey?: string;
|
|
2886
|
+
/**
|
|
2887
|
+
* The Global Secondary Indexes that are configured on this table
|
|
2888
|
+
*/
|
|
2889
|
+
readonly gsis: Record<string, Index>;
|
|
2890
|
+
constructor(config: TConfig);
|
|
2891
|
+
/**
|
|
2892
|
+
* Creates a new item in the table, it will fail if the item already exists
|
|
2893
|
+
*
|
|
2894
|
+
* @param item The item to create
|
|
2895
|
+
* @returns A PutBuilder instance for chaining conditions and executing the put operation
|
|
2896
|
+
*/
|
|
2897
|
+
create<T extends Record<string, unknown>>(item: T): PutBuilder<T>;
|
|
2898
|
+
get<T extends Record<string, unknown>>(keyCondition: PrimaryKeyWithoutExpression): GetBuilder<T>;
|
|
2899
|
+
/**
|
|
2900
|
+
* Updates an item in the table
|
|
2901
|
+
*
|
|
2902
|
+
* @param item The item to update
|
|
2903
|
+
* @returns A PutBuilder instance for chaining conditions and executing the put operation
|
|
2904
|
+
*/
|
|
2905
|
+
put<T extends Record<string, unknown>>(item: T): PutBuilder<T>;
|
|
2906
|
+
/**
|
|
2907
|
+
* Creates a query builder for complex queries
|
|
2908
|
+
* If useIndex is called on the returned QueryBuilder, it will use the GSI configuration
|
|
2909
|
+
*/
|
|
2910
|
+
query<T extends Record<string, unknown>>(keyCondition: PrimaryKey): QueryBuilder<T, TConfig>;
|
|
2911
|
+
/**
|
|
2912
|
+
* Creates a scan builder for scanning the entire table
|
|
2913
|
+
* Use this when you need to:
|
|
2914
|
+
* - Process all items in a table
|
|
2915
|
+
* - Apply filters to a large dataset
|
|
2916
|
+
* - Use a GSI for scanning
|
|
2917
|
+
*
|
|
2918
|
+
* @returns A ScanBuilder instance for chaining operations
|
|
2919
|
+
*/
|
|
2920
|
+
scan<T extends Record<string, unknown>>(): ScanBuilder<T, TConfig>;
|
|
2921
|
+
delete(keyCondition: PrimaryKeyWithoutExpression): DeleteBuilder;
|
|
2922
|
+
/**
|
|
2923
|
+
* Updates an item in the table
|
|
2924
|
+
*
|
|
2925
|
+
* @param keyCondition The primary key of the item to update
|
|
2926
|
+
* @returns An UpdateBuilder instance for chaining update operations and conditions
|
|
2927
|
+
*/
|
|
2928
|
+
update<T extends Record<string, unknown>>(keyCondition: PrimaryKeyWithoutExpression): UpdateBuilder<T>;
|
|
2929
|
+
/**
|
|
2930
|
+
* Creates a transaction builder for performing multiple operations atomically
|
|
2931
|
+
*/
|
|
2932
|
+
transactionBuilder(): TransactionBuilder;
|
|
2933
|
+
/**
|
|
2934
|
+
* Executes a transaction using a callback function
|
|
2935
|
+
*
|
|
2936
|
+
* @param callback A function that receives a transaction context and performs operations on it
|
|
2937
|
+
* @param options Optional transaction options
|
|
2938
|
+
* @returns A promise that resolves when the transaction is complete
|
|
2939
|
+
*/
|
|
2940
|
+
transaction<T>(callback: (tx: TransactionBuilder) => Promise<T>, options?: TransactionOptions): Promise<T>;
|
|
2941
|
+
/**
|
|
2942
|
+
* Creates a condition check operation for use in transactions
|
|
2943
|
+
*
|
|
2944
|
+
* This is useful for when you require a transaction to succeed only when a specific condition is met on a
|
|
2945
|
+
* a record within the database that you are not directly updating.
|
|
2946
|
+
*
|
|
2947
|
+
* For example, you are updating a record and you want to ensure that another record exists and/or has a specific value before proceeding.
|
|
2948
|
+
*/
|
|
2949
|
+
conditionCheck(keyCondition: PrimaryKeyWithoutExpression): ConditionCheckBuilder;
|
|
2950
|
+
/**
|
|
2951
|
+
* Performs a batch get operation to retrieve multiple items at once
|
|
2952
|
+
*
|
|
2953
|
+
* @param keys Array of primary keys to retrieve
|
|
2954
|
+
* @returns A promise that resolves to the retrieved items
|
|
2955
|
+
*/
|
|
2956
|
+
batchGet<T extends Record<string, unknown>>(keys: Array<PrimaryKeyWithoutExpression>): Promise<{
|
|
2957
|
+
items: T[];
|
|
2958
|
+
unprocessedKeys: PrimaryKeyWithoutExpression[];
|
|
2959
|
+
}>;
|
|
2960
|
+
/**
|
|
2961
|
+
* Performs a batch write operation to put or delete multiple items at once
|
|
2962
|
+
*
|
|
2963
|
+
* @param operations Array of put or delete operations
|
|
2964
|
+
* @returns A promise that resolves to any unprocessed operations
|
|
2965
|
+
*/
|
|
2966
|
+
batchWrite<T extends Record<string, unknown>>(operations: Array<BatchWriteOperation<T>>): Promise<{
|
|
2967
|
+
unprocessedItems: Array<BatchWriteOperation<T>>;
|
|
2968
|
+
}>;
|
|
2969
|
+
}
|
|
2970
|
+
|
|
2971
|
+
export { type ComparisonOperator, type Condition, ConditionCheckBuilder, type ConditionOperator, DeleteBuilder, type DeleteOptions, type EntityConfig, type ExpressionParams, type GSINames, type Index, type KeyConditionOperator, type LogicalOperator, Paginator, type PrimaryKey, type PrimaryKeyWithoutExpression, PutBuilder, type PutOptions, QueryBuilder, type QueryOptions, Table, type TableConfig, TransactionBuilder, type TransactionExecutor, type TransactionOptions, type UpdateAction, UpdateBuilder, type UpdateOptions, and, attributeExists, attributeNotExists, beginsWith, between, contains, createComparisonCondition, eq, gt, gte, lt, lte, ne, not, or };
|