diff --git a/pgpm/cli/__tests__/diff-e2e.test.ts b/pgpm/cli/__tests__/diff-e2e.test.ts index 468dac974..69579764d 100644 --- a/pgpm/cli/__tests__/diff-e2e.test.ts +++ b/pgpm/cli/__tests__/diff-e2e.test.ts @@ -9,8 +9,8 @@ * * PREREQUISITES: a running PostgreSQL instance via standard PG* env vars. */ -import { diffCatalogSnapshots, loadDiffSideFromDisk, snapshotCatalog, withoutColumnOrder } from '@pgpmjs/export'; -import { diffChangeSets, loadModule } from '@pgpmjs/transform'; +import { loadDiffSideFromDisk } from '@pgpmjs/diff'; +import { diffCatalogSnapshots, diffChangeSets, loadModule, snapshotCatalog, withoutColumnOrder } from '@pgpmjs/transform'; import * as fs from 'fs'; import * as path from 'path'; import { teardownPgPools } from 'pg-cache'; diff --git a/pgpm/cli/__tests__/import-e2e.test.ts b/pgpm/cli/__tests__/import-e2e.test.ts index e686d63b5..b632b3dd4 100644 --- a/pgpm/cli/__tests__/import-e2e.test.ts +++ b/pgpm/cli/__tests__/import-e2e.test.ts @@ -14,7 +14,8 @@ * * PREREQUISITES: a running PostgreSQL instance via standard PG* env vars. */ -import { copyBlockToInsert, diffCatalogSnapshots, preprocessDumpText, snapshotCatalog } from '@pgpmjs/export'; +import { copyBlockToInsert, preprocessDumpText } from '@pgpmjs/import'; +import { diffCatalogSnapshots, snapshotCatalog } from '@pgpmjs/transform'; import * as fs from 'fs'; import * as path from 'path'; import { teardownPgPools } from 'pg-cache'; diff --git a/pgpm/cli/__tests__/transform-e2e.test.ts b/pgpm/cli/__tests__/transform-e2e.test.ts index f36ae9b54..9170a46ae 100644 --- a/pgpm/cli/__tests__/transform-e2e.test.ts +++ b/pgpm/cli/__tests__/transform-e2e.test.ts @@ -9,7 +9,7 @@ * * PREREQUISITES: a running PostgreSQL instance via standard PG* env vars. */ -import { diffCatalogSnapshots, snapshotCatalog } from '@pgpmjs/export'; +import { diffCatalogSnapshots, snapshotCatalog } from '@pgpmjs/transform'; import * as fs from 'fs'; import * as path from 'path'; import { teardownPgPools } from 'pg-cache'; diff --git a/pgpm/cli/package.json b/pgpm/cli/package.json index 793decee6..a1b371ed1 100644 --- a/pgpm/cli/package.json +++ b/pgpm/cli/package.json @@ -47,8 +47,10 @@ "dependencies": { "@inquirerer/utils": "^3.3.9", "@pgpmjs/core": "workspace:^", + "@pgpmjs/diff": "workspace:^", "@pgpmjs/env": "workspace:^", "@pgpmjs/export": "workspace:^", + "@pgpmjs/import": "workspace:^", "@pgpmjs/logger": "workspace:^", "@pgpmjs/slice": "workspace:^", "@pgpmjs/transform": "workspace:^", diff --git a/pgpm/cli/src/commands/diff.ts b/pgpm/cli/src/commands/diff.ts index 459ed80d0..6e8d324cc 100644 --- a/pgpm/cli/src/commands/diff.ts +++ b/pgpm/cli/src/commands/diff.ts @@ -2,21 +2,25 @@ import { PgpmMigrate, PgpmRow, SqlWriteOptions, writePgpmFiles, writePgpmPlan } import { deltaChangesToRows, DiffSide, + loadDiffSideFromDisk, + sqlToDiffChanges +} from '@pgpmjs/diff'; +import { Logger } from '@pgpmjs/logger'; +import { diffCatalogSnapshots, + diffChangeSets, EXPORT_GRANULARITIES, ExportGranularity, isExportGranularity, - loadDiffSideFromDisk, - resolveDiffSideKind, + loadModule, + SemanticDiffResult, + SemanticObjectDiff, snapshotCatalog, - sqlToDiffChanges, withoutColumnOrder -} from '@pgpmjs/export'; -import { Logger } from '@pgpmjs/logger'; -import { diffChangeSets, loadModule, SemanticDiffResult, SemanticObjectDiff } from '@pgpmjs/transform'; +} from '@pgpmjs/transform'; import { spawn } from 'child_process'; import * as fs from 'fs'; -import { CLIOptions, cliExitWithError, extractFirst, Inquirerer, ParsedArgs } from 'inquirerer'; +import { cliExitWithError, CLIOptions, extractFirst, Inquirerer, ParsedArgs } from 'inquirerer'; import * as os from 'os'; import * as path from 'path'; import { getPgPool } from 'pg-cache'; diff --git a/pgpm/cli/src/commands/export.ts b/pgpm/cli/src/commands/export.ts index 3fac14a2f..0a2455263 100644 --- a/pgpm/cli/src/commands/export.ts +++ b/pgpm/cli/src/commands/export.ts @@ -1,6 +1,7 @@ import { PgpmPackage } from '@pgpmjs/core'; import { getEnvOptions } from '@pgpmjs/env'; -import { EXPORT_GRANULARITIES, exportGraphQL, exportMigrations, GraphQLClient, graphqlRowToPostgresRow, isExportGranularity, parsePartitionConfig, PartitionConfig } from '@pgpmjs/export'; +import { exportGraphQL, exportMigrations, GraphQLClient, graphqlRowToPostgresRow } from '@pgpmjs/export'; +import { EXPORT_GRANULARITIES, isExportGranularity, parsePartitionConfig, PartitionConfig } from '@pgpmjs/transform'; import { getGitConfigInfo } from '@pgpmjs/types'; import { CLIOptions, Inquirerer } from 'inquirerer'; import { resolve } from 'path'; diff --git a/pgpm/cli/src/commands/import.ts b/pgpm/cli/src/commands/import.ts index 217d493af..cd52405d3 100644 --- a/pgpm/cli/src/commands/import.ts +++ b/pgpm/cli/src/commands/import.ts @@ -1,17 +1,19 @@ import { dumpCompatibilityWarnings, + importDumpRows, + linkTextualDeps, + loadDumpSource +} from '@pgpmjs/import'; +import { Logger } from '@pgpmjs/logger'; +import { EXPORT_GRANULARITIES, ExportGranularity, - importDumpRows, isExportGranularity, - linkTextualDeps, - loadDumpSource, parsePartitionConfig, PartitionConfig, + PartitionCycleError, partitionExportRows -} from '@pgpmjs/export'; -import { Logger } from '@pgpmjs/logger'; -import { PartitionCycleError } from '@pgpmjs/transform'; +} from '@pgpmjs/transform'; import { cliExitWithError, CLIOptions, Inquirerer, ParsedArgs } from 'inquirerer'; import * as path from 'path'; diff --git a/pgpm/cli/src/commands/transform.ts b/pgpm/cli/src/commands/transform.ts index 3683faa08..c796fbd10 100644 --- a/pgpm/cli/src/commands/transform.ts +++ b/pgpm/cli/src/commands/transform.ts @@ -1,4 +1,5 @@ import { PgpmMigrate, PgpmPackage, PgpmRow } from '@pgpmjs/core'; +import { Logger } from '@pgpmjs/logger'; import { diffCatalogSnapshots, EXPORT_GRANULARITIES, @@ -7,13 +8,12 @@ import { loadModuleSource, parsePartitionConfig, PartitionConfig, + PartitionCycleError, PartitionedPackageRows, partitionExportRows, restructureExportRows, snapshotCatalog -} from '@pgpmjs/export'; -import { Logger } from '@pgpmjs/logger'; -import { PartitionCycleError } from '@pgpmjs/transform'; +} from '@pgpmjs/transform'; import * as fs from 'fs'; import { cliExitWithError, CLIOptions, Inquirerer, ParsedArgs } from 'inquirerer'; import * as path from 'path'; diff --git a/pgpm/diff/README.md b/pgpm/diff/README.md new file mode 100644 index 000000000..1625e6774 --- /dev/null +++ b/pgpm/diff/README.md @@ -0,0 +1,7 @@ +# @pgpmjs/diff + +`pgpm diff` engine: identity-keyed semantic schema diff between any two SQL sources — pgpm modules, SQL dumps, or live databases (dumped via `pg_dump` by the CLI). + +Every side normalizes to the same `DiffInputChange[]` seam consumed by the semantic diff driver in `@pgpmjs/transform`, so the comparison is source- and dial-invariant. `deltaChangesToRows` lifts the resulting deltas back onto deployable `PgpmRow`s. + +Used by the `pgpm diff` CLI command (`pgpm/cli`). Sibling front doors: `@pgpmjs/export` (live database), `@pgpmjs/import` (dumps). diff --git a/pgpm/export/__tests__/diff-source.test.ts b/pgpm/diff/__tests__/diff-source.test.ts similarity index 99% rename from pgpm/export/__tests__/diff-source.test.ts rename to pgpm/diff/__tests__/diff-source.test.ts index 3839cb149..177d97402 100644 --- a/pgpm/export/__tests__/diff-source.test.ts +++ b/pgpm/diff/__tests__/diff-source.test.ts @@ -55,8 +55,8 @@ describe('stripDumpPreamble', () => { '-- PostgreSQL database dump', '--', '\\restrict abcdef', - "SET statement_timeout = 0;", - "SET lock_timeout = 0;", + 'SET statement_timeout = 0;', + 'SET lock_timeout = 0;', "SELECT pg_catalog.set_config('search_path', '', false);", "SET default_tablespace = '';", '\\connect mydb', diff --git a/pgpm/diff/jest.config.js b/pgpm/diff/jest.config.js new file mode 100644 index 000000000..057a9420e --- /dev/null +++ b/pgpm/diff/jest.config.js @@ -0,0 +1,18 @@ +/** @type {import('ts-jest').JestConfigWithTsJest} */ +module.exports = { + preset: 'ts-jest', + testEnvironment: 'node', + transform: { + '^.+\\.tsx?$': [ + 'ts-jest', + { + babelConfig: false, + tsconfig: 'tsconfig.json', + }, + ], + }, + transformIgnorePatterns: [`/node_modules/*`], + testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$', + moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], + modulePathIgnorePatterns: ['dist/*'] +}; diff --git a/pgpm/diff/package.json b/pgpm/diff/package.json new file mode 100644 index 000000000..8116b270c --- /dev/null +++ b/pgpm/diff/package.json @@ -0,0 +1,49 @@ +{ + "name": "@pgpmjs/diff", + "version": "0.1.0", + "author": "Constructive ", + "description": "pgpm diff — identity-keyed semantic schema diff between pgpm modules, SQL dumps, and live databases", + "main": "index.js", + "module": "esm/index.js", + "types": "index.d.ts", + "homepage": "https://github.com/constructive-io/constructive", + "license": "MIT", + "publishConfig": { + "access": "public", + "directory": "dist" + }, + "repository": { + "type": "git", + "url": "https://github.com/constructive-io/constructive" + }, + "bugs": { + "url": "https://github.com/constructive-io/constructive/issues" + }, + "scripts": { + "clean": "makage clean", + "prepack": "npm run build", + "build": "makage build", + "build:dev": "makage build --dev", + "lint": "eslint . --fix", + "test": "jest", + "test:watch": "jest --watch" + }, + "keywords": [ + "sql", + "postgres", + "postgresql", + "pgpm", + "pgpmjs", + "diff", + "schema", + "migration" + ], + "devDependencies": { + "makage": "^0.3.0" + }, + "dependencies": { + "@pgpmjs/ast": "workspace:^", + "@pgpmjs/naming-spec": "workspace:^", + "@pgpmjs/transform": "workspace:^" + } +} diff --git a/pgpm/export/src/diff-source.ts b/pgpm/diff/src/diff-source.ts similarity index 97% rename from pgpm/export/src/diff-source.ts rename to pgpm/diff/src/diff-source.ts index 1e3c7f780..44d7aa69b 100644 --- a/pgpm/export/src/diff-source.ts +++ b/pgpm/diff/src/diff-source.ts @@ -7,14 +7,13 @@ * `DiffInputChange[]` seam the semantic diff driver consumes, so the * comparison is source- and dial-invariant. */ -import { PgpmRow } from '@pgpmjs/core'; +import { PgpmRow } from '@pgpmjs/ast'; import { alterationPathFor } from '@pgpmjs/naming-spec'; import type { DiffInputChange, SemanticDeltaChange } from '@pgpmjs/transform'; +import { loadModuleSource, stripTransactionWrapper } from '@pgpmjs/transform'; import * as fs from 'fs'; import * as path from 'path'; -import { loadModuleSource, stripTransactionWrapper } from './module-source'; - /** What a diff side spec resolves to. */ export type DiffSideKind = 'module' | 'sql' | 'database'; diff --git a/pgpm/diff/src/index.ts b/pgpm/diff/src/index.ts new file mode 100644 index 000000000..055287570 --- /dev/null +++ b/pgpm/diff/src/index.ts @@ -0,0 +1,2 @@ +export type { DiffSide, DiffSideKind } from './diff-source'; +export { deltaChangesToRows, loadDiffSideFromDisk, resolveDiffSideKind, sqlToDiffChanges, stripDumpPreamble } from './diff-source'; diff --git a/pgpm/diff/tsconfig.esm.json b/pgpm/diff/tsconfig.esm.json new file mode 100644 index 000000000..800d7506d --- /dev/null +++ b/pgpm/diff/tsconfig.esm.json @@ -0,0 +1,9 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "dist/esm", + "module": "es2022", + "rootDir": "src/", + "declaration": false + } +} diff --git a/pgpm/diff/tsconfig.json b/pgpm/diff/tsconfig.json new file mode 100644 index 000000000..1a9d5696c --- /dev/null +++ b/pgpm/diff/tsconfig.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "outDir": "dist", + "rootDir": "src/" + }, + "include": ["src/**/*.ts"], + "exclude": ["dist", "node_modules", "**/*.spec.*", "**/*.test.*"] +} diff --git a/pgpm/export/src/export-graphql.ts b/pgpm/export/src/export-graphql.ts index 0963d3ddb..78cd40949 100644 --- a/pgpm/export/src/export-graphql.ts +++ b/pgpm/export/src/export-graphql.ts @@ -9,6 +9,7 @@ */ import { PgpmPackage, PgpmRow, SqlWriteOptions, writePgpmFiles, writePgpmPlan } from '@pgpmjs/core'; import { createClient } from '@pgpmjs/migrate-client'; +import { ExportGranularity, PartitionConfig, partitionExportRows, restructureExportRows } from '@pgpmjs/transform'; import { Inquirerer } from 'inquirerer'; import { exportGraphQLMeta } from './export-graphql-meta'; @@ -26,8 +27,6 @@ import { SERVICE_REQUIRED_EXTENSIONS} from './export-utils'; import { GraphQLClient } from './graphql-client'; import { graphqlRowToPostgresRow } from './graphql-naming'; -import { PartitionConfig, partitionExportRows } from './partition'; -import { ExportGranularity, restructureExportRows } from './restructure'; // ============================================================================= // Public API diff --git a/pgpm/export/src/export-migrations.ts b/pgpm/export/src/export-migrations.ts index 07ce473bc..cc19b068a 100644 --- a/pgpm/export/src/export-migrations.ts +++ b/pgpm/export/src/export-migrations.ts @@ -1,4 +1,5 @@ import { PgpmPackage, PgpmRow, SqlWriteOptions, writePgpmFiles, writePgpmPlan } from '@pgpmjs/core'; +import { ExportGranularity, PartitionConfig, partitionExportRows, restructureExportRows } from '@pgpmjs/transform'; import { PgpmOptions } from '@pgpmjs/types'; import { Inquirerer } from 'inquirerer'; import { getPgPool } from 'pg-cache'; @@ -15,8 +16,6 @@ import { normalizeOutdir, preparePackage, SERVICE_REQUIRED_EXTENSIONS} from './export-utils'; -import { PartitionConfig, partitionExportRows } from './partition'; -import { ExportGranularity, restructureExportRows } from './restructure'; interface ExportMigrationsToDiskOptions { project: PgpmPackage; diff --git a/pgpm/export/src/index.ts b/pgpm/export/src/index.ts index 4ad80df69..2b040861a 100644 --- a/pgpm/export/src/index.ts +++ b/pgpm/export/src/index.ts @@ -1,9 +1,3 @@ -export type { CatalogQueryable, CatalogSnapshot } from './catalog-check'; -export { diffCatalogSnapshots, snapshotCatalog, withoutColumnOrder } from './catalog-check'; -export type { DiffSide, DiffSideKind } from './diff-source'; -export { deltaChangesToRows, loadDiffSideFromDisk, resolveDiffSideKind, sqlToDiffChanges, stripDumpPreamble } from './diff-source'; -export type { CopyBlock, CopyTarget, DumpSource } from './dump-source'; -export { copyBlockToInsert, copyTargetOf, dumpCompatibilityWarnings, loadDumpSource, preprocessDumpText } from './dump-source'; export * from './export-data'; export * from './export-graphql'; export * from './export-graphql-meta'; @@ -34,13 +28,5 @@ export { SERVICE_REQUIRED_EXTENSIONS} from './export-utils'; export { GraphQLClient } from './graphql-client'; export { buildFieldsFragment, getGraphQLQueryName, getGraphQLTypeName, graphqlRowToPostgresRow, GraphQLTypeInfo,mapGraphQLTypeToFieldType, unwrapGraphQLType } from './graphql-naming'; -export type { ImportDumpRowsOptions, ImportDumpRowsResult, ImportDumpSummary } from './import'; -export { importDumpRows, linkTextualDeps, MISC_CHANGE_PATH } from './import'; export { intervalToPostgres, parsePgInterval, PgInterval } from './interval-utils'; -export type { ModuleSource, ModuleSourceChange } from './module-source'; -export { loadModuleSource, stripTransactionWrapper } from './module-source'; -export type { PartitionConfig, PartitionedPackageRows, PartitionExportRowsResult } from './partition'; -export { parsePartitionConfig, partitionExportRows } from './partition'; -export type { ExportGranularity, RestructureExportRowsOptions, RestructureExportRowsResult } from './restructure'; -export { EXPORT_GRANULARITIES, isExportGranularity, restructureExportRows } from './restructure'; export { lookupByGqlType,lookupByPgUdt, PG_TYPE_MAP, TypeMapEntry } from './type-map'; diff --git a/pgpm/import/README.md b/pgpm/import/README.md new file mode 100644 index 000000000..a52017e4f --- /dev/null +++ b/pgpm/import/README.md @@ -0,0 +1,8 @@ +# @pgpmjs/import + +`pgpm import` engine: pgpm-itize arbitrary SQL dumps (plain `pg_dump` output or raw `.sql` files) through the dials pipeline. + +- `dump-source` — preprocess dump text: strip psql backslash commands, extract `COPY ... FROM stdin` blocks, convert COPY data to INSERTs. +- `import` — `importDumpRows`: classify statements, attach riders (grants/comments/ownership) to their host objects, route through the shared restructure seam (`@pgpmjs/transform`), and emit deployable `PgpmRow`s with generated revert/verify. + +Used by the `pgpm import` CLI command (`pgpm/cli`). Sibling front doors: `@pgpmjs/export` (live database), `@pgpmjs/diff` (semantic diff). diff --git a/pgpm/export/__tests__/dump-source.test.ts b/pgpm/import/__tests__/dump-source.test.ts similarity index 100% rename from pgpm/export/__tests__/dump-source.test.ts rename to pgpm/import/__tests__/dump-source.test.ts diff --git a/pgpm/export/__tests__/import-rows.test.ts b/pgpm/import/__tests__/import-rows.test.ts similarity index 100% rename from pgpm/export/__tests__/import-rows.test.ts rename to pgpm/import/__tests__/import-rows.test.ts diff --git a/pgpm/import/jest.config.js b/pgpm/import/jest.config.js new file mode 100644 index 000000000..057a9420e --- /dev/null +++ b/pgpm/import/jest.config.js @@ -0,0 +1,18 @@ +/** @type {import('ts-jest').JestConfigWithTsJest} */ +module.exports = { + preset: 'ts-jest', + testEnvironment: 'node', + transform: { + '^.+\\.tsx?$': [ + 'ts-jest', + { + babelConfig: false, + tsconfig: 'tsconfig.json', + }, + ], + }, + transformIgnorePatterns: [`/node_modules/*`], + testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$', + moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], + modulePathIgnorePatterns: ['dist/*'] +}; diff --git a/pgpm/import/package.json b/pgpm/import/package.json new file mode 100644 index 000000000..09cb67994 --- /dev/null +++ b/pgpm/import/package.json @@ -0,0 +1,49 @@ +{ + "name": "@pgpmjs/import", + "version": "0.1.0", + "author": "Constructive ", + "description": "pgpm import — pgpm-itize arbitrary SQL dumps (pg_dump output, raw .sql) through the dials pipeline", + "main": "index.js", + "module": "esm/index.js", + "types": "index.d.ts", + "homepage": "https://github.com/constructive-io/constructive", + "license": "MIT", + "publishConfig": { + "access": "public", + "directory": "dist" + }, + "repository": { + "type": "git", + "url": "https://github.com/constructive-io/constructive" + }, + "bugs": { + "url": "https://github.com/constructive-io/constructive/issues" + }, + "scripts": { + "clean": "makage clean", + "prepack": "npm run build", + "build": "makage build", + "build:dev": "makage build --dev", + "lint": "eslint . --fix", + "test": "jest", + "test:watch": "jest --watch" + }, + "keywords": [ + "sql", + "postgres", + "postgresql", + "pgpm", + "pgpmjs", + "import", + "pg_dump", + "migration" + ], + "devDependencies": { + "makage": "^0.3.0" + }, + "dependencies": { + "@pgpmjs/ast": "workspace:^", + "@pgpmjs/naming-spec": "workspace:^", + "@pgpmjs/transform": "workspace:^" + } +} diff --git a/pgpm/export/src/dump-source.ts b/pgpm/import/src/dump-source.ts similarity index 100% rename from pgpm/export/src/dump-source.ts rename to pgpm/import/src/dump-source.ts diff --git a/pgpm/export/src/import.ts b/pgpm/import/src/import.ts similarity index 99% rename from pgpm/export/src/import.ts rename to pgpm/import/src/import.ts index b46f48c13..bb3d7b472 100644 --- a/pgpm/export/src/import.ts +++ b/pgpm/import/src/import.ts @@ -19,12 +19,11 @@ * default privileges, ...) land in a `misc/statements` change, first in * the plan, with a warning — never dropped silently. */ -import { PgpmRow } from '@pgpmjs/core'; +import { PgpmRow } from '@pgpmjs/ast'; import { ObjectIdentity, pathFor, PathStyle } from '@pgpmjs/naming-spec'; -import { classifyStatements, loadModule, regenerateScripts, StatementFacts } from '@pgpmjs/transform'; +import { classifyStatements, ExportGranularity, loadModule, regenerateScripts, restructureExportRows, StatementFacts } from '@pgpmjs/transform'; import { copyBlockToInsert, copyTargetOf, DumpSource } from './dump-source'; -import { ExportGranularity, restructureExportRows } from './restructure'; export const MISC_CHANGE_PATH = 'misc/statements'; diff --git a/pgpm/import/src/index.ts b/pgpm/import/src/index.ts new file mode 100644 index 000000000..20216789b --- /dev/null +++ b/pgpm/import/src/index.ts @@ -0,0 +1,4 @@ +export type { CopyBlock, CopyTarget, DumpSource } from './dump-source'; +export { copyBlockToInsert, copyTargetOf, dumpCompatibilityWarnings, loadDumpSource, preprocessDumpText } from './dump-source'; +export type { ImportDumpRowsOptions, ImportDumpRowsResult, ImportDumpSummary } from './import'; +export { importDumpRows, linkTextualDeps, MISC_CHANGE_PATH } from './import'; diff --git a/pgpm/import/tsconfig.esm.json b/pgpm/import/tsconfig.esm.json new file mode 100644 index 000000000..800d7506d --- /dev/null +++ b/pgpm/import/tsconfig.esm.json @@ -0,0 +1,9 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "dist/esm", + "module": "es2022", + "rootDir": "src/", + "declaration": false + } +} diff --git a/pgpm/import/tsconfig.json b/pgpm/import/tsconfig.json new file mode 100644 index 000000000..1a9d5696c --- /dev/null +++ b/pgpm/import/tsconfig.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "outDir": "dist", + "rootDir": "src/" + }, + "include": ["src/**/*.ts"], + "exclude": ["dist", "node_modules", "**/*.spec.*", "**/*.test.*"] +} diff --git a/pgpm/export/__tests__/module-source.test.ts b/pgpm/transform/__tests__/module-source.test.ts similarity index 100% rename from pgpm/export/__tests__/module-source.test.ts rename to pgpm/transform/__tests__/module-source.test.ts diff --git a/pgpm/transform/package.json b/pgpm/transform/package.json index 2cb122525..275840d6d 100644 --- a/pgpm/transform/package.json +++ b/pgpm/transform/package.json @@ -43,6 +43,7 @@ "makage": "^0.3.0" }, "dependencies": { + "@pgpmjs/ast": "workspace:^", "@pgpmjs/naming-spec": "workspace:^", "@pgsql/scripts": "^18.2.0", "@pgsql/transform": "^18.11.0", diff --git a/pgpm/export/src/catalog-check.ts b/pgpm/transform/src/catalog-check.ts similarity index 100% rename from pgpm/export/src/catalog-check.ts rename to pgpm/transform/src/catalog-check.ts diff --git a/pgpm/transform/src/index.ts b/pgpm/transform/src/index.ts index 7e58ee6f7..19f64aba2 100644 --- a/pgpm/transform/src/index.ts +++ b/pgpm/transform/src/index.ts @@ -12,6 +12,8 @@ export { makeNamespaceValidator, makeSchemaTranspiler, } from './bundle-driver'; +export type { CatalogQueryable, CatalogSnapshot } from './catalog-check'; +export { diffCatalogSnapshots, snapshotCatalog, withoutColumnOrder } from './catalog-check'; export type { CategoryProfile, ChangeCategory, @@ -39,6 +41,10 @@ export { defaultChangeName, restructureChanges, } from './granularity-driver'; +export type { ModuleSource, ModuleSourceChange } from './module-source'; +export { loadModuleSource, stripTransactionWrapper } from './module-source'; +export type { PartitionedPackageRows, PartitionExportRowsResult } from './partition'; +export { parsePartitionConfig, partitionExportRows } from './partition'; export type { PartitionConfig, PartitionedChange, @@ -69,6 +75,8 @@ export { isStubScript, regenerateScripts, } from './regen'; +export type { ExportGranularity, RestructureExportRowsOptions, RestructureExportRowsResult } from './restructure'; +export { EXPORT_GRANULARITIES, isExportGranularity, restructureExportRows } from './restructure'; export type { DiffInputChange, ObjectDelta, diff --git a/pgpm/export/src/module-source.ts b/pgpm/transform/src/module-source.ts similarity index 99% rename from pgpm/export/src/module-source.ts rename to pgpm/transform/src/module-source.ts index 99232c24b..a200970a4 100644 --- a/pgpm/export/src/module-source.ts +++ b/pgpm/transform/src/module-source.ts @@ -4,7 +4,7 @@ * consume. `pgpm transform` uses this today; a future `pgpm import` (dumps) * and `pgpm diff` are expected to reuse the same seam. */ -import { parsePgpmHeader, parsePlanFile, readScript } from '@pgpmjs/core'; +import { parsePgpmHeader, parsePlanFile, readScript } from '@pgpmjs/ast'; import * as path from 'path'; /** One change of a loaded module: headerless, unwrapped deploy SQL. */ diff --git a/pgpm/export/src/partition.ts b/pgpm/transform/src/partition.ts similarity index 93% rename from pgpm/export/src/partition.ts rename to pgpm/transform/src/partition.ts index aa389d7ef..472b2e013 100644 --- a/pgpm/export/src/partition.ts +++ b/pgpm/transform/src/partition.ts @@ -4,18 +4,15 @@ * `partitionUnits` (`@pgpmjs/transform`), and lift the emitted packages back * onto the PgpmRow seam with generated revert/verify per change. */ -import { PgpmRow } from '@pgpmjs/core'; +import { PgpmRow } from '@pgpmjs/ast'; import { PathStyle } from '@pgpmjs/naming-spec'; -import { - loadModule, - PartitionConfig, - PartitionInputChange, - partitionUnits, - regenerateScripts -} from '@pgpmjs/transform'; import * as fs from 'fs'; +import { loadModule } from 'plpgsql-parser'; -export type { PartitionConfig } from '@pgpmjs/transform'; +import { PartitionConfig, PartitionInputChange, partitionUnits } from './partition-driver'; +import { regenerateScripts } from './regen'; + +export type { PartitionConfig } from './partition-driver'; const PATH_STYLES: readonly PathStyle[] = ['directory', 'flat']; diff --git a/pgpm/export/src/restructure.ts b/pgpm/transform/src/restructure.ts similarity index 93% rename from pgpm/export/src/restructure.ts rename to pgpm/transform/src/restructure.ts index bfeaf4df9..5e8b232a7 100644 --- a/pgpm/export/src/restructure.ts +++ b/pgpm/transform/src/restructure.ts @@ -5,9 +5,12 @@ * `requires` come from the statement dependency graph instead of the * hand-chained deps recorded at action time. */ -import { PgpmRow } from '@pgpmjs/core'; +import { PgpmRow } from '@pgpmjs/ast'; import { alterationPathFor, pathFor, PathStyle } from '@pgpmjs/naming-spec'; -import { Granularity, identityOf, loadModule, restructureChanges, StatementFacts } from '@pgpmjs/transform'; +import { Granularity, identityOf, StatementFacts } from '@pgsql/transform'; +import { loadModule } from 'plpgsql-parser'; + +import { restructureChanges } from './granularity-driver'; export type ExportGranularity = Granularity; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9827619e1..99c086d06 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2807,12 +2807,18 @@ importers: '@pgpmjs/core': specifier: workspace:^ version: link:../core/dist + '@pgpmjs/diff': + specifier: workspace:^ + version: link:../diff/dist '@pgpmjs/env': specifier: workspace:^ version: link:../env/dist '@pgpmjs/export': specifier: workspace:^ version: link:../export/dist + '@pgpmjs/import': + specifier: workspace:^ + version: link:../import/dist '@pgpmjs/logger': specifier: workspace:^ version: link:../logger/dist @@ -2968,6 +2974,23 @@ importers: version: 0.3.0 publishDirectory: dist + pgpm/diff: + dependencies: + '@pgpmjs/ast': + specifier: workspace:^ + version: link:../ast/dist + '@pgpmjs/naming-spec': + specifier: workspace:^ + version: link:../naming-spec/dist + '@pgpmjs/transform': + specifier: workspace:^ + version: link:../transform/dist + devDependencies: + makage: + specifier: ^0.3.0 + version: 0.3.0 + publishDirectory: dist + pgpm/env: dependencies: 12factor-env: @@ -3041,6 +3064,23 @@ importers: version: link:../../postgres/pgsql-test/dist publishDirectory: dist + pgpm/import: + dependencies: + '@pgpmjs/ast': + specifier: workspace:^ + version: link:../ast/dist + '@pgpmjs/naming-spec': + specifier: workspace:^ + version: link:../naming-spec/dist + '@pgpmjs/transform': + specifier: workspace:^ + version: link:../transform/dist + devDependencies: + makage: + specifier: ^0.3.0 + version: 0.3.0 + publishDirectory: dist + pgpm/logger: dependencies: yanse: @@ -3104,6 +3144,9 @@ importers: pgpm/transform: dependencies: + '@pgpmjs/ast': + specifier: workspace:^ + version: link:../ast/dist '@pgpmjs/naming-spec': specifier: workspace:^ version: link:../naming-spec/dist @@ -4256,10 +4299,7 @@ packages: resolution: {integrity: sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==} '@constructive-io/eslint-config@0.2.0': - resolution: - { - integrity: sha512-BaIBn/3Oi+DcyzNqMyUQmelSD7z7MMnFQtlKr4vVrgAv8PXVkYXaY2IlfZH4MeqYactf3mDunS11+7ndOf9oVw==, - } + resolution: {integrity: sha512-BaIBn/3Oi+DcyzNqMyUQmelSD7z7MMnFQtlKr4vVrgAv8PXVkYXaY2IlfZH4MeqYactf3mDunS11+7ndOf9oVw==} peerDependencies: eslint: ^9 @@ -7989,11 +8029,8 @@ packages: engines: {node: '>=18'} globals@17.8.0: - resolution: - { - integrity: sha512-Zz/LMDZScFmkakeL2cTHzf+PbWKdpU3uclqkZT7TjDG58j5WPt0PpA+n9uPI24fZtlw07q0OtEi84K+umsRzqQ==, - } - engines: { node: '>=18' } + resolution: {integrity: sha512-Zz/LMDZScFmkakeL2cTHzf+PbWKdpU3uclqkZT7TjDG58j5WPt0PpA+n9uPI24fZtlw07q0OtEi84K+umsRzqQ==} + engines: {node: '>=18'} google-auth-library@10.9.1: resolution: {integrity: sha512-i1ydyHrqcIxXkWh/uBmVkzCvIuq5yiK2ATndIe5XxKholrG/MTYP9xGYka4sQhrbIAgGjL2B6NOE7rFaiF3fXw==}