import type { ApiRequestOptions, Prettify } from "@trigger.dev/core/v3"; export type { QueryTable, RunsTableRow, RunFriendlyStatus } from "@trigger.dev/core/v3"; export type QueryScope = "environment" | "project" | "organization"; export type QueryFormat = "json" | "csv"; /** * Options for executing a TRQL query */ export type QueryOptions = { /** * The scope of the query - determines what data is accessible * - "environment": Current environment only (default) * - "project": All environments in the project * - "organization": All projects in the organization * * @default "environment" */ scope?: QueryScope; /** * Time period to query (e.g., "7d", "30d", "1h") * Cannot be used with `from` or `to` */ period?: string; /** * Start of time range as a Date object or Unix timestamp in milliseconds. * Must be used with `to`. */ from?: Date | number; /** * End of time range as a Date object or Unix timestamp in milliseconds. * Must be used with `from`. */ to?: Date | number; /** * Response format * - "json": Returns structured data (default) * - "csv": Returns CSV string * * @default "json" */ format?: QueryFormat; }; /** * Execute a TRQL query and get the results as a CSV string. * * @param {string} query - The TRQL query string to execute * @param {QueryOptions & { format: "csv" }} options - Query options with `format: "csv"` * @param {ApiRequestOptions} [requestOptions] - Optional API request configuration * @returns A promise resolving to `{ format: "csv", results: string }` where `results` is the raw CSV text * * @example * ```typescript * const csvResult = await query.execute( * "SELECT run_id, status, triggered_at FROM runs", * { format: "csv", period: "7d" } * ); * const lines = csvResult.results.split('\n'); * ``` */ declare function execute(query: string, options: QueryOptions & { format: "csv"; }, requestOptions?: ApiRequestOptions): Promise<{ format: "csv"; results: string; }>; /** * Execute a TRQL query and return typed JSON rows. * * @template TRow - The shape of each row in the result set. Use {@link QueryTable} for type-safe column access (e.g. `QueryTable<"runs", "status" | "run_id">`) * @param {string} query - The TRQL query string to execute * @param {QueryOptions} [options] - Optional query configuration * @param {ApiRequestOptions} [requestOptions] - Optional API request configuration * @returns A promise resolving to `{ format: "json", results: Array }` * * @example * ```typescript * // Basic query with defaults (environment scope, json format) * const result = await query.execute("SELECT run_id, status FROM runs LIMIT 10"); * console.log(result.results); // Array> * * // Type-safe query using QueryTable with specific columns * const typedResult = await query.execute>( * "SELECT run_id, status, triggered_at FROM runs LIMIT 10" * ); * typedResult.results.forEach(row => { * console.log(row.run_id, row.status); // Fully typed! * }); * * // Inline type for aggregation queries * const stats = await query.execute<{ status: string; count: number }>( * "SELECT status, COUNT(*) as count FROM runs GROUP BY status" * ); * stats.results.forEach(row => { * console.log(row.status, row.count); // Fully type-safe * }); * * // Query with a custom time period * const recent = await query.execute( * "SELECT COUNT(*) as count FROM runs", * { period: "3d" } * ); * console.log(recent.results[0].count); * ``` */ declare function execute = Record>(query: string, options?: Omit | (QueryOptions & { format?: "json"; }), requestOptions?: ApiRequestOptions): Promise<{ format: "json"; results: Array>; }>; export declare const query: { execute: typeof execute; };