import { BranchTarget, BranchTuningFn, BucketDef, Config, DataApiInput, FunctionDef, PreviewInput, ResolvedBranchConfig, ServiceEnabled, ServiceToggleInput } from "./types.js"; //#region src/lib/define-config.d.ts /** * Whether a `dataApi` toggle is **enabled and verified by Neon Auth** at the type level: it is * on (see {@link ServiceEnabled}) and not the explicit `authProvider: "external"` variant * (so the default / `"neon"` provider). This is the case that requires top-level Neon Auth. */ type DataApiUsesNeonAuth = ServiceEnabled extends true ? [DataApi] extends [{ authProvider: "external"; }] ? false : true : false; /** * Human-readable hint surfaced as the **expected type** of `dataApi` when a Neon-Auth Data * API is declared without Neon Auth enabled (see {@link DataApiField}). TypeScript prints the * offending value against this string literal — `Type 'true' is not assignable to type * '…requires `auth: true`…'` — which points straight at the fix, instead of the opaque * `Type 'true' is not assignable to type 'never'` an intersection guard produces. * * It documents **both** fixes: enabling Neon Auth (`auth: true`), and running the Data API * *without* Neon Auth by verifying a third-party IdP (`authProvider: 'external'` + `jwksUrl`). */ type NeonAuthRequiredHint = "`dataApi` with Neon Auth (the default `authProvider: 'neon'`) requires Neon Auth, so add `auth: true`. To enable the Data API WITHOUT Neon Auth, verify a third-party IdP instead: `dataApi: { authProvider: 'external', jwksUrl: 'https://your-idp/.well-known/jwks.json' }`"; /** * Static cross-field guard for {@link defineConfig}, expressed as the **type of the `dataApi` * field** rather than an intersected requirement on `auth`. * * - A Neon-Auth Data API (`authProvider: "neon"`, the default) with top-level `auth` enabled, * or any external Data API: the field keeps its normal `DataApi & DataApiInput` type (the * `& DataApiInput` preserves member autocomplete; the `const DataApi` still types the * returned {@link Config}). * - A Neon-Auth Data API **without** `auth` enabled: the field's expected type collapses to * the {@link NeonAuthRequiredHint} message, so the author sees the rule (and the two fixes) * right on the `dataApi` value. * * The runtime `superRefine` in {@link configInputSchema} enforces the same invariant for * non-typed (plain-JS) callers, so the behavior is identical — only the type-level message * changes. */ type DataApiField = DataApiUsesNeonAuth extends true ? ServiceEnabled extends true ? DataApi & DataApiInput : NeonAuthRequiredHint : DataApi & DataApiInput; /** * Autocomplete bridge for the nested `preview.functions` / `preview.buckets` slug objects. * * {@link PreviewInput} types those records with a string index signature * (`Record` / `Record`). When `defineConfig` infers * `const Preview`, every authored slug becomes a **named** property on the inferred literal * (e.g. `{ hello: { name; source } }`), and a named property **shadows** the index signature * when the editor computes the contextual type of that slug's value — so the rest of * {@link FunctionDef} / {@link BucketDef} (`env`, `dev`, `access`, …) never surfaces as * completions inside `hello: { … }` / `uploads: { … }`. * * Re-declaring each inferred slug's value as `FunctionDef` / `BucketDef` (a *named* member, via * a mapped type over the already-inferred keys) puts those members back onto the contextual * type without going through an index signature, which restores autocomplete. Intersected with * `Preview & PreviewInput` it neither widens what is accepted (the values were already * `FunctionDef` / `BucketDef`) nor perturbs the inferred `const Preview` — so slug inference for * `BranchTuningFn` and the returned {@link Config} is unchanged. */ type PreviewAutocomplete = (Preview extends { functions: infer F; } ? { functions: { [Slug in keyof F]: FunctionDef }; } : unknown) & (Preview extends { buckets: infer B; } ? { buckets: { [Name in keyof B]: BucketDef }; } : unknown); /** * Validate and freeze a Neon branch policy. * * Used at the top of `neon.ts`: * ```ts * import { defineConfig } from "@neon/config/v1"; * * export default defineConfig({ * auth: true, * preview: { * functions: { * hello: { name: "Hello", source: "./functions/hello.ts", dev: { port: 8787 } }, * }, * }, * branch: (branch) => ({ protected: branch.name === "main" }), * }); * ``` * * The policy is split into a **static** existential set (top-level `auth` / `dataApi` * toggles and the beta `preview` block) and a **dynamic** per-branch `branch` closure. The * static half determines which secrets exist — so `NeonEnv` and `parseEnv` * are exact — while the closure can only *tune* a branch (lifecycle, compute, per-function * deploy settings), never change what exists. * * The `branch` callback receives a read-only {@link BranchTarget} descriptor of the branch * being decided for (not a live handle); switch on its facts (`branch.name`, * `branch.isDefault`, `branch.exists`, …) and **return** the desired tuning. It runs in two * modes: against an existing branch (fields populated from Neon) and during pre-create * evaluation (`exists: false`, `id` undefined). * * Pure: no I/O, no side effects. The static parts are validated here; the closure's output * is validated every time it is evaluated so errors point at the concrete branch target. */ declare function defineConfig(input: { auth?: Auth & ServiceToggleInput; dataApi?: DataApiField; preview?: Preview & PreviewInput & PreviewAutocomplete; branch?: BranchTuningFn; }): Config; /** * Evaluate a branch policy for a specific branch target and return a normalized config. * * Merges the static existential set (services + preview functions/buckets) with the * per-branch tuning returned by the `branch` closure into the same {@link * ResolvedBranchConfig} the rest of the runtime (diff / push / fetchEnv) consumes. */ declare function resolveConfig(config: Config, branch: BranchTarget): ResolvedBranchConfig; /** * Normalize a region identifier to Neon's `-` format. When the user writes * `us-east-1` we assume `aws-us-east-1`. Pure helper used by both the validator and the * NeonApi adapter. */ declare function normalizeRegion(region: string): string; //#endregion export { DataApiField, NeonAuthRequiredHint, defineConfig, normalizeRegion, resolveConfig }; //# sourceMappingURL=define-config.d.ts.map