@jsonkit/db 2.0.1 → 3.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 +50 -42
- package/dist/cjs/index.cjs +140 -156
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/index.js +141 -155
- package/dist/esm/index.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/common/index.d.ts +2 -0
- package/dist/types/common/multiEntryDb.d.ts +19 -0
- package/dist/types/common/types.d.ts +38 -0
- package/dist/types/file/files.d.ts +1 -1
- package/dist/types/file/multiEntryFileDb.d.ts +3 -11
- package/dist/types/file/singleEntryFileDb.d.ts +2 -2
- package/dist/types/index.d.ts +1 -1
- package/dist/types/memory/multiEntryMemDb.d.ts +3 -11
- package/dist/types/memory/singleEntryMemDb.d.ts +5 -6
- package/package.json +1 -1
- package/dist/types/types.d.ts +0 -55
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export type Identifiable = {
|
|
2
|
+
id: Id;
|
|
3
|
+
};
|
|
4
|
+
export type Id = string;
|
|
5
|
+
export type Promisable<T> = T | Promise<T>;
|
|
6
|
+
export type PaginationInput = {
|
|
7
|
+
take: number;
|
|
8
|
+
page: number;
|
|
9
|
+
skip?: number | undefined | null;
|
|
10
|
+
};
|
|
11
|
+
export type DeleteManyOutput = {
|
|
12
|
+
deletedIds: Id[];
|
|
13
|
+
ignoredIds: Id[];
|
|
14
|
+
};
|
|
15
|
+
export type PredicateFn<T extends Identifiable> = (entry: T) => boolean;
|
|
16
|
+
export type JsonEntryParser<T> = {
|
|
17
|
+
parse: (text: string) => T;
|
|
18
|
+
};
|
|
19
|
+
export type MultiEntryFileDbOptions<T> = {
|
|
20
|
+
noPathlikeIds?: boolean;
|
|
21
|
+
parser?: JsonEntryParser<T>;
|
|
22
|
+
};
|
|
23
|
+
export type FileMeta = {
|
|
24
|
+
path: string;
|
|
25
|
+
size: number;
|
|
26
|
+
created: Date;
|
|
27
|
+
modified: Date;
|
|
28
|
+
accessed: Date;
|
|
29
|
+
} & ({
|
|
30
|
+
type: FileType.File;
|
|
31
|
+
} | {
|
|
32
|
+
type: FileType.Directory;
|
|
33
|
+
children: FileMeta[];
|
|
34
|
+
});
|
|
35
|
+
export declare enum FileType {
|
|
36
|
+
File = "file",
|
|
37
|
+
Directory = "directory"
|
|
38
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Identifiable, DeleteManyOutput, Promisable,
|
|
1
|
+
import { Identifiable, DeleteManyOutput, Promisable, JsonEntryParser, MultiEntryFileDbOptions, MultiEntryDb } from '../common';
|
|
2
2
|
import { Files } from './files';
|
|
3
3
|
export declare class MultiEntryFileDb<T extends Identifiable> extends MultiEntryDb<T> {
|
|
4
4
|
protected readonly dirpath: string;
|
|
@@ -8,21 +8,13 @@ export declare class MultiEntryFileDb<T extends Identifiable> extends MultiEntry
|
|
|
8
8
|
constructor(dirpath: string, options?: MultiEntryFileDbOptions<T>);
|
|
9
9
|
create(entry: T): Promise<T>;
|
|
10
10
|
getById(id: T['id']): Promise<T | null>;
|
|
11
|
-
getByIdOrThrow(id: T['id']): Promise<T>;
|
|
12
|
-
getWhere(predicate: PredicateFn<T>, max?: number): Promise<T[]>;
|
|
13
|
-
getAll(whereIds?: T['id'][]): Promise<T[]>;
|
|
14
|
-
getAllIds(): Promise<T['id'][]>;
|
|
15
11
|
update(id: T['id'], updater: (entry: T) => Promisable<Partial<T>>): Promise<T>;
|
|
16
|
-
|
|
12
|
+
deleteById(id: T['id']): Promise<boolean>;
|
|
17
13
|
deleteByIds(ids: T['id'][]): Promise<DeleteManyOutput>;
|
|
18
|
-
deleteWhere(predicate: PredicateFn<T>): Promise<DeleteManyOutput>;
|
|
19
14
|
destroy(): Promise<void>;
|
|
20
|
-
exists(id: T['id']): Promise<boolean>;
|
|
21
|
-
countAll(): Promise<number>;
|
|
22
|
-
countWhere(predicate: PredicateFn<T>): Promise<number>;
|
|
23
15
|
protected getFilePath(id: T['id']): string;
|
|
24
|
-
protected readEntry(id: T['id']): Promise<T | null>;
|
|
25
16
|
protected writeEntry(entry: T): Promise<void>;
|
|
26
17
|
isIdValid(id: T['id']): boolean;
|
|
27
18
|
protected iterEntries(): AsyncGenerator<T, void, unknown>;
|
|
19
|
+
protected iterIds(): AsyncGenerator<string, void, unknown>;
|
|
28
20
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { JsonEntryParser, Promisable
|
|
1
|
+
import { JsonEntryParser, Promisable } from '../common/types';
|
|
2
2
|
import { Files } from './files';
|
|
3
|
-
export declare class SingleEntryFileDb<T>
|
|
3
|
+
export declare class SingleEntryFileDb<T> {
|
|
4
4
|
protected readonly filepath: string;
|
|
5
5
|
protected readonly parser: JsonEntryParser<T>;
|
|
6
6
|
protected readonly files: Files;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,19 +1,11 @@
|
|
|
1
|
-
import { Identifiable,
|
|
1
|
+
import { Identifiable, Promisable, MultiEntryDb } from '../common';
|
|
2
2
|
export declare class MultiEntryMemDb<T extends Identifiable> extends MultiEntryDb<T> {
|
|
3
3
|
protected entries: Map<T['id'], T>;
|
|
4
4
|
create(entry: T): Promise<T>;
|
|
5
5
|
getById(id: T['id']): Promise<T | null>;
|
|
6
|
-
getByIdOrThrow(id: T['id']): Promise<T>;
|
|
7
|
-
getWhere(predicate: PredicateFn<T>, max?: number): Promise<T[]>;
|
|
8
|
-
getAll(whereIds?: T['id'][]): Promise<T[]>;
|
|
9
|
-
getAllIds(): Promise<T['id'][]>;
|
|
10
6
|
update(id: T['id'], updater: (entry: T) => Promisable<Partial<T>>): Promise<T>;
|
|
11
|
-
|
|
12
|
-
deleteByIds(ids: T['id'][]): Promise<DeleteManyOutput>;
|
|
13
|
-
deleteWhere(predicate: PredicateFn<T>): Promise<DeleteManyOutput>;
|
|
7
|
+
deleteById(id: T['id']): Promise<boolean>;
|
|
14
8
|
destroy(): Promise<void>;
|
|
15
|
-
exists(id: T['id']): Promise<boolean>;
|
|
16
|
-
countAll(): Promise<number>;
|
|
17
|
-
countWhere(predicate: PredicateFn<T>): Promise<number>;
|
|
18
9
|
protected iterEntries(): AsyncGenerator<T, void, unknown>;
|
|
10
|
+
protected iterIds(): AsyncGenerator<T["id"], void, unknown>;
|
|
19
11
|
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
export declare class SingleEntryMemDb<T> extends SingleEntryDb<T> {
|
|
1
|
+
export declare class SingleEntryMemDb<T> {
|
|
3
2
|
protected entry: T | null;
|
|
4
3
|
constructor(initialEntry?: T | null);
|
|
5
|
-
isInited():
|
|
6
|
-
read():
|
|
7
|
-
write(updaterOrEntry: T | ((entry: T) =>
|
|
8
|
-
delete():
|
|
4
|
+
isInited(): boolean;
|
|
5
|
+
read(): T;
|
|
6
|
+
write(updaterOrEntry: T | ((entry: T) => Partial<T>)): T;
|
|
7
|
+
delete(): void;
|
|
9
8
|
}
|
package/package.json
CHANGED
package/dist/types/types.d.ts
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
export type Identifiable = {
|
|
2
|
-
id: Id;
|
|
3
|
-
};
|
|
4
|
-
export type Id = string;
|
|
5
|
-
export type Promisable<T> = T | Promise<T>;
|
|
6
|
-
export type DeleteManyOutput = {
|
|
7
|
-
deletedIds: Id[];
|
|
8
|
-
ignoredIds: Id[];
|
|
9
|
-
};
|
|
10
|
-
export type PredicateFn<T extends Identifiable> = (entry: T) => boolean;
|
|
11
|
-
export type JsonEntryParser<T> = {
|
|
12
|
-
parse: (text: string) => T;
|
|
13
|
-
};
|
|
14
|
-
export type MultiEntryFileDbOptions<T> = {
|
|
15
|
-
noPathlikeIds?: boolean;
|
|
16
|
-
parser?: JsonEntryParser<T>;
|
|
17
|
-
};
|
|
18
|
-
export type FileMeta = {
|
|
19
|
-
path: string;
|
|
20
|
-
size: number;
|
|
21
|
-
created: Date;
|
|
22
|
-
modified: Date;
|
|
23
|
-
accessed: Date;
|
|
24
|
-
} & ({
|
|
25
|
-
type: FileType.File;
|
|
26
|
-
} | {
|
|
27
|
-
type: FileType.Directory;
|
|
28
|
-
children: FileMeta[];
|
|
29
|
-
});
|
|
30
|
-
export declare enum FileType {
|
|
31
|
-
File = "file",
|
|
32
|
-
Directory = "directory"
|
|
33
|
-
}
|
|
34
|
-
export declare abstract class SingleEntryDb<T> {
|
|
35
|
-
abstract isInited(): Promise<boolean>;
|
|
36
|
-
abstract read(): Promise<T>;
|
|
37
|
-
abstract write(updaterOrEntry: T | ((entry: T) => Promisable<Partial<T>>)): Promise<T>;
|
|
38
|
-
abstract delete(): Promise<void>;
|
|
39
|
-
}
|
|
40
|
-
export declare abstract class MultiEntryDb<T extends Identifiable> {
|
|
41
|
-
abstract create(entry: T): Promise<T>;
|
|
42
|
-
abstract getById(id: T['id']): Promise<T | null>;
|
|
43
|
-
abstract getByIdOrThrow(id: T['id']): Promise<T>;
|
|
44
|
-
abstract getWhere(predicate: PredicateFn<T>, max?: number): Promise<T[]>;
|
|
45
|
-
abstract getAll(whereIds?: T['id'][]): Promise<T[]>;
|
|
46
|
-
abstract getAllIds(): Promise<T['id'][]>;
|
|
47
|
-
abstract update(id: T['id'], updater: (entry: T) => Promisable<Partial<T>>): Promise<T>;
|
|
48
|
-
abstract delete(id: T['id']): Promise<boolean>;
|
|
49
|
-
abstract deleteByIds(ids: T['id'][]): Promise<DeleteManyOutput>;
|
|
50
|
-
abstract deleteWhere(predicate: PredicateFn<T>): Promise<DeleteManyOutput>;
|
|
51
|
-
abstract destroy(): Promise<void>;
|
|
52
|
-
abstract exists(id: T['id']): Promise<boolean>;
|
|
53
|
-
abstract countAll(): Promise<number>;
|
|
54
|
-
abstract countWhere(predicate: PredicateFn<T>): Promise<number>;
|
|
55
|
-
}
|