@onurege3467/zerohelper 10.2.5 → 10.2.6
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 +432 -54
- package/dist/bin/commands/cache.d.ts +2 -0
- package/dist/bin/commands/cache.js +92 -0
- package/dist/bin/commands/db-backup.d.ts +3 -0
- package/dist/bin/commands/db-backup.js +118 -0
- package/dist/bin/commands/db.d.ts +2 -0
- package/dist/bin/commands/db.js +334 -0
- package/dist/bin/commands/import-export.d.ts +3 -0
- package/dist/bin/commands/import-export.js +123 -0
- package/dist/bin/commands/init.d.ts +2 -0
- package/dist/bin/commands/init.js +85 -0
- package/dist/bin/commands/migrate.d.ts +3 -0
- package/dist/bin/commands/migrate.js +167 -0
- package/dist/bin/commands/repl.d.ts +2 -0
- package/dist/bin/commands/repl.js +96 -0
- package/dist/bin/commands/seed.d.ts +2 -0
- package/dist/bin/commands/seed.js +76 -0
- package/dist/bin/commands/zpack.d.ts +2 -0
- package/dist/bin/commands/zpack.js +36 -0
- package/dist/bin/index.d.ts +2 -0
- package/dist/bin/index.js +28 -0
- package/dist/bin/types.d.ts +22 -0
- package/dist/bin/types.js +2 -0
- package/dist/bin/utils/config.d.ts +3 -0
- package/dist/bin/utils/config.js +78 -0
- package/dist/bin/utils/prompts.d.ts +3 -0
- package/dist/bin/utils/prompts.js +115 -0
- package/dist/bin/zero.js +789 -81
- package/dist/migrations/1767521950635_test_migration.d.ts +3 -0
- package/dist/migrations/1767521950635_test_migration.js +11 -0
- package/dist/migrations/1767522158826_create_users_table.d.ts +2 -0
- package/dist/migrations/1767522158826_create_users_table.js +11 -0
- package/dist/package.json +79 -0
- package/dist/zero.config.d.ts +10 -0
- package/dist/zero.config.js +13 -0
- package/package.json +2 -2
|
@@ -0,0 +1,78 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
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
|
+
}
|