Skip to content

Commit

Permalink
feat: expose types via #nuxt-api-party
Browse files Browse the repository at this point in the history
  • Loading branch information
johannschopplich committed Aug 18, 2023
1 parent 159b27d commit 5c5b308
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,15 @@ export const ${getDataComposableName(i)} = (...args) => _useApiData('${i}', ...a
getContents() {
return `
// Generated by ${moduleName}
import type { $Api } from '${relativeTo('runtime/composables/$api')}'
import type { UseApiData } from '${relativeTo('runtime/composables/useApiData')}'
import type { $Api, $AnyApi, $OpenApi, AnyApiFetchOptions } from '${relativeTo('runtime/composables/$api')}'
import type { UseApiData, UseAnyApiData, UseOpenApiData, UseAnyApiDataOptions } from '${relativeTo('runtime/composables/useApiData')}'
export type { $Api, $AnyApi, $OpenApi, AnyApiFetchOptions, UseApiData, UseAnyApiData, UseOpenApiData, UseAnyApiDataOptions }
${schemaEndpointIds.map(i => `import type { paths as ${pascalCase(i)}Paths } from '#${moduleName}/${i}'`).join('')}
${endpointKeys.map(i => `
export declare const ${getRawComposableName(i)}: $Api${schemaEndpointIds.includes(i) ? `<${pascalCase(i)}Paths>` : ''}
export declare const ${getDataComposableName(i)}: UseApiData${schemaEndpointIds.includes(i) ? `<${pascalCase(i)}Paths>` : ''}
export declare const ${getRawComposableName(i)}: ${schemaEndpointIds.includes(i) ? `$OpenApi<${pascalCase(i)}Paths>` : '$AnyApi'}
export declare const ${getDataComposableName(i)}: ${schemaEndpointIds.includes(i) ? `UseOpenApiData<${pascalCase(i)}Paths>` : 'UseAnyApiData'}
`.trimStart()).join('').trimEnd()}
`.trimStart()
},
Expand Down
1 change: 1 addition & 0 deletions src/runtime/composables/$api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export interface $OpenApi<Paths extends Record<string, PathItemObject>> {
): Promise<OpenApiResponse<Paths[`/${P}`][Lowercase<M>]>>
}

/** @remarks Prefer using `$AnyApi` and `$OpenApi` directly */
export type $Api<Paths extends Record<string, PathItemObject> = never> = [Paths] extends [never]
? $AnyApi
: $OpenApi<Paths>
Expand Down
1 change: 1 addition & 0 deletions src/runtime/composables/useApiData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export interface UseOpenApiData<Paths extends Record<string, PathItemObject>> {
): AsyncData<OpenApiResponse<Paths[`/${P}`][Lowercase<M>]>, OpenApiError<Paths[`/${P}`][Lowercase<M>]>>
}

/** @remarks Prefer using `UseAnyApiData` and `UseOpenApiData` directly */
export type UseApiData<Paths extends Record<string, PathItemObject> = never> = [Paths] extends [never]
? UseAnyApiData
: UseOpenApiData<Paths>
Expand Down

0 comments on commit 5c5b308

Please sign in to comment.