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

Function intercept

packages/shared/src/interceptor.ts:99–118  ·  view source on GitHub ↗
(
  interceptors: Interceptor<TOptions, TResult>[],
  options: NoInfer<TOptions>,
  main: NoInfer<(options: TOptions) => TResult>,
)

Source from the content-addressed store, hash-verified

97}
98
99export function intercept<TOptions extends InterceptableOptions, TResult>(
100 interceptors: Interceptor<TOptions, TResult>[],
101 options: NoInfer<TOptions>,
102 main: NoInfer<(options: TOptions) => TResult>,
103): TResult {
104 const next = (options: TOptions, index: number): TResult => {
105 const interceptor = interceptors[index]
106
107 if (!interceptor) {
108 return main(options)
109 }
110
111 return interceptor({
112 ...options,
113 next: (newOptions: TOptions = options) => next(newOptions, index + 1),
114 })
115 }
116
117 return next(options, 0)
118}

Callers 13

callMethod · 0.90
callMethod · 0.90
useServerActionFunction · 0.90
interceptMethod · 0.90
createProcedureClientFunction · 0.90
handleMethod · 0.90
handleMethod · 0.90
handleMethod · 0.90
handleMethod · 0.90

Calls 1

nextFunction · 0.70

Tested by

no test coverage detected