nuxt-apex
Version:
Auto-generates fully typed useFetch composables for Nuxt 3/4 server endpoints with Zod validation and zero boilerplate
72 lines (68 loc) • 2.91 kB
text/typescript
import * as _nuxt_schema from '@nuxt/schema';
import { ProjectOptions, Project } from 'ts-morph';
interface ApexModuleOptions {
/** Custom path to the source files (default: 'api') */
sourcePath: string;
/** Output path (default: 'node_modules/.nuxt-apex/composables') */
outputPath: string;
/** Composable name prefix (default: 'useTFetch') */
composablePrefix: string;
/**Custom naming function for composable names (without prefix) */
namingFucntion: (path: string) => string;
/** @see https://ts-morph.com/setup/ */
tsMorphOptions: ProjectOptions;
/**When true, the module will listen for changes in the source files and re-generate the composables (default: true) */
listenFileDependenciesChanges: boolean;
/**The name of the server event handler (default: 'defineApexHandler') */
serverEventHandlerName: string;
/** The path to the tsconfig.json file */
tsConfigFilePath?: string;
/** Ignore endpoints by relative path, e.g. api/some-endpoint.ts (default: []) */
ignore?: string[];
/** The path to the cache folder (default: 'node_modules/.cache/nuxt-apex') */
cacheFolder?: string;
/** The concurrency limit for generating composables (default: 50) */
concurrency?: number;
}
type EndpointStructure = {
url: string;
slugs: string[];
method: 'get' | 'post' | 'put' | 'delete';
name: string;
};
type EndpointTypeStructure = {
inputType: string;
inputFilePath: string;
responseType: string;
responseFilePath: string;
alias?: string;
};
declare const DEFAULTS: {
sourcePath: string;
outputPath: string;
cacheFolder: string;
composablePrefix: string;
namingFucntion: undefined;
listenFileDependenciesChanges: boolean;
serverEventHandlerName: string;
tsConfigFilePath: undefined;
ignore: never[];
concurrency: number;
tsMorphOptions: {
addFilesFromTsConfig: boolean;
skipFileDependencyResolution: boolean;
compilerOptions: {
skipLibCheck: boolean;
allowJs: boolean;
declaration: boolean;
noEmit: boolean;
preserveConstEnums: boolean;
};
};
};
declare const _default: _nuxt_schema.NuxtModule<ApexModuleOptions, ApexModuleOptions, false>;
declare function extractTypesFromEndpoint(endpoint: string, tsProject: Project, handlerName: string, isUpdate?: boolean): Promise<EndpointTypeStructure>;
declare function getEndpointStructure(endpoint: string, sourcePath: string, baseUrl: string, namingFucntion?: (path: string) => string): EndpointStructure;
declare function constructComposableCode(template: string, et: EndpointTypeStructure, es: EndpointStructure, composablePrefix: string): string;
export { DEFAULTS, constructComposableCode, _default as default, extractTypesFromEndpoint, getEndpointStructure };
export type { ApexModuleOptions };