MCPcopy Index your code
hub / github.com/upstash/jstack / registerOperation

Method registerOperation

packages/jstack/src/server/router.ts:207–420  ·  view source on GitHub ↗
(
    path: string,
    operation: OperationType<any, any, E>,
  )

Source from the content-addressed store, hash-verified

205 }
206
207 private registerOperation(
208 path: string,
209 operation: OperationType<any, any, E>,
210 ) {
211 const routePath = `/${path}` as const
212
213 if (!this._metadata.procedures[path]) {
214 this._metadata.procedures[path] = {
215 type: operation.type as any,
216 }
217 }
218
219 const operationMiddlewares: MiddlewareHandler<E>[] =
220 operation.middlewares.map((middleware) => {
221 const middlewareHandler = async (c: Context<E>, next: Next) => {
222 const typedC = c as ContextWithSuperJSON<
223 E & { Variables: InternalContext }
224 >
225 let middlewareOutput = typedC.get("__middleware_output") ?? {}
226
227 const nextWrapper = async <B>(args: B) => {
228 Object.assign(middlewareOutput, args)
229 return middlewareOutput
230 }
231
232 const res = await middleware({
233 ctx: middlewareOutput,
234 next: nextWrapper,
235 c: c as ContextWithSuperJSON<E>,
236 })
237
238 if (res) {
239 Object.assign(middlewareOutput, res)
240 }
241
242 typedC.set("__middleware_output", middlewareOutput)
243 await next()
244 }
245
246 return middlewareHandler
247 })
248
249 if (operation.type === "get") {
250 if (operation.schema) {
251 this.get(
252 routePath,
253 queryParsingMiddleware,
254 ...operationMiddlewares,
255 async (c) => {
256 const typedC = c as Context<E & { Variables: InternalContext }>
257 const ctx = typedC.get("__middleware_output") || {}
258 const parsedQuery = typedC.get("__parsed_query")
259
260 const queryInput =
261 Object.keys(parsedQuery || {}).length === 0
262 ? undefined
263 : parsedQuery
264

Callers 1

setupRoutesMethod · 0.95

Calls 5

closeMethod · 0.95
handleEventMethod · 0.95
getMethod · 0.80
handlerMethod · 0.80
postMethod · 0.80

Tested by

no test coverage detected