/* eslint-disable @typescript-eslint/no-explicit-any */ import type { Env, Input, MiddlewareHandler, H, HandlerResponse } from '../../types.ts' /** * @experimental * `Factory` class is an experimental feature. * The API might be changed. */ export class Factory { createMiddleware = (middleware: MiddlewareHandler) => middleware /** * @experimental * `createHandlers` is an experimental feature. * The API might be changed. */ createHandlers(handler1: H): [H] // handler x2 /** * @experimental * `createHandlers` is an experimental feature. * The API might be changed. */ createHandlers = any>( handler1: H, handler2: H ): [H, H] // handler x3 /** * @experimental * `createHandlers` is an experimental feature. * The API might be changed. */ createHandlers< I extends Input = {}, I2 extends Input = I, I3 extends Input = I & I2, R extends HandlerResponse = any >( handler1: H, handler2: H, handler3: H ): [H, H, H] // handler x4 /** * @experimental * `createHandlers` is an experimental feature. * The API might be changed. */ createHandlers< I extends Input = {}, I2 extends Input = I, I3 extends Input = I & I2, I4 extends Input = I & I2 & I3, R extends HandlerResponse = any >( handler1: H, handler2: H, handler3: H, handler4: H ): [H, H, H, H] // handler x5 /** * @experimental * `createHandlers` is an experimental feature. * The API might be changed. */ createHandlers< I extends Input = {}, I2 extends Input = I, I3 extends Input = I & I2, I4 extends Input = I & I2 & I3, I5 extends Input = I & I2 & I3 & I4, R extends HandlerResponse = any >( handler1: H, handler2: H, handler3: H, handler4: H, handler5: H ): [H, H, H, H, H] // handler x6 /** * @experimental * `createHandlers` is an experimental feature. * The API might be changed. */ createHandlers< I extends Input = {}, I2 extends Input = I, I3 extends Input = I & I2, I4 extends Input = I & I2 & I3, I5 extends Input = I & I2 & I3 & I4, I6 extends Input = I & I2 & I3 & I4 & I5, R extends HandlerResponse = any >( handler1: H, handler2: H, handler3: H, handler4: H, handler5: H, handler6: H ): [H, H, H, H, H, H] // handler x7 /** * @experimental * `createHandlers` is an experimental feature. * The API might be changed. */ createHandlers< I extends Input = {}, I2 extends Input = I, I3 extends Input = I & I2, I4 extends Input = I & I2 & I3, I5 extends Input = I & I2 & I3 & I4, I6 extends Input = I & I2 & I3 & I4 & I5, I7 extends Input = I & I2 & I3 & I4 & I5 & I6, R extends HandlerResponse = any >( handler1: H, handler2: H, handler3: H, handler4: H, handler5: H, handler6: H, handler7: H ): [ H, H, H, H, H, H, H ] // handler x8 /** * @experimental * `createHandlers` is an experimental feature. * The API might be changed. */ createHandlers< I extends Input = {}, I2 extends Input = I, I3 extends Input = I & I2, I4 extends Input = I & I2 & I3, I5 extends Input = I & I2 & I3 & I4, I6 extends Input = I & I2 & I3 & I4 & I5, I7 extends Input = I & I2 & I3 & I4 & I5 & I6, I8 extends Input = I & I2 & I3 & I4 & I5 & I6 & I7, R extends HandlerResponse = any >( handler1: H, handler2: H, handler3: H, handler4: H, handler5: H, handler6: H, handler7: H, handler8: H ): [ H, H, H, H, H, H, H, H ] // handler x9 /** * @experimental * `createHandlers` is an experimental feature. * The API might be changed. */ createHandlers< I extends Input = {}, I2 extends Input = I, I3 extends Input = I & I2, I4 extends Input = I & I2 & I3, I5 extends Input = I & I2 & I3 & I4, I6 extends Input = I & I2 & I3 & I4 & I5, I7 extends Input = I & I2 & I3 & I4 & I5 & I6, I8 extends Input = I & I2 & I3 & I4 & I5 & I6 & I7, I9 extends Input = I & I2 & I3 & I4 & I5 & I6 & I7 & I8, R extends HandlerResponse = any >( handler1: H, handler2: H, handler3: H, handler4: H, handler5: H, handler6: H, handler7: H, handler8: H, handler9: H ): [ H, H, H, H, H, H, H, H, H ] // handler x10 /** * @experimental * `createHandlers` is an experimental feature. * The API might be changed. */ createHandlers< I extends Input = {}, I2 extends Input = I, I3 extends Input = I & I2, I4 extends Input = I & I2 & I3, I5 extends Input = I & I2 & I3 & I4, I6 extends Input = I & I2 & I3 & I4 & I5, I7 extends Input = I & I2 & I3 & I4 & I5 & I6, I8 extends Input = I & I2 & I3 & I4 & I5 & I6 & I7, I9 extends Input = I & I2 & I3 & I4 & I5 & I6 & I7 & I8, I10 extends Input = I & I2 & I3 & I4 & I5 & I6 & I7 & I8 & I9, R extends HandlerResponse = any >( handler1: H, handler2: H, handler3: H, handler4: H, handler5: H, handler6: H, handler7: H, handler8: H, handler9: H, handler10: H ): [ H, H, H, H, H, H, H, H, H, H ] createHandlers(...handlers: H[]) { return handlers.filter((handler) => handler !== undefined) } } /** * @experimental * `createFactory` is an experimental feature. * The API might be changed. */ export const createFactory = () => new Factory() export const createMiddleware = ( middleware: MiddlewareHandler ) => createFactory().createMiddleware(middleware)