@edgebasejs/cli 0.1.0 → 0.1.2
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/dist/cli/src/generators/__tests__/migration-generator.test.d.ts +2 -0
- package/dist/cli/src/generators/__tests__/migration-generator.test.d.ts.map +1 -0
- package/dist/cli/src/generators/__tests__/migration-generator.test.js +54 -0
- package/dist/cli/src/generators/__tests__/migration-generator.test.js.map +1 -0
- package/dist/index.js +19 -0
- package/package.json +4 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration-generator.test.d.ts","sourceRoot":"","sources":["../../../../../src/generators/__tests__/migration-generator.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// Test migration generator
|
|
2
|
+
import { diffSchemas, generateMigrationSQL, generateMigrationFilename } from '../migration-sql-generator.js';
|
|
3
|
+
describe('Migration Generator', () => {
|
|
4
|
+
describe('diffSchemas', () => {
|
|
5
|
+
it('should detect new entities', () => {
|
|
6
|
+
const oldSchema = { entities: {} };
|
|
7
|
+
const newSchema = {
|
|
8
|
+
entities: {
|
|
9
|
+
todos: {
|
|
10
|
+
fields: {
|
|
11
|
+
id: { type: 'string', required: true, primary: true },
|
|
12
|
+
title: { type: 'string', required: true },
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
const diff = diffSchemas(oldSchema, newSchema);
|
|
18
|
+
expect(Object.keys(diff.newEntities)).toContain('todos');
|
|
19
|
+
expect(Object.keys(diff.modifiedEntities).length).toBe(0);
|
|
20
|
+
expect(Object.keys(diff.deletedEntities).length).toBe(0);
|
|
21
|
+
});
|
|
22
|
+
it('should generate CREATE TABLE SQL', () => {
|
|
23
|
+
const oldSchema = { entities: {} };
|
|
24
|
+
const newSchema = {
|
|
25
|
+
entities: {
|
|
26
|
+
todos: {
|
|
27
|
+
fields: {
|
|
28
|
+
id: { type: 'string', required: true, primary: true },
|
|
29
|
+
title: { type: 'string', required: true },
|
|
30
|
+
completed: { type: 'boolean', required: false, default: false },
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
const diff = diffSchemas(oldSchema, newSchema);
|
|
36
|
+
const { up } = generateMigrationSQL(diff);
|
|
37
|
+
expect(up).toContain('CREATE TABLE todos');
|
|
38
|
+
expect(up).toContain('id TEXT PRIMARY KEY');
|
|
39
|
+
expect(up).toContain('title TEXT NOT NULL');
|
|
40
|
+
expect(up).toContain('completed INTEGER NOT NULL DEFAULT 0');
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
describe('generateMigrationFilename', () => {
|
|
44
|
+
it('should generate proper filename', () => {
|
|
45
|
+
const filename = generateMigrationFilename('add todos table', 1);
|
|
46
|
+
expect(filename).toBe('0001_add_todos_table.sql');
|
|
47
|
+
});
|
|
48
|
+
it('should handle version padding', () => {
|
|
49
|
+
const filename = generateMigrationFilename('update schema', 42);
|
|
50
|
+
expect(filename).toBe('0042_update_schema.sql');
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
//# sourceMappingURL=migration-generator.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration-generator.test.js","sourceRoot":"","sources":["../../../../../src/generators/__tests__/migration-generator.test.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAE3B,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AAG1G,QAAQ,CAAC,qBAAqB,EAAE,GAAG,EAAE;IACnC,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;QAC3B,EAAE,CAAC,4BAA4B,EAAE,GAAG,EAAE;YACpC,MAAM,SAAS,GAAmB,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;YACnD,MAAM,SAAS,GAAmB;gBAChC,QAAQ,EAAE;oBACR,KAAK,EAAE;wBACL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AAM,EAAE,EAAE,EAAE,GAAG,oBAAoB,CAAC,IAAI,CAAC,CAAC;YAE1C,MAAM,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,oBAAoB,CAAC,CAAC;YAC3C,MAAM,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,qBAAqB,CAAC,CAAC;YAC5C,MAAM,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,qBAAqB,CAAC,CAAC;YAC5C,MAAM,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,sCAAsC,CAAC,CAAC;QAC/D,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,2BAA2B,EAAE,GAAG,EAAE;QACzC,EAAE,CAAC,iCAAiC,EAAE,GAAG,EAAE;YACzC,MAAM,QAAQ,GAAG,yBAAyB,CAAC,iBAAiB,EAAE,CAAC,CAAC,CAAC;YACjE,MAAM,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAC;QACpD,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,+BAA+B,EAAE,GAAG,EAAE;YACvC,MAAM,QAAQ,GAAG,yBAAyB,CAAC,eAAe,EAAE,EAAE,CAAC,CAAC;YAChE,MAAM,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC;QAClD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// Wrapper that ensures proper module resolution for workspace packages
|
|
4
|
+
import { fileURLToPath } from 'url';
|
|
5
|
+
import { dirname, join } from 'path';
|
|
6
|
+
|
|
7
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
8
|
+
const __dirname = dirname(__filename);
|
|
9
|
+
const rootDir = join(__dirname, '../../');
|
|
10
|
+
const nodeModulesPath = join(rootDir, 'node_modules');
|
|
11
|
+
|
|
12
|
+
// Add root node_modules to module resolution
|
|
13
|
+
process.env.NODE_PATH = nodeModulesPath + ':' + (process.env.NODE_PATH || '');
|
|
14
|
+
|
|
15
|
+
// Now load the actual CLI
|
|
16
|
+
import('./cli/src/cli.js').catch(err => {
|
|
17
|
+
console.error('Failed to load CLI:', err);
|
|
18
|
+
process.exit(1);
|
|
19
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@edgebasejs/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "EdgeBase CLI for schema generation and migrations",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -11,9 +11,9 @@
|
|
|
11
11
|
"dist"
|
|
12
12
|
],
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"
|
|
15
|
-
"@edgebasejs/
|
|
16
|
-
"
|
|
14
|
+
"@edgebasejs/schema": "^0.1.0",
|
|
15
|
+
"@edgebasejs/types": "^0.1.0",
|
|
16
|
+
"zod": "^3.22.0"
|
|
17
17
|
},
|
|
18
18
|
"publishConfig": {
|
|
19
19
|
"registry": "https://registry.npmjs.org/"
|