@pgpmjs/core 6.32.2 → 6.34.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/esm/files/sql/header.js +259 -0
- package/esm/files/sql/index.js +1 -0
- package/esm/index.js +1 -0
- package/esm/refactor/index.js +1 -0
- package/esm/refactor/rename.js +200 -0
- package/esm/resolution/deps.js +26 -63
- package/esm/slice/slice.js +11 -3
- package/files/sql/header.d.ts +114 -0
- package/files/sql/header.js +266 -0
- package/files/sql/index.d.ts +1 -0
- package/files/sql/index.js +1 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +2 -2
- package/refactor/index.d.ts +1 -0
- package/refactor/index.js +17 -0
- package/refactor/rename.d.ts +59 -0
- package/refactor/rename.js +206 -0
- package/resolution/deps.js +26 -63
- package/slice/slice.d.ts +2 -2
- package/slice/slice.js +11 -3
- package/slice/types.d.ts +15 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { ParsedReference } from '../plan/validators';
|
|
2
|
+
/**
|
|
3
|
+
* A parsed `-- requires:` line from a pgpm SQL script header.
|
|
4
|
+
*/
|
|
5
|
+
export interface PgpmHeaderRequire {
|
|
6
|
+
/** The dependency reference exactly as written (e.g. `schema`, `pkg:tables/users`, `pkg:@v1`). */
|
|
7
|
+
raw: string;
|
|
8
|
+
/** Structured breakdown of the reference (package/change/tag), when parseable. */
|
|
9
|
+
ref: ParsedReference | null;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* The parsed header block of a pgpm SQL script (deploy/revert/verify).
|
|
13
|
+
*
|
|
14
|
+
* The header is everything from the top of the file through the last
|
|
15
|
+
* header-relevant comment line (`-- Deploy|Revert|Verify ...`,
|
|
16
|
+
* `-- requires: ...`, and any interleaved comment/blank lines), with the
|
|
17
|
+
* remainder of the file preserved as `body`.
|
|
18
|
+
*/
|
|
19
|
+
export interface PgpmHeader {
|
|
20
|
+
/** Header verb: Deploy, Revert or Verify. Null when no header line was found. */
|
|
21
|
+
verb: 'Deploy' | 'Revert' | 'Verify' | null;
|
|
22
|
+
/** The project (extension) name from `-- Deploy <project>:<change>`, if present. */
|
|
23
|
+
project: string | null;
|
|
24
|
+
/**
|
|
25
|
+
* The change name from the header line. By convention this must equal the
|
|
26
|
+
* script's path identity: `deploy/<change>.sql`.
|
|
27
|
+
*/
|
|
28
|
+
change: string | null;
|
|
29
|
+
/** Whether the header line carried the legacy ` to pg` suffix. */
|
|
30
|
+
toPg: boolean;
|
|
31
|
+
/** Parsed `-- requires:` dependencies, in file order. */
|
|
32
|
+
requires: PgpmHeaderRequire[];
|
|
33
|
+
/** The raw header lines, byte-exact, in file order. */
|
|
34
|
+
lines: string[];
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Result of splitting a SQL script into header and body.
|
|
38
|
+
*/
|
|
39
|
+
export interface ParsedPgpmScript {
|
|
40
|
+
header: PgpmHeader;
|
|
41
|
+
/** Everything after the header block, byte-exact. */
|
|
42
|
+
body: string;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Parse the header block of a pgpm SQL script into a structured model.
|
|
46
|
+
*
|
|
47
|
+
* Recognizes both header formats:
|
|
48
|
+
* `-- Deploy <project>:<change> to pg` (legacy sqitch-compatible)
|
|
49
|
+
* `-- Deploy <change>` / `-- Deploy: <change>` (new)
|
|
50
|
+
* along with `-- requires: <ref>` lines where `<ref>` may be a plain change
|
|
51
|
+
* name, `{package}:{change}`, `@tag`, or `{package}:@tag`.
|
|
52
|
+
*
|
|
53
|
+
* The parse is lossless: `header.lines` plus `body` reassemble the original
|
|
54
|
+
* content byte-exactly (see {@link writePgpmScript}).
|
|
55
|
+
*/
|
|
56
|
+
export declare function parsePgpmHeader(content: string): ParsedPgpmScript;
|
|
57
|
+
/**
|
|
58
|
+
* Serialize a header back to its raw lines. When the structured fields have
|
|
59
|
+
* been modified via {@link renameInHeader}, the raw lines already reflect the
|
|
60
|
+
* change; this simply joins header and body losslessly.
|
|
61
|
+
*/
|
|
62
|
+
export declare function writePgpmScript(script: ParsedPgpmScript): string;
|
|
63
|
+
/**
|
|
64
|
+
* Rewrite change names in a script header according to a rename map
|
|
65
|
+
* (old change name -> new change name). Rewrites both the `-- Deploy` line's
|
|
66
|
+
* change identity and any `-- requires:` lines referencing renamed changes,
|
|
67
|
+
* preserving format (project qualifier, ` to pg` suffix, tag refs untouched).
|
|
68
|
+
*
|
|
69
|
+
* Returns the number of substitutions applied; mutates `script` in place.
|
|
70
|
+
*/
|
|
71
|
+
export declare function renameInHeader(script: ParsedPgpmScript, renames: Map<string, string>): number;
|
|
72
|
+
/**
|
|
73
|
+
* Options for {@link scanDeployScript}.
|
|
74
|
+
*/
|
|
75
|
+
export interface ScanDeployScriptOptions {
|
|
76
|
+
/** The script's path identity key (e.g. `/deploy/tables/users.sql`). */
|
|
77
|
+
key: string;
|
|
78
|
+
/** The current extension (project) name. */
|
|
79
|
+
extname: string;
|
|
80
|
+
/** Maps a change name to its path identity key. */
|
|
81
|
+
makeKey: (change: string) => string;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Scan a deploy script the way dependency resolution historically has:
|
|
85
|
+
* line-by-line over the whole file, collecting `-- requires: <ref>` lines
|
|
86
|
+
* verbatim and validating any `-- Deploy <project>:<change>[ to pg]` line
|
|
87
|
+
* against the script's path identity and project name.
|
|
88
|
+
*
|
|
89
|
+
* Kept strictly line-regex-compatible with the original resolver behavior
|
|
90
|
+
* (requires lines are honored anywhere in the file, and the legacy
|
|
91
|
+
* `-- Deploy: <change>` colon form is not identity-validated).
|
|
92
|
+
*
|
|
93
|
+
* @throws when the Deploy line's project or change identity mismatches.
|
|
94
|
+
*/
|
|
95
|
+
export declare function scanDeployScript(content: string, options: ScanDeployScriptOptions): {
|
|
96
|
+
requires: string[];
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* A single plan-vs-header discrepancy found by {@link verifyPlanMatchesHeaders}.
|
|
100
|
+
*/
|
|
101
|
+
export interface HeaderDriftIssue {
|
|
102
|
+
change: string;
|
|
103
|
+
file: string;
|
|
104
|
+
kind: 'missing-file' | 'identity-mismatch' | 'requires-drift';
|
|
105
|
+
message: string;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Verify that every change in a module's pgpm.plan has a deploy script whose
|
|
109
|
+
* header identity matches its path, and report dependency drift between the
|
|
110
|
+
* plan's dep lists and the scripts' `-- requires:` lines.
|
|
111
|
+
*
|
|
112
|
+
* Read-only diagnostic; returns issues rather than throwing.
|
|
113
|
+
*/
|
|
114
|
+
export declare function verifyPlanMatchesHeaders(moduleDir: string): HeaderDriftIssue[];
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parsePgpmHeader = parsePgpmHeader;
|
|
4
|
+
exports.writePgpmScript = writePgpmScript;
|
|
5
|
+
exports.renameInHeader = renameInHeader;
|
|
6
|
+
exports.scanDeployScript = scanDeployScript;
|
|
7
|
+
exports.verifyPlanMatchesHeaders = verifyPlanMatchesHeaders;
|
|
8
|
+
const fs_1 = require("fs");
|
|
9
|
+
const path_1 = require("path");
|
|
10
|
+
const parser_1 = require("../plan/parser");
|
|
11
|
+
const validators_1 = require("../plan/validators");
|
|
12
|
+
const HEADER_LINE = /^--\s*(Deploy|Revert|Verify)\b(:)?\s*(.*?)\s*$/;
|
|
13
|
+
const REQUIRES_LINE = /^--\s*requires:\s*(.*?)\s*$/;
|
|
14
|
+
const COMMENT_LINE = /^\s*--/;
|
|
15
|
+
const TO_PG_SUFFIX = /\s+to\s+pg\s*$/;
|
|
16
|
+
/**
|
|
17
|
+
* Parse the header block of a pgpm SQL script into a structured model.
|
|
18
|
+
*
|
|
19
|
+
* Recognizes both header formats:
|
|
20
|
+
* `-- Deploy <project>:<change> to pg` (legacy sqitch-compatible)
|
|
21
|
+
* `-- Deploy <change>` / `-- Deploy: <change>` (new)
|
|
22
|
+
* along with `-- requires: <ref>` lines where `<ref>` may be a plain change
|
|
23
|
+
* name, `{package}:{change}`, `@tag`, or `{package}:@tag`.
|
|
24
|
+
*
|
|
25
|
+
* The parse is lossless: `header.lines` plus `body` reassemble the original
|
|
26
|
+
* content byte-exactly (see {@link writePgpmScript}).
|
|
27
|
+
*/
|
|
28
|
+
function parsePgpmHeader(content) {
|
|
29
|
+
const header = {
|
|
30
|
+
verb: null,
|
|
31
|
+
project: null,
|
|
32
|
+
change: null,
|
|
33
|
+
toPg: false,
|
|
34
|
+
requires: [],
|
|
35
|
+
lines: []
|
|
36
|
+
};
|
|
37
|
+
const lines = content.split('\n');
|
|
38
|
+
let lastHeaderIdx = -1;
|
|
39
|
+
for (let i = 0; i < lines.length; i++) {
|
|
40
|
+
const line = lines[i];
|
|
41
|
+
if (line.trim() === '') {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (!COMMENT_LINE.test(line)) {
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
const headerMatch = line.match(HEADER_LINE);
|
|
48
|
+
if (headerMatch && header.verb === null) {
|
|
49
|
+
header.verb = headerMatch[1];
|
|
50
|
+
let target = headerMatch[3];
|
|
51
|
+
if (TO_PG_SUFFIX.test(target)) {
|
|
52
|
+
header.toPg = true;
|
|
53
|
+
target = target.replace(TO_PG_SUFFIX, '');
|
|
54
|
+
}
|
|
55
|
+
const colonIndex = target.indexOf(':');
|
|
56
|
+
if (colonIndex > 0 && /^[a-zA-Z0-9_-]+$/.test(target.substring(0, colonIndex))) {
|
|
57
|
+
header.project = target.substring(0, colonIndex);
|
|
58
|
+
header.change = target.substring(colonIndex + 1).trim();
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
header.change = target.trim() || null;
|
|
62
|
+
}
|
|
63
|
+
lastHeaderIdx = i;
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
const requiresMatch = line.match(REQUIRES_LINE);
|
|
67
|
+
if (requiresMatch) {
|
|
68
|
+
const raw = requiresMatch[1];
|
|
69
|
+
header.requires.push({ raw, ref: (0, validators_1.parseReference)(raw) });
|
|
70
|
+
lastHeaderIdx = i;
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
// Other comment lines (e.g. attribution) before/between header lines are
|
|
74
|
+
// tolerated but only absorbed into the header when a later header line
|
|
75
|
+
// follows; trailing comments belong to the body.
|
|
76
|
+
}
|
|
77
|
+
header.lines = lines.slice(0, lastHeaderIdx + 1);
|
|
78
|
+
return {
|
|
79
|
+
header,
|
|
80
|
+
body: lines.slice(lastHeaderIdx + 1).join('\n')
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Serialize a header back to its raw lines. When the structured fields have
|
|
85
|
+
* been modified via {@link renameInHeader}, the raw lines already reflect the
|
|
86
|
+
* change; this simply joins header and body losslessly.
|
|
87
|
+
*/
|
|
88
|
+
function writePgpmScript(script) {
|
|
89
|
+
if (script.header.lines.length === 0)
|
|
90
|
+
return script.body;
|
|
91
|
+
return script.header.lines.join('\n') + '\n' + script.body;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Rewrite change names in a script header according to a rename map
|
|
95
|
+
* (old change name -> new change name). Rewrites both the `-- Deploy` line's
|
|
96
|
+
* change identity and any `-- requires:` lines referencing renamed changes,
|
|
97
|
+
* preserving format (project qualifier, ` to pg` suffix, tag refs untouched).
|
|
98
|
+
*
|
|
99
|
+
* Returns the number of substitutions applied; mutates `script` in place.
|
|
100
|
+
*/
|
|
101
|
+
function renameInHeader(script, renames) {
|
|
102
|
+
const { header } = script;
|
|
103
|
+
let count = 0;
|
|
104
|
+
const renameRef = (raw) => {
|
|
105
|
+
const ref = (0, validators_1.parseReference)(raw);
|
|
106
|
+
if (!ref) {
|
|
107
|
+
const to = renames.get(raw);
|
|
108
|
+
return to ?? null;
|
|
109
|
+
}
|
|
110
|
+
if (ref.tag || ref.symbolic || ref.relative)
|
|
111
|
+
return null;
|
|
112
|
+
const change = ref.change;
|
|
113
|
+
if (!change)
|
|
114
|
+
return null;
|
|
115
|
+
const to = renames.get(change);
|
|
116
|
+
if (!to)
|
|
117
|
+
return null;
|
|
118
|
+
return ref.package ? `${ref.package}:${to}` : to;
|
|
119
|
+
};
|
|
120
|
+
header.lines = header.lines.map(line => {
|
|
121
|
+
const headerMatch = line.match(HEADER_LINE);
|
|
122
|
+
if (headerMatch && header.change && renames.has(header.change)) {
|
|
123
|
+
const to = renames.get(header.change);
|
|
124
|
+
const oldTarget = header.project ? `${header.project}:${header.change}` : header.change;
|
|
125
|
+
const newTarget = header.project ? `${header.project}:${to}` : to;
|
|
126
|
+
const rewritten = line.replace(oldTarget, newTarget);
|
|
127
|
+
if (rewritten !== line) {
|
|
128
|
+
header.change = to;
|
|
129
|
+
count++;
|
|
130
|
+
return rewritten;
|
|
131
|
+
}
|
|
132
|
+
return line;
|
|
133
|
+
}
|
|
134
|
+
const requiresMatch = line.match(REQUIRES_LINE);
|
|
135
|
+
if (requiresMatch) {
|
|
136
|
+
const raw = requiresMatch[1];
|
|
137
|
+
const renamed = renameRef(raw);
|
|
138
|
+
if (renamed !== null) {
|
|
139
|
+
count++;
|
|
140
|
+
return line.replace(raw, renamed);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return line;
|
|
144
|
+
});
|
|
145
|
+
header.requires = header.requires.map(req => {
|
|
146
|
+
const renamed = renameRef(req.raw);
|
|
147
|
+
if (renamed === null)
|
|
148
|
+
return req;
|
|
149
|
+
return { raw: renamed, ref: (0, validators_1.parseReference)(renamed) };
|
|
150
|
+
});
|
|
151
|
+
return count;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Scan a deploy script the way dependency resolution historically has:
|
|
155
|
+
* line-by-line over the whole file, collecting `-- requires: <ref>` lines
|
|
156
|
+
* verbatim and validating any `-- Deploy <project>:<change>[ to pg]` line
|
|
157
|
+
* against the script's path identity and project name.
|
|
158
|
+
*
|
|
159
|
+
* Kept strictly line-regex-compatible with the original resolver behavior
|
|
160
|
+
* (requires lines are honored anywhere in the file, and the legacy
|
|
161
|
+
* `-- Deploy: <change>` colon form is not identity-validated).
|
|
162
|
+
*
|
|
163
|
+
* @throws when the Deploy line's project or change identity mismatches.
|
|
164
|
+
*/
|
|
165
|
+
function scanDeployScript(content, options) {
|
|
166
|
+
const { key, extname, makeKey } = options;
|
|
167
|
+
const requires = [];
|
|
168
|
+
for (const line of content.split('\n')) {
|
|
169
|
+
const requiresMatch = line.match(/^-- requires: (.*)/);
|
|
170
|
+
if (requiresMatch) {
|
|
171
|
+
requires.push(requiresMatch[1].trim());
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
if (/:/.test(line)) {
|
|
175
|
+
const m2 = line.match(/^-- Deploy ([^:]*):([\w\/]+)(?:\s+to\s+pg)?/);
|
|
176
|
+
if (m2) {
|
|
177
|
+
const actualProject = m2[1];
|
|
178
|
+
const keyToTest = m2[2];
|
|
179
|
+
if (extname !== actualProject) {
|
|
180
|
+
throw new Error(`Mismatched project name in deploy file:
|
|
181
|
+
Expected project: ${extname}
|
|
182
|
+
Found in line : ${actualProject}
|
|
183
|
+
Line : ${line}`);
|
|
184
|
+
}
|
|
185
|
+
const expectedKey = makeKey(keyToTest);
|
|
186
|
+
if (key !== expectedKey) {
|
|
187
|
+
throw new Error(`Deployment script path or internal name mismatch:
|
|
188
|
+
Expected key : ${key}
|
|
189
|
+
Found in line : ${expectedKey}
|
|
190
|
+
Line : ${line}`);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
const m2 = line.match(/^-- Deploy (.*?)(?:\s+to\s+pg)?\s*$/);
|
|
196
|
+
if (m2) {
|
|
197
|
+
const keyToTest = m2[1].trim();
|
|
198
|
+
if (key !== makeKey(keyToTest)) {
|
|
199
|
+
throw new Error('deployment script in wrong place or is named wrong internally\n' + line);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return { requires };
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Verify that every change in a module's pgpm.plan has a deploy script whose
|
|
208
|
+
* header identity matches its path, and report dependency drift between the
|
|
209
|
+
* plan's dep lists and the scripts' `-- requires:` lines.
|
|
210
|
+
*
|
|
211
|
+
* Read-only diagnostic; returns issues rather than throwing.
|
|
212
|
+
*/
|
|
213
|
+
function verifyPlanMatchesHeaders(moduleDir) {
|
|
214
|
+
const issues = [];
|
|
215
|
+
const planPath = (0, path_1.join)(moduleDir, 'pgpm.plan');
|
|
216
|
+
const parsed = (0, parser_1.parsePlanFile)(planPath);
|
|
217
|
+
if (!parsed.data) {
|
|
218
|
+
throw new Error(`Failed to parse plan file: ${planPath}`);
|
|
219
|
+
}
|
|
220
|
+
for (const planChange of parsed.data.changes) {
|
|
221
|
+
const change = planChange.name;
|
|
222
|
+
const file = (0, path_1.join)(moduleDir, 'deploy', `${change}.sql`);
|
|
223
|
+
let content;
|
|
224
|
+
try {
|
|
225
|
+
content = (0, fs_1.readFileSync)(file, 'utf-8');
|
|
226
|
+
}
|
|
227
|
+
catch {
|
|
228
|
+
issues.push({
|
|
229
|
+
change,
|
|
230
|
+
file,
|
|
231
|
+
kind: 'missing-file',
|
|
232
|
+
message: `deploy script not found for plan change "${change}"`
|
|
233
|
+
});
|
|
234
|
+
continue;
|
|
235
|
+
}
|
|
236
|
+
const { header } = parsePgpmHeader(content);
|
|
237
|
+
if (header.change && header.change !== change) {
|
|
238
|
+
issues.push({
|
|
239
|
+
change,
|
|
240
|
+
file,
|
|
241
|
+
kind: 'identity-mismatch',
|
|
242
|
+
message: `header declares "${header.change}" but path identity is "${change}"`
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
const planDeps = new Set(planChange.dependencies || []);
|
|
246
|
+
const headerDeps = new Set(header.requires.map(r => r.raw));
|
|
247
|
+
const missingInHeader = [...planDeps].filter(d => !headerDeps.has(d));
|
|
248
|
+
const missingInPlan = [...headerDeps].filter(d => !planDeps.has(d));
|
|
249
|
+
if (missingInHeader.length > 0 || missingInPlan.length > 0) {
|
|
250
|
+
const parts = [];
|
|
251
|
+
if (missingInHeader.length > 0) {
|
|
252
|
+
parts.push(`in plan but not in header requires: ${missingInHeader.join(', ')}`);
|
|
253
|
+
}
|
|
254
|
+
if (missingInPlan.length > 0) {
|
|
255
|
+
parts.push(`in header requires but not in plan: ${missingInPlan.join(', ')}`);
|
|
256
|
+
}
|
|
257
|
+
issues.push({
|
|
258
|
+
change,
|
|
259
|
+
file,
|
|
260
|
+
kind: 'requires-drift',
|
|
261
|
+
message: parts.join('; ')
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
return issues;
|
|
266
|
+
}
|
package/files/sql/index.d.ts
CHANGED
package/files/sql/index.js
CHANGED
|
@@ -14,4 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./header"), exports);
|
|
17
18
|
__exportStar(require("./writer"), exports);
|
package/index.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export * from './core/template-scaffold';
|
|
|
12
12
|
export * from './core/boilerplate-types';
|
|
13
13
|
export * from './core/boilerplate-scanner';
|
|
14
14
|
export * from './files';
|
|
15
|
+
export * from './refactor';
|
|
15
16
|
export { cleanSql } from './migrate/clean';
|
|
16
17
|
export { PgpmMigrate } from './migrate/client';
|
|
17
18
|
export { PgpmInit } from './init/client';
|
package/index.js
CHANGED
|
@@ -30,6 +30,7 @@ __exportStar(require("./core/boilerplate-types"), exports);
|
|
|
30
30
|
__exportStar(require("./core/boilerplate-scanner"), exports);
|
|
31
31
|
// Export package-files functionality (now integrated into core)
|
|
32
32
|
__exportStar(require("./files"), exports);
|
|
33
|
+
__exportStar(require("./refactor"), exports);
|
|
33
34
|
var clean_1 = require("./migrate/clean");
|
|
34
35
|
Object.defineProperty(exports, "cleanSql", { enumerable: true, get: function () { return clean_1.cleanSql; } });
|
|
35
36
|
var client_1 = require("./migrate/client");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pgpmjs/core",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.34.0",
|
|
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.17",
|
|
65
65
|
"yanse": "^0.2.1"
|
|
66
66
|
},
|
|
67
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "08b12923f099191b2d1592b9c897f9f04b4950aa"
|
|
68
68
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './rename';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./rename"), exports);
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for {@link renameChanges}.
|
|
3
|
+
*/
|
|
4
|
+
export interface RenameChangesOptions {
|
|
5
|
+
/** Report planned operations without touching the filesystem. Default: false */
|
|
6
|
+
dryRun?: boolean;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Result of a {@link renameChanges} run.
|
|
10
|
+
*/
|
|
11
|
+
export interface RenameChangesResult {
|
|
12
|
+
/** deploy/revert/verify script files moved (old path -> new path, module-relative). */
|
|
13
|
+
filesMoved: Array<{
|
|
14
|
+
from: string;
|
|
15
|
+
to: string;
|
|
16
|
+
}>;
|
|
17
|
+
/** Script files whose headers were rewritten (identity and/or requires). */
|
|
18
|
+
headersRewritten: string[];
|
|
19
|
+
/** Whether pgpm.plan was rewritten. */
|
|
20
|
+
planRewritten: boolean;
|
|
21
|
+
/** Dry-run report lines (only populated when dryRun). */
|
|
22
|
+
dryRunReport?: string[];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Validate a rename map against a module directory: every source change must
|
|
26
|
+
* exist in the plan, no target may collide with an existing change, and no
|
|
27
|
+
* two sources may map to the same target.
|
|
28
|
+
*
|
|
29
|
+
* @throws on any violation.
|
|
30
|
+
*/
|
|
31
|
+
export declare function validateRenames(moduleDir: string, renames: Map<string, string>): void;
|
|
32
|
+
/**
|
|
33
|
+
* Rewrite change names in a pgpm.plan's content according to a rename map.
|
|
34
|
+
* Textual and format-preserving: only the change-name token at the start of a
|
|
35
|
+
* change line, plain (same-package) dependency refs inside `[...]`, and tag
|
|
36
|
+
* lines' change field are rewritten; timestamps, planners, comments,
|
|
37
|
+
* cross-package refs, and tag refs are untouched.
|
|
38
|
+
*/
|
|
39
|
+
export declare function renameInPlanContent(content: string, renames: Map<string, string>): string;
|
|
40
|
+
/**
|
|
41
|
+
* Atomically rename/move changes within a pgpm module: the coupled 4-way
|
|
42
|
+
* rewrite of (1) deploy/revert/verify script files on disk, (2) the moved
|
|
43
|
+
* scripts' own header identity, (3) `-- requires:` headers in every script
|
|
44
|
+
* that references a renamed change, and (4) the pgpm.plan.
|
|
45
|
+
*
|
|
46
|
+
* SQL statement bodies are NOT touched: schema-name rewrites inside SQL are a
|
|
47
|
+
* separate AST-level concern for callers to compose (e.g. transform passes).
|
|
48
|
+
*/
|
|
49
|
+
export declare function renameChanges(moduleDir: string, renames: Map<string, string>, options?: RenameChangesOptions): RenameChangesResult;
|
|
50
|
+
/**
|
|
51
|
+
* Derive a change rename map from a schema mapping (old schema name -> new
|
|
52
|
+
* schema name) by rewriting the `schemas/<name>/` path segment of every plan
|
|
53
|
+
* change that lives under a renamed schema.
|
|
54
|
+
*
|
|
55
|
+
* This is the module-level counterpart of directory-based schema renames:
|
|
56
|
+
* `schemas/my-app/tables/users` with mapping `my-app -> my_app` yields
|
|
57
|
+
* `schemas/my_app/tables/users`.
|
|
58
|
+
*/
|
|
59
|
+
export declare function deriveRenamesFromSchemaMapping(moduleDir: string, schemaMapping: Map<string, string>): Map<string, string>;
|