Skip to content
Closed
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
25 changes: 25 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
"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:tsd": "find packages -name \"*.test-d.ts\" -exec dirname {} \\; | sed 's|packages/||' | sort -u | xargs -I {} tsd packages/{}",
"test:types:tstyche": "find packages -name \"*.tst.ts\" -exec dirname {} \\; | sed 's|packages/||' | sort -u | xargs -I {} tstyche packages/{}",
Comment on lines +26 to +27
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one allows us to keep both systems during the migration, and run the tests only where they are available for that framework.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"test:types:tstyche": "find packages -name \"*.tst.ts\" -exec dirname {} \\; | sed 's|packages/||' | sort -u | xargs -I {} tstyche packages/{}",
"test:types:tstyche": "tstyche",

Copy link
Contributor

@mrazauskas mrazauskas Jun 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you stick with the *.tst.ts pattern, TSTyche will handle that.

"test:types": "npm run test:types:tsd && npm run 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,6 +72,7 @@
"husky": "^9.0.0",
"tinybench": "^4.0.0",
"tsd": "^0.32.0",
"tstyche": "^4.1.0",
"typescript": "^5.0.0"
},
"workspaces": [
Expand Down
159 changes: 0 additions & 159 deletions packages/appconfig/index.test-d.ts

This file was deleted.

164 changes: 164 additions & 0 deletions packages/appconfig/index.tst.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
import { AppConfigDataClient } from "@aws-sdk/client-appconfigdata";
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 { expect, test } from "tstyche";
import appConfig, { appConfigReq } from ".";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can it be that extension less imports are still allowed? Ah.. The root ./tsconfig.json makes this work. It defaults to CJS resolution. Is that useful for any other tooling?

I see two options:

  • npm run test:types:tstyche -- --tsconfig ignore, simply use TSTyche defaults;
  • extend the root TSConfig from @tsconfig/node20, since Node.js 20 is the lowest supported version

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The extension less imports should fail after badad62. (Many thanks to @willfarrell!)


const options = {
AwsClient: AppConfigDataClient,
awsClientOptions: {
credentials: {
secretAccessKey: "secret",
sessionToken: "token",
accessKeyId: "key",
},
},
awsClientAssumeRole: "some-role",
awsClientCapture: captureAWSv3Client,
disablePrefetch: true,
cacheKey: "some-key",
cacheExpiry: 60 * 60 * 5,
setToContext: false,
} as const;
Copy link
Contributor

@mrazauskas mrazauskas Jun 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps? And remember to import the AppConfigOptions type:

Suggested change
} as const;
} satisfies AppConfigOptions;


test("should use default options", () => {
expect(appConfig()).type.toBe<
middy.MiddlewareObj<unknown, any, Error, LambdaContext>
>();
});

test("should use with setToContext: false", () => {
expect(
appConfig({
...options,
fetchData: {
config: {
ApplicationIdentifier: "app",
ConfigurationProfileIdentifier: "configId",
EnvironmentIdentifier: "development",
},
},
setToContext: false,
}),
).type.toBe<
middy.MiddlewareObj<
unknown,
any,
Error,
LambdaContext,
Record<"config", unknown>
>
>();
});

test("should use with setToContext: true", () => {
expect(
appConfig({
...options,
fetchData: {
config: {
ApplicationIdentifier: "app",
ConfigurationProfileIdentifier: "configId",
EnvironmentIdentifier: "development",
},
},
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" });
Comment on lines +80 to +81
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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


appConfig({
...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,
},
},
});
Comment on lines +83 to +95
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
appConfig({
...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,
},
},
});
expect(appConfig).type.not.toBeCallableWith({
...options,
fetchData: {
config: {
ApplicationIdentifier: 123,
ConfigurationProfileIdentifier: 123,
EnvironmentIdentifier: 123,
},
},
});


appConfig({
...options,
fetchData: {
// @ts-expect-error - config must contain Application, ClientId, Configuration and Environment
config: {},
},
});
Comment on lines +97 to +103
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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


const handler = middy(async (event: {}, context: LambdaContext) => {
return await Promise.resolve({});
});

test("should return the correct config", () => {
handler
.use(
appConfig({
fetchData: {
config: appConfigReq<{
config1: string;
config2: string;
config3: number;
}>({
ApplicationIdentifier: "app",
ConfigurationProfileIdentifier: "configId",
EnvironmentIdentifier: "development",
}),
},
setToContext: true,
}),
)
.before(async (request) => {
expect(request.context.config).type.toBe<{
config1: string;
config2: string;
config3: number;
}>();
const data = await getInternal("config", request);
expect(data.config.config1).type.toBe<string>();
});
});

test("should return the correct config using the getInternal method", () => {
handler
.use(
appConfig({
fetchData: {
config: appConfigReq<{
config1: string;
config2: string;
config3: number;
}>({
ApplicationIdentifier: "app",
ConfigurationProfileIdentifier: "configId",
EnvironmentIdentifier: "development",
}),
},
setToContext: false,
}),
)
.before(async (request) => {
const data = await getInternal("config", request);
expect(data.config).type.toBe<{
config1: string;
config2: string;
config3: number;
}>();
});
});
1 change: 1 addition & 0 deletions packages/validator/transpile.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { expectType } from "tsd";
import { transpileLocale, transpileSchema } from "./transpile";

const schema = transpileSchema({ type: "object" }, {});
expectType<any>(schema);
Expand Down
Loading