@codapult/cli 0.15.2 → 0.16.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.
Files changed (67) hide show
  1. package/README.md +107 -3
  2. package/dist/commands/config-show.js +6 -32
  3. package/dist/commands/db.d.ts +2 -0
  4. package/dist/commands/db.js +81 -2
  5. package/dist/commands/deploy.js +44 -17
  6. package/dist/commands/doctor.d.ts +1 -1
  7. package/dist/commands/doctor.js +9 -234
  8. package/dist/commands/env.js +21 -17
  9. package/dist/commands/mcp.d.ts +5 -0
  10. package/dist/commands/mcp.js +98 -0
  11. package/dist/commands/plugins.js +40 -5
  12. package/dist/commands/setup.js +6 -6
  13. package/dist/index.js +24 -5
  14. package/dist/mcp/resources.js +34 -3
  15. package/dist/mcp/server.js +4 -1
  16. package/dist/mcp/tools/db.js +185 -49
  17. package/dist/mcp/tools/db.test.js +59 -7
  18. package/dist/mcp/tools/env.d.ts +7 -0
  19. package/dist/mcp/tools/env.js +96 -2
  20. package/dist/mcp/tools/env.test.js +4 -2
  21. package/dist/mcp/tools/generate.js +64 -10
  22. package/dist/mcp/tools/plugins.js +125 -13
  23. package/dist/mcp/tools/project.js +59 -46
  24. package/dist/mcp/tools/project.test.js +20 -8
  25. package/dist/utils/check-report.d.ts +18 -0
  26. package/dist/utils/check-report.js +30 -0
  27. package/dist/utils/command.d.ts +18 -0
  28. package/dist/utils/command.js +29 -0
  29. package/dist/utils/config-report.d.ts +12 -0
  30. package/dist/utils/config-report.js +41 -0
  31. package/dist/utils/config-report.test.d.ts +1 -0
  32. package/dist/utils/config-report.test.js +20 -0
  33. package/dist/utils/db-diff.d.ts +11 -0
  34. package/dist/utils/db-diff.js +37 -0
  35. package/dist/utils/env-compatibility.d.ts +10 -0
  36. package/dist/utils/env-compatibility.js +52 -0
  37. package/dist/utils/env-compatibility.test.d.ts +1 -0
  38. package/dist/utils/env-compatibility.test.js +23 -0
  39. package/dist/utils/env-config.d.ts +9 -0
  40. package/dist/utils/env-config.js +116 -4
  41. package/dist/utils/env-schema-parser.d.ts +2 -0
  42. package/dist/utils/env-schema-parser.js +32 -0
  43. package/dist/utils/env-schema-parser.test.d.ts +1 -0
  44. package/dist/utils/env-schema-parser.test.js +11 -0
  45. package/dist/utils/health-render.d.ts +3 -0
  46. package/dist/utils/health-render.js +28 -0
  47. package/dist/utils/health-render.test.d.ts +1 -0
  48. package/dist/utils/health-render.test.js +18 -0
  49. package/dist/utils/health.d.ts +26 -0
  50. package/dist/utils/health.js +249 -0
  51. package/dist/utils/live-db-diff.d.ts +17 -0
  52. package/dist/utils/live-db-diff.js +131 -0
  53. package/dist/utils/live-db-diff.test.d.ts +1 -0
  54. package/dist/utils/live-db-diff.test.js +29 -0
  55. package/dist/utils/manifest.d.ts +1 -0
  56. package/dist/utils/patchers.d.ts +2 -0
  57. package/dist/utils/patchers.js +25 -13
  58. package/dist/utils/patchers.test.js +41 -7
  59. package/dist/utils/schema-parity.d.ts +15 -0
  60. package/dist/utils/schema-parity.js +91 -0
  61. package/dist/utils/schema-parity.test.d.ts +1 -0
  62. package/dist/utils/schema-parity.test.js +27 -0
  63. package/dist/utils/schema-parser.d.ts +12 -0
  64. package/dist/utils/schema-parser.js +130 -0
  65. package/dist/utils/schema-parser.test.d.ts +1 -0
  66. package/dist/utils/schema-parser.test.js +59 -0
  67. package/package.json +8 -7
@@ -0,0 +1,91 @@
1
+ function typeGroup(type) {
2
+ const normalized = type.toLowerCase().replaceAll(/\s+/g, '');
3
+ if (['text', 'varchar', 'char', 'uuid', 'json', 'jsonb'].includes(normalized))
4
+ return 'text';
5
+ if (['integer', 'serial', 'bigint', 'smallint'].includes(normalized))
6
+ return 'integer';
7
+ if (['real', 'doubleprecision', 'numeric', 'decimal'].includes(normalized))
8
+ return 'real';
9
+ if (['timestamp', 'date', 'time'].includes(normalized))
10
+ return 'datetime';
11
+ if (['boolean', 'bool'].includes(normalized))
12
+ return 'boolean';
13
+ if (['blob', 'bytea'].includes(normalized))
14
+ return 'binary';
15
+ return normalized;
16
+ }
17
+ /**
18
+ * SQLite and PostgreSQL use different physical representations for several
19
+ * shared Drizzle types (for example SQLite integer vs PostgreSQL timestamp).
20
+ * Compare semantic groups so the check catches real drift without flagging
21
+ * the expected provider-specific representation.
22
+ */
23
+ function compatibleTypes(sqliteType, postgresType) {
24
+ const sqliteGroup = typeGroup(sqliteType);
25
+ const postgresGroup = typeGroup(postgresType);
26
+ if (sqliteGroup === postgresGroup)
27
+ return true;
28
+ if (sqliteGroup === 'integer' && ['datetime', 'boolean'].includes(postgresGroup))
29
+ return true;
30
+ if (sqliteGroup === 'text' && postgresGroup === 'text')
31
+ return true;
32
+ return false;
33
+ }
34
+ export function compareSchemaFiles(sqlite, postgres) {
35
+ const sqliteTables = new Map(sqlite.map((table) => [table.name, table]));
36
+ const postgresTables = new Map(postgres.map((table) => [table.name, table]));
37
+ const differences = [];
38
+ for (const tableName of new Set([...sqliteTables.keys(), ...postgresTables.keys()])) {
39
+ const sqliteTable = sqliteTables.get(tableName);
40
+ const postgresTable = postgresTables.get(tableName);
41
+ if (!sqliteTable) {
42
+ differences.push({ table: tableName, issue: 'missing_in_sqlite', severity: 'fail' });
43
+ continue;
44
+ }
45
+ if (!postgresTable) {
46
+ differences.push({ table: tableName, issue: 'missing_in_postgres', severity: 'fail' });
47
+ continue;
48
+ }
49
+ const sqliteColumns = new Map(sqliteTable.columns.map((column) => [column.databaseName, column]));
50
+ const postgresColumns = new Map(postgresTable.columns.map((column) => [column.databaseName, column]));
51
+ for (const columnName of new Set([...sqliteColumns.keys(), ...postgresColumns.keys()])) {
52
+ const sqliteColumn = sqliteColumns.get(columnName);
53
+ const postgresColumn = postgresColumns.get(columnName);
54
+ if (!sqliteColumn) {
55
+ differences.push({
56
+ table: tableName,
57
+ issue: 'column_missing_in_sqlite',
58
+ severity: 'fail',
59
+ details: columnName,
60
+ });
61
+ continue;
62
+ }
63
+ if (!postgresColumn) {
64
+ differences.push({
65
+ table: tableName,
66
+ issue: 'column_missing_in_postgres',
67
+ severity: 'fail',
68
+ details: columnName,
69
+ });
70
+ continue;
71
+ }
72
+ if (!compatibleTypes(sqliteColumn.type, postgresColumn.type)) {
73
+ differences.push({
74
+ table: tableName,
75
+ issue: 'column_type_differs',
76
+ severity: 'warn',
77
+ details: { column: columnName, sqlite: sqliteColumn.type, postgres: postgresColumn.type },
78
+ });
79
+ }
80
+ }
81
+ }
82
+ return {
83
+ status: differences.some((difference) => difference.severity === 'fail')
84
+ ? 'fail'
85
+ : differences.length > 0
86
+ ? 'warn'
87
+ : 'ok',
88
+ identical: differences.length === 0,
89
+ differences,
90
+ };
91
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,27 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { compareSchemaFiles } from './schema-parity.js';
3
+ const column = (databaseName, type) => ({
4
+ name: databaseName,
5
+ databaseName,
6
+ type,
7
+ constraints: [],
8
+ });
9
+ describe('compareSchemaFiles', () => {
10
+ it('accepts provider-specific representations of shared types', () => {
11
+ const report = compareSchemaFiles([{ name: 'users', columns: [column('id', 'text'), column('created_at', 'integer')] }], [{ name: 'users', columns: [column('id', 'text'), column('created_at', 'timestamp')] }]);
12
+ expect(report).toEqual({ status: 'ok', identical: true, differences: [] });
13
+ });
14
+ it('fails for missing tables and columns', () => {
15
+ const report = compareSchemaFiles([{ name: 'users', columns: [column('id', 'text')] }], [{ name: 'posts', columns: [column('id', 'text'), column('title', 'text')] }]);
16
+ expect(report.status).toBe('fail');
17
+ expect(report.differences).toEqual([
18
+ { table: 'users', issue: 'missing_in_postgres', severity: 'fail' },
19
+ { table: 'posts', issue: 'missing_in_sqlite', severity: 'fail' },
20
+ ]);
21
+ });
22
+ it('warns for an incompatible column type without failing structural parity', () => {
23
+ const report = compareSchemaFiles([{ name: 'users', columns: [column('id', 'text')] }], [{ name: 'users', columns: [column('id', 'integer')] }]);
24
+ expect(report.status).toBe('warn');
25
+ expect(report.differences[0]?.severity).toBe('warn');
26
+ });
27
+ });
@@ -0,0 +1,12 @@
1
+ export interface ParsedColumn {
2
+ name: string;
3
+ databaseName: string;
4
+ type: string;
5
+ constraints: string[];
6
+ }
7
+ export interface ParsedTable {
8
+ name: string;
9
+ columns: ParsedColumn[];
10
+ }
11
+ /** Parse Drizzle sqliteTable/pgTable declarations without relying on formatting. */
12
+ export declare function parseDatabaseSchema(content: string, fileName?: string): ParsedTable[];
@@ -0,0 +1,130 @@
1
+ import ts from 'typescript';
2
+ function nodeName(node) {
3
+ if (ts.isIdentifier(node) || ts.isStringLiteral(node) || ts.isNumericLiteral(node)) {
4
+ return node.text;
5
+ }
6
+ return undefined;
7
+ }
8
+ function callName(expression) {
9
+ if (ts.isIdentifier(expression))
10
+ return expression.text;
11
+ if (ts.isPropertyAccessExpression(expression))
12
+ return expression.name.text;
13
+ return undefined;
14
+ }
15
+ function baseFactoryName(expression) {
16
+ let current = expression;
17
+ while (ts.isPropertyAccessExpression(current) || ts.isCallExpression(current)) {
18
+ current = ts.isPropertyAccessExpression(current) ? current.expression : current.expression;
19
+ }
20
+ return ts.isIdentifier(current) ? current.text : undefined;
21
+ }
22
+ function baseFactoryCall(expression) {
23
+ if (ts.isCallExpression(expression)) {
24
+ const name = callName(expression.expression);
25
+ const columnFactories = new Set([
26
+ 'text',
27
+ 'integer',
28
+ 'real',
29
+ 'blob',
30
+ 'boolean',
31
+ 'timestamp',
32
+ 'serial',
33
+ 'bigint',
34
+ 'varchar',
35
+ 'char',
36
+ 'uuid',
37
+ 'json',
38
+ 'jsonb',
39
+ 'numeric',
40
+ 'decimal',
41
+ 'date',
42
+ 'time',
43
+ 'vector',
44
+ ]);
45
+ if (name && columnFactories.has(name)) {
46
+ return expression;
47
+ }
48
+ return baseFactoryCall(expression.expression);
49
+ }
50
+ if (ts.isPropertyAccessExpression(expression))
51
+ return baseFactoryCall(expression.expression);
52
+ return undefined;
53
+ }
54
+ function stringArgument(call) {
55
+ if (call.arguments.length === 0)
56
+ return undefined;
57
+ const first = call.arguments[0];
58
+ return ts.isStringLiteral(first) || ts.isNoSubstitutionTemplateLiteral(first)
59
+ ? first.text
60
+ : undefined;
61
+ }
62
+ function columnConstraints(initializer) {
63
+ const constraints = new Set();
64
+ const visit = (node) => {
65
+ if (ts.isPropertyAccessExpression(node)) {
66
+ const name = node.name.text;
67
+ if (name === 'primaryKey')
68
+ constraints.add('PRIMARY KEY');
69
+ if (name === 'notNull')
70
+ constraints.add('NOT NULL');
71
+ if (name === 'unique')
72
+ constraints.add('UNIQUE');
73
+ if (name === 'references')
74
+ constraints.add('FK');
75
+ if (name === '$defaultFn' || name === '$default')
76
+ constraints.add('DEFAULT');
77
+ }
78
+ ts.forEachChild(node, visit);
79
+ };
80
+ visit(initializer);
81
+ return [...constraints];
82
+ }
83
+ function parseTable(statement) {
84
+ for (const declaration of statement.declarationList.declarations) {
85
+ const initializer = declaration.initializer;
86
+ if (!initializer || !ts.isCallExpression(initializer))
87
+ continue;
88
+ const factory = callName(initializer.expression);
89
+ if (factory !== 'sqliteTable' && factory !== 'pgTable')
90
+ continue;
91
+ const name = stringArgument(initializer);
92
+ const columnsArgument = initializer.arguments[1];
93
+ if (!name || initializer.arguments.length < 2 || !ts.isObjectLiteralExpression(columnsArgument))
94
+ continue;
95
+ const columns = [];
96
+ for (const property of columnsArgument.properties) {
97
+ if (!ts.isPropertyAssignment(property))
98
+ continue;
99
+ const columnName = nodeName(property.name);
100
+ const value = property.initializer;
101
+ if (!columnName || !ts.isCallExpression(value))
102
+ continue;
103
+ const type = baseFactoryName(value.expression);
104
+ if (!type)
105
+ continue;
106
+ const databaseName = stringArgument(baseFactoryCall(value) ?? value) ?? columnName;
107
+ const constraints = columnConstraints(value);
108
+ const order = ['PRIMARY KEY', 'NOT NULL', 'UNIQUE', 'FK', 'DEFAULT'];
109
+ constraints.sort((a, b) => order.indexOf(a) - order.indexOf(b));
110
+ columns.push({ name: columnName, databaseName, type, constraints });
111
+ }
112
+ return { name, columns };
113
+ }
114
+ return undefined;
115
+ }
116
+ /** Parse Drizzle sqliteTable/pgTable declarations without relying on formatting. */
117
+ export function parseDatabaseSchema(content, fileName = 'schema.ts') {
118
+ const sourceFile = ts.createSourceFile(fileName, content, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
119
+ const tables = [];
120
+ const visit = (node) => {
121
+ if (ts.isVariableStatement(node)) {
122
+ const table = parseTable(node);
123
+ if (table)
124
+ tables.push(table);
125
+ }
126
+ ts.forEachChild(node, visit);
127
+ };
128
+ visit(sourceFile);
129
+ return tables;
130
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,59 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { parseDatabaseSchema } from './schema-parser.js';
3
+ describe('parseDatabaseSchema', () => {
4
+ it('parses sqlite and postgres tables regardless of formatting', () => {
5
+ const tables = parseDatabaseSchema(`
6
+ export const account = sqliteTable(
7
+ 'account',
8
+ { id: text('id').primaryKey().notNull(),
9
+ owner_id: integer('owner_id', { mode: 'number' }).references(() => user.id),
10
+ metadata: jsonb('metadata').$default(() => ({})), },
11
+ );
12
+ export const user = pgTable('user', {
13
+ id: uuid('id').defaultRandom().primaryKey(),
14
+ email: varchar('email', { length: 255 }).notNull().unique(),
15
+ });
16
+ `);
17
+ expect(tables).toEqual([
18
+ {
19
+ name: 'account',
20
+ columns: [
21
+ {
22
+ name: 'id',
23
+ databaseName: 'id',
24
+ type: 'text',
25
+ constraints: ['PRIMARY KEY', 'NOT NULL'],
26
+ },
27
+ { name: 'owner_id', databaseName: 'owner_id', type: 'integer', constraints: ['FK'] },
28
+ { name: 'metadata', databaseName: 'metadata', type: 'jsonb', constraints: ['DEFAULT'] },
29
+ ],
30
+ },
31
+ {
32
+ name: 'user',
33
+ columns: [
34
+ { name: 'id', databaseName: 'id', type: 'uuid', constraints: ['PRIMARY KEY'] },
35
+ {
36
+ name: 'email',
37
+ databaseName: 'email',
38
+ type: 'varchar',
39
+ constraints: ['NOT NULL', 'UNIQUE'],
40
+ },
41
+ ],
42
+ },
43
+ ]);
44
+ });
45
+ it('ignores unrelated objects and supports quoted column keys', () => {
46
+ const tables = parseDatabaseSchema(`
47
+ const config = { id: text('not a table') };
48
+ export const thing = sqliteTable('thing', { 'display-name': text('display-name') });
49
+ `);
50
+ expect(tables).toEqual([
51
+ {
52
+ name: 'thing',
53
+ columns: [
54
+ { name: 'display-name', databaseName: 'display-name', type: 'text', constraints: [] },
55
+ ],
56
+ },
57
+ ]);
58
+ });
59
+ });
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@codapult/cli",
3
- "version": "0.15.2",
3
+ "version": "0.16.0",
4
4
  "description": "Codapult CLI — manage, update, and diagnose your Codapult SaaS project",
5
5
  "license": "MIT",
6
- "packageManager": "pnpm@11.20.0+sha512.9a6f330a95b66446ea088faf1521405a8a01f07fde7124cc9958dfed52d4bb436737e65b08f85f37b46fcba375092558ac51262b816844b22f63406ed166bfee",
6
+ "packageManager": "pnpm@11.22.0+sha512.1ff870c4c6133dfd88fb2afc46dd13d47f09c9794b438c6fdb47ca98caf3bc16381ee0be93a091b8e3824cf01f889f46d7d9e20910fb0be1ab0fb5baa80dd621",
7
7
  "engines": {
8
8
  "node": ">=20.19.0"
9
9
  },
@@ -46,6 +46,7 @@
46
46
  "@modelcontextprotocol/sdk": "^1.30.0",
47
47
  "commander": "^15.0.0",
48
48
  "picocolors": "^1.1.1",
49
+ "typescript": "npm:@typescript/typescript6@^6.0.2",
49
50
  "zod": "^4.4.3"
50
51
  },
51
52
  "devDependencies": {
@@ -53,15 +54,15 @@
53
54
  "@js-toolkit/eslint-config": "^1.1.4",
54
55
  "@js-toolkit/prettier-config": "^1.0.1",
55
56
  "@js-toolkit/tsconfig": "^1.0.1",
56
- "@release-it/conventional-changelog": "^11.0.1",
57
+ "@release-it/conventional-changelog": "^12.0.0",
57
58
  "@types/node": "^26.2.0",
59
+ "@typescript/native": "npm:typescript@^7.0.2",
58
60
  "eslint": "^9.39.4",
59
61
  "eslint-config-prettier": "^10.1.8",
60
62
  "eslint-plugin-prettier": "^5.5.6",
61
63
  "prettier": "^3.9.6",
62
- "release-it": "^21.0.1",
63
- "typescript": "^6.0.3",
64
- "typescript-eslint": "^8.66.0",
65
- "vitest": "^4.1.10"
64
+ "release-it": "^21.0.2",
65
+ "typescript-eslint": "^8.67.0",
66
+ "vitest": "^4.1.11"
66
67
  }
67
68
  }