import { PgpmOptions, PgpmWorkspaceConfig } from '@pgpmjs/types'; import { PgConfig } from 'pg-env'; import { ExtensionInfo } from '../../files'; import { ModuleMap } from '../../modules/modules'; import { PackageAnalysisResult, RenameOptions } from '../../files/types'; export declare enum PackageContext { Outside = "outside", Workspace = "workspace-root", Module = "module", ModuleInsideWorkspace = "module-in-workspace" } export interface InitModuleOptions { name: string; description: string; author: string; extensions: string[]; branch?: string; templateRepo?: string; templatePath?: string; /** Override the base directory for template resolution (e.g., 'supabase', 'drizzle') */ dir?: string; cacheTtlMs?: number; noTty?: boolean; toolName?: string; answers?: Record; /** * Parent directory where the module should be created. * When provided, bypasses createModuleDirectory() and creates the module at outputDir/name. * Must be an absolute path or relative to workspace root. */ outputDir?: string; /** * Whether this is a pgpm-managed module that should create pgpm.plan and .control files. * Defaults to true for backward compatibility. */ pgpm?: boolean; /** * Optional Inquirerer instance to reuse for prompting during template scaffolding. * If provided, prevents creating a duplicate instance on process.stdin which * would cause double-echoed keystrokes and other input conflicts. * The caller retains ownership and is responsible for closing it. */ prompter?: import('inquirerer').Inquirerer; } export declare class PgpmPackage { cwd: string; workspacePath?: string; modulePath?: string; config?: PgpmWorkspaceConfig; allowedDirs: string[]; allowedParentDirs: string[]; private _moduleMap?; private _moduleInfo?; constructor(cwd?: string); resetCwd(cwd: string): void; private resolveSqitchPath; private loadConfigSync; private loadAllowedDirs; private loadAllowedParentDirs; isInsideAllowedDirs(cwd: string): boolean; isParentOfAllowedDirs(cwd: string): boolean; private createModuleDirectory; ensureModule(): void; ensureWorkspace(): void; getContext(): PackageContext; isInWorkspace(): boolean; isInModule(): boolean; getWorkspacePath(): string | undefined; getModulePath(): string | undefined; clearCache(): void; getModules(): Promise; /** * List all modules by parsing .control files in the workspace directory. * Handles naming collisions by preferring the shortest path. */ listModules(): ModuleMap; getModuleMap(): ModuleMap; getAvailableModules(): Promise; getModuleProject(name: string): PgpmPackage; getModuleInfo(): ExtensionInfo; getModuleName(): string; getRequiredModules(): string[]; setModuleDependencies(modules: string[]): void; private validateModuleDependencies; private initModuleSqitch; initModule(options: InitModuleOptions): Promise; getLatestChange(moduleName: string): string; getLatestChangeAndVersion(moduleName: string): { change: string; version: string; }; getModuleExtensions(): { resolved: string[]; external: string[]; }; getModuleDependencies(moduleName: string): { native: string[]; modules: string[]; }; getModuleDependencyChanges(moduleName: string): { native: string[]; modules: { name: string; latest: string; version: string; }[]; }; getModulePlan(): string; getModuleControlFile(): string; getModuleMakefile(): string; getModuleSQL(): string; generateModulePlan(options: { uri?: string; includePackages?: boolean; includeTags?: boolean; }): string; writeModulePlan(options: { uri?: string; includePackages?: boolean; includeTags?: boolean; }): void; /** * Add a tag to the current module's plan file */ addTag(tagName: string, changeName?: string, comment?: string): void; /** * Add a change to the current module's plan file and create SQL files */ addChange(changeName: string, dependencies?: string[], comment?: string): void; /** * Add change to the current module (internal helper) */ private addChangeToModule; /** * Create deploy/revert/verify SQL files for a change */ private createSqlFiles; publishToDist(distFolder?: string): void; /** * Installs an extension npm package into the local skitch extensions directory, * and automatically adds it to the current module’s package.json dependencies. */ installModules(...pkgstrs: string[]): Promise; /** * Returns information about which of the specified modules are installed. * Checks the module's package.json dependencies to determine installation status. * * @param moduleNames - Array of npm package names to check (e.g., '@pgpm/base32') * @returns Object with installed (array of installed module names) and * installedVersions (map of module name to installed version) */ modulesInstalled(moduleNames: string[]): { installed: string[]; installedVersions: Record; }; /** * Returns all installed pgpm modules from the module's package.json dependencies. * Only returns dependencies that exist in the workspace extensions directory. * * @returns Object with installed module names and their versions */ getInstalledModules(): { installed: string[]; installedVersions: Record; }; /** * Returns all pgpm modules installed in the workspace extensions directory. * Unlike getInstalledModules(), this does NOT require being inside a module. * It scans the workspace/extensions/ directory directly to find installed packages. * * This is useful for checking what's available at workspace level before a module exists. * * @returns Array of installed npm package names (e.g., '@pgpm/base32', '@pgpm/totp') */ getWorkspaceInstalledModules(): string[]; /** * Updates installed pgpm modules to their latest versions from npm. * Re-installs each module to get the latest version. * Also updates package.json for ALL modules in the workspace that reference the upgraded packages. * * Note: Extensions are installed globally in the workspace's extensions/ directory, * so upgrading affects all modules that depend on the upgraded package. * * @param options - Options for the update operation * @param options.modules - Specific modules to update (defaults to all installed modules) * @param options.dryRun - If true, only returns what would be updated without making changes * @returns Object with updated modules and their old/new versions */ upgradeModules(options?: { modules?: string[]; dryRun?: boolean; }): Promise<{ updates: Array<{ name: string; oldVersion: string; newVersion: string | null; }>; affectedModules: string[]; }>; /** * Updates package.json dependencies for all modules in the workspace that reference * the specified packages with their new versions. * * @param packageVersions - Map of package name to new version * @returns Array of module names that were updated */ private updateWorkspaceModuleVersions; /** * Get the set of modules that have been deployed to the database */ private getDeployedModules; resolveWorkspaceExtensionDependencies(opts?: { filterDeployed?: boolean; pgConfig?: PgConfig; }): Promise<{ resolved: string[]; external: string[]; }>; private parsePackageTarget; deploy(opts: PgpmOptions, target?: string, recursive?: boolean): Promise; /** * Reverts database changes for modules. Unlike verify operations, revert operations * modify database state and must ensure dependent modules are reverted before their * dependencies to prevent database constraint violations. */ revert(opts: PgpmOptions, target?: string, recursive?: boolean): Promise; verify(opts: PgpmOptions, target?: string, recursive?: boolean): Promise; removeFromPlan(toChange: string): Promise; analyzeModule(): PackageAnalysisResult; renameModule(newName: string, opts?: RenameOptions): { changed: string[]; warnings: string[]; }; }