import type { DataRules } from "../data-streams/types"; export interface CostForecastRequest { as_of?: Date; details: ForecastDetails; } export interface ForecastRequest extends CostForecastRequest { /** Additional dimensions to compute alongside the forecast. */ dimensions?: ForecastDimensions; fingerprint?: string; skip_cache?: boolean; /** When true, schedules an unsampled forecast run in addition to the sampled one. */ schedule_unsampled_forecast?: boolean; } export type ForecastType = "marketplace" | "data_stream" | "data_stream_creation"; export type ForecastDetails = DataStreamPurchaseDetails | DataStreamCreationDetails | MarketplaceForecastDetails; export interface MarketplaceForecastDetails { type: "marketplace"; company_constraint?: CompanyConstraint; dataset_constraint?: DatasetConstraint; data_rules: DataRules; pricing: ForecastPricing; } export interface DataStreamPurchaseDetails { type: "data_stream"; data_stream_id: string; offer_id: string; data_shop_id?: string; } /** Details for forecasting the creation of a new data stream directly from a set of data rules. */ export interface DataStreamCreationDetails { type: "data_stream_creation"; data_rules: DataRules; } export type CompanyConstraintType = "inclusion" | "exclusion"; export interface CompanyConstraint { type: CompanyConstraintType; company_ids: number[]; } export type DatasetConstraintType = "inclusion" | "exclusion" | "all"; export interface DatasetConstraint { type: DatasetConstraintType; /** Required when `type` is `inclusion` or `exclusion`; unused for `all`. */ dataset_ids?: number[]; } export interface ForecastPricing { micro_cents_usd: number; } export interface ForecastGenericResponse { id: string; company_id: number; completed_at?: Date; created_at: Date; failures: JobFailure[]; idempotency_key: string; input: TInput; request_source: RequestSource; state: JobState; updated_at: Date; } export interface ForecastResponse extends ForecastGenericResponse { result?: ForecastResult | ForecastOverBudgetResult | ForecastResultFailure; } export interface CostForecastResponse extends ForecastGenericResponse { result?: CostForecastResult | ForecastResultFailure; } export interface CostForecastInput { details: ForecastDetails; } export interface ForecastInput { as_of?: Date; dimensions: ForecastDimensions; fingerprint?: string; } export interface RequestSource { type: string; company_id?: number; user_id?: number; } export interface ForecastDimensions { distinct_counts: string[]; group_by?: string; } export type JobState = "pending" | "scheduled" | "running" | "completed" | "pending_cancellation" | "cancelled" | "failed"; export interface ForecastResult { type: "success"; cost: number; datasets: DatasetForecastResponse[]; rows: number; scan_cost: ScanCostEstimate; } /** Returned instead of {@link ForecastResult} when the forecast exceeds the subscription's budget. */ export interface ForecastOverBudgetResult { type: "over_budget"; cost: ScanCostEstimate; } export interface CostForecastResult { cost: ScanCostEstimate; } export interface ForecastResultFailure { message: string; nql_type: string; type: string; } export interface DatasetForecastResponse { company_id: number; dataset_id: number; group?: string; cost: number; rows: number; } export interface ScanCostEstimate { rows: number; size: number; sources: DataSourceCost[]; } export interface DataSourceCost { source: DataSource; rows: number; size: number; } export type DataSource = DatasetSource | TableSource; export interface DatasetSource { type: "dataset"; dataset_id: number; } export interface TableSource { type: "table"; name: string; } export interface JobFailure { message?: string; timestamp?: Date; /** Free-form diagnostic information, e.g. an Apache Spark stacktrace. */ value?: Record; }