import { Observable, ReplaySubject, type Subscription as ObservableSubscription } from 'rxjs'; import type { DataSource, ObservableData } from '@splunk/datasources'; import type { DataSourceDefinition, DataSourceMeta, RequestParams, RootDataSourcesDefinition, BroadcastEventCallback, BroadcastEventArgs, SearchCapabilityGate, PresetUtility, ErrorPayload, SearchControlAction, JobStatus } from '@splunk/dashboard-types'; import Subscription from './Subscription'; import RefreshScheduler from './RefreshScheduler'; import type RiskyCommandController from './RiskyCommandController'; type RefreshConfig = { refresh?: string | number; refreshType?: string; [key: string]: unknown; }; export type ExtendedDataSource = DataSource & { completeSearchQuery?: string; getRefreshConfig?: () => RefreshConfig; getMetaData?: () => DataSourceMeta; }; type SearchCapabilityGates = { autoRefresh?: SearchCapabilityGate; [key: string]: SearchCapabilityGate | undefined; }; type DataSourceControllerContext = { enableRiskyCommand?: boolean; capabilities?: SearchCapabilityGates; [key: string]: unknown; }; type ReplaySubjectInterface = { meta?: DataSourceMeta; error?: ErrorPayload; }; export interface ControlOptionTypes { checkIfInUse?: boolean; } /** * A control wrapper on top of actual DataSource instance */ declare class DataSourceController { id: string; baseChainModel?: RootDataSourcesDefinition; consumerIds: Set; context?: DataSourceControllerContext; dataSource?: ExtendedDataSource; dataSourceEventCallback?: BroadcastEventCallback; dataSourceSubs: Map; def: DataSourceDefinition & ReplaySubjectInterface; enableRiskyCommand: boolean; handleSubscriptionCancelOverride?: boolean; parent?: DataSourceController; children: DataSourceController[]; parentDataSourceSub: Subscription | null; parentStatusSub: ObservableSubscription | null; preset: PresetUtility; query: string | undefined; refreshing?: boolean; riskyCommandController?: RiskyCommandController; scheduler?: RefreshScheduler; setupOnce: () => Promise; setupError: string | null; subs: Map; statusSubject: ReplaySubject; teardownCallback?: () => void; additionalDataSourceIds: Set; private isSetup; private status?; /** * * @param {o.String} id DataSource Id * @param {o.Object} dataSourceDef DataSource definition * @param {o.Object} dataSourceContext DataSource context * @param {o.Object} preset dashboard preset * @param {o.Object} riskyCommandController RiskyCommandController */ constructor({ id, dataSourceDef, dataSourceContext, preset, riskyCommandController, }: { id: string; dataSourceDef: DataSourceDefinition; dataSourceContext?: DataSourceControllerContext; preset: PresetUtility; riskyCommandController?: RiskyCommandController; }); /** * Check if a gated capability is allowed. Calls onReject if not. * @param definition - Optional override; when provided (e.g. with decorated options for autoRefresh), * the gate receives this instead of this.def so it can make environment-aware decisions. * @returns true if allowed, false if rejected */ private checkCapability; /** * setup DataSource auto refresh * Checks capability gate before setting up auto refresh. * If gate check fails, will not setup auto refresh and teardown existing scheduler if it exists. */ setupAutoRefresh(): void; /** * get existing additional datasource ids * @returns {Set} additional Datasource Ids */ getAdditionalDataSourceIds(): DataSourceController['additionalDataSourceIds']; /** * get existing subscriptions * @returns {Map} subscriptions */ getSubscriptions: () => DataSourceController["subs"]; /** * Get a specific subscription * @param {string} consumerId identifier for the consumer+binding * @returns {Subscription | undefined} */ getSubscription(consumerId: string): Subscription | undefined; /** * get existing data source subscriptions * @returns {Map} data source subscriptions */ getDataSourceSubscriptions: () => DataSourceController["dataSourceSubs"]; get completeSearchQuery(): string; /** * check if a consumer is subscribed to this data source controller * @param {String} consumerId * @returns {Boolean} */ isSubscribed(consumerId: string): boolean; /** * check if viz or input is attached to the data source * @returns {Boolean} */ isVizOrInputAttached: () => boolean; /** * setup DataSource */ setup: () => Promise; /** * teardown DataSource */ teardown: () => Promise; /** * Refresh the base data source, if has parent subscription, otherwise refresh current data source * @param {Boolean} checkRiskyCommand optional, by default assuming all searches are risky */ refresh: ({ checkRiskyCommand }?: { checkRiskyCommand?: boolean | undefined; }) => Promise; /** * reset the current DataSource */ reset: () => Promise; /** * refresh all subscriptions */ refreshSubscriptions(): void; /** * additional dataSource Ids * @param dataSourceId */ addAdditionalDataSourceId: (dataSourceId: string) => void; /** * broadcast a DataSource event * @param {Object} event DataSource lifecycle event */ broadcast: (event: BroadcastEventArgs) => void; /** * register teardown callback * @param {Function} teardownCallback teardown callback */ onTeardown: (teardownCallback: () => void) => void; /** * register DataSource event callback * @param {Function} eventCallback callback */ onDataSourceEvent: (eventCallback: (args: BroadcastEventArgs) => void) => void; /** * handle subscription cancel * @param {String} consumerId DataSource consumerId, this will either be viz or input id */ handleSubscriptionCancel: (consumerId: string) => void; handleSubscriptionStart: () => void; handleSubscriptionComplete: () => void; /** * request a new dataset * @param {Object} requestParams requestParams * @returns {Observable} Observable instance that will emit data or error */ request: (requestParams?: RequestParams) => Observable; /** * create a new DataSource subscription * @param {String} consumerId DataSource consumerId, this will either be viz or input id * @param {Object} initialRequestParams initial requestParams * @param {Boolean} isDataSource * @returns {Subscription} DataSource subscription */ subscribe: ({ consumerId, initialRequestParams, isDataSource, }: { consumerId: string; initialRequestParams?: RequestParams; isDataSource?: boolean; }) => Promise; /** * pause a running DataSource */ pause({ checkIfInUse }?: ControlOptionTypes): Promise; /** * resume a paused DataSource */ resume(): Promise; /** * finalize a DataSource */ finalize(): Promise; /** * Control the datasource. If action is `togglePause` then this will call either * `pause` or `resume` in order to toggle between a paused and running state */ control(action: SearchControlAction): Promise; /** * Handle propagation of control flows through a chain: * 1. Update the status value of the current controller * 2. Exercise the control action upon the parent data subscription * 3. For all subscribers to the controller exercise the control flow (broadcast control event) * 4. For all children to the controller repeat these steps (propagation from base --> bottom) * 5. If not the base search controller then invoke action on search implementation * @see {@link Subscription.control} - The `Subscription` control method called during steps 2 and 3 */ private notifyChainOfControlAction; /** * get DataSource metadata * @returns {Object} DataSource meta data */ getDataSourceMetaData: () => DataSourceMeta; /** * Subscribe to parent data source controller */ subscribeToParentDataSourceController(): Promise; /** * Generate the id and definition data */ getIdAndDefinition(): { id: string; definition: DataSourceController['def']; }; /** * Sets the current parent in the data source * @param {DataSourceController} parent */ setParent(parent: DataSourceController): void; /** * Get the current JobStatus of the data source */ getStatus(): JobStatus | undefined; /** * Get if the data source is finalizing */ isFinalizing(): boolean; /** * Get if the data source is paused */ isPaused(): boolean; /** * Get if the base data source is paused */ isParentPaused(): boolean; /** * @deprecated use isParentPaused() instead. * Get if the base data source is paused */ getPauseStatus(): boolean; /** * Return `true` if the search implementation reports support for * control actions or the controller has an associated scheduler */ supportsControlActions(action?: SearchControlAction): boolean; getStatusObservable(): DataSourceController['statusSubject']; /** * Get the base data source for the current one */ getBase(): DataSourceController; /** * Set the base chain model * @param {Object} baseChainModel */ setBaseChainModel(baseChainModel: RootDataSourcesDefinition): void; /** * Function to determine if consumer id has previously subscribed * @param {String} consumerId * @returns {Boolean} */ isConsumerSubscribedBefore(consumerId: string): boolean; /** * Function to override handleSubscriptionCancel */ setHandleSubscriptionCancelOverride(): void; } export default DataSourceController; //# sourceMappingURL=DataSourceController.d.ts.map