mirror of
https://github.com/langgenius/dify.git
synced 2026-05-03 00:48:04 +08:00
Update
This commit is contained in:
@ -19,7 +19,6 @@ export default defineConfig({
|
||||
},
|
||||
defineOrpcConfig({
|
||||
output: 'orpc',
|
||||
generateRouter: true,
|
||||
}),
|
||||
],
|
||||
})
|
||||
|
||||
@ -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'],
|
||||
|
||||
@ -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<string>()
|
||||
|
||||
@ -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<string, OperationInfo[]>()
|
||||
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<string, OperationInfo[]>()
|
||||
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)
|
||||
}
|
||||
|
||||
@ -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<Config, ResolvedConfig>
|
||||
|
||||
Reference in New Issue
Block a user