UNPKG

@grafana/runtime

Version:
1 lines 2.93 kB
{"version":3,"file":"live.mjs","sources":["../../../src/services/live.ts"],"sourcesContent":["import { Observable } from 'rxjs';\n\nimport {\n DataFrameJSON,\n DataQueryRequest,\n DataQueryResponse,\n LiveChannelAddress,\n LiveChannelEvent,\n LiveChannelPresenceStatus,\n StreamingFrameOptions,\n} from '@grafana/data';\n\n/**\n * @alpha -- experimental\n */\nexport interface LiveDataFilter {\n fields?: string[];\n}\n\n// StreamingFrameAction and StreamingFrameOptions are now in @grafana/data\nexport { StreamingFrameAction, type StreamingFrameOptions } from '@grafana/data';\n\n/**\n * @alpha\n */\nexport interface LiveDataStreamOptions {\n addr: LiveChannelAddress;\n frame?: DataFrameJSON; // initial results\n key?: string;\n buffer?: Partial<StreamingFrameOptions>;\n filter?: LiveDataFilter;\n}\n\n/**\n * @alpha -- experimental: send a normal query request over websockt\n */\nexport interface LiveQueryDataOptions {\n request: DataQueryRequest;\n body: unknown; // processed queries, same as sent to `/api/query/ds`\n}\n\n/**\n * @alpha -- experimental\n */\nexport interface LivePublishOptions {\n /**\n * Publish the data over the websocket instead of the HTTP API.\n *\n * This is not recommended for most use cases.\n *\n * @experimental\n */\n useSocket?: boolean;\n}\n\n/**\n * @alpha -- experimental\n */\nexport interface GrafanaLiveSrv {\n /**\n * Listen for changes to the main service\n */\n getConnectionState(): Observable<boolean>;\n\n /**\n * Watch for messages in a channel\n */\n getStream<T>(address: LiveChannelAddress): Observable<LiveChannelEvent<T>>;\n\n /**\n * Connect to a channel and return results as DataFrames\n */\n getDataStream(options: LiveDataStreamOptions): Observable<DataQueryResponse>;\n\n /**\n * For channels that support presence, this will request the current state from the server.\n *\n * Join and leave messages will be sent to the open stream\n */\n getPresence(address: LiveChannelAddress): Promise<LiveChannelPresenceStatus>;\n\n /**\n * Publish into a channel\n *\n * @alpha -- experimental\n */\n publish(address: LiveChannelAddress, data: unknown, options?: LivePublishOptions): Promise<unknown>;\n}\n\nlet singletonInstance: GrafanaLiveSrv;\n\n/**\n * Used during startup by Grafana to set the GrafanaLiveSrv so it is available\n * via the {@link getGrafanaLiveSrv} to the rest of the application.\n *\n * @internal\n */\nexport const setGrafanaLiveSrv = (instance: GrafanaLiveSrv) => {\n singletonInstance = instance;\n};\n\n/**\n * Used to retrieve the GrafanaLiveSrv that allows you to subscribe to\n * server side events and streams\n *\n * @alpha -- experimental\n */\nexport const getGrafanaLiveSrv = (): GrafanaLiveSrv => singletonInstance;\n"],"names":[],"mappings":";;;AAyFA,IAAI,iBAAA;AAQG,MAAM,iBAAA,GAAoB,CAAC,QAAA,KAA6B;AAC7D,EAAA,iBAAA,GAAoB,QAAA;AACtB;AAQO,MAAM,oBAAoB,MAAsB;;;;"}