@pi-r/aws 0.9.4 → 0.10.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.
package/client/index.js CHANGED
@@ -112,7 +112,7 @@ function createDatabaseClient(credential) {
112
112
  let options;
113
113
  if (fromPath) {
114
114
  try {
115
- options = JSON.parse(this.readFile(fromPath, { encoding: 'utf-8', ownPermissionOnly: true, cache: false }));
115
+ options = JSON.parse(this.readFile(fromPath, { encoding: 'utf8', ownPermissionOnly: true, cache: false }));
116
116
  }
117
117
  catch {
118
118
  }
@@ -354,21 +354,32 @@ async function executeBatchQuery(credential, batch, sessionKey) {
354
354
  rows = Responses[TableName];
355
355
  }
356
356
  }
357
- else if (TableName) {
358
- let params = item.params;
359
- if ((0, types_1.isPlainObject)(params)) {
360
- params.TableName = TableName;
361
- }
362
- else {
363
- params = { TableName };
357
+ else if (TableName || item.params) {
358
+ const params = (item.params || {});
359
+ if (!params.TransactItems) {
360
+ if (TableName) {
361
+ params.TableName = TableName;
362
+ }
363
+ else if (!params.TableName) {
364
+ throw (0, util_1.formatError)(item, "Missing database table");
365
+ }
364
366
  }
365
367
  if (useCache && (rows = this.getCacheResult(service, credential, queryString = Cloud.asString(params, true), cacheValue, ignoreCache))) {
366
368
  result[i] = rows;
367
369
  continue;
368
370
  }
369
- const { Count, Items } = await createClient().scan(params).promise();
370
- if (Count && Items) {
371
- rows = Items;
371
+ const db = createClient();
372
+ if (params.TransactItems) {
373
+ const { Responses } = await db.transactGet(params).promise();
374
+ if (Responses) {
375
+ rows = Responses.map(value => value.Item || {});
376
+ }
377
+ }
378
+ else {
379
+ const { Count, Items } = await db.scan(params).promise();
380
+ if (Count && Items) {
381
+ rows = Items;
382
+ }
372
383
  }
373
384
  }
374
385
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/aws",
3
- "version": "0.9.4",
3
+ "version": "0.10.0",
4
4
  "description": "AWS V2 cloud functions for E-mc.",
5
5
  "main": "client/index.js",
6
6
  "types": "client/index.d.ts",
@@ -20,10 +20,10 @@
20
20
  "license": "MIT",
21
21
  "homepage": "https://github.com/anpham6/pi-r#readme",
22
22
  "dependencies": {
23
- "@e-mc/cloud": "^0.11.5",
24
- "@e-mc/module": "^0.11.5",
25
- "@e-mc/types": "^0.11.5",
26
- "@pi-r/aws-lib": "^0.9.4",
23
+ "@e-mc/cloud": "^0.12.0",
24
+ "@e-mc/module": "^0.12.0",
25
+ "@e-mc/types": "^0.12.0",
26
+ "@pi-r/aws-lib": "^0.10.0",
27
27
  "aws-sdk": "^2.1692.0"
28
28
  }
29
29
  }
package/types/index.d.ts CHANGED
@@ -11,6 +11,7 @@ export type QueryInput = DocumentClient.QueryInput;
11
11
  export type UpdateItemInput = DocumentClient.UpdateItemInput;
12
12
  export type ScanInput = DocumentClient.ScanInput;
13
13
  export type BatchGetItemInput = DocumentClient.BatchGetItemInput;
14
+ export type TransactGetItemsInput = DocumentClient.TransactGetItemsInput;
14
15
  export type DynamoDBClientConfig = Types.ClientConfiguration & DocumentClient.DocumentClientOptions;
15
16
 
16
17
  export type AWSStorage = CloudStorage<AWSStorageCredential, "aws">;
@@ -20,7 +21,7 @@ export interface AWSStorageCredential extends ConfigurationOptions {
20
21
  fromPath?: string;
21
22
  }
22
23
 
23
- export interface AWSDatabaseQuery extends CloudDatabase<QueryInput | Key[], Record<string, unknown>, UpdateItemInput, BatchGetItemInput | ScanInput, AWSDatabaseCredential> {
24
+ export interface AWSDatabaseQuery extends CloudDatabase<QueryInput | Key[], Record<string, unknown>, UpdateItemInput, BatchGetItemInput | ScanInput | TransactGetItemsInput, AWSDatabaseCredential> {
24
25
  source: "cloud";
25
26
  service: "aws";
26
27
  key?: string | Key;