@codapult/cli 0.17.2 → 0.19.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 (63) hide show
  1. package/README.md +94 -7
  2. package/dist/commands/config-show.js +6 -9
  3. package/dist/commands/db.js +10 -36
  4. package/dist/commands/deploy.js +8 -19
  5. package/dist/commands/doctor.js +2 -7
  6. package/dist/commands/env.js +3 -11
  7. package/dist/commands/generate.js +5 -21
  8. package/dist/commands/guard.d.ts +5 -0
  9. package/dist/commands/guard.js +5 -0
  10. package/dist/commands/mcp.js +5 -16
  11. package/dist/commands/plugins.js +5 -21
  12. package/dist/commands/setup.js +2 -6
  13. package/dist/commands/update.js +2 -6
  14. package/dist/index.js +111 -5
  15. package/dist/mcp/resources.js +15 -15
  16. package/dist/mcp/server.js +6 -0
  17. package/dist/mcp/tools/db.js +11 -16
  18. package/dist/mcp/tools/deploy.js +2 -8
  19. package/dist/mcp/tools/env.js +6 -12
  20. package/dist/mcp/tools/generate.js +10 -15
  21. package/dist/mcp/tools/plugins.js +5 -11
  22. package/dist/mcp/tools/project.js +9 -30
  23. package/dist/utils/command.d.ts +3 -0
  24. package/dist/utils/command.js +35 -4
  25. package/dist/utils/config.d.ts +5 -0
  26. package/dist/utils/config.js +5 -0
  27. package/dist/utils/project-checks.d.ts +2 -0
  28. package/dist/utils/project-checks.js +2 -0
  29. package/dist/utils/project.d.ts +1 -0
  30. package/dist/utils/project.js +16 -0
  31. package/package.json +16 -5
  32. package/dist/commands/generate.test.d.ts +0 -1
  33. package/dist/commands/generate.test.js +0 -125
  34. package/dist/mcp/tools/db.test.d.ts +0 -1
  35. package/dist/mcp/tools/db.test.js +0 -221
  36. package/dist/mcp/tools/env.test.d.ts +0 -1
  37. package/dist/mcp/tools/env.test.js +0 -156
  38. package/dist/mcp/tools/project.test.d.ts +0 -1
  39. package/dist/mcp/tools/project.test.js +0 -188
  40. package/dist/utils/config-report.test.d.ts +0 -1
  41. package/dist/utils/config-report.test.js +0 -18
  42. package/dist/utils/env-compatibility.test.d.ts +0 -1
  43. package/dist/utils/env-compatibility.test.js +0 -23
  44. package/dist/utils/env-schema-parser.test.d.ts +0 -1
  45. package/dist/utils/env-schema-parser.test.js +0 -11
  46. package/dist/utils/git.test.d.ts +0 -1
  47. package/dist/utils/git.test.js +0 -77
  48. package/dist/utils/health-render.test.d.ts +0 -1
  49. package/dist/utils/health-render.test.js +0 -18
  50. package/dist/utils/live-db-diff.test.d.ts +0 -1
  51. package/dist/utils/live-db-diff.test.js +0 -29
  52. package/dist/utils/manifest.test.d.ts +0 -1
  53. package/dist/utils/manifest.test.js +0 -107
  54. package/dist/utils/patchers.test.d.ts +0 -1
  55. package/dist/utils/patchers.test.js +0 -647
  56. package/dist/utils/project-env.test.d.ts +0 -1
  57. package/dist/utils/project-env.test.js +0 -47
  58. package/dist/utils/project.test.d.ts +0 -1
  59. package/dist/utils/project.test.js +0 -123
  60. package/dist/utils/schema-parity.test.d.ts +0 -1
  61. package/dist/utils/schema-parity.test.js +0 -27
  62. package/dist/utils/schema-parser.test.d.ts +0 -1
  63. package/dist/utils/schema-parser.test.js +0 -59
@@ -1,47 +0,0 @@
1
- import { describe, it, expect, vi, beforeEach } from 'vitest';
2
- import { ENV_FILE_NAME, getProjectEnvFilePath, getProjectEnvOptions, getProjectEnvSource, loadProjectEnv, } from './project-env.js';
3
- vi.mock('node:fs');
4
- const { existsSync, readFileSync } = await import('node:fs');
5
- const mockedExists = vi.mocked(existsSync);
6
- const mockedRead = vi.mocked(readFileSync);
7
- beforeEach(() => {
8
- vi.resetAllMocks();
9
- vi.unstubAllEnvs();
10
- });
11
- describe('project-env', () => {
12
- it('defaults to file env source', () => {
13
- expect(getProjectEnvSource()).toBe('file');
14
- });
15
- it('uses process env source when envFile is disabled', () => {
16
- expect(getProjectEnvSource({ envFile: false })).toBe('process');
17
- });
18
- it('maps env source to options', () => {
19
- expect(getProjectEnvOptions('process')).toEqual({ envFile: false });
20
- expect(getProjectEnvOptions('file')).toEqual({ envFile: true });
21
- expect(getProjectEnvOptions()).toEqual({ envFile: true });
22
- });
23
- it(`loads env content from ${ENV_FILE_NAME} in file mode`, () => {
24
- mockedExists.mockImplementation((path) => path === `/project/${ENV_FILE_NAME}`);
25
- mockedRead.mockReturnValue('AUTH_PROVIDER=better-auth\nDB_PROVIDER=postgres');
26
- expect(loadProjectEnv('/project')).toEqual({
27
- source: 'file',
28
- content: 'AUTH_PROVIDER=better-auth\nDB_PROVIDER=postgres',
29
- filePath: `/project/${ENV_FILE_NAME}`,
30
- fileExists: true,
31
- });
32
- });
33
- it('loads env content from process.env in process mode', () => {
34
- mockedExists.mockReturnValue(false);
35
- vi.stubEnv('AUTH_PROVIDER', 'better-auth');
36
- vi.stubEnv('DB_PROVIDER', 'postgres');
37
- const env = loadProjectEnv('/project', { envFile: false });
38
- expect(env.source).toBe('process');
39
- expect(env.filePath).toBe(`/project/${ENV_FILE_NAME}`);
40
- expect(env.fileExists).toBe(false);
41
- expect(env.content).toContain('AUTH_PROVIDER=better-auth');
42
- expect(env.content).toContain('DB_PROVIDER=postgres');
43
- });
44
- it(`returns ${ENV_FILE_NAME} path helper`, () => {
45
- expect(getProjectEnvFilePath('/project')).toBe(`/project/${ENV_FILE_NAME}`);
46
- });
47
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,123 +0,0 @@
1
- import { describe, it, expect, vi, beforeEach } from 'vitest';
2
- import { findProjectRoot, readJsonFile, projectFileExists, readProjectFile } from './project.js';
3
- vi.mock('node:fs');
4
- const { existsSync, readFileSync } = await import('node:fs');
5
- const mockedExists = vi.mocked(existsSync);
6
- const mockedRead = vi.mocked(readFileSync);
7
- beforeEach(() => {
8
- vi.resetAllMocks();
9
- });
10
- // ---------------------------------------------------------------------------
11
- // findProjectRoot
12
- // ---------------------------------------------------------------------------
13
- describe('findProjectRoot', () => {
14
- it('finds root by package name "codapult"', () => {
15
- mockedExists.mockImplementation((p) => {
16
- return p === '/home/user/projects/codapult/package.json';
17
- });
18
- mockedRead.mockReturnValue(JSON.stringify({ name: 'codapult' }));
19
- const root = findProjectRoot('/home/user/projects/codapult/src/lib');
20
- expect(root).toBe('/home/user/projects/codapult');
21
- });
22
- it('finds root by src/config/app.ts marker', () => {
23
- mockedExists.mockImplementation((p) => {
24
- const path = p;
25
- if (path === '/project/package.json')
26
- return true;
27
- if (path === '/project/src/config/app.ts')
28
- return true;
29
- return false;
30
- });
31
- mockedRead.mockReturnValue(JSON.stringify({ name: 'my-saas' }));
32
- const root = findProjectRoot('/project/src/deep/nested');
33
- expect(root).toBe('/project');
34
- });
35
- it('finds root by codapult.plugins.ts marker', () => {
36
- mockedExists.mockImplementation((p) => {
37
- const path = p;
38
- if (path === '/project/package.json')
39
- return true;
40
- if (path === '/project/codapult.plugins.ts')
41
- return true;
42
- return false;
43
- });
44
- mockedRead.mockReturnValue(JSON.stringify({ name: 'my-saas' }));
45
- const root = findProjectRoot('/project/src');
46
- expect(root).toBe('/project');
47
- });
48
- it('returns null when no project root found', () => {
49
- mockedExists.mockReturnValue(false);
50
- const root = findProjectRoot('/home/user/random');
51
- expect(root).toBeNullable();
52
- });
53
- it('skips directories with invalid JSON in package.json', () => {
54
- let callCount = 0;
55
- mockedExists.mockImplementation((p) => {
56
- const path = p;
57
- if (path === '/a/b/package.json')
58
- return true;
59
- if (path === '/a/package.json')
60
- return true;
61
- return false;
62
- });
63
- mockedRead.mockImplementation((_p) => {
64
- callCount += 1;
65
- if (callCount === 1)
66
- return 'invalid json';
67
- return JSON.stringify({ name: 'codapult' });
68
- });
69
- const root = findProjectRoot('/a/b/c');
70
- expect(root).toBe('/a');
71
- });
72
- });
73
- // ---------------------------------------------------------------------------
74
- // readJsonFile
75
- // ---------------------------------------------------------------------------
76
- describe('readJsonFile', () => {
77
- it('parses valid JSON file', () => {
78
- mockedRead.mockReturnValue('{"key": "value", "num": 42}');
79
- const result = readJsonFile('/some/file.json');
80
- expect(result).toEqual({ key: 'value', num: 42 });
81
- });
82
- it('returns null for invalid JSON', () => {
83
- mockedRead.mockReturnValue('not json');
84
- const result = readJsonFile('/some/file.json');
85
- expect(result).toBeNullable();
86
- });
87
- it('returns null when file does not exist', () => {
88
- mockedRead.mockImplementation(() => {
89
- throw new Error('ENOENT');
90
- });
91
- const result = readJsonFile('/nonexistent.json');
92
- expect(result).toBeNullable();
93
- });
94
- });
95
- // ---------------------------------------------------------------------------
96
- // projectFileExists
97
- // ---------------------------------------------------------------------------
98
- describe('projectFileExists', () => {
99
- it('returns true when file exists', () => {
100
- mockedExists.mockReturnValue(true);
101
- expect(projectFileExists('/project', 'src/lib/db/schema.ts')).toBe(true);
102
- });
103
- it('returns false when file does not exist', () => {
104
- mockedExists.mockReturnValue(false);
105
- expect(projectFileExists('/project', 'nonexistent.ts')).toBe(false);
106
- });
107
- });
108
- // ---------------------------------------------------------------------------
109
- // readProjectFile
110
- // ---------------------------------------------------------------------------
111
- describe('readProjectFile', () => {
112
- it('reads file content when it exists', () => {
113
- mockedExists.mockReturnValue(true);
114
- mockedRead.mockReturnValue('file content here');
115
- const result = readProjectFile('/project', 'src/config.ts');
116
- expect(result).toBe('file content here');
117
- });
118
- it('returns null when file does not exist', () => {
119
- mockedExists.mockReturnValue(false);
120
- const result = readProjectFile('/project', 'missing.ts');
121
- expect(result).toBeNullable();
122
- });
123
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,27 +0,0 @@
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
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,59 +0,0 @@
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
- });