Skip to content

Commit

Permalink
chore: experiment without using spread
Browse files Browse the repository at this point in the history
Not going ahead as:
* the marshalling/unmarshalling is not in the hot path and is called just once
* the performance of spread has significantly improved in recent versions of
  Chrome (7.2), which is in Node.js 12.x
* the code used by spread is clean and readable
  • Loading branch information
trivikr committed Feb 24, 2021
1 parent 01c008a commit 1ad4dff
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 48 deletions.
27 changes: 10 additions & 17 deletions lib/lib-dynamodb/src/commands/DeleteCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
ServiceOutputTypes,
} from "@aws-sdk/client-dynamodb";
import { Command as $Command } from "@aws-sdk/smithy-client";
import { Handler, HttpHandlerOptions, MiddlewareStack } from "@aws-sdk/types";
import { Handler, HttpHandlerOptions, InitializeHandlerOutput, MiddlewareStack } from "@aws-sdk/types";
import { marshall, NativeAttributeValue, unmarshall } from "@aws-sdk/util-dynamodb";

import { DynamoDBDocumentClientResolvedConfig } from "../DynamoDBDocumentClient";
Expand Down Expand Up @@ -36,28 +36,21 @@ export class DeleteCommand extends $Command<
configuration: DynamoDBDocumentClientResolvedConfig,
options?: HttpHandlerOptions
): Handler<DeleteCommandInput, DeleteCommandOutput> {
const command = new DeleteItemCommand({
...this.input,
Key: marshall(this.input.Key, configuration.translateConfiguration?.marshallOptions),
});
this.input.Key = marshall(this.input.Key, configuration.translateConfiguration?.marshallOptions);
const command = new DeleteItemCommand(this.input);
const handler = command.resolveMiddleware(clientStack, configuration, options);

return () =>
new Promise((resolve, reject) => {
handler(command)
.then((data) => {
resolve({
...data,
output: {
...data.output,
...(data.output.Attributes && {
Attributes: unmarshall(
data.output.Attributes,
configuration.translateConfiguration?.unmarshallOptions
),
}),
} as DeleteCommandOutput,
});
if (data.output.Attributes) {
data.output.Attributes = unmarshall(
data.output.Attributes,
configuration.translateConfiguration?.unmarshallOptions
);
}
resolve(data as InitializeHandlerOutput<DeleteCommandOutput>);
})
.catch((err) => {
reject(err);
Expand Down
21 changes: 7 additions & 14 deletions lib/lib-dynamodb/src/commands/GetCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
ServiceOutputTypes,
} from "@aws-sdk/client-dynamodb";
import { Command as $Command } from "@aws-sdk/smithy-client";
import { Handler, HttpHandlerOptions, MiddlewareStack } from "@aws-sdk/types";
import { Handler, HttpHandlerOptions, InitializeHandlerOutput, MiddlewareStack } from "@aws-sdk/types";
import { marshall, NativeAttributeValue, unmarshall } from "@aws-sdk/util-dynamodb";

import { DynamoDBDocumentClientResolvedConfig } from "../DynamoDBDocumentClient";
Expand All @@ -32,25 +32,18 @@ export class GetCommand extends $Command<GetCommandInput, GetCommandOutput, Dyna
configuration: DynamoDBDocumentClientResolvedConfig,
options?: HttpHandlerOptions
): Handler<GetCommandInput, GetCommandOutput> {
const command = new GetItemCommand({
...this.input,
Key: marshall(this.input.Key, configuration.translateConfiguration?.marshallOptions),
});
this.input.Key = marshall(this.input.Key, configuration.translateConfiguration?.marshallOptions);
const command = new GetItemCommand(this.input);
const handler = command.resolveMiddleware(clientStack, configuration, options);

return () =>
new Promise((resolve, reject) => {
handler(command)
.then((data) => {
resolve({
...data,
output: {
...data.output,
...(data.output.Item && {
Item: unmarshall(data.output.Item, configuration.translateConfiguration?.unmarshallOptions),
}),
} as GetCommandOutput,
});
if (data.output.Item) {
data.output.Item = unmarshall(data.output.Item, configuration.translateConfiguration?.unmarshallOptions);
}
resolve(data as InitializeHandlerOutput<GetCommandOutput>);
})
.catch((err) => {
reject(err);
Expand Down
27 changes: 10 additions & 17 deletions lib/lib-dynamodb/src/commands/PutCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
ServiceOutputTypes,
} from "@aws-sdk/client-dynamodb";
import { Command as $Command } from "@aws-sdk/smithy-client";
import { Handler, HttpHandlerOptions, MiddlewareStack } from "@aws-sdk/types";
import { Handler, HttpHandlerOptions, InitializeHandlerOutput, MiddlewareStack } from "@aws-sdk/types";
import { marshall, NativeAttributeValue, unmarshall } from "@aws-sdk/util-dynamodb";

import { DynamoDBDocumentClientResolvedConfig } from "../DynamoDBDocumentClient";
Expand All @@ -31,28 +31,21 @@ export class PutCommand extends $Command<PutCommandInput, PutCommandOutput, Dyna
configuration: DynamoDBDocumentClientResolvedConfig,
options?: HttpHandlerOptions
): Handler<PutCommandInput, PutCommandOutput> {
const command = new PutItemCommand({
...this.input,
Item: marshall(this.input.Item, configuration.translateConfiguration?.marshallOptions),
});
this.input.Item = marshall(this.input.Item, configuration.translateConfiguration?.marshallOptions);
const command = new PutItemCommand(this.input);
const handler = command.resolveMiddleware(clientStack, configuration, options);

return () =>
new Promise((resolve, reject) => {
handler(command)
.then((data) => {
resolve({
...data,
output: {
...data.output,
...(data.output.Attributes && {
Attributes: unmarshall(
data.output.Attributes,
configuration.translateConfiguration?.unmarshallOptions
),
}),
} as PutCommandOutput,
});
if (data.output.Attributes) {
data.output.Attributes = unmarshall(
data.output.Attributes,
configuration.translateConfiguration?.unmarshallOptions
);
}
resolve(data as InitializeHandlerOutput<PutCommandOutput>);
})
.catch((err) => {
reject(err);
Expand Down

0 comments on commit 1ad4dff

Please sign in to comment.