{"version":3,"file":"types.js","sources":["../../../../src/integrations/express/types.ts"],"sourcesContent":["/**\n * Platform-portable Express tracing integration.\n *\n * @module\n *\n * This Sentry integration is a derivative work based on the OpenTelemetry\n * Express instrumentation.\n *\n * <https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/packages/instrumentation-express>\n *\n * Extended under the terms of the Apache 2.0 license linked below:\n *\n * ----\n *\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *      https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { RequestEventData } from '../../types-hoist/request';\nimport type { SpanAttributes } from '../../types-hoist/span';\n\nexport const ATTR_EXPRESS_NAME = 'express.name';\nexport const ATTR_HTTP_ROUTE = 'http.route';\nexport const ATTR_EXPRESS_TYPE = 'express.type';\n\nexport type ExpressExport = {\n  Router: ExpressRouterv5 | ExpressRouterv4;\n  application: ExpressApplication;\n};\n\nexport type ExpressExportv5 = ExpressExport & {\n  Router: ExpressRouterv5;\n};\n\nexport type ExpressExportv4 = ExpressExport & {\n  Router: ExpressRouterv4;\n};\n\nexport type ExpressModuleExport = ExpressExport | { default: ExpressExport };\n\nexport interface ExpressRequest extends RequestEventData {\n  originalUrl: string;\n  route: unknown;\n  // Note: req.res is typed as optional (only present after middleware init).\n  // mark optional to preserve compat with express v4 types.\n  res?: ExpressResponse;\n}\n\n// just a minimum type def for what we need, since this also needs to\n// work in environments lacking node:http\nexport interface ExpressResponse {\n  once(ev: string, listener: Function): this;\n  removeListener(ev: string, listener?: Function): this;\n  emit(ev: string, ...data: unknown[]): this;\n}\n\nexport interface NextFunction {\n  (err?: unknown): void;\n  /**\n   * \"Break-out\" of a router by calling {next('router')};\n   * @see {https://expressjs.com/en/guide/using-middleware.html#middleware.router}\n   */\n  (deferToNext: 'router'): void;\n  /**\n   * \"Break-out\" of a route by calling {next('route')};\n   * @see {https://expressjs.com/en/guide/using-middleware.html#middleware.application}\n   */\n  (deferToNext: 'route'): void;\n}\n\n// Need to mark this as `any` so they don't conflict with the actual express\n//oxlint-disable-next-line no-explicit-any\nexport type ExpressApplicationRequestHandler = (...handlers: any[]) => any;\n\nexport type ExpressRequestInfo<T = unknown> = {\n  /** An express request object */\n  request: T;\n  route: string;\n  layerType: ExpressLayerType;\n};\n\nexport type ExpressLayerType = 'router' | 'middleware' | 'request_handler';\nexport const ExpressLayerType_ROUTER = 'router';\nexport const ExpressLayerType_MIDDLEWARE = 'middleware';\nexport const ExpressLayerType_REQUEST_HANDLER = 'request_handler';\n\nexport type PathParams = string | RegExp | Array<string | RegExp>;\nexport type LayerPathSegment = string | RegExp | number;\n\nexport interface ExpressRoute {\n  path: string;\n  stack: ExpressLayer[];\n}\n\nexport type ExpressRouterv4 = ExpressRouter;\n\nexport interface ExpressRouterv5 {\n  prototype: ExpressRouter;\n}\n\n// https://github.com/expressjs/express/blob/main/lib/router/layer.js#L33\nexport type ExpressLayer = {\n  handle: Function &\n    Record<string, unknown> & {\n      stack?: ExpressLayer[];\n    };\n  name: string;\n  params: { [key: string]: string };\n  path?: string;\n  regexp: RegExp;\n  route?: ExpressLayer;\n};\n\nexport type ExpressRouter = {\n  params: { [key: string]: string };\n  _params: string[];\n  caseSensitive: boolean;\n  mergeParams: boolean;\n  strict: boolean;\n  stack: ExpressLayer[];\n  route(prefix: PathParams): ExpressRoute;\n  use(...handlers: unknown[]): unknown;\n};\n\nexport type IgnoreMatcher = string | RegExp | ((name: string) => boolean);\n\nexport type ExpressIntegrationOptions = {\n  /**\n   * @deprecated Pass the express module as the first argument, and an\n   * options getter as the second argument to patchExpressModule.\n   */\n  express?: ExpressModuleExport;\n\n  /** Ignore specific based on their name */\n  ignoreLayers?: IgnoreMatcher[];\n  /** Ignore specific layers based on their type */\n  ignoreLayersType?: ExpressLayerType[];\n  /**\n   * Optional callback invoked each time a layer resolves the matched HTTP route.\n   * Platform-specific integrations (e.g. Node.js) use this to propagate the\n   * resolved route to the underlying transport layer (e.g. OTel RPCMetadata).\n   */\n  onRouteResolved?: (route: string | undefined) => void;\n};\n\nexport type LayerMetadata = {\n  attributes: SpanAttributes;\n  name: string;\n};\n\nexport interface ExpressApplication {\n  stack: ExpressLayer[];\n  use: ExpressApplicationRequestHandler;\n}\n\nexport interface MiddlewareError extends Error {\n  status?: number | string;\n  statusCode?: number | string;\n  status_code?: number | string;\n  output?: {\n    statusCode?: number | string;\n  };\n}\n\nexport type ExpressMiddleware = (req: ExpressRequest, res: ExpressResponse, next: () => void) => void;\n\nexport type ExpressErrorMiddleware = (\n  error: MiddlewareError,\n  req: ExpressRequest,\n  res: ExpressResponse,\n  next: (error: MiddlewareError) => void,\n) => void;\n\nexport interface ExpressHandlerOptions {\n  /**\n   * Callback method deciding whether error should be captured and sent to Sentry\n   * @param error Captured middleware error\n   */\n  shouldHandleError?(this: void, error: MiddlewareError): boolean;\n}\n"],"names":[],"mappings":";;AAgCO,MAAM,iBAAA,GAAoB;AAC1B,MAAM,eAAA,GAAkB;AACxB,MAAM,iBAAA,GAAoB;;AA2D1B,MAAM,uBAAA,GAA0B;AAChC,MAAM,2BAAA,GAA8B;AACpC,MAAM,gCAAA,GAAmC;;;;;;;;;"}