dyno-table 2.5.1 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/dist/builders/batch-builder.d.ts +249 -0
  2. package/dist/builders/builder-types.d.ts +123 -0
  3. package/dist/builders/condition-check-builder.d.ts +149 -0
  4. package/dist/builders/delete-builder.d.ts +208 -0
  5. package/dist/builders/entity-aware-builders.d.ts +127 -0
  6. package/dist/builders/filter-builder.d.ts +294 -0
  7. package/dist/builders/get-builder.d.ts +191 -0
  8. package/dist/builders/index.d.ts +14 -0
  9. package/dist/builders/paginator.d.ts +151 -0
  10. package/dist/builders/put-builder.d.ts +317 -0
  11. package/dist/builders/query-builder.d.ts +218 -0
  12. package/dist/builders/result-iterator.d.ts +55 -0
  13. package/dist/builders/scan-builder.d.ts +109 -0
  14. package/dist/builders/transaction-builder.d.ts +462 -0
  15. package/dist/builders/types.d.ts +25 -0
  16. package/dist/builders/update-builder.d.ts +372 -0
  17. package/dist/builders.d.ts +1 -4
  18. package/dist/{chunk-U6MQGB6Y.js → chunk-JZB6TYST.js} +133 -136
  19. package/dist/{chunk-ZXM6LPRV.cjs → chunk-Z334X72N.cjs} +133 -136
  20. package/dist/conditions.d.ts +705 -3
  21. package/dist/entity/ddb-indexing.d.ts +45 -0
  22. package/dist/entity/entity.d.ts +188 -0
  23. package/dist/entity/index-utils.d.ts +24 -0
  24. package/dist/entity.cjs +4 -4
  25. package/dist/entity.d.ts +1 -261
  26. package/dist/entity.js +1 -1
  27. package/dist/errors.d.ts +212 -0
  28. package/dist/expression.d.ts +9 -0
  29. package/dist/index-definition.d.ts +10 -0
  30. package/dist/index.cjs +25 -25
  31. package/dist/index.d.ts +16 -273
  32. package/dist/index.js +1 -1
  33. package/dist/operation-types.d.ts +8 -0
  34. package/dist/standard-schema.d.ts +2 -4
  35. package/dist/table.d.ts +13 -8
  36. package/dist/types.d.ts +6 -9
  37. package/dist/utils/chunk-array.d.ts +9 -0
  38. package/dist/utils/debug-expression.d.ts +32 -0
  39. package/dist/utils/debug-transaction.d.ts +17 -0
  40. package/dist/utils/error-factory.d.ts +162 -0
  41. package/dist/utils/error-utils.d.ts +170 -0
  42. package/dist/utils/index.d.ts +7 -0
  43. package/dist/utils/partition-key-template.d.ts +30 -0
  44. package/dist/utils/sort-key-template.d.ts +33 -0
  45. package/dist/utils.d.ts +1 -66
  46. package/package.json +12 -10
  47. package/dist/builders.d.cts +0 -4
  48. package/dist/conditions-BSAcZswY.d.ts +0 -731
  49. package/dist/conditions-C8bM__Pn.d.cts +0 -731
  50. package/dist/conditions.d.cts +0 -3
  51. package/dist/entity.d.cts +0 -261
  52. package/dist/index-Bc-ra0im.d.ts +0 -3042
  53. package/dist/index-CPCmWsEv.d.cts +0 -3042
  54. package/dist/index.d.cts +0 -273
  55. package/dist/standard-schema.d.cts +0 -57
  56. package/dist/table.d.cts +0 -165
  57. package/dist/types.d.cts +0 -29
  58. package/dist/utils.d.cts +0 -66
@@ -1,731 +0,0 @@
1
- import { DynamoItem } from './types.js';
2
-
3
- type Primitive = null | undefined | string | number | boolean | symbol | bigint;
4
- type IsEqual<T1, T2> = T1 extends T2 ? (<G>() => G extends T1 ? 1 : 2) extends <G>() => G extends T2 ? 1 : 2 ? true : false : false;
5
- interface File extends Blob {
6
- readonly lastModified: number;
7
- readonly name: string;
8
- }
9
- interface FileList {
10
- readonly length: number;
11
- item(index: number): File | null;
12
- [index: number]: File;
13
- }
14
- type BrowserNativeObject = Date | FileList | File;
15
- type IsTuple<T extends ReadonlyArray<any>> = number extends T["length"] ? false : true;
16
- type TupleKeys<T extends ReadonlyArray<any>> = Exclude<keyof T, keyof any[]>;
17
- type AnyIsEqual<T1, T2> = T1 extends T2 ? (IsEqual<T1, T2> extends true ? true : never) : never;
18
- 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>}`;
19
- type ArrayKey = number;
20
- type PathInternal<T, TraversedTypes = T> = T extends ReadonlyArray<infer V> ? IsTuple<T> extends true ? {
21
- [K in TupleKeys<T>]-?: PathImpl<K & string, T[K], TraversedTypes>;
22
- }[TupleKeys<T>] : PathImpl<ArrayKey, V, TraversedTypes> : {
23
- [K in keyof T]-?: PathImpl<K & string, T[K], TraversedTypes>;
24
- }[keyof T];
25
- type Path<T> = T extends any ? PathInternal<T> : never;
26
- type PathType<T, K extends keyof any> = K extends `${infer Key}.${infer Rest}` ? Key extends keyof T ? Rest extends keyof any ? PathType<NonNullable<T[Key]>, Rest> : never : never : K extends keyof T ? T[K] : never;
27
-
28
- /**
29
- * Supported comparison operators for DynamoDB conditions.
30
- * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html AWS DynamoDB - Comparison Operator Reference}
31
- *
32
- * - eq: Equals (=)
33
- * - ne: Not equals (≠ / <>)
34
- * - lt: Less than (<)
35
- * - lte: Less than or equal to (≤)
36
- * - gt: Greater than (>)
37
- * - gte: Greater than or equal to (≥)
38
- * - between: Between two values (inclusive)
39
- * - in: Checks if attribute value is in a list of values
40
- * - beginsWith: Checks if string attribute begins with specified substring
41
- * - contains: Checks if string/set attribute contains specified value
42
- * - attributeExists: Checks if attribute exists
43
- * - attributeNotExists: Checks if attribute does not exist
44
- */
45
- type ComparisonOperator = "eq" | "ne" | "lt" | "lte" | "gt" | "gte" | "between" | "in" | "beginsWith" | "contains" | "attributeExists" | "attributeNotExists";
46
- /**
47
- * Logical operators for combining multiple conditions.
48
- * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Logical AWS DynamoDB - Logical Operator Reference}
49
- *
50
- * - and: Evaluates to true if all conditions are true
51
- * - or: Evaluates to true if any condition is true
52
- * - not: Negate the result of a condition
53
- */
54
- type LogicalOperator = "and" | "or" | "not";
55
- /**
56
- * Represents a DynamoDB condition expression.
57
- * Can be either a comparison condition or a logical combination of conditions.
58
- *
59
- * @example
60
- * // Simple comparison condition
61
- * const condition: Condition = {
62
- * type: "eq",
63
- * attr: "status",
64
- * value: "ACTIVE"
65
- * };
66
- *
67
- * @example
68
- * // Logical combination of conditions
69
- * const condition: Condition = {
70
- * type: "and",
71
- * conditions: [
72
- * { type: "eq", attr: "status", value: "ACTIVE" },
73
- * { type: "gt", attr: "age", value: 5 }
74
- * ]
75
- * };
76
- */
77
- interface Condition {
78
- /** The type of condition (comparison or logical operator) */
79
- type: ComparisonOperator | LogicalOperator;
80
- /** The attribute name for comparison conditions */
81
- attr?: string;
82
- /** The value to compare against for comparison conditions */
83
- value?: unknown;
84
- /** Array of conditions for logical operators (and/or) */
85
- conditions?: Condition[];
86
- /** Single condition for the 'not' operator */
87
- condition?: Condition;
88
- }
89
- /**
90
- * Parameters used to build DynamoDB expression strings.
91
- * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.ExpressionAttributeNames.html Expression Attribute Names}
92
- * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.ExpressionAttributeValues.html Expression Attribute Values}
93
- */
94
- interface ExpressionParams {
95
- /** Map of attribute name placeholders to actual attribute names */
96
- expressionAttributeNames: Record<string, string>;
97
- /** Map of value placeholders to actual values */
98
- expressionAttributeValues: DynamoItem;
99
- /** Counter for generating unique value placeholders */
100
- valueCounter: {
101
- count: number;
102
- };
103
- }
104
- /**
105
- * Creates a comparison condition builder function for the specified operator.
106
- * @internal
107
- */
108
- declare const createComparisonCondition: (type: ComparisonOperator) => (attr: string, value: unknown) => Condition;
109
- /**
110
- * Creates an equals (=) condition
111
- * @example
112
- * eq("status", "ACTIVE") // status = "ACTIVE"
113
- * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html}
114
- */
115
- declare const eq: (attr: string, value: unknown) => Condition;
116
- /**
117
- * Creates a not equals (≠) condition
118
- * @example
119
- * ne("status", "DELETED") // status <> "DELETED"
120
- * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html}
121
- */
122
- declare const ne: (attr: string, value: unknown) => Condition;
123
- /**
124
- * Creates a less than (<) condition
125
- * @example
126
- * lt("age", 18) // age < 18
127
- * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html}
128
- */
129
- declare const lt: (attr: string, value: unknown) => Condition;
130
- /**
131
- * Creates a less than or equal to (≤) condition
132
- * @example
133
- * lte("age", 18) // age <= 18
134
- * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html}
135
- */
136
- declare const lte: (attr: string, value: unknown) => Condition;
137
- /**
138
- * Creates a greater than (>) condition
139
- * @example
140
- * gt("price", 100) // price > 100
141
- * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html}
142
- */
143
- declare const gt: (attr: string, value: unknown) => Condition;
144
- /**
145
- * Creates a greater than or equal to (≥) condition
146
- * @example
147
- * gte("price", 100) // price >= 100
148
- * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html}
149
- */
150
- declare const gte: (attr: string, value: unknown) => Condition;
151
- /**
152
- * Creates a between condition that checks if a value is within a range (inclusive)
153
- * @example
154
- * between("age", 18, 65) // age BETWEEN 18 AND 65
155
- * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Comparators AWS DynamoDB - BETWEEN}
156
- */
157
- declare const between: (attr: string, lower: unknown, upper: unknown) => Condition;
158
- /**
159
- * Creates an in condition that checks if a value is in a list of values
160
- * @example
161
- * inArray("status", ["ACTIVE", "PENDING", "PROCESSING"]) // status IN ("ACTIVE", "PENDING", "PROCESSING")
162
- * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Comparators AWS DynamoDB - IN}
163
- */
164
- declare const inArray: (attr: string, values: unknown[]) => Condition;
165
- /**
166
- * Creates a begins_with condition that checks if a string attribute starts with a substring
167
- * @example
168
- * beginsWith("email", "@example.com") // begins_with(email, "@example.com")
169
- * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions AWS DynamoDB - begins_with}
170
- */
171
- declare const beginsWith: (attr: string, value: unknown) => Condition;
172
- /**
173
- * Creates a contains condition that checks if a string contains a substring or if a set contains an element
174
- * @example
175
- * contains("tags", "important") // contains(tags, "important")
176
- * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions AWS DynamoDB - contains}
177
- */
178
- declare const contains: (attr: string, value: unknown) => Condition;
179
- /**
180
- * Creates a condition that checks if an attribute exists
181
- * @example
182
- * attributeExists("email") // attribute_exists(email)
183
- * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions AWS DynamoDB - attribute_exists}
184
- */
185
- declare const attributeExists: (attr: string) => Condition;
186
- /**
187
- * Creates a condition that checks if an attribute does not exist
188
- * @example
189
- * attributeNotExists("deletedAt") // attribute_not_exists(deletedAt)
190
- * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions AWS DynamoDB - attribute_not_exists}
191
- */
192
- declare const attributeNotExists: (attr: string) => Condition;
193
- /**
194
- * Combines multiple conditions with AND operator
195
- * @example
196
- * and(
197
- * eq("status", "ACTIVE"),
198
- * gt("age", 18)
199
- * ) // status = "ACTIVE" AND age > 18
200
- * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Logical AWS DynamoDB - AND}
201
- */
202
- declare const and: (...conditions: Condition[]) => Condition;
203
- /**
204
- * Combines multiple conditions with OR operator
205
- * @example
206
- * or(
207
- * eq("status", "PENDING"),
208
- * eq("status", "PROCESSING")
209
- * ) // status = "PENDING" OR status = "PROCESSING"
210
- * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Logical AWS DynamoDB - OR}
211
- */
212
- declare const or: (...conditions: Condition[]) => Condition;
213
- /**
214
- * Negates a condition
215
- * @example
216
- * not(eq("status", "DELETED")) // NOT status = "DELETED"
217
- * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Logical AWS DynamoDB - NOT}
218
- */
219
- declare const not: (condition: Condition) => Condition;
220
- /**
221
- * Type-safe operators for building key conditions in DynamoDB queries.
222
- * Only includes operators that are valid for key conditions.
223
- * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Query.html#Query.KeyConditionExpressions AWS DynamoDB - Key Condition Expressions}
224
- *
225
- * @example
226
- * // Using with sort key conditions
227
- * table.query({
228
- * pk: "USER#123",
229
- * sk: op => op.beginsWith("ORDER#")
230
- * })
231
- */
232
- type KeyConditionOperator = {
233
- /** Equals comparison for key attributes */
234
- eq: (value: unknown) => Condition;
235
- /** Less than comparison for key attributes */
236
- lt: (value: unknown) => Condition;
237
- /** Less than or equal comparison for key attributes */
238
- lte: (value: unknown) => Condition;
239
- /** Greater than comparison for key attributes */
240
- gt: (value: unknown) => Condition;
241
- /** Greater than or equal comparison for key attributes */
242
- gte: (value: unknown) => Condition;
243
- /** Between range comparison for key attributes */
244
- between: (lower: unknown, upper: unknown) => Condition;
245
- /** Begins with comparison for key attributes */
246
- beginsWith: (value: unknown) => Condition;
247
- /** Combines multiple key conditions with AND */
248
- and: (...conditions: Condition[]) => Condition;
249
- };
250
- type FlexiblePath<T> = Path<T> extends never ? string : Path<T>;
251
- type FlexiblePathType<T, K extends keyof any> = PathType<T, K> extends never ? unknown : PathType<T, K>;
252
- /**
253
- * Type-safe operators for building conditions in DynamoDB operations.
254
- * Includes all available condition operators with proper type inference.
255
- * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html AWS DynamoDB - Condition Expressions}
256
- *
257
- * @example
258
- * // Using with type-safe conditions
259
- * interface User {
260
- * status: string;
261
- * age: number;
262
- * email?: string;
263
- * }
264
- *
265
- * table.scan<User>()
266
- * .where(op => op.and(
267
- * op.eq("status", "ACTIVE"),
268
- * op.gt("age", 18),
269
- * op.attributeExists("email")
270
- * ))
271
- *
272
- * @template T The type of the item being operated on
273
- */
274
- type ConditionOperator<T extends DynamoItem> = {
275
- /**
276
- * Creates an equals (=) condition for type-safe attribute comparison.
277
- * Tests if the specified attribute equals the provided value.
278
- *
279
- * @param attr - The attribute path to compare (with full type safety)
280
- * @param value - The value to compare against (must match attribute type)
281
- * @returns A condition that evaluates to true when attr equals value
282
- *
283
- * @example
284
- * ```typescript
285
- * interface User { status: string; age: number; }
286
- *
287
- * // String comparison
288
- * op.eq("status", "ACTIVE") // status = "ACTIVE"
289
- *
290
- * // Numeric comparison
291
- * op.eq("age", 25) // age = 25
292
- *
293
- * // Nested attribute
294
- * op.eq("profile.role", "admin") // profile.role = "admin"
295
- * ```
296
- *
297
- * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Comparators AWS DynamoDB - Comparison Operators}
298
- */
299
- eq: <K extends FlexiblePath<T>>(attr: K, value: FlexiblePathType<T, K>) => Condition;
300
- /**
301
- * Creates a not equals (≠ / <>) condition for type-safe attribute comparison.
302
- * Tests if the specified attribute does not equal the provided value.
303
- *
304
- * @param attr - The attribute path to compare (with full type safety)
305
- * @param value - The value to compare against (must match attribute type)
306
- * @returns A condition that evaluates to true when attr does not equal value
307
- *
308
- * @example
309
- * ```typescript
310
- * interface User { status: string; priority: number; }
311
- *
312
- * // String comparison
313
- * op.ne("status", "DELETED") // status <> "DELETED"
314
- *
315
- * // Numeric comparison
316
- * op.ne("priority", 0) // priority <> 0
317
- *
318
- * // Useful for filtering out specific values
319
- * op.ne("category", "ARCHIVED") // category <> "ARCHIVED"
320
- * ```
321
- *
322
- * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Comparators AWS DynamoDB - Comparison Operators}
323
- */
324
- ne: <K extends FlexiblePath<T>>(attr: K, value: FlexiblePathType<T, K>) => Condition;
325
- /**
326
- * Creates a less than (<) condition for type-safe attribute comparison.
327
- * Tests if the specified attribute is less than the provided value.
328
- * Works with numbers, strings (lexicographic), and dates.
329
- *
330
- * @param attr - The attribute path to compare (with full type safety)
331
- * @param value - The value to compare against (must match attribute type)
332
- * @returns A condition that evaluates to true when attr is less than value
333
- *
334
- * @example
335
- * ```typescript
336
- * interface Product { price: number; name: string; createdAt: string; }
337
- *
338
- * // Numeric comparison
339
- * op.lt("price", 100) // price < 100
340
- *
341
- * // String comparison (lexicographic)
342
- * op.lt("name", "M") // name < "M" (names starting with A-L)
343
- *
344
- * // Date comparison (ISO strings)
345
- * op.lt("createdAt", "2024-01-01") // createdAt < "2024-01-01"
346
- * ```
347
- *
348
- * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Comparators AWS DynamoDB - Comparison Operators}
349
- */
350
- lt: <K extends FlexiblePath<T>>(attr: K, value: FlexiblePathType<T, K>) => Condition;
351
- /**
352
- * Creates a less than or equal to (≤) condition for type-safe attribute comparison.
353
- * Tests if the specified attribute is less than or equal to the provided value.
354
- * Works with numbers, strings (lexicographic), and dates.
355
- *
356
- * @param attr - The attribute path to compare (with full type safety)
357
- * @param value - The value to compare against (must match attribute type)
358
- * @returns A condition that evaluates to true when attr is less than or equal to value
359
- *
360
- * @example
361
- * ```typescript
362
- * interface Order { total: number; priority: number; dueDate: string; }
363
- *
364
- * // Numeric comparison
365
- * op.lte("total", 1000) // total <= 1000
366
- *
367
- * // Priority levels
368
- * op.lte("priority", 3) // priority <= 3 (low to medium priority)
369
- *
370
- * // Date deadlines
371
- * op.lte("dueDate", "2024-12-31") // dueDate <= "2024-12-31"
372
- * ```
373
- *
374
- * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Comparators AWS DynamoDB - Comparison Operators}
375
- */
376
- lte: <K extends FlexiblePath<T>>(attr: K, value: FlexiblePathType<T, K>) => Condition;
377
- /**
378
- * Creates a greater than (>) condition for type-safe attribute comparison.
379
- * Tests if the specified attribute is greater than the provided value.
380
- * Works with numbers, strings (lexicographic), and dates.
381
- *
382
- * @param attr - The attribute path to compare (with full type safety)
383
- * @param value - The value to compare against (must match attribute type)
384
- * @returns A condition that evaluates to true when attr is greater than value
385
- *
386
- * @example
387
- * ```typescript
388
- * interface User { age: number; score: number; lastLogin: string; }
389
- *
390
- * // Age restrictions
391
- * op.gt("age", 18) // age > 18 (adults only)
392
- *
393
- * // Performance thresholds
394
- * op.gt("score", 85) // score > 85 (high performers)
395
- *
396
- * // Recent activity
397
- * op.gt("lastLogin", "2024-01-01") // lastLogin > "2024-01-01"
398
- * ```
399
- *
400
- * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Comparators AWS DynamoDB - Comparison Operators}
401
- */
402
- gt: <K extends FlexiblePath<T>>(attr: K, value: FlexiblePathType<T, K>) => Condition;
403
- /**
404
- * Creates a greater than or equal to (≥) condition for type-safe attribute comparison.
405
- * Tests if the specified attribute is greater than or equal to the provided value.
406
- * Works with numbers, strings (lexicographic), and dates.
407
- *
408
- * @param attr - The attribute path to compare (with full type safety)
409
- * @param value - The value to compare against (must match attribute type)
410
- * @returns A condition that evaluates to true when attr is greater than or equal to value
411
- *
412
- * @example
413
- * ```typescript
414
- * interface Product { rating: number; version: string; releaseDate: string; }
415
- *
416
- * // Minimum ratings
417
- * op.gte("rating", 4.0) // rating >= 4.0 (highly rated)
418
- *
419
- * // Version requirements
420
- * op.gte("version", "2.0.0") // version >= "2.0.0"
421
- *
422
- * // Release date filters
423
- * op.gte("releaseDate", "2024-01-01") // releaseDate >= "2024-01-01"
424
- * ```
425
- *
426
- * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Comparators AWS DynamoDB - Comparison Operators}
427
- */
428
- gte: <K extends FlexiblePath<T>>(attr: K, value: FlexiblePathType<T, K>) => Condition;
429
- /**
430
- * Creates a between condition for type-safe range comparison.
431
- * Tests if the specified attribute value falls within the inclusive range [lower, upper].
432
- * Works with numbers, strings (lexicographic), and dates.
433
- *
434
- * @param attr - The attribute path to compare (with full type safety)
435
- * @param lower - The lower bound of the range (inclusive, must match attribute type)
436
- * @param upper - The upper bound of the range (inclusive, must match attribute type)
437
- * @returns A condition that evaluates to true when lower ≤ attr ≤ upper
438
- *
439
- * @example
440
- * ```typescript
441
- * interface Event { price: number; date: string; priority: number; }
442
- *
443
- * // Price range
444
- * op.between("price", 50, 200) // price BETWEEN 50 AND 200
445
- *
446
- * // Date range
447
- * op.between("date", "2024-01-01", "2024-12-31") // date BETWEEN "2024-01-01" AND "2024-12-31"
448
- *
449
- * // Priority levels
450
- * op.between("priority", 1, 5) // priority BETWEEN 1 AND 5
451
- * ```
452
- *
453
- * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Comparators AWS DynamoDB - BETWEEN}
454
- */
455
- between: <K extends FlexiblePath<T>>(attr: K, lower: FlexiblePathType<T, K>, upper: FlexiblePathType<T, K>) => Condition;
456
- /**
457
- * Creates an IN condition for type-safe list membership testing.
458
- * Tests if the specified attribute value matches any value in the provided list.
459
- * Supports up to 100 values in the list as per DynamoDB limitations.
460
- *
461
- * @param attr - The attribute path to compare (with full type safety)
462
- * @param values - Array of values to test against (must match attribute type, max 100 items)
463
- * @returns A condition that evaluates to true when attr matches any value in the list
464
- *
465
- * @example
466
- * ```typescript
467
- * interface User { status: string; role: string; priority: number; }
468
- *
469
- * // Status filtering
470
- * op.inArray("status", ["ACTIVE", "PENDING", "PROCESSING"]) // status IN ("ACTIVE", "PENDING", "PROCESSING")
471
- *
472
- * // Role-based access
473
- * op.inArray("role", ["admin", "moderator", "editor"]) // role IN ("admin", "moderator", "editor")
474
- *
475
- * // Priority levels
476
- * op.inArray("priority", [1, 2, 3]) // priority IN (1, 2, 3)
477
- * ```
478
- *
479
- * @throws {Error} When values array is empty or contains more than 100 items
480
- * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Comparators AWS DynamoDB - IN}
481
- */
482
- inArray: <K extends FlexiblePath<T>>(attr: K, values: FlexiblePathType<T, K>[]) => Condition;
483
- /**
484
- * Creates a begins_with condition for type-safe string prefix testing.
485
- * Tests if the specified string attribute starts with the provided substring.
486
- * Only works with string attributes - will fail on other data types.
487
- *
488
- * @param attr - The string attribute path to test (with full type safety)
489
- * @param value - The prefix string to test for (must match attribute type)
490
- * @returns A condition that evaluates to true when attr starts with value
491
- *
492
- * @example
493
- * ```typescript
494
- * interface User { email: string; name: string; id: string; }
495
- *
496
- * // Email domain filtering
497
- * op.beginsWith("email", "admin@") // begins_with(email, "admin@")
498
- *
499
- * // Name prefix search
500
- * op.beginsWith("name", "John") // begins_with(name, "John")
501
- *
502
- * // ID pattern matching
503
- * op.beginsWith("id", "USER#") // begins_with(id, "USER#")
504
- * ```
505
- *
506
- * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions AWS DynamoDB - begins_with}
507
- */
508
- beginsWith: <K extends FlexiblePath<T>>(attr: K, value: FlexiblePathType<T, K>) => Condition;
509
- /**
510
- * Creates a contains condition for type-safe substring or set membership testing.
511
- * For strings: tests if the attribute contains the specified substring.
512
- * For sets: tests if the set contains the specified element.
513
- *
514
- * @param attr - The attribute path to test (with full type safety)
515
- * @param value - The substring or element to search for (must match attribute type)
516
- * @returns A condition that evaluates to true when attr contains value
517
- *
518
- * @example
519
- * ```typescript
520
- * interface Post { content: string; tags: Set<string>; categories: string[]; }
521
- *
522
- * // Substring search in content
523
- * op.contains("content", "important") // contains(content, "important")
524
- *
525
- * // Tag membership (for DynamoDB String Sets)
526
- * op.contains("tags", "featured") // contains(tags, "featured")
527
- *
528
- * // Category search (for string arrays stored as lists)
529
- * op.contains("categories", "technology") // contains(categories, "technology")
530
- * ```
531
- *
532
- * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions AWS DynamoDB - contains}
533
- */
534
- contains: <K extends FlexiblePath<T>>(attr: K, value: FlexiblePathType<T, K>) => Condition;
535
- /**
536
- * Creates an attribute_exists condition for type-safe attribute presence testing.
537
- * Tests if the specified attribute exists in the item, regardless of its value.
538
- * Useful for filtering items that have optional attributes populated.
539
- *
540
- * @param attr - The attribute path to test for existence (with full type safety)
541
- * @returns A condition that evaluates to true when the attribute exists
542
- *
543
- * @example
544
- * ```typescript
545
- * interface User { email: string; phone?: string; profile?: { avatar?: string; }; }
546
- *
547
- * // Check for optional fields
548
- * op.attributeExists("phone") // attribute_exists(phone)
549
- *
550
- * // Check for nested optional attributes
551
- * op.attributeExists("profile.avatar") // attribute_exists(profile.avatar)
552
- *
553
- * // Useful in combination with other conditions
554
- * op.and(
555
- * op.eq("status", "ACTIVE"),
556
- * op.attributeExists("email") // Only active users with email
557
- * )
558
- * ```
559
- *
560
- * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions AWS DynamoDB - attribute_exists}
561
- */
562
- attributeExists: <K extends FlexiblePath<T>>(attr: K) => Condition;
563
- /**
564
- * Creates an attribute_not_exists condition for type-safe attribute absence testing.
565
- * Tests if the specified attribute does not exist in the item.
566
- * Useful for conditional writes to prevent overwriting existing data.
567
- *
568
- * @param attr - The attribute path to test for absence (with full type safety)
569
- * @returns A condition that evaluates to true when the attribute does not exist
570
- *
571
- * @example
572
- * ```typescript
573
- * interface User { id: string; email: string; deletedAt?: string; }
574
- *
575
- * // Ensure item hasn't been soft-deleted
576
- * op.attributeNotExists("deletedAt") // attribute_not_exists(deletedAt)
577
- *
578
- * // Prevent duplicate creation
579
- * op.attributeNotExists("id") // attribute_not_exists(id)
580
- *
581
- * // Conditional updates
582
- * op.and(
583
- * op.eq("status", "PENDING"),
584
- * op.attributeNotExists("processedAt") // Only unprocessed items
585
- * )
586
- * ```
587
- *
588
- * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Functions AWS DynamoDB - attribute_not_exists}
589
- */
590
- attributeNotExists: <K extends FlexiblePath<T>>(attr: K) => Condition;
591
- /**
592
- * Combines multiple conditions with logical AND operator.
593
- * All provided conditions must evaluate to true for the AND condition to be true.
594
- * Supports any number of conditions as arguments.
595
- *
596
- * @param conditions - Variable number of conditions to combine with AND
597
- * @returns A condition that evaluates to true when all input conditions are true
598
- *
599
- * @example
600
- * ```typescript
601
- * interface User { status: string; age: number; role: string; verified: boolean; }
602
- *
603
- * // Multiple criteria
604
- * op.and(
605
- * op.eq("status", "ACTIVE"),
606
- * op.gt("age", 18),
607
- * op.eq("verified", true)
608
- * ) // status = "ACTIVE" AND age > 18 AND verified = true
609
- *
610
- * // Complex business logic
611
- * op.and(
612
- * op.inArray("role", ["admin", "moderator"]),
613
- * op.attributeExists("permissions"),
614
- * op.ne("status", "SUSPENDED")
615
- * )
616
- * ```
617
- *
618
- * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Logical AWS DynamoDB - AND}
619
- */
620
- and: (...conditions: Condition[]) => Condition;
621
- /**
622
- * Combines multiple conditions with logical OR operator.
623
- * At least one of the provided conditions must evaluate to true for the OR condition to be true.
624
- * Supports any number of conditions as arguments.
625
- *
626
- * @param conditions - Variable number of conditions to combine with OR
627
- * @returns A condition that evaluates to true when any input condition is true
628
- *
629
- * @example
630
- * ```typescript
631
- * interface Order { status: string; priority: string; urgent: boolean; }
632
- *
633
- * // Alternative statuses
634
- * op.or(
635
- * op.eq("status", "PENDING"),
636
- * op.eq("status", "PROCESSING"),
637
- * op.eq("status", "SHIPPED")
638
- * ) // status = "PENDING" OR status = "PROCESSING" OR status = "SHIPPED"
639
- *
640
- * // High priority items
641
- * op.or(
642
- * op.eq("priority", "HIGH"),
643
- * op.eq("urgent", true)
644
- * )
645
- * ```
646
- *
647
- * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Logical AWS DynamoDB - OR}
648
- */
649
- or: (...conditions: Condition[]) => Condition;
650
- /**
651
- * Negates a condition with logical NOT operator.
652
- * Inverts the boolean result of the provided condition.
653
- *
654
- * @param condition - The condition to negate
655
- * @returns A condition that evaluates to true when the input condition is false
656
- *
657
- * @example
658
- * ```typescript
659
- * interface User { status: string; role: string; banned: boolean; }
660
- *
661
- * // Exclude specific status
662
- * op.not(op.eq("status", "DELETED")) // NOT status = "DELETED"
663
- *
664
- * // Complex negation
665
- * op.not(
666
- * op.and(
667
- * op.eq("role", "guest"),
668
- * op.eq("banned", true)
669
- * )
670
- * ) // NOT (role = "guest" AND banned = true)
671
- *
672
- * // Exclude multiple values
673
- * op.not(op.inArray("status", ["DELETED", "ARCHIVED"]))
674
- * ```
675
- *
676
- * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Logical AWS DynamoDB - NOT}
677
- */
678
- not: (condition: Condition) => Condition;
679
- };
680
- /**
681
- * Primary key type for QUERY operations.
682
- * Allows building complex key conditions for the sort key.
683
- * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Query.html AWS DynamoDB - Query Operations}
684
- *
685
- * @example
686
- * // Query items with a specific partition key and sort key prefix
687
- * table.query({
688
- * pk: "USER#123",
689
- * sk: op => op.beginsWith("ORDER#2023")
690
- * })
691
- *
692
- * @example
693
- * // Query items within a specific sort key range
694
- * table.query({
695
- * pk: "USER#123",
696
- * sk: op => op.between("ORDER#2023-01", "ORDER#2023-12")
697
- * })
698
- */
699
- type PrimaryKey = {
700
- /** Partition key value */
701
- pk: string;
702
- /** Optional sort key condition builder */
703
- sk?: (op: KeyConditionOperator) => Condition;
704
- };
705
- /**
706
- * Primary key type for GET and DELETE operations.
707
- * Used when you need to specify exact key values without conditions.
708
- * @see {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/WorkingWithItems.html AWS DynamoDB - Working with Items}
709
- *
710
- * @example
711
- * // Get a specific item by its complete primary key
712
- * table.get({
713
- * pk: "USER#123",
714
- * sk: "PROFILE#123"
715
- * })
716
- *
717
- * @example
718
- * // Delete a specific item by its complete primary key
719
- * table.delete({
720
- * pk: "USER#123",
721
- * sk: "ORDER#456"
722
- * })
723
- */
724
- type PrimaryKeyWithoutExpression = {
725
- /** Partition key value */
726
- pk: string;
727
- /** Optional sort key value */
728
- sk?: string;
729
- };
730
-
731
- export { type ComparisonOperator as C, type ExpressionParams as E, type KeyConditionOperator as K, type LogicalOperator as L, type PrimaryKeyWithoutExpression as P, type PrimaryKey as a, type Condition as b, type ConditionOperator as c, and as d, attributeExists as e, attributeNotExists as f, beginsWith as g, between as h, contains as i, eq as j, gt as k, gte as l, inArray as m, lt as n, lte as o, ne as p, not as q, or as r, type Path as s, type PathType as t, createComparisonCondition as u };