import type { LinkInfoResult } from '@heroku/types/data'; import type { ResourceCtx } from '../../core/extend-resource.js'; import type { ResolvedAddOn } from '../platform/add-on/types.js'; import type { ResolvedPgDatabase } from './internal/resolve-pg-database.js'; import type { LegacyDatabase } from './postgres-database/index.js'; /** A Data Link between a local Postgres database and a remote Postgres database. */ export type PgLink = LinkInfoResult; export type LinkedDatabase = { addon: LegacyDatabase; links: PgLink[]; }; export type ListLinksByAppOptions = { signal?: AbortSignal; }; export type CreateLinkBody = { /** Name to register the link under. The API generates one when omitted. */ as?: string; }; export type CreateLinkOptions = { /** * Runs once both sides are resolved and validated, before the link is * created. A throw (or abort) here prevents the create. */ beforeCreate?: (preview: { addon: ResolvedPgDatabase; target: ResolvedAddOn; }) => Promise | void; signal?: AbortSignal; }; export type CreateLinkResult = { addon: ResolvedPgDatabase; link: PgLink; target: ResolvedAddOn; }; export type DeleteLinkOptions = { /** * Runs once the database is resolved and validated, before the link is * deleted. Callers can confirm here; a throw (or abort) prevents the delete. */ beforeDelete?: (preview: { addon: ResolvedPgDatabase; link: string; }) => Promise | void; signal?: AbortSignal; }; export type DeleteLinkResult = { addon: ResolvedPgDatabase; link: PgLink; }; /** Thrown when a link's remote isn't a Heroku Postgres add-on. Data Links only connect Postgres to Postgres. */ export declare class InvalidLinkRemoteError extends Error { readonly addon: ResolvedAddOn; readonly id = "invalid_link_remote"; constructor(addon: ResolvedAddOn); get body(): { id: string; message: string; }; } /** * Lists the links on an app's Postgres databases. * * With `databaseIdentity`, resolves that one database (an attachment name, * config var, `app::attachment`, or add-on name) and returns its links. Without * it, returns the links on every legacy Postgres database attached to the app, * in attachment order. Each `addon` carries the `attachmentNames` it's known * by on the app (just the resolved attachment when `databaseIdentity` is given). * * Returns an empty array when the app has no databases. Links are fetched in * parallel, one request per database; the first failure rejects the call. */ export declare function listByApp(ctx: Pick, appIdentity: string, databaseIdentity?: string, options?: ListLinksByAppOptions): Promise; /** * Resolves a local and a remote Postgres database, then links the remote * into the local one. * * `databaseIdentity` resolves through the app's attachments (`''` means * `DATABASE_URL`). `remoteIdentity` resolves as an add-on, scoped to the app * first and then globally. Both resolve in parallel, so when both are invalid, * either error may surface. * * Throws `InvalidLinkRemoteError` when the remote isn't Heroku Postgres, and `EssentialDatabaseNotSupportedError` when either side is * Essential-tier. */ export declare function createForDatabase(ctx: Pick, appIdentity: string, databaseIdentity: string, remoteIdentity: string, body?: CreateLinkBody, options?: CreateLinkOptions): Promise; /** * Resolves a Postgres database and deletes one of its links. * * `databaseIdentity` resolves through the app's attachments (`''` means * `DATABASE_URL`). Throws `EssentialDatabaseNotSupportedError` when the * database is Essential-tier. If provided, `beforeDelete` runs before the * delete request; a throw there prevents it. */ export declare function deleteFromDatabase(ctx: Pick, appIdentity: string, databaseIdentity: string, linkName: string, options?: DeleteLinkOptions): Promise; export declare const linkExtensions: import("../../core/extend-resource.js").ResourceExtension<"data", "link", { createForDatabase: (appIdentity: string, databaseIdentity: string, remoteIdentity: string, body?: CreateLinkBody, options?: CreateLinkOptions) => Promise; deleteFromDatabase: (appIdentity: string, databaseIdentity: string, linkName: string, options?: DeleteLinkOptions) => Promise; listByApp: (appIdentity: string, databaseIdentity?: string, options?: ListLinksByAppOptions) => Promise; }>;