@pgpmjs/transform 0.20.0 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bundle-driver.js CHANGED
@@ -13,8 +13,8 @@ exports.buildExtensionRouter = buildExtensionRouter;
13
13
  exports.buildSchemaRouter = buildSchemaRouter;
14
14
  exports.makeSchemaTranspiler = makeSchemaTranspiler;
15
15
  exports.makeNamespaceValidator = makeNamespaceValidator;
16
+ const semantics_1 = require("@pgsql/semantics");
16
17
  const transform_1 = require("@pgsql/transform");
17
- const transform_2 = require("@pgsql/transform");
18
18
  /**
19
19
  * Build an {@link ExtensionRouter} from the declarative {@link ExtensionRoutingInput}:
20
20
  * an explicit `routes` spec when given, otherwise the "move everything matched
@@ -27,8 +27,8 @@ function buildExtensionRouter(input) {
27
27
  if (input.inventory)
28
28
  opts.inventory = input.inventory;
29
29
  if (input.routes)
30
- return new transform_2.ExtensionRouter(input.routes, opts);
31
- return transform_2.ExtensionRouter.toSchema(input.toSchema ?? null, {
30
+ return new transform_1.ExtensionRouter(input.routes, opts);
31
+ return transform_1.ExtensionRouter.toSchema(input.toSchema ?? null, {
32
32
  ...opts,
33
33
  extensions: input.only,
34
34
  from: input.from
@@ -75,7 +75,7 @@ function buildSchemaRouter(options) {
75
75
  ...(route.toName !== undefined ? { name: route.toName } : {})
76
76
  };
77
77
  }
78
- return new transform_2.SchemaRouter(spec);
78
+ return new transform_1.SchemaRouter(spec);
79
79
  }
80
80
  /**
81
81
  * Rewrite the schema segment of a pgpm change path to the object's routed
@@ -125,14 +125,14 @@ function makeSchemaTranspiler(options) {
125
125
  // after schema routing on each script. Each is a self-contained parse →
126
126
  // rewrite → deparse pass, so they compose by threading the SQL through.
127
127
  const extRouter = options.extensions ? buildExtensionRouter(options.extensions) : undefined;
128
- const roleRouter = options.roles ? transform_2.RoleRouter.from(options.roles) : undefined;
129
- const extensionResult = extRouter ? (0, transform_2.createExtensionResult)() : undefined;
130
- const roleResult = roleRouter ? (0, transform_2.createRoleResult)() : undefined;
128
+ const roleRouter = options.roles ? transform_1.RoleRouter.from(options.roles) : undefined;
129
+ const extensionResult = extRouter ? (0, transform_1.createExtensionResult)() : undefined;
130
+ const roleResult = roleRouter ? (0, transform_1.createRoleResult)() : undefined;
131
131
  const renameChange = (name) => renameChangePath(name, router);
132
132
  const transformScript = (sql, _ctx) => {
133
- let out = (0, transform_2.transformSql)(sql, router, options.transform, result).content;
133
+ let out = (0, transform_1.transformSql)(sql, router, options.transform, result).content;
134
134
  if (extRouter) {
135
- const r = (0, transform_2.transformExtensions)(out, extRouter);
135
+ const r = (0, transform_1.transformExtensions)(out, extRouter);
136
136
  out = r.sql;
137
137
  for (const [name, schema] of r.result.installsMoved) {
138
138
  extensionResult.installsMoved.set(name, schema);
@@ -142,7 +142,7 @@ function makeSchemaTranspiler(options) {
142
142
  }
143
143
  }
144
144
  if (roleRouter) {
145
- const r = (0, transform_2.transformRoles)(out, roleRouter);
145
+ const r = (0, transform_1.transformRoles)(out, roleRouter);
146
146
  out = r.sql;
147
147
  for (const [name, count] of r.result.rolesRenamed) {
148
148
  roleResult.rolesRenamed.set(name, (roleResult.rolesRenamed.get(name) ?? 0) + count);
@@ -162,7 +162,7 @@ function makeNamespaceValidator(options) {
162
162
  const allowed = new Set(options.allowedSchemas);
163
163
  return (sql, _ctx) => {
164
164
  const violations = new Set();
165
- for (const facts of (0, transform_1.classifyStatements)(sql)) {
165
+ for (const facts of (0, semantics_1.classifyStatements)(sql)) {
166
166
  for (const ref of [...facts.creates, ...facts.references, ...facts.fkTargets]) {
167
167
  if (ref.schema && !allowed.has(ref.schema)) {
168
168
  violations.add(`${facts.nodeTag}: ${ref.schema}.${ref.name}`);
package/categorize.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { StatementFacts } from '@pgsql/transform';
1
+ import { StatementFacts } from '@pgsql/semantics';
2
2
  /**
3
3
  * A category is a chunk-seam key a change is assigned to. Free-form string; the
4
4
  * built-in {@link TIER_PROFILE} uses `'security' | 'functionality' | 'fixtures'
package/categorize.js CHANGED
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TIER_PROFILE = void 0;
4
4
  exports.categorizeChange = categorizeChange;
5
5
  exports.buildCategoryOf = buildCategoryOf;
6
- const transform_1 = require("@pgsql/transform");
6
+ const semantics_1 = require("@pgsql/semantics");
7
7
  /**
8
8
  * Default tier profile: isolates the security surface and procedural code out
9
9
  * of the schema base. Precedence, highest first — a change is placed in the
@@ -37,7 +37,7 @@ exports.TIER_PROFILE = {
37
37
  * (defaults to {@link TIER_PROFILE}).
38
38
  */
39
39
  function categorizeChange(sql, changeName, profile = exports.TIER_PROFILE) {
40
- return profile.categorize((0, transform_1.classifyStatements)(sql), changeName);
40
+ return profile.categorize((0, semantics_1.classifyStatements)(sql), changeName);
41
41
  }
42
42
  /**
43
43
  * Build a `categoryOf(changeName)` seam function from a map of change name to
@@ -7,7 +7,7 @@
7
7
  * purpose — no dependency on `@pgpmjs/bundle`/`@pgpmjs/core` — so the driver
8
8
  * stays a pure function factory over `transformSql` and `classifyStatements`.
9
9
  */
10
- import { classifyStatements } from '@pgsql/transform';
10
+ import { classifyStatements } from '@pgsql/semantics';
11
11
  import { createExtensionResult, createRoleResult, ExtensionRouter, RoleRouter, SchemaRouter, transformExtensions, transformRoles, transformSql } from '@pgsql/transform';
12
12
  /**
13
13
  * Build an {@link ExtensionRouter} from the declarative {@link ExtensionRoutingInput}:
package/esm/categorize.js CHANGED
@@ -1,4 +1,4 @@
1
- import { classifyStatements } from '@pgsql/transform';
1
+ import { classifyStatements } from '@pgsql/semantics';
2
2
  /**
3
3
  * Default tier profile: isolates the security surface and procedural code out
4
4
  * of the schema base. Precedence, highest first — a change is placed in the
@@ -1,4 +1,4 @@
1
- import { classifyStatements } from '@pgsql/transform';
1
+ import { classifyStatements } from '@pgsql/semantics';
2
2
  import { TIER_PROFILE } from './categorize';
3
3
  function objectKey(schema, name) {
4
4
  return `${schema ?? ''}\u0000${name}`;
@@ -1,6 +1,7 @@
1
1
  import { pathFor } from '@pgpmjs/naming-spec';
2
2
  import { revertFor, verifyFor } from '@pgsql/scripts';
3
- import { buildStatementGraph, classifyStatements, identityOf, restructureSql } from '@pgsql/transform';
3
+ import { classifyStatements } from '@pgsql/semantics';
4
+ import { buildStatementGraph, identityOf, restructureSql } from '@pgsql/transform';
4
5
  import { nameUnnamedConstraints, subObjectIdentityOf } from './sub-object';
5
6
  export const CHANGE_GRANULARITIES = ['alteration', 'object', 'single'];
6
7
  export const isChangeGranularity = (value) => CHANGE_GRANULARITIES.includes(value);
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Partition dial: project one deploy surface into a set of pgpm packages.
3
3
  *
4
- * The object graph (statements classified by `@pgsql/transform`, grouped
4
+ * The object graph (statements classified by `@pgsql/semantics`, grouped
5
5
  * into identity-keyed units) is the source of truth; which package a unit
6
6
  * lives in is a *derived projection* of a declarative partition config.
7
7
  * Units can be assigned by schema, by object kind, by explicit cherry-pick
@@ -21,7 +21,8 @@
21
21
  * pgpm.plan + deploy trees, feed a bundle, ...).
22
22
  */
23
23
  import { pathFor } from '@pgpmjs/naming-spec';
24
- import { buildStatementGraph, classifyStatements, identityOf } from '@pgsql/transform';
24
+ import { classifyStatements } from '@pgsql/semantics';
25
+ import { buildStatementGraph, identityOf } from '@pgsql/transform';
25
26
  /** A partition whose packages require each other in a cycle — unshippable. */
26
27
  export class PartitionCycleError extends Error {
27
28
  packages;
package/esm/program.js CHANGED
@@ -1,4 +1,4 @@
1
- import { classifyStatements } from '@pgsql/transform';
1
+ import { classifyStatements } from '@pgsql/semantics';
2
2
  import { Deparser, parseSql } from 'plpgsql-parser';
3
3
  /**
4
4
  * Parse a SQL script into a statement program. Requires `loadModule()` from
package/esm/regen.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { revertFor, verifyFor } from '@pgsql/scripts';
2
- import { classifyStatements } from '@pgsql/transform';
2
+ import { classifyStatements } from '@pgsql/semantics';
3
3
  /**
4
4
  * Classify a pgpm script's substantive statements: every top-level statement
5
5
  * except transaction control (`BEGIN`/`COMMIT`/`ROLLBACK` wrappers).
@@ -28,7 +28,8 @@
28
28
  */
29
29
  import { pathFor } from '@pgpmjs/naming-spec';
30
30
  import { existenceCheck, invertStatement, revertFor, verifyFor } from '@pgsql/scripts';
31
- import { buildStatementGraph, classifyStatements, cleanTree, identityOf } from '@pgsql/transform';
31
+ import { classifyStatements } from '@pgsql/semantics';
32
+ import { buildStatementGraph, cleanTree, identityOf } from '@pgsql/transform';
32
33
  import { Deparser, parseSync } from 'plpgsql-parser';
33
34
  import { defaultConstraintName } from './constraint-names';
34
35
  import { restructureChanges } from './granularity-driver';
@@ -1,4 +1,4 @@
1
- import { QualifiedName } from '@pgsql/transform';
1
+ import { QualifiedName } from '@pgsql/semantics';
2
2
  import { CategoryProfile, ChangeCategory } from './categorize';
3
3
  /**
4
4
  * A change plus its deploy SQL. Optional plan `dependencies` (from `pgpm.plan`)
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.resolveFixtureClosure = resolveFixtureClosure;
4
- const transform_1 = require("@pgsql/transform");
4
+ const semantics_1 = require("@pgsql/semantics");
5
5
  const categorize_1 = require("./categorize");
6
6
  function objectKey(schema, name) {
7
7
  return `${schema ?? ''}\u0000${name}`;
8
8
  }
9
9
  function analyze(change, profile) {
10
- const facts = (0, transform_1.classifyStatements)(change.sql);
10
+ const facts = (0, semantics_1.classifyStatements)(change.sql);
11
11
  const category = profile.categorize(facts, change.name);
12
12
  const creates = [];
13
13
  const createsSchemas = [];
@@ -18,7 +18,8 @@
18
18
  * - `consolidated` — additionally inlines FKs proven safe by the graph.
19
19
  */
20
20
  import type { ObjectIdentity as NamingIdentity } from '@pgpmjs/naming-spec';
21
- import type { Granularity, StatementFacts } from '@pgsql/transform';
21
+ import type { StatementFacts } from '@pgsql/semantics';
22
+ import type { Granularity } from '@pgsql/transform';
22
23
  export type { Granularity } from '@pgsql/transform';
23
24
  /**
24
25
  * How statements are distributed across pgpm changes — orthogonal to
@@ -5,6 +5,7 @@ exports.defaultChangeName = defaultChangeName;
5
5
  exports.restructureChanges = restructureChanges;
6
6
  const naming_spec_1 = require("@pgpmjs/naming-spec");
7
7
  const scripts_1 = require("@pgsql/scripts");
8
+ const semantics_1 = require("@pgsql/semantics");
8
9
  const transform_1 = require("@pgsql/transform");
9
10
  const sub_object_1 = require("./sub-object");
10
11
  exports.CHANGE_GRANULARITIES = ['alteration', 'object', 'single'];
@@ -57,7 +58,7 @@ function restructureChanges(changes, options) {
57
58
  // Re-classify the emitted script; group statements by the object they
58
59
  // target (creates[0]), so a table's CREATE and its remaining ALTERs land
59
60
  // in the same change regardless of statement kind.
60
- const facts = (0, transform_1.classifyStatements)(sql);
61
+ const facts = (0, semantics_1.classifyStatements)(sql);
61
62
  if (options.changeGranularity === 'single') {
62
63
  const name = options.singleChangeName ?? 'module/init';
63
64
  const inputNames = new Set(changes.map(c => c.name));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pgpmjs/transform",
3
- "version": "0.20.0",
3
+ "version": "0.21.0",
4
4
  "author": "Constructive <developers@constructive.io>",
5
5
  "description": "Change-aware SQL transformation for PGPM — superset of @pgsql/transform plus change categorization, fixture closure, and bundle transpile/apply drivers",
6
6
  "main": "index.js",
@@ -39,15 +39,16 @@
39
39
  "plpgsql"
40
40
  ],
41
41
  "devDependencies": {
42
- "@pgpmjs/bundle": "^0.13.3",
42
+ "@pgpmjs/bundle": "^0.14.0",
43
43
  "makage": "^0.3.0"
44
44
  },
45
45
  "dependencies": {
46
- "@pgpmjs/ast": "^0.10.3",
47
- "@pgpmjs/naming-spec": "^0.2.0",
48
- "@pgsql/scripts": "^18.3.1",
49
- "@pgsql/transform": "^18.14.1",
46
+ "@pgpmjs/ast": "^0.11.0",
47
+ "@pgpmjs/naming-spec": "^0.3.0",
48
+ "@pgsql/scripts": "^18.3.2",
49
+ "@pgsql/semantics": "^18.1.0",
50
+ "@pgsql/transform": "^18.15.0",
50
51
  "plpgsql-parser": "^18.5.1"
51
52
  },
52
- "gitHead": "e6a7a57f88c9deb2a4acecaba2451320d1be8203"
53
+ "gitHead": "d508453a32a2f1d70ff6916871046615226e6f33"
53
54
  }
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Partition dial: project one deploy surface into a set of pgpm packages.
3
3
  *
4
- * The object graph (statements classified by `@pgsql/transform`, grouped
4
+ * The object graph (statements classified by `@pgsql/semantics`, grouped
5
5
  * into identity-keyed units) is the source of truth; which package a unit
6
6
  * lives in is a *derived projection* of a declarative partition config.
7
7
  * Units can be assigned by schema, by object kind, by explicit cherry-pick
@@ -21,7 +21,8 @@
21
21
  * pgpm.plan + deploy trees, feed a bundle, ...).
22
22
  */
23
23
  import { PathStyle } from '@pgpmjs/naming-spec';
24
- import { ObjectIdentity, ObjectIdentityKind, StatementKind } from '@pgsql/transform';
24
+ import { StatementKind } from '@pgsql/semantics';
25
+ import { ObjectIdentity, ObjectIdentityKind } from '@pgsql/transform';
25
26
  /** One deployable unit: an object (by identity) and the statements that build it. */
26
27
  export interface PartitionUnit {
27
28
  /** The object's identity, or `null` for split riders and the residual unit. */
@@ -5,7 +5,7 @@ exports.partitionUnits = partitionUnits;
5
5
  /**
6
6
  * Partition dial: project one deploy surface into a set of pgpm packages.
7
7
  *
8
- * The object graph (statements classified by `@pgsql/transform`, grouped
8
+ * The object graph (statements classified by `@pgsql/semantics`, grouped
9
9
  * into identity-keyed units) is the source of truth; which package a unit
10
10
  * lives in is a *derived projection* of a declarative partition config.
11
11
  * Units can be assigned by schema, by object kind, by explicit cherry-pick
@@ -25,6 +25,7 @@ exports.partitionUnits = partitionUnits;
25
25
  * pgpm.plan + deploy trees, feed a bundle, ...).
26
26
  */
27
27
  const naming_spec_1 = require("@pgpmjs/naming-spec");
28
+ const semantics_1 = require("@pgsql/semantics");
28
29
  const transform_1 = require("@pgsql/transform");
29
30
  /** A partition whose packages require each other in a cycle — unshippable. */
30
31
  class PartitionCycleError extends Error {
@@ -84,7 +85,7 @@ exports.RESIDUAL_UNIT_PATH = 'misc/statements';
84
85
  * otherwise) that depend on their host unit.
85
86
  */
86
87
  function buildUnitGraph(sql, style, splitRiders) {
87
- const facts = (0, transform_1.classifyStatements)(sql);
88
+ const facts = (0, semantics_1.classifyStatements)(sql);
88
89
  const graph = (0, transform_1.buildStatementGraph)(facts);
89
90
  const unitOf = new Array(facts.length).fill(-1);
90
91
  const units = [];
package/program.d.ts CHANGED
@@ -9,7 +9,7 @@
9
9
  * untouched statements). A program with no dirty statements emits its source
10
10
  * byte-identically, so content-addressed hashes are preserved.
11
11
  */
12
- import type { StatementFacts } from '@pgsql/transform';
12
+ import type { StatementFacts } from '@pgsql/semantics';
13
13
  /** A statement's location in the source script (byte offsets). */
14
14
  export type SqlStatementSpan = StatementFacts['span'];
15
15
  /** One statement of a parsed SQL script. */
package/program.js CHANGED
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseSqlProgram = parseSqlProgram;
4
4
  exports.emitSqlProgram = emitSqlProgram;
5
- const transform_1 = require("@pgsql/transform");
5
+ const semantics_1 = require("@pgsql/semantics");
6
6
  const plpgsql_parser_1 = require("plpgsql-parser");
7
7
  /**
8
8
  * Parse a SQL script into a statement program. Requires `loadModule()` from
@@ -11,7 +11,7 @@ const plpgsql_parser_1 = require("plpgsql-parser");
11
11
  function parseSqlProgram(source) {
12
12
  const parseResult = (0, plpgsql_parser_1.parseSql)(source);
13
13
  const stmts = parseResult?.stmts ?? [];
14
- const facts = (0, transform_1.classifyStatements)(source);
14
+ const facts = (0, semantics_1.classifyStatements)(source);
15
15
  const statements = [];
16
16
  for (let i = 0; i < stmts.length; i++) {
17
17
  const rawStmt = stmts[i];
package/regen.d.ts CHANGED
@@ -12,7 +12,7 @@
12
12
  * Requires `loadModule()` from `plpgsql-parser` to have completed.
13
13
  */
14
14
  import type { GeneratedScript } from '@pgsql/scripts';
15
- import type { StatementFacts } from '@pgsql/transform';
15
+ import type { StatementFacts } from '@pgsql/semantics';
16
16
  export type { GeneratedScript } from '@pgsql/scripts';
17
17
  /** Generated revert and verify scripts for one change's deploy SQL. */
18
18
  export interface RegeneratedScripts {
package/regen.js CHANGED
@@ -4,13 +4,13 @@ exports.classifyScript = classifyScript;
4
4
  exports.isStubScript = isStubScript;
5
5
  exports.regenerateScripts = regenerateScripts;
6
6
  const scripts_1 = require("@pgsql/scripts");
7
- const transform_1 = require("@pgsql/transform");
7
+ const semantics_1 = require("@pgsql/semantics");
8
8
  /**
9
9
  * Classify a pgpm script's substantive statements: every top-level statement
10
10
  * except transaction control (`BEGIN`/`COMMIT`/`ROLLBACK` wrappers).
11
11
  */
12
12
  function classifyScript(sql) {
13
- return (0, transform_1.classifyStatements)(sql).filter(f => f.nodeTag !== 'TransactionStmt');
13
+ return (0, semantics_1.classifyStatements)(sql).filter(f => f.nodeTag !== 'TransactionStmt');
14
14
  }
15
15
  /**
16
16
  * Whether a script is an empty stub: nothing but comments, whitespace, and
@@ -32,6 +32,7 @@ exports.diffChangeSets = diffChangeSets;
32
32
  */
33
33
  const naming_spec_1 = require("@pgpmjs/naming-spec");
34
34
  const scripts_1 = require("@pgsql/scripts");
35
+ const semantics_1 = require("@pgsql/semantics");
35
36
  const transform_1 = require("@pgsql/transform");
36
37
  const plpgsql_parser_1 = require("plpgsql-parser");
37
38
  const constraint_names_1 = require("./constraint-names");
@@ -44,7 +45,7 @@ const identityKey = (id) => `${id.kind}\u0000${id.schema ?? ''}\u0000${id.table
44
45
  * statements are reported via `warnings`.
45
46
  */
46
47
  function readSide(sql, warnings, label) {
47
- const facts = (0, transform_1.classifyStatements)(sql);
48
+ const facts = (0, semantics_1.classifyStatements)(sql);
48
49
  const graph = (0, transform_1.buildStatementGraph)(facts);
49
50
  const units = new Map();
50
51
  const order = [];
@@ -367,7 +368,7 @@ function diffSchemas(from, to, options = {}) {
367
368
  * statement to surface its not-derivable comment and warning.
368
369
  */
369
370
  const inverseOf = (deploy, context) => {
370
- const facts = (0, transform_1.classifyStatements)(deploy);
371
+ const facts = (0, semantics_1.classifyStatements)(deploy);
371
372
  const graph = (0, transform_1.buildStatementGraph)(facts);
372
373
  const pieces = [];
373
374
  for (const i of [...graph.order].reverse()) {
@@ -390,7 +391,7 @@ function diffSchemas(from, to, options = {}) {
390
391
  */
391
392
  const verifyOf = (deploy, context) => {
392
393
  const pieces = [];
393
- for (const fact of (0, transform_1.classifyStatements)(deploy)) {
394
+ for (const fact of (0, semantics_1.classifyStatements)(deploy)) {
394
395
  const nodes = (0, scripts_1.existenceCheck)(fact);
395
396
  if (nodes === null) {
396
397
  const { warnings: w } = (0, scripts_1.verifyFor)([fact]);
package/sub-object.d.ts CHANGED
@@ -10,7 +10,7 @@
10
10
  * every alteration.
11
11
  */
12
12
  import type { ObjectIdentity } from '@pgpmjs/naming-spec';
13
- import type { StatementFacts } from '@pgsql/transform';
13
+ import type { StatementFacts } from '@pgsql/semantics';
14
14
  /**
15
15
  * The column or constraint a one-command `ALTER TABLE .. ADD COLUMN` /
16
16
  * `ADD CONSTRAINT` statement adds, as a naming-spec identity