Skip to content

Commit

Permalink
use types from aws-lite/<plugin>-types
Browse files Browse the repository at this point in the history
types test pass again
  • Loading branch information
tbeseda committed Feb 2, 2024
1 parent 004179d commit 0326877
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 40 deletions.
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
"@architect/eslint-config": "2.1.1",
"@architect/req-res-fixtures": "git+https://github.com/architect/req-res-fixtures.git",
"@architect/sandbox": "^6.0.0-RC.1",
"@aws-lite/apigatewaymanagementapi-types": "^0.0.9",
"@aws-lite/dynamodb-types": "^0.3.4",
"@aws-lite/sns-types": "^0.0.5",
"@aws-lite/sqs-types": "^0.2.1",
"@types/aws-lambda": "^8.10.133",
"@types/node": "18",
"cross-env": "~7.0.3",
Expand Down
34 changes: 18 additions & 16 deletions types/events.d.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
import { Callback } from "./util";
import type { PublishResponse as SnsPublishResponse } from "@aws-lite/sns-types"
import type { SendMessageResponse as SqsPublishResponse } from "@aws-lite/sqs-types"

// Turn off automatic exporting
export {};
export { };

// import { PublishResponse } from "@aws-sdk/client-sns"; // @3.503.1
interface PublishResponse {
MessageId?: string;
SequenceNumber?: string;
}
// // import { PublishResponse } from "@aws-sdk/client-sns"; // @3.503.1
// interface PublishResponse {
// MessageId?: string;
// SequenceNumber?: string;
// }

// import { SendMessageResult } from "@aws-sdk/client-sqs"; // @3.503.1
interface SendMessageResult {
MD5OfMessageBody?: string;
MD5OfMessageAttributes?: string;
MD5OfMessageSystemAttributes?: string;
MessageId?: string;
SequenceNumber?: string;
}
// // import { SendMessageResult } from "@aws-sdk/client-sqs"; // @3.503.1
// interface SendMessageResult {
// MD5OfMessageBody?: string;
// MD5OfMessageAttributes?: string;
// MD5OfMessageSystemAttributes?: string;
// MessageId?: string;
// SequenceNumber?: string;
// }

interface Params<Payload> {
name: string;
Expand All @@ -40,5 +42,5 @@ interface EventsOrQueues<PublishResult> {
): LambdaFunction;
}

export type ArcEvents = EventsOrQueues<PublishResponse>;
export type ArcQueues = EventsOrQueues<SendMessageResult>;
export type ArcEvents = EventsOrQueues<SnsPublishResponse>;
export type ArcQueues = EventsOrQueues<SqsPublishResponse>;
20 changes: 12 additions & 8 deletions types/index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { ApiGatewayManagementApi, DynamoDB, SNS, SQS } from "aws-sdk";
import { Context } from "aws-lambda";
import type { AwsLiteClient } from "@aws-lite/client"
import type { GetConnectionResponse } from "@aws-lite/apigatewaymanagementapi-types";
import type { QueryResponse, ScanResponse, UpdateItemResponse } from "@aws-lite/dynamodb-types"
import type { PublishResponse } from "@aws-lite/sns-types"
import type { SendMessageResponse } from "@aws-lite/sqs-types"
import type { Context } from "aws-lambda";
import { expectType, expectAssignable, expectNotAssignable } from "tsd";
import arc from "../";
import type { HttpHandler, HttpAsyncHandler } from "../"
Expand All @@ -8,12 +12,12 @@ import type { HttpMethods, HttpRequest, HttpResponse } from "./http";
// EVENTS
const eventsPublishArg = { name: "test", payload: { foo: "bar" } };
const eventsPublishResult = await arc.events.publish(eventsPublishArg);
expectType<SNS.Types.PublishResponse>(eventsPublishResult);
expectType<PublishResponse>(eventsPublishResult);

// QUEUES
const queuesPublishArg = { name: "test", payload: { foo: "bar" } };
const queuesPublishResult = await arc.queues.publish(queuesPublishArg);
expectType<SQS.Types.SendMessageResult>(queuesPublishResult);
expectType<SendMessageResponse>(queuesPublishResult);

// HTTP
const middleware: HttpHandler = (req, res, next) => {
Expand Down Expand Up @@ -94,8 +98,8 @@ arc.static("/", { stagePath: false });

// TABLES
const dbClient = await arc.tables()
expectType<DynamoDB>(dbClient._db)
expectType<DynamoDB.DocumentClient>(dbClient._doc)
expectType<AwsLiteClient["DynamoDB"]>(dbClient._db)
// expectType<DynamoDB.DocumentClient>(dbClient._doc)
expectType<string>(dbClient.name('widgets'))
expectType<Record<string, string>>(dbClient.reflect())
const myTable = dbClient.foobar
Expand All @@ -122,9 +126,9 @@ await myTable.scanAll({
})

// WS
expectType<ApiGatewayManagementApi>(arc.ws._api);
expectType<AwsLiteClient["ApiGatewayManagementApi"]>(arc.ws._api);
expectType<void>(await arc.ws.send({ id: "foo", payload: { bar: "baz" } }));
expectType<void>(await arc.ws.close({ id: "foo" }));
expectType<ApiGatewayManagementApi.Types.GetConnectionResponse>(
expectType<GetConnectionResponse>(
await arc.ws.info({ id: "foo" }),
);
22 changes: 11 additions & 11 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 { AwsLiteClient } from "@aws-lite/client"
import type { QueryResponse, ScanResponse, UpdateItemResponse } from "@aws-lite/dynamodb-types"
import { Callback } from "./util";

// Turn off automatic exporting
Expand All @@ -17,17 +18,16 @@ 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<Parameters<AwsLiteClient["DynamoDB"]["Query"]>[0]>;
type QueryOutput<Item> = ItemsOutput<QueryResponse, Item>;

type ScanParams = Params<DynamoDB.DocumentClient.ScanInput>;
type ScanOutput<Item> = ItemsOutput<DynamoDB.DocumentClient.ScanOutput, Item>;
type ScanParams = Params<Parameters<AwsLiteClient["DynamoDB"]["Scan"]>[0]>;
type ScanOutput<Item> = ItemsOutput<ScanResponse, Item>;

type UpdateParams<Item> = ParamsWithKey<
DynamoDB.DocumentClient.UpdateItemInput,
Parameters<AwsLiteClient["DynamoDB"]["UpdateItem"]>[0],
Item
>;
type UpdateOutput = DynamoDB.DocumentClient.UpdateItemOutput;

// 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 All @@ -51,8 +51,8 @@ export interface ArcTable<Item = unknown> {

scanAll(params: ScanParams): Promise<Item[]>;

update(params: UpdateParams<Item>): Promise<UpdateOutput>;
update(params: UpdateParams<Item>, callback: Callback<UpdateOutput>): void;
update(params: UpdateParams<Item>): Promise<UpdateItemResponse>;
update(params: UpdateParams<Item>, callback: Callback<UpdateItemResponse>): void;
}

type ArcDBWith<Tables> = {
Expand All @@ -64,8 +64,8 @@ export type ArcDB<Tables> = ArcDBWith<Tables> & {
reflect(): {
[tableName in keyof Tables]: string;
};
_db: DynamoDB;
_doc: DynamoDB.DocumentClient;
_db: AwsLiteClient["DynamoDB"];
// _doc: DynamoDB.DocumentClient;
};

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

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

export interface ArcWebSocket {
_api: ApiGatewayManagementApi;
_api: AwsLiteClient["ApiGatewayManagementApi"];

send(params: SendParams): Promise<void>;
send(params: SendParams, callback: Callback<void>): void;

close(params: CloseParams): Promise<void>;
close(params: CloseParams, callback: Callback<void>): void;

info(params: InfoParams): Promise<InfoResponse>;
info(params: InfoParams, callback: Callback<InfoResponse>): void;
info(params: InfoParams): Promise<GetConnectionResponse>;
info(params: InfoParams, callback: Callback<GetConnectionResponse>): void;
}

0 comments on commit 0326877

Please sign in to comment.