import { DbAdapter, ListOptions, AdapterConfigurationError } from '@geenius/adapters'; export { AuthContractError, AuthIdentitySchema, AuthProviderAdapter, AuthSessionContractSchema, CacheAdapter, CacheContractError, CacheEntrySchema, DeployAdapter, DeployContractError, DeploymentResultSchema, DeploymentTargetSchema, EventEnvelopeSchema, EventsAdapter, EventsContractError, PaymentCheckoutInputSchema, PaymentPlanContractSchema, PaymentSubscriptionContractSchema, PaymentsContractError, PaymentsProviderAdapter, QueueAdapter, QueueContractError, QueueJobSchema, StorageAdapter, StorageContractError, StorageObjectSchema } from '@geenius/adapters'; /** * @module types * @package @geenius/adapters/neon * @description Declares the SDK-free native Neon/Postgres SQL binding and * migration helper types without importing provider SDKs at runtime. */ /** * Error codes emitted by the SDK-free Neon binding layer. */ type NeonBindingErrorCode = "INVALID_NEON_ADAPTER" | "INVALID_NEON_OPTIONS" | "NEON_MIGRATION_FAILED"; /** * Plain row returned by native SQL helpers. */ type NeonSqlRow = Record; /** * Raw SQL result accepted from common Postgres clients. */ type NeonSqlResult = TRow[] | { /** Rows returned by the SQL execution. */ rows: TRow[]; /** Optional count of affected rows. */ rowCount?: number; }; /** * Function contract for SQL execution. Downstream packages can adapt * `@neondatabase/serverless` `neon()` or any Postgres query client to this * text-plus-params shape without this package importing the SDK. */ type NeonSqlExecutor = (text: string, params?: readonly unknown[]) => Promise>; /** * Raw SQL client shape accepted by adapter and migration helpers. */ type NeonSqlClient = NeonSqlExecutor | { /** Query method compatible with common Postgres clients. */ query: NeonSqlExecutor; }; /** * Collection-to-table mapping used by `createNeonDbAdapter()`. */ type NeonSqlTableConfig = string | { /** SQL table name, optionally schema-qualified. */ name: string; /** Use `generic-record` for the package-owned collection/id/payload table. */ mode?: "table" | "generic-record"; /** Primary key column; defaults to `id`. */ idColumn?: string; /** Optional field-to-column mapping for public adapter field names. */ columns?: Record; }; /** * Options required to construct a Neon `DbAdapter` without importing Neon SDKs. */ interface CreateNeonDbAdapterOptions { /** SQL executor or query-object owned by `@geenius/db` or the app. */ client: NeonSqlClient; /** Collection-to-table registry used by shared adapter methods. */ tables: Record; /** Optional id factory used by generic-record tables. */ idFactory?: () => string; /** Optional transaction wrapper that can expose `adapter.transaction()`. */ transaction?: NeonTransactionRunner; } /** * List options accepted by the Neon adapter. */ type NeonListOptions = ListOptions; /** * Context object passed to Neon transaction handlers. */ interface NeonTransactionContext { /** * Adapter facade bound to the OUTER (non-transactional) SQL client. Kept * for back-compat; new runners should invoke `createScopedAdapter` inside * their BEGIN/COMMIT block and expose the result to the handler so CRUD * calls run inside the transaction. */ adapter: DbAdapter; /** SQL client configured for this adapter. */ client: NeonSqlClient; /** Normalized OUTER SQL executor configured for this adapter. */ sql: NeonSqlExecutor; /** Collection-to-table registry available inside the transaction. */ tables: Record; /** * Build a `DbAdapter` whose CRUD operations execute against a * transaction-scoped SQL executor supplied by the runner. Runners must call * this inside their BEGIN/COMMIT block to obtain a handler-safe adapter. */ createScopedAdapter: (scopedSql: NeonSqlExecutor) => DbAdapter; } /** * User-supplied transaction body. */ type NeonTransactionHandler = (context: NeonTransactionContext) => Promise; /** * Runner that executes a transaction handler in the concrete Neon integration. */ type NeonTransactionRunner = (handler: NeonTransactionHandler, context: NeonTransactionContext) => Promise; /** * `DbAdapter` extension that exposes a typed transaction helper. */ type NeonDbAdapter = DbAdapter & { /** Execute a transaction through the concrete provider integration. */ transaction(handler: NeonTransactionHandler): Promise; }; /** * Output accepted from downstream Neon adapter factories. */ type NeonDbFactoryOutput = NeonDbAdapter; /** * Binding object accepted by `withNeonDb()` when wrapping a downstream adapter. */ interface NeonDbAdapterOptions { /** Adapter returned by `@geenius/db`, a consumer app, or `createNeonDbAdapter()`. */ adapter: NeonDbFactoryOutput | DbAdapter; /** Required provider tag proving this binding targets the Neon launch provider. */ provider: "neon"; /** Required metadata retained for conformance and diagnostics. */ source: { /** Factory options used to construct the adapter, when available. */ factoryOptions: CreateNeonDbAdapterOptions; }; } /** * Union of accepted inputs for Neon binding helpers. */ type NeonDbAdapterInput = NeonDbAdapterOptions | CreateNeonDbAdapterOptions; /** * Idempotent migration record shipped by the Neon contract package. */ interface NeonMigration { /** Stable migration identifier. */ id: string; /** SQL text to execute when the migration has not been applied. */ sql: string; } /** * @module adapter * @package @geenius/adapters/neon * @description Implements the Neon/Postgres adapter binding and the * SDK-free native SQL `DbAdapter` factory for the shared adapters contract. */ /** * Creates a Neon-backed database adapter using native parameterized SQL. The * caller owns the Neon connection and table schema; this package owns only the * shared `DbAdapter` behavior and SDK-free binding validation. */ declare function createNeonDbAdapter(options: CreateNeonDbAdapterOptions & { transaction: NonNullable; }): NeonDbAdapter; declare function createNeonDbAdapter(options: CreateNeonDbAdapterOptions): DbAdapter; /** * Validates or constructs a Neon `DbAdapter` for provider registries and * downstream app bindings. Pass native SQL factory options to build the * SDK-free facade locally, or pass an existing Neon adapter with provider * metadata returned by `@geenius/db`. */ declare function withNeonDb(config: CreateNeonDbAdapterOptions & { transaction: NonNullable; }): NeonDbAdapter; declare function withNeonDb(config: CreateNeonDbAdapterOptions): DbAdapter; declare function withNeonDb(config: NeonDbAdapterOptions & { adapter: NeonDbFactoryOutput; }): NeonDbAdapter; declare function withNeonDb(config: NeonDbAdapterInput): DbAdapter; /** * @module errors * @package @geenius/adapters/neon * @description Defines Neon-specific binding errors for adapter construction * and migration helper validation. */ /** * Error thrown when Neon adapter binding, factory, or migration inputs do not * satisfy the SDK-free contract expected by this package. */ declare class NeonBindingError extends AdapterConfigurationError { readonly neonCode: NeonBindingErrorCode; constructor(message: string, code?: NeonBindingErrorCode, cause?: unknown); } /** * Checks whether an unknown failure came from Neon binding or migration * validation rather than a downstream database client. */ declare function isNeonBindingError(error: unknown): error is NeonBindingError; /** * @module migrations * @package @geenius/adapters/neon * @description Declares the idempotent Neon/Postgres schema contract for the * generic adapter-record table used by conformance and local backend swaps. */ /** * Table names owned by the Neon adapters backend contract. Consumers can use * this list to verify their schema before enabling the conformance adapter. */ declare const neonAdapterTables: readonly ["geenius_adapter_records"]; /** * Idempotent SQL migration for the generic adapter records table used by the * Neon conformance adapter. The statement avoids provider SDK imports and can * run through any Postgres-compatible executor. */ declare const NEON_MIGRATION_0001_ADAPTERS_CORE = "CREATE TABLE IF NOT EXISTS geenius_adapter_records (\n collection text NOT NULL,\n id text NOT NULL,\n payload jsonb NOT NULL,\n created_at timestamptz NOT NULL DEFAULT now(),\n updated_at timestamptz NOT NULL DEFAULT now(),\n PRIMARY KEY (collection, id)\n);\n\nCREATE INDEX IF NOT EXISTS geenius_adapter_records_by_collection\n ON geenius_adapter_records(collection);\n\nCREATE INDEX IF NOT EXISTS geenius_adapter_records_payload_gin\n ON geenius_adapter_records USING gin (payload);\n\nCREATE OR REPLACE FUNCTION geenius_adapter_records_set_updated_at()\nRETURNS trigger AS $$\nBEGIN\n NEW.updated_at = now();\n RETURN NEW;\nEND;\n$$ LANGUAGE plpgsql;\n\nDROP TRIGGER IF EXISTS geenius_adapter_records_set_updated_at\n ON geenius_adapter_records;\n\nCREATE TRIGGER geenius_adapter_records_set_updated_at\n BEFORE UPDATE ON geenius_adapter_records\n FOR EACH ROW\n EXECUTE FUNCTION geenius_adapter_records_set_updated_at();"; /** * Ordered Neon migrations shipped by this package. Apply them in sequence * before using the generic adapter-record table in tests or local bindings. */ declare const neonMigrations: readonly Readonly<{ id: "0001_adapters_core"; sql: "CREATE TABLE IF NOT EXISTS geenius_adapter_records (\n collection text NOT NULL,\n id text NOT NULL,\n payload jsonb NOT NULL,\n created_at timestamptz NOT NULL DEFAULT now(),\n updated_at timestamptz NOT NULL DEFAULT now(),\n PRIMARY KEY (collection, id)\n);\n\nCREATE INDEX IF NOT EXISTS geenius_adapter_records_by_collection\n ON geenius_adapter_records(collection);\n\nCREATE INDEX IF NOT EXISTS geenius_adapter_records_payload_gin\n ON geenius_adapter_records USING gin (payload);\n\nCREATE OR REPLACE FUNCTION geenius_adapter_records_set_updated_at()\nRETURNS trigger AS $$\nBEGIN\n NEW.updated_at = now();\n RETURN NEW;\nEND;\n$$ LANGUAGE plpgsql;\n\nDROP TRIGGER IF EXISTS geenius_adapter_records_set_updated_at\n ON geenius_adapter_records;\n\nCREATE TRIGGER geenius_adapter_records_set_updated_at\n BEFORE UPDATE ON geenius_adapter_records\n FOR EACH ROW\n EXECUTE FUNCTION geenius_adapter_records_set_updated_at();"; }>[]; /** * Applies the ordered Neon migrations through a function or query-object SQL * executor and returns the migration ids that completed. * * @param client - SQL executor function or object exposing `query(sql)`. * @param migrations - Ordered migration list; defaults to this package's Neon migrations. * @returns Migration ids applied in order. * @throws {NeonBindingError} When the client shape is invalid or a migration fails. */ declare function applyNeonMigrations(client: NeonSqlClient, migrations?: readonly NeonMigration[]): Promise; export { type CreateNeonDbAdapterOptions, NEON_MIGRATION_0001_ADAPTERS_CORE, NeonBindingError, type NeonBindingErrorCode, type NeonDbAdapter, type NeonDbAdapterInput, type NeonDbAdapterOptions, type NeonDbFactoryOutput, type NeonListOptions, type NeonMigration, type NeonSqlClient, type NeonSqlExecutor, type NeonSqlResult, type NeonSqlRow, type NeonSqlTableConfig, type NeonTransactionContext, type NeonTransactionHandler, type NeonTransactionRunner, applyNeonMigrations, createNeonDbAdapter, isNeonBindingError, neonAdapterTables, neonMigrations, withNeonDb };