Skip to content
Open
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
4 changes: 2 additions & 2 deletions packages/adapter/adapter-test/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interface CreateTestClientArgs<P = unknown> {
handler: HattipHandler<P>;
baseUrl?: string | URL;
platform?: P;
env?: Record<string, string>;
env?: Record<string, string | undefined>;
}

export function createTestClient<P = { name: "test" }>({
Expand Down Expand Up @@ -38,7 +38,7 @@ export function createTestClient<P = { name: "test" }>({
void promise;
},
env(variable) {
return env[variable];
return env[variable] as any;
Copy link
Copy Markdown
Contributor Author

@aleclarson aleclarson Feb 4, 2025

Choose a reason for hiding this comment

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

Due to #197's changes to the return type of env(), we have to cast to any.

Actually, this might belong in #197 (not sure).

},
});
};
Expand Down
13 changes: 12 additions & 1 deletion packages/base/core/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/**
* Interface defining the shape of environment variables
*/
export interface AdapterEnv {}

export type AdapterEnvKey = keyof AdapterEnv | (string & {});

export type AdapterEnvGetter = <K extends AdapterEnvKey>(
variable: K,
) => K extends keyof AdapterEnv ? AdapterEnv[K] : string | undefined;

/**
* Request context as dispatched by the platform adapter
*/
Expand All @@ -24,7 +35,7 @@ export interface AdapterRequestContext<P = unknown> {
*
* @returns The value of the variable or undefined if it doesn't exist.
*/
env(variable: string): string | undefined;
env: AdapterEnvGetter;
/**
* Signal that the request hasn't been handled and the returned response is
* a placeholder (usually a 404). In this case the adapter should handle the
Expand Down
Loading