devcode-canavar-pro 3.3.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/.env.example +9 -0
- package/README.md +82 -0
- package/bin/devcode.js +43 -0
- package/index.js +47 -0
- package/lib/BackupService.js +184 -0
- package/lib/CLI.js +87 -0
- package/lib/Cache.js +41 -0
- package/lib/Collection.js +295 -0
- package/lib/Core.js +164 -0
- package/lib/Dashboard.js +247 -0
- package/lib/Database.js +60 -0
- package/lib/Index.js +69 -0
- package/lib/Journal.js +79 -0
- package/lib/Middleware.js +50 -0
- package/lib/QueryParser.js +57 -0
- package/lib/RemoteClient.js +275 -0
- package/lib/Schema.js +54 -0
- package/lib/Server.js +224 -0
- package/lib/Storage.js +52 -0
- package/lib/UpdateParser.js +71 -0
- package/package.json +36 -0
- package/test_uri.js +31 -0
- package/vds.js +49 -0
- package/vds_setup.js +36 -0
- package/vds_start.js +27 -0
package/.env.example
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# DevCode Environment Configuration
|
|
2
|
+
# Bu dosyayı .env olarak kaydedin ve gerçek bilgilerinizi girin.
|
|
3
|
+
# BU DOSYAYI ASLA GITHUB'A VEYA NPM'E ATMAYIN!
|
|
4
|
+
|
|
5
|
+
# Veri Merkezi (VDS) IP veya Domain Adresi
|
|
6
|
+
DEVCODE_HOST=123.45.67.89
|
|
7
|
+
|
|
8
|
+
# İsteğe bağlı port (varsayılan 4242)
|
|
9
|
+
# DEVCODE_PORT=4242
|
package/README.md
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# 🦖 DevCode MONSTER: ULTRA-SECURE PRO (v3.3)
|
|
2
|
+
|
|
3
|
+
```text
|
|
4
|
+
██████╗ ███████╗██╗ ██╗ ██████╗ ██████╗ ██████╗ ███████╗
|
|
5
|
+
██╔══██╗██╔════╝██║ ██║██╔════╝ ██╔═══██╗██╔══██╗██╔════╝
|
|
6
|
+
██║ ██║█████╗ ██║ ██║██║ ██║ ██║██║ ██║█████╗
|
|
7
|
+
██║ ██║██╔══╝ ╚██╗ ██╔╝██║ ██║ ██║██║ ██║██╔══╝
|
|
8
|
+
██████╔╝███████╗ ╚████╔╝ ╚██████╗ ╚██████╔╝██████╔╝███████╗
|
|
9
|
+
╚═════╝ ╚══════╝ ╚═══╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚══════╝
|
|
10
|
+
[ THE ULTIMATE SAFE CLOUD DATABASE ]
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
[](https://www.npmjs.com/package/devcode-canavar-pro)
|
|
14
|
+
[](https://www.npmjs.com/package/devcode-canavar-pro)
|
|
15
|
+
[]()
|
|
16
|
+
[]()
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## 🛡️ "Dünyanın En Güvenli Veri Depolama Sistemi"
|
|
21
|
+
|
|
22
|
+
DevCode Monster Pro, sadece bir veritabanı değil; verileriniz için **kurşun geçirmez bir zırhdır.** Sıradan JSON veritabanlarının aksine DevCode, kurumsal düzeyde veri güvenliği ve fiziksel izolasyon sağlar. **Sıfır risk, maksimum koruma.**
|
|
23
|
+
|
|
24
|
+
| Güvenlik Katmanı | Standart Veritabanları | 🦖 DevCode Monster Pro |
|
|
25
|
+
| :--- | :---: | :---: |
|
|
26
|
+
| **Veri Bütünlüğü** | ❌ Bozulmaya Açık | **✅ Ultra-Atomic (Sıfır Bozulma)** |
|
|
27
|
+
| **Fiziksel Güvenlik** | ❌ Herkese Açık Dosya | **✅ VDS Zırhı (Görünmez Veri)** |
|
|
28
|
+
| **Bağlantı Güvenliği** | ❌ Savunmasız | **✅ Secret-Key & IP Shield** |
|
|
29
|
+
| **Saldırı Koruması** | ❌ Korumasız | **✅ Pro Rate-Limit Kalkanı** |
|
|
30
|
+
| **Veri Akış Garantisi** | ❌ Hatalı Kesinti | **✅ Resilience Pro (Tam Teslim)** |
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## 💎 Kurumsal Düzey "God-Mode" Güvenlik
|
|
35
|
+
|
|
36
|
+
### � **Kurşun Geçirmez Veri Akışı (The Fortress)**
|
|
37
|
+
Veri yazılırken ASLA bozulmaz. **Atomic Write** teknolojimiz, veriyi önce güvenli bir tampon bölgede hazırlar ve ancak %100 doğrulandığında sisteme işler. Elektrik kesintisi, sunucu çökmesi veya ağ hatası; veriniz her zaman güvende.
|
|
38
|
+
|
|
39
|
+
### 🛡️ **VDS Zırhlı Kalkanı (The Shield)**
|
|
40
|
+
Sunucunuz artık bir kale. Yerleşik **Rate Limiting** ve **IP Whitelisting** desteği sayesinde sadece sizin izin verdiğiniz "Trusted" (Güvenilir) IP adresleri verilerinize erişebilir. Kalan tüm saldırılar daha kapıdan girmeden engellenir.
|
|
41
|
+
|
|
42
|
+
### ⚡ **Ultra-Fast & Safe Indexing**
|
|
43
|
+
Hızdan ödün vermeden güvenlik sağlıyoruz. **Auto-Indexing** teknolojisi sayesinde verileriniz devasa boyutlara ulaşsa bile sorgularınız Turbo hızında ve stabil bir şekilde yanıtlanır.
|
|
44
|
+
|
|
45
|
+
### 🎨 **Elite Pro Dashboard**
|
|
46
|
+
Kendi VDS verilerinizi kendi PC'nizden yönetin. Premium Glassmorphism arayüzü ile sunucunuzun sağlığını, aktif bağlantıları ve güvenlik metriklerini anlık olarak izleyin.
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## 🚀 Fırlatma Protokolü (The Launch Sequence)
|
|
51
|
+
|
|
52
|
+
### 1️⃣ **VDS: Kaleyi İnşa Edin**
|
|
53
|
+
VDS sunucunuzda sadece şunu çalıştırın:
|
|
54
|
+
```bash
|
|
55
|
+
# Tek komutla kurumsal bulut sunucunuzu başlatın
|
|
56
|
+
npm install -g devcode-canavar-pro
|
|
57
|
+
devcode server --port 4242 --secret sizin_max_guvenli_anahtarınız
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### 2️⃣ **Projeniz: Zırhlı Bağlantı**
|
|
61
|
+
```javascript
|
|
62
|
+
const db = require('devcode-canavar-pro')('sizin_max_guvenli_anahtarınız');
|
|
63
|
+
|
|
64
|
+
// 📊 Güvenlik Panelini yerelinizde başlatın
|
|
65
|
+
db.startDashboard(3000);
|
|
66
|
+
|
|
67
|
+
// 💾 Veriler anında şifreli ve izole bir şekilde VDS'e akar
|
|
68
|
+
const users = db.use('Private').collection('users');
|
|
69
|
+
await users.insert({ username: 'Baran', access: 'Admin' });
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## 🛡️ Neden DevCode Monster Pro?
|
|
75
|
+
- **Namespace Isolation**: Her anahtar için tamamen izole edilmiş veri dünyaları.
|
|
76
|
+
- **Memory Caching Pro**: Hızlı ama güvenli veri okuma garantisi.
|
|
77
|
+
- **No-Disk footprint**: İstemci bilgisayarında iz bırakmaz, veriler sadece merkezde.
|
|
78
|
+
|
|
79
|
+
---
|
|
80
|
+
|
|
81
|
+
## 📜 Lisans ve Elite Destek
|
|
82
|
+
MIT © 2026 [Baran](https://github.com/baran) - **Building Bulletproof Solutions.**
|
package/bin/devcode.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* DevCode Monster CLI Launcher
|
|
5
|
+
* Usage: npx devcode or npm start
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const DevCode = require('../lib/Core');
|
|
9
|
+
const path = require('path');
|
|
10
|
+
|
|
11
|
+
const db = new DevCode();
|
|
12
|
+
|
|
13
|
+
process.on('uncaughtException', (err) => {
|
|
14
|
+
console.error('\n❌ Beklenmedik Hata:', err.message);
|
|
15
|
+
process.exit(1);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
process.on('unhandledRejection', (reason, promise) => {
|
|
19
|
+
console.error('\n❌ İşlenmemiş Reddetme (Promise):', reason);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
async function launch() {
|
|
23
|
+
console.log(`
|
|
24
|
+
\x1b[36m██████╗ ███████╗██╗ ██╗ ██████╗ ██████╗ ██████╗ ███████╗
|
|
25
|
+
██╔══██╗██╔════╝██║ ██║██╔════╝██╔═══██╗██╔══██╗██╔════╝
|
|
26
|
+
██║ ██║█████╗ ██║ ██║██║ ██║ ██║██║ ██║█████╗
|
|
27
|
+
██║ ██║██╔══╝ ╚██╗ ██╔╝██║ ██║ ██║██║ ██║██╔══╝
|
|
28
|
+
██████╔╝███████╗ ╚████╔╝ ╚██████╗╚██████╔╝██████╔╝███████╗
|
|
29
|
+
╚═════╝ ╚══════╝ ╚═══╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚══════╝\x1b[0m
|
|
30
|
+
\x1b[32m--- Monster Edition v2.0 ---\x1b[0m
|
|
31
|
+
`);
|
|
32
|
+
|
|
33
|
+
console.log(`📡 \x1b[1mGörsel Panel Hazırlanıyor...\x1b[0m`);
|
|
34
|
+
db.startDashboard(3000);
|
|
35
|
+
|
|
36
|
+
console.log(`🐚 \x1b[1mİnteraktif Shell Başlatılıyor...\x1b[0m`);
|
|
37
|
+
db.startShell();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
launch().catch(err => {
|
|
41
|
+
console.error('Launcher Hatası:', err);
|
|
42
|
+
process.exit(1);
|
|
43
|
+
});
|
package/index.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
const RemoteClient = require('./lib/RemoteClient');
|
|
2
|
+
const Core = require('./lib/Core');
|
|
3
|
+
const Server = require('./lib/Server');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* DevCode MONSTER: Invisible Cloud Database
|
|
7
|
+
*/
|
|
8
|
+
function devcode(secretOrOptions) {
|
|
9
|
+
let client;
|
|
10
|
+
if (typeof secretOrOptions === 'string') {
|
|
11
|
+
client = new RemoteClient({ secret: secretOrOptions });
|
|
12
|
+
} else {
|
|
13
|
+
client = new RemoteClient(secretOrOptions);
|
|
14
|
+
}
|
|
15
|
+
return client;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
module.exports = devcode;
|
|
19
|
+
|
|
20
|
+
// Gelişmiş sunucu/yerel kullanım
|
|
21
|
+
module.exports.Server = Server; // HTTP Sunucusu
|
|
22
|
+
module.exports.Core = Core; // Veritabanı Motoru
|
|
23
|
+
module.exports.Local = Core;
|
|
24
|
+
|
|
25
|
+
// --- EĞER DOĞRUDAN ÇALIŞTIRILIYORSA (node index.js) ---
|
|
26
|
+
if (require.main === module) {
|
|
27
|
+
const db = new Core();
|
|
28
|
+
|
|
29
|
+
(async () => {
|
|
30
|
+
console.log('\n--- DevCode MONSTER Aktif Ediliyor ---');
|
|
31
|
+
|
|
32
|
+
// Örnek veritabanını hazırla
|
|
33
|
+
const shop = db.use('MonsterShop');
|
|
34
|
+
const guardians = shop.collection('guardians');
|
|
35
|
+
|
|
36
|
+
if (guardians.find({}).length === 0) {
|
|
37
|
+
await guardians.insertMany([
|
|
38
|
+
{ name: 'Baran', power: 9999, rank: 'Legend' },
|
|
39
|
+
{ name: 'DevCode Bot', power: 5000, rank: 'Elite' }
|
|
40
|
+
]);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Dashboard ve Shell'i başlat
|
|
44
|
+
db.startDashboard(3000);
|
|
45
|
+
db.startShell();
|
|
46
|
+
})();
|
|
47
|
+
}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const Storage = require('./Storage');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* DevCode BackupService
|
|
7
|
+
* VDS ortamında verilerinizi otomatik olarak yedekler.
|
|
8
|
+
* Belirtilen aralıkta snapshot alır, eski yedekleri temizler.
|
|
9
|
+
*/
|
|
10
|
+
class BackupService {
|
|
11
|
+
/**
|
|
12
|
+
* @param {string} dataPath - Ana veri klasörü (örn: /home/user/app/data)
|
|
13
|
+
* @param {object} options
|
|
14
|
+
* @param {string} options.backupPath - Yedek klasörü (varsayılan: dataPath/../backups)
|
|
15
|
+
* @param {number} options.intervalHours - Kaç saatte bir yedek alınsın (varsayılan: 6)
|
|
16
|
+
* @param {number} options.maxBackups - Kaç yedek tutulsun, eski silinsin (varsayılan: 24)
|
|
17
|
+
*/
|
|
18
|
+
constructor(dataPath, options = {}) {
|
|
19
|
+
this.dataPath = dataPath;
|
|
20
|
+
this.backupPath = options.backupPath || path.join(dataPath, '..', 'backups');
|
|
21
|
+
this.intervalHours = options.intervalHours || 6;
|
|
22
|
+
this.maxBackups = options.maxBackups || 24;
|
|
23
|
+
this._timer = null;
|
|
24
|
+
|
|
25
|
+
// Yedek klasörünü oluştur
|
|
26
|
+
if (!fs.existsSync(this.backupPath)) {
|
|
27
|
+
fs.mkdirSync(this.backupPath, { recursive: true });
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Otomatik yedeklemeyi başlatır.
|
|
33
|
+
*/
|
|
34
|
+
start() {
|
|
35
|
+
const intervalMs = this.intervalHours * 60 * 60 * 1000;
|
|
36
|
+
|
|
37
|
+
// İlk yedek hemen alınsın
|
|
38
|
+
this.createSnapshot();
|
|
39
|
+
|
|
40
|
+
this._timer = setInterval(() => {
|
|
41
|
+
this.createSnapshot();
|
|
42
|
+
}, intervalMs);
|
|
43
|
+
|
|
44
|
+
// Node.js'in bu timer yüzünden kapanmamasını engelle (VDS için kritik)
|
|
45
|
+
if (this._timer.unref) this._timer.unref();
|
|
46
|
+
|
|
47
|
+
console.log(`\x1b[32m[BackupService]\x1b[0m Otomatik yedekleme aktif. Aralık: ${this.intervalHours}h | Maksimum yedek: ${this.maxBackups}`);
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Otomatik yedeklemeyi durdurur.
|
|
53
|
+
*/
|
|
54
|
+
stop() {
|
|
55
|
+
if (this._timer) {
|
|
56
|
+
clearInterval(this._timer);
|
|
57
|
+
this._timer = null;
|
|
58
|
+
console.log('\x1b[33m[BackupService]\x1b[0m Otomatik yedekleme durduruldu.');
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Anlık bir yedek (snapshot) alır.
|
|
64
|
+
* Tüm veri klasörünü JSON formatında yedekler.
|
|
65
|
+
* @returns {string|null} Yedek dosyasının yolu
|
|
66
|
+
*/
|
|
67
|
+
createSnapshot() {
|
|
68
|
+
try {
|
|
69
|
+
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
70
|
+
const backupFile = path.join(this.backupPath, `backup_${timestamp}.json`);
|
|
71
|
+
const snapshot = {};
|
|
72
|
+
|
|
73
|
+
if (!fs.existsSync(this.dataPath)) {
|
|
74
|
+
console.warn('\x1b[33m[BackupService]\x1b[0m Veri klasörü bulunamadı, yedek atlandı.');
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Her veritabanı klasörünü tara
|
|
79
|
+
const dbs = fs.readdirSync(this.dataPath).filter(f =>
|
|
80
|
+
fs.statSync(path.join(this.dataPath, f)).isDirectory()
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
for (const dbName of dbs) {
|
|
84
|
+
const dbPath = path.join(this.dataPath, dbName);
|
|
85
|
+
snapshot[dbName] = {};
|
|
86
|
+
|
|
87
|
+
const files = fs.readdirSync(dbPath).filter(f => f.endsWith('.json'));
|
|
88
|
+
for (const file of files) {
|
|
89
|
+
const collectionName = path.basename(file, '.json');
|
|
90
|
+
const filePath = path.join(dbPath, file);
|
|
91
|
+
try {
|
|
92
|
+
const content = fs.readFileSync(filePath, 'utf8');
|
|
93
|
+
snapshot[dbName][collectionName] = JSON.parse(content || '[]');
|
|
94
|
+
} catch (e) {
|
|
95
|
+
// Okunamayan dosyayı atla, diğerlerine devam et
|
|
96
|
+
console.warn(`\x1b[33m[BackupService]\x1b[0m ${file} okunamadı, atlandı.`);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Atomik yazma ile yedek kaydet
|
|
102
|
+
Storage.save(backupFile, snapshot);
|
|
103
|
+
console.log(`\x1b[32m[BackupService]\x1b[0m Yedek alındı: ${path.basename(backupFile)}`);
|
|
104
|
+
|
|
105
|
+
// Eski yedekleri temizle
|
|
106
|
+
this._cleanup();
|
|
107
|
+
|
|
108
|
+
return backupFile;
|
|
109
|
+
} catch (err) {
|
|
110
|
+
console.error('\x1b[31m[BackupService HATA]\x1b[0m Yedek alınamadı:', err.message);
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Maksimum yedek sayısını aşan eski yedekleri siler.
|
|
117
|
+
* @private
|
|
118
|
+
*/
|
|
119
|
+
_cleanup() {
|
|
120
|
+
try {
|
|
121
|
+
const backups = fs.readdirSync(this.backupPath)
|
|
122
|
+
.filter(f => f.startsWith('backup_') && f.endsWith('.json'))
|
|
123
|
+
.map(f => ({ name: f, time: fs.statSync(path.join(this.backupPath, f)).mtimeMs }))
|
|
124
|
+
.sort((a, b) => a.time - b.time); // En eskiden yeniye sırala
|
|
125
|
+
|
|
126
|
+
while (backups.length > this.maxBackups) {
|
|
127
|
+
const oldest = backups.shift();
|
|
128
|
+
fs.unlinkSync(path.join(this.backupPath, oldest.name));
|
|
129
|
+
console.log(`\x1b[33m[BackupService]\x1b[0m Eski yedek silindi: ${oldest.name}`);
|
|
130
|
+
}
|
|
131
|
+
} catch (e) {
|
|
132
|
+
// Temizlik hatalarını yoksay
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Bir yedeği geri yükler.
|
|
138
|
+
* @param {string} backupFile - Geri yüklenecek yedek dosyasının tam yolu
|
|
139
|
+
*/
|
|
140
|
+
restore(backupFile) {
|
|
141
|
+
if (!fs.existsSync(backupFile)) {
|
|
142
|
+
throw new Error(`Yedek dosyası bulunamadı: ${backupFile}`);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const snapshot = Storage.load(backupFile);
|
|
146
|
+
|
|
147
|
+
for (const [dbName, collections] of Object.entries(snapshot)) {
|
|
148
|
+
const dbPath = path.join(this.dataPath, dbName);
|
|
149
|
+
if (!fs.existsSync(dbPath)) {
|
|
150
|
+
fs.mkdirSync(dbPath, { recursive: true });
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
for (const [collectionName, data] of Object.entries(collections)) {
|
|
154
|
+
const filePath = path.join(dbPath, `${collectionName}.json`);
|
|
155
|
+
// Atomik yazma ile geri yükle
|
|
156
|
+
Storage.save(filePath, data);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
console.log(`\x1b[32m[BackupService]\x1b[0m Geri yükleme başarılı: ${path.basename(backupFile)}`);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Mevcut yedekleri listeler.
|
|
165
|
+
* @returns {Array<{name: string, date: string, size: number}>}
|
|
166
|
+
*/
|
|
167
|
+
listBackups() {
|
|
168
|
+
if (!fs.existsSync(this.backupPath)) return [];
|
|
169
|
+
|
|
170
|
+
return fs.readdirSync(this.backupPath)
|
|
171
|
+
.filter(f => f.startsWith('backup_') && f.endsWith('.json'))
|
|
172
|
+
.map(f => {
|
|
173
|
+
const stat = fs.statSync(path.join(this.backupPath, f));
|
|
174
|
+
return {
|
|
175
|
+
name: f,
|
|
176
|
+
date: stat.mtime.toISOString(),
|
|
177
|
+
sizeKB: Math.round(stat.size / 1024)
|
|
178
|
+
};
|
|
179
|
+
})
|
|
180
|
+
.sort((a, b) => new Date(b.date) - new Date(a.date));
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
module.exports = BackupService;
|
package/lib/CLI.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
const readline = require('readline');
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* DevCode Interactive CLI Shell
|
|
5
|
+
* Terminal üzerinden veritabanı komutları çalıştırmayı sağlar.
|
|
6
|
+
*/
|
|
7
|
+
class CLI {
|
|
8
|
+
constructor(core) {
|
|
9
|
+
this.core = core;
|
|
10
|
+
this.rl = readline.createInterface({
|
|
11
|
+
input: process.stdin,
|
|
12
|
+
output: process.stdout,
|
|
13
|
+
prompt: 'devcode> '
|
|
14
|
+
});
|
|
15
|
+
this.currentDB = null;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
start() {
|
|
19
|
+
console.log('\n--- DevCode Monster Shell v2.0 ---');
|
|
20
|
+
console.log('Yardım için "help" yazın. Çıkmak için "exit".');
|
|
21
|
+
this.rl.prompt();
|
|
22
|
+
|
|
23
|
+
this.rl.on('line', (line) => {
|
|
24
|
+
const input = line.trim();
|
|
25
|
+
if (!input) {
|
|
26
|
+
this.rl.prompt();
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (input === 'exit') {
|
|
31
|
+
console.log('Görüşmek üzere!');
|
|
32
|
+
process.exit(0);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
this.execute(input);
|
|
36
|
+
this.rl.prompt();
|
|
37
|
+
}).on('close', () => {
|
|
38
|
+
process.exit(0);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
execute(cmd) {
|
|
43
|
+
try {
|
|
44
|
+
if (cmd === 'help') {
|
|
45
|
+
console.log('\nKomutlar:');
|
|
46
|
+
console.log(' show dbs : Tüm veritabanlarını listele');
|
|
47
|
+
console.log(' use <db> : Veritabanı seç');
|
|
48
|
+
console.log(' show collections : Koleksiyonları listele');
|
|
49
|
+
console.log(' db.<coll>.find() : Veri ara');
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (cmd === 'show dbs') {
|
|
54
|
+
console.table(this.core.listDatabases());
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (cmd.startsWith('use ')) {
|
|
59
|
+
const dbName = cmd.split(' ')[1];
|
|
60
|
+
this.currentDB = this.core.use(dbName);
|
|
61
|
+
console.log(`Switched to db ${dbName}`);
|
|
62
|
+
this.rl.setPrompt(`${dbName}> `);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (cmd === 'show collections' && this.currentDB) {
|
|
67
|
+
console.table(this.currentDB.listCollections());
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Basit db.collection.find() simülasyonu
|
|
72
|
+
if (cmd.includes('.find(') && this.currentDB) {
|
|
73
|
+
const collName = cmd.split('.')[1];
|
|
74
|
+
const collection = this.currentDB.collection(collName);
|
|
75
|
+
const results = collection.find({});
|
|
76
|
+
console.dir(results, { depth: null, colors: true });
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
console.log(`Bilinmeyen komut: ${cmd}`);
|
|
81
|
+
} catch (err) {
|
|
82
|
+
console.error('Hata:', err.message);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
module.exports = CLI;
|
package/lib/Cache.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DevCode LRU Cache
|
|
3
|
+
* En son kullanılan dökümanları bellekte tutarak disk erişimini azaltır.
|
|
4
|
+
*/
|
|
5
|
+
class LRUCache {
|
|
6
|
+
constructor(limit = 1000) {
|
|
7
|
+
this.limit = limit;
|
|
8
|
+
this.cache = new Map();
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
get(key) {
|
|
12
|
+
if (!this.cache.has(key)) return null;
|
|
13
|
+
|
|
14
|
+
const value = this.cache.get(key);
|
|
15
|
+
// "Son kullanılan" durumuna getir
|
|
16
|
+
this.cache.delete(key);
|
|
17
|
+
this.cache.set(key, value);
|
|
18
|
+
return value;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
set(key, value) {
|
|
22
|
+
if (this.cache.has(key)) {
|
|
23
|
+
this.cache.delete(key);
|
|
24
|
+
} else if (this.cache.size >= this.limit) {
|
|
25
|
+
// En eski (ilk eklenen) anahtarı sil
|
|
26
|
+
const firstKey = this.cache.keys().next().value;
|
|
27
|
+
this.cache.delete(firstKey);
|
|
28
|
+
}
|
|
29
|
+
this.cache.set(key, value);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
delete(key) {
|
|
33
|
+
this.cache.delete(key);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
clear() {
|
|
37
|
+
this.cache.clear();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
module.exports = LRUCache;
|