@jsonkit/db 1.0.0 → 2.0.1
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 +239 -1
- package/dist/cjs/index.cjs +162 -11
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/index.js +159 -12
- package/dist/esm/index.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/{files.d.ts → file/files.d.ts} +2 -2
- package/dist/types/{multiEntryFileDb.d.ts → file/multiEntryFileDb.d.ts} +8 -7
- package/dist/types/file/singleEntryFileDb.d.ts +13 -0
- package/dist/types/index.d.ts +4 -2
- package/dist/types/memory/__tests__/multiEntryMemDb.test.d.ts +1 -0
- package/dist/types/memory/__tests__/singleEntryMemDb.test.d.ts +1 -0
- package/dist/types/memory/multiEntryMemDb.d.ts +19 -0
- package/dist/types/memory/singleEntryMemDb.d.ts +9 -0
- package/dist/types/types.d.ts +29 -0
- package/package.json +6 -6
- package/dist/types/singleEntryFileDb.d.ts +0 -14
- /package/dist/types/{__tests__ → file/__tests__}/multiEntryFileDb.test.d.ts +0 -0
- /package/dist/types/{__tests__ → file/__tests__}/singleEntryFileDb.test.d.ts +0 -0
package/README.md
CHANGED
|
@@ -1,3 +1,241 @@
|
|
|
1
1
|
# @jsonkit/db
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`@jsonkit/db` is a lightweight, zero-dependency database abstraction for rapid prototyping. It provides simple **file-based** and **in-memory** databases with consistent APIs, suitable for small applications, tooling, tests, and early-stage prototypes where setting up a full database would be unnecessary overhead.
|
|
4
|
+
|
|
5
|
+
The package exposes two core concepts:
|
|
6
|
+
|
|
7
|
+
* **Single-entry databases** – manage exactly one JSON-serializable object.
|
|
8
|
+
* **Multi-entry databases** – manage collections of identifiable records keyed by an `id`.
|
|
9
|
+
|
|
10
|
+
Both concepts are available in **file-backed** and **in-memory** variants.
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @jsonkit/db
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## Core Types
|
|
23
|
+
|
|
24
|
+
### `Identifiable`
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
type Identifiable = { id: string }
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
All multi-entry databases require entries to have a string `id`.
|
|
31
|
+
|
|
32
|
+
### `Promisable<T>`
|
|
33
|
+
|
|
34
|
+
A value or a promise of a value.
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
type Promisable<T> = T | Promise<T>
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### `PredicateFn<T>`
|
|
41
|
+
|
|
42
|
+
Used for filtering entries.
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
type PredicateFn<T extends Identifiable> = (entry: T) => boolean
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### `DeleteManyOutput`
|
|
49
|
+
|
|
50
|
+
Returned by bulk delete operations.
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
type DeleteManyOutput = {
|
|
54
|
+
deletedIds: string[]
|
|
55
|
+
ignoredIds: string[]
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
## Multi-entry Databases
|
|
62
|
+
|
|
63
|
+
Multi-entry databases manage collections of entries keyed by `id`.
|
|
64
|
+
|
|
65
|
+
### Common API (`MultiEntryDb<T>`)
|
|
66
|
+
|
|
67
|
+
All multi-entry implementations expose the same async API:
|
|
68
|
+
|
|
69
|
+
* `create(entry)`
|
|
70
|
+
* `getById(id)`
|
|
71
|
+
* `getByIdOrThrow(id)`
|
|
72
|
+
* `getWhere(predicate, max?)`
|
|
73
|
+
* `getAll(ids?)`
|
|
74
|
+
* `getAllIds()`
|
|
75
|
+
* `update(id, updater)`
|
|
76
|
+
* `delete(id)`
|
|
77
|
+
* `deleteByIds(ids)`
|
|
78
|
+
* `deleteWhere(predicate)`
|
|
79
|
+
* `exists(id)`
|
|
80
|
+
* `countAll()`
|
|
81
|
+
* `countWhere(predicate)`
|
|
82
|
+
* `destroy()`
|
|
83
|
+
|
|
84
|
+
Updates are **partial merges**, and changing an entry’s `id` during an update is supported.
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
### `MultiEntryFileDb<T extends Identifiable>`
|
|
89
|
+
|
|
90
|
+
A file-backed database where **each entry is stored as its own JSON file**.
|
|
91
|
+
|
|
92
|
+
```ts
|
|
93
|
+
import { MultiEntryFileDb } from '@jsonkit/db'
|
|
94
|
+
|
|
95
|
+
const db = new MultiEntryFileDb<User>('./data/users')
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
#### Behavior
|
|
99
|
+
|
|
100
|
+
* Each entry is stored as `<id>.json` in the provided directory.
|
|
101
|
+
* The directory is created implicitly as files are written.
|
|
102
|
+
* IDs are validated to prevent path traversal by default.
|
|
103
|
+
|
|
104
|
+
#### Constructor
|
|
105
|
+
|
|
106
|
+
```ts
|
|
107
|
+
new MultiEntryFileDb<T>(dirpath, options?)
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
**Options**
|
|
111
|
+
|
|
112
|
+
| Option | Description | Default |
|
|
113
|
+
| --------------- | -------------------------------------- | ------- |
|
|
114
|
+
| `noPathlikeIds` | Reject IDs containing `/` or `\` | `true` |
|
|
115
|
+
| `parser` | Custom JSON parser (`{ parse(text) }`) | `JSON` |
|
|
116
|
+
|
|
117
|
+
#### Notes
|
|
118
|
+
|
|
119
|
+
* Failed reads (missing file or invalid JSON) return `null`.
|
|
120
|
+
* `destroy()` deletes the entire directory.
|
|
121
|
+
* Intended for development, prototyping, and small datasets.
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
|
|
125
|
+
### `MultiEntryMemDb<T extends Identifiable>`
|
|
126
|
+
|
|
127
|
+
An in-memory implementation backed by a `Map`.
|
|
128
|
+
|
|
129
|
+
```ts
|
|
130
|
+
import { MultiEntryMemDb } from '@jsonkit/db'
|
|
131
|
+
|
|
132
|
+
const db = new MultiEntryMemDb<User>()
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
#### Behavior
|
|
136
|
+
|
|
137
|
+
* Fast, ephemeral storage.
|
|
138
|
+
* Ideal for tests and short-lived processes.
|
|
139
|
+
* `destroy()` clears all entries.
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
## Single-entry Databases
|
|
144
|
+
|
|
145
|
+
Single-entry databases manage **exactly one value**, often used for configuration or application state.
|
|
146
|
+
|
|
147
|
+
### Common API (`SingleEntryDb<T>`)
|
|
148
|
+
|
|
149
|
+
* `isInited()`
|
|
150
|
+
* `read()`
|
|
151
|
+
* `write(entry | updater)`
|
|
152
|
+
* `delete()`
|
|
153
|
+
|
|
154
|
+
`write` supports either replacing the entry or partially updating it via an updater function.
|
|
155
|
+
|
|
156
|
+
---
|
|
157
|
+
|
|
158
|
+
### `SingleEntryFileDb<T>`
|
|
159
|
+
|
|
160
|
+
Stores a single JSON object in a file.
|
|
161
|
+
|
|
162
|
+
```ts
|
|
163
|
+
import { SingleEntryFileDb } from '@jsonkit/db'
|
|
164
|
+
|
|
165
|
+
const db = new SingleEntryFileDb<AppConfig>('./config.json')
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
#### Behavior
|
|
169
|
+
|
|
170
|
+
* Reads and writes a single JSON file.
|
|
171
|
+
* `isInited()` checks file existence.
|
|
172
|
+
* `read()` throws if the file does not exist.
|
|
173
|
+
|
|
174
|
+
#### Constructor
|
|
175
|
+
|
|
176
|
+
```ts
|
|
177
|
+
new SingleEntryFileDb<T>(filepath, parser?)
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
* `parser` defaults to `JSON`.
|
|
181
|
+
|
|
182
|
+
---
|
|
183
|
+
|
|
184
|
+
### `SingleEntryMemDb<T>`
|
|
185
|
+
|
|
186
|
+
An in-memory single-value database.
|
|
187
|
+
|
|
188
|
+
```ts
|
|
189
|
+
import { SingleEntryMemDb } from '@jsonkit/db'
|
|
190
|
+
|
|
191
|
+
const db = new SingleEntryMemDb<AppConfig>()
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
#### Behavior
|
|
195
|
+
|
|
196
|
+
* Optional initial value.
|
|
197
|
+
* `read()` throws if uninitialized.
|
|
198
|
+
* `delete()` resets the entry to `null`.
|
|
199
|
+
|
|
200
|
+
---
|
|
201
|
+
|
|
202
|
+
## Example
|
|
203
|
+
|
|
204
|
+
```ts
|
|
205
|
+
type User = { id: string; name: string }
|
|
206
|
+
|
|
207
|
+
const users = new MultiEntryFileDb<User>('./users')
|
|
208
|
+
|
|
209
|
+
await users.create({ id: 'u1', name: 'Alice' })
|
|
210
|
+
|
|
211
|
+
await users.update('u1', (u) => ({ name: 'Alice Smith' }))
|
|
212
|
+
|
|
213
|
+
const allUsers = await users.getAll()
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
---
|
|
217
|
+
|
|
218
|
+
## Use Cases
|
|
219
|
+
|
|
220
|
+
* Rapid application prototyping
|
|
221
|
+
* CLI tools
|
|
222
|
+
* Small internal services
|
|
223
|
+
* Tests and mocks
|
|
224
|
+
* Configuration and state persistence
|
|
225
|
+
|
|
226
|
+
---
|
|
227
|
+
|
|
228
|
+
## Non-goals
|
|
229
|
+
|
|
230
|
+
* Concurrency control
|
|
231
|
+
* High-performance querying
|
|
232
|
+
* Large datasets
|
|
233
|
+
* ACID guarantees
|
|
234
|
+
|
|
235
|
+
For these, a dedicated database is recommended.
|
|
236
|
+
|
|
237
|
+
---
|
|
238
|
+
|
|
239
|
+
## License
|
|
240
|
+
|
|
241
|
+
MIT
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -33,9 +33,13 @@ exports.FileType = void 0;
|
|
|
33
33
|
FileType["Directory"] = "directory";
|
|
34
34
|
//Symlink: 'symlink'
|
|
35
35
|
})(exports.FileType || (exports.FileType = {}));
|
|
36
|
+
class SingleEntryDb {
|
|
37
|
+
}
|
|
38
|
+
class MultiEntryDb {
|
|
39
|
+
}
|
|
36
40
|
|
|
37
41
|
const DEFUALT_ENCODING = 'utf-8';
|
|
38
|
-
class
|
|
42
|
+
class Files {
|
|
39
43
|
async move(oldPath, newPath) {
|
|
40
44
|
await fs__namespace.rename(oldPath, newPath);
|
|
41
45
|
}
|
|
@@ -243,11 +247,13 @@ class FilesService {
|
|
|
243
247
|
}
|
|
244
248
|
}
|
|
245
249
|
|
|
246
|
-
class MultiEntryFileDb {
|
|
247
|
-
constructor(dirpath,
|
|
250
|
+
class MultiEntryFileDb extends MultiEntryDb {
|
|
251
|
+
constructor(dirpath, options) {
|
|
252
|
+
super();
|
|
248
253
|
this.dirpath = dirpath;
|
|
249
|
-
this.
|
|
250
|
-
this.
|
|
254
|
+
this.files = new Files();
|
|
255
|
+
this.parser = options?.parser ?? JSON;
|
|
256
|
+
this.noPathlikeIds = options?.noPathlikeIds ?? true;
|
|
251
257
|
}
|
|
252
258
|
async create(entry) {
|
|
253
259
|
await this.writeEntry(entry);
|
|
@@ -272,9 +278,8 @@ class MultiEntryFileDb {
|
|
|
272
278
|
const entries = [];
|
|
273
279
|
for (const id of ids) {
|
|
274
280
|
const entry = await this.readEntry(id);
|
|
275
|
-
if (entry)
|
|
281
|
+
if (entry)
|
|
276
282
|
entries.push(entry);
|
|
277
|
-
}
|
|
278
283
|
}
|
|
279
284
|
return entries;
|
|
280
285
|
}
|
|
@@ -349,21 +354,35 @@ class MultiEntryFileDb {
|
|
|
349
354
|
return path__namespace.join(this.dirpath, `${id}.json`);
|
|
350
355
|
}
|
|
351
356
|
async readEntry(id) {
|
|
357
|
+
if (!this.isIdValid(id))
|
|
358
|
+
throw new Error(`Invalid id: ${id}`);
|
|
352
359
|
try {
|
|
353
360
|
const filepath = this.getFilePath(id);
|
|
354
361
|
const text = await this.files.read(filepath);
|
|
355
362
|
const entry = this.parser.parse(text);
|
|
356
363
|
return entry;
|
|
357
364
|
}
|
|
358
|
-
catch {
|
|
365
|
+
catch (error) {
|
|
366
|
+
console.error('Failed to read entry', error);
|
|
359
367
|
// File doesn't exist or invalid JSON
|
|
360
368
|
return null;
|
|
361
369
|
}
|
|
362
370
|
}
|
|
363
371
|
async writeEntry(entry) {
|
|
372
|
+
if (!this.isIdValid(entry.id))
|
|
373
|
+
throw new Error(`Invalid id: ${entry.id}`);
|
|
364
374
|
const filepath = this.getFilePath(entry.id);
|
|
365
375
|
await this.files.write(filepath, JSON.stringify(entry, null, 2));
|
|
366
376
|
}
|
|
377
|
+
isIdValid(id) {
|
|
378
|
+
if (typeof id !== 'string')
|
|
379
|
+
return false;
|
|
380
|
+
if (!this.noPathlikeIds)
|
|
381
|
+
return true;
|
|
382
|
+
if (id.includes('/') || id.includes('\\'))
|
|
383
|
+
return false;
|
|
384
|
+
return true;
|
|
385
|
+
}
|
|
367
386
|
async *iterEntries() {
|
|
368
387
|
const ids = await this.getAllIds();
|
|
369
388
|
for (const id of ids) {
|
|
@@ -374,11 +393,12 @@ class MultiEntryFileDb {
|
|
|
374
393
|
}
|
|
375
394
|
}
|
|
376
395
|
|
|
377
|
-
class SingleEntryFileDb {
|
|
378
|
-
constructor(filepath, parser) {
|
|
396
|
+
class SingleEntryFileDb extends SingleEntryDb {
|
|
397
|
+
constructor(filepath, parser = JSON) {
|
|
398
|
+
super();
|
|
379
399
|
this.filepath = filepath;
|
|
380
400
|
this.parser = parser;
|
|
381
|
-
this.files = new
|
|
401
|
+
this.files = new Files();
|
|
382
402
|
}
|
|
383
403
|
path() {
|
|
384
404
|
return this.filepath;
|
|
@@ -411,6 +431,137 @@ class SingleEntryFileDb {
|
|
|
411
431
|
}
|
|
412
432
|
}
|
|
413
433
|
|
|
434
|
+
class MultiEntryMemDb extends MultiEntryDb {
|
|
435
|
+
constructor() {
|
|
436
|
+
super(...arguments);
|
|
437
|
+
this.entries = new Map();
|
|
438
|
+
}
|
|
439
|
+
async create(entry) {
|
|
440
|
+
this.entries.set(entry.id, entry);
|
|
441
|
+
return entry;
|
|
442
|
+
}
|
|
443
|
+
async getById(id) {
|
|
444
|
+
return this.entries.get(id) ?? null;
|
|
445
|
+
}
|
|
446
|
+
async getByIdOrThrow(id) {
|
|
447
|
+
const entry = await this.getById(id);
|
|
448
|
+
if (!entry) {
|
|
449
|
+
throw new Error('Entry with id ' + id + ' does not exist');
|
|
450
|
+
}
|
|
451
|
+
return entry;
|
|
452
|
+
}
|
|
453
|
+
async getWhere(predicate, max) {
|
|
454
|
+
const entries = Array.from(this.entries.values()).filter(predicate);
|
|
455
|
+
return max !== undefined ? entries.slice(0, max) : entries;
|
|
456
|
+
}
|
|
457
|
+
async getAll(whereIds) {
|
|
458
|
+
if (whereIds === undefined) {
|
|
459
|
+
return Array.from(this.entries.values());
|
|
460
|
+
}
|
|
461
|
+
const entries = [];
|
|
462
|
+
for (const id of whereIds) {
|
|
463
|
+
const entry = this.entries.get(id);
|
|
464
|
+
if (entry)
|
|
465
|
+
entries.push(entry);
|
|
466
|
+
}
|
|
467
|
+
return entries;
|
|
468
|
+
}
|
|
469
|
+
async getAllIds() {
|
|
470
|
+
return Array.from(this.entries.keys());
|
|
471
|
+
}
|
|
472
|
+
async update(id, updater) {
|
|
473
|
+
const entry = this.entries.get(id);
|
|
474
|
+
if (!entry) {
|
|
475
|
+
throw new Error('Entry with id ' + id + ' does not exist');
|
|
476
|
+
}
|
|
477
|
+
const updatedEntryFields = await updater(entry);
|
|
478
|
+
const updatedEntry = { ...entry, ...updatedEntryFields };
|
|
479
|
+
this.entries.set(updatedEntry.id, updatedEntry);
|
|
480
|
+
if (updatedEntry.id !== id) {
|
|
481
|
+
this.entries.delete(id);
|
|
482
|
+
}
|
|
483
|
+
return updatedEntry;
|
|
484
|
+
}
|
|
485
|
+
async delete(id) {
|
|
486
|
+
return this.entries.delete(id);
|
|
487
|
+
}
|
|
488
|
+
async deleteByIds(ids) {
|
|
489
|
+
return this.deleteWhere((entry) => ids.includes(entry.id));
|
|
490
|
+
}
|
|
491
|
+
async deleteWhere(predicate) {
|
|
492
|
+
const deletedIds = [];
|
|
493
|
+
const ignoredIds = [];
|
|
494
|
+
for (const [id, entry] of this.entries) {
|
|
495
|
+
if (!predicate(entry))
|
|
496
|
+
continue;
|
|
497
|
+
const didDelete = await this.delete(id);
|
|
498
|
+
if (didDelete) {
|
|
499
|
+
deletedIds.push(id);
|
|
500
|
+
}
|
|
501
|
+
else {
|
|
502
|
+
ignoredIds.push(id);
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
return { deletedIds, ignoredIds };
|
|
506
|
+
}
|
|
507
|
+
async destroy() {
|
|
508
|
+
this.entries.clear();
|
|
509
|
+
}
|
|
510
|
+
async exists(id) {
|
|
511
|
+
return this.entries.has(id);
|
|
512
|
+
}
|
|
513
|
+
async countAll() {
|
|
514
|
+
return this.entries.size;
|
|
515
|
+
}
|
|
516
|
+
async countWhere(predicate) {
|
|
517
|
+
return Array.from(this.entries.values()).filter(predicate).length;
|
|
518
|
+
}
|
|
519
|
+
async *iterEntries() {
|
|
520
|
+
for (const entry of this.entries.values()) {
|
|
521
|
+
yield entry;
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
class SingleEntryMemDb extends SingleEntryDb {
|
|
527
|
+
constructor(initialEntry = null) {
|
|
528
|
+
super();
|
|
529
|
+
this.entry = null;
|
|
530
|
+
this.entry = initialEntry;
|
|
531
|
+
}
|
|
532
|
+
async isInited() {
|
|
533
|
+
return this.entry !== null;
|
|
534
|
+
}
|
|
535
|
+
async read() {
|
|
536
|
+
if (this.entry === null)
|
|
537
|
+
throw new Error('Entry not initialized');
|
|
538
|
+
return this.entry;
|
|
539
|
+
}
|
|
540
|
+
async write(updaterOrEntry) {
|
|
541
|
+
let entry;
|
|
542
|
+
if (typeof updaterOrEntry === 'function') {
|
|
543
|
+
const updater = updaterOrEntry;
|
|
544
|
+
if (this.entry === null) {
|
|
545
|
+
throw new Error('Cannot update uninitialized entry. Use write(entry) to initialize first.');
|
|
546
|
+
}
|
|
547
|
+
const updatedFields = await updater(this.entry);
|
|
548
|
+
entry = { ...this.entry, ...updatedFields };
|
|
549
|
+
}
|
|
550
|
+
else {
|
|
551
|
+
entry = updaterOrEntry;
|
|
552
|
+
}
|
|
553
|
+
this.entry = entry;
|
|
554
|
+
return entry;
|
|
555
|
+
}
|
|
556
|
+
async delete() {
|
|
557
|
+
this.entry = null;
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
exports.MultiEntryDb = MultiEntryDb;
|
|
414
562
|
exports.MultiEntryFileDb = MultiEntryFileDb;
|
|
563
|
+
exports.MultiEntryMemDb = MultiEntryMemDb;
|
|
564
|
+
exports.SingleEntryDb = SingleEntryDb;
|
|
415
565
|
exports.SingleEntryFileDb = SingleEntryFileDb;
|
|
566
|
+
exports.SingleEntryMemDb = SingleEntryMemDb;
|
|
416
567
|
//# sourceMappingURL=index.cjs.map
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../src/types.ts","../../src/files.ts","../../src/multiEntryFileDb.ts","../../src/singleEntryFileDb.ts"],"sourcesContent":["export type Identifiable = {\n id: Id\n}\n\nexport type Id = string\n\nexport type Promisable<T> = T | Promise<T>\n\nexport type DeleteManyOutput = {\n deletedIds: Id[]\n ignoredIds: Id[]\n}\n\nexport type PredicateFn<T extends Identifiable> = (entry: T) => boolean\n\nexport type FileMeta = {\n path: string\n size: number\n created: Date\n modified: Date\n accessed: Date\n} & (\n | {\n type: FileType.File\n }\n | {\n type: FileType.Directory\n children: FileMeta[]\n }\n)\n\nexport enum FileType {\n File = 'file',\n Directory = 'directory',\n //Symlink: 'symlink'\n}\n","import type { FileMeta } from './types'\nimport { FileType } from './types'\nimport * as fs from 'fs/promises'\nimport * as path from 'path'\nimport * as fsSync from 'fs'\nimport * as readline from 'readline'\n\ntype ListOptions = {\n depth?: number\n stripBasepath?: string\n}\n\ntype DeleteOptions = {\n force?: boolean\n recursive?: boolean\n}\n\ntype WriteOptions = {\n encoding?: BufferEncoding\n}\n\ntype ReadOptions = {\n encoding?: BufferEncoding\n lines?: number\n}\n\ntype CopyOptions = {\n recursive?: boolean\n overwrite?: boolean\n}\n\nconst DEFUALT_ENCODING: BufferEncoding = 'utf-8'\n\nexport class FilesService {\n async move(oldPath: string, newPath: string) {\n await fs.rename(oldPath, newPath)\n }\n\n async copy(sourcePath: string, destinationPath: string, options?: CopyOptions) {\n const { recursive = false, overwrite = true } = options ?? {}\n\n // Check if destination exists and handle overwrite\n if (!overwrite && (await this.exists(destinationPath))) {\n throw new Error(`Destination '${destinationPath}' already exists`)\n }\n\n const sourceStats = await fs.stat(sourcePath)\n\n if (sourceStats.isFile()) {\n const destinationDir = path.dirname(destinationPath)\n await this.mkdirUnsafe(destinationDir)\n await fs.copyFile(sourcePath, destinationPath)\n return\n }\n\n if (sourceStats.isDirectory()) {\n if (!recursive) {\n throw new Error(`'${sourcePath}' is a directory (use recursive option)`)\n }\n await this.copyRecursive(sourcePath, destinationPath)\n }\n }\n\n async copyRecursive(sourcePath: string, destinationPath: string) {\n const sourceStats = await fs.stat(sourcePath)\n\n if (sourceStats.isFile()) {\n const destinationDir = path.dirname(destinationPath)\n await this.mkdirUnsafe(destinationDir)\n await fs.copyFile(sourcePath, destinationPath)\n return\n }\n\n if (sourceStats.isDirectory()) {\n await this.mkdirUnsafe(destinationPath)\n const entries = await fs.readdir(sourcePath)\n\n for (const entry of entries) {\n const sourceEntryPath = path.join(sourcePath, entry)\n const destEntryPath = path.join(destinationPath, entry)\n await this.copyRecursive(sourceEntryPath, destEntryPath)\n }\n }\n }\n\n async mkdir(filepath: string) {\n await this.mkdirUnsafe(filepath)\n }\n\n protected async mkdirUnsafe(filepath: string) {\n await fs.mkdir(filepath, { recursive: true })\n }\n\n async write(filepath: string, content: string, options?: WriteOptions) {\n const { encoding = DEFUALT_ENCODING } = options ?? {}\n\n const parentDirs = path.dirname(filepath)\n await this.mkdirUnsafe(parentDirs)\n\n await fs.writeFile(filepath, content, encoding)\n }\n\n async touch(filepath: string) {\n const exists = await this.exists(filepath)\n if (!exists) await this.write(filepath, '')\n }\n\n async read(filepath: string, options?: ReadOptions) {\n const { encoding = DEFUALT_ENCODING, lines } = options ?? {}\n\n if (lines === undefined) {\n return await fs.readFile(filepath, encoding)\n }\n\n const stream = fsSync.createReadStream(filepath, { encoding })\n const reader = readline.createInterface({\n input: stream,\n crlfDelay: Infinity,\n })\n\n let result = ''\n let linesRead = 0\n for await (const line of reader) {\n if (linesRead >= lines) break\n result += line + '\\n'\n linesRead++\n }\n\n return result\n }\n\n async delete(filepath: string, options?: DeleteOptions) {\n const { force = true, recursive = true } = options ?? {}\n await fs.rm(filepath, { force, recursive })\n }\n\n async exists(filepath: string) {\n try {\n await fs.access(filepath)\n return true\n } catch {\n return false\n }\n }\n\n async isDir(filepath: string) {\n try {\n const stats = await fs.stat(filepath)\n return stats.isDirectory()\n } catch {\n return false\n }\n }\n\n async isFile(filepath: string) {\n try {\n const stats = await fs.stat(filepath)\n return stats.isFile()\n } catch {\n return false\n }\n }\n\n async isSymlink(filepath: string) {\n try {\n const stats = await fs.stat(filepath)\n return stats.isSymbolicLink()\n } catch {\n return false\n }\n }\n\n async getMeta(filepath: string, options?: ListOptions): Promise<FileMeta> {\n const { depth = 0, stripBasepath } = options ?? {}\n const stats = await fs.stat(filepath)\n const isDir = stats.isDirectory()\n const isFile = stats.isFile()\n\n const { size, ctime, mtime, atime } = stats\n const commonMeta = {\n path: this.stripBasepath(filepath, stripBasepath),\n size,\n created: ctime,\n modified: mtime,\n accessed: atime,\n }\n\n if (isDir) {\n const children: FileMeta[] = []\n\n if (depth > 0) {\n const childNames = await this.list(filepath)\n\n for (const child of childNames) {\n const childDepth = Math.max(0, depth - 1)\n const childMeta = await this.getMeta(path.join(filepath, child), {\n depth: childDepth,\n stripBasepath,\n })\n children.push(childMeta)\n }\n }\n\n return {\n ...commonMeta,\n type: FileType.Directory,\n children,\n }\n }\n if (isFile)\n return {\n ...commonMeta,\n type: FileType.File,\n }\n\n throw new Error(`File at ${filepath} is not normal file or directory`)\n }\n\n async list(dirpath: string, options?: ListOptions) {\n const { depth = 0, stripBasepath } = options ?? {}\n if (depth > 0) {\n return await this.listRecursive(dirpath, depth, 0, stripBasepath)\n }\n return await fs.readdir(dirpath)\n }\n\n async *listRead(dirpath: string, options?: ListOptions) {\n const { depth = 0 } = options ?? {}\n\n const files = await this.list(dirpath, { depth })\n\n for (const filepath of files) {\n const isFile = await this.isFile(filepath)\n if (!isFile) continue\n\n try {\n const content = await this.read(filepath)\n yield {\n filepath,\n content,\n }\n } catch {\n // Skip files that can't be read\n continue\n }\n }\n }\n\n protected async listRecursive(\n dirpath: string,\n maxDepth: number,\n currentDepth: number,\n stripBasepath: string | undefined,\n ): Promise<string[]> {\n const results: string[] = []\n const entries = await fs.readdir(dirpath, { withFileTypes: true })\n\n for (const entry of entries) {\n const fullPath = path.join(dirpath, entry.name)\n const strippedPath = this.stripBasepath(fullPath, stripBasepath)\n results.push(strippedPath)\n\n if (entry.isDirectory() && currentDepth < maxDepth) {\n const subResults = await this.listRecursive(\n fullPath,\n maxDepth,\n currentDepth + 1,\n stripBasepath,\n )\n results.push(...subResults)\n }\n }\n\n return results\n }\n\n protected stripBasepath(original: string, pathToStrip: string | undefined): string {\n if (!pathToStrip) return original\n const base = pathToStrip.replace(/^\\/+/, '/').replace(/\\/+$/, '/')\n const stripped = original.replace(base, '')\n return `/${stripped}`\n }\n}\n","import type { Identifiable, DeleteManyOutput, Promisable, PredicateFn } from './types'\nimport { FilesService } from './files'\nimport { JsonParser } from '@jsonkit/tools'\nimport * as path from 'path'\n\nexport class MultiEntryFileDb<T extends Identifiable> {\n protected readonly files: FilesService = new FilesService()\n\n constructor(\n protected readonly dirpath: string,\n protected readonly parser: JsonParser,\n ) {}\n\n async create(entry: T): Promise<T> {\n await this.writeEntry(entry)\n return entry\n }\n\n async getById(id: T['id']): Promise<T | null> {\n return await this.readEntry(id)\n }\n\n async getByIdOrThrow(id: T['id']): Promise<T> {\n const entry = await this.readEntry(id)\n if (!entry) {\n throw new Error('Entry with id ' + id + ' does not exist')\n }\n return entry\n }\n\n async getWhere(predicate: PredicateFn<T>, max?: number): Promise<T[]> {\n const entries = await this.getAll()\n return entries.filter(predicate).slice(0, max)\n }\n\n async getAll(whereIds?: T['id'][]): Promise<T[]> {\n const ids = whereIds === undefined ? await this.getAllIds() : whereIds\n const entries: T[] = []\n\n for (const id of ids) {\n const entry = await this.readEntry(id)\n if (entry) {\n entries.push(entry)\n }\n }\n\n return entries\n }\n\n async getAllIds(): Promise<T['id'][]> {\n try {\n const entries = await this.files.list(this.dirpath)\n return entries.filter((name) => name.endsWith('.json')).map((name) => name.slice(0, -5)) // Remove .json extension\n } catch {\n // Directory might not exist\n return []\n }\n }\n\n async update(id: T['id'], updater: (entry: T) => Promisable<Partial<T>>): Promise<T> {\n const entry = await this.readEntry(id)\n if (!entry) {\n throw new Error('Entry with id ' + id + ' does not exist')\n }\n\n const updatedEntryFields = await updater(entry)\n const updatedEntry = { ...entry, ...updatedEntryFields }\n await this.writeEntry(updatedEntry)\n\n if (updatedEntry.id !== id) {\n await this.delete(id)\n }\n\n return updatedEntry\n }\n\n async delete(id: T['id']): Promise<boolean> {\n try {\n const filepath = this.getFilePath(id)\n await this.files.delete(filepath, { force: false })\n return true\n } catch {\n // File might not exist, ignore error\n return false\n }\n }\n\n async deleteByIds(ids: T['id'][]): Promise<DeleteManyOutput> {\n return this.deleteWhere((entry) => ids.includes(entry.id))\n }\n\n async deleteWhere(predicate: PredicateFn<T>): Promise<DeleteManyOutput> {\n const deletedIds: T['id'][] = []\n const ignoredIds: T['id'][] = []\n\n for await (const entry of this.iterEntries()) {\n if (!predicate(entry)) continue\n\n const didDelete = await this.delete(entry.id)\n if (didDelete) {\n deletedIds.push(entry.id)\n } else {\n ignoredIds.push(entry.id)\n }\n }\n\n return { deletedIds, ignoredIds }\n }\n\n async destroy() {\n await this.files.delete(this.dirpath)\n }\n\n async exists(id: T['id']): Promise<boolean> {\n const entry = await this.readEntry(id)\n return entry !== null\n }\n\n async countAll(): Promise<number> {\n const ids = await this.getAllIds()\n return ids.length\n }\n\n async countWhere(predicate: PredicateFn<T>): Promise<number> {\n return (await this.getWhere(predicate)).length\n }\n\n protected getFilePath(id: T['id']) {\n return path.join(this.dirpath, `${id}.json`)\n }\n\n protected async readEntry(id: T['id']) {\n try {\n const filepath = this.getFilePath(id)\n const text = await this.files.read(filepath)\n const entry = this.parser.parse<T>(text)\n return entry\n } catch {\n // File doesn't exist or invalid JSON\n return null\n }\n }\n\n protected async writeEntry(entry: T) {\n const filepath = this.getFilePath(entry.id)\n await this.files.write(filepath, JSON.stringify(entry, null, 2))\n }\n\n protected async *iterEntries() {\n const ids = await this.getAllIds()\n for (const id of ids) {\n const entry = await this.readEntry(id)\n if (entry) yield entry\n }\n }\n}\n","import type { Identifiable, Promisable } from './types'\nimport { FilesService } from './files'\nimport { JsonParser } from '@jsonkit/tools'\n\nexport class SingleEntryFileDb<T> {\n protected readonly files: FilesService = new FilesService()\n\n constructor(\n protected readonly filepath: string,\n protected readonly parser: JsonParser,\n ) {}\n\n path() {\n return this.filepath\n }\n\n async isInited() {\n const exists = await this.files.exists(this.filepath)\n return exists\n }\n\n async read() {\n const text = await this.files.read(this.filepath)\n const entry = this.parser.parse<T>(text)\n return entry\n }\n\n async write(updaterOrEntry: T | ((entry: T) => Promisable<Partial<T>>)): Promise<T> {\n let entry: T\n if (typeof updaterOrEntry === 'function') {\n const updater = updaterOrEntry as (entry: T) => T\n const existing = await this.read()\n\n const updatedFields = await updater(existing)\n entry = { ...existing, ...updatedFields }\n } else {\n entry = updaterOrEntry\n }\n\n await this.files.write(this.filepath, JSON.stringify(entry, null, 2))\n\n return entry\n }\n\n async delete(): Promise<void> {\n await this.files.delete(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AG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAI,IAAI,CAAC;AACxC,QAAA,OAAO,KAAK;IACd;IAEA,MAAM,KAAK,CAAC,cAA0D,EAAA;AACpE,QAAA,IAAI,KAAQ;AACZ,QAAA,IAAI,OAAO,cAAc,KAAK,UAAU,EAAE;YACxC,MAAM,OAAO,GAAG,cAAiC;AACjD,YAAA,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,IAAI,EAAE;AAElC,YAAA,MAAM,aAAa,GAAG,MAAM,OAAO,CAAC,QAAQ,CAAC;YAC7C,KAAK,GAAG,EAAE,GAAG,QAAQ,EAAE,GAAG,aAAa,EAAE;QAC3C;aAAO;YACL,KAAK,GAAG,cAAc;QACxB;QAEA,MAAM,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;AAErE,QAAA,OAAO,KAAK;IACd;AAEA,IAAA,MAAM,MAAM,GAAA;QACV,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC;IACxC;AACD;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/types.ts","../../src/file/files.ts","../../src/file/multiEntryFileDb.ts","../../src/file/singleEntryFileDb.ts","../../src/memory/multiEntryMemDb.ts","../../src/memory/singleEntryMemDb.ts"],"sourcesContent":["export type Identifiable = {\n id: Id\n}\n\nexport type Id = string\n\nexport type Promisable<T> = T | Promise<T>\n\nexport type DeleteManyOutput = {\n deletedIds: Id[]\n ignoredIds: Id[]\n}\n\nexport type PredicateFn<T extends Identifiable> = (entry: T) => boolean\n\nexport type JsonEntryParser<T> = {\n parse: (text: string) => T\n}\n\nexport type MultiEntryFileDbOptions<T> = {\n noPathlikeIds?: boolean\n parser?: JsonEntryParser<T>\n}\n\nexport type FileMeta = {\n path: string\n size: number\n created: Date\n modified: Date\n accessed: Date\n} & (\n | {\n type: FileType.File\n }\n | {\n type: FileType.Directory\n children: FileMeta[]\n }\n)\n\nexport enum FileType {\n File = 'file',\n Directory = 'directory',\n //Symlink: 'symlink'\n}\n\nexport abstract class SingleEntryDb<T> {\n abstract isInited(): Promise<boolean>\n abstract read(): Promise<T>\n abstract write(updaterOrEntry: T | ((entry: T) => Promisable<Partial<T>>)): Promise<T>\n abstract delete(): Promise<void>\n}\n\nexport abstract class MultiEntryDb<T extends Identifiable> {\n abstract create(entry: T): Promise<T>\n abstract getById(id: T['id']): Promise<T | null>\n abstract getByIdOrThrow(id: T['id']): Promise<T>\n abstract getWhere(predicate: PredicateFn<T>, max?: number): Promise<T[]>\n abstract getAll(whereIds?: T['id'][]): Promise<T[]>\n abstract getAllIds(): Promise<T['id'][]>\n abstract update(id: T['id'], updater: (entry: T) => Promisable<Partial<T>>): Promise<T>\n abstract delete(id: T['id']): Promise<boolean>\n abstract deleteByIds(ids: T['id'][]): Promise<DeleteManyOutput>\n abstract deleteWhere(predicate: PredicateFn<T>): Promise<DeleteManyOutput>\n abstract destroy(): Promise<void>\n abstract exists(id: T['id']): Promise<boolean>\n abstract countAll(): Promise<number>\n abstract countWhere(predicate: PredicateFn<T>): Promise<number>\n}\n","import type { FileMeta } from '../types'\nimport { FileType } from '../types'\nimport * as fs from 'fs/promises'\nimport * as path from 'path'\nimport * as fsSync from 'fs'\nimport * as readline from 'readline'\n\ntype ListOptions = {\n depth?: number\n stripBasepath?: string\n}\n\ntype DeleteOptions = {\n force?: boolean\n recursive?: boolean\n}\n\ntype WriteOptions = {\n encoding?: BufferEncoding\n}\n\ntype ReadOptions = {\n encoding?: BufferEncoding\n lines?: number\n}\n\ntype CopyOptions = {\n recursive?: boolean\n overwrite?: boolean\n}\n\nconst DEFUALT_ENCODING: BufferEncoding = 'utf-8'\n\nexport class Files {\n async move(oldPath: string, newPath: string) {\n await fs.rename(oldPath, newPath)\n }\n\n async copy(sourcePath: string, destinationPath: string, options?: CopyOptions) {\n const { recursive = false, overwrite = true } = options ?? {}\n\n // Check if destination exists and handle overwrite\n if (!overwrite && (await this.exists(destinationPath))) {\n throw new Error(`Destination '${destinationPath}' already exists`)\n }\n\n const sourceStats = await fs.stat(sourcePath)\n\n if (sourceStats.isFile()) {\n const destinationDir = path.dirname(destinationPath)\n await this.mkdirUnsafe(destinationDir)\n await fs.copyFile(sourcePath, destinationPath)\n return\n }\n\n if (sourceStats.isDirectory()) {\n if (!recursive) {\n throw new Error(`'${sourcePath}' is a directory (use recursive option)`)\n }\n await this.copyRecursive(sourcePath, destinationPath)\n }\n }\n\n async copyRecursive(sourcePath: string, destinationPath: string) {\n const sourceStats = await fs.stat(sourcePath)\n\n if (sourceStats.isFile()) {\n const destinationDir = path.dirname(destinationPath)\n await this.mkdirUnsafe(destinationDir)\n await fs.copyFile(sourcePath, destinationPath)\n return\n }\n\n if (sourceStats.isDirectory()) {\n await this.mkdirUnsafe(destinationPath)\n const entries = await fs.readdir(sourcePath)\n\n for (const entry of entries) {\n const sourceEntryPath = path.join(sourcePath, entry)\n const destEntryPath = path.join(destinationPath, entry)\n await this.copyRecursive(sourceEntryPath, destEntryPath)\n }\n }\n }\n\n async mkdir(filepath: string) {\n await this.mkdirUnsafe(filepath)\n }\n\n protected async mkdirUnsafe(filepath: string) {\n await fs.mkdir(filepath, { recursive: true })\n }\n\n async write(filepath: string, content: string, options?: WriteOptions) {\n const { encoding = DEFUALT_ENCODING } = options ?? {}\n\n const parentDirs = path.dirname(filepath)\n await this.mkdirUnsafe(parentDirs)\n\n await fs.writeFile(filepath, content, encoding)\n }\n\n async touch(filepath: string) {\n const exists = await this.exists(filepath)\n if (!exists) await this.write(filepath, '')\n }\n\n async read(filepath: string, options?: ReadOptions) {\n const { encoding = DEFUALT_ENCODING, lines } = options ?? {}\n\n if (lines === undefined) {\n return await fs.readFile(filepath, encoding)\n }\n\n const stream = fsSync.createReadStream(filepath, { encoding })\n const reader = readline.createInterface({\n input: stream,\n crlfDelay: Infinity,\n })\n\n let result = ''\n let linesRead = 0\n for await (const line of reader) {\n if (linesRead >= lines) break\n result += line + '\\n'\n linesRead++\n }\n\n return result\n }\n\n async delete(filepath: string, options?: DeleteOptions) {\n const { force = true, recursive = true } = options ?? {}\n await fs.rm(filepath, { force, recursive })\n }\n\n async exists(filepath: string) {\n try {\n await fs.access(filepath)\n return true\n } catch {\n return false\n }\n }\n\n async isDir(filepath: string) {\n try {\n const stats = await fs.stat(filepath)\n return stats.isDirectory()\n } catch {\n return false\n }\n }\n\n async isFile(filepath: string) {\n try {\n const stats = await fs.stat(filepath)\n return stats.isFile()\n } catch {\n return false\n }\n }\n\n async isSymlink(filepath: string) {\n try {\n const stats = await fs.stat(filepath)\n return stats.isSymbolicLink()\n } catch {\n return false\n }\n }\n\n async getMeta(filepath: string, options?: ListOptions): Promise<FileMeta> {\n const { depth = 0, stripBasepath } = options ?? {}\n const stats = await fs.stat(filepath)\n const isDir = stats.isDirectory()\n const isFile = stats.isFile()\n\n const { size, ctime, mtime, atime } = stats\n const commonMeta = {\n path: this.stripBasepath(filepath, stripBasepath),\n size,\n created: ctime,\n modified: mtime,\n accessed: atime,\n }\n\n if (isDir) {\n const children: FileMeta[] = []\n\n if (depth > 0) {\n const childNames = await this.list(filepath)\n\n for (const child of childNames) {\n const childDepth = Math.max(0, depth - 1)\n const childMeta = await this.getMeta(path.join(filepath, child), {\n depth: childDepth,\n stripBasepath,\n })\n children.push(childMeta)\n }\n }\n\n return {\n ...commonMeta,\n type: FileType.Directory,\n children,\n }\n }\n if (isFile)\n return {\n ...commonMeta,\n type: FileType.File,\n }\n\n throw new Error(`File at ${filepath} is not normal file or directory`)\n }\n\n async list(dirpath: string, options?: ListOptions) {\n const { depth = 0, stripBasepath } = options ?? {}\n if (depth > 0) {\n return await this.listRecursive(dirpath, depth, 0, stripBasepath)\n }\n return await fs.readdir(dirpath)\n }\n\n async *listRead(dirpath: string, options?: ListOptions) {\n const { depth = 0 } = options ?? {}\n\n const files = await this.list(dirpath, { depth })\n\n for (const filepath of files) {\n const isFile = await this.isFile(filepath)\n if (!isFile) continue\n\n try {\n const content = await this.read(filepath)\n yield {\n filepath,\n content,\n }\n } catch {\n // Skip files that can't be read\n continue\n }\n }\n }\n\n protected async listRecursive(\n dirpath: string,\n maxDepth: number,\n currentDepth: number,\n stripBasepath: string | undefined,\n ): Promise<string[]> {\n const results: string[] = []\n const entries = await fs.readdir(dirpath, { withFileTypes: true })\n\n for (const entry of entries) {\n const fullPath = path.join(dirpath, entry.name)\n const strippedPath = this.stripBasepath(fullPath, stripBasepath)\n results.push(strippedPath)\n\n if (entry.isDirectory() && currentDepth < maxDepth) {\n const subResults = await this.listRecursive(\n fullPath,\n maxDepth,\n currentDepth + 1,\n stripBasepath,\n )\n results.push(...subResults)\n }\n }\n\n return results\n }\n\n protected stripBasepath(original: string, pathToStrip: string | undefined): string {\n if (!pathToStrip) return original\n const base = pathToStrip.replace(/^\\/+/, '/').replace(/\\/+$/, '/')\n const stripped = original.replace(base, '')\n return `/${stripped}`\n }\n}\n","import {\n Identifiable,\n DeleteManyOutput,\n Promisable,\n PredicateFn,\n JsonEntryParser,\n MultiEntryFileDbOptions,\n MultiEntryDb,\n} from '../types'\nimport { Files } from './files'\nimport * as path from 'path'\n\nexport class MultiEntryFileDb<T extends Identifiable> extends MultiEntryDb<T> {\n protected readonly files: Files\n protected readonly parser: JsonEntryParser<T>\n readonly noPathlikeIds: boolean\n\n constructor(\n protected readonly dirpath: string,\n options?: MultiEntryFileDbOptions<T>,\n ) {\n super()\n this.files = new Files()\n this.parser = options?.parser ?? JSON\n this.noPathlikeIds = options?.noPathlikeIds ?? true\n }\n\n async create(entry: T): Promise<T> {\n await this.writeEntry(entry)\n return entry\n }\n\n async getById(id: T['id']): Promise<T | null> {\n return await this.readEntry(id)\n }\n\n async getByIdOrThrow(id: T['id']): Promise<T> {\n const entry = await this.readEntry(id)\n if (!entry) {\n throw new Error('Entry with id ' + id + ' does not exist')\n }\n return entry\n }\n\n async getWhere(predicate: PredicateFn<T>, max?: number): Promise<T[]> {\n const entries = await this.getAll()\n return entries.filter(predicate).slice(0, max)\n }\n\n async getAll(whereIds?: T['id'][]): Promise<T[]> {\n const ids = whereIds === undefined ? await this.getAllIds() : whereIds\n const entries: T[] = []\n\n for (const id of ids) {\n const entry = await this.readEntry(id)\n if (entry) entries.push(entry)\n }\n\n return entries\n }\n\n async getAllIds(): Promise<T['id'][]> {\n try {\n const entries = await this.files.list(this.dirpath)\n return entries.filter((name) => name.endsWith('.json')).map((name) => name.slice(0, -5)) // Remove .json extension\n } catch {\n // Directory might not exist\n return []\n }\n }\n\n async update(id: T['id'], updater: (entry: T) => Promisable<Partial<T>>): Promise<T> {\n const entry = await this.readEntry(id)\n if (!entry) {\n throw new Error('Entry with id ' + id + ' does not exist')\n }\n\n const updatedEntryFields = await updater(entry)\n const updatedEntry = { ...entry, ...updatedEntryFields }\n await this.writeEntry(updatedEntry)\n\n if (updatedEntry.id !== id) {\n await this.delete(id)\n }\n\n return updatedEntry\n }\n\n async delete(id: T['id']): Promise<boolean> {\n try {\n const filepath = this.getFilePath(id)\n await this.files.delete(filepath, { force: false })\n return true\n } catch {\n // File might not exist, ignore error\n return false\n }\n }\n\n async deleteByIds(ids: T['id'][]): Promise<DeleteManyOutput> {\n return this.deleteWhere((entry) => ids.includes(entry.id))\n }\n\n async deleteWhere(predicate: PredicateFn<T>): Promise<DeleteManyOutput> {\n const deletedIds: T['id'][] = []\n const ignoredIds: T['id'][] = []\n\n for await (const entry of this.iterEntries()) {\n if (!predicate(entry)) continue\n\n const didDelete = await this.delete(entry.id)\n if (didDelete) {\n deletedIds.push(entry.id)\n } else {\n ignoredIds.push(entry.id)\n }\n }\n\n return { deletedIds, ignoredIds }\n }\n\n async destroy() {\n await this.files.delete(this.dirpath)\n }\n\n async exists(id: T['id']): Promise<boolean> {\n const entry = await this.readEntry(id)\n return entry !== null\n }\n\n async countAll(): Promise<number> {\n const ids = await this.getAllIds()\n return ids.length\n }\n\n async countWhere(predicate: PredicateFn<T>): Promise<number> {\n return (await this.getWhere(predicate)).length\n }\n\n protected getFilePath(id: T['id']) {\n return path.join(this.dirpath, `${id}.json`)\n }\n\n protected async readEntry(id: T['id']) {\n if (!this.isIdValid(id)) throw new Error(`Invalid id: ${id}`)\n\n try {\n const filepath = this.getFilePath(id)\n const text = await this.files.read(filepath)\n const entry = this.parser.parse(text)\n return entry\n } catch (error) {\n console.error('Failed to read entry', error)\n // File doesn't exist or invalid JSON\n return null\n }\n }\n\n protected async writeEntry(entry: T) {\n if (!this.isIdValid(entry.id)) throw new Error(`Invalid id: ${entry.id}`)\n\n const filepath = this.getFilePath(entry.id)\n await this.files.write(filepath, JSON.stringify(entry, null, 2))\n }\n\n isIdValid(id: T['id']): boolean {\n if (typeof id !== 'string') return false\n\n if (!this.noPathlikeIds) return true\n\n if (id.includes('/') || id.includes('\\\\')) return false\n\n return true\n }\n\n protected async *iterEntries() {\n const ids = await this.getAllIds()\n for (const id of ids) {\n const entry = await this.readEntry(id)\n if (entry) yield entry\n }\n }\n}\n","import { JsonEntryParser, Promisable, SingleEntryDb } from '../types'\nimport { Files } from './files'\n\nexport class SingleEntryFileDb<T> extends SingleEntryDb<T> {\n protected readonly files: Files = new Files()\n\n constructor(\n protected readonly filepath: string,\n protected readonly parser: JsonEntryParser<T> = JSON,\n ) {\n super()\n }\n\n path() {\n return this.filepath\n }\n\n async isInited() {\n const exists = await this.files.exists(this.filepath)\n return exists\n }\n\n async read() {\n const text = await this.files.read(this.filepath)\n const entry = this.parser.parse(text)\n return entry\n }\n\n async write(updaterOrEntry: T | ((entry: T) => Promisable<Partial<T>>)): Promise<T> {\n let entry: T\n if (typeof updaterOrEntry === 'function') {\n const updater = updaterOrEntry as (entry: T) => T\n const existing = await this.read()\n\n const updatedFields = await updater(existing)\n entry = { ...existing, ...updatedFields }\n } else {\n entry = updaterOrEntry\n }\n\n await this.files.write(this.filepath, JSON.stringify(entry, null, 2))\n\n return entry\n }\n\n async delete(): Promise<void> {\n await this.files.delete(this.filepath)\n }\n}\n","import { Identifiable, DeleteManyOutput, Promisable, PredicateFn, MultiEntryDb } from '../types'\n\nexport class MultiEntryMemDb<T extends Identifiable> extends MultiEntryDb<T> {\n protected entries: Map<T['id'], T> = new Map()\n\n async create(entry: T): Promise<T> {\n this.entries.set(entry.id, entry)\n return entry\n }\n\n async getById(id: T['id']): Promise<T | null> {\n return this.entries.get(id) ?? null\n }\n\n async getByIdOrThrow(id: T['id']): Promise<T> {\n const entry = await this.getById(id)\n if (!entry) {\n throw new Error('Entry with id ' + id + ' does not exist')\n }\n return entry\n }\n\n async getWhere(predicate: PredicateFn<T>, max?: number): Promise<T[]> {\n const entries = Array.from(this.entries.values()).filter(predicate)\n return max !== undefined ? entries.slice(0, max) : entries\n }\n\n async getAll(whereIds?: T['id'][]): Promise<T[]> {\n if (whereIds === undefined) {\n return Array.from(this.entries.values())\n }\n\n const entries: T[] = []\n for (const id of whereIds) {\n const entry = this.entries.get(id)\n if (entry) entries.push(entry)\n }\n return entries\n }\n\n async getAllIds(): Promise<T['id'][]> {\n return Array.from(this.entries.keys())\n }\n\n async update(id: T['id'], updater: (entry: T) => Promisable<Partial<T>>): Promise<T> {\n const entry = this.entries.get(id)\n if (!entry) {\n throw new Error('Entry with id ' + id + ' does not exist')\n }\n\n const updatedEntryFields = await updater(entry)\n const updatedEntry = { ...entry, ...updatedEntryFields }\n\n this.entries.set(updatedEntry.id, updatedEntry)\n\n if (updatedEntry.id !== id) {\n this.entries.delete(id)\n }\n\n return updatedEntry\n }\n\n async delete(id: T['id']): Promise<boolean> {\n return this.entries.delete(id)\n }\n\n async deleteByIds(ids: T['id'][]): Promise<DeleteManyOutput> {\n return this.deleteWhere((entry) => ids.includes(entry.id))\n }\n\n async deleteWhere(predicate: PredicateFn<T>): Promise<DeleteManyOutput> {\n const deletedIds: T['id'][] = []\n const ignoredIds: T['id'][] = []\n\n for (const [id, entry] of this.entries) {\n if (!predicate(entry)) continue\n\n const didDelete = await this.delete(id)\n if (didDelete) {\n deletedIds.push(id)\n } else {\n ignoredIds.push(id)\n }\n }\n\n return { deletedIds, ignoredIds }\n }\n\n async destroy() {\n this.entries.clear()\n }\n\n async exists(id: T['id']): Promise<boolean> {\n return this.entries.has(id)\n }\n\n async countAll(): Promise<number> {\n return this.entries.size\n }\n\n async countWhere(predicate: PredicateFn<T>): Promise<number> {\n return Array.from(this.entries.values()).filter(predicate).length\n }\n\n protected async *iterEntries() {\n for (const entry of this.entries.values()) {\n yield entry\n }\n }\n}\n","import { Promisable, SingleEntryDb } from '../types'\n\nexport class SingleEntryMemDb<T> extends SingleEntryDb<T> {\n protected entry: T | null = null\n\n constructor(initialEntry: T | null = null) {\n super()\n this.entry = initialEntry\n }\n\n async isInited() {\n return this.entry !== null\n }\n\n async read() {\n if (this.entry === null) throw new Error('Entry not initialized')\n return this.entry!\n }\n\n async write(updaterOrEntry: T | ((entry: T) => Promisable<Partial<T>>)): Promise<T> {\n let entry: T\n\n if (typeof updaterOrEntry === 'function') {\n const updater = updaterOrEntry as (entry: T) => Promisable<Partial<T>>\n\n if (this.entry === null) {\n throw new Error('Cannot update uninitialized entry. Use write(entry) to initialize first.')\n }\n\n const updatedFields = await updater(this.entry)\n entry = { ...this.entry, ...updatedFields }\n } else {\n entry = updaterOrEntry\n }\n\n this.entry = entry\n return entry\n }\n\n async delete(): Promise<void> {\n this.entry = null\n }\n}\n"],"names":["FileType","fs","path","fsSync","readline"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCYA;AAAZ,CAAA,UAAY,QAAQ,EAAA;AAClB,IAAA,QAAA,CAAA,MAAA,CAAA,GAAA,MAAa;AACb,IAAA,QAAA,CAAA,WAAA,CAAA,GAAA,WAAuB;;AAEzB,CAAC,EAJWA,gBAAQ,KAARA,gBAAQ,GAAA,EAAA,CAAA,CAAA;MAME,aAAa,CAAA;AAKlC;MAEqB,YAAY,CAAA;AAejC;;ACrCD,MAAM,gBAAgB,GAAmB,OAAO;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