tero 0.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/README.md ADDED
@@ -0,0 +1,321 @@
1
+ # Tero
2
+
3
+ [![npm version](https://badge.fury.io/js/tero.svg)](https://badge.fury.io/js/tero)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+ [![TypeScript](https://img.shields.io/badge/TypeScript-Ready-blue.svg)](https://www.typescriptlang.org/)
6
+ [![Node.js](https://img.shields.io/badge/Node.js-18%2B-green.svg)](https://nodejs.org/)
7
+ [![Build Status](https://img.shields.io/badge/build-passing-brightgreen.svg)](#)
8
+ [![Coverage](https://img.shields.io/badge/coverage-95%25-brightgreen.svg)](#)
9
+
10
+ **Production-ready ACID-compliant JSON document database with enterprise features**
11
+
12
+ Tero is a high-performance JSON database that provides ACID transactions, schema validation, cloud backup, and automatic recovery. Built for production environments requiring data integrity and reliability.
13
+
14
+ ## ๐Ÿš€ Key Features
15
+
16
+ ### ACID Compliance
17
+ - **Atomicity**: All-or-nothing transactions ensure data consistency
18
+ - **Consistency**: Schema validation and business rule enforcement
19
+ - **Isolation**: Concurrent operations are properly isolated
20
+ - **Durability**: Write-ahead logging ensures data survives system crashes
21
+
22
+ ### Production-Ready
23
+ - **High Performance**: Intelligent caching and batch operations
24
+ - **Data Integrity**: Built-in corruption detection and recovery
25
+ - **Schema Validation**: Flexible schema system with strict mode
26
+ - **Error Handling**: Comprehensive error handling and recovery
27
+ - **Memory Management**: Efficient memory usage with automatic cleanup
28
+
29
+ ### Enterprise Features
30
+ - **Cloud Backup**: AWS S3 and Cloudflare R2 support
31
+ - **Data Recovery**: Automatic crash recovery and cloud restore
32
+ - **Monitoring**: Performance metrics and health checks
33
+ - **Security**: Path traversal protection and input validation
34
+
35
+ ## ๐Ÿ“ฆ Installation
36
+
37
+ ```bash
38
+ npm install tero
39
+ ```
40
+
41
+ ## ๐Ÿ”ง Quick Start
42
+
43
+ ```javascript
44
+ import { Tero } from 'tero';
45
+
46
+ // Initialize database
47
+ const db = new Tero({
48
+ directory: './mydata',
49
+ cacheSize: 1000
50
+ });
51
+
52
+ // Basic operations
53
+ await db.create('user1', { name: 'Alice', email: 'alice@example.com' });
54
+ const user = await db.get('user1');
55
+ await db.update('user1', { age: 30 });
56
+ await db.remove('user1');
57
+ ```
58
+
59
+ ## ๐Ÿ”’ ACID Transactions
60
+
61
+ ### Automatic Transactions
62
+ All basic operations are automatically wrapped in ACID transactions:
63
+
64
+ ```javascript
65
+ // These operations are automatically ACID-compliant
66
+ await db.create('account', { balance: 1000 });
67
+ await db.update('account', { balance: 1500 });
68
+ ```
69
+
70
+ ### Manual Transactions
71
+ For complex operations requiring multiple steps:
72
+
73
+ ```javascript
74
+ const txId = db.beginTransaction();
75
+
76
+ try {
77
+ await db.write(txId, 'account1', { balance: 900 });
78
+ await db.write(txId, 'account2', { balance: 1100 });
79
+
80
+ // Verify within transaction
81
+ const account1 = await db.read(txId, 'account1');
82
+
83
+ await db.commit(txId);
84
+ } catch (error) {
85
+ await db.rollback(txId);
86
+ throw error;
87
+ }
88
+ ```
89
+
90
+ ### Money Transfer Example
91
+ Demonstrates ACID properties with business logic:
92
+
93
+ ```javascript
94
+ // Atomic money transfer with validation
95
+ await db.transferMoney('savings', 'checking', 500);
96
+ ```
97
+
98
+ ## ๐Ÿ“‹ Schema Validation
99
+
100
+ Define and enforce data schemas:
101
+
102
+ ```javascript
103
+ // Set schema
104
+ db.setSchema('users', {
105
+ name: { type: 'string', required: true, min: 2, max: 50 },
106
+ email: { type: 'string', required: true, format: 'email' },
107
+ age: { type: 'number', min: 0, max: 150 },
108
+ profile: {
109
+ type: 'object',
110
+ properties: {
111
+ bio: { type: 'string', max: 500 },
112
+ website: { type: 'string', format: 'url' }
113
+ }
114
+ }
115
+ });
116
+
117
+ // Create with validation
118
+ await db.create('user1', userData, {
119
+ validate: true,
120
+ schemaName: 'users',
121
+ strict: true
122
+ });
123
+ ```
124
+
125
+ ## ๐Ÿ“ฆ Batch Operations
126
+
127
+ Efficient batch processing with ACID guarantees:
128
+
129
+ ```javascript
130
+ // Batch write
131
+ await db.batchWrite([
132
+ { key: 'product1', data: { name: 'Laptop', price: 999.99 } },
133
+ { key: 'product2', data: { name: 'Mouse', price: 29.99 } },
134
+ { key: 'product3', data: { name: 'Keyboard', price: 79.99 } }
135
+ ]);
136
+
137
+ // Batch read
138
+ const products = await db.batchRead(['product1', 'product2', 'product3']);
139
+ ```
140
+
141
+ ## โ˜๏ธ Cloud Backup
142
+
143
+ Configure automatic cloud backups:
144
+
145
+ ```javascript
146
+ db.configureBackup({
147
+ format: 'archive',
148
+ cloudStorage: {
149
+ provider: 'aws-s3',
150
+ region: 'us-east-1',
151
+ bucket: 'my-backup-bucket',
152
+ accessKeyId: process.env.AWS_ACCESS_KEY_ID,
153
+ secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY
154
+ },
155
+ retention: '30d'
156
+ });
157
+
158
+ // Perform backup
159
+ const result = await db.performBackup();
160
+ ```
161
+
162
+ ## ๐Ÿ”„ Data Recovery
163
+
164
+ Automatic crash recovery and cloud restore:
165
+
166
+ ```javascript
167
+ // Configure data recovery
168
+ db.configureDataRecovery({
169
+ cloudStorage: cloudConfig,
170
+ localPath: './mydata'
171
+ });
172
+
173
+ // Recover specific file
174
+ await db.recoverFromCloud('important-data');
175
+
176
+ // Recover all files
177
+ const result = await db.recoverAllFromCloud();
178
+ ```
179
+
180
+ ## ๐Ÿ“Š Monitoring
181
+
182
+ Built-in performance monitoring and health checks:
183
+
184
+ ```javascript
185
+ // Cache performance
186
+ const cacheStats = db.getCacheStats();
187
+ console.log(`Cache hit rate: ${cacheStats.hitRate}%`);
188
+
189
+ // Data integrity check
190
+ const integrity = await db.verifyDataIntegrity();
191
+ if (!integrity.healthy) {
192
+ console.log(`Issues found: ${integrity.corruptedFiles.length} corrupted files`);
193
+ }
194
+
195
+ // Active transactions
196
+ const activeTx = db.getActiveTransactions();
197
+ console.log(`Active transactions: ${activeTx.length}`);
198
+ ```
199
+
200
+ ## ๐Ÿ›ก๏ธ Error Handling
201
+
202
+ Comprehensive error handling with detailed messages:
203
+
204
+ ```javascript
205
+ try {
206
+ await db.create('user', invalidData, { validate: true, strict: true });
207
+ } catch (error) {
208
+ if (error.message.includes('Schema validation failed')) {
209
+ // Handle validation error
210
+ } else if (error.message.includes('already exists')) {
211
+ // Handle duplicate key error
212
+ }
213
+ }
214
+ ```
215
+
216
+ ## ๐Ÿ”ง Configuration
217
+
218
+ ### Database Options
219
+ ```javascript
220
+ const db = new Tero({
221
+ directory: './data', // Database directory
222
+ cacheSize: 1000 // Maximum cache entries
223
+ });
224
+ ```
225
+
226
+ ### Schema Field Types
227
+ - `string`: Text data with length and format validation
228
+ - `number`: Numeric data with range validation
229
+ - `boolean`: True/false values
230
+ - `object`: Nested objects with property schemas
231
+ - `array`: Arrays with item type validation
232
+ - `date`: Date/time values
233
+ - `any`: Any data type (no validation)
234
+
235
+ ### Schema Validation Options
236
+ - `required`: Field is mandatory
237
+ - `min/max`: Length/value constraints
238
+ - `format`: Built-in formats (email, url, uuid, etc.)
239
+ - `pattern`: Regular expression validation
240
+ - `enum`: Allowed values list
241
+ - `default`: Default value if not provided
242
+ - `custom`: Custom validation function
243
+
244
+ ### Optimization Tips
245
+ 1. Use batch operations for multiple documents
246
+ 2. Enable caching for frequently accessed data
247
+ 3. Use schema validation to catch errors early
248
+ 4. Monitor cache hit rates and adjust cache size
249
+ 5. Use transactions for related operations
250
+
251
+ ## ๐Ÿ”’ Security
252
+
253
+ - **Path Traversal Protection**: Automatic key sanitization
254
+ - **Input Validation**: Comprehensive data validation
255
+ - **Error Handling**: No sensitive data in error messages
256
+ - **Access Control**: File system permissions respected
257
+
258
+ ## ๐Ÿ“š API Reference
259
+
260
+ ### Core Methods
261
+ - `create(key, data, options?)`: Create new document
262
+ - `get(key)`: Read document
263
+ - `update(key, data, options?)`: Update document
264
+ - `remove(key)`: Delete document
265
+ - `exists(key)`: Check if document exists
266
+
267
+ ### Transaction Methods
268
+ - `beginTransaction()`: Start new transaction
269
+ - `write(txId, key, data, options?)`: Write in transaction
270
+ - `read(txId, key)`: Read in transaction
271
+ - `delete(txId, key)`: Delete in transaction
272
+ - `commit(txId)`: Commit transaction
273
+ - `rollback(txId)`: Rollback transaction
274
+
275
+ ### Batch Methods
276
+ - `batchWrite(operations, options?)`: Batch write operations
277
+ - `batchRead(keys)`: Batch read operations
278
+
279
+ ### Schema Methods
280
+ - `setSchema(name, schema)`: Define schema
281
+ - `getSchema(name)`: Get schema definition
282
+ - `removeSchema(name)`: Remove schema
283
+ - `validateData(name, data)`: Validate against schema
284
+
285
+ ### Utility Methods
286
+ - `getCacheStats()`: Cache performance metrics
287
+ - `verifyDataIntegrity()`: Check data health
288
+ - `getActiveTransactions()`: List active transactions
289
+ - `forceCheckpoint()`: Force WAL flush
290
+ - `clearCache()`: Clear memory cache
291
+ - `destroy()`: Cleanup and shutdown
292
+
293
+ ## ๐Ÿงช Testing
294
+
295
+ Run the production test suite:
296
+
297
+ ```bash
298
+ npm run test:production
299
+ ```
300
+
301
+ ## ๐Ÿ“„ License
302
+
303
+ MIT License - see LICENSE file for details.
304
+
305
+ ## ๐Ÿค Contributing
306
+
307
+ 1. Fork the repository
308
+ 2. Create a feature branch
309
+ 3. Add tests for new functionality
310
+ 4. Ensure all tests pass
311
+ 5. Submit a pull request
312
+
313
+ ## ๐Ÿ“ž Support
314
+
315
+ For issues and questions:
316
+ - GitHub Issues: [Report bugs and request features](https://github.com/codedynasty-dev/tero/issues)
317
+ - Documentation: [Full API documentation](https://github.com/codedynasty-dev/tero/wiki)
318
+
319
+ ---
320
+
321
+ **Tero** - Production-ready ACID JSON database for modern applications.