@moicky/dynamodb 1.2.1 → 1.2.2

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.
@@ -5,3 +5,6 @@ export declare function splitEvery<T>(items: T[], limit?: number): T[][];
5
5
  export declare function getAttributeValues(key: any, attributesToGet?: string[]): Record<string, any>;
6
6
  export declare function getAttributeNames(key: any, attributesToGet?: string[]): Record<string, string>;
7
7
  export declare function getAttributesFromExpression(expression: string, prefix?: string): string[];
8
+ export declare function handleAliases(aliases: {
9
+ [attr: string]: string[];
10
+ }, args?: Record<string, any>): Record<string, any>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getAttributesFromExpression = exports.getAttributeNames = exports.getAttributeValues = exports.splitEvery = exports.stripKey = void 0;
3
+ exports.handleAliases = exports.getAttributesFromExpression = exports.getAttributeNames = exports.getAttributeValues = exports.splitEvery = exports.stripKey = void 0;
4
4
  const util_dynamodb_1 = require("@aws-sdk/util-dynamodb");
5
5
  const client_1 = require("../lib/client");
6
6
  // Since dynamo only accepts key atrtributes which are described in table schema
@@ -42,3 +42,15 @@ function getAttributesFromExpression(expression, prefix = "#") {
42
42
  ?.map((attr) => attr.slice(1)) || []);
43
43
  }
44
44
  exports.getAttributesFromExpression = getAttributesFromExpression;
45
+ function handleAliases(aliases, args = {}) {
46
+ Object.keys(aliases).forEach((key) => {
47
+ aliases[key].forEach((alias) => {
48
+ if (args[alias]) {
49
+ args[key] = args[alias];
50
+ delete args[alias];
51
+ }
52
+ });
53
+ });
54
+ return args;
55
+ }
56
+ exports.handleAliases = handleAliases;
@@ -1,4 +1,9 @@
1
- import { QueryCommandInput, QueryCommandOutput } from "@aws-sdk/client-dynamodb";
1
+ import { QueryCommandInput as _QueryCommandInput, QueryCommandOutput } from "@aws-sdk/client-dynamodb";
2
+ type QueryCommandInput = {
3
+ GSI: _QueryCommandInput["IndexName"];
4
+ Index: _QueryCommandInput["IndexName"];
5
+ } & _QueryCommandInput;
2
6
  export declare function query(keyCondition: string, key: any, args?: Partial<QueryCommandInput>): Promise<QueryCommandOutput>;
3
7
  export declare function queryItems(keyCondition: string, key: any, args?: Partial<QueryCommandInput>): Promise<Record<string, any>[]>;
4
8
  export declare function queryAllItems(keyCondition: string, key: any, args?: Partial<QueryCommandInput>): Promise<Record<string, any>[]>;
9
+ export {};
@@ -5,7 +5,11 @@ const client_dynamodb_1 = require("@aws-sdk/client-dynamodb");
5
5
  const util_dynamodb_1 = require("@aws-sdk/util-dynamodb");
6
6
  const client_1 = require("../lib/client");
7
7
  const helpers_1 = require("../lib/helpers");
8
+ const aliases = {
9
+ IndexName: ["GSI", "Index"],
10
+ };
8
11
  async function query(keyCondition, key, args = {}) {
12
+ args = (0, helpers_1.handleAliases)(aliases, args);
9
13
  return client_1.client.send(new client_dynamodb_1.QueryCommand({
10
14
  KeyConditionExpression: keyCondition,
11
15
  ExpressionAttributeValues: (0, helpers_1.getAttributeValues)(key, [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moicky/dynamodb",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "description": "Contains a collection of convenience functions for working with AWS DynamoDB",
package/readme.md CHANGED
@@ -31,7 +31,7 @@ import { initSchema } from "@moicky/dynamodb";
31
31
 
32
32
  // Should be called once at the start of the runtime before any operation is executed
33
33
  initSchema({
34
- // first one will be used if no TableName is specified
34
+ // first one will be used by default if no TableName is specified
35
35
  [process.env.DEFAULT_TABLE]: {
36
36
  hash: "PK",
37
37
  range: "SK",
@@ -376,8 +376,10 @@ const result = await updateItem(
376
376
 
377
377
  ### Setup
378
378
 
379
- Requires `DEFAULT_TABLE` and `SECOND_TABLE` to be present inside the environment (`.env file`)
380
- Can be deployed using the `template.yml` on aws:
379
+ Requires environment variables to be present for the tests to successfully connect to dynamodb tables. You can find a list of required environment variables here:
380
+ [./test/setup/setup-each.js](./test/setup/setup-each.js)
381
+
382
+ They can be obtained using the **template.yml** which can be deployed on aws using:
381
383
 
382
384
  ```bash
383
385
  sam deploy