@onurege3467/zerohelper 10.2.6 → 11.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.
Files changed (79) hide show
  1. package/README.md +9 -704
  2. package/dist/index.js +19 -44
  3. package/package.json +21 -70
  4. package/dist/bin/commands/cache.d.ts +0 -2
  5. package/dist/bin/commands/cache.js +0 -92
  6. package/dist/bin/commands/db-backup.d.ts +0 -3
  7. package/dist/bin/commands/db-backup.js +0 -118
  8. package/dist/bin/commands/db.d.ts +0 -2
  9. package/dist/bin/commands/db.js +0 -334
  10. package/dist/bin/commands/import-export.d.ts +0 -3
  11. package/dist/bin/commands/import-export.js +0 -123
  12. package/dist/bin/commands/init.d.ts +0 -2
  13. package/dist/bin/commands/init.js +0 -85
  14. package/dist/bin/commands/migrate.d.ts +0 -3
  15. package/dist/bin/commands/migrate.js +0 -167
  16. package/dist/bin/commands/repl.d.ts +0 -2
  17. package/dist/bin/commands/repl.js +0 -96
  18. package/dist/bin/commands/seed.d.ts +0 -2
  19. package/dist/bin/commands/seed.js +0 -76
  20. package/dist/bin/commands/zpack.d.ts +0 -2
  21. package/dist/bin/commands/zpack.js +0 -36
  22. package/dist/bin/index.d.ts +0 -2
  23. package/dist/bin/index.js +0 -28
  24. package/dist/bin/types.d.ts +0 -22
  25. package/dist/bin/types.js +0 -2
  26. package/dist/bin/utils/config.d.ts +0 -3
  27. package/dist/bin/utils/config.js +0 -78
  28. package/dist/bin/utils/prompts.d.ts +0 -3
  29. package/dist/bin/utils/prompts.js +0 -115
  30. package/dist/bin/zero.d.ts +0 -2
  31. package/dist/bin/zero.js +0 -849
  32. package/dist/database/IDatabase.d.ts +0 -71
  33. package/dist/database/IDatabase.js +0 -48
  34. package/dist/database/cacheWrapper.d.ts +0 -34
  35. package/dist/database/cacheWrapper.js +0 -214
  36. package/dist/database/index.d.ts +0 -12
  37. package/dist/database/index.js +0 -100
  38. package/dist/database/json.d.ts +0 -32
  39. package/dist/database/json.js +0 -208
  40. package/dist/database/migration.d.ts +0 -21
  41. package/dist/database/migration.js +0 -97
  42. package/dist/database/mongodb.d.ts +0 -26
  43. package/dist/database/mongodb.js +0 -145
  44. package/dist/database/mysql.d.ts +0 -29
  45. package/dist/database/mysql.js +0 -282
  46. package/dist/database/pg.d.ts +0 -28
  47. package/dist/database/pg.js +0 -200
  48. package/dist/database/redis.d.ts +0 -31
  49. package/dist/database/redis.js +0 -176
  50. package/dist/database/seeder.d.ts +0 -20
  51. package/dist/database/seeder.js +0 -37
  52. package/dist/database/sqlite.d.ts +0 -26
  53. package/dist/database/sqlite.js +0 -211
  54. package/dist/database/telemetry.d.ts +0 -35
  55. package/dist/database/telemetry.js +0 -41
  56. package/dist/database/toon.d.ts +0 -33
  57. package/dist/database/toon.js +0 -244
  58. package/dist/database/types.d.ts +0 -71
  59. package/dist/database/types.js +0 -2
  60. package/dist/database/zpack.d.ts +0 -75
  61. package/dist/database/zpack.js +0 -616
  62. package/dist/functions/index.d.ts +0 -199
  63. package/dist/functions/index.js +0 -682
  64. package/dist/functions/security.d.ts +0 -15
  65. package/dist/functions/security.js +0 -46
  66. package/dist/functions/toon.d.ts +0 -10
  67. package/dist/functions/toon.js +0 -214
  68. package/dist/functions/worker.d.ts +0 -5
  69. package/dist/functions/worker.js +0 -35
  70. package/dist/index.d.ts +0 -8
  71. package/dist/migrations/1767521950635_test_migration.d.ts +0 -3
  72. package/dist/migrations/1767521950635_test_migration.js +0 -11
  73. package/dist/migrations/1767522158826_create_users_table.d.ts +0 -2
  74. package/dist/migrations/1767522158826_create_users_table.js +0 -11
  75. package/dist/package.json +0 -79
  76. package/dist/tests/test.d.ts +0 -1
  77. package/dist/tests/test.js +0 -26
  78. package/dist/zero.config.d.ts +0 -10
  79. package/dist/zero.config.js +0 -13
package/README.md CHANGED
@@ -1,718 +1,23 @@
1
- # 🚀 ZeroHelper - The Ultimate Elite Node.js Utility & Database Framework
1
+ # @onurege3467/zerohelper
2
2
 
3
- [![Version](https://img.shields.io/npm/v/@onurege3467/zerohelper?style=for-the-badge)](https://www.npmjs.com/package/@onurege3467/zerohelper)
4
- [![TypeScript](https://img.shields.io/badge/TypeScript-Ready-blue?style=for-the-badge&logo=typescript)](https://www.typescriptlang.org/)
5
- [![License](https://img.shields.io/badge/License-ISC-green?style=for-the-badge)](https://opensource.org/licenses/ISC)
3
+ ZeroHelper - Meta package for backward compatibility.
6
4
 
7
- **ZeroHelper** is an elite-level, high-performance, and fully TypeScript-native utility ecosystem. Rebuilt from the ground up for version 10.2.6, it offers a unified abstraction layer over multiple database engines, advanced caching strategies, and a massive collection of "battle-tested" utility functions.
5
+ ## Description
8
6
 
9
- ---
7
+ This is a meta-package that re-exports all ZeroHelper modules for backward compatibility.
10
8
 
11
- ## 🏛️ Introduction & Philosophy
12
-
13
- ZeroHelper was born out of a simple need: **Stop reinventing the wheel in every project.**
14
-
15
- In modern backend development, we often find ourselves writing the same boilerplate for database connections, caching logic, slug generation, and password hashing. ZeroHelper consolidates these into a single, highly optimized dependency.
16
-
17
- ### 📜 The Origin Story & Commercial Heritage
18
- For the vast majority of its existence, **ZeroHelper operated as a strictly closed-source, proprietary framework.** It was the backbone of multiple high-revenue commercial platforms where failure was not an option. Every module, from the ZPack binary engine to the advanced caching layer, was engineered to meet the brutal demands of real-world commerce.
19
-
20
- Unlike many open-source libraries that start as experiments, ZeroHelper was forged in the fire of **private commercial ecosystems.** It served as a competitive advantage for years, providing enterprise-grade performance and stability to closed-door projects.
21
-
22
- We have now decided to open the vault. By open-sourcing this battle-hardened framework, we are giving the community access to a codebase that has already proven its worth in the most demanding commercial environments. When you use ZeroHelper, you aren't using an "alpha" project—you are using a framework that has been powering commercial success for years.
23
-
24
- ---
25
-
26
- ## 📑 Table of Contents
27
- 1. [Installation](#-installation)
28
- 2. [TypeScript Excellence](#-typescript-excellence)
29
- 3. [Database Unified API](#-database-unified-api)
30
- - [ZPack (High Performance Binary)](#zpack-binary)
31
- - [TOON (Native Object Notation DB)](#toon-db)
32
- - [SQL Adapters (MySQL, PostgreSQL, SQLite)](#sql-adapters)
33
- - [NoSQL Adapters (MongoDB, Redis)](#nosql-adapters)
34
- - [JSON Adapter](#json-adapter)
35
- 4. [Advanced Caching (Memory & Redis)](#-advanced-caching)
36
- 5. [Database Lifecycle Hooks](#-database-lifecycle-hooks)
37
- 6. [Telemetry & Performance Tracking](#-telemetry--performance-tracking)
38
- 7. [Database Migration System](#-database-migration-system)
39
- 8. [ZeroWorker (Worker Threads)](#-zeroworker-worker-threads)
40
- 9. [Zero-CLI Management Tool](#-zero-cli)
41
- - [Project Initialization](#project-initialization)
42
- - [Database Management](#database-management)
43
- - [Migration Management](#migration-management)
44
- - [Cache Management](#cache-management)
45
- - [Data Export/Import](#data-exportimport)
46
- - [Interactive REPL](#interactive-repl)
47
- 10. [Data Seeder](#-data-seeder)
48
- 11. [Function Modules in Depth](#-function-modules-in-depth)
49
- - [TOON Module](#toon-module)
50
- - [Math & Statistics](#math-module)
51
- - [String & Slug Module](#string-module)
52
- - [Array & Collection Module](#array-module)
53
- - [Security & Cryptography](#security-cryptography)
54
- 12. [Validation & Sanitization Engine](#-validation--sanitization-engine)
55
- 13. [Professional Logger Pro](#-professional-logger-pro)
56
- 14. [HTTP & Networking](#-http--networking)
57
- 15. [Real-World Use Cases](#-real-world-use-cases)
58
- 16. [Frequently Asked Questions](#-frequently-asked-questions)
59
- 17. [Architecture & Performance Benchmarks](#-architecture--performance)
60
- 18. [Best Practices](#-best-practices)
61
- 19. [Troubleshooting](#-troubleshooting)
62
- 20. [License](#-license)
63
-
64
- ---
65
-
66
- ## 📦 Installation
9
+ ## Installation
67
10
 
68
11
  ```bash
69
12
  npm install @onurege3467/zerohelper
70
13
  ```
71
14
 
72
- ---
73
-
74
- ## 🛡️ TypeScript Excellence
75
-
76
- ZeroHelper 10.2.6 leverages **Discriminated Unions** to ensure that your configuration object perfectly matches your selected adapter. This eliminates the "configuration guesswork" that plagues most multi-database libraries.
77
-
78
- ### Example: Config Autocomplete
79
- ```typescript
80
- import { database } from '@onurege3467/zerohelper';
81
-
82
- const db = database.createDatabase({
83
- adapter: 'zpack',
84
- config: {
85
- path: './data.zpack',
86
- indexFields: { 'users': ['email'] },
87
- autoFlush: true
88
- }
89
- });
90
- ```
91
-
92
- ---
93
-
94
- ## 💾 Database Unified API
95
-
96
- All adapters implement the `IDatabase` interface, allowing you to swap database backends without changing a single line of your business logic.
97
-
98
- ### 📝 Common Operations
99
-
100
- #### 1. Inserting Data
101
- ```typescript
102
- const newId = await db.insert('users', {
103
- username: 'onurege',
104
- email: 'contact@onurege.com',
105
- created_at: new Date()
106
- });
107
-
108
- const count = await db.bulkInsert('logs', [
109
- { message: 'System Start', level: 'info' },
110
- { message: 'Database Connected', level: 'info' }
111
- ]);
112
- ```
113
-
114
- #### 2. Advanced Selection
115
- ```typescript
116
- interface User { _id: number; username: string; email: string; }
117
- const user = await db.selectOne<User>('users', { username: 'onurege' });
118
- ```
119
-
120
- #### 3. Atomic Counters
121
- ```typescript
122
- await db.increment('wallets', { balance: 100 }, { user_id: 1 });
123
- await db.decrement('inventory', { stock: 1 }, { sku: 'PRO-123' });
124
- ```
125
-
126
- #### 4. Upsert Operations
127
- ```typescript
128
- await db.set('settings', { value: 'dark' }, { key: 'theme' });
129
- ```
130
-
131
- ---
132
-
133
- ## 🚀 Specialized Database Adapters
134
-
135
- ### 🏎️ ZPack (The Binary Powerhouse)
136
-
137
- ZPack is ZeroHelper's proprietary binary format engineered for **maximum write performance** and **minimum storage footprint**.
138
-
139
- #### Key Features
140
- - **Ultra-Fast Writes**: 0.08ms average write latency
141
- - **zlib Compression**: 40-60% smaller file sizes
142
- - **Vacuum Operation**: Eliminate fragmentation from deleted records
143
- - **Secondary Indexing**: Instant lookups on indexed fields
144
- - **Auto-Flush**: Configurable write-through behavior
145
-
146
- #### When to Use ZPack
147
- - High-volume event logging
148
- - Audit trail storage
149
- - Data archival and backup
150
- - Time-series data (with vacuum maintenance)
151
-
152
- #### Example
153
- ```typescript
154
- const zpack = database.createDatabase({
155
- adapter: 'zpack',
156
- config: {
157
- path: './storage/events.zpack',
158
- indexFields: { 'events': ['event_type', 'user_id'] },
159
- autoFlush: true
160
- }
161
- });
162
-
163
- await zpack.insert('logs', { timestamp: new Date(), level: 'info', message: 'Event' });
164
-
165
- await zpack.vacuum();
166
- ```
167
-
168
- ### 📊 TOON (World's First Native TOON Database)
169
-
170
- ZeroHelper introduces the **world's first native TOON (Token-Oriented Object Notation) database** - a revolutionary format optimized for both humans and AI.
171
-
172
- #### Why TOON?
173
-
174
- | Feature | JSON | YAML | TOON |
175
- |---------|------|------|------|
176
- | Human Readable | ⭐⭐ | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐ |
177
- | Parse Speed | ⭐⭐⭐⭐⭐ | ⭐⭐⭐ | ⭐⭐⭐⭐ |
178
- | Token Efficiency | ⭐⭐ | ⭐⭐⭐ | ⭐⭐⭐⭐⭐ |
179
- | AI-Optimized | ❌ | ❌ | ⭐⭐⭐⭐⭐ |
180
- | File Size | Medium | Large | Small |
181
-
182
- #### TOON Syntax Example
183
- ```toon
184
- users:
185
- name: John
186
- age: 25
187
- active: true
188
-
189
- products:
190
- [3]{name,price,stock}:
191
- Laptop,1500,10
192
- Mouse,25,100
193
- Keyboard,75,50
194
- ```
195
-
196
- #### LLM Token Savings
197
- ```
198
- JSON: {"users":[{"name":"John","age":25,"active":true}]} = 47 tokens
199
- TOON: users: name: John age: 25 active: true = 12 tokens
200
-
201
- Savings: ~75% reduction in token usage!
202
- ```
203
-
204
- #### Use Cases
205
- - AI/LLM application data storage
206
- - Configuration files
207
- - Prompt engineering templates
208
- - Agent memory and context
209
-
210
- #### Example
211
- ```typescript
212
- const toonDb = database.createDatabase({
213
- adapter: 'toon',
214
- config: {
215
- path: './ai-data.toon',
216
- saveInterval: 1000
217
- }
218
- });
219
-
220
- await toonDb.insert('prompts', { system: 'You are helpful...', temperature: 0.7 });
221
- ```
222
-
223
- ### 🐘 PostgreSQL & 🐬 MySQL
224
-
225
- Enterprise-grade SQL adapters with automatic schema evolution.
226
- - **Auto-Table/Column Creation**: ZeroHelper creates missing tables and performs `ALTER TABLE` automatically when new keys are detected in your data.
227
-
228
- ### 🍃 MongoDB & 💚 Redis
229
-
230
- Flexible NoSQL adapters for document storage and caching.
231
-
232
- ---
233
-
234
- ## ⚡ Advanced Caching Layer
235
-
236
- Supports **Local LRU Memory** and **Remote Redis**. It automatically invalidates cache on writes.
237
-
238
- ```typescript
239
- const db = database.createDatabase({
240
- adapter: 'mysql',
241
- config: {
242
- host: 'localhost',
243
- cache: {
244
- type: 'redis',
245
- host: '127.0.0.1',
246
- ttl: 300000
247
- }
248
- }
249
- });
250
- ```
251
-
252
- ---
253
-
254
- ## 🪝 Database Lifecycle Hooks
255
-
256
- Register global hooks to monitor or modify data flow.
257
- ```typescript
258
- db.on('beforeInsert', (table, data) => {
259
- console.log(`Inserting into ${table}...`);
260
- data.updated_at = Date.now();
261
- });
262
-
263
- db.on('afterUpdate', (table, result) => {
264
- console.log(`Table ${table} updated. Rows affected: ${result.affected}`);
265
- });
266
- ```
267
-
268
- ---
269
-
270
- ## 📊 Telemetry & Performance Tracking
271
-
272
- Monitor your system health and operation latencies in real-time.
273
- ```typescript
274
- const metrics = db.getMetrics();
275
- console.log(`Avg Database Latency: ${metrics.database.averageDuration}`);
276
- console.log(`Cache Hit Ratio: ${metrics.cache.ratio}`);
277
- ```
278
-
279
- ---
280
-
281
- ## 📂 Database Migration System
282
-
283
- A professional workflow for schema changes.
284
- ```typescript
285
- const migration = new database.MigrationManager(db);
286
- migration.createMigration('add_profile_pictures');
287
- await migration.migrate();
288
- ```
289
-
290
- ---
291
-
292
- ## 🧵 ZeroWorker (Worker Threads)
293
-
294
- Run heavy CPU-bound tasks in the background without blocking the event loop.
295
- ```typescript
296
- import { functions } from '@onurege3467/zerohelper';
297
-
298
- const result = await functions.worker_module.runAsyncTask(
299
- "(data) => { return data.map(x => x * 2); }",
300
- [1, 2, 3]
301
- );
302
- ```
303
-
304
- ---
305
-
306
- ## 🛠️ Zero-CLI
307
-
308
- A professional command-line interface to manage your database and ZeroHelper framework.
309
-
310
- ### 📋 Available Commands
311
-
312
- #### **Project Initialization**
313
- ```bash
314
- npx zero init
315
- ```
316
-
317
- #### **Database Management**
318
- ```bash
319
- npx zero db:test
320
- npx zero db:stats
321
- npx zero db:seed --table users --count 100
322
- npx zero db:backup
323
- npx zero db:backup --output ./custom-backups
324
- npx zero db:restore ./backups/backup_2024-01-01.zerohelper.json
325
- ```
326
-
327
- #### **Migration Management**
328
- ```bash
329
- npx zero migrate
330
- npx zero migration:rollback --steps 1
331
- npx zero migration:status
332
- npx zero make:migration create_users_table
333
- ```
334
-
335
- #### **Cache Management**
336
- ```bash
337
- npx zero cache:clear
338
- npx zero cache:stats
339
- ```
340
-
341
- #### **Data Export/Import**
342
- ```bash
343
- npx zero db:export --table users --format json
344
- npx zero db:export --table users --format csv --output ./exports/users.csv
345
- npx zero db:import ./exports/users.csv --table users --format csv
346
- npx zero db:import ./exports/users.json --table users --format json
347
- ```
348
-
349
- #### **ZPack Maintenance**
350
- ```bash
351
- npx zero zpack:vacuum ./data.zpack
352
- ```
353
-
354
- #### **Interactive REPL**
355
- ```bash
356
- npx zero repl
357
- ```
358
- **Available REPL commands:**
359
- - `.exit` - Exit REPL
360
- - `.help` - Show available commands
361
- - `.stats` - Show database stats
362
- - `.metrics` - Show performance metrics
363
- - `.clear` - Clear screen
364
- - `select <table>` - Select all from table
365
- - `count <table>` - Count records in table
366
-
367
- #### **Global Options**
368
- - `-c, --config <path>` - Path to config file (default: `zero.config.ts`)
369
- - `-h, --help` - Show help for command
370
- - `-V, --version` - Output version number
371
-
372
- ---
373
-
374
- ## 📥 Data Seeder
375
-
376
- Populate your database with realistic mock data in seconds.
15
+ ## Usage
377
16
 
378
- ### Programmatic Usage
379
17
  ```typescript
380
- const seeder = new database.DataSeeder(db);
381
- await seeder.seed('users', 100, {
382
- email: { type: 'email' },
383
- age: { type: 'number', min: 18, max: 65 },
384
- isActive: { type: 'boolean' }
385
- });
18
+ import { database, functions } from '@onurege3467/zerohelper';
386
19
  ```
387
20
 
388
- ### CLI Usage
389
- ```bash
390
- npx zero db:seed --table users --count 100
391
- ```
392
-
393
- ### Supported Field Types
394
- - `string` - Random string with configurable length
395
- - `number` - Random number within min/max range
396
- - `email` - Random email address with various domains
397
- - `boolean` - Random true/false value
398
- - `date` - Random date within the last decade
399
- - `id` - Unique ID string
400
- - `pick` - Random value from provided array
401
-
402
- ---
403
-
404
- ## 🛠️ Function Modules in Depth
405
-
406
- ### 📄 TOON Module
407
- Standard API matching the native `JSON` object for zero learning curve.
408
- ```typescript
409
- import { functions } from '@onurege3467/zerohelper';
410
-
411
- const str = functions.toon_module.stringify({ a: 1, b: 2 });
412
- const obj = functions.toon_module.parse(str);
413
- ```
414
-
415
- ### 🔢 Math & Statistics (`math_module`)
416
- ```typescript
417
- const data = [10, 2, 38, 23, 21];
418
- functions.math_module.mean(data);
419
- functions.math_module.standardDeviation(data);
420
- functions.math_module.isPrime(13);
421
- ```
422
-
423
- ### 🔤 String & Slug Module (`string_module`)
424
- ```typescript
425
- functions.string_module.generateSlug("ZeroHelper: The Best!");
426
- functions.string_module.titleCase("hello world");
427
- ```
428
-
429
- ### 🎲 Random Module (`random_module`)
430
- ```typescript
431
- functions.random_module.makeUniqueId();
432
- functions.random_module.randomHex();
433
- functions.random_module.randomEmoji();
434
- ```
435
-
436
- ### 🌐 HTTP Module (`http_module`)
437
- ```typescript
438
- const data = await functions.http_module.fetchData('https://api.example.com/data');
439
- const response = await functions.http_module.postData('https://api.example.com/post', { key: 'value' });
440
- ```
441
-
442
- ### 📅 Date Module (`date_module`)
443
- ```typescript
444
- functions.date_module.formatDate(new Date(), 'YYYY-MM-DD');
445
- functions.date_module.addDays(new Date(), 5);
446
- functions.date_module.dateDifference(date1, date2);
447
- ```
448
-
449
- ### 🛠️ Array Module (`array_module`)
450
- ```typescript
451
- functions.array_module.shuffleArray([1, 2, 3, 4, 5]);
452
- functions.array_module.groupBy(users, 'role');
453
- functions.array_module.pluck(users, 'email');
454
- functions.array_module.sortBy(users, 'name');
455
- ```
456
-
457
- ### 🔧 Object Module (`object_module`)
458
- ```typescript
459
- functions.object_module.deepMerge(obj1, obj2);
460
- functions.object_module.filterObjectByKey(obj, ['name', 'email']);
461
- ```
462
-
463
- ---
464
-
465
- ## 🔐 Security & Cryptography
466
-
467
- ### Password Handling
468
- ```typescript
469
- const hash = functions.crypto_module.hashPassword('securePassword123');
470
- const isValid = functions.crypto_module.verifyPassword('securePassword123', hash);
471
- ```
472
-
473
- ### Text Encryption (AES-256-CBC)
474
- ```typescript
475
- const { encryptedText, iv } = functions.crypto_module.encryptText('secret', 'mySecretKey');
476
- const original = functions.crypto_module.decryptText(encryptedText, 'mySecretKey', iv);
477
- ```
478
-
479
- ### JWT Tokens
480
- ```typescript
481
- const token = functions.crypto_module.generateJWT({ userId: 1 }, 'jwtSecret');
482
- const payload = functions.crypto_module.verifyJWT(token, 'jwtSecret');
483
- ```
484
-
485
- ### Rate Limiting
486
-
487
- #### Memory-based (Single Instance)
488
- ```typescript
489
- const result = await functions.security_module.checkRateLimit('user:1', {
490
- limit: 10,
491
- window: 60,
492
- storage: 'memory'
493
- });
494
- console.log(result.allowed); // true or false
495
- ```
496
-
497
- #### Redis-based (Distributed Systems)
498
- ```typescript
499
- const result = await functions.security_module.checkRateLimit('api:192.168.1.1', {
500
- limit: 100,
501
- window: 60,
502
- storage: 'redis',
503
- redisClient: redisDb
504
- });
505
- ```
506
-
507
- ### Additional Security Functions
508
- ```typescript
509
- functions.crypto_module.isPasswordStrong('MySecureP@ss123');
510
- functions.crypto_module.validateUUID('550e8400-e29b-41d4-a716-446655440000');
511
- functions.crypto_module.generateSalt();
512
- ```
513
-
514
- ---
515
-
516
- ## 🛡️ Validation & Sanitization Engine
517
-
518
- ### Schema Validation
519
- ```typescript
520
- const schema = {
521
- email: { required: true, type: 'string', pattern: /^[^\s@]+@[^\s@]+\.[^\s@]+$/ },
522
- age: { required: false, type: 'number', min: 18, max: 120 },
523
- password: { required: true, type: 'string', minLength: 8 }
524
- };
525
-
526
- const result = functions.validation_module.validateSchema(data, schema);
527
- console.log(result.isValid);
528
- console.log(result.errors);
529
- ```
530
-
531
- ### Input Sanitization
532
- ```typescript
533
- const clean = functions.validation_module.sanitizeInput(userInput, {
534
- trim: true,
535
- removeHTML: true,
536
- escape: true
537
- });
538
- ```
539
-
540
- ### Utilities
541
- ```typescript
542
- functions.validation_module.isEmail('test@example.com');
543
- functions.validation_module.isPhone('+1234567890');
544
- functions.validation_module.isURL('https://example.com');
545
- functions.validation_module.sanitizeHTML('<script>alert("xss")</script>');
546
- functions.validation_module.validateCreditCard('4111111111111111');
547
- ```
548
-
549
- ---
550
-
551
- ## 📝 Professional Logger Pro
552
-
553
- ```typescript
554
- import { functions } from '@onurege3467/zerohelper';
555
-
556
- const logger = functions.logger_module.createLogger({
557
- level: 'info',
558
- enableColors: true,
559
- enableTimestamp: true,
560
- logFile: './app.log'
561
- });
562
-
563
- logger.info('User logged in', { userId: 123 });
564
- logger.warn('Rate limit approaching', { remaining: 10 });
565
- logger.error('Database connection failed', { error: err.message });
566
- logger.debug('Cache hit', { key: 'user:123' });
567
- ```
568
-
569
- ### Quick Logging Functions
570
- ```typescript
571
- functions.logger_module.info('Message');
572
- functions.logger_module.warn('Message');
573
- functions.logger_module.error('Message');
574
- functions.logger_module.debug('Message');
575
- ```
576
-
577
- ---
578
-
579
- ## 🏎️ Performance Benchmarks
580
- *Hardware: Intel i9-12900K, 64GB RAM*
581
- - **ZPack Binary Write:** 0.08ms
582
- - **TOON Serialization:** 0.15ms / 1KB
583
- - **Array Grouping (1M items):** 45ms
584
-
585
- ---
586
-
587
- ## 🎯 Real-World Use Cases
588
-
589
- ### E-Commerce Application
590
- ```typescript
591
- const db = database.createDatabase({
592
- adapter: 'postgres',
593
- config: {
594
- host: 'localhost',
595
- user: 'admin',
596
- password: 'secure',
597
- database: 'shop',
598
- cache: { type: 'redis', host: '127.0.0.1', ttl: 300000 }
599
- }
600
- });
601
-
602
- await db.insert('products', { name: 'Laptop', price: 1500, stock: 10 });
603
- await db.decrement('products', { stock: 1 }, { sku: 'PROD-001' });
604
- await db.increment('orders', { total: 1500 }, { orderId: 1001 });
605
-
606
- const hash = functions.crypto_module.hashPassword(userPassword);
607
- await db.insert('users', { email, password: hash });
608
- ```
609
-
610
- ### AI/LLM Applications with TOON
611
- ```typescript
612
- const toonDb = database.createDatabase({
613
- adapter: 'toon',
614
- config: { path: './ai-data.toon' }
615
- });
616
-
617
- await toonDb.insert('prompts', {
618
- system: 'You are a helpful assistant designed for customer support.',
619
- examples: [...],
620
- temperature: 0.7,
621
- maxTokens: 1000
622
- });
623
-
624
- const prompts = toonDb.select('prompts', { category: 'support' });
625
- ```
626
-
627
- ### High-Performance Logging with ZPack
628
- ```typescript
629
- const zpack = database.createDatabase({
630
- adapter: 'zpack',
631
- config: { path: './logs.zpack', autoFlush: true }
632
- });
633
-
634
- await zpack.insert('events', {
635
- timestamp: new Date(),
636
- level: 'info',
637
- message: 'User action recorded',
638
- userId: 123,
639
- action: 'purchase',
640
- amount: 99.99
641
- });
642
-
643
- await zpack.vacuum();
644
- ```
645
-
646
- ### Distributed API Protection
647
- ```typescript
648
- import { database } from '@onurege3467/zerohelper';
649
-
650
- const redisDb = database.createDatabase({
651
- adapter: 'redis',
652
- config: { host: '127.0.0.1', port: 6379 }
653
- });
654
-
655
- async function handleApiRequest(ip: string) {
656
- const rateLimit = await functions.security_module.checkRateLimit(`api:${ip}`, {
657
- limit: 1000,
658
- window: 3600,
659
- storage: 'redis',
660
- redisClient: redisDb
661
- });
662
-
663
- if (!rateLimit.allowed) {
664
- throw new Error('Rate limit exceeded');
665
- }
666
-
667
- return processRequest();
668
- }
669
- ```
670
-
671
- ---
672
-
673
- ## ❓ Frequently Asked Questions
674
-
675
- ### Q: Which adapter should I choose?
676
-
677
- **A:**
678
- - **ZPack**: High-volume logging, archival, audit trails
679
- - **TOON**: AI/LLM applications, configs, human-readable needs
680
- - **JSON**: Development, small projects, prototyping
681
- - **SQLite**: Desktop apps, single-user applications
682
- - **PostgreSQL/MySQL**: Web applications, enterprise systems
683
- - **MongoDB**: Flexible document schemas, content management
684
- - **Redis**: Caching, sessions, real-time features
685
-
686
- ### Q: How does TOON save tokens for LLMs?
687
-
688
- **A:** TOON uses compact syntax like `[3]{name,age}: John,25 Jane,30 Bob,28` instead of verbose JSON arrays. This reduces token count by 30-60% while maintaining full data fidelity and human readability.
689
-
690
- ### Q: Is ZPack suitable for concurrent access?
691
-
692
- **A:** ZPack is optimized for single-writer scenarios. For multi-threaded logging, consider using SQLite or a dedicated logging service with ZPack for archival.
693
-
694
- ### Q: Can I migrate between adapters?
695
-
696
- **A:** Yes! All adapters implement the IDatabase interface. Export data using `db:export` CLI command and import to any other adapter.
697
-
698
- ### Q: What's the difference between memory and Redis rate limiting?
699
-
700
- **A:** Memory storage is fast and suitable for single-instance applications. Redis storage enables distributed rate limiting across multiple server instances.
701
-
702
- ### Q: Does ZeroHelper support transactions?
703
-
704
- **A:** SQL adapters (PostgreSQL, MySQL, SQLite) support transactions. NoSQL and file-based adapters have atomic operations but not full ACID transactions.
705
-
706
- ---
707
-
708
- ## 🏁 Final Words
709
-
710
- **ZeroHelper** is the result of years of private commercial development, now open for the community to build the next generation of high-performance Node.js applications.
711
-
712
- Developed with ❤️ by **Onure9e**. Built for excellence.
713
-
714
- ---
715
-
716
- ## 📜 License
21
+ ## License
717
22
 
718
- Licensed under the [ISC License](LICENSE).
23
+ ISC