{
  "version": 3,
  "sources": ["../src/index.ts", "../src/server.ts", "../src/server/address.ts", "../src/logger.ts", "../src/gateway/ws/core.ts", "../src/gateway/gateway-manager.ts", "../src/gateway/config.ts", "../src/common/compose.ts", "../src/http/exchange.ts", "../src/http/media-type.ts", "../src/utils/mime-type-utils.ts", "../src/http/headers.ts", "../src/http/status.ts", "../src/server/exchange.ts", "../src/http/server/path.ts", "../src/http/server/exchange.ts", "../src/server/monitoring.ts", "../src/server/server-header.ts", "../src/server/ws-client-verify.ts", "../src/server/util/matchers.ts", "../src/app/route.ts", "../src/server/cors.ts", "../src/web/cors/utils.ts", "../src/app/cors.ts", "../src/server/security/types.ts", "../src/server/security/http-headers.ts", "../src/server/security/entry-point-failure-handler.ts", "../src/server/security/http-basic-entry-point.ts", "../src/server/security/http-basic-converter.ts", "../src/server/security/security-context.ts", "../src/server/security/authentication-filter.ts", "../src/server/security/http-status-entry-point.ts", "../src/server/security/delegating-entry-point.ts", "../src/server/security/delegating-success-handler.ts", "../src/server/security/http-basic.ts", "../src/server/security/oauth2/token-error.ts", "../src/server/security/oauth2/token-converter.ts", "../src/server/security/oauth2/token-entry-point.ts", "../src/server/security/oauth2/jwt-auth-manager.ts", "../src/server/security/oauth2-resource-server.ts", "../src/server/security/config.ts", "../src/server/security/error-filter.ts", "../src/server/security/delegating-authorization-manager.ts", "../src/server/security/authorization-filter.ts", "../src/server/security/exchange-filter.ts", "../src/server/security/x509-converter.ts", "../src/server/security/preauth/x509.ts", "../src/server/security/crypto/password.ts", "../src/server/security/crypto/argon2.ts", "../src/server/security/crypto/index.ts", "../src/server/security/users/types.ts", "../src/server/security/users.ts", "../src/server/security/x509.ts", "../src/web/server/handler.ts", "../src/server/security/web.ts", "../src/server/security/users/memory.ts", "../src/app/auth.ts", "../src/server/handler.ts", "../src/server/ws.ts", "../src/server/socket.ts", "../src/server/ws-pings.ts", "../src/server/ssl/config.ts", "../src/codec/hints.ts", "../src/codec/encoder.ts", "../src/http/codec/core.ts", "../src/http/codec/multipart.ts", "../src/http/codec/config.ts", "../src/manage/server.ts", "../src/manage/client.ts", "../src/server/welcome-page.ts", "../src/web/server/adapter.ts", "../src/web/util/client.ts", "../src/web/async/fn/server/request.ts", "../src/web/util/pattern/internal/path-element.ts", "../src/web/util/pattern/internal/separator-path-element.ts", "../src/web/util/pattern/internal/wildcard-path-element.ts", "../src/web/util/pattern/internal/capture-segments-path-element.ts", "../src/web/util/pattern/internal/wildcard-segments-path-element.ts", "../src/web/util/pattern/path-pattern.ts", "../src/web/util/pattern/pattern-parse-error.ts", "../src/web/util/pattern/internal/capture-variable-path-element.ts", "../src/web/util/pattern/internal/single-char-wildcarded-path-element.ts", "../src/web/util/pattern/internal/regex-path-element.ts", "../src/web/util/pattern/internal/literal-path-element.ts", "../src/web/util/pattern/internal/path-pattern-parser.ts", "../src/web/util/pattern/path-pattern-parser.ts", "../src/web/async/fn/server/router.ts", "../src/web/async/fn/server/response.ts", "../src/server/error.ts", "../src/web/error.ts", "../src/web/server/error.ts", "../src/web/async/handler.ts", "../src/web/async/fn/server/handler.ts"],
  "sourcesContent": ["import * as GatewayServer from './server.ts';\n\nexport { GatewayServer };\nexport default GatewayServer.Factory;\n", "import http from 'node:http';\nimport https from 'node:https';\nimport type { AddressInfo, Socket } from 'node:net';\nimport { AsyncLocalStorage } from 'node:async_hooks';\nimport wsGateway from './gateway/ws/core.ts';\nimport { GatewayManager } from './gateway/gateway-manager.ts';\nimport { compose } from './common/compose.ts';\nimport {\n    ExtendedHttpIncomingMessage,\n    ExtendedHttpServerResponse,\n    HttpServerRequest,\n    HttpServerResponse\n} from './server/exchange.ts';\nimport getLogger from './logger.ts';\nimport { addressAndPort, localIp, portRange } from './server/address.ts';\nimport * as monitoring from './server/monitoring.ts';\nimport type { ServerConfig } from '../types/config.d.ts';\nimport { GatewayServer } from '@interopio/gateway-server';\nimport serverHeader from './server/server-header.ts';\nimport { configure, type RouteConfig } from './app/route.ts';\nimport { httpSecurity } from './app/auth.ts';\nimport type { ServerConfigurer, ServerHttpResponse, ServerWebExchange } from '../types/web/server.d.ts';\nimport { HttpHeadResponseDecorator } from './server/handler.ts';\nimport { initRoute } from './server/ws.ts';\nimport { type SocketRoute, webSockets } from './server/socket.ts';\nimport { HttpStatus } from './http/status.ts';\nimport { secureContextOptions } from './server/ssl/config.ts';\nimport codecConfig from './http/codec/config.ts';\nimport { gatewayManagementServer } from './manage/server.ts';\n\nconst logger = getLogger('app');\n\ntype RequestListener<\n    Request extends typeof ExtendedHttpIncomingMessage = typeof ExtendedHttpIncomingMessage,\n    Response extends typeof ExtendedHttpServerResponse<InstanceType<Request>> = typeof ExtendedHttpServerResponse,\n> = (req: InstanceType<Request>, resOrUpgradeHead: (InstanceType<Response> & { req: InstanceType<Request> }) | Buffer<ArrayBufferLike>) => void;\n\ntype ServerOptions = http.ServerOptions<typeof ExtendedHttpIncomingMessage, typeof ExtendedHttpServerResponse>;\n\nasync function createListener(builder: WebHttpHandlerBuilder,\n                              onSocketError: (err: Error) => void): Promise<RequestListener> {\n\n    const httpHandler = builder.build();\n\n    return async (req: ExtendedHttpIncomingMessage, resOrUpgradeHead: ExtendedHttpServerResponse | Buffer<ArrayBufferLike>) => {\n        req.socket.addListener('error', onSocketError);\n        let res: ExtendedHttpServerResponse;\n        if (resOrUpgradeHead instanceof ExtendedHttpServerResponse) {\n            res = resOrUpgradeHead;\n        }\n        else {\n            req.upgradeHead = resOrUpgradeHead;\n            res = new ExtendedHttpServerResponse(req);\n            res.assignSocket(req.socket);\n        }\n        try {\n            const request = new HttpServerRequest(req);\n            const response = new HttpServerResponse(res);\n            const decoratedResponse: ServerHttpResponse = request.method === 'HEAD' ? new HttpHeadResponseDecorator(response) : response;\n            const hp: Promise<void> = httpHandler(request, decoratedResponse)\n            try {\n                await hp;\n                if (logger.enabledFor('trace')) {\n                    logger.debug(`${request.id} handling completed.`);\n                }\n            }\n            catch (e) {\n                if (e instanceof Error && e['code'] === 'ERR_INVALID_URL') {\n                    throw e; // Let the outer catch handle this and return 400 Bad Request\n                }\n                if (logger.enabledFor('trace')) {\n                    logger.debug(`${request.id} failed to complete: ${e instanceof Error ? e.message : e}`);\n                }\n            }\n        }\n        catch (e) {\n            if (e instanceof Error && e['code'] === 'ERR_INVALID_URL') {\n                if (logger.enabledFor('debug')) {\n                    logger.debug(`failed to get request URI: ${e.message}`);\n                }\n                res.statusCode = 400; // Bad Request\n                res.end(http.STATUS_CODES[400]);\n                return Promise.resolve();\n            }\n            throw e;\n        }\n    };\n}\n\nfunction promisify<T>(fn: (callback?: (err?: Error) => void) => T): Promise<T> {\n    return new Promise<T>((resolve, reject) => {\n        const r = fn((err?: Error) => {\n            if (err) {\n                reject(err);\n            } else {\n                resolve(r);\n            }\n        });\n    });\n}\n\nfunction memoryMonitor(config?: ServerConfig['memory']) {\n    if (config) {\n        return monitoring.start({\n            memoryLimit: config.memory_limit,\n            dumpLocation: config.dump_location,\n            dumpPrefix: config.dump_prefix,\n            reportInterval: config.report_interval,\n            maxBackups: config.max_backups\n        });\n    }\n}\n\nimport info from '@interopio/gateway-server/package.json' with { type: 'json' };\nimport welcomePage from './server/welcome-page.ts';\nimport { WebHttpHandlerBuilder } from './web/server/adapter.ts';\nimport { DefaultErrorAttributes, DefaultWebErrorHandler } from './server/error.ts';\nimport { WebFilterChainProxy } from './server/security/web.ts';\nimport { ResponseStatusError } from './web/server/error.ts';\nimport { DispatcherHandler } from './web/async/handler.ts';\nimport {\n    HandlerFunctionAdapter,\n    RouterFunctionMapping,\n    ServerResponseResultHandler\n} from './web/async/fn/server/handler.ts';\nexport const VERSION = `${info.name} - v${info.version}`;\n\nasync function initBuilder(context: RouteConfig) {\n    const storage = context.storage;\n    const security = await httpSecurity(context);\n    // websocket upgrade handler\n    const sockets = webSockets(context);\n    const codecConfigurer = codecConfig.serverConfigurer.create();\n    codecConfigurer.defaultCodecs.enableLoggingRequestDetails(true);\n    const welcomePageRouterFunctionMapping = new RouterFunctionMapping();\n    // welcomePageRouterFunctionMapping.init(await welcomePage(context.resourcesConfig?.locations));\n    const h = new DispatcherHandler(\n        [welcomePageRouterFunctionMapping],\n        [new HandlerFunctionAdapter()],\n        [new ServerResponseResultHandler(codecConfigurer.writers)]\n    )\n    const handler = {\n        handle: compose<ServerWebExchange>(\n            serverHeader(VERSION, context.serverHeader),\n            ...sockets,\n            ...context.middleware,\n            // health check\n            async ({ request, response }, next) => {\n                if (request.method === 'GET' && request.path === '/health') {\n                    response.setStatusCode(HttpStatus.OK);\n                    const buffer = Buffer.from('UP', 'utf-8');\n                    response.headers.set('Content-Type', 'text/plain; charset=utf-8');\n                    await response.body(buffer);\n                }\n                else {\n                    await next();\n                }\n            },\n            await welcomePage(context.resourcesConfig?.locations),\n            // not found\n            async ({ response }, _next) => {\n                throw new ResponseStatusError(HttpStatus.NOT_FOUND);\n                // response.setStatusCode(HttpStatus.NOT_FOUND);\n                // await response.end();\n            }\n        )\n    };\n\n    return new WebHttpHandlerBuilder(handler)\n        .filter(new WebFilterChainProxy(security))\n        .codecConfigurer(codecConfigurer)\n        .exceptionHandler(\n            new DefaultWebErrorHandler(\n                codecConfigurer.readers,\n                codecConfigurer.writers,\n                new DefaultErrorAttributes()))\n        .storage(storage);\n}\n\nexport const Factory = async (options: ServerConfig): Promise<GatewayServer.Server> => {\n    const ssl = options.ssl;\n    const host = options.host;\n\n    // Build serverCertificate config if auth.x509.key is provided\n    const serverCertificate = options.auth?.x509?.key ? {\n        host: host ?? 'localhost',\n        key: options.auth.x509.key,\n        passphrase: options.auth.x509.passphrase\n    } : undefined;\n\n    const createServer = ssl\n        ? (options: ServerOptions, handler: RequestListener) => https.createServer({...options, ...secureContextOptions(ssl, serverCertificate)}, handler)\n        : (options: ServerOptions, handler: RequestListener) => http.createServer(options, handler);\n    const monitor = memoryMonitor(options.memory);\n    const context: RouteConfig = {\n        middleware: [],\n        corsConfig: options.cors,\n        cors: [],\n        authConfig: options.auth,\n        authorize: [],\n        storage: new AsyncLocalStorage<{ exchange: ServerWebExchange }>(),\n        sockets: new Map<string, SocketRoute>(),\n        resourcesConfig: options.resources,\n    };\n\n    // Create gateway manager to handle default and per-principal gateway instances\n    const gatewayManager = new GatewayManager({\n        baseConfig: { ...(options.gateway) },\n        scope: options.gateway?.scope ?? 'principal'\n    });\n\n    if (options.gateway) {\n        const path = options.gateway.route ? (options.gateway.route === '/' ? undefined : options.gateway.route) : undefined;\n\n        await configure(async (configurer: ServerConfigurer) => {\n            configurer.socket({ path, factory: wsGateway.bind(gatewayManager), options: options.gateway })\n        }, options, context);\n\n    }\n    if (options.app) {\n        await configure(options.app, options, context)\n    }\n\n    const ports = portRange(options.port ?? 0);\n    const onSocketError = (err: Error) => logger.error(`socket error: ${err}`, err);\n    const builder = await initBuilder(context);\n\n    const listener = await createListener(builder, onSocketError);\n\n    const serverP = new Promise<http.Server<typeof ExtendedHttpIncomingMessage, typeof ExtendedHttpServerResponse>>((resolve, reject) => {\n\n        const server = createServer({\n            IncomingMessage: ExtendedHttpIncomingMessage,\n            ServerResponse: ExtendedHttpServerResponse,\n            ...options.http\n        }, listener);\n\n        server.on('error', (e: Error) => {\n            if (e['code'] === 'EADDRINUSE') {\n                logger.debug(`port ${e['port']} already in use on address ${e['address']}`);\n                const {value: port} = ports.next();\n                if (port) {\n                    logger.info(`retry starting server on port ${port} and host ${host ?? '<unspecified>'}`);\n                    server.close();\n                    server.listen(port, host);\n                } else {\n                    logger.warn(`all configured port(s) ${options.port} are in use. closing...`);\n                    server.close();\n                    reject(e);\n                }\n            } else {\n                logger.error(`server error: ${e.message}`, e);\n                reject(e);\n            }\n        });\n        server\n            .on('listening', async () => {\n                const info = server.address() as AddressInfo;\n\n                for (const [path, route] of context.sockets) {\n                    const endpoint = `${ssl ? 'wss' : 'ws'}://${localIp}:${info.port}${path}`;\n                    await initRoute(path, route, endpoint, context.storage, onSocketError);\n                }\n                logger.info(`http server listening on ${ ssl ? 'https' : 'http' }://${addressAndPort(info)}`);\n                resolve(server);\n            });\n        server\n            .on('upgrade', (req: ExtendedHttpIncomingMessage, _socket: Socket, head: Buffer<ArrayBufferLike>) => {\n                try {\n                    listener(req, head);\n                } catch (err) {\n                    logger.error(`upgrade error: ${err}`, err);\n                }\n            })\n            .on('close', async () => {\n                logger.info(`http server closed.`);\n            });\n        try {\n            const {value: port} = ports.next();\n            server.listen(port, host);\n        } catch (e) {\n            logger.error(`error starting web socket server`, e);\n            reject(e instanceof Error ? e : new Error(`listen failed: ${e}`));\n        }\n    });\n    const server = await serverP;\n    const closeActions = new Array<() => Promise<void>>();\n    const closeSockets = async () => {\n        for (const [path, route] of context.sockets) {\n            try {\n                if (route.close !== undefined) {\n                    await route.close();\n                }\n            } catch (e) {\n                logger.warn(`error closing route ${path}`, e);\n            }\n        }\n    };\n    const closeServer = async () => {\n        await promisify(cb => {\n            server.closeAllConnections();\n            server.close(cb);\n        });\n    };\n    closeActions.push(closeSockets);\n    closeActions.push(closeServer);\n\n    closeActions.push(async () => {\n        if (monitor) {\n            await monitoring.stop(monitor);\n        }\n    });\n    closeActions.push(async () => {\n        // Stop all gateways (default + per-principal)\n        await gatewayManager.stop();\n    });\n    const fullServer = new class implements GatewayServer.Server {\n        // Expose the gateway manager which implements ScopedGateway\n        readonly gateway = gatewayManager;\n\n        get address(): AddressInfo | null {\n            const address = server.address();\n            return typeof address === 'object' ? address : null;\n        }\n\n        async close(): Promise<void> {\n            const errors = new Array<unknown>();\n            for (const action of closeActions) {\n                try {\n                    await action();\n                }\n                catch (e) {\n                    errors.push(e);\n                    logger.warn(`error during server shutdown`, e);\n                }\n            }\n            if (errors.length === 1) {\n                throw errors[0];\n            }\n            else if (errors.length > 1) {\n                throw new AggregateError(errors, 'multiple errors during server shutdown');\n            }\n        }\n    }\n\n    if (options.management?.server.path) {\n        const managementServer =\n            await gatewayManagementServer({\n                options: options.management.server,\n                info: async () => ({\n                    pid: process.pid,\n                    type: 'gateway-server',\n                    ...(gatewayManager.info())\n                }),\n                logger: logger.child('management'),\n                shutdown: options.management.commands?.['shutdown'].enabled ? async () => {\n                    if (logger.enabledFor('info')) {\n                        logger.info(`stopping gateway-server...`);\n                    }\n                    await fullServer.close();\n                } : undefined\n            });\n        closeActions.push(async () => {\n            await promisify((cb) => {\n                managementServer.close(cb);\n            });\n        });\n    }\n\n    return fullServer;\n}\n", "import type { AddressInfo } from 'node:net';\nimport { type NetworkInterfaceInfo, networkInterfaces } from 'node:os';\n\nconst PORT_RANGE_MATCHER = /^(\\d+|(0x[\\da-f]+))(-(\\d+|(0x[\\da-f]+)))?$/i;\nfunction validPort(port: number) {\n    if (port > 0xFFFF) throw new Error(`bad port ${port}`);\n    return port;\n}\n\n/**\n * parse port range. port can be number or string representing comma separated\n *   list of port ranges for e.g. \"3434,8380-8385\"\n * @param port\n */\nexport function* portRange(port: number | string): Generator<number> {\n    if (typeof port === 'string') {\n        for (const portRange of port.split(',')) {\n            const trimmed = portRange.trim();\n            const matchResult = PORT_RANGE_MATCHER.exec(trimmed);\n            if (matchResult) {\n                const start = parseInt(matchResult[1]);\n                const end = parseInt(matchResult[4] ?? matchResult[1]);\n                for (let i = validPort(start); i < validPort(end) + 1; i++) {\n                    yield i;\n                }\n            }\n            else {\n                throw new Error(`'${portRange}' is not a valid port or range.`);\n            }\n        }\n    } else {\n        yield validPort(port);\n    }\n}\n\nexport const localIp = (() => {\n    function first<T>(a: T[]): T | undefined {\n        return a.length > 0 ? a[0] : undefined;\n    }\n    const addresses = Object.values(networkInterfaces())\n        .flatMap((details?: NetworkInterfaceInfo[]) => {\n            return (details ?? []).filter((info) => info.family === 'IPv4');\n        }).reduce((acc, info) => {\n            acc[info.internal ? 'internal' : 'external'].push(info);\n            return acc;\n        }, {internal: [] as NetworkInterfaceInfo[], external: [] as NetworkInterfaceInfo[]});\n    return (first(addresses.internal) ??  first(addresses.external))?.address;\n})();\n\nexport function addressAndPort(address?: AddressInfo) {\n    if (address) {\n        if (address.family === 'IPv6') {\n            return `[${address.address}]:${address.port}`;\n        }\n        return `${address.address}:${address.port}`;\n    }\n}\n", "import * as GatewayLogging from '@interopio/gateway/logging/core';\n\nexport type Logger = GatewayLogging.Logger;\n\nexport default function getLogger(name: string): Logger {\n    return GatewayLogging.getLogger(`gateway.server.${name}`);\n}\n\n// This function is used to ensure that RegExp objects are displayed correctly when logging.\nexport function regexAwareReplacer<T>(_key: string, value: T): string | T {\n    return value instanceof RegExp ? value.toString() : value;\n}\n", "import { addressAndPort } from '../../server/address.ts';\nimport type { WebSocket } from 'ws';\nimport getLogger from '../../logger.ts';\nimport type { Authentication } from '../../server/security/types.ts';\nimport { IOGateway } from '@interopio/gateway';\nimport { GatewayManager } from '../gateway-manager.ts';\n\nimport type {ServerWebSocketHandler} from '../../../types/web/server';\nimport type {AddressInfo} from 'node:net';\nimport {AsyncLocalStorage} from 'node:async_hooks';\n\nconst log = getLogger('ws');\nconst codec = IOGateway.Encoding.json<IOGateway.Message>();\n\nfunction principalName(authentication: Authentication): string | undefined {\n    let name: string | undefined;\n    if (authentication.authenticated) {\n        name = authentication.name;\n        if (name === undefined) {\n            if (authentication['principal'] !== undefined) {\n                const principal = authentication['principal'];\n                if (typeof principal === 'object' && principal !== null && ('username' in principal || 'name' in principal)) {\n                    name = (principal as { username?: string }).username ?? (principal as { name?: string }).name;\n                }\n                if (name === undefined) {\n                    if (principal === undefined || principal === null) {\n                        name = '';\n                    }\n                    else {\n                        name = String(principal);\n                    }\n                }\n            }\n        }\n    }\n    return name;\n}\n\nfunction initClient(gateway: IOGateway.Gateway,\n                    socket: WebSocket,\n                    authenticationPromise: () => Promise<Authentication | undefined>,\n                    remoteAddress?: AddressInfo\n): IOGateway.GatewayClient<string> | undefined {\n    const key = addressAndPort(remoteAddress);\n    const host = remoteAddress?.address ?? '<unknown>';\n    const opts = {\n        key,\n        host,\n        codec,\n        onAuthenticate: async (): Promise<IOGateway.Auth.AuthenticationSuccess> => {\n            const authentication = (await authenticationPromise());\n            if (authentication?.authenticated) {\n                return {type: 'success', user: principalName(authentication)};\n            }\n            throw new Error(`no valid client authentication ${key}`);\n        },\n        onPing: () => {\n            socket.ping((err?: Error) => {\n                if (err) {\n                    log.warn(`failed to ping ${key}`, err);\n                }\n                else {\n                    log.info(`ping sent to ${key}`);\n                }\n            });\n        },\n        onDisconnect: (reason: 'inactive' | 'shutdown') => {\n            switch (reason) {\n                case 'inactive': {\n                    log.warn(`no heartbeat (ping) received from ${key}, closing socket`);\n                    socket.close(4001, 'ping expected');\n                    break;\n                }\n                case 'shutdown': {\n                    socket.close(1001, 'shutdown');\n                    break;\n                }\n            }\n        }\n    };\n    try {\n        return gateway.client((data) => socket.send(data), opts as IOGateway.GatewayClientOptions<string>);\n    } catch (err) {\n        log.warn(`${key} failed to create client`, err);\n    }\n}\n\nasync function create(this: GatewayManager, environment: {\n    endpoint: string,\n    storage?: AsyncLocalStorage<{ }>\n}): Promise<ServerWebSocketHandler> {\n    log.info(`starting gateway on ${environment.endpoint}`);\n    await this.start(environment);\n\n\n    return async ({socket, handshake}) => {\n        const { logPrefix, remoteAddress, principal: principalPromise } = handshake;\n        const user = (await principalPromise())?.name;\n        log.info(`${logPrefix}connected on gw as ${user ?? '<anonymous>'}`);\n\n        const gw = await this.getGateway(user);\n        const client = initClient(gw, socket, principalPromise, remoteAddress);\n        if (!client) {\n            log.error(`${logPrefix}gw client init failed`);\n            socket.terminate();\n            return;\n        }\n        socket.on('error', (err: Error) => {\n            log.error(`${logPrefix}websocket error: ${err}`, err);\n        });\n\n        const contextFn = environment.storage !== undefined ? AsyncLocalStorage.snapshot() : undefined;\n        socket.on('message', (data, _isBinary) => {\n            if (Array.isArray(data)) {\n                data = Buffer.concat(data);\n            }\n            // JSON.parse will invoke abstract operation ToString (coerce it) prior parsing (https://262.ecma-international.org/5.1/#sec-15.12.2)\n            if (contextFn !== undefined) {\n                contextFn(() => client.send(data as unknown as string))\n            }\n            else {\n                client.send(data as unknown as string);\n            }\n\n        });\n        socket.on('close', (code) => {\n            log.info(`${logPrefix}disconnected from gw. code: ${code}`);\n            client.close();\n        });\n    }\n}\n\nexport default create;\n", "import { IOGateway } from '@interopio/gateway';\nimport getLogger from '../logger.ts';\nimport type { GatewayServer  } from '../../gateway-server.ts';\nimport { processGatewayConfig } from './config.ts';\n\nconst log = getLogger('gateway-manager');\n\nfunction generateRandomGatewayId(): string {\n    return globalThis.crypto.randomUUID().replaceAll('-', '');\n}\n\n\nexport interface GatewayManagerConfig {\n    /**\n     * Base gateway configuration to use for all gateway instances.\n     */\n    baseConfig: IOGateway.GatewayConfig & {\n        metrics?: IOGateway.MetricsConfig & { enabled?: boolean },\n        mesh?: IOGateway.MeshConfig & { enabled?: boolean }\n    };\n\n    /**\n     * Gateway scope - determines how gateway instances are managed:\n     * - 'principal': Each authenticated principal gets their own gateway instance.\n     *                A default (shared) gateway instance handles all unauthenticated connections.\n     * - 'singleton': All connections share the same gateway instance\n     *\n     * Default: 'principal'\n     */\n    scope?: 'singleton' | 'principal';\n}\n\n/**\n * Manages multiple Gateway instances - one default and optionally one per authenticated principal.\n * Each gateway instance gets a unique node ID to ensure proper isolation.\n */\nexport class GatewayManager implements GatewayServer.ScopedGateway {\n    readonly #defaultGatewayId: string;\n    readonly #defaultGateway: IOGateway.Gateway;\n    readonly #managedGateways = new Map<string, IOGateway.Gateway>();\n    readonly #principalToGatewayId = new Map<string, string>();\n    readonly #config: GatewayManagerConfig;\n    #started = false;\n    #environment?: { endpoint?: string };\n\n    constructor(config: GatewayManagerConfig) {\n        this.#config = {\n            baseConfig: processGatewayConfig(config.baseConfig),\n            scope: config.scope ?? 'principal'\n        }\n\n        // Use configured gateway ID or generate a random one for the default gateway\n        this.#defaultGatewayId = config.baseConfig.node ?? generateRandomGatewayId();\n\n        if (log.enabledFor('debug')) {\n            log.debug(`creating default gateway with gateway id: ${this.#defaultGatewayId}`);\n        }\n\n        this.#defaultGateway = IOGateway.Factory({...this.#config.baseConfig, node: this.#defaultGatewayId});\n    }\n\n    /**\n     * Starts the default gateway.\n     */\n    async start(environment?: { endpoint?: string }): Promise<this> {\n        if (this.#started) {\n            return this;\n        }\n\n        // Store environment for use with per-principal gateways\n        this.#environment = environment;\n\n        log.debug('starting default gateway');\n        await this.#defaultGateway.start(environment);\n        this.#started = true;\n        return this;\n    }\n\n    /**\n     * Gets a gateway instance for the given principal.\n     * If scope is 'singleton' or no principal is provided, returns the default gateway.\n     * Otherwise, creates a new gateway instance for the principal if it doesn't exist.\n     */\n    async getGateway(principal?: string): Promise<IOGateway.Gateway> {\n        // If scope is singleton or no principal, use default\n        if (this.#config.scope === 'singleton' || !principal) {\n            return this.#defaultGateway;\n        }\n\n        // Check if we already have a gateway for this principal\n        const gatewayId = this.#principalToGatewayId.get(principal);\n        let gateway = gatewayId ? this.#managedGateways.get(gatewayId) : undefined;\n\n        if (!gateway) {\n            if (log.enabledFor('debug')) {\n                log.debug(`no existing gateway for principal '${principal}', creating new one`);\n            }\n            gateway = await this.#createPrincipalGateway(principal);\n        } else {\n            if (log.enabledFor('debug')) {\n                log.debug(`reusing existing gateway for principal '${principal}'`);\n            }\n        }\n\n        return gateway;\n    }\n\n    /**\n     * Creates a new gateway instance for a specific principal with a unique gateway ID.\n     */\n    async #createPrincipalGateway(principal: string): Promise<IOGateway.Gateway> {\n        const gatewayId = generateRandomGatewayId();\n        const config = {\n            ...this.#config.baseConfig,\n            node: gatewayId\n         };\n\n        if (log.enabledFor('debug')) {\n            log.debug(`creating gateway for principal '${principal}' with gateway id: ${config.node}`);\n        }\n        const gateway = IOGateway.Factory(config);\n\n        // Track the principal-to-gateway ID mapping\n        this.#principalToGatewayId.set(principal, gatewayId);\n        this.#managedGateways.set(gatewayId, gateway);\n\n        // Start the gateway with the same environment as the default gateway\n        await gateway.start(this.#environment);\n\n        return gateway;\n    }\n\n    // ScopedGateway interface methods\n\n    /**\n     * Get all gateway instances including the default.\n     */\n    getGateways(): Map<string, IOGateway.Gateway> {\n        const allGateways = new Map<string, IOGateway.Gateway>(this.#managedGateways);\n        allGateways.set(this.#defaultGatewayId, this.#defaultGateway);\n        return allGateways;\n    }\n\n    /**\n     * Gets information about specific or all active gateways.\n     * - If no gatewayId is provided: returns aggregated info for all gateways (default + managed).\n     * - If default gateway ID is provided: returns info only for the default gateway.\n     * - If a non-default gateway ID is provided: returns info only for that specific gateway. If not found, throws an error.\n     */\n    info(gatewayId?: string): Record<string, unknown> {\n        // Case 1: Specific non-default gateway ID provided\n        if (gatewayId && this.#defaultGatewayId !== gatewayId) {\n            const gateway = this.#managedGateways.get(gatewayId);\n            if (gateway) {\n                return gateway.info();\n            } else {\n                throw new Error(`no gateway found with ID: ${gatewayId}`);\n            }\n        }\n\n        // Case 2: Default gateway ID explicitly provided - return only default info\n        if (gatewayId === this.#defaultGatewayId) {\n            return this.#defaultGateway.info();\n        }\n\n        // Case 3: No gateway ID provided - return aggregated info\n        return {\n            ...this.#defaultGateway.info(),\n            managedGateways: this.#managedGateways.size,\n            scope: this.#config.scope\n        };\n    }\n\n    /**\n     * Stops specific or all gateway instances.\n     * - If no gatewayId is provided: stops all gateways (default + managed), returning the stopped default.\n     * - If default gateway ID is provided: stops only the default gateway, leaving managed gateways running.\n     * - If a non-default gateway ID is provided: stops only that specific gateway. If not found, throws an error.\n     * @param gatewayId - ID of the gateway to stop.\n     * @returns stopped gateway instance.\n     */\n    async stop(gatewayId?: string): Promise<IOGateway.Gateway> {\n        // Case 1: Specific non-default gateway ID provided\n        if (gatewayId && this.#defaultGatewayId !== gatewayId) {\n            const gateway = this.#managedGateways.get(gatewayId);\n            if (gateway) {\n                log.info(`stopping gateway with ID: ${gatewayId}`);\n                await gateway.stop();\n                this.#managedGateways.delete(gatewayId);\n\n                // Remove principal mapping for this gateway\n                for (const [principal, gId] of this.#principalToGatewayId.entries()) {\n                    if (gId === gatewayId) {\n                        this.#principalToGatewayId.delete(principal);\n                        break;\n                    }\n                }\n\n                return gateway;\n            } else {\n                throw new Error(`no gateway found with ID: ${gatewayId}`);\n            }\n        }\n\n        // Case 2: Default gateway ID explicitly provided - stop only default\n        if (gatewayId === this.#defaultGatewayId) {\n            log.debug('stopping default gateway (managed gateways will continue running)');\n            await this.#defaultGateway.stop();\n            this.#started = false;\n            return this.#defaultGateway;\n        }\n\n        // Case 3: No gateway ID provided - stop all gateways\n        log.info(`stopping all gateways (1 default + ${this.#managedGateways.size} managed)`);\n\n        // Stop all managed gateways\n        for (const [id, gateway] of this.#managedGateways.entries()) {\n            if (log.enabledFor('debug')) {\n                log.debug(`stopping gateway with ID: ${id}`);\n            }\n            await gateway.stop();\n        }\n        this.#managedGateways.clear();\n        this.#principalToGatewayId.clear();\n\n        log.debug('stopping default gateway');\n        await this.#defaultGateway.stop();\n        this.#started = false;\n        return this.#defaultGateway;\n    }\n\n\n    /**\n     * Get the gateway ID for a specific principal.\n     */\n    getPrincipalGatewayId(principal: string): string | undefined {\n        return this.#principalToGatewayId.get(principal);\n    }\n\n    /**\n     * Get all principal-to-gateway ID mappings.\n     */\n    getPrincipalGatewayIds(): Map<string, string> {\n        return new Map(this.#principalToGatewayId);\n    }\n\n\n    // Gateway interface delegation to defaultGateway\n\n    /**\n     * Get the default gateway instance.\n     */\n    getDefaultGateway(): IOGateway.Gateway {\n        return this.#defaultGateway;\n    }\n\n    /**\n     * Create a gateway client with the specified handler.\n     * Delegates to the default gateway.\n     */\n    client<T = IOGateway.Message>(\n        handler: (this: IOGateway.GatewayClient<T>, msg: T) => void,\n        opts?: IOGateway.GatewayClientOptions<T>\n    ): IOGateway.GatewayClient<T> {\n        return this.#defaultGateway.client(handler, opts);\n    }\n\n    /**\n     * Connect to the gateway with the specified handler.\n     * Delegates to the default gateway.\n     * @deprecated\n     */\n    async connect(\n        handler: (client: IOGateway.GatewayClient, msg: IOGateway.Message) => void\n    ): Promise<IOGateway.GatewayClient> {\n        return this.#defaultGateway.connect(handler);\n    }\n\n    /**\n     * Gets the number of active principal gateways.\n     */\n    getPrincipalCount(): number {\n        return this.#managedGateways.size;\n    }\n}\n", "import { IOGateway } from '@interopio/gateway';\n\n/**\n * Processes visibility rules by converting string matchers to RegExp where appropriate.\n */\nexport function processVisibilityRules<K extends string>(rules?: IOGateway.VisibilityRule<K>[]) {\n    if (rules !== undefined) {\n        return rules.map(rule => {\n            const result = {...rule} as IOGateway.VisibilityRule<K>;\n\n            // Process all keys in the rule that might be matchers (context, method, domain, etc.)\n            // Exclude known non-matcher properties: identity and restrictions\n            for (const [key, value] of Object.entries(rule)) {\n                if (key !== 'identity' && key !== 'restrictions' && value !== undefined) {\n                    // Value should be a Matcher type (string, RegExp, or array)\n                    (result as Record<K, IOGateway.Filtering.Matcher>)[key] = IOGateway.Filtering.regexify(value as IOGateway.Filtering.Matcher);\n                }\n            }\n\n            // Process identity matchers separately\n            if (rule.identity !== undefined) {\n                result.identity = {};\n                for (const [key, value] of Object.entries(rule.identity)) {\n                    result.identity[key] = IOGateway.Filtering.regexify(value);\n                }\n            }\n\n            return result;\n        });\n    }\n}\n\n/**\n * Processes metric filters by converting matchers to RegExp and merging deprecated properties.\n */\nexport function processMetricFilters(filters?: IOGateway.MetricFilters): IOGateway.MetricFilters | undefined {\n    if (!filters) {\n        return undefined;\n    }\n\n    const result = {...filters};\n\n    if (filters.publishers) {\n        result.publishers = filters.publishers.map(publisher => {\n            const { metrics: originalMetrics, identity: originalIdentity, ...rest } = publisher;\n\n            // Build result object with proper typing\n            type ProcessedPublisher = Omit<typeof publisher, 'metrics' | 'identity'> & {\n                identity: Record<string, IOGateway.Filtering.Matcher>;\n                metrics: {\n                    allow?: IOGateway.Filtering.Matcher[];\n                    block?: IOGateway.Filtering.Matcher[];\n                };\n            };\n\n            const processedPublisher = { ...rest } as ProcessedPublisher;\n\n            // Process identity matchers (always set, even if empty)\n            processedPublisher.identity = {};\n            if (originalIdentity) {\n                for (const [key, value] of Object.entries(originalIdentity)) {\n                    processedPublisher.identity[key] = IOGateway.Filtering.regexify(value);\n                }\n            }\n\n            // Process metrics matchers (allow, block, whitelist, blacklist)\n            // Note: whitelist/blacklist are deprecated, merge them with allow/block\n            processedPublisher.metrics = {};\n            if (originalMetrics) {\n                const allow = (originalMetrics.allow ?? originalMetrics.whitelist ?? []).map(m => IOGateway.Filtering.regexify(m));\n                const block = (originalMetrics.block ?? originalMetrics.blacklist ?? []).map(m => IOGateway.Filtering.regexify(m));\n\n                // Only include non-empty arrays to avoid meaningless empty filters\n                if (allow.length > 0) {\n                    processedPublisher.metrics.allow = allow;\n                }\n                if (block.length > 0) {\n                    processedPublisher.metrics.block = block;\n                }\n            }\n\n            return processedPublisher as typeof publisher;\n        });\n    }\n\n    return result;\n}\n\n/**\n * Processes publisher configuration by processing its filters.\n */\nexport function processPublisherConfig<T extends IOGateway.BasicMetricsPublisherConfig>(publisherConfig?: T): T | undefined {\n    if (!publisherConfig) {\n        return undefined;\n    }\n\n    const result = {...publisherConfig};\n\n    if (publisherConfig.filters) {\n        result.filters = processMetricFilters(publisherConfig.filters);\n    }\n\n    return result;\n}\n\n/**\n * Processes mesh configuration, returning undefined if disabled.\n */\nexport function processMeshConfig(meshConfig?: IOGateway.MeshConfig & { enabled?: boolean }): IOGateway.MeshConfig | undefined {\n    if (meshConfig?.enabled === false) {\n        return undefined;\n    }\n    return meshConfig;\n}\n\n/**\n * Processes metrics configuration by handling filters and publisher configs.\n */\nexport function processMetricsConfig(config?: IOGateway.MetricsConfig & { enabled?: boolean }): IOGateway.MetricsConfig | undefined {\n    if (config === undefined || config?.enabled === false) {\n        return undefined;\n    }\n    const result = { ...(config) };\n\n    // Process top-level filters\n    if (config.filters) {\n        result.filters = processMetricFilters(config.filters);\n    }\n\n    // Process file publisher config\n    if (config.file) {\n        result.file = processPublisherConfig(config.file);\n    }\n\n    // Process rest publisher config\n    if (config.rest) {\n        result.rest = processPublisherConfig(config.rest);\n    }\n\n    // Process publishers array (which can contain custom publishers with filters)\n    if (config.publishers) {\n        result.publishers = config.publishers.map(publisher => {\n            if (typeof publisher === 'string') {\n                return [publisher];\n            }\n            // It's a CustomMetricsPublisherConfig\n            const c = processPublisherConfig(publisher);\n            if (c !== undefined) {\n                return [c];\n            }\n            return [];\n        }).flat();\n    }\n\n    return result;\n}\n\n/**\n * Processes gateway configuration by converting string matchers to RegExp and handling special flags.\n * This ensures that configurations loaded from JSON files work correctly.\n */\nexport function processGatewayConfig(config: IOGateway.GatewayConfig & {\n    metrics?: IOGateway.MetricsConfig & { enabled?: boolean },\n    mesh?: IOGateway.MeshConfig & { enabled?: boolean }\n}): IOGateway.GatewayConfig {\n    // regexify in case config is coming from JSON config file\n    const result = {...config};\n\n    if (config.contexts) {\n        result.contexts = {\n            ...config.contexts,\n            visibility: processVisibilityRules(config.contexts.visibility)\n        };\n    }\n\n    if (config.methods) {\n        result.methods = {\n            ...config.methods,\n            visibility: processVisibilityRules(config.methods.visibility)\n        };\n    }\n\n    if (config.peers) {\n        result.peers = {\n            ...config.peers,\n            visibility: processVisibilityRules(config.peers.visibility)\n        };\n    }\n\n    if (config.metrics) {\n        result.metrics = processMetricsConfig(config.metrics);\n    }\n\n    if (config.mesh) {\n        result.mesh = processMeshConfig(config.mesh);\n    }\n\n    return result;\n}\n", "type MiddlewareFunction<T> = ((ctx: T, next: (ctx?: T) => Promise<void>) => Promise<void>) | ((ctx: T) => Promise<void>);\n\n// https://github.com/koajs/compose/blob/master/index.js\n/**\n * @typeParam T - Type of context passed through the middleware\n * @param middleware middleware stack\n * @return {MiddlewareFunction}\n */\nexport function compose<T>(...middleware: MiddlewareFunction<T>[]): (ctx: T) => Promise<void> {\n    if (!Array.isArray(middleware)) {\n        throw new Error('middleware must be array!');\n    }\n    const fns = middleware.flat();\n    for (const fn of fns) {\n        if (typeof fn !== 'function') {\n            throw new Error('middleware must be compose of functions!');\n        }\n    }\n    return async function (ctx: T, next?: (ctx?: T) => Promise<void>) {\n        const dispatch = async (i: number, dispatchedCtx: T): Promise<void> => {\n            const fn = i === fns.length ? next : fns[i];\n            if (fn === undefined) {\n                return;\n            }\n            let nextCalled = false;\n            let nextResolved = false;\n            const nextFn = async (nextCtx?: T) => {\n                if (nextCalled) {\n                    throw new Error('next() called multiple times');\n                }\n                nextCalled = true;\n                try {\n                    return await dispatch(i + 1, nextCtx ?? dispatchedCtx);\n                }\n                finally {\n                    nextResolved = true;\n                }\n            };\n            const result = await fn(dispatchedCtx, nextFn);\n            if (nextCalled && !nextResolved) {\n                throw new Error('middleware resolved before downstream.\\n\\t You are probably missing an await or return statement in your middleware function.');\n            }\n            return result;\n        }\n\n        return dispatch(0, ctx);\n    }\n}\n", "import type { HttpCookie, HttpHeaders, ResponseCookie } from '../../types/web/http';\nimport { type AddressInfo, isIP } from 'node:net';\nimport { Cookie } from 'tough-cookie';\n\nfunction parseHost(headers: HttpHeaders, defaultHost?: string): string | undefined {\n    let host = headers.get('x-forwarded-host');\n    if (Array.isArray(host)) {\n        host = host[0];\n    }\n    if (host) {\n        const port = headers.one('x-forwarded-port');\n        if (port) {\n            host = `${host}:${port}`;\n        }\n    }\n    host ??= headers.one('host');\n    if (Array.isArray(host)) {\n        host = host[0];\n    }\n    if (host) {\n        return (host as string).split(',', 1)[0].trim();\n    }\n\n    return defaultHost;\n}\n\nfunction isForwardedSsl(headers: HttpHeaders): boolean {\n    const v = headers.one('x-forwarded-ssl');\n    return (typeof v === 'string') && (v.toLowerCase() === 'on');\n}\n\nfunction parseProtocol(headers: HttpHeaders, defaultProtocol: string): string {\n    let proto = headers.get('x-forwarded-proto');\n\n    if (Array.isArray(proto)) {\n        proto = proto[0];\n    }\n    if (proto !== undefined) {\n        return (proto as string).split(',', 1)[0].trim();\n    }\n    else if (isForwardedSsl(headers)) {\n        return 'https';\n    }\n    return defaultProtocol;\n}\n\nfunction parseRemoteAddress(url: URL, headers: HttpHeaders, remoteAddress?: AddressInfo) : AddressInfo | undefined {\n    const port = remoteAddress ? remoteAddress.port : 'https:' === url.protocol ? 443 : 80;\n\n    let host = headers.one('x-forwarded-for');\n    if (Array.isArray(host)) {\n        host = host[0];\n    }\n    if (host !== undefined) {\n        host = (host as string).split(',', 1)[0].trim();\n        return { address: host, port: Number(port), family: isIP(host) === 6 ? 'IPv6' : 'IPv4' };\n    }\n}\n\nexport abstract class AbstractHttpMessage<Headers extends HttpHeaders = HttpHeaders> {\n    readonly #headers: Headers;\n    protected constructor(headers: Headers) {\n        this.#headers = headers;\n    }\n    get headers(): Headers {\n        return this.#headers;\n    }\n}\n\nexport abstract class AbstractHttpRequest<Headers extends HttpHeaders = HttpHeaders> extends AbstractHttpMessage<Headers> {\n    private static logIdCounter = 0;\n    #id?: string\n\n    get id(): string {\n        if (this.#id === undefined) {\n            this.#id = `${this.initId()}-${++AbstractHttpRequest.logIdCounter}`;\n\n        }\n        return this.#id;\n    }\n\n    protected initId(): string {\n        return 'request';\n    }\n\n    get cookies(): HttpCookie[] {\n        return parseCookies(this.headers);\n    }\n\n    protected parseHost(defaultHost?: string): string | undefined {\n        return parseHost(this.headers, defaultHost);\n    }\n\n    protected parseProtocol(defaultProtocol: string): string {\n        return parseProtocol(this.headers, defaultProtocol);\n    }\n\n    abstract get URL(): URL;\n\n    protected parseRemoteAddress(remoteAddress?: AddressInfo) {\n        return parseRemoteAddress(this.URL, this.headers, remoteAddress);\n    }\n}\n\nexport abstract class AbstractHttpResponse<Headers extends HttpHeaders = HttpHeaders> extends AbstractHttpMessage<Headers> {\n    get cookies(): ResponseCookie[] {\n        return parseResponseCookies(this.headers);\n    }\n\n    protected setCookieValue(responseCookie: ResponseCookie): string {\n        const cookie = new Cookie({\n            key: responseCookie.name,\n            value: responseCookie.value,\n            maxAge: responseCookie.maxAge,\n            domain: responseCookie.domain,\n            path: responseCookie.path,\n            secure: responseCookie.secure,\n            httpOnly: responseCookie.httpOnly,\n            sameSite: responseCookie.sameSite\n        });\n        return cookie.toString();\n    }\n\n}\n\nfunction parseCookies(headers: HttpHeaders): HttpCookie[] {\n    return headers.list('cookie')\n        .map(s => s.split(';').map((cs) => Cookie.parse(cs)))\n        .flat(1)\n        .filter((tc) => tc !== undefined)\n        .map((tc) => {\n            const result: HttpCookie = Object.freeze({name: tc.key, value: tc.value});\n            return result;\n        });\n}\n\ntype Mutable<T> = {-readonly [K in keyof T]: T[K]};\n\nfunction parseResponseCookies(headers: HttpHeaders): ResponseCookie[] {\n    return headers.list('set-cookie').map((cookie) => {\n        const parsed = Cookie.parse(cookie);\n        if (parsed) {\n            const result: Mutable<ResponseCookie> = {name: parsed.key, value: parsed.value, maxAge: Number(parsed.maxAge ?? -1)};\n            if (parsed.httpOnly) result.httpOnly = true;\n            if (parsed.domain) result.domain = parsed.domain;\n            if (parsed.path) result.path = parsed.path;\n            if (parsed.secure) result.secure = true;\n            if (parsed.httpOnly) result.httpOnly = true;\n            if (parsed.sameSite) result.sameSite = parsed.sameSite as 'strict' | 'lax' | 'none';\n            return Object.freeze(result);\n        }\n    }).filter((cookie): cookie is ResponseCookie => cookie !== undefined);\n}\n", "import { extname } from 'node:path';\nimport { MIMEType } from 'node:util';\nimport {\n    APPLICATION_OCTET_STREAM_VALUE, InvalidMimeTypeError,\n    isWildcardSubtype,\n    isWildcardType\n} from '../utils/mime-type-utils.ts';\n\n//excerpt from mime types database\nconst mimeTypes = `\napplication/octet-stream    bin dms lrf mar so dist distz pkg bpk dump elc deploy\napplication/json            json\napplication/wasm            wasm\napplication/x-pkcs12        p12 pfx\ntext/css                    css\ntext/csv                    csv\ntext/html                   html htm\ntext/javascript             js mjs\ntext/plain                  txt text conf def list log in\n`\n\nexport class MediaType extends MIMEType {\n    static readonly ALL: MediaType = new MediaType('*/*');\n    static readonly APPLICATION_OCTET_STREAM: MediaType = new MediaType(APPLICATION_OCTET_STREAM_VALUE);\n    static readonly APPLICATION_JSON: MediaType = new MediaType('application/json');\n    static readonly APPLICATION_NDJSON: MediaType = new MediaType('application/x-ndjson');\n\n    static readonly MULTIPART_FORM_DATA: MediaType = new MediaType('multipart/form-data');\n\n    static readonly TEXT_PLAIN: MediaType = new MediaType('text/plain');\n    static readonly TEXT_HTML: MediaType = new MediaType('text/html');\n\n    static readonly #PARAM_QUALITY_FACTOR = 'q';\n\n    private constructor(input: string) {\n        super(input);\n        this.#checkToken(this.type);\n        this.#checkToken(this.subtype);\n        for (const [key, value] of this.params) {\n            this.checkParameters(key, value);\n        }\n    }\n\n    protected checkParameters(key: string, value: string) {\n        this.#checkToken(key);\n        if (!isQuoted(value)) {\n            this.#checkToken(value);\n        }\n        if (key === MediaType.#PARAM_QUALITY_FACTOR) {\n            const unquotedValue = unquote(value);\n            const q = parseFloat(unquotedValue);\n            if (isNaN(q) || q < 0.0 || q > 1.0) {\n                throw new InvalidMediaTypeError(`Invalid quality value: ${value}`);\n            }\n        }\n    }\n\n    #checkToken(token: string) {\n        for (let i = 0; i < token.length; i++) {\n            const c = token.charCodeAt(i);\n            if (c < 0x20 // control characters\n                || c > 0x7E // non-ASCII characters\n                || c === 0x28 // (\n                || c === 0x29 // )\n                || c === 0x3C // <\n                || c === 0x3E // >\n                || c === 0x40 // @\n                || c === 0x2C // ,\n                || c === 0x3B // ;\n                || c === 0x3A // :\n                || c === 0x5C // \\\n                || c === 0x22 // \"\n                || c === 0x35 // /\n                || c === 0x5B // [\n                || c === 0x5D // ]\n                || c === 0x3F // ?\n                || c === 0x3D // =\n                || c === 0x7B // {\n                || c === 0x7D // }\n                || c === 0x20 // space\n                || c === 0x09 // tab\n            ) {\n                throw new InvalidMediaTypeError(`Invalid token: ${token}`);\n            }\n        }\n    }\n\n\n    get quality(): number {\n        const qualityFactor = this.params.get(MediaType.#PARAM_QUALITY_FACTOR);\n        return (qualityFactor !== null) ? parseFloat(unquote(qualityFactor)) : 1.0;\n    }\n\n    static parseMediaType(input: string): MediaType {\n        return new MediaType(input);\n    }\n\n    static parseMediaTypesList(mediaTypes: string): MediaType[] {\n        if (!mediaTypes?.trim()) {\n            return [];\n        }\n        return mediaTypes.split(',')\n            .map(type => type.trim())\n            .filter(type => type.length > 0)\n            .map(type => MediaType.parseMediaType(type));\n    }\n\n    static parseMediaTypes(...mediaTypes: string[]): MediaType[] {\n        if (!mediaTypes) {\n            return [];\n        }\n        else if (mediaTypes.length === 1) {\n            return MediaType.parseMediaTypesList(mediaTypes[0]);\n        }\n        else {\n            return mediaTypes.flatMap(mediaType => MediaType.parseMediaTypesList(mediaType));\n        }\n    }\n\n    static asMediaType(mimeType: MIMEType): MediaType {\n        if (mimeType instanceof MediaType) {\n            return mimeType;\n        }\n        return new MediaType(mimeType.toString());\n    }\n\n    static asMediaTypes(...mimeTypes: MIMEType[]): MediaType[] {\n        return mimeTypes.map(mimeType => MediaType.asMediaType(mimeType));\n    }\n}\n\nexport class InvalidMediaTypeError extends Error {\n    constructor(message: string) {\n        super(message);\n    }\n}\n\nconst fileExtensionToMediaTypes: Map<string, MediaType[]> = (function parseMimeTypes(): Map<string, MediaType[]> {\n    const map = new Map<string, MediaType[]>();\n\n    for (const line of mimeTypes.trim().split('\\n')) {\n        const trimmed = line.trim();\n        if (!trimmed || trimmed.startsWith('#')) continue;\n\n        const parts = trimmed.split(/\\s+/);\n        if (parts.length < 2) continue;\n\n        const [mimeType, ...extensions] = parts;\n        const mediaType = MediaType.parseMediaType(mimeType);\n\n        for (const ext of extensions) {\n            const key = '.' + ext.toLowerCase();\n            const existing = map.get(key);\n            if (existing) {\n                existing.push(mediaType);\n            }\n            else {\n                map.set(key, [mediaType]);\n            }\n        }\n    }\n\n    return map;\n})();\n\nexport function getMediaType(filename?: string): MediaType | undefined {\n    return getMediaTypes(filename)[0];\n}\n\nexport function getMediaTypes(filename?: string): MediaType[] {\n    const extension = filename ? extname(filename) : '';\n    let mediaTypes: MediaType[] | undefined = undefined;\n    if (extension) {\n        mediaTypes = fileExtensionToMediaTypes.get(extension.toLowerCase());\n    }\n    return mediaTypes ?? [];\n}\n\nfunction isQuoted(s: string): boolean {\n    return s.length >= 2 && (\n        (s.startsWith('\"') && s.endsWith('\"')) ||\n        (s.startsWith(\"'\") && s.endsWith(\"'\")));\n}\n\nfunction unquote(s: string) {\n    if (isQuoted(s)) {\n        return s.substring(1, s.length - 1);\n    }\n    return s;\n}\n\nfunction isMoreSpecific(a: MIMEType, b: MIMEType): boolean {\n    if (a instanceof MediaType) {\n        if (b instanceof MediaType) {\n            const aQuality = a.quality;\n            const bQuality = b.quality;\n            if (aQuality > bQuality) {\n                return true;\n            }\n            else if (aQuality < bQuality) {\n                return false;\n            }\n        }\n    }\n    const aWildcard = isWildcardType(a);\n    const bWildcard = isWildcardType(b);\n    if (aWildcard && !bWildcard) { // */* > text/*\n        return false;\n    }\n    else if (!aWildcard && bWildcard) { // text/* < */*\n        return true;\n    }\n    else {\n        const aWildcardSubtype = isWildcardSubtype(a);\n        const bWildcardSubtype = isWildcardSubtype(b);\n        if (aWildcardSubtype && !bWildcardSubtype) { // text/* > text/html\n            return false;\n        }\n        else if (!aWildcardSubtype && bWildcardSubtype) { // text/html < text/*\n            return true;\n        }\n        else if (a.type === b.type && a.subtype === b.subtype) {\n            const aParamsSize = Array.from(a.params.keys()).length;\n            const bParamsSize = Array.from(b.params.keys()).length;\n            return aParamsSize > bParamsSize; // text/html;level=1 > text/html\n        }\n        else {\n            return false; // both are equally specific\n        }\n    }\n}\n\nfunction isLessSpecific(a: MIMEType, b: MIMEType): boolean {\n    return isMoreSpecific(b, a);\n}\n\nfunction bubbleSort<T>(list: T[], swap: (a: T, b: T) => boolean) {\n    const n = list.length;\n    for (let i = 0; i < n; i++) {\n        for (let j = 1; j < n - i; j++) {\n            const prev = list[j - 1];\n            const curr = list[j];\n            if (swap(prev, curr)) {\n                list[j] = prev;\n                list[j - 1] = curr;\n            }\n        }\n    }\n}\n\nexport function sortBySpecificity<T extends MIMEType>(mimeTypes: T[]) {\n    if (mimeTypes === undefined) {\n        throw new Error('mimeTypes must not be undefined');\n    }\n    if (mimeTypes.length > 100) {\n        throw new InvalidMimeTypeError(`too many elements`);\n    }\n    bubbleSort(mimeTypes, isLessSpecific);\n\n}\n", "import { MIMEType } from 'node:util';\n\nexport const WILDCARD_TYPE = '*';\nexport const ALL = new MIMEType(`${WILDCARD_TYPE}/${WILDCARD_TYPE}`);\nexport const APPLICATION_OCTET_STREAM_VALUE = 'application/octet-stream';\nexport const APPLICATION_OCTET_STREAM = new MIMEType(APPLICATION_OCTET_STREAM_VALUE);\n\nexport function isWildcardType(mimeType: MIMEType): boolean {\n    return mimeType.type === WILDCARD_TYPE;\n}\n\nexport function isWildcardSubtype(mimeType: MIMEType): boolean {\n    return mimeType.subtype === WILDCARD_TYPE || mimeType.subtype.startsWith(`${WILDCARD_TYPE}+`);\n}\n\nexport function isConcrete(mimeType: MIMEType): boolean {\n    return !isWildcardType(mimeType) && !isWildcardSubtype(mimeType);\n}\n\n\nexport class InvalidMimeTypeError extends Error {\n    readonly mimeType: string;\n    constructor(mimeType: string, message?: string, options?: ErrorOptions) {\n        super(message === undefined ? `Invalid MIME type \"${mimeType}\"` : `Invalid MIME type \"${mimeType}\": ${message}`, options);\n        this.mimeType = mimeType;\n    }\n}\n\nexport function createMimeType(type: string, subtype: string, charset?: string): MIMEType {\n    const input = `${type}/${subtype}`;\n    let result: MIMEType;\n    try {\n        result = new MIMEType(input);\n    }\n    catch (error) {\n        throw new InvalidMimeTypeError(input, undefined,  { cause: error } );\n    }\n    if (charset) {\n        result.params.set('charset', charset);\n    }\n    return result;\n}\n\nexport function getSubtypeSuffix(mimeType: MIMEType): string | null {\n    const suffixIndex = mimeType.subtype.lastIndexOf('+');\n    if (suffixIndex !== -1 && suffixIndex < mimeType.subtype.length) {\n        return mimeType.subtype.substring(suffixIndex + 1);\n    }\n    return null;\n\n}\n\nexport function isCompatibleWith(a: MIMEType, b?: MIMEType): boolean {\n    if (!b) {\n        return false;\n    }\n\n    if (isWildcardType(a) || isWildcardType(b)) {\n        return true;\n    }\n\n    else if (a.type === b.type) {\n        if (a.subtype === b.subtype) {\n            return true;\n        }\n        if (isWildcardSubtype(a) || isWildcardSubtype(b)) {\n            const aSuffix = getSubtypeSuffix(a);\n            const bSuffix = getSubtypeSuffix(b);\n            if (a.subtype === WILDCARD_TYPE || b.subtype === WILDCARD_TYPE) {\n                return true;\n            }\n            else if (isWildcardSubtype(a) && bSuffix !== null) {\n                return aSuffix === b.subtype || aSuffix === bSuffix;\n            }\n            else if (isWildcardSubtype(b) && aSuffix !== null) {\n                return a.subtype === bSuffix || bSuffix === aSuffix;\n            }\n        }\n    }\n    return false;\n}\n", "import type {\n    HeaderValues,\n    HttpHeaders,\n    MutableHttpHeaders,\n    ReadonlyHeaderValues, ReadonlyHttpHeaders\n} from '../../types/web/http';\nimport { MediaType } from './media-type.ts';\n\nfunction parseHeader(value: string): string[] {\n    const list: string[] = [];\n    {\n        let start = 0;\n        let end = 0;\n\n        for (let i = 0; i < value.length; i++) {\n            switch (value.charCodeAt(i)) {\n                case 0x20: // space\n                    if (start === end) {\n                        start = end = i + 1;\n                    }\n                    break;\n                case 0x2c: // comma\n                    list.push(value.slice(start, end));\n                    start = end = i + 1;\n                    break;\n                default:\n                    end = end + 1;\n                    break;\n            }\n        }\n        list.push(value.slice(start, end));\n    }\n\n    return list;\n}\n\nfunction toList(values: number | string | (readonly string[]) | undefined): string[] {\n    if (typeof values === 'string') {\n        values = [values];\n    }\n    if (typeof values === 'number') {\n        values = [String(values)];\n    }\n    const list: string[] = [];\n    if (values) {\n        for (const value of values) {\n            if (value) {\n                list.push(...parseHeader(value));\n            }\n        }\n    }\n    return list;\n}\n\nexport abstract class AbstractHttpHeaders<Values extends HeaderValues | ReadonlyHeaderValues> {\n    protected constructor() {\n    }\n\n    abstract get(name: string): Values\n\n    toList(name: string): string[] {\n        const values = this.get(name);\n        return toList(values);\n    }\n}\n\nexport class MapHttpHeaders extends Map<string, (readonly string[])> implements MutableHttpHeaders {\n\n    get(name: string) {\n        return super.get(name.toLowerCase());\n    }\n\n    one(name: string): string | undefined {\n        return this.get(name)?.[0];\n    }\n\n    list(name: string) {\n        const values = super.get(name.toLowerCase());\n        return toList(values);\n    }\n\n    set(name: string, value: number | string | (readonly string[]) | undefined): this {\n        if (typeof value === 'number') {\n            value = String(value);\n        }\n        if (typeof value === 'string') {\n            value = [value];\n        }\n        if (value) {\n            return super.set(name.toLowerCase(), value);\n        }\n        else {\n            super.delete(name.toLowerCase());\n            return this;\n        }\n    }\n\n    add(name: string, value: string | (readonly string[])) {\n        const prev = super.get(name.toLowerCase());\n        if (typeof value === 'string') {\n            value = [value];\n        }\n        if (prev) {\n            value = prev.concat(value);\n        }\n        this.set(name, value);\n        return this;\n    }\n}\n\nexport const EMPTY_HTTP_HEADERS: ReadonlyHttpHeaders = new MapHttpHeaders();\n\n\nexport function getContentType(headers: HttpHeaders): MediaType | undefined {\n    const value = headers.one('content-type');\n    return value ? MediaType.parseMediaType(value as string) : undefined;\n\n}\n", "import type {HttpStatusCode} from '../../types/web/http';\n\nclass DefaultHttpStatusCode implements HttpStatusCode {\n    readonly #value:  number;\n    constructor(value: number) {\n        this.#value = value;\n    }\n    get value(): number {\n        return this.#value;\n    }\n\n    toString(): string {\n        return this.#value.toString();\n    }\n}\n\nexport class HttpStatus implements HttpStatusCode {\n    static readonly CONTINUE = new HttpStatus(100, 'Continue');\n    static readonly SWITCHING_PROTOCOLS = new HttpStatus(101, 'Switching Protocols');\n\n    // 2xx Success\n\n    static readonly OK = new HttpStatus(200, 'OK');\n    static readonly CREATED = new HttpStatus(201, 'Created');\n    static readonly ACCEPTED = new HttpStatus(202, 'Accepted');\n    static readonly  NON_AUTHORITATIVE_INFORMATION = new HttpStatus(203, 'Non-Authoritative Information');\n    static readonly NO_CONTENT = new HttpStatus(204, 'No Content');\n    static readonly RESET_CONTENT = new HttpStatus(205, 'Reset Content');\n    static readonly PARTIAL_CONTENT = new HttpStatus(206, 'Partial Content');\n    static readonly MULTI_STATUS = new HttpStatus(207, 'Multi-Status');\n\n    static readonly IM_USED = new HttpStatus(226, 'IM Used');\n\n\n    // 3xx Redirection\n    static readonly MULTIPLE_CHOICES = new HttpStatus(300, 'Multiple Choices');\n    static readonly MOVED_PERMANENTLY = new HttpStatus(301, 'Moved Permanently');\n\n    // 4xx Client Error\n\n    static readonly BAD_REQUEST = new HttpStatus(400, 'Bad Request');\n    static readonly UNAUTHORIZED = new HttpStatus(401, 'Unauthorized');\n    static readonly FORBIDDEN = new HttpStatus(403, 'Forbidden');\n    static readonly NOT_FOUND = new HttpStatus(404, 'Not Found');\n    static readonly METHOD_NOT_ALLOWED = new HttpStatus(405, 'Method Not Allowed');\n    static readonly NOT_ACCEPTABLE = new HttpStatus(406, 'Not Acceptable');\n    static readonly PROXY_AUTHENTICATION_REQUIRED = new HttpStatus(407, 'Proxy Authentication Required');\n    static readonly REQUEST_TIMEOUT = new HttpStatus(408, 'Request Timeout');\n    static readonly CONFLICT = new HttpStatus(409, 'Conflict');\n    static readonly GONE = new HttpStatus(410, 'Gone');\n    static readonly LENGTH_REQUIRED = new HttpStatus(411, 'Length Required');\n    static readonly PRECONDITION_FAILED = new HttpStatus(412, 'Precondition Failed');\n    static readonly PAYLOAD_TOO_LARGE = new HttpStatus(413, 'Payload Too Large');\n    static readonly URI_TOO_LONG = new HttpStatus(414, 'URI Too Long');\n    static readonly UNSUPPORTED_MEDIA_TYPE = new HttpStatus(415, 'Unsupported Media Type');\n\n    static readonly EXPECTATION_FAILED = new HttpStatus(417, 'Expectation Failed');\n    static readonly IM_A_TEAPOT = new HttpStatus(418, 'I\\'m a teapot');\n\n    static readonly TOO_EARLY = new HttpStatus(425, 'Too Early');\n    static readonly UPGRADE_REQUIRED = new HttpStatus(426, 'Upgrade Required');\n    static readonly PRECONDITION_REQUIRED = new HttpStatus(428, 'Precondition Required');\n    static readonly TOO_MANY_REQUESTS = new HttpStatus(429, 'Too Many Requests');\n    static readonly REQUEST_HEADER_FIELDS_TOO_LARGE = new HttpStatus(431, 'Request Header Fields Too Large');\n    static readonly UNAVAILABLE_FOR_LEGAL_REASONS = new HttpStatus(451, 'Unavailable For Legal Reasons');\n\n    // 5xx Server Error\n    static readonly INTERNAL_SERVER_ERROR = new HttpStatus(500, 'Internal Server Error');\n    static readonly NOT_IMPLEMENTED = new HttpStatus(501, 'Not Implemented');\n    static readonly BAD_GATEWAY = new HttpStatus(502, 'Bad Gateway');\n    static readonly SERVICE_UNAVAILABLE = new HttpStatus(503, 'Service Unavailable');\n    static readonly GATEWAY_TIMEOUT = new HttpStatus(504, 'Gateway Timeout');\n    static readonly HTTP_VERSION_NOT_SUPPORTED = new HttpStatus(505, 'HTTP Version Not Supported');\n    static readonly VARIANT_ALSO_NEGOTIATES = new HttpStatus(506, 'Variant Also Negotiates');\n    static readonly INSUFFICIENT_STORAGE = new HttpStatus(507, 'Insufficient Storage');\n    static readonly LOOP_DETECTED = new HttpStatus(508, 'Loop Detected');\n    static readonly NOT_EXTENDED = new HttpStatus(510, 'Not Extended');\n    static readonly NETWORK_AUTHENTICATION_REQUIRED = new HttpStatus(511, 'Network Authentication Required');\n\n    static readonly #VALUES: HttpStatus[] = [];\n    static {\n        Object.keys(HttpStatus)\n            .filter(key => key !== 'VALUES' && key !== 'resolve')\n            .forEach(key => {\n                const value = HttpStatus[key];\n                if (value instanceof HttpStatus) {\n                    Object.defineProperty(value, 'name', { enumerable: true, value: key, writable: false });\n                    HttpStatus.#VALUES.push(value);\n                }\n            })\n\n    }\n\n    static resolve(code: number): HttpStatus | undefined {\n        for (const status of HttpStatus.#VALUES) {\n            if (status.value === code) {\n                return status;\n            }\n        }\n    }\n\n    readonly #value: number;\n    readonly #phrase: string;\n\n    private constructor(value: number, phrase: string) {\n        this.#value = value;\n        this.#phrase = phrase;\n    }\n\n    get value(): number {\n        return this.#value;\n    }\n    get phrase(): string {\n        return this.#phrase;\n    }\n\n    toString() {\n        return `${this.#value} ${this['name']}`;\n    }\n}\n\n\nexport function httpStatusCode(value: number | HttpStatusCode): HttpStatusCode {\n    if (typeof value === 'number') {\n        if (value < 100 || value > 999) {\n            throw new Error(`status code ${value} should be in range 100-999`);\n        }\n        const status = HttpStatus.resolve(value);\n        if (status !== undefined) {\n            return status;\n        }\n        return new DefaultHttpStatusCode(value);\n    }\n    return value;\n}\n", "import type { Principal } from '../../types/auth';\nimport type {\n    BodyChunk,\n    HeaderValue,\n    HeaderValues,\n    HttpCookie,\n    HttpMethod,\n    HttpStatusCode,\n    MutableHttpHeaders,\n    ReadonlyHeaderValues,\n    ReadonlyHttpHeaders,\n    ResponseCookie\n} from '../../types/web/http'\n\nimport type {\n    RequestPath,\n    ServerHttpRequest,\n    ServerHttpResponse,\n    ServerWebExchange,\n    SslInfo\n} from '../../types/web/server';\nimport { AbstractHttpResponse } from '../http/exchange.ts';\nimport { AbstractHttpHeaders } from '../http/headers.ts';\nimport { httpStatusCode } from '../http/status.ts';\nimport type { X509Certificate } from 'node:crypto';\nimport http from 'node:http';\nimport http2 from 'node:http2';\nimport net from 'node:net';\nimport type { TLSSocket } from 'node:tls';\nimport { AbstractServerHttpRequest } from '../http/server/exchange.ts';\nimport type { ServerCodecConfigurer } from '../http/codec/types.ts';\n\nexport class ExtendedHttpIncomingMessage extends http.IncomingMessage {\n    // circular reference to the exchange\n    exchange?: ServerWebExchange;\n\n    upgradeHead?: Buffer<ArrayBufferLike>\n\n\n    get urlBang(): string {\n        return this.url!;\n    }\n\n    get socketEncrypted(): boolean {\n        // see tls.TLSSocket#encrypted\n        return this.socket['encrypted'] === true;\n    }\n}\n\nexport class ExtendedHttpServerResponse<Request extends ExtendedHttpIncomingMessage = ExtendedHttpIncomingMessage> extends http.ServerResponse<Request> {\n\n    markHeadersSent(): void {\n        this['_header'] = true; // prevent response from being sent\n    }\n\n    getRawHeaderNames(): string[] {\n        return super['getRawHeaderNames']();\n    }\n}\n\nexport abstract class AbstractServerHttpResponse extends AbstractHttpResponse<MutableHttpHeaders> {\n    #cookies: ResponseCookie[] = [];\n    #statusCode?: HttpStatusCode;\n    #state: 'new' | 'committing' | 'commit-action-failed' | 'committed' = 'new';\n    #commitActions: (() => Promise<void>)[] = [];\n\n    setStatusCode(statusCode?: HttpStatusCode): boolean {\n        if (this.#state === 'committed') {\n           return false;\n        }\n        else {\n            this.#statusCode = statusCode;\n            return true;\n        }\n    }\n\n    setRawStatusCode(statusCode?: number): boolean {\n        return this.setStatusCode(statusCode === undefined ? undefined : httpStatusCode(statusCode));\n    };\n\n    get statusCode(): HttpStatusCode | undefined {\n        return this.#statusCode;\n    }\n\n    addCookie(cookie: ResponseCookie): this {\n        if (this.#state === 'committed') {\n            throw new Error(`Cannot add cookie ${JSON.stringify(cookie)} because HTTP response has already been committed`);\n        }\n        this.#cookies.push(cookie);\n        return this;\n    }\n\n    abstract getNativeResponse<T>(): T;\n\n    beforeCommit(action: () => Promise<void>): void {\n        this.#commitActions.push(action);\n    }\n\n    get commited(): boolean {\n        const state = this.#state;\n        return state !== 'new' && state !== 'commit-action-failed';\n    }\n\n    async body(body: ReadableStream<BodyChunk> | Promise<BodyChunk | void> | BodyChunk): Promise<boolean> {\n        if (body instanceof ReadableStream) {\n            throw new Error('ReadableStream body not supported yet');\n        }\n        const buffer = await body;\n        try {\n            // touch buffers if needed\n\n            return await this.doCommit(async () => {\n\n                return await this.bodyInternal(Promise.resolve(buffer));\n\n            }).catch(error => {\n                // release buffers\n                throw error;\n            });\n        }\n        catch (error) {\n            // clear content headers\n            throw error;\n        }\n    }\n\n    abstract bodyInternal(body: Promise<BodyChunk | void>): Promise<boolean>;\n\n    async end(): Promise<boolean> {\n        if (!this.commited) {\n            return this.doCommit(async () => {\n                return await this.bodyInternal(Promise.resolve());\n            });\n        }\n        else {\n            return Promise.resolve(false);\n        }\n    }\n\n    protected doCommit(writeAction?: () => Promise<boolean>): Promise<boolean> {\n        const state = this.#state;\n        let allActions = Promise.resolve();\n        if (state === 'new') {\n            this.#state = 'committing';\n            if (this.#commitActions.length > 0) {\n                allActions = this.#commitActions\n                    .reduce(\n                        (acc, cur) => acc.then(() => cur()),\n                        Promise.resolve())\n                    .catch((_error) => {\n                        const state = this.#state;\n                        if (state === 'committing') {\n                            this.#state = 'commit-action-failed';\n                            // clear content headers\n                        }\n                    });\n            }\n        }\n        else if (state === 'commit-action-failed') {\n            this.#state = 'committing';\n            // skip commit actions\n        } else {\n            return Promise.resolve(false);\n        }\n\n        allActions = allActions.then(() => {\n            this.applyStatusCode();\n            this.applyHeaders();\n            this.applyCookies();\n            this.#state = 'committed';\n        });\n\n\n        return allActions.then(async () => {\n            return writeAction !== undefined ? await writeAction() : true;\n        });\n    }\n\n    protected applyStatusCode(): void {}\n    protected applyHeaders(): void {}\n    protected applyCookies(): void {}\n}\nexport class HttpServerRequest extends AbstractServerHttpRequest implements ServerHttpRequest {\n\n    #url?: URL;\n    #cookies?: HttpCookie[];\n    readonly #req: ExtendedHttpIncomingMessage;\n\n    constructor(req: ExtendedHttpIncomingMessage) {\n        super(new IncomingMessageHeaders(req));\n        this.#req = req;\n    }\n\n    getNativeRequest<T>(): T {\n        return this.#req as T;\n    }\n\n    get upgrade() {\n        return this.#req['upgrade'];\n    }\n\n    get http2(): boolean {\n        return this.#req.httpVersionMajor >= 2;\n    }\n\n    get path() {\n        return this.URL?.pathname;\n    }\n\n    get URL() {\n        this.#url ??= new URL(this.#req.urlBang, `${this.protocol}://${this.host}`);\n        return this.#url;\n    }\n\n    get query() {\n        return this.URL?.search;\n    }\n\n    get method() {\n        return this.#req.method as HttpMethod;\n    }\n\n    get host() {\n        let dh: string | undefined = undefined;\n        if (this.#req.httpVersionMajor >= 2) {\n            dh = (this.#req.headers as http2.IncomingHttpHeaders)[':authority'];\n        }\n        dh ??= this.#req.socket.remoteAddress;\n        return super.parseHost(dh);\n    }\n\n    get protocol() {\n        let dp: string | undefined = undefined;\n        if (this.#req.httpVersionMajor > 2) {\n            dp = (this.#req.headers as http2.IncomingHttpHeaders)[':scheme'];\n        }\n        dp ??= this.#req.socketEncrypted ? 'https' : 'http';\n        return super.parseProtocol(dp);\n    }\n\n    get socket() {\n        return this.#req.socket;\n    }\n\n    get remoteAddress(): net.AddressInfo | undefined {\n        const family = this.#req.socket.remoteFamily;\n        const address = this.#req.socket.remoteAddress;\n        const port = this.#req.socket.remotePort;\n        const remoteAddress = (!family || !address || !port) ? undefined : { family, address, port };\n        return super.parseRemoteAddress(remoteAddress) ?? remoteAddress;\n    }\n\n    protected initSslInfo(): SslInfo | undefined {\n        if (this.#req.socketEncrypted) {\n            return new DefaultSslInfo(this.#req.socket as TLSSocket);\n        }\n    }\n\n    get cookies(): HttpCookie[] {\n        this.#cookies ??= super.cookies\n        return this.#cookies;\n    }\n\n    get body(): ReadableStream<BodyChunk> {\n        return http.IncomingMessage.toWeb(this.#req) as ReadableStream<BodyChunk>;\n    }\n\n    async blob() {\n        const chunks: BodyChunk[] = [];\n        if (this.body !== undefined) {\n            for await (const chunk of this.body) {\n                chunks.push(chunk);\n            }\n        }\n        return new Blob(chunks, {type: this.headers.one('content-type') as string || 'application/octet-stream'});\n    }\n\n\n    async text() {\n        const blob = await this.blob();\n        return await blob.text();\n    }\n\n    async formData() {\n        const blob = await this.blob();\n        const text = await blob.text();\n        return new URLSearchParams(text);\n    }\n\n    async json() {\n        const blob = await this.blob();\n        if (blob.size === 0) {\n            return undefined;\n        }\n        const text = await blob.text();\n        return JSON.parse(text);\n    }\n\n\n    protected initId(): string {\n        const remoteIp = this.#req.socket.remoteAddress;\n        if (!remoteIp) {\n            throw new Error('Socket has no remote address');\n        }\n        return `${remoteIp}:${this.#req.socket.remotePort}`;\n    }\n}\n\nclass DefaultSslInfo implements SslInfo {\n    readonly peerCertificate?: X509Certificate;\n    constructor(socket: TLSSocket) {\n        this.peerCertificate = socket.getPeerX509Certificate();\n    }\n}\n\nclass IncomingMessageHeaders extends AbstractHttpHeaders<ReadonlyHeaderValues> implements ReadonlyHttpHeaders {\n    readonly #msg: ExtendedHttpIncomingMessage;\n\n    constructor(msg: ExtendedHttpIncomingMessage) {\n        super();\n        this.#msg = msg;\n    }\n\n    has(name: string): boolean {\n        return this.#msg.headers[name] !== undefined;\n    }\n\n    get(name: string): string | (readonly string[]) | undefined {\n        return this.#msg.headers[name];\n    }\n\n    list(name: string): string[] {\n        return super.toList(name);\n    }\n\n    one(name: string): string | undefined {\n        const value = this.#msg.headers[name];\n        if (Array.isArray(value)) {\n            return value[0];\n        }\n        return value;\n    }\n\n    keys() {\n        return Object.keys(this.#msg.headers).values();\n    }\n}\n\nclass OutgoingMessageHeaders extends AbstractHttpHeaders<HeaderValues> implements MutableHttpHeaders {\n    readonly #msg: ExtendedHttpServerResponse;\n\n    constructor(msg: ExtendedHttpServerResponse) {\n        super();\n        this.#msg = msg;\n    }\n\n    has(name: string): boolean {\n        return this.#msg.hasHeader(name);\n    }\n\n    keys() {\n        return this.#msg.getHeaderNames().values();\n    }\n\n    get(name: string): HeaderValues {\n        return this.#msg.getHeader(name);\n    }\n\n    one(name: string): HeaderValue {\n        const value = this.#msg.getHeader(name);\n        if (Array.isArray(value)) {\n            return value[0];\n        }\n        return value;\n    }\n\n    set(name: string, value: HeaderValues): this {\n        if (!this.#msg.headersSent) {\n            if (Array.isArray(value)) {\n                value = value.map(v => typeof v === 'number' ? String(v) : v);\n            } else if (typeof value === 'number') {\n                value = String(value);\n            }\n\n            if (value) {\n                this.#msg.setHeader(name, value);\n            }\n            else {\n                this.#msg.removeHeader(name);\n            }\n        }\n        return this;\n    }\n\n    add(name: string, value: string | (readonly string[])): this {\n        if (!this.#msg.headersSent) {\n            this.#msg.appendHeader(name, value);\n        }\n        return this;\n    }\n\n    list(name: string): string[] {\n        return super.toList(name);\n    }\n}\n\nexport class HttpServerResponse extends AbstractServerHttpResponse implements ServerHttpResponse {\n    readonly #res: ExtendedHttpServerResponse;\n\n    constructor(res: ExtendedHttpServerResponse) {\n        super(new OutgoingMessageHeaders(res));\n        this.#res = res;\n    }\n\n    getNativeResponse<T>(): T {\n        return this.#res as T;\n    }\n\n    get statusCode(): HttpStatusCode {\n        const status = super.statusCode;\n        return status ?? {value: this.#res.statusCode};\n    }\n\n    applyStatusCode() {\n        const status = super.statusCode;\n        if (status !== undefined) {\n            this.#res.statusCode = status.value;\n        }\n    }\n\n    addCookie(cookie: ResponseCookie): this {\n        this.headers.add('Set-Cookie', super.setCookieValue(cookie));\n        return this;\n    }\n\n    async bodyInternal(body: Promise<BodyChunk | void>): Promise<boolean> {\n        if (!this.#res.headersSent) {\n            if (body instanceof ReadableStream) {\n                // http.IncomingMessage.fromWeb(body)\n                throw new Error('ReadableStream body not supported in response');\n            }\n            else {\n                const chunk = await body;\n                return await new Promise<boolean>((resolve, reject) => {\n                    try {\n                        if (chunk === undefined) {\n                            this.#res.end(() => {\n                                resolve(true);\n                            });\n                        } else {\n                            if (!this.headers.has('content-length')) {\n                                // set Content-Length if not already set\n                                if (typeof chunk === 'string') {\n                                    this.headers.set('Content-Length', Buffer.byteLength(chunk));\n                                }\n                                else if (chunk instanceof Blob) {\n                                    this.headers.set('Content-Length', chunk.size);\n                                }\n                                else {\n                                    this.headers.set('Content-Length', chunk.byteLength);\n                                }\n                            }\n                            this.#res.end(chunk, () => {\n                                resolve(true);\n                            });\n                        }\n                    } catch (e) {\n                        reject(e instanceof Error ? e : new Error(`end failed: ${e}`));\n                    }\n                });\n            }\n        }\n        else {\n            return false; // already ended\n        }\n    }\n}\n\nexport class ServerHttpRequestDecorator implements ServerHttpRequest {\n    readonly #delegate: ServerHttpRequest;\n\n    constructor(request: ServerHttpRequest) {\n        this.#delegate = request;\n    }\n\n    get delegate(): ServerHttpRequest {\n        return this.#delegate;\n    }\n\n    get id(): string {\n        return this.#delegate.id;\n    }\n\n    get method(): HttpMethod {\n        return this.#delegate.method;\n    }\n\n    get path(): string {\n        return this.#delegate.path;\n    }\n\n    get requestPath(): RequestPath {\n        return this.#delegate.requestPath;\n    }\n\n    get protocol() {\n        return this.#delegate.protocol;\n    }\n\n    get host(): string | undefined {\n        return this.#delegate.host;\n    }\n\n    get URL(): URL {\n        return this.#delegate.URL;\n    }\n\n    get headers(): ReadonlyHttpHeaders {\n        return this.#delegate.headers;\n    }\n\n    get cookies(): HttpCookie[] {\n        return this.#delegate.cookies;\n    }\n\n    get remoteAddress() {\n        return this.#delegate.remoteAddress;\n    }\n\n    get upgrade() {\n        return this.#delegate.upgrade;\n    }\n\n    get sslInfo() {\n        return this.#delegate.sslInfo;\n    }\n\n    get body(): ReadableStream<BodyChunk> | undefined {\n        return this.#delegate.body;\n    }\n    async blob(): Promise<Blob> {\n        return await this.#delegate.blob();\n    }\n    async text(): Promise<string> {\n        return await this.#delegate.text();\n    }\n    async formData(): Promise<URLSearchParams> {\n        return await this.#delegate.formData();\n    }\n    async json(): Promise<unknown> {\n        return await this.#delegate.json();\n    }\n\n    toString(): string {\n        return `${ServerHttpRequestDecorator.name} [delegate: ${this.delegate.toString()}]`;\n    }\n\n    public static getNativeRequest<T>(request: ServerHttpRequest): T {\n        if (request instanceof AbstractServerHttpRequest) {\n            return request.getNativeRequest<T>();\n        }\n        else if (request instanceof ServerHttpRequestDecorator) {\n            return ServerHttpRequestDecorator.getNativeRequest<T>(request.delegate);\n        }\n        else {\n            throw new Error(`Cannot get native request from ${request.constructor.name}`);\n        }\n    }\n}\nexport class ServerHttpResponseDecorator implements ServerHttpResponse {\n    readonly #delegate: ServerHttpResponse;\n\n    constructor(response: ServerHttpResponse) {\n        this.#delegate = response;\n    }\n\n    get delegate(): ServerHttpResponse {\n        return this.#delegate;\n    }\n\n    setStatusCode(statusCode: HttpStatusCode): boolean {\n        return this.delegate.setStatusCode(statusCode);\n    }\n\n    setRawStatusCode(statusCode?: number): boolean {\n        return this.delegate.setRawStatusCode(statusCode);\n    }\n\n    get statusCode(): HttpStatusCode {\n        return this.delegate.statusCode;\n    }\n\n    get cookies(): ResponseCookie[] {\n        return this.delegate.cookies;\n    }\n\n    addCookie(cookie: ResponseCookie): this {\n        this.delegate.addCookie(cookie);\n        return this;\n    }\n\n    async end(): Promise<boolean> {\n        return await this.delegate.end();\n    }\n\n    async body(body: ReadableStream<BodyChunk> | Promise<BodyChunk | void> | BodyChunk): Promise<boolean> {\n        return await this.#delegate.body(body);\n    }\n\n    get headers(): MutableHttpHeaders {\n        return this.#delegate.headers;\n    }\n\n    toString(): string {\n        return `${ServerHttpResponseDecorator.name} [delegate: ${this.delegate.toString()}]`;\n    }\n\n    public static getNativeResponse<T>(response: ServerHttpResponse): T {\n        if (response instanceof AbstractServerHttpResponse) {\n            return response.getNativeResponse<T>();\n        }\n        else if (response instanceof ServerHttpResponseDecorator) {\n            return ServerHttpResponseDecorator.getNativeResponse<T>(response.delegate);\n        }\n        else {\n            throw new Error(`Cannot get native response from ${response.constructor.name}`);\n        }\n    }\n}\n\nexport class ServerWebExchangeDecorator implements ServerWebExchange {\n    readonly #delegate: ServerWebExchange;\n\n    protected constructor(exchange: ServerWebExchange) {\n        this.#delegate = exchange;\n    }\n\n    get delegate(): ServerWebExchange {\n        return this.#delegate;\n    }\n\n    get request(): ServerHttpRequest {\n        return this.#delegate.request;\n    }\n\n    get response(): ServerHttpResponse {\n        return this.#delegate.response;\n    }\n\n    attribute<T>(name: string): T | undefined {\n        return this.#delegate.attribute(name);\n    }\n\n    get attributes(): Map<string, unknown> {\n        return this.#delegate.attributes;\n    }\n\n    principal<P extends Principal>(): Promise<P | undefined> {\n        return this.#delegate.principal();\n    }\n\n    get logPrefix(): string {\n        return this.#delegate.logPrefix;\n    }\n\n    toString() {\n        return `${ServerWebExchangeDecorator.name} [delegate: ${this.delegate}]`;\n    }\n}\n\nexport class DefaultWebExchange<Request extends ServerHttpRequest, Response extends ServerHttpResponse> {\n    readonly request: Request;\n    readonly response: Response;\n    readonly #attributes: Map<string, unknown> = new Map();\n    #logId?: unknown;\n    #logPrefix: string = '';\n\n    constructor(request: Request, response: Response, codecConfigurer: ServerCodecConfigurer) {\n        this.#attributes[LOG_ID_ATTRIBUTE] = request.id;\n        this.request = request;\n        this.response = response;\n    }\n\n    get method(): HttpMethod {\n        return this.request.method;\n    }\n\n    get path(): string | null | undefined {\n        return this.request.path;\n    }\n\n    get attributes(): Map<string, unknown> {\n        return this.#attributes;\n    }\n\n    attribute<T>(name: string): T | undefined {\n        return this.attributes.get(name) as T;\n    }\n\n    principal<P extends Principal>(): Promise<P | undefined> {\n        return Promise.resolve(undefined);\n    }\n\n    get logPrefix(): string {\n        const value = this.attribute(LOG_ID_ATTRIBUTE);\n        if (this.#logId !== value) {\n            this.#logId = value;\n            this.#logPrefix = value !== undefined ? `[${value}] ` : '';\n        }\n        return this.#logPrefix;\n    }\n}\n\nexport const LOG_ID_ATTRIBUTE = 'io.interop.web.server.exchange.log_id';\n\n", "import type { PathContainer, PathContainerElement, PathSegment, Separator } from '../../../types/path';\n\nexport function subPath(container: PathContainer, start: number, end?: number): PathContainer {\n    const elements = container.elements;\n    end = end ?? elements.length;\n    if (start === 0 && end === elements.length) {\n        return container;\n    }\n    if (start === end) {\n        return DefaultPathContainer.EMPTY_PATH;\n    }\n    if (!(start >= 0 && start < elements.length)) throw new Error('start index out of bounds: ' + start);\n    if (!(start >= 0 && end <= elements.length)) throw new Error('end index out of bounds: ' + end);\n    if (!(start < end)) throw new Error('start index must be less than end index: ' + start + ' >= ' + end);\n    const slice = elements.slice(start, end);\n    const path = slice.map(e => e.value).join('');\n    return new DefaultPathContainer(path, slice);\n}\n\nexport function isSeparator(element: PathContainerElement): element is Separator {\n    return element.value.length === 1 && element['valueToMatch'] === undefined && element['parameters'] === undefined;\n}\n\nexport function isPathSegment(element: PathContainerElement): element is PathSegment {\n    return !isSeparator(element);\n}\n\nexport type Options = {\n    readonly separator: number; // char code 0x2f for '/' and 0x2e for '.'\n    readonly decodeAndParseParameters: boolean;\n}\nexport const HTTP_OPTIONS: Options = {\n    separator: '/'.charCodeAt(0),\n    decodeAndParseParameters: true,\n}\n\nexport const MESSAGING_OPTIONS: Options = {\n    separator: '.'.charCodeAt(0),\n    decodeAndParseParameters: false,\n}\n\nexport function parsePath(path: string, options?: Options): PathContainer {\n    return DefaultPathContainer.createFromUrlPath(path, options ?? HTTP_OPTIONS);\n}\n\ntype DefaultSeparator = Separator & { readonly encoded: string };\n\nclass DefaultPathContainer implements PathContainer {\n    static readonly EMPTY_PATH: PathContainer = new DefaultPathContainer('', []);\n    static readonly #SEPARATORS: Map<number, DefaultSeparator> = new Map([\n        ['/'.charCodeAt(0), { value: '/', encoded: '%2F' }],\n        ['.'.charCodeAt(0), { value: '.', encoded: '%2E' }],\n    ]);\n\n    readonly #path: string;\n    readonly #elements: readonly PathContainerElement[];\n\n    constructor(path: string, elements: PathContainerElement[]) {\n        this.#path = path;\n        this.#elements = Object.freeze(elements);\n    }\n\n    get value(): string {\n        return this.#path;\n    }\n\n    get elements(): readonly PathContainerElement[] {\n        return this.#elements;\n    }\n\n    static createFromUrlPath(path: string, options: Options): PathContainer {\n        if (path === '') {\n            return DefaultPathContainer.EMPTY_PATH;\n        }\n        const separator = options.separator;\n        const separatorElement = DefaultPathContainer.#SEPARATORS.get(separator);\n        if (separatorElement === undefined) {\n            throw new Error('Unsupported separator: ' + separator);\n        }\n\n        const elements: PathContainerElement[] = [];\n        let start: number;\n        if (path.charCodeAt(0) === separator) {\n            start = 1;\n            elements.push(separatorElement);\n        }\n        else {\n            start = 0;\n        }\n\n        while (start < path.length) {\n            let end = -1;\n            for (let i = start; i < path.length; i++) {\n                if (path.charCodeAt(i) === separator) {\n                    end = i;\n                    break;\n                }\n            }\n            const segment = (end !== -1) ? path.substring(start, end) : path.substring(start);\n\n            if (segment.length > 0) {\n                elements.push(options.decodeAndParseParameters ?\n                    DefaultPathContainer.#decodeAndParsePathSegment(segment) :\n                    DefaultPathSegment.from(segment, separatorElement)\n                );\n            }\n            if (end === -1) {\n                break;\n            }\n            elements.push(separatorElement);\n            start = end + 1;\n        }\n        return new DefaultPathContainer(path, elements);\n    }\n\n    static #decodeAndParsePathSegment(segment: string): PathSegment {\n        const paramsIndex = segment.indexOf(';');\n        if (paramsIndex === -1) {\n            const valueToMatch = decodeURIComponent(segment);\n            return DefaultPathSegment.from(segment, valueToMatch);\n        }\n        else {\n            const valueToMatch = decodeURIComponent(segment.substring(0, paramsIndex));\n            const pathParameterContent = segment.substring(paramsIndex);\n            const parameters = DefaultPathContainer.#parsePathParameters(pathParameterContent);\n            return DefaultPathSegment.from(segment, valueToMatch, parameters);\n        }\n    }\n\n    static #parsePathParameters(content: string): Map<string, readonly string[]> {\n        const parameters: Map<string, string[]> = new Map<string, string[]>();\n        let start = 1; // skip initial ';'\n        while (start < content.length) {\n            let end = -1;\n            for (let i = start; i < content.length; i++) {\n                if (content.charAt(i) === ';') {\n                    end = i;\n                    break;\n                }\n            }\n            const parameter = (end !== -1) ? content.substring(start, end) : content.substring(start);\n            DefaultPathContainer.#parsePathParameterValue(parameter, parameters);\n            if (end === -1) {\n                break;\n            }\n            start = end + 1;\n        }\n        if (parameters.size > 0) {\n            // freeze all value arrays and the map itself for runtime immutability\n            for (const values of parameters.values()) {\n                Object.freeze(values);\n            }\n        }\n        return parameters;\n    }\n\n    static #parsePathParameterValue(input: string, output: Map<string, string[]>): void {\n        if (input) {\n            const eqIndex = input.indexOf('=');\n            if (eqIndex !== -1) {\n                const name = decodeURIComponent(input.substring(0, eqIndex));\n                if (name.trim()) {\n                    const value = input.substring(eqIndex + 1);\n                    for (const v of value.split(',')) {\n                        const values = output.get(name);\n                        if (values !== undefined) {\n                            values.push(decodeURIComponent(v));\n                        }\n                        else {\n                            output.set(name, [decodeURIComponent(v)]);\n                        }\n                    }\n                }\n            }\n            else {\n                const name = decodeURIComponent(input);\n                if (name.trim()) {\n                    const values = output.get(name);\n                    if (values !== undefined) {\n                        values.push('');\n                    }\n                    else {\n                        output.set(name, ['']);\n                    }\n                }\n            }\n        }\n    }\n}\n\nclass DefaultPathSegment implements PathSegment {\n    static readonly #EMPTY_PARAMS: ReadonlyMap<string, readonly string[]> = new Map<string, readonly string[]>();\n\n    static from(value: string, separatorOrValueToMatch: string | DefaultSeparator, parameters?: Map<string, readonly string[]>): PathSegment {\n        if (typeof separatorOrValueToMatch === 'string') {\n            const valueToMatch = separatorOrValueToMatch;\n            return new DefaultPathSegment(value, valueToMatch, parameters);\n        }\n        else {\n            const separator = separatorOrValueToMatch;\n            const valueToMatch = (value.includes(separator.encoded)) ? value.replaceAll(separator.encoded, separator.value) : value;\n            return DefaultPathSegment.from(value, valueToMatch, parameters);\n        }\n    }\n\n    readonly #value: string;\n    readonly #valueToMatch: string;\n    readonly #parameters: ReadonlyMap<string, readonly string[]>;\n\n    constructor(value: string, valueToMatch: string, parameters: ReadonlyMap<string, readonly string[]> = DefaultPathSegment.#EMPTY_PARAMS) {\n        this.#value = value;\n        this.#valueToMatch = valueToMatch;\n        this.#parameters = parameters;\n    }\n\n    get value(): string {\n        return this.#value;\n    }\n\n    get valueToMatch(): string {\n        return this.#valueToMatch;\n    }\n\n    get parameters(): ReadonlyMap<string, readonly string[]> {\n        return this.#parameters;\n    }\n\n}\n", "import type { ReadonlyHttpHeaders } from '../../../types/web/http';\nimport type { RequestPath, SslInfo } from '../../../types/web/server';\nimport type { PathContainer } from '../../../types/path';\nimport { AbstractHttpRequest } from '../exchange.ts';\nimport { parsePath, subPath } from './path.ts';\n\nexport function parseRequestPath(uri: string | URL, contextPath?: string) {\n    if (typeof uri === 'string') {\n        return DefaultRequestPath.parse(uri, contextPath);\n    }\n    else {\n        return parseRequestPath(uri.href, contextPath);\n    }\n}\n\nclass DefaultRequestPath implements RequestPath {\n\n    static #initContextPath(path: PathContainer, contextPath?: string): PathContainer {\n        if (!(contextPath && contextPath.trim()) || contextPath.charAt(0) !== '/') {\n            return parsePath('');\n        }\n\n        DefaultRequestPath.#validateContextPath(path.value, contextPath);\n\n        const length = contextPath.length;\n        let counter = 0;\n\n        for (let i = 0; i < path.elements.length; i++) {\n            const element = path.elements[i];\n            counter += element.value.length;\n            if (length === counter) {\n                return subPath(path, 0, i + 1);\n            }\n        }\n\n        // should not reach here\n        throw new Error(`Failed to initialize context path: '${contextPath}' for request path: '${path.value}'`);\n    }\n\n    static #validateContextPath(fullPath: string, contextPath: string): void {\n        const length = contextPath.length;\n        if (contextPath.charAt(0) !== '/' || contextPath.charAt(length - 1) === '/') {\n            throw new Error(`Invalid context path: '${contextPath}'. Context path must start with '/' and must not end with '/'`);\n        }\n        if (!fullPath.startsWith(contextPath)) {\n            throw new Error(`Invalid context path: '${contextPath}'. Context path must be a prefix of request path: '${fullPath}'`);\n        }\n        if (fullPath.length > length && fullPath.charAt(length) !== '/') {\n            throw new Error(`Invalid context path: '${contextPath}'. Context path must match to full path segments for request path: '${fullPath}'`);\n        }\n    }\n\n    static #extractPathWithinApplication(fullPath: PathContainer, contextPath: PathContainer): PathContainer {\n        const contextPathLength = contextPath.elements.length;\n        return subPath(fullPath, contextPathLength);\n    }\n\n    static parse(rawPath: string, contextPath?: string) {\n        const fullPath = parsePath(rawPath);\n        const contextPathContainer = DefaultRequestPath.#initContextPath(fullPath, contextPath);\n        const pathWithinApplication = DefaultRequestPath.#extractPathWithinApplication(fullPath, contextPathContainer);\n        return new DefaultRequestPath(\n            parsePath(rawPath),\n            contextPathContainer,\n            pathWithinApplication\n        )\n    }\n\n    readonly #fullPath: PathContainer;\n    readonly #contextPath: PathContainer;\n    readonly #pathWithinApplication: PathContainer;\n\n    private constructor(fullPath: PathContainer, contextPath: PathContainer, pathWithinApplication: PathContainer) {\n        this.#fullPath = fullPath;\n        this.#contextPath = contextPath;\n        this.#pathWithinApplication = pathWithinApplication;\n    }\n\n    // path container\n    get value() {\n        return this.#fullPath.value;\n    }\n\n    get elements() {\n        return this.#fullPath.elements;\n    }\n\n    // request path\n    get contextPath() {\n        return this.#contextPath;\n    }\n\n    get pathWithinApplication() {\n        return this.#pathWithinApplication;\n    }\n\n    modifyContextPath(contextPath: string): RequestPath {\n        const contextPathContainer = DefaultRequestPath.#initContextPath(this, contextPath);\n        const pathWithinApplication = DefaultRequestPath.#extractPathWithinApplication(this, contextPathContainer);\n        return new DefaultRequestPath(\n            this,\n            contextPathContainer,\n            pathWithinApplication\n        );\n    }\n\n    toString(): string {\n        return this.#fullPath.toString();\n    }\n}\n\nexport abstract class AbstractServerHttpRequest extends AbstractHttpRequest<ReadonlyHttpHeaders> {\n    #sslInfo?: SslInfo\n    #path?: RequestPath\n    #contextPath?: string;\n\n    abstract getNativeRequest<T>(): T;\n\n    get requestPath(): RequestPath {\n        if (this.#path === undefined) {\n            this.#path = parseRequestPath(this.URL.pathname, this.#contextPath)\n        }\n        return this.#path;\n    }\n\n    protected abstract initSslInfo(): SslInfo | undefined;\n\n    get sslInfo(): SslInfo | undefined {\n        if (this.#sslInfo === undefined) {\n            this.#sslInfo = this.initSslInfo();\n        }\n        return this.#sslInfo;\n    }\n}\n", "import getLogger from '../logger.ts';\nimport { getHeapStatistics, writeHeapSnapshot, type HeapInfo } from 'node:v8';\nimport type { PathLike } from 'node:fs';\nimport { access, mkdir, rename, unlink } from 'node:fs/promises';\n\nconst log = getLogger('monitoring');\n\nexport type Options = typeof DEFAULT_OPTIONS;\n\nexport type Command = 'run' | 'dump' | 'stop';\nexport type Channel = (command?: Command) => Promise<boolean>;\n\nconst DEFAULT_OPTIONS = {\n    memoryLimit: 1024 * 1024 * 1024, // 1GB\n    reportInterval: 10 * 60 * 1000, // 10 min\n    dumpLocation: '.', // current folder\n    maxBackups: 10,\n    dumpPrefix: 'Heap'\n}\n\nfunction fetchStats(): HeapInfo {\n    return getHeapStatistics();\n}\n\nasync function dumpHeap(opts: Options) {\n    const prefix = opts.dumpPrefix ?? 'Heap';\n    const target = `${opts.dumpLocation}/${prefix}.heapsnapshot`;\n    if (log.enabledFor('debug')) {\n        log.debug(`starting heap dump in ${target}`);\n    }\n\n    await fileExists(opts.dumpLocation)\n        .catch(async (_) => {\n            if (log.enabledFor('debug')) {\n                log.debug(`dump location  ${opts.dumpLocation} does not exists. Will try to create it`);\n            }\n            try {\n                await mkdir(opts.dumpLocation, {recursive: true});\n                log.info(`dump location dir ${opts.dumpLocation} successfully created`);\n            } catch (e) {\n                log.error(`failed to create dump location ${opts.dumpLocation}`);\n            }\n        });\n    const dumpFileName = writeHeapSnapshot(target);\n    log.info(`heap dumped`);\n    try {\n        log.debug(`rolling snapshot backups`);\n        const lastFileName = `${opts.dumpLocation}/${prefix}.${opts.maxBackups}.heapsnapshot`;\n        await fileExists(lastFileName)\n            .then(async () => {\n                if (log.enabledFor('debug')) {\n                    log.debug(`deleting ${lastFileName}`);\n                }\n                try {\n                    await unlink(lastFileName);\n                } catch (e) {\n                    log.warn(`failed to delete ${lastFileName}`, e);\n                }\n            })\n            .catch(() => {\n                /* do nothing*/\n            });\n        for (let i = opts.maxBackups - 1; i > 0; i--) {\n            const currentFileName = `${opts.dumpLocation}/${prefix}.${i}.heapsnapshot`;\n            const nextFileName = `${opts.dumpLocation}/${prefix}.${i + 1}.heapsnapshot`;\n            await fileExists(currentFileName)\n                .then(async () => {\n                    try {\n                        await rename(currentFileName, nextFileName);\n                    } catch (e) {\n                        log.warn(`failed to rename ${currentFileName} to ${nextFileName}`, e);\n                    }\n                })\n                .catch(() => {\n                    /* do nothing*/\n                });\n        }\n        const firstFileName = `${opts.dumpLocation}/${prefix}.${1}.heapsnapshot`;\n        try {\n            await rename(dumpFileName, firstFileName);\n        } catch (e) {\n            log.warn(`failed to rename ${dumpFileName} to ${firstFileName}`, e);\n        }\n        log.debug('snapshots rolled');\n    } catch (e) {\n        log.error('error rolling backups', e);\n        throw e;\n    }\n}\n\nasync function fileExists(path: PathLike): Promise<void> {\n    if (log.enabledFor('trace')) {\n        log.debug(`checking file ${path}`);\n    }\n    await access(path);\n}\n\nasync function processStats(stats: HeapInfo, state: {\n    memoryLimitExceeded: boolean,\n    snapshot?: boolean\n}, opts: Options) {\n    if (log.enabledFor('debug')) {\n        log.debug(`processing heap stats ${JSON.stringify(stats)}`);\n    }\n    const limit = Math.min(opts.memoryLimit, (0.95 * stats.heap_size_limit));\n    const used = stats.used_heap_size;\n    log.info(`heap stats ${JSON.stringify(stats)}`);\n    if (used >= limit) {\n        log.warn(`used heap ${used} bytes exceeds memory limit ${limit} bytes`);\n        if (state.memoryLimitExceeded) {\n            delete state.snapshot;\n        } else {\n            state.memoryLimitExceeded = true;\n            state.snapshot = true;\n        }\n        await dumpHeap(opts);\n    } else {\n        state.memoryLimitExceeded = false;\n        delete state.snapshot;\n    }\n}\n\nexport function start(opts?: Partial<Options>): Options & { channel: Channel } {\n    const merged: Options = {...DEFAULT_OPTIONS, ...opts};\n\n    let stopped = false;\n    const state = {memoryLimitExceeded: false};\n    const report = async () => {\n        const stats = fetchStats();\n        await processStats(stats, state, merged);\n    }\n    const interval = setInterval(report, merged.reportInterval);\n    const channel = async (command?: Command) => {\n        if (!stopped) {\n            command ??= 'run';\n            switch (command) {\n                case 'run': {\n                    await report();\n                    break;\n                }\n                case 'dump': {\n                    await dumpHeap(merged);\n                    break;\n                }\n                case 'stop': {\n                    stopped = true;\n                    clearInterval(interval);\n                    log.info('exit memory diagnostic');\n                    break;\n                }\n            }\n\n        }\n        return stopped;\n    }\n\n    return {...merged, channel};\n}\n\nasync function run({channel}: { channel: Channel }, command?: Command) {\n    if (!await channel(command)) {\n        log.warn(`cannot execute command \"${command}\" already closed`)\n    }\n}\n\n\nexport async function stop(m: { channel: Channel }) {\n    return await run(m, 'stop');\n}\n", "import type {ServerWebExchange} from '../../types/web/server';\n\nconst serverHeader = (version: string, server?: string | false) => {\n    server ??= version;\n    return async ({ response }: ServerWebExchange, next: () => Promise<void>) => {\n        if (server !== false && !response.headers.has('server')) {\n            response.headers.set('Server', server);\n        }\n        await next();\n    }\n};\n\nexport default (version: string, server?: string | false) => serverHeader(version, server);\n", "import { IOGateway } from '@interopio/gateway';\nimport type { OriginFilters } from '../../types/web/server';\nimport getLogger from '../logger.ts';\n\nconst log = getLogger('gateway.ws.client-verify');\n\nexport type ProcessedOriginFilters\n    = Required<Omit<OriginFilters, 'blacklist' | 'whitelist'>>\n    //| Required<Omit<GatewayServer.OriginFilters, 'block' | 'allow'>>\n    ;\n\nfunction acceptsMissing(originFilters: ProcessedOriginFilters): boolean {\n    switch (originFilters.missing) {\n        case 'allow': // fall-through\n        case 'whitelist':\n            return true;\n        case 'block': // fall-through\n        case 'blacklist':\n            return false;\n        default:\n            return false;\n    }\n}\n\nfunction tryMatch(originFilters: ProcessedOriginFilters, origin: string): boolean | undefined {\n    const block = originFilters.block ?? originFilters['blacklist'];\n    const allow = originFilters.allow ?? originFilters['whitelist'];\n    if (block.length > 0 && IOGateway.Filtering.valuesMatch(block, origin)) {\n        log.warn(`origin ${origin} matches block filter`);\n        return false;\n    } else if (allow.length > 0 && IOGateway.Filtering.valuesMatch(allow, origin)) {\n        if (log.enabledFor('debug')) {\n            log.debug(`origin ${origin} matches allow filter`);\n        }\n        return true;\n    }\n}\n\nfunction acceptsNonMatched(originFilters: ProcessedOriginFilters): boolean {\n    switch (originFilters.non_matched) {\n        case 'allow': // fall-through\n        case 'whitelist':\n            return true;\n        case 'block': // fall-through\n        case 'blacklist':\n            return false;\n        default:\n            return false;\n    }\n}\n\nexport function acceptsOrigin(origin?: string, originFilters?: ProcessedOriginFilters): boolean {\n    if (!originFilters) {\n        return true;\n    }\n    if (!origin) {\n        return acceptsMissing(originFilters);\n    } else {\n        const matchResult: boolean | undefined = tryMatch(originFilters, origin);\n        if (matchResult) {\n            return matchResult;\n        } else {\n            return acceptsNonMatched(originFilters);\n        }\n    }\n}\n\nexport function regexifyOriginFilters(originFilters?: OriginFilters): ProcessedOriginFilters | undefined {\n    if (originFilters) {\n        const block = (originFilters.block ?? originFilters.blacklist ?? []).map(IOGateway.Filtering.regexify);\n        const allow = (originFilters.allow ?? originFilters.whitelist ?? []).map(IOGateway.Filtering.regexify);\n        return {\n            non_matched: originFilters.non_matched ?? 'allow',\n            missing: originFilters.missing ?? 'allow',\n            allow,\n            block,\n        }\n    }\n}\n", "import type {ServerWebExchange} from '../../../types/web/server';\n\nexport type MatchResult = Readonly<{ match: boolean, variables: Readonly<Record<string, string>> }>;\n\nexport interface ServerWebExchangeMatcher {\n    /**\n     * Matches the given exchange against the matcher.\n     * @param exchange The web exchange to match.\n     * @returns A promise that resolves to true if the exchange matches, false otherwise.\n     */\n    (exchange: ServerWebExchange): Promise<MatchResult>;\n\n    /**\n     * Returns a string representation of the matcher.\n     * @returns A string representation of the matcher.\n     */\n    toString(): string;\n}\n\nexport type ServerWebExchangeMatcherEntry<T> = Readonly<[ServerWebExchangeMatcher, T]>\n\nexport const or: (matchers: ServerWebExchangeMatcher[]) => ServerWebExchangeMatcher = (matchers: ServerWebExchangeMatcher[]): ServerWebExchangeMatcher => {\n    return async (exchange: ServerWebExchange): Promise<MatchResult> => {\n        for (const matcher of matchers) {\n            const result = await matcher(exchange);\n            if (result.match) {\n                return match();\n            }\n        }\n        return NO_MATCH;\n    };\n}\n\nexport const and: (matchers: ServerWebExchangeMatcher[]) => ServerWebExchangeMatcher = (matchers: ServerWebExchangeMatcher[])  => {\n    const matcher = async (exchange: ServerWebExchange): Promise<MatchResult> => {\n        for (const matcher of matchers) {\n            const result = await matcher(exchange);\n            if (!result.match) {\n                return NO_MATCH;\n            }\n        }\n        return match();\n    };\n    matcher.toString = () => `and(${matchers.map(m => m.toString()).join(', ')})`;\n    return matcher;\n}\n\n\nexport const not: (matcher: ServerWebExchangeMatcher) => ServerWebExchangeMatcher = (matcher: ServerWebExchangeMatcher): ServerWebExchangeMatcher => {\n    return async (exchange: ServerWebExchange): Promise<MatchResult> => {\n        const result = await matcher(exchange);\n        return result.match ? NO_MATCH : match();\n    };\n}\n\nexport const anyExchange: ServerWebExchangeMatcher = async (_exchange: ServerWebExchange): Promise<MatchResult> => {\n    return match();\n}\nanyExchange.toString = () => 'any-exchange';\n\nconst EMPTY_OBJECT = Object.freeze({});\nexport const NO_MATCH: MatchResult = Object.freeze({match: false, variables: EMPTY_OBJECT});\nexport const match = (variables: Record<string, string> = EMPTY_OBJECT): MatchResult => {\n    return { match: true, variables };\n}\n\nexport const pattern: ((pattern: string | RegExp, opts?: {method?: string}) => ServerWebExchangeMatcher) = (pattern, opts) => {\n    const method = opts?.method;\n    const matcher = async (exchange: ServerWebExchange): Promise<MatchResult> => {\n        const request = exchange.request;\n        const path = request.path;\n        if (method !== undefined && request.method !== method) {\n            return NO_MATCH;\n        }\n        if (typeof pattern === 'string') {\n            if (path === pattern) {\n                return match();\n            }\n            return NO_MATCH;\n        }\n        else {\n            const match = pattern.exec(path);\n            if (match === null) {\n                return NO_MATCH;\n            }\n            return {match: true, variables: {...match.groups}};\n        }\n    };\n    matcher.toString = () => {\n        return `pattern(${pattern.toString()}, method=${method ?? '<any>'})`;\n    }\n    return matcher\n\n}\nexport const mediaType : ((opts: { mediaTypes: string[], ignoredMediaTypes?: string[], useEquality?: boolean }) => ServerWebExchangeMatcher) = (opts): ServerWebExchangeMatcher => {\n\n    const shouldIgnore = (requestedMediaType: string): boolean => {\n        if (opts.ignoredMediaTypes !== undefined) {\n            for (const ignoredMediaType of opts.ignoredMediaTypes) {\n                if (requestedMediaType === ignoredMediaType || ignoredMediaType === '*/*') {\n                    return true;\n                }\n            }\n        }\n        return false;\n    }\n\n    return async (exchange: ServerWebExchange): Promise<MatchResult> => {\n        const request = exchange.request;\n        let requestMediaTypes: string[];\n        try {\n            requestMediaTypes = request.headers.list('accept');\n        }\n        catch (e) {\n            return NO_MATCH;\n        }\n        for (const requestedMediaType of requestMediaTypes) {\n            if (shouldIgnore(requestedMediaType)) {\n                continue;\n            }\n            for (const mediaType of opts.mediaTypes) {\n                if (requestedMediaType.startsWith(mediaType)) {\n                    return match();\n                }\n            }\n        }\n\n        return NO_MATCH;\n    };\n}\n\nexport const upgradeMatcher: ServerWebExchangeMatcher = async ({request}: ServerWebExchange): Promise<MatchResult> => {\n    const upgrade = request.upgrade && request.headers.one('upgrade')?.toLowerCase() === 'websocket';\n    return upgrade ? match() : NO_MATCH;\n};\nupgradeMatcher.toString = () => 'websocket upgrade';\n", "import { regexifyOriginFilters } from '../server/ws-client-verify.ts';\nimport type { SecurityContext } from '../server/security/security-context.ts';\nimport { pattern, type ServerWebExchangeMatcher } from '../server/util/matchers.ts';\nimport type { Middleware } from '../server/types.ts';\nimport type { AsyncLocalStorage } from 'node:async_hooks';\nimport type { SocketRoute } from '../server/socket.ts';\nimport type { ServerConfig, ServerCustomizer } from '../../types/config';\nimport type {\n    ServerConfigurer,\n    ServerConfigurerHandlerSpec,\n    ServerConfigurerSocketSpec,\n    ServerExchangeOptions,\n    ServerWebExchange\n} from '../../types/web/server';\nimport type { AuthorizationRule } from '../../types/auth';\nimport { IOGateway } from '@interopio/gateway';\nimport type { CorsConfig } from '../web/cors/types.ts';\n\nexport type PathPattern = string | RegExp;\nexport type RouteConfig = Readonly<{\n    readonly storage: AsyncLocalStorage<{\n        exchange: ServerWebExchange,\n        securityContext?: Promise<SecurityContext>\n    }>,\n    readonly serverHeader?: string | false\n    readonly corsConfig?: ServerConfig['cors'],\n    readonly authConfig?: ServerConfig['auth'],\n    readonly middleware: Middleware,\n    readonly cors: Array<[PathPattern, CorsConfig | undefined]>,\n    readonly authorize: Array<[ServerWebExchangeMatcher, AuthorizationRule]>\n    readonly sockets: Map<string, SocketRoute>\n    readonly resourcesConfig?: ServerConfig['resources']\n}>\n\nexport async function configure(app: ServerCustomizer, config: ServerConfig, routes: RouteConfig): Promise<void> {\n    const applyCors = (request: ServerConfigurerHandlerSpec['request'], options?: ServerExchangeOptions) => {\n        // // disable CORS for this route\n        // if (options?.cors === false) {\n        //     const path = request.path as (PathPattern);\n        //     routes.cors.push([request.path, undefined]);\n        // }\n        if (options?.cors) {\n            const cors: CorsConfig = options.cors === true ? {\n                allowOrigins: options.origins?.allow?.map(IOGateway.Filtering.regexify),\n                allowMethods: request.method === undefined ? ['*'] : [request.method],\n                allowCredentials: options.authorize?.access !== 'permitted' ? true : undefined,\n            } : options.cors;\n            const path = request.path as (PathPattern);\n            routes.cors.push([path, cors]);\n        }\n    }\n\n    const configurer = new class implements ServerConfigurer {\n\n        handle(...handlers: Array<ServerConfigurerHandlerSpec>) {\n            handlers.forEach(({request, options, handler}) => {\n                const matcher = pattern(IOGateway.Filtering.regexify(request.path) as string | RegExp, {method: request.method});\n                if (options?.authorize) {\n                    routes.authorize.push([matcher, options.authorize]);\n                }\n\n                applyCors(request, options);\n                const middleware = async (exchange: ServerWebExchange, next: () => Promise<void>): Promise<void> => {\n                    const {match, variables} = await matcher(exchange);\n                    if (match) {\n                        await handler(exchange, variables);\n                    } else {\n                        await next();\n                    }\n                };\n                routes.middleware.push(middleware);\n            });\n        }\n\n        socket(...sockets: Array<ServerConfigurerSocketSpec>) {\n            for (const {path, factory, options} of sockets) {\n                const route = path ?? '/';\n\n                // cors and authorize are currently handled for ws\n                routes.sockets.set(route, {\n                    default: path === undefined || path === '/',\n                    ping: options?.ping,\n                    factory: factory,\n                    maxConnections: options?.maxConnections,\n                    authorize: options?.authorize,\n                    originFilters: regexifyOriginFilters(options?.origins)\n                });\n            }\n        }\n    };\n    await app(configurer, config);\n}\n", "import type { ServerWebExchangeMatcher } from './util/matchers.ts';\nimport { HttpStatus } from '../http/status.ts';\nimport getLogger from '../logger.ts';\nimport type { HttpRequest, ReadonlyHttpHeaders } from '../../types/web/http';\nimport type { ServerHttpResponse, ServerWebExchange } from '../../types/web/server';\nimport { IOGateway } from '@interopio/gateway';\nimport type { CorsConfig, CorsConfigSource, CorsProcessor } from '../web/cors/types.ts';\nimport { isCorsRequest, isPreFlightRequest } from '../web/cors/utils.ts';\nimport type { WebFilterChain } from '../web/server/types.ts';\n\nconst VARY_HEADERS: readonly string[] = ['Origin', 'Access-Control-Request-Method', 'Access-Control-Request-Headers'];\n\n/**\n * Processes a request given a {@link CorsConfig}.\n *\n * @param exchange the current exchange\n * @param config the CORS configuration to use, possibly `undefined` in which case pre-flight requests are rejected, but all others allowed\n * @returns `false` if the request is rejected, `true` otherwise\n */\nexport const processRequest: CorsProcessor = (exchange: ServerWebExchange, config?: CorsConfig): boolean => {\n    const {request, response} = exchange;\n    const responseHeaders = response.headers;\n\n    if (!responseHeaders.has('Vary')) {\n        responseHeaders.set('Vary', VARY_HEADERS.join(', '));\n    }\n    else {\n        const varyHeaders = responseHeaders.list('Vary');\n        for (const header of VARY_HEADERS) {\n            if (!varyHeaders.find(h => h === header)) {\n                varyHeaders.push(header);\n            }\n        }\n        responseHeaders.set('Vary', varyHeaders.join(', '));\n    }\n\n    try {\n        if (!isCorsRequest(request)) {\n            return true;\n        }\n    }\n    catch (e) {\n        if(logger.enabledFor('debug')) {\n            logger.debug(`reject: origin is malformed`);\n        }\n        rejectRequest(response);\n        return false;\n    }\n\n    if (responseHeaders.has('access-control-allow-origin')) {\n        if (logger.enabledFor('trace')) {\n            logger.debug(`skip: already contains \"Access-Control-Allow-Origin\"`);\n        }\n        return true;\n    }\n\n    const preFlightRequest = isPreFlightRequest(request);\n\n    if (config) {\n        return handleInternal(exchange, config, preFlightRequest);\n    }\n    if (preFlightRequest) {\n        rejectRequest(response);\n        return false;\n    }\n    return true;\n}\n\nconst DEFAULT_PERMIT_ALL = ['*'];\nconst DEFAULT_PERMIT_METHODS = ['GET', 'HEAD', 'POST'];\nexport const PERMIT_DEFAULT_CONFIG: CorsConfig = {\n    allowOrigins: DEFAULT_PERMIT_ALL,\n    allowMethods: DEFAULT_PERMIT_METHODS,\n    allowHeaders: DEFAULT_PERMIT_ALL,\n    maxAge: 1800 // 30 minutes\n}\nexport /*testing*/ function validateCorsConfig(config?: CorsConfig): CorsConfig | undefined {\n    if (config) {\n        const allowHeaders = config.allowHeaders;\n        if (allowHeaders && allowHeaders !== ALL) {\n            config = {\n                ...config,\n                allowHeaders: allowHeaders.map(header => header.toLowerCase())\n            };\n        }\n        const allowOrigins = config.allowOrigins;\n        if (allowOrigins) {\n            if (allowOrigins === '*') {\n                validateAllowCredentials(config);\n                validateAllowPrivateNetwork(config);\n            }\n            else {\n                config = {\n                    ...config,\n                    allowOrigins: allowOrigins.map(origin => {\n                        if (typeof origin === 'string' && origin !== ALL) {\n                            origin = IOGateway.Filtering.regexify(origin);\n                            if (typeof origin === 'string') {\n                                // exact match\n                                return trimTrailingSlash(origin).toLowerCase();\n                            }\n                        }\n                        return origin;\n                    })\n                };\n            }\n        }\n        return config;\n    }\n}\n\nfunction combine<T = (string | IOGateway.Filtering.Matcher)>(source?: '*' | T[], other?: '*' | T[]): T[] | undefined {\n    if (other === undefined) {\n        return source !== undefined ? (source === ALL ? [ALL as T] : source) : [];\n    }\n    if (source === undefined) {\n        return other === ALL ? [ALL as T] : other;\n    }\n    if (source == DEFAULT_PERMIT_ALL || source === DEFAULT_PERMIT_METHODS) {\n        return other === ALL ? [ALL as T] : other;\n    }\n    if (other == DEFAULT_PERMIT_ALL || other === DEFAULT_PERMIT_METHODS) {\n        return source === ALL ? [ALL as T] : source;\n    }\n    if (source === ALL || source.includes(ALL as T) || other === ALL || other.includes(ALL as T)) {\n        return [ALL as T];\n    }\n    const combined = new Set<T>();\n    source.forEach((v) => combined.add(v));\n    other.forEach((v) => combined.add(v));\n    return Array.from(combined);\n}\nexport const combineCorsConfig = (source: CorsConfig, other?: CorsConfig): CorsConfig => {\n    if (other === undefined) {\n        return source;\n    }\n    const config: CorsConfig = {\n        allowOrigins: combine(source.allowOrigins, other?.allowOrigins),\n        allowMethods: combine(source.allowMethods, other?.allowMethods),\n        allowHeaders: combine(source.allowHeaders, other?.allowHeaders),\n        exposeHeaders: combine(source.exposeHeaders, other?.exposeHeaders),\n        allowCredentials: other?.allowCredentials ?? source.allowCredentials,\n        allowPrivateNetwork: other?.allowPrivateNetwork ?? source.allowPrivateNetwork,\n        maxAge: other?.maxAge ?? source.maxAge\n    }\n    return config;\n\n}\n\nconst corsFilter = (opts: {corsConfigSource: CorsConfigSource, corsProcessor?: CorsProcessor}) => {\n    const source = opts.corsConfigSource;\n    const processor = opts.corsProcessor ?? processRequest;\n    if (source === undefined) {\n        throw new Error('corsConfigSource is required');\n    }\n    if (processor === undefined) {\n        throw new Error('corsProcessor is required');\n    }\n    return {\n        filter: async (ctx: ServerWebExchange, chain: WebFilterChain) => {\n            const config = await source(ctx);\n            const isValid = processor(ctx, config);\n            if (!isValid || isPreFlightRequest(ctx.request)) {\n                return;\n            }\n            else {\n                await chain.filter(ctx);\n            }\n        }\n    };\n}\n\nexport default corsFilter;\n\n\nconst logger = getLogger('cors');\n\nfunction rejectRequest(response: ServerHttpResponse) {\n    response.setStatusCode(HttpStatus.FORBIDDEN);\n}\n\nfunction handleInternal(exchange: ServerWebExchange,\n                        config: CorsConfig, preFlightRequest: boolean): boolean {\n    const {request, response} = exchange;\n    const responseHeaders = response.headers;\n\n    const requestOrigin = request.headers.one('origin');\n    const allowOrigin = checkOrigin(config, requestOrigin);\n\n    if (allowOrigin === undefined) {\n        if (logger.enabledFor('debug')) {\n            logger.debug(`reject: '${requestOrigin}' origin is not allowed`);\n        }\n        rejectRequest(response);\n        return false;\n    }\n\n    const requestMethod = getMethodToUse(request, preFlightRequest);\n    const allowMethods = checkMethods(config, requestMethod);\n    if (allowMethods === undefined) {\n        if (logger.enabledFor('debug')) {\n            logger.debug(`reject: HTTP '${requestMethod}' is not allowed`);\n        }\n        rejectRequest(response);\n        return false;\n    }\n\n    const requestHeaders = getHeadersToUse(request, preFlightRequest);\n    const allowHeaders = checkHeaders(config, requestHeaders);\n    if (preFlightRequest && allowHeaders === undefined) {\n        if (logger.enabledFor('debug')) {\n            logger.debug(`reject: headers '${requestHeaders}' are not allowed`);\n        }\n        rejectRequest(response);\n        return false;\n    }\n\n    responseHeaders.set('Access-Control-Allow-Origin', allowOrigin);\n\n    if (preFlightRequest) {\n        responseHeaders.set('Access-Control-Allow-Methods', allowMethods.join(','));\n\n    }\n    if (preFlightRequest && allowHeaders !== undefined && allowHeaders.length  > 0) {\n        responseHeaders.set('Access-Control-Allow-Headers', allowHeaders.join(', '));\n    }\n    const exposeHeaders = config.exposeHeaders;\n    if (exposeHeaders && exposeHeaders.length > 0) {\n        responseHeaders.set('Access-Control-Expose-Headers', exposeHeaders.join(', '));\n    }\n    if (config.allowCredentials) {\n        responseHeaders.set('Access-Control-Allow-Credentials', 'true');\n    }\n    if (config.allowPrivateNetwork && request.headers.one('access-control-request-private-network') === 'true') {\n        responseHeaders.set('Access-Control-Allow-Private-Network', 'true');\n    }\n\n    if (preFlightRequest && config.maxAge !== undefined) {\n        responseHeaders.set('Access-Control-Max-Age', config.maxAge.toString());\n    }\n    return true;\n}\n\nconst ALL = '*';\nconst DEFAULT_METHODS = ['GET', 'HEAD'];\n\nfunction validateAllowCredentials(config: CorsConfig) {\n    if (config.allowCredentials === true && config.allowOrigins === ALL) {\n        throw new Error(`when allowCredentials is true allowOrigins cannot be \"*\"`);\n    }\n}\n\nfunction validateAllowPrivateNetwork(config: CorsConfig) {\n    if (config.allowPrivateNetwork === true && config.allowOrigins === ALL) {\n        throw new Error(`when allowPrivateNetwork is true allowOrigins cannot be \"*\"`);\n    }\n}\n\nfunction checkOrigin(config: CorsConfig, origin? :string): string | undefined {\n    if (origin) {\n        const allowedOrigins = config.allowOrigins;\n        if (allowedOrigins) {\n            if (allowedOrigins === ALL) {\n                validateAllowCredentials(config);\n                validateAllowPrivateNetwork(config);\n                return ALL;\n            }\n            const originToCheck = trimTrailingSlash(origin.toLowerCase());\n\n            for (const allowedOrigin of allowedOrigins) {\n                if ((allowedOrigin ===  ALL) || IOGateway.Filtering.valueMatches(allowedOrigin, originToCheck)) {\n                    return origin;\n                }\n            }\n        }\n    }\n}\n\nfunction checkMethods(config: CorsConfig, requestMethod?: string): string[] | undefined {\n    if (requestMethod) {\n        const allowedMethods = config.allowMethods ?? DEFAULT_METHODS;\n        if (allowedMethods === ALL) {\n            return [requestMethod];\n        }\n        if (IOGateway.Filtering.valuesMatch(allowedMethods, requestMethod)) {\n            return allowedMethods;\n        }\n    }\n}\n\nfunction checkHeaders(config: CorsConfig, requestHeaders?: string[]): string[] | undefined {\n    if (requestHeaders === undefined) {\n        return;\n    }\n    if (requestHeaders.length == 0) {\n        return [];\n    }\n    const allowedHeaders = config.allowHeaders;\n    if (allowedHeaders === undefined) {\n        return;\n    }\n    const allowAnyHeader = allowedHeaders === ALL || allowedHeaders.includes(ALL);\n    const result: string[] = [];\n    for (const requestHeader of requestHeaders) {\n        const value = requestHeader?.trim();\n        if (value) {\n            if (allowAnyHeader) {\n                result.push(value);\n            }\n            else {\n                for (const allowedHeader of allowedHeaders) {\n                    if (value.toLowerCase() === allowedHeader) {\n                        result.push(value);\n                        break;\n                    }\n                }\n            }\n        }\n    }\n    if (result.length > 0) {\n        return result;\n    }\n}\n\nfunction trimTrailingSlash(origin: string): string {\n    return origin.endsWith('/') ? origin.slice(0, -1) : origin;\n}\n\nfunction getMethodToUse(request: HttpRequest<ReadonlyHttpHeaders>, isPreFlight: boolean): string | undefined {\n    return (isPreFlight ? request.headers.one('access-control-request-method') : request.method);\n}\n\nfunction getHeadersToUse(request: HttpRequest, isPreFlight: boolean): string[] {\n    const headers = request.headers;\n    return (isPreFlight ? headers.list('access-control-request-headers') : Array.from(headers.keys()));\n}\n\nexport const matchingCorsConfigSource = (opts: {mappings: Array<[ServerWebExchangeMatcher, CorsConfig | undefined]>}): CorsConfigSource => {\n    return async (exchange: ServerWebExchange) => {\n        for (const [matcher, config] of opts.mappings) {\n            if ((await matcher(exchange)).match) {\n                logger.debug(`resolved cors config on '${exchange.request.path}' using ${matcher}: ${JSON.stringify(config)}`);\n                return config;\n            }\n        }\n    }\n}\n", "import type { HttpRequest, ReadonlyHttpHeaders } from '../../../types/web/http';\n\nfunction isSameOrigin(request: HttpRequest<ReadonlyHttpHeaders>) {\n    const origin = request.headers.one('origin');\n    if (origin === undefined) {\n        return true;\n    }\n    const url = request.URL;\n    const actualProtocol = url.protocol;\n    const actualHost = url.host;\n\n    const originUrl = URL.parse(origin); // URL.parse requires Node.js 20.18 || 22.1\n\n    const originHost = originUrl?.host;\n    const originProtocol = originUrl?.protocol;\n    return actualProtocol === originProtocol\n        && actualHost === originHost;\n}\n\n/**\n * Returns `true` if the request is a valid CORS one by checking `Origin` header presence and ensuring origins differ.\n */\nexport function isCorsRequest(request: HttpRequest<ReadonlyHttpHeaders>): boolean {\n    return request.headers.has('origin') && !isSameOrigin(request);\n\n}\n\nexport function isPreFlightRequest(request: HttpRequest): boolean {\n    return request.method === 'OPTIONS'\n        && request.headers.has('origin')\n        && request.headers.has('access-control-request-method');\n}\n", "import type { RouteConfig, PathPattern } from './route.ts';\nimport {\n    combineCorsConfig,\n    matchingCorsConfigSource,\n    PERMIT_DEFAULT_CONFIG,\n    validateCorsConfig\n} from '../server/cors.ts';\nimport { and, pattern, type ServerWebExchangeMatcher, upgradeMatcher } from '../server/util/matchers.ts';\nimport { IOGateway } from '@interopio/gateway';\nimport type { CorsConfig, CorsConfigSource } from '../web/cors/types.ts';\n\nexport function createCorsConfigSource(context: Pick<RouteConfig, 'sockets' | 'cors' | 'corsConfig'>): CorsConfigSource {\n    const {sockets: routes, cors} = context;\n\n    // create a default CORS config that allows all origins and methods and then combine it with the provided corsConfig\n    const defaultCorsConfig: CorsConfig | undefined = context.corsConfig === false ? undefined : combineCorsConfig(PERMIT_DEFAULT_CONFIG, context.corsConfig);\n\n    const validatedConfigs: Array<[ServerWebExchangeMatcher, CorsConfig | undefined]> = [];\n\n    // for each socket route, combine the default CORS config, then any app CORS config that match, and finally the route CORS config\n    for (const [path, route] of routes) {\n        let routeCorsConfig: CorsConfig | undefined = defaultCorsConfig;\n        for (const [matcher, config] of cors) {\n            if (IOGateway.Filtering.valueMatches(matcher, path)) {\n                if (config === undefined) {\n                    routeCorsConfig = undefined;\n                }\n                else {\n                    routeCorsConfig = routeCorsConfig === undefined ? config : combineCorsConfig(routeCorsConfig, config);\n                }\n            }\n        }\n        const config = context.corsConfig === false ? undefined : {\n            allowOrigins: route.originFilters?.allow,\n            allowMethods: ['GET', 'CONNECT', 'OPTIONS'],\n            allowHeaders: [\n                'Upgrade',\n                'Connection',\n                'Origin',\n                'Sec-Websocket-Key',\n                'Sec-Websocket-Version',\n                'Sec-Websocket-Protocol',\n                'Sec-Websocket-Extensions'\n            ],\n            exposeHeaders: ['Sec-Websocket-Accept', 'Sec-Websocket-Protocol', 'Sec-Websocket-Extensions'],\n            allowCredentials: route.authorize?.access !== 'permitted' ? true : undefined,\n        };\n        routeCorsConfig = routeCorsConfig === undefined ? config : combineCorsConfig(routeCorsConfig, config);\n\n        validatedConfigs.push([\n            and([upgradeMatcher, pattern(path)]),\n            validateCorsConfig(routeCorsConfig)]);\n    }\n\n    const appConfigs: Array<[PathPattern, CorsConfig | undefined]> = [];\n    // add app CORS configs\n    for (const [matcher, config] of cors) {\n        let [, routeCorsConfig] = appConfigs.find(([m]) => String(m) === String(matcher)) ?? [matcher, defaultCorsConfig];\n\n        routeCorsConfig = routeCorsConfig === undefined ? config : combineCorsConfig(routeCorsConfig, config);\n        let added = false;\n        for (const entry of appConfigs) {\n            if (String(entry[0]) === String(matcher)) {\n                entry[1] = routeCorsConfig;\n                added = true;\n                break;\n            }\n        }\n        if (!added) {\n            appConfigs.push([matcher, routeCorsConfig]);\n        }\n    }\n    for (const [matcher, config] of appConfigs) {\n        validatedConfigs.push([pattern(matcher), validateCorsConfig(config)]);\n    }\n\n    validatedConfigs.push([pattern(/\\/api\\/.*/), validateCorsConfig(defaultCorsConfig)]);\n\n\n    return matchingCorsConfigSource({mappings: validatedConfigs});\n}\n", "import type { Principal } from '../../../types/auth';\nimport type { ServerWebExchange } from '../../../types/web/server';\nimport type { WebFilterChain } from '../../web/server/types.ts';\n\n// A principal that has been authenticated and has a name.\nexport type AuthenticatedPrincipal = Principal & { readonly name: string };\n\nexport type Authentication = Principal & {\n    type: string;\n    readonly authorities?: ReadonlyArray<GrantedAuthority>;\n    readonly credentials?: unknown;\n    readonly details?: unknown;\n    readonly principal?: unknown;\n    authenticated: boolean;\n}\n\nexport type GrantedAuthority = {\n    readonly authority?: string;\n}\n\n// An interface for holding credentials that can be erased. Not CredentialsContainer to avoid confusion with web Credential Management API .\nexport interface CredentialsHolder {\n    eraseCredentials?(): void;\n}\n\nexport type AbstractAuthenticationToken = Authentication & CredentialsHolder & {\n    readonly name: string;\n    details?: unknown;\n}\n\nexport function isAuthentication(principal?: Principal): principal is Authentication {\n    return principal !== undefined && typeof principal['type'] === 'string' && typeof principal['authenticated'] === 'boolean';\n}\n\nexport type AuthenticationConverter = (exchange: ServerWebExchange) => Promise<Authentication | undefined>;\n\nexport class AuthenticationError extends Error {\n    private _authentication?: Authentication;\n\n    get authentication(): Authentication | undefined {\n        return this._authentication;\n    }\n\n    set authentication(value: Authentication) {\n        if (value === undefined) {\n            throw new TypeError(\"Authentication cannot be undefined\");\n        }\n        this._authentication = value;\n    }\n}\n\nexport class InsufficientAuthenticationError extends AuthenticationError {}\n\nexport class BadCredentialsError extends AuthenticationError {}\n\nabstract class AccountStatusError extends AuthenticationError {\n    protected constructor(message: string) {\n        super(message);\n    }\n}\n\nexport class LockedError extends AccountStatusError {\n    constructor(message: string) {\n        super(message);\n    }\n}\n\nexport class DisabledError extends AccountStatusError {\n    constructor(message: string) {\n        super(message);\n    }\n}\n\nexport class AccountExpiredError extends AccountStatusError {\n    constructor(message: string) {\n        super(message);\n    }\n}\n\nexport class CredentialsExpiredError extends AccountStatusError {\n    constructor(message: string) {\n        super(message);\n    }\n}\n\n\nexport class AuthenticationCredentialsNotFoundError extends AuthenticationError {}\n\nexport class AccessDeniedError extends Error {}\n\nexport type AuthenticationManager = (authentication: Authentication) => Promise<Authentication | undefined>;\n\nexport type AuthorizationManager<T> = {\n\n    /**\n     * Determines if access should be granted to the given object for the provided authentication.\n     * @param authentication\n     * @param object\n     */\n    verify(authentication: Promise<Authentication | undefined>, object: T): Promise<void>,\n    /**\n     * Checks if the authentication is authorized to access the given object.\n     * @param authentication\n     * @param object\n     */\n    authorize: (authentication: Promise<Authentication | undefined>, object: T) => Promise<AuthorizationResult | undefined>;\n}\nexport interface AuthorizationResult {readonly granted: boolean;}\nexport class AuthorizationDecision implements AuthorizationResult {\n    constructor(granted: boolean) {\n        this.granted = granted;\n    }\n\n    readonly granted: boolean;\n}\nexport class DefaultAuthorizationManager<T> implements AuthorizationManager<T> {\n    readonly #check: (authentication: Promise<Authentication | undefined>, object: T) => Promise<AuthorizationDecision | undefined>;\n\n    constructor(check: (authentication: Promise<Authentication | undefined>, object: T) => Promise<AuthorizationDecision>) {\n        this.#check = check;\n    }\n\n    async verify(authentication: Promise<Authentication | undefined>, object: T): Promise<void> {\n        const decision = await this.#check(authentication, object);\n        if (!decision?.granted) {\n            throw new AccessDeniedError(\"Access denied\");\n        }\n    }\n\n    async authorize(authentication: Promise<Authentication | undefined>, object: T) {\n        return await this.#check(authentication, object);\n    }\n}\n\nexport class AuthenticationServiceError extends AuthenticationError {}\nexport type ServerAuthenticationSuccessHandler = (filterExchange: {exchange: ServerWebExchange, chain: WebFilterChain}, authentication: Authentication) => Promise<void>;\nexport type ServerAuthenticationFailureHandler = (filterExchange: {exchange: ServerWebExchange, chain: WebFilterChain}, error: AuthenticationError) => Promise<void>;\nexport type ServerAuthenticationEntryPoint = (exchange: ServerWebExchange, error: AuthenticationError) => Promise<void>;\nexport type ServerAccessDeniedHandler = (exchange: ServerWebExchange, error: AccessDeniedError) => Promise<void>;\n", "import type { ServerWebExchange } from '../../../types/web/server';\nimport { MapHttpHeaders } from '../../http/headers.ts';\nimport type { WebFilter, WebFilterChain } from '../../web/server/types.ts';\n\ntype ServerHttpHeadersWriter = (exchange: ServerWebExchange) => Promise<void>;\n\nconst staticServerHttpHeadersWriter = (headers: MapHttpHeaders): ServerHttpHeadersWriter => {\n    return async (exchange: ServerWebExchange) => {\n        let containsNoHeaders = true;\n        const { response } = exchange;\n        for (const name of headers.keys()) {\n            if (response.headers.has(name)) {\n                containsNoHeaders = false;\n            }\n        }\n        if (containsNoHeaders) {\n            for (const [name, value] of headers) {\n                response.headers.set(name, value);\n            }\n        }\n    }\n}\n\nconst cacheControlServerHttpHeadersWriter = () => staticServerHttpHeadersWriter(\n    new MapHttpHeaders()\n        .add('cache-control', 'no-cache, no-store, max-age=0, must-revalidate')\n        .add('pragma', 'no-cache')\n        .add('expires', '0'));\n\nconst contentTypeServerHttpHeadersWriter = () => staticServerHttpHeadersWriter(\n    new MapHttpHeaders()\n        .add('x-content-type-options', 'nosniff'));\n\nconst strictTransportSecurityServerHttpHeadersWriter = (maxAgeInSeconds: number, includeSubDomains: boolean, preload: boolean) => {\n    let headerValue = `max-age=${maxAgeInSeconds}`;\n    if (includeSubDomains) {\n        headerValue += ' ; includeSubDomains';\n    }\n    if (preload) {\n        headerValue += ' ; preload';\n    }\n    const delegate = staticServerHttpHeadersWriter(\n        new MapHttpHeaders()\n            .add('strict-transport-security', headerValue))\n\n    const isSecure = (exchange: ServerWebExchange) => {\n        const protocol = exchange.request.URL.protocol;\n        return protocol === 'https:';\n    }\n\n    return async (exchange: ServerWebExchange) => {\n        if (isSecure(exchange)) {\n            await delegate(exchange);\n        }\n    }\n};\n\ntype FrameOptionsMode = 'DENY' | 'SAMEORIGIN';\nconst frameOptionsServerHttpHeadersWriter = (mode: FrameOptionsMode) => {\n    return staticServerHttpHeadersWriter(\n        new MapHttpHeaders()\n            .add('x-frame-options', mode))\n};\n\ntype XssProtectionHeaderValue = '0' | '1' | '1; mode=block';\nconst xssProtectionServerHttpHeadersWriter = (headerValue: XssProtectionHeaderValue) => staticServerHttpHeadersWriter(\n    new MapHttpHeaders()\n        .add('x-xss-protection', headerValue));\n\n\nconst permissionsPolicyServerHttpHeadersWriter = (policyDirectives?: string) => {\n\n    const delegate = policyDirectives === undefined ? undefined : staticServerHttpHeadersWriter(\n        new MapHttpHeaders()\n            .add('permissions-policy', policyDirectives));\n    return async (exchange: ServerWebExchange) => {\n        if (delegate !== undefined) {\n            await delegate(exchange);\n        }\n    }\n}\nconst contentSecurityPolicyServerHttpHeadersWriter = (policyDirectives?: string, reportOnly?: boolean) => {\n    const headerName = reportOnly ? 'content-security-policy-report-only' : 'content-security-policy';\n    const delegate = policyDirectives === undefined ? undefined : staticServerHttpHeadersWriter(\n        new MapHttpHeaders()\n            .add(headerName, policyDirectives));\n    return async (exchange: ServerWebExchange) => {\n        if (delegate !== undefined) {\n            await delegate(exchange);\n        }\n    }\n};\n\ntype ReferrerPolicy =\n    'no-referrer'\n    | 'no-referrer-when-downgrade'\n    | 'origin'\n    | 'origin-when-cross-origin'\n    | 'same-origin'\n    | 'strict-origin'\n    | 'strict-origin-when-cross-origin'\n    | 'unsafe-url';\nconst refererPolicyServerHttpHeadersWriter = (policy: ReferrerPolicy = 'no-referrer') => {\n    return staticServerHttpHeadersWriter(\n        new MapHttpHeaders()\n            .add('referer-policy', policy));\n}\n\ntype CrossOriginOpenerPolicy = 'unsafe-none' | 'same-origin' | 'same-origin-allow-popups';\nconst crossOriginOpenerPolicyServerHttpHeadersWriter = (policy?: CrossOriginOpenerPolicy) => {\n    const delegate = policy === undefined ? undefined : staticServerHttpHeadersWriter(\n        new MapHttpHeaders()\n            .add('cross-origin-opener-policy', policy));\n    return async (exchange: ServerWebExchange) => {\n        if (delegate !== undefined) {\n            await delegate(exchange);\n        }\n    }\n}\n\ntype CrossOriginEmbedderPolicy = 'unsafe-none' | 'require-corp';\nconst crossOriginEmbedderPolicyServerHttpHeadersWriter = (policy?: CrossOriginEmbedderPolicy) => {\n    const delegate = policy === undefined ? undefined : staticServerHttpHeadersWriter(\n        new MapHttpHeaders()\n            .add('cross-origin-embedder-policy', policy));\n    return async (exchange: ServerWebExchange) => {\n        if (delegate !== undefined) {\n            await delegate(exchange);\n        }\n    }\n}\n\ntype CrossOriginResourcePolicy = 'same-origin' | 'same-site' | 'cross-origin';\nconst crossOriginResourcePolicyServerHttpHeadersWriter = (policy?: CrossOriginResourcePolicy) => {\n    const delegate = policy === undefined ? undefined : staticServerHttpHeadersWriter(\n        new MapHttpHeaders()\n            .add('cross-origin-resource-policy', policy));\n    return async (exchange: ServerWebExchange) => {\n        if (delegate !== undefined) {\n            await delegate(exchange);\n        }\n    }\n}\n\nconst compositeServerHttpHeadersWriter = (\n    ...writers: ServerHttpHeadersWriter[]\n): ServerHttpHeadersWriter => {\n    return async (exchange: ServerWebExchange) => {\n        for (const writer of writers) {\n            await writer(exchange);\n        }\n    }\n}\n\nexport default function headers(opts?: {\n    cache?: { disabled?: boolean }\n    contentType?: { disabled?: boolean },\n    frameOptions?: { disabled?: boolean, mode?: FrameOptionsMode },\n    hsts?: { disabled?: boolean, maxAge?: number, includeSubDomains?: boolean, preload?: boolean },\n    xss?: { disabled?: boolean, headerValue?: XssProtectionHeaderValue },\n    permissionsPolicy?: { disabled?: boolean, policyDirectives?: string },\n    contentSecurityPolicy?: { disabled?: boolean, policyDirectives?: string, reportOnly?: boolean },\n    refererPolicy?: { disabled?: boolean, policy?: ReferrerPolicy },\n    crossOriginOpenerPolicy?: { disabled?: boolean, policy?: CrossOriginOpenerPolicy },\n    crossOriginEmbedderPolicy?: { disabled?: boolean, policy?: CrossOriginEmbedderPolicy },\n    crossOriginResourcePolicy?: { disabled?: boolean, policy?: CrossOriginResourcePolicy }\n    writers?: ServerHttpHeadersWriter[]\n}): WebFilter {\n    const writers: ServerHttpHeadersWriter[] = [];\n    if (!opts?.cache?.disabled) {\n        writers.push(cacheControlServerHttpHeadersWriter());\n    }\n    if (!opts?.contentType?.disabled) {\n        writers.push(contentTypeServerHttpHeadersWriter());\n    }\n    if (!opts?.hsts?.disabled) {\n        writers.push(strictTransportSecurityServerHttpHeadersWriter(opts?.hsts?.maxAge ?? 365 * 24 * 60 * 60, opts?.hsts?.includeSubDomains ?? true, opts?.hsts?.preload ?? false));\n    }\n    if (!opts?.frameOptions?.disabled) {\n        writers.push(frameOptionsServerHttpHeadersWriter(opts?.frameOptions?.mode ?? 'DENY'));\n    }\n    if (!opts?.xss?.disabled) {\n        writers.push(xssProtectionServerHttpHeadersWriter(opts?.xss?.headerValue ?? '0'));\n    }\n    if (!opts?.permissionsPolicy?.disabled) {\n        writers.push(permissionsPolicyServerHttpHeadersWriter(opts?.permissionsPolicy?.policyDirectives));\n    }\n    if (!opts?.contentSecurityPolicy?.disabled) {\n        writers.push(contentSecurityPolicyServerHttpHeadersWriter(opts?.contentSecurityPolicy?.policyDirectives ?? \"default-src 'self'\", opts?.contentSecurityPolicy?.reportOnly));\n    }\n    if (!opts?.refererPolicy?.disabled) {\n        writers.push(refererPolicyServerHttpHeadersWriter(opts?.refererPolicy?.policy ?? 'no-referrer'));\n    }\n    if (!opts?.crossOriginOpenerPolicy?.disabled) {\n        writers.push(crossOriginOpenerPolicyServerHttpHeadersWriter(opts?.crossOriginOpenerPolicy?.policy));\n    }\n    if (!opts?.crossOriginEmbedderPolicy?.disabled) {\n        writers.push(crossOriginEmbedderPolicyServerHttpHeadersWriter(opts?.crossOriginEmbedderPolicy?.policy));\n    }\n    if (!opts?.crossOriginResourcePolicy?.disabled) {\n        writers.push(crossOriginResourcePolicyServerHttpHeadersWriter(opts?.crossOriginResourcePolicy?.policy));\n    }\n    if (opts?.writers) {\n        writers.push(...opts.writers);\n    }\n    const writer = compositeServerHttpHeadersWriter(...writers);\n\n    return {\n        filter: async (exchange: ServerWebExchange, chain: WebFilterChain) => {\n            await writer(exchange);\n            return chain.filter(exchange);\n        }\n    }\n}\n", "import {\n    AuthenticationServiceError,\n    type ServerAuthenticationEntryPoint,\n    type ServerAuthenticationFailureHandler\n} from './types.ts';\n\nexport const serverAuthenticationEntryPointFailureHandler = (opts: {\n    entryPoint: ServerAuthenticationEntryPoint,\n    rethrowAuthenticationServiceError?: boolean\n}): ServerAuthenticationFailureHandler => {\n    const entryPoint = opts.entryPoint;\n    const rethrowAuthenticationServiceError = opts?.rethrowAuthenticationServiceError ?? true;\n    return async ({exchange}, error) => {\n        if (!rethrowAuthenticationServiceError) {\n            return entryPoint(exchange, error);\n        }\n        if (!(error instanceof AuthenticationServiceError)) {\n            return entryPoint(exchange, error);\n        }\n        throw error;\n\n    };\n\n\n}\n", "import type { ServerAuthenticationEntryPoint } from './types.ts';\nimport { HttpStatus } from '../../http/status.ts';\n\nconst DEFAULT_REALM = 'Realm';\nconst createHeaderValue = (realm: string): string => {\n    return `Basic realm=\"${realm}\"`;\n}\n\nexport const httpBasicEntryPoint = (opts?: { realm?: string }): ServerAuthenticationEntryPoint => {\n    const headerValue = createHeaderValue(opts?.realm ?? DEFAULT_REALM);\n    return async (exchange, _error) => {\n        const {response} = exchange;\n        response.setStatusCode(HttpStatus.UNAUTHORIZED);\n        response.headers.set('WWW-Authenticate', headerValue);\n    };\n}\n", "import type { AbstractAuthenticationToken, AuthenticationConverter } from './types.ts';\n\nconst BASIC = 'Basic ';\n\nexport const httpBasicAuthenticationConverter = (opts?: {credentialsEncoding?: BufferEncoding}): AuthenticationConverter => {\n    const credentialsEncoding = opts?.credentialsEncoding ?? 'utf-8';\n\n    return async (exchange): Promise<AbstractAuthenticationToken | undefined> => {\n        const { request } = exchange;\n        const authorization = request.headers.one(\"authorization\");\n        if (!authorization || !(/basic/i).test(authorization.substring(0,))) {\n            return;\n        }\n        const credentials = authorization.length <= BASIC.length ? '' : authorization.substring(BASIC.length);\n        const decoded = Buffer.from(credentials, 'base64').toString(credentialsEncoding);\n        const parts = decoded.split(\":\", 2);\n        if (parts.length !== 2) {\n            return undefined;\n        }\n        const principal = parts[0];\n        let erasableCredentials: string | null = parts[1];\n        return {\n            type: 'UsernamePassword',\n            authenticated: false,\n            principal,\n            credentials: erasableCredentials,\n            name: principal,\n            eraseCredentials: () => {\n                erasableCredentials = null;\n            },\n        };\n    }\n\n}\n", "import type { Authentication } from './types';\nimport { AsyncLocalStorage } from 'node:async_hooks';\n\nexport interface SecurityContext {\n    authentication?: Authentication;\n}\n\nexport class AsyncStorageSecurityContextHolder {\n    private static hasSecurityContext(storage: AsyncLocalStorage<{\n        securityContext?: Promise<SecurityContext>\n    }>): boolean {\n        return storage.getStore()?.securityContext !== undefined;\n    }\n\n    private static async getSecurityContext(storage: AsyncLocalStorage<{\n        securityContext?: Promise<SecurityContext>\n    }>): Promise<SecurityContext | undefined> {\n        return await storage.getStore()?.securityContext;\n    }\n\n    public static clearSecurityContext(storage: AsyncLocalStorage<{ securityContext?: Promise<SecurityContext> }>) {\n        delete storage.getStore()?.securityContext;\n    }\n\n    public static withSecurityContext(securityContext: Promise<SecurityContext>) {\n        return (storage: AsyncLocalStorage<{ securityContext?: Promise<SecurityContext> }> = new AsyncLocalStorage<{\n            securityContext?: Promise<SecurityContext>\n        }>()) => {\n            storage.getStore()!.securityContext = securityContext;\n            return storage;\n        };\n    }\n\n    public static withAuthentication(authentication: Authentication) {\n        return AsyncStorageSecurityContextHolder.withSecurityContext(Promise.resolve({authentication}));\n    }\n\n    public static async getContext(storage: AsyncLocalStorage<{ securityContext?: Promise<SecurityContext> }>): Promise<SecurityContext | undefined> {\n        if (AsyncStorageSecurityContextHolder.hasSecurityContext(storage)) {\n            return AsyncStorageSecurityContextHolder.getSecurityContext(storage);\n        }\n    }\n}\n\n", "import { type Authentication } from './types.ts';\nimport {\n    type AuthenticationConverter,\n    AuthenticationError,\n    type AuthenticationManager,\n    type ServerAuthenticationFailureHandler,\n    type ServerAuthenticationSuccessHandler\n} from './types.ts';\nimport { serverAuthenticationEntryPointFailureHandler } from './entry-point-failure-handler.ts';\nimport { httpBasicEntryPoint } from './http-basic-entry-point.ts';\nimport { httpBasicAuthenticationConverter } from './http-basic-converter.ts';\nimport { anyExchange, type ServerWebExchangeMatcher } from '../util/matchers.ts';\nimport { AsyncStorageSecurityContextHolder, type SecurityContext } from './security-context.ts';\nimport { AsyncLocalStorage } from 'node:async_hooks';\nimport type { ServerWebExchange } from '../../../types/web/server'\nimport type { WebFilter, WebFilterChain } from '../../web/server/types.ts';\n\nasync function authenticate(exchange: ServerWebExchange,\n                            chain: WebFilterChain,\n                            token: Authentication,\n                            managerResolver: (exchange: ServerWebExchange) => Promise<AuthenticationManager | undefined>,\n                            successHandler: ServerAuthenticationSuccessHandler,\n                            storage: AsyncLocalStorage<{ securityContext?: Promise<SecurityContext> }>): Promise<void> {\n    const authManager = await managerResolver(exchange);\n    const authentication = await authManager?.(token);\n    if (authentication === undefined) {\n        throw new Error(\"No authentication manager found for the exchange\");\n    }\n    try {\n        await onAuthenticationSuccess(authentication, {exchange, chain}, successHandler, storage);\n    } catch (e) {\n        if (e instanceof AuthenticationError) {\n            // todo debug log\n        }\n        throw e;\n    }\n}\n\nasync function onAuthenticationSuccess(authentication: Authentication,\n                                       filterExchange: {exchange: ServerWebExchange, chain: WebFilterChain},\n                                       successHandler: ServerAuthenticationSuccessHandler,\n                                       storage: AsyncLocalStorage<{ securityContext?: Promise<SecurityContext> }>): Promise<void> {\n    AsyncStorageSecurityContextHolder.withAuthentication(authentication)(storage);\n    await successHandler(filterExchange, authentication);\n\n}\n\nexport type AuthenticationFilterOptions = {\n    storage: AsyncLocalStorage<{securityContext?: Promise<SecurityContext>}>\n    managerResolver?: (exchange: ServerWebExchange) => Promise<AuthenticationManager | undefined>,\n    manager?: AuthenticationManager,\n    successHandler?: ServerAuthenticationSuccessHandler,\n    // converter is a function that converts the exchange to an authentication object\n    converter?: AuthenticationConverter,\n    failureHandler?: ServerAuthenticationFailureHandler\n    // matcher is a function that checks if the exchange must be authenticated\n    matcher?: ServerWebExchangeMatcher,\n};\n\nexport default function authenticationFilter(opts: AuthenticationFilterOptions): WebFilter {\n    const auth = {\n        matcher: anyExchange,\n        successHandler: async({exchange, chain}: {exchange: ServerWebExchange, chain: WebFilterChain}) => {\n            await chain.filter(exchange);\n        },\n        converter: httpBasicAuthenticationConverter({}),\n        failureHandler: serverAuthenticationEntryPointFailureHandler({ entryPoint: httpBasicEntryPoint({}) }),\n        ...opts\n    };\n    let managerResolver = auth.managerResolver;\n    if (managerResolver === undefined && auth.manager !== undefined) {\n        const manager: AuthenticationManager = auth.manager;\n        managerResolver = async (_exchange: ServerWebExchange) => {\n            return manager;\n        };\n    }\n    if (managerResolver === undefined) {\n        throw new Error(\"Authentication filter requires a managerResolver or a manager\");\n    }\n    return {\n        filter: async (exchange: ServerWebExchange, chain: WebFilterChain): Promise<void> => {\n            const matchResult = await auth.matcher(exchange);\n            const token = matchResult.match ? await auth.converter(exchange) : undefined;\n            if (token === undefined) {\n                await chain.filter(exchange);\n                return;\n            }\n\n            try {\n                await authenticate(exchange, chain, token, managerResolver, auth.successHandler, auth.storage);\n\n            }\n            catch (error) {\n                if (error instanceof AuthenticationError) {\n                    await auth.failureHandler({ exchange, chain }, error);\n                    return;\n                }\n                throw error; // Re-throw the error to be handled by the next middleware or error handler\n            }\n        }\n    };\n}\n", "import type { AuthenticationError, ServerAuthenticationEntryPoint } from './types.ts';\nimport { HttpStatus } from \"../../http/status.ts\";\n\nexport const httpStatusEntryPoint = (opts: {\n    httpStatus: HttpStatus\n}): ServerAuthenticationEntryPoint => {\n    return async (exchange, _error: AuthenticationError) => {\n        const response = exchange.response;\n        response.setStatusCode(opts.httpStatus);\n    };\n}\n", "import {AuthenticationError, type ServerAuthenticationEntryPoint} from './types.ts';\nimport {type ServerWebExchangeMatcher} from '../util/matchers.ts';\nimport {HttpStatus} from '../../http/status.ts';\nimport getLogger from '../../logger.ts';\nimport type {ServerWebExchange} from '../../../types/web/server';\n\nconst logger = getLogger('auth.entry-point');\n\nexport const delegatingEntryPoint = (opts: {\n    entryPoints: Array<[ServerWebExchangeMatcher, ServerAuthenticationEntryPoint]>;\n    defaultEntryPoint: ServerAuthenticationEntryPoint;\n}): ServerAuthenticationEntryPoint => {\n    const defaultEntryPoint = opts.defaultEntryPoint ?? (async ({response}, _error) => {\n        response.setStatusCode(HttpStatus.UNAUTHORIZED);\n        await response.end();\n    });\n    return async (exchange: ServerWebExchange, error: AuthenticationError) => {\n        for (const [matcher, entryPoint] of opts.entryPoints) {\n            if (logger.enabledFor('debug')) {\n                logger.debug(`trying to match using: ${matcher}`);\n            }\n            const match = await matcher(exchange);\n            if (match.match) {\n                if (logger.enabledFor('debug')) {\n                    logger.debug(`match found. using default entry point ${entryPoint}`);\n                }\n                return entryPoint(exchange, error);\n            }\n        }\n        if (logger.enabledFor('debug')) {\n            logger.debug(`no match found. using default entry point ${defaultEntryPoint}`);\n        }\n        return defaultEntryPoint(exchange, error);\n    };\n}\n", "import type {Authentication, ServerAuthenticationSuccessHandler} from './types.ts';\n\nexport const delegatingSuccessHandler = (handlers: Array<ServerAuthenticationSuccessHandler>) => {\n\n    return async ({exchange, chain}, authentication: Authentication) => {\n        for (const handler of handlers) {\n            await handler({exchange, chain}, authentication);\n        }\n    };\n}\n", "import authenticationFilter from './authentication-filter.ts';\nimport { serverAuthenticationEntryPointFailureHandler } from './entry-point-failure-handler.ts';\nimport type {\n    AuthenticationManager,\n    ServerAuthenticationEntryPoint,\n    ServerAuthenticationFailureHandler,\n    ServerAuthenticationSuccessHandler\n} from './types.ts';\nimport { httpStatusEntryPoint } from './http-status-entry-point.ts';\nimport { httpBasicEntryPoint } from './http-basic-entry-point.ts';\nimport { delegatingEntryPoint } from './delegating-entry-point.ts';\nimport { httpBasicAuthenticationConverter } from './http-basic-converter.ts';\nimport { delegatingSuccessHandler } from './delegating-success-handler.ts';\nimport type { SecurityContext } from './security-context.ts';\nimport type { MatchResult, ServerWebExchangeMatcher } from '../util/matchers.ts';\nimport * as matchers from '../util/matchers.ts';\nimport { HttpStatus } from '../../http/status.ts';\nimport { AsyncLocalStorage } from 'node:async_hooks';\nimport type { ServerWebExchange } from '../../../types/web/server';\n\nexport default function httpBasic(opts: {\n    readonly storage: AsyncLocalStorage<{securityContext?: Promise<SecurityContext>}>\n    readonly manager: AuthenticationManager;\n    readonly entryPoint?: ServerAuthenticationEntryPoint;\n    readonly failureHandler?: ServerAuthenticationFailureHandler;\n    readonly successHandlers?: ServerAuthenticationSuccessHandler[];\n    defaultEntryPoints: Array<[ServerWebExchangeMatcher, ServerAuthenticationEntryPoint]>;\n    defaultSuccessHandlers: ServerAuthenticationSuccessHandler[];\n}) {\n\n    const xhrMatcher: ServerWebExchangeMatcher = async (exchange: ServerWebExchange): Promise<MatchResult> => {\n        const headers = exchange.request.headers;\n        const h = headers.list('X-Requested-With');\n        if (h.includes('XMLHttpRequest')) {\n            return matchers.match();\n        }\n        return matchers.NO_MATCH;\n    }\n\n    const defaultEntryPoint = delegatingEntryPoint({\n        entryPoints: [[xhrMatcher, httpStatusEntryPoint({httpStatus: HttpStatus.UNAUTHORIZED})]],\n        defaultEntryPoint: httpBasicEntryPoint({})\n    });\n\n    const entryPoint = opts.entryPoint ?? defaultEntryPoint;\n\n    const manager = opts.manager;\n\n    const restMatcher = matchers.mediaType({\n        mediaTypes: [\n            'application/atom+xml',\n            'application/x-www-form-urlencoded',\n            'application/json',\n            'application/octet-stream',\n            'application/xml',\n            'multipart/form-data',\n            'text/xml'\n        ],\n        ignoredMediaTypes: ['*/*']\n    });\n\n    const notHtmlMatcher = matchers.not(matchers.mediaType({ mediaTypes: ['text/html'] }));\n    const restNoHtmlMatcher = matchers.and([notHtmlMatcher, restMatcher]);\n    const preferredMatcher = matchers.or([xhrMatcher, restNoHtmlMatcher]);\n    opts.defaultEntryPoints.push([preferredMatcher, entryPoint]);\n    const failureHandler = opts.failureHandler ?? serverAuthenticationEntryPointFailureHandler({entryPoint});\n    const successHandler = delegatingSuccessHandler(opts.successHandlers ?? opts.defaultSuccessHandlers);\n    const converter = httpBasicAuthenticationConverter({});\n    return authenticationFilter({\n        storage: opts.storage,\n        manager,\n        failureHandler,\n        successHandler,\n        converter\n    });\n}\n\n", "import { HttpStatus } from '../../../http/status.ts';\n\nexport type OAuth2Error = {\n    readonly errorCode: string\n    readonly description?: string\n    readonly uri?: string\n}\n\nexport type BearerTokenError = OAuth2Error & {\n    readonly httpStatus: HttpStatus\n    readonly scope?: string\n}\n\nexport const BearerTokenErrorCodes = {\n    invalid_request: 'invalid_request',\n    invalid_token: 'invalid_token',\n    insufficient_scope: 'insufficient_scope',\n}\n\nconst DEFAULT_URI = \"https://tools.ietf.org/html/rfc6750#section-3.1\";\n\nexport function invalidToken(message: string): BearerTokenError {\n    return {\n        errorCode: BearerTokenErrorCodes.invalid_token,\n        httpStatus: HttpStatus.UNAUTHORIZED,\n        description: message,\n        uri: DEFAULT_URI\n    };\n}\n\nexport function invalidRequest(message: string): BearerTokenError {\n    return {\n        errorCode: BearerTokenErrorCodes.invalid_request,\n        httpStatus: HttpStatus.BAD_REQUEST,\n        description: message,\n        uri: DEFAULT_URI\n    };\n}\n\nexport function insufficientScope(message: string, scope?: string): BearerTokenError {\n    return {\n        errorCode: BearerTokenErrorCodes.insufficient_scope,\n        httpStatus: HttpStatus.FORBIDDEN,\n        description: message,\n        uri: DEFAULT_URI,\n        scope\n    };\n}\n", "import { type Authentication, type AuthenticationConverter, AuthenticationError } from '../types.ts';\nimport { invalidRequest, invalidToken, type OAuth2Error } from './token-error.ts';\nimport type { ReadonlyHttpHeaders } from '../../../../types/web/http';\nimport type { ServerHttpRequest, ServerWebExchange } from '../../../../types/web/server';\n\nconst ACCESS_TOKEN_PARAMETER_NAME = 'access_token';\nconst authorizationPattern = /^Bearer\\s+(?<token>[a-zA-Z0-9-._~+/]+=*)$/i;\n\nexport class Oauth2AuthenticationError extends AuthenticationError {\n    readonly error: OAuth2Error;\n\n    constructor(error: string | OAuth2Error, message?: string, options?: ErrorOptions) {\n        super(message ?? (typeof error === 'string' ? undefined : error.description), options);\n        this.error = typeof error === 'string' ? {errorCode: error} : error;\n    }\n}\n\nexport type BearerTokenAuthenticationToken = Authentication & {\n    type: 'BearerToken';\n    token: string;\n}\n\nexport const isBearerTokenAuthenticationToken = (authentication: Authentication): authentication is BearerTokenAuthenticationToken => {\n    return authentication.type === 'BearerToken';\n}\n\nconst serverBearerTokenAuthenticationConverter = (opts?: {headerName?: string, uriQueryParameter?: boolean, formEncodedBodyParameter?: boolean }): AuthenticationConverter => {\n    return async (exchange: ServerWebExchange) => {\n        const {request} = exchange;\n        return Promise.all<string[] | undefined>([\n            resolveFromAuthorizationHeader(request.headers, opts?.headerName).then((token?: string) => token !== undefined ? [token] : undefined),\n            resolveFromQueryString(request, opts?.uriQueryParameter),\n            resolveFromBody(exchange, opts?.formEncodedBodyParameter)\n        ])\n            .then(rs => rs.filter(r => r !== undefined).flat(1))\n            .then(resolveToken)\n            .then(token => {\n                if (token) return {authenticated: false, type: 'BearerToken', token};\n            });\n    }\n}\n\nasync function resolveToken(accessTokens: string[]) {\n    if (accessTokens.length === 0) {\n        return;\n    }\n    if (accessTokens.length > 1) {\n        const error = invalidRequest('Found multiple access tokens in the request');\n        throw new Oauth2AuthenticationError(error);\n    }\n\n    const accessToken = accessTokens[0];\n    if (!accessToken || accessToken.length === 0) {\n        const error = invalidRequest('The requested access token parameter is an empty string');\n        throw new Oauth2AuthenticationError(error);\n    }\n    return accessToken;\n}\n\nasync function resolveFromAuthorizationHeader(headers: ReadonlyHttpHeaders, headerName: string = 'authorization'): Promise<string | undefined> {\n    const authorization = headers.one(headerName);\n    if (!authorization || !(/bearer/i).test(authorization.substring(0,))) {\n        return;\n    }\n    const match = authorizationPattern.exec(authorization);\n    if (match === null) {\n        const error = invalidToken('Bearer token is malformed');\n        throw new Oauth2AuthenticationError(error);\n    }\n    return match.groups?.token;\n}\n\nasync function resolveTokens(parameters: URLSearchParams): Promise<string[] | undefined> {\n    const accessTokens = parameters.getAll(ACCESS_TOKEN_PARAMETER_NAME);\n    if (accessTokens.length === 0) {\n        return;\n    }\n    return accessTokens;\n}\n\nasync function resolveFromQueryString(request: ServerHttpRequest, allow = false): Promise<string[] | undefined> {\n    if (!allow || request.method !== 'GET') {\n        return;\n    }\n    return resolveTokens(request.URL.searchParams);\n}\n\nasync function resolveFromBody(exchange: ServerWebExchange, allow = false): Promise<string[] | undefined> {\n    const {request} = exchange;\n    if (!allow\n        || ('application/x-www-form-urlencoded' !== request.headers.one('content-type'))\n        || request.method !== 'POST') {\n        return;\n    }\n    const parameters = await exchange.request.formData();\n    if (parameters) {\n        return resolveTokens(parameters);\n    }\n}\n\nexport default serverBearerTokenAuthenticationConverter;\n", "import { AuthenticationError, type ServerAuthenticationEntryPoint } from '../types.ts';\nimport { Oauth2AuthenticationError } from './token-converter.ts';\nimport type { BearerTokenError, OAuth2Error } from './token-error.ts';\nimport { HttpStatus } from '../../../http/status.ts';\n\nfunction computeWWWAuthenticate(parameters: Map<string, string>) {\n    let wwwAuthenticate = 'Bearer';\n    if (parameters.size !== 0) {\n        wwwAuthenticate += ' ';\n        let i = 0;\n        for (const [key, value] of parameters) {\n            wwwAuthenticate += `${key}=\"${value}\"`;\n            if (i !== parameters.size - 1) {\n                wwwAuthenticate += ', ';\n            }\n            i++;\n        }\n    }\n    return wwwAuthenticate;\n}\n\nconst isBearerTokenError = (error: OAuth2Error): error is BearerTokenError => {\n    return (error as BearerTokenError).httpStatus !== undefined;\n}\n\nfunction getStatus(authError: AuthenticationError): HttpStatus {\n    if (authError instanceof Oauth2AuthenticationError) {\n        const {error} = authError;\n        if (isBearerTokenError(error)) {\n            return error.httpStatus;\n        }\n    }\n    return HttpStatus.UNAUTHORIZED;\n}\n\nfunction createParameters(authError: AuthenticationError, realm?: string) {\n    const parameters = new Map<string, string>();\n    if (realm) {\n        parameters.set('realm', realm);\n    }\n    if (authError instanceof Oauth2AuthenticationError) {\n        const {error} = authError;\n        parameters.set('error', error.errorCode);\n        if (error.description) {\n            parameters.set('error_description', error.description);\n        }\n        if (error.uri) {\n            parameters.set('error_uri',  error.uri);\n        }\n        if (isBearerTokenError(error) && error.scope) {\n            parameters.set('scope', error.scope);\n        }\n    }\n    return parameters;\n}\n\nconst bearerTokenServerAuthenticationEntryPoint = (opts?: { realmName?: string }): ServerAuthenticationEntryPoint => {\n    return async (exchange, error) => {\n        const status = getStatus(error);\n        const parameters = createParameters(error, opts?.realmName)\n        const wwwAuthenticate = computeWWWAuthenticate(parameters);\n        const {response} = exchange;\n        response.headers.set('WWW-Authenticate', wwwAuthenticate);\n        response.setStatusCode(status);\n        await response.end();\n    };\n}\n\nexport default bearerTokenServerAuthenticationEntryPoint;\n", "import {\n    type AbstractAuthenticationToken,\n    type Authentication,\n    type AuthenticationManager,\n    AuthenticationServiceError\n} from '../types.ts';\nimport { invalidToken } from './token-error.ts';\nimport { isBearerTokenAuthenticationToken, Oauth2AuthenticationError } from './token-converter.ts';\n\nexport interface Jwt extends OAuth2Token {\n    readonly subject?: string\n\n    getClaimAsString(claim: string): string | undefined\n}\n\nexport type OAuth2Token = {\n    readonly tokenValue: string;\n    readonly issuedAt?: Date;\n    readonly expiresAt?: Date;\n}\n\ntype AbstractOAuth2TokenAuthenticationToken<T extends OAuth2Token> = AbstractAuthenticationToken & {\n    // token: T;\n}\n\n\nconst jwtAuthConverter = (opts?: { principalClaimName?: string}): (jwt: Jwt) => AbstractAuthenticationToken => {\n    const principalClaimName = opts?.principalClaimName ?? 'sub';\n\n    return (jwt: Jwt) => {\n        const name = jwt.getClaimAsString(principalClaimName)!;\n        const authentication: (AbstractOAuth2TokenAuthenticationToken<any> & { type: 'JwtToken' }) = { type: 'JwtToken', authenticated: true, name };\n        return authentication;\n    };\n}\n\nconst asyncJwtConverter = (converter: (jwt: Jwt) => Authentication): (jwt: Jwt) => Promise<Authentication> => {\n    return async (jwt: Jwt) => {\n        return converter(jwt);\n    };\n};\n\nexport class JwtError extends Error {}\nexport class BadJwtError extends JwtError {}\n\n\nfunction onError(error: JwtError) {\n    if (error instanceof BadJwtError) {\n        return new Oauth2AuthenticationError(invalidToken(error.message), error.message, {cause: error});\n    }\n    throw new AuthenticationServiceError(error.message, {cause: error});\n\n}\n\nexport default function jwtAuthManager(opts: {\n    decoder: (token: string) => Promise<Jwt>\n    authConverter?: (jwt: Jwt) => Promise<Authentication>\n}): AuthenticationManager {\n    const decoder = opts.decoder;\n    const authConverter = opts.authConverter ?? asyncJwtConverter(jwtAuthConverter({}));\n    return async (authentication) => {\n        if (isBearerTokenAuthenticationToken(authentication)) {\n            const token = authentication.token;\n            try {\n                const jwt = await decoder(token);\n                return await authConverter(jwt);\n            } catch (e) {\n                if (e instanceof JwtError) {\n                    throw onError(e);\n                }\n                throw e;\n            }\n        }\n    }\n}\n", "import authenticationFilter from './authentication-filter.ts';\nimport type {\n    Authentication,\n    AuthenticationConverter,\n    AuthenticationManager,\n    ServerAuthenticationEntryPoint,\n    ServerAuthenticationFailureHandler\n} from './types.ts';\nimport serverBearerTokenAuthenticationConverter from './oauth2/token-converter.ts';\nimport { serverAuthenticationEntryPointFailureHandler } from './entry-point-failure-handler.ts';\nimport bearerTokenServerAuthenticationEntryPoint from './oauth2/token-entry-point.ts';\nimport jwtAuthManager, { type Jwt } from './oauth2/jwt-auth-manager.ts';\nimport type { SecurityContext } from './security-context.ts';\nimport { AsyncLocalStorage } from 'node:async_hooks';\nimport type { ServerWebExchange } from '../../../types/web/server';\nimport type { WebFilter } from '../../web/server/types.ts';\n\nexport default function resourceServer(opts: {\n    readonly storage: AsyncLocalStorage<{securityContext?: Promise<SecurityContext>}>,\n    converter?: AuthenticationConverter,\n    failureHandler?: ServerAuthenticationFailureHandler,\n    entryPoint?: ServerAuthenticationEntryPoint,\n    managerResolver?: (exchange: ServerWebExchange) => Promise<AuthenticationManager | undefined>,\n    jwt?: {\n        manager?: AuthenticationManager,\n        decoder: (token: string) => Promise<Jwt>,\n        authConverter?: (jwt: Jwt) => Promise<Authentication>\n    }\n}): WebFilter {\n    const entryPoint = opts.entryPoint ?? bearerTokenServerAuthenticationEntryPoint({});\n    const converter = opts?.converter ?? serverBearerTokenAuthenticationConverter({});\n    const failureHandler = opts.failureHandler ?? serverAuthenticationEntryPointFailureHandler({entryPoint})\n    if (opts.managerResolver!== undefined) {\n        return authenticationFilter({\n            storage: opts.storage,\n            converter,\n            failureHandler,\n            managerResolver: opts.managerResolver,\n        });\n    }\n    if (opts.jwt !== undefined) {\n\n        const manager = opts.jwt.manager ?? jwtAuthManager(opts.jwt);\n        return authenticationFilter({\n            storage: opts.storage,\n            converter,\n            failureHandler,\n            managerResolver: async (_exchange: ServerWebExchange) => {\n                return manager;\n            },\n        });\n    }\n    throw new Error(\"Invalid resource server configuration: either managerResolver or jwt must be provided\");\n}\n", "import {\n    type Authentication,\n    type AuthenticationManager,\n    AuthorizationDecision,\n    DefaultAuthorizationManager,\n    type ServerAuthenticationEntryPoint,\n    type ServerAuthenticationSuccessHandler\n} from './types.ts';\nimport headers from './http-headers.ts';\nimport httpBasic from './http-basic.ts';\nimport resourceServer from './oauth2-resource-server.ts';\nimport serverBearerTokenAuthenticationConverter from './oauth2/token-converter.ts';\nimport bearerTokenServerAuthenticationEntryPoint from './oauth2/token-entry-point.ts';\nimport { BadJwtError, type Jwt, JwtError } from './oauth2/jwt-auth-manager.ts';\nimport { jwtVerifier, JwtVerifyError } from '@interopio/gateway/jose/jwt';\nimport {\n    anyExchange,\n    match,\n    NO_MATCH,\n    type ServerWebExchangeMatcher,\n    type ServerWebExchangeMatcherEntry\n} from '../util/matchers.ts';\nimport { errorFilter } from './error-filter.ts';\nimport { delegatingEntryPoint } from './delegating-entry-point.ts';\nimport delegatingAuthorizationManager from './delegating-authorization-manager.ts';\nimport authorizationFilter from './authorization-filter.ts';\nimport { exchangeFilter } from './exchange-filter.ts';\nimport type { SecurityContext } from './security-context.ts';\nimport cors from '../cors.ts';\nimport { type AsyncLocalStorage } from 'node:async_hooks';\nimport type { ServerWebExchange } from '../../../types/web/server';\nimport x509 from './x509.ts';\nimport { subjectX500PrincipalExtractor } from './preauth/x509.ts';\nimport { userDetailsServiceAuthenticationManager } from './users.ts';\nimport type { UserDetailsPasswordService, UserDetailsService } from './users/types.ts';\nimport type { CorsConfigSource } from '../../web/cors/types.ts';\nimport type { WebFilter } from '../../web/server/types.ts';\nimport { MatcherSecurityWebFilterChain, type SecurityWebFilterChain } from './web.ts';\n\nexport type HttpSecurityConfig = {\n    authorize?: Array<[\n            'any-exchange' | ServerWebExchangeMatcher,\n        ( { access: 'permitted' | 'denied' | 'authenticated' }\n            | { access: 'has-any-authority', authorities: string[] }\n            | { access: 'has-ip-address', address: string })\n    ]>,\n    headers?: {\n        disabled?: boolean\n        xss?: { disabled?: boolean }\n    },\n    x509?: {\n        disabled?: boolean\n        /** Extract principal from Subject Alternative Name. Use 'email' to extract from email SAN. If undefined, uses subject (default). */\n        principalAltName?: 'email'\n    }\n    cors?: {\n        disabled?: boolean\n    }\n    basic?: {\n        disabled?: boolean\n        realm?: string\n    },\n    jwt?: {\n        disabled?: boolean;\n        issuerUri?: string; // base URI for the issuer, e.g. 'https://example.com'\n        issuer?: string;\n        audience?: string | string[]; // audience for the JWT, e.g. 'https://example.com/api'\n    }\n}\n\nconst filterOrder = {\n    first: Number.MAX_SAFE_INTEGER,\n    http_headers: 1 * 100,\n    https_redirect: 2 * 100,\n    cors: 3 * 100,\n    http_basic: 6 * 100,\n    authentication: 8 * 100,\n    security_context_server_web_exchange: 15 * 100,\n    error_translation: 18 * 100,\n    authorization: 19 * 100,\n    last: Number.MAX_SAFE_INTEGER\n}\nconst filterOrderSymbol = Symbol.for(\"filterOrder\");\n\nexport default (config: HttpSecurityConfig,\n                context: {\n                    storage: AsyncLocalStorage<{ securityContext?: Promise<SecurityContext> }>\n                    corsConfigSource?: CorsConfigSource,\n                    userDetailsService?: UserDetailsService,\n                    userDetailsPasswordService?: UserDetailsPasswordService,\n                    authenticationManager?: AuthenticationManager,\n                }): SecurityWebFilterChain => {\n\n    const getService = <T>(name: string, defaultService?: T): T => {\n        if (context === undefined) {\n            return defaultService as T; // will not throw but return defaultService which may be undefined\n        }\n        if (name === 'UserDetailsService' && context.userDetailsService !== undefined) {\n            return context.userDetailsService as T;\n        }\n        if (name === 'AuthenticationManager' && context.authenticationManager !== undefined) {\n            return context.authenticationManager as T;\n        }\n        if (defaultService !== undefined) {\n            return defaultService;\n        }\n        throw new Error(`No service registered with name: ${name}`);\n    };\n\n    const authenticationManager = (): AuthenticationManager | undefined => {\n        if (context.authenticationManager !== undefined) {\n            return context.authenticationManager;\n        }\n        if (context.userDetailsService !== undefined) {\n            const manager = userDetailsServiceAuthenticationManager(context.userDetailsService, {\n                userDetailsPasswordService: context.userDetailsPasswordService\n            });\n            return manager;\n        }\n    }\n\n\n    const middleware: WebFilter[] = [];\n\n    class ServerHttpSecurity {\n        #authenticationEntryPoint?: ServerAuthenticationEntryPoint;\n        readonly #defaultEntryPoints: Array<[ServerWebExchangeMatcher, ServerAuthenticationEntryPoint]> = [];\n        #authenticationManager?: AuthenticationManager;\n\n        set authenticationManager(authenticationManager: AuthenticationManager | undefined) {\n            this.#authenticationManager = authenticationManager;\n        }\n\n        get authenticationEntryPoint(): ServerAuthenticationEntryPoint | undefined {\n            if (this.#authenticationEntryPoint !== undefined || this.#defaultEntryPoints.length === 0) {\n                return this.#authenticationEntryPoint!;\n            }\n            if (this.#defaultEntryPoints.length === 1) {\n                return this.#defaultEntryPoints[0][1];\n            }\n            return delegatingEntryPoint({\n                entryPoints: this.#defaultEntryPoints,\n                defaultEntryPoint: this.#defaultEntryPoints[this.#defaultEntryPoints.length - 1][1]\n            });\n        }\n\n\n        build() {\n            if (config.headers !== undefined && config.headers.disabled !== true) {\n                const writer: WebFilter = headers(config.headers);\n                writer[filterOrderSymbol] = filterOrder.http_headers;\n                middleware.push(writer);\n            }\n            if (config.x509 !== undefined && config.x509.disabled !== true) {\n\n                const filter: WebFilter = x509({\n                    storage: context.storage,\n                    getService,\n                    extractor: subjectX500PrincipalExtractor({ principalAltName: config.x509.principalAltName })\n                });\n                filter[filterOrderSymbol] = filterOrder.authentication;\n                middleware.push(filter);\n            }\n            if (config.cors?.disabled !== true && context.corsConfigSource !== undefined) {\n                const filter: WebFilter = cors({corsConfigSource: context.corsConfigSource });\n                filter[filterOrderSymbol] = filterOrder.cors;\n                middleware.push(filter);\n            }\n\n            if (config.basic !== undefined && config.basic?.disabled !== true) {\n\n                const defaultSuccessHandlers: ServerAuthenticationSuccessHandler[] = [\n                    async ({exchange, chain}, _authentication) => {\n                        return await chain.filter(exchange);\n                    }\n                ];\n\n                const filter = httpBasic({\n                    storage: context.storage,\n                    manager: this.#authenticationManager!,\n                    defaultEntryPoints: this.#defaultEntryPoints,\n                    defaultSuccessHandlers,\n                });\n                filter[filterOrderSymbol] = filterOrder.http_basic;\n                middleware.push(filter);\n            }\n            if (config.jwt !== undefined && config.jwt.disabled !== true) {\n\n                const verifier = jwtVerifier({\n                    issuerBaseUri: config.jwt.issuerUri,\n                    issuer: config.jwt.issuer,\n                    audience: config.jwt.audience\n                });\n                const decoder = async (token: string): Promise<Jwt> => {\n                    try {\n                        const {payload} = await verifier(token);\n                        return {\n                            tokenValue: token,\n                            subject: payload.sub,\n                            getClaimAsString(claim: string): string | undefined {\n                                return payload[claim] as string | undefined;\n                            }\n                        };\n                    } catch (e) {\n                        if (e instanceof JwtVerifyError) {\n                            throw new BadJwtError(e.message, {cause: e});\n                        }\n                        throw new JwtError(\"error occurred while attempting to decoding jwt\", {cause: e});\n                    }\n                }\n\n\n                const authenticationConverter = serverBearerTokenAuthenticationConverter({uriQueryParameter: true});\n                const authenticationConverterMatcher: ServerWebExchangeMatcher = async (exchange) => {\n                    try {\n                        const a = await authenticationConverter(exchange)\n                        if (a === undefined) {\n                            return NO_MATCH;\n                        }\n                        return match();\n                    }\n                    catch (e) {\n                        return NO_MATCH;\n                    }\n                }\n\n                const entryPoint = bearerTokenServerAuthenticationEntryPoint({});\n\n                this.#defaultEntryPoints.push([authenticationConverterMatcher, entryPoint]);\n\n                const filter: WebFilter = resourceServer({\n                    storage: context.storage,\n                    entryPoint: entryPoint,\n                    converter: authenticationConverter,\n                    jwt: {decoder}});\n                filter[filterOrderSymbol] = filterOrder.authentication;\n                middleware.push(filter);\n\n            }\n            const exchangeF: WebFilter = exchangeFilter({storage: context.storage});\n            middleware.push(exchangeF);\n            exchangeF[filterOrderSymbol] = filterOrder.security_context_server_web_exchange;\n\n\n            if (config.authorize !== undefined) {\n                const errorFf: WebFilter = errorFilter({authenticationEntryPoint: this.authenticationEntryPoint});\n                errorFf[filterOrderSymbol] = filterOrder.error_translation;\n                middleware.push(errorFf)\n                const buildAuthorizationManager = (authorize: HttpSecurityConfig['authorize']) => {\n                    const mappings: ServerWebExchangeMatcherEntry<DefaultAuthorizationManager<{\n                        exchange: ServerWebExchange\n                    }>>[] = [];\n                    let anyExchangeRegistered = false;\n                    for (const [matcher, access] of authorize ?? []) {\n                        let serverMatcher: ServerWebExchangeMatcher;\n                        if (matcher === 'any-exchange') {\n                            anyExchangeRegistered = true;\n                            serverMatcher = anyExchange;\n                        } else if (anyExchangeRegistered) {\n                            throw new Error(\"Cannot register other matchers after 'any-exchange' matcher\");\n                        } else {\n                            serverMatcher = matcher;\n                        }\n                        let manager: DefaultAuthorizationManager<{ exchange: ServerWebExchange }>;\n                        if (access.access === 'permitted') {\n                            manager = new DefaultAuthorizationManager(async () => new AuthorizationDecision(true));\n                            manager.toString = () => 'AuthorizationManager[permitted]';\n                        } else if (access.access === 'denied') {\n                            manager = new DefaultAuthorizationManager(async () => new AuthorizationDecision(false));\n                            manager.toString = () => 'AuthorizationManager[denied]';\n                        } else if (access.access === 'authenticated') {\n                            manager = new DefaultAuthorizationManager(async (p: Promise<Authentication | undefined>) => {\n                                const authentication = await p;\n                                if (authentication !== undefined) {\n                                    return new AuthorizationDecision(authentication.authenticated);\n                                }\n                                return new AuthorizationDecision(false);\n                            });\n                            manager.toString = () => 'AuthorizationManager[authenticated]';\n                        } else {\n                            throw new Error(`Unknown access type: ${JSON.stringify(access)}`);\n                        }\n                        mappings.push([serverMatcher, manager]);\n                    }\n                    return delegatingAuthorizationManager({mappings});\n                }\n                const manager = buildAuthorizationManager(config.authorize);\n                const filter: WebFilter = authorizationFilter({manager, storage: context.storage});\n                filter[filterOrderSymbol] = filterOrder.authorization;\n                middleware.push(filter);\n\n            }\n\n            middleware.sort((a, b) => {\n                const aOrder = a[filterOrderSymbol] ?? filterOrder.last;\n                const bOrder = b[filterOrderSymbol] ?? filterOrder.last;\n                return aOrder - bOrder;\n            });\n        }\n    }\n\n\n    const security = new ServerHttpSecurity();\n    security.authenticationManager = authenticationManager();\n    security.build();\n\n\n    return new MatcherSecurityWebFilterChain(anyExchange, ...middleware);\n};\n", "import {\n    type Authentication,\n    AccessDeniedError,\n    AuthenticationError,\n    InsufficientAuthenticationError,\n    type ServerAuthenticationEntryPoint,\n    isAuthentication\n} from './types.ts';\nimport { httpBasicEntryPoint } from './http-basic-entry-point.ts';\nimport type { ServerWebExchange } from '../../../types/web/server';\nimport { HttpStatus } from '../../http/status.ts';\nimport type { WebFilterChain } from '../../web/server/types.ts';\n\nasync function commenceAuthentication(exchange: ServerWebExchange, authentication: Authentication | undefined, entryPoint: ServerAuthenticationEntryPoint) {\n    const cause = new InsufficientAuthenticationError(`Full authentication is required to access this resource.`);\n    const e: AuthenticationError = new AuthenticationError(\"Access Denied\", {cause});\n    if (authentication) {\n        e.authentication = authentication;\n    }\n    await entryPoint(exchange, e);\n}\nexport function httpStatusAccessDeniedHandler(httpStatus: HttpStatus) {\n    return async (exchange: ServerWebExchange, _error: AccessDeniedError) => {\n        exchange.response.setStatusCode(httpStatus);\n        exchange.response.headers.set(\"Content-Type\", \"text/plain; charset=utf-8\");\n        const buffer = Buffer.from(\"Access Denied\", \"utf-8\");\n        exchange.response.headers.set('Content-Length', buffer.length);\n        await exchange.response.body(buffer);\n    };\n}\n\nexport const errorFilter = (opts: {\n    authenticationEntryPoint?: ServerAuthenticationEntryPoint\n}) => {\n    const accessDeniedHandler = httpStatusAccessDeniedHandler(HttpStatus.FORBIDDEN);\n    const authenticationEntryPoint = opts.authenticationEntryPoint ?? httpBasicEntryPoint();\n    return {\n        filter: async (exchange: ServerWebExchange, chain: WebFilterChain) => {\n            try {\n                await chain.filter(exchange);\n            }\n            catch (error) {\n                if (error instanceof AccessDeniedError) {\n                    const principal = await exchange.principal();\n                    if (!isAuthentication(principal)) {\n                        await commenceAuthentication(exchange, undefined, authenticationEntryPoint);\n                    }\n                    else {\n                        if (!principal.authenticated) {\n                            await accessDeniedHandler(exchange, error);\n                        }\n                        await commenceAuthentication(exchange, principal, authenticationEntryPoint);\n                    }\n                    return;\n                }\n                throw error;\n            }\n        }\n    };\n}\n", "import type {ServerWebExchangeMatcherEntry} from '../util/matchers.ts';\nimport {type Authentication, AuthorizationDecision, type AuthorizationManager, DefaultAuthorizationManager} from './types.ts';\nimport getLogger from '../../logger.ts';\nimport type {ServerWebExchange} from '../../../types/web/server';\n\nconst logger = getLogger('security.auth');\n\nexport default function delegatingAuthorizationManager(opts: { mappings: Array<ServerWebExchangeMatcherEntry<AuthorizationManager<{ exchange: ServerWebExchange }>>> }) {\n    const check = async (authentication: Promise<Authentication | undefined>, exchange: ServerWebExchange): Promise<AuthorizationDecision> => {\n        let decision: AuthorizationDecision;\n        for (const [matcher, manager] of opts.mappings) {\n            if ((await matcher(exchange))?.match) {\n                logger.debug(`checking authorization on '${exchange.request.path}' using [${matcher}, ${manager}]`);\n                const checkResult = await manager.authorize(authentication, {exchange});\n                if (checkResult !== undefined) {\n                    decision = checkResult;\n                    break;\n                }\n            }\n        }\n        decision ??= new AuthorizationDecision(false);\n        return decision;\n\n    }\n    return new DefaultAuthorizationManager(check);\n}\n", "import { AccessDeniedError, type AuthorizationManager } from './types.ts';\nimport { AsyncStorageSecurityContextHolder, type SecurityContext } from './security-context.ts';\nimport type { AsyncLocalStorage } from 'node:async_hooks';\nimport type { ServerWebExchange } from '../../../types/web/server';\n\nimport getLogger from '../../logger.ts';\nimport type { WebFilterChain } from '../../web/server/types.ts';\n\nconst logger = getLogger('security.auth');\n\nexport default function authorizationFilter(opts: {\n    storage: AsyncLocalStorage<{ securityContext?: Promise<SecurityContext> }>,\n    manager: AuthorizationManager<ServerWebExchange>\n}) {\n\n    const { manager, storage } = opts;\n\n    return {\n        filter: async (exchange: ServerWebExchange, chain: WebFilterChain) => {\n            const promise = AsyncStorageSecurityContextHolder.getContext(storage)\n                .then(c => c?.authentication);\n            try {\n                await manager.verify(promise, exchange);\n                if (logger.enabledFor('debug')) {\n                    logger.debug('authorization successful')\n                }\n            }\n            catch (error) {\n                if (error instanceof AccessDeniedError) {\n                    if (logger.enabledFor('debug')) {\n                        logger.debug(`authorization failed: ${error.message}`);\n                    }\n                }\n                throw error;\n            }\n            await chain.filter(exchange);\n        }\n    };\n}\n", "import { AsyncStorageSecurityContextHolder, type  SecurityContext } from './security-context.ts';\nimport { ServerWebExchangeDecorator } from '../exchange.ts';\nimport type { ServerWebExchange } from '../../../types/web/server';\nimport type { Principal } from '../../../types/auth';\nimport type { AsyncLocalStorage } from 'node:async_hooks';\nimport type { WebFilterChain } from '../../web/server/types.ts';\n\n\nexport class SecurityContextServerWebExchange extends ServerWebExchangeDecorator {\n    readonly #context: () => Promise<SecurityContext | undefined>;\n    constructor(exchange: ServerWebExchange, context: () => Promise<SecurityContext | undefined>) {\n        super(exchange);\n        this.#context = context;\n    }\n\n    async principal<T extends Principal>(): Promise<T | undefined> {\n        const context = await this.#context();\n        return context?.authentication as (T | undefined);\n    }\n}\n\nexport const exchangeFilter = (opts: {storage: AsyncLocalStorage<{ securityContext?: Promise<SecurityContext> }>}) => {\n    const storage = opts.storage;\n    return {\n        filter: async (exchange: ServerWebExchange, chain: WebFilterChain) => {\n            await chain.filter(new SecurityContextServerWebExchange(exchange, async () => await AsyncStorageSecurityContextHolder.getContext(storage)));\n        }\n    };\n}\n", "import type { AbstractAuthenticationToken, AuthenticationConverter } from './types.ts';\nimport type { X509PrincipalExtractor } from './preauth/x509.ts';\nimport type { ServerWebExchange } from '../../../types/web/server';\n\nexport const x509Converter = (opts: { principalExtractor: X509PrincipalExtractor }): AuthenticationConverter => {\n    const { principalExtractor } = opts;\n    return async (exchange: ServerWebExchange): Promise<AbstractAuthenticationToken | undefined> => {\n        const sslInfo = exchange.request.sslInfo;\n        if (sslInfo === undefined) {\n            // no SslInfo provided with a request, skipping x509 authentication\n            return;\n        }\n        if (sslInfo.peerCertificate === undefined) {\n            // no peer certificate found in SslInfo, skipping x509 authentication\n            return;\n        }\n        const clientCertificate = sslInfo.peerCertificate;\n        const principal = principalExtractor(clientCertificate);\n        return {\n            type: 'PreAuthenticated',\n            authenticated: false,\n            principal,\n            name: principal ?? '',\n            credentials: clientCertificate\n        };\n    }\n}\n", "import type {X509Certificate} from 'node:crypto';\nimport { BadCredentialsError } from '../types.ts';\n\nexport type X509PrincipalExtractor = (cert: X509Certificate) => string;\n\n/**\n * Extracts principal from X.509 certificate.\n * By default, extracts from certificate subject.\n * If principalAltName is 'email', extracts from email in Subject Alternative Name.\n */\nexport const subjectX500PrincipalExtractor: (opts?: {\n    principalAltName?: 'email'\n}) => X509PrincipalExtractor = (opts) => {\n    const extractFromEmail = opts?.principalAltName === 'email';\n    const subjectDnRegEx = /CN=(.*?)(?:,|$)/mi;\n    return (cert: X509Certificate): string => {\n        if (extractFromEmail) {\n            const email = cert.subjectAltName?.split(', ').find((altName) => altName.startsWith('email:'));\n            if (email) {\n                return email.replace('email:', '');\n            }\n        }\n        // Default: extract from subject\n        const result = subjectDnRegEx.exec(cert.subject);\n        if (result === null) {\n            throw new BadCredentialsError(`Cannot extract principal from subject DN: ${cert.subject}`);\n        }\n        const username = result[1];\n        return username;\n    }\n}\n", "import type { PasswordEncoder } from './index.ts';\n\nexport abstract class AbstractPasswordEncoder implements PasswordEncoder {\n    async encode(rawPassword?: string): Promise<string | undefined> {\n        if (rawPassword === undefined || rawPassword === null) {\n            return undefined\n        }\n        return await this.encodeDefinedPassword(rawPassword.toString());\n    }\n\n    abstract encodeDefinedPassword(rawPassword: string): Promise<string>;\n\n    async matches(rawPassword?: string, encodedPassword?: string): Promise<boolean> {\n        if (!rawPassword || !encodedPassword) {\n            return false;\n        }\n        return await this.matchesDefined(rawPassword.toString(), encodedPassword);\n    }\n\n    abstract matchesDefined(rawPassword: string, encodedPassword: string): Promise<boolean>;\n\n\n    upgradeEncoding(encodedPassword?: string): boolean {\n        if (!encodedPassword) {\n            return false;\n        }\n        return this.upgradeEncodingDefined(encodedPassword);\n    }\n\n    protected upgradeEncodingDefined(encodedPassword: string): boolean {\n        return false;\n    }\n\n}\n\nexport class DelegatingPasswordEncoder extends AbstractPasswordEncoder {\n    static DEFAULT_ID_PREFIX = '{'; // {\n    static DEFAULT_ID_SUFFIX = '}'; // }\n    readonly #idPrefix: string;\n    readonly #idSuffix: string;\n    readonly #idForEncode: string;\n    readonly #encoderForEncode: PasswordEncoder;\n    readonly #encoders: Map<string, PasswordEncoder>\n\n    #defaultEncoderForMatches: PasswordEncoder = new class extends AbstractPasswordEncoder {\n        readonly #outer: DelegatingPasswordEncoder;\n        constructor(outer: DelegatingPasswordEncoder) {\n            super();\n            this.#outer = outer;\n        }\n        async encodeDefinedPassword(rawPassword: string): Promise<string> {\n            throw new Error('encode is not supported');\n        }\n\n        async matchesDefined(rawPassword: string, prefixEncodedPassword: string): Promise<boolean> {\n            const id = this.#outer.#extractId(prefixEncodedPassword);\n            if (!id) {\n                throw new Error(`No password encoder mapped for id ${id}`);\n            }\n            if (prefixEncodedPassword) {\n                const start = prefixEncodedPassword.indexOf(this.#outer.#idPrefix);\n                const end = prefixEncodedPassword.indexOf(this.#outer.#idSuffix, start + this.#outer.#idPrefix.length);\n                if (start === -1 && end === -1) {\n                    throw new Error(`No prefix found in encoded password`);\n                }\n            }\n            throw new Error(`malformed password encoder prefix`);\n        }\n    }(this);\n\n    constructor(idForEncode: string, encoders: Map<string, PasswordEncoder>, idPrefix:string = DelegatingPasswordEncoder.DEFAULT_ID_PREFIX, idSuffix: string = DelegatingPasswordEncoder.DEFAULT_ID_SUFFIX) {\n        if (idForEncode === undefined || idForEncode === null) {\n            throw new Error('idForEncode cannot be null or undefined');\n        }\n        if (idPrefix === undefined || idPrefix === null) {\n            throw new Error(`idPrefix cannot be null or undefined`);\n        }\n        if (!idSuffix) {\n            throw new Error(`idSuffix cannot be empty`);\n        }\n        if (idPrefix.indexOf(idSuffix) !== -1) {\n            throw new Error(`idPrefix \"${idPrefix}\" cannot contain idSuffix \"${idSuffix}\"`);\n        }\n        if (!encoders.has(idForEncode)) {\n            throw new Error(`No PasswordEncoder mapped for id \"${idForEncode}\"`);\n        }\n        for (const id of encoders.keys()) {\n            if (id === null) {\n                continue;\n            }\n            if (idPrefix && id.includes(idPrefix)) {\n                throw new Error(`id \"${id}\" cannot include ${idPrefix}`);\n            }\n            if (idSuffix && id.includes(idSuffix)) {\n                throw new Error(`id \"${id}\" cannot include ${idSuffix}`);\n            }\n        }\n        super();\n        this.#idForEncode = idForEncode;\n        this.#encoderForEncode = encoders.get(idForEncode)!;\n        this.#encoders = new Map(encoders);\n        this.#idPrefix = idPrefix;\n        this.#idSuffix = idSuffix;\n    }\n\n    set defaultPasswordEncoderForMatches(encoder: PasswordEncoder) {\n        if (encoder === null || encoder === undefined) {\n            throw new Error('defaultPasswordEncoderForMatches cannot be null or undefined');\n        }\n        this.#defaultEncoderForMatches = encoder;\n    }\n\n    async encodeDefinedPassword(rawPassword: string): Promise<string> {\n        const encoded = await this.#encoderForEncode.encode(rawPassword);\n        return `${this.#idPrefix}${this.#idForEncode}${this.#idSuffix}${encoded}`;\n    }\n\n    async matchesDefined(rawPassword: string, prefixEncodedPassword: string): Promise<boolean> {\n        const id = this.#extractId(prefixEncodedPassword);\n        const delegate = id ? this.#encoders.get(id) : undefined;\n        if (delegate === undefined) {\n            return await this.#defaultEncoderForMatches.matches(rawPassword, prefixEncodedPassword);\n        }\n        else {\n            const encodedPassword = this.#extractEncodedPassword(prefixEncodedPassword);\n            return await delegate.matches(rawPassword, encodedPassword);\n        }\n    }\n\n    #extractId(encodedPassword?: string): string | undefined {\n        if (encodedPassword === undefined) {\n            return undefined;\n        }\n        const start = encodedPassword.indexOf(this.#idPrefix);\n        if (start !== 0) {\n            return undefined;\n        }\n        const end = encodedPassword.indexOf(this.#idSuffix, start + this.#idPrefix.length);\n        if (end === -1) {\n            return undefined;\n        }\n        return encodedPassword.substring(start + this.#idPrefix.length, end);\n    }\n\n    protected upgradeEncodingDefined(prefixEncodedPassword: string): boolean {\n        const id = this.#extractId(prefixEncodedPassword);\n        if (this.#idForEncode !== id) {\n            // todo case-insensitive compare?\n            return true;\n        }\n        else {\n            const encodedPassword = this.#extractEncodedPassword(prefixEncodedPassword);\n            return this.#encoderForEncode.upgradeEncoding?.(encodedPassword) ?? false;\n        }\n    }\n\n    #extractEncodedPassword(prefixEncodedPassword: string) {\n        const start = prefixEncodedPassword.indexOf(this.#idSuffix);\n        return prefixEncodedPassword.substring(start + this.#idSuffix.length);\n    }\n\n}\n\nexport class NoopPasswordEncoder extends AbstractPasswordEncoder {\n    static readonly #INSTANCE = new NoopPasswordEncoder();\n\n    static get instance(): NoopPasswordEncoder {\n        return NoopPasswordEncoder.#INSTANCE;\n    }\n\n    private constructor() {\n        super();\n    }\n\n    async encodeDefinedPassword(rawPassword: string): Promise<string> {\n        return rawPassword.toString();\n    }\n\n    async matchesDefined(rawPassword: string, encodedPassword: string): Promise<boolean> {\n        return rawPassword.toString() === encodedPassword;\n    }\n}\n", "import { AbstractPasswordEncoder } from './password.ts';\nimport { argon2, keygen } from '@interopio/gateway-server/tools';\n\n/**\n * Constant-time buffer comparison to prevent timing attacks.\n *\n * @param a - First buffer\n * @param b - Second buffer\n * @returns true if buffers are equal, false otherwise\n */\nfunction bufferEquals(a: Buffer, b: Buffer): boolean {\n    if (a.length !== b.length) {\n        return false;\n    }\n    let diff = 0;\n    for (let i = 0; i < a.length; i++) {\n        diff |= a[i] ^ b[i];\n    }\n    return diff === 0;\n}\n\n\n\nexport class Argon2PasswordEncoder extends AbstractPasswordEncoder {\n    readonly #saltLength: number;\n    readonly #hashLength: number;\n    readonly #parallelism: number;\n    readonly #memory: number\n    readonly #passes: number;\n\n    constructor(\n        saltLength: number = argon2.DEFAULT_SALT_LENGTH,\n        hashLength: number = argon2.DEFAULT_HASH_LENGTH,\n        parallelism: number = argon2.DEFAULT_PARALLELISM,\n        memory: number = argon2.DEFAULT_MEMORY,\n        passes: number = argon2.DEFAULT_PASSES\n    ) {\n        super();\n        this.#saltLength = saltLength;\n        this.#hashLength = hashLength;\n        this.#parallelism = parallelism;\n        this.#memory = memory;\n        this.#passes = passes;\n    }\n\n    async matchesDefined(rawPassword: string, encodedPassword: string): Promise<boolean> {\n        try {\n            const decoded = argon2.decode(encodedPassword);\n            const hash = await argon2.createHash(\n                decoded.algorithm,\n                rawPassword,\n                decoded.hash.length,\n                decoded.parameters\n            );\n            return bufferEquals(decoded.hash, hash);\n        } catch {\n            return false;\n        }\n    }\n\n    async encodeDefinedPassword(rawPassword: string): Promise<string> {\n        const nonce = keygen.createSalt(this.#saltLength);\n        const parameters = {\n            memory: this.#memory,\n            passes: this.#passes,\n            parallelism: this.#parallelism,\n            nonce\n        };\n        const hash = await argon2.createHash(\n            'argon2id',\n            rawPassword,\n            this.#hashLength,\n            parameters\n        );\n        return argon2.encode({\n            algorithm: 'argon2id',\n            version: argon2.ARGON2_VERSION,\n            parameters,\n            hash\n        });\n    }\n\n    upgradeEncodingDefined(encodedPassword: string): boolean {\n        const decoded = argon2.decode(encodedPassword);\n        return decoded.version < argon2.ARGON2_VERSION || decoded.parameters.memory < this.#memory || decoded.parameters.passes < this.#passes;\n    }\n}\n", "import { DelegatingPasswordEncoder, NoopPasswordEncoder } from './password.ts';\nimport { Argon2PasswordEncoder } from './argon2.ts';\n\nexport const MAX_PASSWORD_LENGTH = 4096;\n\nexport interface PasswordEncoder {\n    encode(rawPassword?: string): Promise<string | undefined>;\n\n    matches(rawPassword?: string, encodedPassword?: string): Promise<boolean>;\n\n    upgradeEncoding?(encodedPassword?: string): boolean;\n}\n\nexport function createDelegatingPasswordEncoder(): PasswordEncoder {\n    const idForEncode = 'argon2id';\n    const encoders: Map<string, PasswordEncoder> = new Map<string, PasswordEncoder>([\n        [idForEncode, new Argon2PasswordEncoder()], ['noop', NoopPasswordEncoder.instance]]);\n    return new DelegatingPasswordEncoder(idForEncode, encoders, DelegatingPasswordEncoder.DEFAULT_ID_PREFIX, DelegatingPasswordEncoder.DEFAULT_ID_SUFFIX);\n}\n", "import { AuthenticationError, type GrantedAuthority, type CredentialsHolder } from '../types.ts';\n\nexport type UserDetails = {\n    readonly username: string;\n    readonly password?: string | null; // null means credentials have been erased\n    readonly authorities: ReadonlyArray<GrantedAuthority>;\n\n    readonly accountExpired?: boolean;\n    // Indicates whether the user's account is locked. A locked account prevents authentication.\n    readonly accountLocked?: boolean;\n    // Indicates whether the user's credentials (password) has expired. Expired credentials prevent authentication.\n    readonly credentialsExpired?: boolean;\n    // Indicates whether the user is enabled or disabled. A disabled user cannot be authenticated.\n    readonly disabled?: boolean;\n};\n\nexport type UserDetailsChecker = (user: UserDetails) => void;\n\nexport interface UserDetailsService {\n    findByUsername(username: string): Promise<UserDetails | undefined>;\n}\n\nexport interface UserDetailsPasswordService {\n    updatePassword(user: UserDetails, newPassword?: string): Promise<UserDetails>;\n}\n\nexport const NoopUserDetailsPasswordService: UserDetailsPasswordService = {\n    async updatePassword(user: UserDetails, _newPassword?: string): Promise<UserDetails> {\n        return user;\n    }\n}\n\nexport class UsernameNotFoundError extends AuthenticationError {\n    readonly username?: string;\n\n    constructor(message: string, username?: string, options?: ErrorOptions) {\n        super(message, options);\n        this.username = username;\n    }\n}\n\nexport type User = UserDetails & CredentialsHolder & { toString(): string };\n\nexport class UserBuilder {\n    #username!: string;\n    #password?: string | null;\n    #authorities: ReadonlyArray<GrantedAuthority> = [];\n    #accountExpired?: boolean;\n    #accountLocked?: boolean;\n    #credentialsExpired?: boolean;\n    #disabled?: boolean;\n\n    #passwordEncoder: (rawPassword?: string | null) => string | undefined | null = (rawPassword) => rawPassword;\n\n    private constructor() {\n    }\n\n    static ofUsername(username: string): UserBuilder {\n        return new UserBuilder().username(username);\n    }\n\n    static ofUserDetails(user: UserDetails): UserBuilder {\n        const builder = UserBuilder.ofUsername(user.username)\n            .accountExpired(user.accountExpired ?? false)\n            .accountLocked(user.accountLocked ?? false)\n            .authorities(user.authorities)\n            .credentialsExpired(user.credentialsExpired ?? false)\n            .disabled(user.disabled ?? false);\n        if (user.password !== undefined) {\n            builder.password(user.password);\n        }\n        return builder;\n    }\n\n    username(username: string): this {\n        if (!username) {\n            throw new TypeError('username cannot be empty');\n        }\n        this.#username = username;\n        return this;\n    }\n\n    password(password?: string | null): this {\n        this.#password = password;\n        return this;\n    }\n\n    passwordEncoder(encoder: (rawPassword?: string | null) => string | null | undefined): this {\n        if (!encoder) {\n            throw new TypeError('password encoder cannot be null or undefined');\n        }\n        this.#passwordEncoder = encoder;\n        return this;\n    }\n\n    roles(...roles: string[]): this {\n        return this.authorities(roles.map(role => {\n            if (role.startsWith('role:')) {\n                throw new Error(`${role}  must not start with 'role:' (it is automatically added)`);\n            }\n            const authority = `role:${role}`;\n            return { authority };\n        }));\n    }\n\n    authorities(authorities: ReadonlyArray<GrantedAuthority>): this {\n        this.#authorities = [...authorities];\n        return this;\n    }\n\n    accountExpired(accountExpired: boolean): this {\n        this.#accountExpired = accountExpired;\n        return this;\n    }\n\n    accountLocked(accountLocked: boolean): this {\n        this.#accountLocked = accountLocked;\n        return this;\n    }\n\n    credentialsExpired(credentialsExpired: boolean): this {\n        this.#credentialsExpired = credentialsExpired;\n        return this;\n    }\n\n    disabled(disabled: boolean): this {\n        this.#disabled = disabled;\n        return this;\n    }\n\n    build(): User {\n        if (!this.#username) {\n            throw new TypeError('username is required');\n        }\n        let encodedPassword: string | null | undefined = this.#password !== undefined ? this.#passwordEncoder(this.#password) : undefined;\n        return {\n            username: this.#username,\n            password: encodedPassword,\n            authorities: this.#authorities,\n            accountExpired: this.#accountExpired,\n            accountLocked: this.#accountLocked,\n            credentialsExpired: this.#credentialsExpired,\n            disabled: this.#disabled,\n            eraseCredentials(): void {\n                encodedPassword = null;\n            },\n            toString(): string {\n                return `User(username=${this.username}, password=[PROTECTED], authorities=${JSON.stringify(this.authorities)}, accountExpired=${this.accountExpired}, accountLocked=${this.accountLocked}, credentialsExpired=${this.credentialsExpired}, disabled=${this.disabled})`;\n            }\n        }\n    }\n}\n", "import {\n    type AbstractAuthenticationToken,\n    AccountExpiredError,\n    type AuthenticatedPrincipal,\n    type Authentication,\n    type AuthenticationManager,\n    BadCredentialsError,\n    CredentialsExpiredError,\n    DisabledError,\n    LockedError\n} from './types.ts';\nimport { createDelegatingPasswordEncoder, type PasswordEncoder } from './crypto/index.ts';\nimport getLogger from '../../logger.ts';\nimport {\n    NoopUserDetailsPasswordService,\n    type UserDetails,\n    type UserDetailsChecker,\n    type UserDetailsPasswordService,\n    type UserDetailsService,\n    UsernameNotFoundError\n} from './users/types.ts';\n\nconst logger = getLogger('security.users');\n\nexport function userDetailsServiceAuthenticationManager(\n    userDetailsService: UserDetailsService,\n    options?: {\n        preAuthenticationChecks?: UserDetailsChecker;\n        postAuthenticationChecks?: UserDetailsChecker;\n        passwordEncoder?: PasswordEncoder;\n        userDetailsPasswordService?: UserDetailsPasswordService;\n    }\n): AuthenticationManager {\n    const preAuthenticationChecks = options?.preAuthenticationChecks ?? ((user: UserDetails) => {\n        if (user.accountLocked) {\n            logger.debug(`user account is locked`);\n            throw new LockedError(`User account is locked`);\n        }\n        if (user.disabled) {\n            logger.debug(`user account is disabled`);\n            throw new DisabledError(`User is disabled`);\n        }\n        if (user.accountExpired) {\n            logger.debug(`user account is expired`);\n            throw new AccountExpiredError(`User account has expired`);\n        }\n    });\n    const postAuthenticationChecks = options?.postAuthenticationChecks ?? ((user: UserDetails) => {\n        if (user.credentialsExpired) {\n            logger.debug(`user credentials have expired`);\n            throw new CredentialsExpiredError(`User credentials have expired`);\n        }\n    });\n    const passwordEncoder = options?.passwordEncoder ?? createDelegatingPasswordEncoder();\n\n    const userDetailsPasswordService: UserDetailsPasswordService = options?.userDetailsPasswordService ?? NoopUserDetailsPasswordService;\n\n    const upgradeEncodingIfNeeded = async (userDetails: UserDetails, presentedPassword?: string) => {\n        const existingEncodedPassword = userDetails.password;\n        const upgradeEncoding = existingEncodedPassword !== undefined\n            && passwordEncoder.upgradeEncoding?.(existingEncodedPassword!);\n        if (upgradeEncoding) {\n            const newEncodedPassword = await passwordEncoder.encode(presentedPassword);\n            return await userDetailsPasswordService.updatePassword(userDetails, newEncodedPassword);\n        }\n        return userDetails;\n    }\n\n    return async (authentication: Authentication): Promise<AbstractAuthenticationToken> => {\n\n        const username = authentication.name!;\n        const presentedPassword = (authentication.credentials !== undefined && authentication.credentials !== null) ? authentication.credentials.toString() : undefined;\n        // retrieve user\n        const user = await userDetailsService.findByUsername(username);\n\n        if (!user) {\n            throw new Error(`User not found: ${username}`);\n        }\n\n        preAuthenticationChecks(user);\n        if (!(await passwordEncoder.matches(presentedPassword, user.password!))) {\n            throw new BadCredentialsError('Invalid Credentials');\n        }\n        const principal = await upgradeEncodingIfNeeded(user, presentedPassword);\n\n        postAuthenticationChecks(principal);\n        let credentials = principal.password;\n        return {\n            type: 'UsernamePassword',\n            principal: principal,\n            credentials: credentials,\n            authorities: principal.authorities,\n            authenticated: true,\n            name: principal.username,\n            eraseCredentials() {\n                credentials = null;\n            }\n        };\n    };\n}\n\nexport function accountStatusUserDetailsChecker(): UserDetailsChecker {\n    return (user: UserDetails) => {\n        if (user.accountLocked) {\n            logger.debug(`failed to authenticate since user account is locked`);\n            throw new LockedError(`User account is locked`);\n        }\n        if (user.disabled) {\n            logger.debug(`failed to authenticate user account is disabled`);\n            throw new DisabledError(`User is disabled`);\n        }\n        if (user.accountExpired) {\n            logger.debug(`failed to authenticate since user account is expired`);\n            throw new AccountExpiredError(`User account has expired`);\n        }\n        if (user.credentialsExpired) {\n            logger.debug(`failed to authenticate since user credentials have expired`);\n            throw new CredentialsExpiredError(`User credentials have expired`);\n        }\n    }\n}\n\nexport function preAuthenticatedAuthenticationManager(opts: {\n    userDetailsService: UserDetailsService,\n    userDetailsChecker?: UserDetailsChecker\n}): AuthenticationManager {\n    const userDetailsService = opts.userDetailsService;\n    const userDetailsChecker = opts.userDetailsChecker ?? accountStatusUserDetailsChecker();\n\n    const supports = (authentication: Authentication): authentication is AbstractAuthenticationToken & AuthenticatedPrincipal => {\n        return (authentication.type === 'PreAuthenticated' && authentication.name !== undefined);\n    }\n\n    return async (authentication: Authentication): Promise<AbstractAuthenticationToken> => {\n        const userDetails = supports(authentication) && await userDetailsService.findByUsername(authentication.name);\n        if (!userDetails) {\n            throw new UsernameNotFoundError(`user not found`, authentication.name);\n        }\n        userDetailsChecker(userDetails);\n        let erasableCredentials = authentication.credentials;\n        const result: AbstractAuthenticationToken = {\n            type: 'PreAuthenticated',\n            principal: userDetails,\n            credentials: erasableCredentials,\n            authorities: userDetails.authorities,\n            authenticated: true,\n            details: userDetails,\n            name: userDetails.username,\n            eraseCredentials() {\n                erasableCredentials = null;\n            }\n        };\n        return result;\n    };\n}\n", "import authenticationFilter from './authentication-filter.ts';\nimport type { AsyncLocalStorage } from 'node:async_hooks';\nimport { x509Converter } from './x509-converter.ts';\nimport { subjectX500PrincipalExtractor, type X509PrincipalExtractor } from './preauth/x509.ts';\nimport type { AuthenticationConverter, AuthenticationManager } from './types.ts';\nimport { preAuthenticatedAuthenticationManager } from './users.ts';\nimport type { WebFilter } from '../../web/server/types.ts';\n\n\nexport default function x509(opts: {\n    readonly storage: AsyncLocalStorage< {} >,\n    readonly manager?: AuthenticationManager,\n    readonly extractor?: X509PrincipalExtractor,\n    readonly converter?: AuthenticationConverter,\n    getService: <T>(type: string) => T\n}): WebFilter {\n    const manager = opts.manager ?? preAuthenticatedAuthenticationManager({\n        userDetailsService: opts.getService('UserDetailsService')\n    });\n    const principalExtractor = opts.extractor ?? subjectX500PrincipalExtractor();\n    const converter = opts.converter ?? x509Converter({ principalExtractor })\n    return authenticationFilter({\n        storage: opts.storage,\n        manager,\n        converter\n    })\n}\n", "\nimport type { ServerWebExchange } from '../../../types/web/server';\nimport type { WebErrorHandler, WebFilter, WebFilterChain, WebHandler } from './types.ts';\n\nexport class WebHandlerDecorator implements WebHandler {\n    readonly #delegate: WebHandler;\n\n    constructor(delegate: WebHandler) {\n        if (delegate === null || delegate === undefined) throw new Error('delegate must not be null or undefined');\n        this.#delegate = delegate;\n    }\n\n    get delegate(): WebHandler {\n        return this.#delegate;\n    }\n\n    async handle(exchange: ServerWebExchange): Promise<void> {\n        return await this.#delegate.handle(exchange);\n    }\n\n    toString(): string {\n        return `WebHandlerDecorator[delegate=${this.#delegate}]`;\n    }\n}\n\nexport class ErrorHandlingWebHandler extends WebHandlerDecorator {\n    readonly #errorHandlers: Array<WebErrorHandler>;\n    constructor(delegate: WebHandler, ...errorHandlers: Array<WebErrorHandler>) {\n        super(delegate);\n        this.#errorHandlers = [... (errorHandlers)];\n        Object.freeze(this.#errorHandlers);\n    }\n\n    get errorHandlers(): ReadonlyArray<WebErrorHandler> {\n        return this.#errorHandlers;\n    }\n\n    handle(exchange: ServerWebExchange): Promise<void> {\n        let completion: Promise<void>;\n        try {\n            completion = super.handle(exchange);\n        }\n        catch (e) {\n            completion = Promise.reject(e);\n        }\n\n        // set handled web error attribute\n        //exchange.attribute()\n        for (const handler of this.#errorHandlers) {\n            completion = completion.catch(async (reason) => {\n                const error = reason instanceof Error ? reason : new Error(String(reason));\n                await handler.handle(exchange, error);\n            });\n        }\n        return completion;\n    }\n}\n\nexport class DefaultWebFilterChain implements WebFilterChain {\n    readonly #filters: WebFilter[];\n    readonly #handler: WebHandler;\n\n    /*readonly */ #current?: WebFilter;\n    /*readonly */ #chian?: DefaultWebFilterChain;\n\n    static of(handler: WebHandler, ...filters: WebFilter[]) {\n        const allFilters = [...filters];\n        const result = new DefaultWebFilterChain(filters, handler);\n        const chain = DefaultWebFilterChain.initChain(filters, handler);\n        result.#current = chain.#current;\n        result.#chian = chain.#chian;\n        return result;\n    }\n\n    private static initChain(filters: WebFilter[], handler: WebHandler): DefaultWebFilterChain {\n        let chain = new DefaultWebFilterChain(filters, handler, undefined, undefined);\n        for (const current of [...filters].reverse()) {\n            chain = new DefaultWebFilterChain(filters, handler, current, chain);\n        }\n        return chain;\n    }\n\n    private constructor(filters: WebFilter[], handler: WebHandler, current? : WebFilter, chain?: DefaultWebFilterChain) {\n        this.#filters = filters;\n        this.#handler = handler;\n        this.#current = current;\n        this.#chian = chain;\n    }\n\n    get filters(): ReadonlyArray<WebFilter> {\n        return this.#filters;\n    }\n\n    get handler(): WebHandler {\n        return this.#handler;\n    }\n\n    async filter(exchange: ServerWebExchange): Promise<void> {\n        if (this.#current !== undefined && this.#chian !== undefined) {\n            await this.#invokeFilter(this.#current, this.#chian, exchange);\n        }\n        else {\n            await this.#handler.handle(exchange);\n        }\n    }\n\n    #invokeFilter(filter: WebFilter, chain: DefaultWebFilterChain, exchange: ServerWebExchange): Promise<void> {\n        return filter.filter(exchange, chain);\n    }\n}\n\nexport class FilteringWebHandler extends WebHandlerDecorator {\n    readonly #chain: DefaultWebFilterChain;\n\n    constructor(handler: WebHandler, ...filters: Array<WebFilter>) {\n        super(handler);\n        this.#chain = DefaultWebFilterChain.of(handler, ...(filters));\n    }\n\n    get filters() {\n        return this.#chain.filters;\n    }\n\n    handle(exchange: ServerWebExchange): Promise<void> {\n        return this.#chain.filter(exchange);\n    }\n}\n", "import type { WebFilter, WebFilterChain } from '../../web/server/types.ts';\nimport type { ServerWebExchange } from '../../../types/web/server';\nimport { DefaultWebFilterChain } from '../../web/server/handler.ts';\nimport { HttpStatus } from '../../http/status.ts';\nimport type { ServerWebExchangeMatcher } from '../util/matchers.ts';\n\nexport class WebFilterChainProxy implements WebFilter {\n    #filters: SecurityWebFilterChain[]\n    #firewall: ServerWebExchangeFirewall = new StrictServerWebExchangeFirewall();\n    #decorator: WebFilterChainDecorator = new DefaultWebFilterChainDecorator();\n    #exchangeRejectedHandler: ServerExchangeRejectedHandler = new HttpStatusExchangeRejectedHandler();\n\n    constructor(...filters: SecurityWebFilterChain[]) {\n        this.#filters = [...filters];\n    }\n\n    async filter(exchange: ServerWebExchange, chain: WebFilterChain): Promise<void> {\n        const firewalledExchange = await this.#firewall.firewalledExchange(exchange);\n        try {\n            await this.#filterFirewalledExchange(firewalledExchange, chain);\n        }\n        catch (e) {\n            if (e instanceof ServerExchangeRejectedError) {\n                await this.#exchangeRejectedHandler.handle(exchange, e)\n            }\n            else {\n                throw e;\n            }\n        }\n    }\n\n    async #filterFirewalledExchange(firewalledExchange: ServerWebExchange, chain: WebFilterChain) {\n        for (const securityFilterChain of this.#filters) {\n            if (await securityFilterChain.matches(firewalledExchange)) {\n                const filters = await securityFilterChain.webFilters();\n                const currentChain = this.#decorator.decorate(chain, filters);\n                await currentChain.filter(firewalledExchange);\n                return;\n            }\n        }\n        await this.#decorator.decorate(chain).filter(firewalledExchange);\n    }\n\n    set firewall(firewall: ServerWebExchangeFirewall) {\n        if (!firewall) {\n            throw new Error('firewall must be provided');\n        }\n        this.#firewall = firewall;\n    }\n\n    set decorator(decorator: WebFilterChainDecorator) {\n        if (!decorator) {\n            throw new Error('decorator must be provided');\n        }\n        this.#decorator = decorator;\n    }\n\n    set exchangeRejectedHandler(handler: ServerExchangeRejectedHandler) {\n        if (!handler) {\n            throw new Error('handler must be provided');\n        }\n        this.#exchangeRejectedHandler = handler;\n    }\n}\n\nexport interface WebFilterChainDecorator {\n    decorate(chain: WebFilterChain, filters?: WebFilter[]): WebFilterChain;\n}\n\nclass DefaultWebFilterChainDecorator implements WebFilterChainDecorator {\n    decorate(original: WebFilterChain, filters?: WebFilter[]): WebFilterChain {\n        filters = filters || [];\n        return DefaultWebFilterChain.of({handle: (exchange) => original.filter(exchange) }, ...filters);\n    }\n}\nexport interface SecurityWebFilterChain {\n    matches(exchange: ServerWebExchange): Promise<boolean>;\n    webFilters(): Promise<WebFilter[]>;\n}\nexport class MatcherSecurityWebFilterChain implements SecurityWebFilterChain {\n    readonly #matcher: ServerWebExchangeMatcher\n    readonly #filters: WebFilter[];\n\n    constructor(matcher: ServerWebExchangeMatcher, ...filters: WebFilter[]) {\n        this.#matcher = matcher;\n        this.#filters = filters;\n    }\n\n    async matches(exchange: ServerWebExchange): Promise<boolean> {\n        return (await this.#matcher(exchange))?.match === true;\n    }\n    async webFilters(): Promise<WebFilter[]> {\n        return this.#filters;\n    }\n}\n\nexport interface ServerWebExchangeFirewall {\n    firewalledExchange(exchange: ServerWebExchange): Promise<ServerWebExchange>;\n}\nclass StrictServerWebExchangeFirewall {\n    async firewalledExchange(exchange: ServerWebExchange): Promise<ServerWebExchange> {\n        return exchange;\n    }\n}\n\nexport class ServerExchangeRejectedError extends Error {\n    constructor(message: string) {\n        super(message);\n        this.name = 'ServerExchangeRejectedError';\n    }\n}\nexport interface ServerExchangeRejectedHandler {\n    handle(exchange: ServerWebExchange, error: ServerExchangeRejectedError): Promise<void>;\n}\n\nclass HttpStatusExchangeRejectedHandler implements ServerExchangeRejectedHandler {\n    readonly #status: HttpStatus;\n    constructor(status: HttpStatus = HttpStatus.BAD_REQUEST) {\n        this.#status = status;\n    }\n    async handle(exchange: ServerWebExchange, error: ServerExchangeRejectedError): Promise<void> {\n        exchange.response.setStatusCode(this.#status);\n    }\n\n}\n", "import type { UserDetails, UserDetailsPasswordService, UserDetailsService } from './types.ts';\n\nexport class MapUserDetailsService implements UserDetailsService, UserDetailsPasswordService {\n    readonly #users = new Map<string, UserDetails>();\n\n    constructor(...users: UserDetails[]) {\n        for (const user of users) {\n            this.#users.set(this.#getKey(user.username), user);\n        }\n    }\n\n    async findByUsername(username: string): Promise<UserDetails | undefined> {\n        const key = this.#getKey(username);\n        const result = this.#users.get(key);\n        return result !== undefined ? { ...(result) } : undefined;\n    }\n\n    async updatePassword(user: UserDetails, newPassword?: string): Promise<UserDetails> {\n        const userDetails = { ...(user), password: newPassword };\n        // what if user does not exist?\n        if (userDetails) {\n            const key = this.#getKey(user.username);\n            this.#users.set(key, userDetails);\n        }\n        return userDetails;\n    }\n\n    #getKey(username: string) {\n        return username.toLowerCase();\n    }\n}\n", "import { createCorsConfigSource } from './cors.ts';\nimport type { RouteConfig } from './route.ts';\nimport security, { type HttpSecurityConfig } from '../server/security/config.ts';\nimport { and, pattern, type ServerWebExchangeMatcher, upgradeMatcher } from '../server/util/matchers.ts';\nimport type { AuthorizationRule } from '../../types/auth';\nimport { MapUserDetailsService } from '../server/security/users/memory.ts';\nimport { UserBuilder, type UserDetails } from '../server/security/users/types.ts';\nimport { randomUUID } from 'node:crypto';\nimport { MAX_PASSWORD_LENGTH, type PasswordEncoder } from '../server/security/crypto/index.ts';\nimport getLogger from '../logger.ts';\nimport type { CorsConfigSource } from '../web/cors/types.ts';\nimport type { SecurityWebFilterChain } from '../server/security/web.ts';\n\nconst logger = getLogger('auth');\n\nexport function createSecurityConfig(context: RouteConfig): HttpSecurityConfig {\n    const authorize: HttpSecurityConfig['authorize'] = [];\n    const type = context.authConfig?.type;\n    const defaultAccess: AuthorizationRule = { access: type !== 'none' ? 'authenticated' : 'permitted' };\n    if (logger.enabledFor('info')) {\n        logger.info(`using auth type: ${type ?? 'none'}, default access: ${defaultAccess.access}`);\n    }\n    for (const [path, route] of context.sockets) {\n        const rule = route.authorize ?? defaultAccess;\n        let matcher: ServerWebExchangeMatcher = pattern(path, { method: 'GET' });\n        matcher = and([upgradeMatcher, matcher]);\n        authorize.push([matcher, rule]);\n    }\n    authorize.push([pattern('/', { method: 'GET' }), { access: 'permitted' }]);\n    authorize.push([pattern('/favicon.ico', {method: 'GET'}), { access: 'permitted' }]);\n    authorize.push([pattern('/health', {method: 'GET'}), { access: 'permitted' }]);\n    if (context.authorize.length > 0) {\n        authorize.push(...context.authorize);\n    }\n\n    authorize.push(['any-exchange', defaultAccess]); // default rule for all other exchanges\n    return {\n        authorize,\n        cors: {\n            disabled: context.corsConfig === false,\n        },\n        x509: {\n            disabled: type !== 'x509',\n            ...context.authConfig?.x509,\n        },\n        basic: {\n            disabled: type !== 'basic',\n            ...context.authConfig?.basic,\n        },\n        jwt: {\n            disabled: type !== 'oauth2',\n            ...context.authConfig?.oauth2?.jwt\n        }\n    }\n}\n\nexport function createUserDetailsService(context: RouteConfig) {\n    // if (context.userDetailsService) {\n    //     return context.userDetailsService;\n    // }\n    if (context.authConfig?.type === 'none') {\n        return undefined;\n    }\n\n    function getOrDeducePassword(user: { password?: string }, encoder?: PasswordEncoder): string | null {\n        if (context.authConfig?.type === 'x509') {\n            return null;\n        }\n        let password = user.password;\n        if (password === undefined) {\n            // generate password\n            const generatedPassword = randomUUID().replaceAll('-', '');\n            if (logger.enabledFor('info')) {\n                logger.info(`\\n\\n using generated password: ${generatedPassword}\\n\\nThis generated password is for development only. Your authentication configuration should be updated before running in production.\\n`);\n            }\n            password = generatedPassword;\n        }\n        if (password.length > MAX_PASSWORD_LENGTH) {\n            throw new Error(`Password length exceeds maximum length of ${MAX_PASSWORD_LENGTH} characters`);\n        }\n        if ((encoder !== undefined && encoder !== null) || /^\\{.+}.*$/.test(password)) {\n            return password;\n        }\n        return `{noop}${password}`;\n    }\n\n    const user = { name : 'dev-user', roles: [], ...(context.authConfig?.user) };\n    const password = getOrDeducePassword(user);\n    const roles = user.roles;\n    const userDetails: UserDetails = UserBuilder.ofUsername(user.name).password(password).roles(...(roles)).build();\n    return new MapUserDetailsService(userDetails);\n}\n\nexport async function httpSecurity(context: RouteConfig): Promise<SecurityWebFilterChain> {\n    const corsConfigSource: CorsConfigSource = createCorsConfigSource(context);\n    const config = createSecurityConfig(context);\n    const userDetailsService = createUserDetailsService(context);\n    const { storage } = context;\n    return security(config, {\n        storage,\n        corsConfigSource,\n        userDetailsService,\n        userDetailsPasswordService: userDetailsService\n    });\n}\n", "import { ServerHttpResponseDecorator } from './exchange.ts';\n\nexport class HttpHeadResponseDecorator extends ServerHttpResponseDecorator {\n\n}\n\n\n", "import type { AsyncLocalStorage } from \"node:async_hooks\";\nimport { WebSocketServer } from 'ws';\nimport type { ServerHttpResponse, ServerWebExchange } from '../../types/web/server';\nimport { HttpStatus } from '../http/status.ts';\nimport getLogger, { regexAwareReplacer } from '../logger.ts';\nimport {\n    ExtendedHttpIncomingMessage,\n    ExtendedHttpServerResponse,\n    ServerHttpRequestDecorator,\n    ServerHttpResponseDecorator\n} from './exchange.ts';\nimport { createHandshakeInfo, type SocketRoute } from './socket.ts';\nimport { acceptsOrigin } from './ws-client-verify.ts';\nimport { ExtendedWebSocket, PingManager } from './ws-pings.ts';\n\nconst logger = getLogger('ws');\n\nfunction upgradeStrategy(path: string, route: SocketRoute, wss: WebSocketServer, onSocketError: (err: Error) => void) {\n    return (exchange: ServerWebExchange) => {\n\n        const { logPrefix, request } = exchange;\n        const req = ServerHttpRequestDecorator.getNativeRequest<ExtendedHttpIncomingMessage>(request);\n        req.exchange = exchange;\n        const { socket, upgradeHead } = req;\n\n        const host = request.host;\n        socket.removeListener('error', onSocketError);\n        if (route.maxConnections !== undefined && wss.clients?.size >= route.maxConnections) {\n            logger.warn(`${logPrefix}dropping ws connection request on ${host}${path}. max connections exceeded.`);\n            socket.destroy();\n            return;\n        }\n\n        const origin = request.headers.one('origin');\n        if (!acceptsOrigin(origin, route.originFilters)) {\n            if (logger.enabledFor('info')) {\n                logger.info(`${logPrefix}dropping ws connection request on ${host}${path}. origin ${origin ?? '<missing>'}`);\n            }\n            socket.destroy();\n            return;\n        }\n        if (logger.enabledFor('debug')) {\n            logger.debug(`${logPrefix}accepted new ws connection request on ${host}${path}`);\n        }\n\n        wss.handleUpgrade(req, socket, upgradeHead!, (client, req) => {\n            wss.emit('connection', client, req);\n        });\n    }\n}\n\nfunction applyHandshakeHeaders(headers: string[], response: ServerHttpResponse) {\n    const seen = new Set<string>(); // track headers we've taken care of\n    headers.forEach((header, index) => {\n        if (index === 0 && header.startsWith('HTTP/1.1 101 ')) {\n            response.setStatusCode(HttpStatus.SWITCHING_PROTOCOLS);\n            return;\n        }\n        const [name, value] = header.split(': ');\n        if (response.headers.has(name)) {\n            headers[index] = `${name}: ${response.headers.one(name)}`;\n        }\n        else {\n            response.headers.set(name, value);\n        }\n        seen.add(name.toLowerCase());\n    });\n    const nativeResponse = ServerHttpResponseDecorator.getNativeResponse<ExtendedHttpServerResponse>(response);\n    for (const name of nativeResponse.getRawHeaderNames()) {\n        // if we have already set this header, skip it\n        const nameLowerCase = name.toLowerCase();\n        if (!seen.has(nameLowerCase)) {\n            const value = response.headers.get(nameLowerCase);\n            if (value !== undefined) {\n                headers.push(`${name}: ${value}`);\n            }\n        }\n    }\n    nativeResponse.markHeadersSent();\n}\n\nexport async function initRoute(path: string,\n                                route: SocketRoute,\n                                endpoint: string,\n                                storage: AsyncLocalStorage<{ securityContext? }>,\n                                onSocketError: (err: Error) => void): Promise<void> {\n    try {\n        logger.info(`creating ws server for [${path}]. max connections: ${route.maxConnections ?? '<unlimited>'}, origin filters: ${route.originFilters ? JSON.stringify(route.originFilters, regexAwareReplacer) : '<none>'}, ping: ${typeof route.ping === 'number' ? route.ping + 'ms' : route.ping ? JSON.stringify(route.ping) : '<none>'}`);\n        const wss = new WebSocketServer<typeof ExtendedWebSocket, typeof ExtendedHttpIncomingMessage>({\n            noServer: true,\n            WebSocket: ExtendedWebSocket,\n            autoPong: false\n        });\n\n        const pings = new PingManager(logger.child('pings'), () => [path, wss.clients], route.ping);\n\n        const handler = await route.factory({ endpoint, storage });\n        wss\n            .on('error', (err: Error) => {\n                logger.error(`error starting the ws server for [${path}]`, err);\n            })\n            .on('listening', () => {\n                logger.info(`ws server for [${path}] is listening`);\n            })\n            .on('headers', (headers, request) => {\n                if (request.exchange !== undefined) {\n                    const { response } = request.exchange;\n                    applyHandshakeHeaders(headers, response);\n                }\n            })\n            .on('connection', (socket, request) => {\n\n                const handshake = createHandshakeInfo(request, socket.protocol);\n\n                socket.on('pong', (data) => {\n                    pings.handlePong(handshake, socket, data);\n                });\n                socket.on('ping', (data: Buffer) => {\n                    pings.handlePing(handshake, socket, data);\n                });\n                handler({ socket, handshake });\n            });\n        wss.on('close', () => {\n            pings.close();\n        });\n\n        route.upgradeStrategy = upgradeStrategy(path, route, wss, onSocketError);\n        route.close = async () => {\n            await handler.close?.call(handler);\n            logger.info(`stopping ws server for [${path}]. clients: ${wss.clients?.size ?? 0}`);\n            wss.clients?.forEach(client => {\n                client.terminate();\n            });\n            wss.close();\n        }\n    }\n    catch (e) {\n        logger.warn(`failed to init route ${path}`, e);\n    }\n\n}\n", "import type { AuthorizationRule, Principal } from '../../types/auth';\nimport type { WebSocketHandshakeInfo } from '../../types/web/socket';\nimport type { ServerWebExchange, ServerWebSocketHandler } from '../../types/web/server';\n\nimport { HttpStatus } from '../http/status.ts';\nimport { MapHttpHeaders } from '../http/headers.ts';\nimport type { Middleware } from './types.ts';\nimport { type ExtendedHttpIncomingMessage, HttpServerRequest } from './exchange.ts';\nimport { upgradeMatcher } from './util/matchers.ts';\nimport type { ProcessedOriginFilters } from './ws-client-verify.ts';\nimport type { AsyncLocalStorage } from 'node:async_hooks';\n\nexport function createHandshakeInfo(req: ExtendedHttpIncomingMessage, protocol?: string): WebSocketHandshakeInfo {\n    const exchange = req?.exchange;\n    const request = exchange?.request ?? new HttpServerRequest(req);\n    const principalPromiseProvider = exchange?.principal;\n    const principal = principalPromiseProvider ? principalPromiseProvider.bind(exchange) : async function principal<P extends Principal> (): Promise<P | undefined> { return undefined; };\n    const url = request.URL;\n    const headers = new MapHttpHeaders();\n    for (const key of request.headers.keys()) {\n        headers.set(key, request.headers.list(key));\n    }\n    const cookies = request.cookies;\n    const logPrefix = exchange?.logPrefix ?? `[${request.id}] `;\n    const remoteAddress = request.remoteAddress;\n    const handshake: WebSocketHandshakeInfo = {\n        url,\n        headers,\n        cookies,\n        principal,\n        protocol,\n        remoteAddress,\n        logPrefix,\n    };\n    return handshake;\n}\n\nexport function webSockets(context: { sockets: Map<string, SocketRoute> }): Middleware {\n    // websocket upgrade handler\n    const sockets = async (exchange: ServerWebExchange, next: () => Promise<void>) => {\n        const request = exchange.request;\n        const path = request.path ?? '/';\n\n        const routes = context.sockets;\n        const route = (routes.get(path) ?? Array.from(routes.values()).find(route => {\n            if (path === '/' && route.default === true) {\n                return true;\n            }\n        }));\n\n        if (route !== undefined) {\n            const {request, response} = exchange;\n            const upgradeMatchResult = await upgradeMatcher(exchange);\n            if ((request.method === 'GET' || request.method === 'CONNECT') && upgradeMatchResult.match) {\n                if (route.upgradeStrategy !== undefined) {\n                    route.upgradeStrategy(exchange);\n                    return;\n                }\n                else {\n                    throw new Error(`No upgrade strategy defined for route on ${path}`);\n                }\n            }\n            else {\n                if (route.default) {\n                    // allow default route to pass through\n                    await next();\n                    return;\n                }\n\n                response.setStatusCode(HttpStatus.UPGRADE_REQUIRED);\n                response.headers\n                    .set('Upgrade', 'websocket')\n                    .set('Connection', 'Upgrade')\n                    .set('Content-Type', 'text/plain');\n\n                const buffer = Buffer.from(`This service [${request.path}] requires use of the websocket protocol.`, 'utf-8');\n                await response.body(buffer);\n            }\n        } else {\n            await next();\n        }\n    };\n    return [sockets];\n}\n\nexport type SocketRoute = {\n    readonly default?: boolean,\n    readonly ping?: number | { interval: number, data?: 'timestamp' | 'empty' },\n    readonly maxConnections?: number\n    readonly authorize?: AuthorizationRule,\n    readonly originFilters?: ProcessedOriginFilters\n    readonly factory: (server: { endpoint: string, storage?: AsyncLocalStorage<{ exchange?, securityContext? }> }) => Promise<ServerWebSocketHandler>,\n    // set later in listening\n    upgradeStrategy?: (exchange: ServerWebExchange) => void,\n    close?: () => Promise<void>\n}\n", "import { addressAndPort } from './address.ts';\nimport type { Logger } from '../logger.ts';\nimport { WebSocket } from 'ws';\nimport type { WebSocketHandshakeInfo } from '../../types/web/socket';\n\nexport class ExtendedWebSocket extends WebSocket {\n    constructor(_first: unknown, _second?: unknown, options?: unknown) {\n        /* eslint-disable  @typescript-eslint/no-explicit-any */\n        super(null as unknown as any, undefined, options as any);\n    }\n\n    connected?: boolean;\n}\n\nexport type PingConfig = { interval: number, data?: 'timestamp' | 'empty' };\n\nexport class PingManager {\n    static readonly #EMPTY_BUFFER = Buffer.alloc(0);\n    static #LAST_TIMESTAMP_BUFFER: [number, Buffer] = [0, Buffer.alloc(8)];\n\n    readonly #pingData: () => Buffer;\n    readonly #pingInterval: number | undefined;\n    readonly #pingIntervalId?: ReturnType<typeof setInterval>;\n    readonly #mask = false;\n    readonly #logger: Logger;\n\n    constructor(logger: Logger, supplier: () => [string, Set<ExtendedWebSocket>], ping?: number | PingConfig) {\n        this.#logger = logger;\n        this.#pingInterval = typeof ping === 'number' ? ping : ping?.interval;\n        this.#pingData =\n            typeof ping === 'number' || ping?.data === 'timestamp'\n                ? () => PingManager.#createBufferFromTimestamp(Date.now())\n                : () => PingManager.#EMPTY_BUFFER;\n\n        if (this.#pingInterval) {\n            this.#pingIntervalId = setInterval(() => {\n                const [path, clients] = supplier();\n                for (const client of clients) {\n                    if (this.#terminateIfDisconnected(client, path)) {\n                        continue;\n                    }\n                    this.#markAndSendPing(client, path);\n                }\n            }, this.#pingInterval);\n\n        }\n    }\n\n    #terminateIfDisconnected(client: ExtendedWebSocket, path: string) {\n        if (client.connected === false) {\n            if (this.#logger.enabledFor('debug')) {\n                this.#logger.debug(`terminating unresponsive ws client on [${path}]`);\n            }\n            client.terminate();\n            return true;\n        }\n        return false;\n    }\n\n    #markAndSendPing(client: ExtendedWebSocket, path: string) {\n        client.connected = false;\n        const data = this.#pingData();\n        if (this.#logger.enabledFor('trace')) {\n            this.#logger.debug(`pinging ws client on [${path}]`);\n        }\n        client.ping(data, this.#mask, (err: Error) => {\n            if (err && this.#logger.enabledFor('warn')) {\n                this.#logger.warn(`failed to ping ws client on [${path}]`, err);\n            }\n        });\n    }\n\n    static #createBufferFromTimestamp(now = Date.now()): Buffer {\n        if (now - PingManager.#LAST_TIMESTAMP_BUFFER[0] > 0) {\n            const buffer = Buffer.allocUnsafe(8);\n            buffer.writeBigInt64BE(BigInt(now), 0);\n            PingManager.#LAST_TIMESTAMP_BUFFER = [now, buffer];\n        }\n        return PingManager.#LAST_TIMESTAMP_BUFFER[1];\n    }\n\n    static #createTimestampFromBuffer(data: Buffer): number {\n        if (data.length === 8) {\n            return Number(data.readBigInt64BE(0));\n        }\n        return 0;\n    }\n\n    close() {\n        clearInterval(this.#pingIntervalId);\n    }\n\n    handlePing(handshake: WebSocketHandshakeInfo, socket: ExtendedWebSocket, data: Buffer): void {\n        socket.connected = true;\n        socket.pong(data, false, (err: Error) => {\n            if (err && this.#logger.enabledFor('warn')) {\n                this.#logger.warn(`${handshake.logPrefix}failed to pong ws client ${addressAndPort(handshake.remoteAddress)}`, err);\n            }\n        });\n    }\n\n    handlePong(handshake: WebSocketHandshakeInfo, socket: ExtendedWebSocket, data: Buffer): void {\n        socket.connected = true;\n        if (this.#logger.enabledFor('warn')) {\n            const sent = PingManager.#createTimestampFromBuffer(data);\n            if (sent > 0) {\n                const latency = Date.now() - sent;\n                if (this.#logger.enabledFor('debug')) {\n                    this.#logger.debug(`${handshake.logPrefix}ws client ${addressAndPort(handshake.remoteAddress)} ping-pong latency: ${latency}ms`);\n                }\n                if (this.#pingInterval && latency > this.#pingInterval / 2 && this.#logger.enabledFor('warn')) {\n                    this.#logger.warn(`${handshake.logPrefix}ws client ${addressAndPort(handshake.remoteAddress)} high ping-pong latency: ${latency}ms`);\n                }\n            }\n        }\n    }\n}\n", "import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'node:fs';\nimport { dirname } from 'node:path';\nimport type { TlsOptions } from 'node:tls';\nimport { KEYUTIL, X509 } from 'jsrsasign';\nimport { mkcert } from '@interopio/gateway-server/tools';\nimport type { SslConfig } from '../../../types/config';\nimport getLogger from '../../logger.ts';\n\nconst logger = getLogger('ssl');\n\nexport type ServerCertificateConfig = {\n    /** Hostname for the server certificate (used in CN and SAN) */\n    host: string;\n    /** Path to CA private key file (PEM format), for auto-generating server certificates */\n    key?: string;\n    /** Passphrase for encrypted CA private key */\n    passphrase?: string;\n};\n\nexport function secureContextOptions(ssl: SslConfig, serverCertificate?: ServerCertificateConfig): TlsOptions {\n    // Prepare common SSL/TLS options (client certificate verification)\n    const commonOptions: TlsOptions = {};\n\n    if (ssl.requestCert !== undefined) {\n        commonOptions.requestCert = ssl.requestCert;\n    }\n    if (ssl.rejectUnauthorized !== undefined) {\n        commonOptions.rejectUnauthorized = ssl.rejectUnauthorized;\n    }\n\n    // Mode 1: Explicit key and cert provided - check if files exist and use them\n    if (ssl.key && ssl.cert && existsSync(ssl.key) && existsSync(ssl.cert)) {\n        logger.info(`using SSL/TLS certificate ${ssl.cert} with private key in ${ssl.key}${ssl.passphrase ? ' (password-protected)' : ''}`);\n        const options: TlsOptions = {\n            key: readFileSync(ssl.key),\n            cert: readFileSync(ssl.cert),\n            ...commonOptions\n        };\n        if (ssl.passphrase) {\n            options.passphrase = ssl.passphrase;\n        }\n        // Only set ca if requestCert is true (ca is for validating client certificates)\n        if (ssl.requestCert && ssl.ca && existsSync(ssl.ca)) {\n            options.ca = readFileSync(ssl.ca);\n        }\n        return options;\n    }\n\n    // Mode 1b: Key and cert not explicitly provided, but default files exist - use them\n    if (!ssl.key && !ssl.cert) {\n        const defaultKeyPath = './gateway-server.key';\n        const defaultCertPath = './gateway-server.crt';\n\n        if (existsSync(defaultKeyPath) && existsSync(defaultCertPath)) {\n            logger.info(`using SSL/TLS certificate ${defaultCertPath} with private key in ${defaultKeyPath}${ssl.passphrase ? ' (password-protected)' : ''}`);\n            const options: TlsOptions = {\n                key: readFileSync(defaultKeyPath),\n                cert: readFileSync(defaultCertPath),\n                ...commonOptions\n            };\n            if (ssl.passphrase) {\n                options.passphrase = ssl.passphrase;\n            }\n            // Only set ca if requestCert is true (ca is for validating client certificates)\n            if (ssl.requestCert && ssl.ca && existsSync(ssl.ca)) {\n                options.ca = readFileSync(ssl.ca);\n            }\n            return options;\n        }\n    }\n\n    // Mode 2: Generate server certificate using CA key (from auth.x509.key)\n    // If serverCertificate is undefined, skip certificate generation\n    if (!serverCertificate) {\n        throw new Error('SSL/TLS enabled but no server certificate provided. Either provide ssl.key and ssl.cert, or configure auth.x509.key for auto-generation.');\n    }\n\n    // Note: CA key is primarily for client certificate generation, incidentally used for server cert\n    const caKeyPath = serverCertificate.key ?? 'gateway-ca.key';\n    const caPemPath = ssl.ca ?? `${caKeyPath.replace(/\\.key$/, '.crt')}`;\n    const passphrase = serverCertificate.passphrase ?? ssl.passphrase;\n\n    // Auto-generate Root CA if it doesn't exist\n\n    if (!existsSync(caKeyPath)) {\n        if (existsSync(caPemPath)) {\n            throw new Error(`CA key file not found: ${caKeyPath} (CA certificate exists: ${caPemPath})`);\n        }\n        const rootCA = mkcert.generateRootCA({ name: mkcert.DEFAULT_CA_NAME, passphrase });\n\n        // Ensure directory exists\n        const keyDir = dirname(caKeyPath);\n        if (keyDir && keyDir !== '.' && !existsSync(keyDir)) {\n            mkdirSync(keyDir, { recursive: true });\n        }\n        const certDir = dirname(caPemPath);\n        if (certDir && certDir !== '.' && certDir !== keyDir && !existsSync(certDir)) {\n            mkdirSync(certDir, { recursive: true });\n\n        }\n        writeFileSync(caKeyPath, rootCA.key, { mode: 0o400 });\n        writeFileSync(caPemPath, rootCA.cert, { mode: 0o644 });\n        logger.info(`created new local Root CA in ${caPemPath}, ${caKeyPath}${passphrase ? ' (password-protected)' : ''}`);\n    }\n\n    // Load CA key (with optional passphrase)\n    const caKeyPem = readFileSync(caKeyPath, 'utf8');\n    const caKeyObj = KEYUTIL.getKey(caKeyPem, passphrase);\n\n    // Extract issuer from CA certificate\n    const caCertPem = readFileSync(caPemPath, 'utf8');\n    const caCert = new X509();\n    caCert.readCertPEM(caCertPem);\n    const issuer = caCert.getSubjectString();\n\n    // Use hostname from serverCertificate config\n    const hostname = serverCertificate.host;\n\n    // Generate server certificate with correct issuer and hostname\n    logger.debug(`generating server certificate signed by: ${issuer} for host: ${hostname}`);\n    const serverCert = mkcert.generateCert(caKeyObj, issuer, [hostname], false); // false = server cert\n\n    // Only save to disk if key or cert paths are explicitly provided\n    if (ssl.key || ssl.cert) {\n        const keyPath = ssl.key || './gateway-server.key';\n        const certPath = ssl.cert || './gateway-server.crt';\n\n        // Ensure directory exists for key\n        const keyDir = dirname(keyPath);\n        if (keyDir && keyDir !== '.' && !existsSync(keyDir)) {\n            mkdirSync(keyDir, { recursive: true });\n        }\n        // Ensure directory exists for cert\n        const certDir = dirname(certPath);\n        if (certDir && certDir !== '.' && certDir !== keyDir && !existsSync(certDir)) {\n            mkdirSync(certDir, { recursive: true });\n        }\n\n        writeFileSync(keyPath, serverCert.key, { mode: 0o600 });\n        writeFileSync(certPath, serverCert.cert, { mode: 0o644 });\n\n        logger.info(`generated server certificate saved to ${certPath} with private key in ${keyPath}${passphrase ? ' (password-protected)' : ''}`);\n    } else {\n        logger.info(`using in-memory server certificate for host: ${hostname}`);\n    }\n    const result: TlsOptions = {\n        key: serverCert.key,\n        cert: serverCert.cert,\n        ...commonOptions\n    };\n\n    // Only set ca if requestCert is true (ca is for validating client certificates)\n    // At this point, CA file is guaranteed to exist (either pre-existing or just generated)\n    if (ssl.requestCert && ssl.ca && existsSync(caPemPath)) {\n        result.ca = readFileSync(caPemPath);\n    }\n\n    return result;\n}\n", "export function isLoggingSuppressed(hints?: Map<string, unknown>): boolean {\n    return hints?.get('io.gateway.logging.suppress') === true;\n}\n\nexport const LOG_PREFIX_HINT = 'io.gateway.logging.prefix';\n\nexport function getLogPrefix(hints?: Map<string, unknown>): string {\n    if (hints?.has(LOG_PREFIX_HINT)) {\n        return (hints.get(LOG_PREFIX_HINT) as string) ?? '';\n    }\n    return '';\n}\n", "import { MIMEType } from 'node:util';\nimport getLogger, { type Logger } from '../logger.ts';\nimport { ALL, createMimeType, isCompatibleWith } from '../utils/mime-type-utils.ts';\nimport { getLogPrefix, isLoggingSuppressed } from './hints.ts';\nimport type { Encoder } from './types.ts';\n\nexport abstract class AbstractEncoder<T> implements Encoder<T> {\n    #encodableMimeTypes: readonly MIMEType[];\n    protected logger: Logger = getLogger('codec.encoder');\n\n    protected constructor(...supportedMimeTypes: MIMEType[]) {\n        this.#encodableMimeTypes = [...supportedMimeTypes];\n    }\n\n    setLogger(logger: Logger) {\n        this.logger = logger;\n    }\n\n    encodableMimeTypes(): readonly MIMEType[] {\n        return this.#encodableMimeTypes;\n    }\n\n    canEncode(type, mimeType?: MIMEType): boolean {\n        if (mimeType === undefined) {\n            return true;\n        }\n        for (const supportedMimeType of this.#encodableMimeTypes) {\n            if (isCompatibleWith(mimeType, supportedMimeType)) {\n                return true;\n            }\n        }\n        return false;\n    }\n\n    abstract encode(input: Promise<T> | T, mimeType?: MIMEType, hints?: Map<string, unknown>): Promise<BlobPart>;\n}\n\nexport class BlobEncoder extends AbstractEncoder<BlobPart> {\n    constructor() {\n        super(ALL);\n    }\n\n    canEncode(type, mimeType?: MIMEType): boolean {\n        return super.canEncode(type, mimeType);\n    }\n\n    async encode(input: Promise<BlobPart> | BlobPart, mimeType?: MIMEType, hints?: Map<string, unknown>): Promise<BlobPart> {\n        const part = await input;\n        if (this.logger.enabledFor('debug') && !isLoggingSuppressed(hints)) {\n            this.#logValue(part);\n        }\n        return part;\n    }\n\n    #logValue(part: BlobPart, hints?: Map<string, unknown>): void {\n        const prefix = getLogPrefix(hints);\n        this.logger.debug(`${prefix}Encoding value of type ${typeof part} with size ${part['byteLength'] ?? part['size'] ?? part['length']}`);\n    }\n}\n\n\nexport class StringEncoder extends AbstractEncoder<string> {\n    private constructor(...mimeTypes: MIMEType[]) {\n        super(...mimeTypes);\n    }\n\n    canEncode(type, mimeType?: MIMEType): boolean {\n        return super.canEncode(type, mimeType) && type === 'string';\n    }\n\n    async encode(input: Promise<string> | string, mimeType?: MIMEType, hints?: Map<string, unknown>): Promise<BlobPart> {\n        input = await input;\n        if (!isLoggingSuppressed(hints) && this.logger.enabledFor('debug')) {\n            const logPrefix = getLogPrefix(hints);\n            const traceEnabled = this.logger.enabledFor('trace');\n            this.logger.debug(`${logPrefix}Writing ${traceEnabled ? `${input}` : `${input.substring(0, 100)}...`}`);\n        }\n        return input;\n    }\n\n    static textPlainOnly(): StringEncoder {\n        return new StringEncoder(createMimeType('text','plain', 'utf-8'));\n    }\n    static allMimeTypes(): StringEncoder {\n        return new StringEncoder(createMimeType('text', 'plain', 'utf-8'), ALL);\n    }\n}\n", "import getLogger, { Logger } from '../../logger.ts';\n\nexport abstract class LoggingCodecSupport {\n    protected log: Logger = getLogger('http.codec');\n    #enableLoggingRequestDetails = false;\n\n    set enableLoggingRequestDetails(enable: boolean) {\n        this.#enableLoggingRequestDetails = enable;\n    }\n\n    get enableLoggingRequestDetails(): boolean {\n        return this.#enableLoggingRequestDetails;\n    }\n}\n", "import { HttpMessageReader } from './types.ts';\nimport { MediaType } from '../media-type.ts';\nimport { isCompatibleWith } from '../../utils/mime-type-utils.ts';\nimport type { HttpInputMessage } from '../../../types/web/http';\nimport { LoggingCodecSupport } from './core.ts';\n\nexport class MultipartHttpMessageReader extends LoggingCodecSupport implements HttpMessageReader<FormData> {\n    static readonly MEDIA_TYPES = Object.freeze([MediaType.MULTIPART_FORM_DATA]);\n    #partReader: HttpMessageReader<[string, FormDataEntryValue]>;\n\n    constructor(partReader: HttpMessageReader<[string, FormDataEntryValue]>) {\n        super();\n        this.#partReader = partReader;\n    }\n\n    get partReader() {\n        return this.#partReader;\n    }\n\n    getReadableMediaTypes(): ReadonlyArray<MediaType> {\n        return MultipartHttpMessageReader.MEDIA_TYPES;\n    }\n\n\n    canRead(type, mediaType?: MediaType): boolean {\n        return this.#supportsMediaType(mediaType) && (type.name === FormData.name);\n    }\n\n    #supportsMediaType(mediaType?: MediaType): boolean {\n        if (mediaType === undefined) return true;\n\n        for (const supportedMediaType of MultipartHttpMessageReader.MEDIA_TYPES) {\n            if (isCompatibleWith(supportedMediaType, mediaType)) {\n                return true;\n            }\n        }\n        return false;\n    }\n\n    async readPromise(type, message: HttpInputMessage, hints: Map<string, unknown>): Promise<FormData> {\n        const stream = this.#partReader.read(type, message, hints);\n        const result = new FormData();\n        for await (const  [name, value] of stream) {\n            result.append(name, value)\n        }\n        return result;\n    }\n\n\n    read(type, message: HttpInputMessage, hints: Map<string, unknown>): ReadableStream<FormData> {\n        throw new Error(`not implemented yet`);\n    }\n\n}\n\n\nexport class DefaultPartHttpMessageReader extends LoggingCodecSupport implements HttpMessageReader<[string, FormDataEntryValue]> {\n    getReadableMediaTypes(): ReadonlyArray<MediaType> {\n        return [MediaType.MULTIPART_FORM_DATA];\n    }\n\n    canRead(type, mediaType?: MediaType): boolean {\n        return type === 'string' || type.name === File.name && (\n            mediaType === undefined || isCompatibleWith(MediaType.MULTIPART_FORM_DATA, mediaType)\n        );\n    }\n\n    readPromise(type, message: HttpInputMessage, hints: Map<string, unknown>): Promise<[string, FormDataEntryValue]> {\n        throw new Error(`not implemented yet`);\n    }\n\n    read(type, message: HttpInputMessage, hints: Map<string, unknown>): ReadableStream<[string, FormDataEntryValue]> {\n        throw new Error(`not implemented yet`);\n    }\n}\n", "import type {\n    CodecConfigurer,\n    DefaultCodecs,\n    HttpMessageReader,\n    HttpMessageWriter,\n    ServerCodecConfigurer,\n    ServerDefaultCodecs\n} from './types.ts';\nimport type { HttpOutputMessage, MutableHttpHeaders } from '../../../types/web/http';\nimport { AbstractEncoder, BlobEncoder, StringEncoder } from '../../codec/encoder.ts';\nimport type { Encoder } from '../../codec/types.ts';\nimport { MediaType } from '../media-type.ts';\nimport { isConcrete } from '../../utils/mime-type-utils.ts';\nimport { getContentType } from '../headers.ts';\nimport { DefaultPartHttpMessageReader, MultipartHttpMessageReader } from './multipart.ts';\n\n\nclass EncoderHttpMessageWriter<T> implements HttpMessageWriter {\n    readonly #encoder: Encoder<T>;\n    readonly #mediaTypes: readonly MediaType[];\n    #defaultMediaType?: MediaType;\n\n    constructor(encoder: Encoder<T>) {\n        EncoderHttpMessageWriter.initLogger(encoder);\n        this.#encoder = encoder;\n        this.#mediaTypes = MediaType.asMediaTypes(...encoder.encodableMimeTypes());\n        this.#defaultMediaType = this.#mediaTypes.find(mediaType => isConcrete(mediaType));\n    }\n\n    get encoder(): Encoder<T> {\n        return this.#encoder;\n    }\n\n    getWriteableMediaTypes(): ReadonlyArray<MediaType> {\n        return this.#mediaTypes;\n    }\n\n    canWrite(type, mediaType?: MediaType): boolean {\n        return this.#encoder.canEncode(type, mediaType);\n    }\n\n    async write(input: Promise<T> | T, type, message: HttpOutputMessage<MutableHttpHeaders>, mediaType?: MediaType, hints?: Map<string, unknown>): Promise<void> {\n        const resolvedMediaType = this.#updateContentType(message, mediaType);\n        const part = this.#encoder.encode(input, resolvedMediaType, hints);\n        await message.body(part);\n    }\n\n    private static initLogger(encoder: Encoder<unknown>): void {\n        if (encoder instanceof AbstractEncoder) {\n            // encoder.setLogger();\n        }\n    }\n\n    #updateContentType(message: HttpOutputMessage<MutableHttpHeaders>, mediaType?: MediaType) {\n        let resolvedMediaType = getContentType(message.headers);\n        if (resolvedMediaType) {\n            return resolvedMediaType;\n        }\n        let fallback = this.#defaultMediaType;\n        resolvedMediaType = (useFallback(mediaType, fallback) ? fallback : mediaType);\n        if (resolvedMediaType) {\n            resolvedMediaType = addDefaultCharsetIfNeeded(resolvedMediaType, fallback);\n            message.headers.set('Content-Type', resolvedMediaType.toString());\n        }\n    }\n}\n\nfunction addDefaultCharsetIfNeeded(main: MediaType, defaultType?: MediaType): MediaType {\n    if (!main.params.has('charset') && defaultType !== undefined) {\n        const defaultCharset = defaultType.params.get('charset');\n        if (defaultCharset) {\n            const result = MediaType.parseMediaType(main.toString());\n            result.params.set('charset', defaultCharset);\n            return result;\n        }\n    }\n    return main;\n}\n\nfunction useFallback(main?: MediaType, fallback?: MediaType): boolean {\n    return (main === undefined || !isConcrete(main) || main.essence === MediaType.APPLICATION_OCTET_STREAM.essence) && fallback !== undefined;\n}\n\nclass BaseDefaultCodecs implements DefaultCodecs {\n    #multipartReader?: HttpMessageReader<unknown>;\n    #maxInMemorySize?: number;\n    #enableLoggingRequestDetails?: boolean;\n    #registerDefaults = true;\n    #writers = Array<HttpMessageWriter>();\n    #readers = Array<HttpMessageReader>();\n\n    constructor() {\n        this.initReaders();\n        this.initWriters();\n    }\n\n    multipartReader(reader: HttpMessageReader<unknown>) {\n        this.#multipartReader = reader;\n        this.initReaders();\n    }\n\n    registerDefaults(registerDefaults: boolean) {\n        if (this.#registerDefaults !== registerDefaults) {\n            this.#registerDefaults = registerDefaults;\n            this.initReaders();\n            this.initWriters();\n        }\n    }\n\n    protected initReaders(): void {\n        this.#readers.length = 0;\n        if (!this.#registerDefaults) {\n            return;\n        }\n\n        if (this.#multipartReader !== undefined) {\n            this.addCodec(this.#readers, this.#multipartReader);\n        }\n        else {\n            const partReader = new DefaultPartHttpMessageReader();\n            this.addCodec(this.#readers, partReader);\n            this.addCodec(this.#readers, new MultipartHttpMessageReader(partReader));\n        }\n    }\n\n    protected initWriters(): void {\n        this.#writers.length = 0;\n        if (!this.#registerDefaults) {\n            return;\n        }\n        this.#writers.push(...this.#getBaseWriters());\n        this.extendWriters(this.#writers);\n    }\n\n    protected extendWriters(writers: Array<HttpMessageWriter>): void {\n    }\n\n    #getBaseWriters(): HttpMessageWriter[] {\n        if (!this.#registerDefaults) {\n            return [];\n        }\n        const writers = Array<HttpMessageWriter>();\n        this.addCodec(writers, new EncoderHttpMessageWriter(new BlobEncoder()));\n        return writers;\n    }\n\n    maxInMemorySize(bytes: number) {\n        if (this.#maxInMemorySize !== bytes) {\n            this.#maxInMemorySize = bytes;\n            this.initReaders();\n        }\n    }\n\n    enableLoggingRequestDetails(enable: boolean) {\n        if (this.#enableLoggingRequestDetails !== enable) {\n            this.#enableLoggingRequestDetails = enable;\n            this.initReaders();\n            this.initWriters();\n        }\n    }\n\n    get catchAllReaders() {\n        if (!this.#registerDefaults) {\n            return [];\n        }\n        const readers = Array<HttpMessageReader>();\n\n        return readers;\n    }\n\n    get typedWriters() {\n        return this.#writers;\n    }\n\n    get typedReaders() {\n        return this.#readers;\n    }\n\n    get catchAllWriters(): readonly HttpMessageWriter[]{\n        if (!this.#registerDefaults) {\n            return [];\n        }\n        const result = Array<HttpMessageWriter>();\n        this.addCodec(result, new EncoderHttpMessageWriter(StringEncoder.allMimeTypes()));\n        return result;\n    }\n\n    protected addCodec<T >(codecs: Array<T>, codec: T) {\n        this.#initCodec(codec);\n        codecs.push(codec);\n    }\n\n    #initCodec(codec: unknown): void {\n        if (codec instanceof EncoderHttpMessageWriter) {\n            codec = codec.encoder;\n        }\n        if (codec === undefined) {\n            return;\n        }\n        const size = this.#maxInMemorySize;\n        if (size !== undefined) {\n            // todo\n        }\n\n        const enable = this.#enableLoggingRequestDetails;\n        if (enable !== undefined) {\n            if (codec instanceof MultipartHttpMessageReader) {\n                codec.enableLoggingRequestDetails = enable;\n            }\n            if (codec instanceof DefaultPartHttpMessageReader) {\n                codec.enableLoggingRequestDetails = enable;\n            }\n        }\n    }\n}\nabstract class BaseCodecConfigurer implements CodecConfigurer {\n    protected readonly baseDefaultCodecs: BaseDefaultCodecs;\n\n    protected constructor(defaultCodecs: BaseDefaultCodecs) {\n        this.baseDefaultCodecs = defaultCodecs;\n    }\n\n    get defaultCodecs(): DefaultCodecs {\n        return this.baseDefaultCodecs;\n    }\n\n    registerDefaults(registerDefaults: boolean) {\n        this.baseDefaultCodecs.registerDefaults(registerDefaults);\n    }\n\n    get readers() {\n        const result = new Array<HttpMessageReader>();\n        result.push(...this.baseDefaultCodecs.typedReaders);\n        result.push(...this.baseDefaultCodecs.catchAllReaders);\n        return result;\n    }\n\n    get writers(): readonly HttpMessageWriter[] {\n        const result = new Array<HttpMessageWriter>();\n        result.push(...this.baseDefaultCodecs.typedWriters);\n        result.push(...this.baseDefaultCodecs.catchAllWriters);\n        return result;\n    }\n\n}\n\nclass ServerDefaultCodecsImpl extends BaseDefaultCodecs implements ServerDefaultCodecs {\n\n}\nclass DefaultServerCodecConfigurer extends BaseCodecConfigurer implements ServerCodecConfigurer {\n    constructor() {\n        super(new ServerDefaultCodecsImpl());\n    }\n}\n\nfunction createServerCodecConfigurer(): ServerCodecConfigurer {\n    return new DefaultServerCodecConfigurer();\n}\n\nexport default {\n    serverConfigurer: {\n        create: createServerCodecConfigurer\n    }\n}\n", "import type { Logger } from '@interopio/gateway/logging/api';\nimport { createServer, type ListenOptions, type Server } from 'node:net';\nimport type { ManagementCommand } from '../../types/manage.d.ts';\nimport type { PipeServerOptions } from './types.d.ts';\nimport { unlink } from 'node:fs/promises';\nimport { sendCommand } from './client.ts';\n\nasync function isSocketStale(pipeName: string): Promise<{ stale: true } | { stale: false; pid: number }> {\n    try {\n        const response = await sendCommand({ path: pipeName }, { command: 'info' }, { timeout: 2000 }) as { pid?: number };\n        // Got a response, socket is in use by another instance\n        return { stale: false, pid: response?.pid ?? 0 };\n    } catch {\n        // Connection failed, socket is stale\n        return { stale: true };\n    }\n}\n\nasync function cleanupSocketFile(logger: Logger, pipeName?: string) {\n    if (process.platform === 'win32') {\n        // On Windows, the pipe file is automatically removed when the server is closed.\n        return;\n    }\n    if (pipeName) {\n        try {\n            await unlink(pipeName);\n        }\n        catch (e) {\n            const code = (e as NodeJS.ErrnoException).code;\n            if (code !== 'ENOENT') {\n                logger.warn(`[${pipeName}] error while removing the pipe - ${pipeName} (${code})`, e);\n            }\n        }\n    }\n}\n\nfunction createManagementServer({ logger, options, handler, onClose }: {\n    options: ListenOptions,\n    logger: Logger,\n    handler: (msg: ManagementCommand) => Promise<unknown>,\n    onClose?: () => void\n}): Promise<Server> {\n    const pipeName = options.path;\n\n    if (logger.enabledFor('info')) {\n        logger.info(`[${pipeName}] opening command server pipe, waiting for the data...`);\n    }\n    return new Promise<Server>((resolve, reject) => {\n        try {\n            const server: Server = createServer((stream) => {\n                if (logger.enabledFor('debug')) {\n                    logger.debug(`[${pipeName}] command pipe server got client, waiting for the data...`);\n                }\n                stream.on('close', () => {\n                    if (logger.enabledFor('debug')) {\n                        logger.debug(`[${pipeName}] client closed`);\n                    }\n                });\n                stream.on('error', (error) => {\n                    logger.error(`[${pipeName}] error on pipe stream`, error);\n                });\n                stream.on('data', async (data) => {\n                    try {\n                        const asString = data.toString('utf8');\n                        const msg = JSON.parse(asString) as ManagementCommand;\n                        if (logger.enabledFor('debug')) {\n                            logger.debug(`[${pipeName}] received command ${msg.command}`);\n                        }\n                        handler(msg)\n                            .then((result) => {\n                                const response = JSON.stringify({result});\n                                if (logger.enabledFor('debug')) {\n                                    logger.debug(`[${pipeName}] command ${msg.command} processed successfully. sending : ${response}`);\n                                }\n                                stream.write(response, (e) => {\n                                    if (e) {\n                                        if (logger.enabledFor('debug')) {\n                                            logger.debug(`[${pipeName}] error while sending response for command ${msg.command}`, e);\n                                        }\n                                    }\n                                });\n\n                            })\n                            .catch((error: { message: string }) => {\n                                const response = JSON.stringify({error: error.message});\n                                logger.error(`[${pipeName}] processing command ${msg.command} failed, sending ${response}`, error);\n                                stream.write(response, (e) => {\n                                    if (e) {\n                                        if (logger.enabledFor('debug')) {\n                                            logger.debug(`[${pipeName}] error while sending error response for command ${msg.command}`, e);\n                                        }\n                                    }\n                                });\n                            })\n                            .finally(() => {\n                                // if (msg.command === 'shutdown') {\n                                //     if (logger.enabledFor('info')) {\n                                //         logger.info(`[${pipeName}] stopping management pipe server`);\n                                //     }\n                                //     server.close(onClose);\n                                // }\n                            });\n                    }\n                    catch (error) {\n                        logger.error(`[${pipeName}] unable to parse the data`, error);\n                    }\n                });\n            });\n            server.on(\"listening\", () => {\n                if (logger.enabledFor('info')) {\n                    logger.info(`[${pipeName}] ready for commands...`);\n                }\n                resolve(server);\n            });\n            server.on(\"error\", (error) => {\n                if ((error as NodeJS.ErrnoException).code === 'EADDRINUSE') {\n                    if (pipeName) {\n                        logger.info(`[${pipeName}] already in use, checking if socket is stale...`);\n                        isSocketStale(pipeName).then((result) => {\n                            if (result.stale) {\n                                logger.info(`[${pipeName}] socket is stale, cleaning up and retrying...`);\n                                cleanupSocketFile(logger, pipeName).then(() => {\n                                    server.listen(options);\n                                }).catch(error => {\n                                    reject(error);\n                                });\n                            } else {\n                                const msg = `[${pipeName}] another gateway-server instance is already running on this path (pid: ${result.pid})`;\n                                logger.error(msg);\n                                reject(new Error(msg));\n                            }\n                        }).catch(error => {\n                            reject(error);\n                        });\n                        return;\n                    }\n                }\n                logger.error(`[${pipeName}] error while opening the pipe - ${pipeName}`, error);\n                reject(error);\n            });\n            server.on('close', () => onClose?.());\n            server.listen(options);\n        }\n        catch (cause) {\n            const msg = `error while opening the pipe - ${pipeName}`;\n            logger.error(msg, cause);\n            const error = new Error(msg) as Error & { cause?: unknown };\n            error.cause = cause;\n            reject(error);\n        }\n    });\n}\n\nexport async function gatewayManagementServer({ options, logger, shutdown, info }: PipeServerOptions) {\n    return await createManagementServer({\n        options,\n        logger,\n        onClose: () => {\n            if (logger.enabledFor('info')) {\n                logger.info(`[${options.path}] command server closed`);\n            }\n        },\n        handler: async (msg) => {\n            if (msg.command === 'shutdown') {\n                if (shutdown) {\n                    // will not wait for the shutdown to complete, as the server will need to close the connection\n                    // on which the shutdown command is received\n                    void shutdown().catch(error => {\n                        if (logger.enabledFor('error')) {\n                            logger.error(`[${options.path}] error during shutdown`, error);\n                        }\n                    });\n                    return 'shutdown initiated';\n                }\n                else {\n                    return 'shutdown disabled';\n                }\n            }\n            else if (msg.command === 'get-info' || msg.command === 'info') {\n                return await info();\n            }\n        }\n    });\n}\n", "import net from 'net';\nimport type { ManagementCommand, ManagementEndpoint, SendCommandOptions } from '../../types/manage.d.ts';\n\nexport function sendCommand(\n    server: ManagementEndpoint,\n    command: ManagementCommand,\n    options: SendCommandOptions = {}\n): Promise<unknown> {\n    const { timeout = 5000 } = options;\n\n    // Determine connection target: named pipe/socket path or port\n    const connectOptions: net.NetConnectOpts = server?.path\n        ? { path: server.path }\n        : { port: server?.port ?? 0 };\n\n    const target = server?.path ?? `port ${server?.port}`;\n\n    return new Promise((resolve, reject) => {\n        const client = net.connect(connectOptions, () => {\n            client.write(JSON.stringify(command));\n        });\n\n        const timeoutId = setTimeout(() => {\n            client.destroy();\n            reject(new Error(`Connection timed out after ${timeout}`));\n        }, timeout);\n\n        client.on('data', (data) => {\n            clearTimeout(timeoutId);\n            try {\n                const response = JSON.parse(data.toString());\n                if (response.error) {\n                    reject(new Error(response.error));\n                }\n                else {\n                    resolve(response.result);\n                }\n            }\n            catch {\n                // Not JSON, return as raw string\n                resolve(data.toString());\n            }\n            client.end();\n        });\n\n        client.on('error', (err: NodeJS.ErrnoException) => {\n            clearTimeout(timeoutId);\n            if (err.code === 'ENOENT' || err.code === 'ECONNREFUSED') {\n                reject(new Error(`Cannot connect to gateway at ${target}. Make sure the gateway server is running and the path is correct.`, { cause: err }));\n            }\n            else {\n                reject(err);\n            }\n        });\n    });\n}\n\n", "import { resolve } from 'node:path';\nimport { access, readFile } from 'node:fs/promises';\nimport { constants } from 'node:fs';\nimport type { ServerWebExchange } from '../../types/web/server';\nimport { HttpStatus } from '../http/status.ts';\nimport { mediaType } from './util/matchers.ts';\n\nasync function getWelcomePage(staticLocations?: string[]): Promise<string | undefined> {\n    if (staticLocations) {\n        for (const filePath of staticLocations) {\n            const indexHtml = resolve(filePath, 'index.html');\n            try {\n                await access(indexHtml, constants.R_OK);\n                // found readable welcome page\n                return indexHtml;\n            }\n            catch {\n                // continue to next candidate\n            }\n        }\n    }\n}\n\nexport default async function welcomePageFactory(staticLocations?: string[]) {\n    const welcomePage = await getWelcomePage(staticLocations);\n    const htmlMatcher = mediaType({mediaTypes: ['text/html']});\n\n    return async (exchange: ServerWebExchange, next: () => Promise<void>) => {\n        const { request, response } = exchange;\n        if (request.method === 'GET' && request.path === '/') {\n            response.setStatusCode(HttpStatus.OK);\n            if (welcomePage !== undefined && (await htmlMatcher(exchange)).match) {\n                response.headers.set('Content-Type', 'text/html; charset=utf-8');\n                await response.body(readFile(welcomePage));\n            }\n            else {\n                response.headers.set('Content-Type', 'text/plain; charset=utf-8');\n                const buffer = Buffer.from('io.Gateway Server', 'utf-8');\n                await response.body(buffer);\n            }\n        }\n        else {\n            await next();\n        }\n    }\n}\n", "import type { Logger } from '@interopio/gateway/logging/api';\nimport { AsyncLocalStorage } from 'node:async_hooks';\nimport type { Middleware, ServerHttpRequest, ServerHttpResponse, ServerWebExchange } from '../../../types/web/server';\nimport { DefaultWebExchange } from '../../server/exchange.ts';\nimport type { HttpHeaders } from '../../../types/web/http';\nimport { HttpStatus } from '../../http/status.ts';\nimport getLogger from '../../logger.ts';\nimport { checkAndLogClientDisconnectedError } from '../util/client.ts';\nimport type { WebErrorHandler, WebFilter, WebHandler } from './types.ts';\nimport { ErrorHandlingWebHandler, FilteringWebHandler } from './handler.ts';\nimport type { HttpHandler } from '../../http/server/types.ts';\nimport { ServerCodecConfigurer } from '../../http/codec/types.ts';\nimport codecConfig from '../../http/codec/config.ts';\nimport { LoggingCodecSupport } from '../../http/codec/core.ts';\n\nclass HttpWebHandlerAdapter {\n\n    readonly #logger: Logger;\n\n    #codecConfigurer: ServerCodecConfigurer = undefined!;\n    #enableLoggingRequestDetails: boolean = false;\n    readonly #delegate: WebHandler;\n    #storage?: AsyncLocalStorage<{ exchange: ServerWebExchange }>;\n\n    constructor(logger: Logger, delegate: WebHandler) {\n        this.#logger = logger;\n        this.#delegate = delegate;\n    }\n\n    get codecConfigurer(): ServerCodecConfigurer {\n        if (this.#codecConfigurer === undefined) {\n            this.codecConfigurer = codecConfig.serverConfigurer.create()\n        }\n        return this.#codecConfigurer;\n    }\n\n    set codecConfigurer(configurer: ServerCodecConfigurer) {\n        if (configurer === null || configurer === undefined) {\n            throw new Error('codecConfigurer must not be null or undefined');\n        }\n        this.#codecConfigurer = configurer;\n\n        this.#enableLoggingRequestDetails = false;\n        for (const reader of this.#codecConfigurer.readers) {\n            if (reader instanceof LoggingCodecSupport && reader.enableLoggingRequestDetails) {\n                this.#enableLoggingRequestDetails = true;\n                break;\n            }\n        }\n    }\n\n    protected createExchange(request: ServerHttpRequest, response: ServerHttpResponse): ServerWebExchange {\n        const exchange = new DefaultWebExchange(request, response, this.codecConfigurer);\n        return exchange;\n    }\n\n    set storage(storage: AsyncLocalStorage<{ exchange: ServerWebExchange }>) {\n        this.#storage = storage;\n    }\n\n\n    formatHeaders(headers: HttpHeaders): string {\n        let result = '{';\n\n        for (const key of headers.keys()) {\n            if (!this.#enableLoggingRequestDetails) {\n                result += 'masked, ';\n                break;\n            }\n            else {\n                const value = headers.get(key);\n                result += `\"${key}\": \"${value}\", `;\n            }\n        }\n        if (result.endsWith(', ')) {\n            result = result.slice(0, -2);\n        }\n        result += '}';\n        return result;\n\n    }\n\n    formatRequest(request: ServerHttpRequest): string {\n        const query = request.URL.search;\n        return `HTTP ${request.method} \"${request.path}${query}`;\n    }\n\n    logRequest(exchange: ServerWebExchange) {\n        if (this.#logger.enabledFor('debug')) {\n            const trace = this.#logger.enabledFor('trace');\n            this.#logger.debug(`${exchange.logPrefix}${this.formatRequest(exchange.request)}${trace ? `, headers: ${this.formatHeaders(exchange.request.headers)}` : ''}\"`);\n\n        }\n    }\n\n    logResponse(exchange: ServerWebExchange) {\n        if (this.#logger.enabledFor('debug')) {\n            const trace = this.#logger.enabledFor('trace');\n            const status = exchange.response.statusCode;\n            this.#logger.debug(`${exchange.logPrefix}Completed ${status ?? '200 OK'}${trace ? `, headers: ${this.formatHeaders(exchange.response.headers)}` : ''}\"`);\n        }\n    }\n\n    handleUnresolvedError(exchange: ServerWebExchange, error: Error) {\n        const { request, response, logPrefix } = exchange;\n\n        if (response.setStatusCode(HttpStatus.INTERNAL_SERVER_ERROR)) {\n            this.#logger.error(`${logPrefix}500 Server Error for ${this.formatRequest(request)}`, error);\n            return;\n        }\n        else if (checkAndLogClientDisconnectedError(error, this.#logger)) {\n            // todo notify observers\n            return;\n        }\n        else {\n\n            this.#logger.error(`${logPrefix}Error [${error.message} for ${this.formatRequest(request)}, but already ended (${response.statusCode})`, error);\n            throw error;\n        }\n\n    }\n\n    async web(exchange: ServerWebExchange): Promise<void> {\n        return await this.#delegate.handle(exchange);\n    }\n\n    async http(request: ServerHttpRequest, response: ServerHttpResponse): Promise<void> {\n\n        const exchange = this.createExchange(request, response);\n        const callback = () => {\n            this.logRequest(exchange);\n            return this.web(exchange)\n                .then(() => {\n                    this.logResponse(exchange);\n                })\n                .catch((error: Error) => {\n                    this.handleUnresolvedError(exchange, error)\n                })\n                .then(async () => {\n                    await exchange.response.end();\n                });\n        };\n\n        await new Promise<void>((resolve, reject) => {\n            if (this.#storage !== undefined) {\n                this.#storage.run({ exchange }, () => {\n                    callback().then(() => resolve()).catch((error) => reject(error));\n                });\n            }\n            else {\n                callback().then(() => resolve()).catch((error) => reject(error));\n            }\n        });\n    }\n}\n\nexport class WebHttpHandlerBuilder {\n    readonly #webHandler: WebHandler;\n    readonly #filters: WebFilter[] = [];\n    readonly #exceptionHandlers: WebErrorHandler[] = [];\n    readonly #middleware: Middleware = [];\n    #handlerDecorator?: (handler: HttpHandler) => HttpHandler;\n    #storage?: AsyncLocalStorage<{ exchange: ServerWebExchange }> = new AsyncLocalStorage();\n    #codecConfigurer?: ServerCodecConfigurer;\n\n    constructor(webHandler: WebHandler) {\n        this.#webHandler = webHandler;\n    }\n\n    static webHandler(webHandler: WebHandler): WebHttpHandlerBuilder {\n        return new WebHttpHandlerBuilder(webHandler);\n    }\n\n    filter(...filters: WebFilter[]): this {\n        if (filters) {\n            this.#filters.push(...filters);\n        }\n        return this;\n    }\n\n    middleware(consumer: (middleware: Middleware) => void): this {\n        consumer(this.#middleware);\n        return this;\n    }\n\n    exceptionHandler(...handlers: WebErrorHandler[]): this {\n        if (handlers) {\n            this.#exceptionHandlers.push(...handlers);\n        }\n        return this;\n    }\n\n    exceptionHandlers(consumer: (handlers: WebErrorHandler[]) => void): this {\n        consumer(this.#exceptionHandlers);\n        return this;\n    }\n\n    storage(storage: AsyncLocalStorage<{ exchange: ServerWebExchange }>): this {\n        this.#storage = storage;\n        return this;\n    }\n\n    codecConfigurer(configurer: ServerCodecConfigurer): this {\n        this.#codecConfigurer = configurer;\n        return this;\n    }\n\n    hasCodecConfigurer(): boolean {\n        return this.#codecConfigurer !== undefined;\n    }\n\n    httpHandlerDecorator(decorator: (handler: HttpHandler) => HttpHandler): this {\n        if (this.#handlerDecorator === undefined) {\n            this.#handlerDecorator = decorator;\n        }\n        else {\n            const previousDecorator = this.#handlerDecorator;\n            this.#handlerDecorator = (handler: HttpHandler) => {\n                handler = decorator(handler);\n                handler = previousDecorator(handler);\n                return handler;\n            }\n        }\n        return this;\n    }\n\n    hasHttpHandlerDecorator(): boolean {\n        return this.#handlerDecorator !== undefined;\n    }\n\n    build(): HttpHandler {\n        const logger = getLogger('http');\n        let decorated: WebHandler = new FilteringWebHandler(this.#webHandler, ...this.#filters);\n        decorated = new ErrorHandlingWebHandler(decorated, ...this.#exceptionHandlers);\n\n        const adapter = new HttpWebHandlerAdapter(logger, decorated);\n        if (this.#storage !== undefined) adapter.storage = this.#storage;\n        if (this.#codecConfigurer !== undefined) {\n            adapter.codecConfigurer = this.#codecConfigurer;\n        }\n        const adapted: HttpHandler = async (request, response) => adapter.http(request, response);\n\n\n        return this.#handlerDecorator ? this.#handlerDecorator(adapted) : adapted;\n    }\n}\n", "import type { Logger } from '@interopio/gateway/logging/api';\n\nexport function isClientDisconnectedError(error: Error): boolean {\n    if (error === null || error === undefined) {\n        return false;\n    }\n    const { code, message } = error as any;\n    return code === 'ECONNRESET' ||\n        code === 'EPIPE' ||\n        code === 'ERR_STREAM_PREMATURE_CLOSE' ||\n        message?.toLowerCase().includes('client aborted') ||\n        message?.toLowerCase().includes('socket hang up') ||\n        message?.toLowerCase().includes('aborted');\n}\n\nexport function checkAndLogClientDisconnectedError(error: Error, logger: Logger): boolean {\n    const isClientDisconnected = isClientDisconnectedError(error);\n    if (isClientDisconnected) {\n        if (logger.enabledFor('trace')) {\n            logger.debug('looks like the client has gone away:', error);\n        }\n        else if (logger.enabledFor('debug')) {\n            logger.debug(`looks like the client has gone away: ${error.message} (For full stack trace enable trace logging level.)`);\n        }\n        return true;\n    }\n    return false;\n}\n", "import type { ServerHttpRequest, ServerWebExchange } from '../../../../../types/web/server';\nimport type { ReadonlyHttpHeaders } from '../../../../../types/web/http';\nimport type { ServerRequest, ServerRequestHeaders } from './types.ts';\nimport { MIMEType } from 'node:util';\nimport { MediaType } from '../../../../http/media-type.ts';\nimport { getContentType } from '../../../../http/headers.ts';\nimport type { HttpMessageReader } from '../../../../http/codec/types.ts';\n\nexport default {\n    create: (exchange: ServerWebExchange, messageReaders: readonly HttpMessageReader[]) : ServerRequest => {\n        return new DefaultServerRequest(exchange, messageReaders);\n    }\n}\n\nclass DefaultServerRequestHeaders implements ServerRequestHeaders {\n    readonly #headers: ReadonlyHttpHeaders;\n    constructor(headers: ReadonlyHttpHeaders) {\n        this.#headers = headers;\n    }\n\n    accept(): MIMEType[] {\n        return MediaType.parseMediaTypes(...this.#headers.list('accept'));\n    }\n\n    contentLength(): number | undefined {\n        const value = this.#headers.one('content-length');\n        return value !== undefined ? Number.parseInt(value) : undefined;\n    }\n\n    contentType(): MIMEType | undefined {\n        return getContentType(this.#headers);\n    }\n\n    header(name: string): string[] {\n        return this.#headers.list(name);\n    }\n\n    firstHeader(name: string): string | undefined {\n        const list = this.#headers.list(name);\n        return list.length > 0 ? list[0] : undefined;\n    }\n\n    asHttpHeaders(): ReadonlyHttpHeaders {\n        return this.#headers;\n    }\n}\n\nexport class DefaultServerRequest implements ServerRequest {\n    readonly exchange: ServerWebExchange;\n    readonly messageReaders: readonly HttpMessageReader[];\n    readonly #headers: ServerRequestHeaders;\n    constructor(exchange: ServerWebExchange, messageReaders: readonly HttpMessageReader[]) {\n        this.exchange = exchange;\n        this.messageReaders = [...messageReaders];\n        this.#headers = new DefaultServerRequestHeaders(exchange.request.headers);\n    }\n\n    get attributes(): Map<string, unknown> {\n        return this.exchange.attributes;\n    }\n\n    get headers() {\n        return this.#headers;\n    }\n\n    get method() {\n        return this.request.method;\n    }\n\n    get URL() {\n        return this.request.URL;\n    }\n\n    get requestPath() {\n        return this.request.requestPath;\n    }\n\n    queryParam(name: string): string | null {\n        return this.request.URL.searchParams.get(name);\n    }\n\n    get principal() {\n        return this.exchange.principal();\n    }\n\n    get request(): ServerHttpRequest {\n        return this.exchange.request;\n    }\n}\n", "import { MatchingContext } from '../path-pattern.ts';\n\n/*internal*/ export abstract class PathElement {\n    protected static readonly WILDCARD_WEIGHT = 100;\n    protected static readonly CAPTURE_VARIABLE_WEIGHT = 1;\n\n    protected static readonly NO_PARAMETERS: Map<string, readonly string[]> = new Map();\n\n    // position in the pattern where this path element starts\n    protected readonly pos: number;\n    // the separator used in this path pattern\n    protected readonly separator: number;\n\n    // the next path element in the chain\n    /*protected*/ next?: PathElement;\n    // the previous path element in the chain\n    /*protected*/ prev?: PathElement;\n\n    /*internal*/ protected constructor(pos: number, separator: number) {\n        this.pos = pos;\n        this.separator = separator;\n    }\n\n    abstract matches(candidatePos: number, matchingContext: MatchingContext): boolean;\n\n    abstract get normalizedLength(): number;\n\n    abstract get chars(): Uint16Array;\n\n    get captureCount(): number {\n        return 0;\n    }\n\n    get wildcardCount(): number {\n        return 0;\n    }\n\n    get score(): number {\n        return 0;\n    }\n\n    get literal() {\n        return false;\n    }\n\n    /*protected final*/\n    noMorePattern() {\n        return this.next === undefined;\n    }\n\n}\n", "import { PathElement } from './path-element.ts';\nimport { MatchingContext } from '../path-pattern.ts';\n\n/*internal*/ export class SeparatorPathElement extends PathElement {\n    constructor(pos: number, separator: number) {\n        super(pos, separator);\n    }\n\n    matches(pathIndex: number, matchingContext: MatchingContext): boolean {\n        if (pathIndex < matchingContext.pathLength && matchingContext.isSeparator(pathIndex)) {\n            if (this.noMorePattern()) {\n                if (matchingContext.determinedRemainingPath) {\n                    matchingContext.remainingPathIndex = pathIndex + 1;\n                    return true;\n                }\n                else {\n                    return (pathIndex + 1 === matchingContext.pathLength);\n                }\n            }\n            else {\n                pathIndex++;\n                return (this.next !== undefined && this.next.matches(pathIndex, matchingContext));\n            }\n        }\n        return false;\n    }\n\n    get normalizedLength() {\n        return 1;\n    }\n\n    get chars(): Uint16Array {\n        return new Uint16Array([this.separator]);\n    }\n\n    get literal() {\n        return true;\n    }\n\n    toString() {\n        return `Separator(${String.fromCharCode(this.separator)})`;\n    }\n}\n", "import { isPathSegment } from '../../../../http/server/path.ts';\nimport { PathElement } from './path-element.ts';\nimport { MatchingContext } from '../path-pattern.ts';\n\n/*internal*/ export class WildcardPathElement extends PathElement {\n    constructor(pos: number, separator: number) {\n        super(pos, separator);\n    }\n\n    matches(pathIndex: number, matchingContext: MatchingContext): boolean {\n        let segmentData: string = undefined!;\n        if (pathIndex < matchingContext.pathLength) {\n            const element = matchingContext.pathElements[pathIndex];\n            if (!isPathSegment(element)) {\n                // should not match a separator\n                return false;\n            }\n            segmentData = element.valueToMatch;\n            pathIndex++;\n        }\n\n        if (this.noMorePattern()) {\n            if (matchingContext.determinedRemainingPath) {\n                matchingContext.remainingPathIndex = pathIndex;\n                return true;\n            }\n            else {\n                // and the path data has run out too\n                return (pathIndex === matchingContext.pathLength);\n            }\n        }\n        else {\n            // within a path (e.g. /aa/*/bb) there must be at least one character to match the wildcard\n            if (segmentData === undefined || segmentData.length === 0) {\n                return false;\n            }\n            return (this.next !== undefined && this.next.matches(pathIndex, matchingContext));\n        }\n    }\n\n    get normalizedLength(): number {\n        return 1;\n    }\n\n    get chars() {\n        return new Uint16Array(['*'.charCodeAt(0)]);\n    }\n\n    get wildcardCount(): number {\n        return 1;\n    }\n\n    get score(): number {\n        return PathElement.WILDCARD_WEIGHT;\n    }\n\n    toString() {\n        return `Wildcard(*)`;\n    }\n}\n", "import { PathElement } from './path-element.ts';\nimport { MatchingContext } from '../path-pattern.ts';\nimport { isPathSegment } from '../../../../http/server/path.ts';\nimport type { PathContainerElement } from '../../../../../types/path';\n\n/*internal*/ export class CaptureSegmentsPathElement extends PathElement {\n    readonly #variableName: string;\n\n    constructor(pos: number, captureDescriptor: Uint16Array, separator: number) {\n        super(pos, separator);\n        this.#variableName = String.fromCharCode(...captureDescriptor.slice(2, captureDescriptor.length - 1));\n    }\n\n    matches(pathIndex: number, matchingContext: MatchingContext): boolean {\n        if (pathIndex === 0 && this.next !== undefined) {\n            let endPathIndex = pathIndex;\n            while (endPathIndex < matchingContext.pathLength) {\n                if (this.next.matches(endPathIndex, matchingContext)) {\n                    this.#collectParameters(matchingContext, pathIndex, endPathIndex);\n                    return true;\n                }\n                endPathIndex++;\n            }\n            return false;\n        }\n        else if (pathIndex < matchingContext.pathLength && !matchingContext.isSeparator(pathIndex)) {\n            return false;\n        }\n        if (matchingContext.determinedRemainingPath) {\n            matchingContext.remainingPathIndex = matchingContext.pathLength;\n        }\n        this.#collectParameters(matchingContext, pathIndex, matchingContext.pathLength);\n        return true;\n    }\n\n    #collectParameters(matchingContext: MatchingContext, startPathIndex: number, endPathIndex: number) {\n        if (matchingContext.extractingVariables) {\n            // collect the parameters from all the remaining path segments\n            let parametersCollector = PathElement.NO_PARAMETERS;\n            for (let i = startPathIndex; i < endPathIndex; i++) {\n                const element = matchingContext.pathElements[i];\n                if (isPathSegment(element)) {\n                    const { parameters } = element;\n                    if (parameters.size > 0) {\n                        if (parametersCollector === PathElement.NO_PARAMETERS) {\n                            parametersCollector = new Map<string, string[]>();\n                        }\n                        for (const [key, values] of parameters) {\n                            if (parametersCollector.has(key)) {\n                                const existingValues = parametersCollector.get(key)!;\n                                parametersCollector.set(key, existingValues.concat(values));\n                            }\n                            else {\n                                parametersCollector.set(key, values);\n                            }\n                        }\n                    }\n                }\n            }\n            matchingContext.set(\n                this.#variableName,\n                this.#pathToString(startPathIndex, endPathIndex, matchingContext.pathElements), parametersCollector);\n        }\n    }\n\n    #pathToString(fromSegment: number, toSegment: number, pathElements: readonly PathContainerElement[]): string {\n        const sb: string[] = [];\n        for (let i = fromSegment; i <  toSegment; i++) {\n            const element = pathElements[i];\n            if (isPathSegment(element)) {\n                sb.push(element.valueToMatch);\n            }\n            else {\n                sb.push(element.value);\n            }\n        }\n        return sb.join('');\n    }\n\n    get normalizedLength() {\n        return 1;\n    }\n\n    get chars(): Uint16Array {\n        const s = `${String.fromCharCode(this.separator)}{*${this.#variableName}}`;\n        const result = new Uint16Array(s.length);\n        for (let i = 0; i < s.length; i++) {\n            result[i] = s.charCodeAt(i);\n        }\n        return result;\n    }\n\n    get wildcardCount(): number {\n        return 0;\n    }\n\n    get captureCount(): number {\n        return 1;\n    }\n\n    toString() {\n        return `CaptureSegments(${String.fromCharCode(this.separator)}{*${this.#variableName}})`;\n    }\n}\n", "import { PathElement } from './path-element.ts';\nimport { MatchingContext } from '../path-pattern.ts';\n\n/*internal*/ export class WildcardSegmentsPathElement extends PathElement {\n    constructor(pos: number, separator: number) {\n        super(pos, separator);\n    }\n\n    matches(pathIndex: number, matchingContext: MatchingContext): boolean {\n        // wildcard segments at the start of the pattern\n        if (pathIndex === 0 && this.next !== undefined) {\n            let endPathIndex = pathIndex;\n            while (endPathIndex < matchingContext.pathLength) {\n                if (this.next.matches(endPathIndex, matchingContext)) {\n                    return true;\n                }\n                endPathIndex++;\n            }\n            return false;\n        }\n        // match until the end of the path\n        else if (pathIndex < matchingContext.pathLength && !matchingContext.isSeparator(pathIndex)) {\n            return false;\n        }\n        if (matchingContext.determinedRemainingPath) {\n            matchingContext.remainingPathIndex = matchingContext.pathLength;\n        }\n        return true;\n    }\n\n    get normalizedLength() {\n        return 1;\n    }\n\n    get chars(): Uint16Array {\n        const s = `${String.fromCharCode(this.separator)}**`;\n        const result = new Uint16Array(s.length);\n        for (let i = 0; i < s.length; i++) {\n            result[i] = s.charCodeAt(i);\n        }\n        return result;\n    }\n\n    get wildcardCount() {\n        return 1;\n    }\n\n    toString() {\n        return `WildcardSegments(${String.fromCharCode(this.separator)}**)`;\n    }\n}\n", "import {\n    isPathSegment,\n    isSeparator,\n    type Options,\n    parsePath,\n    subPath\n} from '../../../http/server/path.ts';\n\nimport { PathPatternParser } from './path-pattern-parser.ts';\nimport { PathElement } from './internal/path-element.ts';\nimport { SeparatorPathElement } from './internal/separator-path-element.ts';\nimport { WildcardPathElement } from './internal/wildcard-path-element.ts';\nimport { CaptureSegmentsPathElement } from './internal/capture-segments-path-element.ts';\nimport { WildcardSegmentsPathElement } from './internal/wildcard-segments-path-element.ts';\nimport type { PathContainer, PathContainerElement } from '../../../../types/path';\n\nexport /* internal */ class MatchingContext {\n    readonly #candidate: PathContainer;\n    readonly pathElements: readonly PathContainerElement[];\n    readonly pathLength: number;\n    #extractedUriVariables?: Map<string, string>;\n    #extractedMatrixVariables?: Map<string, ReadonlyMap<string, readonly string[]>>;\n    readonly extractingVariables: boolean = false;\n    #determineRemainingPath: boolean = false;\n\n    remainingPathIndex: number = 0;\n\n    constructor(pathContainer: PathContainer, extractVariables: boolean) {\n        this.#candidate = pathContainer;\n        this.pathElements = pathContainer.elements;\n        this.pathLength = this.pathElements.length;\n        this.extractingVariables = extractVariables;\n    }\n\n    get determinedRemainingPath(): boolean {\n        return this.#determineRemainingPath;\n    }\n\n    setMatchAllowExtraPath() {\n        this.#determineRemainingPath = true;\n    }\n\n\n    set(key: string, value: string, parameters: ReadonlyMap<string, readonly string[]>) {\n        if (this.#extractedUriVariables === undefined) {\n            this.#extractedUriVariables = new Map();\n        }\n        this.#extractedUriVariables.set(key, value);\n\n        if (parameters.size > 0) {\n            if (this.#extractedMatrixVariables === undefined) {\n                this.#extractedMatrixVariables = new Map();\n            }\n            this.#extractedMatrixVariables.set(key, parameters);\n        }\n    }\n\n    get pathMatchResult() {\n        if (this.#extractedUriVariables === undefined) {\n            return PathMatchInfo.EMPTY;\n        }\n        else {\n            return new PathMatchInfo(this.#extractedUriVariables, this.#extractedMatrixVariables);\n        }\n    }\n\n    /*internal*/\n    isSeparator(pathIndex: number): boolean {\n        return isSeparator(this.pathElements[pathIndex]);\n    }\n\n    /*internal*/\n    pathElementValue(pathIndex: number): string {\n        const element = (pathIndex < this.pathLength) ? this.pathElements[pathIndex] : null;\n        if (element !== null && isPathSegment(element)) {\n            return element.valueToMatch;\n        }\n        else {\n            return '';\n        }\n    }\n}\n\nexport class PathMatchInfo {\n    static readonly EMPTY = new PathMatchInfo(new Map(), new Map());\n\n    readonly uriVariables: ReadonlyMap<string, string>;\n    readonly matrixVariables: ReadonlyMap<string, ReadonlyMap<string, readonly string[]>>;\n\n    constructor(uriVars: ReadonlyMap<string, string>, matrixVars?: ReadonlyMap<string, ReadonlyMap<string, readonly string[]>>) {\n        this.uriVariables = uriVars;\n        this.matrixVariables = matrixVars ?? new Map();\n    }\n\n    toString(): string {\n        return `PathMatchInfo(uriVariables=${this.uriVariables}, matrixVariables=${this.matrixVariables})`;\n    }\n}\n\nexport class PathPattern {\n    static readonly #EMPTY_PATH = parsePath('');\n    static readonly SPECIFICITY_COMPARATOR = (a: PathPattern, b: PathPattern): number => {\n        if (a === null || a === undefined) {\n            return (b === null || b === undefined) ? 0 : 1;\n        }\n        else if (b === null || b === undefined) {\n            return -1;\n        }\n        else {\n            // catchAll true > catchAll false\n            if (a.catchAll && !b.catchAll) {\n                return 1;\n            }\n            else if (!a.catchAll && b.catchAll) {\n                return -1;\n            }\n            else {\n                // todo\n                return 0;\n            }\n        }\n    }\n\n    readonly #patternString: string;\n    readonly #parser: PathPatternParser;\n    readonly #pathOptions: Options;\n    readonly #caseSensitive: boolean;\n    readonly #head?: PathElement;\n\n    #capturedVariableCount: number = 0;\n    #normalizedLength: number = 0;\n    #endsWithSeparatorWildcard: boolean = false;\n    #score: number = 0;\n    // does the pattern ends with {*...}.\n    #catchAll: boolean = false;\n\n    constructor(patternText: string, parser: PathPatternParser, head?: PathElement) {\n        this.#patternString = patternText;\n        this.#parser = parser;\n        this.#pathOptions = parser.pathOptions;\n        this.#caseSensitive = parser.caseSensitive;\n        this.#head = head;\n\n        // Compute fields for fast comparison\n        let current = head;\n        while (current !== undefined) {\n            this.#capturedVariableCount += current.captureCount;\n            this.#normalizedLength += current.normalizedLength;\n            this.#score += current.score;\n            if (current instanceof CaptureSegmentsPathElement || current instanceof WildcardSegmentsPathElement) {\n                this.#catchAll = true;\n            }\n            if (current instanceof SeparatorPathElement && current.next instanceof WildcardPathElement && current.next.next === undefined) {\n                this.#endsWithSeparatorWildcard = true;\n            }\n\n            current = current.next;\n        }\n    }\n\n    get patternString(): string {\n        return this.#patternString;\n    }\n\n    get hasPatternSyntax(): boolean {\n        return (this.#score > 0 || this.#catchAll || this.#patternString.indexOf('?') !== -1);\n    }\n\n    #hasLength(container?: PathContainer): container is PathContainer {\n        return container !== undefined && container.elements.length > 0;\n    }\n\n    #pathContainerIsJustSeparator(container: PathContainer): boolean {\n        return container.value.length === 1 && container.value.charCodeAt(0) === this.separator;\n    }\n\n    matches(pathContainer?: PathContainer): boolean {\n        if (this.#head === undefined) {\n            return !this.#hasLength(pathContainer);\n        }\n        else if (!this.#hasLength(pathContainer)) {\n            if (this.#head instanceof WildcardSegmentsPathElement || this.#head instanceof CaptureSegmentsPathElement) {\n                pathContainer = PathPattern.#EMPTY_PATH; // will allow CaptureTheRest to bind the variable to empty\n            }\n            else {\n                return false;\n            }\n        }\n        const matchingContext = new MatchingContext(pathContainer, false);\n        return this.#head.matches(0, matchingContext);\n    }\n\n    matchAndExtract(pathContainer: undefined | PathContainer): PathMatchInfo | undefined {\n        if (this.#head === undefined) {\n            return (this.#hasLength(pathContainer) && !this.#pathContainerIsJustSeparator(pathContainer)) ? undefined : PathMatchInfo.EMPTY;\n        }\n        else if (!this.#hasLength(pathContainer)) {\n            if (this.#head instanceof WildcardSegmentsPathElement || this.#head instanceof CaptureSegmentsPathElement) {\n                pathContainer = PathPattern.#EMPTY_PATH; // will allow CaptureTheRest to bind the variable to empty\n            }\n            else {\n                return undefined;\n            }\n        }\n        const matchingContext = new MatchingContext(pathContainer, true);\n        return this.#head.matches(0, matchingContext) ? matchingContext.pathMatchResult : undefined;\n    }\n\n\n    extractPathWithinPattern(path: PathContainer): PathContainer {\n        const pathElements = path.elements;\n        const pathElementsLength = pathElements.length;\n\n        let startIndex = 0;\n\n        let elem = this.#head;\n        while (elem !== undefined) {\n            if (!elem.literal) {\n                break;\n            }\n            elem = elem.next;\n            startIndex++;\n        }\n        if (elem === undefined) {\n            // there is no pattern piece\n            return parsePath('')\n        }\n\n        // skip leading separators that would be in the result\n        while (startIndex < pathElementsLength && isSeparator(pathElements[startIndex])) {\n            startIndex++;\n        }\n\n        let endIndex = pathElementsLength;\n        // skip trailing separators that would be in the result\n        while (endIndex > 0 && isSeparator(pathElements[endIndex - 1])) {\n            endIndex--;\n        }\n\n        let multipleAdjacentSeparators = false;\n        for (let i = startIndex; i < endIndex - 1; i++) {\n            if (isSeparator(pathElements[i]) && isSeparator(pathElements[i + 1])) {\n                multipleAdjacentSeparators = true;\n                break;\n            }\n        }\n\n        let resultPath: PathContainer;\n        if (multipleAdjacentSeparators) {\n            const sb : string[] = [];\n            let  i = startIndex;\n            while (i < endIndex) {\n                const e = pathElements[i++];\n                sb.push(e.value);\n                if (isSeparator(e)) {\n                    while (i < endIndex && isSeparator(pathElements[i])) {\n                        i++;\n                    }\n                }\n            }\n            resultPath = parsePath(sb.join(''), this.#pathOptions);\n        }\n        else if (startIndex >= endIndex) {\n            resultPath = parsePath('', this.#pathOptions);\n        }\n        else {\n            resultPath = subPath(path, startIndex, endIndex);\n        }\n        return resultPath;\n    }\n\n    /* internal */\n    get score(): number {\n        return this.#score;\n    }\n\n    /* internal */\n    get catchAll(): boolean {\n        return this.#catchAll;\n    }\n\n    /* internal */\n    get normalizedLength(): number {\n        return this.#normalizedLength;\n    }\n\n    /* internal */\n    get separator(): number {\n        return this.#pathOptions.separator;\n    }\n\n    /* internal */\n    get capturedVariableCount(): number {\n        return this.#capturedVariableCount;\n    }\n\n    /* internal */\n    toChainString(): string {\n        const sb: string[] = [];\n        let pe = this.#head;\n        while (pe !== undefined) {\n            sb.push(pe.toString());\n            pe = pe.next;\n        }\n        return sb.join(' ');\n    }\n\n    /* internal */\n    computePatternString(): string {\n        const sb: string[] = [];\n        let current = this.#head;\n        while (current !== undefined) {\n            sb.push(String.fromCharCode(...(current.chars)));\n            current = current.next;\n        }\n        return sb.join('');\n    }\n\n    /* internal */\n    get head(): PathElement | undefined {\n        return this.#head;\n    }\n\n}\n", "import { format } from 'node:util';\n\nconst PatternMessages = {\n    MISSING_CLOSE_CAPTURE: \"Expected close capture character after variable name '}'\",\n    MISSING_OPEN_CAPTURE: \"Missing preceding open capture character before variable name'{'\",\n    ILLEGAL_NESTED_CAPTURE: \"Not allowed to nest variable captures\",\n    CANNOT_HAVE_ADJACENT_CAPTURES: \"Adjacent captures are not allowed\",\n    ILLEGAL_CHARACTER_AT_START_OF_CAPTURE_DESCRIPTOR: \"Char '%s' not allowed at start of captured variable name\",\n    ILLEGAL_CHARACTER_IN_CAPTURE_DESCRIPTOR: \"Char '%s' is not allowed in a captured variable name\",\n    CANNOT_HAVE_MANY_MULTISEGMENT_PATH_ELEMENTS: \"Multiple '{*...}' or '**' pattern elements are not allowed\",\n    INVALID_LOCATION_FOR_MULTISEGMENT_PATH_ELEMENT: \"'{*...}' or '**' pattern elements should be placed at the start or end of the pattern\",\n    MISSING_REGEX_CONSTRAINT: \"Missing regex constraint on capture\",\n    ILLEGAL_DOUBLE_CAPTURE: \"Not allowed to capture ''{0}'' twice in the same pattern\",\n    REGEX_PATTERN_SYNTAX_EXCEPTION: \"Exception occurred in regex pattern compilation\",\n    CAPTURE_ALL_IS_STANDALONE_CONSTRUCT: \"'{*...}' cannot be mixed with other path elements in the same path segment\",\n}\n\nexport type PatternMessage = keyof typeof PatternMessages;\n\nexport class PatternParseError extends Error {\n\n    readonly position: number;\n    readonly messageType: PatternMessage;\n    readonly inserts: readonly unknown[];\n    readonly #pattern: Uint16Array;\n\n    static formatMessage(messageType: PatternMessage, inserts: readonly unknown[]): string {\n        return format(PatternMessages[messageType], ...inserts);\n    }\n\n    /* internal */ static createWithCause(cause: Error,\n                                  position: number,\n                                  pattern: Uint16Array,\n                                  messageType: PatternMessage,\n                                  ...inserts: readonly unknown[]): PatternParseError {\n        const message = PatternParseError.formatMessage(messageType, inserts);\n        return new PatternParseError(position, pattern, messageType, inserts, message, { cause });\n    }\n\n    /* internal */ static create(pos: number, pattern: Uint16Array, messageType: PatternMessage, ...inserts: readonly unknown[]): PatternParseError {\n        const message = PatternParseError.formatMessage(messageType, inserts);\n        return new PatternParseError(pos, pattern, messageType, inserts, message);\n    }\n\n    private constructor(\n        pos: number,\n        pattern: Uint16Array,\n        messageType: PatternMessage,\n        inserts: readonly unknown[],\n        message: string,\n        options?: { cause?: Error },\n    ) {\n        super(message, options);\n        this.position = pos;\n        this.#pattern = pattern;\n        this.messageType = messageType;\n        this.inserts = inserts;\n    }\n\n    toDetailedString(): string {\n        const sb: string[] = [];\n        sb.push(String.fromCharCode(...this.#pattern));\n        sb.push('\\n');\n        for (let i = 0; i < Math.max(0, this.position); i++) {\n            sb.push(' ');\n        }\n        sb.push('^\\n');\n        sb.push(this.message);\n        return sb.join('');\n    }\n}\n", "import { PathElement } from './path-element.ts';\nimport { MatchingContext } from '../path-pattern.ts';\n\nimport type { PathSegment } from '../../../../../types/path';\n\n/*internal*/ export class CaptureVariablePathElement extends PathElement {\n    readonly variableName: string\n    readonly #constraintPattern?: RegExp;\n\n    constructor(pos: number, captureDescriptor: Uint16Array, caseSensitive: boolean, separator: number) {\n        super(pos, separator);\n        let colon = -1;\n        for (let i = 0; i < captureDescriptor.length; i++) {\n            if (captureDescriptor[i] === 58) { // ':'\n                colon = i;\n                break;\n            }\n        }\n        if (colon === -1) {\n            // no constraint\n            this.variableName = String.fromCharCode(...captureDescriptor.slice(1, captureDescriptor.length - 1));\n            this.#constraintPattern = undefined;\n        }\n        else {\n            this.variableName = String.fromCharCode(...captureDescriptor.slice(1, colon));\n            const patternText = String.fromCharCode(...captureDescriptor.slice(colon + 1, captureDescriptor.length - 1));\n            // always set dotall to true\n            const flags = caseSensitive ? 's' : 'si';\n            this.#constraintPattern = new RegExp(patternText, flags);\n        }\n    }\n\n    matches(pathIndex: number, matchingContext: MatchingContext): boolean {\n        if (pathIndex >= matchingContext.pathLength) {\n            // no more path left to match this element\n            return false;\n        }\n        const candidateCapture = matchingContext.pathElementValue(pathIndex);\n        if (candidateCapture.length === 0) {\n            return false;\n        }\n\n        if (this.#constraintPattern !== undefined) {\n            // TODO possible optimization - only regex match if rest of pattern matches?\n            const exec = this.#constraintPattern.exec(candidateCapture);\n            if (exec === null) {\n                return false;\n            }\n            // Ensure the match covers the entire string (full match)\n            if (exec.index !== 0 || exec[0].length !== candidateCapture.length) {\n                return false;\n            }\n            if (exec.length > 1) {\n                throw new TypeError(`No capture groups allowed in the constraint regex: ${this.#constraintPattern}`)\n            }\n        }\n\n        let match = false;\n        pathIndex++;\n        if (this.noMorePattern()) {\n            if (matchingContext.determinedRemainingPath) {\n                matchingContext.remainingPathIndex = pathIndex;\n                match = true;\n            }\n            else {\n                // needs to be at least one character\n                match = (pathIndex === matchingContext.pathLength);\n            }\n        }\n        else {\n            if (this.next !== undefined) {\n                match = this.next.matches(pathIndex, matchingContext);\n            }\n        }\n\n        if (match && matchingContext.extractingVariables) {\n            matchingContext.set(\n                this.variableName,\n                candidateCapture,\n                (matchingContext.pathElements[pathIndex - 1] as PathSegment).parameters\n            );\n        }\n        return match;\n    }\n\n    get normalizedLength() {\n        return 1;\n    }\n\n    get chars(): Uint16Array {\n        const sb: string[] = [];\n        sb.push('{');\n        sb.push(this.variableName);\n        if (this.#constraintPattern !== undefined) {\n            sb.push(':');\n            sb.push(this.#constraintPattern.source);\n        }\n        sb.push('}');\n        const s = sb.join('');\n        const result = new Uint16Array(s.length);\n        for (let i = 0; i < s.length; i++) {\n            result[i] = s.charCodeAt(i);\n        }\n        return result;\n    }\n\n    get wildcardCount() {\n        return 0;\n    }\n\n    get captureCount(): number {\n        return 1;\n    }\n\n    get score(): number {\n        return PathElement.CAPTURE_VARIABLE_WEIGHT;\n    }\n\n    toString() {\n        return `CaptureVariable({${this.variableName}${this.#constraintPattern ? ':' + this.#constraintPattern.source : ''}})`;\n    }\n}\n", "import { isPathSegment } from '../../../../http/server/path.ts';\nimport { PathElement } from './path-element.ts';\nimport { MatchingContext } from '../path-pattern.ts';\n\n/*internal*/ export class SingleCharWildcardedPathElement extends PathElement {\n    readonly #text: Uint16Array;\n    readonly #len: number;\n    readonly #questionMarkCount: number;\n    readonly #caseSensitive: boolean;\n\n    constructor(pos: number, literalText: Uint16Array, questionMarkCount: number, caseSensitive: boolean, separator: number) {\n        super(pos, separator);\n        this.#len = literalText.length;\n        this.#questionMarkCount = questionMarkCount;\n        this.#caseSensitive = caseSensitive;\n        if (caseSensitive) {\n            this.#text = literalText;\n        }\n        else {\n            this.#text = new Uint16Array(literalText.length);\n            for (let i = 0; i < literalText.length; i++) {\n                this.#text[i] = String.fromCharCode(literalText[i]).toLowerCase().charCodeAt(0);\n            }\n        }\n    }\n\n    matches(pathIndex: number, matchingContext: MatchingContext): boolean {\n        if (pathIndex >= matchingContext.pathLength) {\n            // no more path left to match this element\n            return false;\n        }\n\n        const element = matchingContext.pathElements[pathIndex];\n        if (!isPathSegment(element)) {\n            return false;\n        }\n\n        const value = element.valueToMatch;\n        if (value.length !== this.#len) {\n            // not enough data to match this path element\n            return false;\n        }\n        if (this.#caseSensitive) {\n            for (let i = 0; i < this.#len; i++) {\n                const c = this.#text[i];\n                if ((c !== '?'.charCodeAt(0)) && (c !== value.charCodeAt(i))) {\n                    return false;\n                }\n            }\n        }\n        else {\n            for (let i = 0; i < this.#len; i++) {\n                const c = this.#text[i];\n                if ((c !== '?'.charCodeAt(0)) && (c !== String.fromCharCode(value.charCodeAt(i)).toLowerCase().charCodeAt(0))) {\n                    return false;\n                }\n            }\n        }\n\n        pathIndex++;\n        if (this.noMorePattern()) {\n            if (matchingContext.determinedRemainingPath) {\n                matchingContext.remainingPathIndex = pathIndex;\n                return true;\n            }\n            else {\n                return (pathIndex === matchingContext.pathLength);\n            }\n        }\n        else {\n            return (this.next !== undefined && this.next.matches(pathIndex, matchingContext));\n        }\n    }\n\n    get wildcardCount(): number {\n        return this.#questionMarkCount;\n    }\n\n    get normalizedLength() {\n        return this.#len;\n    }\n\n    get chars() {\n        return this.#text;\n    }\n\n    toString() {\n        return `SingleCharWildcarded(${String.fromCharCode(...(this.#text))})`;\n    }\n}\n", "import { PathElement } from './path-element.ts';\nimport { MatchingContext } from '../path-pattern.ts';\nimport type { PathSegment } from '../../../../../types/path';\n\n/*internal*/\nexport class RegexPathElement extends PathElement {\n\n    readonly #regex: Uint16Array;\n    readonly #caseSensitive: boolean;\n    readonly #pattern: RegExp;\n    readonly #wildcardCount;\n    readonly #variableNames: readonly string[];\n\n    constructor(pos: number, regex: Uint16Array, caseSensitive: boolean, completePattern: Uint16Array, separator: number) {\n        super(pos, separator);\n        this.#regex = regex;\n        this.#caseSensitive = caseSensitive;\n        [this.#pattern, this.#wildcardCount, this.#variableNames] = this.#buildPattern(regex, completePattern);\n    }\n\n    #buildPattern(regex: Uint16Array, _completePattern: Uint16Array): [RegExp, number, readonly string[]] {\n        const text = String.fromCharCode(...regex);\n        const variableNames: string[] = [];\n        let wildcardCount = 0;\n        const patternBuilder: string[] = [];\n\n        let pos = 0;\n        while (pos < text.length) {\n            const ch = text.charAt(pos);\n\n            if (ch === '{') {\n                // Start of a variable capture\n                const closeBrace = text.indexOf('}', pos);\n                if (closeBrace === -1) {\n                    throw new SyntaxError(`Missing closing brace in pattern: ${text}`);\n                }\n\n                const captureContent = text.substring(pos + 1, closeBrace);\n                const colonIndex = captureContent.indexOf(':');\n\n                let variableName: string;\n                let constraint: string;\n\n                if (colonIndex !== -1) {\n                    // Has constraint: {varname:constraint}\n                    variableName = captureContent.substring(0, colonIndex);\n                    constraint = captureContent.substring(colonIndex + 1);\n                } else {\n                    // No constraint: {varname} - default to match anything except separator\n                    variableName = captureContent;\n                    constraint = '[^/]*';\n                }\n\n                // Handle {*varname} syntax for capture-all\n                if (variableName.startsWith('*')) {\n                    variableName = variableName.substring(1);\n                    constraint = '.*';\n                }\n\n                variableNames.push(variableName);\n                patternBuilder.push('(', constraint, ')');\n\n                pos = closeBrace + 1;\n            } else if (ch === '*') {\n                // Wildcard - match anything except separator\n                wildcardCount++;\n                patternBuilder.push('[^/]*');\n                pos++;\n            } else if (ch === '?') {\n                // Single character wildcard\n                patternBuilder.push('.');\n                pos++;\n            } else if ('.+()[]^$|\\\\'.includes(ch)) {\n                // Escape regex special characters\n                patternBuilder.push('\\\\', ch);\n                pos++;\n            } else {\n                patternBuilder.push(ch);\n                pos++;\n            }\n        }\n\n        const patternString = patternBuilder.join('');\n        const flags = this.#caseSensitive ? 's' : 'si';\n\n        return [new RegExp(`^${patternString}$`, flags), wildcardCount, variableNames];\n    }\n\n    matches(pathIndex: number, matchingContext: MatchingContext): boolean {\n        const textToMatch = matchingContext.pathElementValue(pathIndex);\n        const match = this.#pattern.exec(textToMatch);\n        let matches = match !== null && match.index === 0 && match[0].length === textToMatch.length;\n        if (matches) {\n            if (this.noMorePattern()) {\n                if (matchingContext.determinedRemainingPath && (this.#variableNames.length === 0 || textToMatch.length !== 0)) {\n                    matchingContext.remainingPathIndex = pathIndex + 1;\n                    matches = true;\n                }\n                else {\n                    // no more pattern, is there more data?\n                    // if pattern is capturing variables there must be some actual data to bind to them\n                    matches = (pathIndex + 1 >= matchingContext.pathLength) &&\n                        (this.#variableNames.length === 0 || textToMatch.length !== 0);\n                }\n            }\n            else {\n                matches = (this.next !== undefined && this.next.matches(pathIndex + 1, matchingContext));\n            }\n        }\n\n        if (matches && matchingContext.extractingVariables) {\n            // process captures\n            if (this.#variableNames.length + 1 !== match?.length) {\n                throw new Error(`The number of capturing groups in the pattern segment\n                ${this.#pattern} does not match the number of variables it defines, which can occur if capturing groups are used in the regex itself. Use non-capturing groups (?:...) instead.`);\n            }\n            for (let i = 1; i < match.length; i++) {\n                const name = this.#variableNames[i - 1];\n                const value = match[i];\n                matchingContext.set(\n                    name,\n                    value,\n                    (i == this.#variableNames.length) ? (matchingContext.pathElements[pathIndex] as PathSegment).parameters : PathElement.NO_PARAMETERS)\n            }\n        }\n        return matches;\n    }\n\n    get variableNames(): readonly string[] {\n        return this.#variableNames;\n    }\n\n    get normalizedLength() {\n        let varsLength = 0;\n        for (const name of this.#variableNames) {\n            varsLength += name.length;\n        }\n        return (this.#regex.length - varsLength - this.#variableNames.length);\n    }\n\n    get chars(): Uint16Array {\n        return this.#regex;\n    }\n\n    get captureCount() {\n        return this.#variableNames.length;\n    }\n\n    get wildcardCount() {\n        return this.#wildcardCount;\n    }\n\n    get score() {\n        return this.captureCount * PathElement.CAPTURE_VARIABLE_WEIGHT + this.wildcardCount * PathElement.WILDCARD_WEIGHT;\n    }\n\n    toString() {\n        return `Regex(${String.fromCharCode(...(this.#regex))})`;\n    }\n\n\n}\n", "import { PathElement } from './path-element.ts';\nimport { MatchingContext } from '../path-pattern.ts';\nimport { isPathSegment } from '../../../../http/server/path.ts';\n\nexport class LiteralPathElement extends PathElement {\n    readonly #text: string;\n    readonly #len: number;\n    readonly #caseSensitive: boolean;\n\n    constructor(pos: number, literalText: Uint16Array, caseSensitive: boolean, separator: number) {\n        super(pos, separator);\n        this.#len = literalText.length;\n        this.#caseSensitive = caseSensitive;\n        this.#text = String.fromCharCode(...(literalText));\n    }\n\n    matches(pathIndex: number, matchingContext: MatchingContext): boolean {\n        if (pathIndex >= matchingContext.pathLength) {\n            // no more path to match\n            return false;\n        }\n        const pathSegment = matchingContext.pathElements[pathIndex];\n        if (!isPathSegment(pathSegment)) {\n            return false;\n        }\n        const value = pathSegment.valueToMatch;\n        if (value.length !== this.#len) {\n            // not enough data to match this path element\n            return false;\n        }\n\n        if (this.#caseSensitive) {\n            if (this.#text !== value) {\n                return false;\n            }\n        }\n        else {\n            if (this.#text.toLowerCase() !== value.toLowerCase()) {\n                return false;\n            }\n        }\n\n        pathIndex++;\n        if (this.noMorePattern()) {\n            if (matchingContext.determinedRemainingPath) {\n                matchingContext.remainingPathIndex = pathIndex;\n                return true;\n            }\n            else {\n                return (pathIndex === matchingContext.pathLength);\n            }\n        }\n        else {\n            return this.next!.matches(pathIndex, matchingContext);\n        }\n    }\n\n    get normalizedLength(): number {\n        return this.#len;\n    }\n\n    get chars(): Uint16Array {\n        const arr = new Uint16Array(this.#len);\n        for (let i = 0; i < this.#len; i++) {\n            arr[i] = this.#text.charCodeAt(i);\n        }\n        return arr;\n    }\n\n    get literal() {\n        return true;\n    }\n\n    toString(): string {\n        return `Literal(${this.#text})`;\n    }\n\n}\n", "import { PathPatternParser } from '../path-pattern-parser.ts';\nimport { PathPattern } from '../path-pattern.ts';\nimport { PathElement } from './path-element.ts';\nimport { SeparatorPathElement } from './separator-path-element.ts';\nimport { WildcardPathElement } from './wildcard-path-element.ts';\nimport { CaptureSegmentsPathElement } from './capture-segments-path-element.ts';\nimport { PatternParseError } from '../pattern-parse-error.ts';\nimport { WildcardSegmentsPathElement } from './wildcard-segments-path-element.ts';\nimport { CaptureVariablePathElement } from './capture-variable-path-element.ts';\nimport { SingleCharWildcardedPathElement } from './single-char-wildcarded-path-element.ts';\nimport { RegexPathElement } from './regex-path-element.ts';\nimport { LiteralPathElement } from './literal-path-element.ts';\n\nfunction isJavaScriptIdentifierStartChar(ch: number) {\n    return (ch === 36 || ch === 95 || // $ and _\n        (ch >= 65 && ch <= 90) || // A..Z\n        (ch >= 97 && ch <= 122)); // a..z;\n}\n\n\nfunction isJavaScriptIdentifierPartChar(ch: number) {\n    return (ch === 36 || ch === 95 || // $ and _\n        (ch >= 65 && ch <= 90) || // A..Z\n        (ch >= 97 && ch <= 122) || // a..z;\n        (ch >= 48 && ch <= 57)); // 0..9;\n}\n\n/*internal*/ export class InternalPathPatternParser {\n    readonly #parser: PathPatternParser;\n\n    // the input data for parsing\n    #pathPatternData: Uint16Array = new Uint16Array(0);\n    // the length of the input data\n    #pathPatternLength: number = 0;\n    // current parsing position\n    #pos: number = 0;\n    // how many ? characters in a particular path element\n    #singleCharWildcardCount: number = 0;\n    // is the path pattern using * characters in a particular path element\n    #wildcard: boolean = false;\n    // is the construct {*...} being used in a particular path element\n    #isCaptureSegmentsVariable: boolean = false;\n    // has the parser entered a  {...}  capture variable block in a particular path element\n    #insideVariableCapture: boolean = false;\n    // how many variable captures are occurring in a particular path element\n    #variableCaptureCount: number = 0;\n    // start of the most recent path element in a particular path element\n    #pathElementStart: number = 0;\n    // start of the most recent variable capture in a particular path element\n    #variableCaptureStart: number = 0;\n    // did we parse a WildcardSegments(**) or CaptureSegments({*foo}) PathElement already?\n    #hasMultipleSegmentsElements: boolean = false;\n    // variables captured in this path pattern\n    #capturedVariableNames?: string[];\n    // the head of the path element chain currently being built\n    #headPE?: PathElement;\n    // the most recently constructed path element in the chain\n    #currentPE?: PathElement;\n\n    constructor(parser: PathPatternParser) {\n        this.#parser = parser;\n    }\n\n    parse(pathPattern: string): PathPattern {\n        if (pathPattern === undefined || pathPattern === null) throw new TypeError(`pathPattern must be defined`);\n\n        this.#pathPatternData = new Uint16Array(pathPattern.length);\n        for (let i = 0; i < pathPattern.length; i++) {\n            this.#pathPatternData[i] = pathPattern.charCodeAt(i);\n        }\n        this.#pathPatternLength = this.#pathPatternData.length;\n        this.#headPE = undefined;\n        this.#currentPE = undefined;\n        this.#capturedVariableNames = undefined;\n        this.#pathElementStart = -1;\n        this.#pos = 0;\n        this.#resetPathElementState();\n\n        while (this.#pos < this.#pathPatternLength) {\n            const ch = this.#pathPatternData[this.#pos];\n            const separator = this.#parser.pathOptions.separator;\n            if (ch === separator) {\n                if (this.#pathElementStart !== -1) {\n                    this.#pushPathElement(this.#createPathElement());\n                }\n                this.#pushPathElement(new SeparatorPathElement(this.#pos, separator));\n            }\n            else {\n                if (this.#pathElementStart === -1) {\n                    this.#pathElementStart = this.#pos;\n                }\n                if (ch === '?'.charCodeAt(0)) {\n                    this.#singleCharWildcardCount++;\n                }\n                else if (ch === '{'.charCodeAt(0)) {\n                    if (this.#insideVariableCapture) {\n                        throw PatternParseError.create(this.#pos, this.#pathPatternData, 'ILLEGAL_NESTED_CAPTURE');\n                    }\n                    // if we enforced that adjacent captures weren't allowed,\n                    // this would do it (this would be and error: /foo/{bar}{boo}/)\n                    // } else if (this.#pos > 0 && this.#pathPatternData[this.#pos - 1] === '}'.charCodeAt(0)) {\n                    //     throw new PatternParseError(this.#pos, this.#pathPatternData, PatternMessage.CANNOT_HAVE_ADJACENT_CAPTURES);\n                    // }\n                    this.#insideVariableCapture = true;\n                    this.#variableCaptureStart = this.#pos;\n                }\n                else if (ch === '}'.charCodeAt(0)) {\n                    if (!this.#insideVariableCapture) {\n                        throw PatternParseError.create(this.#pos, this.#pathPatternData, 'MISSING_OPEN_CAPTURE');\n                    }\n                    this.#insideVariableCapture = false;\n                    this.#variableCaptureCount++;\n                }\n                else if (ch === ':'.charCodeAt(0)) {\n                    if (this.#insideVariableCapture && !this.#isCaptureSegmentsVariable) {\n                        this.#skipCaptureRegex();\n                        this.#insideVariableCapture = false;\n                        this.#variableCaptureCount++;\n                    }\n                }\n                else if (this.#isDoubleWildcard(separator)) {\n                    this.#checkValidMultipleSegmentsElements(this.#pos, this.#pos + 1);\n                    this.#pushPathElement(new WildcardSegmentsPathElement(this.#pos, separator));\n                    this.#hasMultipleSegmentsElements = true;\n                    this.#pos++;\n                }\n                else if (ch === '*'.charCodeAt(0)) {\n                    if (this.#insideVariableCapture && this.#variableCaptureStart == this.#pos - 1) {\n                        this.#isCaptureSegmentsVariable = true;\n                    }\n                    this.#wildcard = true;\n                }\n                if (this.#insideVariableCapture) {\n                    if ((this.#variableCaptureStart + 1 + (this.#isCaptureSegmentsVariable ? 1 : 0)) === this.#pos &&\n                            !isJavaScriptIdentifierStartChar(ch)) {\n                        throw PatternParseError.create(this.#pos, this.#pathPatternData, 'ILLEGAL_CHARACTER_AT_START_OF_CAPTURE_DESCRIPTOR', String.fromCharCode(ch));\n                    }\n                    else if ((this.#pos > (this.#variableCaptureStart + 1 + (this.#isCaptureSegmentsVariable ? 1 : 0)) &&\n                            !isJavaScriptIdentifierPartChar(ch) && ch !== '-'.charCodeAt(0))) {\n                        throw PatternParseError.create(this.#pos, this.#pathPatternData, 'ILLEGAL_CHARACTER_IN_CAPTURE_DESCRIPTOR', String.fromCharCode(ch));\n                    }\n                }\n            }\n            this.#pos++;\n        }\n        if (this.#pathElementStart !== -1) {\n            this.#pushPathElement(this.#createPathElement());\n        }\n        return new PathPattern(pathPattern, this.#parser, this.#headPE);\n    }\n\n    #getPathElementText(): Uint16Array {\n        const pathElementText = new Uint16Array(this.#pos - this.#pathElementStart);\n        let index = 0;\n        for (let i = this.#pathElementStart; i < this.#pos; i++) {\n            pathElementText[index++] = this.#pathPatternData[i];\n        }\n        return pathElementText;\n    }\n\n    #createPathElement(): PathElement {\n        if (this.#insideVariableCapture) {\n            throw PatternParseError.create(this.#pos, this.#pathPatternData, 'MISSING_CLOSE_CAPTURE');\n        }\n\n        let newPE: PathElement = undefined!;\n        const separator = this.#parser.pathOptions.separator;\n\n        if (this.#variableCaptureCount > 0) {\n            if (this.#variableCaptureCount === 1 && this.#pathElementStart === this.#variableCaptureStart &&\n                this.#pathPatternData[this.#pos - 1] === '}'.charCodeAt(0)) {\n                if (this.#isCaptureSegmentsVariable) {\n                    // It is {*....}\n                    this.#checkValidMultipleSegmentsElements(this.#pathElementStart, this.#pos - 1);\n                    this.#hasMultipleSegmentsElements = true;\n                    newPE = new CaptureSegmentsPathElement(this.#pathElementStart, this.#getPathElementText(), separator);\n                }\n                else {\n                    // It is a full capture of this element (possibly with constraint), for example: /foo/{abc}/\n                    try {\n                        newPE = new CaptureVariablePathElement(this.#pathElementStart, this.#getPathElementText(), this.#parser.caseSensitive, separator);\n                    }\n                    catch (err) {\n                        if (err instanceof SyntaxError) {\n                            throw PatternParseError.createWithCause(err,\n                                this.#findRegExpStart(this.#pathPatternData, this.#pathElementStart) + (err['index'] ?? 0),\n                                this.#pathPatternData, 'REGEX_PATTERN_SYNTAX_EXCEPTION');\n                        }\n                        throw err;\n                    }\n                    this.#recordCapturedVariable(this.#pathElementStart, (newPE as CaptureVariablePathElement).variableName);\n                }\n            }\n            else {\n                if (this.#isCaptureSegmentsVariable) {\n                    throw PatternParseError.create(this.#pathElementStart, this.#pathPatternData, 'CAPTURE_ALL_IS_STANDALONE_CONSTRUCT');\n                }\n                const newRegexPE = new RegexPathElement(\n                    this.#pathElementStart,\n                    this.#getPathElementText(),\n                    this.#parser.caseSensitive,\n                    this.#pathPatternData, separator\n                );\n                for (const variableName of newRegexPE.variableNames) {\n                    this.#recordCapturedVariable(this.#pathElementStart, variableName);\n                }\n                newPE = newRegexPE;\n            }\n        }\n        else {\n            if (this.#wildcard) {\n                if (this.#pos - 1 === this.#pathElementStart) {\n                    newPE = new WildcardPathElement(this.#pathElementStart, separator);\n                }\n                else {\n                    newPE = new RegexPathElement(\n                        this.#pathElementStart,\n                        this.#getPathElementText(),\n                        this.#parser.caseSensitive,\n                        this.#pathPatternData,\n                        separator\n                    );\n                }\n            }\n            else if (this.#singleCharWildcardCount !== 0) {\n                newPE = new SingleCharWildcardedPathElement(\n                    this.#pathElementStart,\n                    this.#getPathElementText(),\n                    this.#singleCharWildcardCount,\n                    this.#parser.caseSensitive,\n                    separator\n                );\n            }\n            else {\n                newPE = new LiteralPathElement(\n                    this.#pathElementStart,\n                    this.#getPathElementText(),\n                    this.#parser.caseSensitive,\n                    separator\n                );\n            }\n        }\n\n        return newPE;\n    }\n\n    #skipCaptureRegex() {\n        this.#pos++;\n        const regexStartPos = this.#pos;\n        let curlyBracketDepth = 0; // how deep in nested {...} pairs we are\n        let previousBackslash = false;\n\n        while (this.#pos < this.#pathPatternLength) {\n            const ch = this.#pathPatternData[this.#pos];\n            if (ch === '\\\\'.charCodeAt(0) && !previousBackslash) {\n                this.#pos++;\n                previousBackslash = true;\n                continue;\n            }\n            if (ch === '{'.charCodeAt(0) && !previousBackslash) {\n                curlyBracketDepth++;\n            }\n            else if (ch === '}'.charCodeAt(0) && !previousBackslash) {\n                if (curlyBracketDepth === 0) {\n                    if (regexStartPos == this.#pos) {\n                        throw PatternParseError.create(this.#pos, this.#pathPatternData, 'MISSING_REGEX_CONSTRAINT');\n                    }\n                    return;\n                }\n                curlyBracketDepth--;\n            }\n            if (ch == this.#parser.pathOptions.separator && !previousBackslash) {\n                throw PatternParseError.create(this.#pos, this.#pathPatternData, 'MISSING_CLOSE_CAPTURE');\n            }\n            this.#pos++;\n            previousBackslash = false;\n        }\n        throw PatternParseError.create(this.#pos - 1, this.#pathPatternData, 'MISSING_CLOSE_CAPTURE');\n    }\n\n    #isDoubleWildcard(separator: number): boolean {\n        // next char is present\n        if ((this.#pos + 1) >= this.#pathPatternLength) {\n            return false;\n        }\n        // current char and next char are '*'\n        if (this.#pathPatternData[this.#pos] !== '*'.charCodeAt(0) ||\n            this.#pathPatternData[this.#pos + 1] !== '*'.charCodeAt(0)) {\n            return false;\n        }\n        // previous char is separator, if any\n        if ((this.#pos - 1 >= 0) && (this.#pathPatternData[this.#pos - 1] !== separator)) {\n            return false;\n        }\n        // next char is separator, if any\n        if ((this.#pos + 2 < this.#pathPatternLength) &&\n            (this.#pathPatternData[this.#pos + 2] !== separator)) {\n            return false;\n        }\n        return true;\n    }\n\n    #checkValidMultipleSegmentsElements(startPos: number, endPos: number) {\n        if (this.#hasMultipleSegmentsElements) {\n            throw PatternParseError.create(this.#pos, this.#pathPatternData, 'CANNOT_HAVE_MANY_MULTISEGMENT_PATH_ELEMENTS');\n        }\n        if (startPos > 1 && endPos !== (this.#pathPatternLength - 1)) {\n            throw PatternParseError.create(this.#pos, this.#pathPatternData, 'INVALID_LOCATION_FOR_MULTISEGMENT_PATH_ELEMENT');\n        }\n    }\n\n    #pushPathElement(newPathElement: PathElement) {\n        if (newPathElement instanceof CaptureSegmentsPathElement ||\n            newPathElement instanceof WildcardSegmentsPathElement) {\n            // there must be a separator ahead of this thing\n            // currentPE SHOULD be a SeparatorPathElement\n            if (this.#currentPE === undefined) {\n                this.#headPE = newPathElement;\n                this.#currentPE = newPathElement;\n            }\n            else if (this.#currentPE instanceof SeparatorPathElement) {\n                const peBeforeSeparator = this.#currentPE.prev;\n                if (peBeforeSeparator === undefined) {\n                    // {*foo} is at the start\n                    this.#headPE = newPathElement;\n                    newPathElement.prev = undefined;\n                }\n                else {\n                    peBeforeSeparator.next = newPathElement;\n                    newPathElement.prev = peBeforeSeparator;\n                }\n                this.#currentPE = newPathElement;\n            }\n            else {\n                throw new Error(`expected SeparatorPathElement before ${newPathElement} but was ${this.#currentPE}`);\n            }\n        }\n        else {\n            if (this.#headPE === undefined) {\n                this.#headPE = newPathElement;\n                this.#currentPE = newPathElement;\n            }\n            else if (this.#currentPE !== undefined) {\n                this.#currentPE.next = newPathElement;\n                newPathElement.prev = this.#currentPE;\n                this.#currentPE = newPathElement;\n            }\n        }\n\n        this.#resetPathElementState();\n    }\n\n    #findRegExpStart(data: Uint16Array, offset: number): number {\n        let pos = offset;\n        while (pos < data.length) {\n            if (data[pos] === ':'.charCodeAt(0)) {\n                return pos + 1;\n            }\n            pos++;\n        }\n        return -1;\n    }\n\n    #resetPathElementState() {\n        this.#pathElementStart = -1;\n        this.#singleCharWildcardCount = 0;\n        this.#insideVariableCapture = false;\n        this.#variableCaptureCount = 0;\n        this.#wildcard = false;\n        this.#isCaptureSegmentsVariable = false;\n        this.#variableCaptureStart = -1;\n    }\n\n    #recordCapturedVariable(pos: number, variableName: string) {\n        if (this.#capturedVariableNames === undefined) {\n            this.#capturedVariableNames = [];\n        }\n        if (this.#capturedVariableNames?.find(v => v === variableName) !== undefined) {\n            throw PatternParseError.create(pos, this.#pathPatternData, 'ILLEGAL_DOUBLE_CAPTURE', variableName);\n        }\n        this.#capturedVariableNames.push(variableName);\n    }\n}\n", "import { HTTP_OPTIONS, type Options } from '../../../http/server/path.ts';\nimport type { PathPattern } from './path-pattern.ts';\n\nimport { InternalPathPatternParser } from './internal/path-pattern-parser.ts';\n\nexport class PathPatternParser {\n    #caseSensitive: boolean = true;\n    #pathOptions: Options = HTTP_OPTIONS;\n\n    get caseSensitive(): boolean {\n        return this.#caseSensitive;\n    }\n    set caseSensitive(value: boolean) {\n        this.#caseSensitive = value;\n    }\n\n    get pathOptions(): Options {\n        return this.#pathOptions;\n    }\n    set pathOptions(value: Options) {\n        this.#pathOptions = value;\n    }\n\n    public initFullPathPattern(pattern: string): string {\n        return (pattern && !pattern.startsWith('/') ? '/' + pattern : pattern);\n    }\n\n    parse(pathPattern: string): PathPattern {\n        return new InternalPathPatternParser(this).parse(pathPattern);\n    }\n\n    static readonly DEFAULT: PathPatternParser = new class extends PathPatternParser {\n        override get caseSensitive(): boolean {\n            return super.caseSensitive;\n        }\n        override set caseSensitive(_value: boolean) {\n            this.#raiseError();\n        }\n        override get pathOptions(): Options {\n            return super.pathOptions;\n        }\n        override set pathOptions(_value: Options) {\n            this.#raiseError();\n        }\n\n        #raiseError(): never {\n            throw new Error('PathPatternParser.DEFAULT is immutable');\n        }\n    };\n}\n", "import type { HttpMethod } from '../../../../../types/web/http';\nimport { isPreFlightRequest } from '../../../cors/utils.ts';\nimport type { HandlerFunction, RouterFunction, ServerRequest, ServerRequestHeaders, ServerResponse } from './types.ts';\nimport { MediaType, sortBySpecificity } from '../../../../http/media-type.ts';\nimport getLogger from '../../../../logger.ts';\nimport { PathPatternParser } from '../../../util/pattern/path-pattern-parser.ts';\nimport type { MIMEType } from 'node:util';\nimport { isCompatibleWith } from '../../../../utils/mime-type-utils.ts';\n\nexport type RequestPredicate = {\n    test(request: ServerRequest): boolean;\n    and(other: RequestPredicate): RequestPredicate;\n    or(other: RequestPredicate): RequestPredicate;\n    negate(): RequestPredicate;\n    toString(): string;\n};\n\nconst logger = getLogger('web.async.fn.router');\n\nexport const REQUEST_ATTRIBUTE          = 'io.interop.web.async.fn.router.request';\nexport const URI_VARIABLES_ATTRIBUTE    = 'io.interop.web.async.fn.router.variables';\nexport const MATCHING_PATTERN_ATTRIBUTE = 'io.interop.web.async.fn.router.pattern';\n\nfunction routerFunction<T extends ServerResponse>(route: RouterFunction<T>['route']): RouterFunction<T> {\n    const result: RouterFunction<T> = {\n        route: route,\n        and: <T2 extends ServerResponse>(other: RouterFunction<T2>) => and(result, other)\n    };\n    return result;\n}\n\nfunction and<T1 extends ServerResponse, T2 extends ServerResponse>(first: RouterFunction<T1>, second: RouterFunction<T2>): RouterFunction<T1 | T2> {\n    return routerFunction<T1 | T2>(async (request) => {\n        const handler = first.route(request);\n        if (handler !== undefined) {\n            return handler;\n        }\n        return second.route(request);\n    });\n}\n\nexport function route<T extends ServerResponse>(predicate: RequestPredicate, handlerFunction: HandlerFunction<T>): RouterFunction<T> {\n\n    return routerFunction<T>(async (request: ServerRequest) => {\n        if (predicate.test(request)) {\n            if (logger.enabledFor(`trace`)) {\n                const logPrefix = request.exchange.logPrefix;\n                logger.debug(`${logPrefix}Matched ${predicate}`);\n            }\n            return handlerFunction;\n        }\n        else {\n            return; // undefined\n        }\n    });\n}\n\nexport const predicates: {\n    all: () => RequestPredicate;\n    method: (method: HttpMethod) => RequestPredicate;\n    methods: (...methods: HttpMethod[]) => RequestPredicate;\n    path: (pattern: string) => RequestPredicate;\n    pathPredicates: (patternParser: PathPatternParser)=> ((pattern: string) => RequestPredicate);\n    headers: (predicate: (headers: ServerRequestHeaders) => boolean) => RequestPredicate;\n    accept: (...mediaTypes: MIMEType[]) => RequestPredicate;\n    GET: (pattern: string) => RequestPredicate;\n    HEAD: (pattern: string) => RequestPredicate;\n    POST: (pattern: string) => RequestPredicate;\n    PUT: (pattern: string) => RequestPredicate;\n    PATCH: (pattern: string) => RequestPredicate;\n    DELETE: (pattern: string) => RequestPredicate;\n    OPTIONS: (pattern: string) => RequestPredicate;\n    queryParam: (name: string,  valueOrPredicate: string | ((value: string) => boolean)) => RequestPredicate;\n} = function () {\n    const logger = getLogger('request.predicates');\n\n    function requestMethod(request: ServerRequest): HttpMethod {\n        if (isPreFlightRequest(request.exchange.request)) {\n            const accessControlRequestMethod = request.headers.firstHeader('Access-Control-Request-Method');\n            if (accessControlRequestMethod !== undefined) {\n                return accessControlRequestMethod.toUpperCase() as HttpMethod;\n            }\n        }\n        return request.method;\n    }\n\n    function requestPredicate(predicate: (request: ServerRequest) => boolean): RequestPredicate {\n        const result: RequestPredicate = {\n            test: predicate,\n            and: (other: RequestPredicate) => and(result, other),\n            negate: () => negate(result),\n            or: (other: RequestPredicate) => or(result, other),\n            toString: () => predicate.toString(),\n        };\n        return result;\n    }\n\n    function and(first: RequestPredicate, other: RequestPredicate): RequestPredicate {\n        return requestPredicate((request: ServerRequest) => first.test(request) && other.test(request));\n    }\n\n    function or(first: RequestPredicate, other: RequestPredicate): RequestPredicate {\n        const orRequestPredicate = requestPredicate((request: ServerRequest) => first.test(request) || other.test(request));\n        orRequestPredicate.toString = () => `(${first} || ${other})`;\n        return orRequestPredicate;\n    }\n    function negate(delegate: RequestPredicate): RequestPredicate {\n        const negateRequestPredicate = requestPredicate((request: ServerRequest) => !delegate.test(request));\n        negateRequestPredicate.toString = () => `!${delegate}`;\n        return negateRequestPredicate;\n    }\n    function method(httpMethod: HttpMethod): RequestPredicate {\n        const singleHttpMethodPredicate = (request: ServerRequest) => {\n            const method = requestMethod(request);\n            const match = httpMethod === method;\n            traceMatch('Method', httpMethod, method, match);\n            return match;\n        };\n        singleHttpMethodPredicate.toString = () => `${httpMethod}`;\n        return requestPredicate(singleHttpMethodPredicate)\n    }\n    function methods(...methods: HttpMethod[]): RequestPredicate {\n        if (!methods) {\n            throw new Error('At least one HTTP method must be provided');\n        }\n        if (methods.length === 1) {\n            return method(methods[0]);\n        }\n        const httpMethods = new Set(...methods);\n        const multipleHttpMethodsPredicate = (request: ServerRequest) => {\n            const method = requestMethod(request);\n            const match = httpMethods.has(method);\n            traceMatch('Method', `[${[...httpMethods].join(', ')}]`, method, match);\n            return match;\n        }\n        multipleHttpMethodsPredicate.toString = () => `[${methods.join(', ')}]`;\n        return requestPredicate(multipleHttpMethodsPredicate);\n    }\n    function path(pattern: string): RequestPredicate {\n        const parser = PathPatternParser.DEFAULT;\n        pattern = parser.initFullPathPattern(pattern);\n        return pathPredicates(parser)(pattern);\n    }\n\n    function pathPredicates(patternParser: PathPatternParser) {\n        return (pattern: string): RequestPredicate => {\n            const pathPattern = patternParser.parse(pattern);\n            const pathPatternPredicate = (request: ServerRequest) => {\n                const pathContainer = request.requestPath.pathWithinApplication;\n                const info = pathPattern.matchAndExtract(pathContainer);\n                traceMatch('Pattern', pathPattern.patternString, pathContainer.value, info !== undefined);\n                if (info !== undefined) {\n\n                    // todo modify attributes\n                    return true;\n                }\n                else {\n                    return false;\n                }\n            };\n            pathPatternPredicate.toString = () => pathPattern.patternString;\n            return requestPredicate(pathPatternPredicate);\n        }\n    }\n    function traceMatch(prefix: string, desired: unknown, actual: unknown, match: boolean) {\n        if (logger.enabledFor('trace')) {\n            logger.debug(`${prefix} \"${desired}\" ${match ? 'matches' : 'does not match'} against value \"${actual}\"`);\n        }\n    }\n\n    function headers(headersPredicate: (headers: ServerRequestHeaders) => boolean): RequestPredicate {\n        const result = (request: ServerRequest) => {\n            if (isPreFlightRequest(request.exchange.request)) {\n                return true;\n            }\n            else {\n                return headersPredicate(request.headers);\n            }\n        };\n        result.toString = () => headersPredicate.toString();\n        return requestPredicate(result);\n    }\n\n    function accept(...mediaTypes: MIMEType[]) {\n        if (!mediaTypes) {\n            throw new Error('mediaTypes must not be empty');\n        }\n\n        function acceptedMediaTypes(headers: ServerRequestHeaders) {\n            let acceptedMediaTypes = headers.accept();\n            if (acceptedMediaTypes.length === 0) {\n                acceptedMediaTypes = [MediaType.ALL];\n            }\n            else {\n                sortBySpecificity(acceptedMediaTypes);\n            }\n            return acceptedMediaTypes;\n        }\n\n        if (mediaTypes.length === 1) {\n            const mediaType = mediaTypes[0];\n            const singleAcceptPredicate = (headers: ServerRequestHeaders) => {\n                const accepted = acceptedMediaTypes(headers);\n                let match = false;\n                for (const acceptedMediaType of accepted) {\n                    if (isCompatibleWith(acceptedMediaType, mediaType)) {\n                        match = true;\n                        break;\n                    }\n                }\n                traceMatch('Accept', mediaType, accepted, match);\n                return match;\n            };\n            singleAcceptPredicate.toString = () => `Accept: ${mediaType}`;\n            return headers(singleAcceptPredicate);\n        }\n        else {\n            const multipleAcceptsPredicate = (headers: ServerRequestHeaders) => {\n                const accepted = acceptedMediaTypes(headers);\n                let match = false;\n                outer:\n                    for (const acceptedMediaType of accepted) {\n                        for (const mediaType of mediaTypes) {\n                            if (isCompatibleWith(acceptedMediaType, mediaType)) {\n                                match = true;\n                                break outer;\n                            }\n                        }\n                    }\n                traceMatch('Accept', mediaTypes, accepted, match);\n                return match;\n            }\n            multipleAcceptsPredicate.toString = () => `Accept: ${mediaTypes.join(', ')}`;\n            return headers(multipleAcceptsPredicate)\n        }\n    }\n\n    function queryParam(name: string, valueOrPredicate: string | ((value: string) => boolean)): RequestPredicate {\n        const value = typeof valueOrPredicate === 'string' ? valueOrPredicate : undefined;\n        const predicate = typeof valueOrPredicate === 'string' ? (v: string) => v === value : valueOrPredicate;\n        const queryParamPredicate = (request: ServerRequest) => {\n            const s = request.queryParam(name);\n            return s !== null && s !== undefined && predicate(s);\n        };\n\n        queryParamPredicate.toString = () => {\n            return `?${name} ${valueOrPredicate}`;\n        };\n        return requestPredicate(queryParamPredicate);\n    }\n\n\n    return {\n        all: () => requestPredicate((request) => true),\n        method,\n        methods,\n        path,\n        pathPredicates,\n        headers,\n        accept,\n        GET: (pattern: string) => method('GET').and(path(pattern)),\n        HEAD: (pattern: string) => method('HEAD').and(path(pattern)),\n        POST: (pattern: string) => method('POST').and(path(pattern)),\n        PUT: (pattern: string) => method('PUT').and(path(pattern)),\n        PATCH: (pattern: string) => method('PATCH').and(path(pattern)),\n        DELETE: (pattern: string) => method('DELETE').and(path(pattern)),\n        OPTIONS: (pattern: string) => method('OPTIONS').and(path(pattern)),\n        queryParam,\n    }\n}();\n", "import type { ErrorResponse } from '../../../error.ts';\nimport type {\n    BodyChunk,\n    HttpOutputMessage,\n    HttpStatusCode,\n    MutableHttpHeaders,\n    ResponseCookie\n} from '../../../../../types/web/http';\nimport type { ServerHttpResponse, ServerWebExchange } from '../../../../../types/web/server';\nimport { getContentType, MapHttpHeaders } from '../../../../http/headers.ts';\nimport { HttpStatus, httpStatusCode } from '../../../../http/status.ts';\nimport type { ServerResponse, ServerResponseContext } from './types.ts';\nimport type { BodyInserter, BodyInserterContext } from '../types.ts';\nimport { MIMEType } from 'node:util';\nimport { LOG_PREFIX_HINT } from '../../../../codec/hints.ts';\n\nexport async function from(response: ErrorResponse) {\n    return status(response.statusCode)\n        .headers(headers => {\n            for (const name of response.headers.keys()) {\n                headers.add(name, response.headers.list(name));\n            }\n        })\n        .bodyValue(response.body);\n}\n\nfunction status(status: HttpStatusCode | number): BodyBuilder {\n    status = typeof status === 'number' ? httpStatusCode(status) : status;\n    return new DefaultServerResponseBuilder(status);\n}\n\nfunction ok() {\n    return status(HttpStatus.OK);\n}\n\nfunction created(location: URL) {\n    const builder = status(HttpStatus.CREATED);\n    return builder.location(location);\n}\n\nexport default {\n    from,\n    status,\n    ok,\n    created,\n}\n\nexport interface HeadersBuilder {\n    headers(consumer: (headers: MutableHttpHeaders) => void): this;\n\n    location(location: URL): this;\n\n    build(): Promise<ServerResponse>\n\n    build(writeFunction: (exchange: ServerWebExchange, context: ServerResponseContext) => Promise<void>): Promise<ServerResponse>\n}\n\nexport interface BodyBuilder extends HeadersBuilder {\n    contentLength(length: number): this;\n    contentType(contentType: MIMEType): this;\n    bodyValue(body: unknown): Promise<ServerResponse>;\n}\n\nfunction writeWithMessageWriters(message: HttpOutputMessage<MutableHttpHeaders>,\n                                 context: BodyInserterContext,\n                                 promise: Promise<Awaited<ArrayBufferView<ArrayBuffer> | ArrayBuffer | Blob | string>>,\n                                 bodyType) {\n    const mediaType = getContentType(message.headers);\n    for (const writer of context.messageWriters) {\n        if (writer.canWrite(bodyType, mediaType)) {\n            return writer.write(promise, bodyType, message, mediaType);\n        }\n    }\n    return Promise.reject(new Error(`No HttpMessageWriter found for body type ${bodyType} and media type ${mediaType}`));\n}\n\nfunction bodyFromValue<T>(body: BodyChunk): BodyInserter<T> {\n    return async (message: HttpOutputMessage<MutableHttpHeaders>, context: BodyInserterContext) => {\n        return writeWithMessageWriters(message, context, Promise.resolve(body), typeof body);\n    }\n}\n\nclass DefaultServerResponseBuilder implements BodyBuilder {\n    readonly #statusCode: HttpStatusCode;\n    readonly #headers: MutableHttpHeaders = new MapHttpHeaders();\n    readonly #cookies: Map<string, ResponseCookie[]> = new Map();\n    readonly #hints: Map<string, unknown> = new Map();\n\n    constructor(statusCode: HttpStatusCode) {\n        this.#statusCode = statusCode;\n    }\n\n    header(headerName: string, ...headerValues: string[]): this {\n        for (const headerValue of headerValues) {\n            this.#headers.add(headerName, headerValue);\n        }\n        return this;\n    }\n\n    cookie(cookie: ResponseCookie): this {\n        const cookies = this.#cookies.get(cookie.name) ?? [];\n        cookies.push(cookie);\n        this.#cookies.set(cookie.name, cookies);\n        return this;\n    }\n\n    headers(consumer: (headers: MutableHttpHeaders) => void): this {\n        consumer(this.#headers);\n        return this;\n    }\n\n    contentType(contentType: MIMEType): this {\n        this.#headers.set('Content-Type', contentType.toString());\n        return this;\n    }\n\n    contentLength(length: number): this {\n        this.#headers.set('Content-Length', length.toString());\n        return this;\n    }\n\n    location(location: URL | undefined): this {\n        this.#headers.set('Location', location?.href);\n        return this;\n    }\n\n    bodyValue(body: BodyChunk): Promise<ServerResponse> {\n        return this.#initEntityResponse(body, bodyFromValue(body));\n    }\n\n    #initEntityResponse<T>(entity: T, inserter: BodyInserter<T>): Promise<ServerResponse> {\n        return Promise.resolve(new DefaultEntityResponse<T>(this.#statusCode, this.#headers, new Map(this.#cookies), entity, inserter, new Map(this.#hints)));\n    }\n\n    build(writeFunction?: (exchange: ServerWebExchange, context: ServerResponseContext) => Promise<void>): Promise<ServerResponse> {\n        if (writeFunction) {\n            return Promise.resolve(new WriterFunctionServerResponse(this.#statusCode, this.#headers, this.#cookies, writeFunction));\n        }\n        else {\n            return this.build(async (exchange, context) => {\n                await exchange.response.end();\n            });\n        }\n    }\n\n}\n\nexport abstract class AbstractServerResponse implements ServerResponse {\n    readonly #statusCode: HttpStatusCode\n    readonly #headers: MutableHttpHeaders\n    readonly #cookies: Map<string, ResponseCookie[]>;\n\n    /* internal */ readonly hints?: Map<string, unknown>;\n\n    protected constructor(\n        statusCode: HttpStatusCode,\n        headers: MutableHttpHeaders,\n        cookies: Map<string, ResponseCookie[]>,\n        hints?: Map<string, unknown>\n    ) {\n        this.#statusCode = statusCode;\n        this.#headers = headers;\n        this.#cookies = cookies;\n        this.hints = hints;\n    }\n\n    get statusCode() {\n        return this.#statusCode;\n    }\n\n    get headers() {\n        return this.#headers;\n    }\n\n    get cookies(): ResponseCookie[] {\n        const allCookies: ResponseCookie[] = [];\n        for (const cookieList of this.#cookies.values()) {\n            allCookies.push(...cookieList);\n        }\n        return allCookies;\n    }\n\n    async writeTo(exchange: ServerWebExchange, context: ServerResponseContext): Promise<void> {\n        this.#writeStatusAndHeaders(exchange.response);\n\n        // todo check not modified\n\n        return this.writeInternal(exchange, context);\n    }\n\n    #writeStatusAndHeaders(response: ServerHttpResponse) {\n        response.setStatusCode(this.#statusCode);\n        for (const name of this.#headers.keys()) {\n            response.headers.add(name, this.#headers.list(name));\n        }\n        for (const cookieList of this.#cookies.values()) {\n            for (const cookie of cookieList) {\n                response.addCookie(cookie);\n            }\n        }\n    }\n\n    protected abstract writeInternal(exchange: ServerWebExchange, context: unknown): Promise<void>;\n}\n\nconst NO_HINTS = new Map<string, unknown>();\nclass WriterFunctionServerResponse extends AbstractServerResponse {\n    readonly #writeFunction: (exchange: ServerWebExchange, context: ServerResponseContext) => Promise<void>;\n\n    constructor(\n        statusCode: HttpStatusCode,\n        headers: MutableHttpHeaders,\n        cookies: Map<string, ResponseCookie[]>,\n        writeFunction: (exchange: ServerWebExchange, context: ServerResponseContext) => Promise<void>\n    ) {\n        super(statusCode, headers, cookies);\n        this.#writeFunction = writeFunction;\n    }\n\n    protected async writeInternal(exchange: ServerWebExchange, context: ServerResponseContext): Promise<void> {\n        await this.#writeFunction(exchange, context);\n    }\n}\n\ninterface EntityResponse<T> extends ServerResponse {\n    readonly entity: T;\n\n    readonly inserter: BodyInserter<T>;\n\n    readonly hints?: ReadonlyMap<string, unknown>;\n}\n\nclass DefaultEntityResponse<T> extends AbstractServerResponse implements EntityResponse<T> {\n    readonly #entity: T;\n    readonly #inserter: BodyInserter<T>;\n\n    constructor(\n        statusCode: HttpStatusCode,\n        headers: MutableHttpHeaders,\n        cookies: Map<string, ResponseCookie[]>,\n        entity: T, inserter: BodyInserter<T>,\n        hints: Map<string, unknown>) {\n        super(statusCode, headers, cookies, hints);\n        this.#entity = entity;\n        this.#inserter = inserter;\n    }\n\n    get entity(): T {\n        return this.#entity;\n    }\n\n    get inserter(): BodyInserter<T> {\n        return this.#inserter;\n    }\n\n    protected async writeInternal(exchange: ServerWebExchange, { messageWriters }: ServerResponseContext): Promise<void> {\n\n        this.hints?.set(LOG_PREFIX_HINT, exchange.logPrefix);\n        await this.inserter(\n            exchange.response,\n            {\n                messageWriters,\n                serverRequest: exchange.request,\n                hints: this.hints\n            });\n    }\n}\n", "import type { WebErrorHandler } from '../web/server/types.ts';\nimport type { ServerWebExchange } from '../../types/web/server';\nimport { HttpServerRequest, HttpServerResponse } from './exchange.ts';\nimport { isClientDisconnectedError } from '../web/util/client.ts';\nimport serverRequest from '../web/async/fn/server/request.ts';\nimport { route } from '../web/async/fn/server/router.ts';\nimport serverResponse from '../web/async/fn/server/response.ts';\nimport { MIMEType } from 'node:util';\nimport { HttpStatus } from '../http/status.ts';\nimport type { RouterFunction, ServerRequest, ServerResponse } from '../web/async/fn/server/types.ts';\nimport { predicates as r} from '../web/async/fn/server/router.ts';\nimport { ResponseStatusError } from '../web/server/error.ts';\nimport type { HttpMessageReader, HttpMessageWriter } from '../http/codec/types.ts';\nimport { ALL } from '../utils/mime-type-utils.ts';\n\nexport type ErrorAttributeKey = 'error' | 'trace' | 'message' | 'errors' | 'timestamp' | 'status' | 'reason' | 'requestId' | 'path';\n\nexport type ErrorAttributeOptions = {\n    readonly includes: ReadonlyArray<ErrorAttributeKey>;\n}\n\nexport interface ErrorAttributes {\n    getErrorAttributes(request: ServerRequest, options: ErrorAttributeOptions): Partial<Record<ErrorAttributeKey, unknown>>;\n\n    getError(request: ServerRequest): Error;\n\n    storeErrorInformation(error: Error, exchange: ServerWebExchange): void;\n}\n\nexport class DefaultErrorAttributes implements ErrorAttributes {\n    static readonly ERROR_ATTRIBUTE = 'io.interop.web.server.exchange.error';\n\n    getErrorAttributes(request: ServerRequest, options: ErrorAttributeOptions): Partial<Record<ErrorAttributeKey, unknown>> {\n        const erroroAttributes = this.#getErrorAttributesInternal(request, options.includes.includes('trace'));\n        return erroroAttributes;\n    }\n\n    getError(request: ServerRequest): Error {\n        const error = request.attributes.get(DefaultErrorAttributes.ERROR_ATTRIBUTE);\n        if (error === undefined) {\n            throw new Error('No error found in request attributes');\n        }\n        return error as Error;\n    }\n\n    storeErrorInformation(error: Error, exchange: ServerWebExchange): void {\n        exchange.attributes.set(DefaultErrorAttributes.ERROR_ATTRIBUTE, error);\n    }\n\n    #getErrorAttributesInternal(request: ServerRequest, includeStackTrace: boolean) {\n        const errorAttributes: Partial<Record<ErrorAttributeKey, unknown>> = {};\n        errorAttributes.timestamp = new Date();\n        const error = this.getError(request);\n        const errorStatus = this.#determineHttpStatus(error);\n        errorAttributes.status = errorStatus.value;\n        errorAttributes.reason = errorStatus.phrase;\n        errorAttributes.requestId = request.exchange.request.id;\n\n        this.#handleError(errorAttributes, error, includeStackTrace);\n        return errorAttributes;\n\n    }\n\n    #determineHttpStatus(error: Error): HttpStatus {\n        if (error instanceof ResponseStatusError) {\n            const httpStatus = HttpStatus.resolve(error.statusCode.value);\n            if (httpStatus) {\n                return httpStatus;\n            }\n        }\n        return HttpStatus.INTERNAL_SERVER_ERROR;\n    }\n\n    #handleError(errorAttributes: Partial<Record<ErrorAttributeKey, unknown>>, error: Error, includeStackTrace: boolean) {\n\n        if (error instanceof ResponseStatusError) {\n            errorAttributes.message = error.reason;\n        }\n    }\n}\n\nexport abstract class AbstractWebErrorHandler implements WebErrorHandler {\n\n    readonly #errorAttributes: ErrorAttributes;\n    readonly #messageReaders: readonly HttpMessageReader[];\n    readonly #messageWriters: readonly HttpMessageWriter[];\n\n    protected constructor(messageReaders: readonly HttpMessageReader[],\n                          messageWriters: readonly HttpMessageWriter[],\n                          errorAttributes: ErrorAttributes) {\n        if (!messageWriters) {\n            throw new Error('messageWriters must not be null.');\n        }\n        this.#errorAttributes = errorAttributes;\n        this.#messageReaders = messageReaders;\n        this.#messageWriters = messageWriters;\n    }\n\n    getErrorAttributes(request: ServerRequest, options: ErrorAttributeOptions) {\n        return this.#errorAttributes.getErrorAttributes(request, options);\n    }\n\n    async handle(exchange: ServerWebExchange<HttpServerRequest, HttpServerResponse>, error: Error): Promise<void> {\n        if (exchange.response.commited || this.#isDisconnectedClientError(error)) {\n            return Promise.reject(error);\n        }\n        this.#errorAttributes.storeErrorInformation(error, exchange);\n        const request = serverRequest.create(exchange, this.#messageReaders);\n        const handler = await this.getRoutingFunction(this.#errorAttributes)?.route(request);\n        if (handler) {\n            const response = await handler(request);\n            this.logError(request, response, error);\n            await this.#write(exchange, response);\n        }\n        else {\n            throw error;\n        }\n    }\n\n    protected abstract getRoutingFunction(errorAttributes: ErrorAttributes): RouterFunction<ServerResponse>;\n\n\n    protected logError(request: ServerRequest, response: ServerResponse, error: Error) {\n\n    }\n\n    #isDisconnectedClientError(error: Error) {\n        return isClientDisconnectedError(error);\n    }\n\n    async #write(exchange: ServerWebExchange<HttpServerRequest, HttpServerResponse>, response: ServerResponse) {\n        exchange.response.headers.set('Content-Type', response.headers.get('Content-Type'));\n        const responseContext = {\n            messageWriters: this.#messageWriters\n        };\n        return response.writeTo(exchange, responseContext);\n    }\n}\n\nexport type ErrorProperties = {}\n\nexport class DefaultWebErrorHandler extends AbstractWebErrorHandler {\n    static readonly #defaultErrorAttributes: DefaultErrorAttributes = new DefaultErrorAttributes();\n    static readonly #ONLY_STATUS: ErrorAttributeOptions = { includes: ['status'] };\n\n    constructor(readers: ReadonlyArray<HttpMessageReader>,\n                writers: ReadonlyArray<HttpMessageWriter>,\n                errorAttributes: ErrorAttributes,\n                errorProperties: ErrorProperties = {}) {\n        super(readers, writers, errorAttributes);\n    }\n\n    protected getRoutingFunction(errorAttributes: ErrorAttributes): RouterFunction<ServerResponse> {\n        return route(r.all(), (request) => {\n            return this.#renderErrorResponse(request);\n        });\n    }\n\n    #getErrorAttributes(request: ServerRequest, mimeType: MIMEType) {\n        return super.getErrorAttributes(request, this.getErrorAttributeOptions(request, mimeType));\n    }\n\n    protected getErrorAttributeOptions(request: ServerRequest, mimeType: MIMEType): ErrorAttributeOptions {\n        return {\n            includes: ['error', 'message', 'status', 'path']\n        };\n    }\n\n    async #renderErrorResponse(request: ServerRequest): Promise<ServerResponse> {\n        const errorAttributes = this.#getErrorAttributes(request, ALL);\n        const status = this.#getHttpStatus(request, errorAttributes);\n        return serverResponse.status(status).contentType(new MIMEType('application/json')).bodyValue(JSON.stringify(errorAttributes));\n    }\n\n    #getHttpStatus(request: ServerRequest, errorAttributes: Partial<Record<ErrorAttributeKey, unknown>>): number {\n        return this.getHttpStatus(errorAttributes.status !== undefined ? errorAttributes\n            : DefaultWebErrorHandler.#defaultErrorAttributes.getErrorAttributes(request, DefaultWebErrorHandler.#ONLY_STATUS));\n    }\n\n    protected getHttpStatus(errorAttributes: Partial<Record<ErrorAttributeKey, unknown>>): number {\n        const status = errorAttributes.status;\n        if (typeof status === 'number') {\n            return status;\n        }\n        throw new Error(`Invalid status code: ${status}`);\n    }\n}\n", "import type { HttpHeaders, HttpStatusCode, ReadonlyHttpHeaders } from '../../types/web/http';\nimport { MapHttpHeaders } from '../http/headers.ts';\n\n/**\n * RFC 9457 - Problem Details for HTTP APIs\n */\nexport type ProblemDetail = {\n    title?: string;\n    status: number;\n    detail?: string;\n    [key: string]: unknown;\n}\n\nexport type ErrorResponse = {\n    readonly statusCode: HttpStatusCode;\n    readonly headers: HttpHeaders;\n    readonly body: ProblemDetail;\n}\n\nexport class ErrorResponseError extends Error implements ErrorResponse {\n    readonly #status: HttpStatusCode;\n    readonly #headers: ReadonlyHttpHeaders = new MapHttpHeaders();\n    readonly body: ProblemDetail;\n\n    constructor(status: HttpStatusCode, body?: ProblemDetail) {\n        super();\n        this.#status = status;\n        this.body = body ?? ErrorResponseError.problemDetailFor(status);\n    }\n\n    get statusCode() {\n        return this.#status\n    }\n\n    set detail(detail: string | undefined) {\n        this.body.detail = detail;\n    }\n\n    get headers() {\n        return this.#headers;\n    }\n\n    static problemDetailFor(status: HttpStatusCode, detail?: string): ProblemDetail {\n        const problem: ProblemDetail = {\n            status: status.value\n        };\n        if (detail !== undefined) {\n            problem.detail = detail;\n        }\n        return problem;\n    }\n}\n", "import { ErrorResponseError } from '../error.ts';\nimport type { HttpStatusCode } from '../../../types/web/http';\nimport { EMPTY_HTTP_HEADERS } from '../../http/headers.ts';\n\nexport class ResponseStatusError extends ErrorResponseError {\n    readonly #reason?: string;\n\n    constructor(status: HttpStatusCode, reason?: string) {\n        super(status, ResponseStatusError.problemDetailFor(status, reason));\n        this.#reason = reason;\n    }\n\n    get reason() {\n        return this.#reason;\n    }\n\n    get headers() {\n        return EMPTY_HTTP_HEADERS;\n    }\n}\n", "import type { ServerWebExchange } from '../../../types/web/server';\nimport type { WebHandler } from '../server/types.ts';\nimport type { CorsConfigSource, PreFlightRequestHandler } from '../cors/types.ts';\nimport { isPreFlightRequest } from '../cors/utils.ts';\nimport { HttpStatus } from '../../http/status.ts';\nimport type { HandlerAdapter, HandlerMapping, HandlerResult, HandlerResultHandler } from './types.ts';\nimport getLogger from '../../logger.ts';\nimport { ResponseStatusError } from '../server/error.ts';\n\nexport const BEST_MATCHING_HANDLER_ATTRIBUTE = 'io.interop.web.async.handler.handler';\nexport const BEST_MATCHING_PATTERN_ATTRIBUTE = 'io.interop.web.async.handler.pattern';\nexport const URI_VARIABLES_ATTRIBUTE         = 'io.interop.web.async.handler.variables';\n\nexport class DispatcherHandler implements WebHandler, PreFlightRequestHandler {\n    #handlerMappings?: Array<HandlerMapping>;\n    #handlerAdapters?: Array<HandlerAdapter>;\n    #resultHandlers?: Array<HandlerResultHandler>;\n\n    constructor(handlerMappings?: Array<HandlerMapping>,\n                handlerAdapters?: Array<HandlerAdapter>,\n                resultHandlers?: Array<HandlerResultHandler>) {\n        this.#handlerMappings = handlerMappings;\n        this.#handlerAdapters = handlerAdapters;\n        this.#resultHandlers = resultHandlers;\n    }\n    async handle(exchange: ServerWebExchange): Promise<void> {\n        if (!this.#handlerMappings) {\n            return this.#createNotFoundError();\n        }\n        if (isPreFlightRequest(exchange.request)) {\n            return this.handlePreFlight(exchange);\n        }\n        let handler: unknown;\n        try {\n            for (const mapping of this.#handlerMappings) {\n                handler = await mapping.getHandler(exchange);\n                if (handler !== undefined) {\n                    break;\n                }\n            }\n            if (handler === undefined) {\n                await this.#createNotFoundError();\n            }\n        }\n        catch (e) {\n            return this.#handleResultPromise(exchange, Promise.reject(e));\n        }\n        return this.#handleRequestWith(exchange, handler);\n    }\n\n    async #handleResultPromise(exchange: ServerWebExchange, resultPromise: Promise<HandlerResult>): Promise<void> {\n        if (this.#handlerAdapters) {\n            // dispatch exception handler\n        }\n        const result = await resultPromise;\n        try {\n            await this.#handleResult(exchange, result, `Handler ${result.handler}`);\n        }\n        catch (e) {\n            const exceptionHandler = result.exceptionHandler;\n            if (exceptionHandler) {\n                const error = e instanceof Error ? e : new Error(String(e));\n                const result2 = await exceptionHandler(exchange, error);\n                await this.#handleResult(exchange, result2, `Exception handler ${result2.handler}, error=\"${error.message}\"`);\n            }\n        }\n    }\n\n    #handleResult(exchange: ServerWebExchange, result: HandlerResult, details: string): Promise<void> {\n        if (this.#resultHandlers) {\n            for (const handler of this.#resultHandlers) {\n                if (handler.supports(result)) {\n                    details += ' [DispatcherHandler]';\n                    return handler.handle(exchange, result);\n                }\n            }\n        }\n        return Promise.reject(new Error(`No HandlerResultHandler for ${result.returnValue}`));\n    }\n\n    #handleRequestWith(exchange: ServerWebExchange, handler: unknown): Promise<void> {\n        if (exchange.response.statusCode?.value === HttpStatus.FORBIDDEN.value) {\n            return Promise.resolve(); // Pre-flight request was denied\n        }\n        if (this.#handlerAdapters) {\n            for (const adapter of this.#handlerAdapters) {\n                if (adapter.supports(handler)) {\n                    const resultPromise = adapter.handle(exchange, handler);\n                    return this.#handleResultPromise(exchange, resultPromise);\n                }\n            }\n        }\n        return Promise.reject(new Error(`No HandlerAdapter for handler ${handler}`));\n    }\n\n\n    #createNotFoundError<R>(): Promise<R> {\n        return Promise.reject(new ResponseStatusError(HttpStatus.NOT_FOUND));\n    }\n\n    async handlePreFlight(exchange: ServerWebExchange): Promise<void> {\n        let handler: unknown;\n        for (const mapping of this.#handlerMappings ?? []) {\n            handler = await mapping.getHandler(exchange);\n            if (handler !== undefined) {\n                break;\n            }\n        }\n        // If no handler found, return 403 Forbidden\n        if (handler === undefined) {\n            exchange.response.setStatusCode(HttpStatus.FORBIDDEN);\n            return;\n        }\n    }\n}\n\n\nexport abstract class AbstractHandlerMapping implements HandlerMapping {\n    protected logger = getLogger('web.async.handler');\n    #corsConfigSource?: CorsConfigSource;\n\n    set corsConfigSource(source: CorsConfigSource) {\n        if (source === undefined) {\n            throw new Error('CorsConfigSource must not be undefined');\n        }\n        this.#corsConfigSource = source;\n    }\n\n    async getHandler(exchange: ServerWebExchange): Promise<unknown | undefined> {\n        const handler = await this.getHandlerInternal(exchange);\n        if (handler !== undefined) {\n            if (this.logger.enabledFor('debug')) {\n                this.logger.debug(`${exchange.logPrefix}Mapped to ${handler}`);\n            }\n            const request = exchange.request;\n            if (this.hasCorsConfigSource(handler) || isPreFlightRequest(request)) {\n                const config = this.#corsConfigSource !== undefined ? await this.#corsConfigSource(exchange) : undefined;\n                const handlerConfig = this.getCorsConfig(handler, exchange);\n                // Merge configs if both exist\n            }\n            return handler;\n        }\n    }\n\n    protected abstract getHandlerInternal(exchange: ServerWebExchange): Promise<unknown | undefined>;\n\n    protected hasCorsConfigSource(handler: unknown): boolean {\n        return this.#corsConfigSource !== undefined;\n    }\n\n    protected getCorsConfig(handler: unknown, exchange: ServerWebExchange) {\n        return undefined;\n    }\n}\n", "import type { HandlerAdapter, HandlerResult, HandlerResultHandler } from '../../types.ts';\nimport type { ServerWebExchange } from '../../../../../types/web/server';\nimport { AbstractServerResponse } from './response.ts';\nimport type { HandlerFunction, RouterFunction, ServerRequest } from './types.ts';\nimport * as handler from '../../handler.ts';\nimport serverRequest from './request.ts';\nimport { MATCHING_PATTERN_ATTRIBUTE, REQUEST_ATTRIBUTE, URI_VARIABLES_ATTRIBUTE } from './router.ts';\nimport { PathPattern } from '../../../util/pattern/path-pattern.ts';\nimport type { HttpMessageReader, HttpMessageWriter } from '../../../../http/codec/types.ts';\nimport codecConfig from '../../../../http/codec/config.ts';\n\nexport class HandlerFunctionAdapter implements HandlerAdapter {\n    supports(handler: unknown): boolean {\n        return typeof handler === 'function';\n    }\n    async handle(exchange: ServerWebExchange, handler: unknown): Promise<HandlerResult> {\n        const handlerFunction = handler as HandlerFunction;\n        const request = exchange.attribute<ServerRequest>(REQUEST_ATTRIBUTE);\n        if (!request) {\n            throw new Error('ServerRequest is not found in exchange attributes.');\n        }\n        return handlerFunction(request).then(response => ({\n            handler, returnValue: response\n        }));\n\n    }\n}\n\nexport class ServerResponseResultHandler implements HandlerResultHandler {\n    readonly #messageWriters: readonly HttpMessageWriter[] = Array<HttpMessageWriter>();\n    constructor(messageWriters: readonly HttpMessageWriter[]) {\n        if (!messageWriters || messageWriters.length === 0) {\n            throw new Error('messageWriters must not be empty.');\n        }\n        this.#messageWriters = messageWriters;\n    }\n\n    supports(result: HandlerResult): boolean {\n        return result.returnValue instanceof AbstractServerResponse;\n    }\n\n    get messageWriters(): readonly HttpMessageWriter[] {\n        return this.#messageWriters;\n    }\n    async handle(exchange: ServerWebExchange, result: HandlerResult): Promise<void> {\n        const response = result.returnValue as AbstractServerResponse;\n        if (response === undefined) {\n            throw new Error('No ServerResponse');\n        }\n        return response.writeTo(exchange, {\n            messageWriters: this.messageWriters\n        });\n    }\n}\n\nexport class RouterFunctionMapping extends handler.AbstractHandlerMapping {\n    #routerFunction?: RouterFunction;\n    #messageReaders: readonly HttpMessageReader[] = undefined!;\n    constructor(routerFunction?: RouterFunction) {\n        super();\n        this.#routerFunction = routerFunction;\n    }\n\n    set messageReaders(messageReaders: readonly HttpMessageReader[]) {\n        this.#messageReaders = messageReaders;\n    }\n\n    public init(...routerFunctions: Array<RouterFunction>): void {\n        if (this.#messageReaders === undefined || this.#messageReaders.length === 0) {\n            this.#messageReaders = codecConfig.serverConfigurer.create().readers;\n        }\n        if (this.#routerFunction) {\n            throw new Error('RouterFunctionMapping is already initialized with a RouterFunction');\n        }\n        this.#routerFunction = routerFunctions.reduce((a, b) => a.and(b));\n\n    }\n\n    protected async getHandlerInternal(exchange: ServerWebExchange): Promise<unknown | undefined> {\n        if (this.#routerFunction === undefined) {\n            return; // undefined\n        }\n        const request = serverRequest.create(exchange, this.#messageReaders);\n        const handlerFunction = await this.#routerFunction.route(request)\n        if (handlerFunction !== undefined) {\n            this.#setAttributes(exchange.attributes, request, handlerFunction);\n        }\n        return handlerFunction;\n    }\n\n    #setAttributes(attributes: Map<string, unknown>, request: unknown, handlerFunction: HandlerFunction): void {\n        attributes.set(REQUEST_ATTRIBUTE, request);\n        attributes.set(handler.BEST_MATCHING_HANDLER_ATTRIBUTE, handlerFunction);\n\n        const pattern = attributes.get(MATCHING_PATTERN_ATTRIBUTE) as PathPattern;\n        if (pattern) {\n            attributes.set(handler.BEST_MATCHING_PATTERN_ATTRIBUTE, pattern);\n        }\n        const uriVariables = attributes.get(URI_VARIABLES_ATTRIBUTE);\n        if (uriVariables !== undefined) {\n            attributes.set(URI_VARIABLES_ATTRIBUTE, uriVariables);\n        }\n    }\n}\n"],
  "mappings": "+kBAAA,IAAAA,GAAA,GAAAC,GAAAD,GAAA,mBAAAE,GAAA,YAAAC,KAAA,eAAAC,GAAAJ,ICAA,IAAAK,GAAA,GAAAC,GAAAD,GAAA,aAAAE,GAAA,YAAAC,KAAA,IAAAC,GAAiB,2BACjBC,GAAkB,4BAElBC,GAAkC,4BCFlC,IAAAC,GAA6D,mBAEvDC,GAAqB,8CAC3B,SAASC,GAAUC,EAAc,CAC7B,GAAIA,EAAO,MAAQ,MAAM,IAAI,MAAM,YAAYA,CAAI,EAAE,EACrD,OAAOA,CACX,CAOO,SAAUC,GAAUD,EAA0C,CACjE,GAAI,OAAOA,GAAS,SAChB,QAAWC,KAAaD,EAAK,MAAM,GAAG,EAAG,CACrC,IAAME,EAAUD,EAAU,KAAK,EACzBE,EAAcL,GAAmB,KAAKI,CAAO,EACnD,GAAIC,EAAa,CACb,IAAMC,EAAQ,SAASD,EAAY,CAAC,CAAC,EAC/BE,EAAM,SAASF,EAAY,CAAC,GAAKA,EAAY,CAAC,CAAC,EACrD,QAASG,EAAIP,GAAUK,CAAK,EAAGE,EAAIP,GAAUM,CAAG,EAAI,EAAGC,IACnD,MAAMA,CAEd,KAEI,OAAM,IAAI,MAAM,IAAIL,CAAS,iCAAiC,CAEtE,MAEA,MAAMF,GAAUC,CAAI,CAE5B,CAEO,IAAMO,IAAW,IAAM,CAC1B,SAASC,EAASC,EAAuB,CACrC,OAAOA,EAAE,OAAS,EAAIA,EAAE,CAAC,EAAI,MACjC,CACA,IAAMC,EAAY,OAAO,UAAO,sBAA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AwB,CAC1B,QAASrC,EAAQ,WAAW,OAC5B,KAAM,UAAa,CACf,IAAK,QAAQ,IACb,KAAM,iBACN,GAAIQ,EAAe,KAAK,CAC5B,GACA,OAAQnE,EAAO,MAAM,YAAY,EACjC,SAAU2D,EAAQ,WAAW,UAAW,SAAY,QAAU,SAAY,CAClE3D,EAAO,WAAW,MAAM,GACxBA,EAAO,KAAK,4BAA4B,EAE5C,MAAM2F,EAAW,MAAM,CAC3B,EAAI,MACR,CAAC,EACLL,EAAa,KAAK,SAAY,CAC1B,MAAMnE,GAAWsE,GAAO,CACpBM,EAAiB,MAAMN,CAAE,CAC7B,CAAC,CACL,CAAC,CACL,CAEA,OAAOE,CACX,ED/WA,IAAOM,GAAsBC",
  "names": ["index_exports", "__export", "server_exports", "index_default", "__toCommonJS", "server_exports", "__export", "Factory", "VERSION", "import_node_http", "import_node_https", "import_node_async_hooks", "import_node_os", "PORT_RANGE_MATCHER", "validPort", "port", "portRange", "trimmed", "matchResult", "start", "end", "i", "localIp", "first", "a", "addresses", "details", "info", "acc", "addressAndPort", "address", "GatewayLogging", "getLogger", "name", "regexAwareReplacer", "_key", "value", "import_gateway", "import_node_async_hooks", "log", "getLogger", "codec", "principalName", "authentication", "name", "principal", "initClient", "gateway", "socket", "authenticationPromise", "remoteAddress", "key", "addressAndPort", "host", "opts", "err", "reason", "data", "create", "environment", "handshake", "logPrefix", "principalPromise", "user", "gw", "client", "contextFn", "_isBinary", "code", "core_default", "import_gateway", "import_gateway", "processVisibilityRules", "rules", "rule", "result", "key", "value", "processMetricFilters", "filters", "publisher", "originalMetrics", "originalIdentity", "rest", "processedPublisher", "allow", "m", "block", "processPublisherConfig", "publisherConfig", "processMeshConfig", "meshConfig", "processMetricsConfig", "config", "c", "processGatewayConfig", "log", "getLogger", "generateRandomGatewayId", "GatewayManager", "#defaultGatewayId", "#defaultGateway", "#managedGateways", "#principalToGatewayId", "#config", "#started", "#environment", "config", "processGatewayConfig", "environment", "principal", "gatewayId", "gateway", "#createPrincipalGateway", "allGateways", "gId", "id", "handler", "opts", "compose", "middleware", "fns", "fn", "ctx", "next", "dispatch", "dispatchedCtx", "nextCalled", "nextResolved", "result", "nextCtx", "import_node_net", "import_tough_cookie", "parseHost", "headers", "defaultHost", "host", "port", "isForwardedSsl", "v", "parseProtocol", "defaultProtocol", "proto", "parseRemoteAddress", "url", "remoteAddress", "AbstractHttpMessage", "#headers", "AbstractHttpRequest", "_AbstractHttpRequest", "#id", "parseCookies", "AbstractHttpResponse", "parseResponseCookies", "responseCookie", "s", "cs", "tc", "cookie", "parsed", "result", "import_node_util", "import_node_util", "WILDCARD_TYPE", "ALL", "APPLICATION_OCTET_STREAM_VALUE", "APPLICATION_OCTET_STREAM", "isWildcardType", "mimeType", "isWildcardSubtype", "isConcrete", "InvalidMimeTypeError", "message", "options", "createMimeType", "type", "subtype", "charset", "input", "result", "error", "getSubtypeSuffix", "suffixIndex", "isCompatibleWith", "a", "b", "aSuffix", "bSuffix", "mimeTypes", "MediaType", "_MediaType", "APPLICATION_OCTET_STREAM_VALUE", "#PARAM_QUALITY_FACTOR", "input", "#checkToken", "key", "value", "isQuoted", "unquotedValue", "unquote", "q", "InvalidMediaTypeError", "token", "i", "c", "qualityFactor", "mediaTypes", "type", "mediaType", "mimeType", "message", "fileExtensionToMediaTypes", "map", "line", "trimmed", "parts", "extensions", "ext", "existing", "isQuoted", "s", "unquote", "isMoreSpecific", "a", "b", "MediaType", "aQuality", "bQuality", "aWildcard", "isWildcardType", "bWildcard", "aWildcardSubtype", "isWildcardSubtype", "bWildcardSubtype", "aParamsSize", "bParamsSize", "isLessSpecific", "bubbleSort", "list", "swap", "n", "i", "j", "prev", "curr", "sortBySpecificity", "mimeTypes", "InvalidMimeTypeError", "parseHeader", "value", "list", "start", "end", "i", "toList", "values", "AbstractHttpHeaders", "name", "MapHttpHeaders", "prev", "EMPTY_HTTP_HEADERS", "getContentType", "headers", "MediaType", "DefaultHttpStatusCode", "#value", "value", "HttpStatus", "_HttpStatus", "#VALUES", "key", "code", "status", "#phrase", "phrase", "httpStatusCode", "import_node_http", "subPath", "container", "start", "end", "elements", "DefaultPathContainer", "slice", "path", "e", "isSeparator", "element", "isPathSegment", "HTTP_OPTIONS", "parsePath", "path", "options", "DefaultPathContainer", "HTTP_OPTIONS", "_DefaultPathContainer", "#SEPARATORS", "#path", "#elements", "elements", "separator", "separatorElement", "start", "end", "i", "segment", "#decodeAndParsePathSegment", "DefaultPathSegment", "paramsIndex", "valueToMatch", "pathParameterContent", "parameters", "#parsePathParameters", "content", "parameter", "#parsePathParameterValue", "values", "input", "output", "eqIndex", "name", "value", "v", "_DefaultPathSegment", "#EMPTY_PARAMS", "separatorOrValueToMatch", "#value", "#valueToMatch", "#parameters", "parseRequestPath", "uri", "contextPath", "DefaultRequestPath", "_DefaultRequestPath", "#initContextPath", "path", "parsePath", "#validateContextPath", "length", "counter", "element", "subPath", "fullPath", "#extractPathWithinApplication", "contextPathLength", "rawPath", "contextPathContainer", "pathWithinApplication", "#fullPath", "#contextPath", "#pathWithinApplication", "AbstractServerHttpRequest", "AbstractHttpRequest", "#sslInfo", "#path", "ExtendedHttpIncomingMessage", "http", "ExtendedHttpServerResponse", "AbstractServerHttpResponse", "AbstractHttpResponse", "#cookies", "#statusCode", "#state", "#commitActions", "statusCode", "httpStatusCode", "cookie", "action", "state", "body", "buffer", "error", "writeAction", "allActions", "acc", "cur", "_error", "HttpServerRequest", "AbstractServerHttpRequest", "#url", "#req", "req", "IncomingMessageHeaders", "dh", "dp", "family", "address", "port", "remoteAddress", "DefaultSslInfo", "chunks", "chunk", "text", "blob", "remoteIp", "socket", "AbstractHttpHeaders", "#msg", "msg", "name", "value", "OutgoingMessageHeaders", "v", "HttpServerResponse", "#res", "res", "status", "resolve", "reject", "e", "ServerHttpRequestDecorator", "_ServerHttpRequestDecorator", "#delegate", "request", "ServerHttpResponseDecorator", "_ServerHttpResponseDecorator", "response", "ServerWebExchangeDecorator", "_ServerWebExchangeDecorator", "exchange", "DefaultWebExchange", "#attributes", "#logId", "#logPrefix", "codecConfigurer", "LOG_ID_ATTRIBUTE", "import_node_v8", "import_promises", "log", "getLogger", "DEFAULT_OPTIONS", "fetchStats", "dumpHeap", "opts", "prefix", "target", "fileExists", "_", "dumpFileName", "lastFileName", "e", "i", "currentFileName", "nextFileName", "firstFileName", "path", "processStats", "stats", "state", "limit", "used", "start", "merged", "stopped", "report", "interval", "command", "run", "channel", "stop", "m", "serverHeader", "version", "server", "response", "next", "server_header_default", "import_gateway", "log", "getLogger", "acceptsMissing", "originFilters", "tryMatch", "origin", "block", "allow", "acceptsNonMatched", "acceptsOrigin", "matchResult", "regexifyOriginFilters", "or", "matchers", "exchange", "matcher", "match", "NO_MATCH", "and", "m", "not", "anyExchange", "_exchange", "EMPTY_OBJECT", "variables", "pattern", "opts", "method", "request", "path", "mediaType", "shouldIgnore", "requestedMediaType", "ignoredMediaType", "requestMediaTypes", "upgradeMatcher", "import_gateway", "configure", "app", "config", "routes", "applyCors", "request", "options", "cors", "path", "configurer", "handlers", "handler", "matcher", "pattern", "middleware", "exchange", "next", "match", "variables", "sockets", "factory", "route", "regexifyOriginFilters", "import_gateway", "isSameOrigin", "request", "origin", "url", "actualProtocol", "actualHost", "originUrl", "originHost", "originProtocol", "isCorsRequest", "isPreFlightRequest", "VARY_HEADERS", "processRequest", "exchange", "config", "request", "response", "responseHeaders", "varyHeaders", "header", "h", "isCorsRequest", "logger", "rejectRequest", "preFlightRequest", "isPreFlightRequest", "handleInternal", "DEFAULT_PERMIT_ALL", "DEFAULT_PERMIT_METHODS", "PERMIT_DEFAULT_CONFIG", "validateCorsConfig", "allowHeaders", "ALL", "allowOrigins", "validateAllowCredentials", "validateAllowPrivateNetwork", "origin", "trimTrailingSlash", "combine", "source", "other", "combined", "v", "combineCorsConfig", "corsFilter", "opts", "processor", "ctx", "chain", "cors_default", "getLogger", "HttpStatus", "requestOrigin", "allowOrigin", "checkOrigin", "requestMethod", "getMethodToUse", "allowMethods", "checkMethods", "requestHeaders", "getHeadersToUse", "checkHeaders", "exposeHeaders", "DEFAULT_METHODS", "allowedOrigins", "originToCheck", "allowedOrigin", "allowedMethods", "allowedHeaders", "allowAnyHeader", "result", "requestHeader", "value", "allowedHeader", "isPreFlight", "headers", "matchingCorsConfigSource", "matcher", "import_gateway", "createCorsConfigSource", "context", "routes", "cors", "defaultCorsConfig", "combineCorsConfig", "PERMIT_DEFAULT_CONFIG", "validatedConfigs", "path", "route", "routeCorsConfig", "matcher", "config", "and", "upgradeMatcher", "pattern", "validateCorsConfig", "appConfigs", "m", "added", "entry", "matchingCorsConfigSource", "isAuthentication", "principal", "AuthenticationError", "value", "InsufficientAuthenticationError", "BadCredentialsError", "AccountStatusError", "message", "LockedError", "DisabledError", "AccountExpiredError", "CredentialsExpiredError", "AccessDeniedError", "AuthorizationDecision", "granted", "DefaultAuthorizationManager", "#check", "check", "authentication", "object", "AuthenticationServiceError", "AuthenticationError", "staticServerHttpHeadersWriter", "headers", "exchange", "containsNoHeaders", "response", "name", "value", "cacheControlServerHttpHeadersWriter", "MapHttpHeaders", "contentTypeServerHttpHeadersWriter", "strictTransportSecurityServerHttpHeadersWriter", "maxAgeInSeconds", "includeSubDomains", "preload", "headerValue", "delegate", "isSecure", "frameOptionsServerHttpHeadersWriter", "mode", "xssProtectionServerHttpHeadersWriter", "permissionsPolicyServerHttpHeadersWriter", "policyDirectives", "contentSecurityPolicyServerHttpHeadersWriter", "reportOnly", "headerName", "refererPolicyServerHttpHeadersWriter", "policy", "crossOriginOpenerPolicyServerHttpHeadersWriter", "crossOriginEmbedderPolicyServerHttpHeadersWriter", "crossOriginResourcePolicyServerHttpHeadersWriter", "compositeServerHttpHeadersWriter", "writers", "writer", "opts", "chain", "serverAuthenticationEntryPointFailureHandler", "opts", "entryPoint", "rethrowAuthenticationServiceError", "exchange", "error", "AuthenticationServiceError", "DEFAULT_REALM", "createHeaderValue", "realm", "httpBasicEntryPoint", "opts", "headerValue", "exchange", "_error", "response", "HttpStatus", "BASIC", "httpBasicAuthenticationConverter", "opts", "credentialsEncoding", "exchange", "request", "authorization", "credentials", "parts", "principal", "erasableCredentials", "import_node_async_hooks", "AsyncStorageSecurityContextHolder", "_AsyncStorageSecurityContextHolder", "storage", "securityContext", "authentication", "authenticate", "exchange", "chain", "token", "managerResolver", "successHandler", "storage", "authentication", "onAuthenticationSuccess", "e", "AuthenticationError", "filterExchange", "AsyncStorageSecurityContextHolder", "authenticationFilter", "opts", "auth", "anyExchange", "httpBasicAuthenticationConverter", "serverAuthenticationEntryPointFailureHandler", "httpBasicEntryPoint", "manager", "_exchange", "error", "httpStatusEntryPoint", "opts", "exchange", "_error", "logger", "getLogger", "delegatingEntryPoint", "opts", "defaultEntryPoint", "response", "_error", "HttpStatus", "exchange", "error", "matcher", "entryPoint", "delegatingSuccessHandler", "handlers", "exchange", "chain", "authentication", "handler", "httpBasic", "opts", "xhrMatcher", "exchange", "match", "NO_MATCH", "defaultEntryPoint", "delegatingEntryPoint", "httpStatusEntryPoint", "HttpStatus", "httpBasicEntryPoint", "entryPoint", "manager", "restMatcher", "mediaType", "notHtmlMatcher", "not", "restNoHtmlMatcher", "and", "preferredMatcher", "or", "failureHandler", "serverAuthenticationEntryPointFailureHandler", "successHandler", "delegatingSuccessHandler", "converter", "httpBasicAuthenticationConverter", "authenticationFilter", "BearerTokenErrorCodes", "DEFAULT_URI", "invalidToken", "message", "HttpStatus", "invalidRequest", "ACCESS_TOKEN_PARAMETER_NAME", "authorizationPattern", "Oauth2AuthenticationError", "AuthenticationError", "error", "message", "options", "isBearerTokenAuthenticationToken", "authentication", "serverBearerTokenAuthenticationConverter", "opts", "exchange", "request", "resolveFromAuthorizationHeader", "token", "resolveFromQueryString", "resolveFromBody", "rs", "r", "resolveToken", "accessTokens", "invalidRequest", "accessToken", "headers", "headerName", "authorization", "match", "invalidToken", "resolveTokens", "parameters", "allow", "token_converter_default", "computeWWWAuthenticate", "parameters", "wwwAuthenticate", "i", "key", "value", "isBearerTokenError", "error", "getStatus", "authError", "Oauth2AuthenticationError", "HttpStatus", "createParameters", "realm", "bearerTokenServerAuthenticationEntryPoint", "opts", "exchange", "status", "response", "token_entry_point_default", "jwtAuthConverter", "opts", "principalClaimName", "jwt", "asyncJwtConverter", "converter", "JwtError", "BadJwtError", "onError", "error", "Oauth2AuthenticationError", "invalidToken", "AuthenticationServiceError", "jwtAuthManager", "decoder", "authConverter", "authentication", "isBearerTokenAuthenticationToken", "token", "e", "resourceServer", "opts", "entryPoint", "token_entry_point_default", "converter", "token_converter_default", "failureHandler", "serverAuthenticationEntryPointFailureHandler", "authenticationFilter", "manager", "jwtAuthManager", "_exchange", "import_jwt", "commenceAuthentication", "exchange", "authentication", "entryPoint", "cause", "InsufficientAuthenticationError", "e", "AuthenticationError", "httpStatusAccessDeniedHandler", "httpStatus", "_error", "buffer", "errorFilter", "opts", "accessDeniedHandler", "HttpStatus", "authenticationEntryPoint", "httpBasicEntryPoint", "chain", "error", "AccessDeniedError", "principal", "isAuthentication", "logger", "getLogger", "delegatingAuthorizationManager", "opts", "check", "authentication", "exchange", "decision", "matcher", "manager", "checkResult", "AuthorizationDecision", "DefaultAuthorizationManager", "logger", "getLogger", "authorizationFilter", "opts", "manager", "storage", "exchange", "chain", "promise", "AsyncStorageSecurityContextHolder", "c", "error", "AccessDeniedError", "SecurityContextServerWebExchange", "ServerWebExchangeDecorator", "#context", "exchange", "context", "exchangeFilter", "opts", "storage", "chain", "AsyncStorageSecurityContextHolder", "x509Converter", "opts", "principalExtractor", "exchange", "sslInfo", "clientCertificate", "principal", "subjectX500PrincipalExtractor", "opts", "extractFromEmail", "subjectDnRegEx", "cert", "email", "altName", "result", "BadCredentialsError", "AbstractPasswordEncoder", "rawPassword", "encodedPassword", "DelegatingPasswordEncoder", "_DelegatingPasswordEncoder", "#idPrefix", "#idSuffix", "#idForEncode", "#encoderForEncode", "#encoders", "#defaultEncoderForMatches", "#outer", "outer", "prefixEncodedPassword", "id", "#extractId", "start", "end", "idForEncode", "encoders", "idPrefix", "idSuffix", "encoder", "encoded", "delegate", "#extractEncodedPassword", "NoopPasswordEncoder", "_NoopPasswordEncoder", "#INSTANCE", "import_tools", "bufferEquals", "a", "b", "diff", "i", "Argon2PasswordEncoder", "AbstractPasswordEncoder", "#saltLength", "#hashLength", "#parallelism", "#memory", "#passes", "saltLength", "hashLength", "parallelism", "memory", "passes", "rawPassword", "encodedPassword", "decoded", "hash", "nonce", "parameters", "MAX_PASSWORD_LENGTH", "createDelegatingPasswordEncoder", "idForEncode", "encoders", "Argon2PasswordEncoder", "NoopPasswordEncoder", "DelegatingPasswordEncoder", "NoopUserDetailsPasswordService", "user", "_newPassword", "UsernameNotFoundError", "AuthenticationError", "message", "username", "options", "UserBuilder", "_UserBuilder", "#username", "#password", "#authorities", "#accountExpired", "#accountLocked", "#credentialsExpired", "#disabled", "#passwordEncoder", "rawPassword", "builder", "password", "encoder", "roles", "role", "authorities", "accountExpired", "accountLocked", "credentialsExpired", "disabled", "encodedPassword", "logger", "getLogger", "userDetailsServiceAuthenticationManager", "userDetailsService", "options", "preAuthenticationChecks", "user", "LockedError", "DisabledError", "AccountExpiredError", "postAuthenticationChecks", "CredentialsExpiredError", "passwordEncoder", "createDelegatingPasswordEncoder", "userDetailsPasswordService", "NoopUserDetailsPasswordService", "upgradeEncodingIfNeeded", "userDetails", "presentedPassword", "existingEncodedPassword", "newEncodedPassword", "authentication", "username", "BadCredentialsError", "principal", "credentials", "accountStatusUserDetailsChecker", "preAuthenticatedAuthenticationManager", "opts", "userDetailsChecker", "supports", "UsernameNotFoundError", "erasableCredentials", "x509", "opts", "manager", "preAuthenticatedAuthenticationManager", "principalExtractor", "subjectX500PrincipalExtractor", "converter", "x509Converter", "authenticationFilter", "WebHandlerDecorator", "#delegate", "delegate", "exchange", "ErrorHandlingWebHandler", "#errorHandlers", "errorHandlers", "completion", "e", "handler", "reason", "error", "DefaultWebFilterChain", "_DefaultWebFilterChain", "#filters", "#handler", "#current", "#chian", "filters", "allFilters", "result", "chain", "current", "#invokeFilter", "filter", "FilteringWebHandler", "#chain", "WebFilterChainProxy", "#filters", "#firewall", "StrictServerWebExchangeFirewall", "#decorator", "DefaultWebFilterChainDecorator", "#exchangeRejectedHandler", "HttpStatusExchangeRejectedHandler", "filters", "exchange", "chain", "firewalledExchange", "#filterFirewalledExchange", "e", "ServerExchangeRejectedError", "securityFilterChain", "firewall", "decorator", "handler", "original", "DefaultWebFilterChain", "MatcherSecurityWebFilterChain", "#matcher", "matcher", "message", "#status", "status", "HttpStatus", "error", "filterOrder", "filterOrderSymbol", "config_default", "config", "context", "getService", "name", "defaultService", "authenticationManager", "userDetailsServiceAuthenticationManager", "middleware", "ServerHttpSecurity", "#authenticationEntryPoint", "#defaultEntryPoints", "#authenticationManager", "delegatingEntryPoint", "writer", "headers", "filter", "x509", "subjectX500PrincipalExtractor", "cors_default", "defaultSuccessHandlers", "exchange", "chain", "_authentication", "httpBasic", "verifier", "decoder", "token", "payload", "claim", "e", "BadJwtError", "JwtError", "authenticationConverter", "token_converter_default", "authenticationConverterMatcher", "NO_MATCH", "match", "entryPoint", "token_entry_point_default", "resourceServer", "exchangeF", "exchangeFilter", "errorFf", "errorFilter", "manager", "authorize", "mappings", "anyExchangeRegistered", "matcher", "access", "serverMatcher", "anyExchange", "DefaultAuthorizationManager", "AuthorizationDecision", "p", "authentication", "delegatingAuthorizationManager", "authorizationFilter", "a", "b", "aOrder", "bOrder", "security", "MatcherSecurityWebFilterChain", "MapUserDetailsService", "#users", "users", "user", "#getKey", "username", "key", "result", "newPassword", "userDetails", "import_node_crypto", "logger", "getLogger", "createSecurityConfig", "context", "authorize", "type", "defaultAccess", "path", "route", "rule", "matcher", "pattern", "and", "upgradeMatcher", "createUserDetailsService", "getOrDeducePassword", "user", "encoder", "password", "generatedPassword", "MAX_PASSWORD_LENGTH", "roles", "userDetails", "UserBuilder", "MapUserDetailsService", "httpSecurity", "corsConfigSource", "createCorsConfigSource", "config", "userDetailsService", "storage", "config_default", "HttpHeadResponseDecorator", "ServerHttpResponseDecorator", "import_ws", "createHandshakeInfo", "req", "protocol", "exchange", "request", "HttpServerRequest", "principalPromiseProvider", "principal", "url", "headers", "MapHttpHeaders", "key", "cookies", "logPrefix", "remoteAddress", "webSockets", "context", "next", "path", "routes", "route", "response", "upgradeMatchResult", "upgradeMatcher", "HttpStatus", "buffer", "import_ws", "ExtendedWebSocket", "_first", "_second", "options", "PingManager", "_PingManager", "#EMPTY_BUFFER", "#LAST_TIMESTAMP_BUFFER", "#pingData", "#pingInterval", "#pingIntervalId", "#mask", "#logger", "logger", "supplier", "ping", "#createBufferFromTimestamp", "path", "clients", "client", "#terminateIfDisconnected", "#markAndSendPing", "data", "err", "now", "buffer", "#createTimestampFromBuffer", "handshake", "socket", "addressAndPort", "sent", "latency", "logger", "getLogger", "upgradeStrategy", "path", "route", "wss", "onSocketError", "exchange", "logPrefix", "request", "req", "ServerHttpRequestDecorator", "socket", "upgradeHead", "host", "origin", "acceptsOrigin", "client", "applyHandshakeHeaders", "headers", "response", "seen", "header", "index", "HttpStatus", "name", "value", "nativeResponse", "ServerHttpResponseDecorator", "nameLowerCase", "initRoute", "endpoint", "storage", "regexAwareReplacer", "ExtendedWebSocket", "pings", "PingManager", "handler", "err", "handshake", "createHandshakeInfo", "data", "e", "import_node_fs", "import_node_path", "import_jsrsasign", "import_tools", "logger", "getLogger", "secureContextOptions", "ssl", "serverCertificate", "commonOptions", "options", "defaultKeyPath", "defaultCertPath", "caKeyPath", "caPemPath", "passphrase", "rootCA", "keyDir", "certDir", "caKeyPem", "caKeyObj", "caCertPem", "caCert", "issuer", "hostname", "serverCert", "keyPath", "certPath", "result", "isLoggingSuppressed", "hints", "LOG_PREFIX_HINT", "getLogPrefix", "AbstractEncoder", "#encodableMimeTypes", "getLogger", "supportedMimeTypes", "logger", "type", "mimeType", "supportedMimeType", "isCompatibleWith", "BlobEncoder", "ALL", "input", "hints", "part", "isLoggingSuppressed", "#logValue", "prefix", "getLogPrefix", "StringEncoder", "_StringEncoder", "mimeTypes", "logPrefix", "traceEnabled", "createMimeType", "LoggingCodecSupport", "getLogger", "#enableLoggingRequestDetails", "enable", "MultipartHttpMessageReader", "_MultipartHttpMessageReader", "LoggingCodecSupport", "MediaType", "#partReader", "partReader", "type", "mediaType", "#supportsMediaType", "supportedMediaType", "isCompatibleWith", "message", "hints", "stream", "result", "name", "value", "DefaultPartHttpMessageReader", "EncoderHttpMessageWriter", "_EncoderHttpMessageWriter", "#encoder", "#mediaTypes", "#defaultMediaType", "encoder", "MediaType", "mediaType", "isConcrete", "type", "input", "message", "hints", "resolvedMediaType", "#updateContentType", "part", "AbstractEncoder", "getContentType", "fallback", "useFallback", "addDefaultCharsetIfNeeded", "main", "defaultType", "defaultCharset", "result", "BaseDefaultCodecs", "#multipartReader", "#maxInMemorySize", "#enableLoggingRequestDetails", "#registerDefaults", "#writers", "#readers", "reader", "registerDefaults", "partReader", "DefaultPartHttpMessageReader", "MultipartHttpMessageReader", "#getBaseWriters", "writers", "BlobEncoder", "bytes", "enable", "StringEncoder", "codecs", "codec", "#initCodec", "size", "BaseCodecConfigurer", "defaultCodecs", "ServerDefaultCodecsImpl", "DefaultServerCodecConfigurer", "createServerCodecConfigurer", "config_default", "import_node_net", "import_promises", "import_net", "sendCommand", "server", "command", "options", "timeout", "connectOptions", "target", "resolve", "reject", "client", "net", "timeoutId", "data", "response", "err", "isSocketStale", "pipeName", "sendCommand", "cleanupSocketFile", "logger", "e", "code", "createManagementServer", "options", "handler", "onClose", "resolve", "reject", "server", "stream", "error", "data", "asString", "msg", "result", "response", "cause", "gatewayManagementServer", "shutdown", "info", "import_package", "import_node_path", "import_promises", "import_node_fs", "getWelcomePage", "staticLocations", "filePath", "indexHtml", "welcomePageFactory", "welcomePage", "htmlMatcher", "mediaType", "exchange", "next", "request", "response", "HttpStatus", "buffer", "import_node_async_hooks", "isClientDisconnectedError", "error", "code", "message", "checkAndLogClientDisconnectedError", "logger", "HttpWebHandlerAdapter", "#logger", "#codecConfigurer", "#enableLoggingRequestDetails", "#delegate", "#storage", "logger", "delegate", "config_default", "configurer", "reader", "LoggingCodecSupport", "request", "response", "DefaultWebExchange", "storage", "headers", "result", "key", "value", "query", "exchange", "trace", "status", "error", "logPrefix", "HttpStatus", "checkAndLogClientDisconnectedError", "callback", "resolve", "reject", "WebHttpHandlerBuilder", "_WebHttpHandlerBuilder", "#webHandler", "#filters", "#exceptionHandlers", "#middleware", "#handlerDecorator", "webHandler", "filters", "consumer", "handlers", "decorator", "previousDecorator", "handler", "getLogger", "decorated", "FilteringWebHandler", "ErrorHandlingWebHandler", "adapter", "adapted", "request_default", "exchange", "messageReaders", "DefaultServerRequest", "DefaultServerRequestHeaders", "#headers", "headers", "MediaType", "value", "getContentType", "name", "list", "PathElement", "pos", "separator", "SeparatorPathElement", "PathElement", "pos", "separator", "pathIndex", "matchingContext", "WildcardPathElement", "PathElement", "pos", "separator", "pathIndex", "matchingContext", "segmentData", "element", "isPathSegment", "CaptureSegmentsPathElement", "PathElement", "#variableName", "pos", "captureDescriptor", "separator", "pathIndex", "matchingContext", "endPathIndex", "#collectParameters", "startPathIndex", "parametersCollector", "element", "isPathSegment", "parameters", "key", "values", "existingValues", "#pathToString", "fromSegment", "toSegment", "pathElements", "sb", "s", "result", "i", "WildcardSegmentsPathElement", "PathElement", "pos", "separator", "pathIndex", "matchingContext", "endPathIndex", "s", "result", "i", "MatchingContext", "#candidate", "#extractedUriVariables", "#extractedMatrixVariables", "#determineRemainingPath", "pathContainer", "extractVariables", "key", "value", "parameters", "PathMatchInfo", "pathIndex", "isSeparator", "element", "isPathSegment", "_PathMatchInfo", "uriVars", "matrixVars", "PathPattern", "_PathPattern", "#EMPTY_PATH", "parsePath", "a", "b", "#patternString", "#parser", "#pathOptions", "#caseSensitive", "#head", "#capturedVariableCount", "#normalizedLength", "#endsWithSeparatorWildcard", "#score", "#catchAll", "patternText", "parser", "head", "current", "CaptureSegmentsPathElement", "WildcardSegmentsPathElement", "SeparatorPathElement", "WildcardPathElement", "#hasLength", "container", "#pathContainerIsJustSeparator", "matchingContext", "path", "pathElements", "pathElementsLength", "startIndex", "elem", "endIndex", "multipleAdjacentSeparators", "i", "resultPath", "sb", "e", "subPath", "pe", "import_node_util", "PatternMessages", "PatternParseError", "_PatternParseError", "#pattern", "messageType", "inserts", "cause", "position", "pattern", "message", "pos", "options", "sb", "i", "CaptureVariablePathElement", "PathElement", "#constraintPattern", "pos", "captureDescriptor", "caseSensitive", "separator", "colon", "i", "patternText", "flags", "pathIndex", "matchingContext", "candidateCapture", "exec", "match", "sb", "s", "result", "SingleCharWildcardedPathElement", "PathElement", "#text", "#len", "#questionMarkCount", "#caseSensitive", "pos", "literalText", "questionMarkCount", "caseSensitive", "separator", "i", "pathIndex", "matchingContext", "element", "isPathSegment", "value", "c", "RegexPathElement", "PathElement", "#regex", "#caseSensitive", "#pattern", "#wildcardCount", "#variableNames", "pos", "regex", "caseSensitive", "completePattern", "separator", "#buildPattern", "_completePattern", "text", "variableNames", "wildcardCount", "patternBuilder", "ch", "closeBrace", "captureContent", "colonIndex", "variableName", "constraint", "patternString", "flags", "pathIndex", "matchingContext", "textToMatch", "match", "matches", "i", "name", "value", "varsLength", "LiteralPathElement", "PathElement", "#text", "#len", "#caseSensitive", "pos", "literalText", "caseSensitive", "separator", "pathIndex", "matchingContext", "pathSegment", "isPathSegment", "value", "arr", "i", "isJavaScriptIdentifierStartChar", "ch", "isJavaScriptIdentifierPartChar", "InternalPathPatternParser", "#parser", "#pathPatternData", "#pathPatternLength", "#pos", "#singleCharWildcardCount", "#wildcard", "#isCaptureSegmentsVariable", "#insideVariableCapture", "#variableCaptureCount", "#pathElementStart", "#variableCaptureStart", "#hasMultipleSegmentsElements", "#capturedVariableNames", "#headPE", "#currentPE", "parser", "pathPattern", "i", "#resetPathElementState", "separator", "#pushPathElement", "#createPathElement", "SeparatorPathElement", "PatternParseError", "#skipCaptureRegex", "#isDoubleWildcard", "#checkValidMultipleSegmentsElements", "WildcardSegmentsPathElement", "PathPattern", "#getPathElementText", "pathElementText", "index", "newPE", "CaptureSegmentsPathElement", "CaptureVariablePathElement", "err", "#findRegExpStart", "#recordCapturedVariable", "newRegexPE", "RegexPathElement", "variableName", "WildcardPathElement", "SingleCharWildcardedPathElement", "LiteralPathElement", "regexStartPos", "curlyBracketDepth", "previousBackslash", "startPos", "endPos", "newPathElement", "peBeforeSeparator", "data", "offset", "pos", "v", "PathPatternParser", "_PathPatternParser", "#caseSensitive", "#pathOptions", "HTTP_OPTIONS", "value", "pattern", "pathPattern", "InternalPathPatternParser", "_value", "#raiseError", "logger", "getLogger", "REQUEST_ATTRIBUTE", "URI_VARIABLES_ATTRIBUTE", "MATCHING_PATTERN_ATTRIBUTE", "routerFunction", "route", "result", "other", "and", "first", "second", "request", "handler", "predicate", "handlerFunction", "logPrefix", "predicates", "requestMethod", "isPreFlightRequest", "accessControlRequestMethod", "requestPredicate", "negate", "or", "orRequestPredicate", "delegate", "negateRequestPredicate", "method", "httpMethod", "singleHttpMethodPredicate", "match", "traceMatch", "methods", "httpMethods", "multipleHttpMethodsPredicate", "path", "pattern", "parser", "PathPatternParser", "pathPredicates", "patternParser", "pathPattern", "pathPatternPredicate", "pathContainer", "info", "prefix", "desired", "actual", "headers", "headersPredicate", "accept", "mediaTypes", "acceptedMediaTypes", "MediaType", "sortBySpecificity", "mediaType", "singleAcceptPredicate", "accepted", "acceptedMediaType", "isCompatibleWith", "multipleAcceptsPredicate", "outer", "queryParam", "name", "valueOrPredicate", "value", "v", "queryParamPredicate", "s", "from", "response", "status", "headers", "name", "httpStatusCode", "DefaultServerResponseBuilder", "ok", "HttpStatus", "created", "location", "response_default", "writeWithMessageWriters", "message", "context", "promise", "bodyType", "mediaType", "getContentType", "writer", "bodyFromValue", "body", "#statusCode", "#headers", "MapHttpHeaders", "#cookies", "#hints", "statusCode", "headerName", "headerValues", "headerValue", "cookie", "cookies", "consumer", "contentType", "length", "#initEntityResponse", "entity", "inserter", "DefaultEntityResponse", "writeFunction", "WriterFunctionServerResponse", "exchange", "AbstractServerResponse", "hints", "allCookies", "cookieList", "#writeStatusAndHeaders", "WriterFunctionServerResponse", "AbstractServerResponse", "#writeFunction", "statusCode", "headers", "cookies", "writeFunction", "exchange", "context", "DefaultEntityResponse", "#entity", "#inserter", "entity", "inserter", "hints", "messageWriters", "LOG_PREFIX_HINT", "import_node_util", "ErrorResponseError", "_ErrorResponseError", "#status", "#headers", "MapHttpHeaders", "status", "body", "detail", "problem", "ResponseStatusError", "_ResponseStatusError", "ErrorResponseError", "#reason", "status", "reason", "EMPTY_HTTP_HEADERS", "DefaultErrorAttributes", "_DefaultErrorAttributes", "request", "options", "#getErrorAttributesInternal", "error", "exchange", "includeStackTrace", "errorAttributes", "errorStatus", "#determineHttpStatus", "#handleError", "ResponseStatusError", "httpStatus", "HttpStatus", "AbstractWebErrorHandler", "#errorAttributes", "#messageReaders", "#messageWriters", "messageReaders", "messageWriters", "#isDisconnectedClientError", "request_default", "handler", "response", "#write", "isClientDisconnectedError", "responseContext", "DefaultWebErrorHandler", "_DefaultWebErrorHandler", "#defaultErrorAttributes", "#ONLY_STATUS", "readers", "writers", "errorProperties", "route", "predicates", "#renderErrorResponse", "#getErrorAttributes", "mimeType", "ALL", "status", "#getHttpStatus", "response_default", "BEST_MATCHING_HANDLER_ATTRIBUTE", "BEST_MATCHING_PATTERN_ATTRIBUTE", "DispatcherHandler", "#handlerMappings", "#handlerAdapters", "#resultHandlers", "handlerMappings", "handlerAdapters", "resultHandlers", "exchange", "#createNotFoundError", "isPreFlightRequest", "handler", "mapping", "e", "#handleResultPromise", "#handleRequestWith", "resultPromise", "result", "#handleResult", "exceptionHandler", "error", "result2", "details", "HttpStatus", "adapter", "ResponseStatusError", "AbstractHandlerMapping", "getLogger", "#corsConfigSource", "source", "request", "config", "handlerConfig", "HandlerFunctionAdapter", "handler", "exchange", "handlerFunction", "request", "REQUEST_ATTRIBUTE", "response", "ServerResponseResultHandler", "#messageWriters", "messageWriters", "result", "AbstractServerResponse", "RouterFunctionMapping", "AbstractHandlerMapping", "#routerFunction", "#messageReaders", "routerFunction", "messageReaders", "routerFunctions", "config_default", "a", "b", "request_default", "#setAttributes", "attributes", "BEST_MATCHING_HANDLER_ATTRIBUTE", "pattern", "MATCHING_PATTERN_ATTRIBUTE", "BEST_MATCHING_PATTERN_ATTRIBUTE", "uriVariables", "URI_VARIABLES_ATTRIBUTE", "logger", "getLogger", "createListener", "builder", "onSocketError", "httpHandler", "req", "resOrUpgradeHead", "res", "ExtendedHttpServerResponse", "request", "HttpServerRequest", "response", "HttpServerResponse", "decoratedResponse", "HttpHeadResponseDecorator", "hp", "e", "http", "promisify", "fn", "resolve", "reject", "r", "err", "memoryMonitor", "config", "start", "VERSION", "info", "initBuilder", "context", "storage", "security", "httpSecurity", "sockets", "webSockets", "codecConfigurer", "config_default", "welcomePageRouterFunctionMapping", "RouterFunctionMapping", "h", "DispatcherHandler", "HandlerFunctionAdapter", "ServerResponseResultHandler", "handler", "compose", "server_header_default", "next", "HttpStatus", "buffer", "welcomePageFactory", "_next", "ResponseStatusError", "WebHttpHandlerBuilder", "WebFilterChainProxy", "DefaultWebErrorHandler", "DefaultErrorAttributes", "Factory", "options", "ssl", "host", "serverCertificate", "createServer", "https", "secureContextOptions", "monitor", "gatewayManager", "GatewayManager", "path", "configure", "configurer", "core_default", "ports", "portRange", "listener", "server", "ExtendedHttpIncomingMessage", "port", "route", "endpoint", "localIp", "initRoute", "addressAndPort", "_socket", "head", "closeActions", "closeSockets", "closeServer", "cb", "stop", "fullServer", "address", "errors", "action", "managementServer", "gatewayManagementServer", "index_default", "Factory"]
}
