diff --git a/src/module.ts b/src/module.ts index b257962..c55509e 100644 --- a/src/module.ts +++ b/src/module.ts @@ -11,8 +11,10 @@ export default defineNuxtModule({ configKey: 'apiUtils', }, defaults: {}, - setup(_options, _nuxt) { + setup(_options, nuxt) { const resolver = createResolver(import.meta.url) + nuxt.options.alias['#api-utils'] = resolver.resolve('./runtime/types/index') + addServerImportsDir(resolver.resolve('./runtime/server/utils')) }, }) diff --git a/src/runtime/server/utils/binder.ts b/src/runtime/server/utils/binder.ts index 3387e77..028078c 100644 --- a/src/runtime/server/utils/binder.ts +++ b/src/runtime/server/utils/binder.ts @@ -1,9 +1,5 @@ import type { H3Event, Router } from 'h3' - -export interface BinderConfig { - prismaFactory: (event: H3Event) => unknown - models: Record -} +import type { BinderConfig } from '#api-utils' export function modelBinder(config: BinderConfig, router: Router) { async function lookupModels>(modelNames: (keyof T)[], event: H3Event): Promise { diff --git a/src/runtime/server/utils/metapi.ts b/src/runtime/server/utils/metapi.ts index e8ff982..13f94e1 100644 --- a/src/runtime/server/utils/metapi.ts +++ b/src/runtime/server/utils/metapi.ts @@ -1,13 +1,4 @@ -type MetapiDetail = string | import('zod').ZodIssue[] - -interface MetapiResponse { - meta: { - benchmark: string - success: boolean - detail?: MetapiDetail - } - data: T -} +import type { MetapiResponse, MetapiDetail } from '#api-utils' let start: number | undefined diff --git a/src/runtime/types/index.d.ts b/src/runtime/types/index.d.ts new file mode 100644 index 0000000..fc773c4 --- /dev/null +++ b/src/runtime/types/index.d.ts @@ -0,0 +1,18 @@ +import type { H3Event } from 'h3' +import type { ZodIssue } from 'zod' + +export type BinderConfig = { + prismaFactory: (event: H3Event) => unknown + models: Record +} + +export type MetapiDetail = string | ZodIssue[] + +export interface MetapiResponse { + meta: { + benchmark: string + success: boolean + detail?: MetapiDetail + } + data: T +}