{"version":3,"file":"index.mjs","names":["options: RegisterCacheRouterOptions"],"sources":["../src/index.ts"],"sourcesContent":["/**\n * Module exports a single function to register\n * the TurboRepo Remote Cache router.\n *\n * @see https://turborepo.com/docs/openapi\n *\n * @module\n */\n\nimport { app } from \"@azure/functions\";\nimport { checkServiceStatusHandler } from \"./handlers/check-service-status\";\nimport { downloadArtifactHandler } from \"./handlers/get-artifact\";\nimport { uploadArtifactHandler } from \"./handlers/upload-artifact\";\nimport { queryArtifactsInfoHandler } from \"./handlers/query-artifacts-info\";\nimport { RegisterCacheRouterOptions } from \"./utils/types\";\nimport { checkArtifactExistsHandler } from \"./handlers/check-artifact\";\nimport { recordUsageEventsHandler } from \"./handlers/record-usage-events\";\n\nexport type {\n  RegisterCacheRouterOptions,\n  AzureBlobStorageOptions,\n} from \"./utils/types\";\n\n/**\n * Registers all routes required for TurboRepo Remote Caching.\n */\nexport function registerCacheRouter(options: RegisterCacheRouterOptions = {}) {\n  const { healthCheck } = options;\n\n  app.setup({ enableHttpStream: true });\n\n  if (healthCheck !== false) {\n    app.get(\"health-check\", {\n      route: typeof healthCheck === \"string\" ? healthCheck : \"/\",\n      handler: async () => ({\n        body: `TurboRepo Remote Cache is up and running!`,\n        status: 200,\n      }),\n    });\n  }\n\n  app.get(\"check-service-status\", {\n    route: \"/v8/artifacts/status\",\n    handler: checkServiceStatusHandler(options),\n  });\n\n  app.post(\"query-artifacts-info\", {\n    route: \"/v8/artifacts\",\n    handler: queryArtifactsInfoHandler(options),\n  });\n\n  app.http(\"check-artifact-exists\", {\n    methods: [\"HEAD\"],\n    route: \"/v8/artifacts/{hash}\",\n    handler: checkArtifactExistsHandler(options),\n  });\n\n  app.get(\"download-artifact\", {\n    route: \"/v8/artifacts/{hash}\",\n    handler: downloadArtifactHandler(options),\n  });\n\n  app.put(\"upload-artifact\", {\n    route: \"/v8/artifacts/{hash}\",\n    handler: uploadArtifactHandler(options),\n  });\n\n  app.post(\"record-usage-events\", {\n    route: \"/v8/artifacts/events\",\n    handler: recordUsageEventsHandler(options),\n  });\n\n  app.get(\"openapi-spec\", {\n    route: \"/v8/openapi\",\n    handler: () => {\n      const headers = new Headers();\n      headers.set(\"location\", \"https://turborepo.com/api/remote-cache-spec\");\n      return { status: 308, headers };\n    },\n  });\n}\n"],"mappings":";;;;;;;;;;;;;;;AA0BA,SAAgB,oBAAoBA,UAAsC,CAAE,GAAE;CAC5E,MAAM,EAAE,aAAa,GAAG;CAExB,IAAI,MAAM,EAAE,kBAAkB,KAAM,EAAC;AAErC,KAAI,gBAAgB,OAClB,IAAI,IAAI,gBAAgB;EACtB,OAAO,OAAO,gBAAgB,WAAW,cAAc;EACvD,SAAS,aAAa;GACpB,MAAM,CAAC,yCAAyC,CAAC;GACjD,QAAQ;EACT;CACF,EAAC;CAGJ,IAAI,IAAI,wBAAwB;EAC9B,OAAO;EACP,SAAS,0BAA0B,QAAQ;CAC5C,EAAC;CAEF,IAAI,KAAK,wBAAwB;EAC/B,OAAO;EACP,SAAS,0BAA0B,QAAQ;CAC5C,EAAC;CAEF,IAAI,KAAK,yBAAyB;EAChC,SAAS,CAAC,MAAO;EACjB,OAAO;EACP,SAAS,2BAA2B,QAAQ;CAC7C,EAAC;CAEF,IAAI,IAAI,qBAAqB;EAC3B,OAAO;EACP,SAAS,wBAAwB,QAAQ;CAC1C,EAAC;CAEF,IAAI,IAAI,mBAAmB;EACzB,OAAO;EACP,SAAS,sBAAsB,QAAQ;CACxC,EAAC;CAEF,IAAI,KAAK,uBAAuB;EAC9B,OAAO;EACP,SAAS,yBAAyB,QAAQ;CAC3C,EAAC;CAEF,IAAI,IAAI,gBAAgB;EACtB,OAAO;EACP,SAAS,MAAM;GACb,MAAM,UAAU,IAAI;GACpB,QAAQ,IAAI,YAAY,8CAA8C;AACtE,UAAO;IAAE,QAAQ;IAAK;GAAS;EAChC;CACF,EAAC;AACH"}