@encodeagent/platform-helper-data 1.2603.1311456 → 1.2604.1031117
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/dist/cosmosdb/index.d.ts +6 -6
- package/dist/cosmosdb/index.d.ts.map +1 -1
- package/dist/cosmosdb/index.js +60 -43
- package/dist/cosmosdb/index.js.map +1 -1
- package/dist/dynamodb/index.d.ts +4 -4
- package/dist/dynamodb/index.d.ts.map +1 -1
- package/dist/dynamodb/index.js +51 -110
- package/dist/dynamodb/index.js.map +1 -1
- package/dist/firestore/index.d.ts +2 -2
- package/dist/firestore/index.d.ts.map +1 -1
- package/dist/firestore/index.js +45 -52
- package/dist/firestore/index.js.map +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/mongodb/index.d.ts +3 -7
- package/dist/mongodb/index.d.ts.map +1 -1
- package/dist/mongodb/index.js +47 -110
- package/dist/mongodb/index.js.map +1 -1
- package/dist/util.d.ts +10 -5
- package/dist/util.d.ts.map +1 -1
- package/dist/util.js +5 -5
- package/dist/util.js.map +1 -1
- package/dist/wrapper/index.d.ts +12 -10
- package/dist/wrapper/index.d.ts.map +1 -1
- package/dist/wrapper/index.js +146 -106
- package/dist/wrapper/index.js.map +1 -1
- package/package.json +7 -7
package/dist/cosmosdb/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @fileoverview Azure Cosmos DB implementation
|
|
3
3
|
*/
|
|
4
|
-
import { IConnectionForServiceProps, IConnectionResult, IRetrieveResult, IRetrieveProps,
|
|
4
|
+
import { IConnectionForServiceProps, IConnectionResult, IRetrieveResult, IRetrieveProps, IInsertProps, IInsertResult, IInsertBatchProps, IInsertBatchResult, IQueryProps, IQueryResult, IUpsertProps, IUpsertResult, IUpdateProps, IUpdateResult } from "../util";
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* Insert Azure Cosmos DB connection
|
|
7
7
|
* @param props Connection properties with URI and key
|
|
8
8
|
* @returns Promise<IConnectionResult>
|
|
9
9
|
*/
|
|
@@ -15,11 +15,11 @@ export declare function connect(props: IConnectionForServiceProps): Promise<ICon
|
|
|
15
15
|
*/
|
|
16
16
|
export declare function retrieve(props: IRetrieveProps): Promise<IRetrieveResult>;
|
|
17
17
|
export declare function query(props: IQueryProps): Promise<IQueryResult>;
|
|
18
|
-
export declare function
|
|
19
|
-
export declare function
|
|
18
|
+
export declare function insert(props: IInsertProps): Promise<IInsertResult>;
|
|
19
|
+
export declare function insertBatch(props: IInsertBatchProps): Promise<IInsertBatchResult>;
|
|
20
20
|
/**
|
|
21
|
-
* Upsert (
|
|
22
|
-
* @param props Upsert properties with client, databaseId, containerId, record
|
|
21
|
+
* Upsert (insert or update) a document in Azure Cosmos DB
|
|
22
|
+
* @param props Upsert properties with client, databaseId, containerId, record
|
|
23
23
|
* @returns Promise<IUpsertResult>
|
|
24
24
|
*/
|
|
25
25
|
export declare function upsert(props: IUpsertProps): Promise<IUpsertResult>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cosmosdb/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACH,0BAA0B,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cosmosdb/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACH,0BAA0B,EAC1B,iBAAiB,EACjB,eAAe,EACf,cAAc,EACd,YAAY,EACZ,aAAa,EACb,iBAAiB,EACjB,kBAAkB,EAClB,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,aAAa,EAGhB,MAAM,SAAS,CAAC;AAWjB;;;;GAIG;AACH,wBAAsB,OAAO,CAAC,KAAK,EAAE,0BAA0B,GAAG,OAAO,CAAC,iBAAiB,CAAC,CA8C3F;AAED;;;;GAIG;AACH,wBAAsB,QAAQ,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO,CAAC,eAAe,CAAC,CA2D9E;AAED,wBAAsB,KAAK,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC,CAuDrE;AAED,wBAAsB,MAAM,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC,CA4CxE;AAED,wBAAsB,WAAW,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAkDvF;AAED;;;;GAIG;AACH,wBAAsB,MAAM,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC,CAsDxE;AAED,wBAAsB,MAAM,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC,CAgExE"}
|
package/dist/cosmosdb/index.js
CHANGED
|
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.connect = connect;
|
|
7
7
|
exports.retrieve = retrieve;
|
|
8
8
|
exports.query = query;
|
|
9
|
-
exports.
|
|
10
|
-
exports.
|
|
9
|
+
exports.insert = insert;
|
|
10
|
+
exports.insertBatch = insertBatch;
|
|
11
11
|
exports.upsert = upsert;
|
|
12
12
|
exports.update = update;
|
|
13
13
|
const util_1 = require("../util");
|
|
@@ -20,7 +20,7 @@ const ERROR_INFO = {
|
|
|
20
20
|
module: "database-cosmosdb"
|
|
21
21
|
};
|
|
22
22
|
/**
|
|
23
|
-
*
|
|
23
|
+
* Insert Azure Cosmos DB connection
|
|
24
24
|
* @param props Connection properties with URI and key
|
|
25
25
|
* @returns Promise<IConnectionResult>
|
|
26
26
|
*/
|
|
@@ -49,7 +49,7 @@ async function connect(props) {
|
|
|
49
49
|
}
|
|
50
50
|
};
|
|
51
51
|
}
|
|
52
|
-
//
|
|
52
|
+
// Insert Azure Cosmos DB client
|
|
53
53
|
const client = new cosmos_1.CosmosClient({ endpoint: uri, key });
|
|
54
54
|
return {
|
|
55
55
|
service: SERVICE,
|
|
@@ -63,7 +63,7 @@ async function connect(props) {
|
|
|
63
63
|
...ERROR_INFO,
|
|
64
64
|
source: "connect",
|
|
65
65
|
code: "database-connect",
|
|
66
|
-
message: error instanceof Error ? error.message :
|
|
66
|
+
message: error instanceof Error ? error.message : "Failed to connect to Azure Cosmos DB"
|
|
67
67
|
}
|
|
68
68
|
};
|
|
69
69
|
}
|
|
@@ -100,10 +100,10 @@ async function retrieve(props) {
|
|
|
100
100
|
else {
|
|
101
101
|
const iterator = container.items.query({
|
|
102
102
|
query: "SELECT * FROM c WHERE c.id = @id",
|
|
103
|
-
parameters: [{ name: "@id", value: id }]
|
|
103
|
+
parameters: [{ name: "@id", value: id }]
|
|
104
104
|
}, {
|
|
105
105
|
enableCrossPartitionQuery: true,
|
|
106
|
-
maxItemCount: 1
|
|
106
|
+
maxItemCount: 1 // fetch small pages; still fan-out under the hood
|
|
107
107
|
});
|
|
108
108
|
const { resources: items /*, headers */ } = await iterator.fetchNext();
|
|
109
109
|
return {
|
|
@@ -119,7 +119,9 @@ async function retrieve(props) {
|
|
|
119
119
|
...ERROR_INFO,
|
|
120
120
|
source: "retrieve",
|
|
121
121
|
code: "database-retrieve",
|
|
122
|
-
message: error instanceof Error
|
|
122
|
+
message: error instanceof Error
|
|
123
|
+
? error.message
|
|
124
|
+
: "Failed to retrieve document from Cosmos DB"
|
|
123
125
|
}
|
|
124
126
|
};
|
|
125
127
|
}
|
|
@@ -163,14 +165,20 @@ async function query(props) {
|
|
|
163
165
|
...ERROR_INFO,
|
|
164
166
|
source: "query",
|
|
165
167
|
code: "database-query",
|
|
166
|
-
message: error instanceof Error
|
|
168
|
+
message: error instanceof Error
|
|
169
|
+
? error.message
|
|
170
|
+
: "Failed to query documents from Cosmos DB"
|
|
167
171
|
}
|
|
168
172
|
};
|
|
169
173
|
}
|
|
170
174
|
}
|
|
171
|
-
async function
|
|
175
|
+
async function insert(props) {
|
|
172
176
|
try {
|
|
173
|
-
const { client, databaseId, containerId
|
|
177
|
+
const { client, databaseId, containerId } = props;
|
|
178
|
+
let record = { ...props.record, id: props.record.id ?? (0, platform_helper_util_1.newGuid)() };
|
|
179
|
+
if (props.onPreprocessRecord) {
|
|
180
|
+
record = await props.onPreprocessRecord(record);
|
|
181
|
+
}
|
|
174
182
|
const errorResult = (0, util_1.validateDatabaseSetting)({
|
|
175
183
|
service: SERVICE,
|
|
176
184
|
...ERROR_INFO,
|
|
@@ -184,10 +192,7 @@ async function create(props) {
|
|
|
184
192
|
}
|
|
185
193
|
const database = client.database(databaseId);
|
|
186
194
|
const container = database.container(containerId);
|
|
187
|
-
const response = await container.items.create(
|
|
188
|
-
...record,
|
|
189
|
-
id: record.id ?? (0, platform_helper_util_1.newGuid)()
|
|
190
|
-
});
|
|
195
|
+
const response = await container.items.create(record);
|
|
191
196
|
return {
|
|
192
197
|
service: SERVICE,
|
|
193
198
|
result: response.resource
|
|
@@ -198,16 +203,20 @@ async function create(props) {
|
|
|
198
203
|
service: SERVICE,
|
|
199
204
|
error: {
|
|
200
205
|
...ERROR_INFO,
|
|
201
|
-
source: "
|
|
202
|
-
code: "database-
|
|
203
|
-
message: error instanceof Error ? error.message :
|
|
206
|
+
source: "insert",
|
|
207
|
+
code: "database-insert",
|
|
208
|
+
message: error instanceof Error ? error.message : "Failed to insert record in Cosmos DB"
|
|
204
209
|
}
|
|
205
210
|
};
|
|
206
211
|
}
|
|
207
212
|
}
|
|
208
|
-
async function
|
|
213
|
+
async function insertBatch(props) {
|
|
209
214
|
try {
|
|
210
|
-
const { client, databaseId, containerId
|
|
215
|
+
const { client, databaseId, containerId } = props;
|
|
216
|
+
let records = props.records;
|
|
217
|
+
if (props.onPreprocessRecord) {
|
|
218
|
+
records = await Promise.all(records.map(async (r, index) => await props.onPreprocessRecord({ ...r, id: r.id ?? (0, platform_helper_util_1.newGuid)() }, index)));
|
|
219
|
+
}
|
|
211
220
|
const errorResult = (0, util_1.validateDatabaseSetting)({
|
|
212
221
|
service: SERVICE,
|
|
213
222
|
...ERROR_INFO,
|
|
@@ -221,14 +230,10 @@ async function createBatch(props) {
|
|
|
221
230
|
}
|
|
222
231
|
const database = client.database(databaseId);
|
|
223
232
|
const container = database.container(containerId);
|
|
224
|
-
const
|
|
225
|
-
...r,
|
|
226
|
-
id: r.id ?? (0, platform_helper_util_1.newGuid)()
|
|
227
|
-
}));
|
|
228
|
-
const responses = await Promise.all(payloads.map(p => container.items.create(p)));
|
|
233
|
+
const responses = await Promise.all(records.map((p) => container.items.create(p)));
|
|
229
234
|
return {
|
|
230
235
|
service: SERVICE,
|
|
231
|
-
result: responses.map(r => r.resource)
|
|
236
|
+
result: responses.map((r) => r.resource)
|
|
232
237
|
};
|
|
233
238
|
}
|
|
234
239
|
catch (error) {
|
|
@@ -236,21 +241,27 @@ async function createBatch(props) {
|
|
|
236
241
|
service: SERVICE,
|
|
237
242
|
error: {
|
|
238
243
|
...ERROR_INFO,
|
|
239
|
-
source: "
|
|
240
|
-
code: "database-
|
|
241
|
-
message: error instanceof Error
|
|
244
|
+
source: "insertBatch",
|
|
245
|
+
code: "database-insert-batch",
|
|
246
|
+
message: error instanceof Error
|
|
247
|
+
? error.message
|
|
248
|
+
: "Failed to batch insert records in Cosmos DB"
|
|
242
249
|
}
|
|
243
250
|
};
|
|
244
251
|
}
|
|
245
252
|
}
|
|
246
253
|
/**
|
|
247
|
-
* Upsert (
|
|
248
|
-
* @param props Upsert properties with client, databaseId, containerId, record
|
|
254
|
+
* Upsert (insert or update) a document in Azure Cosmos DB
|
|
255
|
+
* @param props Upsert properties with client, databaseId, containerId, record
|
|
249
256
|
* @returns Promise<IUpsertResult>
|
|
250
257
|
*/
|
|
251
258
|
async function upsert(props) {
|
|
252
259
|
try {
|
|
253
|
-
const { client, databaseId, containerId
|
|
260
|
+
const { client, databaseId, containerId } = props;
|
|
261
|
+
let record = { ...props.record, id: props.record.id ?? (0, platform_helper_util_1.newGuid)() };
|
|
262
|
+
if (props.onPreprocessRecord) {
|
|
263
|
+
record = await props.onPreprocessRecord(record);
|
|
264
|
+
}
|
|
254
265
|
const errorResult = (0, util_1.validateDatabaseSetting)({
|
|
255
266
|
service: SERVICE,
|
|
256
267
|
...ERROR_INFO,
|
|
@@ -264,13 +275,12 @@ async function upsert(props) {
|
|
|
264
275
|
}
|
|
265
276
|
const database = client.database(databaseId);
|
|
266
277
|
const container = database.container(containerId);
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
};
|
|
278
|
+
if (props.onPreprocessRecordWithExistingRecord) {
|
|
279
|
+
const { resource: existingRecord } = await container.item(record.id).read();
|
|
280
|
+
record = await props.onPreprocessRecordWithExistingRecord(record, existingRecord);
|
|
281
|
+
}
|
|
272
282
|
// Use upsert operation which creates if not exists or replaces if exists
|
|
273
|
-
const response = await container.items.upsert(
|
|
283
|
+
const response = await container.items.upsert(record);
|
|
274
284
|
// Check if this was a new document or an update
|
|
275
285
|
// Cosmos DB doesn't directly tell us, but we can infer from the response
|
|
276
286
|
const isNew = response.statusCode === 201;
|
|
@@ -287,14 +297,18 @@ async function upsert(props) {
|
|
|
287
297
|
...ERROR_INFO,
|
|
288
298
|
source: "upsert",
|
|
289
299
|
code: "database-upsert",
|
|
290
|
-
message: error instanceof Error ? error.message :
|
|
300
|
+
message: error instanceof Error ? error.message : "Failed to upsert record in Cosmos DB"
|
|
291
301
|
}
|
|
292
302
|
};
|
|
293
303
|
}
|
|
294
304
|
}
|
|
295
305
|
async function update(props) {
|
|
296
306
|
try {
|
|
297
|
-
const { client, databaseId, containerId
|
|
307
|
+
const { client, databaseId, containerId } = props;
|
|
308
|
+
let record = props.record;
|
|
309
|
+
if (props.onPreprocessRecord) {
|
|
310
|
+
record = await props.onPreprocessRecord(record);
|
|
311
|
+
}
|
|
298
312
|
const errorResult = (0, util_1.validateDatabaseSetting)({
|
|
299
313
|
service: SERVICE,
|
|
300
314
|
...ERROR_INFO,
|
|
@@ -317,10 +331,13 @@ async function update(props) {
|
|
|
317
331
|
}
|
|
318
332
|
};
|
|
319
333
|
}
|
|
334
|
+
if (props.onPreprocessRecord) {
|
|
335
|
+
record = await props.onPreprocessRecord(record);
|
|
336
|
+
}
|
|
320
337
|
const database = client.database(databaseId);
|
|
321
338
|
const container = database.container(containerId);
|
|
322
|
-
const item = (0, platform_helper_util_1.isNonEmptyString)(partitionKey)
|
|
323
|
-
? container.item(record.id, partitionKey)
|
|
339
|
+
const item = (0, platform_helper_util_1.isNonEmptyString)(record.partitionKey)
|
|
340
|
+
? container.item(record.id, record.partitionKey)
|
|
324
341
|
: container.item(record.id);
|
|
325
342
|
const response = await item.replace(record);
|
|
326
343
|
return {
|
|
@@ -335,7 +352,7 @@ async function update(props) {
|
|
|
335
352
|
...ERROR_INFO,
|
|
336
353
|
source: "update",
|
|
337
354
|
code: "database-update",
|
|
338
|
-
message: error instanceof Error ? error.message :
|
|
355
|
+
message: error instanceof Error ? error.message : "Failed to update record in Cosmos DB"
|
|
339
356
|
}
|
|
340
357
|
};
|
|
341
358
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cosmosdb/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cosmosdb/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAmCH,0BA8CC;AAOD,4BA2DC;AAED,sBAuDC;AAED,wBA4CC;AAED,kCAkDC;AAOD,wBAsDC;AAED,wBAgEC;AA3aD,kCAiBiB;AACjB,4EAA8E;AAC9E,0CAA6C;AAC7C,mDAA+C;AAE/C,MAAM,OAAO,GAAG,UAAU,CAAC;AAC3B,MAAM,UAAU,GAAG;IACf,OAAO,EAAE,cAAO;IAChB,MAAM,EAAE,mBAAmB;CAC9B,CAAC;AAEF;;;;GAIG;AACI,KAAK,UAAU,OAAO,CAAC,KAAiC;IAC3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N,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,OAAO;YACH,OAAO,EAAE,OAAO;YAChB,KAAK,EAAE;gBACH,GAAG,UAAU;gBACb,MAAM,EAAE,QAAQ;gBAChB,IAAI,EAAE,iBAAiB;gBACvB,OAAO,EACH,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,sCAAsC;aACtF;SACJ,CAAC;IACN,CAAC;AACL,CAAC"}
|
package/dist/dynamodb/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @fileoverview AWS DynamoDB implementation
|
|
3
3
|
*/
|
|
4
|
-
import { IConnectionForServiceProps, IConnectionResult, IRetrieveResult, IRetrieveProps,
|
|
4
|
+
import { IConnectionForServiceProps, IConnectionResult, IRetrieveResult, IRetrieveProps, IInsertProps, IInsertResult, IUpsertProps, IUpsertResult, IUpdateProps, IUpdateResult } from "../util";
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* Insert AWS DynamoDB connection
|
|
7
7
|
* @param props Connection properties with URI and key
|
|
8
8
|
* @returns Promise<IConnectionResult>
|
|
9
9
|
*/
|
|
@@ -14,9 +14,9 @@ export declare function connect(props: IConnectionForServiceProps): Promise<ICon
|
|
|
14
14
|
* @returns Promise<IRetrieveResult>
|
|
15
15
|
*/
|
|
16
16
|
export declare function retrieve(props: IRetrieveProps): Promise<IRetrieveResult>;
|
|
17
|
-
export declare function
|
|
17
|
+
export declare function insert(props: IInsertProps): Promise<IInsertResult>;
|
|
18
18
|
/**
|
|
19
|
-
* Upsert (
|
|
19
|
+
* Upsert (insert or update) a document in AWS DynamoDB
|
|
20
20
|
* @param props Upsert properties with client, containerId (table name), and record
|
|
21
21
|
* @returns Promise<IUpsertResult>
|
|
22
22
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/dynamodb/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAEH,0BAA0B,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/dynamodb/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAEH,0BAA0B,EAC1B,iBAAiB,EACjB,eAAe,EACf,cAAc,EACd,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,aAAa,EAChB,MAAM,SAAS,CAAC;AAiBjB;;;;GAIG;AACH,wBAAsB,OAAO,CAAC,KAAK,EAAE,0BAA0B,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAuE3F;AAED;;;;GAIG;AACH,wBAAsB,QAAQ,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO,CAAC,eAAe,CAAC,CAqD9E;AAED,wBAAsB,MAAM,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC,CA8CxE;AAED;;;;GAIG;AACH,wBAAsB,MAAM,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC,CA8DxE;AAED,wBAAsB,MAAM,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC,CA2FxE"}
|
package/dist/dynamodb/index.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.connect = connect;
|
|
7
7
|
exports.retrieve = retrieve;
|
|
8
|
-
exports.
|
|
8
|
+
exports.insert = insert;
|
|
9
9
|
exports.upsert = upsert;
|
|
10
10
|
exports.update = update;
|
|
11
11
|
const util_1 = require("../util");
|
|
@@ -19,7 +19,7 @@ const ERROR_INFO = {
|
|
|
19
19
|
module: "database-dynamodb"
|
|
20
20
|
};
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
22
|
+
* Insert AWS DynamoDB connection
|
|
23
23
|
* @param props Connection properties with URI and key
|
|
24
24
|
* @returns Promise<IConnectionResult>
|
|
25
25
|
*/
|
|
@@ -49,7 +49,7 @@ async function connect(props) {
|
|
|
49
49
|
};
|
|
50
50
|
}
|
|
51
51
|
// Parse AWS credentials from key (format: accessKeyId:secretAccessKey)
|
|
52
|
-
const [accessKeyId, secretAccessKey] = key.split(
|
|
52
|
+
const [accessKeyId, secretAccessKey] = key.split(":");
|
|
53
53
|
if (!accessKeyId || !secretAccessKey) {
|
|
54
54
|
return {
|
|
55
55
|
service: SERVICE,
|
|
@@ -61,15 +61,15 @@ async function connect(props) {
|
|
|
61
61
|
}
|
|
62
62
|
};
|
|
63
63
|
}
|
|
64
|
-
//
|
|
64
|
+
// Insert DynamoDB client configuration
|
|
65
65
|
const clientConfig = {
|
|
66
66
|
credentials: {
|
|
67
67
|
accessKeyId,
|
|
68
68
|
secretAccessKey
|
|
69
69
|
},
|
|
70
|
-
endpoint: uri.startsWith(
|
|
70
|
+
endpoint: uri.startsWith("http") ? uri : undefined
|
|
71
71
|
};
|
|
72
|
-
//
|
|
72
|
+
// Insert AWS DynamoDB client
|
|
73
73
|
const client = new client_dynamodb_1.DynamoDBClient(clientConfig);
|
|
74
74
|
return {
|
|
75
75
|
service: SERVICE,
|
|
@@ -83,7 +83,7 @@ async function connect(props) {
|
|
|
83
83
|
...ERROR_INFO,
|
|
84
84
|
source: "connect",
|
|
85
85
|
code: "database-connect",
|
|
86
|
-
message: error instanceof Error ? error.message :
|
|
86
|
+
message: error instanceof Error ? error.message : "Failed to connect to AWS DynamoDB"
|
|
87
87
|
}
|
|
88
88
|
};
|
|
89
89
|
}
|
|
@@ -107,7 +107,7 @@ async function retrieve(props) {
|
|
|
107
107
|
if (errorResult) {
|
|
108
108
|
return errorResult;
|
|
109
109
|
}
|
|
110
|
-
//
|
|
110
|
+
// Insert GetItem command
|
|
111
111
|
const command = new client_dynamodb_1.GetItemCommand({
|
|
112
112
|
TableName: containerId,
|
|
113
113
|
Key: (0, util_dynamodb_1.marshall)({ id })
|
|
@@ -133,14 +133,20 @@ async function retrieve(props) {
|
|
|
133
133
|
...ERROR_INFO,
|
|
134
134
|
source: "retrieve",
|
|
135
135
|
code: "database-retrieve",
|
|
136
|
-
message: error instanceof Error
|
|
136
|
+
message: error instanceof Error
|
|
137
|
+
? error.message
|
|
138
|
+
: "Failed to retrieve document from DynamoDB"
|
|
137
139
|
}
|
|
138
140
|
};
|
|
139
141
|
}
|
|
140
142
|
}
|
|
141
|
-
async function
|
|
143
|
+
async function insert(props) {
|
|
142
144
|
try {
|
|
143
|
-
const { client, containerId,
|
|
145
|
+
const { client, containerId, databaseId } = props;
|
|
146
|
+
let record = { ...props.record, id: props.record.id ?? (0, platform_helper_util_1.newGuid)() };
|
|
147
|
+
if (props.onPreprocessRecord) {
|
|
148
|
+
record = await props.onPreprocessRecord(record);
|
|
149
|
+
}
|
|
144
150
|
const errorResult = (0, util_1.validateDatabaseSetting)({
|
|
145
151
|
service: SERVICE,
|
|
146
152
|
...ERROR_INFO,
|
|
@@ -152,40 +158,14 @@ async function create(props) {
|
|
|
152
158
|
if (errorResult) {
|
|
153
159
|
return errorResult;
|
|
154
160
|
}
|
|
155
|
-
if (!containerId) {
|
|
156
|
-
return {
|
|
157
|
-
service: SERVICE,
|
|
158
|
-
error: {
|
|
159
|
-
...ERROR_INFO,
|
|
160
|
-
source: "create",
|
|
161
|
-
code: "require-container-id",
|
|
162
|
-
message: "The containerId (table name) is required"
|
|
163
|
-
}
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
if (!record) {
|
|
167
|
-
return {
|
|
168
|
-
service: SERVICE,
|
|
169
|
-
error: {
|
|
170
|
-
...ERROR_INFO,
|
|
171
|
-
source: "create",
|
|
172
|
-
code: "require-record",
|
|
173
|
-
message: "The record is required"
|
|
174
|
-
}
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
const item = {
|
|
178
|
-
...record,
|
|
179
|
-
id: record.id ?? (0, platform_helper_util_1.newGuid)()
|
|
180
|
-
};
|
|
181
161
|
const command = new client_dynamodb_1.PutItemCommand({
|
|
182
162
|
TableName: containerId,
|
|
183
|
-
Item: (0, util_dynamodb_1.marshall)(
|
|
163
|
+
Item: (0, util_dynamodb_1.marshall)(record)
|
|
184
164
|
});
|
|
185
165
|
await client.send(command);
|
|
186
166
|
return {
|
|
187
167
|
service: SERVICE,
|
|
188
|
-
result:
|
|
168
|
+
result: record
|
|
189
169
|
};
|
|
190
170
|
}
|
|
191
171
|
catch (error) {
|
|
@@ -193,21 +173,25 @@ async function create(props) {
|
|
|
193
173
|
service: SERVICE,
|
|
194
174
|
error: {
|
|
195
175
|
...ERROR_INFO,
|
|
196
|
-
source: "
|
|
197
|
-
code: "database-
|
|
198
|
-
message: error instanceof Error ? error.message :
|
|
176
|
+
source: "insert",
|
|
177
|
+
code: "database-insert",
|
|
178
|
+
message: error instanceof Error ? error.message : "Failed to insert record in DynamoDB"
|
|
199
179
|
}
|
|
200
180
|
};
|
|
201
181
|
}
|
|
202
182
|
}
|
|
203
183
|
/**
|
|
204
|
-
* Upsert (
|
|
184
|
+
* Upsert (insert or update) a document in AWS DynamoDB
|
|
205
185
|
* @param props Upsert properties with client, containerId (table name), and record
|
|
206
186
|
* @returns Promise<IUpsertResult>
|
|
207
187
|
*/
|
|
208
188
|
async function upsert(props) {
|
|
209
189
|
try {
|
|
210
|
-
const { client, containerId,
|
|
190
|
+
const { client, containerId, databaseId } = props;
|
|
191
|
+
let record = { ...props.record, id: props.record.id ?? (0, platform_helper_util_1.newGuid)() };
|
|
192
|
+
if (props.onPreprocessRecord) {
|
|
193
|
+
record = await props.onPreprocessRecord(record);
|
|
194
|
+
}
|
|
211
195
|
const errorResult = (0, util_1.validateDatabaseSetting)({
|
|
212
196
|
service: SERVICE,
|
|
213
197
|
...ERROR_INFO,
|
|
@@ -219,52 +203,27 @@ async function upsert(props) {
|
|
|
219
203
|
if (errorResult) {
|
|
220
204
|
return errorResult;
|
|
221
205
|
}
|
|
222
|
-
if (!containerId) {
|
|
223
|
-
return {
|
|
224
|
-
service: SERVICE,
|
|
225
|
-
error: {
|
|
226
|
-
...ERROR_INFO,
|
|
227
|
-
source: "upsert",
|
|
228
|
-
code: "require-container-id",
|
|
229
|
-
message: "The containerId (table name) is required"
|
|
230
|
-
}
|
|
231
|
-
};
|
|
232
|
-
}
|
|
233
|
-
if (!record) {
|
|
234
|
-
return {
|
|
235
|
-
service: SERVICE,
|
|
236
|
-
error: {
|
|
237
|
-
...ERROR_INFO,
|
|
238
|
-
source: "upsert",
|
|
239
|
-
code: "require-record",
|
|
240
|
-
message: "The record is required"
|
|
241
|
-
}
|
|
242
|
-
};
|
|
243
|
-
}
|
|
244
|
-
// Ensure the record has an id
|
|
245
|
-
const recordWithId = {
|
|
246
|
-
...record,
|
|
247
|
-
id: record.id ?? (0, platform_helper_util_1.newGuid)()
|
|
248
|
-
};
|
|
249
206
|
// Check if the item exists to determine if this is a new record
|
|
250
207
|
let isNew = true;
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
208
|
+
const getCommand = new client_dynamodb_1.GetItemCommand({
|
|
209
|
+
TableName: containerId,
|
|
210
|
+
Key: (0, util_dynamodb_1.marshall)({ id: record.id })
|
|
211
|
+
});
|
|
212
|
+
const getResponse = await client.send(getCommand);
|
|
213
|
+
isNew = !getResponse.Item;
|
|
214
|
+
if (props.onPreprocessRecordWithExistingRecord) {
|
|
215
|
+
const existingRecord = getResponse.Item ? (0, util_dynamodb_1.unmarshall)(getResponse.Item) : undefined;
|
|
216
|
+
record = await props.onPreprocessRecordWithExistingRecord(record, existingRecord);
|
|
258
217
|
}
|
|
259
|
-
// Use PutItem which will
|
|
218
|
+
// Use PutItem which will insert or replace the item
|
|
260
219
|
const putCommand = new client_dynamodb_1.PutItemCommand({
|
|
261
220
|
TableName: containerId,
|
|
262
|
-
Item: (0, util_dynamodb_1.marshall)(
|
|
221
|
+
Item: (0, util_dynamodb_1.marshall)(record)
|
|
263
222
|
});
|
|
264
223
|
await client.send(putCommand);
|
|
265
224
|
return {
|
|
266
225
|
service: SERVICE,
|
|
267
|
-
result:
|
|
226
|
+
result: record,
|
|
268
227
|
isNew
|
|
269
228
|
};
|
|
270
229
|
}
|
|
@@ -275,14 +234,18 @@ async function upsert(props) {
|
|
|
275
234
|
...ERROR_INFO,
|
|
276
235
|
source: "upsert",
|
|
277
236
|
code: "database-upsert",
|
|
278
|
-
message: error instanceof Error ? error.message :
|
|
237
|
+
message: error instanceof Error ? error.message : "Failed to upsert record in DynamoDB"
|
|
279
238
|
}
|
|
280
239
|
};
|
|
281
240
|
}
|
|
282
241
|
}
|
|
283
242
|
async function update(props) {
|
|
284
243
|
try {
|
|
285
|
-
const { client, databaseId, containerId
|
|
244
|
+
const { client, databaseId, containerId } = props;
|
|
245
|
+
let record = props.record;
|
|
246
|
+
if (props.onPreprocessRecord) {
|
|
247
|
+
record = await props.onPreprocessRecord(record);
|
|
248
|
+
}
|
|
286
249
|
const errorResult = (0, util_1.validateDatabaseSetting)({
|
|
287
250
|
service: SERVICE,
|
|
288
251
|
...ERROR_INFO,
|
|
@@ -294,28 +257,6 @@ async function update(props) {
|
|
|
294
257
|
if (errorResult) {
|
|
295
258
|
return errorResult;
|
|
296
259
|
}
|
|
297
|
-
if (!containerId) {
|
|
298
|
-
return {
|
|
299
|
-
service: SERVICE,
|
|
300
|
-
error: {
|
|
301
|
-
...ERROR_INFO,
|
|
302
|
-
source: "update",
|
|
303
|
-
code: "require-container-id",
|
|
304
|
-
message: "The containerId (table name) is required"
|
|
305
|
-
}
|
|
306
|
-
};
|
|
307
|
-
}
|
|
308
|
-
if (!record) {
|
|
309
|
-
return {
|
|
310
|
-
service: SERVICE,
|
|
311
|
-
error: {
|
|
312
|
-
...ERROR_INFO,
|
|
313
|
-
source: "update",
|
|
314
|
-
code: "require-record",
|
|
315
|
-
message: "The record is required"
|
|
316
|
-
}
|
|
317
|
-
};
|
|
318
|
-
}
|
|
319
260
|
const id = record.id;
|
|
320
261
|
if (!id) {
|
|
321
262
|
return {
|
|
@@ -328,7 +269,7 @@ async function update(props) {
|
|
|
328
269
|
}
|
|
329
270
|
};
|
|
330
271
|
}
|
|
331
|
-
const entries = Object.entries(record).filter(([k]) => k !==
|
|
272
|
+
const entries = Object.entries(record).filter(([k]) => k !== "id");
|
|
332
273
|
if (entries.length === 0) {
|
|
333
274
|
return {
|
|
334
275
|
service: SERVICE,
|
|
@@ -350,17 +291,17 @@ async function update(props) {
|
|
|
350
291
|
ExpressionAttributeValues[valueKey] = value;
|
|
351
292
|
assignments.push(`${nameKey} = ${valueKey}`);
|
|
352
293
|
});
|
|
353
|
-
const UpdateExpression = `SET ${assignments.join(
|
|
294
|
+
const UpdateExpression = `SET ${assignments.join(", ")}`;
|
|
354
295
|
const command = new client_dynamodb_1.UpdateItemCommand({
|
|
355
296
|
TableName: containerId,
|
|
356
297
|
Key: (0, util_dynamodb_1.marshall)({ id }),
|
|
357
298
|
UpdateExpression,
|
|
358
299
|
ExpressionAttributeNames,
|
|
359
300
|
ExpressionAttributeValues: (0, util_dynamodb_1.marshall)(ExpressionAttributeValues),
|
|
360
|
-
ReturnValues:
|
|
301
|
+
ReturnValues: "ALL_NEW"
|
|
361
302
|
});
|
|
362
303
|
const resp = await client.send(command);
|
|
363
|
-
const data = resp.Attributes ? (
|
|
304
|
+
const data = resp.Attributes ? (0, util_dynamodb_1.unmarshall)(resp.Attributes) : record;
|
|
364
305
|
return {
|
|
365
306
|
service: SERVICE,
|
|
366
307
|
result: data
|
|
@@ -373,7 +314,7 @@ async function update(props) {
|
|
|
373
314
|
...ERROR_INFO,
|
|
374
315
|
source: "update",
|
|
375
316
|
code: "database-update",
|
|
376
|
-
message: error instanceof Error ? error.message :
|
|
317
|
+
message: error instanceof Error ? error.message : "Failed to update record in DynamoDB"
|
|
377
318
|
}
|
|
378
319
|
};
|
|
379
320
|
}
|