/** * Tinybird client for querying pipes and ingesting events */ import type { ClientConfig, ClientContext, DatasourcesNamespace, QueryResult, IngestResult, QueryOptions, IngestOptions } from "./types.js"; import { TokensNamespace } from "./tokens.js"; /** * Tinybird API client * * Provides methods for querying pipe endpoints and ingesting events to datasources. * * @example * ```ts * import { TinybirdClient } from '@tinybirdco/sdk'; * * const client = new TinybirdClient({ * baseUrl: 'https://api.tinybird.co', * token: process.env.TINYBIRD_TOKEN, * }); * * // Query a pipe * const result = await client.query('top_events', { * start_date: '2024-01-01', * end_date: '2024-01-31', * }); * * // Ingest an event * await client.ingest('events', { * timestamp: '2024-01-15 10:30:00', * event_type: 'page_view', * user_id: 'user_123', * }); * ``` */ export declare class TinybirdClient { private readonly config; private readonly apisByToken; private contextPromise; private resolvedContext; /** * Datasources namespace for ingest and import operations */ readonly datasources: DatasourcesNamespace; /** Token operations (JWT creation, etc.) */ readonly tokens: TokensNamespace; constructor(config: ClientConfig); /** * Append data to a datasource from a URL or local file * * @param datasourceName - Name of the datasource * @param options - Append options including url or file source * @returns Append result * * @example * ```ts * // Append from URL * await client.datasources.append('events', { * url: 'https://example.com/data.csv', * }); * * // Append from local file * await client.datasources.append('events', { * file: './data/events.ndjson', * }); * ``` */ private appendDatasource; /** * Replace datasource rows from a URL or local file * * @param datasourceName - Name of the datasource * @param options - Replace options including url or file source * @returns Append-style result */ private replaceDatasource; /** * Delete rows from a datasource using a SQL condition * * @param datasourceName - Name of the datasource * @param options - Delete options including deleteCondition * @returns Delete job result */ private deleteDatasource; /** * Truncate all rows from a datasource * * @param datasourceName - Name of the datasource * @param options - Truncate options * @returns Truncate result */ private truncateDatasource; /** * Ingest a single event to a datasource * * @param datasourceName - Name of the datasource * @param event - Event data to ingest * @param options - Additional request options * @returns Ingest result */ private ingestDatasource; /** * Get the effective token, resolving branch token in dev mode if needed */ private getToken; /** * Resolve the client context, including branch token resolution in dev mode * This is the single source of truth for all context data */ private resolveContext; /** * Build the client context from resolved token info */ private buildContext; /** * Resolve the branch context in dev mode */ private resolveBranchContext; /** * Query a pipe endpoint * * @param pipeName - Name of the pipe to query * @param params - Query parameters * @param options - Additional request options * @returns Query result with typed data */ query(pipeName: string, params?: Record, options?: QueryOptions): Promise>; /** * Ingest a single event to a datasource * * @param datasourceName - Name of the datasource * @param event - Event data to ingest * @param options - Additional request options * @returns Ingest result */ ingest>(datasourceName: string, event: T, options?: IngestOptions): Promise; /** * Ingest multiple events to a datasource * * @param datasourceName - Name of the datasource * @param events - Array of events to ingest * @param options - Additional request options * @returns Ingest result */ ingestBatch>(datasourceName: string, events: T[], options?: IngestOptions): Promise; /** * Execute a raw SQL query * * @param sql - SQL query to execute * @param options - Additional request options * @returns Query result */ sql(sql: string, options?: QueryOptions): Promise>; /** * Get the current client context * * Returns information about the resolved configuration including the token being used, * API URL, dev mode status, and branch information. * * @returns Client context with resolved configuration * * @example * ```ts * const client = createClient({ * baseUrl: 'https://api.tinybird.co', * token: process.env.TINYBIRD_TOKEN, * devMode: true, * }); * * const context = await client.getContext(); * console.log(context.branchName); // 'feature_my_branch' * console.log(context.isBranchToken); // true * ``` */ getContext(): Promise; private getApi; private rethrowApiError; } /** * Create a Tinybird client * * @param config - Client configuration * @returns Configured Tinybird client * * @example * ```ts * import { createClient } from '@tinybirdco/sdk'; * * const client = createClient({ * baseUrl: process.env.TINYBIRD_URL, * token: process.env.TINYBIRD_TOKEN, * }); * ``` */ export declare function createClient(config: ClientConfig): TinybirdClient; //# sourceMappingURL=base.d.ts.map