pgpm 0.0.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/README.md +416 -0
- package/commands/add.d.ts +7 -0
- package/commands/add.js +86 -0
- package/commands/admin-users/add.d.ts +4 -0
- package/commands/admin-users/add.js +89 -0
- package/commands/admin-users/bootstrap.d.ts +4 -0
- package/commands/admin-users/bootstrap.js +50 -0
- package/commands/admin-users/remove.d.ts +4 -0
- package/commands/admin-users/remove.js +82 -0
- package/commands/admin-users.d.ts +4 -0
- package/commands/admin-users.js +68 -0
- package/commands/analyze.d.ts +4 -0
- package/commands/analyze.js +21 -0
- package/commands/clear.d.ts +3 -0
- package/commands/clear.js +59 -0
- package/commands/deploy.d.ts +4 -0
- package/commands/deploy.js +146 -0
- package/commands/explorer.d.ts +3 -0
- package/commands/explorer.js +94 -0
- package/commands/export.d.ts +3 -0
- package/commands/export.js +129 -0
- package/commands/extension.d.ts +4 -0
- package/commands/extension.js +48 -0
- package/commands/init/index.d.ts +7 -0
- package/commands/init/index.js +47 -0
- package/commands/init/module.d.ts +4 -0
- package/commands/init/module.js +71 -0
- package/commands/init/workspace.d.ts +4 -0
- package/commands/init/workspace.js +52 -0
- package/commands/install.d.ts +4 -0
- package/commands/install.js +37 -0
- package/commands/kill.d.ts +3 -0
- package/commands/kill.js +107 -0
- package/commands/migrate/deps.d.ts +4 -0
- package/commands/migrate/deps.js +186 -0
- package/commands/migrate/init.d.ts +4 -0
- package/commands/migrate/init.js +65 -0
- package/commands/migrate/list.d.ts +4 -0
- package/commands/migrate/list.js +85 -0
- package/commands/migrate/status.d.ts +4 -0
- package/commands/migrate/status.js +94 -0
- package/commands/migrate.d.ts +4 -0
- package/commands/migrate.js +69 -0
- package/commands/package.d.ts +3 -0
- package/commands/package.js +65 -0
- package/commands/plan.d.ts +3 -0
- package/commands/plan.js +62 -0
- package/commands/remove.d.ts +3 -0
- package/commands/remove.js +42 -0
- package/commands/rename.d.ts +4 -0
- package/commands/rename.js +35 -0
- package/commands/revert.d.ts +3 -0
- package/commands/revert.js +107 -0
- package/commands/server.d.ts +3 -0
- package/commands/server.js +187 -0
- package/commands/tag.d.ts +6 -0
- package/commands/tag.js +168 -0
- package/commands/verify.d.ts +3 -0
- package/commands/verify.js +85 -0
- package/commands.d.ts +5 -0
- package/commands.js +118 -0
- package/dist/README.md +416 -0
- package/dist/package.json +77 -0
- package/esm/commands/add.js +51 -0
- package/esm/commands/admin-users/add.js +87 -0
- package/esm/commands/admin-users/bootstrap.js +48 -0
- package/esm/commands/admin-users/remove.js +80 -0
- package/esm/commands/admin-users.js +63 -0
- package/esm/commands/analyze.js +16 -0
- package/esm/commands/clear.js +54 -0
- package/esm/commands/deploy.js +144 -0
- package/esm/commands/explorer.js +92 -0
- package/esm/commands/export.js +127 -0
- package/esm/commands/extension.js +46 -0
- package/esm/commands/init/index.js +42 -0
- package/esm/commands/init/module.js +68 -0
- package/esm/commands/init/workspace.js +46 -0
- package/esm/commands/install.js +35 -0
- package/esm/commands/kill.js +105 -0
- package/esm/commands/migrate/deps.js +184 -0
- package/esm/commands/migrate/init.js +63 -0
- package/esm/commands/migrate/list.js +83 -0
- package/esm/commands/migrate/status.js +92 -0
- package/esm/commands/migrate.js +64 -0
- package/esm/commands/package.js +63 -0
- package/esm/commands/plan.js +60 -0
- package/esm/commands/remove.js +40 -0
- package/esm/commands/rename.js +30 -0
- package/esm/commands/revert.js +105 -0
- package/esm/commands/server.js +185 -0
- package/esm/commands/tag.js +133 -0
- package/esm/commands/verify.js +83 -0
- package/esm/commands.js +111 -0
- package/esm/index.js +20 -0
- package/esm/package.js +26 -0
- package/esm/utils/argv.js +92 -0
- package/esm/utils/cli-error.js +48 -0
- package/esm/utils/database.js +78 -0
- package/esm/utils/deployed-changes.js +68 -0
- package/esm/utils/display.js +58 -0
- package/esm/utils/index.js +3 -0
- package/esm/utils/module-utils.js +51 -0
- package/index.d.ts +3 -0
- package/index.js +23 -0
- package/package.d.ts +1 -0
- package/package.js +29 -0
- package/package.json +77 -0
- package/utils/argv.d.ts +46 -0
- package/utils/argv.js +100 -0
- package/utils/cli-error.d.ts +8 -0
- package/utils/cli-error.js +52 -0
- package/utils/database.d.ts +21 -0
- package/utils/database.js +83 -0
- package/utils/deployed-changes.d.ts +4 -0
- package/utils/deployed-changes.js +72 -0
- package/utils/display.d.ts +3 -0
- package/utils/display.js +66 -0
- package/utils/index.d.ts +3 -0
- package/utils/index.js +19 -0
- package/utils/module-utils.d.ts +8 -0
- package/utils/module-utils.js +54 -0
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const logger_1 = require("@launchql/logger");
|
|
4
|
+
const server_1 = require("@launchql/server");
|
|
5
|
+
const env_1 = require("@launchql/env");
|
|
6
|
+
const pg_cache_1 = require("pg-cache");
|
|
7
|
+
const log = new logger_1.Logger('server');
|
|
8
|
+
const serverUsageText = `
|
|
9
|
+
LaunchQL Server Command:
|
|
10
|
+
|
|
11
|
+
lql server [OPTIONS]
|
|
12
|
+
|
|
13
|
+
Start LaunchQL GraphQL development server.
|
|
14
|
+
|
|
15
|
+
Options:
|
|
16
|
+
--help, -h Show this help message
|
|
17
|
+
--port <number> Server port (default: 5555)
|
|
18
|
+
--simpleInflection Use simple inflection (default: true)
|
|
19
|
+
--oppositeBaseNames Use opposite base names (default: false)
|
|
20
|
+
--postgis Enable PostGIS extension (default: true)
|
|
21
|
+
--metaApi Enable Meta API (default: true)
|
|
22
|
+
--cwd <directory> Working directory (default: current directory)
|
|
23
|
+
|
|
24
|
+
Examples:
|
|
25
|
+
lql server Start server with defaults
|
|
26
|
+
lql server --port 8080 Start server on custom port
|
|
27
|
+
lql server --no-postgis Start server without PostGIS
|
|
28
|
+
`;
|
|
29
|
+
const questions = [
|
|
30
|
+
{
|
|
31
|
+
name: 'simpleInflection',
|
|
32
|
+
message: 'Use simple inflection?',
|
|
33
|
+
type: 'confirm',
|
|
34
|
+
required: false,
|
|
35
|
+
default: true,
|
|
36
|
+
useDefault: true
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name: 'oppositeBaseNames',
|
|
40
|
+
message: 'Use opposite base names?',
|
|
41
|
+
type: 'confirm',
|
|
42
|
+
required: false,
|
|
43
|
+
default: false,
|
|
44
|
+
useDefault: true
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
name: 'postgis',
|
|
48
|
+
message: 'Enable PostGIS extension?',
|
|
49
|
+
type: 'confirm',
|
|
50
|
+
required: false,
|
|
51
|
+
default: true,
|
|
52
|
+
useDefault: true
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
name: 'metaApi',
|
|
56
|
+
message: 'Enable Meta API?',
|
|
57
|
+
type: 'confirm',
|
|
58
|
+
required: false,
|
|
59
|
+
default: true,
|
|
60
|
+
useDefault: true
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
name: 'origin',
|
|
64
|
+
message: 'CORS origin (exact URL or *)',
|
|
65
|
+
type: 'text',
|
|
66
|
+
required: false,
|
|
67
|
+
// no default to avoid accidentally opening up CORS; pass explicitly or via env
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
name: 'port',
|
|
71
|
+
message: 'Development server port',
|
|
72
|
+
type: 'number',
|
|
73
|
+
required: false,
|
|
74
|
+
default: 5555,
|
|
75
|
+
useDefault: true
|
|
76
|
+
}
|
|
77
|
+
];
|
|
78
|
+
exports.default = async (argv, prompter, _options) => {
|
|
79
|
+
// Show usage if explicitly requested
|
|
80
|
+
if (argv.help || argv.h) {
|
|
81
|
+
console.log(serverUsageText);
|
|
82
|
+
process.exit(0);
|
|
83
|
+
}
|
|
84
|
+
log.info('🔧 LaunchQL Server Configuration:\n');
|
|
85
|
+
let selectedDb = process.env.PGDATABASE;
|
|
86
|
+
if (!selectedDb) {
|
|
87
|
+
const db = await (0, pg_cache_1.getPgPool)({ database: 'postgres' });
|
|
88
|
+
const result = await db.query(`
|
|
89
|
+
SELECT datname FROM pg_database
|
|
90
|
+
WHERE datistemplate = false AND datname NOT IN ('postgres')
|
|
91
|
+
AND datname !~ '^pg_'
|
|
92
|
+
ORDER BY datname;
|
|
93
|
+
`);
|
|
94
|
+
const dbChoices = result.rows.map(row => row.datname);
|
|
95
|
+
const { database } = await prompter.prompt(argv, [
|
|
96
|
+
{
|
|
97
|
+
type: 'autocomplete',
|
|
98
|
+
name: 'database',
|
|
99
|
+
message: 'Select the database to use',
|
|
100
|
+
options: dbChoices,
|
|
101
|
+
required: true
|
|
102
|
+
}
|
|
103
|
+
]);
|
|
104
|
+
selectedDb = database;
|
|
105
|
+
log.info(`📌 Using database: "${selectedDb}"`);
|
|
106
|
+
}
|
|
107
|
+
const { oppositeBaseNames, port, postgis, simpleInflection, metaApi, origin } = await prompter.prompt(argv, questions);
|
|
108
|
+
// Warn when passing CORS override via CLI, especially in production
|
|
109
|
+
if (origin && origin.trim().length) {
|
|
110
|
+
const env = (process.env.NODE_ENV || 'development').toLowerCase();
|
|
111
|
+
if (env === 'production') {
|
|
112
|
+
if (origin.trim() === '*') {
|
|
113
|
+
log.warn('CORS wildcard ("*") provided via --origin in production: this effectively disables CORS and is not recommended. Prefer per-API CORS via meta schema.');
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
log.warn(`CORS override (origin=${origin.trim()}) provided via --origin in production. Prefer per-API CORS via meta schema.`);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
let selectedSchemas = [];
|
|
121
|
+
let authRole;
|
|
122
|
+
let roleName;
|
|
123
|
+
if (!metaApi) {
|
|
124
|
+
const db = await (0, pg_cache_1.getPgPool)({ database: selectedDb });
|
|
125
|
+
const result = await db.query(`
|
|
126
|
+
SELECT nspname
|
|
127
|
+
FROM pg_namespace
|
|
128
|
+
WHERE nspname NOT IN ('pg_catalog', 'information_schema')
|
|
129
|
+
ORDER BY nspname;
|
|
130
|
+
`);
|
|
131
|
+
const schemaChoices = result.rows.map(row => ({
|
|
132
|
+
name: row.nspname,
|
|
133
|
+
value: row.nspname,
|
|
134
|
+
selected: true
|
|
135
|
+
}));
|
|
136
|
+
const { schemas } = await prompter.prompt(argv, [
|
|
137
|
+
{
|
|
138
|
+
type: 'checkbox',
|
|
139
|
+
name: 'schemas',
|
|
140
|
+
message: 'Select schemas to expose',
|
|
141
|
+
options: schemaChoices,
|
|
142
|
+
required: true
|
|
143
|
+
}
|
|
144
|
+
]);
|
|
145
|
+
selectedSchemas = schemas.filter(s => s.selected).map(s => s.value);
|
|
146
|
+
const { authRole: selectedAuthRole, roleName: selectedRoleName } = await prompter.prompt(argv, [
|
|
147
|
+
{
|
|
148
|
+
type: 'autocomplete',
|
|
149
|
+
name: 'authRole',
|
|
150
|
+
message: 'Select the authentication role',
|
|
151
|
+
options: ['postgres', 'authenticated', 'anonymous'],
|
|
152
|
+
required: true
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
type: 'autocomplete',
|
|
156
|
+
name: 'roleName',
|
|
157
|
+
message: 'Enter the default role name:',
|
|
158
|
+
options: ['postgres', 'authenticated', 'anonymous'],
|
|
159
|
+
required: true
|
|
160
|
+
}
|
|
161
|
+
]);
|
|
162
|
+
authRole = selectedAuthRole;
|
|
163
|
+
roleName = selectedRoleName;
|
|
164
|
+
}
|
|
165
|
+
const options = (0, env_1.getEnvOptions)({
|
|
166
|
+
pg: { database: selectedDb },
|
|
167
|
+
features: {
|
|
168
|
+
oppositeBaseNames,
|
|
169
|
+
simpleInflection,
|
|
170
|
+
postgis
|
|
171
|
+
},
|
|
172
|
+
api: {
|
|
173
|
+
enableMetaApi: metaApi,
|
|
174
|
+
...(metaApi === false && { exposedSchemas: selectedSchemas, authRole, roleName })
|
|
175
|
+
},
|
|
176
|
+
server: {
|
|
177
|
+
port,
|
|
178
|
+
...(origin ? { origin } : {})
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
log.success('✅ Selected Configuration:');
|
|
182
|
+
for (const [key, value] of Object.entries(options)) {
|
|
183
|
+
log.debug(`${key}: ${JSON.stringify(value)}`);
|
|
184
|
+
}
|
|
185
|
+
log.success('🚀 Launching Server...\n');
|
|
186
|
+
(0, server_1.LaunchQLServer)(options);
|
|
187
|
+
};
|
package/commands/tag.js
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
const core_1 = require("@launchql/core");
|
|
37
|
+
const logger_1 = require("@launchql/logger");
|
|
38
|
+
const types_1 = require("@launchql/types");
|
|
39
|
+
const argv_1 = require("../utils/argv");
|
|
40
|
+
const module_utils_1 = require("../utils/module-utils");
|
|
41
|
+
const path = __importStar(require("path"));
|
|
42
|
+
const log = new logger_1.Logger('tag');
|
|
43
|
+
const tagUsageText = `
|
|
44
|
+
LaunchQL Tag Command:
|
|
45
|
+
|
|
46
|
+
lql tag [tag_name] [OPTIONS]
|
|
47
|
+
|
|
48
|
+
Add tags to changes for versioning.
|
|
49
|
+
|
|
50
|
+
Arguments:
|
|
51
|
+
tag_name Name of the tag to create
|
|
52
|
+
|
|
53
|
+
Options:
|
|
54
|
+
--help, -h Show this help message
|
|
55
|
+
--package <name> Target specific package
|
|
56
|
+
--changeName <name> Target specific change (default: latest)
|
|
57
|
+
--comment <text> Optional tag comment
|
|
58
|
+
--cwd <directory> Working directory (default: current directory)
|
|
59
|
+
|
|
60
|
+
Examples:
|
|
61
|
+
lql tag v1.0.0 Add tag to latest change
|
|
62
|
+
lql tag v1.0.0 --comment "Initial release" Add tag with comment
|
|
63
|
+
lql tag v1.1.0 --package mypackage --changeName my-change Tag specific change in package
|
|
64
|
+
`;
|
|
65
|
+
exports.default = async (argv, prompter, _options) => {
|
|
66
|
+
// Show usage if explicitly requested
|
|
67
|
+
if (argv.help || argv.h) {
|
|
68
|
+
console.log(tagUsageText);
|
|
69
|
+
process.exit(0);
|
|
70
|
+
}
|
|
71
|
+
const { first: tagName, newArgv } = (0, argv_1.extractFirst)(argv);
|
|
72
|
+
const cwdResult = await prompter.prompt(newArgv, [
|
|
73
|
+
{
|
|
74
|
+
type: 'text',
|
|
75
|
+
name: 'cwd',
|
|
76
|
+
message: 'Working directory',
|
|
77
|
+
required: false,
|
|
78
|
+
default: process.cwd(),
|
|
79
|
+
useDefault: true
|
|
80
|
+
}
|
|
81
|
+
]);
|
|
82
|
+
const cwd = cwdResult.cwd || process.cwd();
|
|
83
|
+
const pkg = new core_1.LaunchQLPackage(cwd);
|
|
84
|
+
let packageName;
|
|
85
|
+
if (argv.package) {
|
|
86
|
+
packageName = argv.package;
|
|
87
|
+
log.info(`Using specified package: ${packageName}`);
|
|
88
|
+
}
|
|
89
|
+
else if (pkg.isInModule()) {
|
|
90
|
+
packageName = pkg.getModuleName();
|
|
91
|
+
log.info(`Using current module: ${packageName}`);
|
|
92
|
+
}
|
|
93
|
+
else if (pkg.isInWorkspace()) {
|
|
94
|
+
packageName = await (0, module_utils_1.selectPackage)(newArgv, prompter, cwd, 'add tag to', log);
|
|
95
|
+
if (!packageName) {
|
|
96
|
+
throw new Error('No package selected. Cannot add tag without specifying a target package.');
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
throw new Error('This command must be run inside a LaunchQL workspace or module.');
|
|
101
|
+
}
|
|
102
|
+
const questions = [];
|
|
103
|
+
if (!tagName) {
|
|
104
|
+
questions.push({
|
|
105
|
+
type: 'text',
|
|
106
|
+
name: 'tagName',
|
|
107
|
+
message: 'Tag name',
|
|
108
|
+
required: true,
|
|
109
|
+
validate: (value) => {
|
|
110
|
+
if (!value || value.trim().length === 0) {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
if (value.includes('/')) {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
if (value.includes('@')) {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
questions.push({
|
|
124
|
+
type: 'text',
|
|
125
|
+
name: 'changeName',
|
|
126
|
+
message: 'Target change name (leave empty for latest change)',
|
|
127
|
+
required: false
|
|
128
|
+
}, {
|
|
129
|
+
type: 'text',
|
|
130
|
+
name: 'comment',
|
|
131
|
+
message: 'Tag comment (optional)',
|
|
132
|
+
required: false
|
|
133
|
+
});
|
|
134
|
+
const answers = await prompter.prompt(newArgv, questions);
|
|
135
|
+
const finalTagName = tagName || answers.tagName;
|
|
136
|
+
const changeName = answers.changeName;
|
|
137
|
+
const comment = answers.comment;
|
|
138
|
+
try {
|
|
139
|
+
if (argv.package || !pkg.isInModule()) {
|
|
140
|
+
const moduleMap = pkg.getModuleMap();
|
|
141
|
+
const module = moduleMap[packageName];
|
|
142
|
+
if (!module) {
|
|
143
|
+
throw types_1.errors.MODULE_NOT_FOUND({ name: packageName });
|
|
144
|
+
}
|
|
145
|
+
const workspacePath = pkg.getWorkspacePath();
|
|
146
|
+
const absoluteModulePath = path.resolve(workspacePath, module.path);
|
|
147
|
+
const originalCwd = process.cwd();
|
|
148
|
+
process.chdir(absoluteModulePath);
|
|
149
|
+
try {
|
|
150
|
+
const modulePkg = new core_1.LaunchQLPackage(absoluteModulePath);
|
|
151
|
+
modulePkg.addTag(finalTagName.trim(), changeName?.trim() || undefined, comment?.trim() || undefined);
|
|
152
|
+
log.info(`Successfully added tag '${finalTagName}' to ${changeName || 'latest change'} in package '${packageName}'`);
|
|
153
|
+
}
|
|
154
|
+
finally {
|
|
155
|
+
process.chdir(originalCwd);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
pkg.addTag(finalTagName.trim(), changeName?.trim() || undefined, comment?.trim() || undefined);
|
|
160
|
+
log.info(`Successfully added tag '${finalTagName}' to ${changeName || 'latest change'}`);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
log.error(`Failed to add tag: ${error instanceof Error ? error.message : String(error)}`);
|
|
165
|
+
throw error;
|
|
166
|
+
}
|
|
167
|
+
return newArgv;
|
|
168
|
+
};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const core_1 = require("@launchql/core");
|
|
4
|
+
const logger_1 = require("@launchql/logger");
|
|
5
|
+
const env_1 = require("@launchql/env");
|
|
6
|
+
const pg_env_1 = require("pg-env");
|
|
7
|
+
const utils_1 = require("../utils");
|
|
8
|
+
const deployed_changes_1 = require("../utils/deployed-changes");
|
|
9
|
+
const cli_error_1 = require("../utils/cli-error");
|
|
10
|
+
const log = new logger_1.Logger('verify');
|
|
11
|
+
const verifyUsageText = `
|
|
12
|
+
LaunchQL Verify Command:
|
|
13
|
+
|
|
14
|
+
lql verify [OPTIONS]
|
|
15
|
+
|
|
16
|
+
Verify database state matches expected migrations.
|
|
17
|
+
|
|
18
|
+
Options:
|
|
19
|
+
--help, -h Show this help message
|
|
20
|
+
--recursive Verify recursively through dependencies
|
|
21
|
+
--package <name> Verify specific package
|
|
22
|
+
--to <target> Verify up to specific change or tag
|
|
23
|
+
--to Interactive selection of deployed changes
|
|
24
|
+
--cwd <directory> Working directory (default: current directory)
|
|
25
|
+
|
|
26
|
+
Examples:
|
|
27
|
+
lql verify Verify current database state
|
|
28
|
+
lql verify --package mypackage Verify specific package
|
|
29
|
+
lql verify --to Interactive selection from deployed changes
|
|
30
|
+
`;
|
|
31
|
+
exports.default = async (argv, prompter, _options) => {
|
|
32
|
+
// Show usage if explicitly requested
|
|
33
|
+
if (argv.help || argv.h) {
|
|
34
|
+
console.log(verifyUsageText);
|
|
35
|
+
process.exit(0);
|
|
36
|
+
}
|
|
37
|
+
const database = await (0, utils_1.getTargetDatabase)(argv, prompter, {
|
|
38
|
+
message: 'Select database'
|
|
39
|
+
});
|
|
40
|
+
const questions = [
|
|
41
|
+
{
|
|
42
|
+
name: 'recursive',
|
|
43
|
+
type: 'confirm',
|
|
44
|
+
message: 'Deploy recursively through dependencies?',
|
|
45
|
+
useDefault: true,
|
|
46
|
+
default: true,
|
|
47
|
+
required: false
|
|
48
|
+
},
|
|
49
|
+
];
|
|
50
|
+
let { recursive, cwd } = await prompter.prompt(argv, questions);
|
|
51
|
+
log.debug(`Using current directory: ${cwd}`);
|
|
52
|
+
let packageName;
|
|
53
|
+
if (recursive && argv.to !== true) {
|
|
54
|
+
packageName = await (0, deployed_changes_1.selectDeployedPackage)(database, argv, prompter, log, 'verify');
|
|
55
|
+
if (!packageName) {
|
|
56
|
+
await (0, cli_error_1.cliExitWithError)('No package found to verify');
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const project = new core_1.LaunchQLPackage(cwd);
|
|
60
|
+
const opts = (0, env_1.getEnvOptions)({
|
|
61
|
+
pg: (0, pg_env_1.getPgEnvOptions)({ database })
|
|
62
|
+
});
|
|
63
|
+
let target;
|
|
64
|
+
if (argv.to === true) {
|
|
65
|
+
target = await (0, deployed_changes_1.selectDeployedChange)(database, argv, prompter, log, 'verify');
|
|
66
|
+
if (!target) {
|
|
67
|
+
await (0, cli_error_1.cliExitWithError)('No target selected, operation cancelled');
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
else if (packageName && argv.to) {
|
|
71
|
+
target = `${packageName}:${argv.to}`;
|
|
72
|
+
}
|
|
73
|
+
else if (packageName) {
|
|
74
|
+
target = packageName;
|
|
75
|
+
}
|
|
76
|
+
else if (argv.package && argv.to) {
|
|
77
|
+
target = `${argv.package}:${argv.to}`;
|
|
78
|
+
}
|
|
79
|
+
else if (argv.package) {
|
|
80
|
+
target = argv.package;
|
|
81
|
+
}
|
|
82
|
+
await project.verify(opts, target, recursive);
|
|
83
|
+
log.success('Verify complete.');
|
|
84
|
+
return argv;
|
|
85
|
+
};
|
package/commands.d.ts
ADDED
package/commands.js
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
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.commands = void 0;
|
|
7
|
+
const pg_cache_1 = require("pg-cache");
|
|
8
|
+
// Commands
|
|
9
|
+
const add_1 = __importDefault(require("./commands/add"));
|
|
10
|
+
const admin_users_1 = __importDefault(require("./commands/admin-users"));
|
|
11
|
+
const clear_1 = __importDefault(require("./commands/clear"));
|
|
12
|
+
const deploy_1 = __importDefault(require("./commands/deploy"));
|
|
13
|
+
const explorer_1 = __importDefault(require("./commands/explorer"));
|
|
14
|
+
const export_1 = __importDefault(require("./commands/export"));
|
|
15
|
+
const extension_1 = __importDefault(require("./commands/extension"));
|
|
16
|
+
const init_1 = __importDefault(require("./commands/init"));
|
|
17
|
+
const install_1 = __importDefault(require("./commands/install"));
|
|
18
|
+
const kill_1 = __importDefault(require("./commands/kill"));
|
|
19
|
+
const migrate_1 = __importDefault(require("./commands/migrate"));
|
|
20
|
+
const package_1 = __importDefault(require("./commands/package"));
|
|
21
|
+
const plan_1 = __importDefault(require("./commands/plan"));
|
|
22
|
+
const remove_1 = __importDefault(require("./commands/remove"));
|
|
23
|
+
const revert_1 = __importDefault(require("./commands/revert"));
|
|
24
|
+
const server_1 = __importDefault(require("./commands/server"));
|
|
25
|
+
const tag_1 = __importDefault(require("./commands/tag"));
|
|
26
|
+
const verify_1 = __importDefault(require("./commands/verify"));
|
|
27
|
+
const analyze_1 = __importDefault(require("./commands/analyze"));
|
|
28
|
+
const rename_1 = __importDefault(require("./commands/rename"));
|
|
29
|
+
const package_2 = require("./package");
|
|
30
|
+
const utils_1 = require("./utils");
|
|
31
|
+
const cli_error_1 = require("./utils/cli-error");
|
|
32
|
+
const withPgTeardown = (fn, skipTeardown = false) => async (...args) => {
|
|
33
|
+
try {
|
|
34
|
+
await fn(...args);
|
|
35
|
+
}
|
|
36
|
+
finally {
|
|
37
|
+
if (!skipTeardown) {
|
|
38
|
+
await (0, pg_cache_1.teardownPgPools)();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
const createCommandMap = (skipPgTeardown = false) => {
|
|
43
|
+
const pgt = (fn) => withPgTeardown(fn, skipPgTeardown);
|
|
44
|
+
return {
|
|
45
|
+
add: add_1.default,
|
|
46
|
+
'admin-users': pgt(admin_users_1.default),
|
|
47
|
+
clear: pgt(clear_1.default),
|
|
48
|
+
deploy: pgt(deploy_1.default),
|
|
49
|
+
verify: pgt(verify_1.default),
|
|
50
|
+
revert: pgt(revert_1.default),
|
|
51
|
+
remove: pgt(remove_1.default),
|
|
52
|
+
init: pgt(init_1.default),
|
|
53
|
+
extension: pgt(extension_1.default),
|
|
54
|
+
plan: pgt(plan_1.default),
|
|
55
|
+
export: pgt(export_1.default),
|
|
56
|
+
package: pgt(package_1.default),
|
|
57
|
+
tag: pgt(tag_1.default),
|
|
58
|
+
kill: pgt(kill_1.default),
|
|
59
|
+
install: pgt(install_1.default),
|
|
60
|
+
migrate: pgt(migrate_1.default),
|
|
61
|
+
analyze: pgt(analyze_1.default),
|
|
62
|
+
rename: pgt(rename_1.default),
|
|
63
|
+
// These manage their own connection lifecycles
|
|
64
|
+
server: server_1.default,
|
|
65
|
+
explorer: explorer_1.default
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
const commands = async (argv, prompter, options) => {
|
|
69
|
+
if (argv.version || argv.v) {
|
|
70
|
+
const pkg = (0, package_2.readAndParsePackageJson)();
|
|
71
|
+
console.log(pkg.version);
|
|
72
|
+
process.exit(0);
|
|
73
|
+
}
|
|
74
|
+
let { first: command, newArgv } = (0, utils_1.extractFirst)(argv);
|
|
75
|
+
// Show usage if explicitly requested but no command specified
|
|
76
|
+
if ((argv.help || argv.h || command === 'help') && !command) {
|
|
77
|
+
console.log(utils_1.usageText);
|
|
78
|
+
process.exit(0);
|
|
79
|
+
}
|
|
80
|
+
// Show usage for help command specifically
|
|
81
|
+
if (command === 'help') {
|
|
82
|
+
console.log(utils_1.usageText);
|
|
83
|
+
process.exit(0);
|
|
84
|
+
}
|
|
85
|
+
const commandMap = createCommandMap(options?.skipPgTeardown);
|
|
86
|
+
// Prompt if no command provided
|
|
87
|
+
if (!command) {
|
|
88
|
+
const answer = await prompter.prompt(argv, [
|
|
89
|
+
{
|
|
90
|
+
type: 'autocomplete',
|
|
91
|
+
name: 'command',
|
|
92
|
+
message: 'What do you want to do?',
|
|
93
|
+
options: Object.keys(commandMap)
|
|
94
|
+
}
|
|
95
|
+
]);
|
|
96
|
+
command = answer.command;
|
|
97
|
+
}
|
|
98
|
+
// Prompt for working directory
|
|
99
|
+
newArgv = await prompter.prompt(newArgv, [
|
|
100
|
+
{
|
|
101
|
+
type: 'text',
|
|
102
|
+
name: 'cwd',
|
|
103
|
+
message: 'Working directory',
|
|
104
|
+
required: false,
|
|
105
|
+
default: process.cwd(),
|
|
106
|
+
useDefault: true
|
|
107
|
+
}
|
|
108
|
+
]);
|
|
109
|
+
const commandFn = commandMap[command];
|
|
110
|
+
if (!commandFn) {
|
|
111
|
+
console.log(utils_1.usageText);
|
|
112
|
+
await (0, cli_error_1.cliExitWithError)(`Unknown command: ${command}`);
|
|
113
|
+
}
|
|
114
|
+
await commandFn(newArgv, prompter, options);
|
|
115
|
+
prompter.close();
|
|
116
|
+
return argv;
|
|
117
|
+
};
|
|
118
|
+
exports.commands = commands;
|