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
package/dist/index.d.cts DELETED
@@ -1,273 +0,0 @@
1
- import { c as BatchError, d as ConfigurationError, E as ExpressionError, e as EntityValidationError, K as KeyGenerationError, I as IndexGenerationError, O as OperationError, f as TransactionError, V as ValidationError, g as DynoTableError, h as EntityError } from './index-CPCmWsEv.cjs';
2
- export { B as BatchBuilder, i as BatchResult, D as DeleteBuilder, j as DeleteOptions, k as ErrorCode, l as ErrorCodes, P as PutBuilder, m as PutOptions, Q as QueryBuilder, n as QueryOptions, T as TransactionBuilder, a as TransactionOptions, U as UpdateBuilder, o as UpdateOptions } from './index-CPCmWsEv.cjs';
3
- export { C as ComparisonOperator, b as Condition, c as ConditionOperator, E as ExpressionParams, K as KeyConditionOperator, L as LogicalOperator, a as PrimaryKey, P as PrimaryKeyWithoutExpression, d as and, e as attributeExists, f as attributeNotExists, g as beginsWith, h as between, i as contains, j as eq, k as gt, l as gte, m as inArray, n as lt, o as lte, p as ne, q as not, r as or } from './conditions-C8bM__Pn.cjs';
4
- export { EntityConfig, EntityRepository, IndexDefinition, QueryEntity, QueryRecord, createIndex, createQueries, defineEntity } from './entity.cjs';
5
- export { Table } from './table.cjs';
6
- export { partitionKey, sortKey } from './utils.cjs';
7
- import './types.cjs';
8
- import '@aws-sdk/lib-dynamodb';
9
- import './standard-schema.cjs';
10
-
11
- /**
12
- * Factory functions for Expression errors
13
- */
14
- declare const ExpressionErrors: {
15
- missingAttribute: (conditionType: string, condition: unknown) => ExpressionError;
16
- missingValue: (conditionType: string, condition: unknown) => ExpressionError;
17
- invalidCondition: (conditionType: string, condition: unknown, suggestion?: string) => ExpressionError;
18
- emptyArray: (conditionType: string, providedValue: unknown) => ExpressionError;
19
- unknownType: (conditionType: string, condition: unknown) => ExpressionError;
20
- };
21
- /**
22
- * Factory functions for Validation errors
23
- */
24
- declare const ValidationErrors: {
25
- indexSchemaValidationFailed: (validationIssues: unknown, keyType: "partition" | "sort" | "both") => ValidationError;
26
- noUpdateActions: (tableName: string, key: Record<string, unknown>) => ValidationError;
27
- conditionRequired: (tableName: string, key: Record<string, unknown>) => ValidationError;
28
- queryInputValidationFailed: (entityName: string, queryName: string, validationIssues: unknown, providedInput: unknown) => ValidationError;
29
- undefinedValue: (path: string, tableName: string, key: Record<string, unknown>) => ValidationError;
30
- };
31
- /**
32
- * Factory functions for Configuration errors
33
- */
34
- declare const ConfigurationErrors: {
35
- invalidChunkSize: (size: number) => ConfigurationError;
36
- sortKeyRequired: (tableName: string, partitionKey: string, sortKey?: string) => ConfigurationError;
37
- sortKeyNotDefined: (tableName: string, partitionKey: string, indexName?: string) => ConfigurationError;
38
- gsiNotFound: (indexName: string, tableName: string, availableIndexes: string[]) => ConfigurationError;
39
- primaryKeyMissing: (tableName: string, partitionKeyName: string, providedItem: unknown) => ConfigurationError;
40
- pkExtractionFailed: (tableName: string, indexName: string, item: unknown, cause?: Error) => ConfigurationError;
41
- conditionGenerationFailed: (condition: unknown, suggestion?: string) => ExpressionError;
42
- };
43
- /**
44
- * Factory functions for Operation errors
45
- */
46
- declare const OperationErrors: {
47
- queryFailed: (tableName: string, context: Record<string, unknown>, cause?: Error) => OperationError;
48
- scanFailed: (tableName: string, context: Record<string, unknown>, cause?: Error) => OperationError;
49
- getFailed: (tableName: string, key: Record<string, unknown>, cause?: Error) => OperationError;
50
- putFailed: (tableName: string, item: unknown, cause?: Error) => OperationError;
51
- updateFailed: (tableName: string, key: Record<string, unknown>, cause?: Error) => OperationError;
52
- deleteFailed: (tableName: string, key: Record<string, unknown>, cause?: Error) => OperationError;
53
- batchGetFailed: (tableName: string, context: Record<string, unknown>, cause?: Error) => OperationError;
54
- batchWriteFailed: (tableName: string, context: Record<string, unknown>, cause?: Error) => OperationError;
55
- };
56
- /**
57
- * Factory functions for Transaction errors
58
- */
59
- declare const TransactionErrors: {
60
- transactionFailed: (itemCount: number, context: Record<string, unknown>, cause?: Error) => TransactionError;
61
- duplicateItem: (tableName: string, partitionKey: {
62
- name: string;
63
- value: unknown;
64
- }, sortKey?: {
65
- name: string;
66
- value: unknown;
67
- }) => TransactionError;
68
- transactionEmpty: () => TransactionError;
69
- unsupportedType: (item: unknown) => TransactionError;
70
- };
71
- /**
72
- * Factory functions for Batch errors
73
- */
74
- declare const BatchErrors: {
75
- batchEmpty: (operation: "write" | "read") => BatchError;
76
- unsupportedType: (operation: "write" | "read", item: unknown) => BatchError;
77
- batchWriteFailed: (unprocessedItems: unknown[], context: Record<string, unknown>, cause?: Error) => BatchError;
78
- batchGetFailed: (unprocessedItems: unknown[], context: Record<string, unknown>, cause?: Error) => BatchError;
79
- };
80
- /**
81
- * Factory functions for Entity errors
82
- */
83
- declare const EntityErrors: {
84
- validationFailed: (entityName: string, operation: string, validationIssues: unknown, providedData: unknown) => EntityValidationError;
85
- queryInputValidationFailed: (entityName: string, queryName: string, validationIssues: unknown, providedInput: unknown) => EntityValidationError;
86
- asyncValidationNotSupported: (entityName: string, operation: string) => EntityValidationError;
87
- keyGenerationFailed: (entityName: string, operation: string, providedData: unknown, requiredAttributes?: string[], cause?: Error) => KeyGenerationError;
88
- keyInvalidFormat: (entityName: string, operation: string, providedData: unknown, generatedKey: unknown) => KeyGenerationError;
89
- keyMissingAttributes: (entityName: string, operation: string, missingAttributes: string[], providedData: unknown) => KeyGenerationError;
90
- };
91
- /**
92
- * Factory functions for Index errors
93
- */
94
- declare const IndexErrors: {
95
- generationFailed: (indexName: string, operation: string, providedItem: unknown, partitionKeyAttribute?: string, sortKeyAttribute?: string, cause?: Error) => IndexGenerationError;
96
- missingAttributes: (indexName: string, operation: string, missingAttributes: string[], providedData: unknown, isReadOnly: boolean) => IndexGenerationError;
97
- undefinedValues: (indexName: string, operation: string, generatedKey: unknown, providedItem: unknown) => IndexGenerationError;
98
- notFound: (requestedIndexes: string[], availableIndexes: string[], entityName?: string, tableName?: string) => IndexGenerationError;
99
- readonlyUpdateFailed: (indexName: string, operation: string, providedData: unknown) => IndexGenerationError;
100
- };
101
-
102
- /**
103
- * Utility functions for error handling
104
- *
105
- * This module provides helper functions for wrapping AWS SDK errors,
106
- * extracting information from errors, and formatting error context.
107
- */
108
-
109
- /**
110
- * Checks if an error is a DynamoDB conditional check failure
111
- *
112
- * @param error - The error to check
113
- * @returns true if the error is a conditional check failure
114
- */
115
- declare function isConditionalCheckFailed(error: unknown): boolean;
116
- /**
117
- * Checks if an error is a DynamoDB transaction cancellation
118
- *
119
- * @param error - The error to check
120
- * @returns true if the error is a transaction cancellation
121
- */
122
- declare function isTransactionCanceled(error: unknown): boolean;
123
- /**
124
- * Checks if an error is a DynamoDB validation exception
125
- *
126
- * @param error - The error to check
127
- * @returns true if the error is a validation exception
128
- */
129
- declare function isValidationException(error: unknown): boolean;
130
- /**
131
- * Checks if an error is a DynamoDB provisioned throughput exceeded exception
132
- *
133
- * @param error - The error to check
134
- * @returns true if the error is a throughput exceeded exception
135
- */
136
- declare function isProvisionedThroughputExceeded(error: unknown): boolean;
137
- /**
138
- * Checks if an error is a retryable error
139
- *
140
- * Retryable errors include:
141
- * - ProvisionedThroughputExceededException
142
- * - ThrottlingException
143
- * - RequestLimitExceeded
144
- * - InternalServerError
145
- * - ServiceUnavailable
146
- *
147
- * @param error - The error to check
148
- * @returns true if the error is retryable
149
- */
150
- declare function isRetryableError(error: unknown): boolean;
151
- /**
152
- * Extracts the AWS error code from an error
153
- *
154
- * @param error - The error to extract the code from
155
- * @returns The error code, or undefined if not found
156
- */
157
- declare function getAwsErrorCode(error: unknown): string | undefined;
158
- /**
159
- * Extracts the AWS error message from an error
160
- *
161
- * @param error - The error to extract the message from
162
- * @returns The error message, or undefined if not found
163
- */
164
- declare function getAwsErrorMessage(error: unknown): string | undefined;
165
- /**
166
- * Attempts to extract required attribute names from an error message
167
- *
168
- * This is a best-effort function that looks for common patterns in error
169
- * messages to identify which attributes are missing or required.
170
- *
171
- * @param error - The error to extract attributes from
172
- * @returns Array of attribute names, or undefined if none found
173
- */
174
- declare function extractRequiredAttributes(error: unknown): string[] | undefined;
175
- /**
176
- * Formats error context for logging
177
- *
178
- * Converts the error context object to a readable string format,
179
- * handling special types like arrays and nested objects.
180
- *
181
- * @param context - The error context to format
182
- * @param indent - The indentation level (for nested objects)
183
- * @returns Formatted context string
184
- */
185
- declare function formatErrorContext(context: Record<string, unknown>, indent?: number): string;
186
- /**
187
- * Creates a detailed error summary including context
188
- *
189
- * Useful for logging or displaying error information to developers.
190
- *
191
- * @param error - The DynoTableError to summarize
192
- * @returns Formatted error summary
193
- */
194
- declare function getErrorSummary(error: DynoTableError): string;
195
- /**
196
- * Type guard to check if an error is a DynoTableError
197
- *
198
- * @param error - The error to check
199
- * @returns true if the error is a DynoTableError
200
- */
201
- declare function isDynoTableError(error: unknown): error is DynoTableError;
202
- /**
203
- * Type guard to check if an error is a ValidationError
204
- *
205
- * @param error - The error to check
206
- * @returns true if the error is a ValidationError
207
- */
208
- declare function isValidationError(error: unknown): error is ValidationError;
209
- /**
210
- * Type guard to check if an error is an OperationError
211
- *
212
- * @param error - The error to check
213
- * @returns true if the error is an OperationError
214
- */
215
- declare function isOperationError(error: unknown): error is OperationError;
216
- /**
217
- * Type guard to check if an error is a TransactionError
218
- *
219
- * @param error - The error to check
220
- * @returns true if the error is a TransactionError
221
- */
222
- declare function isTransactionError(error: unknown): error is TransactionError;
223
- /**
224
- * Type guard to check if an error is a BatchError
225
- *
226
- * @param error - The error to check
227
- * @returns true if the error is a BatchError
228
- */
229
- declare function isBatchError(error: unknown): error is BatchError;
230
- /**
231
- * Type guard to check if an error is an ExpressionError
232
- *
233
- * @param error - The error to check
234
- * @returns true if the error is an ExpressionError
235
- */
236
- declare function isExpressionError(error: unknown): error is ExpressionError;
237
- /**
238
- * Type guard to check if an error is a ConfigurationError
239
- *
240
- * @param error - The error to check
241
- * @returns true if the error is a ConfigurationError
242
- */
243
- declare function isConfigurationError(error: unknown): error is ConfigurationError;
244
- /**
245
- * Type guard to check if an error is an EntityError
246
- *
247
- * @param error - The error to check
248
- * @returns true if the error is an EntityError
249
- */
250
- declare function isEntityError(error: unknown): error is EntityError;
251
- /**
252
- * Type guard to check if an error is a KeyGenerationError
253
- *
254
- * @param error - The error to check
255
- * @returns true if the error is a KeyGenerationError
256
- */
257
- declare function isKeyGenerationError(error: unknown): error is KeyGenerationError;
258
- /**
259
- * Type guard to check if an error is an IndexGenerationError
260
- *
261
- * @param error - The error to check
262
- * @returns true if the error is an IndexGenerationError
263
- */
264
- declare function isIndexGenerationError(error: unknown): error is IndexGenerationError;
265
- /**
266
- * Type guard to check if an error is an EntityValidationError
267
- *
268
- * @param error - The error to check
269
- * @returns true if the error is an EntityValidationError
270
- */
271
- declare function isEntityValidationError(error: unknown): error is EntityValidationError;
272
-
273
- export { BatchError, BatchErrors, ConfigurationError, ConfigurationErrors, DynoTableError, EntityError, EntityErrors, EntityValidationError, ExpressionError, ExpressionErrors, IndexErrors, IndexGenerationError, KeyGenerationError, OperationError, OperationErrors, TransactionError, TransactionErrors, ValidationError, ValidationErrors, extractRequiredAttributes, formatErrorContext, getAwsErrorCode, getAwsErrorMessage, getErrorSummary, isBatchError, isConditionalCheckFailed, isConfigurationError, isDynoTableError, isEntityError, isEntityValidationError, isExpressionError, isIndexGenerationError, isKeyGenerationError, isOperationError, isProvisionedThroughputExceeded, isRetryableError, isTransactionCanceled, isTransactionError, isValidationError, isValidationException };
@@ -1,57 +0,0 @@
1
- /** The Standard Schema interface. */
2
- interface StandardSchemaV1<Input = unknown, Output = Input> {
3
- /** The Standard Schema properties. */
4
- readonly "~standard": StandardSchemaV1.Props<Input, Output>;
5
- }
6
- declare namespace StandardSchemaV1 {
7
- /** The Standard Schema properties interface. */
8
- interface Props<Input = unknown, Output = Input> {
9
- /** The version number of the standard. */
10
- readonly version: 1;
11
- /** The vendor name of the schema library. */
12
- readonly vendor: string;
13
- /** Validates unknown input values. */
14
- readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
15
- /** Inferred types associated with the schema. */
16
- readonly types?: Types<Input, Output> | undefined;
17
- }
18
- /** The result interface of the validate function. */
19
- type Result<Output> = SuccessResult<Output> | FailureResult;
20
- /** The result interface if validation succeeds. */
21
- interface SuccessResult<Output> {
22
- /** The typed output value. */
23
- readonly value: Output;
24
- /** The non-existent issues. */
25
- readonly issues?: undefined;
26
- }
27
- /** The result interface if validation fails. */
28
- interface FailureResult {
29
- /** The issues of failed validation. */
30
- readonly issues: ReadonlyArray<Issue>;
31
- }
32
- /** The issue interface of the failure output. */
33
- interface Issue {
34
- /** The error message of the issue. */
35
- readonly message: string;
36
- /** The path of the issue, if any. */
37
- readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
38
- }
39
- /** The path segment interface of the issue. */
40
- interface PathSegment {
41
- /** The key representing a path segment. */
42
- readonly key: PropertyKey;
43
- }
44
- /** The Standard Schema types interface. */
45
- interface Types<Input = unknown, Output = Input> {
46
- /** The input type of the schema. */
47
- readonly input: Input;
48
- /** The output type of the schema. */
49
- readonly output: Output;
50
- }
51
- /** Infers the input type of a Standard Schema. */
52
- type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["input"];
53
- /** Infers the output type of a Standard Schema. */
54
- type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["output"];
55
- }
56
-
57
- export { StandardSchemaV1 };
package/dist/table.d.cts DELETED
@@ -1,165 +0,0 @@
1
- import { P as PutBuilder, G as GetBuilder, Q as QueryBuilder, S as ScanBuilder, D as DeleteBuilder, U as UpdateBuilder, T as TransactionBuilder, B as BatchBuilder, a as TransactionOptions, C as ConditionCheckBuilder, b as BatchWriteOperation } from './index-CPCmWsEv.cjs';
2
- import { P as PrimaryKeyWithoutExpression, a as PrimaryKey } from './conditions-C8bM__Pn.cjs';
3
- import { TableConfig, Index, DynamoItem } from './types.cjs';
4
- import '@aws-sdk/lib-dynamodb';
5
-
6
- declare class Table<TConfig extends TableConfig = TableConfig> {
7
- private readonly dynamoClient;
8
- readonly tableName: string;
9
- /**
10
- * The column name of the partitionKey for the Table
11
- */
12
- readonly partitionKey: string;
13
- /**
14
- * The column name of the sortKey for the Table
15
- */
16
- readonly sortKey?: string;
17
- /**
18
- * The Global Secondary Indexes that are configured on this table
19
- */
20
- readonly gsis: Record<string, Index>;
21
- constructor(config: TConfig);
22
- private getIndexAttributeNames;
23
- protected createKeyForPrimaryIndex(keyCondition: PrimaryKeyWithoutExpression): Record<string, unknown>;
24
- /**
25
- * Creates a new item in the table, it will fail if the item already exists.
26
- *
27
- * By default, this method returns the input values passed to the create operation
28
- * upon successful creation.
29
- *
30
- * You can customise the return behaviour by chaining the `.returnValues()` method:
31
- *
32
- * @param item The item to create
33
- * @returns A PutBuilder instance for chaining additional conditions and executing the create operation
34
- *
35
- * @example
36
- * ```ts
37
- * // Create with default behavior (returns input values)
38
- * const result = await table.create({
39
- * id: 'user-123',
40
- * name: 'John Doe',
41
- * email: 'john@example.com'
42
- * }).execute();
43
- * console.log(result); // Returns the input object
44
- *
45
- * // Create with no return value for better performance
46
- * await table.create(userData).returnValues('NONE').execute();
47
- *
48
- * // Create and get fresh data from dynamodb using a strongly consistent read
49
- * const freshData = await table.create(userData).returnValues('CONSISTENT').execute();
50
- *
51
- * // Create and get previous values (if the item was overwritten)
52
- * const oldData = await table.create(userData).returnValues('ALL_OLD').execute();
53
- * ```
54
- */
55
- create<T extends DynamoItem>(item: T): PutBuilder<T>;
56
- get<T extends DynamoItem>(keyCondition: PrimaryKeyWithoutExpression): GetBuilder<T>;
57
- /**
58
- * Updates an item in the table
59
- *
60
- * @param item The item to update
61
- * @returns A PutBuilder instance for chaining conditions and executing the put operation
62
- */
63
- put<T extends DynamoItem>(item: T): PutBuilder<T>;
64
- /**
65
- * Creates a query builder for complex queries
66
- * If useIndex is called on the returned QueryBuilder, it will use the GSI configuration
67
- */
68
- query<T extends DynamoItem>(keyCondition: PrimaryKey): QueryBuilder<T, TConfig>;
69
- /**
70
- * Creates a scan builder for scanning the entire table
71
- * Use this when you need to:
72
- * - Process all items in a table
73
- * - Apply filters to a large dataset
74
- * - Use a GSI for scanning
75
- *
76
- * @returns A ScanBuilder instance for chaining operations
77
- */
78
- scan<T extends DynamoItem>(): ScanBuilder<T, TConfig>;
79
- delete(keyCondition: PrimaryKeyWithoutExpression): DeleteBuilder;
80
- /**
81
- * Updates an item in the table
82
- *
83
- * @param keyCondition The primary key of the item to update
84
- * @returns An UpdateBuilder instance for chaining update operations and conditions
85
- */
86
- update<T extends DynamoItem>(keyCondition: PrimaryKeyWithoutExpression): UpdateBuilder<T>;
87
- /**
88
- * Creates a transaction builder for performing multiple operations atomically
89
- */
90
- transactionBuilder(): TransactionBuilder;
91
- /**
92
- * Creates a batch builder for performing multiple operations efficiently with optional type inference
93
- *
94
- * @example Basic Usage
95
- * ```typescript
96
- * const batch = table.batchBuilder();
97
- *
98
- * // Add operations
99
- * userRepo.create(newUser).withBatch(batch);
100
- * orderRepo.get({ id: 'order-1' }).withBatch(batch);
101
- *
102
- * // Execute operations
103
- * const result = await batch.execute();
104
- * ```
105
- *
106
- * @example Typed Usage
107
- * ```typescript
108
- * // Define entity types for the batch
109
- * const batch = table.batchBuilder<{
110
- * User: UserEntity;
111
- * Order: OrderEntity;
112
- * Product: ProductEntity;
113
- * }>();
114
- *
115
- * // Add operations with type information
116
- * userRepo.create(newUser).withBatch(batch, 'User');
117
- * orderRepo.get({ id: 'order-1' }).withBatch(batch, 'Order');
118
- * productRepo.delete({ id: 'old-product' }).withBatch(batch, 'Product');
119
- *
120
- * // Execute and get typed results
121
- * const result = await batch.execute();
122
- * const users: UserEntity[] = result.reads.itemsByType.User;
123
- * const orders: OrderEntity[] = result.reads.itemsByType.Order;
124
- * ```
125
- */
126
- batchBuilder<TEntities extends Record<string, DynamoItem> = Record<string, DynamoItem>>(): BatchBuilder<TEntities>;
127
- /**
128
- * Executes a transaction using a callback function
129
- *
130
- * @param callback A function that receives a transaction context and performs operations on it
131
- * @param options Optional transaction options
132
- * @returns A promise that resolves when the transaction is complete
133
- */
134
- transaction(callback: (tx: TransactionBuilder) => Promise<void> | void, options?: TransactionOptions): Promise<void>;
135
- /**
136
- * Creates a condition check operation for use in transactions
137
- *
138
- * This is useful for when you require a transaction to succeed only when a specific condition is met on a
139
- * a record within the database that you are not directly updating.
140
- *
141
- * For example, you are updating a record and you want to ensure that another record exists and/or has a specific value before proceeding.
142
- */
143
- conditionCheck(keyCondition: PrimaryKeyWithoutExpression): ConditionCheckBuilder;
144
- /**
145
- * Performs a batch get operation to retrieve multiple items at once
146
- *
147
- * @param keys Array of primary keys to retrieve
148
- * @returns A promise that resolves to the retrieved items
149
- */
150
- batchGet<T extends DynamoItem>(keys: Array<PrimaryKeyWithoutExpression>): Promise<{
151
- items: T[];
152
- unprocessedKeys: PrimaryKeyWithoutExpression[];
153
- }>;
154
- /**
155
- * Performs a batch write operation to put or delete multiple items at once
156
- *
157
- * @param operations Array of put or delete operations
158
- * @returns A promise that resolves to any unprocessed operations
159
- */
160
- batchWrite<T extends DynamoItem>(operations: Array<BatchWriteOperation<T>>): Promise<{
161
- unprocessedItems: Array<BatchWriteOperation<T>>;
162
- }>;
163
- }
164
-
165
- export { Table };
package/dist/types.d.cts DELETED
@@ -1,29 +0,0 @@
1
- import { DynamoDBDocument } from '@aws-sdk/lib-dynamodb';
2
-
3
- type DynamoItem = {
4
- [key: string]: unknown;
5
- };
6
- interface Index<T extends DynamoItem = DynamoItem> {
7
- partitionKey: string;
8
- sortKey?: string;
9
- /** Function to generate the index key from an item */
10
- generateKey?: (item: T, safeParse?: boolean) => {
11
- pk: string;
12
- sk?: string;
13
- };
14
- /** Whether the index is read-only */
15
- isReadOnly?: boolean;
16
- }
17
- interface IndexConfig {
18
- partitionKey: string;
19
- sortKey?: string;
20
- gsis?: Record<string, Index>;
21
- }
22
- interface TableConfig {
23
- client: DynamoDBDocument;
24
- tableName: string;
25
- indexes: IndexConfig;
26
- }
27
- type GSINames<T extends TableConfig> = keyof NonNullable<T["indexes"]["gsis"]>;
28
-
29
- export type { DynamoItem, GSINames, Index, IndexConfig, TableConfig };
package/dist/utils.d.cts DELETED
@@ -1,66 +0,0 @@
1
- type StrictGenerateType<T extends readonly string[]> = {
2
- [K in T[number]]: string;
3
- };
4
- /**
5
- * Creates a template function for generating DynamoDB partition keys with dynamic values.
6
- * Use this function when you need to:
7
- * - Create consistent partition key patterns with variable parts
8
- * - Generate partition keys that follow a specific format
9
- * - Ensure type safety for partition key parameters
10
- * - Require all parameters to be provided
11
- *
12
- * @example
13
- * ```ts
14
- * // Define a partition key template
15
- * const pk = partitionKey`country#${"country"}#enclosure#${"enclosure"}`;
16
- *
17
- * // Generate a partition key (all parameters required)
18
- * const key = pk({ country: "NZ", enclosure: "A1" });
19
- * // Result: "country#NZ#enclosure#A1"
20
- *
21
- * // Type checking ensures all parameters are provided
22
- * const invalidKey = pk({ country: "NZ" }); // TypeScript error
23
- * ```
24
- *
25
- * @param strings - The static parts of the template string
26
- * @param keys - The dynamic parts of the template string that will be replaced with values
27
- *
28
- * @returns A function that accepts an object with the dynamic values and returns the formatted partition key
29
- */
30
- declare function partitionKey<T extends readonly string[]>(strings: TemplateStringsArray, ...keys: T): (params: StrictGenerateType<T>) => string;
31
-
32
- type GenerateType<T extends readonly string[], U extends string = never> = T extends [infer F, ...infer R] ? F extends string ? R extends string[] ? ({
33
- [K in F | U]: string | number;
34
- } & Partial<Record<Exclude<T[number], F | U>, never>>) | GenerateType<R, F | U> : never : never : never;
35
- /**
36
- * Creates a template function for generating DynamoDB sort keys with dynamic values.
37
- * Use this function when you need to:
38
- * - Create consistent sort key patterns with variable parts
39
- * - Generate sort keys that follow a specific format
40
- * - Ensure type safety for sort key parameters
41
- *
42
- * @example
43
- * ```ts
44
- * // Define a sort key template
45
- * const sk = sortKey`country#${"country"}#enclosure#${"enclosure"}#diet#${"diet"}`;
46
- *
47
- * // Generate a sort key with partial parameters
48
- * const templatedString = sk({ country: "NZ", enclosure: "A1" });
49
- * // Result: "country#NZ#enclosure#A1#diet#"
50
- *
51
- * // Generate a complete sort key
52
- * const fullKey = sk({ country: "NZ", enclosure: "A1", diet: "carnivore" });
53
- * // Result: "country#NZ#enclosure#A1#diet#carnivore"
54
- *
55
- * // Type checking ensures only valid parameters are used
56
- * const invalidKey = sk({ country: "NZ", invalid: "value" }); // TypeScript error
57
- * ```
58
- *
59
- * @param strings - The static parts of the template string
60
- * @param keys - The dynamic parts of the template string that will be replaced with values
61
- *
62
- * @returns A function that accepts an object with the dynamic values and returns the formatted sort key
63
- */
64
- declare function sortKey<T extends readonly string[]>(strings: TemplateStringsArray, ...keys: T): (params: GenerateType<T>) => string;
65
-
66
- export { partitionKey, sortKey };