/** * Neon API Client * * A thin, dependency-free wrapper over the Neon REST API (v2) covering the * branch-canary orchestration surface: create a copy-on-write branch, resolve * a branch's connection string, diff a branch's schema against its parent, and * delete the branch. * * The underlying HTTP transport is INJECTABLE (`fetch`) so the canary * orchestration can be unit-tested with a mocked Neon — no live token, no * network. In production the global `fetch` is used. * * API reference: https://api-docs.neon.tech/reference/getting-started-with-neon-api * Auth: `Authorization: Bearer `. */ /** * The subset of the global `fetch` contract this client relies on. Typing it * as `typeof fetch` lets production pass the real global unchanged while tests * hand in a stub that returns ordinary `Response` objects. */ export type FetchLike = typeof fetch; /** * Neon's default REST base. Override via `NEON_API_BASE` (or the constructor) * for Neon-compatible proxies or a future host. Both `console.neon.tech` and * `api.neon.tech` front the same v2 API; `console.neon.tech` is the one the * public docs curl against, so it's the default. */ export declare const DEFAULT_NEON_API_BASE = "https://console.neon.tech/api/v2"; export interface NeonClientOptions { apiKey: string; projectId: string; /** Injectable HTTP transport. Defaults to the global `fetch`. */ fetch?: FetchLike; /** REST base URL. Defaults to {@link DEFAULT_NEON_API_BASE}. */ baseUrl?: string; } /** A Neon branch as returned by the branches endpoints (fields we consume). */ export interface NeonBranch { id: string; project_id: string; parent_id?: string; name: string; current_state?: string; created_at?: string; } /** An endpoint (compute) attached to a branch. */ export interface NeonEndpoint { id: string; branch_id: string; host: string; type: string; } export interface CreateBranchResult { branchId: string; branch: NeonBranch; endpoints: NeonEndpoint[]; /** * Connection URIs Neon minted alongside the branch. Present only when the * create request asked for an endpoint; each entry is a ready-to-use * `postgresql://…` string for one (role, database) pair. */ connectionUris: Array<{ connection_uri: string; connection_parameters?: Record; }>; } export interface CreateBranchParams { /** Human/CI-friendly branch name (e.g. `canary/production-1720…`). */ name: string; /** * Parent branch to fork from, by Neon branch id. When omitted Neon forks * from the project's default branch. Resolve a name to an id first with * {@link NeonClient.getBranchByName}. */ parentBranchId?: string; /** * Point-in-time to fork from. Omit for "latest". A canary wants the current * head of the parent, so this is normally left unset. */ parentLsn?: string; parentTimestamp?: string; /** * Attach a read-write compute so the branch is immediately connectable and * migratable. Defaults to `true` — a canary is useless without a compute. */ withEndpoint?: boolean; } export interface ConnectionStringParams { branchId: string; /** Postgres database name. Neon's default is `neondb`. */ database?: string; /** Role to connect as. Neon's default owner role varies per project. */ role?: string; /** Return the pooled (PgBouncer) URI. Defaults to `false` (direct). */ pooled?: boolean; } export interface SchemaDiffParams { /** Branch whose schema is the "new" side of the diff. */ branchId: string; /** Base branch to diff against. Defaults to the branch's own parent. */ baseBranchId?: string; /** Database to compare. Defaults to `neondb`. */ database?: string; } /** Structured error carrying Neon's HTTP status + response body for triage. */ export declare class NeonApiError extends Error { readonly status: number; readonly method: string; readonly path: string; readonly body: string; constructor(method: string, path: string, status: number, body: string, message?: string); } export declare class NeonClient { private readonly apiKey; private readonly projectId; private readonly fetch; private readonly baseUrl; constructor(options: NeonClientOptions); getProjectId(): string; /** * Issue a request against the Neon REST API. `path` is relative to the * project (e.g. `/branches`); it's expanded to * `${baseUrl}/projects/${projectId}${path}`. Non-2xx responses throw a * {@link NeonApiError}. */ private request; /** List all branches in the project. */ listBranches(): Promise; /** Find a branch by its (non-unique in theory, unique in practice) name. */ getBranchByName(name: string): Promise; /** * Create a copy-on-write branch. When `withEndpoint` (default true) a * read-write compute is attached so the branch is immediately connectable; * the response's `connectionUris` then carry ready-to-use URIs. */ createBranch(params: CreateBranchParams): Promise; /** * Resolve a connection string for a branch. Returns a `postgresql://…` URI. * Neon requires `database_name` and `role_name`; sensible Neon defaults are * applied when the caller doesn't specify them. */ getConnectionString(params: ConnectionStringParams): Promise; /** * Diff a branch's schema against a base branch. Returns the DDL diff Neon * computes (unified-diff text of the two schemas' `pg_dump --schema-only`). * An empty string means the schemas are identical. */ schemaDiff(params: SchemaDiffParams): Promise; /** Delete a branch (and its computes). Idempotent-ish: 404s throw. */ deleteBranch(branchId: string): Promise; } //# sourceMappingURL=neon.d.ts.map