@onurege3467/zerohelper
Version:
ZeroHelper is a versatile high-performance utility library and database framework for Node.js, fully written in TypeScript.
116 lines (115 loc) • 3.98 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.confirmAction = confirmAction;
exports.getInitAnswers = getInitAnswers;
exports.getFilePathPrompts = getFilePathPrompts;
const inquirer_1 = __importDefault(require("inquirer"));
async function confirmAction(message) {
const { confirm } = await inquirer_1.default.prompt([
{
type: 'confirm',
name: 'confirm',
message,
default: false
}
]);
return confirm;
}
async function getInitAnswers() {
return inquirer_1.default.prompt([
{
type: 'list',
name: 'adapter',
message: 'Select database adapter:',
choices: [
{ name: '📄 JSON (Simple file-based)', value: 'json' },
{ name: '📦 ZPack (High-performance binary)', value: 'zpack' },
{ name: '💾 SQLite (Embedded SQL)', value: 'sqlite' },
{ name: '🐬 MySQL (Network SQL)', value: 'mysql' },
{ name: '🐘 PostgreSQL (Network SQL)', value: 'postgres' },
{ name: '🍃 MongoDB (Document NoSQL)', value: 'mongodb' },
{ name: '⚡ Redis (In-memory cache)', value: 'redis' },
{ name: '📊 TOON (Native TOON DB)', value: 'toon' }
]
},
{
type: 'confirm',
name: 'enableCache',
message: 'Enable caching layer?',
default: true
}
]);
}
async function getFilePathPrompts(adapter, enableCache, cacheType) {
const prompts = [];
if (['json', 'zpack', 'sqlite', 'toon'].includes(adapter)) {
prompts.push({
type: 'input',
name: 'filePath',
message: 'Enter database file path:',
default: () => {
const ext = adapter === 'json' ? '.json' :
adapter === 'zpack' ? '.zpack' :
adapter === 'toon' ? '.toon' : '.db';
return `./data/storage${ext}`;
},
validate: (input) => input.length > 0 || 'Path is required'
});
}
else {
prompts.push({
type: 'input',
name: 'host',
message: 'Database host:',
default: 'localhost',
validate: (input) => input.length > 0 || 'Host is required'
}, {
type: 'number',
name: 'port',
message: 'Database port:',
default: (ans) => {
const ports = { mysql: 3306, postgres: 5432, mongodb: 27017, redis: 6379 };
return ports[ans.adapter] || 3306;
}
}, {
type: 'input',
name: 'username',
message: 'Username:',
default: 'root',
when: (ans) => ans.adapter !== 'mongodb'
}, {
type: 'password',
name: 'password',
message: 'Password (leave empty if none):'
}, {
type: 'input',
name: 'database',
message: 'Database name:',
default: 'zero_db',
validate: (input) => input.length > 0 || 'Database name is required'
});
}
if (enableCache) {
prompts.push({
type: 'list',
name: 'cacheType',
message: 'Cache type:',
choices: ['memory', 'redis'],
default: 'memory',
when: () => !cacheType
});
if (!cacheType || cacheType === 'memory') {
prompts.push({
type: 'number',
name: 'cacheTtl',
message: 'Cache TTL (seconds):',
default: 300,
when: (ans) => !cacheType || ans.cacheType === 'memory'
});
}
}
return prompts;
}