@onurege3467/zerohelper 9.2.0 → 10.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/dist/test.js DELETED
@@ -1,55 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- // test.ts
4
- const index_1 = require("./index");
5
- async function runTest() {
6
- console.log("🚀 ZeroHelper TypeScript Test Başlatılıyor...\n");
7
- // --- 1. Yardımcı Fonksiyonlar Testi ---
8
- console.log("🛠️ Helper Functions:");
9
- console.log("- Unique ID:", index_1.functions.random_module.makeUniqueId());
10
- console.log("- Random Text (10):", index_1.functions.random_module.randomText(10));
11
- console.log("- Slug:", index_1.functions.string_module.generateSlug("TypeScript Test Case"));
12
- console.log("- Formatted Date:", index_1.functions.date_module.formatDate(new Date(), "YYYY-MM-DD HH:mm:ss"));
13
- const numbers = [10, 20, 30, 40, 50];
14
- console.log("- Mean of numbers:", index_1.functions.math_module.mean(numbers));
15
- // --- 2. Veritabanı Testi (JSON Adaptörü) ---
16
- console.log("\n💾 Database Test (JSON Adapter):");
17
- // Veri Ekleme (Insert)
18
- const db = index_1.database.createDatabase({
19
- adapter: 'json',
20
- config: {
21
- filePath: './test-db.json'
22
- },
23
- });
24
- const table = 'users';
25
- try {
26
- // Veri Ekleme (Insert)
27
- const userId = await db.insert(table, {
28
- name: 'Onur Ege',
29
- role: 'Developer',
30
- level: 1
31
- });
32
- console.log(`✅ Kayıt eklendi, ID: ${userId}`);
33
- // Veri Seçme (Select One)
34
- const user = await db.selectOne(table, { _id: userId });
35
- console.log("🔍 Seçilen Veri:", user);
36
- // Veri Güncelleme (Update)
37
- await db.update(table, { role: 'Senior Developer' }, { _id: userId });
38
- console.log("📝 Veri güncellendi.");
39
- // Sayısal Değer Artırma (Increment)
40
- await db.increment(table, { level: 5 }, { _id: userId });
41
- const finalUser = await db.selectOne(table, { _id: userId });
42
- console.log("📈 Increment sonrası veri:", finalUser);
43
- // Veri Silme (Delete)
44
- const deletedCount = await db.delete(table, { _id: userId });
45
- console.log(`🗑️ Silinen kayıt sayısı: ${deletedCount}`);
46
- console.log("\n✨ Tüm testler başarıyla tamamlandı!");
47
- }
48
- catch (error) {
49
- console.error("❌ Test sırasında hata oluştu:", error);
50
- }
51
- finally {
52
- await db.close();
53
- }
54
- }
55
- runTest().catch(console.error);
@@ -1 +0,0 @@
1
- export {};
@@ -1,48 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- // test_v91_advanced.ts
4
- const index_1 = require("./index");
5
- async function runAdvancedTest() {
6
- console.log("🚀 ZeroHelper v9.1.0 Advanced Features Test\n");
7
- // 1. Database with Cache & Telemetry
8
- const db = index_1.database.createDatabase({
9
- adapter: 'zpack',
10
- config: {
11
- filePath: './v91_advanced.zpack',
12
- cache: { type: 'memory', ttl: 10000 }
13
- }
14
- });
15
- console.log("📊 Telemetry: Initializing...");
16
- // Trigger some DB operations to generate metrics
17
- await db.insert('users', { name: 'Onur', role: 'Admin' });
18
- await db.insert('users', { name: 'Ege', role: 'Dev' });
19
- console.log("🔍 Cache Test: First read (Miss)");
20
- await db.select('users'); // Should be a miss
21
- console.log("🔍 Cache Test: Second read (Hit)");
22
- await db.select('users'); // Should be a hit
23
- // Show Metrics
24
- const metrics = db.getMetrics();
25
- console.log("\n📈 Database Metrics:", JSON.stringify(metrics.database, null, 2));
26
- console.log("🧠 Cache Metrics:", JSON.stringify(metrics.cache, null, 2));
27
- // 2. Rate Limiter Test
28
- console.log("\n🛡️ Security: Rate Limiter Test");
29
- const limiterKey = "user_123_login";
30
- const limitOptions = { limit: 3, window: 5 }; // 3 requests per 5 seconds
31
- for (let i = 1; i <= 5; i++) {
32
- const status = await index_1.functions.security_module.checkRateLimit(limiterKey, limitOptions);
33
- console.log(`Request ${i}: ${status.allowed ? '✅ Allowed' : '❌ Blocked'} (Remaining: ${status.remaining})`);
34
- }
35
- // 3. Hooks Test
36
- console.log("\n🪝 Hooks Test: Monitoring 'logs' table");
37
- db.on('beforeInsert', (table, data) => {
38
- if (table === 'logs') {
39
- data.processedByHook = true;
40
- data.timestamp = Date.now();
41
- }
42
- });
43
- await db.insert('logs', { event: 'TEST_EVENT' });
44
- const loggedEvent = await db.selectOne('logs', { event: 'TEST_EVENT' });
45
- console.log("Hooked Data:", loggedEvent);
46
- await db.close();
47
- }
48
- runAdvancedTest().catch(console.error);
@@ -1 +0,0 @@
1
- export {};
@@ -1,54 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- // test_v91_basics.ts
4
- const index_1 = require("./index");
5
- async function testHooksAndVacuum() {
6
- console.log("🧪 Testing v9.1.0 Basics: Hooks & Vacuum\n");
7
- const db = index_1.database.createDatabase({
8
- adapter: 'zpack',
9
- config: { filePath: './v91_test.zpack', autoFlush: true }
10
- });
11
- // 1. Test Lifecycle Hooks
12
- console.log("🪝 Setting up Hooks...");
13
- db.on('beforeInsert', (table, data) => {
14
- console.log(`[HOOK] beforeInsert on ${table}:`, data.name);
15
- // Auto-modify data before insert (e.g., adding a server-side timestamp)
16
- data.hooked = true;
17
- });
18
- db.on('afterInsert', (table, data) => {
19
- console.log(`[HOOK] afterInsert on ${table}. New ID:`, data._id);
20
- });
21
- db.on('beforeDelete', (table, data) => {
22
- console.log(`[HOOK] beforeDelete on ${table}. Deleting user:`, data.name);
23
- });
24
- // Execute insert to trigger hooks
25
- await db.insert('users', { name: 'Hook Tester', level: 10 });
26
- // 2. Test ZPack Vacuum
27
- console.log("\n📦 Testing Vacuum (Compaction)...");
28
- // Add some data and then delete it to create "tombstones" (bloat)
29
- console.log("Adding temporary data for bloat...");
30
- const ids = [];
31
- for (let i = 0; i < 5; i++) {
32
- ids.push(await db.insert('temp', { data: 'garbage'.repeat(100) }));
33
- }
34
- // Delete all temp data
35
- for (const id of ids) {
36
- await db.delete('temp', { _id: id });
37
- }
38
- const fs = require('fs');
39
- const sizeBefore = fs.statSync('./v91_test.zpack').size;
40
- console.log(`Size before Vacuum: ${sizeBefore} bytes`);
41
- console.log("Running Vacuum...");
42
- // Cast to any because vacuum is specific to ZPackAdapter but db is typed as IDatabase
43
- await db.vacuum();
44
- const sizeAfter = fs.statSync('./v91_test.zpack').size;
45
- console.log(`Size after Vacuum: ${sizeAfter} bytes`);
46
- if (sizeAfter < sizeBefore) {
47
- console.log("✅ Vacuum successful! File compacted.");
48
- }
49
- else {
50
- console.log("⚠️ Vacuum didn't reduce size (maybe file was already small).");
51
- }
52
- await db.close();
53
- }
54
- testHooksAndVacuum().catch(console.error);
@@ -1 +0,0 @@
1
- export {};
@@ -1,54 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- // test_v91_performance.ts
4
- const index_1 = require("./index");
5
- async function runPerformanceTest() {
6
- console.log("🚀 ZeroHelper v9.1.0 Performance & Compression Test\n");
7
- const db = index_1.database.createDatabase({
8
- adapter: 'zpack',
9
- config: {
10
- filePath: './perf_test.zpack',
11
- autoFlush: false, // Hız için false yapıyoruz
12
- cache: { type: 'memory' }, // Compression'ı tetiklemek için kullandık (yapıda compression true yaptık)
13
- indexFields: {
14
- 'users': ['email'] // Email alanına indeks ekledik
15
- }
16
- }
17
- });
18
- try {
19
- const table = 'users';
20
- const count = 5000;
21
- console.log(`📥 ${count} adet veri ekleniyor (Sıkıştırılmış + İndeksli)...`);
22
- const startInsert = Date.now();
23
- for (let i = 1; i <= count; i++) {
24
- await db.insert(table, {
25
- name: `User ${i}`,
26
- email: `user${i}@example.com`,
27
- bio: "Bu bir uzun biyografi metnidir. Sıkıştırma oranını test etmek için bilerek uzun tutulmuştur. ".repeat(5),
28
- age: 20 + (i % 50)
29
- });
30
- }
31
- const endInsert = Date.now();
32
- console.log(`✅ Ekleme tamamlandı: ${endInsert - startInsert}ms`);
33
- // 1. İndekssiz Arama (Normalde _id dışındakiler yavaştır ama Map cache sayesinde hızlanır)
34
- console.log("\n🔍 İndeksli arama testi (email ile)...");
35
- const startSearch = Date.now();
36
- const targetEmail = `user${count - 10}@example.com`;
37
- const found = await db.selectOne(table, { email: targetEmail });
38
- const endSearch = Date.now();
39
- console.log(`Bulunan Kullanıcı: ${found?.name}`);
40
- console.log(`⏱️ Arama Süresi: ${endSearch - startSearch}ms (Milyonlarca satırda bile milisaniye altı!)`);
41
- // 2. Dosya Boyutu Kontrolü
42
- const fs = require('fs');
43
- const stats = fs.statSync('./perf_test.zpack');
44
- console.log(`\n📦 Toplam Dosya Boyutu: ${(stats.size / 1024).toFixed(2)} KB`);
45
- console.log("\n✨ Performans testi başarıyla tamamlandı!");
46
- }
47
- catch (error) {
48
- console.error("❌ Performans testi hatası:", error);
49
- }
50
- finally {
51
- await db.close();
52
- }
53
- }
54
- runPerformanceTest().catch(console.error);
@@ -1 +0,0 @@
1
- export {};
@@ -1,64 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- // test_zpack.ts
4
- const index_1 = require("./index");
5
- async function runZPackTest() {
6
- console.log("📦 ZPack Database TypeScript Testi Başlatılıyor...\n");
7
- // 1. Veritabanı Kurulumu
8
- // Autocomplete burada 'filePath' ve 'autoFlush' seçeneklerini sunacaktır.
9
- const db = index_1.database.createDatabase({
10
- adapter: 'zpack',
11
- config: {
12
- filePath: './test_data.zpack',
13
- autoFlush: true
14
- }
15
- });
16
- const table = 'products';
17
- try {
18
- // 2. Veri Ekleme (Insert)
19
- console.log("📥 Veri ekleniyor...");
20
- const productId = await db.insert(table, {
21
- name: 'Gaming Mouse',
22
- price: 150,
23
- stock: 50,
24
- category: 'Electronics'
25
- });
26
- console.log(`✅ Ürün eklendi, logical_id: ${productId}`);
27
- // 3. Tekil Veri Seçme (Select One)
28
- console.log("\n🔍 Ürün sorgulanıyor...");
29
- const product = await db.selectOne(table, { _id: productId });
30
- console.log("Bulunan Ürün:", product);
31
- // 4. Toplu Veri Ekleme (Bulk Insert)
32
- console.log("\n📥 Toplu veri ekleniyor...");
33
- await db.bulkInsert(table, [
34
- { name: 'Keyboard', price: 300, stock: 20 },
35
- { name: 'Monitor', price: 1200, stock: 10 }
36
- ]);
37
- // 5. Filtreleme ile Seçme (Select)
38
- console.log("\n📂 Tüm ürünler listeleniyor...");
39
- const allProducts = await db.select(table);
40
- console.log(`Toplam ürün sayısı: ${allProducts.length}`);
41
- allProducts.forEach(p => console.log(`- ${p.name}: ${p.price} TL (Stok: ${p.stock})`));
42
- // 6. Güncelleme (Update)
43
- console.log("\n📝 Fiyat güncellemesi yapılıyor...");
44
- await db.update(table, { price: 175 }, { name: 'Gaming Mouse' });
45
- // 7. Sayısal İşlemler (Increment/Decrement)
46
- console.log("\n📈 Stok artırılıyor...");
47
- await db.increment(table, { stock: 10 }, { name: 'Gaming Mouse' });
48
- const updatedProduct = await db.selectOne(table, { name: 'Gaming Mouse' });
49
- console.log("Güncel Veri:", updatedProduct);
50
- // 8. Silme (Delete)
51
- console.log("\n🗑️ Monitor siliniyor...");
52
- await db.delete(table, { name: 'Monitor' });
53
- const finalCount = await db.select(table);
54
- console.log(`Kalan ürün sayısı: ${finalCount.length}`);
55
- console.log("\n✨ ZPack testi başarıyla tamamlandı!");
56
- }
57
- catch (error) {
58
- console.error("❌ ZPack hatası:", error);
59
- }
60
- finally {
61
- await db.close();
62
- }
63
- }
64
- runZPackTest().catch(console.error);
File without changes