diff --git a/web/openapi-ts.config.ts b/web/openapi-ts.config.ts index 6641db0b0e..9825722d02 100644 --- a/web/openapi-ts.config.ts +++ b/web/openapi-ts.config.ts @@ -19,7 +19,6 @@ export default defineConfig({ }, defineOrpcConfig({ output: 'orpc', - generateRouter: true, }), ], }) diff --git a/web/plugins/hey-api-orpc/config.ts b/web/plugins/hey-api-orpc/config.ts index 1cda602e9d..051a3cf863 100644 --- a/web/plugins/hey-api-orpc/config.ts +++ b/web/plugins/hey-api-orpc/config.ts @@ -6,9 +6,6 @@ import { handler } from './plugin' export const defaultConfig: OrpcPlugin['Config'] = { config: { - baseName: 'base', - exportFromIndex: false, - generateRouter: true, output: 'orpc', }, dependencies: ['@hey-api/typescript', 'zod'], diff --git a/web/plugins/hey-api-orpc/plugin.ts b/web/plugins/hey-api-orpc/plugin.ts index 1713778800..6cbc5f7119 100644 --- a/web/plugins/hey-api-orpc/plugin.ts +++ b/web/plugins/hey-api-orpc/plugin.ts @@ -61,7 +61,6 @@ function collectOperation(operation: IR.OperationObject): OperationInfo { } export const handler: OrpcPlugin['Handler'] = ({ plugin }) => { - const config = plugin.config const operations: OperationInfo[] = [] const zodImports = new Set() @@ -95,7 +94,7 @@ export const handler: OrpcPlugin['Handler'] = ({ plugin }) => { } // Create base contract: export const base = oc.$route({ inputStructure: 'detailed' }) - const baseSymbol = plugin.symbol(config.baseName, { + const baseSymbol = plugin.symbol('base', { exported: true, meta: { category: 'schema', @@ -167,55 +166,53 @@ export const handler: OrpcPlugin['Handler'] = ({ plugin }) => { plugin.node(contractNode) } - // Create contracts object export if enabled - if (config.generateRouter) { - // Group operations by tag - const operationsByTag = new Map() - for (const op of operations) { - const tag = op.tags[0] - if (!operationsByTag.has(tag)) { - operationsByTag.set(tag, []) - } - operationsByTag.get(tag)!.push(op) + // Create contracts object export + // Group operations by tag + const operationsByTag = new Map() + for (const op of operations) { + const tag = op.tags[0] + if (!operationsByTag.has(tag)) { + operationsByTag.set(tag, []) } - - // Build contracts object - const contractsObject = $.object() - for (const [tag, tagOps] of operationsByTag) { - const tagKey = tag.charAt(0).toLowerCase() + tag.slice(1) - const tagObject = $.object() - for (const op of tagOps) { - const contractSymbol = contractSymbols[op.id] - if (contractSymbol) { - tagObject.prop(`${op.id}Contract`, $(contractSymbol)) - } - } - contractsObject.prop(tagKey, tagObject) - } - - const contractsSymbol = plugin.symbol('contracts', { - exported: true, - meta: { - category: 'schema', - }, - }) - - const contractsNode = $.const(contractsSymbol) - .export() - .assign(contractsObject) - plugin.node(contractsNode) - - // Create type export: export type Contracts = typeof contracts - const contractsTypeSymbol = plugin.symbol('Contracts', { - exported: true, - meta: { - category: 'type', - }, - }) - - const contractsTypeNode = $.type.alias(contractsTypeSymbol) - .export() - .type($.type.query($(contractsSymbol))) - plugin.node(contractsTypeNode) + operationsByTag.get(tag)!.push(op) } + + // Build contracts object + const contractsObject = $.object() + for (const [tag, tagOps] of operationsByTag) { + const tagKey = tag.charAt(0).toLowerCase() + tag.slice(1) + const tagObject = $.object() + for (const op of tagOps) { + const contractSymbol = contractSymbols[op.id] + if (contractSymbol) { + tagObject.prop(`${op.id}Contract`, $(contractSymbol)) + } + } + contractsObject.prop(tagKey, tagObject) + } + + const contractsSymbol = plugin.symbol('contracts', { + exported: true, + meta: { + category: 'schema', + }, + }) + + const contractsNode = $.const(contractsSymbol) + .export() + .assign(contractsObject) + plugin.node(contractsNode) + + // Create type export: export type Contracts = typeof contracts + const contractsTypeSymbol = plugin.symbol('Contracts', { + exported: true, + meta: { + category: 'type', + }, + }) + + const contractsTypeNode = $.type.alias(contractsTypeSymbol) + .export() + .type($.type.query($(contractsSymbol))) + plugin.node(contractsTypeNode) } diff --git a/web/plugins/hey-api-orpc/types.ts b/web/plugins/hey-api-orpc/types.ts index b9bdcbf653..914c19fc94 100644 --- a/web/plugins/hey-api-orpc/types.ts +++ b/web/plugins/hey-api-orpc/types.ts @@ -6,31 +6,10 @@ export type Config = { name: 'orpc' } & { * @default 'orpc' */ output?: string - - /** - * The name of the base contract variable. - * @default 'base' - */ - baseName?: string - - /** - * Whether to generate a contracts object that combines all contracts. - * @default true - */ - generateRouter?: boolean - - /** - * Whether to export from index file. - * @default false - */ - exportFromIndex?: boolean } export type ResolvedConfig = Config & { output: string - baseName: string - generateRouter: boolean - exportFromIndex: boolean } export type OrpcPlugin = DefinePlugin