This commit is contained in:
Stephen Zhou
2026-01-25 20:03:54 +08:00
parent e3a355aaad
commit a6286dbffd
4 changed files with 45 additions and 41 deletions

View File

@ -6,18 +6,21 @@ import { handler } from './plugin'
export const defaultConfig: OrpcPlugin['Config'] = {
config: {
contractNameBuilder: (id: string) => `${id}Contract`,
defaultTag: 'default',
exportFromIndex: false,
output: 'orpc',
},
dependencies: ['@hey-api/typescript', 'zod'],
handler,
name: 'orpc',
resolveConfig: (plugin) => {
plugin.config.output = plugin.config.output ?? 'orpc'
plugin.config.exportFromIndex = plugin.config.exportFromIndex ?? false
plugin.config.contractNameBuilder = plugin.config.contractNameBuilder
?? ((id: string) => `${id}Contract`)
plugin.config.defaultTag = plugin.config.defaultTag ?? 'default'
resolveConfig: (plugin, _context) => {
plugin.config.output ??= 'orpc'
plugin.config.exportFromIndex ??= false
plugin.config.contractNameBuilder ??= (id: string) => `${id}Contract`
plugin.config.defaultTag ??= 'default'
},
tags: ['client'],
}
/**

View File

@ -1,2 +1,2 @@
export { defaultConfig, defineConfig } from './config'
export type { Config, OrpcPlugin, ResolvedConfig } from './types'
export type { OrpcPlugin, UserConfig } from './types'

35
web/plugins/hey-api-orpc/types.d.ts vendored Normal file
View File

@ -0,0 +1,35 @@
import type { DefinePlugin, Plugin } from '@hey-api/openapi-ts'
export type UserConfig = Plugin.Name<'orpc'>
& Plugin.Hooks & {
/**
* Name of the generated file.
* @default 'orpc'
*/
output?: string
/**
* Whether exports should be re-exported in the index file.
* @default false
*/
exportFromIndex?: boolean
/**
* Custom naming function for contract symbols.
* @default (id) => `${id}Contract`
*/
contractNameBuilder?: (operationId: string) => string
/**
* Default tag name for operations without tags.
* @default 'default'
*/
defaultTag?: string
}
export type Config = Plugin.Name<'orpc'>
& Plugin.Hooks & {
output: string
exportFromIndex: boolean
contractNameBuilder: (operationId: string) => string
defaultTag: string
}
export type OrpcPlugin = DefinePlugin<UserConfig, Config>

View File

@ -1,34 +0,0 @@
import type { DefinePlugin } from '@hey-api/openapi-ts'
export type Config = { name: 'orpc' } & {
/**
* Name of the generated file.
* @default 'orpc'
*/
output?: string
/**
* Whether exports should be re-exported in the index file.
* @default false
*/
exportFromIndex?: boolean
/**
* Custom naming function for contract symbols.
* @default (id) => `${id}Contract`
*/
contractNameBuilder?: (operationId: string) => string
/**
* Default tag name for operations without tags.
* @default 'default'
*/
defaultTag?: string
}
export type ResolvedConfig = {
name: 'orpc'
output: string
exportFromIndex: boolean
contractNameBuilder: (operationId: string) => string
defaultTag: string
}
export type OrpcPlugin = DefinePlugin<Config, ResolvedConfig>