import { FunctionBundler } from "./function-bundle.js"; import { PulledBranchConfig } from "./pull-config.js"; import { PushConfigOptions } from "./push-config.js"; import { Config, NeonApi, PushResult } from "@neon/config"; //#region src/lib/operations.d.ts /** * Where to run the operation and how to authenticate. Filesystem- and env-agnostic: the * `projectId` and `branchId` are always passed explicitly by the caller (e.g. neonctl * resolves them from `.neon` / `NEON_*` and forwards them here). */ interface ConfigOperationOptions { /** * Neon project id. **Required** — the management API addresses branches through their * project, so operations cannot run without it. */ projectId: string; /** * Neon branch id (`br-…`). **Required.** Must already exist on the project; resolve * branch names to ids before calling. */ branchId: string; /** Neon API key. Falls back to `NEON_API_KEY` / neonctl credentials. */ apiKey?: string; /** Neon API base URL. Falls back to `NEON_API_HOST`, then production. */ apiHost?: string; /** Inject a custom NeonApi adapter (primarily for tests). */ api?: PushConfigOptions["api"]; } /** * Options accepted by {@link apply} on top of {@link ConfigOperationOptions}. */ interface ApplyOptions extends ConfigOperationOptions { /** * Auto-confirm overriding existing remote settings (TTL, `protected`, compute * settings) on the selected branch. Without it, drift is reported as a conflict. */ updateExisting?: boolean; /** Auto-confirm applying to a branch marked `protected` on Neon. */ allowProtectedBranch?: boolean; /** * Custom function bundler. Defaults to esbuild (`buildFunctionBundle`); inject * your own to deploy functions without pulling esbuild's native binary into * your build. See {@link FunctionBundler}. */ bundleFunction?: FunctionBundler; } /** * Read a branch's live Neon state as a plain object (project + branch metadata and the * reverse-engineered `BranchConfig`). Network read only — never mutates. * * `projectId` and `branchId` are **required** (both in `options`). */ declare function inspect(options: ConfigOperationOptions): Promise; /** * Compute what {@link apply} would do for the given branch without mutating anything * (dry-run plan). Returns the full {@link PushResult} with the planned changes in * `applied` and any blocking drift in `conflicts` — the Neon equivalent of * `terraform plan`. * * `projectId` and `branchId` are **required** (both in `options`). */ declare function plan(config: Config, options: ConfigOperationOptions): Promise; /** * Apply a `neon.ts` policy to the given Neon branch and return the {@link PushResult} * describing what changed — the Neon equivalent of `terraform apply`. * * `projectId` and `branchId` are **required** (both in `options`). Pass `updateExisting` * to auto-confirm overriding existing remote settings and `allowProtectedBranch` to * auto-confirm applying to a protected branch; otherwise drift is reported as a * `PushConflictError`. * * Never creates projects or branches — both must already exist. */ declare function apply(config: Config, options: ApplyOptions): Promise; /** * Options accepted by {@link createBranch}. Unlike {@link ConfigOperationOptions} this takes a * branch **name** (the branch does not exist yet) rather than an id. */ interface CreateBranchOptions { /** Neon project id to create the branch in. **Required.** */ projectId: string; /** Name of the branch to create. **Required.** Must not already exist on the project. */ branchName: string; /** Neon API key. Falls back to `NEON_API_KEY` / neonctl credentials. Ignored when `api` is set. */ apiKey?: string; /** Inject a custom NeonApi adapter (primarily for tests). */ api?: NeonApi; /** Custom function bundler (defaults to esbuild). See {@link FunctionBundler}. */ bundleFunction?: FunctionBundler; } /** * Result of {@link createBranch}: the created branch's id/name plus the {@link PushResult} * describing the policy that was applied to it. */ interface CreateBranchResult { branchId: string; branchName: string; /** What applying the policy to the freshly created branch changed. */ result: PushResult; } /** * Create a Neon branch **from a `neon.ts` policy** and bring it up with its declared * settings/infra in one step — the operation `neonctl checkout ` needs. * * The flow is the one a creation actually wants: * 1. Evaluate the policy for the new branch with `exists: false` (so creation-time tuning — * `parent`, `ttl`, compute settings, `protected` — resolves instead of the * "existing branch, leave as-is" path most policies guard with `if (branch.exists)`). * 2. Create the branch **with** that tuning: `parent`, `expires_at`, `protected`, and the * compute settings all ride along on the single create call, which Neon validates as a * whole. A setting it rejects therefore fails the creation outright, leaving nothing * behind, rather than producing a branch that doesn't match the policy. * 3. {@link pushConfig} the rest onto it with `branchExists: false` — the services (Neon * Auth, Data API, buckets, functions), which have no create-time equivalent because they * are provisioned against an existing branch id. * * This is why `apply` alone couldn't do it: `apply` operates on an *existing* branch * (`exists: true`), so a policy keyed on `!branch.exists` never returns the creation tuning. * * `result.applied` covers both steps — the settings the create call carried are reported * exactly like the ones a push applies (see {@link settingsAppliedAtCreate}), so folding them * into the creation doesn't make them vanish from the summary. * * Throws {@link PlatformError} (`Conflict`) if a branch with `branchName` already exists, or * (`BranchNotFound`) if the policy names a `parent` that isn't on the project — both before * anything is created, as is a setting Neon rejects in step 2. Only step 3 can fail with a * branch already created; that throws {@link PartialBranchCreateError} carrying its id/name. */ declare function createBranch(config: Config, options: CreateBranchOptions): Promise; //#endregion export { ApplyOptions, ConfigOperationOptions, CreateBranchOptions, CreateBranchResult, apply, createBranch, inspect, plan }; //# sourceMappingURL=operations.d.ts.map