@wxn0brp/db 0.0.6 → 0.0.8
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 +1 -1
- package/dist/cjs/CollectionManager.d.ts +11 -10
- package/dist/cjs/CollectionManager.js +4 -4
- package/dist/cjs/action.d.ts +10 -15
- package/dist/cjs/action.js +6 -12
- package/dist/cjs/client/database.d.ts +72 -0
- package/dist/cjs/{remote/client → client}/database.js +10 -10
- package/dist/cjs/database.d.ts +10 -18
- package/dist/cjs/database.js +9 -17
- package/dist/cjs/file/find.d.ts +3 -3
- package/dist/cjs/file/remove.d.ts +2 -2
- package/dist/cjs/file/update.d.ts +2 -2
- package/dist/cjs/file/update.js +8 -6
- package/dist/cjs/index.d.ts +8 -2
- package/dist/cjs/index.js +2 -2
- package/dist/cjs/relation.d.ts +3 -3
- package/dist/cjs/types/arg.d.ts +7 -1
- package/dist/cjs/types/searchOpts.d.ts +5 -4
- package/dist/cjs/types/types.d.ts +1 -0
- package/dist/cjs/types/updater.d.ts +26 -0
- package/dist/cjs/types/updater.js +5 -0
- package/dist/cjs/utils/updateObject.d.ts +4 -5
- package/dist/cjs/utils/updateObject.js +135 -5
- package/dist/esm/CollectionManager.d.ts +11 -10
- package/dist/esm/CollectionManager.js +4 -4
- package/dist/esm/action.d.ts +10 -15
- package/dist/esm/action.js +6 -12
- package/dist/esm/client/database.d.ts +72 -0
- package/dist/esm/{remote/client → client}/database.js +10 -10
- package/dist/esm/database.d.ts +10 -18
- package/dist/esm/database.js +9 -17
- package/dist/esm/file/find.d.ts +3 -3
- package/dist/esm/file/remove.d.ts +2 -2
- package/dist/esm/file/update.d.ts +2 -2
- package/dist/esm/file/update.js +11 -9
- package/dist/esm/index.d.ts +8 -2
- package/dist/esm/index.js +2 -2
- package/dist/esm/relation.d.ts +3 -3
- package/dist/esm/types/arg.d.ts +7 -1
- package/dist/esm/types/searchOpts.d.ts +5 -4
- package/dist/esm/types/types.d.ts +1 -0
- package/dist/esm/types/updater.d.ts +26 -0
- package/dist/esm/types/updater.js +4 -0
- package/dist/esm/utils/updateObject.d.ts +4 -5
- package/dist/esm/utils/updateObject.js +135 -5
- package/package.json +8 -11
- package/dist/cjs/remote/client/database.d.ts +0 -71
- package/dist/cjs/remote/server/auth.d.ts +0 -31
- package/dist/cjs/remote/server/auth.js +0 -99
- package/dist/cjs/remote/server/db.d.ts +0 -2
- package/dist/cjs/remote/server/db.js +0 -223
- package/dist/cjs/remote/server/function.d.ts +0 -2
- package/dist/cjs/remote/server/function.js +0 -89
- package/dist/cjs/remote/server/graph.d.ts +0 -2
- package/dist/cjs/remote/server/graph.js +0 -145
- package/dist/cjs/remote/server/gui/css/main.css +0 -130
- package/dist/cjs/remote/server/gui/css/scrool.css +0 -81
- package/dist/cjs/remote/server/gui/css/style.css +0 -61
- package/dist/cjs/remote/server/gui/favicon.svg +0 -12
- package/dist/cjs/remote/server/gui/html/data.html +0 -15
- package/dist/cjs/remote/server/gui/html/main.html +0 -46
- package/dist/cjs/remote/server/gui/html/nav.html +0 -25
- package/dist/cjs/remote/server/gui/html/popup.html +0 -51
- package/dist/cjs/remote/server/gui/index.html +0 -49
- package/dist/cjs/remote/server/gui/js/api.js +0 -166
- package/dist/cjs/remote/server/gui/js/index.js +0 -17
- package/dist/cjs/remote/server/gui/js/loadHTML.js +0 -16
- package/dist/cjs/remote/server/gui/js/popUp.js +0 -72
- package/dist/cjs/remote/server/gui/js/queryApi.js +0 -51
- package/dist/cjs/remote/server/gui/js/queryDb.js +0 -79
- package/dist/cjs/remote/server/gui/js/queryGraph.js +0 -144
- package/dist/cjs/remote/server/gui/js/render.js +0 -64
- package/dist/cjs/remote/server/gui/js/templates.js +0 -31
- package/dist/cjs/remote/server/gui/js/utils.js +0 -36
- package/dist/cjs/remote/server/gui/js/vars.js +0 -9
- package/dist/cjs/remote/server/gui/libs/core.js +0 -176
- package/dist/cjs/remote/server/gui/libs/d3.v7.min.js +0 -2
- package/dist/cjs/remote/server/gui/libs/handlebars.min.js +0 -29
- package/dist/cjs/remote/server/gui/libs/json5.min.js +0 -1
- package/dist/cjs/remote/server/index.d.ts +0 -1
- package/dist/cjs/remote/server/index.js +0 -66
- package/dist/cjs/remote/server/initDataBases.d.ts +0 -1
- package/dist/cjs/remote/server/initDataBases.js +0 -25
- package/dist/cjs/remote/server/pathUtils.d.ts +0 -1
- package/dist/cjs/remote/server/pathUtils.js +0 -12
- package/dist/cjs/remote/server/secret.d.ts +0 -1
- package/dist/cjs/remote/server/secret.js +0 -25
- package/dist/cjs/remote/serverMgmt/index.d.ts +0 -1
- package/dist/cjs/remote/serverMgmt/index.js +0 -87
- package/dist/esm/remote/client/database.d.ts +0 -71
- package/dist/esm/remote/server/auth.d.ts +0 -31
- package/dist/esm/remote/server/auth.js +0 -87
- package/dist/esm/remote/server/db.d.ts +0 -2
- package/dist/esm/remote/server/db.js +0 -218
- package/dist/esm/remote/server/function.d.ts +0 -2
- package/dist/esm/remote/server/function.js +0 -87
- package/dist/esm/remote/server/graph.d.ts +0 -2
- package/dist/esm/remote/server/graph.js +0 -143
- package/dist/esm/remote/server/gui/css/main.css +0 -130
- package/dist/esm/remote/server/gui/css/scrool.css +0 -81
- package/dist/esm/remote/server/gui/css/style.css +0 -61
- package/dist/esm/remote/server/gui/favicon.svg +0 -12
- package/dist/esm/remote/server/gui/html/data.html +0 -15
- package/dist/esm/remote/server/gui/html/main.html +0 -46
- package/dist/esm/remote/server/gui/html/nav.html +0 -25
- package/dist/esm/remote/server/gui/html/popup.html +0 -51
- package/dist/esm/remote/server/gui/index.html +0 -49
- package/dist/esm/remote/server/gui/js/api.js +0 -166
- package/dist/esm/remote/server/gui/js/index.js +0 -17
- package/dist/esm/remote/server/gui/js/loadHTML.js +0 -16
- package/dist/esm/remote/server/gui/js/popUp.js +0 -72
- package/dist/esm/remote/server/gui/js/queryApi.js +0 -51
- package/dist/esm/remote/server/gui/js/queryDb.js +0 -79
- package/dist/esm/remote/server/gui/js/queryGraph.js +0 -144
- package/dist/esm/remote/server/gui/js/render.js +0 -64
- package/dist/esm/remote/server/gui/js/templates.js +0 -31
- package/dist/esm/remote/server/gui/js/utils.js +0 -36
- package/dist/esm/remote/server/gui/js/vars.js +0 -9
- package/dist/esm/remote/server/gui/libs/core.js +0 -176
- package/dist/esm/remote/server/gui/libs/d3.v7.min.js +0 -2
- package/dist/esm/remote/server/gui/libs/handlebars.min.js +0 -29
- package/dist/esm/remote/server/gui/libs/json5.min.js +0 -1
- package/dist/esm/remote/server/index.d.ts +0 -1
- package/dist/esm/remote/server/index.js +0 -61
- package/dist/esm/remote/server/initDataBases.d.ts +0 -1
- package/dist/esm/remote/server/initDataBases.js +0 -20
- package/dist/esm/remote/server/pathUtils.d.ts +0 -1
- package/dist/esm/remote/server/pathUtils.js +0 -6
- package/dist/esm/remote/server/secret.d.ts +0 -1
- package/dist/esm/remote/server/secret.js +0 -19
- package/dist/esm/remote/serverMgmt/index.d.ts +0 -1
- package/dist/esm/remote/serverMgmt/index.js +0 -82
- /package/dist/cjs/{remote/client → client}/function.d.ts +0 -0
- /package/dist/cjs/{remote/client → client}/function.js +0 -0
- /package/dist/cjs/{remote/client → client}/graph.d.ts +0 -0
- /package/dist/cjs/{remote/client → client}/graph.js +0 -0
- /package/dist/cjs/{remote/client → client}/remote.d.ts +0 -0
- /package/dist/cjs/{remote/client → client}/remote.js +0 -0
- /package/dist/esm/{remote/client → client}/function.d.ts +0 -0
- /package/dist/esm/{remote/client → client}/function.js +0 -0
- /package/dist/esm/{remote/client → client}/graph.d.ts +0 -0
- /package/dist/esm/{remote/client → client}/graph.js +0 -0
- /package/dist/esm/{remote/client → client}/remote.d.ts +0 -0
- /package/dist/esm/{remote/client → client}/remote.js +0 -0
package/README.md
CHANGED
|
@@ -27,7 +27,7 @@ For detailed information, refer to the following resources:
|
|
|
27
27
|
- [DataBase Documentation](./docs/database.md)
|
|
28
28
|
- [Graph Documentation](./docs/graph.md)
|
|
29
29
|
- [Remote Database and Graph Client Documentation](./docs/remote.md)
|
|
30
|
-
- [Remote Server Documentation](./docs/remote_server.md)
|
|
31
30
|
- [Search Options Documentation](./docs/search_opts.md)
|
|
32
31
|
- [Find Options Documentation](./docs/find_opts.md)
|
|
32
|
+
- [Updater Options Documentation](./docs/updater.md)
|
|
33
33
|
- [Relation Documentation](./docs/relation.md)
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import DataBase from "./database.js";
|
|
2
|
-
import DataBaseRemote from "./
|
|
3
|
-
import { Arg,
|
|
2
|
+
import DataBaseRemote from "./client/database.js";
|
|
3
|
+
import { Arg, Search, Updater } from "./types/arg.js";
|
|
4
4
|
import { DbFindOpts, FindOpts } from "./types/options.js";
|
|
5
5
|
import { Context } from "./types/types.js";
|
|
6
|
+
import Data from "./types/data.js";
|
|
6
7
|
declare class CollectionManager {
|
|
7
8
|
db: DataBase | DataBaseRemote;
|
|
8
9
|
collection: string;
|
|
@@ -10,34 +11,34 @@ declare class CollectionManager {
|
|
|
10
11
|
/**
|
|
11
12
|
* Add data to a database.
|
|
12
13
|
*/
|
|
13
|
-
add(data: Arg, id_gen?: boolean): Promise<
|
|
14
|
+
add<T = Data>(data: Arg, id_gen?: boolean): Promise<T>;
|
|
14
15
|
/**
|
|
15
16
|
* Find data in a database.
|
|
16
17
|
*/
|
|
17
|
-
find(search:
|
|
18
|
+
find<T = Data>(search: Search, context?: Context, options?: DbFindOpts, findOpts?: FindOpts): Promise<T[]>;
|
|
18
19
|
/**
|
|
19
20
|
* Find one data entry in a database.
|
|
20
21
|
*/
|
|
21
|
-
findOne(search:
|
|
22
|
+
findOne<T = Data>(search: Search, context?: Context, findOpts?: FindOpts): Promise<T>;
|
|
22
23
|
/**
|
|
23
24
|
* Update data in a database.
|
|
24
25
|
*/
|
|
25
|
-
update(search:
|
|
26
|
+
update(search: Search, updater: Updater, context?: Context): Promise<boolean>;
|
|
26
27
|
/**
|
|
27
28
|
* Update one data entry in a database.
|
|
28
29
|
*/
|
|
29
|
-
updateOne(search:
|
|
30
|
+
updateOne(search: Search, updater: Updater, context?: Context): Promise<boolean>;
|
|
30
31
|
/**
|
|
31
32
|
* Remove data from a database.
|
|
32
33
|
*/
|
|
33
|
-
remove(search:
|
|
34
|
+
remove(search: Search, context?: Context): Promise<boolean>;
|
|
34
35
|
/**
|
|
35
36
|
* Remove one data entry from a database.
|
|
36
37
|
*/
|
|
37
|
-
removeOne(search:
|
|
38
|
+
removeOne(search: Search, context?: Context): Promise<boolean>;
|
|
38
39
|
/**
|
|
39
40
|
* Asynchronously updates one entry in a database or adds a new one if it doesn't exist.
|
|
40
41
|
*/
|
|
41
|
-
updateOneOrAdd(search:
|
|
42
|
+
updateOneOrAdd(search: Search, arg: Search, add_arg?: Arg, context?: Context, id_gen?: boolean): Promise<boolean>;
|
|
42
43
|
}
|
|
43
44
|
export default CollectionManager;
|
|
@@ -28,14 +28,14 @@ class CollectionManager {
|
|
|
28
28
|
/**
|
|
29
29
|
* Update data in a database.
|
|
30
30
|
*/
|
|
31
|
-
async update(search,
|
|
32
|
-
return await this.db.update(this.collection, search,
|
|
31
|
+
async update(search, updater, context = {}) {
|
|
32
|
+
return await this.db.update(this.collection, search, updater, context);
|
|
33
33
|
}
|
|
34
34
|
/**
|
|
35
35
|
* Update one data entry in a database.
|
|
36
36
|
*/
|
|
37
|
-
async updateOne(search,
|
|
38
|
-
return await this.db.updateOne(this.collection, search,
|
|
37
|
+
async updateOne(search, updater, context = {}) {
|
|
38
|
+
return await this.db.updateOne(this.collection, search, updater, context);
|
|
39
39
|
}
|
|
40
40
|
/**
|
|
41
41
|
* Remove data from a database.
|
package/dist/cjs/action.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { Arg,
|
|
1
|
+
import { Arg, Search, Updater } from "./types/arg.js";
|
|
2
2
|
import { DbFindOpts, DbOpts, FindOpts } from "./types/options.js";
|
|
3
3
|
import { Context } from "./types/types";
|
|
4
|
+
import { SearchOptions } from "./types/searchOpts.js";
|
|
4
5
|
import Data from "./types/data.js";
|
|
5
6
|
/**
|
|
6
7
|
* A class representing database actions on files.
|
|
@@ -12,27 +13,21 @@ declare class dbActionC {
|
|
|
12
13
|
/**
|
|
13
14
|
* Creates a new instance of dbActionC.
|
|
14
15
|
* @constructor
|
|
15
|
-
* @param
|
|
16
|
-
* @param
|
|
16
|
+
* @param folder - The folder where database files are stored.
|
|
17
|
+
* @param options - The options object.
|
|
17
18
|
*/
|
|
18
19
|
constructor(folder: string, options: DbOpts);
|
|
19
20
|
_getCollectionPath(collection: string): string;
|
|
20
21
|
/**
|
|
21
22
|
* Get a list of available databases in the specified folder.
|
|
22
|
-
* @returns {string[]} An array of database names.
|
|
23
23
|
*/
|
|
24
24
|
getCollections(): string[];
|
|
25
25
|
/**
|
|
26
26
|
* Check and create the specified collection if it doesn't exist.
|
|
27
|
-
* @function
|
|
28
|
-
* @param {string} collection - The collection to check.
|
|
29
27
|
*/
|
|
30
28
|
checkCollection(collection: string): void;
|
|
31
29
|
/**
|
|
32
30
|
* Check if a collection exists.
|
|
33
|
-
* @function
|
|
34
|
-
* @param {string} collection - The name of the collection.
|
|
35
|
-
* @returns {boolean} True if the collection exists, false otherwise.
|
|
36
31
|
*/
|
|
37
32
|
issetCollection(collection: string): boolean;
|
|
38
33
|
/**
|
|
@@ -42,27 +37,27 @@ declare class dbActionC {
|
|
|
42
37
|
/**
|
|
43
38
|
* Find entries in the specified database based on search criteria.
|
|
44
39
|
*/
|
|
45
|
-
find(collection: string, arg:
|
|
40
|
+
find(collection: string, arg: Search, context?: Context, options?: DbFindOpts, findOpts?: FindOpts): Promise<any[]>;
|
|
46
41
|
/**
|
|
47
42
|
* Find the first matching entry in the specified database based on search criteria.
|
|
48
43
|
*/
|
|
49
|
-
findOne(collection: string, arg:
|
|
44
|
+
findOne(collection: string, arg: SearchOptions, context?: Context, findOpts?: FindOpts): Promise<Data>;
|
|
50
45
|
/**
|
|
51
46
|
* Update entries in the specified database based on search criteria and an updater function or object.
|
|
52
47
|
*/
|
|
53
|
-
update(collection: string, arg:
|
|
48
|
+
update(collection: string, arg: Search, updater: Updater, context?: {}): Promise<boolean>;
|
|
54
49
|
/**
|
|
55
50
|
* Update the first matching entry in the specified database based on search criteria and an updater function or object.
|
|
56
51
|
*/
|
|
57
|
-
updateOne(collection: string, arg:
|
|
52
|
+
updateOne(collection: string, arg: Search, updater: Updater, context?: Context): Promise<boolean>;
|
|
58
53
|
/**
|
|
59
54
|
* Remove entries from the specified database based on search criteria.
|
|
60
55
|
*/
|
|
61
|
-
remove(collection: string, arg:
|
|
56
|
+
remove(collection: string, arg: Search, context?: Context): Promise<boolean>;
|
|
62
57
|
/**
|
|
63
58
|
* Remove the first matching entry from the specified database based on search criteria.
|
|
64
59
|
*/
|
|
65
|
-
removeOne(collection: string, arg:
|
|
60
|
+
removeOne(collection: string, arg: Search, context?: Context): Promise<boolean>;
|
|
66
61
|
/**
|
|
67
62
|
* Removes a database collection from the file system.
|
|
68
63
|
*/
|
package/dist/cjs/action.js
CHANGED
|
@@ -17,8 +17,8 @@ class dbActionC {
|
|
|
17
17
|
/**
|
|
18
18
|
* Creates a new instance of dbActionC.
|
|
19
19
|
* @constructor
|
|
20
|
-
* @param
|
|
21
|
-
* @param
|
|
20
|
+
* @param folder - The folder where database files are stored.
|
|
21
|
+
* @param options - The options object.
|
|
22
22
|
*/
|
|
23
23
|
constructor(folder, options) {
|
|
24
24
|
this.folder = folder;
|
|
@@ -34,7 +34,6 @@ class dbActionC {
|
|
|
34
34
|
}
|
|
35
35
|
/**
|
|
36
36
|
* Get a list of available databases in the specified folder.
|
|
37
|
-
* @returns {string[]} An array of database names.
|
|
38
37
|
*/
|
|
39
38
|
getCollections() {
|
|
40
39
|
const collections = (0, fs_1.readdirSync)(this.folder, { recursive: true, withFileTypes: true })
|
|
@@ -48,8 +47,6 @@ class dbActionC {
|
|
|
48
47
|
}
|
|
49
48
|
/**
|
|
50
49
|
* Check and create the specified collection if it doesn't exist.
|
|
51
|
-
* @function
|
|
52
|
-
* @param {string} collection - The collection to check.
|
|
53
50
|
*/
|
|
54
51
|
checkCollection(collection) {
|
|
55
52
|
const cpath = this._getCollectionPath(collection);
|
|
@@ -58,9 +55,6 @@ class dbActionC {
|
|
|
58
55
|
}
|
|
59
56
|
/**
|
|
60
57
|
* Check if a collection exists.
|
|
61
|
-
* @function
|
|
62
|
-
* @param {string} collection - The name of the collection.
|
|
63
|
-
* @returns {boolean} True if the collection exists, false otherwise.
|
|
64
58
|
*/
|
|
65
59
|
issetCollection(collection) {
|
|
66
60
|
const path = this.folder + "/" + collection;
|
|
@@ -129,16 +123,16 @@ class dbActionC {
|
|
|
129
123
|
/**
|
|
130
124
|
* Update entries in the specified database based on search criteria and an updater function or object.
|
|
131
125
|
*/
|
|
132
|
-
async update(collection, arg,
|
|
126
|
+
async update(collection, arg, updater, context = {}) {
|
|
133
127
|
this.checkCollection(collection);
|
|
134
|
-
return await (0, index_js_1.update)(this._getCollectionPath(collection), arg,
|
|
128
|
+
return await (0, index_js_1.update)(this._getCollectionPath(collection), arg, updater, context);
|
|
135
129
|
}
|
|
136
130
|
/**
|
|
137
131
|
* Update the first matching entry in the specified database based on search criteria and an updater function or object.
|
|
138
132
|
*/
|
|
139
|
-
async updateOne(collection, arg,
|
|
133
|
+
async updateOne(collection, arg, updater, context = {}) {
|
|
140
134
|
this.checkCollection(collection);
|
|
141
|
-
return await (0, index_js_1.update)(this._getCollectionPath(collection), arg,
|
|
135
|
+
return await (0, index_js_1.update)(this._getCollectionPath(collection), arg, updater, context, true);
|
|
142
136
|
}
|
|
143
137
|
/**
|
|
144
138
|
* Remove entries from the specified database based on search criteria.
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import CollectionManager from "../CollectionManager.js";
|
|
2
|
+
import { Remote, RequestData } from "./remote.js";
|
|
3
|
+
import { Arg, Search, Updater } from "../types/arg";
|
|
4
|
+
import { DbFindOpts, FindOpts } from "../types/options.js";
|
|
5
|
+
import { Context } from "../types/types";
|
|
6
|
+
import Data from "../types/data.js";
|
|
7
|
+
/**
|
|
8
|
+
* Represents a database management class for performing CRUD operations.
|
|
9
|
+
* Uses a remote database.
|
|
10
|
+
* @class
|
|
11
|
+
*/
|
|
12
|
+
declare class DataBaseRemote {
|
|
13
|
+
remote: Remote;
|
|
14
|
+
constructor(remote: Remote);
|
|
15
|
+
/**
|
|
16
|
+
* Make a request to the remote database.
|
|
17
|
+
*/
|
|
18
|
+
_request<T>(type: string, data: RequestData): Promise<T>;
|
|
19
|
+
/**
|
|
20
|
+
* Create a new instance of a CollectionManager class.
|
|
21
|
+
*/
|
|
22
|
+
c(collection: string): CollectionManager;
|
|
23
|
+
/**
|
|
24
|
+
* Get the names of all available databases.
|
|
25
|
+
*/
|
|
26
|
+
getCollections(): Promise<string[]>;
|
|
27
|
+
/**
|
|
28
|
+
* Check and create the specified collection if it doesn't exist.
|
|
29
|
+
*/
|
|
30
|
+
checkCollection(collection: string): Promise<boolean>;
|
|
31
|
+
/**
|
|
32
|
+
* Check if a collection exists.
|
|
33
|
+
*/
|
|
34
|
+
issetCollection(collection: string): Promise<boolean>;
|
|
35
|
+
/**
|
|
36
|
+
* Add data to a database.
|
|
37
|
+
*/
|
|
38
|
+
add<T = Data>(collection: string, data: Arg, id_gen?: boolean): Promise<T>;
|
|
39
|
+
/**
|
|
40
|
+
* Find data in a database.
|
|
41
|
+
*/
|
|
42
|
+
find<T = Data>(collection: string, search: Search, context?: Context, options?: DbFindOpts, findOpts?: FindOpts): Promise<T[]>;
|
|
43
|
+
/**
|
|
44
|
+
* Find one data entry in a database.
|
|
45
|
+
*/
|
|
46
|
+
findOne<T = Data>(collection: string, search: Search, context?: Context, findOpts?: FindOpts): Promise<T>;
|
|
47
|
+
/**
|
|
48
|
+
* Update data in a database.
|
|
49
|
+
*/
|
|
50
|
+
update(collection: string, search: Search, updater: Updater, context?: Context): Promise<boolean>;
|
|
51
|
+
/**
|
|
52
|
+
* Update one data entry in a database.
|
|
53
|
+
*/
|
|
54
|
+
updateOne(collection: string, search: Search, updater: Updater, context?: Context): Promise<boolean>;
|
|
55
|
+
/**
|
|
56
|
+
* Remove data from a database.
|
|
57
|
+
*/
|
|
58
|
+
remove(collection: string, search: Search, context?: Context): Promise<boolean>;
|
|
59
|
+
/**
|
|
60
|
+
* Remove one data entry from a database.
|
|
61
|
+
*/
|
|
62
|
+
removeOne(collection: string, search: Search, context?: Context): Promise<boolean>;
|
|
63
|
+
/**
|
|
64
|
+
* Asynchronously updates one entry in a database or adds a new one if it doesn't exist.
|
|
65
|
+
*/
|
|
66
|
+
updateOneOrAdd(collection: string, search: Search, arg: Search, add_arg?: Arg, context?: Context, id_gen?: boolean): Promise<boolean>;
|
|
67
|
+
/**
|
|
68
|
+
* Removes a database collection from the file system.
|
|
69
|
+
*/
|
|
70
|
+
removeCollection(name: string): Promise<boolean>;
|
|
71
|
+
}
|
|
72
|
+
export default DataBaseRemote;
|
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const got_1 = __importDefault(require("got"));
|
|
7
|
-
const CollectionManager_js_1 = __importDefault(require("
|
|
7
|
+
const CollectionManager_js_1 = __importDefault(require("../CollectionManager.js"));
|
|
8
8
|
const function_js_1 = __importDefault(require("./function.js"));
|
|
9
9
|
/**
|
|
10
10
|
* Represents a database management class for performing CRUD operations.
|
|
@@ -21,10 +21,10 @@ class DataBaseRemote {
|
|
|
21
21
|
*/
|
|
22
22
|
async _request(type, data) {
|
|
23
23
|
data.db = this.remote.name;
|
|
24
|
-
const
|
|
24
|
+
const processed = (0, function_js_1.default)(data);
|
|
25
25
|
data = {
|
|
26
|
-
keys:
|
|
27
|
-
...
|
|
26
|
+
keys: processed.keys,
|
|
27
|
+
...processed.data
|
|
28
28
|
};
|
|
29
29
|
const res = await got_1.default.post(this.remote.url + "/db/database/" + type, {
|
|
30
30
|
// @ts-ignore: Some jerk can't do the types correctly.
|
|
@@ -100,17 +100,17 @@ class DataBaseRemote {
|
|
|
100
100
|
/**
|
|
101
101
|
* Update data in a database.
|
|
102
102
|
*/
|
|
103
|
-
async update(collection, search,
|
|
103
|
+
async update(collection, search, updater, context = {}) {
|
|
104
104
|
const searchStr = typeof search === "function" ? search.toString() : search;
|
|
105
|
-
const argStr = typeof
|
|
105
|
+
const argStr = typeof updater === "function" ? updater.toString() : updater;
|
|
106
106
|
return await this._request("update", { collection, search: searchStr, arg: argStr, context });
|
|
107
107
|
}
|
|
108
108
|
/**
|
|
109
109
|
* Update one data entry in a database.
|
|
110
110
|
*/
|
|
111
|
-
async updateOne(collection, search,
|
|
111
|
+
async updateOne(collection, search, updater, context = {}) {
|
|
112
112
|
const searchStr = typeof search === "function" ? search.toString() : search;
|
|
113
|
-
const argStr = typeof
|
|
113
|
+
const argStr = typeof updater === "function" ? updater.toString() : updater;
|
|
114
114
|
return await this._request("updateOne", { collection, search: searchStr, arg: argStr, context });
|
|
115
115
|
}
|
|
116
116
|
/**
|
|
@@ -138,8 +138,8 @@ class DataBaseRemote {
|
|
|
138
138
|
/**
|
|
139
139
|
* Removes a database collection from the file system.
|
|
140
140
|
*/
|
|
141
|
-
removeCollection(name) {
|
|
142
|
-
return this._request("removeCollection", { name });
|
|
141
|
+
async removeCollection(name) {
|
|
142
|
+
return await this._request("removeCollection", { name });
|
|
143
143
|
}
|
|
144
144
|
}
|
|
145
145
|
exports.default = DataBaseRemote;
|
package/dist/cjs/database.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import dbActionC from "./action.js";
|
|
|
2
2
|
import executorC from "./executor.js";
|
|
3
3
|
import CollectionManager from "./CollectionManager.js";
|
|
4
4
|
import { DbFindOpts, DbOpts, FindOpts } from "./types/options.js";
|
|
5
|
-
import { Arg,
|
|
5
|
+
import { Arg, Search, Updater } from "./types/arg.js";
|
|
6
6
|
import Data from "./types/data.js";
|
|
7
7
|
import { Context } from "./types/types.js";
|
|
8
8
|
/**
|
|
@@ -32,46 +32,38 @@ declare class DataBase {
|
|
|
32
32
|
/**
|
|
33
33
|
* Add data to a database.
|
|
34
34
|
*/
|
|
35
|
-
add(collection: string, data: Arg, id_gen?: boolean): Promise<
|
|
35
|
+
add<T = Data>(collection: string, data: Arg, id_gen?: boolean): Promise<T>;
|
|
36
36
|
/**
|
|
37
37
|
* Find data in a database.
|
|
38
38
|
*/
|
|
39
|
-
find(collection: string, search:
|
|
39
|
+
find<T = Data>(collection: string, search: Search, context?: Context, options?: DbFindOpts, findOpts?: FindOpts): Promise<T[]>;
|
|
40
40
|
/**
|
|
41
41
|
* Find one data entry in a database.
|
|
42
|
-
*
|
|
43
|
-
* @async
|
|
44
|
-
* @function
|
|
45
|
-
* @param {string} collection - Name of the database collection.
|
|
46
|
-
* @param {function|Object} search - The query. It can be an object or a function.
|
|
47
|
-
* @param {Object} context - The context object (for functions).
|
|
48
|
-
* @param {Object} findOpts - Update result object with findOpts options.
|
|
49
|
-
* @returns {Promise<Object|null>} A Promise that resolves with the first matching data entry.
|
|
50
42
|
*/
|
|
51
|
-
findOne(collection: string, search:
|
|
43
|
+
findOne<T = Data>(collection: string, search: Search, context?: Context, findOpts?: FindOpts): Promise<T>;
|
|
52
44
|
/**
|
|
53
45
|
* Update data in a database.
|
|
54
46
|
*/
|
|
55
|
-
update(collection: string, search:
|
|
47
|
+
update(collection: string, search: Search, updater: Updater, context?: {}): Promise<boolean>;
|
|
56
48
|
/**
|
|
57
49
|
* Update one data entry in a database.
|
|
58
50
|
*/
|
|
59
|
-
updateOne(collection: string, search:
|
|
51
|
+
updateOne(collection: string, search: Search, updater: Updater, context?: Context): Promise<boolean>;
|
|
60
52
|
/**
|
|
61
53
|
* Remove data from a database.
|
|
62
54
|
*/
|
|
63
|
-
remove(collection: string, search:
|
|
55
|
+
remove(collection: string, search: Search, context?: Context): Promise<boolean>;
|
|
64
56
|
/**
|
|
65
57
|
* Remove one data entry from a database.
|
|
66
58
|
*/
|
|
67
|
-
removeOne(collection: string, search:
|
|
59
|
+
removeOne(collection: string, search: Search, context?: Context): Promise<boolean>;
|
|
68
60
|
/**
|
|
69
61
|
* Asynchronously updates one entry in a database or adds a new one if it doesn't exist.
|
|
70
62
|
*/
|
|
71
|
-
updateOneOrAdd(collection: string, search:
|
|
63
|
+
updateOneOrAdd(collection: string, search: Search, updater: Updater, add_arg?: Arg, context?: Context, id_gen?: boolean): Promise<boolean>;
|
|
72
64
|
/**
|
|
73
65
|
* Removes a database collection from the file system.
|
|
74
66
|
*/
|
|
75
|
-
removeCollection(collection: string): void
|
|
67
|
+
removeCollection(collection: string): Promise<void>;
|
|
76
68
|
}
|
|
77
69
|
export default DataBase;
|
package/dist/cjs/database.js
CHANGED
|
@@ -55,14 +55,6 @@ class DataBase {
|
|
|
55
55
|
}
|
|
56
56
|
/**
|
|
57
57
|
* Find one data entry in a database.
|
|
58
|
-
*
|
|
59
|
-
* @async
|
|
60
|
-
* @function
|
|
61
|
-
* @param {string} collection - Name of the database collection.
|
|
62
|
-
* @param {function|Object} search - The query. It can be an object or a function.
|
|
63
|
-
* @param {Object} context - The context object (for functions).
|
|
64
|
-
* @param {Object} findOpts - Update result object with findOpts options.
|
|
65
|
-
* @returns {Promise<Object|null>} A Promise that resolves with the first matching data entry.
|
|
66
58
|
*/
|
|
67
59
|
async findOne(collection, search, context = {}, findOpts = {}) {
|
|
68
60
|
return await this.executor.addOp(this.dbAction.findOne.bind(this.dbAction), collection, search, context, findOpts);
|
|
@@ -70,14 +62,14 @@ class DataBase {
|
|
|
70
62
|
/**
|
|
71
63
|
* Update data in a database.
|
|
72
64
|
*/
|
|
73
|
-
async update(collection, search,
|
|
74
|
-
return await this.executor.addOp(this.dbAction.update.bind(this.dbAction), collection, search,
|
|
65
|
+
async update(collection, search, updater, context = {}) {
|
|
66
|
+
return await this.executor.addOp(this.dbAction.update.bind(this.dbAction), collection, search, updater, context);
|
|
75
67
|
}
|
|
76
68
|
/**
|
|
77
69
|
* Update one data entry in a database.
|
|
78
70
|
*/
|
|
79
|
-
async updateOne(collection, search,
|
|
80
|
-
return await this.executor.addOp(this.dbAction.updateOne.bind(this.dbAction), collection, search,
|
|
71
|
+
async updateOne(collection, search, updater, context = {}) {
|
|
72
|
+
return await this.executor.addOp(this.dbAction.updateOne.bind(this.dbAction), collection, search, updater, context);
|
|
81
73
|
}
|
|
82
74
|
/**
|
|
83
75
|
* Remove data from a database.
|
|
@@ -94,14 +86,14 @@ class DataBase {
|
|
|
94
86
|
/**
|
|
95
87
|
* Asynchronously updates one entry in a database or adds a new one if it doesn't exist.
|
|
96
88
|
*/
|
|
97
|
-
async updateOneOrAdd(collection, search,
|
|
98
|
-
const res = await this.updateOne(collection, search,
|
|
89
|
+
async updateOneOrAdd(collection, search, updater, add_arg = {}, context = {}, id_gen = true) {
|
|
90
|
+
const res = await this.updateOne(collection, search, updater, context);
|
|
99
91
|
if (!res) {
|
|
100
92
|
const assignData = [];
|
|
101
93
|
if (typeof search === "object" && !Array.isArray(search))
|
|
102
94
|
assignData.push(search);
|
|
103
|
-
if (typeof
|
|
104
|
-
assignData.push(
|
|
95
|
+
if (typeof updater === "object" && !Array.isArray(updater))
|
|
96
|
+
assignData.push(updater);
|
|
105
97
|
if (typeof add_arg === "object" && !Array.isArray(add_arg))
|
|
106
98
|
assignData.push(add_arg);
|
|
107
99
|
await this.add(collection, Object.assign({}, ...assignData), id_gen);
|
|
@@ -111,7 +103,7 @@ class DataBase {
|
|
|
111
103
|
/**
|
|
112
104
|
* Removes a database collection from the file system.
|
|
113
105
|
*/
|
|
114
|
-
removeCollection(collection) {
|
|
106
|
+
async removeCollection(collection) {
|
|
115
107
|
this.dbAction.removeCollection(collection);
|
|
116
108
|
}
|
|
117
109
|
}
|
package/dist/cjs/file/find.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Search } from "../types/arg.js";
|
|
2
2
|
import { Context } from "../types/types.js";
|
|
3
3
|
import { FindOpts } from "../types/options.js";
|
|
4
4
|
/**
|
|
5
5
|
* Asynchronously finds entries in a file based on search criteria.
|
|
6
6
|
*/
|
|
7
|
-
export declare function find(file: string, arg:
|
|
7
|
+
export declare function find(file: string, arg: Search, context?: Context, findOpts?: FindOpts): Promise<unknown>;
|
|
8
8
|
/**
|
|
9
9
|
* Asynchronously finds one entry in a file based on search criteria.
|
|
10
10
|
*/
|
|
11
|
-
export declare function findOne(file: string, arg:
|
|
11
|
+
export declare function findOne(file: string, arg: Search, context?: Context, findOpts?: FindOpts): Promise<unknown>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Search } from "../types/arg.js";
|
|
2
2
|
import { Context } from "../types/types.js";
|
|
3
3
|
/**
|
|
4
4
|
* Asynchronously removes entries from a file based on search criteria.
|
|
5
5
|
*/
|
|
6
|
-
declare function remove(cpath: string, arg:
|
|
6
|
+
declare function remove(cpath: string, arg: Search, context?: Context, one?: boolean): Promise<boolean>;
|
|
7
7
|
export default remove;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Context } from "../types/types.js";
|
|
2
|
-
import {
|
|
2
|
+
import { Search, Updater } from "../types/arg.js";
|
|
3
3
|
/**
|
|
4
4
|
* Asynchronously updates entries in a file based on search criteria and an updater function or object.
|
|
5
5
|
*/
|
|
6
|
-
declare function update(cpath: string, arg:
|
|
6
|
+
declare function update(cpath: string, arg: Search, updater: Updater, context?: Context, one?: boolean): Promise<boolean>;
|
|
7
7
|
export default update;
|
package/dist/cjs/file/update.js
CHANGED
|
@@ -23,7 +23,7 @@ async function updateWorker(file, search, updater, context = {}, one = false) {
|
|
|
23
23
|
let updated = false;
|
|
24
24
|
for await (let line of rl) {
|
|
25
25
|
if (one && updated) {
|
|
26
|
-
|
|
26
|
+
await fs_1.promises.appendFile(file, line + "\n");
|
|
27
27
|
continue;
|
|
28
28
|
}
|
|
29
29
|
const data = (0, format_js_1.parse)(line);
|
|
@@ -35,9 +35,11 @@ async function updateWorker(file, search, updater, context = {}, one = false) {
|
|
|
35
35
|
ob = (0, hasFieldsAdvanced_js_1.default)(data, search);
|
|
36
36
|
}
|
|
37
37
|
if (ob) {
|
|
38
|
-
let updateObj;
|
|
38
|
+
let updateObj = data;
|
|
39
39
|
if (typeof updater === "function") {
|
|
40
|
-
|
|
40
|
+
const updateObjValue = updater(data, context);
|
|
41
|
+
if (updateObjValue)
|
|
42
|
+
updateObj = updateObjValue;
|
|
41
43
|
}
|
|
42
44
|
else if (typeof updater === "object" && !Array.isArray(updater)) {
|
|
43
45
|
updateObj = (0, updateObject_js_1.default)(data, updater);
|
|
@@ -45,7 +47,7 @@ async function updateWorker(file, search, updater, context = {}, one = false) {
|
|
|
45
47
|
line = await (0, format_js_1.stringify)(updateObj);
|
|
46
48
|
updated = true;
|
|
47
49
|
}
|
|
48
|
-
|
|
50
|
+
await fs_1.promises.appendFile(file, line + "\n");
|
|
49
51
|
}
|
|
50
52
|
await fs_1.promises.writeFile(file + ".tmp", "");
|
|
51
53
|
return updated;
|
|
@@ -53,12 +55,12 @@ async function updateWorker(file, search, updater, context = {}, one = false) {
|
|
|
53
55
|
/**
|
|
54
56
|
* Asynchronously updates entries in a file based on search criteria and an updater function or object.
|
|
55
57
|
*/
|
|
56
|
-
async function update(cpath, arg,
|
|
58
|
+
async function update(cpath, arg, updater, context = {}, one = false) {
|
|
57
59
|
let files = (0, fs_1.readdirSync)(cpath).filter(file => !/\.tmp$/.test(file));
|
|
58
60
|
files.reverse();
|
|
59
61
|
let update = false;
|
|
60
62
|
for (const file of files) {
|
|
61
|
-
const updated = await updateWorker(cpath + file, arg,
|
|
63
|
+
const updated = await updateWorker(cpath + file, arg, updater, context, one);
|
|
62
64
|
if (one && updated)
|
|
63
65
|
return true;
|
|
64
66
|
update = update || updated;
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import DataBase from "./database.js";
|
|
2
2
|
import Graph from "./graph.js";
|
|
3
|
-
import DataBaseRemote from "./
|
|
4
|
-
import GraphRemote from "./
|
|
3
|
+
import DataBaseRemote from "./client/database.js";
|
|
4
|
+
import GraphRemote from "./client/graph.js";
|
|
5
5
|
import genId from "./gen.js";
|
|
6
6
|
import Relation from "./relation.js";
|
|
7
7
|
export { DataBase, Graph, DataBaseRemote, GraphRemote, Relation, genId };
|
|
8
|
+
import type Id from "./types/Id.js";
|
|
9
|
+
import type { Arg, Search, Updater } from "./types/arg.js";
|
|
10
|
+
import type { DbFindOpts, FindOpts, DbOpts } from "./types/options.js";
|
|
11
|
+
import type Data from "./types/data.js";
|
|
12
|
+
import type { SearchOptions } from "./types/searchOpts.js";
|
|
13
|
+
export type { Id, Arg, Search, Updater, DbFindOpts, FindOpts, DbOpts, Data, SearchOptions };
|
package/dist/cjs/index.js
CHANGED
|
@@ -8,9 +8,9 @@ const database_js_1 = __importDefault(require("./database.js"));
|
|
|
8
8
|
exports.DataBase = database_js_1.default;
|
|
9
9
|
const graph_js_1 = __importDefault(require("./graph.js"));
|
|
10
10
|
exports.Graph = graph_js_1.default;
|
|
11
|
-
const database_js_2 = __importDefault(require("./
|
|
11
|
+
const database_js_2 = __importDefault(require("./client/database.js"));
|
|
12
12
|
exports.DataBaseRemote = database_js_2.default;
|
|
13
|
-
const graph_js_2 = __importDefault(require("./
|
|
13
|
+
const graph_js_2 = __importDefault(require("./client/graph.js"));
|
|
14
14
|
exports.GraphRemote = graph_js_2.default;
|
|
15
15
|
const gen_js_1 = __importDefault(require("./gen.js"));
|
|
16
16
|
exports.genId = gen_js_1.default;
|
package/dist/cjs/relation.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import DataBase from "./database.js";
|
|
2
|
-
import {
|
|
2
|
+
import { Search } from "./types/arg.js";
|
|
3
3
|
import { DbFindOpts } from "./types/options.js";
|
|
4
4
|
export interface Databases {
|
|
5
5
|
[key: string]: DataBase;
|
|
@@ -36,7 +36,7 @@ declare class Relation {
|
|
|
36
36
|
* @param relations - Relations configuration
|
|
37
37
|
* @param options - Search options
|
|
38
38
|
*/
|
|
39
|
-
find(path: string, search:
|
|
39
|
+
find(path: string, search: Search, relations?: {}, options?: DbFindOpts): Promise<{
|
|
40
40
|
constructor: Function;
|
|
41
41
|
toString(): string;
|
|
42
42
|
toLocaleString(): string;
|
|
@@ -51,7 +51,7 @@ declare class Relation {
|
|
|
51
51
|
* @param search - Search query or function
|
|
52
52
|
* @param relations - Relations configuration
|
|
53
53
|
*/
|
|
54
|
-
findOne(path: string, search:
|
|
54
|
+
findOne(path: string, search: Search, relations?: Object): Promise<{
|
|
55
55
|
constructor: Function;
|
|
56
56
|
toString(): string;
|
|
57
57
|
toLocaleString(): string;
|
package/dist/cjs/types/arg.d.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import Id from "./Id";
|
|
2
|
+
import { SearchOptions } from "./searchOpts";
|
|
3
|
+
import { Context } from "./types";
|
|
4
|
+
import { UpdaterArg } from "./updater";
|
|
2
5
|
export interface Arg {
|
|
3
6
|
_id?: Id;
|
|
4
7
|
[key: string]: any;
|
|
5
8
|
}
|
|
6
|
-
export type
|
|
9
|
+
export type SearchFunc<T = any> = (data: T, context: Context) => boolean;
|
|
10
|
+
export type UpdaterFunc<T = any> = (data: T, context: Context) => boolean;
|
|
11
|
+
export type Search<T = any> = SearchOptions | SearchFunc<T>;
|
|
12
|
+
export type Updater<T = any> = UpdaterArg | UpdaterArg[] | UpdaterFunc<T>;
|