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

Function onFinish

packages/shared/src/interceptor.ts:71–97  ·  view source on GitHub ↗
(
  callback: NoInfer<(
    state: OnFinishState<
      Awaited<ReturnType<TOptions['next']>>,
      ReturnType<TOptions['next']> extends PromiseWithError<any, infer E> ? E : ThrowableError
    >,
    options: TOptions,
    ...rest: TRest
  ) => Promisable<void>>,
)

Source from the content-addressed store, hash-verified

69 * Can be used for interceptors or middlewares
70 */
71export function onFinish<T, TOptions extends { next(): any }, TRest extends any[]>(
72 callback: NoInfer<(
73 state: OnFinishState<
74 Awaited<ReturnType<TOptions['next']>>,
75 ReturnType<TOptions['next']> extends PromiseWithError<any, infer E> ? E : ThrowableError
76 >,
77 options: TOptions,
78 ...rest: TRest
79 ) => Promisable<void>>,
80): (options: TOptions, ...rest: TRest) => T | Promise<Awaited<ReturnType<TOptions['next']>>> {
81 let state: any
82
83 return async (options, ...rest) => {
84 try {
85 const result = await options.next()
86 state = [null, result, true]
87 return result
88 }
89 catch (error) {
90 state = [error, undefined, false]
91 throw error
92 }
93 finally {
94 await callback(state, options, ...rest)
95 }
96 }
97}
98
99export function intercept<TOptions extends InterceptableOptions, TResult>(
100 interceptors: Interceptor<TOptions, TResult>[],

Callers 3

onFinishDeferredFunction · 0.90

Calls 2

callbackFunction · 0.85
nextMethod · 0.45

Tested by

no test coverage detected