{"version":3,"file":"collector.mjs","sources":["../../src/routes/collector.ts"],"sourcesContent":["import type { Core } from '@strapi/types';\n\nimport { createDebugger } from '../utils';\nimport { RouteMatcher } from './matcher';\n\nimport type { RoutesProvider } from './providers';\n\nconst debug = createDebugger('routes:collector');\n\n/**\n * Class responsible for collecting and filtering routes from multiple providers.\n */\nexport class RouteCollector {\n  private readonly _providers: RoutesProvider[];\n\n  private readonly _matcher: RouteMatcher;\n\n  /**\n   * @param providers - An array of route providers to collect routes from. Defaults to an empty array.\n   * @param matcher - An instance of RouteMatcher to filter routes. Defaults to a new {@link RouteMatcher} with no rules.\n   */\n  constructor(providers: RoutesProvider[] = [], matcher: RouteMatcher = new RouteMatcher()) {\n    this._providers = providers;\n    this._matcher = matcher;\n  }\n\n  /**\n   * Collects routes from all providers and filters them based on the matcher rules.\n   *\n   * @returns An array of {@link Core.Route} that pass the filter rules.\n   */\n  public collect(): Core.Route[] {\n    const routes = this._providers.flatMap((provider) => Array.from(provider));\n    const sanitizedRoutes = this.filter(routes);\n\n    debug(\n      'collected %o/%o routes from %o providers %o',\n      sanitizedRoutes.length,\n      routes.length,\n      this._providers.length,\n      this._providers.map((provider) => provider.constructor.name)\n    );\n\n    return sanitizedRoutes;\n  }\n\n  /**\n   * Filters the given array of routes based on the matcher rules.\n   *\n   * @param routes - The list of routes to filter.\n   * @returns An array of routes that match the rules.\n   */\n  private filter(routes: Core.Route[]): Core.Route[] {\n    return routes.filter((route) => this._matcher.match(route));\n  }\n}\n"],"names":["debug","createDebugger","RouteCollector","collect","routes","_providers","flatMap","provider","Array","from","sanitizedRoutes","filter","length","map","name","route","_matcher","match","providers","matcher","RouteMatcher"],"mappings":";;;;;AAOA,MAAMA,QAAQC,cAAAA,CAAe,kBAAA,CAAA;AAE7B;;AAEC,IACM,MAAMC,cAAAA,CAAAA;AAcX;;;;AAIC,MACD,OAAOC,GAAwB;QAC7B,MAAMC,MAAAA,GAAS,IAAI,CAACC,UAAU,CAACC,OAAO,CAAC,CAACC,QAAAA,GAAaC,KAAAA,CAAMC,IAAI,CAACF,QAAAA,CAAAA,CAAAA;AAChE,QAAA,MAAMG,eAAAA,GAAkB,IAAI,CAACC,MAAM,CAACP,MAAAA,CAAAA;QAEpCJ,KAAAA,CACE,6CAAA,EACAU,eAAAA,CAAgBE,MAAM,EACtBR,MAAAA,CAAOQ,MAAM,EACb,IAAI,CAACP,UAAU,CAACO,MAAM,EACtB,IAAI,CAACP,UAAU,CAACQ,GAAG,CAAC,CAACN,QAAAA,GAAaA,QAAAA,CAAS,WAAW,CAACO,IAAI,CAAA,CAAA;QAG7D,OAAOJ,eAAAA;AACT,IAAA;AAEA;;;;;MAMQC,MAAAA,CAAOP,MAAoB,EAAgB;QACjD,OAAOA,MAAAA,CAAOO,MAAM,CAAC,CAACI,KAAAA,GAAU,IAAI,CAACC,QAAQ,CAACC,KAAK,CAACF,KAAAA,CAAAA,CAAAA;AACtD,IAAA;AArCA;;;AAGC,MACD,YAAYG,SAAAA,GAA8B,EAAE,EAAEC,OAAAA,GAAwB,IAAIC,cAAc,CAAE;QACxF,IAAI,CAACf,UAAU,GAAGa,SAAAA;QAClB,IAAI,CAACF,QAAQ,GAAGG,OAAAA;AAClB,IAAA;AA+BF;;;;"}