UNPKG

@orpc/server

Version:

<div align="center"> <image align="center" src="https://orpc.dev/logo.webp" width=280 alt="oRPC logo" /> </div>

55 lines (51 loc) 2.06 kB
import { toArray, intercept, resolveMaybeOptionalOptions } from '@orpc/shared'; import { toStandardLazyRequest, sendStandardResponse } from '@orpc/standard-server-fastify'; import { r as resolveFriendlyStandardHandleOptions } from '../../shared/server.DZ5BIITo.mjs'; import '@orpc/standard-server'; import '@orpc/standard-server/batch'; import '@orpc/standard-server-fetch'; import '@orpc/client'; import { S as StrictGetMethodPlugin } from '../../shared/server.TEVCLCFC.mjs'; import '@orpc/contract'; import { b as StandardRPCHandler } from '../../shared/server.Bxx6tqNe.mjs'; import '@orpc/client/standard'; import '../../shared/server.Ds4HPpvH.mjs'; class FastifyHandler { constructor(standardHandler, options = {}) { this.standardHandler = standardHandler; this.adapterInterceptors = toArray(options.adapterInterceptors); this.sendStandardResponseOptions = options; } sendStandardResponseOptions; adapterInterceptors; async handle(request, reply, ...rest) { return intercept( this.adapterInterceptors, { ...resolveFriendlyStandardHandleOptions(resolveMaybeOptionalOptions(rest)), request, reply, sendStandardResponseOptions: this.sendStandardResponseOptions }, async ({ request: request2, reply: reply2, sendStandardResponseOptions, ...options }) => { const standardRequest = toStandardLazyRequest(request2, reply2); const result = await this.standardHandler.handle(standardRequest, options); if (!result.matched) { return { matched: false }; } await sendStandardResponse(reply2, result.response, sendStandardResponseOptions); return { matched: true }; } ); } } class RPCHandler extends FastifyHandler { constructor(router, options = {}) { if (options.strictGetMethodPluginEnabled ?? true) { options.plugins ??= []; options.plugins.push(new StrictGetMethodPlugin()); } super(new StandardRPCHandler(router, options), options); } } export { FastifyHandler, RPCHandler };