@pgpmjs/core 7.1.0 → 7.2.1
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/apply.d.ts +93 -0
- package/bundle/apply.js +137 -0
- package/bundle/index.d.ts +12 -0
- package/bundle/index.js +31 -0
- package/core/class/pgpm.d.ts +2 -2
- package/core/class/pgpm.js +6 -6
- package/esm/bundle/apply.js +131 -0
- package/esm/bundle/index.js +15 -0
- package/esm/core/class/pgpm.js +6 -6
- package/esm/index.js +5 -3
- package/esm/migrate/client.js +1 -1
- package/esm/migrate/utils/hash.js +3 -6
- package/esm/modules/modules.js +1 -1
- package/esm/packaging/package.js +1 -1
- package/esm/rebundle/module.js +1 -1
- package/esm/rebundle/rebundle.js +2 -2
- package/esm/rebundle/workspace.js +1 -1
- package/esm/refactor/rename.js +5 -27
- package/esm/resolution/deps.js +2 -2
- package/esm/resolution/resolve.js +2 -2
- package/esm/slice/slice.js +7 -32
- package/index.d.ts +4 -2
- package/index.js +6 -4
- package/migrate/client.js +1 -1
- package/migrate/utils/hash.d.ts +2 -4
- package/migrate/utils/hash.js +4 -8
- package/modules/modules.d.ts +1 -1
- package/modules/modules.js +1 -1
- package/package.json +4 -2
- package/packaging/package.js +1 -1
- package/rebundle/module.js +1 -1
- package/rebundle/rebundle.js +2 -2
- package/rebundle/types.d.ts +1 -1
- package/rebundle/workspace.js +1 -1
- package/refactor/rename.d.ts +2 -8
- package/refactor/rename.js +6 -29
- package/resolution/deps.d.ts +1 -1
- package/resolution/deps.js +2 -2
- package/resolution/resolve.js +2 -2
- package/slice/slice.d.ts +1 -1
- package/slice/slice.js +7 -32
- package/slice/types.d.ts +1 -1
- package/workspace/minimal.d.ts +1 -1
- package/esm/files/extension/index.js +0 -3
- package/esm/files/extension/reader.js +0 -79
- package/esm/files/extension/writer.js +0 -99
- package/esm/files/index.js +0 -6
- package/esm/files/plan/generator.js +0 -82
- package/esm/files/plan/index.js +0 -5
- package/esm/files/plan/parser.js +0 -297
- package/esm/files/plan/validators.js +0 -181
- package/esm/files/plan/writer.js +0 -142
- package/esm/files/sql/header.js +0 -259
- package/esm/files/sql/index.js +0 -2
- package/esm/files/sql/writer.js +0 -107
- package/esm/files/sql-scripts/index.js +0 -2
- package/esm/files/sql-scripts/reader.js +0 -19
- package/esm/files/types/index.js +0 -1
- package/esm/files/types/package.js +0 -1
- package/esm/utils/author.js +0 -11
- package/files/extension/index.d.ts +0 -2
- package/files/extension/index.js +0 -19
- package/files/extension/reader.d.ts +0 -24
- package/files/extension/reader.js +0 -86
- package/files/extension/writer.d.ts +0 -48
- package/files/extension/writer.js +0 -107
- package/files/index.d.ts +0 -5
- package/files/index.js +0 -22
- package/files/plan/generator.d.ts +0 -23
- package/files/plan/generator.js +0 -90
- package/files/plan/index.d.ts +0 -4
- package/files/plan/index.js +0 -21
- package/files/plan/parser.d.ts +0 -28
- package/files/plan/parser.js +0 -304
- package/files/plan/validators.d.ts +0 -52
- package/files/plan/validators.js +0 -187
- package/files/plan/writer.d.ts +0 -27
- package/files/plan/writer.js +0 -152
- package/files/sql/header.d.ts +0 -114
- package/files/sql/header.js +0 -266
- package/files/sql/index.d.ts +0 -2
- package/files/sql/index.js +0 -18
- package/files/sql/writer.d.ts +0 -12
- package/files/sql/writer.js +0 -114
- package/files/sql-scripts/index.d.ts +0 -1
- package/files/sql-scripts/index.js +0 -18
- package/files/sql-scripts/reader.d.ts +0 -8
- package/files/sql-scripts/reader.js +0 -23
- package/files/types/index.d.ts +0 -46
- package/files/types/index.js +0 -17
- package/files/types/package.d.ts +0 -20
- package/files/types/package.js +0 -2
- package/utils/author.d.ts +0 -5
- package/utils/author.js +0 -14
package/files/sql/header.js
DELETED
|
@@ -1,266 +0,0 @@
|
|
|
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
DELETED
package/files/sql/index.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
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("./header"), exports);
|
|
18
|
-
__exportStar(require("./writer"), exports);
|
package/files/sql/writer.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { PgpmRow } from '../types';
|
|
2
|
-
export interface SqlWriteOptions {
|
|
3
|
-
outdir: string;
|
|
4
|
-
name: string;
|
|
5
|
-
replacer: (str: string) => string;
|
|
6
|
-
author?: string;
|
|
7
|
-
useTx?: boolean;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Write SQL files for PGPM migrations (deploy, revert, verify)
|
|
11
|
-
*/
|
|
12
|
-
export declare const writePgpmFiles: (rows: PgpmRow[], opts: SqlWriteOptions) => void;
|
package/files/sql/writer.js
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.writePgpmFiles = void 0;
|
|
7
|
-
const env_1 = require("@pgpmjs/env");
|
|
8
|
-
const fs_1 = __importDefault(require("fs"));
|
|
9
|
-
const path_1 = __importDefault(require("path"));
|
|
10
|
-
/**
|
|
11
|
-
* Write SQL files for PGPM migrations (deploy, revert, verify)
|
|
12
|
-
*/
|
|
13
|
-
const writePgpmFiles = (rows, opts) => {
|
|
14
|
-
rows.forEach((row) => writeVerify(row, opts));
|
|
15
|
-
rows.forEach((row) => writeRevert(row, opts));
|
|
16
|
-
rows.forEach((row) => writeDeploy(row, opts));
|
|
17
|
-
};
|
|
18
|
-
exports.writePgpmFiles = writePgpmFiles;
|
|
19
|
-
/**
|
|
20
|
-
* Sort dependencies in a consistent order
|
|
21
|
-
*/
|
|
22
|
-
const ordered = (arr) => {
|
|
23
|
-
if (!arr)
|
|
24
|
-
return [];
|
|
25
|
-
return arr.sort((a, b) => a.length - b.length || a.localeCompare(b));
|
|
26
|
-
};
|
|
27
|
-
/**
|
|
28
|
-
* Write a deploy SQL file for a PGPM change
|
|
29
|
-
*/
|
|
30
|
-
const writeDeploy = (row, opts) => {
|
|
31
|
-
const globalOpts = (0, env_1.getEnvOptions)({
|
|
32
|
-
migrations: {
|
|
33
|
-
codegen: {
|
|
34
|
-
useTx: opts.useTx
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
const useTx = globalOpts.migrations.codegen.useTx;
|
|
39
|
-
const deploy = opts.replacer(row.deploy);
|
|
40
|
-
const dir = path_1.default.dirname(deploy);
|
|
41
|
-
const prefix = path_1.default.join(opts.outdir, opts.name, 'deploy');
|
|
42
|
-
const actualDir = path_1.default.resolve(prefix, dir);
|
|
43
|
-
const actualFile = path_1.default.resolve(prefix, `${deploy}.sql`);
|
|
44
|
-
fs_1.default.mkdirSync(actualDir, { recursive: true });
|
|
45
|
-
const sqlContent = opts.replacer(row.content);
|
|
46
|
-
const content = `-- Deploy: ${deploy}
|
|
47
|
-
-- made with <3 @ constructive.io
|
|
48
|
-
|
|
49
|
-
${opts.replacer(ordered(row?.deps)
|
|
50
|
-
.map((dep) => `-- requires: ${dep}`)
|
|
51
|
-
.join('\n') || '')}
|
|
52
|
-
|
|
53
|
-
${useTx ? 'BEGIN;' : ''}
|
|
54
|
-
${sqlContent}
|
|
55
|
-
${useTx ? 'COMMIT;' : ''}
|
|
56
|
-
`;
|
|
57
|
-
fs_1.default.writeFileSync(actualFile, content);
|
|
58
|
-
};
|
|
59
|
-
/**
|
|
60
|
-
* Write a verify SQL file for a PGPM change
|
|
61
|
-
*/
|
|
62
|
-
const writeVerify = (row, opts) => {
|
|
63
|
-
const globalOpts = (0, env_1.getEnvOptions)({
|
|
64
|
-
migrations: {
|
|
65
|
-
codegen: {
|
|
66
|
-
useTx: opts.useTx
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
const useTx = globalOpts.migrations.codegen.useTx;
|
|
71
|
-
const deploy = opts.replacer(row.deploy);
|
|
72
|
-
const dir = path_1.default.dirname(deploy);
|
|
73
|
-
const prefix = path_1.default.join(opts.outdir, opts.name, 'verify');
|
|
74
|
-
const actualDir = path_1.default.resolve(prefix, dir);
|
|
75
|
-
const actualFile = path_1.default.resolve(prefix, `${deploy}.sql`);
|
|
76
|
-
fs_1.default.mkdirSync(actualDir, { recursive: true });
|
|
77
|
-
const sqlContent = opts.replacer(row.verify);
|
|
78
|
-
const content = opts.replacer(`-- Verify: ${deploy}
|
|
79
|
-
|
|
80
|
-
${useTx ? 'BEGIN;' : ''}
|
|
81
|
-
${sqlContent}
|
|
82
|
-
${useTx ? 'COMMIT;' : ''}
|
|
83
|
-
|
|
84
|
-
`);
|
|
85
|
-
fs_1.default.writeFileSync(actualFile, content);
|
|
86
|
-
};
|
|
87
|
-
/**
|
|
88
|
-
* Write a revert SQL file for a PGPM change
|
|
89
|
-
*/
|
|
90
|
-
const writeRevert = (row, opts) => {
|
|
91
|
-
const globalOpts = (0, env_1.getEnvOptions)({
|
|
92
|
-
migrations: {
|
|
93
|
-
codegen: {
|
|
94
|
-
useTx: opts.useTx
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
const useTx = globalOpts.migrations.codegen.useTx;
|
|
99
|
-
const deploy = opts.replacer(row.deploy);
|
|
100
|
-
const dir = path_1.default.dirname(deploy);
|
|
101
|
-
const prefix = path_1.default.join(opts.outdir, opts.name, 'revert');
|
|
102
|
-
const actualDir = path_1.default.resolve(prefix, dir);
|
|
103
|
-
const actualFile = path_1.default.resolve(prefix, `${deploy}.sql`);
|
|
104
|
-
fs_1.default.mkdirSync(actualDir, { recursive: true });
|
|
105
|
-
const sqlContent = opts.replacer(row.revert);
|
|
106
|
-
const content = `-- Revert: ${deploy}
|
|
107
|
-
|
|
108
|
-
${useTx ? 'BEGIN;' : ''}
|
|
109
|
-
${sqlContent}
|
|
110
|
-
${useTx ? 'COMMIT;' : ''}
|
|
111
|
-
|
|
112
|
-
`;
|
|
113
|
-
fs_1.default.writeFileSync(actualFile, content);
|
|
114
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './reader';
|
|
@@ -1,18 +0,0 @@
|
|
|
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
|
-
// Re-export all sql-scripts functionality
|
|
18
|
-
__exportStar(require("./reader"), exports);
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Read a SQL script file, return empty string if not found
|
|
3
|
-
*/
|
|
4
|
-
export declare function readScript(basePath: string, scriptType: string, changeName: string): string;
|
|
5
|
-
/**
|
|
6
|
-
* Check if a script file exists
|
|
7
|
-
*/
|
|
8
|
-
export declare function scriptExists(basePath: string, scriptType: string, changeName: string): boolean;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.readScript = readScript;
|
|
4
|
-
exports.scriptExists = scriptExists;
|
|
5
|
-
const fs_1 = require("fs");
|
|
6
|
-
const path_1 = require("path");
|
|
7
|
-
/**
|
|
8
|
-
* Read a SQL script file, return empty string if not found
|
|
9
|
-
*/
|
|
10
|
-
function readScript(basePath, scriptType, changeName) {
|
|
11
|
-
const scriptPath = (0, path_1.join)(basePath, scriptType, `${changeName}.sql`);
|
|
12
|
-
if (!(0, fs_1.existsSync)(scriptPath)) {
|
|
13
|
-
return '';
|
|
14
|
-
}
|
|
15
|
-
return (0, fs_1.readFileSync)(scriptPath, 'utf-8');
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Check if a script file exists
|
|
19
|
-
*/
|
|
20
|
-
function scriptExists(basePath, scriptType, changeName) {
|
|
21
|
-
const scriptPath = (0, path_1.join)(basePath, scriptType, `${changeName}.sql`);
|
|
22
|
-
return (0, fs_1.existsSync)(scriptPath);
|
|
23
|
-
}
|
package/files/types/index.d.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
export * from './package';
|
|
2
|
-
export interface Change {
|
|
3
|
-
name: string;
|
|
4
|
-
dependencies: string[];
|
|
5
|
-
timestamp?: string;
|
|
6
|
-
planner?: string;
|
|
7
|
-
email?: string;
|
|
8
|
-
comment?: string;
|
|
9
|
-
}
|
|
10
|
-
export interface PlanFile {
|
|
11
|
-
package: string;
|
|
12
|
-
uri?: string;
|
|
13
|
-
changes: Change[];
|
|
14
|
-
}
|
|
15
|
-
export interface Tag {
|
|
16
|
-
name: string;
|
|
17
|
-
change: string;
|
|
18
|
-
timestamp?: string;
|
|
19
|
-
planner?: string;
|
|
20
|
-
email?: string;
|
|
21
|
-
comment?: string;
|
|
22
|
-
}
|
|
23
|
-
export interface ExtendedPlanFile extends PlanFile {
|
|
24
|
-
tags: Tag[];
|
|
25
|
-
}
|
|
26
|
-
export interface ParseError {
|
|
27
|
-
line: number;
|
|
28
|
-
message: string;
|
|
29
|
-
}
|
|
30
|
-
export interface ParseResult<T> {
|
|
31
|
-
data?: T;
|
|
32
|
-
errors: ParseError[];
|
|
33
|
-
}
|
|
34
|
-
export interface ResolvedReference {
|
|
35
|
-
type: 'change' | 'tag' | 'sha1' | 'relative';
|
|
36
|
-
target: string;
|
|
37
|
-
resolved?: string;
|
|
38
|
-
}
|
|
39
|
-
export interface PgpmRow {
|
|
40
|
-
deploy: string;
|
|
41
|
-
revert?: string;
|
|
42
|
-
verify?: string;
|
|
43
|
-
content: string;
|
|
44
|
-
deps?: string[];
|
|
45
|
-
name?: string;
|
|
46
|
-
}
|
package/files/types/index.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
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("./package"), exports);
|
package/files/types/package.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export interface PackageAnalysisIssue {
|
|
2
|
-
code: string;
|
|
3
|
-
message: string;
|
|
4
|
-
file?: string;
|
|
5
|
-
fixable?: boolean;
|
|
6
|
-
}
|
|
7
|
-
export interface PackageAnalysisResult {
|
|
8
|
-
ok: boolean;
|
|
9
|
-
name: string;
|
|
10
|
-
path: string;
|
|
11
|
-
issues: PackageAnalysisIssue[];
|
|
12
|
-
}
|
|
13
|
-
export interface RenameOptions {
|
|
14
|
-
dryRun?: boolean;
|
|
15
|
-
syncPackageJsonName?: boolean;
|
|
16
|
-
}
|
|
17
|
-
export interface RenameResult {
|
|
18
|
-
changed: string[];
|
|
19
|
-
warnings: string[];
|
|
20
|
-
}
|
package/files/types/package.js
DELETED
package/utils/author.d.ts
DELETED
package/utils/author.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
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
|
-
}
|