Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,318 changes: 23 additions & 1,295 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"test:sast:sandworm": "sandworm-audit --skip-all --show-tips false",
"test:sast:semgrep": "semgrep scan --config auto",
"test:sast:trufflehog": "trufflehog filesystem --only-verified --log-level=-1 ./",
"test:types": "ls packages | xargs -I {} tsd packages/{}",
"test:types": "tstyche",
"test:perf": "node --test ./**/*.perf.js",
"test:dast": "npm run test:dast:fuzz",
"test:dast:fuzz": "node --test ./**/*.fuzz.js",
Expand Down Expand Up @@ -70,7 +70,7 @@
"fast-check": "^4.0.0",
"husky": "^9.0.0",
"tinybench": "^4.0.0",
"tsd": "^0.33.0",
"tstyche": "^4.3.0",
"typescript": "^5.0.0"
},
"workspaces": [
Expand Down
88 changes: 45 additions & 43 deletions packages/appconfig/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import middy from "@middy/core";
import { getInternal } from "@middy/util";
import type { Context as LambdaContext } from "aws-lambda";
import { captureAWSv3Client } from "aws-xray-sdk";
import { expectType } from "tsd";
import { expect } from "tstyche";
import appConfig, { appConfigReq, type Context } from "./index.js";

const options = {
Expand All @@ -21,28 +21,20 @@ const options = {
cacheKey: "some-key",
cacheExpiry: 60 * 60 * 5,
setToContext: false,
} as const;
};

// use with default options
expectType<middy.MiddlewareObj<unknown, any, Error, LambdaContext>>(
appConfig(),
);
expect(appConfig()).type.toBe<
middy.MiddlewareObj<unknown, any, Error, LambdaContext>
>();

// use with all options
expectType<middy.MiddlewareObj<unknown, any, Error, Context<typeof options>>>(
appConfig(options),
);
expect(appConfig(options)).type.toBe<
middy.MiddlewareObj<unknown, any, Error, Context<typeof options>>
>();

// use with setToContext: false
expectType<
middy.MiddlewareObj<
unknown,
any,
Error,
LambdaContext,
Record<"config", unknown>
>
>(
expect(
appConfig({
...options,
fetchData: {
Expand All @@ -54,18 +46,18 @@ expectType<
},
setToContext: false,
}),
);

// use with setToContext: true
expectType<
).type.toBe<
middy.MiddlewareObj<
unknown,
any,
Error,
LambdaContext & Record<"config", unknown>,
LambdaContext,
Record<"config", unknown>
>
>(
>();

// use with setToContext: true
expect(
appConfig({
...options,
fetchData: {
Expand All @@ -77,30 +69,36 @@ expectType<
},
setToContext: true,
}),
);
).type.toBe<
middy.MiddlewareObj<
unknown,
any,
Error,
LambdaContext & Record<"config", unknown>,
Record<"config", unknown>
>
>();

// @ts-expect-error - fetchData must be an object
appConfig({ ...options, fetchData: "not-an-object" });
expect(appConfig).type.not.toBeCallableWith({
...options,
fetchData: "not-an-object", // fetchData must be an object
});

appConfig({
expect(appConfig).type.not.toBeCallableWith({
...options,
fetchData: {
config: {
// @ts-expect-error - Application must be a string
ApplicationIdentifier: 123,
// @ts-expect-error - Configuration must be a string
ConfigurationProfileIdentifier: 123,
// @ts-expect-error - Environment must be a string
EnvironmentIdentifier: 123,
ApplicationIdentifier: 123, // Application must be a string
ConfigurationProfileIdentifier: 123, // Configuration must be a string
EnvironmentIdentifier: 123, // Environment must be a string
},
},
});

appConfig({
expect(appConfig).type.not.toBeCallableWith({
...options,
fetchData: {
// @ts-expect-error - config must contain Application, ClientId, Configuration and Environment
config: {},
config: {}, // config must contain Application, ClientId, Configuration and Environment
},
});

Expand All @@ -126,12 +124,14 @@ handler
}),
)
.before(async (request) => {
expectType<{ config1: string; config2: string; config3: number }>(
request.context.config,
);
expect(request.context.config).type.toBe<{
config1: string;
config2: string;
config3: number;
}>();

const data = await getInternal("config", request);
expectType<string>(data.config.config1);
expect(data.config.config1).type.toBe<string>();
});

handler
Expand All @@ -153,7 +153,9 @@ handler
)
.before(async (request) => {
const data = await getInternal("config", request);
expectType<{ config1: string; config2: string; config3: number }>(
data.config,
);
expect(data.config).type.toBe<{
config1: string;
config2: string;
config3: number;
}>();
});
4 changes: 2 additions & 2 deletions packages/cloudformation-response/index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type middy from "@middy/core";
import { expectType } from "tsd";
import { expect } from "tstyche";

import cloudformationResponse from "./index.js";

// use with default options
const middleware = cloudformationResponse();
expectType<middy.MiddlewareObj>(middleware);
expect(middleware).type.toBe<middy.MiddlewareObj>();
6 changes: 3 additions & 3 deletions packages/cloudformation-router/index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type middy from "@middy/core";
// import { CloudFormationCustomResourceHandler } from 'aws-lambda'
import { expectType } from "tsd";
// import { CloudFormationCustomResourceHandler } from "aws-lambda";
import { expect } from "tstyche";
import cloudformationRouterHandler from "./index.js";

const createLambdaHandler: any = async () => {
Expand All @@ -25,4 +25,4 @@ const middleware = cloudformationRouterHandler([
handler: deleteLambdaHandler,
},
]);
expectType<middy.MiddyfiedHandler>(middleware);
expect(middleware).type.toBe<middy.MiddyfiedHandler>();
10 changes: 7 additions & 3 deletions packages/cloudwatch-metrics/index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import type middy from "@middy/core";
import { expectType } from "tsd";
import { expect } from "tstyche";
import cloudwatchMetrics, { type Context } from "./index.js";

// use with default options
let middleware = cloudwatchMetrics();
expectType<middy.MiddlewareObj<unknown, any, Error, Context>>(middleware);
expect(middleware).type.toBe<
middy.MiddlewareObj<unknown, any, Error, Context>
>();

// use with all options
middleware = cloudwatchMetrics({
namespace: "myApp",
dimensions: [{ Action: "Buy" }],
});
expectType<middy.MiddlewareObj<unknown, any, Error, Context>>(middleware);
expect(middleware).type.toBe<
middy.MiddlewareObj<unknown, any, Error, Context>
>();
Loading
Loading