UNPKG

@grafana/runtime

Version:
1 lines 2.47 kB
{"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;AAYG,MAAM,qBAAA,GAAwB,CAAC,QAAA,KAAuC;AAC3E,EAAA,IAAI,OAAA,EAAS;AACX,IAAA,MAAM,IAAI,MAAM,qDAAqD,CAAA;AAAA,EACvE;AACA,EAAA,OAAA,GAAU,QAAA;AACZ;AAQO,MAAM,oBAAoB,MAAmB;AAClD,EAAA,IAAI,CAAC,OAAA,EAAS;AACZ,IAAA,MAAM,IAAI,MAAM,0EAA0E,CAAA;AAAA,EAC5F;AACA,EAAA,OAAO,OAAA,EAAQ;AACjB;AAQA,IAAI,UAAA;AAOG,SAAS,cAAc,EAAA,EAAwB;AACpD,EAAA,IAAI,UAAA,IAAc,OAAA,CAAQ,GAAA,CAAI,QAAA,KAAa,MAAA,EAAQ;AACjD,IAAA,MAAM,IAAI,MAAM,wEAAwE,CAAA;AAAA,EAC1F;AACA,EAAA,UAAA,GAAa,EAAA;AACf;AAEO,SAAS,aAAA,GAA8B;AAC5C,EAAA,IAAI,CAAC,UAAA,EAAY;AACf,IAAA,MAAM,IAAI,MAAM,oEAAoE,CAAA;AAAA,EACtF;AACA,EAAA,OAAO,UAAA;AACT;;;;"}