@pgpmjs/core 4.5.0 → 4.5.2

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.
@@ -6,6 +6,7 @@ import { getPgPool } from 'pg-cache';
6
6
  import { PgpmPackage } from '../core/class/pgpm';
7
7
  import { writePgpmFiles, writePgpmPlan } from '../files';
8
8
  import { getMissingInstallableModules } from '../modules/modules';
9
+ import { parseAuthor } from '../utils/author';
9
10
  import { exportMeta } from './export-meta';
10
11
  /**
11
12
  * Required extensions for database schema exports.
@@ -244,6 +245,7 @@ const preparePackage = async ({ project, author, outdir, name, description, exte
244
245
  process.chdir(pgpmDir);
245
246
  const plan = glob(path.join(pgpmDir, 'pgpm.plan'));
246
247
  if (!plan.length) {
248
+ const { fullName, email } = parseAuthor(author);
247
249
  await project.initModule({
248
250
  name,
249
251
  description,
@@ -253,7 +255,9 @@ const preparePackage = async ({ project, author, outdir, name, description, exte
253
255
  moduleName: name,
254
256
  moduleDesc: description,
255
257
  access: 'restricted',
256
- license: 'CLOSED'
258
+ license: 'CLOSED',
259
+ fullName,
260
+ ...(email && { email })
257
261
  }
258
262
  });
259
263
  }
@@ -1,5 +1,6 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
+ import { parseAuthor } from '../../utils/author';
3
4
  /**
4
5
  * Write a PGPM plan file based on the provided rows
5
6
  */
@@ -7,22 +8,9 @@ export function writePgpmPlan(rows, opts) {
7
8
  const dir = path.resolve(path.join(opts.outdir, opts.name));
8
9
  fs.mkdirSync(dir, { recursive: true });
9
10
  const date = () => '2017-08-11T08:11:51Z'; // stubbed timestamp
10
- // Parse author string - it might contain email in format "Name <email>"
11
- const authorInput = (opts.author || 'constructive').trim();
12
- let authorName = authorInput;
13
- let authorEmail = '';
14
- // Check if author already contains email in <...> format
15
- const emailMatch = authorInput.match(/^(.+?)\s*<([^>]+)>\s*$/);
16
- if (emailMatch) {
17
- // Author already has email format: "Name <email>"
18
- authorName = emailMatch[1].trim();
19
- authorEmail = emailMatch[2].trim();
20
- }
21
- else {
22
- // No email in author, use default format
23
- authorName = authorInput;
24
- authorEmail = `${authorName}@5b0c196eeb62`;
25
- }
11
+ const { fullName, email } = parseAuthor(opts.author || 'constructive');
12
+ const authorName = fullName;
13
+ const authorEmail = email || `${fullName}@5b0c196eeb62`;
26
14
  const duplicates = {};
27
15
  const plan = opts.replacer(`%syntax-version=1.0.0
28
16
  %project=constructive-extension-name
@@ -24,7 +24,7 @@ const filterStatements = (stmts, extension) => {
24
24
  !stmt.hasOwnProperty('CreateExtensionStmt');
25
25
  });
26
26
  };
27
- export const packageModule = async (packageDir, { usePlan = true, extension = true, pretty = true, functionDelimiter = '$EOFCODE$' } = {}) => {
27
+ export const packageModule = async (packageDir, { usePlan = true, extension = true, pretty = true, functionDelimiter = '$EOFCODE$', outputDiff = false } = {}) => {
28
28
  const resolveFn = usePlan ? resolveWithPlan : resolve;
29
29
  const sql = resolveFn(packageDir);
30
30
  if (!sql?.trim()) {
@@ -43,7 +43,8 @@ export const packageModule = async (packageDir, { usePlan = true, extension = tr
43
43
  functionDelimiter
44
44
  });
45
45
  const tree1 = parsed.stmts;
46
- const tree2 = await parse(finalSql);
46
+ const reparsed = await parse(finalSql);
47
+ const tree2 = filterStatements(reparsed.stmts, extension);
47
48
  const results = {
48
49
  sql: `${topLine}${finalSql}`,
49
50
  };
@@ -61,7 +62,7 @@ export const packageModule = async (packageDir, { usePlan = true, extension = tr
61
62
  throw e;
62
63
  }
63
64
  };
64
- export const writePackage = async ({ version, extension = true, usePlan = true, packageDir, }) => {
65
+ export const writePackage = async ({ version, extension = true, usePlan = true, packageDir, outputDiff = false, }) => {
65
66
  const pkgPath = `${packageDir}/package.json`;
66
67
  const pkg = require(pkgPath);
67
68
  const extname = await getExtensionName(packageDir);
@@ -73,6 +74,7 @@ export const writePackage = async ({ version, extension = true, usePlan = true,
73
74
  const { sql, diff, tree1, tree2 } = await packageModule(packageDir, {
74
75
  extension,
75
76
  usePlan,
77
+ outputDiff,
76
78
  });
77
79
  const outPath = extension ? `${packageDir}/sql` : `${packageDir}/out`;
78
80
  rmSync(outPath, { recursive: true, force: true });
@@ -85,10 +87,14 @@ export const writePackage = async ({ version, extension = true, usePlan = true,
85
87
  writeFileSync(makePath, Makefile.replace(regex, sqlFileName));
86
88
  }
87
89
  if (diff) {
88
- log.warn(`⚠️ SQL diff exists! Review the ${relative(packageDir, outPath)}/ folder.`);
89
- // Uncomment if needed:
90
- // writeFileSync(`${outPath}/orig.${sqlFileName}.tree.json`, tree1);
91
- // writeFileSync(`${outPath}/parsed.${sqlFileName}.tree.json`, tree2);
90
+ if (outputDiff) {
91
+ writeFileSync(`${outPath}/orig.${sqlFileName}.tree.json`, tree1);
92
+ writeFileSync(`${outPath}/parsed.${sqlFileName}.tree.json`, tree2);
93
+ log.warn(`⚠️ AST round-trip diff detected! Diff files written to ${relative(packageDir, outPath)}/`);
94
+ }
95
+ else {
96
+ log.warn(`⚠️ AST round-trip diff detected! Run with --outputDiff to export the AST diff files.`);
97
+ }
92
98
  }
93
99
  const writePath = `${outPath}/${sqlFileName}`;
94
100
  writeFileSync(writePath, sql);
@@ -0,0 +1,11 @@
1
+ export function parseAuthor(author) {
2
+ const trimmed = (author || '').trim();
3
+ const match = trimmed.match(/^(.+?)\s*<([^>]+)>$/);
4
+ if (match) {
5
+ return {
6
+ fullName: match[1].trim(),
7
+ email: match[2].trim()
8
+ };
9
+ }
10
+ return { fullName: trimmed };
11
+ }
@@ -12,6 +12,7 @@ const pg_cache_1 = require("pg-cache");
12
12
  const pgpm_1 = require("../core/class/pgpm");
13
13
  const files_1 = require("../files");
14
14
  const modules_1 = require("../modules/modules");
15
+ const author_1 = require("../utils/author");
15
16
  const export_meta_1 = require("./export-meta");
16
17
  /**
17
18
  * Required extensions for database schema exports.
@@ -251,6 +252,7 @@ const preparePackage = async ({ project, author, outdir, name, description, exte
251
252
  process.chdir(pgpmDir);
252
253
  const plan = (0, glob_1.sync)(path_1.default.join(pgpmDir, 'pgpm.plan'));
253
254
  if (!plan.length) {
255
+ const { fullName, email } = (0, author_1.parseAuthor)(author);
254
256
  await project.initModule({
255
257
  name,
256
258
  description,
@@ -260,7 +262,9 @@ const preparePackage = async ({ project, author, outdir, name, description, exte
260
262
  moduleName: name,
261
263
  moduleDesc: description,
262
264
  access: 'restricted',
263
- license: 'CLOSED'
265
+ license: 'CLOSED',
266
+ fullName,
267
+ ...(email && { email })
264
268
  }
265
269
  });
266
270
  }
@@ -11,6 +11,7 @@ exports.generateChangeLineContent = generateChangeLineContent;
11
11
  exports.generateTagLineContent = generateTagLineContent;
12
12
  const fs_1 = __importDefault(require("fs"));
13
13
  const path_1 = __importDefault(require("path"));
14
+ const author_1 = require("../../utils/author");
14
15
  /**
15
16
  * Write a PGPM plan file based on the provided rows
16
17
  */
@@ -18,22 +19,9 @@ function writePgpmPlan(rows, opts) {
18
19
  const dir = path_1.default.resolve(path_1.default.join(opts.outdir, opts.name));
19
20
  fs_1.default.mkdirSync(dir, { recursive: true });
20
21
  const date = () => '2017-08-11T08:11:51Z'; // stubbed timestamp
21
- // Parse author string - it might contain email in format "Name <email>"
22
- const authorInput = (opts.author || 'constructive').trim();
23
- let authorName = authorInput;
24
- let authorEmail = '';
25
- // Check if author already contains email in <...> format
26
- const emailMatch = authorInput.match(/^(.+?)\s*<([^>]+)>\s*$/);
27
- if (emailMatch) {
28
- // Author already has email format: "Name <email>"
29
- authorName = emailMatch[1].trim();
30
- authorEmail = emailMatch[2].trim();
31
- }
32
- else {
33
- // No email in author, use default format
34
- authorName = authorInput;
35
- authorEmail = `${authorName}@5b0c196eeb62`;
36
- }
22
+ const { fullName, email } = (0, author_1.parseAuthor)(opts.author || 'constructive');
23
+ const authorName = fullName;
24
+ const authorEmail = email || `${fullName}@5b0c196eeb62`;
37
25
  const duplicates = {};
38
26
  const plan = opts.replacer(`%syntax-version=1.0.0
39
27
  %project=constructive-extension-name
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pgpmjs/core",
3
- "version": "4.5.0",
3
+ "version": "4.5.2",
4
4
  "author": "Constructive <developers@constructive.io>",
5
5
  "description": "PGPM Package and Migration Tools",
6
6
  "main": "index.js",
@@ -64,5 +64,5 @@
64
64
  "pgsql-parser": "^17.9.5",
65
65
  "yanse": "^0.1.8"
66
66
  },
67
- "gitHead": "09721f934b339bd8c55d2e633abaded6d20b0f65"
67
+ "gitHead": "3768b497b5b65410a23bcf7e01ed4192a5f1dd95"
68
68
  }
@@ -4,16 +4,17 @@ interface PackageModuleOptions {
4
4
  extension?: boolean;
5
5
  pretty?: boolean;
6
6
  functionDelimiter?: string;
7
+ outputDiff?: boolean;
7
8
  }
8
9
  interface WritePackageOptions extends PackageModuleOptions {
9
10
  version: string;
10
11
  packageDir: string;
11
12
  }
12
- export declare const packageModule: (packageDir: string, { usePlan, extension, pretty, functionDelimiter }?: PackageModuleOptions) => Promise<{
13
+ export declare const packageModule: (packageDir: string, { usePlan, extension, pretty, functionDelimiter, outputDiff }?: PackageModuleOptions) => Promise<{
13
14
  sql: string;
14
15
  diff?: boolean;
15
16
  tree1?: string;
16
17
  tree2?: string;
17
18
  }>;
18
- export declare const writePackage: ({ version, extension, usePlan, packageDir, }: WritePackageOptions) => Promise<void>;
19
+ export declare const writePackage: ({ version, extension, usePlan, packageDir, outputDiff, }: WritePackageOptions) => Promise<void>;
19
20
  export {};
@@ -28,7 +28,7 @@ const filterStatements = (stmts, extension) => {
28
28
  !stmt.hasOwnProperty('CreateExtensionStmt');
29
29
  });
30
30
  };
31
- const packageModule = async (packageDir, { usePlan = true, extension = true, pretty = true, functionDelimiter = '$EOFCODE$' } = {}) => {
31
+ const packageModule = async (packageDir, { usePlan = true, extension = true, pretty = true, functionDelimiter = '$EOFCODE$', outputDiff = false } = {}) => {
32
32
  const resolveFn = usePlan ? resolve_1.resolveWithPlan : resolve_1.resolve;
33
33
  const sql = resolveFn(packageDir);
34
34
  if (!sql?.trim()) {
@@ -47,7 +47,8 @@ const packageModule = async (packageDir, { usePlan = true, extension = true, pre
47
47
  functionDelimiter
48
48
  });
49
49
  const tree1 = parsed.stmts;
50
- const tree2 = await (0, pgsql_parser_1.parse)(finalSql);
50
+ const reparsed = await (0, pgsql_parser_1.parse)(finalSql);
51
+ const tree2 = filterStatements(reparsed.stmts, extension);
51
52
  const results = {
52
53
  sql: `${topLine}${finalSql}`,
53
54
  };
@@ -66,7 +67,7 @@ const packageModule = async (packageDir, { usePlan = true, extension = true, pre
66
67
  }
67
68
  };
68
69
  exports.packageModule = packageModule;
69
- const writePackage = async ({ version, extension = true, usePlan = true, packageDir, }) => {
70
+ const writePackage = async ({ version, extension = true, usePlan = true, packageDir, outputDiff = false, }) => {
70
71
  const pkgPath = `${packageDir}/package.json`;
71
72
  const pkg = require(pkgPath);
72
73
  const extname = await (0, files_1.getExtensionName)(packageDir);
@@ -78,6 +79,7 @@ const writePackage = async ({ version, extension = true, usePlan = true, package
78
79
  const { sql, diff, tree1, tree2 } = await (0, exports.packageModule)(packageDir, {
79
80
  extension,
80
81
  usePlan,
82
+ outputDiff,
81
83
  });
82
84
  const outPath = extension ? `${packageDir}/sql` : `${packageDir}/out`;
83
85
  (0, fs_1.rmSync)(outPath, { recursive: true, force: true });
@@ -90,10 +92,14 @@ const writePackage = async ({ version, extension = true, usePlan = true, package
90
92
  (0, fs_1.writeFileSync)(makePath, Makefile.replace(regex, sqlFileName));
91
93
  }
92
94
  if (diff) {
93
- log.warn(`⚠️ SQL diff exists! Review the ${(0, path_1.relative)(packageDir, outPath)}/ folder.`);
94
- // Uncomment if needed:
95
- // writeFileSync(`${outPath}/orig.${sqlFileName}.tree.json`, tree1);
96
- // writeFileSync(`${outPath}/parsed.${sqlFileName}.tree.json`, tree2);
95
+ if (outputDiff) {
96
+ (0, fs_1.writeFileSync)(`${outPath}/orig.${sqlFileName}.tree.json`, tree1);
97
+ (0, fs_1.writeFileSync)(`${outPath}/parsed.${sqlFileName}.tree.json`, tree2);
98
+ log.warn(`⚠️ AST round-trip diff detected! Diff files written to ${(0, path_1.relative)(packageDir, outPath)}/`);
99
+ }
100
+ else {
101
+ log.warn(`⚠️ AST round-trip diff detected! Run with --outputDiff to export the AST diff files.`);
102
+ }
97
103
  }
98
104
  const writePath = `${outPath}/${sqlFileName}`;
99
105
  (0, fs_1.writeFileSync)(writePath, sql);
@@ -0,0 +1,5 @@
1
+ export interface ParsedAuthor {
2
+ fullName: string;
3
+ email?: string;
4
+ }
5
+ export declare function parseAuthor(author: string): ParsedAuthor;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseAuthor = parseAuthor;
4
+ function parseAuthor(author) {
5
+ const trimmed = (author || '').trim();
6
+ const match = trimmed.match(/^(.+?)\s*<([^>]+)>$/);
7
+ if (match) {
8
+ return {
9
+ fullName: match[1].trim(),
10
+ email: match[2].trim()
11
+ };
12
+ }
13
+ return { fullName: trimmed };
14
+ }