/** * Convention over Configuration for Feature-First * * Automatically infers method, path, steps, asyncTasks from folder structure. * * Folder structure rules: * /features/{resource}/@{method}/ * * The @ prefix explicitly marks HTTP method folders, eliminating ambiguity * with resource names like "steps", "get", "post", etc. * * Examples: * /features/orders/@post/ -> POST /orders * /features/api/v1/users/@get/ -> GET /api/v1/users * /features/users/[id]/@put/ -> PUT /users/:id * /features/workflows/[id]/steps/@get/ -> GET /workflows/:id/steps (no conflict!) * * Implicit Feature (no index.js required): * /features/todos/@get/ * └── steps/ * └── 100-list.js * * Explicit Feature (with index.js for configuration): * /features/todos/@post/ * ├── index.js <- contextInitializer, middlewares, etc. * └── steps/ * └── 100-create.js */ /** * HTTP Method type */ export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE'; /** * Convention Resolver * Automatically infers Feature configuration from folder structure. */ export declare class ConventionResolver { /** * Features base directory cache * key: startPath, value: features directory path */ private static featuresBaseDirCache; /** * Infer HTTP method from folder name (with @ prefix) * * @param dirPath - Feature directory path * @returns HTTP method (GET, POST, PUT, PATCH, DELETE) * @throws {Error} Invalid method name * * @example * inferMethod('/features/orders/@post') // -> 'POST' * inferMethod('/features/users/@get') // -> 'GET' */ static inferMethod(dirPath: string): HttpMethod; /** * Infer API path from folder structure * * @param dirPath - Feature directory path * @param featuresBase - features base directory path * @returns API path (e.g. /api/v1/orders) * * @example * inferPath('/features/orders/@post', '/features') * // -> '/orders' * * inferPath('/features/api/v1/orders/@post', '/features') * // -> '/api/v1/orders' * * inferPath('/features/users/[id]/@get', '/features') * // -> '/users/:id' * * inferPath('/features/workflows/[id]/steps/@get', '/features') * // -> '/workflows/:id/steps' (no conflict with "steps" resource name!) */ static inferPath(dirPath: string, featuresBase: string): string; /** * Parse dynamic route * [id] -> :id * [userId] -> :userId * * @param segment - Path segment * @returns Converted segment * * @example * parseDynamicRoute('[id]') // -> ':id' * parseDynamicRoute('[userId]') // -> ':userId' * parseDynamicRoute('orders') // -> 'orders' */ static parseDynamicRoute(segment: string): string; /** * Auto-search for steps folder * * @param featureDir - Feature directory path * @returns steps folder path or null * * @example * findStepsDir('/features/orders/post') * // -> './steps' (if folder exists) * // -> null (if folder doesn't exist) */ static findStepsDir(featureDir: string): string | null; /** * Auto-search for async-tasks folder * * @param featureDir - Feature directory path * @returns async-tasks folder path or null * * @example * findAsyncTasksDir('/features/orders/post') * // -> './async-tasks' (if folder exists) * // -> null (if folder doesn't exist) */ static findAsyncTasksDir(featureDir: string): string | null; /** * Check if string is HTTP method folder name (with @ prefix) * * @param dirname - Folder name * @returns Whether it's HTTP method folder name * * @example * isHttpMethod('@get') // -> true * isHttpMethod('@post') // -> true * isHttpMethod('get') // -> false (no @ prefix) * isHttpMethod('steps') // -> false */ static isHttpMethod(dirname: string): boolean; /** * Find features base directory * * @param startPath - Start path * @returns features directory path * @throws {Error} If features directory cannot be found * * @performance * - First call: File system traversal (slow) * - Repeated calls: Cache lookup (very fast, 30% server startup time reduction) */ static findFeaturesBaseDir(startPath: string): string; /** * Clear cache (for testing) * * Deletes all Features base directory cache. * Mainly used in test environments. */ static clearCache(): void; /** * Return cache size (for testing/debugging) * * @returns Number of items stored in cache */ static getCacheSize(): number; /** * Get caller's file path * * Supports both CommonJS and ESM: * - CJS: Uses V8 stack trace API * - ESM: Handles different stack structure * * @returns Caller's absolute path */ static getCallerPath(): string; /** * Infer features base directory from feature directory * * Walks up the directory tree to find the @{method} folder, * then returns its parent directory as the features base. * * @param featureDir - Feature directory path * @returns Inferred features base directory * * @example * inferFeaturesBase('/path/to/test.xml/@get') * // -> '/path/to' * * inferFeaturesBase('/path/to/api/users/@post') * // -> '/path/to/api/users' */ static inferFeaturesBase(featureDir: string): string; /** * Infer complete Feature configuration * * @param callerPath - Caller file path (index.js or directory path) * @param featuresBase - Features base directory (optional, will auto-detect if not provided) * @returns Inferred configuration * * @example * // When called from /features/api/v1/orders/@post/index.js: * resolveConventions('/features/api/v1/orders/@post/index') * // -> { * // method: 'POST', * // path: '/api/v1/orders', * // steps: './steps', * // asyncTasks: './async-tasks' * // } * * // When called with directory path (implicit Feature): * resolveConventions('/features/todos/@get') * // -> { * // method: 'GET', * // path: '/todos', * // steps: './steps', * // asyncTasks: null * // } * * // When called with custom features base directory: * resolveConventions('/my-api/users/@get/index', '/my-api') * // -> { * // method: 'GET', * // path: '/users', * // steps: './steps', * // asyncTasks: null * // } */ static resolveConventions(callerPath: string, featuresBase?: string): { method: HttpMethod; path: string; steps: string | null; asyncTasks: string | null; }; } //# sourceMappingURL=convention.d.ts.map