dyno-table 2.2.1 → 2.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +187 -1865
- package/dist/builders.cjs +55 -0
- package/dist/builders.d.cts +4 -0
- package/dist/builders.d.ts +4 -0
- package/dist/builders.js +2 -0
- package/dist/chunk-2EWNZOUK.js +618 -0
- package/dist/chunk-2WIBY7PZ.js +46 -0
- package/dist/chunk-7UJJ7JXM.cjs +63 -0
- package/dist/chunk-DTFJJASK.js +3200 -0
- package/dist/chunk-EODPMYPE.js +558 -0
- package/dist/chunk-KA3VPIPS.cjs +560 -0
- package/dist/chunk-NTA6GDPP.cjs +622 -0
- package/dist/chunk-PB7BBCZO.cjs +32 -0
- package/dist/chunk-QVRMYGC4.js +29 -0
- package/dist/chunk-XYL43FDX.cjs +3217 -0
- package/dist/conditions.cjs +67 -62
- package/dist/conditions.js +1 -48
- package/dist/entity.cjs +14 -625
- package/dist/entity.d.cts +2 -10
- package/dist/entity.d.ts +2 -10
- package/dist/entity.js +2 -626
- package/dist/index-2cbm07Bi.d.ts +2797 -0
- package/dist/index-DlN8G9hd.d.cts +2797 -0
- package/dist/index.cjs +111 -4460
- package/dist/index.d.cts +2 -10
- package/dist/index.d.ts +2 -10
- package/dist/index.js +5 -4442
- package/dist/standard-schema.cjs +0 -2
- package/dist/standard-schema.js +0 -2
- package/dist/table.cjs +7 -3796
- package/dist/table.d.cts +163 -12
- package/dist/table.d.ts +163 -12
- package/dist/table.js +3 -3799
- package/dist/types.cjs +0 -2
- package/dist/types.js +0 -2
- package/dist/utils.cjs +10 -30
- package/dist/utils.js +1 -31
- package/package.json +6 -66
- package/dist/batch-builder-BiQDIZ7p.d.cts +0 -398
- package/dist/batch-builder-CNsLS6sR.d.ts +0 -398
- package/dist/builder-types-BTVhQSHI.d.cts +0 -169
- package/dist/builder-types-CzuLR4Th.d.ts +0 -169
- package/dist/builders/condition-check-builder.cjs +0 -422
- package/dist/builders/condition-check-builder.cjs.map +0 -1
- package/dist/builders/condition-check-builder.d.cts +0 -153
- package/dist/builders/condition-check-builder.d.ts +0 -153
- package/dist/builders/condition-check-builder.js +0 -420
- package/dist/builders/condition-check-builder.js.map +0 -1
- package/dist/builders/delete-builder.cjs +0 -484
- package/dist/builders/delete-builder.cjs.map +0 -1
- package/dist/builders/delete-builder.d.cts +0 -211
- package/dist/builders/delete-builder.d.ts +0 -211
- package/dist/builders/delete-builder.js +0 -482
- package/dist/builders/delete-builder.js.map +0 -1
- package/dist/builders/paginator.cjs +0 -193
- package/dist/builders/paginator.cjs.map +0 -1
- package/dist/builders/paginator.d.cts +0 -155
- package/dist/builders/paginator.d.ts +0 -155
- package/dist/builders/paginator.js +0 -191
- package/dist/builders/paginator.js.map +0 -1
- package/dist/builders/put-builder.cjs +0 -554
- package/dist/builders/put-builder.cjs.map +0 -1
- package/dist/builders/put-builder.d.cts +0 -319
- package/dist/builders/put-builder.d.ts +0 -319
- package/dist/builders/put-builder.js +0 -552
- package/dist/builders/put-builder.js.map +0 -1
- package/dist/builders/query-builder.cjs +0 -757
- package/dist/builders/query-builder.cjs.map +0 -1
- package/dist/builders/query-builder.d.cts +0 -6
- package/dist/builders/query-builder.d.ts +0 -6
- package/dist/builders/query-builder.js +0 -755
- package/dist/builders/query-builder.js.map +0 -1
- package/dist/builders/transaction-builder.cjs +0 -906
- package/dist/builders/transaction-builder.cjs.map +0 -1
- package/dist/builders/transaction-builder.d.cts +0 -464
- package/dist/builders/transaction-builder.d.ts +0 -464
- package/dist/builders/transaction-builder.js +0 -904
- package/dist/builders/transaction-builder.js.map +0 -1
- package/dist/builders/update-builder.cjs +0 -668
- package/dist/builders/update-builder.cjs.map +0 -1
- package/dist/builders/update-builder.d.cts +0 -374
- package/dist/builders/update-builder.d.ts +0 -374
- package/dist/builders/update-builder.js +0 -666
- package/dist/builders/update-builder.js.map +0 -1
- package/dist/conditions.cjs.map +0 -1
- package/dist/conditions.js.map +0 -1
- package/dist/entity.cjs.map +0 -1
- package/dist/entity.js.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/query-builder-D3URwK9k.d.cts +0 -477
- package/dist/query-builder-cfEkU0_w.d.ts +0 -477
- package/dist/standard-schema.cjs.map +0 -1
- package/dist/standard-schema.js.map +0 -1
- package/dist/table-ClST8nkR.d.cts +0 -276
- package/dist/table-vE3cGoDy.d.ts +0 -276
- package/dist/table.cjs.map +0 -1
- package/dist/table.js.map +0 -1
- package/dist/types.cjs.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/utils.cjs.map +0 -1
- package/dist/utils.js.map +0 -1
package/dist/types.cjs
CHANGED
package/dist/types.js
CHANGED
package/dist/utils.cjs
CHANGED
|
@@ -1,34 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
function partitionKey(strings, ...keys) {
|
|
5
|
-
return (params) => {
|
|
6
|
-
let result = strings[0] ?? "";
|
|
7
|
-
for (let i = 0; i < keys.length; i++) {
|
|
8
|
-
const key = keys[i];
|
|
9
|
-
if (key) {
|
|
10
|
-
result += params[key] + (strings[i + 1] ?? "");
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
return result;
|
|
14
|
-
};
|
|
15
|
-
}
|
|
3
|
+
var chunkPB7BBCZO_cjs = require('./chunk-PB7BBCZO.cjs');
|
|
16
4
|
|
|
17
|
-
// src/utils/sort-key-template.ts
|
|
18
|
-
function sortKey(strings, ...keys) {
|
|
19
|
-
return (params) => {
|
|
20
|
-
let result = strings[0] ?? "";
|
|
21
|
-
for (let i = 0; i < keys.length; i++) {
|
|
22
|
-
const key = keys[i];
|
|
23
|
-
if (key && params && key in params) {
|
|
24
|
-
result += params[key] + (strings[i + 1] ?? "");
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return result;
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
5
|
|
|
31
|
-
|
|
32
|
-
exports
|
|
33
|
-
|
|
34
|
-
|
|
6
|
+
|
|
7
|
+
Object.defineProperty(exports, "partitionKey", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () { return chunkPB7BBCZO_cjs.partitionKey; }
|
|
10
|
+
});
|
|
11
|
+
Object.defineProperty(exports, "sortKey", {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: function () { return chunkPB7BBCZO_cjs.sortKey; }
|
|
14
|
+
});
|
package/dist/utils.js
CHANGED
|
@@ -1,31 +1 @@
|
|
|
1
|
-
|
|
2
|
-
function partitionKey(strings, ...keys) {
|
|
3
|
-
return (params) => {
|
|
4
|
-
let result = strings[0] ?? "";
|
|
5
|
-
for (let i = 0; i < keys.length; i++) {
|
|
6
|
-
const key = keys[i];
|
|
7
|
-
if (key) {
|
|
8
|
-
result += params[key] + (strings[i + 1] ?? "");
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
return result;
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// src/utils/sort-key-template.ts
|
|
16
|
-
function sortKey(strings, ...keys) {
|
|
17
|
-
return (params) => {
|
|
18
|
-
let result = strings[0] ?? "";
|
|
19
|
-
for (let i = 0; i < keys.length; i++) {
|
|
20
|
-
const key = keys[i];
|
|
21
|
-
if (key && params && key in params) {
|
|
22
|
-
result += params[key] + (strings[i + 1] ?? "");
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return result;
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export { partitionKey, sortKey };
|
|
30
|
-
//# sourceMappingURL=utils.js.map
|
|
31
|
-
//# sourceMappingURL=utils.js.map
|
|
1
|
+
export { partitionKey, sortKey } from './chunk-QVRMYGC4.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dyno-table",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.1",
|
|
4
4
|
"description": "A TypeScript library to simplify working with DynamoDB",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -77,74 +77,14 @@
|
|
|
77
77
|
"default": "./dist/utils.cjs"
|
|
78
78
|
}
|
|
79
79
|
},
|
|
80
|
-
"./builders
|
|
80
|
+
"./builders": {
|
|
81
81
|
"import": {
|
|
82
|
-
"types": "./dist/builders
|
|
83
|
-
"default": "./dist/builders
|
|
82
|
+
"types": "./dist/builders.d.ts",
|
|
83
|
+
"default": "./dist/builders.js"
|
|
84
84
|
},
|
|
85
85
|
"require": {
|
|
86
|
-
"types": "./dist/builders
|
|
87
|
-
"default": "./dist/builders
|
|
88
|
-
}
|
|
89
|
-
},
|
|
90
|
-
"./builders/paginator": {
|
|
91
|
-
"import": {
|
|
92
|
-
"types": "./dist/builders/paginator.d.ts",
|
|
93
|
-
"default": "./dist/builders/paginator.js"
|
|
94
|
-
},
|
|
95
|
-
"require": {
|
|
96
|
-
"types": "./dist/builders/paginator.d.cts",
|
|
97
|
-
"default": "./dist/builders/paginator.cjs"
|
|
98
|
-
}
|
|
99
|
-
},
|
|
100
|
-
"./builders/put-builder": {
|
|
101
|
-
"import": {
|
|
102
|
-
"types": "./dist/builders/put-builder.d.ts",
|
|
103
|
-
"default": "./dist/builders/put-builder.js"
|
|
104
|
-
},
|
|
105
|
-
"require": {
|
|
106
|
-
"types": "./dist/builders/put-builder.d.cts",
|
|
107
|
-
"default": "./dist/builders/put-builder.cjs"
|
|
108
|
-
}
|
|
109
|
-
},
|
|
110
|
-
"./builders/update-builder": {
|
|
111
|
-
"import": {
|
|
112
|
-
"types": "./dist/builders/update-builder.d.ts",
|
|
113
|
-
"default": "./dist/builders/update-builder.js"
|
|
114
|
-
},
|
|
115
|
-
"require": {
|
|
116
|
-
"types": "./dist/builders/update-builder.d.cts",
|
|
117
|
-
"default": "./dist/builders/update-builder.cjs"
|
|
118
|
-
}
|
|
119
|
-
},
|
|
120
|
-
"./builders/delete-builder": {
|
|
121
|
-
"import": {
|
|
122
|
-
"types": "./dist/builders/delete-builder.d.ts",
|
|
123
|
-
"default": "./dist/builders/delete-builder.js"
|
|
124
|
-
},
|
|
125
|
-
"require": {
|
|
126
|
-
"types": "./dist/builders/delete-builder.d.cts",
|
|
127
|
-
"default": "./dist/builders/delete-builder.cjs"
|
|
128
|
-
}
|
|
129
|
-
},
|
|
130
|
-
"./builders/transaction-builder": {
|
|
131
|
-
"import": {
|
|
132
|
-
"types": "./dist/builders/transaction-builder.d.ts",
|
|
133
|
-
"default": "./dist/builders/transaction-builder.js"
|
|
134
|
-
},
|
|
135
|
-
"require": {
|
|
136
|
-
"types": "./dist/builders/transaction-builder.d.cts",
|
|
137
|
-
"default": "./dist/builders/transaction-builder.cjs"
|
|
138
|
-
}
|
|
139
|
-
},
|
|
140
|
-
"./builders/condition-check-builder": {
|
|
141
|
-
"import": {
|
|
142
|
-
"types": "./dist/builders/condition-check-builder.d.ts",
|
|
143
|
-
"default": "./dist/builders/condition-check-builder.js"
|
|
144
|
-
},
|
|
145
|
-
"require": {
|
|
146
|
-
"types": "./dist/builders/condition-check-builder.d.cts",
|
|
147
|
-
"default": "./dist/builders/condition-check-builder.cjs"
|
|
86
|
+
"types": "./dist/builders.d.cts",
|
|
87
|
+
"default": "./dist/builders.cjs"
|
|
148
88
|
}
|
|
149
89
|
}
|
|
150
90
|
},
|
|
@@ -1,398 +0,0 @@
|
|
|
1
|
-
import { c as PrimaryKeyWithoutExpression, s as Path } from './conditions-CcZL0sR2.cjs';
|
|
2
|
-
import { DynamoItem } from './types.cjs';
|
|
3
|
-
import { a as PutCommandParams, D as DeleteCommandParams } from './builder-types-BTVhQSHI.cjs';
|
|
4
|
-
|
|
5
|
-
type BatchWriteOperation<T extends Record<string, unknown>> = {
|
|
6
|
-
type: "put";
|
|
7
|
-
item: T;
|
|
8
|
-
} | {
|
|
9
|
-
type: "delete";
|
|
10
|
-
key: PrimaryKeyWithoutExpression;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Parameters for the DynamoDB get command.
|
|
15
|
-
*/
|
|
16
|
-
interface GetCommandParams {
|
|
17
|
-
/** The name of the DynamoDB table */
|
|
18
|
-
tableName: string;
|
|
19
|
-
/** The primary key of the item to get */
|
|
20
|
-
key: PrimaryKeyWithoutExpression;
|
|
21
|
-
/** Comma-separated list of attributes to return */
|
|
22
|
-
projectionExpression?: string;
|
|
23
|
-
/** Map of expression attribute name placeholders to actual names */
|
|
24
|
-
expressionAttributeNames?: Record<string, string>;
|
|
25
|
-
/** Whether to use strongly consistent reads */
|
|
26
|
-
consistentRead?: boolean;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Function type for executing DynamoDB get operations.
|
|
30
|
-
* @typeParam T - The type of item being retrieved
|
|
31
|
-
*/
|
|
32
|
-
type GetExecutor<T extends DynamoItem> = (params: GetCommandParams) => Promise<{
|
|
33
|
-
item: T | undefined;
|
|
34
|
-
}>;
|
|
35
|
-
/**
|
|
36
|
-
* Builder for creating DynamoDB get operations.
|
|
37
|
-
* Use this builder when you need to:
|
|
38
|
-
* - Retrieve a single dinosaur by its primary key
|
|
39
|
-
* - Project specific dinosaur attributes
|
|
40
|
-
* - Use consistent reads for critical dinosaur data
|
|
41
|
-
*
|
|
42
|
-
* @example
|
|
43
|
-
* ```typescript
|
|
44
|
-
* // Simple get
|
|
45
|
-
* const result = await new GetBuilder(executor, { pk: 'dinosaur#123', sk: 'profile' })
|
|
46
|
-
* .execute();
|
|
47
|
-
*
|
|
48
|
-
* // Get with projection and consistent read
|
|
49
|
-
* const result = await new GetBuilder(executor, { pk: 'dinosaur#123', sk: 'profile' })
|
|
50
|
-
* .select(['species', 'name', 'diet'])
|
|
51
|
-
* .consistentRead()
|
|
52
|
-
* .execute();
|
|
53
|
-
* ```
|
|
54
|
-
*
|
|
55
|
-
* @typeParam T - The type of item being retrieved
|
|
56
|
-
*/
|
|
57
|
-
declare class GetBuilder<T extends DynamoItem> {
|
|
58
|
-
private readonly executor;
|
|
59
|
-
private readonly params;
|
|
60
|
-
private options;
|
|
61
|
-
private selectedFields;
|
|
62
|
-
/**
|
|
63
|
-
* Creates a new GetBuilder instance.
|
|
64
|
-
*
|
|
65
|
-
* @param executor - Function that executes the get operation
|
|
66
|
-
* @param key - Primary key of the item to retrieve
|
|
67
|
-
* @param tableName - Name of the DynamoDB table
|
|
68
|
-
*/
|
|
69
|
-
constructor(executor: GetExecutor<T>, key: PrimaryKeyWithoutExpression, tableName: string);
|
|
70
|
-
/**
|
|
71
|
-
* Specifies which attributes to return in the get results.
|
|
72
|
-
*
|
|
73
|
-
* @example
|
|
74
|
-
* ```typescript
|
|
75
|
-
* // Select single attribute
|
|
76
|
-
* builder.select('species')
|
|
77
|
-
*
|
|
78
|
-
* // Select multiple attributes
|
|
79
|
-
* builder.select(['id', 'species', 'diet'])
|
|
80
|
-
*
|
|
81
|
-
* // Chain multiple select calls
|
|
82
|
-
* builder
|
|
83
|
-
* .select('id')
|
|
84
|
-
* .select(['species', 'diet'])
|
|
85
|
-
* ```
|
|
86
|
-
*
|
|
87
|
-
* @param fields - A single field name or an array of field names to return
|
|
88
|
-
* @returns The builder instance for method chaining
|
|
89
|
-
*/
|
|
90
|
-
select<K extends Path<T>>(fields: K | K[]): GetBuilder<T>;
|
|
91
|
-
/**
|
|
92
|
-
* Sets whether to use strongly consistent reads for the get operation.
|
|
93
|
-
* Use this method when you need:
|
|
94
|
-
* - The most up-to-date dinosaur data
|
|
95
|
-
* - To ensure you're reading the latest dinosaur status
|
|
96
|
-
* - Critical safety information about dangerous species
|
|
97
|
-
*
|
|
98
|
-
* Note: Consistent reads consume twice the throughput
|
|
99
|
-
*
|
|
100
|
-
* @example
|
|
101
|
-
* ```typescript
|
|
102
|
-
* // Get the latest T-Rex data
|
|
103
|
-
* const result = await new GetBuilder(executor, { pk: 'dinosaur#123', sk: 'profile' })
|
|
104
|
-
* .consistentRead()
|
|
105
|
-
* .execute();
|
|
106
|
-
* ```
|
|
107
|
-
*
|
|
108
|
-
* @param consistentRead - Whether to use consistent reads (defaults to true)
|
|
109
|
-
* @returns The builder instance for method chaining
|
|
110
|
-
*/
|
|
111
|
-
consistentRead(consistentRead?: boolean): GetBuilder<T>;
|
|
112
|
-
/**
|
|
113
|
-
* Adds this get operation to a batch with optional entity type information.
|
|
114
|
-
*
|
|
115
|
-
* @example Basic Usage
|
|
116
|
-
* ```ts
|
|
117
|
-
* const batch = table.batchBuilder();
|
|
118
|
-
*
|
|
119
|
-
* // Add multiple get operations to batch
|
|
120
|
-
* dinosaurRepo.get({ id: 'dino-1' }).withBatch(batch);
|
|
121
|
-
* dinosaurRepo.get({ id: 'dino-2' }).withBatch(batch);
|
|
122
|
-
* dinosaurRepo.get({ id: 'dino-3' }).withBatch(batch);
|
|
123
|
-
*
|
|
124
|
-
* // Execute all gets efficiently
|
|
125
|
-
* const results = await batch.execute();
|
|
126
|
-
* ```
|
|
127
|
-
*
|
|
128
|
-
* @example Typed Usage
|
|
129
|
-
* ```ts
|
|
130
|
-
* const batch = table.batchBuilder<{
|
|
131
|
-
* User: UserEntity;
|
|
132
|
-
* Order: OrderEntity;
|
|
133
|
-
* }>();
|
|
134
|
-
*
|
|
135
|
-
* // Add operations with type information
|
|
136
|
-
* userRepo.get({ id: 'user-1' }).withBatch(batch, 'User');
|
|
137
|
-
* orderRepo.get({ id: 'order-1' }).withBatch(batch, 'Order');
|
|
138
|
-
*
|
|
139
|
-
* // Execute and get typed results
|
|
140
|
-
* const result = await batch.execute();
|
|
141
|
-
* const users: UserEntity[] = result.reads.itemsByType.User;
|
|
142
|
-
* const orders: OrderEntity[] = result.reads.itemsByType.Order;
|
|
143
|
-
* ```
|
|
144
|
-
*
|
|
145
|
-
* @param batch - The batch builder to add this operation to
|
|
146
|
-
* @param entityType - Optional entity type key for type tracking
|
|
147
|
-
*/
|
|
148
|
-
withBatch<TEntities extends Record<string, DynamoItem> = Record<string, DynamoItem>, K extends keyof TEntities = keyof TEntities>(batch: BatchBuilder<TEntities>, entityType?: K): void;
|
|
149
|
-
/**
|
|
150
|
-
* Converts the builder configuration to a DynamoDB command
|
|
151
|
-
*/
|
|
152
|
-
private toDynamoCommand;
|
|
153
|
-
/**
|
|
154
|
-
* Executes the get operation against DynamoDB.
|
|
155
|
-
*
|
|
156
|
-
* @example
|
|
157
|
-
* ```typescript
|
|
158
|
-
* try {
|
|
159
|
-
* const result = await new GetBuilder(executor, { pk: 'dinosaur#123', sk: 'profile' })
|
|
160
|
-
* .select(['species', 'name', 'diet'])
|
|
161
|
-
* .consistentRead()
|
|
162
|
-
* .execute();
|
|
163
|
-
*
|
|
164
|
-
* if (result.item) {
|
|
165
|
-
* console.log('Dinosaur found:', result.item);
|
|
166
|
-
* } else {
|
|
167
|
-
* console.log('Dinosaur not found');
|
|
168
|
-
* }
|
|
169
|
-
* } catch (error) {
|
|
170
|
-
* console.error('Error getting dinosaur:', error);
|
|
171
|
-
* }
|
|
172
|
-
* ```
|
|
173
|
-
*
|
|
174
|
-
* @returns A promise that resolves to an object containing:
|
|
175
|
-
* - item: The retrieved dinosaur or undefined if not found
|
|
176
|
-
*/
|
|
177
|
-
execute(): Promise<{
|
|
178
|
-
item: T | undefined;
|
|
179
|
-
}>;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* Configuration for batch operations
|
|
184
|
-
*/
|
|
185
|
-
interface BatchConfig {
|
|
186
|
-
partitionKey: string;
|
|
187
|
-
sortKey?: string;
|
|
188
|
-
}
|
|
189
|
-
/**
|
|
190
|
-
* Executor function for batch write operations
|
|
191
|
-
*/
|
|
192
|
-
type BatchWriteExecutor = (operations: Array<BatchWriteOperation<DynamoItem>>) => Promise<{
|
|
193
|
-
unprocessedItems: Array<BatchWriteOperation<DynamoItem>>;
|
|
194
|
-
}>;
|
|
195
|
-
/**
|
|
196
|
-
* Executor function for batch get operations
|
|
197
|
-
*/
|
|
198
|
-
type BatchGetExecutor = (keys: Array<PrimaryKeyWithoutExpression>) => Promise<{
|
|
199
|
-
items: DynamoItem[];
|
|
200
|
-
unprocessedKeys: PrimaryKeyWithoutExpression[];
|
|
201
|
-
}>;
|
|
202
|
-
/**
|
|
203
|
-
* Error class for batch operation failures
|
|
204
|
-
*/
|
|
205
|
-
declare class BatchError extends Error {
|
|
206
|
-
readonly operation: "write" | "read";
|
|
207
|
-
readonly cause?: Error;
|
|
208
|
-
constructor(message: string, operation: "write" | "read", cause?: Error);
|
|
209
|
-
}
|
|
210
|
-
/**
|
|
211
|
-
* Result structure for batch operations
|
|
212
|
-
*/
|
|
213
|
-
interface BatchResult {
|
|
214
|
-
/** Whether the batch operation completed successfully */
|
|
215
|
-
success: boolean;
|
|
216
|
-
/** Write operation results */
|
|
217
|
-
writes: {
|
|
218
|
-
/** Number of write operations processed successfully */
|
|
219
|
-
processed: number;
|
|
220
|
-
/** Write operations that were not processed and may need retry */
|
|
221
|
-
unprocessed: Array<BatchWriteOperation<DynamoItem>>;
|
|
222
|
-
};
|
|
223
|
-
/** Read operation results */
|
|
224
|
-
reads: {
|
|
225
|
-
/** Items retrieved from the batch get operations */
|
|
226
|
-
items: DynamoItem[];
|
|
227
|
-
/** Number of items found and returned */
|
|
228
|
-
found: number;
|
|
229
|
-
/** Keys that were not processed and may need retry */
|
|
230
|
-
unprocessed: PrimaryKeyWithoutExpression[];
|
|
231
|
-
};
|
|
232
|
-
/** Total number of operations in the batch */
|
|
233
|
-
totalOperations: number;
|
|
234
|
-
/** Any errors that occurred during batch processing */
|
|
235
|
-
errors?: BatchError[];
|
|
236
|
-
}
|
|
237
|
-
/**
|
|
238
|
-
* Typed result structure for batch operations with entity type information
|
|
239
|
-
*/
|
|
240
|
-
interface TypedBatchResult<TEntities extends Record<string, DynamoItem> = Record<string, DynamoItem>> {
|
|
241
|
-
/** Whether the batch operation completed successfully */
|
|
242
|
-
success: boolean;
|
|
243
|
-
/** Write operation results */
|
|
244
|
-
writes: {
|
|
245
|
-
/** Number of write operations processed successfully */
|
|
246
|
-
processed: number;
|
|
247
|
-
/** Write operations that were not processed and may need retry */
|
|
248
|
-
unprocessed: Array<BatchWriteOperation<DynamoItem>>;
|
|
249
|
-
};
|
|
250
|
-
/** Read operation results with typed items */
|
|
251
|
-
reads: {
|
|
252
|
-
/** Items retrieved from the batch get operations, grouped by entity type */
|
|
253
|
-
itemsByType: {
|
|
254
|
-
[K in keyof TEntities]: TEntities[K][];
|
|
255
|
-
};
|
|
256
|
-
/** All items retrieved (typed as union of all entity types) */
|
|
257
|
-
items: TEntities[keyof TEntities][];
|
|
258
|
-
/** Number of items found and returned */
|
|
259
|
-
found: number;
|
|
260
|
-
/** Keys that were not processed and may need retry */
|
|
261
|
-
unprocessed: PrimaryKeyWithoutExpression[];
|
|
262
|
-
};
|
|
263
|
-
/** Total number of operations in the batch */
|
|
264
|
-
totalOperations: number;
|
|
265
|
-
/** Any errors that occurred during batch execution */
|
|
266
|
-
errors?: BatchError[];
|
|
267
|
-
}
|
|
268
|
-
/**
|
|
269
|
-
* Builder for creating and executing DynamoDB batch operations with full entity support and type inference.
|
|
270
|
-
*
|
|
271
|
-
* Use BatchBuilder when you need to:
|
|
272
|
-
* - Perform multiple operations efficiently (up to 25 writes, 100 reads per batch)
|
|
273
|
-
* - Maintain entity validation, key generation, and type safety
|
|
274
|
-
* - Mix read and write operations in a single batch
|
|
275
|
-
* - Get typed results grouped by entity type
|
|
276
|
-
*
|
|
277
|
-
* @example Basic Usage
|
|
278
|
-
* ```typescript
|
|
279
|
-
* // Define entity types for the batch
|
|
280
|
-
* const batch = table.batchBuilder<{
|
|
281
|
-
* User: UserEntity;
|
|
282
|
-
* Order: OrderEntity;
|
|
283
|
-
* }>();
|
|
284
|
-
*
|
|
285
|
-
* // Add operations using entity repositories
|
|
286
|
-
* userRepo.create(newUser).withBatch(batch, 'User')
|
|
287
|
-
* userRepo.delete({ id: 'old-user' }).withBatch(batch, 'User')
|
|
288
|
-
* orderRepo.get({ id: 'existing-order' }).withBatch(batch, 'Order')
|
|
289
|
-
*
|
|
290
|
-
* // Execute all operations and get typed results
|
|
291
|
-
* const result = await batch.execute()
|
|
292
|
-
* const users: UserEntity[] = result.reads.itemsByType.User
|
|
293
|
-
* const orders: OrderEntity[] = result.reads.itemsByType.Order
|
|
294
|
-
* ```
|
|
295
|
-
*
|
|
296
|
-
* @example Error Handling
|
|
297
|
-
* ```typescript
|
|
298
|
-
* try {
|
|
299
|
-
* const result = await batch.execute()
|
|
300
|
-
*
|
|
301
|
-
* if (result.writes.unprocessed.length > 0) {
|
|
302
|
-
* console.warn('Some writes were not processed:', result.writes.unprocessed)
|
|
303
|
-
* }
|
|
304
|
-
* } catch (error) {
|
|
305
|
-
* if (error instanceof BatchError) {
|
|
306
|
-
* console.error('Batch operation failed:', error.message)
|
|
307
|
-
* }
|
|
308
|
-
* }
|
|
309
|
-
* ```
|
|
310
|
-
*/
|
|
311
|
-
declare class BatchBuilder<TEntities extends Record<string, DynamoItem> = Record<string, DynamoItem>> {
|
|
312
|
-
private batchWriteExecutor;
|
|
313
|
-
private batchGetExecutor;
|
|
314
|
-
private config;
|
|
315
|
-
private writeItems;
|
|
316
|
-
private getItems;
|
|
317
|
-
constructor(batchWriteExecutor: BatchWriteExecutor, batchGetExecutor: BatchGetExecutor, config: BatchConfig);
|
|
318
|
-
/**
|
|
319
|
-
* Checks if the batch is empty (contains no operations)
|
|
320
|
-
*
|
|
321
|
-
* @returns true if the batch contains no operations
|
|
322
|
-
*/
|
|
323
|
-
isEmpty(): boolean;
|
|
324
|
-
/**
|
|
325
|
-
* Gets the count of operations in the batch
|
|
326
|
-
*
|
|
327
|
-
* @returns Object containing the count of write and read operations
|
|
328
|
-
*/
|
|
329
|
-
getOperationCount(): {
|
|
330
|
-
writes: number;
|
|
331
|
-
reads: number;
|
|
332
|
-
};
|
|
333
|
-
/**
|
|
334
|
-
* Validates that the batch is not empty before execution
|
|
335
|
-
*
|
|
336
|
-
* @throws {BatchError} If the batch is empty
|
|
337
|
-
*/
|
|
338
|
-
private validateNotEmpty;
|
|
339
|
-
/**
|
|
340
|
-
* Adds a put operation to the batch with entity type information.
|
|
341
|
-
* This method is used internally by entity builders.
|
|
342
|
-
*
|
|
343
|
-
* @param command - The complete put command configuration
|
|
344
|
-
* @param entityType - The entity type name for type tracking
|
|
345
|
-
* @returns The batch builder for method chaining
|
|
346
|
-
* @internal
|
|
347
|
-
*/
|
|
348
|
-
putWithCommand<K extends keyof TEntities>(command: PutCommandParams, entityType?: K): this;
|
|
349
|
-
/**
|
|
350
|
-
* Adds a delete operation to the batch with entity type information.
|
|
351
|
-
* This method is used internally by entity builders.
|
|
352
|
-
*
|
|
353
|
-
* @param command - The complete delete command configuration
|
|
354
|
-
* @param entityType - The entity type name for type tracking
|
|
355
|
-
* @returns The batch builder for method chaining
|
|
356
|
-
* @internal
|
|
357
|
-
*/
|
|
358
|
-
deleteWithCommand<K extends keyof TEntities>(command: DeleteCommandParams, entityType?: K): this;
|
|
359
|
-
/**
|
|
360
|
-
* Adds a get operation to the batch with entity type information.
|
|
361
|
-
* This method is used internally by entity builders.
|
|
362
|
-
*
|
|
363
|
-
* @param command - The complete get command configuration
|
|
364
|
-
* @param entityType - The entity type name for type tracking
|
|
365
|
-
* @returns The batch builder for method chaining
|
|
366
|
-
* @internal
|
|
367
|
-
*/
|
|
368
|
-
getWithCommand<K extends keyof TEntities>(command: GetCommandParams, entityType?: K): this;
|
|
369
|
-
/**
|
|
370
|
-
* Executes all write operations in the batch.
|
|
371
|
-
*
|
|
372
|
-
* @returns A promise that resolves to any unprocessed operations
|
|
373
|
-
* @private
|
|
374
|
-
*/
|
|
375
|
-
private executeWrites;
|
|
376
|
-
/**
|
|
377
|
-
* Executes all get operations in the batch.
|
|
378
|
-
*
|
|
379
|
-
* @returns A promise that resolves to the retrieved items
|
|
380
|
-
* @private
|
|
381
|
-
*/
|
|
382
|
-
private executeGets;
|
|
383
|
-
/**
|
|
384
|
-
* Groups retrieved items by their entity type.
|
|
385
|
-
* @private
|
|
386
|
-
*/
|
|
387
|
-
private groupItemsByType;
|
|
388
|
-
/**
|
|
389
|
-
* Executes all operations in the batch with typed results.
|
|
390
|
-
* Performs write operations first, then get operations.
|
|
391
|
-
*
|
|
392
|
-
* @returns A promise that resolves to a TypedBatchResult with entity type information
|
|
393
|
-
* @throws {BatchError} If the batch is empty or if operations fail
|
|
394
|
-
*/
|
|
395
|
-
execute(): Promise<TypedBatchResult<TEntities>>;
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
export { BatchBuilder as B, GetBuilder as G, BatchError as a, type BatchResult as b, type BatchWriteOperation as c };
|