MCPcopy Create free account
hub / github.com/middleapi/orpc / implement

Function implement

packages/server/src/implementer.ts:214–246  ·  view source on GitHub ↗
(
  contract: T,
  config: BuilderConfig = {},
)

Source from the content-addressed store, hash-verified

212 & ImplementerInternal<TContract, TInitialContext, TCurrentContext>
213
214export function implement<T extends AnyContractRouter, TContext extends Context = Record<never, never>>(
215 contract: T,
216 config: BuilderConfig = {},
217): Implementer<T, TContext, TContext> {
218 const implInternal = implementerInternal(contract, config, [])
219
220 const impl = new Proxy(implInternal, {
221 get: (target, key) => {
222 let method: AnyFunction | undefined
223
224 if (key === '$context') {
225 method = () => impl
226 }
227 else if (key === '$config') {
228 method = (config: BuilderConfig) => implement(contract, config)
229 }
230
231 const next = Reflect.get(target, key)
232
233 if (!method || !next || (typeof next !== 'function' && typeof next !== 'object')) {
234 return method || next
235 }
236
237 return new Proxy(method, {
238 get(_, key) {
239 return Reflect.get(next, key)
240 },
241 })
242 },
243 })
244
245 return impl as any
246}

Callers 15

helpers.tsFile · 0.90
pingMethod · 0.90
ping_wrong_implementMethod · 0.90
ping_with_lazyMethod · 0.90
pingMethod · 0.90
pongMethod · 0.90
pengMethod · 0.90
routerMethod · 0.90

Calls 2

implementerInternalFunction · 0.85
getMethod · 0.65

Tested by 9

pingMethod · 0.72
pongMethod · 0.72
pengMethod · 0.72
routerMethod · 0.72
pengMethod · 0.72
pongMethod · 0.72
pingMethod · 0.72
pongMethod · 0.72
pengMethod · 0.72