@forgebase/cli 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/LICENSE +21 -0
- package/README.md +52 -0
- package/dist/cjs/commands/database.d.ts +3 -0
- package/dist/cjs/commands/database.d.ts.map +1 -0
- package/dist/cjs/commands/database.js +185 -0
- package/dist/cjs/commands/database.js.map +1 -0
- package/dist/cjs/index.d.ts +3 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +13 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/utils/ui.d.ts +3 -0
- package/dist/cjs/utils/ui.d.ts.map +1 -0
- package/dist/cjs/utils/ui.js +34 -0
- package/dist/cjs/utils/ui.js.map +1 -0
- package/dist/esm/commands/database.d.ts +3 -0
- package/dist/esm/commands/database.d.ts.map +1 -0
- package/dist/esm/commands/database.js +146 -0
- package/dist/esm/commands/database.js.map +1 -0
- package/dist/esm/index.d.ts +3 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +11 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/utils/ui.d.ts +3 -0
- package/dist/esm/utils/ui.d.ts.map +1 -0
- package/dist/esm/utils/ui.js +27 -0
- package/dist/esm/utils/ui.js.map +1 -0
- package/dist/tsconfig.cjs.tsbuildinfo +1 -0
- package/dist/tsconfig.esm.tsbuildinfo +1 -0
- package/mock-server.js +39 -0
- package/package.json +49 -0
- package/src/commands/database.ts +204 -0
- package/src/index.ts +14 -0
- package/src/utils/ui.ts +37 -0
- package/test-schema.ts +25 -0
- package/tsconfig.cjs.json +9 -0
- package/tsconfig.esm.json +9 -0
- package/tsconfig.json +19 -0
- package/tsconfig.spec.json +15 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 ForgeBase
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# @forgebase/cli
|
|
2
|
+
|
|
3
|
+
Command Line Interface for ForgeBase.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -g @forgebase/cli
|
|
9
|
+
# or use with npx/pnpx
|
|
10
|
+
npx @forgebase/cli <command>
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Commands
|
|
14
|
+
|
|
15
|
+
### `database`
|
|
16
|
+
|
|
17
|
+
Generate TypeScript schema definitions from your running ForgeBase instance.
|
|
18
|
+
|
|
19
|
+
**Usage:**
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npx @forgebase/cli database --url <schema-endpoint-url> --output <output-file-path>
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
**Options:**
|
|
26
|
+
|
|
27
|
+
- `--url <url>`: The URL to the ForgeBase schema endpoint (e.g., `http://localhost:3000/schema`).
|
|
28
|
+
- `--output <path>`: The path to save the generated TypeScript schema file (e.g., `src/lib/db/schema.ts`).
|
|
29
|
+
|
|
30
|
+
**Example:**
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
# Generate schema.ts from local API
|
|
34
|
+
npx @forgebase/cli database --url http://localhost:3000/schema --output src/lib/db/schema.ts
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Using the Generated Schema
|
|
38
|
+
|
|
39
|
+
Once generated, you can use the schema with the `@forgebase/sdk` client for full type safety:
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
import { DatabaseSDK } from '@forgebase/sdk/client';
|
|
43
|
+
import type { Schema } from './lib/db/schema';
|
|
44
|
+
|
|
45
|
+
const db = new DatabaseSDK<Schema>({
|
|
46
|
+
baseUrl: 'http://localhost:3000',
|
|
47
|
+
// ... config
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
// Fully typed!
|
|
51
|
+
const users = await db.table('users').select('email').query();
|
|
52
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../../../src/commands/database.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAqEpC,eAAO,MAAM,eAAe,SAyHxB,CAAC"}
|
|
@@ -0,0 +1,185 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.databaseCommand = void 0;
|
|
40
|
+
const commander_1 = require("commander");
|
|
41
|
+
const axios_1 = __importDefault(require("axios"));
|
|
42
|
+
const fs = __importStar(require("fs"));
|
|
43
|
+
const path = __importStar(require("path"));
|
|
44
|
+
const prettier = __importStar(require("prettier"));
|
|
45
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
46
|
+
const ora_1 = __importDefault(require("ora"));
|
|
47
|
+
const KyselyTypeMapping = {
|
|
48
|
+
// Number types
|
|
49
|
+
integer: 'number',
|
|
50
|
+
int2: 'number',
|
|
51
|
+
int4: 'number',
|
|
52
|
+
int8: 'number',
|
|
53
|
+
smallint: 'number',
|
|
54
|
+
bigint: 'number',
|
|
55
|
+
real: 'number',
|
|
56
|
+
'double precision': 'number',
|
|
57
|
+
float4: 'number',
|
|
58
|
+
float8: 'number',
|
|
59
|
+
decimal: 'number',
|
|
60
|
+
numeric: 'number',
|
|
61
|
+
serial: 'number',
|
|
62
|
+
bigserial: 'number',
|
|
63
|
+
// String types
|
|
64
|
+
varchar: 'string',
|
|
65
|
+
char: 'string',
|
|
66
|
+
text: 'string',
|
|
67
|
+
uuid: 'string',
|
|
68
|
+
date: 'string',
|
|
69
|
+
time: 'string',
|
|
70
|
+
timetz: 'string',
|
|
71
|
+
timestamp: 'string',
|
|
72
|
+
timestamptz: 'string',
|
|
73
|
+
datetime: 'string',
|
|
74
|
+
blob: 'string',
|
|
75
|
+
varbinary: 'string',
|
|
76
|
+
// Boolean
|
|
77
|
+
boolean: 'boolean',
|
|
78
|
+
// JSON/Any
|
|
79
|
+
json: 'any',
|
|
80
|
+
jsonb: 'any',
|
|
81
|
+
binary: 'any',
|
|
82
|
+
bytea: 'any',
|
|
83
|
+
};
|
|
84
|
+
// Default mapping for unknown types
|
|
85
|
+
const DEFAULT_TYPE = 'any';
|
|
86
|
+
const ui_js_1 = require("../utils/ui.js");
|
|
87
|
+
exports.databaseCommand = new commander_1.Command('database')
|
|
88
|
+
.description('Database management commands')
|
|
89
|
+
.requiredOption('--url <url>', 'URL to the ForgeBase schema endpoint')
|
|
90
|
+
.requiredOption('--output <path>', 'Path to save the generated schema file')
|
|
91
|
+
.option('-y, --yes', 'Skip confirmation prompt')
|
|
92
|
+
.action(async (options) => {
|
|
93
|
+
(0, ui_js_1.showBanner)('Database Schema Generator', 'Generates TypeScript definitions from your running database.');
|
|
94
|
+
const confirmed = await (0, ui_js_1.confirmAction)(`Do you want to generate the schema from ${chalk_1.default.bold(options.url)} to ${chalk_1.default.bold(options.output)}?`, options.yes);
|
|
95
|
+
if (!confirmed) {
|
|
96
|
+
console.log(chalk_1.default.yellow('Operation cancelled.'));
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
const spinner = (0, ora_1.default)('Fetching database schema...').start();
|
|
100
|
+
try {
|
|
101
|
+
// 1. Fetch Schema
|
|
102
|
+
const response = await axios_1.default.get(options.url);
|
|
103
|
+
const schema = response.data;
|
|
104
|
+
if (!schema || typeof schema !== 'object') {
|
|
105
|
+
throw new Error('Invalid schema response from server');
|
|
106
|
+
}
|
|
107
|
+
spinner.text = 'Generating TypeScript definitions...';
|
|
108
|
+
// 2. Generate TypeScript Interfaces
|
|
109
|
+
const lines = [];
|
|
110
|
+
const tableNames = [];
|
|
111
|
+
// Add file header
|
|
112
|
+
lines.push('/**');
|
|
113
|
+
lines.push(' * This file was auto-generated by @forgebase/cli.');
|
|
114
|
+
lines.push(' * Do not modify this file manually.');
|
|
115
|
+
lines.push(' */');
|
|
116
|
+
lines.push('');
|
|
117
|
+
for (const [tableName, tableInfo] of Object.entries(schema)) {
|
|
118
|
+
const interfaceName = toPascalCase(tableName);
|
|
119
|
+
tableNames.push(tableName); // Keep original table name for Schema interface keys
|
|
120
|
+
lines.push(`export interface ${interfaceName} {`);
|
|
121
|
+
for (const col of tableInfo.columns) {
|
|
122
|
+
// Map type
|
|
123
|
+
let tsType = KyselyTypeMapping[col.dataType.toLowerCase()] || DEFAULT_TYPE;
|
|
124
|
+
// Handle nullability
|
|
125
|
+
if (col.isNullable) {
|
|
126
|
+
tsType += ' | null';
|
|
127
|
+
}
|
|
128
|
+
lines.push(` ${col.name}: ${tsType};`);
|
|
129
|
+
}
|
|
130
|
+
lines.push('}');
|
|
131
|
+
lines.push('');
|
|
132
|
+
}
|
|
133
|
+
// 3. Generate Schema Interface
|
|
134
|
+
lines.push('export interface Schema {');
|
|
135
|
+
for (const tableName of tableNames) {
|
|
136
|
+
// Map table name to interface name
|
|
137
|
+
// e.g. "users" -> "users: User" (assuming User interface is generated)
|
|
138
|
+
// But commonly tables are plural, interfaces are singular/pascal.
|
|
139
|
+
// Let's use the generated interface name.
|
|
140
|
+
const interfaceName = toPascalCase(tableName);
|
|
141
|
+
lines.push(` ${tableName}: ${interfaceName};`);
|
|
142
|
+
}
|
|
143
|
+
lines.push('}');
|
|
144
|
+
lines.push('');
|
|
145
|
+
// 4. Format with Prettier
|
|
146
|
+
const rawContent = lines.join('\n');
|
|
147
|
+
const formattedContent = await prettier.format(rawContent, {
|
|
148
|
+
parser: 'typescript',
|
|
149
|
+
singleQuote: true,
|
|
150
|
+
});
|
|
151
|
+
// 5. Write to file
|
|
152
|
+
const outputPath = path.resolve(process.cwd(), options.output);
|
|
153
|
+
const outputDir = path.dirname(outputPath);
|
|
154
|
+
if (!fs.existsSync(outputDir)) {
|
|
155
|
+
fs.mkdirSync(outputDir, { recursive: true });
|
|
156
|
+
}
|
|
157
|
+
fs.writeFileSync(outputPath, formattedContent);
|
|
158
|
+
spinner.succeed(chalk_1.default.green(`Schema generated successfully!`));
|
|
159
|
+
console.log('');
|
|
160
|
+
console.log(chalk_1.default.cyan(' → ') + chalk_1.default.bold('Source: ') + options.url);
|
|
161
|
+
console.log(chalk_1.default.cyan(' → ') + chalk_1.default.bold('Output: ') + outputPath);
|
|
162
|
+
console.log(chalk_1.default.cyan(' → ') + chalk_1.default.bold('Tables: ') + tableNames.length);
|
|
163
|
+
console.log('');
|
|
164
|
+
console.log(chalk_1.default.gray(' You can now use this schema with the SDK:'));
|
|
165
|
+
console.log(chalk_1.default.blue(' const db = new DatabaseSDK<Schema>(...);'));
|
|
166
|
+
console.log('');
|
|
167
|
+
}
|
|
168
|
+
catch (error) {
|
|
169
|
+
spinner.fail(chalk_1.default.red('Failed to generate schema'));
|
|
170
|
+
console.error(chalk_1.default.red(error.message));
|
|
171
|
+
if (axios_1.default.isAxiosError(error)) {
|
|
172
|
+
console.error(chalk_1.default.red(`Status: ${error.response?.status} ${error.response?.statusText}`));
|
|
173
|
+
}
|
|
174
|
+
process.exit(1);
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
function toPascalCase(str) {
|
|
178
|
+
// Handle snake_case, kebab-case, etc.
|
|
179
|
+
// e.g. user_profiles -> UserProfiles
|
|
180
|
+
return (str
|
|
181
|
+
.match(/[a-z0-9]+/gi)
|
|
182
|
+
?.map((word) => word.charAt(0).toUpperCase() + word.substr(1).toLowerCase())
|
|
183
|
+
.join('') || str);
|
|
184
|
+
}
|
|
185
|
+
//# sourceMappingURL=database.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"database.js","sourceRoot":"","sources":["../../../src/commands/database.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAAoC;AACpC,kDAA0B;AAC1B,uCAAyB;AACzB,2CAA6B;AAC7B,mDAAqC;AACrC,kDAA0B;AAC1B,8CAAsB;AAEtB,MAAM,iBAAiB,GAA2B;IAChD,eAAe;IACf,OAAO,EAAE,QAAQ;IACjB,IAAI,EAAE,QAAQ;IACd,IAAI,EAAE,QAAQ;IACd,IAAI,EAAE,QAAQ;IACd,QAAQ,EAAE,QAAQ;IAClB,MAAM,EAAE,QAAQ;IAChB,IAAI,EAAE,QAAQ;IACd,kBAAkB,EAAE,QAAQ;IAC5B,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,QAAQ;IAChB,OAAO,EAAE,QAAQ;IACjB,OAAO,EAAE,QAAQ;IACjB,MAAM,EAAE,QAAQ;IAChB,SAAS,EAAE,QAAQ;IAEnB,eAAe;IACf,OAAO,EAAE,QAAQ;IACjB,IAAI,EAAE,QAAQ;IACd,IAAI,EAAE,QAAQ;IACd,IAAI,EAAE,QAAQ;IACd,IAAI,EAAE,QAAQ;IACd,IAAI,EAAE,QAAQ;IACd,MAAM,EAAE,QAAQ;IA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;AAEL,SAAS,YAAY,CAAC,GAAW;IAC/B,sCAAsC;IACtC,qCAAqC;IACrC,OAAO,CACL,GAAG;SACA,KAAK,CAAC,aAAa,CAAC;QACrB,EAAE,GAAG,CACH,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CACtE;SACA,IAAI,CAAC,EAAE,CAAC,IAAI,GAAG,CACnB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const commander_1 = require("commander");
|
|
5
|
+
const database_js_1 = require("./commands/database.js");
|
|
6
|
+
const program = new commander_1.Command();
|
|
7
|
+
program
|
|
8
|
+
.name('forgebase-cli')
|
|
9
|
+
.description('CLI tool for ForgeBase')
|
|
10
|
+
.version('0.0.1');
|
|
11
|
+
program.addCommand(database_js_1.databaseCommand);
|
|
12
|
+
program.parse();
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AACA,yCAAoC;AACpC,wDAAyD;AAEzD,MAAM,OAAO,GAAG,IAAI,mBAAO,EAAE,CAAC;AAE9B,OAAO;KACJ,IAAI,CAAC,eAAe,CAAC;KACrB,WAAW,CAAC,wBAAwB,CAAC;KACrC,OAAO,CAAC,OAAO,CAAC,CAAC;AAEpB,OAAO,CAAC,UAAU,CAAC,6BAAe,CAAC,CAAC;AAEpC,OAAO,CAAC,KAAK,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ui.d.ts","sourceRoot":"","sources":["../../../src/utils/ui.ts"],"names":[],"mappings":"AAIA,wBAAgB,UAAU,CAAC,WAAW,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,QAYlE;AAED,wBAAsB,aAAa,CACjC,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,OAAO,GACZ,OAAO,CAAC,OAAO,CAAC,CAelB"}
|
|
@@ -0,0 +1,34 @@
|
|
|
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.showBanner = showBanner;
|
|
7
|
+
exports.confirmAction = confirmAction;
|
|
8
|
+
const figlet_1 = __importDefault(require("figlet"));
|
|
9
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
|
10
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
11
|
+
function showBanner(commandName, description) {
|
|
12
|
+
console.log('');
|
|
13
|
+
console.log(chalk_1.default.hex('#FF5733')(figlet_1.default.textSync('ForgeBase CLI', { horizontalLayout: 'full' })));
|
|
14
|
+
console.log('');
|
|
15
|
+
console.log(chalk_1.default.bold.cyan(`Command: ${commandName}`));
|
|
16
|
+
console.log(chalk_1.default.gray(description));
|
|
17
|
+
console.log(chalk_1.default.gray('--------------------------------------------------'));
|
|
18
|
+
console.log('');
|
|
19
|
+
}
|
|
20
|
+
async function confirmAction(message, skip) {
|
|
21
|
+
if (skip) {
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
const { proceed } = await inquirer_1.default.prompt([
|
|
25
|
+
{
|
|
26
|
+
type: 'confirm',
|
|
27
|
+
name: 'proceed',
|
|
28
|
+
message: message,
|
|
29
|
+
default: true,
|
|
30
|
+
},
|
|
31
|
+
]);
|
|
32
|
+
return proceed;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=ui.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ui.js","sourceRoot":"","sources":["../../../src/utils/ui.ts"],"names":[],"mappings":";;;;;AAIA,gCAYC;AAED,sCAkBC;AApCD,oDAA4B;AAC5B,wDAAgC;AAChC,kDAA0B;AAE1B,SAAgB,UAAU,CAAC,WAAmB,EAAE,WAAmB;IACjE,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAChB,OAAO,CAAC,GAAG,CACT,eAAK,CAAC,GAAG,CAAC,SAAS,CAAC,CAClB,gBAAM,CAAC,QAAQ,CAAC,eAAe,EAAE,EAAE,gBAAgB,EAAE,MAAM,EAAE,CAAC,CAC/D,CACF,CAAC;IACF,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAChB,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,WAAW,EAAE,CAAC,CAAC,CAAC;IACxD,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC;IACrC,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,oDAAoD,CAAC,CAAC,CAAC;IAC9E,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;AAClB,CAAC;AAEM,KAAK,UAAU,aAAa,CACjC,OAAe,EACf,IAAa;IAEb,IAAI,IAAI,EAAE,CAAC;QACT,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,kBAAQ,CAAC,MAAM,CAAC;QACxC;YACE,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,SAAS;YACf,OAAO,EAAE,OAAO;YAChB,OAAO,EAAE,IAAI;SACd;KACF,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../../../src/commands/database.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAqEpC,eAAO,MAAM,eAAe,SAyHxB,CAAC"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import axios from 'axios';
|
|
3
|
+
import * as fs from 'fs';
|
|
4
|
+
import * as path from 'path';
|
|
5
|
+
import * as prettier from 'prettier';
|
|
6
|
+
import chalk from 'chalk';
|
|
7
|
+
import ora from 'ora';
|
|
8
|
+
const KyselyTypeMapping = {
|
|
9
|
+
// Number types
|
|
10
|
+
integer: 'number',
|
|
11
|
+
int2: 'number',
|
|
12
|
+
int4: 'number',
|
|
13
|
+
int8: 'number',
|
|
14
|
+
smallint: 'number',
|
|
15
|
+
bigint: 'number',
|
|
16
|
+
real: 'number',
|
|
17
|
+
'double precision': 'number',
|
|
18
|
+
float4: 'number',
|
|
19
|
+
float8: 'number',
|
|
20
|
+
decimal: 'number',
|
|
21
|
+
numeric: 'number',
|
|
22
|
+
serial: 'number',
|
|
23
|
+
bigserial: 'number',
|
|
24
|
+
// String types
|
|
25
|
+
varchar: 'string',
|
|
26
|
+
char: 'string',
|
|
27
|
+
text: 'string',
|
|
28
|
+
uuid: 'string',
|
|
29
|
+
date: 'string',
|
|
30
|
+
time: 'string',
|
|
31
|
+
timetz: 'string',
|
|
32
|
+
timestamp: 'string',
|
|
33
|
+
timestamptz: 'string',
|
|
34
|
+
datetime: 'string',
|
|
35
|
+
blob: 'string',
|
|
36
|
+
varbinary: 'string',
|
|
37
|
+
// Boolean
|
|
38
|
+
boolean: 'boolean',
|
|
39
|
+
// JSON/Any
|
|
40
|
+
json: 'any',
|
|
41
|
+
jsonb: 'any',
|
|
42
|
+
binary: 'any',
|
|
43
|
+
bytea: 'any',
|
|
44
|
+
};
|
|
45
|
+
// Default mapping for unknown types
|
|
46
|
+
const DEFAULT_TYPE = 'any';
|
|
47
|
+
import { showBanner, confirmAction } from '../utils/ui.js';
|
|
48
|
+
export const databaseCommand = new Command('database')
|
|
49
|
+
.description('Database management commands')
|
|
50
|
+
.requiredOption('--url <url>', 'URL to the ForgeBase schema endpoint')
|
|
51
|
+
.requiredOption('--output <path>', 'Path to save the generated schema file')
|
|
52
|
+
.option('-y, --yes', 'Skip confirmation prompt')
|
|
53
|
+
.action(async (options) => {
|
|
54
|
+
showBanner('Database Schema Generator', 'Generates TypeScript definitions from your running database.');
|
|
55
|
+
const confirmed = await confirmAction(`Do you want to generate the schema from ${chalk.bold(options.url)} to ${chalk.bold(options.output)}?`, options.yes);
|
|
56
|
+
if (!confirmed) {
|
|
57
|
+
console.log(chalk.yellow('Operation cancelled.'));
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const spinner = ora('Fetching database schema...').start();
|
|
61
|
+
try {
|
|
62
|
+
// 1. Fetch Schema
|
|
63
|
+
const response = await axios.get(options.url);
|
|
64
|
+
const schema = response.data;
|
|
65
|
+
if (!schema || typeof schema !== 'object') {
|
|
66
|
+
throw new Error('Invalid schema response from server');
|
|
67
|
+
}
|
|
68
|
+
spinner.text = 'Generating TypeScript definitions...';
|
|
69
|
+
// 2. Generate TypeScript Interfaces
|
|
70
|
+
const lines = [];
|
|
71
|
+
const tableNames = [];
|
|
72
|
+
// Add file header
|
|
73
|
+
lines.push('/**');
|
|
74
|
+
lines.push(' * This file was auto-generated by @forgebase/cli.');
|
|
75
|
+
lines.push(' * Do not modify this file manually.');
|
|
76
|
+
lines.push(' */');
|
|
77
|
+
lines.push('');
|
|
78
|
+
for (const [tableName, tableInfo] of Object.entries(schema)) {
|
|
79
|
+
const interfaceName = toPascalCase(tableName);
|
|
80
|
+
tableNames.push(tableName); // Keep original table name for Schema interface keys
|
|
81
|
+
lines.push(`export interface ${interfaceName} {`);
|
|
82
|
+
for (const col of tableInfo.columns) {
|
|
83
|
+
// Map type
|
|
84
|
+
let tsType = KyselyTypeMapping[col.dataType.toLowerCase()] || DEFAULT_TYPE;
|
|
85
|
+
// Handle nullability
|
|
86
|
+
if (col.isNullable) {
|
|
87
|
+
tsType += ' | null';
|
|
88
|
+
}
|
|
89
|
+
lines.push(` ${col.name}: ${tsType};`);
|
|
90
|
+
}
|
|
91
|
+
lines.push('}');
|
|
92
|
+
lines.push('');
|
|
93
|
+
}
|
|
94
|
+
// 3. Generate Schema Interface
|
|
95
|
+
lines.push('export interface Schema {');
|
|
96
|
+
for (const tableName of tableNames) {
|
|
97
|
+
// Map table name to interface name
|
|
98
|
+
// e.g. "users" -> "users: User" (assuming User interface is generated)
|
|
99
|
+
// But commonly tables are plural, interfaces are singular/pascal.
|
|
100
|
+
// Let's use the generated interface name.
|
|
101
|
+
const interfaceName = toPascalCase(tableName);
|
|
102
|
+
lines.push(` ${tableName}: ${interfaceName};`);
|
|
103
|
+
}
|
|
104
|
+
lines.push('}');
|
|
105
|
+
lines.push('');
|
|
106
|
+
// 4. Format with Prettier
|
|
107
|
+
const rawContent = lines.join('\n');
|
|
108
|
+
const formattedContent = await prettier.format(rawContent, {
|
|
109
|
+
parser: 'typescript',
|
|
110
|
+
singleQuote: true,
|
|
111
|
+
});
|
|
112
|
+
// 5. Write to file
|
|
113
|
+
const outputPath = path.resolve(process.cwd(), options.output);
|
|
114
|
+
const outputDir = path.dirname(outputPath);
|
|
115
|
+
if (!fs.existsSync(outputDir)) {
|
|
116
|
+
fs.mkdirSync(outputDir, { recursive: true });
|
|
117
|
+
}
|
|
118
|
+
fs.writeFileSync(outputPath, formattedContent);
|
|
119
|
+
spinner.succeed(chalk.green(`Schema generated successfully!`));
|
|
120
|
+
console.log('');
|
|
121
|
+
console.log(chalk.cyan(' → ') + chalk.bold('Source: ') + options.url);
|
|
122
|
+
console.log(chalk.cyan(' → ') + chalk.bold('Output: ') + outputPath);
|
|
123
|
+
console.log(chalk.cyan(' → ') + chalk.bold('Tables: ') + tableNames.length);
|
|
124
|
+
console.log('');
|
|
125
|
+
console.log(chalk.gray(' You can now use this schema with the SDK:'));
|
|
126
|
+
console.log(chalk.blue(' const db = new DatabaseSDK<Schema>(...);'));
|
|
127
|
+
console.log('');
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
spinner.fail(chalk.red('Failed to generate schema'));
|
|
131
|
+
console.error(chalk.red(error.message));
|
|
132
|
+
if (axios.isAxiosError(error)) {
|
|
133
|
+
console.error(chalk.red(`Status: ${error.response?.status} ${error.response?.statusText}`));
|
|
134
|
+
}
|
|
135
|
+
process.exit(1);
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
function toPascalCase(str) {
|
|
139
|
+
// Handle snake_case, kebab-case, etc.
|
|
140
|
+
// e.g. user_profiles -> UserProfiles
|
|
141
|
+
return (str
|
|
142
|
+
.match(/[a-z0-9]+/gi)
|
|
143
|
+
?.map((word) => word.charAt(0).toUpperCase() + word.substr(1).toLowerCase())
|
|
144
|
+
.join('') || str);
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=database.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"database.js","sourceRoot":"","sources":["../../../src/commands/database.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,QAAQ,MAAM,UAAU,CAAC;AACrC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,GAAG,MAAM,KAAK,CAAC;AAEtB,MAAM,iBAAiB,GAA2B;IAChD,eAAe;IACf,OAAO,EAAE,QAAQ;IACjB,IAAI,EAAE,QAAQ;IACd,IAAI,EAAE,QAAQ;IACd,IAAI,EAAE,QAAQ;IACd,QAAQ,EAAE,QAAQ;IAClB,MAAM,EAAE,QAAQ;IAChB,IAAI,EAAE,QAAQ;IACd,kBAAk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ACrD,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;QACxC,IAAI,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,EAAE,CAAC;YAC9B,OAAO,CAAC,KAAK,CACX,KAAK,CAAC,GAAG,CACP,WAAW,KAAK,CAAC,QAAQ,EAAE,MAAM,IAAI,KAAK,CAAC,QAAQ,EAAE,UAAU,EAAE,CAClE,CACF,CAAC;QACJ,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC,CAAC,CAAC;AAEL,SAAS,YAAY,CAAC,GAAW;IAC/B,sCAAsC;IACtC,qCAAqC;IACrC,OAAO,CACL,GAAG;SACA,KAAK,CAAC,aAAa,CAAC;QACrB,EAAE,GAAG,CACH,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CACtE;SACA,IAAI,CAAC,EAAE,CAAC,IAAI,GAAG,CACnB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Command } from 'commander';
|
|
3
|
+
import { databaseCommand } from './commands/database.js';
|
|
4
|
+
const program = new Command();
|
|
5
|
+
program
|
|
6
|
+
.name('forgebase-cli')
|
|
7
|
+
.description('CLI tool for ForgeBase')
|
|
8
|
+
.version('0.0.1');
|
|
9
|
+
program.addCommand(databaseCommand);
|
|
10
|
+
program.parse();
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;AAE9B,OAAO;KACJ,IAAI,CAAC,eAAe,CAAC;KACrB,WAAW,CAAC,wBAAwB,CAAC;KACrC,OAAO,CAAC,OAAO,CAAC,CAAC;AAEpB,OAAO,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC;AAEpC,OAAO,CAAC,KAAK,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ui.d.ts","sourceRoot":"","sources":["../../../src/utils/ui.ts"],"names":[],"mappings":"AAIA,wBAAgB,UAAU,CAAC,WAAW,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,QAYlE;AAED,wBAAsB,aAAa,CACjC,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,OAAO,GACZ,OAAO,CAAC,OAAO,CAAC,CAelB"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import figlet from 'figlet';
|
|
2
|
+
import inquirer from 'inquirer';
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
export function showBanner(commandName, description) {
|
|
5
|
+
console.log('');
|
|
6
|
+
console.log(chalk.hex('#FF5733')(figlet.textSync('ForgeBase CLI', { horizontalLayout: 'full' })));
|
|
7
|
+
console.log('');
|
|
8
|
+
console.log(chalk.bold.cyan(`Command: ${commandName}`));
|
|
9
|
+
console.log(chalk.gray(description));
|
|
10
|
+
console.log(chalk.gray('--------------------------------------------------'));
|
|
11
|
+
console.log('');
|
|
12
|
+
}
|
|
13
|
+
export async function confirmAction(message, skip) {
|
|
14
|
+
if (skip) {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
const { proceed } = await inquirer.prompt([
|
|
18
|
+
{
|
|
19
|
+
type: 'confirm',
|
|
20
|
+
name: 'proceed',
|
|
21
|
+
message: message,
|
|
22
|
+
default: true,
|
|
23
|
+
},
|
|
24
|
+
]);
|
|
25
|
+
return proceed;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=ui.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ui.js","sourceRoot":"","sources":["../../../src/utils/ui.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,MAAM,UAAU,UAAU,CAAC,WAAmB,EAAE,WAAmB;IACjE,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAChB,OAAO,CAAC,GAAG,CACT,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,CAClB,MAAM,CAAC,QAAQ,CAAC,eAAe,EAAE,EAAE,gBAAgB,EAAE,MAAM,EAAE,CAAC,CAC/D,CACF,CAAC;IACF,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAChB,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,WAAW,EAAE,CAAC,CAAC,CAAC;IACxD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC;IACrC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,oDAAoD,CAAC,CAAC,CAAC;IAC9E,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;AAClB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,OAAe,EACf,IAAa;IAEb,IAAI,IAAI,EAAE,CAAC;QACT,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,QAAQ,CAAC,MAAM,CAAC;QACxC;YACE,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,SAAS;YACf,OAAO,E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