import { Inquirerer } from 'inquirerer'; import { PgpmPackage } from '@pgpmjs/core'; /** * Required extensions for database schema exports. * Includes native PostgreSQL extensions and pgpm modules. */ export declare const DB_REQUIRED_EXTENSIONS: readonly ["plpgsql", "uuid-ossp", "citext", "pgcrypto", "btree_gin", "btree_gist", "pg_textsearch", "pg_trgm", "postgis", "hstore", "vector", "ltree", "metaschema-schema", "pgpm-inflection", "pgpm-uuid", "pgpm-utils", "pgpm-database-jobs", "pgpm-jwt-claims", "pgpm-stamps", "pgpm-base32", "pgpm-totp", "pgpm-types", "pgpm-ltree-helpers", "pgpm-partman"]; /** * Map PostgreSQL data types to FieldType values. * Uses udt_name from information_schema which gives the base type name. * Delegates to the canonical PG_TYPE_MAP in type-map.ts. */ export declare const mapPgTypeToFieldType: (udtName: string) => FieldType; /** * Required extensions for service/meta exports. * Includes native PostgreSQL extensions and pgpm modules for metadata management. */ export declare const SERVICE_REQUIRED_EXTENSIONS: readonly ["plpgsql", "metaschema-schema", "metaschema-modules", "services"]; /** * Common SQL header for meta export files. * Sets session_replication_role and grants necessary permissions. */ export declare const META_COMMON_HEADER = "SET session_replication_role TO replica;\n-- using replica in case we are deploying triggers to metaschema_public\n\n-- unaccent, postgis affected and require grants\nGRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA public to public;\n\nDO $LQLMIGRATION$\n DECLARE\n BEGIN\n\n EXECUTE format('GRANT CONNECT ON DATABASE %I TO %I', current_database(), 'app_user');\n EXECUTE format('GRANT CONNECT ON DATABASE %I TO %I', current_database(), 'app_admin');\n\n END;\n$LQLMIGRATION$;"; /** * Common SQL footer for meta export files. */ export declare const META_COMMON_FOOTER = "\nSET session_replication_role TO DEFAULT;"; /** * Ordered list of meta tables for export. * Tables are processed in this order to satisfy foreign key dependencies. */ export declare const META_TABLE_ORDER: readonly ["database", "schema", "function", "table", "field", "spatial_relation", "policy", "index", "trigger", "trigger_function", "rls_function", "foreign_key_constraint", "primary_key_constraint", "unique_constraint", "check_constraint", "full_text_search", "schema_grant", "table_grant", "default_privilege", "domains", "sites", "apis", "apps", "site_modules", "site_themes", "site_metadata", "api_modules", "api_extensions", "api_schemas", "database_settings", "api_settings", "rls_settings", "cors_settings", "pubkey_settings", "webauthn_settings", "rls_module", "user_auth_module", "memberships_module", "permissions_module", "limits_module", "levels_module", "events_module", "users_module", "hierarchy_module", "membership_types_module", "invites_module", "emails_module", "sessions_module", "user_state_module", "profiles_module", "config_secrets_user_module", "user_credentials_module", "user_settings_module", "connected_accounts_module", "phone_numbers_module", "crypto_addresses_module", "crypto_auth_module", "field_module", "table_module", "secure_table_provision", "uuid_module", "default_ids_module", "denormalized_table_field", "relation_provision", "entity_type_provision", "rate_limits_module", "storage_module", "billing_module", "billing_provider_module", "devices_module", "identity_providers_module", "notifications_module", "plans_module", "realtime_module", "session_secrets_module", "config_secrets_org_module", "config_secrets_module", "i18n_module", "agent_module", "function_module", "namespace_module", "merkle_store_module", "graph_module", "graph_execution_module", "function_deployment_module", "function_invocation_module", "compute_log_module", "db_usage_module", "storage_log_module", "transfer_log_module", "webauthn_auth_module", "webauthn_credentials_module", "inference_log_module", "rate_limit_meters_module"]; export type FieldType = 'uuid' | 'uuid[]' | 'text' | 'text[]' | 'boolean' | 'image' | 'upload' | 'url' | 'jsonb' | 'jsonb[]' | 'int' | 'interval' | 'timestamptz'; export interface TableConfig { schema: string; table: string; conflictDoNothing?: boolean; typeOverrides?: Record; gqlTypeName?: string; /** Columns whose values are environment-specific and should be excluded from the * exported INSERT so that the column's DDL DEFAULT applies at deploy time. * Key = column name, Value = the SQL expression the column defaults to (for documentation). * E.g. { dbname: 'current_database()' } — the exporter omits `dbname` from the * INSERT, and `DEFAULT current_database()` in the table definition supplies it. */ columnDefaults?: Record; } /** * Shared metadata table configuration. * * Fields are discovered dynamically at runtime via introspection: * - SQL flow: uses information_schema.columns + mapPgTypeToFieldType() * - GraphQL flow: uses __type introspection + mapGraphQLTypeToFieldType() * * Only `typeOverrides` are hardcoded for special types (image, upload, url) * that cannot be inferred from database/GraphQL types alone. * */ export declare const META_TABLE_CONFIG: Record; export interface Schema { name: string; schema_name: string; } export interface MakeReplacerOptions { schemas: Schema[]; name: string; /** * Optional prefix for schema name replacement. * When provided, schema names are replaced using this prefix instead of `name`. * This is needed for the services/meta package where `name` is the services * extension name (e.g. "agent-db-services") but schemas should use the * application extension prefix (e.g. "agent-db" → "agent_db_auth_public"). */ schemaPrefix?: string; } export interface ReplacerResult { replacer: (str: string, n?: number) => string; replace: [RegExp, string][]; } export interface PreparePackageOptions { project: PgpmPackage; author: string; outdir: string; name: string; description: string; extensions: string[]; prompter?: Inquirerer; /** Repository name for module scaffolding. Defaults to module name if not provided. */ repoName?: string; /** GitHub username/org for module scaffolding. Required for non-interactive use. */ username?: string; } /** * Result of checking for missing modules at workspace level. */ export interface MissingModulesResult { missingModules: { controlName: string; npmName: string; }[]; shouldInstall: boolean; } /** * Checks which pgpm modules from the extensions list are missing from the workspace * and prompts the user if they want to install them. * * This function only does detection and prompting - it does NOT install. * Use installMissingModules() after the module is created to do the actual installation. * * @param project - The PgpmPackage instance (only needs workspace context) * @param extensions - List of extension names (control file names) * @param prompter - Optional prompter for interactive confirmation * @returns Object with missing modules and whether user wants to install them */ export declare const detectMissingModules: (project: PgpmPackage, extensions: string[], prompter?: Inquirerer, argv?: Record) => Promise; /** * Installs missing modules into a specific module directory. * Must be called after the module has been created. * * @param moduleDir - The directory of the module to install into * @param missingModules - Array of missing modules to install */ export declare const installMissingModules: (moduleDir: string, missingModules: { controlName: string; npmName: string; }[]) => Promise; /** * Generates a function for replacing schema names and extension names in strings. */ export declare const makeReplacer: ({ schemas, name, schemaPrefix }: MakeReplacerOptions) => ReplacerResult; /** * Creates a PGPM package directory or resets the deploy/revert/verify directories if it exists. * If the module already exists and a prompter is provided, prompts the user for confirmation. * * @returns The absolute path to the created/prepared module directory */ export declare const preparePackage: ({ project, author, outdir, name, description, extensions, prompter, repoName, username }: PreparePackageOptions) => Promise; /** * Normalizes an output directory path to ensure it ends with a path separator. */ export declare const normalizeOutdir: (outdir: string) => string;