dyno-table 0.1.8 → 0.2.0-0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/README.md +570 -147
  2. package/dist/builder-types-C_PDZhnP.d.ts +118 -0
  3. package/dist/builder-types-DtwbqMeF.d.cts +118 -0
  4. package/dist/builders/condition-check-builder.cjs +1 -1
  5. package/dist/builders/condition-check-builder.cjs.map +1 -1
  6. package/dist/builders/condition-check-builder.d.cts +157 -0
  7. package/dist/builders/condition-check-builder.d.ts +157 -0
  8. package/dist/builders/condition-check-builder.js +1 -1
  9. package/dist/builders/condition-check-builder.js.map +1 -1
  10. package/dist/builders/delete-builder.cjs +0 -17
  11. package/dist/builders/delete-builder.cjs.map +1 -1
  12. package/dist/builders/delete-builder.d.cts +166 -0
  13. package/dist/builders/delete-builder.d.ts +166 -0
  14. package/dist/builders/delete-builder.js +0 -17
  15. package/dist/builders/delete-builder.js.map +1 -1
  16. package/dist/builders/paginator.cjs.map +1 -1
  17. package/dist/builders/paginator.d.cts +179 -0
  18. package/dist/builders/paginator.d.ts +179 -0
  19. package/dist/builders/paginator.js.map +1 -1
  20. package/dist/builders/put-builder.cjs +8 -0
  21. package/dist/builders/put-builder.cjs.map +1 -1
  22. package/dist/builders/put-builder.d.cts +274 -0
  23. package/dist/builders/put-builder.d.ts +274 -0
  24. package/dist/builders/put-builder.js +8 -0
  25. package/dist/builders/put-builder.js.map +1 -1
  26. package/dist/builders/query-builder.cjs.map +1 -1
  27. package/dist/builders/query-builder.d.cts +6 -0
  28. package/dist/builders/query-builder.d.ts +6 -0
  29. package/dist/builders/query-builder.js.map +1 -1
  30. package/dist/builders/transaction-builder.cjs +40 -22
  31. package/dist/builders/transaction-builder.cjs.map +1 -1
  32. package/dist/builders/transaction-builder.d.cts +511 -0
  33. package/dist/builders/transaction-builder.d.ts +511 -0
  34. package/dist/builders/transaction-builder.js +40 -22
  35. package/dist/builders/transaction-builder.js.map +1 -1
  36. package/dist/builders/update-builder.cjs +3 -38
  37. package/dist/builders/update-builder.cjs.map +1 -1
  38. package/dist/builders/update-builder.d.cts +365 -0
  39. package/dist/builders/update-builder.d.ts +365 -0
  40. package/dist/builders/update-builder.js +3 -38
  41. package/dist/builders/update-builder.js.map +1 -1
  42. package/dist/conditions--ld9a78i.d.ts +331 -0
  43. package/dist/conditions-ChhQWd6z.d.cts +331 -0
  44. package/dist/conditions.cjs.map +1 -1
  45. package/dist/conditions.d.cts +3 -0
  46. package/dist/conditions.d.ts +3 -0
  47. package/dist/conditions.js.map +1 -1
  48. package/dist/entity.cjs +156 -97
  49. package/dist/entity.cjs.map +1 -1
  50. package/dist/entity.d.cts +149 -0
  51. package/dist/entity.d.ts +149 -0
  52. package/dist/entity.js +156 -97
  53. package/dist/entity.js.map +1 -1
  54. package/dist/query-builder-Csror9Iu.d.ts +507 -0
  55. package/dist/query-builder-D2FM9rsu.d.cts +507 -0
  56. package/dist/standard-schema.d.cts +57 -0
  57. package/dist/standard-schema.d.ts +57 -0
  58. package/dist/table-BEhBPy2G.d.cts +364 -0
  59. package/dist/table-BW3cmUqr.d.ts +364 -0
  60. package/dist/table.cjs +82 -102
  61. package/dist/table.cjs.map +1 -1
  62. package/dist/table.d.cts +12 -0
  63. package/dist/table.d.ts +12 -0
  64. package/dist/table.js +82 -102
  65. package/dist/table.js.map +1 -1
  66. package/dist/types.d.cts +22 -0
  67. package/dist/types.d.ts +22 -0
  68. package/dist/utils/{key-template.cjs → partition-key-template.cjs} +3 -3
  69. package/dist/utils/partition-key-template.cjs.map +1 -0
  70. package/dist/utils/partition-key-template.d.cts +32 -0
  71. package/dist/utils/partition-key-template.d.ts +32 -0
  72. package/dist/utils/{key-template.js → partition-key-template.js} +3 -3
  73. package/dist/utils/partition-key-template.js.map +1 -0
  74. package/dist/utils/sort-key-template.d.cts +35 -0
  75. package/dist/utils/sort-key-template.d.ts +35 -0
  76. package/package.json +86 -9
  77. package/dist/index.cjs +0 -3333
  78. package/dist/index.d.cts +0 -2971
  79. package/dist/index.d.ts +0 -2971
  80. package/dist/index.js +0 -3284
  81. package/dist/utils/key-template.cjs.map +0 -1
  82. package/dist/utils/key-template.js.map +0 -1
@@ -0,0 +1,364 @@
1
+ import { DynamoItem, TableConfig, Index } from './types.cjs';
2
+ import { P as PrimaryKeyWithoutExpression, a as PrimaryKey } from './conditions-ChhQWd6z.cjs';
3
+ import { F as FilterBuilder, a as FilterOptions, Q as QueryBuilder } from './query-builder-D2FM9rsu.cjs';
4
+ import { PutBuilder } from './builders/put-builder.cjs';
5
+ import { DeleteBuilder } from './builders/delete-builder.cjs';
6
+ import { UpdateBuilder } from './builders/update-builder.cjs';
7
+ import { TransactionBuilder, TransactionOptions } from './builders/transaction-builder.cjs';
8
+ import { ConditionCheckBuilder } from './builders/condition-check-builder.cjs';
9
+ import { S as ScanBuilderInterface } from './builder-types-DtwbqMeF.cjs';
10
+
11
+ type BatchWriteOperation<T extends Record<string, unknown>> = {
12
+ type: "put";
13
+ item: T;
14
+ } | {
15
+ type: "delete";
16
+ key: PrimaryKeyWithoutExpression;
17
+ };
18
+
19
+ /**
20
+ * Parameters for the DynamoDB get command.
21
+ */
22
+ interface GetCommandParams {
23
+ /** The name of the DynamoDB table */
24
+ tableName: string;
25
+ /** The primary key of the item to get */
26
+ key: PrimaryKeyWithoutExpression;
27
+ /** Comma-separated list of attributes to return */
28
+ projectionExpression?: string;
29
+ /** Map of expression attribute name placeholders to actual names */
30
+ expressionAttributeNames?: Record<string, string>;
31
+ /** Whether to use strongly consistent reads */
32
+ consistentRead?: boolean;
33
+ }
34
+ /**
35
+ * Function type for executing DynamoDB get operations.
36
+ * @typeParam T - The type of item being retrieved
37
+ */
38
+ type GetExecutor<T extends DynamoItem> = (params: GetCommandParams) => Promise<{
39
+ item: T | undefined;
40
+ }>;
41
+ /**
42
+ * Builder for creating DynamoDB get operations.
43
+ * Use this builder when you need to:
44
+ * - Retrieve a single dinosaur by its primary key
45
+ * - Project specific dinosaur attributes
46
+ * - Use consistent reads for critical dinosaur data
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * // Simple get
51
+ * const result = await new GetBuilder(executor, { pk: 'dinosaur#123', sk: 'profile' })
52
+ * .execute();
53
+ *
54
+ * // Get with projection and consistent read
55
+ * const result = await new GetBuilder(executor, { pk: 'dinosaur#123', sk: 'profile' })
56
+ * .select(['species', 'name', 'diet'])
57
+ * .consistentRead()
58
+ * .execute();
59
+ * ```
60
+ *
61
+ * @typeParam T - The type of item being retrieved
62
+ */
63
+ declare class GetBuilder<T extends DynamoItem> {
64
+ private readonly executor;
65
+ private readonly params;
66
+ private options;
67
+ private selectedFields;
68
+ /**
69
+ * Creates a new GetBuilder instance.
70
+ *
71
+ * @param executor - Function that executes the get operation
72
+ * @param key - Primary key of the item to retrieve
73
+ * @param tableName - Name of the DynamoDB table
74
+ */
75
+ constructor(executor: GetExecutor<T>, key: PrimaryKeyWithoutExpression, tableName: string);
76
+ /**
77
+ * Specifies which attributes to return in the get results.
78
+ * Use this method when you need to:
79
+ * - Reduce data transfer by selecting specific dinosaur attributes
80
+ * - Optimize response size for dinosaur records
81
+ * - Focus on relevant dinosaur characteristics only
82
+ *
83
+ * @example
84
+ * ```typescript
85
+ * // Select single attribute
86
+ * builder.select('species')
87
+ *
88
+ * // Select multiple attributes
89
+ * builder.select(['id', 'species', 'diet'])
90
+ *
91
+ * // Chain multiple select calls
92
+ * builder
93
+ * .select('id')
94
+ * .select(['species', 'diet'])
95
+ * ```
96
+ *
97
+ * @param fields - A single field name or an array of field names to return
98
+ * @returns The builder instance for method chaining
99
+ */
100
+ select(fields: string | string[]): GetBuilder<T>;
101
+ /**
102
+ * Sets whether to use strongly consistent reads for the get operation.
103
+ * Use this method when you need:
104
+ * - The most up-to-date dinosaur data
105
+ * - To ensure you're reading the latest dinosaur status
106
+ * - Critical safety information about dangerous species
107
+ *
108
+ * Note: Consistent reads consume twice the throughput
109
+ *
110
+ * @example
111
+ * ```typescript
112
+ * // Get the latest T-Rex data
113
+ * const result = await new GetBuilder(executor, { pk: 'dinosaur#123', sk: 'profile' })
114
+ * .consistentRead()
115
+ * .execute();
116
+ * ```
117
+ *
118
+ * @param consistentRead - Whether to use consistent reads (defaults to true)
119
+ * @returns The builder instance for method chaining
120
+ */
121
+ consistentRead(consistentRead?: boolean): GetBuilder<T>;
122
+ /**
123
+ * Executes the get operation against DynamoDB.
124
+ *
125
+ * @example
126
+ * ```typescript
127
+ * try {
128
+ * const result = await new GetBuilder(executor, { pk: 'dinosaur#123', sk: 'profile' })
129
+ * .select(['species', 'name', 'diet'])
130
+ * .consistentRead()
131
+ * .execute();
132
+ *
133
+ * if (result.item) {
134
+ * console.log('Dinosaur found:', result.item);
135
+ * } else {
136
+ * console.log('Dinosaur not found');
137
+ * }
138
+ * } catch (error) {
139
+ * console.error('Error getting dinosaur:', error);
140
+ * }
141
+ * ```
142
+ *
143
+ * @returns A promise that resolves to an object containing:
144
+ * - item: The retrieved dinosaur or undefined if not found
145
+ */
146
+ execute(): Promise<{
147
+ item: T | undefined;
148
+ }>;
149
+ }
150
+
151
+ /**
152
+ * Configuration options for DynamoDB scan operations.
153
+ * Extends the base FilterOptions.
154
+ */
155
+ type ScanOptions = FilterOptions;
156
+ /**
157
+ * Function type for executing DynamoDB filter operations.
158
+ * @typeParam T - The type of items being filtered
159
+ */
160
+ type ScanExecutor<T extends DynamoItem> = (options: ScanOptions) => Promise<{
161
+ items: T[];
162
+ lastEvaluatedKey?: DynamoItem;
163
+ }>;
164
+ /**
165
+ * Builder for creating DynamoDB scan operations.
166
+ * Use this builder when you need to:
167
+ * - Scan all items in a table
168
+ * - Filter results based on non-key attributes
169
+ * - Scan items on a Secondary Index (GSI)
170
+ * - Implement pagination
171
+ * - Project specific attributes
172
+ *
173
+ * The builder supports:
174
+ * - Type-safe GSI selection
175
+ * - Complex filter conditions
176
+ * - Automatic pagination handling
177
+ * - Consistent reads
178
+ * - Attribute projection
179
+ *
180
+ * @example
181
+ * ```typescript
182
+ * // Simple scan with filtering
183
+ * const result = await new ScanBuilder(executor)
184
+ * .filter(op => op.eq('status', 'ACTIVE'))
185
+ * .execute();
186
+ *
187
+ * // Scan with GSI and filtering
188
+ * const result = await new ScanBuilder(executor)
189
+ * .useIndex('status-index')
190
+ * .filter(op => op.gt('securityLevel', 8))
191
+ * .select(['id', 'capacity', 'currentOccupants'])
192
+ * .limit(10)
193
+ * .execute();
194
+ *
195
+ * // Scan with pagination
196
+ * const paginator = new ScanBuilder(executor)
197
+ * .filter(op => op.eq('type', 'INCIDENT'))
198
+ * .paginate(25);
199
+ *
200
+ * while (paginator.hasNextPage()) {
201
+ * const page = await paginator.getNextPage();
202
+ * // Process page.items
203
+ * }
204
+ * ```
205
+ *
206
+ * @typeParam T - The type of items being scanned
207
+ * @typeParam TConfig - The table configuration type for type-safe GSI selection
208
+ */
209
+ declare class ScanBuilder<T extends DynamoItem, TConfig extends TableConfig = TableConfig> extends FilterBuilder<T, TConfig> implements ScanBuilderInterface<T, TConfig> {
210
+ protected readonly executor: ScanExecutor<T>;
211
+ constructor(executor: ScanExecutor<T>);
212
+ /**
213
+ * Creates a deep clone of this ScanBuilder instance.
214
+ * Use this method when you need to:
215
+ * - Create scan templates
216
+ * - Run multiple variations of a scan
217
+ * - Implement pagination (used internally by paginate())
218
+ *
219
+ * @returns A new ScanBuilder instance with the same configuration
220
+ */
221
+ clone(): ScanBuilder<T, TConfig>;
222
+ /**
223
+ * Executes the scan against DynamoDB.
224
+ * Use this method when you need to:
225
+ * - Search across the entire table
226
+ * - Find items matching specific criteria
227
+ * - Perform full table analysis
228
+ * - Generate reports across all data
229
+ *
230
+ * The method returns both the matched items and, if there are more results,
231
+ * a lastEvaluatedKey that can be used with startFrom() to continue the scan.
232
+ *
233
+ * @example
234
+ * ```typescript
235
+ * try {
236
+ * // Find all dinosaurs with high aggression levels
237
+ * const result = await new ScanBuilder(executor)
238
+ * .filter(op =>
239
+ * op.and([
240
+ * op.eq('status', 'ACTIVE'),
241
+ * op.gt('aggressionLevel', 7)
242
+ * ])
243
+ * )
244
+ * .limit(20)
245
+ * .execute();
246
+ *
247
+ * console.log(`Found ${result.items.length} potentially dangerous dinosaurs`);
248
+ *
249
+ * if (result.lastEvaluatedKey) {
250
+ * console.log('More results available');
251
+ * }
252
+ * } catch (error) {
253
+ * console.error('Security scan failed:', error);
254
+ * }
255
+ * ```
256
+ *
257
+ * @returns A promise that resolves to an object containing:
258
+ * - items: Array of items matching the scan criteria
259
+ * - lastEvaluatedKey: Token for continuing the scan, if more items exist
260
+ */
261
+ execute(): Promise<{
262
+ items: T[];
263
+ lastEvaluatedKey?: Record<string, unknown>;
264
+ }>;
265
+ }
266
+
267
+ declare class Table<TConfig extends TableConfig = TableConfig> {
268
+ private readonly dynamoClient;
269
+ readonly tableName: string;
270
+ /**
271
+ * The column name of the partitionKey for the Table
272
+ */
273
+ readonly partitionKey: string;
274
+ /**
275
+ * The column name of the sortKey for the Table
276
+ */
277
+ readonly sortKey?: string;
278
+ /**
279
+ * The Global Secondary Indexes that are configured on this table
280
+ */
281
+ readonly gsis: Record<string, Index>;
282
+ constructor(config: TConfig);
283
+ protected createKeyForPrimaryIndex(keyCondition: PrimaryKeyWithoutExpression): Record<string, unknown>;
284
+ /**
285
+ * Creates a new item in the table, it will fail if the item already exists
286
+ *
287
+ * @param item The item to create
288
+ * @returns A PutBuilder instance for chaining conditions and executing the put operation
289
+ */
290
+ create<T extends DynamoItem>(item: T): PutBuilder<T>;
291
+ get<T extends DynamoItem>(keyCondition: PrimaryKeyWithoutExpression): GetBuilder<T>;
292
+ /**
293
+ * Updates an item in the table
294
+ *
295
+ * @param item The item to update
296
+ * @returns A PutBuilder instance for chaining conditions and executing the put operation
297
+ */
298
+ put<T extends DynamoItem>(item: T): PutBuilder<T>;
299
+ /**
300
+ * Creates a query builder for complex queries
301
+ * If useIndex is called on the returned QueryBuilder, it will use the GSI configuration
302
+ */
303
+ query<T extends DynamoItem>(keyCondition: PrimaryKey): QueryBuilder<T, TConfig>;
304
+ /**
305
+ * Creates a scan builder for scanning the entire table
306
+ * Use this when you need to:
307
+ * - Process all items in a table
308
+ * - Apply filters to a large dataset
309
+ * - Use a GSI for scanning
310
+ *
311
+ * @returns A ScanBuilder instance for chaining operations
312
+ */
313
+ scan<T extends DynamoItem>(): ScanBuilder<T, TConfig>;
314
+ delete(keyCondition: PrimaryKeyWithoutExpression): DeleteBuilder;
315
+ /**
316
+ * Updates an item in the table
317
+ *
318
+ * @param keyCondition The primary key of the item to update
319
+ * @returns An UpdateBuilder instance for chaining update operations and conditions
320
+ */
321
+ update<T extends DynamoItem>(keyCondition: PrimaryKeyWithoutExpression): UpdateBuilder<T>;
322
+ /**
323
+ * Creates a transaction builder for performing multiple operations atomically
324
+ */
325
+ transactionBuilder(): TransactionBuilder;
326
+ /**
327
+ * Executes a transaction using a callback function
328
+ *
329
+ * @param callback A function that receives a transaction context and performs operations on it
330
+ * @param options Optional transaction options
331
+ * @returns A promise that resolves when the transaction is complete
332
+ */
333
+ transaction<T>(callback: (tx: TransactionBuilder) => Promise<T>, options?: TransactionOptions): Promise<T>;
334
+ /**
335
+ * Creates a condition check operation for use in transactions
336
+ *
337
+ * This is useful for when you require a transaction to succeed only when a specific condition is met on a
338
+ * a record within the database that you are not directly updating.
339
+ *
340
+ * For example, you are updating a record and you want to ensure that another record exists and/or has a specific value before proceeding.
341
+ */
342
+ conditionCheck(keyCondition: PrimaryKeyWithoutExpression): ConditionCheckBuilder;
343
+ /**
344
+ * Performs a batch get operation to retrieve multiple items at once
345
+ *
346
+ * @param keys Array of primary keys to retrieve
347
+ * @returns A promise that resolves to the retrieved items
348
+ */
349
+ batchGet<T extends DynamoItem>(keys: Array<PrimaryKeyWithoutExpression>): Promise<{
350
+ items: T[];
351
+ unprocessedKeys: PrimaryKeyWithoutExpression[];
352
+ }>;
353
+ /**
354
+ * Performs a batch write operation to put or delete multiple items at once
355
+ *
356
+ * @param operations Array of put or delete operations
357
+ * @returns A promise that resolves to any unprocessed operations
358
+ */
359
+ batchWrite<T extends DynamoItem>(operations: Array<BatchWriteOperation<T>>): Promise<{
360
+ unprocessedItems: Array<BatchWriteOperation<T>>;
361
+ }>;
362
+ }
363
+
364
+ export { GetBuilder as G, ScanBuilder as S, Table as T };