@xube/kit-aws 0.0.43 → 0.0.45
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.
|
@@ -2,4 +2,7 @@ import { TableItem } from "./schema/item";
|
|
|
2
2
|
import { PartialTableKey } from "./schema/keys";
|
|
3
3
|
import { XubeResponse } from "@xube/kit-request";
|
|
4
4
|
import { XubeLog } from "@xube/kit-log";
|
|
5
|
-
export declare const queryItemsFromTable: (tableName: string, keys: PartialTableKey, indexName: string | undefined,
|
|
5
|
+
export declare const queryItemsFromTable: (tableName: string, keys: PartialTableKey, indexName: string | undefined, keyLabels?: {
|
|
6
|
+
partitionKey: string;
|
|
7
|
+
sortKey?: string;
|
|
8
|
+
}, log?: XubeLog) => Promise<XubeResponse<TableItem[]>>;
|
|
@@ -9,20 +9,22 @@ const kit_request_1 = require("@xube/kit-request");
|
|
|
9
9
|
const kit_log_1 = require("@xube/kit-log");
|
|
10
10
|
const ddbClient = new client_dynamodb_1.DynamoDBClient({ region: process.env.AWS_REGION });
|
|
11
11
|
const ddbDocClient = lib_dynamodb_1.DynamoDBDocumentClient.from(ddbClient);
|
|
12
|
-
const queryItemsFromTable = async (tableName, keys, indexName,
|
|
12
|
+
const queryItemsFromTable = async (tableName, keys, indexName, keyLabels = {
|
|
13
|
+
partitionKey: keys_1.PARTITION_KEY,
|
|
14
|
+
sortKey: keys_1.SORT_KEY,
|
|
15
|
+
}, log = kit_log_1.XubeLog.getInstance()) => {
|
|
13
16
|
let KeyConditionExpression = "#pk = :pkValue";
|
|
14
17
|
let ExpressionAttributeNames = {
|
|
15
|
-
"#pk":
|
|
18
|
+
"#pk": keyLabels.partitionKey,
|
|
16
19
|
};
|
|
17
20
|
let ExpressionAttributeValues = {
|
|
18
21
|
":pkValue": keys[keys_1.PARTITION_KEY],
|
|
19
22
|
};
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
// }
|
|
23
|
+
if (keys[keys_1.SORT_KEY]) {
|
|
24
|
+
KeyConditionExpression += " AND begins_with(#sk, :skPrefix)";
|
|
25
|
+
ExpressionAttributeNames["#sk"] = keyLabels.sortKey ?? keys_1.SORT_KEY;
|
|
26
|
+
ExpressionAttributeValues[":skPrefix"] = keys[keys_1.SORT_KEY];
|
|
27
|
+
}
|
|
26
28
|
const params = {
|
|
27
29
|
TableName: tableName,
|
|
28
30
|
IndexName: indexName,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xube/kit-aws",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.45",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -18,14 +18,14 @@
|
|
|
18
18
|
"homepage": "https://github.com/XubeLtd/dev-kit#readme",
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"@types/aws-lambda": "^8.10.119",
|
|
21
|
-
"@xube/kit-build": "^0.0.
|
|
21
|
+
"@xube/kit-build": "^0.0.45"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@aws-sdk/client-dynamodb": "^3.427.0",
|
|
25
25
|
"@aws-sdk/lib-dynamodb": "^3.427.0",
|
|
26
26
|
"@aws-sdk/util-dynamodb": "^3.427.0",
|
|
27
|
-
"@xube/kit-log": "^0.0.
|
|
28
|
-
"@xube/kit-request": "^0.0.
|
|
27
|
+
"@xube/kit-log": "^0.0.45",
|
|
28
|
+
"@xube/kit-request": "^0.0.45",
|
|
29
29
|
"zod": "^3.22.4"
|
|
30
30
|
}
|
|
31
31
|
}
|
|
@@ -17,21 +17,28 @@ export const queryItemsFromTable = async (
|
|
|
17
17
|
tableName: string,
|
|
18
18
|
keys: PartialTableKey,
|
|
19
19
|
indexName: string | undefined,
|
|
20
|
+
keyLabels: {
|
|
21
|
+
partitionKey: string;
|
|
22
|
+
sortKey?: string;
|
|
23
|
+
} = {
|
|
24
|
+
partitionKey: PARTITION_KEY,
|
|
25
|
+
sortKey: SORT_KEY,
|
|
26
|
+
},
|
|
20
27
|
log: XubeLog = XubeLog.getInstance()
|
|
21
28
|
): Promise<XubeResponse<TableItem[]>> => {
|
|
22
29
|
let KeyConditionExpression = "#pk = :pkValue";
|
|
23
30
|
let ExpressionAttributeNames: { [key: string]: string } = {
|
|
24
|
-
"#pk":
|
|
31
|
+
"#pk": keyLabels.partitionKey,
|
|
25
32
|
};
|
|
26
33
|
let ExpressionAttributeValues: { [key: string]: string } = {
|
|
27
34
|
":pkValue": keys[PARTITION_KEY],
|
|
28
35
|
};
|
|
29
36
|
|
|
30
|
-
|
|
37
|
+
if (keys[SORT_KEY]) {
|
|
31
38
|
KeyConditionExpression += " AND begins_with(#sk, :skPrefix)";
|
|
32
|
-
ExpressionAttributeNames["#sk"] =
|
|
33
|
-
ExpressionAttributeValues[":skPrefix"] = keys[SORT_KEY]
|
|
34
|
-
|
|
39
|
+
ExpressionAttributeNames["#sk"] = keyLabels.sortKey ?? SORT_KEY;
|
|
40
|
+
ExpressionAttributeValues[":skPrefix"] = keys[SORT_KEY];
|
|
41
|
+
}
|
|
35
42
|
|
|
36
43
|
const params = {
|
|
37
44
|
TableName: tableName,
|