| 122 | * @publicApi |
| 123 | */ |
| 124 | export class FastifyAdapter< |
| 125 | TServer extends RawServerBase = RawServerDefault, |
| 126 | TRawRequest extends FastifyRawRequest<TServer> = FastifyRawRequest<TServer>, |
| 127 | TRawResponse extends RawReplyDefaultExpression<TServer> = |
| 128 | RawReplyDefaultExpression<TServer>, |
| 129 | TRequest extends FastifyRequest< |
| 130 | RequestGenericInterface, |
| 131 | TServer, |
| 132 | TRawRequest |
| 133 | > = FastifyRequest<RequestGenericInterface, TServer, TRawRequest>, |
| 134 | TReply extends FastifyReply< |
| 135 | RouteGenericInterface, |
| 136 | TServer, |
| 137 | TRawRequest, |
| 138 | TRawResponse |
| 139 | > = FastifyReply<RouteGenericInterface, TServer, TRawRequest, TRawResponse>, |
| 140 | TInstance extends FastifyInstance<TServer, TRawRequest, TRawResponse> = |
| 141 | FastifyInstance<TServer, TRawRequest, TRawResponse>, |
| 142 | > extends AbstractHttpAdapter<TServer, TRequest, TReply> { |
| 143 | protected readonly logger = new Logger(FastifyAdapter.name); |
| 144 | protected readonly instance: TInstance; |
| 145 | protected _pathPrefix?: string; |
| 146 | |
| 147 | private _isParserRegistered: boolean; |
| 148 | private onRequestHook?: ( |
| 149 | request: TRequest, |
| 150 | reply: TReply, |
| 151 | done: (err?: Error) => void, |
| 152 | ) => void | Promise<void>; |
| 153 | private onResponseHook?: ( |
| 154 | request: TRequest, |
| 155 | reply: TReply, |
| 156 | done: (err?: Error) => void, |
| 157 | ) => void | Promise<void>; |
| 158 | private isMiddieRegistered: boolean; |
| 159 | private pendingMiddlewares: Array<{ args: any[] }> = []; |
| 160 | private versioningOptions?: VersioningOptions; |
| 161 | private readonly versionConstraint = { |
| 162 | name: 'version', |
| 163 | validate(value: unknown) { |
| 164 | if (!isString(value) && !Array.isArray(value)) { |
| 165 | throw new Error( |
| 166 | 'Version constraint should be a string or an array of strings.', |
| 167 | ); |
| 168 | } |
| 169 | }, |
| 170 | storage() { |
| 171 | const versions = new Map<string, unknown>(); |
| 172 | return { |
| 173 | get(version: string | Array<string>) { |
| 174 | if (Array.isArray(version)) { |
| 175 | return versions.get(version.find(v => versions.has(v))!) || null; |
| 176 | } |
| 177 | return versions.get(version) || null; |
| 178 | }, |
| 179 | set(versionOrVersions: string | Array<string>, store: unknown) { |
| 180 | const storeVersionConstraint = (version: string) => |
| 181 | versions.set(version, store); |
nothing calls this directly
no test coverage detected