( contract: T, config: BuilderConfig, middlewares: AnyMiddleware[], )
| 97 | } |
| 98 | |
| 99 | export function implementerInternal< |
| 100 | T extends AnyContractRouter, |
| 101 | TInitialContext extends Context, |
| 102 | TCurrentContext extends Context, |
| 103 | >( |
| 104 | contract: T, |
| 105 | config: BuilderConfig, |
| 106 | middlewares: AnyMiddleware[], |
| 107 | ): ImplementerInternal<T, TInitialContext, TCurrentContext> { |
| 108 | if (isContractProcedure(contract)) { |
| 109 | const impl = new Builder({ |
| 110 | ...contract['~orpc'], |
| 111 | config, |
| 112 | middlewares, |
| 113 | inputValidationIndex: fallbackConfig('initialInputValidationIndex', config?.initialInputValidationIndex) + middlewares.length, |
| 114 | outputValidationIndex: fallbackConfig('initialOutputValidationIndex', config?.initialOutputValidationIndex) + middlewares.length, |
| 115 | dedupeLeadingMiddlewares: fallbackConfig('dedupeLeadingMiddlewares', config.dedupeLeadingMiddlewares), |
| 116 | }) |
| 117 | |
| 118 | return impl as any |
| 119 | } |
| 120 | |
| 121 | const impl = new Proxy(contract, { |
| 122 | get: (target, key) => { |
| 123 | if (typeof key !== 'string') { |
| 124 | return Reflect.get(target, key) |
| 125 | } |
| 126 | |
| 127 | let method: AnyFunction | undefined |
| 128 | |
| 129 | if (key === 'middleware') { |
| 130 | method = (mid: any) => decorateMiddleware(mid) |
| 131 | } |
| 132 | else if (key === 'use') { |
| 133 | method = (mid: any) => { |
| 134 | return implementerInternal( |
| 135 | contract, |
| 136 | config, |
| 137 | addMiddleware(middlewares, mid), |
| 138 | ) |
| 139 | } |
| 140 | } |
| 141 | else if (key === 'router') { |
| 142 | method = (router: any) => { |
| 143 | const adapted = enhanceRouter(router, { |
| 144 | middlewares, |
| 145 | errorMap: {}, |
| 146 | prefix: undefined, |
| 147 | tags: undefined, |
| 148 | dedupeLeadingMiddlewares: fallbackConfig('dedupeLeadingMiddlewares', config.dedupeLeadingMiddlewares), |
| 149 | }) |
| 150 | |
| 151 | return setHiddenRouterContract(adapted, contract) |
| 152 | } |
| 153 | } |
| 154 | else if (key === 'lazy') { |
| 155 | method = (loader: () => Promise<{ default: AnyRouter }>) => { |
| 156 | const adapted = enhanceRouter(lazy(loader) as any, { |
no test coverage detected