@jsonkit/db 4.0.0 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -13
- package/dist/cjs/index.cjs +76 -69
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/index.js +76 -69
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.ts +21 -11
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
package/dist/esm/index.js
CHANGED
|
@@ -18,11 +18,42 @@ class InvalidIdError extends DbError {
|
|
|
18
18
|
}
|
|
19
19
|
class UninitError extends DbError {
|
|
20
20
|
constructor() {
|
|
21
|
-
super('Cannot read or update uninitialized entry. Use write(entry) to initialize first
|
|
21
|
+
super('Cannot read or update uninitialized entry. Use write(entry) to initialize first');
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
class MultiEntryDb {
|
|
26
|
+
async *iterWhere(predicate, pagination) {
|
|
27
|
+
if (!pagination) {
|
|
28
|
+
for await (const entry of this.iterEntries()) {
|
|
29
|
+
const isMatch = await predicate(entry);
|
|
30
|
+
if (isMatch)
|
|
31
|
+
yield entry;
|
|
32
|
+
}
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const { take, page } = pagination;
|
|
36
|
+
this.validatePaginationField(take, 'take');
|
|
37
|
+
this.validatePaginationField(page, 'page');
|
|
38
|
+
const startIndex = page * take;
|
|
39
|
+
const endIndex = startIndex + take;
|
|
40
|
+
let totalMatched = 0;
|
|
41
|
+
for await (const entry of this.iterEntries()) {
|
|
42
|
+
if (totalMatched >= endIndex)
|
|
43
|
+
break;
|
|
44
|
+
const isMatch = await predicate(entry);
|
|
45
|
+
totalMatched++;
|
|
46
|
+
if (isMatch && totalMatched - 1 >= startIndex) {
|
|
47
|
+
yield entry;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
validatePaginationField(field, fieldName) {
|
|
52
|
+
if (isNaN(field))
|
|
53
|
+
throw new Error(`PaginationInput.${fieldName} must not be NaN`);
|
|
54
|
+
if (field < 0)
|
|
55
|
+
throw new Error(`PaginationInput.${fieldName} must not be less than 0, got ${field}`);
|
|
56
|
+
}
|
|
26
57
|
async getByIdOrThrow(id) {
|
|
27
58
|
const entry = await this.getById(id);
|
|
28
59
|
if (!entry)
|
|
@@ -40,30 +71,9 @@ class MultiEntryDb {
|
|
|
40
71
|
return match;
|
|
41
72
|
}
|
|
42
73
|
async getWhere(predicate, pagination) {
|
|
43
|
-
let totalMatched = 0;
|
|
44
74
|
const entries = [];
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const isMatch = predicate(entry);
|
|
48
|
-
if (isMatch)
|
|
49
|
-
entries.push(entry);
|
|
50
|
-
}
|
|
51
|
-
return entries;
|
|
52
|
-
}
|
|
53
|
-
const { take, page } = pagination;
|
|
54
|
-
const skip = pagination.skip ?? 0;
|
|
55
|
-
const startIndex = (page - 1) * take + skip;
|
|
56
|
-
const endIndex = startIndex + take;
|
|
57
|
-
for await (const entry of this.iterEntries()) {
|
|
58
|
-
const isMatch = predicate(entry);
|
|
59
|
-
if (isMatch) {
|
|
60
|
-
if (totalMatched >= startIndex && totalMatched < endIndex) {
|
|
61
|
-
entries.push(entry);
|
|
62
|
-
}
|
|
63
|
-
totalMatched++;
|
|
64
|
-
if (totalMatched >= endIndex)
|
|
65
|
-
break;
|
|
66
|
-
}
|
|
75
|
+
for await (const entry of this.iterWhere(predicate, pagination)) {
|
|
76
|
+
entries.push(entry);
|
|
67
77
|
}
|
|
68
78
|
return entries;
|
|
69
79
|
}
|
|
@@ -77,15 +87,27 @@ class MultiEntryDb {
|
|
|
77
87
|
}
|
|
78
88
|
return ids;
|
|
79
89
|
}
|
|
90
|
+
async updateById(id, updater) {
|
|
91
|
+
const entry = await this.getByIdOrThrow(id);
|
|
92
|
+
return this.updateEntry(entry, updater);
|
|
93
|
+
}
|
|
94
|
+
async updateFirstWhere(predicate, updater) {
|
|
95
|
+
return this.updateWhere(predicate, updater, { page: 0, take: 1 });
|
|
96
|
+
}
|
|
97
|
+
async updateWhere(predicate, updater, pagination) {
|
|
98
|
+
const result = [];
|
|
99
|
+
for await (const entry of this.iterWhere(predicate, pagination)) {
|
|
100
|
+
result.push(await this.updateEntry(entry, updater));
|
|
101
|
+
}
|
|
102
|
+
return result;
|
|
103
|
+
}
|
|
80
104
|
deleteByIds(ids) {
|
|
81
105
|
return this.deleteWhere((entry) => ids.includes(entry.id));
|
|
82
106
|
}
|
|
83
107
|
async deleteWhere(predicate) {
|
|
84
108
|
const deletedIds = [];
|
|
85
109
|
const ignoredIds = [];
|
|
86
|
-
for await (const entry of this.
|
|
87
|
-
if (!predicate(entry))
|
|
88
|
-
continue;
|
|
110
|
+
for await (const entry of this.iterWhere(predicate)) {
|
|
89
111
|
const didDelete = await this.deleteById(entry.id);
|
|
90
112
|
if (didDelete) {
|
|
91
113
|
deletedIds.push(entry.id);
|
|
@@ -97,37 +119,15 @@ class MultiEntryDb {
|
|
|
97
119
|
return { deletedIds, ignoredIds };
|
|
98
120
|
}
|
|
99
121
|
async exists(id) {
|
|
100
|
-
|
|
101
|
-
return entry !== null;
|
|
122
|
+
return (await this.getById(id)) !== null;
|
|
102
123
|
}
|
|
103
124
|
countAll() {
|
|
104
125
|
return this.countWhere(() => true);
|
|
105
126
|
}
|
|
106
127
|
async countWhere(predicate, pagination) {
|
|
107
|
-
let totalMatched = 0;
|
|
108
128
|
let count = 0;
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
const isMatch = predicate(entry);
|
|
112
|
-
if (isMatch)
|
|
113
|
-
count++;
|
|
114
|
-
}
|
|
115
|
-
return count;
|
|
116
|
-
}
|
|
117
|
-
const { take, page } = pagination;
|
|
118
|
-
const skip = pagination.skip ?? 0;
|
|
119
|
-
const startIndex = (page - 1) * take + skip;
|
|
120
|
-
const endIndex = startIndex + take;
|
|
121
|
-
for await (const entry of this.iterEntries()) {
|
|
122
|
-
const isMatch = predicate(entry);
|
|
123
|
-
if (isMatch) {
|
|
124
|
-
if (totalMatched >= startIndex && totalMatched < endIndex)
|
|
125
|
-
count++;
|
|
126
|
-
totalMatched++;
|
|
127
|
-
if (totalMatched >= endIndex)
|
|
128
|
-
break;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
129
|
+
for await (const _ of this.iterWhere(predicate, pagination))
|
|
130
|
+
count++;
|
|
131
131
|
return count;
|
|
132
132
|
}
|
|
133
133
|
}
|
|
@@ -135,6 +135,10 @@ class MultiEntryDb {
|
|
|
135
135
|
class SingleEntryDb {
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
+
function runJsonEntryParser(parser, text) {
|
|
139
|
+
return typeof parser === 'function' ? parser(text) : parser.parse(text);
|
|
140
|
+
}
|
|
141
|
+
|
|
138
142
|
var FileType;
|
|
139
143
|
(function (FileType) {
|
|
140
144
|
FileType["File"] = "file";
|
|
@@ -355,6 +359,7 @@ class MultiEntryFileDb extends MultiEntryDb {
|
|
|
355
359
|
dirpath;
|
|
356
360
|
files;
|
|
357
361
|
parser;
|
|
362
|
+
disableLogs;
|
|
358
363
|
noPathlikeIds;
|
|
359
364
|
constructor(dirpath, options) {
|
|
360
365
|
super();
|
|
@@ -362,6 +367,7 @@ class MultiEntryFileDb extends MultiEntryDb {
|
|
|
362
367
|
this.files = new Files();
|
|
363
368
|
this.parser = options?.parser ?? JSON;
|
|
364
369
|
this.noPathlikeIds = options?.noPathlikeIds ?? true;
|
|
370
|
+
this.disableLogs = options?.disableLogs ?? false;
|
|
365
371
|
}
|
|
366
372
|
async create(entry) {
|
|
367
373
|
await this.writeEntry(entry);
|
|
@@ -373,22 +379,22 @@ class MultiEntryFileDb extends MultiEntryDb {
|
|
|
373
379
|
try {
|
|
374
380
|
const filepath = this.getFilePath(id);
|
|
375
381
|
const text = await this.files.read(filepath);
|
|
376
|
-
const entry = this.parser
|
|
382
|
+
const entry = runJsonEntryParser(this.parser, text);
|
|
377
383
|
return entry;
|
|
378
384
|
}
|
|
379
385
|
catch (error) {
|
|
380
|
-
|
|
386
|
+
if (!this.disableLogs)
|
|
387
|
+
console.error('Failed to read entry', error);
|
|
381
388
|
// File doesn't exist or invalid JSON
|
|
382
389
|
return null;
|
|
383
390
|
}
|
|
384
391
|
}
|
|
385
|
-
async
|
|
386
|
-
const entry = await this.getByIdOrThrow(id);
|
|
392
|
+
async updateEntry(entry, updater) {
|
|
387
393
|
const updatedEntryFields = await updater(entry);
|
|
388
394
|
const updatedEntry = { ...entry, ...updatedEntryFields };
|
|
389
395
|
await this.writeEntry(updatedEntry);
|
|
390
|
-
if (updatedEntry.id !== id) {
|
|
391
|
-
await this.deleteById(id);
|
|
396
|
+
if (updatedEntry.id !== entry.id) {
|
|
397
|
+
await this.deleteById(entry.id);
|
|
392
398
|
}
|
|
393
399
|
return updatedEntry;
|
|
394
400
|
}
|
|
@@ -410,7 +416,7 @@ class MultiEntryFileDb extends MultiEntryDb {
|
|
|
410
416
|
await this.files.delete(this.dirpath);
|
|
411
417
|
}
|
|
412
418
|
getFilePath(id) {
|
|
413
|
-
return path.join(this.dirpath, `${id}.json`);
|
|
419
|
+
return path.join(this.dirpath, `${String(id)}.json`);
|
|
414
420
|
}
|
|
415
421
|
async writeEntry(entry) {
|
|
416
422
|
if (!this.isIdValid(entry.id))
|
|
@@ -418,11 +424,10 @@ class MultiEntryFileDb extends MultiEntryDb {
|
|
|
418
424
|
const filepath = this.getFilePath(entry.id);
|
|
419
425
|
await this.files.write(filepath, JSON.stringify(entry, null, 2));
|
|
420
426
|
}
|
|
421
|
-
isIdValid(
|
|
422
|
-
if (typeof id !== 'string')
|
|
423
|
-
return false;
|
|
427
|
+
isIdValid(rawId) {
|
|
424
428
|
if (!this.noPathlikeIds)
|
|
425
429
|
return true;
|
|
430
|
+
const id = String(rawId);
|
|
426
431
|
if (id.includes('/') || id.includes('\\'))
|
|
427
432
|
return false;
|
|
428
433
|
return true;
|
|
@@ -434,12 +439,13 @@ class MultiEntryFileDb extends MultiEntryDb {
|
|
|
434
439
|
yield entry;
|
|
435
440
|
}
|
|
436
441
|
}
|
|
437
|
-
async *iterIds() {
|
|
442
|
+
async *iterIds(objectIdParser) {
|
|
438
443
|
const filenames = await this.files.list(this.dirpath);
|
|
439
444
|
for (const filename of filenames) {
|
|
440
445
|
if (!filename.endsWith('.json'))
|
|
441
446
|
continue;
|
|
442
|
-
const
|
|
447
|
+
const stringId = filename.replace(/\.json$/, '');
|
|
448
|
+
const id = objectIdParser ? runJsonEntryParser(objectIdParser, stringId) : stringId;
|
|
443
449
|
if (this.isIdValid(id))
|
|
444
450
|
yield id;
|
|
445
451
|
}
|
|
@@ -464,7 +470,7 @@ class SingleEntryFileDb extends SingleEntryDb {
|
|
|
464
470
|
}
|
|
465
471
|
async read() {
|
|
466
472
|
const text = await this.files.read(this.filepath);
|
|
467
|
-
const entry = this.parser
|
|
473
|
+
const entry = runJsonEntryParser(this.parser, text);
|
|
468
474
|
return entry;
|
|
469
475
|
}
|
|
470
476
|
async write(updaterOrEntry) {
|
|
@@ -495,13 +501,13 @@ class MultiEntryMemDb extends MultiEntryDb {
|
|
|
495
501
|
async getById(id) {
|
|
496
502
|
return this.entries.get(id) ?? null;
|
|
497
503
|
}
|
|
498
|
-
async
|
|
499
|
-
const entry = await this.getByIdOrThrow(id);
|
|
504
|
+
async updateEntry(entry, updater) {
|
|
500
505
|
const updatedEntryFields = await updater(entry);
|
|
501
506
|
const updatedEntry = { ...entry, ...updatedEntryFields };
|
|
502
507
|
this.entries.set(updatedEntry.id, updatedEntry);
|
|
503
|
-
if (updatedEntry.id !== id)
|
|
504
|
-
this.
|
|
508
|
+
if (updatedEntry.id !== entry.id) {
|
|
509
|
+
await this.deleteById(entry.id);
|
|
510
|
+
}
|
|
505
511
|
return updatedEntry;
|
|
506
512
|
}
|
|
507
513
|
async deleteById(id) {
|
|
@@ -528,6 +534,7 @@ class MultiEntryMemDb extends MultiEntryDb {
|
|
|
528
534
|
}
|
|
529
535
|
async load(dirpath, parser) {
|
|
530
536
|
const fileDb = new MultiEntryFileDb(dirpath, { parser });
|
|
537
|
+
await this.destroy();
|
|
531
538
|
for await (const entry of fileDb.iterEntries()) {
|
|
532
539
|
await this.create(entry);
|
|
533
540
|
}
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/common/errors.ts","../../../src/common/multiEntryDb.ts","../../../src/common/singleEntryDb.ts","../../../src/common/types.ts","../../../src/file/files.ts","../../../src/file/multiEntryFileDb.ts","../../../src/file/singleEntryFileDb.ts","../../../src/memory/multiEntryMemDb.ts","../../../src/memory/singleEntryMemDb.ts"],"sourcesContent":["export class DbError extends Error {}\n\nexport class NotFoundError extends DbError {}\n\nexport class ConflictError extends DbError {}\n\nexport class FileIoError extends DbError {}\n\nexport class InvalidIdError extends DbError {\n constructor(id: unknown) {\n super(`Invalid entry id '${id}'`)\n }\n}\n\nexport class UninitError extends DbError {\n constructor() {\n super('Cannot read or update uninitialized entry. Use write(entry) to initialize first.')\n }\n}\n","import { NotFoundError } from './errors'\nimport type {\n Identifiable,\n DeleteManyOutput,\n PaginationInput,\n PredicateFn,\n UpdaterFn,\n} from './types'\n\nexport abstract class MultiEntryDb<T extends Identifiable> {\n abstract create(entry: T): Promise<T>\n\n abstract getById(id: T['id']): Promise<T | null>\n\n abstract update(id: T['id'], updater: UpdaterFn<T>): Promise<T>\n\n abstract deleteById(id: T['id']): Promise<boolean>\n\n abstract destroy(): Promise<void>\n\n abstract iterEntries(): AsyncIterable<T>\n\n abstract iterIds(): AsyncIterable<T['id']>\n\n async getByIdOrThrow(id: T['id']): Promise<T> {\n const entry = await this.getById(id)\n if (!entry) throw new NotFoundError(`Entry with id '${id}' does not exist`)\n return entry\n }\n\n async getFirstWhere(predicate: PredicateFn<T>): Promise<T | null> {\n const matches = await this.getWhere(predicate, { page: 0, take: 1 })\n return matches.at(0) ?? null\n }\n\n async getFirstWhereOrThrow(predicate: PredicateFn<T>): Promise<T | null> {\n const match = await this.getFirstWhere(predicate)\n if (!match) throw new NotFoundError('No entry matches predicate')\n return match\n }\n\n async getWhere(predicate: PredicateFn<T>, pagination?: PaginationInput): Promise<T[]> {\n let totalMatched = 0\n const entries: T[] = []\n\n if (!pagination) {\n for await (const entry of this.iterEntries()) {\n const isMatch = predicate(entry)\n if (isMatch) entries.push(entry)\n }\n return entries\n }\n\n const { take, page } = pagination\n const skip = pagination.skip ?? 0\n const startIndex = (page - 1) * take + skip\n const endIndex = startIndex + take\n\n for await (const entry of this.iterEntries()) {\n const isMatch = predicate(entry)\n if (isMatch) {\n if (totalMatched >= startIndex && totalMatched < endIndex) {\n entries.push(entry)\n }\n totalMatched++\n\n if (totalMatched >= endIndex) break\n }\n }\n\n return entries\n }\n\n getAll(): Promise<T[]> {\n return this.getWhere(() => true)\n }\n\n async getAllIds(): Promise<T['id'][]> {\n const ids: T['id'][] = []\n for await (const id of this.iterIds()) {\n ids.push(id)\n }\n return ids\n }\n\n 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.deleteById(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 exists(id: T['id']): Promise<boolean> {\n const entry = await this.getById(id)\n return entry !== null\n }\n\n countAll(): Promise<number> {\n return this.countWhere(() => true)\n }\n\n async countWhere(predicate: PredicateFn<T>, pagination?: PaginationInput): Promise<number> {\n let totalMatched = 0\n let count = 0\n\n if (!pagination) {\n for await (const entry of this.iterEntries()) {\n const isMatch = predicate(entry)\n if (isMatch) count++\n }\n return count\n }\n\n const { take, page } = pagination\n const skip = pagination.skip ?? 0\n const startIndex = (page - 1) * take + skip\n const endIndex = startIndex + take\n\n for await (const entry of this.iterEntries()) {\n const isMatch = predicate(entry)\n if (isMatch) {\n if (totalMatched >= startIndex && totalMatched < endIndex) count++\n totalMatched++\n\n if (totalMatched >= endIndex) break\n }\n }\n\n return count\n }\n}\n","import type { Promisable, UpdaterFn } from '../common/types'\n\nexport abstract class SingleEntryDb<T> {\n abstract isInited(): Promise<boolean>\n abstract read(): Promise<T>\n abstract write(updaterOrEntry: T | UpdaterFn<T>): Promise<T>\n abstract delete(): Promise<void>\n}\n","export type Identifiable = {\n id: Id\n}\n\nexport type Id = string\n\nexport type Promisable<T> = T | Promise<T>\n\nexport type PaginationInput = {\n take: number\n page: number\n skip?: number | undefined | null\n}\n\nexport type DeleteManyOutput = {\n deletedIds: Id[]\n ignoredIds: Id[]\n}\n\nexport type PredicateFn<T extends Identifiable> = (entry: T) => boolean\n\nexport type UpdaterFn<T> = (entry: T) => Promisable<Partial<T>>\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","import type { FileMeta } from '../common'\nimport { FileType, FileIoError } from '../common'\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 FileIoError(`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 FileIoError(`'${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 FileIoError(`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 JsonEntryParser,\n MultiEntryFileDbOptions,\n MultiEntryDb,\n InvalidIdError,\n} from '../common'\nimport { Files } from './files'\nimport * as path from 'path'\n\nexport class MultiEntryFileDb<T extends Identifiable> extends MultiEntryDb<T> {\n protected readonly dirpath: string\n protected readonly files: Files\n protected readonly parser: JsonEntryParser<T>\n readonly noPathlikeIds: boolean\n\n constructor(dirpath: string, options?: MultiEntryFileDbOptions<T>) {\n super()\n this.dirpath = dirpath\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 if (!this.isIdValid(id)) throw new InvalidIdError(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 async update(id: T['id'], updater: (entry: T) => Promisable<Partial<T>>): Promise<T> {\n const entry = await this.getByIdOrThrow(id)\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.deleteById(id)\n }\n\n return updatedEntry\n }\n\n async deleteById(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 destroy() {\n await this.files.delete(this.dirpath)\n }\n\n protected getFilePath(id: T['id']) {\n return path.join(this.dirpath, `${id}.json`)\n }\n\n protected async writeEntry(entry: T) {\n if (!this.isIdValid(entry.id)) throw new InvalidIdError(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 async *iterEntries() {\n for await (const id of this.iterIds()) {\n const entry = await this.getById(id)\n if (entry) yield entry\n }\n }\n\n async *iterIds() {\n const filenames = await this.files.list(this.dirpath)\n for (const filename of filenames) {\n if (!filename.endsWith('.json')) continue\n\n const id = filename.replace(/\\.json$/, '')\n if (this.isIdValid(id)) yield id\n }\n }\n}\n","import { SingleEntryDb, JsonEntryParser, Promisable } from '../common'\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, Promisable, MultiEntryDb, JsonEntryParser } from '../common'\nimport { MultiEntryFileDb } from '../file/multiEntryFileDb'\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 update(id: T['id'], updater: (entry: T) => Promisable<Partial<T>>): Promise<T> {\n const entry = await this.getByIdOrThrow(id)\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) this.entries.delete(id)\n\n return updatedEntry\n }\n\n async deleteById(id: T['id']): Promise<boolean> {\n return this.entries.delete(id)\n }\n\n async destroy() {\n this.entries.clear()\n }\n\n async *iterEntries() {\n for (const entry of this.entries.values()) {\n yield entry\n }\n }\n\n async *iterIds() {\n for (const id of this.entries.keys()) {\n yield id\n }\n }\n\n async persist(dirpath: string) {\n const fileDb = new MultiEntryFileDb<T>(dirpath)\n await fileDb.destroy()\n\n const values = [...this.entries.values()]\n await Promise.all(values.map((entry) => fileDb.create(entry)))\n }\n\n async load(dirpath: string, parser?: JsonEntryParser<T>) {\n const fileDb = new MultiEntryFileDb<T>(dirpath, { parser })\n\n for await (const entry of fileDb.iterEntries()) {\n await this.create(entry)\n }\n }\n}\n","import { JsonEntryParser, SingleEntryDb, UninitError, UpdaterFn } from '../common'\nimport { SingleEntryFileDb } from '../file/singleEntryFileDb'\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 UninitError()\n return this.entry\n }\n\n async write(updaterOrEntry: T | UpdaterFn<T>) {\n let entry: T\n\n if (typeof updaterOrEntry === 'function') {\n const updater = updaterOrEntry as (entry: T) => Partial<T>\n\n if (this.entry === null) throw new UninitError()\n\n const updatedFields = 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() {\n this.entry = null\n }\n\n async persist(filepath: string) {\n const fileDb = new SingleEntryFileDb<T>(filepath)\n await fileDb.write(await this.read())\n }\n\n async load(filepath: string, parser?: JsonEntryParser<T>) {\n const fileDb = new SingleEntryFileDb<T>(filepath, parser)\n const persistedEntry = await fileDb.read()\n this.write(persistedEntry)\n }\n}\n"],"names":[],"mappings":";;;;;AAAM,MAAO,OAAQ,SAAQ,KAAK,CAAA;AAAG;AAE/B,MAAO,aAAc,SAAQ,OAAO,CAAA;AAAG;AAEvC,MAAO,aAAc,SAAQ,OAAO,CAAA;AAAG;AAEvC,MAAO,WAAY,SAAQ,OAAO,CAAA;AAAG;AAErC,MAAO,cAAe,SAAQ,OAAO,CAAA;AACzC,IAAA,WAAA,CAAY,EAAW,EAAA;AACrB,QAAA,KAAK,CAAC,CAAA,kBAAA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G,cAAc;QACxB;AAEA,QAAA,IAAI,CAAC,KAAK,GAAG,KAAK;AAClB,QAAA,OAAO,KAAK;IACd;AAEA,IAAA,MAAM,MAAM,GAAA;AACV,QAAA,IAAI,CAAC,KAAK,GAAG,IAAI;IACnB;IAEA,MAAM,OAAO,CAAC,QAAgB,EAAA;AAC5B,QAAA,MAAM,MAAM,GAAG,IAAI,iBAAiB,CAAI,QAAQ,CAAC;QACjD,MAAM,MAAM,CAAC,KAAK,CAAC,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC;IACvC;AAEA,IAAA,MAAM,IAAI,CAAC,QAAgB,EAAE,MAA2B,EAAA;QACtD,MAAM,MAAM,GAAG,IAAI,iBAAiB,CAAI,QAAQ,EAAE,MAAM,CAAC;AACzD,QAAA,MAAM,cAAc,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE;AAC1C,QAAA,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC;IAC5B;AACD;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/common/errors.ts","../../../src/common/multiEntryDb.ts","../../../src/common/singleEntryDb.ts","../../../src/common/runJsonEntryParser.ts","../../../src/common/types.ts","../../../src/file/files.ts","../../../src/file/multiEntryFileDb.ts","../../../src/file/singleEntryFileDb.ts","../../../src/memory/multiEntryMemDb.ts","../../../src/memory/singleEntryMemDb.ts"],"sourcesContent":["export class DbError extends Error {}\n\nexport class NotFoundError extends DbError {}\n\nexport class ConflictError extends DbError {}\n\nexport class FileIoError extends DbError {}\n\nexport class InvalidIdError extends DbError {\n constructor(id: unknown) {\n super(`Invalid entry id '${id}'`)\n }\n}\n\nexport class UninitError extends DbError {\n constructor() {\n super('Cannot read or update uninitialized entry. Use write(entry) to initialize first')\n }\n}\n","import { NotFoundError } from './errors'\nimport type {\n Identifiable,\n DeleteManyOutput,\n PaginationInput,\n PredicateFn,\n UpdaterFn,\n} from './types'\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 protected abstract updateEntry(entry: T, updater: UpdaterFn<T>): Promise<T>\n abstract deleteById(id: T['id']): Promise<boolean>\n abstract destroy(): Promise<void>\n abstract iterEntries(): AsyncIterable<T>\n abstract iterIds(): AsyncIterable<T['id']>\n\n private async *iterWhere(\n predicate: PredicateFn<T>,\n pagination?: PaginationInput,\n ): AsyncIterable<T> {\n if (!pagination) {\n for await (const entry of this.iterEntries()) {\n const isMatch = await predicate(entry)\n if (isMatch) yield entry\n }\n return\n }\n\n const { take, page } = pagination\n this.validatePaginationField(take, 'take')\n this.validatePaginationField(page, 'page')\n\n const startIndex = page * take\n const endIndex = startIndex + take\n let totalMatched = 0\n\n for await (const entry of this.iterEntries()) {\n if (totalMatched >= endIndex) break\n\n const isMatch = await predicate(entry)\n totalMatched++\n if (isMatch && totalMatched - 1 >= startIndex) {\n yield entry\n }\n }\n }\n\n private validatePaginationField(field: number, fieldName: string) {\n if (isNaN(field)) throw new Error(`PaginationInput.${fieldName} must not be NaN`)\n if (field < 0)\n throw new Error(`PaginationInput.${fieldName} must not be less than 0, got ${field}`)\n }\n\n async getByIdOrThrow(id: T['id']): Promise<T> {\n const entry = await this.getById(id)\n if (!entry) throw new NotFoundError(`Entry with id '${id}' does not exist`)\n return entry\n }\n\n async getFirstWhere(predicate: PredicateFn<T>): Promise<T | null> {\n const matches = await this.getWhere(predicate, { page: 0, take: 1 })\n return matches.at(0) ?? null\n }\n\n async getFirstWhereOrThrow(predicate: PredicateFn<T>): Promise<T | null> {\n const match = await this.getFirstWhere(predicate)\n if (!match) throw new NotFoundError('No entry matches predicate')\n return match\n }\n\n async getWhere(predicate: PredicateFn<T>, pagination?: PaginationInput): Promise<T[]> {\n const entries: T[] = []\n for await (const entry of this.iterWhere(predicate, pagination)) {\n entries.push(entry)\n }\n return entries\n }\n\n getAll(): Promise<T[]> {\n return this.getWhere(() => true)\n }\n\n async getAllIds(): Promise<T['id'][]> {\n const ids: T['id'][] = []\n for await (const id of this.iterIds()) {\n ids.push(id)\n }\n return ids\n }\n\n async updateById(id: T['id'], updater: UpdaterFn<T>): Promise<T> {\n const entry = await this.getByIdOrThrow(id)\n return this.updateEntry(entry, updater)\n }\n\n async updateFirstWhere(predicate: PredicateFn<T>, updater: UpdaterFn<T>) {\n return this.updateWhere(predicate, updater, { page: 0, take: 1 })\n }\n\n async updateWhere(\n predicate: PredicateFn<T>,\n updater: UpdaterFn<T>,\n pagination?: PaginationInput,\n ): Promise<T[]> {\n const result: T[] = []\n for await (const entry of this.iterWhere(predicate, pagination)) {\n result.push(await this.updateEntry(entry, updater))\n }\n return result\n }\n\n 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.iterWhere(predicate)) {\n const didDelete = await this.deleteById(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 exists(id: T['id']): Promise<boolean> {\n return (await this.getById(id)) !== null\n }\n\n countAll(): Promise<number> {\n return this.countWhere(() => true)\n }\n\n async countWhere(predicate: PredicateFn<T>, pagination?: PaginationInput): Promise<number> {\n let count = 0\n for await (const _ of this.iterWhere(predicate, pagination)) count++\n return count\n }\n}\n","import type { UpdaterFn } from './types'\n\nexport abstract class SingleEntryDb<T> {\n abstract isInited(): Promise<boolean>\n abstract read(): Promise<T>\n abstract write(updaterOrEntry: T | UpdaterFn<T>): Promise<T>\n abstract delete(): Promise<void>\n}\n","import { JsonEntryParser } from './types'\n\nexport function runJsonEntryParser<T>(parser: JsonEntryParser<T>, text: string): T {\n return typeof parser === 'function' ? parser(text) : parser.parse(text)\n}\n","export type Identifiable = {\n id: Id\n}\n\nexport type Id =\n | string\n | number\n | {\n toString: () => string\n }\n\nexport type Promisable<T> = T | Promise<T>\n\nexport type PaginationInput = {\n take: number\n page: number\n}\n\nexport type DeleteManyOutput = {\n deletedIds: Id[]\n ignoredIds: Id[]\n}\n\nexport type PredicateFn<T extends Identifiable> = (entry: T) => boolean | Promise<boolean>\n\nexport type UpdaterFn<T> = (entry: T) => Promisable<Partial<T>>\n\nexport type JsonEntryParser<T> = JsonEntryParserFn<T> | JsonEntryParserObj<T>\n\ntype JsonEntryParserFn<T> = (text: string) => T\ntype JsonEntryParserObj<T> = {\n parse: JsonEntryParserFn<T>\n}\n\nexport type MultiEntryFileDbOptions<T> = {\n noPathlikeIds?: boolean\n parser?: JsonEntryParser<T>\n disableLogs?: boolean\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","import type { FileMeta } from '../common'\nimport { FileType, FileIoError } from '../common'\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 FileIoError(`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 FileIoError(`'${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 FileIoError(`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 JsonEntryParser,\n MultiEntryFileDbOptions,\n MultiEntryDb,\n InvalidIdError,\n runJsonEntryParser,\n UpdaterFn,\n} from '../common'\nimport { Files } from './files'\nimport * as path from 'path'\n\nexport class MultiEntryFileDb<T extends Identifiable> extends MultiEntryDb<T> {\n protected readonly dirpath: string\n protected readonly files: Files\n protected readonly parser: JsonEntryParser<T>\n protected readonly disableLogs: boolean\n readonly noPathlikeIds: boolean\n\n constructor(dirpath: string, options?: MultiEntryFileDbOptions<T>) {\n super()\n this.dirpath = dirpath\n this.files = new Files()\n this.parser = options?.parser ?? JSON\n this.noPathlikeIds = options?.noPathlikeIds ?? true\n this.disableLogs = options?.disableLogs ?? false\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 if (!this.isIdValid(id)) throw new InvalidIdError(id)\n\n try {\n const filepath = this.getFilePath(id)\n const text = await this.files.read(filepath)\n const entry = runJsonEntryParser(this.parser, text)\n return entry\n } catch (error) {\n if (!this.disableLogs) console.error('Failed to read entry', error)\n // File doesn't exist or invalid JSON\n return null\n }\n }\n\n protected async updateEntry(entry: T, updater: UpdaterFn<T>): Promise<T> {\n const updatedEntryFields = await updater(entry)\n const updatedEntry = { ...entry, ...updatedEntryFields }\n await this.writeEntry(updatedEntry)\n\n if (updatedEntry.id !== entry.id) {\n await this.deleteById(entry.id)\n }\n\n return updatedEntry\n }\n\n async deleteById(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 destroy() {\n await this.files.delete(this.dirpath)\n }\n\n protected getFilePath(id: T['id']) {\n return path.join(this.dirpath, `${String(id)}.json`)\n }\n\n protected async writeEntry(entry: T) {\n if (!this.isIdValid(entry.id)) throw new InvalidIdError(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(rawId: T['id']): boolean {\n if (!this.noPathlikeIds) return true\n\n const id = String(rawId)\n if (id.includes('/') || id.includes('\\\\')) return false\n\n return true\n }\n\n async *iterEntries() {\n for await (const id of this.iterIds()) {\n const entry = await this.getById(id)\n if (entry) yield entry\n }\n }\n\n async *iterIds(objectIdParser?: JsonEntryParser<T['id']>): AsyncGenerator<T['id']> {\n const filenames = await this.files.list(this.dirpath)\n for (const filename of filenames) {\n if (!filename.endsWith('.json')) continue\n\n const stringId = filename.replace(/\\.json$/, '')\n const id = objectIdParser ? runJsonEntryParser(objectIdParser, stringId) : stringId\n if (this.isIdValid(id)) yield id\n }\n }\n}\n","import { SingleEntryDb, JsonEntryParser, runJsonEntryParser, UpdaterFn } from '../common'\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 = runJsonEntryParser(this.parser, text)\n return entry\n }\n\n async write(updaterOrEntry: T | UpdaterFn<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, MultiEntryDb, JsonEntryParser, UpdaterFn } from '../common'\nimport { MultiEntryFileDb } from '../file/multiEntryFileDb'\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 protected async updateEntry(entry: T, updater: UpdaterFn<T>): Promise<T> {\n const updatedEntryFields = await updater(entry)\n const updatedEntry = { ...entry, ...updatedEntryFields }\n\n this.entries.set(updatedEntry.id, updatedEntry)\n\n if (updatedEntry.id !== entry.id) {\n await this.deleteById(entry.id)\n }\n\n return updatedEntry\n }\n\n async deleteById(id: T['id']): Promise<boolean> {\n return this.entries.delete(id)\n }\n\n async destroy() {\n this.entries.clear()\n }\n\n async *iterEntries() {\n for (const entry of this.entries.values()) {\n yield entry\n }\n }\n\n async *iterIds() {\n for (const id of this.entries.keys()) {\n yield id\n }\n }\n\n async persist(dirpath: string) {\n const fileDb = new MultiEntryFileDb<T>(dirpath)\n await fileDb.destroy()\n\n const values = [...this.entries.values()]\n await Promise.all(values.map((entry) => fileDb.create(entry)))\n }\n\n async load(dirpath: string, parser?: JsonEntryParser<T>) {\n const fileDb = new MultiEntryFileDb<T>(dirpath, { parser })\n\n await this.destroy()\n for await (const entry of fileDb.iterEntries()) {\n await this.create(entry)\n }\n }\n}\n","import { JsonEntryParser, SingleEntryDb, UninitError, UpdaterFn } from '../common'\nimport { SingleEntryFileDb } from '../file/singleEntryFileDb'\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 UninitError()\n return this.entry\n }\n\n async write(updaterOrEntry: T | UpdaterFn<T>) {\n let entry: T\n\n if (typeof updaterOrEntry === 'function') {\n const updater = updaterOrEntry as (entry: T) => Partial<T>\n\n if (this.entry === null) throw new UninitError()\n\n const updatedFields = 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() {\n this.entry = null\n }\n\n async persist(filepath: string) {\n const fileDb = new SingleEntryFileDb<T>(filepath)\n await fileDb.write(await this.read())\n }\n\n async load(filepath: string, parser?: JsonEntryParser<T>) {\n const fileDb = new SingleEntryFileDb<T>(filepath, parser)\n const persistedEntry = await fileDb.read()\n this.write(persistedEntry)\n }\n}\n"],"names":[],"mappings":";;;;;AAAM,MAAO,OAAQ,SAAQ,KAAK,CAAA;AAAG;AAE/B,MAAO,aAAc,SAAQ,OAAO,CAAA;AAAG;AAEvC,MAAO,aAAc,SAAQ,OAAO,CAAA;AAAG;AAEvC,MAAO,WAAY,SAAQ,OAAO,CAAA;AAAG;AAErC,MAAO,cAAe,SAAQ,OAAO,CAAA;AACzC,IAAA,WAAA,CAAY,EAAW,EAAA;AACrB,QAAA,KAAK,CAAC,CAAA,kBAAA,EAAqB,EAAE,CAAA,CAAA,CAAG,CAAC;IACnC;AACD;AAEK,MAAO,WAAY,SAAQ,OAAO,CAAA;AACtC,IAAA,WAAA,GAAA;QACE,KAAK,CAAC,iFAAiF,C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
|
@@ -1,25 +1,29 @@
|
|
|
1
1
|
type Identifiable = {
|
|
2
2
|
id: Id;
|
|
3
3
|
};
|
|
4
|
-
type Id = string
|
|
4
|
+
type Id = string | number | {
|
|
5
|
+
toString: () => string;
|
|
6
|
+
};
|
|
5
7
|
type Promisable<T> = T | Promise<T>;
|
|
6
8
|
type PaginationInput = {
|
|
7
9
|
take: number;
|
|
8
10
|
page: number;
|
|
9
|
-
skip?: number | undefined | null;
|
|
10
11
|
};
|
|
11
12
|
type DeleteManyOutput = {
|
|
12
13
|
deletedIds: Id[];
|
|
13
14
|
ignoredIds: Id[];
|
|
14
15
|
};
|
|
15
|
-
type PredicateFn<T extends Identifiable> = (entry: T) => boolean
|
|
16
|
+
type PredicateFn<T extends Identifiable> = (entry: T) => boolean | Promise<boolean>;
|
|
16
17
|
type UpdaterFn<T> = (entry: T) => Promisable<Partial<T>>;
|
|
17
|
-
type JsonEntryParser<T> =
|
|
18
|
-
|
|
18
|
+
type JsonEntryParser<T> = JsonEntryParserFn<T> | JsonEntryParserObj<T>;
|
|
19
|
+
type JsonEntryParserFn<T> = (text: string) => T;
|
|
20
|
+
type JsonEntryParserObj<T> = {
|
|
21
|
+
parse: JsonEntryParserFn<T>;
|
|
19
22
|
};
|
|
20
23
|
type MultiEntryFileDbOptions<T> = {
|
|
21
24
|
noPathlikeIds?: boolean;
|
|
22
25
|
parser?: JsonEntryParser<T>;
|
|
26
|
+
disableLogs?: boolean;
|
|
23
27
|
};
|
|
24
28
|
type FileMeta = {
|
|
25
29
|
path: string;
|
|
@@ -41,17 +45,22 @@ declare enum FileType {
|
|
|
41
45
|
declare abstract class MultiEntryDb<T extends Identifiable> {
|
|
42
46
|
abstract create(entry: T): Promise<T>;
|
|
43
47
|
abstract getById(id: T['id']): Promise<T | null>;
|
|
44
|
-
abstract
|
|
48
|
+
protected abstract updateEntry(entry: T, updater: UpdaterFn<T>): Promise<T>;
|
|
45
49
|
abstract deleteById(id: T['id']): Promise<boolean>;
|
|
46
50
|
abstract destroy(): Promise<void>;
|
|
47
51
|
abstract iterEntries(): AsyncIterable<T>;
|
|
48
52
|
abstract iterIds(): AsyncIterable<T['id']>;
|
|
53
|
+
private iterWhere;
|
|
54
|
+
private validatePaginationField;
|
|
49
55
|
getByIdOrThrow(id: T['id']): Promise<T>;
|
|
50
56
|
getFirstWhere(predicate: PredicateFn<T>): Promise<T | null>;
|
|
51
57
|
getFirstWhereOrThrow(predicate: PredicateFn<T>): Promise<T | null>;
|
|
52
58
|
getWhere(predicate: PredicateFn<T>, pagination?: PaginationInput): Promise<T[]>;
|
|
53
59
|
getAll(): Promise<T[]>;
|
|
54
60
|
getAllIds(): Promise<T['id'][]>;
|
|
61
|
+
updateById(id: T['id'], updater: UpdaterFn<T>): Promise<T>;
|
|
62
|
+
updateFirstWhere(predicate: PredicateFn<T>, updater: UpdaterFn<T>): Promise<T[]>;
|
|
63
|
+
updateWhere(predicate: PredicateFn<T>, updater: UpdaterFn<T>, pagination?: PaginationInput): Promise<T[]>;
|
|
55
64
|
deleteByIds(ids: T['id'][]): Promise<DeleteManyOutput>;
|
|
56
65
|
deleteWhere(predicate: PredicateFn<T>): Promise<DeleteManyOutput>;
|
|
57
66
|
exists(id: T['id']): Promise<boolean>;
|
|
@@ -128,19 +137,20 @@ declare class MultiEntryFileDb<T extends Identifiable> extends MultiEntryDb<T> {
|
|
|
128
137
|
protected readonly dirpath: string;
|
|
129
138
|
protected readonly files: Files;
|
|
130
139
|
protected readonly parser: JsonEntryParser<T>;
|
|
140
|
+
protected readonly disableLogs: boolean;
|
|
131
141
|
readonly noPathlikeIds: boolean;
|
|
132
142
|
constructor(dirpath: string, options?: MultiEntryFileDbOptions<T>);
|
|
133
143
|
create(entry: T): Promise<T>;
|
|
134
144
|
getById(id: T['id']): Promise<T | null>;
|
|
135
|
-
|
|
145
|
+
protected updateEntry(entry: T, updater: UpdaterFn<T>): Promise<T>;
|
|
136
146
|
deleteById(id: T['id']): Promise<boolean>;
|
|
137
147
|
deleteByIds(ids: T['id'][]): Promise<DeleteManyOutput>;
|
|
138
148
|
destroy(): Promise<void>;
|
|
139
149
|
protected getFilePath(id: T['id']): string;
|
|
140
150
|
protected writeEntry(entry: T): Promise<void>;
|
|
141
|
-
isIdValid(
|
|
151
|
+
isIdValid(rawId: T['id']): boolean;
|
|
142
152
|
iterEntries(): AsyncGenerator<T, void, unknown>;
|
|
143
|
-
iterIds(): AsyncGenerator<
|
|
153
|
+
iterIds(objectIdParser?: JsonEntryParser<T['id']>): AsyncGenerator<T['id']>;
|
|
144
154
|
}
|
|
145
155
|
|
|
146
156
|
declare class SingleEntryFileDb<T> extends SingleEntryDb<T> {
|
|
@@ -151,7 +161,7 @@ declare class SingleEntryFileDb<T> extends SingleEntryDb<T> {
|
|
|
151
161
|
path(): string;
|
|
152
162
|
isInited(): Promise<boolean>;
|
|
153
163
|
read(): Promise<T>;
|
|
154
|
-
write(updaterOrEntry: T |
|
|
164
|
+
write(updaterOrEntry: T | UpdaterFn<T>): Promise<T>;
|
|
155
165
|
delete(): Promise<void>;
|
|
156
166
|
}
|
|
157
167
|
|
|
@@ -159,7 +169,7 @@ declare class MultiEntryMemDb<T extends Identifiable> extends MultiEntryDb<T> {
|
|
|
159
169
|
protected entries: Map<T['id'], T>;
|
|
160
170
|
create(entry: T): Promise<T>;
|
|
161
171
|
getById(id: T['id']): Promise<T | null>;
|
|
162
|
-
|
|
172
|
+
protected updateEntry(entry: T, updater: UpdaterFn<T>): Promise<T>;
|
|
163
173
|
deleteById(id: T['id']): Promise<boolean>;
|
|
164
174
|
destroy(): Promise<void>;
|
|
165
175
|
iterEntries(): AsyncGenerator<T, void, unknown>;
|