@constructive-io/cli 0.0.3 → 5.1.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.
Files changed (130) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +346 -153
  3. package/commands/{analyze.d.ts → codegen.d.ts} +2 -2
  4. package/commands/codegen.js +131 -0
  5. package/commands/explorer.js +94 -0
  6. package/commands/get-graphql-schema.js +73 -0
  7. package/commands/server.js +187 -0
  8. package/commands.d.ts +0 -1
  9. package/commands.js +42 -61
  10. package/esm/commands/codegen.js +126 -0
  11. package/esm/commands/explorer.js +92 -0
  12. package/esm/commands/get-graphql-schema.js +71 -0
  13. package/esm/commands/server.js +185 -0
  14. package/esm/commands.js +41 -59
  15. package/esm/index.js +16 -36
  16. package/esm/utils/display.js +26 -23
  17. package/esm/utils/index.js +3 -6
  18. package/index.d.ts +0 -22
  19. package/index.js +16 -72
  20. package/package.json +50 -25
  21. package/utils/display.d.ts +1 -1
  22. package/utils/display.js +26 -23
  23. package/utils/index.d.ts +3 -6
  24. package/utils/index.js +7 -20
  25. package/commands/add.d.ts +0 -7
  26. package/commands/add.js +0 -86
  27. package/commands/admin-users/add.d.ts +0 -4
  28. package/commands/admin-users/add.js +0 -89
  29. package/commands/admin-users/bootstrap.d.ts +0 -4
  30. package/commands/admin-users/bootstrap.js +0 -50
  31. package/commands/admin-users/remove.d.ts +0 -4
  32. package/commands/admin-users/remove.js +0 -82
  33. package/commands/admin-users.d.ts +0 -4
  34. package/commands/admin-users.js +0 -68
  35. package/commands/analyze.js +0 -21
  36. package/commands/clear.d.ts +0 -3
  37. package/commands/clear.js +0 -59
  38. package/commands/deploy.d.ts +0 -4
  39. package/commands/deploy.js +0 -146
  40. package/commands/docker.d.ts +0 -3
  41. package/commands/docker.js +0 -194
  42. package/commands/env.d.ts +0 -4
  43. package/commands/env.js +0 -124
  44. package/commands/export.js +0 -129
  45. package/commands/extension.js +0 -48
  46. package/commands/init/index.d.ts +0 -7
  47. package/commands/init/index.js +0 -47
  48. package/commands/init/module.d.ts +0 -4
  49. package/commands/init/module.js +0 -71
  50. package/commands/init/workspace.d.ts +0 -4
  51. package/commands/init/workspace.js +0 -52
  52. package/commands/install.d.ts +0 -4
  53. package/commands/install.js +0 -37
  54. package/commands/kill.js +0 -107
  55. package/commands/migrate/deps.d.ts +0 -4
  56. package/commands/migrate/deps.js +0 -186
  57. package/commands/migrate/init.d.ts +0 -4
  58. package/commands/migrate/init.js +0 -65
  59. package/commands/migrate/list.d.ts +0 -4
  60. package/commands/migrate/list.js +0 -85
  61. package/commands/migrate/status.d.ts +0 -4
  62. package/commands/migrate/status.js +0 -94
  63. package/commands/migrate.d.ts +0 -4
  64. package/commands/migrate.js +0 -69
  65. package/commands/package.d.ts +0 -3
  66. package/commands/package.js +0 -65
  67. package/commands/plan.d.ts +0 -3
  68. package/commands/plan.js +0 -62
  69. package/commands/remove.d.ts +0 -3
  70. package/commands/remove.js +0 -42
  71. package/commands/rename.d.ts +0 -4
  72. package/commands/rename.js +0 -35
  73. package/commands/revert.d.ts +0 -3
  74. package/commands/revert.js +0 -107
  75. package/commands/tag.d.ts +0 -6
  76. package/commands/tag.js +0 -168
  77. package/commands/verify.d.ts +0 -3
  78. package/commands/verify.js +0 -85
  79. package/dist/README.md +0 -412
  80. package/dist/package.json +0 -64
  81. package/esm/commands/add.js +0 -51
  82. package/esm/commands/admin-users/add.js +0 -87
  83. package/esm/commands/admin-users/bootstrap.js +0 -48
  84. package/esm/commands/admin-users/remove.js +0 -80
  85. package/esm/commands/admin-users.js +0 -63
  86. package/esm/commands/analyze.js +0 -16
  87. package/esm/commands/clear.js +0 -54
  88. package/esm/commands/deploy.js +0 -144
  89. package/esm/commands/docker.js +0 -192
  90. package/esm/commands/env.js +0 -122
  91. package/esm/commands/export.js +0 -127
  92. package/esm/commands/extension.js +0 -46
  93. package/esm/commands/init/index.js +0 -42
  94. package/esm/commands/init/module.js +0 -68
  95. package/esm/commands/init/workspace.js +0 -46
  96. package/esm/commands/install.js +0 -35
  97. package/esm/commands/kill.js +0 -105
  98. package/esm/commands/migrate/deps.js +0 -184
  99. package/esm/commands/migrate/init.js +0 -63
  100. package/esm/commands/migrate/list.js +0 -83
  101. package/esm/commands/migrate/status.js +0 -92
  102. package/esm/commands/migrate.js +0 -64
  103. package/esm/commands/package.js +0 -63
  104. package/esm/commands/plan.js +0 -60
  105. package/esm/commands/remove.js +0 -40
  106. package/esm/commands/rename.js +0 -30
  107. package/esm/commands/revert.js +0 -105
  108. package/esm/commands/tag.js +0 -133
  109. package/esm/commands/verify.js +0 -83
  110. package/esm/package.js +0 -26
  111. package/esm/utils/argv.js +0 -92
  112. package/esm/utils/cli-error.js +0 -48
  113. package/esm/utils/database.js +0 -78
  114. package/esm/utils/deployed-changes.js +0 -68
  115. package/esm/utils/module-utils.js +0 -51
  116. package/package.d.ts +0 -1
  117. package/package.js +0 -29
  118. package/utils/argv.d.ts +0 -46
  119. package/utils/argv.js +0 -100
  120. package/utils/cli-error.d.ts +0 -8
  121. package/utils/cli-error.js +0 -52
  122. package/utils/database.d.ts +0 -21
  123. package/utils/database.js +0 -83
  124. package/utils/deployed-changes.d.ts +0 -4
  125. package/utils/deployed-changes.js +0 -72
  126. package/utils/module-utils.d.ts +0 -8
  127. package/utils/module-utils.js +0 -54
  128. /package/commands/{export.d.ts → explorer.d.ts} +0 -0
  129. /package/commands/{extension.d.ts → get-graphql-schema.d.ts} +0 -0
  130. /package/commands/{kill.d.ts → server.d.ts} +0 -0
package/utils/argv.js DELETED
@@ -1,100 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.extractFirst = void 0;
4
- exports.validateCommonArgs = validateCommonArgs;
5
- exports.validateFlagDependencies = validateFlagDependencies;
6
- exports.logEffectiveArgs = logEffectiveArgs;
7
- exports.constructTarget = constructTarget;
8
- const logger_1 = require("@launchql/logger");
9
- const log = new logger_1.Logger('argv-utils');
10
- const extractFirst = (argv) => {
11
- const first = argv._?.[0];
12
- const newArgv = {
13
- ...argv,
14
- _: argv._?.slice(1) ?? []
15
- };
16
- return { first, newArgv };
17
- };
18
- exports.extractFirst = extractFirst;
19
- /**
20
- * Validates and normalizes common CLI arguments
21
- */
22
- function validateCommonArgs(argv) {
23
- const validated = {
24
- ...argv,
25
- cwd: argv.cwd || process.cwd(),
26
- _: argv._ || []
27
- };
28
- const booleanFlags = ['recursive', 'yes', 'tx', 'fast', 'logOnly', 'createdb', 'usePlan', 'cache', 'drop', 'all', 'summary', 'help', 'h'];
29
- for (const flag of booleanFlags) {
30
- if (argv[flag] !== undefined && typeof argv[flag] !== 'boolean') {
31
- log.warn(`--${flag} flag should be boolean, converting to true`);
32
- validated[flag] = true;
33
- }
34
- }
35
- const stringFlags = ['package', 'to', 'database'];
36
- for (const flag of stringFlags) {
37
- if (argv[flag] !== undefined && typeof argv[flag] !== 'string') {
38
- log.warn(`--${flag} should be a string, converting`);
39
- validated[flag] = String(argv[flag]);
40
- }
41
- }
42
- return validated;
43
- }
44
- /**
45
- * Checks if required flags are provided when certain conditions are met
46
- */
47
- function validateFlagDependencies(argv) {
48
- if (argv.to && !argv.package && !argv.recursive) {
49
- log.warn('--to flag provided without --package or --recursive. Target may not work as expected.');
50
- }
51
- if (argv.package && argv.recursive) {
52
- if (argv.package.includes(':')) {
53
- log.warn('--package should not contain ":" when using --recursive. Use --to for target specification.');
54
- }
55
- }
56
- }
57
- /**
58
- * Logs the effective CLI arguments for debugging
59
- */
60
- function logEffectiveArgs(argv, commandName) {
61
- const relevantArgs = {
62
- cwd: argv.cwd,
63
- database: argv.database,
64
- package: argv.package,
65
- to: argv.to,
66
- recursive: argv.recursive,
67
- yes: argv.yes,
68
- tx: argv.tx,
69
- fast: argv.fast,
70
- logOnly: argv.logOnly,
71
- createdb: argv.createdb,
72
- usePlan: argv.usePlan,
73
- cache: argv.cache,
74
- drop: argv.drop,
75
- all: argv.all,
76
- summary: argv.summary
77
- };
78
- const definedArgs = Object.fromEntries(Object.entries(relevantArgs).filter(([_, value]) => value !== undefined));
79
- if (Object.keys(definedArgs).length > 1) { // More than just cwd
80
- log.debug(`${commandName} effective arguments:`, definedArgs);
81
- }
82
- }
83
- /**
84
- * Constructs a deployment target string from package and to arguments
85
- */
86
- function constructTarget(argv, packageName) {
87
- if (packageName && argv.to) {
88
- return `${packageName}:${argv.to}`;
89
- }
90
- else if (packageName) {
91
- return packageName;
92
- }
93
- else if (argv.package && argv.to) {
94
- return `${argv.package}:${argv.to}`;
95
- }
96
- else if (argv.package) {
97
- return argv.package;
98
- }
99
- return undefined;
100
- }
@@ -1,8 +0,0 @@
1
- import { LaunchQLError } from '@launchql/types';
2
- /**
3
- * CLI error utility that logs error information and exits with code 1.
4
- * Provides consistent error handling and user experience across all CLI commands.
5
- *
6
- * IMPORTANT: This function properly cleans up PostgreSQL connections before exiting.
7
- */
8
- export declare const cliExitWithError: (error: LaunchQLError | Error | string, context?: Record<string, any>) => Promise<never>;
@@ -1,52 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.cliExitWithError = void 0;
4
- const logger_1 = require("@launchql/logger");
5
- const types_1 = require("@launchql/types");
6
- const pg_cache_1 = require("pg-cache");
7
- const log = new logger_1.Logger('cli');
8
- /**
9
- * CLI error utility that logs error information and exits with code 1.
10
- * Provides consistent error handling and user experience across all CLI commands.
11
- *
12
- * IMPORTANT: This function properly cleans up PostgreSQL connections before exiting.
13
- */
14
- const cliExitWithError = async (error, context) => {
15
- if (error instanceof types_1.LaunchQLError) {
16
- // For LaunchQLError instances, use structured logging
17
- log.error(`Error: ${error.message}`);
18
- // Log additional context if available
19
- if (error.context && Object.keys(error.context).length > 0) {
20
- log.debug('Error context:', error.context);
21
- }
22
- // Log any additional context provided
23
- if (context) {
24
- log.debug('Additional context:', context);
25
- }
26
- }
27
- else if (error instanceof Error) {
28
- // For generic Error instances
29
- log.error(`Error: ${error.message}`);
30
- if (context) {
31
- log.debug('Context:', context);
32
- }
33
- }
34
- else if (typeof error === 'string') {
35
- // For simple string messages
36
- log.error(`Error: ${error}`);
37
- if (context) {
38
- log.debug('Context:', context);
39
- }
40
- }
41
- // Perform cleanup before exiting
42
- try {
43
- await (0, pg_cache_1.teardownPgPools)();
44
- log.debug('Database connections cleaned up');
45
- }
46
- catch (cleanupError) {
47
- log.warn('Failed to cleanup database connections:', cleanupError);
48
- // Don't let cleanup errors prevent the exit
49
- }
50
- process.exit(1);
51
- };
52
- exports.cliExitWithError = cliExitWithError;
@@ -1,21 +0,0 @@
1
- import { Inquirerer } from 'inquirerer';
2
- import { ParsedArgs } from 'minimist';
3
- export interface DatabaseSelectionOptions {
4
- message?: string;
5
- excludeTemplates?: boolean;
6
- excludePostgres?: boolean;
7
- excludeSystemDbs?: boolean;
8
- multiple?: boolean;
9
- }
10
- /**
11
- * Get list of available databases from PostgreSQL
12
- */
13
- export declare function getAvailableDatabases(options?: DatabaseSelectionOptions): Promise<string[]>;
14
- /**
15
- * Prompt user to select a database
16
- */
17
- export declare function selectDatabase(argv: Partial<ParsedArgs>, prompter: Inquirerer, options?: DatabaseSelectionOptions): Promise<string>;
18
- /**
19
- * Get target database with fallback to environment
20
- */
21
- export declare function getTargetDatabase(argv: Partial<ParsedArgs>, prompter: Inquirerer, options?: DatabaseSelectionOptions): Promise<string>;
package/utils/database.js DELETED
@@ -1,83 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getAvailableDatabases = getAvailableDatabases;
4
- exports.selectDatabase = selectDatabase;
5
- exports.getTargetDatabase = getTargetDatabase;
6
- const pg_cache_1 = require("pg-cache");
7
- const pg_env_1 = require("pg-env");
8
- /**
9
- * Get list of available databases from PostgreSQL
10
- */
11
- async function getAvailableDatabases(options = {}) {
12
- const { excludeTemplates = true, excludePostgres = true, excludeSystemDbs = true } = options;
13
- const db = await (0, pg_cache_1.getPgPool)({
14
- database: 'postgres'
15
- });
16
- let query = `
17
- SELECT datname FROM pg_catalog.pg_database
18
- WHERE 1=1
19
- `;
20
- if (excludeTemplates) {
21
- query += ` AND datistemplate = FALSE`;
22
- }
23
- if (excludePostgres) {
24
- query += ` AND datname NOT IN ('postgres')`;
25
- }
26
- if (excludeSystemDbs) {
27
- query += ` AND datname !~ '^pg_'`;
28
- }
29
- query += ` ORDER BY datname`;
30
- const result = await db.query(query);
31
- return result.rows.map((row) => row.datname);
32
- }
33
- /**
34
- * Prompt user to select a database
35
- */
36
- async function selectDatabase(argv, prompter, options = {}) {
37
- const { message = 'Select target database', multiple = false } = options;
38
- // Check if database is already specified
39
- if (!multiple && (argv.db || argv.database)) {
40
- return argv.db || argv.database;
41
- }
42
- // Get available databases
43
- const databases = await getAvailableDatabases(options);
44
- if (databases.length === 0) {
45
- throw new Error('No databases found');
46
- }
47
- // If only one database and not forcing selection, use it
48
- if (!multiple && databases.length === 1 && !argv.interactive) {
49
- return databases[0];
50
- }
51
- // Prompt for selection
52
- const answer = await prompter.prompt(argv, [
53
- {
54
- type: multiple ? 'checkbox' : 'autocomplete',
55
- name: 'database',
56
- message,
57
- options: databases,
58
- required: true
59
- }
60
- ]);
61
- return answer.database;
62
- }
63
- /**
64
- * Get target database with fallback to environment
65
- */
66
- async function getTargetDatabase(argv, prompter, options = {}) {
67
- // If database is specified in args, use it
68
- if (argv.db || argv.database) {
69
- return argv.db || argv.database;
70
- }
71
- // Try to select from available databases
72
- try {
73
- return await selectDatabase(argv, prompter, options);
74
- }
75
- catch (error) {
76
- // Fall back to environment database
77
- const pgEnv = (0, pg_env_1.getPgEnvOptions)();
78
- if (pgEnv.database) {
79
- return pgEnv.database;
80
- }
81
- throw new Error('No database specified and no default database found');
82
- }
83
- }
@@ -1,4 +0,0 @@
1
- import { Logger } from '@launchql/logger';
2
- import { Inquirerer } from 'inquirerer';
3
- export declare function selectDeployedChange(database: string, argv: Partial<Record<string, any>>, prompter: Inquirerer, log: Logger, action?: 'revert' | 'verify'): Promise<string | undefined>;
4
- export declare function selectDeployedPackage(database: string, argv: Partial<Record<string, any>>, prompter: Inquirerer, log: Logger, action?: 'revert' | 'verify'): Promise<string | undefined>;
@@ -1,72 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.selectDeployedChange = selectDeployedChange;
4
- exports.selectDeployedPackage = selectDeployedPackage;
5
- const core_1 = require("@launchql/core");
6
- const pg_env_1 = require("pg-env");
7
- async function selectDeployedChange(database, argv, prompter, log, action = 'revert') {
8
- const pgEnv = (0, pg_env_1.getPgEnvOptions)({ database });
9
- const client = new core_1.LaunchQLMigrate(pgEnv);
10
- let selectedPackage;
11
- if (argv.package) {
12
- selectedPackage = argv.package;
13
- }
14
- else {
15
- const packageStatuses = await client.status();
16
- if (packageStatuses.length === 0) {
17
- log.warn('No deployed packages found in database');
18
- return undefined;
19
- }
20
- const packageAnswer = await prompter.prompt(argv, [{
21
- type: 'autocomplete',
22
- name: 'package',
23
- message: `Select package to ${action} from:`,
24
- options: packageStatuses.map(status => ({
25
- name: status.package,
26
- value: status.package,
27
- description: `${status.totalDeployed} changes, last: ${status.lastChange}`
28
- }))
29
- }]);
30
- selectedPackage = packageAnswer.package;
31
- }
32
- const deployedChanges = await client.getDeployedChanges(database, selectedPackage);
33
- if (deployedChanges.length === 0) {
34
- log.warn(`No deployed changes found for package ${selectedPackage}`);
35
- return undefined;
36
- }
37
- const changeAnswer = await prompter.prompt(argv, [{
38
- type: 'autocomplete',
39
- name: 'change',
40
- message: `Select change to ${action} to in ${selectedPackage}:`,
41
- options: deployedChanges.map(change => ({
42
- name: change.change_name,
43
- value: change.change_name,
44
- description: `Deployed: ${new Date(change.deployed_at).toLocaleString()}`
45
- }))
46
- }]);
47
- const selectedChange = changeAnswer.change;
48
- return `${selectedPackage}:${selectedChange}`;
49
- }
50
- async function selectDeployedPackage(database, argv, prompter, log, action = 'revert') {
51
- if (argv.package) {
52
- return argv.package;
53
- }
54
- const pgEnv = (0, pg_env_1.getPgEnvOptions)({ database });
55
- const client = new core_1.LaunchQLMigrate(pgEnv);
56
- const packageStatuses = await client.status();
57
- if (packageStatuses.length === 0) {
58
- log.warn('No deployed packages found in database');
59
- return undefined;
60
- }
61
- const packageAnswer = await prompter.prompt(argv, [{
62
- type: 'autocomplete',
63
- name: 'package',
64
- message: `Select package to ${action}:`,
65
- options: packageStatuses.map(status => ({
66
- name: status.package,
67
- value: status.package,
68
- description: `${status.totalDeployed} changes, last: ${status.lastChange}`
69
- }))
70
- }]);
71
- return packageAnswer.package;
72
- }
@@ -1,8 +0,0 @@
1
- import { Logger } from '@launchql/logger';
2
- import { Inquirerer } from 'inquirerer';
3
- import { ParsedArgs } from 'minimist';
4
- /**
5
- * Handle package selection for operations that need a specific package
6
- * Returns the selected package name, or undefined if validation fails or no packages exist
7
- */
8
- export declare function selectPackage(argv: Partial<ParsedArgs>, prompter: Inquirerer, cwd: string, operationName: string, log?: Logger): Promise<string | undefined>;
@@ -1,54 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.selectPackage = selectPackage;
4
- const core_1 = require("@launchql/core");
5
- const types_1 = require("@launchql/types");
6
- /**
7
- * Handle package selection for operations that need a specific package
8
- * Returns the selected package name, or undefined if validation fails or no packages exist
9
- */
10
- async function selectPackage(argv, prompter, cwd, operationName, log) {
11
- const pkg = new core_1.LaunchQLPackage(cwd);
12
- const modules = await pkg.getModules();
13
- const moduleNames = modules.map(mod => mod.getModuleName());
14
- // Check if any modules exist
15
- if (!moduleNames.length) {
16
- const errorMsg = 'No modules found in the specified directory.';
17
- if (log) {
18
- log.error(errorMsg);
19
- return undefined;
20
- }
21
- else {
22
- prompter.close();
23
- throw types_1.errors.NOT_FOUND({}, errorMsg);
24
- }
25
- }
26
- // If a specific package was provided, validate it
27
- if (argv.package) {
28
- const packageName = argv.package;
29
- if (log)
30
- log.info(`Using specified package: ${packageName}`);
31
- if (!moduleNames.includes(packageName)) {
32
- const errorMsg = `Package '${packageName}' not found. Available packages: ${moduleNames.join(', ')}`;
33
- if (log) {
34
- log.error(errorMsg);
35
- return undefined;
36
- }
37
- else {
38
- throw types_1.errors.NOT_FOUND({}, errorMsg);
39
- }
40
- }
41
- return packageName;
42
- }
43
- // Interactive selection
44
- const { package: selectedPackage } = await prompter.prompt(argv, [{
45
- type: 'autocomplete',
46
- name: 'package',
47
- message: `Choose a package to ${operationName}`,
48
- options: moduleNames,
49
- required: true
50
- }]);
51
- if (log)
52
- log.info(`Selected package: ${selectedPackage}`);
53
- return selectedPackage;
54
- }
File without changes
File without changes