@liorandb/core 1.0.7 → 1.0.9
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/LICENSE.md +1 -1
- package/README.md +155 -132
- package/package.json +38 -37
package/LICENSE.md
CHANGED
package/README.md
CHANGED
|
@@ -1,27 +1,34 @@
|
|
|
1
1
|
# @liorandb/core
|
|
2
2
|
|
|
3
|
-
**LioranDB Core
|
|
3
|
+
**LioranDB Core** is a lightweight, encrypted, TypeScript-first embedded database engine for Node.js.
|
|
4
4
|
|
|
5
|
-
|
|
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
|
-
|
|
20
|
+
---
|
|
10
21
|
|
|
11
|
-
|
|
12
|
-
* [Overview](#overview)
|
|
13
|
-
* [Getting Started](#getting-started)
|
|
14
|
-
* [API Reference](#api-reference)
|
|
22
|
+
## Features
|
|
15
23
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
*
|
|
23
|
-
*
|
|
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
|
-
##
|
|
43
|
+
## Quick Start (30 seconds)
|
|
39
44
|
|
|
40
|
-
|
|
45
|
+
```ts
|
|
46
|
+
import { LioranManager } from "@liorandb/core"
|
|
41
47
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
-
|
|
52
|
+
const db = await manager.db("app")
|
|
50
53
|
|
|
51
|
-
|
|
54
|
+
const users = db.collection<{ name: string; age: number }>("users")
|
|
52
55
|
|
|
53
|
-
|
|
56
|
+
await users.insertOne({ name: "Swaraj", age: 17 })
|
|
54
57
|
|
|
55
|
-
|
|
56
|
-
|
|
58
|
+
const result = await users.find({ name: "Swaraj" })
|
|
59
|
+
console.log(result)
|
|
60
|
+
```
|
|
57
61
|
|
|
58
|
-
|
|
59
|
-
const manager = new LioranManager();
|
|
60
|
-
const db = await manager.db("myDatabase");
|
|
62
|
+
No config. No server. Just code.
|
|
61
63
|
|
|
62
|
-
|
|
64
|
+
---
|
|
63
65
|
|
|
64
|
-
|
|
65
|
-
const user = await users.insertOne({ name: "Alice", age: 25 });
|
|
66
|
+
## Core Concepts
|
|
66
67
|
|
|
67
|
-
|
|
68
|
-
const results = await users.find({ age: { $gte: 18 } });
|
|
68
|
+
### 1️⃣ LioranManager
|
|
69
69
|
|
|
70
|
-
|
|
71
|
-
}
|
|
70
|
+
The **root controller**. Manages databases, encryption and lifecycle.
|
|
72
71
|
|
|
73
|
-
|
|
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
|
-
|
|
81
|
+
* Creates databases
|
|
82
|
+
* Opens databases
|
|
83
|
+
* Tracks open instances
|
|
84
|
+
* Applies encryption globally
|
|
79
85
|
|
|
80
|
-
|
|
86
|
+
---
|
|
81
87
|
|
|
82
|
-
|
|
88
|
+
### 2️⃣ Database
|
|
89
|
+
|
|
90
|
+
Each database is a **folder on disk**.
|
|
83
91
|
|
|
84
92
|
```ts
|
|
85
|
-
|
|
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
|
-
|
|
96
|
+
* Databases are created automatically if missing
|
|
97
|
+
* Re-opening returns the same instance
|
|
99
98
|
|
|
100
|
-
|
|
101
|
-
const manager = new LioranManager();
|
|
102
|
-
await manager.createDatabase("testDB");
|
|
103
|
-
const db = await manager.db("testDB");
|
|
104
|
-
```
|
|
99
|
+
---
|
|
105
100
|
|
|
106
|
-
###
|
|
101
|
+
### 3️⃣ Collections
|
|
107
102
|
|
|
108
|
-
|
|
103
|
+
Collections are **LevelDB instances** stored inside the database.
|
|
109
104
|
|
|
110
105
|
```ts
|
|
111
|
-
|
|
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
|
-
|
|
109
|
+
* One folder per collection
|
|
110
|
+
* Fully typed
|
|
111
|
+
* JSON documents only
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
## Collection API
|
|
124
116
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
117
|
+
### insertOne
|
|
118
|
+
|
|
119
|
+
```ts
|
|
120
|
+
await users.insertOne({ name: "Alex", age: 22 })
|
|
129
121
|
```
|
|
130
122
|
|
|
131
|
-
|
|
123
|
+
* Auto-generates `_id`
|
|
124
|
+
* `_id` can be provided manually
|
|
132
125
|
|
|
133
|
-
|
|
126
|
+
---
|
|
127
|
+
|
|
128
|
+
### find
|
|
134
129
|
|
|
135
130
|
```ts
|
|
136
|
-
|
|
137
|
-
|
|
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
|
-
|
|
135
|
+
* Partial object matching
|
|
136
|
+
* Returns an array
|
|
151
137
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
138
|
+
---
|
|
139
|
+
|
|
140
|
+
### updateOne
|
|
141
|
+
|
|
142
|
+
```ts
|
|
143
|
+
await users.updateOne(
|
|
144
|
+
{ name: "Alex" },
|
|
145
|
+
{ $set: { age: 23 } }
|
|
146
|
+
)
|
|
157
147
|
```
|
|
158
148
|
|
|
159
|
-
|
|
149
|
+
Supported operators:
|
|
160
150
|
|
|
161
|
-
* `$
|
|
151
|
+
* `$set`
|
|
152
|
+
* `$unset`
|
|
153
|
+
* `$inc`
|
|
162
154
|
|
|
163
|
-
|
|
155
|
+
---
|
|
156
|
+
|
|
157
|
+
## Encryption
|
|
164
158
|
|
|
165
|
-
|
|
166
|
-
|
|
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
|
-
|
|
167
|
+
* Data is encrypted before writing to disk
|
|
168
|
+
* Decrypted automatically on read
|
|
169
|
+
* Wrong key = unreadable data
|
|
170
170
|
|
|
171
|
-
|
|
172
|
-
* `$inc` – increment numeric fields
|
|
171
|
+
> Encryption is global per manager instance.
|
|
173
172
|
|
|
174
|
-
|
|
173
|
+
---
|
|
175
174
|
|
|
176
|
-
|
|
177
|
-
|
|
175
|
+
## File Structure on Disk
|
|
176
|
+
|
|
177
|
+
```
|
|
178
|
+
rootPath/
|
|
179
|
+
└─ app/
|
|
180
|
+
├─ users/
|
|
181
|
+
├─ posts/
|
|
182
|
+
└─ comments/
|
|
178
183
|
```
|
|
179
184
|
|
|
180
|
-
|
|
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
|
-
|
|
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
|
-
|
|
201
|
+
No `any`. No runtime guessing.
|
|
187
202
|
|
|
188
203
|
---
|
|
189
204
|
|
|
190
|
-
##
|
|
205
|
+
## Closing Databases
|
|
191
206
|
|
|
192
|
-
|
|
207
|
+
```ts
|
|
208
|
+
await manager.closeDatabase("app")
|
|
209
|
+
```
|
|
193
210
|
|
|
194
|
-
*
|
|
195
|
-
*
|
|
211
|
+
* Closes all collections
|
|
212
|
+
* Flushes LevelDB handles
|
|
196
213
|
|
|
197
|
-
|
|
214
|
+
---
|
|
198
215
|
|
|
199
|
-
|
|
200
|
-
* `decryptData(encStr)`
|
|
216
|
+
## Design Philosophy
|
|
201
217
|
|
|
202
|
-
**
|
|
218
|
+
* **Simple > clever**
|
|
219
|
+
* **Local-first**
|
|
220
|
+
* **No magic network calls**
|
|
221
|
+
* **Readable source > black box**
|
|
203
222
|
|
|
204
|
-
|
|
205
|
-
* Auto-generates 256-bit key if not found.
|
|
223
|
+
LioranDB is intentionally small and hackable.
|
|
206
224
|
|
|
207
225
|
---
|
|
208
226
|
|
|
209
|
-
##
|
|
227
|
+
## Roadmap
|
|
210
228
|
|
|
211
|
-
*
|
|
212
|
-
*
|
|
213
|
-
*
|
|
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
|
-
|
|
220
|
-
**License:** LIORANDB LICENSE
|
|
239
|
+
LDEP
|
|
221
240
|
|
|
222
241
|
---
|
|
223
242
|
|
|
224
|
-
|
|
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,38 +1,39 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@liorandb/core",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "**LioranDB Core Module** – Lightweight, local-first, peer-to-peer database management for Node.js.",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"types": "dist/index.d.ts",
|
|
7
|
-
"scripts": {
|
|
8
|
-
"build": "tsup src/index.ts --dts --format esm",
|
|
9
|
-
"prepublishOnly": "npm run build"
|
|
10
|
-
},
|
|
11
|
-
"exports": {
|
|
12
|
-
".": {
|
|
13
|
-
"import": "./dist/index.js",
|
|
14
|
-
"types": "./dist/index.d.ts"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
"
|
|
30
|
-
|
|
31
|
-
"
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@liorandb/core",
|
|
3
|
+
"version": "1.0.9",
|
|
4
|
+
"description": "**LioranDB Core Module** – Lightweight, local-first, peer-to-peer database management for Node.js.",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsup src/index.ts --dts --format esm",
|
|
9
|
+
"prepublishOnly": "npm run build"
|
|
10
|
+
},
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"require": "./dist/index.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/LioranGroupOfficial/Liorandb.git"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [],
|
|
23
|
+
"author": "LioranGroup",
|
|
24
|
+
"license": "LDEP",
|
|
25
|
+
"type": "module",
|
|
26
|
+
"bugs": {
|
|
27
|
+
"url": "https://github.com/LioranGroupOfficial/Liorandb/issues"
|
|
28
|
+
},
|
|
29
|
+
"homepage": "https://github.com/LioranGroupOfficial/Liorandb#readme",
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"classic-level": "^3.0.0",
|
|
32
|
+
"uuid": "^13.0.0"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@types/node": "^25.2.0",
|
|
36
|
+
"tsup": "^8.5.1",
|
|
37
|
+
"typescript": "^5.9.3"
|
|
38
|
+
}
|
|
38
39
|
}
|