tero 0.0.5 → 0.0.7
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 +199 -225
- package/dist/acid-engine.d.ts +214 -13
- package/dist/acid-engine.js +786 -282
- package/dist/backup.d.ts +31 -0
- package/dist/backup.js +137 -15
- package/dist/index.d.ts +268 -8
- package/dist/index.js +704 -71
- package/dist/recovery.d.ts +14 -0
- package/dist/recovery.js +100 -17
- package/package.json +5 -2
package/README.md
CHANGED
|
@@ -1,347 +1,321 @@
|
|
|
1
1
|
# Tero
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
[
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
- **
|
|
18
|
-
- **
|
|
19
|
-
- **
|
|
20
|
-
- **
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
-
|
|
26
|
-
-
|
|
27
|
-
-
|
|
28
|
-
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
## Installation
|
|
3
|
+
An embedded ACID JSON database for the edge. Single-node durability via fsync-on-commit; cloud durability via S3/R2/GCS storage.
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
[edge Tero node] --WAL+snapshot--> [S3/R2/GCS bucket]
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Tero is a **library**, not a service. You embed it in a worker, container, or edge runtime. There is no clustering, no Raft, no distributed consensus — by design. Durability and scale come from cheap object storage, the same pattern Litestream pioneered for SQLite.
|
|
10
|
+
|
|
11
|
+
## What it is
|
|
12
|
+
|
|
13
|
+
- **Embedded JSON document DB** with key/value + batch operations
|
|
14
|
+
- **Real ACID**: WAL with fsync barriers on COMMIT/ROLLBACK, atomic data-file writes (temp → rename → fsync), in-memory pending-writes index so transaction reads never re-scan the WAL
|
|
15
|
+
- **WAL rotation** into archive segments — backs up WAL segments and snapshots to object storage
|
|
16
|
+
- **Schema validation** with strict mode (string/number/boolean/object/array/date/any, formats, enums, defaults, custom validators)
|
|
17
|
+
- **Cloud backup** to AWS S3 or Cloudflare R2 (cron-scheduled), archive or individual-file format
|
|
18
|
+
- **Cloud recovery** — full, single-file, or archive restore
|
|
19
|
+
- **v2: hydrate on startup** — pull missing or all files from object storage before the ACID engine initializes to reconstruct node state
|
|
20
|
+
- **v2: bucket backup** — one-shot snapshot of all data files + retained WAL segments + a manifest that hydrate-on-startup can discover
|
|
21
|
+
- **Per-instance cloud credentials** — each Tero instance manages its own storage credentials directly
|
|
22
|
+
|
|
23
|
+
## What it is not
|
|
24
|
+
|
|
25
|
+
- Not a server. No HTTP layer, no wire protocol. You embed it.
|
|
26
|
+
- Not distributed. No multi-node consensus. Global durability is the bucket's job.
|
|
27
|
+
- Not a query engine. Key/value + batch. No SQL, no indexes beyond the in-memory cache.
|
|
28
|
+
- Not horizontally scalable beyond one node's filesystem. One file per document puts a practical ceiling around 10⁵–10⁶ docs per node; the bucket is what scales.
|
|
29
|
+
|
|
30
|
+
These are deliberate design choices to keep Tero lightweight and fast inside edge worker runtimes while using object storage for global durability.
|
|
31
|
+
|
|
32
|
+
## Install
|
|
34
33
|
|
|
35
34
|
```bash
|
|
36
35
|
npm install tero
|
|
37
36
|
```
|
|
38
37
|
|
|
39
|
-
##
|
|
38
|
+
## Quick start
|
|
40
39
|
|
|
41
40
|
```javascript
|
|
42
41
|
import { Tero } from 'tero';
|
|
43
42
|
|
|
44
|
-
// Initialize database
|
|
45
43
|
const db = new Tero({
|
|
46
44
|
directory: './mydata',
|
|
47
|
-
cacheSize: 1000
|
|
45
|
+
cacheSize: 1000,
|
|
48
46
|
});
|
|
49
47
|
|
|
50
|
-
// Basic operations
|
|
51
48
|
await db.create('user1', { name: 'Alice', email: 'alice@example.com' });
|
|
52
49
|
const user = await db.get('user1');
|
|
53
50
|
await db.update('user1', { age: 30 });
|
|
54
51
|
await db.remove('user1');
|
|
55
52
|
```
|
|
56
53
|
|
|
57
|
-
## ACID
|
|
58
|
-
|
|
59
|
-
### Automatic Transactions
|
|
60
|
-
All basic operations are automatically wrapped in ACID transactions:
|
|
61
|
-
|
|
62
|
-
```javascript
|
|
63
|
-
// These operations are automatically ACID-compliant
|
|
64
|
-
await db.create('account', { balance: 1000 });
|
|
65
|
-
await db.update('account', { balance: 1500 });
|
|
66
|
-
```
|
|
54
|
+
## ACID transactions
|
|
67
55
|
|
|
68
|
-
|
|
69
|
-
For complex operations requiring multiple steps:
|
|
56
|
+
Every convenience method (`create`, `get`, `update`, `remove`) is auto-wrapped in a transaction. For multi-step operations, use explicit transactions:
|
|
70
57
|
|
|
71
58
|
```javascript
|
|
72
|
-
const
|
|
59
|
+
const tx = db.beginTransaction();
|
|
73
60
|
|
|
74
61
|
try {
|
|
75
|
-
await db.write(
|
|
76
|
-
await db.write(
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
const account1 = await db.read(txId, 'account1');
|
|
80
|
-
|
|
81
|
-
await db.commit(txId);
|
|
62
|
+
await db.write(tx, 'account1', { balance: 900 });
|
|
63
|
+
await db.write(tx, 'account2', { balance: 1100 });
|
|
64
|
+
const a = await db.read(tx, 'account1'); // reads pending state within the tx
|
|
65
|
+
await db.commit(tx);
|
|
82
66
|
} catch (error) {
|
|
83
|
-
await db.rollback(
|
|
67
|
+
await db.rollback(tx);
|
|
84
68
|
throw error;
|
|
85
69
|
}
|
|
86
70
|
```
|
|
87
71
|
|
|
88
|
-
|
|
89
|
-
Demonstrates ACID properties with business logic:
|
|
72
|
+
The money-transfer example demonstrates atomicity: `db.transferMoney('savings', 'checking', 500)` — both balances update or neither does, with the writer held to a durable commit before control returns.
|
|
90
73
|
|
|
91
|
-
|
|
92
|
-
// Atomic money transfer with validation
|
|
93
|
-
await db.transferMoney('savings', 'checking', 500);
|
|
94
|
-
```
|
|
74
|
+
### Durability guarantee
|
|
95
75
|
|
|
96
|
-
|
|
76
|
+
A `commit()` returns only after the WAL `COMMIT` record and all pending writes have been fsynced to disk. A crash after `commit()` returns cannot lose the transaction. A crash mid-`commit()` leaves either the old or new state on disk, never a partial of either — data files are written via temp-file → fsync → atomic rename.
|
|
97
77
|
|
|
98
|
-
|
|
78
|
+
## Schema validation
|
|
99
79
|
|
|
100
80
|
```javascript
|
|
101
|
-
// Set schema
|
|
102
81
|
db.setSchema('users', {
|
|
103
|
-
name:
|
|
82
|
+
name: { type: 'string', required: true, min: 2, max: 50 },
|
|
104
83
|
email: { type: 'string', required: true, format: 'email' },
|
|
105
|
-
age:
|
|
84
|
+
age: { type: 'number', min: 0, max: 150 },
|
|
106
85
|
profile: {
|
|
107
86
|
type: 'object',
|
|
108
87
|
properties: {
|
|
109
|
-
bio:
|
|
110
|
-
website: { type: 'string', format: 'url' }
|
|
111
|
-
}
|
|
112
|
-
}
|
|
88
|
+
bio: { type: 'string', max: 500 },
|
|
89
|
+
website: { type: 'string', format: 'url' },
|
|
90
|
+
},
|
|
91
|
+
},
|
|
113
92
|
});
|
|
114
93
|
|
|
115
|
-
|
|
116
|
-
await db.create('user1', userData, {
|
|
117
|
-
validate: true,
|
|
118
|
-
schemaName: 'users',
|
|
119
|
-
strict: true
|
|
120
|
-
});
|
|
94
|
+
await db.create('user1', userData, { validate: true, schemaName: 'users', strict: true });
|
|
121
95
|
```
|
|
122
96
|
|
|
123
|
-
|
|
97
|
+
Field types: `string`, `number`, `boolean`, `object`, `array`, `date`, `any`.
|
|
98
|
+
Validation options: `required`, `min`, `max`, `format` (email/url/uuid/date/time/datetime/phone/ip), `pattern`, `enum`, `default`, `custom`.
|
|
124
99
|
|
|
125
|
-
|
|
100
|
+
## Batch operations
|
|
126
101
|
|
|
127
102
|
```javascript
|
|
128
|
-
// Batch write
|
|
129
103
|
await db.batchWrite([
|
|
130
|
-
{ key: 'product1', data: { name: 'Laptop',
|
|
131
|
-
{ key: 'product2', data: { name: 'Mouse',
|
|
132
|
-
{ key: 'product3', data: { name: 'Keyboard', price: 79.99 } }
|
|
104
|
+
{ key: 'product1', data: { name: 'Laptop', price: 999.99 } },
|
|
105
|
+
{ key: 'product2', data: { name: 'Mouse', price: 29.99 } },
|
|
106
|
+
{ key: 'product3', data: { name: 'Keyboard', price: 79.99 } },
|
|
133
107
|
]);
|
|
134
108
|
|
|
135
|
-
// Batch read
|
|
136
109
|
const products = await db.batchRead(['product1', 'product2', 'product3']);
|
|
137
110
|
```
|
|
138
111
|
|
|
139
|
-
##
|
|
140
|
-
|
|
141
|
-
Configure automatic cloud backups:
|
|
112
|
+
## Cloud backup
|
|
142
113
|
|
|
143
114
|
```javascript
|
|
144
115
|
db.configureBackup({
|
|
145
|
-
format: 'archive',
|
|
116
|
+
format: 'archive', // or 'individual' for per-file backups
|
|
146
117
|
cloudStorage: {
|
|
147
118
|
provider: 'aws-s3',
|
|
148
119
|
region: 'us-east-1',
|
|
149
120
|
bucket: 'my-backup-bucket',
|
|
150
121
|
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
|
|
151
|
-
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY
|
|
122
|
+
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
|
|
152
123
|
},
|
|
153
|
-
retention: '30d'
|
|
124
|
+
retention: '30d',
|
|
154
125
|
});
|
|
155
126
|
|
|
156
|
-
// Perform backup
|
|
157
127
|
const result = await db.performBackup();
|
|
128
|
+
const scheduleId = db.scheduleBackup({ interval: '6h', retention: '7d' });
|
|
129
|
+
db.cancelScheduledBackup(scheduleId);
|
|
158
130
|
```
|
|
159
131
|
|
|
160
|
-
|
|
132
|
+
Tero interacts directly with object storage from each instance, keeping credentials local and isolated.
|
|
161
133
|
|
|
162
|
-
|
|
134
|
+
## Cloud recovery
|
|
163
135
|
|
|
164
136
|
```javascript
|
|
165
|
-
// Configure data recovery
|
|
166
137
|
db.configureDataRecovery({
|
|
167
138
|
cloudStorage: cloudConfig,
|
|
168
|
-
localPath: './mydata'
|
|
139
|
+
localPath: './mydata',
|
|
140
|
+
autoRecover: true,
|
|
169
141
|
});
|
|
170
142
|
|
|
171
|
-
//
|
|
172
|
-
await db.
|
|
173
|
-
|
|
174
|
-
//
|
|
175
|
-
const result = await db.recoverAllFromCloud();
|
|
143
|
+
await db.recoverFromCloud('important-data'); // one file
|
|
144
|
+
const result = await db.recoverAllFromCloud(); // all files
|
|
145
|
+
const archives = await db.listAvailableArchives(); // discover tar.gz backups
|
|
146
|
+
const info = await db.getRecoveryInfo(); // local vs cloud diff
|
|
176
147
|
```
|
|
177
148
|
|
|
178
|
-
##
|
|
149
|
+
## v2: hydrate on startup
|
|
179
150
|
|
|
180
|
-
|
|
151
|
+
`Tero.create()` is the async factory that pulls missing/all files from object storage **before** the ACID engine runs crash recovery — so a fresh node boots with the latest durable state.
|
|
181
152
|
|
|
182
153
|
```javascript
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
//
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
email: 'alice@example.com',
|
|
192
|
-
createdAt: new Date()
|
|
154
|
+
const db = await Tero.create({
|
|
155
|
+
directory: './mydata',
|
|
156
|
+
hydrateOnStartup: {
|
|
157
|
+
cloudStorage: cloudConfig,
|
|
158
|
+
mode: 'missing', // 'all' overwrites local; 'missing' only pulls absent files
|
|
159
|
+
continueOnError: true, // don't block boot on a single failed download
|
|
160
|
+
timeout: 30000,
|
|
161
|
+
},
|
|
193
162
|
});
|
|
194
163
|
|
|
195
|
-
//
|
|
196
|
-
|
|
197
|
-
await db.
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
164
|
+
// Or run hydration any time after construction:
|
|
165
|
+
db.configureDataRecovery({ cloudStorage: cloudConfig, localPath: './mydata' });
|
|
166
|
+
await db.hydrate({ mode: 'missing' });
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
Hydration is non-fatal by design: an unreachable or misconfigured bucket will not block engine startup. The local filesystem remains the source of truth.
|
|
170
|
+
|
|
171
|
+
## v2: bucket backup with WAL segments
|
|
172
|
+
|
|
173
|
+
`backupToBucket()` snapshots every data JSON file plus any retained WAL archive segments and writes a manifest the hydrate path can discover:
|
|
174
|
+
|
|
175
|
+
```javascript
|
|
176
|
+
const result = await db.backupToBucket({ tag: 'hourly-snapshot' });
|
|
177
|
+
// result: { success, uploadedDataFiles, uploadedWALSegments, duration, errors }
|
|
178
|
+
|
|
179
|
+
// Force a fresh WAL archive segment first, then back it up:
|
|
180
|
+
await db.checkpointAndBackupToBucket({ tag: 'post-burst' });
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
This enables point-in-time recovery: rotate the WAL into a new immutable segment, push it to object storage, and a rehydrated node can replay from that segment forward.
|
|
184
|
+
|
|
185
|
+
## v2: read with cloud fallback
|
|
186
|
+
|
|
187
|
+
```javascript
|
|
188
|
+
const data = await db.getWithRecovery('maybe-missing');
|
|
189
|
+
// returns the document from local or, if absent locally, fetches from the bucket.
|
|
190
|
+
// returns false if absent on both sides. does not throw on cloud failure —
|
|
191
|
+
// use recoverFromCloud() if you need to see those errors.
|
|
192
|
+
|
|
193
|
+
const probe = await db.existsWithCloudCheck('user1');
|
|
194
|
+
// { local: true, cloud: true, canRecover: false }
|
|
202
195
|
```
|
|
203
196
|
|
|
204
|
-
##
|
|
197
|
+
## Unique ID generation
|
|
205
198
|
|
|
206
|
-
|
|
199
|
+
MongoDB ObjectId-style identifiers, unique across processes and time:
|
|
207
200
|
|
|
208
201
|
```javascript
|
|
209
|
-
|
|
210
|
-
const
|
|
211
|
-
|
|
212
|
-
|
|
202
|
+
const userId = db.getNewId('user'); // user-507f1f77bcf86cd799439011
|
|
203
|
+
const orderId = db.getNewId('order'); // order-507f1f77bcf86cd799439012
|
|
204
|
+
await db.create(userId, { name: 'Alice' });
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
Composition: 4-byte timestamp + 5-byte process-unique random + 3-byte incrementing counter.
|
|
213
208
|
|
|
214
|
-
|
|
209
|
+
## Monitoring
|
|
210
|
+
|
|
211
|
+
```javascript
|
|
212
|
+
const cache = db.getCacheStats(); // { size, maxSize, hitRate }
|
|
213
|
+
const tx = db.getTransactionStats(); // { active, committed, rolledBack, total }
|
|
215
214
|
const integrity = await db.verifyDataIntegrity();
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
215
|
+
// { totalFiles, corruptedFiles, missingFiles, healthy }
|
|
216
|
+
const active = db.getActiveTransactions();
|
|
217
|
+
db.forceCheckpoint(); // flush a CHECKPOINT into the WAL
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
## Architecture
|
|
219
221
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
222
|
+
```
|
|
223
|
+
Tero instance (one per process)
|
|
224
|
+
├── ACIDStorageEngine
|
|
225
|
+
│ ├── WriteAheadLog ─── append-only, fsync on barriers, rotates to archive segments
|
|
226
|
+
│ ├── LockManager ─── per-key shared/exclusive locks with wait queue
|
|
227
|
+
│ └── pendingWrites ─── in-memory per-transaction op index (O(1) reads within a tx)
|
|
228
|
+
├── SchemaValidator
|
|
229
|
+
├── BackupManager ─── cron-scheduled snapshot + WAL segment upload to object storage
|
|
230
|
+
└── DataRecovery ─── hydrate-on-startup + runtime getWithRecovery
|
|
223
231
|
```
|
|
224
232
|
|
|
225
|
-
## Error Handling
|
|
226
233
|
|
|
227
|
-
|
|
234
|
+
## Error handling
|
|
228
235
|
|
|
229
236
|
```javascript
|
|
230
237
|
try {
|
|
231
238
|
await db.create('user', invalidData, { validate: true, strict: true });
|
|
232
239
|
} catch (error) {
|
|
233
|
-
if (error.message.includes('Schema validation failed')) {
|
|
234
|
-
|
|
235
|
-
} else if (error.message.includes('already exists')) {
|
|
236
|
-
// Handle duplicate key error
|
|
237
|
-
}
|
|
240
|
+
if (error.message.includes('Schema validation failed')) { /* validation error */ }
|
|
241
|
+
else if (error.message.includes('already exists')) { /* duplicate key */ }
|
|
238
242
|
}
|
|
239
243
|
```
|
|
240
244
|
|
|
241
|
-
|
|
245
|
+
Keys are validated to prevent path traversal (`..`, `/`, `\` are rejected).
|
|
246
|
+
|
|
247
|
+
## Configuration
|
|
242
248
|
|
|
243
|
-
### Database Options
|
|
244
249
|
```javascript
|
|
245
250
|
const db = new Tero({
|
|
246
|
-
directory: './data', //
|
|
247
|
-
cacheSize: 1000
|
|
251
|
+
directory: './data', // default: 'TeroDB'
|
|
252
|
+
cacheSize: 1000, // default: 100, capped at 1000
|
|
253
|
+
backup: { ... }, // optional: install a BackupConfig at construction
|
|
254
|
+
hydrateOnStartup: { ... }, // optional: v2 hydration before engine init
|
|
248
255
|
});
|
|
249
256
|
```
|
|
250
257
|
|
|
251
|
-
### Schema Field Types
|
|
252
|
-
- `string`: Text data with length and format validation
|
|
253
|
-
- `number`: Numeric data with range validation
|
|
254
|
-
- `boolean`: True/false values
|
|
255
|
-
- `object`: Nested objects with property schemas
|
|
256
|
-
- `array`: Arrays with item type validation
|
|
257
|
-
- `date`: Date/time values
|
|
258
|
-
- `any`: Any data type (no validation)
|
|
259
|
-
|
|
260
|
-
### Schema Validation Options
|
|
261
|
-
- `required`: Field is mandatory
|
|
262
|
-
- `min/max`: Length/value constraints
|
|
263
|
-
- `format`: Built-in formats (email, url, uuid, etc.)
|
|
264
|
-
- `pattern`: Regular expression validation
|
|
265
|
-
- `enum`: Allowed values list
|
|
266
|
-
- `default`: Default value if not provided
|
|
267
|
-
- `custom`: Custom validation function
|
|
268
|
-
|
|
269
|
-
### Optimization Tips
|
|
270
|
-
1. Use batch operations for multiple documents
|
|
271
|
-
2. Enable caching for frequently accessed data
|
|
272
|
-
3. Use schema validation to catch errors early
|
|
273
|
-
4. Monitor cache hit rates and adjust cache size
|
|
274
|
-
5. Use transactions for related operations
|
|
275
|
-
|
|
276
|
-
## Security
|
|
277
|
-
|
|
278
|
-
- **Path Traversal Protection**: Automatic key sanitization
|
|
279
|
-
- **Input Validation**: Comprehensive data validation
|
|
280
|
-
- **Error Handling**: No sensitive data in error messages
|
|
281
|
-
- **Access Control**: File system permissions respected
|
|
282
|
-
|
|
283
|
-
## API Reference
|
|
284
|
-
|
|
285
|
-
### Core Methods
|
|
286
|
-
- `create(key, data, options?)`: Create new document
|
|
287
|
-
- `get(key)`: Read document
|
|
288
|
-
- `update(key, data, options?)`: Update document
|
|
289
|
-
- `remove(key)`: Delete document
|
|
290
|
-
- `exists(key)`: Check if document exists
|
|
291
|
-
|
|
292
|
-
### Transaction Methods
|
|
293
|
-
- `beginTransaction()`: Start new transaction
|
|
294
|
-
- `write(txId, key, data, options?)`: Write in transaction
|
|
295
|
-
- `read(txId, key)`: Read in transaction
|
|
296
|
-
- `delete(txId, key)`: Delete in transaction
|
|
297
|
-
- `commit(txId)`: Commit transaction
|
|
298
|
-
- `rollback(txId)`: Rollback transaction
|
|
299
|
-
|
|
300
|
-
### Batch Methods
|
|
301
|
-
- `batchWrite(operations, options?)`: Batch write operations
|
|
302
|
-
- `batchRead(keys)`: Batch read operations
|
|
303
|
-
|
|
304
|
-
### Schema Methods
|
|
305
|
-
- `setSchema(name, schema)`: Define schema
|
|
306
|
-
- `getSchema(name)`: Get schema definition
|
|
307
|
-
- `removeSchema(name)`: Remove schema
|
|
308
|
-
- `validateData(name, data)`: Validate against schema
|
|
309
|
-
|
|
310
|
-
### Utility Methods
|
|
311
|
-
- `getCacheStats()`: Cache performance metrics
|
|
312
|
-
- `verifyDataIntegrity()`: Check data health
|
|
313
|
-
- `getActiveTransactions()`: List active transactions
|
|
314
|
-
- `forceCheckpoint()`: Force WAL flush
|
|
315
|
-
- `clearCache()`: Clear memory cache
|
|
316
|
-
- `getNewId(prefix)`: Generate unique identifiers with custom prefix
|
|
317
|
-
- `destroy()`: Cleanup and shutdown
|
|
318
|
-
|
|
319
258
|
## Testing
|
|
320
259
|
|
|
321
|
-
Run the production test suite:
|
|
322
|
-
|
|
323
260
|
```bash
|
|
324
|
-
npm run test
|
|
261
|
+
npm run build # tsc + full test suite
|
|
262
|
+
npm run test # full suite (includes the ~60s benchmark)
|
|
263
|
+
npm run test:production # ACID + schema + transactions + perf
|
|
264
|
+
npm run test:backup # backup + scheduling + retention
|
|
265
|
+
npm run test:schema # schema validation
|
|
266
|
+
npm run test:legacy # legacy suite
|
|
267
|
+
node local_tests/v2-test.js # v2: hydrate + bucket backup surface
|
|
325
268
|
```
|
|
326
269
|
|
|
270
|
+
## Performance characteristics
|
|
271
|
+
|
|
272
|
+
```
|
|
273
|
+
normal mode (recommended production — group commit 10ms + deferred data flush):
|
|
274
|
+
Single create: ~10,000–14,000 ops/s
|
|
275
|
+
Update (same key): ~51,000 ops/s
|
|
276
|
+
Batch (100 docs/tx): ~47,000 docs/s
|
|
277
|
+
Hot read (cached): ~1,000,000 ops/s
|
|
278
|
+
exists(): ~1,000,000 ops/s
|
|
279
|
+
|
|
280
|
+
full mode (fsync per commit — max durability):
|
|
281
|
+
Single create: ~45 ops/s
|
|
282
|
+
Batch (100 docs/tx): ~4,000 docs/s
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
- **synchronous: 'full'** (default) — fsync per commit. Max durability. Use when every commit must survive power loss.
|
|
286
|
+
- **synchronous: 'normal'** — group commit + deferred data flush. WAL is fsynced every 10ms (configurable via `commitIntervalMs`); data files checkpoint every 50ms (configurable via `dataFlushIntervalMs`). 200x+ throughput vs full mode. WAL sync window is up to 10ms of writes. This is the SQLite `PRAGMA synchronous=NORMAL` equivalent.
|
|
287
|
+
- **synchronous: 'off'** — never fsync. Testing/benchmark only.
|
|
288
|
+
|
|
289
|
+
Architecture:
|
|
290
|
+
- In-memory WAL write buffer — one `appendFileSync` per flush, not per entry
|
|
291
|
+
- FNV-1a hash for WAL integrity (100x faster than SHA-256 for small entries)
|
|
292
|
+
- Deferred data-file writes via `committedBuffer` + background timer (SQLite WAL-mode pattern)
|
|
293
|
+
- Transaction-free `get()` fast path: LRU cache → committedBuffer → disk (zero syscalls on cache hit)
|
|
294
|
+
- `knownKeys` Set replaces `existsSync()` on the hot path
|
|
295
|
+
- Per-tx `heldLocks` Set for O(1) lock release (was O(allLocks))
|
|
296
|
+
- Per-tx `txTouchedKeys` Set for O(touched) cache promotion (was O(cacheSize))
|
|
297
|
+
- Sync `commitTransaction()` / `rollbackTransaction()` — no async overhead on the happy path
|
|
298
|
+
- Lock manager returns `true` (sync) instead of `Promise` on the uncontended fast path
|
|
299
|
+
- WAL rotation at 1 MB or every 500 commits, keeping recovery replays bounded
|
|
300
|
+
|
|
301
|
+
This is single-node throughput, not cluster throughput. For higher write rates, run multiple Tero instances behind a sharding layer; each owns its own bucket and directory.
|
|
302
|
+
|
|
327
303
|
## License
|
|
328
304
|
|
|
329
|
-
MIT
|
|
305
|
+
MIT — see [LICENSE](./LICENSE).
|
|
330
306
|
|
|
331
|
-
##
|
|
307
|
+
## Contributing
|
|
332
308
|
|
|
333
|
-
1. Fork the
|
|
309
|
+
1. Fork the repo
|
|
334
310
|
2. Create a feature branch
|
|
335
|
-
3. Add tests for new functionality
|
|
336
|
-
4. Ensure
|
|
337
|
-
5.
|
|
311
|
+
3. Add tests in `local_tests/` for new functionality
|
|
312
|
+
4. Ensure `npm run build` is green
|
|
313
|
+
5. Open a pull request
|
|
338
314
|
|
|
339
|
-
##
|
|
315
|
+
## Support
|
|
340
316
|
|
|
341
|
-
|
|
342
|
-
- GitHub Issues: [Report bugs and request features](https://github.com/codedynasty-dev/tero/issues)
|
|
343
|
-
- Documentation: [Full API documentation](https://github.com/codedynasty-dev/tero/wiki)
|
|
317
|
+
- GitHub Issues: https://github.com/codedynasty-dev/tero/issues
|
|
344
318
|
|
|
345
319
|
---
|
|
346
320
|
|
|
347
|
-
**Tero**
|
|
321
|
+
**Tero** — embedded ACID JSON for the edge.
|