Skip to content

Commit

Permalink
feat: export Target and RuntimeAdapter from generated code
Browse files Browse the repository at this point in the history
  • Loading branch information
magne4000 committed Dec 9, 2024
1 parent 6ee464c commit 056df5f
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/universal-middleware/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,13 @@ function loadDts(id: string, resolve?: (handler: string, type: string) => string
if (t === undefined) return;

const selfImports = [fn, `type ${t}`, ...(info.selfImports ?? [])];
const code = `import { type UniversalMiddleware } from '@universal-middleware/core';
const code = `import { type UniversalMiddleware, type RuntimeAdapterTarget } from '@universal-middleware/core';
import { ${selfImports.join(", ")} } from "universal-middleware/adapters/${info.target ?? target}";
import ${type} from "${resolve ? resolve(handler, type) : handler}";
type ExtractT<T> = T extends (...args: infer X) => any ? X : never;
type ExtractInContext<T> = T extends (...args: any[]) => UniversalMiddleware<infer X> ? unknown extends X ? Universal.Context : X : {};
export type Target = '${target}';
export type RuntimeAdapter = RuntimeAdapterTarget<Target>;
export type InContext = ExtractInContext<typeof ${type}>;
export type OutContext = ${info.outContext?.(type) ?? "unknown"};
export type Args = ExtractT<typeof ${type}>;
Expand Down

0 comments on commit 056df5f

Please sign in to comment.