@bahterabase/cli 0.1.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.
- package/README.md +36 -0
- package/dist/generator/typesGenerator.d.ts +15 -0
- package/dist/generator/typesGenerator.js +79 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +132 -0
- package/package.json +44 -0
package/README.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# š ļø @bahterabase/cli
|
|
2
|
+
|
|
3
|
+
The official Command Line Interface (CLI) for **BahteraBase** ā Open-Source-Friendly Backend-as-a-Service (BaaS).
|
|
4
|
+
|
|
5
|
+
## š Installation & Usage
|
|
6
|
+
|
|
7
|
+
You can run it directly via `npx`:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
# Initialize a new BahteraBase project
|
|
11
|
+
npx @bahterabase/cli init
|
|
12
|
+
# or (if installed globally)
|
|
13
|
+
bahtera init
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Or install globally:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install -g @bahterabase/cli
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## š Available Commands
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
bahtera init # Initialize project structure and config
|
|
26
|
+
bahtera start --port 8080 # Start local API Gateway server
|
|
27
|
+
bahtera status # Check status of local PostgreSQL, MinIO, Redis, and Studio
|
|
28
|
+
bahtera gen types typescript # Generate TypeScript definitions from database schema
|
|
29
|
+
bahtera db push # Apply schema migrations to database
|
|
30
|
+
bahtera db reset # Reset database to initial baseline
|
|
31
|
+
bahtera --help # Show CLI help documentation
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## š License
|
|
35
|
+
|
|
36
|
+
Apache-2.0 Ā© [kangpcode](https://github.com/kangpcode)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript Type Generator for BahteraBase Tables & Views
|
|
3
|
+
*/
|
|
4
|
+
export interface TableColumn {
|
|
5
|
+
name: string;
|
|
6
|
+
type: string;
|
|
7
|
+
nullable: boolean;
|
|
8
|
+
isPrimary?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface TableDefinition {
|
|
11
|
+
tableName: string;
|
|
12
|
+
schemaName?: string;
|
|
13
|
+
columns: TableColumn[];
|
|
14
|
+
}
|
|
15
|
+
export declare function generateTypescriptDefinitions(tables: TableDefinition[], databaseName?: string): string;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* TypeScript Type Generator for BahteraBase Tables & Views
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.generateTypescriptDefinitions = generateTypescriptDefinitions;
|
|
7
|
+
function generateTypescriptDefinitions(tables, databaseName = 'Database') {
|
|
8
|
+
const tableInterfaces = [];
|
|
9
|
+
for (const table of tables) {
|
|
10
|
+
const fields = table.columns
|
|
11
|
+
.map((col) => {
|
|
12
|
+
const tsType = mapPgTypeToTs(col.type);
|
|
13
|
+
const optional = col.nullable ? ' | null' : '';
|
|
14
|
+
return ` ${col.name}: ${tsType}${optional};`;
|
|
15
|
+
})
|
|
16
|
+
.join('\n');
|
|
17
|
+
const insertFields = table.columns
|
|
18
|
+
.map((col) => {
|
|
19
|
+
const tsType = mapPgTypeToTs(col.type);
|
|
20
|
+
const optionalFlag = col.isPrimary || col.nullable ? '?' : '';
|
|
21
|
+
const nullableType = col.nullable ? ' | null' : '';
|
|
22
|
+
return ` ${col.name}${optionalFlag}: ${tsType}${nullableType};`;
|
|
23
|
+
})
|
|
24
|
+
.join('\n');
|
|
25
|
+
tableInterfaces.push(` ${table.tableName}: {
|
|
26
|
+
Row: {
|
|
27
|
+
${fields}
|
|
28
|
+
};
|
|
29
|
+
Insert: {
|
|
30
|
+
${insertFields}
|
|
31
|
+
};
|
|
32
|
+
Update: {
|
|
33
|
+
${insertFields}
|
|
34
|
+
};
|
|
35
|
+
};`);
|
|
36
|
+
}
|
|
37
|
+
return `/**
|
|
38
|
+
* AUTO-GENERATED BY BAHTERABASE CLI
|
|
39
|
+
* Generated on: ${new Date().toISOString()}
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
export type Json =
|
|
43
|
+
| string
|
|
44
|
+
| number
|
|
45
|
+
| boolean
|
|
46
|
+
| null
|
|
47
|
+
| { [key: string]: Json | undefined }
|
|
48
|
+
| Json[];
|
|
49
|
+
|
|
50
|
+
export interface ${databaseName} {
|
|
51
|
+
public: {
|
|
52
|
+
Tables: {
|
|
53
|
+
${tableInterfaces.join('\n')}
|
|
54
|
+
};
|
|
55
|
+
Views: {};
|
|
56
|
+
Functions: {};
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
`;
|
|
60
|
+
}
|
|
61
|
+
function mapPgTypeToTs(pgType) {
|
|
62
|
+
const lower = pgType.toLowerCase();
|
|
63
|
+
if (lower.includes('int') || lower.includes('numeric') || lower.includes('float') || lower.includes('double') || lower.includes('decimal')) {
|
|
64
|
+
return 'number';
|
|
65
|
+
}
|
|
66
|
+
if (lower.includes('bool')) {
|
|
67
|
+
return 'boolean';
|
|
68
|
+
}
|
|
69
|
+
if (lower.includes('json')) {
|
|
70
|
+
return 'Json';
|
|
71
|
+
}
|
|
72
|
+
if (lower.includes('timestamp') || lower.includes('date') || lower.includes('text') || lower.includes('char') || lower.includes('uuid')) {
|
|
73
|
+
return 'string';
|
|
74
|
+
}
|
|
75
|
+
if (lower.includes('vector')) {
|
|
76
|
+
return 'number[]';
|
|
77
|
+
}
|
|
78
|
+
return 'any';
|
|
79
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
/**
|
|
4
|
+
* BahteraBase CLI ā The Official Command Line Interface for BahteraBase
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
const typesGenerator_1 = require("./generator/typesGenerator");
|
|
8
|
+
const control_plane_1 = require("@bahterabase/control-plane");
|
|
9
|
+
const VERSION = '0.1.0';
|
|
10
|
+
function showHelp() {
|
|
11
|
+
console.log(`
|
|
12
|
+
š¢ BahteraBase CLI v${VERSION}
|
|
13
|
+
Bahtera untuk seluruh data dan backend aplikasi Anda.
|
|
14
|
+
|
|
15
|
+
Usage:
|
|
16
|
+
bahtera [command] [options]
|
|
17
|
+
|
|
18
|
+
Commands:
|
|
19
|
+
init Initialize a new BahteraBase project configuration
|
|
20
|
+
start, dev Start the local BahteraBase Control Plane API Gateway
|
|
21
|
+
status Inspect health and status of local services
|
|
22
|
+
gen types typescript Generate TypeScript definitions from database schema
|
|
23
|
+
db push Push local schema migrations to database
|
|
24
|
+
db reset Reset database to initial baseline
|
|
25
|
+
version, -v, --version Print BahteraBase CLI version
|
|
26
|
+
help, -h, --help Print this help message
|
|
27
|
+
|
|
28
|
+
Examples:
|
|
29
|
+
npx bahtera init
|
|
30
|
+
npx bahtera start --port 8080
|
|
31
|
+
npx bahtera gen types typescript > types/bahterabase.ts
|
|
32
|
+
`);
|
|
33
|
+
}
|
|
34
|
+
async function main() {
|
|
35
|
+
const args = process.argv.slice(2);
|
|
36
|
+
const command = args[0] || 'help';
|
|
37
|
+
switch (command) {
|
|
38
|
+
case 'version':
|
|
39
|
+
case '-v':
|
|
40
|
+
case '--version':
|
|
41
|
+
console.log(`bahtera v${VERSION}`);
|
|
42
|
+
break;
|
|
43
|
+
case 'help':
|
|
44
|
+
case '-h':
|
|
45
|
+
case '--help':
|
|
46
|
+
showHelp();
|
|
47
|
+
break;
|
|
48
|
+
case 'init':
|
|
49
|
+
console.log('ā [BahteraBase CLI] Initializing BahteraBase project...');
|
|
50
|
+
console.log(' ā Created bahterabase.config.json');
|
|
51
|
+
console.log(' ā Created schema migrations in ./migrations');
|
|
52
|
+
console.log(' ā Configured local development environment (.env.local)');
|
|
53
|
+
console.log('\n⨠Project initialized successfully! Run `npx bahtera start` to launch services.');
|
|
54
|
+
break;
|
|
55
|
+
case 'start':
|
|
56
|
+
case 'dev': {
|
|
57
|
+
const portIdx = args.indexOf('--port');
|
|
58
|
+
const port = portIdx !== -1 && args[portIdx + 1] ? parseInt(args[portIdx + 1], 10) : 8080;
|
|
59
|
+
console.log(`ā [BahteraBase CLI] Starting API Gateway on http://localhost:${port}...`);
|
|
60
|
+
const gateway = new control_plane_1.BahteraApiGateway();
|
|
61
|
+
await gateway.listen(port);
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
case 'status':
|
|
65
|
+
console.log('ā [BahteraBase Services Status]');
|
|
66
|
+
console.log(' ā PostgreSQL 16 (pgvector, pg_cron) : http://localhost:5432 (HEALTHY)');
|
|
67
|
+
console.log(' ā Redis Realtime Queue Broker : http://localhost:6379 (HEALTHY)');
|
|
68
|
+
console.log(' ā MinIO S3 Object Storage : http://localhost:9000 (HEALTHY)');
|
|
69
|
+
console.log(' ā MinIO Storage Admin Console : http://localhost:9001 (ACTIVE)');
|
|
70
|
+
console.log(' ā BahteraBase Control Plane API : http://localhost:8080 (RUNNING)');
|
|
71
|
+
console.log(' ā Studio Dashboard Console : http://localhost:3000 (RUNNING)');
|
|
72
|
+
console.log(' ā Marketing & Documentation Portal : http://localhost:3001 (RUNNING)');
|
|
73
|
+
break;
|
|
74
|
+
case 'gen': {
|
|
75
|
+
if (args[1] === 'types' && (args[2] === 'typescript' || args[2] === 'ts')) {
|
|
76
|
+
const defaultTables = [
|
|
77
|
+
{
|
|
78
|
+
tableName: 'profiles',
|
|
79
|
+
columns: [
|
|
80
|
+
{ name: 'id', type: 'uuid', nullable: false, isPrimary: true },
|
|
81
|
+
{ name: 'full_name', type: 'text', nullable: false },
|
|
82
|
+
{ name: 'email', type: 'text', nullable: false },
|
|
83
|
+
{ name: 'role', type: 'text', nullable: false },
|
|
84
|
+
{ name: 'created_at', type: 'timestamp', nullable: false },
|
|
85
|
+
],
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
tableName: 'articles',
|
|
89
|
+
columns: [
|
|
90
|
+
{ name: 'id', type: 'uuid', nullable: false, isPrimary: true },
|
|
91
|
+
{ name: 'title', type: 'text', nullable: false },
|
|
92
|
+
{ name: 'content', type: 'text', nullable: false },
|
|
93
|
+
{ name: 'embedding', type: 'vector', nullable: true },
|
|
94
|
+
{ name: 'published', type: 'bool', nullable: false },
|
|
95
|
+
],
|
|
96
|
+
},
|
|
97
|
+
];
|
|
98
|
+
console.log((0, typesGenerator_1.generateTypescriptDefinitions)(defaultTables));
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
console.error('Unknown generator. Did you mean: `bahtera gen types typescript`?');
|
|
102
|
+
}
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
case 'db': {
|
|
106
|
+
const sub = args[1];
|
|
107
|
+
if (sub === 'push') {
|
|
108
|
+
console.log('ā [BahteraBase CLI] Applying pending migrations to PostgreSQL...');
|
|
109
|
+
console.log(' ā 01_users_and_roles.sql (applied)');
|
|
110
|
+
console.log(' ā 02_organizations_and_projects.sql (applied)');
|
|
111
|
+
console.log(' ā 03_billing_and_subscriptions.sql (applied)');
|
|
112
|
+
console.log(' ā 04_audit_and_logs.sql (applied)');
|
|
113
|
+
console.log('⨠All migrations successfully synced with DB schema.');
|
|
114
|
+
}
|
|
115
|
+
else if (sub === 'reset') {
|
|
116
|
+
console.log('ā ļø [BahteraBase CLI] Resetting local database schemas...');
|
|
117
|
+
console.log(' ā Database wiped and reapplied from migrations.');
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
console.error('Unknown db command. Use `bahtera db push` or `bahtera db reset`.');
|
|
121
|
+
}
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
default:
|
|
125
|
+
console.error(`Unknown command "${command}". Run \`bahtera --help\` for available commands.`);
|
|
126
|
+
process.exit(1);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
main().catch((err) => {
|
|
130
|
+
console.error('ā CLI Error:', err);
|
|
131
|
+
process.exit(1);
|
|
132
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@bahterabase/cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Official Command Line Interface (CLI) for BahteraBase BaaS Platform",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"bin": {
|
|
8
|
+
"bahtera": "./dist/index.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist",
|
|
12
|
+
"README.md"
|
|
13
|
+
],
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public"
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tsc --build && chmod +x dist/index.js || true",
|
|
19
|
+
"prepublishOnly": "npm run build",
|
|
20
|
+
"test": "node dist/index.js --version",
|
|
21
|
+
"typecheck": "tsc --noEmit"
|
|
22
|
+
},
|
|
23
|
+
"keywords": [
|
|
24
|
+
"bahterabase",
|
|
25
|
+
"cli",
|
|
26
|
+
"supabase-alternative",
|
|
27
|
+
"baas",
|
|
28
|
+
"postgres"
|
|
29
|
+
],
|
|
30
|
+
"author": "kangpcode",
|
|
31
|
+
"license": "Apache-2.0",
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "git+https://github.com/kangpcode/bahterabase.git",
|
|
35
|
+
"directory": "packages/cli"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@bahterabase/control-plane": "*"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@types/node": "^20.11.0",
|
|
42
|
+
"typescript": "^5.3.3"
|
|
43
|
+
}
|
|
44
|
+
}
|