@wxn0brp/db-core 0.4.0 → 0.5.0-alpha.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/dist/base/actions.d.ts +6 -7
- package/dist/base/actions.js +5 -6
- package/dist/base/custom.d.ts +7 -7
- package/dist/base/custom.js +5 -3
- package/dist/customFileCpu.d.ts +7 -8
- package/dist/customFileCpu.js +18 -20
- package/dist/db/memory.d.ts +5 -5
- package/dist/db/memory.js +3 -3
- package/dist/db/multiStorage.d.ts +5 -5
- package/dist/db/multiStorage.js +9 -11
- package/dist/db/routedStorage.d.ts +5 -5
- package/dist/db/routedStorage.js +1 -1
- package/dist/db/valthera.d.ts +19 -24
- package/dist/db/valthera.js +52 -27
- package/dist/helpers/addId.d.ts +1 -1
- package/dist/helpers/addId.js +1 -1
- package/dist/helpers/{collectionManager.d.ts → collection.d.ts} +14 -11
- package/dist/helpers/collection.js +59 -0
- package/dist/helpers/executor.d.ts +2 -4
- package/dist/helpers/executor.js +1 -3
- package/dist/helpers/forge.d.ts +4 -4
- package/dist/helpers/forge.js +2 -2
- package/dist/helpers/gen.d.ts +17 -1
- package/dist/helpers/gen.js +36 -30
- package/dist/helpers/relation.d.ts +5 -2
- package/dist/helpers/relation.js +44 -33
- package/dist/index.d.ts +11 -13
- package/dist/index.js +7 -8
- package/dist/types/data.d.ts +0 -1
- package/dist/types/fileCpu.d.ts +6 -7
- package/dist/types/options.d.ts +3 -3
- package/dist/types/query.d.ts +12 -0
- package/dist/types/relation.d.ts +1 -1
- package/dist/types/valthera.d.ts +22 -14
- package/dist/utils/action.d.ts +2 -2
- package/dist/utils/hasFields.d.ts +1 -1
- package/dist/utils/hasFields.js +1 -1
- package/dist/utils/hasFieldsAdvanced.d.ts +1 -1
- package/dist/utils/hasFieldsAdvanced.js +2 -2
- package/dist/utils/updateFindObject.d.ts +1 -1
- package/dist/utils/updateFindObject.js +1 -1
- package/dist/utils/updateObject.d.ts +1 -1
- package/dist/utils/updateObject.js +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/dist/helpers/collectionManager.js +0 -62
package/dist/base/actions.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import Data from "../types/data.js";
|
|
1
|
+
import { Data } from "../types/data.js";
|
|
2
2
|
import { VQuery } from "../types/query.js";
|
|
3
|
-
declare class ActionsBase {
|
|
3
|
+
export declare class ActionsBase {
|
|
4
4
|
_inited: boolean;
|
|
5
5
|
numberId: boolean;
|
|
6
6
|
init(...args: any[]): Promise<void>;
|
|
@@ -10,12 +10,11 @@ declare class ActionsBase {
|
|
|
10
10
|
add(config: VQuery): Promise<Data>;
|
|
11
11
|
find(config: VQuery): Promise<Data[]>;
|
|
12
12
|
findOne(config: VQuery): Promise<Data | null>;
|
|
13
|
-
update(config: VQuery): Promise<
|
|
14
|
-
updateOne(config: VQuery): Promise<
|
|
15
|
-
remove(config: VQuery): Promise<
|
|
16
|
-
removeOne(config: VQuery): Promise<
|
|
13
|
+
update(config: VQuery): Promise<Data>;
|
|
14
|
+
updateOne(config: VQuery): Promise<Data>;
|
|
15
|
+
remove(config: VQuery): Promise<Data>;
|
|
16
|
+
removeOne(config: VQuery): Promise<Data>;
|
|
17
17
|
removeCollection(config: VQuery): Promise<boolean>;
|
|
18
18
|
updateOneOrAdd(config: VQuery): Promise<boolean>;
|
|
19
19
|
toggleOne(config: VQuery): Promise<boolean>;
|
|
20
20
|
}
|
|
21
|
-
export default ActionsBase;
|
package/dist/base/actions.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { setDataForToggleOne, setDataForUpdateOneOrAdd } from "../helpers/assignDataPush.js";
|
|
2
|
-
class ActionsBase {
|
|
2
|
+
export class ActionsBase {
|
|
3
3
|
_inited = true;
|
|
4
4
|
numberId = false;
|
|
5
5
|
async init(...args) { }
|
|
@@ -29,19 +29,19 @@ class ActionsBase {
|
|
|
29
29
|
}
|
|
30
30
|
async update(config) {
|
|
31
31
|
throw new Error("Not implemented");
|
|
32
|
-
return
|
|
32
|
+
return [];
|
|
33
33
|
}
|
|
34
34
|
async updateOne(config) {
|
|
35
35
|
throw new Error("Not implemented");
|
|
36
|
-
return
|
|
36
|
+
return {};
|
|
37
37
|
}
|
|
38
38
|
async remove(config) {
|
|
39
39
|
throw new Error("Not implemented");
|
|
40
|
-
return
|
|
40
|
+
return [];
|
|
41
41
|
}
|
|
42
42
|
async removeOne(config) {
|
|
43
43
|
throw new Error("Not implemented");
|
|
44
|
-
return
|
|
44
|
+
return {};
|
|
45
45
|
}
|
|
46
46
|
async removeCollection(config) {
|
|
47
47
|
throw new Error("Not implemented");
|
|
@@ -64,4 +64,3 @@ class ActionsBase {
|
|
|
64
64
|
return false;
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
|
-
export default ActionsBase;
|
package/dist/base/custom.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import CustomFileCpu from "../customFileCpu.js";
|
|
2
|
-
import Data from "../types/data.js";
|
|
1
|
+
import { CustomFileCpu } from "../customFileCpu.js";
|
|
2
|
+
import { Data } from "../types/data.js";
|
|
3
3
|
import { VQuery } from "../types/query.js";
|
|
4
|
-
import ActionsBase from "./actions.js";
|
|
4
|
+
import { ActionsBase } from "./actions.js";
|
|
5
5
|
export declare class CustomActionsBase extends ActionsBase {
|
|
6
6
|
fileCpu: CustomFileCpu;
|
|
7
7
|
constructor();
|
|
@@ -20,17 +20,17 @@ export declare class CustomActionsBase extends ActionsBase {
|
|
|
20
20
|
/**
|
|
21
21
|
* Update entries in the specified database based on search criteria and an updater function or object.
|
|
22
22
|
*/
|
|
23
|
-
update({ collection, search, updater, context }: VQuery): Promise<
|
|
23
|
+
update({ collection, search, updater, context }: VQuery): Promise<Data[]>;
|
|
24
24
|
/**
|
|
25
25
|
* Update the first matching entry in the specified database based on search criteria and an updater function or object.
|
|
26
26
|
*/
|
|
27
|
-
updateOne({ collection, search, updater, context }: VQuery): Promise<
|
|
27
|
+
updateOne({ collection, search, updater, context }: VQuery): Promise<Data>;
|
|
28
28
|
/**
|
|
29
29
|
* Remove entries from the specified database based on search criteria.
|
|
30
30
|
*/
|
|
31
|
-
remove({ collection, search, context }: VQuery): Promise<
|
|
31
|
+
remove({ collection, search, context }: VQuery): Promise<Data[]>;
|
|
32
32
|
/**
|
|
33
33
|
* Remove the first matching entry from the specified database based on search criteria.
|
|
34
34
|
*/
|
|
35
|
-
removeOne({ collection, search, context }: VQuery): Promise<
|
|
35
|
+
removeOne({ collection, search, context }: VQuery): Promise<Data>;
|
|
36
36
|
}
|
package/dist/base/custom.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { addId } from "../helpers/addId.js";
|
|
2
2
|
import { findUtil } from "../utils/action.js";
|
|
3
|
-
import ActionsBase from "./actions.js";
|
|
3
|
+
import { ActionsBase } from "./actions.js";
|
|
4
4
|
export class CustomActionsBase extends ActionsBase {
|
|
5
5
|
fileCpu;
|
|
6
6
|
constructor() {
|
|
@@ -44,7 +44,8 @@ export class CustomActionsBase extends ActionsBase {
|
|
|
44
44
|
*/
|
|
45
45
|
async updateOne({ collection, search, updater, context = {} }) {
|
|
46
46
|
await this.ensureCollection(arguments[0]);
|
|
47
|
-
|
|
47
|
+
const res = await this.fileCpu.update(collection, true, search, updater, context);
|
|
48
|
+
return res.length ? res[0] : null;
|
|
48
49
|
}
|
|
49
50
|
/**
|
|
50
51
|
* Remove entries from the specified database based on search criteria.
|
|
@@ -58,6 +59,7 @@ export class CustomActionsBase extends ActionsBase {
|
|
|
58
59
|
*/
|
|
59
60
|
async removeOne({ collection, search, context = {} }) {
|
|
60
61
|
await this.ensureCollection(arguments[0]);
|
|
61
|
-
|
|
62
|
+
const res = await this.fileCpu.remove(collection, true, search, context);
|
|
63
|
+
return res.length ? res[0] : null;
|
|
62
64
|
}
|
|
63
65
|
}
|
package/dist/customFileCpu.d.ts
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
import { Search, Updater } from "./types/arg.js";
|
|
2
|
-
import Data from "./types/data.js";
|
|
3
|
-
import FileCpu from "./types/fileCpu.js";
|
|
2
|
+
import { Data } from "./types/data.js";
|
|
3
|
+
import { FileCpu } from "./types/fileCpu.js";
|
|
4
4
|
import { FindOpts } from "./types/options.js";
|
|
5
5
|
import { VContext } from "./types/types.js";
|
|
6
6
|
export type WriteFile = (file: string, data: any[]) => Promise<void>;
|
|
7
7
|
export type ReadFile = (file: string) => Promise<any[]>;
|
|
8
8
|
export declare function pathRepair(path: string): string;
|
|
9
|
-
declare class CustomFileCpu implements FileCpu {
|
|
9
|
+
export declare class CustomFileCpu implements FileCpu {
|
|
10
10
|
_readFile: ReadFile;
|
|
11
11
|
_writeFile: WriteFile;
|
|
12
12
|
constructor(readFile: ReadFile, writeFile: WriteFile);
|
|
13
13
|
add(file: string, data: Data): Promise<void>;
|
|
14
|
-
find(file: string, search: Search, context?: VContext, findOpts?: FindOpts): Promise<
|
|
15
|
-
findOne(file: string, search: Search, context?: VContext, findOpts?: FindOpts): Promise<
|
|
16
|
-
remove(file: string, one: boolean, search: Search, context?: VContext): Promise<
|
|
17
|
-
update(file: string, one: boolean, search: Search, updater: Updater, context?: VContext): Promise<
|
|
14
|
+
find(file: string, search: Search, context?: VContext, findOpts?: FindOpts): Promise<Data[]>;
|
|
15
|
+
findOne(file: string, search: Search, context?: VContext, findOpts?: FindOpts): Promise<Data | false>;
|
|
16
|
+
remove(file: string, one: boolean, search: Search, context?: VContext): Promise<Data[]>;
|
|
17
|
+
update(file: string, one: boolean, search: Search, updater: Updater, context?: VContext): Promise<Data[]>;
|
|
18
18
|
}
|
|
19
|
-
export default CustomFileCpu;
|
package/dist/customFileCpu.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import hasFieldsAdvanced from "./utils/hasFieldsAdvanced.js";
|
|
2
|
-
import updateFindObject from "./utils/updateFindObject.js";
|
|
3
|
-
import updateObjectAdvanced from "./utils/updateObject.js";
|
|
1
|
+
import { hasFieldsAdvanced } from "./utils/hasFieldsAdvanced.js";
|
|
2
|
+
import { updateFindObject } from "./utils/updateFindObject.js";
|
|
3
|
+
import { updateObjectAdvanced } from "./utils/updateObject.js";
|
|
4
4
|
export function pathRepair(path) {
|
|
5
5
|
return path.replaceAll("//", "/");
|
|
6
6
|
}
|
|
7
|
-
class CustomFileCpu {
|
|
7
|
+
export class CustomFileCpu {
|
|
8
8
|
_readFile;
|
|
9
9
|
_writeFile;
|
|
10
10
|
constructor(readFile, writeFile) {
|
|
@@ -32,40 +32,38 @@ class CustomFileCpu {
|
|
|
32
32
|
async remove(file, one, search, context = {}) {
|
|
33
33
|
file = pathRepair(file);
|
|
34
34
|
let entries = await this._readFile(file);
|
|
35
|
-
|
|
35
|
+
const removed = [];
|
|
36
36
|
entries = entries.filter(entry => {
|
|
37
|
-
if (removed && one)
|
|
37
|
+
if (removed.length && one)
|
|
38
38
|
return true;
|
|
39
39
|
let match = typeof search === "function" ? search(entry, context) : hasFieldsAdvanced(entry, search);
|
|
40
40
|
if (match) {
|
|
41
|
-
removed
|
|
41
|
+
removed.push(entry);
|
|
42
42
|
return false;
|
|
43
43
|
}
|
|
44
44
|
return true;
|
|
45
45
|
});
|
|
46
|
-
if (
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
return true;
|
|
46
|
+
if (removed.length)
|
|
47
|
+
await this._writeFile(file, entries);
|
|
48
|
+
return removed;
|
|
50
49
|
}
|
|
51
50
|
async update(file, one, search, updater, context = {}) {
|
|
52
51
|
file = pathRepair(file);
|
|
53
52
|
let entries = await this._readFile(file);
|
|
54
|
-
|
|
53
|
+
const updated = [];
|
|
55
54
|
entries = entries.map(entry => {
|
|
56
|
-
if (updated && one)
|
|
55
|
+
if (updated.length && one)
|
|
57
56
|
return entry;
|
|
58
57
|
let match = typeof search === "function" ? search(entry, context) : hasFieldsAdvanced(entry, search);
|
|
59
58
|
if (match) {
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
const updatedEntry = typeof updater === "function" ? updater(entry, context) : updateObjectAdvanced(entry, updater);
|
|
60
|
+
updated.push(updatedEntry);
|
|
61
|
+
return updatedEntry;
|
|
62
62
|
}
|
|
63
63
|
return entry;
|
|
64
64
|
});
|
|
65
|
-
if (
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
return true;
|
|
65
|
+
if (updated.length)
|
|
66
|
+
await this._writeFile(file, entries);
|
|
67
|
+
return updated;
|
|
69
68
|
}
|
|
70
69
|
}
|
|
71
|
-
export default CustomFileCpu;
|
package/dist/db/memory.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { CustomActionsBase } from "../base/custom.js";
|
|
2
|
-
import {
|
|
3
|
-
import Data from "../types/data.js";
|
|
2
|
+
import { Collection } from "../helpers/collection.js";
|
|
3
|
+
import { Data } from "../types/data.js";
|
|
4
4
|
import { VQuery } from "../types/query.js";
|
|
5
|
-
import ValtheraClass from "./valthera.js";
|
|
5
|
+
import { ValtheraClass } from "./valthera.js";
|
|
6
6
|
export declare class MemoryAction extends CustomActionsBase {
|
|
7
7
|
memory: Map<string, any[]>;
|
|
8
8
|
constructor();
|
|
@@ -13,9 +13,9 @@ export declare class MemoryAction extends CustomActionsBase {
|
|
|
13
13
|
issetCollection({ collection }: VQuery): Promise<boolean>;
|
|
14
14
|
removeCollection({ collection }: VQuery): Promise<boolean>;
|
|
15
15
|
}
|
|
16
|
-
export
|
|
16
|
+
export declare class ValtheraMemory extends ValtheraClass {
|
|
17
17
|
constructor(...args: any[]);
|
|
18
18
|
}
|
|
19
19
|
export declare function createMemoryValthera<T extends Record<string, Data[]>>(data?: T): ValtheraMemory & {
|
|
20
|
-
[K in keyof T]:
|
|
20
|
+
[K in keyof T]: Collection<T[K][number]>;
|
|
21
21
|
};
|
package/dist/db/memory.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CustomActionsBase } from "../base/custom.js";
|
|
2
|
-
import CustomFileCpu from "../customFileCpu.js";
|
|
2
|
+
import { CustomFileCpu } from "../customFileCpu.js";
|
|
3
3
|
import { forgeValthera } from "../helpers/forge.js";
|
|
4
|
-
import ValtheraClass from "./valthera.js";
|
|
4
|
+
import { ValtheraClass } from "./valthera.js";
|
|
5
5
|
export class MemoryAction extends CustomActionsBase {
|
|
6
6
|
memory;
|
|
7
7
|
constructor() {
|
|
@@ -35,7 +35,7 @@ export class MemoryAction extends CustomActionsBase {
|
|
|
35
35
|
return true;
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
export
|
|
38
|
+
export class ValtheraMemory extends ValtheraClass {
|
|
39
39
|
constructor(...args) {
|
|
40
40
|
super({ dbAction: new MemoryAction() });
|
|
41
41
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import ActionsBase from "../base/actions.js";
|
|
1
|
+
import { ActionsBase } from "../base/actions.js";
|
|
2
2
|
import { VQuery } from "../types/query.js";
|
|
3
3
|
export declare class MultiBackend extends ActionsBase {
|
|
4
4
|
backends: ActionsBase[];
|
|
@@ -8,10 +8,10 @@ export declare class MultiBackend extends ActionsBase {
|
|
|
8
8
|
add(config: VQuery): Promise<import("../types/data.js").Data>;
|
|
9
9
|
find(config: VQuery): Promise<import("../types/data.js").Data[]>;
|
|
10
10
|
findOne(config: VQuery): Promise<import("../types/data.js").Data>;
|
|
11
|
-
update(config: VQuery): Promise<
|
|
12
|
-
updateOne(config: VQuery): Promise<
|
|
13
|
-
remove(config: VQuery): Promise<
|
|
14
|
-
removeOne(config: VQuery): Promise<
|
|
11
|
+
update(config: VQuery): Promise<import("../types/data.js").Data[]>;
|
|
12
|
+
updateOne(config: VQuery): Promise<import("../types/data.js").Data>;
|
|
13
|
+
remove(config: VQuery): Promise<import("../types/data.js").Data[]>;
|
|
14
|
+
removeOne(config: VQuery): Promise<import("../types/data.js").Data>;
|
|
15
15
|
ensureCollection(config: VQuery): Promise<boolean>;
|
|
16
16
|
issetCollection(config: VQuery): Promise<boolean>;
|
|
17
17
|
removeCollection(config: VQuery): Promise<boolean>;
|
package/dist/db/multiStorage.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import ActionsBase from "../base/actions.js";
|
|
1
|
+
import { ActionsBase } from "../base/actions.js";
|
|
2
2
|
export class MultiBackend extends ActionsBase {
|
|
3
3
|
backends;
|
|
4
4
|
primaryBackend;
|
|
@@ -33,39 +33,37 @@ export class MultiBackend extends ActionsBase {
|
|
|
33
33
|
}
|
|
34
34
|
async update(config) {
|
|
35
35
|
const results = await Promise.all(this.backends.map(b => b.update({ ...config })));
|
|
36
|
-
return results.
|
|
36
|
+
return results.flat();
|
|
37
37
|
}
|
|
38
38
|
async updateOne(config) {
|
|
39
39
|
for (const backend of this.backends) {
|
|
40
40
|
try {
|
|
41
41
|
const result = await backend.updateOne({ ...config });
|
|
42
|
-
if (result
|
|
43
|
-
return
|
|
44
|
-
}
|
|
42
|
+
if (result)
|
|
43
|
+
return result;
|
|
45
44
|
}
|
|
46
45
|
catch (error) {
|
|
47
46
|
continue;
|
|
48
47
|
}
|
|
49
48
|
}
|
|
50
|
-
return
|
|
49
|
+
return null;
|
|
51
50
|
}
|
|
52
51
|
async remove(config) {
|
|
53
52
|
const results = await Promise.all(this.backends.map(b => b.remove({ ...config })));
|
|
54
|
-
return results.
|
|
53
|
+
return results.flat();
|
|
55
54
|
}
|
|
56
55
|
async removeOne(config) {
|
|
57
56
|
for (const backend of this.backends) {
|
|
58
57
|
try {
|
|
59
58
|
const result = await backend.removeOne({ ...config });
|
|
60
|
-
if (result
|
|
61
|
-
return
|
|
62
|
-
}
|
|
59
|
+
if (result)
|
|
60
|
+
return result;
|
|
63
61
|
}
|
|
64
62
|
catch (error) {
|
|
65
63
|
continue;
|
|
66
64
|
}
|
|
67
65
|
}
|
|
68
|
-
return
|
|
66
|
+
return null;
|
|
69
67
|
}
|
|
70
68
|
async ensureCollection(config) {
|
|
71
69
|
const results = await Promise.all(this.backends.map(b => b.ensureCollection({ ...config })));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import ActionsBase from "../base/actions.js";
|
|
1
|
+
import { ActionsBase } from "../base/actions.js";
|
|
2
2
|
import { VQuery } from "../types/query.js";
|
|
3
3
|
export type MatchRule = string | RegExp | ((query: VQuery) => boolean);
|
|
4
4
|
export interface RouteEntry {
|
|
@@ -16,10 +16,10 @@ export declare class RoutedStorage extends ActionsBase {
|
|
|
16
16
|
add(config: VQuery): Promise<import("../types/data.js").Data>;
|
|
17
17
|
find(config: VQuery): Promise<import("../types/data.js").Data[]>;
|
|
18
18
|
findOne(config: VQuery): Promise<import("../types/data.js").Data>;
|
|
19
|
-
update(config: VQuery): Promise<
|
|
20
|
-
updateOne(config: VQuery): Promise<
|
|
21
|
-
remove(config: VQuery): Promise<
|
|
22
|
-
removeOne(config: VQuery): Promise<
|
|
19
|
+
update(config: VQuery): Promise<import("../types/data.js").Data>;
|
|
20
|
+
updateOne(config: VQuery): Promise<import("../types/data.js").Data>;
|
|
21
|
+
remove(config: VQuery): Promise<import("../types/data.js").Data>;
|
|
22
|
+
removeOne(config: VQuery): Promise<import("../types/data.js").Data>;
|
|
23
23
|
ensureCollection(config: VQuery): Promise<boolean>;
|
|
24
24
|
issetCollection(config: VQuery): Promise<boolean>;
|
|
25
25
|
removeCollection(config: VQuery): Promise<boolean>;
|
package/dist/db/routedStorage.js
CHANGED
package/dist/db/valthera.d.ts
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { VEE } from "@wxn0brp/event-emitter";
|
|
2
|
-
import ActionsBase from "../base/actions.js";
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
import { DbFindOpts, DbOpts, FindOpts } from "../types/options.js";
|
|
2
|
+
import { ActionsBase } from "../base/actions.js";
|
|
3
|
+
import { Collection } from "../helpers/collection.js";
|
|
4
|
+
import { Executor } from "../helpers/executor.js";
|
|
5
|
+
import { Data } from "../types/data.js";
|
|
6
|
+
import { DbOpts } from "../types/options.js";
|
|
8
7
|
import { VQuery } from "../types/query.js";
|
|
9
|
-
import {
|
|
10
|
-
import { UpdateOneOrAdd, ValtheraCompatible } from "../types/valthera.js";
|
|
8
|
+
import { AddQuery, FindOneQuery, FindQuery, RemoveQuery, ToggleOneQuery, UpdateOneOrAddQuery, UpdateQuery, ValtheraCompatible } from "../types/valthera.js";
|
|
11
9
|
type DbActionsFns = keyof {
|
|
12
10
|
[K in keyof ActionsBase as ActionsBase[K] extends (...args: any[]) => any ? K : never]: any;
|
|
13
11
|
};
|
|
@@ -15,9 +13,9 @@ type DbActionsFns = keyof {
|
|
|
15
13
|
* Represents a database management class for performing CRUD operations.
|
|
16
14
|
* @class
|
|
17
15
|
*/
|
|
18
|
-
declare class ValtheraClass implements ValtheraCompatible {
|
|
16
|
+
export declare class ValtheraClass implements ValtheraCompatible {
|
|
19
17
|
dbAction: ActionsBase;
|
|
20
|
-
executor:
|
|
18
|
+
executor: Executor;
|
|
21
19
|
emiter: VEE<{
|
|
22
20
|
[K in Exclude<DbActionsFns, "init">]: (query: VQuery, result: Awaited<ReturnType<ValtheraCompatible[K]>>) => void;
|
|
23
21
|
} & {
|
|
@@ -30,7 +28,7 @@ declare class ValtheraClass implements ValtheraCompatible {
|
|
|
30
28
|
/**
|
|
31
29
|
* Create a new instance of a CollectionManager class.
|
|
32
30
|
*/
|
|
33
|
-
c<T = Data>(collection: string):
|
|
31
|
+
c<T = Data>(collection: string): Collection<T>;
|
|
34
32
|
/**
|
|
35
33
|
* Get the names of all available databases.
|
|
36
34
|
*/
|
|
@@ -46,45 +44,42 @@ declare class ValtheraClass implements ValtheraCompatible {
|
|
|
46
44
|
/**
|
|
47
45
|
* Add data to a database.
|
|
48
46
|
*/
|
|
49
|
-
add<T
|
|
50
|
-
_id: string;
|
|
51
|
-
}>;
|
|
52
|
-
add<T extends object>(collection: string, data: T, id_gen: false): Promise<T>;
|
|
47
|
+
add<T = Data>(query: AddQuery): Promise<T>;
|
|
53
48
|
/**
|
|
54
49
|
* Find data in a database.
|
|
55
50
|
*/
|
|
56
|
-
find<T = Data>(
|
|
51
|
+
find<T = Data>(query: FindQuery): Promise<T[]>;
|
|
57
52
|
/**
|
|
58
53
|
* Find one data entry in a database.
|
|
59
54
|
*/
|
|
60
|
-
findOne<T = Data>(
|
|
55
|
+
findOne<T = Data>(query: FindOneQuery): Promise<T>;
|
|
61
56
|
/**
|
|
62
57
|
* Update data in a database.
|
|
63
58
|
*/
|
|
64
|
-
update<T = Data>(
|
|
59
|
+
update<T = Data>(query: UpdateQuery): Promise<T[]>;
|
|
65
60
|
/**
|
|
66
61
|
* Update one data entry in a database.
|
|
67
62
|
*/
|
|
68
|
-
updateOne<T = Data>(
|
|
63
|
+
updateOne<T = Data>(query: UpdateQuery): Promise<T>;
|
|
69
64
|
/**
|
|
70
65
|
* Remove data from a database.
|
|
71
66
|
*/
|
|
72
|
-
remove<T = Data>(
|
|
67
|
+
remove<T = Data>(query: RemoveQuery): Promise<T[]>;
|
|
73
68
|
/**
|
|
74
69
|
* Remove one data entry from a database.
|
|
75
70
|
*/
|
|
76
|
-
removeOne<T = Data>(
|
|
71
|
+
removeOne<T = Data>(query: RemoveQuery): Promise<T>;
|
|
77
72
|
/**
|
|
78
73
|
* Asynchronously updates one entry in a database or adds a new one if it doesn't exist.
|
|
79
74
|
*/
|
|
80
|
-
updateOneOrAdd<T = Data>(
|
|
75
|
+
updateOneOrAdd<T = Data>(query: UpdateOneOrAddQuery): Promise<T>;
|
|
81
76
|
/**
|
|
82
77
|
* Asynchronously removes one entry in a database or adds a new one if it doesn't exist. Usage e.g. for toggling a flag.
|
|
83
78
|
*/
|
|
84
|
-
toggleOne<T = Data>(
|
|
79
|
+
toggleOne<T = Data>(query: ToggleOneQuery): Promise<T>;
|
|
85
80
|
/**
|
|
86
81
|
* Removes a database collection from the file system.
|
|
87
82
|
*/
|
|
88
83
|
removeCollection(collection: string): Promise<boolean>;
|
|
89
84
|
}
|
|
90
|
-
export
|
|
85
|
+
export {};
|
package/dist/db/valthera.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { VEE } from "@wxn0brp/event-emitter";
|
|
2
|
-
import ActionsBase from "../base/actions.js";
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
2
|
+
import { ActionsBase } from "../base/actions.js";
|
|
3
|
+
import { Collection } from "../helpers/collection.js";
|
|
4
|
+
import { Executor } from "../helpers/executor.js";
|
|
5
5
|
import { version } from "../version.js";
|
|
6
6
|
/**
|
|
7
7
|
* Represents a database management class for performing CRUD operations.
|
|
8
8
|
* @class
|
|
9
9
|
*/
|
|
10
|
-
class ValtheraClass {
|
|
10
|
+
export class ValtheraClass {
|
|
11
11
|
dbAction;
|
|
12
12
|
executor;
|
|
13
13
|
emiter;
|
|
14
14
|
version = version;
|
|
15
15
|
constructor(options = {}) {
|
|
16
16
|
this.dbAction = options.dbAction || new ActionsBase();
|
|
17
|
-
this.executor = options.executor || new
|
|
17
|
+
this.executor = options.executor || new Executor();
|
|
18
18
|
this.emiter = new VEE();
|
|
19
19
|
if (options.numberId)
|
|
20
20
|
this.dbAction.numberId = true;
|
|
@@ -41,7 +41,7 @@ class ValtheraClass {
|
|
|
41
41
|
* Create a new instance of a CollectionManager class.
|
|
42
42
|
*/
|
|
43
43
|
c(collection) {
|
|
44
|
-
return new
|
|
44
|
+
return new Collection(this, collection);
|
|
45
45
|
}
|
|
46
46
|
/**
|
|
47
47
|
* Get the names of all available databases.
|
|
@@ -61,62 +61,87 @@ class ValtheraClass {
|
|
|
61
61
|
async issetCollection(collection) {
|
|
62
62
|
return await this.execute("issetCollection", { collection });
|
|
63
63
|
}
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
/**
|
|
65
|
+
* Add data to a database.
|
|
66
|
+
*/
|
|
67
|
+
add(query) {
|
|
68
|
+
query.control ||= {};
|
|
69
|
+
return this.execute("add", query);
|
|
66
70
|
}
|
|
67
71
|
/**
|
|
68
72
|
* Find data in a database.
|
|
69
73
|
*/
|
|
70
|
-
|
|
71
|
-
|
|
74
|
+
find(query) {
|
|
75
|
+
query.dbFindOpts ||= {};
|
|
76
|
+
query.findOpts ||= {};
|
|
77
|
+
query.context ||= {};
|
|
78
|
+
query.control ||= {};
|
|
79
|
+
return this.execute("find", query);
|
|
72
80
|
}
|
|
73
81
|
/**
|
|
74
82
|
* Find one data entry in a database.
|
|
75
83
|
*/
|
|
76
|
-
|
|
77
|
-
|
|
84
|
+
findOne(query) {
|
|
85
|
+
query.findOpts ||= {};
|
|
86
|
+
query.context ||= {};
|
|
87
|
+
query.control ||= {};
|
|
88
|
+
return this.execute("findOne", query);
|
|
78
89
|
}
|
|
79
90
|
/**
|
|
80
91
|
* Update data in a database.
|
|
81
92
|
*/
|
|
82
|
-
|
|
83
|
-
|
|
93
|
+
update(query) {
|
|
94
|
+
query.context ||= {};
|
|
95
|
+
query.control ||= {};
|
|
96
|
+
return this.execute("update", query);
|
|
84
97
|
}
|
|
85
98
|
/**
|
|
86
99
|
* Update one data entry in a database.
|
|
87
100
|
*/
|
|
88
|
-
|
|
89
|
-
|
|
101
|
+
updateOne(query) {
|
|
102
|
+
query.context ||= {};
|
|
103
|
+
query.control ||= {};
|
|
104
|
+
return this.execute("updateOne", query);
|
|
90
105
|
}
|
|
91
106
|
/**
|
|
92
107
|
* Remove data from a database.
|
|
93
108
|
*/
|
|
94
|
-
|
|
95
|
-
|
|
109
|
+
remove(query) {
|
|
110
|
+
query.context ||= {};
|
|
111
|
+
query.control ||= {};
|
|
112
|
+
return this.execute("remove", query);
|
|
96
113
|
}
|
|
97
114
|
/**
|
|
98
115
|
* Remove one data entry from a database.
|
|
99
116
|
*/
|
|
100
|
-
|
|
101
|
-
|
|
117
|
+
removeOne(query) {
|
|
118
|
+
query.context ||= {};
|
|
119
|
+
query.control ||= {};
|
|
120
|
+
return this.execute("removeOne", query);
|
|
102
121
|
}
|
|
103
122
|
/**
|
|
104
123
|
* Asynchronously updates one entry in a database or adds a new one if it doesn't exist.
|
|
105
124
|
*/
|
|
106
|
-
|
|
107
|
-
|
|
125
|
+
updateOneOrAdd(query) {
|
|
126
|
+
query.context ||= {};
|
|
127
|
+
query.add_arg ||= {};
|
|
128
|
+
query.control ||= {};
|
|
129
|
+
query.id_gen ||= true;
|
|
130
|
+
return this.execute("updateOneOrAdd", query);
|
|
108
131
|
}
|
|
109
132
|
/**
|
|
110
133
|
* Asynchronously removes one entry in a database or adds a new one if it doesn't exist. Usage e.g. for toggling a flag.
|
|
111
134
|
*/
|
|
112
|
-
|
|
113
|
-
|
|
135
|
+
toggleOne(query) {
|
|
136
|
+
query.data ||= {};
|
|
137
|
+
query.context ||= {};
|
|
138
|
+
query.control ||= {};
|
|
139
|
+
return this.execute("toggleOne", query);
|
|
114
140
|
}
|
|
115
141
|
/**
|
|
116
142
|
* Removes a database collection from the file system.
|
|
117
143
|
*/
|
|
118
|
-
|
|
119
|
-
return
|
|
144
|
+
removeCollection(collection) {
|
|
145
|
+
return this.execute("removeCollection", { collection });
|
|
120
146
|
}
|
|
121
147
|
}
|
|
122
|
-
export default ValtheraClass;
|
package/dist/helpers/addId.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import ActionsBase from "../base/actions.js";
|
|
1
|
+
import { ActionsBase } from "../base/actions.js";
|
|
2
2
|
import { VQuery } from "../types/query.js";
|
|
3
3
|
export declare function addId(query: VQuery, actions: ActionsBase, defaultGen?: boolean): Promise<import("../types/arg.js").Arg>;
|
package/dist/helpers/addId.js
CHANGED