@liorandb/core 1.0.7 → 1.0.8

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 (3) hide show
  1. package/LICENSE.md +1 -1
  2. package/README.md +155 -132
  3. package/package.json +1 -1
package/LICENSE.md CHANGED
@@ -1,4 +1,4 @@
1
- LIORANDB LICENSE
1
+ LDEP LICENSE
2
2
 
3
3
  Copyright (c) 2025 Swaraj Puppalwar
4
4
  All rights reserved.
package/README.md CHANGED
@@ -1,27 +1,34 @@
1
1
  # @liorandb/core
2
2
 
3
- **LioranDB Core Module** Lightweight, local-first, peer-to-peer database management for Node.js.
3
+ **LioranDB Core** is a lightweight, encrypted, TypeScript-first embedded database engine for Node.js.
4
4
 
5
- This is the **core system-level module** of LioranDB. It provides foundational database management functionality, including collections, queries, updates, encryption, and environment setup. **Note:** This is not the final database product, but a core module designed to be used in larger systems.
5
+ Think of it as:
6
6
 
7
- ---
7
+ * ⚡ **LevelDB speed** (powered by `classic-level`)
8
+ * 🔐 **Built-in encryption** (transparent at rest)
9
+ * 🧠 **Mongo-like API** (collections, queries, updates)
10
+ * 📦 **Zero external services** (no server, no daemon)
11
+ * 🧩 **Type-safe by design** (written 100% in TypeScript)
12
+
13
+ Perfect for:
14
+
15
+ * Local-first apps
16
+ * Desktop / CLI tools
17
+ * Edge & serverless experiments
18
+ * P2P & offline-sync systems
8
19
 
9
- ## Table of Contents
20
+ ---
10
21
 
11
- * [Installation](#installation)
12
- * [Overview](#overview)
13
- * [Getting Started](#getting-started)
14
- * [API Reference](#api-reference)
22
+ ## Features
15
23
 
16
- * [LioranManager](#lioranmanager)
17
- * [LioranDB](#liorandb)
18
- * [Collection](#collection)
19
- * [Query Operators](#query-operators)
20
- * [Update Operators](#update-operators)
21
- * [Utilities](#utilities)
22
- * [Encryption](#encryption)
23
- * [Environment Setup](#environment-setup)
24
- * [License](#license)
24
+ * 📂 Multiple databases under one manager
25
+ * 📁 Multiple collections per database
26
+ * 🔑 Optional encryption (AES-based, transparent)
27
+ * 🧵 Write-queue for consistency (no race conditions)
28
+ * 🧠 Simple query matching
29
+ * 🧩 Strong TypeScript inference
30
+ * 🚫 No native bindings
31
+ * 🚀 Fast startup & low memory
25
32
 
26
33
  ---
27
34
 
@@ -31,194 +38,210 @@ This is the **core system-level module** of LioranDB. It provides foundational d
31
38
  npm install @liorandb/core
32
39
  ```
33
40
 
34
- > Node.js v18+ recommended.
35
-
36
41
  ---
37
42
 
38
- ## Overview
43
+ ## Quick Start (30 seconds)
39
44
 
40
- `@liorandb/core` provides:
45
+ ```ts
46
+ import { LioranManager } from "@liorandb/core"
41
47
 
42
- * Local-first, file-based database directories.
43
- * MongoDB-style API (`db`, `collection`, `insertOne`, `find`, `updateOne`, etc.).
44
- * Peer-to-peer-friendly design.
45
- * Data encryption at rest.
46
- * Automatic environment configuration.
47
- * TypeScript typings for full developer support.
48
+ const manager = new LioranManager({
49
+ encryptionKey: "my-secret-key"
50
+ })
48
51
 
49
- This module is intended for **Node.js projects** and can serve as the core database engine for larger LioranDB systems.
52
+ const db = await manager.db("app")
50
53
 
51
- ---
54
+ const users = db.collection<{ name: string; age: number }>("users")
52
55
 
53
- ## Getting Started
56
+ await users.insertOne({ name: "Swaraj", age: 17 })
54
57
 
55
- ```javascript
56
- import { LioranManager } from "@liorandb/core";
58
+ const result = await users.find({ name: "Swaraj" })
59
+ console.log(result)
60
+ ```
57
61
 
58
- async function main() {
59
- const manager = new LioranManager();
60
- const db = await manager.db("myDatabase");
62
+ No config. No server. Just code.
61
63
 
62
- const users = db.collection("users");
64
+ ---
63
65
 
64
- // Insert a document
65
- const user = await users.insertOne({ name: "Alice", age: 25 });
66
+ ## Core Concepts
66
67
 
67
- // Query documents
68
- const results = await users.find({ age: { $gte: 18 } });
68
+ ### 1️⃣ LioranManager
69
69
 
70
- console.log(results);
71
- }
70
+ The **root controller**. Manages databases, encryption and lifecycle.
72
71
 
73
- main();
72
+ ```ts
73
+ const manager = new LioranManager({
74
+ rootPath: "./data", // optional
75
+ encryptionKey: "secret" // optional
76
+ })
74
77
  ```
75
78
 
76
- ---
79
+ Responsibilities:
77
80
 
78
- ## API Reference
81
+ * Creates databases
82
+ * Opens databases
83
+ * Tracks open instances
84
+ * Applies encryption globally
79
85
 
80
- ### LioranManager
86
+ ---
81
87
 
82
- Manages databases and provides MongoDB-style client access.
88
+ ### 2️⃣ Database
89
+
90
+ Each database is a **folder on disk**.
83
91
 
84
92
  ```ts
85
- class LioranManager {
86
- rootPath: string;
87
- db(name: string): Promise<LioranDB>;
88
- createDatabase(name: string): Promise<LioranDB>;
89
- openDatabase(name: string): Promise<LioranDB>;
90
- closeDatabase(name: string): Promise<void>;
91
- renameDatabase(oldName: string, newName: string): Promise<boolean>;
92
- deleteDatabase(name: string): Promise<boolean>;
93
- dropDatabase(name: string): Promise<boolean>;
94
- listDatabases(): Promise<string[]>;
95
- }
93
+ const db = await manager.db("mydb")
96
94
  ```
97
95
 
98
- **Example:**
96
+ * Databases are created automatically if missing
97
+ * Re-opening returns the same instance
99
98
 
100
- ```javascript
101
- const manager = new LioranManager();
102
- await manager.createDatabase("testDB");
103
- const db = await manager.db("testDB");
104
- ```
99
+ ---
105
100
 
106
- ### LioranDB
101
+ ### 3️⃣ Collections
107
102
 
108
- Represents a single database instance with multiple collections.
103
+ Collections are **LevelDB instances** stored inside the database.
109
104
 
110
105
  ```ts
111
- class LioranDB {
112
- basePath: string;
113
- dbName: string;
114
- collection<T>(name: string): Collection<T>;
115
- createCollection(name: string): Promise<boolean>;
116
- deleteCollection(name: string): Promise<boolean>;
117
- dropCollection(name: string): Promise<boolean>;
118
- renameCollection(oldName: string, newName: string): Promise<boolean>;
119
- listCollections(): Promise<string[]>;
120
- }
106
+ const posts = db.collection<{ title: string; views: number }>("posts")
121
107
  ```
122
108
 
123
- **Example:**
109
+ * One folder per collection
110
+ * Fully typed
111
+ * JSON documents only
112
+
113
+ ---
114
+
115
+ ## Collection API
124
116
 
125
- ```javascript
126
- const users = db.collection("users");
127
- await db.createCollection("products");
128
- const collections = await db.listCollections();
117
+ ### insertOne
118
+
119
+ ```ts
120
+ await users.insertOne({ name: "Alex", age: 22 })
129
121
  ```
130
122
 
131
- ### Collection
123
+ * Auto-generates `_id`
124
+ * `_id` can be provided manually
132
125
 
133
- Handles documents within a database.
126
+ ---
127
+
128
+ ### find
134
129
 
135
130
  ```ts
136
- class Collection<T extends { _id?: string }> {
137
- insertOne(doc: T): Promise<T>;
138
- insertMany(docs: T[]): Promise<T[]>;
139
- find(query?: FilterQuery<T>): Promise<T[]>;
140
- findOne(query?: FilterQuery<T>): Promise<T | null>;
141
- updateOne(filter: FilterQuery<T>, update: UpdateQuery<T>, options?: { upsert?: boolean }): Promise<T | null>;
142
- updateMany(filter: FilterQuery<T>, update: UpdateQuery<T>): Promise<T[]>;
143
- deleteOne(filter: FilterQuery<T>): Promise<boolean>;
144
- deleteMany(filter: FilterQuery<T>): Promise<number>;
145
- countDocuments(filter?: FilterQuery<T>): Promise<number>;
146
- close(): Promise<void>;
147
- }
131
+ const all = await users.find()
132
+ const adults = await users.find({ age: 18 })
148
133
  ```
149
134
 
150
- **Example:**
135
+ * Partial object matching
136
+ * Returns an array
151
137
 
152
- ```javascript
153
- await users.insertOne({ name: "Bob", age: 30 });
154
- const adults = await users.find({ age: { $gte: 18 } });
155
- await users.updateOne({ name: "Bob" }, { $inc: { age: 1 } });
156
- await users.deleteOne({ name: "Alice" });
138
+ ---
139
+
140
+ ### updateOne
141
+
142
+ ```ts
143
+ await users.updateOne(
144
+ { name: "Alex" },
145
+ { $set: { age: 23 } }
146
+ )
157
147
  ```
158
148
 
159
- ### Query Operators
149
+ Supported operators:
160
150
 
161
- * `$gt`, `$gte`, `$lt`, `$lte`, `$ne`, `$eq`, `$in`
151
+ * `$set`
152
+ * `$unset`
153
+ * `$inc`
162
154
 
163
- **Example:**
155
+ ---
156
+
157
+ ## Encryption
164
158
 
165
- ```javascript
166
- users.find({ age: { $gte: 18, $lt: 65 } });
159
+ Encryption is **transparent and automatic**.
160
+
161
+ ```ts
162
+ const manager = new LioranManager({
163
+ encryptionKey: process.env.DB_KEY
164
+ })
167
165
  ```
168
166
 
169
- ### Update Operators
167
+ * Data is encrypted before writing to disk
168
+ * Decrypted automatically on read
169
+ * Wrong key = unreadable data
170
170
 
171
- * `$set` set field values
172
- * `$inc` – increment numeric fields
171
+ > Encryption is global per manager instance.
173
172
 
174
- **Example:**
173
+ ---
175
174
 
176
- ```javascript
177
- users.updateOne({ name: "Alice" }, { $set: { city: "Mumbai" }, $inc: { age: 1 } });
175
+ ## File Structure on Disk
176
+
177
+ ```
178
+ rootPath/
179
+ └─ app/
180
+ ├─ users/
181
+ ├─ posts/
182
+ └─ comments/
178
183
  ```
179
184
 
180
- ### Utilities
185
+ * Human-readable folders
186
+ * Binary LevelDB data inside
187
+
188
+ ---
189
+
190
+ ## Type Safety
191
+
192
+ LioranDB is **TypeScript-native**.
181
193
 
182
194
  ```ts
183
- function getBaseDBFolder(): string;
195
+ const users = db.collection<{ name: string; age: number }>("users")
196
+
197
+ users.insertOne({ name: "Sam" }) // ❌ age missing
198
+ users.insertOne({ name: "Sam", age: 20 }) // ✅
184
199
  ```
185
200
 
186
- Returns the root folder for LioranDB databases. Automatically sets environment variables if missing.
201
+ No `any`. No runtime guessing.
187
202
 
188
203
  ---
189
204
 
190
- ## Encryption
205
+ ## Closing Databases
191
206
 
192
- All documents are encrypted using **AES-256-GCM**.
207
+ ```ts
208
+ await manager.closeDatabase("app")
209
+ ```
193
210
 
194
- * Uses a master key stored in `.secureKey` within the base folder.
195
- * Data is encrypted automatically before storage and decrypted on retrieval.
211
+ * Closes all collections
212
+ * Flushes LevelDB handles
196
213
 
197
- **Utility Functions:**
214
+ ---
198
215
 
199
- * `encryptData(obj)`
200
- * `decryptData(encStr)`
216
+ ## Design Philosophy
201
217
 
202
- **Master Key Management:**
218
+ * **Simple > clever**
219
+ * **Local-first**
220
+ * **No magic network calls**
221
+ * **Readable source > black box**
203
222
 
204
- * Managed via `getMasterKey()`
205
- * Auto-generates 256-bit key if not found.
223
+ LioranDB is intentionally small and hackable.
206
224
 
207
225
  ---
208
226
 
209
- ## Environment Setup
227
+ ## Roadmap
210
228
 
211
- * `getBaseDBFolder()` ensures `LIORANDB_PATH` is set.
212
- * Auto-generates scripts for **Windows PowerShell** or **Linux/macOS bash**.
213
- * Guides users to set system-wide environment variables if missing.
229
+ * 🔁 P2P sync layer
230
+ * 🧠 Indexing
231
+ * 🧾 Schema validation
232
+ * ⚡ WAL (write-ahead log)
233
+ * 🌐 Browser storage adapter
214
234
 
215
235
  ---
216
236
 
217
237
  ## License
218
238
 
219
- **Author:** Swaraj Puppalwar
220
- **License:** LIORANDB LICENSE
239
+ LDEP
221
240
 
222
241
  ---
223
242
 
224
- **Keywords:** p2p-database, lioran, liorandb, p2p-db, peer-to-peer-db, peer-to-peer-database, localfirst-db, localfirst-database
243
+ ## Author
244
+
245
+ Built by **Swaraj Puppalwar** 🚀
246
+
247
+ > If you are building local-first or offline-first systems — this DB is for you.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@liorandb/core",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "**LioranDB Core Module** – Lightweight, local-first, peer-to-peer database management for Node.js.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",