@onurege3467/zerohelper 10.2.6 → 11.0.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 +9 -704
- package/dist/index.js +19 -44
- package/package.json +21 -70
- package/dist/bin/commands/cache.d.ts +0 -2
- package/dist/bin/commands/cache.js +0 -92
- package/dist/bin/commands/db-backup.d.ts +0 -3
- package/dist/bin/commands/db-backup.js +0 -118
- package/dist/bin/commands/db.d.ts +0 -2
- package/dist/bin/commands/db.js +0 -334
- package/dist/bin/commands/import-export.d.ts +0 -3
- package/dist/bin/commands/import-export.js +0 -123
- package/dist/bin/commands/init.d.ts +0 -2
- package/dist/bin/commands/init.js +0 -85
- package/dist/bin/commands/migrate.d.ts +0 -3
- package/dist/bin/commands/migrate.js +0 -167
- package/dist/bin/commands/repl.d.ts +0 -2
- package/dist/bin/commands/repl.js +0 -96
- package/dist/bin/commands/seed.d.ts +0 -2
- package/dist/bin/commands/seed.js +0 -76
- package/dist/bin/commands/zpack.d.ts +0 -2
- package/dist/bin/commands/zpack.js +0 -36
- package/dist/bin/index.d.ts +0 -2
- package/dist/bin/index.js +0 -28
- package/dist/bin/types.d.ts +0 -22
- package/dist/bin/types.js +0 -2
- package/dist/bin/utils/config.d.ts +0 -3
- package/dist/bin/utils/config.js +0 -78
- package/dist/bin/utils/prompts.d.ts +0 -3
- package/dist/bin/utils/prompts.js +0 -115
- package/dist/bin/zero.d.ts +0 -2
- package/dist/bin/zero.js +0 -849
- package/dist/database/IDatabase.d.ts +0 -71
- package/dist/database/IDatabase.js +0 -48
- package/dist/database/cacheWrapper.d.ts +0 -34
- package/dist/database/cacheWrapper.js +0 -214
- package/dist/database/index.d.ts +0 -12
- package/dist/database/index.js +0 -100
- package/dist/database/json.d.ts +0 -32
- package/dist/database/json.js +0 -208
- package/dist/database/migration.d.ts +0 -21
- package/dist/database/migration.js +0 -97
- package/dist/database/mongodb.d.ts +0 -26
- package/dist/database/mongodb.js +0 -145
- package/dist/database/mysql.d.ts +0 -29
- package/dist/database/mysql.js +0 -282
- package/dist/database/pg.d.ts +0 -28
- package/dist/database/pg.js +0 -200
- package/dist/database/redis.d.ts +0 -31
- package/dist/database/redis.js +0 -176
- package/dist/database/seeder.d.ts +0 -20
- package/dist/database/seeder.js +0 -37
- package/dist/database/sqlite.d.ts +0 -26
- package/dist/database/sqlite.js +0 -211
- package/dist/database/telemetry.d.ts +0 -35
- package/dist/database/telemetry.js +0 -41
- package/dist/database/toon.d.ts +0 -33
- package/dist/database/toon.js +0 -244
- package/dist/database/types.d.ts +0 -71
- package/dist/database/types.js +0 -2
- package/dist/database/zpack.d.ts +0 -75
- package/dist/database/zpack.js +0 -616
- package/dist/functions/index.d.ts +0 -199
- package/dist/functions/index.js +0 -682
- package/dist/functions/security.d.ts +0 -15
- package/dist/functions/security.js +0 -46
- package/dist/functions/toon.d.ts +0 -10
- package/dist/functions/toon.js +0 -214
- package/dist/functions/worker.d.ts +0 -5
- package/dist/functions/worker.js +0 -35
- package/dist/index.d.ts +0 -8
- package/dist/migrations/1767521950635_test_migration.d.ts +0 -3
- package/dist/migrations/1767521950635_test_migration.js +0 -11
- package/dist/migrations/1767522158826_create_users_table.d.ts +0 -2
- package/dist/migrations/1767522158826_create_users_table.js +0 -11
- package/dist/package.json +0 -79
- package/dist/tests/test.d.ts +0 -1
- package/dist/tests/test.js +0 -26
- package/dist/zero.config.d.ts +0 -10
- package/dist/zero.config.js +0 -13
|
@@ -1,167 +0,0 @@
|
|
|
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.makeMigrationCommand = exports.migrateCommand = void 0;
|
|
40
|
-
const commander_1 = require("commander");
|
|
41
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
42
|
-
const ora_1 = __importDefault(require("ora"));
|
|
43
|
-
const fs_1 = __importDefault(require("fs"));
|
|
44
|
-
const path_1 = __importDefault(require("path"));
|
|
45
|
-
const database = __importStar(require("../../database"));
|
|
46
|
-
const config_1 = require("../utils/config");
|
|
47
|
-
const prompts_1 = require("../utils/prompts");
|
|
48
|
-
exports.migrateCommand = new commander_1.Command().name('migration');
|
|
49
|
-
exports.migrateCommand
|
|
50
|
-
.command('migrate')
|
|
51
|
-
.description('Run pending migrations')
|
|
52
|
-
.option('-c, --config <path>', 'Path to config file', 'zero.config.ts')
|
|
53
|
-
.option('-d, --migrations-dir <path>', 'Migrations directory path', './migrations')
|
|
54
|
-
.action(async (options) => {
|
|
55
|
-
const spinner = (0, ora_1.default)('Loading migrations...').start();
|
|
56
|
-
try {
|
|
57
|
-
const db = await (0, config_1.getDatabase)(options.config);
|
|
58
|
-
const migration = new database.MigrationManager(db, {
|
|
59
|
-
migrationsDir: options.migrationsDir
|
|
60
|
-
});
|
|
61
|
-
const pending = await migration.getPendingMigrations();
|
|
62
|
-
if (pending.length === 0) {
|
|
63
|
-
spinner.succeed(chalk_1.default.green('✅ No pending migrations'));
|
|
64
|
-
await db.close();
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
spinner.text = `Running ${pending.length} migration(s)...`;
|
|
68
|
-
for (const m of pending) {
|
|
69
|
-
await migration.runMigration(m, 'up');
|
|
70
|
-
spinner.text = `✅ ${m.name}`;
|
|
71
|
-
}
|
|
72
|
-
spinner.succeed(chalk_1.default.green(`✅ ${pending.length} migration(s) executed successfully`));
|
|
73
|
-
await db.close();
|
|
74
|
-
}
|
|
75
|
-
catch (error) {
|
|
76
|
-
spinner.fail(chalk_1.default.red('❌ Migration failed'));
|
|
77
|
-
console.error(chalk_1.default.red(error.message));
|
|
78
|
-
process.exit(1);
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
exports.migrateCommand
|
|
82
|
-
.command('rollback')
|
|
83
|
-
.description('Rollback the last migration(s)')
|
|
84
|
-
.option('-c, --config <path>', 'Path to config file', 'zero.config.ts')
|
|
85
|
-
.option('-d, --migrations-dir <path>', 'Migrations directory path', './migrations')
|
|
86
|
-
.option('-s, --steps <number>', 'Number of migrations to rollback', '1')
|
|
87
|
-
.action(async (options) => {
|
|
88
|
-
const steps = parseInt(options.steps);
|
|
89
|
-
const confirmed = await (0, prompts_1.confirmAction)(chalk_1.default.yellow(`⚠️ Are you sure you want to rollback ${steps} migration(s)?`));
|
|
90
|
-
if (!confirmed) {
|
|
91
|
-
console.log(chalk_1.default.yellow('Rollback cancelled'));
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
const spinner = (0, ora_1.default)(`Rolling back ${steps} migration(s)...`).start();
|
|
95
|
-
try {
|
|
96
|
-
const db = await (0, config_1.getDatabase)(options.config);
|
|
97
|
-
const migration = new database.MigrationManager(db, {
|
|
98
|
-
migrationsDir: options.migrationsDir
|
|
99
|
-
});
|
|
100
|
-
await migration.rollback(steps);
|
|
101
|
-
spinner.succeed(chalk_1.default.green(`✅ Rolled back ${steps} migration(s)`));
|
|
102
|
-
await db.close();
|
|
103
|
-
}
|
|
104
|
-
catch (error) {
|
|
105
|
-
spinner.fail(chalk_1.default.red('❌ Rollback failed'));
|
|
106
|
-
console.error(chalk_1.default.red(error.message));
|
|
107
|
-
process.exit(1);
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
exports.migrateCommand
|
|
111
|
-
.command('status')
|
|
112
|
-
.description('Show migration status')
|
|
113
|
-
.option('-c, --config <path>', 'Path to config file', 'zero.config.ts')
|
|
114
|
-
.option('-d, --migrations-dir <path>', 'Migrations directory path', './migrations')
|
|
115
|
-
.action(async (options) => {
|
|
116
|
-
try {
|
|
117
|
-
const db = await (0, config_1.getDatabase)(options.config);
|
|
118
|
-
const migration = new database.MigrationManager(db, {
|
|
119
|
-
migrationsDir: options.migrationsDir
|
|
120
|
-
});
|
|
121
|
-
const all = migration.getMigrationFiles();
|
|
122
|
-
const executed = await migration.getExecutedMigrations();
|
|
123
|
-
console.log(chalk_1.default.bold('\n📋 Migration Status'));
|
|
124
|
-
console.log(chalk_1.default.gray('─'.repeat(50)));
|
|
125
|
-
if (all.length === 0) {
|
|
126
|
-
console.log(chalk_1.default.yellow('No migrations found'));
|
|
127
|
-
}
|
|
128
|
-
else {
|
|
129
|
-
all.forEach(m => {
|
|
130
|
-
const isExecuted = executed.includes(m.name);
|
|
131
|
-
const status = isExecuted ? chalk_1.default.green('✅ Done') : chalk_1.default.yellow('⏳ Pending');
|
|
132
|
-
console.log(` ${status} ${chalk_1.default.white(m.name)}`);
|
|
133
|
-
});
|
|
134
|
-
console.log(chalk_1.default.gray('\n' + '─'.repeat(50)));
|
|
135
|
-
console.log(` Total: ${all.length} | Executed: ${chalk_1.default.green(executed.length)} | Pending: ${chalk_1.default.yellow(all.length - executed.length)}`);
|
|
136
|
-
}
|
|
137
|
-
await db.close();
|
|
138
|
-
}
|
|
139
|
-
catch (error) {
|
|
140
|
-
console.error(chalk_1.default.red(`Error: ${error.message}`));
|
|
141
|
-
process.exit(1);
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
exports.makeMigrationCommand = new commander_1.Command().name('make');
|
|
145
|
-
exports.makeMigrationCommand
|
|
146
|
-
.command('migration')
|
|
147
|
-
.description('Generate a new migration template')
|
|
148
|
-
.argument('<name>', 'Name of the migration')
|
|
149
|
-
.option('-d, --migrations-dir <path>', 'Migrations directory path', './migrations')
|
|
150
|
-
.action((name, options) => {
|
|
151
|
-
const timestamp = Date.now();
|
|
152
|
-
const fileName = `${timestamp}_${name}.ts`;
|
|
153
|
-
const migrationsDir = path_1.default.join(process.cwd(), options.migrationsDir);
|
|
154
|
-
if (!fs_1.default.existsSync(migrationsDir)) {
|
|
155
|
-
fs_1.default.mkdirSync(migrationsDir, { recursive: true });
|
|
156
|
-
}
|
|
157
|
-
const template = `export const up = async (db: any) => {
|
|
158
|
-
// Write your migration logic here
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
export const down = async (db: any) => {
|
|
162
|
-
// Write your rollback logic here
|
|
163
|
-
};
|
|
164
|
-
`;
|
|
165
|
-
fs_1.default.writeFileSync(path_1.default.join(migrationsDir, fileName), template);
|
|
166
|
-
console.log(chalk_1.default.green(`\n✅ Migration created: ./${options.migrationsDir}/${fileName}`));
|
|
167
|
-
});
|
|
@@ -1,96 +0,0 @@
|
|
|
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.replCommand = void 0;
|
|
7
|
-
const commander_1 = require("commander");
|
|
8
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
9
|
-
const config_1 = require("../utils/config");
|
|
10
|
-
exports.replCommand = new commander_1.Command().name('repl');
|
|
11
|
-
exports.replCommand
|
|
12
|
-
.description('Interactive ZeroHelper REPL mode')
|
|
13
|
-
.option('-c, --config <path>', 'Path to config file', 'zero.config.ts')
|
|
14
|
-
.action(async (options) => {
|
|
15
|
-
console.log(chalk_1.default.bold.cyan('\n🔧 ZeroHelper REPL Mode\n'));
|
|
16
|
-
console.log(chalk_1.default.gray('Type .exit to quit, .help for commands\n'));
|
|
17
|
-
try {
|
|
18
|
-
const db = await (0, config_1.getDatabase)(options.config);
|
|
19
|
-
const readline = require('readline');
|
|
20
|
-
const rl = readline.createInterface({
|
|
21
|
-
input: process.stdin,
|
|
22
|
-
output: process.stdout,
|
|
23
|
-
prompt: chalk_1.default.blue('zero> ')
|
|
24
|
-
});
|
|
25
|
-
rl.prompt();
|
|
26
|
-
rl.on('line', async (line) => {
|
|
27
|
-
const cmd = line.trim();
|
|
28
|
-
if (cmd === '.exit') {
|
|
29
|
-
await db.close();
|
|
30
|
-
rl.close();
|
|
31
|
-
console.log(chalk_1.default.green('\n👋 Goodbye!\n'));
|
|
32
|
-
process.exit(0);
|
|
33
|
-
}
|
|
34
|
-
else if (cmd === '.help') {
|
|
35
|
-
console.log(chalk_1.default.bold('\nAvailable REPL Commands:'));
|
|
36
|
-
console.log(' .exit Exit REPL');
|
|
37
|
-
console.log(' .help Show this help');
|
|
38
|
-
console.log(' .stats Show database stats');
|
|
39
|
-
console.log(' .metrics Show performance metrics');
|
|
40
|
-
console.log(' select <table> Select all from table');
|
|
41
|
-
console.log(' count <table> Count records in table');
|
|
42
|
-
console.log(' clear Clear screen\n');
|
|
43
|
-
}
|
|
44
|
-
else if (cmd === '.stats') {
|
|
45
|
-
const metrics = db.getMetrics();
|
|
46
|
-
console.log(chalk_1.default.bold('\n📊 Database Stats:'));
|
|
47
|
-
console.log(` Operations: ${metrics.database.count || 0}`);
|
|
48
|
-
console.log(` Avg Latency: ${(metrics.database.averageDuration || 0).toFixed(2)}ms\n`);
|
|
49
|
-
}
|
|
50
|
-
else if (cmd === '.metrics') {
|
|
51
|
-
const metrics = db.getMetrics();
|
|
52
|
-
console.log(chalk_1.default.bold('\n📊 Full Metrics:'));
|
|
53
|
-
console.log(JSON.stringify(metrics, null, 2));
|
|
54
|
-
console.log('');
|
|
55
|
-
}
|
|
56
|
-
else if (cmd === '.clear') {
|
|
57
|
-
console.clear();
|
|
58
|
-
}
|
|
59
|
-
else if (cmd.startsWith('select ')) {
|
|
60
|
-
const table = cmd.replace('select ', '').trim();
|
|
61
|
-
try {
|
|
62
|
-
const records = await db.select(table);
|
|
63
|
-
console.log(chalk_1.default.bold(`\nFound ${records.length} records in ${table}:`));
|
|
64
|
-
console.log(JSON.stringify(records, null, 2));
|
|
65
|
-
console.log('');
|
|
66
|
-
}
|
|
67
|
-
catch (err) {
|
|
68
|
-
console.error(chalk_1.default.red(`Error: ${err.message}\n`));
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
else if (cmd.startsWith('count ')) {
|
|
72
|
-
const table = cmd.replace('count ', '').trim();
|
|
73
|
-
try {
|
|
74
|
-
const records = await db.select(table);
|
|
75
|
-
console.log(chalk_1.default.bold(`\n${table}: ${records.length} records\n`));
|
|
76
|
-
}
|
|
77
|
-
catch (err) {
|
|
78
|
-
console.error(chalk_1.default.red(`Error: ${err.message}\n`));
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
else if (cmd.length > 0) {
|
|
82
|
-
console.log(chalk_1.default.yellow('Unknown command. Type .help for available commands\n'));
|
|
83
|
-
}
|
|
84
|
-
rl.prompt();
|
|
85
|
-
});
|
|
86
|
-
rl.on('close', () => {
|
|
87
|
-
db.close();
|
|
88
|
-
console.log(chalk_1.default.green('\n👋 Goodbye!\n'));
|
|
89
|
-
process.exit(0);
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
catch (error) {
|
|
93
|
-
console.error(chalk_1.default.red(`Error: ${error.message}`));
|
|
94
|
-
process.exit(1);
|
|
95
|
-
}
|
|
96
|
-
});
|
|
@@ -1,76 +0,0 @@
|
|
|
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.seedCommand = void 0;
|
|
40
|
-
const commander_1 = require("commander");
|
|
41
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
42
|
-
const ora_1 = __importDefault(require("ora"));
|
|
43
|
-
const database = __importStar(require("../../database"));
|
|
44
|
-
const config_1 = require("../utils/config");
|
|
45
|
-
exports.seedCommand = new commander_1.Command().name('db');
|
|
46
|
-
exports.seedCommand
|
|
47
|
-
.command('seed')
|
|
48
|
-
.description('Seed table with mock data')
|
|
49
|
-
.option('-c, --config <path>', 'Path to config file', 'zero.config.ts')
|
|
50
|
-
.option('-t, --table <name>', 'Table name')
|
|
51
|
-
.option('-n, --count <number>', 'Number of records', '10')
|
|
52
|
-
.action(async (options) => {
|
|
53
|
-
if (!options.table) {
|
|
54
|
-
console.error(chalk_1.default.red('Error: --table option is required'));
|
|
55
|
-
process.exit(1);
|
|
56
|
-
}
|
|
57
|
-
const spinner = (0, ora_1.default)(`Seeding ${options.table}...`).start();
|
|
58
|
-
try {
|
|
59
|
-
const db = await (0, config_1.getDatabase)(options.config);
|
|
60
|
-
const seeder = new database.DataSeeder(db);
|
|
61
|
-
const schema = {};
|
|
62
|
-
const fieldTypes = ['string', 'number', 'email', 'boolean', 'date'];
|
|
63
|
-
for (let i = 0; i < 3; i++) {
|
|
64
|
-
const fieldType = fieldTypes[Math.floor(Math.random() * fieldTypes.length)];
|
|
65
|
-
schema[`field_${i + 1}`] = { type: fieldType };
|
|
66
|
-
}
|
|
67
|
-
const count = await seeder.seed(options.table, parseInt(options.count), schema);
|
|
68
|
-
spinner.succeed(chalk_1.default.green(`✅ Seeded ${count} records into ${options.table}`));
|
|
69
|
-
await db.close();
|
|
70
|
-
}
|
|
71
|
-
catch (error) {
|
|
72
|
-
spinner.fail(chalk_1.default.red('❌ Seeding failed'));
|
|
73
|
-
console.error(chalk_1.default.red(error.message));
|
|
74
|
-
process.exit(1);
|
|
75
|
-
}
|
|
76
|
-
});
|
|
@@ -1,36 +0,0 @@
|
|
|
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.zpackCommand = void 0;
|
|
7
|
-
const commander_1 = require("commander");
|
|
8
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
9
|
-
const ora_1 = __importDefault(require("ora"));
|
|
10
|
-
const fs_1 = __importDefault(require("fs"));
|
|
11
|
-
const config_1 = require("../utils/config");
|
|
12
|
-
const config_2 = require("../utils/config");
|
|
13
|
-
exports.zpackCommand = new commander_1.Command().name('zpack');
|
|
14
|
-
exports.zpackCommand
|
|
15
|
-
.command('vacuum')
|
|
16
|
-
.description('Compact a ZPack binary file to save disk space')
|
|
17
|
-
.argument('<file>', 'ZPack file path')
|
|
18
|
-
.action(async (file) => {
|
|
19
|
-
const spinner = (0, ora_1.default)(`Vacuuming ${file}...`).start();
|
|
20
|
-
const startSize = fs_1.default.existsSync(file) ? fs_1.default.statSync(file).size : 0;
|
|
21
|
-
try {
|
|
22
|
-
const db = await (0, config_1.getDatabase)('zero.config.ts');
|
|
23
|
-
await db.vacuum();
|
|
24
|
-
await db.close();
|
|
25
|
-
const endSize = fs_1.default.statSync(file).size;
|
|
26
|
-
const reduction = startSize > 0 ? ((1 - endSize / startSize) * 100) : 0;
|
|
27
|
-
spinner.succeed(chalk_1.default.green(`✅ Vacuum complete for ${file}`));
|
|
28
|
-
console.log(chalk_1.default.gray(` Original Size: ${(0, config_2.formatBytes)(startSize)}`));
|
|
29
|
-
console.log(chalk_1.default.gray(` New Size: ${(0, config_2.formatBytes)(endSize)}`));
|
|
30
|
-
console.log(chalk_1.default.bold.blue(` Efficiency: ${reduction.toFixed(1)}% reduction`));
|
|
31
|
-
}
|
|
32
|
-
catch (error) {
|
|
33
|
-
spinner.fail(chalk_1.default.red(`❌ Vacuum failed: ${error.message}`));
|
|
34
|
-
process.exit(1);
|
|
35
|
-
}
|
|
36
|
-
});
|
package/dist/bin/index.d.ts
DELETED
package/dist/bin/index.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
-
};
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
const commander_1 = require("commander");
|
|
8
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
9
|
-
const package_json_1 = require("../package.json");
|
|
10
|
-
const init_1 = require("./commands/init");
|
|
11
|
-
const db_1 = require("./commands/db");
|
|
12
|
-
const cache_1 = require("./commands/cache");
|
|
13
|
-
const migrate_1 = require("./commands/migrate");
|
|
14
|
-
const zpack_1 = require("./commands/zpack");
|
|
15
|
-
const repl_1 = require("./commands/repl");
|
|
16
|
-
const program = new commander_1.Command();
|
|
17
|
-
program
|
|
18
|
-
.name('zero')
|
|
19
|
-
.description(chalk_1.default.cyan('ZeroHelper CLI - Elite Database Management Tool'))
|
|
20
|
-
.version(package_json_1.version);
|
|
21
|
-
program.addCommand(init_1.initCommand);
|
|
22
|
-
program.addCommand(db_1.dbCommand);
|
|
23
|
-
program.addCommand(cache_1.cacheCommand);
|
|
24
|
-
program.addCommand(migrate_1.migrateCommand);
|
|
25
|
-
program.addCommand(migrate_1.makeMigrationCommand);
|
|
26
|
-
program.addCommand(zpack_1.zpackCommand);
|
|
27
|
-
program.addCommand(repl_1.replCommand);
|
|
28
|
-
program.parse();
|
package/dist/bin/types.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
export interface CLIOptions {
|
|
2
|
-
config: string;
|
|
3
|
-
}
|
|
4
|
-
export interface DBOptions extends CLIOptions {
|
|
5
|
-
table?: string;
|
|
6
|
-
count?: number;
|
|
7
|
-
format?: string;
|
|
8
|
-
output?: string;
|
|
9
|
-
}
|
|
10
|
-
export interface MigrationOptions extends CLIOptions {
|
|
11
|
-
migrationsDir: string;
|
|
12
|
-
steps?: number;
|
|
13
|
-
}
|
|
14
|
-
export interface ImportOptions extends CLIOptions {
|
|
15
|
-
table: string;
|
|
16
|
-
format: string;
|
|
17
|
-
}
|
|
18
|
-
export interface ExportOptions extends CLIOptions {
|
|
19
|
-
table: string;
|
|
20
|
-
format: string;
|
|
21
|
-
output: string;
|
|
22
|
-
}
|
package/dist/bin/types.js
DELETED
package/dist/bin/utils/config.js
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
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.formatBytes = formatBytes;
|
|
40
|
-
exports.loadConfig = loadConfig;
|
|
41
|
-
exports.getDatabase = getDatabase;
|
|
42
|
-
const fs_1 = __importDefault(require("fs"));
|
|
43
|
-
const path_1 = __importDefault(require("path"));
|
|
44
|
-
const database = __importStar(require("../../database"));
|
|
45
|
-
function formatBytes(bytes) {
|
|
46
|
-
if (bytes === 0)
|
|
47
|
-
return '0 Bytes';
|
|
48
|
-
const k = 1024;
|
|
49
|
-
const sizes = ['Bytes', 'KB', 'MB', 'GB'];
|
|
50
|
-
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
51
|
-
return Math.round(bytes / Math.pow(k, i) * 100) / 100 + ' ' + sizes[i];
|
|
52
|
-
}
|
|
53
|
-
function loadConfig(configPath) {
|
|
54
|
-
const absolutePath = path_1.default.resolve(process.cwd(), configPath);
|
|
55
|
-
if (!fs_1.default.existsSync(absolutePath)) {
|
|
56
|
-
throw new Error(`Configuration file not found: ${configPath}`);
|
|
57
|
-
}
|
|
58
|
-
try {
|
|
59
|
-
const modulePath = require.resolve(absolutePath);
|
|
60
|
-
delete require.cache[modulePath];
|
|
61
|
-
const config = require(absolutePath);
|
|
62
|
-
if (!config.zeroConfig) {
|
|
63
|
-
throw new Error('Configuration file must export "zeroConfig"');
|
|
64
|
-
}
|
|
65
|
-
return config.zeroConfig;
|
|
66
|
-
}
|
|
67
|
-
catch (error) {
|
|
68
|
-
if (error.code === 'MODULE_NOT_FOUND') {
|
|
69
|
-
throw new Error(`Cannot load config. Make sure TypeScript is compiled: ${error.message}`);
|
|
70
|
-
}
|
|
71
|
-
throw error;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
async function getDatabase(configPath) {
|
|
75
|
-
const config = loadConfig(configPath);
|
|
76
|
-
const db = database.createDatabase(config);
|
|
77
|
-
return db;
|
|
78
|
-
}
|
|
@@ -1,115 +0,0 @@
|
|
|
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.confirmAction = confirmAction;
|
|
7
|
-
exports.getInitAnswers = getInitAnswers;
|
|
8
|
-
exports.getFilePathPrompts = getFilePathPrompts;
|
|
9
|
-
const inquirer_1 = __importDefault(require("inquirer"));
|
|
10
|
-
async function confirmAction(message) {
|
|
11
|
-
const { confirm } = await inquirer_1.default.prompt([
|
|
12
|
-
{
|
|
13
|
-
type: 'confirm',
|
|
14
|
-
name: 'confirm',
|
|
15
|
-
message,
|
|
16
|
-
default: false
|
|
17
|
-
}
|
|
18
|
-
]);
|
|
19
|
-
return confirm;
|
|
20
|
-
}
|
|
21
|
-
async function getInitAnswers() {
|
|
22
|
-
return inquirer_1.default.prompt([
|
|
23
|
-
{
|
|
24
|
-
type: 'list',
|
|
25
|
-
name: 'adapter',
|
|
26
|
-
message: 'Select database adapter:',
|
|
27
|
-
choices: [
|
|
28
|
-
{ name: '📄 JSON (Simple file-based)', value: 'json' },
|
|
29
|
-
{ name: '📦 ZPack (High-performance binary)', value: 'zpack' },
|
|
30
|
-
{ name: '💾 SQLite (Embedded SQL)', value: 'sqlite' },
|
|
31
|
-
{ name: '🐬 MySQL (Network SQL)', value: 'mysql' },
|
|
32
|
-
{ name: '🐘 PostgreSQL (Network SQL)', value: 'postgres' },
|
|
33
|
-
{ name: '🍃 MongoDB (Document NoSQL)', value: 'mongodb' },
|
|
34
|
-
{ name: '⚡ Redis (In-memory cache)', value: 'redis' },
|
|
35
|
-
{ name: '📊 TOON (Native TOON DB)', value: 'toon' }
|
|
36
|
-
]
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
type: 'confirm',
|
|
40
|
-
name: 'enableCache',
|
|
41
|
-
message: 'Enable caching layer?',
|
|
42
|
-
default: true
|
|
43
|
-
}
|
|
44
|
-
]);
|
|
45
|
-
}
|
|
46
|
-
async function getFilePathPrompts(adapter, enableCache, cacheType) {
|
|
47
|
-
const prompts = [];
|
|
48
|
-
if (['json', 'zpack', 'sqlite', 'toon'].includes(adapter)) {
|
|
49
|
-
prompts.push({
|
|
50
|
-
type: 'input',
|
|
51
|
-
name: 'filePath',
|
|
52
|
-
message: 'Enter database file path:',
|
|
53
|
-
default: () => {
|
|
54
|
-
const ext = adapter === 'json' ? '.json' :
|
|
55
|
-
adapter === 'zpack' ? '.zpack' :
|
|
56
|
-
adapter === 'toon' ? '.toon' : '.db';
|
|
57
|
-
return `./data/storage${ext}`;
|
|
58
|
-
},
|
|
59
|
-
validate: (input) => input.length > 0 || 'Path is required'
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
prompts.push({
|
|
64
|
-
type: 'input',
|
|
65
|
-
name: 'host',
|
|
66
|
-
message: 'Database host:',
|
|
67
|
-
default: 'localhost',
|
|
68
|
-
validate: (input) => input.length > 0 || 'Host is required'
|
|
69
|
-
}, {
|
|
70
|
-
type: 'number',
|
|
71
|
-
name: 'port',
|
|
72
|
-
message: 'Database port:',
|
|
73
|
-
default: (ans) => {
|
|
74
|
-
const ports = { mysql: 3306, postgres: 5432, mongodb: 27017, redis: 6379 };
|
|
75
|
-
return ports[ans.adapter] || 3306;
|
|
76
|
-
}
|
|
77
|
-
}, {
|
|
78
|
-
type: 'input',
|
|
79
|
-
name: 'username',
|
|
80
|
-
message: 'Username:',
|
|
81
|
-
default: 'root',
|
|
82
|
-
when: (ans) => ans.adapter !== 'mongodb'
|
|
83
|
-
}, {
|
|
84
|
-
type: 'password',
|
|
85
|
-
name: 'password',
|
|
86
|
-
message: 'Password (leave empty if none):'
|
|
87
|
-
}, {
|
|
88
|
-
type: 'input',
|
|
89
|
-
name: 'database',
|
|
90
|
-
message: 'Database name:',
|
|
91
|
-
default: 'zero_db',
|
|
92
|
-
validate: (input) => input.length > 0 || 'Database name is required'
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
if (enableCache) {
|
|
96
|
-
prompts.push({
|
|
97
|
-
type: 'list',
|
|
98
|
-
name: 'cacheType',
|
|
99
|
-
message: 'Cache type:',
|
|
100
|
-
choices: ['memory', 'redis'],
|
|
101
|
-
default: 'memory',
|
|
102
|
-
when: () => !cacheType
|
|
103
|
-
});
|
|
104
|
-
if (!cacheType || cacheType === 'memory') {
|
|
105
|
-
prompts.push({
|
|
106
|
-
type: 'number',
|
|
107
|
-
name: 'cacheTtl',
|
|
108
|
-
message: 'Cache TTL (seconds):',
|
|
109
|
-
default: 300,
|
|
110
|
-
when: (ans) => !cacheType || ans.cacheType === 'memory'
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
return prompts;
|
|
115
|
-
}
|
package/dist/bin/zero.d.ts
DELETED