Skip to content

Commit

Permalink
WIP: Fix types for AWS SDK v3
Browse files Browse the repository at this point in the history
This is an incomplete solution, because this makes types correct
for the nodejs18.x runtime but incorrect for nodejs16.x and earlier.

See architect#540.
  • Loading branch information
lpsinger committed Dec 16, 2022
1 parent ddc43ec commit 02644fe
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
7 changes: 4 additions & 3 deletions types/events.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { SNS, SQS } from "aws-sdk";
import type { PublishResponse } from "@aws-sdk/client-sns";
import type { SendMessageResult } from "@aws-sdk/client-sqs";
import { Callback } from "./util";

// Turn off automatic exporting
Expand Down Expand Up @@ -26,5 +27,5 @@ interface EventsOrQueues<PublishResult> {
): LambdaFunction;
}

export type ArcEvents = EventsOrQueues<SNS.Types.PublishResponse>;
export type ArcQueues = EventsOrQueues<SQS.Types.SendMessageResult>;
export type ArcEvents = EventsOrQueues<PublishResponse>;
export type ArcQueues = EventsOrQueues<SendMessageResult>;
17 changes: 9 additions & 8 deletions types/tables.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { DynamoDB } from "aws-sdk";
import type { DynamoDB } from "@aws-sdk/client-dynamodb";
import type { DynamoDBDocument, QueryCommandInput, QueryCommandOutput, ScanCommandInput, ScanCommandOutput, UpdateCommandInput, UpdateCommandOutput } from "@aws-sdk/lib-dynamodb";
import { Callback } from "./util";

// Turn off automatic exporting
Expand All @@ -17,17 +18,17 @@ type ItemsOutput<OutputType, Item> = Omit<OutputType, "Items"> & {
Items: Item[];
};

type QueryParams = Params<DynamoDB.DocumentClient.QueryInput>;
type QueryOutput<Item> = ItemsOutput<DynamoDB.DocumentClient.QueryOutput, Item>;
type QueryParams = Params<QueryCommandInput>;
type QueryOutput<Item> = ItemsOutput<QueryCommandOutput, Item>;

type ScanParams = Params<DynamoDB.DocumentClient.ScanInput>;
type ScanOutput<Item> = ItemsOutput<DynamoDB.DocumentClient.ScanOutput, Item>;
type ScanParams = Params<ScanCommandInput>;
type ScanOutput<Item> = ItemsOutput<ScanCommandOutput, Item>;

type UpdateParams<Item> = ParamsWithKey<
DynamoDB.DocumentClient.UpdateItemInput,
UpdateCommandInput,
Item
>;
type UpdateOutput = DynamoDB.DocumentClient.UpdateItemOutput;
type UpdateOutput = UpdateCommandOutput;

// Depending on the operation, the key attributes may be mandatory, but we don't
// know what the key attributes are, so Partial is the best we can do.
Expand Down Expand Up @@ -63,7 +64,7 @@ export type ArcDB<Tables> = ArcDBWith<Tables> & {
[tableName in keyof Tables]: string;
};
_db: DynamoDB;
_doc: DynamoDB.DocumentClient;
_doc: DynamoDBDocument;
};

// Permissive by default: allows any table, any inputs, any outputs.
Expand Down
4 changes: 2 additions & 2 deletions types/ws.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ApiGatewayManagementApi } from "aws-sdk";
import type { ApiGatewayManagementApi, GetConnectionResponse } from "@aws-sdk/client-apigatewaymanagementapi";
import { Callback } from "./util";

// Turn off automatic exporting
Expand All @@ -7,7 +7,7 @@ export { };
type SendParams = { id: string; payload: any };
type CloseParams = { id: string };
type InfoParams = { id: string };
type InfoResponse = ApiGatewayManagementApi.Types.GetConnectionResponse;
type InfoResponse = GetConnectionResponse;

export interface ArcWebSocket {
_api: ApiGatewayManagementApi;
Expand Down

0 comments on commit 02644fe

Please sign in to comment.