@grafana/runtime
Version:
Grafana Runtime Library
1 lines • 2.45 kB
Source Map (JSON)
{"version":3,"file":"QueryRunner.mjs","sources":["../../../src/services/QueryRunner.ts"],"sourcesContent":["import { Observable } from 'rxjs';\n\nimport { DataQueryRequest, DataSourceApi, PanelData, QueryRunner } from '@grafana/data';\n\nlet factory: QueryRunnerFactory | undefined;\n\n/**\n * @internal\n */\nexport type QueryRunnerFactory = () => QueryRunner;\n\n/**\n * Used to bootstrap the {@link createQueryRunner} during application start.\n *\n * @internal\n */\nexport const setQueryRunnerFactory = (instance: QueryRunnerFactory): void => {\n if (factory) {\n throw new Error('Runner should only be set when Grafana is starting.');\n }\n factory = instance;\n};\n\n/**\n * Used to create QueryRunner instances from outside the core Grafana application.\n * This is helpful to be able to create a QueryRunner to execute queries in e.g. an app plugin.\n *\n * @internal\n */\nexport const createQueryRunner = (): QueryRunner => {\n if (!factory) {\n throw new Error('`createQueryRunner` can only be used after Grafana instance has started.');\n }\n return factory();\n};\n\ntype RunRequestFn = (\n datasource: DataSourceApi,\n request: DataQueryRequest,\n queryFunction?: typeof datasource.query\n) => Observable<PanelData>;\n\nlet runRequest: RunRequestFn | undefined;\n\n/**\n * Used to exspose runRequest implementation to libraries, i.e. @grafana/scenes\n *\n * @internal\n */\nexport function setRunRequest(fn: RunRequestFn): void {\n if (runRequest && process.env.NODE_ENV !== 'test') {\n throw new Error('runRequest function should only be set once, when Grafana is starting.');\n }\n runRequest = fn;\n}\n\nexport function getRunRequest(): RunRequestFn {\n if (!runRequest) {\n throw new Error('getRunRequest can only be used after Grafana instance has started.');\n }\n return runRequest;\n}\n"],"names":[],"mappings":"AAIA,IAAI,OAAA;AAYS,MAAA,qBAAA,GAAwB,CAAC,QAAuC,KAAA;AAC3E,EAAA,IAAI,OAAS,EAAA;AACX,IAAM,MAAA,IAAI,MAAM,qDAAqD,CAAA;AAAA;AAEvE,EAAU,OAAA,GAAA,QAAA;AACZ;AAQO,MAAM,oBAAoB,MAAmB;AAClD,EAAA,IAAI,CAAC,OAAS,EAAA;AACZ,IAAM,MAAA,IAAI,MAAM,0EAA0E,CAAA;AAAA;AAE5F,EAAA,OAAO,OAAQ,EAAA;AACjB;AAQA,IAAI,UAAA;AAOG,SAAS,cAAc,EAAwB,EAAA;AACpD,EAAA,IAAI,UAAc,IAAA,OAAA,CAAQ,GAAI,CAAA,QAAA,KAAa,MAAQ,EAAA;AACjD,IAAM,MAAA,IAAI,MAAM,wEAAwE,CAAA;AAAA;AAE1F,EAAa,UAAA,GAAA,EAAA;AACf;AAEO,SAAS,aAA8B,GAAA;AAC5C,EAAA,IAAI,CAAC,UAAY,EAAA;AACf,IAAM,MAAA,IAAI,MAAM,oEAAoE,CAAA;AAAA;AAEtF,EAAO,OAAA,UAAA;AACT;;;;"}