import { Context, Path, Timestamp } from '.'; import { Temporal } from '@js-temporal/polyfill'; /** * Method for aggregating historical data points within a time bucket. * * - `average`: Mean of all values in the bucket * - `min`: Minimum value * - `max`: Maximum value * - `first`: First value chronologically * - `last`: Last value chronologically * - `mid`: Midpoint between min and max: (min + max) / 2 * - `middle_index`: Value at the middle index position * - `sma`: Simple Moving Average with number of samples specified in the parameter array (e.g., sma:5 for 5-sample SMA) * - `ema`: Exponential Moving Average with alpha specified in the parameter array (e.g., ema:0.2 for alpha=0.2 EMA) */ export type AggregateMethod = 'average' | 'min' | 'max' | 'first' | 'last' | 'mid' | 'middle_index' | 'sma' | 'ema'; export type ValueList = { path: Path; method: AggregateMethod; }[]; /** * A row of historical data: first element is timestamp, followed by aggregated values. * Values can be primitives, objects (like navigation.position), or null depending on the path. */ export type DataRow = [Timestamp, ...unknown[]]; export interface ValuesResponse { context: Context; range: { from: Timestamp; to: Timestamp; }; values: ValueList; data: DataRow[]; } export type TimeRangeQueryParams = { duration: number | string; from?: never; to?: never; } | { duration: number | string; from: string; to?: never; } | { duration: number | string; from?: never; to: string; } | { duration?: never; from: string; to?: never; } | { duration?: never; from: string; to: string; }; export type ValuesRequestQueryParams = TimeRangeQueryParams & { context?: string; resolution?: number; }; export type PathsRequestQueryParams = TimeRangeQueryParams; export type PathsResponse = Path[]; export type ContextsRequestQueryParams = TimeRangeQueryParams; export type ContextsResponse = Context[]; /** @category History API */ export type HistoryProviderRegistry = { registerHistoryApiProvider(provider: HistoryProvider): void; unregisterHistoryApiProvider(): void; }; /** * @deprecated Use {@link HistoryProviderRegistry} instead. * @category History API */ export type HistoryApiRegistry = HistoryProviderRegistry; /** @category History API */ export type WithHistoryApi = { /** * Returns a promise for a History API implementation, or rejects if unavailable. * The property is optional to support explicitly older servers that do not have a history api provider. * * When called without arguments, returns a proxy to the default provider. * When called with a provider id, returns that specific provider's HistoryApi instance. * * @param providerId - Optional id of a specific history provider plugin. If omitted, returns the default provider. * @returns Promise that resolves to a {@link HistoryApi} instance if available, or rejects with an error if not. */ getHistoryApi?: (providerId?: string) => Promise; }; /** * Provider interface for the History API. * * Plugins that supply historical data implement this interface and register * it via {@link HistoryProviderRegistry.registerHistoryApiProvider}. * * @category History API */ export type HistoryProvider = HistoryApi; /** @category History API */ export interface HistoryApi { /** * Retrieves historical values for the specified query parameters. * * For aggregation methods that require parameters (sma, ema), implementations should use sensible defaults * if the parameter array is empty in the PathSpec. For example: sma could default to 5 samples, ema could default to 0.2 alpha. * * @param query - The {@link ValuesRequest} containing context, time range, resolution, and path specifications. * @returns A promise that resolves to a {@link ValuesResponse} containing the requested historical data. */ getValues(query: ValuesRequest): Promise; /** * Lists available contexts for which historical data can be queried. * * @param query - The {@link ContextsRequest} specifying time range and filters. * @returns A promise that resolves to a {@link ContextsResponse} array of available contexts. */ getContexts(query: ContextsRequest): Promise; /** * Lists available paths for historical data queries. * * @param query - The {@link PathsRequest} specifying time range and filters. * @returns A promise that resolves to a {@link PathsResponse} array of available paths. */ getPaths(query: PathsRequest): Promise; } export declare function isHistoryProvider(obj: unknown): obj is HistoryProvider; /** * @deprecated Use {@link isHistoryProvider} instead. */ export declare const isHistoryApi: typeof isHistoryProvider; /** * @hidden visible through ServerAPI * @category History API */ export interface HistoryProviders { [pluginId: string]: { isDefault: boolean; }; } /** * Represents a time duration, either as a {@link Temporal.Duration} object or a number (seconds). * * @example * // Using Temporal.Duration * const duration: Duration = Temporal.Duration.from({ minutes: 5 }); * * // Using seconds * const duration: Duration = 300; // 5 minutes in seconds */ export type Duration = Temporal.Duration | number; export type TimeRangeParams = { duration: Temporal.Duration; from?: never; to?: never; } | { duration: Duration; from: Temporal.Instant; to?: never; } | { duration: Duration; from?: never; to: Temporal.Instant; } | { duration?: never; from: Temporal.Instant; to?: never; } | { duration?: never; from: Temporal.Instant; to: Temporal.Instant; }; export interface PathSpec { path: Path; aggregate: AggregateMethod; parameter: string[]; } export type ValuesRequest = TimeRangeParams & { context?: Context; resolution?: number; pathSpecs: PathSpec[]; }; export type PathsRequest = TimeRangeParams; export type ContextsRequest = TimeRangeParams; //# sourceMappingURL=history.d.ts.map