dyno-table 2.2.0 → 2.3.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 (106) hide show
  1. package/README.md +200 -1860
  2. package/dist/builders.cjs +55 -0
  3. package/dist/builders.d.cts +4 -0
  4. package/dist/builders.d.ts +4 -0
  5. package/dist/builders.js +2 -0
  6. package/dist/chunk-2EWNZOUK.js +618 -0
  7. package/dist/chunk-2WIBY7PZ.js +46 -0
  8. package/dist/chunk-7UJJ7JXM.cjs +63 -0
  9. package/dist/chunk-DTFJJASK.js +3200 -0
  10. package/dist/chunk-EODPMYPE.js +558 -0
  11. package/dist/chunk-KA3VPIPS.cjs +560 -0
  12. package/dist/chunk-NTA6GDPP.cjs +622 -0
  13. package/dist/chunk-PB7BBCZO.cjs +32 -0
  14. package/dist/chunk-QVRMYGC4.js +29 -0
  15. package/dist/chunk-XYL43FDX.cjs +3217 -0
  16. package/dist/{conditions-CC3NDfUU.d.cts → conditions-CcZL0sR2.d.cts} +1 -1
  17. package/dist/{conditions-DD0bvyHm.d.ts → conditions-D_w7vVYG.d.ts} +1 -1
  18. package/dist/conditions.cjs +67 -62
  19. package/dist/conditions.d.cts +1 -1
  20. package/dist/conditions.d.ts +1 -1
  21. package/dist/conditions.js +1 -48
  22. package/dist/entity.cjs +14 -625
  23. package/dist/entity.d.cts +5 -13
  24. package/dist/entity.d.ts +5 -13
  25. package/dist/entity.js +2 -626
  26. package/dist/index-2cbm07Bi.d.ts +2797 -0
  27. package/dist/index-DlN8G9hd.d.cts +2797 -0
  28. package/dist/index.cjs +111 -4446
  29. package/dist/index.d.cts +3 -11
  30. package/dist/index.d.ts +3 -11
  31. package/dist/index.js +5 -4428
  32. package/dist/standard-schema.cjs +0 -2
  33. package/dist/standard-schema.js +0 -2
  34. package/dist/table.cjs +7 -3782
  35. package/dist/table.d.cts +163 -12
  36. package/dist/table.d.ts +163 -12
  37. package/dist/table.js +3 -3785
  38. package/dist/types.cjs +0 -2
  39. package/dist/types.js +0 -2
  40. package/dist/utils.cjs +10 -30
  41. package/dist/utils.js +1 -31
  42. package/package.json +12 -67
  43. package/dist/batch-builder-BPoHyN_Q.d.cts +0 -398
  44. package/dist/batch-builder-Cdo49C2r.d.ts +0 -398
  45. package/dist/builder-types-BTVhQSHI.d.cts +0 -169
  46. package/dist/builder-types-CzuLR4Th.d.ts +0 -169
  47. package/dist/builders/condition-check-builder.cjs +0 -422
  48. package/dist/builders/condition-check-builder.cjs.map +0 -1
  49. package/dist/builders/condition-check-builder.d.cts +0 -153
  50. package/dist/builders/condition-check-builder.d.ts +0 -153
  51. package/dist/builders/condition-check-builder.js +0 -420
  52. package/dist/builders/condition-check-builder.js.map +0 -1
  53. package/dist/builders/delete-builder.cjs +0 -484
  54. package/dist/builders/delete-builder.cjs.map +0 -1
  55. package/dist/builders/delete-builder.d.cts +0 -211
  56. package/dist/builders/delete-builder.d.ts +0 -211
  57. package/dist/builders/delete-builder.js +0 -482
  58. package/dist/builders/delete-builder.js.map +0 -1
  59. package/dist/builders/paginator.cjs +0 -193
  60. package/dist/builders/paginator.cjs.map +0 -1
  61. package/dist/builders/paginator.d.cts +0 -155
  62. package/dist/builders/paginator.d.ts +0 -155
  63. package/dist/builders/paginator.js +0 -191
  64. package/dist/builders/paginator.js.map +0 -1
  65. package/dist/builders/put-builder.cjs +0 -554
  66. package/dist/builders/put-builder.cjs.map +0 -1
  67. package/dist/builders/put-builder.d.cts +0 -319
  68. package/dist/builders/put-builder.d.ts +0 -319
  69. package/dist/builders/put-builder.js +0 -552
  70. package/dist/builders/put-builder.js.map +0 -1
  71. package/dist/builders/query-builder.cjs +0 -743
  72. package/dist/builders/query-builder.cjs.map +0 -1
  73. package/dist/builders/query-builder.d.cts +0 -6
  74. package/dist/builders/query-builder.d.ts +0 -6
  75. package/dist/builders/query-builder.js +0 -741
  76. package/dist/builders/query-builder.js.map +0 -1
  77. package/dist/builders/transaction-builder.cjs +0 -906
  78. package/dist/builders/transaction-builder.cjs.map +0 -1
  79. package/dist/builders/transaction-builder.d.cts +0 -464
  80. package/dist/builders/transaction-builder.d.ts +0 -464
  81. package/dist/builders/transaction-builder.js +0 -904
  82. package/dist/builders/transaction-builder.js.map +0 -1
  83. package/dist/builders/update-builder.cjs +0 -668
  84. package/dist/builders/update-builder.cjs.map +0 -1
  85. package/dist/builders/update-builder.d.cts +0 -374
  86. package/dist/builders/update-builder.d.ts +0 -374
  87. package/dist/builders/update-builder.js +0 -666
  88. package/dist/builders/update-builder.js.map +0 -1
  89. package/dist/conditions.cjs.map +0 -1
  90. package/dist/conditions.js.map +0 -1
  91. package/dist/entity.cjs.map +0 -1
  92. package/dist/entity.js.map +0 -1
  93. package/dist/index.cjs.map +0 -1
  94. package/dist/index.js.map +0 -1
  95. package/dist/query-builder-CUWdavZw.d.ts +0 -477
  96. package/dist/query-builder-DoZzZz_c.d.cts +0 -477
  97. package/dist/standard-schema.cjs.map +0 -1
  98. package/dist/standard-schema.js.map +0 -1
  99. package/dist/table-CZBMkW2Z.d.ts +0 -276
  100. package/dist/table-f-3wsT7K.d.cts +0 -276
  101. package/dist/table.cjs.map +0 -1
  102. package/dist/table.js.map +0 -1
  103. package/dist/types.cjs.map +0 -1
  104. package/dist/types.js.map +0 -1
  105. package/dist/utils.cjs.map +0 -1
  106. package/dist/utils.js.map +0 -1
package/dist/table.d.cts CHANGED
@@ -1,13 +1,164 @@
1
- import './batch-builder-BPoHyN_Q.cjs';
2
- import './builders/condition-check-builder.cjs';
3
- import './builders/delete-builder.cjs';
4
- import './builders/put-builder.cjs';
5
- import './query-builder-DoZzZz_c.cjs';
6
- export { T as Table } from './table-f-3wsT7K.cjs';
7
- import './builders/transaction-builder.cjs';
8
- import './builders/update-builder.cjs';
9
- import './conditions-CC3NDfUU.cjs';
10
- import './types.cjs';
11
- import './builder-types-BTVhQSHI.cjs';
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, f as TransactionOptions, C as ConditionCheckBuilder, h as BatchWriteOperation } from './index-DlN8G9hd.cjs';
2
+ import { c as PrimaryKeyWithoutExpression, P as PrimaryKey } from './conditions-CcZL0sR2.cjs';
3
+ import { TableConfig, Index, DynamoItem } from './types.cjs';
12
4
  import '@aws-sdk/lib-dynamodb';
13
- import './builders/paginator.cjs';
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
+ protected createKeyForPrimaryIndex(keyCondition: PrimaryKeyWithoutExpression): Record<string, unknown>;
23
+ /**
24
+ * Creates a new item in the table, it will fail if the item already exists.
25
+ *
26
+ * By default, this method returns the input values passed to the create operation
27
+ * upon successful creation.
28
+ *
29
+ * You can customise the return behaviour by chaining the `.returnValues()` method:
30
+ *
31
+ * @param item The item to create
32
+ * @returns A PutBuilder instance for chaining additional conditions and executing the create operation
33
+ *
34
+ * @example
35
+ * ```ts
36
+ * // Create with default behavior (returns input values)
37
+ * const result = await table.create({
38
+ * id: 'user-123',
39
+ * name: 'John Doe',
40
+ * email: 'john@example.com'
41
+ * }).execute();
42
+ * console.log(result); // Returns the input object
43
+ *
44
+ * // Create with no return value for better performance
45
+ * await table.create(userData).returnValues('NONE').execute();
46
+ *
47
+ * // Create and get fresh data from dynamodb using a strongly consistent read
48
+ * const freshData = await table.create(userData).returnValues('CONSISTENT').execute();
49
+ *
50
+ * // Create and get previous values (if the item was overwritten)
51
+ * const oldData = await table.create(userData).returnValues('ALL_OLD').execute();
52
+ * ```
53
+ */
54
+ create<T extends DynamoItem>(item: T): PutBuilder<T>;
55
+ get<T extends DynamoItem>(keyCondition: PrimaryKeyWithoutExpression): GetBuilder<T>;
56
+ /**
57
+ * Updates an item in the table
58
+ *
59
+ * @param item The item to update
60
+ * @returns A PutBuilder instance for chaining conditions and executing the put operation
61
+ */
62
+ put<T extends DynamoItem>(item: T): PutBuilder<T>;
63
+ /**
64
+ * Creates a query builder for complex queries
65
+ * If useIndex is called on the returned QueryBuilder, it will use the GSI configuration
66
+ */
67
+ query<T extends DynamoItem>(keyCondition: PrimaryKey): QueryBuilder<T, TConfig>;
68
+ /**
69
+ * Creates a scan builder for scanning the entire table
70
+ * Use this when you need to:
71
+ * - Process all items in a table
72
+ * - Apply filters to a large dataset
73
+ * - Use a GSI for scanning
74
+ *
75
+ * @returns A ScanBuilder instance for chaining operations
76
+ */
77
+ scan<T extends DynamoItem>(): ScanBuilder<T, TConfig>;
78
+ delete(keyCondition: PrimaryKeyWithoutExpression): DeleteBuilder;
79
+ /**
80
+ * Updates an item in the table
81
+ *
82
+ * @param keyCondition The primary key of the item to update
83
+ * @returns An UpdateBuilder instance for chaining update operations and conditions
84
+ */
85
+ update<T extends DynamoItem>(keyCondition: PrimaryKeyWithoutExpression): UpdateBuilder<T>;
86
+ /**
87
+ * Creates a transaction builder for performing multiple operations atomically
88
+ */
89
+ transactionBuilder(): TransactionBuilder;
90
+ /**
91
+ * Creates a batch builder for performing multiple operations efficiently with optional type inference
92
+ *
93
+ * @example Basic Usage
94
+ * ```typescript
95
+ * const batch = table.batchBuilder();
96
+ *
97
+ * // Add operations
98
+ * userRepo.create(newUser).withBatch(batch);
99
+ * orderRepo.get({ id: 'order-1' }).withBatch(batch);
100
+ *
101
+ * // Execute operations
102
+ * const result = await batch.execute();
103
+ * ```
104
+ *
105
+ * @example Typed Usage
106
+ * ```typescript
107
+ * // Define entity types for the batch
108
+ * const batch = table.batchBuilder<{
109
+ * User: UserEntity;
110
+ * Order: OrderEntity;
111
+ * Product: ProductEntity;
112
+ * }>();
113
+ *
114
+ * // Add operations with type information
115
+ * userRepo.create(newUser).withBatch(batch, 'User');
116
+ * orderRepo.get({ id: 'order-1' }).withBatch(batch, 'Order');
117
+ * productRepo.delete({ id: 'old-product' }).withBatch(batch, 'Product');
118
+ *
119
+ * // Execute and get typed results
120
+ * const result = await batch.execute();
121
+ * const users: UserEntity[] = result.reads.itemsByType.User;
122
+ * const orders: OrderEntity[] = result.reads.itemsByType.Order;
123
+ * ```
124
+ */
125
+ batchBuilder<TEntities extends Record<string, DynamoItem> = Record<string, DynamoItem>>(): BatchBuilder<TEntities>;
126
+ /**
127
+ * Executes a transaction using a callback function
128
+ *
129
+ * @param callback A function that receives a transaction context and performs operations on it
130
+ * @param options Optional transaction options
131
+ * @returns A promise that resolves when the transaction is complete
132
+ */
133
+ transaction(callback: (tx: TransactionBuilder) => Promise<void> | void, options?: TransactionOptions): Promise<void>;
134
+ /**
135
+ * Creates a condition check operation for use in transactions
136
+ *
137
+ * This is useful for when you require a transaction to succeed only when a specific condition is met on a
138
+ * a record within the database that you are not directly updating.
139
+ *
140
+ * For example, you are updating a record and you want to ensure that another record exists and/or has a specific value before proceeding.
141
+ */
142
+ conditionCheck(keyCondition: PrimaryKeyWithoutExpression): ConditionCheckBuilder;
143
+ /**
144
+ * Performs a batch get operation to retrieve multiple items at once
145
+ *
146
+ * @param keys Array of primary keys to retrieve
147
+ * @returns A promise that resolves to the retrieved items
148
+ */
149
+ batchGet<T extends DynamoItem>(keys: Array<PrimaryKeyWithoutExpression>): Promise<{
150
+ items: T[];
151
+ unprocessedKeys: PrimaryKeyWithoutExpression[];
152
+ }>;
153
+ /**
154
+ * Performs a batch write operation to put or delete multiple items at once
155
+ *
156
+ * @param operations Array of put or delete operations
157
+ * @returns A promise that resolves to any unprocessed operations
158
+ */
159
+ batchWrite<T extends DynamoItem>(operations: Array<BatchWriteOperation<T>>): Promise<{
160
+ unprocessedItems: Array<BatchWriteOperation<T>>;
161
+ }>;
162
+ }
163
+
164
+ export { Table };
package/dist/table.d.ts CHANGED
@@ -1,13 +1,164 @@
1
- import './batch-builder-Cdo49C2r.js';
2
- import './builders/condition-check-builder.js';
3
- import './builders/delete-builder.js';
4
- import './builders/put-builder.js';
5
- import './query-builder-CUWdavZw.js';
6
- export { T as Table } from './table-CZBMkW2Z.js';
7
- import './builders/transaction-builder.js';
8
- import './builders/update-builder.js';
9
- import './conditions-DD0bvyHm.js';
10
- import './types.js';
11
- import './builder-types-CzuLR4Th.js';
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, f as TransactionOptions, C as ConditionCheckBuilder, h as BatchWriteOperation } from './index-2cbm07Bi.js';
2
+ import { c as PrimaryKeyWithoutExpression, P as PrimaryKey } from './conditions-D_w7vVYG.js';
3
+ import { TableConfig, Index, DynamoItem } from './types.js';
12
4
  import '@aws-sdk/lib-dynamodb';
13
- import './builders/paginator.js';
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
+ protected createKeyForPrimaryIndex(keyCondition: PrimaryKeyWithoutExpression): Record<string, unknown>;
23
+ /**
24
+ * Creates a new item in the table, it will fail if the item already exists.
25
+ *
26
+ * By default, this method returns the input values passed to the create operation
27
+ * upon successful creation.
28
+ *
29
+ * You can customise the return behaviour by chaining the `.returnValues()` method:
30
+ *
31
+ * @param item The item to create
32
+ * @returns A PutBuilder instance for chaining additional conditions and executing the create operation
33
+ *
34
+ * @example
35
+ * ```ts
36
+ * // Create with default behavior (returns input values)
37
+ * const result = await table.create({
38
+ * id: 'user-123',
39
+ * name: 'John Doe',
40
+ * email: 'john@example.com'
41
+ * }).execute();
42
+ * console.log(result); // Returns the input object
43
+ *
44
+ * // Create with no return value for better performance
45
+ * await table.create(userData).returnValues('NONE').execute();
46
+ *
47
+ * // Create and get fresh data from dynamodb using a strongly consistent read
48
+ * const freshData = await table.create(userData).returnValues('CONSISTENT').execute();
49
+ *
50
+ * // Create and get previous values (if the item was overwritten)
51
+ * const oldData = await table.create(userData).returnValues('ALL_OLD').execute();
52
+ * ```
53
+ */
54
+ create<T extends DynamoItem>(item: T): PutBuilder<T>;
55
+ get<T extends DynamoItem>(keyCondition: PrimaryKeyWithoutExpression): GetBuilder<T>;
56
+ /**
57
+ * Updates an item in the table
58
+ *
59
+ * @param item The item to update
60
+ * @returns A PutBuilder instance for chaining conditions and executing the put operation
61
+ */
62
+ put<T extends DynamoItem>(item: T): PutBuilder<T>;
63
+ /**
64
+ * Creates a query builder for complex queries
65
+ * If useIndex is called on the returned QueryBuilder, it will use the GSI configuration
66
+ */
67
+ query<T extends DynamoItem>(keyCondition: PrimaryKey): QueryBuilder<T, TConfig>;
68
+ /**
69
+ * Creates a scan builder for scanning the entire table
70
+ * Use this when you need to:
71
+ * - Process all items in a table
72
+ * - Apply filters to a large dataset
73
+ * - Use a GSI for scanning
74
+ *
75
+ * @returns A ScanBuilder instance for chaining operations
76
+ */
77
+ scan<T extends DynamoItem>(): ScanBuilder<T, TConfig>;
78
+ delete(keyCondition: PrimaryKeyWithoutExpression): DeleteBuilder;
79
+ /**
80
+ * Updates an item in the table
81
+ *
82
+ * @param keyCondition The primary key of the item to update
83
+ * @returns An UpdateBuilder instance for chaining update operations and conditions
84
+ */
85
+ update<T extends DynamoItem>(keyCondition: PrimaryKeyWithoutExpression): UpdateBuilder<T>;
86
+ /**
87
+ * Creates a transaction builder for performing multiple operations atomically
88
+ */
89
+ transactionBuilder(): TransactionBuilder;
90
+ /**
91
+ * Creates a batch builder for performing multiple operations efficiently with optional type inference
92
+ *
93
+ * @example Basic Usage
94
+ * ```typescript
95
+ * const batch = table.batchBuilder();
96
+ *
97
+ * // Add operations
98
+ * userRepo.create(newUser).withBatch(batch);
99
+ * orderRepo.get({ id: 'order-1' }).withBatch(batch);
100
+ *
101
+ * // Execute operations
102
+ * const result = await batch.execute();
103
+ * ```
104
+ *
105
+ * @example Typed Usage
106
+ * ```typescript
107
+ * // Define entity types for the batch
108
+ * const batch = table.batchBuilder<{
109
+ * User: UserEntity;
110
+ * Order: OrderEntity;
111
+ * Product: ProductEntity;
112
+ * }>();
113
+ *
114
+ * // Add operations with type information
115
+ * userRepo.create(newUser).withBatch(batch, 'User');
116
+ * orderRepo.get({ id: 'order-1' }).withBatch(batch, 'Order');
117
+ * productRepo.delete({ id: 'old-product' }).withBatch(batch, 'Product');
118
+ *
119
+ * // Execute and get typed results
120
+ * const result = await batch.execute();
121
+ * const users: UserEntity[] = result.reads.itemsByType.User;
122
+ * const orders: OrderEntity[] = result.reads.itemsByType.Order;
123
+ * ```
124
+ */
125
+ batchBuilder<TEntities extends Record<string, DynamoItem> = Record<string, DynamoItem>>(): BatchBuilder<TEntities>;
126
+ /**
127
+ * Executes a transaction using a callback function
128
+ *
129
+ * @param callback A function that receives a transaction context and performs operations on it
130
+ * @param options Optional transaction options
131
+ * @returns A promise that resolves when the transaction is complete
132
+ */
133
+ transaction(callback: (tx: TransactionBuilder) => Promise<void> | void, options?: TransactionOptions): Promise<void>;
134
+ /**
135
+ * Creates a condition check operation for use in transactions
136
+ *
137
+ * This is useful for when you require a transaction to succeed only when a specific condition is met on a
138
+ * a record within the database that you are not directly updating.
139
+ *
140
+ * For example, you are updating a record and you want to ensure that another record exists and/or has a specific value before proceeding.
141
+ */
142
+ conditionCheck(keyCondition: PrimaryKeyWithoutExpression): ConditionCheckBuilder;
143
+ /**
144
+ * Performs a batch get operation to retrieve multiple items at once
145
+ *
146
+ * @param keys Array of primary keys to retrieve
147
+ * @returns A promise that resolves to the retrieved items
148
+ */
149
+ batchGet<T extends DynamoItem>(keys: Array<PrimaryKeyWithoutExpression>): Promise<{
150
+ items: T[];
151
+ unprocessedKeys: PrimaryKeyWithoutExpression[];
152
+ }>;
153
+ /**
154
+ * Performs a batch write operation to put or delete multiple items at once
155
+ *
156
+ * @param operations Array of put or delete operations
157
+ * @returns A promise that resolves to any unprocessed operations
158
+ */
159
+ batchWrite<T extends DynamoItem>(operations: Array<BatchWriteOperation<T>>): Promise<{
160
+ unprocessedItems: Array<BatchWriteOperation<T>>;
161
+ }>;
162
+ }
163
+
164
+ export { Table };