@factorearth/recordmiddleware-dataaccesslayer 0.0.1-y.11 → 0.0.1-y.12

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/getItem.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  export declare const getItem: (id: string, tableName: string) => Promise<Record<string, any> | null | undefined>;
2
- export declare const getItemsByIndex: (indexName: string, tableName: string, attributeValue: string, attribute: string, columns?: []) => Promise<Record<string, any>[]>;
2
+ export declare const getItemsByIndex: (indexName: string, tableName: string, attributeValue: string, attribute: string, columns?: string[]) => Promise<Record<string, any>[]>;
package/dist/getItem.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { dynamoDbDocClient } from "./aws-services.js";
2
2
  import { GetCommand, QueryCommand } from "@aws-sdk/lib-dynamodb";
3
+ import { _columnsAndAttributeToReturn } from "utils.js";
3
4
  export const getItem = async (id, tableName) => {
4
5
  const params = {
5
6
  TableName: tableName,
@@ -17,14 +18,7 @@ export const getItem = async (id, tableName) => {
17
18
  }
18
19
  };
19
20
  export const getItemsByIndex = async (indexName, tableName, attributeValue, attribute, columns) => {
20
- const expressionAttributeNames = {
21
- "#fk": `${attribute}`
22
- };
23
- const columnsToReturn = columns?.map((col, index) => {
24
- const placeholder = `#col${index}`;
25
- expressionAttributeNames[placeholder] = col;
26
- return placeholder;
27
- }).join(", ");
21
+ const { expressionAttributeNames, columnsToReturn } = _columnsAndAttributeToReturn({ attribute, columns });
28
22
  const params = {
29
23
  TableName: tableName,
30
24
  IndexName: indexName,
@@ -0,0 +1,9 @@
1
+ export declare const _columnsAndAttributeToReturn: ({ attribute, columns, }: {
2
+ attribute: string;
3
+ columns?: string[];
4
+ }) => {
5
+ expressionAttributeNames: {
6
+ [key: string]: string;
7
+ };
8
+ columnsToReturn: string | undefined;
9
+ };
package/dist/utils.js ADDED
@@ -0,0 +1,13 @@
1
+ export const _columnsAndAttributeToReturn = ({ attribute, columns, }) => {
2
+ const expressionAttributeNames = {
3
+ "#fk": `${attribute}`,
4
+ };
5
+ const columnsToReturn = columns
6
+ ?.map((col, index) => {
7
+ const placeholder = `#col${index}`;
8
+ expressionAttributeNames[placeholder] = col;
9
+ return placeholder;
10
+ })
11
+ .join(", ");
12
+ return { expressionAttributeNames, columnsToReturn };
13
+ };
package/lib/getItem.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import { dynamoDbDocClient } from "./aws-services.js";
2
2
  import { GetCommand, GetCommandInput, QueryCommand, QueryCommandInput } from "@aws-sdk/lib-dynamodb";
3
+ import { _columnsAndAttributeToReturn } from "utils.js";
3
4
 
4
- export const getItem = async (id: string, tableName: string) => {
5
+ export const getItem = async (id: string, tableName: string ) => {
5
6
  const params: GetCommandInput = {
6
7
  TableName: tableName,
7
8
  Key: {
@@ -18,15 +19,7 @@ export const getItem = async (id: string, tableName: string) => {
18
19
  }
19
20
 
20
21
  export const getItemsByIndex = async (indexName: string, tableName: string, attributeValue:string, attribute: string, columns?: string[]) => {
21
- const expressionAttributeNames: { [key: string]: string } = {
22
- "#fk" : `${attribute}`
23
- };
24
-
25
- const columnsToReturn = columns?.map((col, index) => {
26
- const placeholder = `#col${index}`;
27
- expressionAttributeNames[placeholder] = col;
28
- return placeholder;
29
- }).join(", ");
22
+ const { expressionAttributeNames, columnsToReturn } = _columnsAndAttributeToReturn({attribute, columns});
30
23
 
31
24
  const params: QueryCommandInput = {
32
25
  TableName: tableName,
package/lib/utils.ts ADDED
@@ -0,0 +1,21 @@
1
+ export const _columnsAndAttributeToReturn = ({
2
+ attribute,
3
+ columns,
4
+ }: {
5
+ attribute: string;
6
+ columns?: string[];
7
+ }) => {
8
+ const expressionAttributeNames: { [key: string]: string } = {
9
+ "#fk": `${attribute}`,
10
+ };
11
+
12
+ const columnsToReturn = columns
13
+ ?.map((col, index) => {
14
+ const placeholder = `#col${index}`;
15
+ expressionAttributeNames[placeholder] = col;
16
+ return placeholder;
17
+ })
18
+ .join(", ");
19
+
20
+ return { expressionAttributeNames, columnsToReturn };
21
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@factorearth/recordmiddleware-dataaccesslayer",
3
- "version": "0.0.1-y.11",
3
+ "version": "0.0.1-y.12",
4
4
  "description": "A module for accessing dynamdb efficiently",
5
5
  "author": "madtrx <marlin.makori@gmail.com>",
6
6
  "homepage": "https://github.com/FactorEarth/RecordMiddleware#readme",
@@ -29,5 +29,5 @@
29
29
  "access": "public",
30
30
  "registry": "https://registry.npmjs.org/"
31
31
  },
32
- "gitHead": "9ab2433ccd7c896de951b06fc1c22da5ce3c7b3f"
32
+ "gitHead": "ce647ddb9d3a7c9fe19a335160972e914a1364bb"
33
33
  }