{"version":3,"file":"elastic.mjs","names":[],"sources":["../src/modules/elastic/methods.ts"],"sourcesContent":["import { client } from '~/lib/fetch';\nimport type { ApiResponse } from '~/lib/api';\n\nimport { assignPermission } from '~/helpers/permissions/decorator';\n\nimport type { Namespace } from '~/modules/namespaces/types';\n\nimport type { Index, Mapping } from './types';\n\n/**\n * List all available indices\n *\n * Providing a query will resolve it\n *\n * @param namespace The concerned namespace. **Needed if not admin**\n *\n * @returns The list of available indices\n */\nexport async function getAllIndices(\n  namespaceOrId?: Namespace | string,\n  query?: string\n): Promise<Index[]> {\n  const namespaceId =\n    typeof namespaceOrId === 'string' ? namespaceOrId : namespaceOrId?.id;\n\n  const { content } = await client.fetch<ApiResponse<Index[]>>(\n    '/elastic/indices',\n    {\n      query: {\n        query: query || undefined,\n        namespaceId: namespaceId || undefined,\n      },\n    }\n  );\n\n  return content;\n}\nassignPermission(getAllIndices, 'GET /elastic/indices', true);\n\n/**\n * Get mapping of an specific index\n *\n * @param index The index (can be a wildcard)\n * @param namespace The concerned namespace. **Needed if not admin**\n *\n * @returns The list of available indices\n */\n\nexport async function getIndexMapping(\n  index: string,\n  namespaceOrId?: Namespace | string\n): Promise<Mapping> {\n  const namespaceId =\n    typeof namespaceOrId === 'string' ? namespaceOrId : namespaceOrId?.id;\n\n  const { content } = await client.fetch<ApiResponse<Mapping>>(\n    `/elastic/indices/${index}`,\n    {\n      query: { namespaceId: namespaceId || undefined },\n    }\n  );\n\n  return content;\n}\nassignPermission(getIndexMapping, 'GET /elastic/indices/:index', true);\n"],"mappings":";;;;;;;;;;;;;;AAkBA,SAAsB,cACpB,IACA;;;;+CADA,eACA,OACkB;EAClB,MAAM,cACJ,OAAO,kBAAkB,WAAW,8EAAgB,cAAe;EAErE,MAAM,EAAE,kBAAkB,OAAO,MAC/B,oBACA,EACE,OAAO;GACL,OAAO,SAAS;GAChB,aAAa,eAAe;GAC7B,EACF,CACF;AAED,SAAO;;;;AAET,iBAAiB,eAAe,wBAAwB,KAAK;;;;;;;;;AAW7D,SAAsB,gBACpB,KACA;;;;iDADA,OACA,eACkB;EAClB,MAAM,cACJ,OAAO,kBAAkB,WAAW,8EAAgB,cAAe;EAErE,MAAM,EAAE,kBAAkB,OAAO,MAC/B,oBAAoB,SACpB,EACE,OAAO,EAAE,aAAa,eAAe,QAAW,EACjD,CACF;AAED,SAAO;;;;AAET,iBAAiB,iBAAiB,+BAA+B,KAAK"}