@wxn0brp/db-core 0.0.6 → 0.1.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 +5 -3
- package/dist/base/actions.js +5 -3
- package/dist/base/custom.d.ts +36 -0
- package/dist/base/custom.js +63 -0
- package/dist/db/memory.d.ts +4 -56
- package/dist/db/memory.js +5 -85
- package/dist/db/valthera.d.ts +6 -5
- package/dist/db/valthera.js +20 -10
- package/dist/helpers/CollectionManager.d.ts +8 -8
- package/dist/types/options.d.ts +2 -2
- package/dist/types/valthera.d.ts +2 -2
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/dist/base/db.d.ts +0 -21
- package/dist/base/db.js +0 -56
package/dist/base/actions.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import Data from "../types/data.js";
|
|
2
2
|
import { VQuery } from "../types/query.js";
|
|
3
|
-
declare class
|
|
3
|
+
declare class ActionsBase {
|
|
4
|
+
_inited: boolean;
|
|
5
|
+
init(...args: any[]): Promise<void>;
|
|
4
6
|
getCollections(): Promise<string[]>;
|
|
5
|
-
|
|
7
|
+
ensureCollection(config: VQuery): Promise<boolean>;
|
|
6
8
|
issetCollection(config: VQuery): Promise<boolean>;
|
|
7
9
|
add(config: VQuery): Promise<Data>;
|
|
8
10
|
find(config: VQuery): Promise<Data[]>;
|
|
@@ -14,4 +16,4 @@ declare class dbActionBase {
|
|
|
14
16
|
removeCollection(config: VQuery): Promise<boolean>;
|
|
15
17
|
updateOneOrAdd(config: VQuery): Promise<boolean>;
|
|
16
18
|
}
|
|
17
|
-
export default
|
|
19
|
+
export default ActionsBase;
|
package/dist/base/actions.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { setDataUsingUpdateOneOrAdd } from "../helpers/updateOneOrAdd.js";
|
|
2
|
-
class
|
|
2
|
+
class ActionsBase {
|
|
3
|
+
_inited = true;
|
|
4
|
+
async init(...args) { }
|
|
3
5
|
async getCollections() {
|
|
4
6
|
throw new Error("Not implemented");
|
|
5
7
|
return [];
|
|
6
8
|
}
|
|
7
|
-
async
|
|
9
|
+
async ensureCollection(config) {
|
|
8
10
|
throw new Error("Not implemented");
|
|
9
11
|
return false;
|
|
10
12
|
}
|
|
@@ -53,4 +55,4 @@ class dbActionBase {
|
|
|
53
55
|
return res;
|
|
54
56
|
}
|
|
55
57
|
}
|
|
56
|
-
export default
|
|
58
|
+
export default ActionsBase;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import CustomFileCpu from "../customFileCpu.js";
|
|
2
|
+
import Data from "../types/data.js";
|
|
3
|
+
import { VQuery } from "../types/query.js";
|
|
4
|
+
import ActionsBase from "./actions.js";
|
|
5
|
+
export declare class CustomActionsBase extends ActionsBase {
|
|
6
|
+
fileCpu: CustomFileCpu;
|
|
7
|
+
constructor();
|
|
8
|
+
/**
|
|
9
|
+
* Add a new entry to the specified database.
|
|
10
|
+
*/
|
|
11
|
+
add({ collection, data, id_gen }: VQuery): Promise<import("../types/arg.js").Arg>;
|
|
12
|
+
/**
|
|
13
|
+
* Find entries in the specified database based on search criteria.
|
|
14
|
+
*/
|
|
15
|
+
find(query: VQuery): Promise<Data[]>;
|
|
16
|
+
/**
|
|
17
|
+
* Find the first matching entry in the specified database based on search criteria.
|
|
18
|
+
*/
|
|
19
|
+
findOne({ collection, search, context, findOpts }: VQuery): Promise<Data>;
|
|
20
|
+
/**
|
|
21
|
+
* Update entries in the specified database based on search criteria and an updater function or object.
|
|
22
|
+
*/
|
|
23
|
+
update({ collection, search, updater, context }: VQuery): Promise<boolean>;
|
|
24
|
+
/**
|
|
25
|
+
* Update the first matching entry in the specified database based on search criteria and an updater function or object.
|
|
26
|
+
*/
|
|
27
|
+
updateOne({ collection, search, updater, context }: VQuery): Promise<boolean>;
|
|
28
|
+
/**
|
|
29
|
+
* Remove entries from the specified database based on search criteria.
|
|
30
|
+
*/
|
|
31
|
+
remove({ collection, search, context }: VQuery): Promise<boolean>;
|
|
32
|
+
/**
|
|
33
|
+
* Remove the first matching entry from the specified database based on search criteria.
|
|
34
|
+
*/
|
|
35
|
+
removeOne({ collection, search, context }: VQuery): Promise<boolean>;
|
|
36
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import genId from "../helpers/gen.js";
|
|
2
|
+
import { findUtil } from "../utils/action.js";
|
|
3
|
+
import ActionsBase from "./actions.js";
|
|
4
|
+
export class CustomActionsBase extends ActionsBase {
|
|
5
|
+
fileCpu;
|
|
6
|
+
constructor() {
|
|
7
|
+
super();
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Add a new entry to the specified database.
|
|
11
|
+
*/
|
|
12
|
+
async add({ collection, data, id_gen = true }) {
|
|
13
|
+
await this.ensureCollection(arguments[0]);
|
|
14
|
+
if (id_gen)
|
|
15
|
+
data._id = data._id || genId();
|
|
16
|
+
await this.fileCpu.add(collection, data);
|
|
17
|
+
return data;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Find entries in the specified database based on search criteria.
|
|
21
|
+
*/
|
|
22
|
+
async find(query) {
|
|
23
|
+
await this.ensureCollection(query);
|
|
24
|
+
const data = await findUtil(query, this.fileCpu, [query.collection]);
|
|
25
|
+
return data;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Find the first matching entry in the specified database based on search criteria.
|
|
29
|
+
*/
|
|
30
|
+
async findOne({ collection, search, context = {}, findOpts = {} }) {
|
|
31
|
+
await this.ensureCollection(arguments[0]);
|
|
32
|
+
let data = await this.fileCpu.findOne(collection, search, context, findOpts);
|
|
33
|
+
return data || null;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Update entries in the specified database based on search criteria and an updater function or object.
|
|
37
|
+
*/
|
|
38
|
+
async update({ collection, search, updater, context = {} }) {
|
|
39
|
+
await this.ensureCollection(arguments[0]);
|
|
40
|
+
return await this.fileCpu.update(collection, false, search, updater, context);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Update the first matching entry in the specified database based on search criteria and an updater function or object.
|
|
44
|
+
*/
|
|
45
|
+
async updateOne({ collection, search, updater, context = {} }) {
|
|
46
|
+
await this.ensureCollection(arguments[0]);
|
|
47
|
+
return await this.fileCpu.update(collection, true, search, updater, context);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Remove entries from the specified database based on search criteria.
|
|
51
|
+
*/
|
|
52
|
+
async remove({ collection, search, context = {} }) {
|
|
53
|
+
await this.ensureCollection(arguments[0]);
|
|
54
|
+
return await this.fileCpu.remove(collection, false, search, context);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Remove the first matching entry from the specified database based on search criteria.
|
|
58
|
+
*/
|
|
59
|
+
async removeOne({ collection, search, context = {} }) {
|
|
60
|
+
await this.ensureCollection(arguments[0]);
|
|
61
|
+
return await this.fileCpu.remove(collection, true, search, context);
|
|
62
|
+
}
|
|
63
|
+
}
|
package/dist/db/memory.d.ts
CHANGED
|
@@ -1,67 +1,15 @@
|
|
|
1
|
-
import
|
|
2
|
-
import dbActionBase from "../base/actions.js";
|
|
1
|
+
import { CustomActionsBase } from "../base/custom.js";
|
|
3
2
|
import Data from "../types/data.js";
|
|
4
|
-
import FileCpu from "../types/fileCpu.js";
|
|
5
|
-
import { DbOpts } from "../types/options.js";
|
|
6
3
|
import { VQuery } from "../types/query.js";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
options: DbOpts;
|
|
10
|
-
fileCpu: FileCpu;
|
|
4
|
+
import ValtheraClass from "./valthera.js";
|
|
5
|
+
export declare class MemoryAction extends CustomActionsBase {
|
|
11
6
|
memory: Map<string, any[]>;
|
|
12
|
-
/**
|
|
13
|
-
* Creates a new instance of dbActionC.
|
|
14
|
-
* @constructor
|
|
15
|
-
* @param folder - The folder where database files are stored.
|
|
16
|
-
* @param options - The options object.
|
|
17
|
-
*/
|
|
18
7
|
constructor();
|
|
19
8
|
_readMemory(key: string): any[];
|
|
20
9
|
_writeMemory(key: string, data: any[]): void;
|
|
21
|
-
_getCollectionPath(collection: string): string;
|
|
22
|
-
/**
|
|
23
|
-
* Get a list of available databases in the specified folder.
|
|
24
|
-
*/
|
|
25
10
|
getCollections(): Promise<string[]>;
|
|
26
|
-
|
|
27
|
-
* Check and create the specified collection if it doesn't exist.
|
|
28
|
-
*/
|
|
29
|
-
checkCollection({ collection }: VQuery): Promise<boolean>;
|
|
30
|
-
/**
|
|
31
|
-
* Check if a collection exists.
|
|
32
|
-
*/
|
|
11
|
+
ensureCollection({ collection }: VQuery): Promise<boolean>;
|
|
33
12
|
issetCollection({ collection }: VQuery): Promise<boolean>;
|
|
34
|
-
/**
|
|
35
|
-
* Add a new entry to the specified database.
|
|
36
|
-
*/
|
|
37
|
-
add({ collection, data, id_gen }: VQuery): Promise<import("../types/arg.js").Arg>;
|
|
38
|
-
/**
|
|
39
|
-
* Find entries in the specified database based on search criteria.
|
|
40
|
-
*/
|
|
41
|
-
find(query: VQuery): Promise<Data[]>;
|
|
42
|
-
/**
|
|
43
|
-
* Find the first matching entry in the specified database based on search criteria.
|
|
44
|
-
*/
|
|
45
|
-
findOne({ collection, search, context, findOpts }: VQuery): Promise<Data>;
|
|
46
|
-
/**
|
|
47
|
-
* Update entries in the specified database based on search criteria and an updater function or object.
|
|
48
|
-
*/
|
|
49
|
-
update({ collection, search, updater, context }: VQuery): Promise<boolean>;
|
|
50
|
-
/**
|
|
51
|
-
* Update the first matching entry in the specified database based on search criteria and an updater function or object.
|
|
52
|
-
*/
|
|
53
|
-
updateOne({ collection, search, updater, context }: VQuery): Promise<boolean>;
|
|
54
|
-
/**
|
|
55
|
-
* Remove entries from the specified database based on search criteria.
|
|
56
|
-
*/
|
|
57
|
-
remove({ collection, search, context }: VQuery): Promise<boolean>;
|
|
58
|
-
/**
|
|
59
|
-
* Remove the first matching entry from the specified database based on search criteria.
|
|
60
|
-
*/
|
|
61
|
-
removeOne({ collection, search, context }: VQuery): Promise<boolean>;
|
|
62
|
-
/**
|
|
63
|
-
* Removes a database collection from the file system.
|
|
64
|
-
*/
|
|
65
13
|
removeCollection({ collection }: VQuery): Promise<boolean>;
|
|
66
14
|
}
|
|
67
15
|
export default class ValtheraMemory extends ValtheraClass {
|
package/dist/db/memory.js
CHANGED
|
@@ -1,23 +1,12 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { CustomActionsBase } from "../base/custom.js";
|
|
2
2
|
import CustomFileCpu from "../customFileCpu.js";
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
import { findUtil } from "../utils/action.js";
|
|
6
|
-
export class MemoryAction extends dbActionBase {
|
|
7
|
-
folder;
|
|
8
|
-
options;
|
|
9
|
-
fileCpu;
|
|
3
|
+
import ValtheraClass from "./valthera.js";
|
|
4
|
+
export class MemoryAction extends CustomActionsBase {
|
|
10
5
|
memory;
|
|
11
|
-
/**
|
|
12
|
-
* Creates a new instance of dbActionC.
|
|
13
|
-
* @constructor
|
|
14
|
-
* @param folder - The folder where database files are stored.
|
|
15
|
-
* @param options - The options object.
|
|
16
|
-
*/
|
|
17
6
|
constructor() {
|
|
18
7
|
super();
|
|
19
|
-
this.memory = new Map();
|
|
20
8
|
this.fileCpu = new CustomFileCpu(this._readMemory.bind(this), this._writeMemory.bind(this));
|
|
9
|
+
this.memory = new Map();
|
|
21
10
|
}
|
|
22
11
|
_readMemory(key) {
|
|
23
12
|
if (!this.memory.has(key))
|
|
@@ -27,88 +16,19 @@ export class MemoryAction extends dbActionBase {
|
|
|
27
16
|
_writeMemory(key, data) {
|
|
28
17
|
this.memory.set(key, data);
|
|
29
18
|
}
|
|
30
|
-
_getCollectionPath(collection) {
|
|
31
|
-
return this.folder + "/" + collection + "/";
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Get a list of available databases in the specified folder.
|
|
35
|
-
*/
|
|
36
19
|
async getCollections() {
|
|
37
20
|
const collections = Array.from(this.memory.keys());
|
|
38
21
|
return collections;
|
|
39
22
|
}
|
|
40
|
-
|
|
41
|
-
* Check and create the specified collection if it doesn't exist.
|
|
42
|
-
*/
|
|
43
|
-
async checkCollection({ collection }) {
|
|
23
|
+
async ensureCollection({ collection }) {
|
|
44
24
|
if (this.issetCollection(collection))
|
|
45
25
|
return;
|
|
46
26
|
this.memory.set(collection, []);
|
|
47
27
|
return true;
|
|
48
28
|
}
|
|
49
|
-
/**
|
|
50
|
-
* Check if a collection exists.
|
|
51
|
-
*/
|
|
52
29
|
async issetCollection({ collection }) {
|
|
53
30
|
return this.memory.has(collection);
|
|
54
31
|
}
|
|
55
|
-
/**
|
|
56
|
-
* Add a new entry to the specified database.
|
|
57
|
-
*/
|
|
58
|
-
async add({ collection, data, id_gen = true }) {
|
|
59
|
-
await this.checkCollection(arguments[0]);
|
|
60
|
-
if (id_gen)
|
|
61
|
-
data._id = data._id || genId();
|
|
62
|
-
await this.fileCpu.add(collection, data);
|
|
63
|
-
return data;
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Find entries in the specified database based on search criteria.
|
|
67
|
-
*/
|
|
68
|
-
async find(query) {
|
|
69
|
-
await this.checkCollection(query);
|
|
70
|
-
const data = await findUtil(query, this.fileCpu, [query.collection]);
|
|
71
|
-
return data;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Find the first matching entry in the specified database based on search criteria.
|
|
75
|
-
*/
|
|
76
|
-
async findOne({ collection, search, context = {}, findOpts = {} }) {
|
|
77
|
-
await this.checkCollection(arguments[0]);
|
|
78
|
-
let data = await this.fileCpu.findOne(collection, search, context, findOpts);
|
|
79
|
-
return data || null;
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Update entries in the specified database based on search criteria and an updater function or object.
|
|
83
|
-
*/
|
|
84
|
-
async update({ collection, search, updater, context = {} }) {
|
|
85
|
-
await this.checkCollection(arguments[0]);
|
|
86
|
-
return await this.fileCpu.update(collection, false, search, updater, context);
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Update the first matching entry in the specified database based on search criteria and an updater function or object.
|
|
90
|
-
*/
|
|
91
|
-
async updateOne({ collection, search, updater, context = {} }) {
|
|
92
|
-
await this.checkCollection(arguments[0]);
|
|
93
|
-
return await this.fileCpu.update(collection, true, search, updater, context);
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Remove entries from the specified database based on search criteria.
|
|
97
|
-
*/
|
|
98
|
-
async remove({ collection, search, context = {} }) {
|
|
99
|
-
await this.checkCollection(arguments[0]);
|
|
100
|
-
return await this.fileCpu.remove(collection, false, search, context);
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Remove the first matching entry from the specified database based on search criteria.
|
|
104
|
-
*/
|
|
105
|
-
async removeOne({ collection, search, context = {} }) {
|
|
106
|
-
await this.checkCollection(arguments[0]);
|
|
107
|
-
return await this.fileCpu.remove(collection, true, search, context);
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Removes a database collection from the file system.
|
|
111
|
-
*/
|
|
112
32
|
async removeCollection({ collection }) {
|
|
113
33
|
this.memory.delete(collection);
|
|
114
34
|
return true;
|
package/dist/db/valthera.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { UniversalEventEmitter } from "../helpers/eventEmiter.js";
|
|
2
|
-
import
|
|
2
|
+
import ActionsBase from "../base/actions.js";
|
|
3
3
|
import CollectionManager from "../helpers/CollectionManager.js";
|
|
4
4
|
import executorC from "../helpers/executor.js";
|
|
5
5
|
import { Arg, Search, Updater } from "../types/arg.js";
|
|
@@ -12,11 +12,12 @@ import { ValtheraCompatible } from "../types/valthera.js";
|
|
|
12
12
|
* @class
|
|
13
13
|
*/
|
|
14
14
|
declare class ValtheraClass implements ValtheraCompatible {
|
|
15
|
-
dbAction:
|
|
15
|
+
dbAction: ActionsBase;
|
|
16
16
|
executor: executorC;
|
|
17
17
|
emiter: UniversalEventEmitter;
|
|
18
18
|
version: string;
|
|
19
19
|
constructor(options?: DbOpts);
|
|
20
|
+
init(...args: any[]): Promise<unknown>;
|
|
20
21
|
private execute;
|
|
21
22
|
/**
|
|
22
23
|
* Create a new instance of a CollectionManager class.
|
|
@@ -29,7 +30,7 @@ declare class ValtheraClass implements ValtheraCompatible {
|
|
|
29
30
|
/**
|
|
30
31
|
* Check and create the specified collection if it doesn't exist.
|
|
31
32
|
*/
|
|
32
|
-
|
|
33
|
+
ensureCollection(collection: string): Promise<boolean>;
|
|
33
34
|
/**
|
|
34
35
|
* Check if a collection exists.
|
|
35
36
|
*/
|
|
@@ -41,11 +42,11 @@ declare class ValtheraClass implements ValtheraCompatible {
|
|
|
41
42
|
/**
|
|
42
43
|
* Find data in a database.
|
|
43
44
|
*/
|
|
44
|
-
find<T = Data>(collection: string, search
|
|
45
|
+
find<T = Data>(collection: string, search?: Search<T>, context?: VContext, dbFindOpts?: DbFindOpts<T>, findOpts?: FindOpts<T>): Promise<T[]>;
|
|
45
46
|
/**
|
|
46
47
|
* Find one data entry in a database.
|
|
47
48
|
*/
|
|
48
|
-
findOne<T = Data>(collection: string, search
|
|
49
|
+
findOne<T = Data>(collection: string, search?: Search<T>, context?: VContext, findOpts?: FindOpts<T>): Promise<T>;
|
|
49
50
|
/**
|
|
50
51
|
* Update data in a database.
|
|
51
52
|
*/
|
package/dist/db/valthera.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { version } from "../version.js";
|
|
2
2
|
import { UniversalEventEmitter } from "../helpers/eventEmiter.js";
|
|
3
|
-
import
|
|
3
|
+
import ActionsBase from "../base/actions.js";
|
|
4
4
|
import CollectionManager from "../helpers/CollectionManager.js";
|
|
5
5
|
import executorC from "../helpers/executor.js";
|
|
6
6
|
/**
|
|
@@ -13,16 +13,26 @@ class ValtheraClass {
|
|
|
13
13
|
emiter;
|
|
14
14
|
version = version;
|
|
15
15
|
constructor(options = {}) {
|
|
16
|
-
this.dbAction = options.dbAction || new
|
|
16
|
+
this.dbAction = options.dbAction || new ActionsBase();
|
|
17
17
|
this.executor = options.executor || new executorC();
|
|
18
18
|
this.emiter = new UniversalEventEmitter();
|
|
19
19
|
}
|
|
20
|
+
async init(...args) {
|
|
21
|
+
if (this.dbAction._inited)
|
|
22
|
+
return;
|
|
23
|
+
const self = this;
|
|
24
|
+
return await this.executor.addOp(async () => {
|
|
25
|
+
if (self.dbAction._inited)
|
|
26
|
+
return;
|
|
27
|
+
await self.dbAction.init(...args);
|
|
28
|
+
self.dbAction._inited = true;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
20
31
|
async execute(name, ...args) {
|
|
32
|
+
await this.init();
|
|
21
33
|
const result = await this.executor.addOp(this.dbAction[name].bind(this.dbAction), ...args);
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (this.emiter.listenerCount("*") !== 0)
|
|
25
|
-
this.emiter.emit("*", name, args, result);
|
|
34
|
+
this.emiter.emit(name, args, result);
|
|
35
|
+
this.emiter.emit("*", name, args, result);
|
|
26
36
|
return result;
|
|
27
37
|
}
|
|
28
38
|
/**
|
|
@@ -40,8 +50,8 @@ class ValtheraClass {
|
|
|
40
50
|
/**
|
|
41
51
|
* Check and create the specified collection if it doesn't exist.
|
|
42
52
|
*/
|
|
43
|
-
async
|
|
44
|
-
return await this.execute("
|
|
53
|
+
async ensureCollection(collection) {
|
|
54
|
+
return await this.execute("ensureCollection", { collection });
|
|
45
55
|
}
|
|
46
56
|
/**
|
|
47
57
|
* Check if a collection exists.
|
|
@@ -58,13 +68,13 @@ class ValtheraClass {
|
|
|
58
68
|
/**
|
|
59
69
|
* Find data in a database.
|
|
60
70
|
*/
|
|
61
|
-
async find(collection, search, context = {}, dbFindOpts = {}, findOpts = {}) {
|
|
71
|
+
async find(collection, search = {}, context = {}, dbFindOpts = {}, findOpts = {}) {
|
|
62
72
|
return await this.execute("find", { collection, search, context, dbFindOpts, findOpts });
|
|
63
73
|
}
|
|
64
74
|
/**
|
|
65
75
|
* Find one data entry in a database.
|
|
66
76
|
*/
|
|
67
|
-
async findOne(collection, search, context = {}, findOpts = {}) {
|
|
77
|
+
async findOne(collection, search = {}, context = {}, findOpts = {}) {
|
|
68
78
|
return await this.execute("findOne", { collection, search, context, findOpts });
|
|
69
79
|
}
|
|
70
80
|
/**
|
|
@@ -10,34 +10,34 @@ declare class CollectionManager {
|
|
|
10
10
|
/**
|
|
11
11
|
* Add data to a database.
|
|
12
12
|
*/
|
|
13
|
-
add<T = Data>(data: Arg
|
|
13
|
+
add<T = Data>(data: Arg<T>, id_gen?: boolean): Promise<T>;
|
|
14
14
|
/**
|
|
15
15
|
* Find data in a database.
|
|
16
16
|
*/
|
|
17
|
-
find<T = Data>(search: Search
|
|
17
|
+
find<T = Data>(search: Search<T>, context?: VContext, options?: DbFindOpts<T>, findOpts?: FindOpts<T>): Promise<T[]>;
|
|
18
18
|
/**
|
|
19
19
|
* Find one data entry in a database.
|
|
20
20
|
*/
|
|
21
|
-
findOne<T = Data>(search: Search
|
|
21
|
+
findOne<T = Data>(search: Search<T>, context?: VContext, findOpts?: FindOpts<T>): Promise<T>;
|
|
22
22
|
/**
|
|
23
23
|
* Update data in a database.
|
|
24
24
|
*/
|
|
25
|
-
update(search: Search
|
|
25
|
+
update<T = Data>(search: Search<T>, updater: Updater<T>, context?: VContext): Promise<boolean>;
|
|
26
26
|
/**
|
|
27
27
|
* Update one data entry in a database.
|
|
28
28
|
*/
|
|
29
|
-
updateOne(search: Search
|
|
29
|
+
updateOne<T = Data>(search: Search<T>, updater: Updater<T>, context?: VContext): Promise<boolean>;
|
|
30
30
|
/**
|
|
31
31
|
* Remove data from a database.
|
|
32
32
|
*/
|
|
33
|
-
remove(search: Search
|
|
33
|
+
remove<T = Data>(search: Search<T>, context?: VContext): Promise<boolean>;
|
|
34
34
|
/**
|
|
35
35
|
* Remove one data entry from a database.
|
|
36
36
|
*/
|
|
37
|
-
removeOne(search: Search
|
|
37
|
+
removeOne<T = Data>(search: Search<T>, context?: VContext): Promise<boolean>;
|
|
38
38
|
/**
|
|
39
39
|
* Asynchronously updates one entry in a database or adds a new one if it doesn't exist.
|
|
40
40
|
*/
|
|
41
|
-
updateOneOrAdd(search: Search
|
|
41
|
+
updateOneOrAdd<T = Data>(search: Search<T>, updater: Updater<T>, add_arg?: Arg<T>, context?: VContext, id_gen?: boolean): Promise<boolean>;
|
|
42
42
|
}
|
|
43
43
|
export default CollectionManager;
|
package/dist/types/options.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import ActionsBase from "../base/actions.js";
|
|
2
2
|
import executorC from "../helpers/executor.js";
|
|
3
3
|
import { KeysMatching } from "./utils.js";
|
|
4
4
|
export interface DbOpts {
|
|
5
5
|
maxFileSize?: number;
|
|
6
|
-
dbAction?:
|
|
6
|
+
dbAction?: ActionsBase;
|
|
7
7
|
executor?: executorC;
|
|
8
8
|
}
|
|
9
9
|
export interface DbFindOpts<T = any> {
|
package/dist/types/valthera.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { VContext } from "./types.js";
|
|
|
7
7
|
export interface ValtheraCompatible {
|
|
8
8
|
c(collection: string): CollectionManager;
|
|
9
9
|
getCollections(): Promise<string[]>;
|
|
10
|
-
|
|
10
|
+
ensureCollection(collection: string): Promise<boolean>;
|
|
11
11
|
issetCollection(collection: string): Promise<boolean>;
|
|
12
12
|
add<T = Data>(collection: string, data: Arg<T>, id_gen?: boolean): Promise<T>;
|
|
13
13
|
find<T = Data>(collection: string, search: Search<T>, context?: VContext, options?: DbFindOpts<T>, findOpts?: FindOpts<T>): Promise<T[]>;
|
|
@@ -22,7 +22,7 @@ export interface ValtheraCompatible {
|
|
|
22
22
|
export interface ValtheraCompatibleInternal {
|
|
23
23
|
c(config: VQuery): CollectionManager;
|
|
24
24
|
getCollections(): Promise<string[]>;
|
|
25
|
-
|
|
25
|
+
ensureCollection(config: VQuery): Promise<boolean>;
|
|
26
26
|
issetCollection(config: VQuery): Promise<boolean>;
|
|
27
27
|
add<T = Data>(config: VQuery): Promise<T>;
|
|
28
28
|
find<T = Data>(config: VQuery): Promise<T[]>;
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = "0.0
|
|
1
|
+
export const version = "0.1.0";
|
package/package.json
CHANGED
package/dist/base/db.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import CollectionManager from "../helpers/CollectionManager.js";
|
|
2
|
-
import Data from "../types/data.js";
|
|
3
|
-
import { VQuery } from "../types/query.js";
|
|
4
|
-
import { ValtheraCompatibleInternal } from "../types/valthera.js";
|
|
5
|
-
declare class ValtheraBase implements ValtheraCompatibleInternal {
|
|
6
|
-
version: string;
|
|
7
|
-
c(config: VQuery): CollectionManager;
|
|
8
|
-
getCollections(): Promise<any[]>;
|
|
9
|
-
checkCollection(config: VQuery): Promise<boolean>;
|
|
10
|
-
issetCollection(config: VQuery): Promise<boolean>;
|
|
11
|
-
add<T = Data>(config: VQuery): Promise<T>;
|
|
12
|
-
find<T = Data>(config: VQuery): Promise<T[]>;
|
|
13
|
-
findOne<T = Data>(config: VQuery): Promise<T>;
|
|
14
|
-
remove(config: VQuery): Promise<boolean>;
|
|
15
|
-
removeCollection(config: VQuery): Promise<boolean>;
|
|
16
|
-
removeOne(config: VQuery): Promise<boolean>;
|
|
17
|
-
update(config: VQuery): Promise<boolean>;
|
|
18
|
-
updateOne(config: VQuery): Promise<boolean>;
|
|
19
|
-
updateOneOrAdd(config: VQuery): Promise<boolean>;
|
|
20
|
-
}
|
|
21
|
-
export default ValtheraBase;
|
package/dist/base/db.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { version } from "../version.js";
|
|
2
|
-
class ValtheraBase {
|
|
3
|
-
version = version;
|
|
4
|
-
c(config) {
|
|
5
|
-
throw new Error("Not implemented");
|
|
6
|
-
}
|
|
7
|
-
async getCollections() {
|
|
8
|
-
throw new Error("Not implemented");
|
|
9
|
-
return [];
|
|
10
|
-
}
|
|
11
|
-
async checkCollection(config) {
|
|
12
|
-
throw new Error("Not implemented");
|
|
13
|
-
return false;
|
|
14
|
-
}
|
|
15
|
-
async issetCollection(config) {
|
|
16
|
-
throw new Error("Not implemented");
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
19
|
-
async add(config) {
|
|
20
|
-
throw new Error("Not implemented");
|
|
21
|
-
return {};
|
|
22
|
-
}
|
|
23
|
-
async find(config) {
|
|
24
|
-
throw new Error("Not implemented");
|
|
25
|
-
return [];
|
|
26
|
-
}
|
|
27
|
-
async findOne(config) {
|
|
28
|
-
throw new Error("Not implemented");
|
|
29
|
-
return {};
|
|
30
|
-
}
|
|
31
|
-
async remove(config) {
|
|
32
|
-
throw new Error("Not implemented");
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
async removeCollection(config) {
|
|
36
|
-
throw new Error("Not implemented");
|
|
37
|
-
return false;
|
|
38
|
-
}
|
|
39
|
-
async removeOne(config) {
|
|
40
|
-
throw new Error("Not implemented");
|
|
41
|
-
return false;
|
|
42
|
-
}
|
|
43
|
-
async update(config) {
|
|
44
|
-
throw new Error("Not implemented");
|
|
45
|
-
return false;
|
|
46
|
-
}
|
|
47
|
-
async updateOne(config) {
|
|
48
|
-
throw new Error("Not implemented");
|
|
49
|
-
return false;
|
|
50
|
-
}
|
|
51
|
-
async updateOneOrAdd(config) {
|
|
52
|
-
throw new Error("Not implemented");
|
|
53
|
-
return false;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
export default ValtheraBase;
|