forked from aws/aws-sdk-js-v3
/
QueryCommand.ts
93 lines (86 loc) · 3.12 KB
/
QueryCommand.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import {
Condition,
QueryCommand as __QueryCommand,
QueryCommandInput as __QueryCommandInput,
QueryCommandOutput as __QueryCommandOutput,
} from "@aws-sdk/client-dynamodb";
import { Command as $Command } from "@aws-sdk/smithy-client";
import { Handler, HttpHandlerOptions as __HttpHandlerOptions, MiddlewareStack } from "@aws-sdk/types";
import { NativeAttributeValue } from "@aws-sdk/util-dynamodb";
import { marshallInput, unmarshallOutput } from "../commands/utils";
import { DynamoDBDocumentClientResolvedConfig, ServiceInputTypes, ServiceOutputTypes } from "../DynamoDBDocumentClient";
export type QueryCommandInput = Omit<
__QueryCommandInput,
"KeyConditions" | "QueryFilter" | "ExclusiveStartKey" | "ExpressionAttributeValues"
> & {
KeyConditions?: {
[key: string]: Omit<Condition, "AttributeValueList"> & {
AttributeValueList?: NativeAttributeValue[];
};
};
QueryFilter?: {
[key: string]: Omit<Condition, "AttributeValueList"> & {
AttributeValueList?: NativeAttributeValue[];
};
};
ExclusiveStartKey?: { [key: string]: NativeAttributeValue };
ExpressionAttributeValues?: { [key: string]: NativeAttributeValue };
};
export type QueryCommandOutput = Omit<__QueryCommandOutput, "Items" | "LastEvaluatedKey"> & {
Items?: {
[key: string]: NativeAttributeValue;
}[];
LastEvaluatedKey?: { [key: string]: NativeAttributeValue };
};
/**
* Accepts native JavaScript types instead of `AttributeValue`s, and calls
* QueryCommand operation from {@link https://www.npmjs.com/package/@aws-sdk/client-dynamodb @aws-sdk/client-dynamodb}.
*
* JavaScript objects passed in as parameters are marshalled into `AttributeValue` shapes
* required by Amazon DynamoDB. Responses from DynamoDB are unmarshalled into plain JavaScript objects.
*/
export class QueryCommand extends $Command<
QueryCommandInput,
QueryCommandOutput,
DynamoDBDocumentClientResolvedConfig
> {
private readonly inputKeyNodes = [
{
key: "KeyConditions",
children: {
children: [{ key: "AttributeValueList" }],
},
},
{
key: "QueryFilter",
children: {
children: [{ key: "AttributeValueList" }],
},
},
{ key: "ExclusiveStartKey" },
{ key: "ExpressionAttributeValues" },
];
private readonly outputKeyNodes = [{ key: "Items" }, { key: "LastEvaluatedKey" }];
constructor(readonly input: QueryCommandInput) {
super();
}
/**
* @internal
*/
resolveMiddleware(
clientStack: MiddlewareStack<ServiceInputTypes, ServiceOutputTypes>,
configuration: DynamoDBDocumentClientResolvedConfig,
options?: __HttpHandlerOptions
): Handler<QueryCommandInput, QueryCommandOutput> {
const { marshallOptions, unmarshallOptions } = configuration.translateConfig || {};
const command = new __QueryCommand(marshallInput(this.input, this.inputKeyNodes, marshallOptions));
const handler = command.resolveMiddleware(clientStack, configuration, options);
return async () => {
const data = await handler(command);
return {
...data,
output: unmarshallOutput(data.output, this.outputKeyNodes, unmarshallOptions),
};
};
}
}