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.
@@ -0,0 +1,247 @@
1
+ const http = require('http');
2
+
3
+ /**
4
+ * DevCode Enterprise Dashboard Server
5
+ * Görsel yönetim, Sorgu Konsolu ve Canlı Metrikler sunar.
6
+ */
7
+ class Dashboard {
8
+ constructor(core, port = 3000) {
9
+ this.core = core;
10
+ this.port = port;
11
+ this.server = null;
12
+ }
13
+
14
+ start() {
15
+ this.server = http.createServer(async (req, res) => {
16
+ console.log(`[Dashboard] Gelen İstek: ${req.method} ${req.url}`);
17
+
18
+ const json = (data, status = 200) => {
19
+ res.writeHead(status, {
20
+ 'Content-Type': 'application/json; charset=utf-8',
21
+ 'Access-Control-Allow-Origin': '*'
22
+ });
23
+ res.end(JSON.stringify(data));
24
+ };
25
+
26
+ const getBody = () => new Promise(resolve => {
27
+ let body = '';
28
+ req.on('data', chunk => { body += chunk; });
29
+ req.on('end', () => {
30
+ try { resolve(JSON.parse(body)); }
31
+ catch { resolve({}); }
32
+ });
33
+ });
34
+
35
+ try {
36
+ if (req.url === '/api/stats' && req.method === 'GET') {
37
+ return json({
38
+ databases: this.core.listDatabases(),
39
+ nodeVersion: process.version,
40
+ memory: (process.memoryUsage().heapUsed / 1024 / 1024).toFixed(2) + ' MB',
41
+ uptime: Math.floor(process.uptime()) + 's',
42
+ platform: process.platform
43
+ });
44
+ }
45
+
46
+ // API: Canlı Sorgu Konsolu (Enterprise)
47
+ if (req.url === '/api/query' && req.method === 'POST') {
48
+ const { dbName, code } = await getBody();
49
+ console.log(`[Dashboard] Sorgu Çalıştırılıyor (DB: ${dbName})`);
50
+ const db = this.core.use(dbName);
51
+
52
+ try {
53
+ const result = await (async () => {
54
+ return eval(code);
55
+ })();
56
+ return json({ result });
57
+ } catch (e) {
58
+ return json({ result: { error: e.message } });
59
+ }
60
+ }
61
+
62
+ const dbMatch = req.url.match(/^\/api\/db\/([^/]+)$/);
63
+ if (dbMatch && req.method === 'GET') {
64
+ const dbName = decodeURIComponent(dbMatch[1]);
65
+ const db = this.core.use(dbName);
66
+ return json({ collections: db.listCollections() });
67
+ }
68
+
69
+ if (req.url === '/api/db/create' && req.method === 'POST') {
70
+ const { name } = await getBody();
71
+ if (!name) return json({ error: 'İsim gerekli' }, 400);
72
+ this.core.use(name);
73
+ return json({ success: true });
74
+ }
75
+
76
+ const colMatch = req.url.match(/^\/api\/db\/([^/]+)\/col\/([^/]+)$/);
77
+ if (colMatch && req.method === 'GET') {
78
+ const dbName = decodeURIComponent(colMatch[1]);
79
+ const colName = decodeURIComponent(colMatch[2]);
80
+ const db = this.core.use(dbName);
81
+ const collection = db.collection(colName);
82
+ return json({ docs: collection.find({}).slice(0, 100) });
83
+ }
84
+
85
+ if (req.url === '/api/doc/delete' && req.method === 'POST') {
86
+ const { dbName, colName, id } = await getBody();
87
+ const db = this.core.use(dbName);
88
+ const collection = db.collection(colName);
89
+ collection.remove({ _id: id });
90
+ return json({ success: true });
91
+ }
92
+
93
+ if (!req.url.startsWith('/api')) {
94
+ res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
95
+ return res.end(await this._renderUI());
96
+ }
97
+
98
+ json({ error: 'Endpoint bulunamadı' }, 404);
99
+ } catch (e) {
100
+ console.error(`[Dashboard] Hata:`, e.message);
101
+ json({ error: e.message }, 500);
102
+ }
103
+ });
104
+
105
+ this.server.on('error', (err) => {
106
+ if (err.code === 'EADDRINUSE') {
107
+ console.error(`❌ Hata: ${this.port} portu zaten kullanımda!`);
108
+ }
109
+ });
110
+
111
+ this.server.listen(this.port, () => {
112
+ console.log(`\n🚀 [DashBoard] DevCode Ultra-Premium UI hazır: http://localhost:${this.port}`);
113
+ });
114
+ }
115
+
116
+ async _renderUI() {
117
+ const dbs = await this.core.listDatabases();
118
+ return `
119
+ <!DOCTYPE html>
120
+ <html lang="tr">
121
+ <head>
122
+ <meta charset="UTF-8">
123
+ <title>DevCode Monster | Pro Edition</title>
124
+ <style>
125
+ @import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;600;800&family=JetBrains+Mono&display=swap');
126
+ :root {
127
+ --bg: #020617; --side: #0f172a; --accent: #38bdf8; --text: #f8fafc;
128
+ --card: rgba(30, 41, 59, 0.4); --border: rgba(255,255,255,0.06);
129
+ }
130
+ * { box-sizing: border-box; transition: 0.2s; }
131
+ body {
132
+ background: var(--bg); color: var(--text); font-family: 'Inter', sans-serif;
133
+ margin: 0; display: grid; grid-template-columns: 280px 1fr; height: 100vh; overflow: hidden;
134
+ }
135
+ aside { background: var(--side); border-right: 1px solid var(--border); padding: 30px 20px; display: flex; flex-direction: column; gap: 30px; }
136
+ .logo { font-size: 1.6rem; font-weight: 800; display: flex; align-items: center; gap: 10px; }
137
+ .logo span { color: var(--accent); }
138
+ .pro-badge { font-size: 0.6rem; background: var(--accent); color: var(--bg); padding: 2px 6px; border-radius: 4px; vertical-align: middle; }
139
+ .nav-label { font-size: 0.7rem; font-weight: 700; color: rgba(255,255,255,0.4); text-transform: uppercase; letter-spacing: 1px; }
140
+ .db-item { padding: 12px; border-radius: 10px; cursor: pointer; display: flex; align-items: center; gap: 10px; }
141
+ .db-item:hover { background: rgba(56, 189, 248, 0.05); }
142
+ .db-item.active { background: var(--accent); color: var(--bg); font-weight: 800; }
143
+ main { padding: 40px; overflow-y: auto; }
144
+ .stats-bar { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; margin-bottom: 40px; }
145
+ .glass-card { background: var(--card); border: 1px solid var(--border); border-radius: 20px; padding: 20px; }
146
+ .stat-val { font-size: 1.5rem; font-weight: 800; }
147
+ .console-box { margin-top: 30px; }
148
+ .editor {
149
+ width: 100%; height: 150px; background: #000; border: 1px solid var(--border);
150
+ border-radius: 10px; color: #fff; font-family: 'JetBrains Mono', monospace;
151
+ padding: 15px; margin-bottom: 10px; outline: none;
152
+ }
153
+ .result { background: #0f172a; padding: 15px; border-radius: 10px; color: #4ade80; font-family: monospace; overflow: auto; max-height: 200px; }
154
+ table { width: 100%; border-collapse: collapse; margin-top: 20px; }
155
+ th { text-align: left; opacity: 0.4; font-size: 0.8rem; padding: 10px; }
156
+ td { padding: 12px; border-bottom: 1px solid var(--border); }
157
+ .btn { padding: 8px 16px; border-radius: 8px; border: none; font-weight: 700; cursor: pointer; }
158
+ .btn-primary { background: var(--accent); color: var(--bg); }
159
+ </style>
160
+ </head>
161
+ <body>
162
+ <aside>
163
+ <div class="logo">DevCode <span>Monster</span> <div class="pro-badge">PRO v3.0</div></div>
164
+ <div class="nav-label">Merkezi Veritabanları</div>
165
+ <div id="db-list">
166
+ ${dbs.map(db => `<div class="db-item" onclick="selectDB('${db}')">📦 ${db}</div>`).join('')}
167
+ </div>
168
+ </aside>
169
+ <main>
170
+ <div class="stats-bar">
171
+ <div class="glass-card">
172
+ <div class="nav-label">Merkezi Bulut</div>
173
+ <div class="stat-val" style="color:var(--accent)">45.74.244.192</div>
174
+ <div style="font-size:0.7rem; color: #10b981">● Hizmet Aktif</div>
175
+ </div>
176
+ <div class="glass-card">
177
+ <div class="nav-label">Güvenlik Kalkanı</div>
178
+ <div class="stat-val">Aktif</div>
179
+ <div style="font-size:0.7rem; opacity:0.6">Rate Limit: 100 req/min</div>
180
+ </div>
181
+ <div class="glass-card">
182
+ <div class="nav-label">Performans Motoru</div>
183
+ <div class="stat-val">Turbo</div>
184
+ <div style="font-size:0.7rem; opacity:0.6">Auto-Indexing Devrede</div>
185
+ </div>
186
+ </div>
187
+ <div id="main-content">
188
+ <div style="text-align:center; padding-top:100px; opacity:0.3;">
189
+ <h2>Enterprise Console Ready</h2>
190
+ <p>Select a database to start dominating.</p>
191
+ </div>
192
+ </div>
193
+ <div id="console-area" style="display:none;" class="console-box">
194
+ <h3>🛸 Query Console</h3>
195
+ <textarea id="query-input" class="editor" placeholder="db.collection('name').find({})"></textarea>
196
+ <button class="btn btn-primary" onclick="runQuery()">Run Code</button>
197
+ <pre id="query-result" class="result">Result will appear here...</pre>
198
+ </div>
199
+ </main>
200
+ <script>
201
+ let currentDB = '';
202
+ async function api(p, m='GET', b=null) {
203
+ const r = await fetch(p, { method: m, body: b ? JSON.stringify(b) : null });
204
+ return await r.json();
205
+ }
206
+ async function fetchStats() {
207
+ const d = await api('/api/stats');
208
+ if(d.memory) {
209
+ document.getElementById('stat-mem').innerText = d.memory;
210
+ document.getElementById('stat-uptime').innerText = d.uptime;
211
+ }
212
+ }
213
+ setInterval(fetchStats, 5000); fetchStats();
214
+ async function selectDB(name) {
215
+ currentDB = name;
216
+ document.getElementById('active-name').innerText = name;
217
+ document.getElementById('console-area').style.display = 'block';
218
+ document.getElementById('query-input').value = "// Try: db.listCollections()\\ndb.listCollections();";
219
+ const data = await api('/api/db/' + encodeURIComponent(name));
220
+ let html = '<h3>Collections</h3><div style="display:flex; gap:10px;">';
221
+ data.collections.forEach(c => {
222
+ html += '<div class="glass-card" style="cursor:pointer" onclick="selectCol(\\''+c+'\\')">'+c+'</div>';
223
+ });
224
+ html += '</div>';
225
+ document.getElementById('main-content').innerHTML = html;
226
+ }
227
+ async function runQuery() {
228
+ const code = document.getElementById('query-input').value;
229
+ const res = await api('/api/query', 'POST', { dbName: currentDB, code });
230
+ document.getElementById('query-result').innerText = JSON.stringify(res.result, null, 2);
231
+ }
232
+ async function selectCol(col) {
233
+ const data = await api('/api/db/' + encodeURIComponent(currentDB) + '/col/' + encodeURIComponent(col));
234
+ let html = '<h3>' + col + ' Data</h3><table><thead><tr><th>ID</th><th>Content</th></tr></thead><tbody>';
235
+ data.docs.forEach(doc => {
236
+ html += '<tr><td>'+doc._id.substring(0,8)+'</td><td>'+JSON.stringify(doc).substring(0,50)+'...</td></tr>';
237
+ });
238
+ html += '</tbody></table>';
239
+ document.getElementById('main-content').innerHTML = html;
240
+ }
241
+ </script>
242
+ </body>
243
+ </html>
244
+ `;
245
+ }
246
+ }
247
+ module.exports = Dashboard;
@@ -0,0 +1,60 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const Collection = require('./Collection');
4
+
5
+ /**
6
+ * Database Instance Class
7
+ * Belirli bir veritabanı klasörünü ve içindeki koleksiyonları yönetir.
8
+ */
9
+ class Database {
10
+ constructor(name, dbPath) {
11
+ this.name = name;
12
+ this.dbPath = dbPath;
13
+ this.collections = new Map();
14
+
15
+ if (!fs.existsSync(this.dbPath)) {
16
+ fs.mkdirSync(this.dbPath, { recursive: true });
17
+ }
18
+ }
19
+
20
+ /**
21
+ * Bir koleksiyona erişir.
22
+ * @param {string} colName Koleksiyon adı
23
+ * @returns {Collection} Koleksiyon örneği
24
+ */
25
+ collection(colName) {
26
+ if (this.collections.has(colName)) {
27
+ return this.collections.get(colName);
28
+ }
29
+
30
+ const col = new Collection(colName, this.dbPath);
31
+ this.collections.set(colName, col);
32
+ return col;
33
+ }
34
+
35
+ /**
36
+ * Veritabanındaki tüm koleksiyonları listeler.
37
+ * @returns {string[]}
38
+ */
39
+ listCollections() {
40
+ return fs.readdirSync(this.dbPath)
41
+ .filter(file => file.endsWith('.devcode'))
42
+ .map(file => file.replace('.devcode', ''));
43
+ }
44
+
45
+ /**
46
+ * Bir koleksiyonu siler.
47
+ * @param {string} colName
48
+ */
49
+ dropCollection(colName) {
50
+ const colFilePath = path.join(this.dbPath, `${colName}.devcode`);
51
+ if (fs.existsSync(colFilePath)) {
52
+ fs.unlinkSync(colFilePath);
53
+ this.collections.delete(colName);
54
+ return true;
55
+ }
56
+ return false;
57
+ }
58
+ }
59
+
60
+ module.exports = Database;
package/lib/Index.js ADDED
@@ -0,0 +1,69 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+
4
+ /**
5
+ * Basic Indexing Engine
6
+ * Belirli alanlar için Hash Map tabanlı hızlı erişim sağlar.
7
+ */
8
+ class Index {
9
+ constructor(collectionName, field, dbPath) {
10
+ this.field = field;
11
+ this.indexPath = path.join(dbPath, `${collectionName}_${field}.idx`);
12
+ this.map = new Map();
13
+ this._load();
14
+ }
15
+
16
+ _load() {
17
+ if (fs.existsSync(this.indexPath)) {
18
+ try {
19
+ const data = JSON.parse(fs.readFileSync(this.indexPath, 'utf8'));
20
+ this.map = new Map(Object.entries(data));
21
+ } catch (err) {
22
+ this.map = new Map();
23
+ }
24
+ }
25
+ }
26
+
27
+ _save() {
28
+ const obj = Object.fromEntries(this.map);
29
+ fs.writeFileSync(this.indexPath, JSON.stringify(obj), 'utf8');
30
+ }
31
+
32
+ /**
33
+ * İndekse yeni bir kayıt ekler.
34
+ */
35
+ add(value, id) {
36
+ if (!this.map.has(value)) {
37
+ this.map.set(value, []);
38
+ }
39
+ const ids = this.map.get(value);
40
+ if (!ids.includes(id)) {
41
+ ids.push(id);
42
+ this._save();
43
+ }
44
+ }
45
+
46
+ /**
47
+ * İndeksten hızlıca ID listesi getirir.
48
+ */
49
+ get(value) {
50
+ return this.map.get(value) || [];
51
+ }
52
+
53
+ /**
54
+ * İndeksi günceller.
55
+ */
56
+ remove(value, id) {
57
+ if (this.map.has(value)) {
58
+ const ids = this.map.get(value).filter(i => i !== id);
59
+ if (ids.length === 0) {
60
+ this.map.delete(value);
61
+ } else {
62
+ this.map.set(value, ids);
63
+ }
64
+ this._save();
65
+ }
66
+ }
67
+ }
68
+
69
+ module.exports = Index;
package/lib/Journal.js ADDED
@@ -0,0 +1,79 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+
4
+ /**
5
+ * Journaling System
6
+ * Yazma işlemlerini güvenli hale getirir.
7
+ * Önce işlemleri geçici bir dosyaya yazar, başarılı olursa ana dosyayı günceller.
8
+ */
9
+ class Journal {
10
+ constructor(dbPath) {
11
+ this.journalPath = path.join(dbPath, 'journal.log');
12
+ this.lockPath = path.join(dbPath, 'write.lock');
13
+ }
14
+
15
+ /**
16
+ * Bir işlemi günlüğe kaydeder.
17
+ */
18
+ async record(collectionName, operation, data) {
19
+ const logEntry = JSON.stringify({
20
+ timestamp: Date.now(),
21
+ collection: collectionName,
22
+ op: operation,
23
+ data: data
24
+ }) + '\n';
25
+
26
+ fs.appendFileSync(this.journalPath, logEntry);
27
+ }
28
+
29
+ /**
30
+ * Yazma işlemi için kilit oluşturur.
31
+ */
32
+ lock() {
33
+ if (fs.existsSync(this.lockPath)) {
34
+ const pid = fs.readFileSync(this.lockPath, 'utf8');
35
+ try {
36
+ // Proses hala yaşıyor mu kontrol et
37
+ process.kill(parseInt(pid), 0);
38
+ throw new Error('Veritabanı şu an başka bir işlem tarafından kilitli.');
39
+ } catch (e) {
40
+ // Proses yaşamıyorsa kilit bayattır (Stale lock), temizle
41
+ this.unlock();
42
+ }
43
+ }
44
+ fs.writeFileSync(this.lockPath, process.pid.toString());
45
+ }
46
+
47
+ /**
48
+ * Kilidi kaldırır.
49
+ */
50
+ unlock() {
51
+ if (fs.existsSync(this.lockPath)) {
52
+ try {
53
+ fs.unlinkSync(this.lockPath);
54
+ } catch (e) {
55
+ // Windows dosya sistemi kilitliyse sessizce geç veya logla
56
+ // Büyük sistemlerde retry mekanizması eklenebilir
57
+ }
58
+ }
59
+ }
60
+
61
+ /**
62
+ * Çökme sonrası kurtarma işlemi.
63
+ * Günlükteki (Journal) tamamlanmamış işlemleri kontrol eder.
64
+ */
65
+ async recover(collection) {
66
+ if (fs.existsSync(this.journalPath)) {
67
+ console.log(`[Recovery] ${collection.name} için günlük kontrol ediliyor...`);
68
+ const logs = fs.readFileSync(this.journalPath, 'utf8').split('\n').filter(Boolean);
69
+
70
+ // Son işlemleri kontrol et ve veri bütünlüğünü sağla
71
+ // Bu kısım büyük ölçekli sistemlerde senkronizasyon için kullanılır
72
+
73
+ // İşlem bitince günlüğü temizle
74
+ fs.writeFileSync(this.journalPath, '');
75
+ }
76
+ }
77
+ }
78
+
79
+ module.exports = Journal;
@@ -0,0 +1,50 @@
1
+ /**
2
+ * DevCode Middleware System
3
+ * İşlemlerden önce ve sonra çalışan fonksiyonlar (Hooks).
4
+ */
5
+ class Middleware {
6
+ constructor() {
7
+ this.hooks = {
8
+ pre: new Map(),
9
+ post: new Map()
10
+ };
11
+ }
12
+
13
+ /**
14
+ * İşlem öncesi kanca ekle.
15
+ */
16
+ pre(action, fn) {
17
+ if (!this.hooks.pre.has(action)) this.hooks.pre.set(action, []);
18
+ this.hooks.pre.get(action).push(fn);
19
+ }
20
+
21
+ /**
22
+ * İşlem sonrası kanca ekle.
23
+ */
24
+ post(action, fn) {
25
+ if (!this.hooks.post.has(action)) this.hooks.post.set(action, []);
26
+ this.hooks.post.get(action).push(fn);
27
+ }
28
+
29
+ /**
30
+ * Tüm 'pre' kancalarını çalıştır.
31
+ */
32
+ async runPre(action, data) {
33
+ const actions = this.hooks.pre.get(action) || [];
34
+ for (let fn of actions) {
35
+ await fn(data);
36
+ }
37
+ }
38
+
39
+ /**
40
+ * Tüm 'post' kancalarını çalıştır.
41
+ */
42
+ async runPost(action, data) {
43
+ const actions = this.hooks.post.get(action) || [];
44
+ for (let fn of actions) {
45
+ await fn(data);
46
+ }
47
+ }
48
+ }
49
+
50
+ module.exports = Middleware;
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Advanced Query Parser
3
+ * MongoDB operatörlerini ($gt, $lt, $in, $or vb.) destekleyen motor.
4
+ */
5
+ class QueryParser {
6
+ /**
7
+ * Bir dökümanın sorguya uyup uymadığını kontrol eder.
8
+ */
9
+ static matches(doc, query) {
10
+ for (let key in query) {
11
+ const condition = query[key];
12
+ const value = doc[key];
13
+
14
+ // Mantıksal Operatörler
15
+ if (key === '$or') {
16
+ return condition.some(subQuery => this.matches(doc, subQuery));
17
+ }
18
+ if (key === '$and') {
19
+ return condition.every(subQuery => this.matches(doc, subQuery));
20
+ }
21
+
22
+ // Karşılaştırma Operatörleri
23
+ if (typeof condition === 'object' && condition !== null) {
24
+ for (let op in condition) {
25
+ const target = condition[op];
26
+ if (!this.evaluateOperator(op, value, target)) return false;
27
+ }
28
+ } else {
29
+ // Normal Eşitlik
30
+ if (value !== condition) return false;
31
+ }
32
+ }
33
+ return true;
34
+ }
35
+
36
+ /**
37
+ * Operatör bazlı değerlendirme yapar.
38
+ */
39
+ static evaluateOperator(op, value, target) {
40
+ switch (op) {
41
+ case '$gt': return value > target;
42
+ case '$gte': return value >= target;
43
+ case '$lt': return value < target;
44
+ case '$lte': return value <= target;
45
+ case '$ne': return value !== target;
46
+ case '$in': return Array.isArray(target) && target.includes(value);
47
+ case '$nin': return Array.isArray(target) && !target.includes(value);
48
+ case '$regex': return new RegExp(target, 'i').test(String(value));
49
+ case '$exists': return (value !== undefined) === target;
50
+ case '$size': return Array.isArray(value) && value.length === target;
51
+ case '$all': return Array.isArray(value) && Array.isArray(target) && target.every(v => value.includes(v));
52
+ default: return false;
53
+ }
54
+ }
55
+ }
56
+
57
+ module.exports = QueryParser;