@wxn0brp/db 0.0.7 → 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/cjs/CollectionManager.d.ts +1 -1
- package/dist/cjs/CollectionManager.js +2 -2
- package/dist/cjs/action.d.ts +1 -1
- package/dist/cjs/action.js +11 -11
- package/dist/cjs/client/database.d.ts +4 -4
- package/dist/cjs/client/database.js +29 -55
- package/dist/cjs/client/graph.d.ts +2 -2
- package/dist/cjs/client/graph.js +22 -21
- package/dist/cjs/client/remote.d.ts +1 -2
- package/dist/cjs/database.js +6 -6
- package/dist/cjs/file/find.js +11 -11
- package/dist/cjs/file/index.js +4 -4
- package/dist/cjs/file/remove.js +7 -7
- package/dist/cjs/file/update.js +10 -10
- package/dist/cjs/format.d.ts +1 -7
- package/dist/cjs/format.js +0 -6
- package/dist/cjs/gen.d.ts +6 -3
- package/dist/cjs/gen.js +111 -52
- package/dist/cjs/graph.js +2 -2
- package/dist/cjs/index.js +12 -12
- package/dist/cjs/relation.d.ts +17 -47
- package/dist/cjs/relation.js +31 -34
- package/dist/cjs/types/arg.d.ts +7 -7
- package/dist/cjs/types/searchOpts.d.ts +5 -4
- package/dist/cjs/types/types.d.ts +1 -0
- package/dist/cjs/utils/hasFields.d.ts +4 -5
- package/dist/cjs/utils/hasFields.js +3 -4
- package/dist/cjs/utils/hasFieldsAdvanced.d.ts +1 -1
- package/dist/cjs/utils/hasFieldsAdvanced.js +3 -3
- package/dist/cjs/utils/updateFindObject.d.ts +8 -8
- package/dist/cjs/utils/updateFindObject.js +6 -7
- package/dist/cjs/utils/updateObject.d.ts +1 -1
- package/dist/esm/CollectionManager.d.ts +1 -1
- package/dist/esm/CollectionManager.js +2 -2
- package/dist/esm/action.d.ts +1 -1
- package/dist/esm/action.js +1 -1
- package/dist/esm/client/database.d.ts +4 -4
- package/dist/esm/client/database.js +26 -52
- package/dist/esm/client/graph.d.ts +2 -2
- package/dist/esm/client/graph.js +22 -21
- package/dist/esm/client/remote.d.ts +1 -2
- package/dist/esm/format.d.ts +1 -7
- package/dist/esm/format.js +0 -6
- package/dist/esm/gen.d.ts +6 -3
- package/dist/esm/gen.js +111 -52
- package/dist/esm/relation.d.ts +17 -47
- package/dist/esm/relation.js +31 -34
- package/dist/esm/types/arg.d.ts +7 -7
- package/dist/esm/types/searchOpts.d.ts +5 -4
- package/dist/esm/types/types.d.ts +1 -0
- package/dist/esm/utils/hasFields.d.ts +4 -5
- package/dist/esm/utils/hasFields.js +3 -4
- package/dist/esm/utils/hasFieldsAdvanced.d.ts +1 -1
- package/dist/esm/utils/updateFindObject.d.ts +8 -8
- package/dist/esm/utils/updateFindObject.js +6 -7
- package/dist/esm/utils/updateObject.d.ts +1 -1
- package/package.json +5 -5
|
@@ -39,6 +39,6 @@ declare class CollectionManager {
|
|
|
39
39
|
/**
|
|
40
40
|
* Asynchronously updates one entry in a database or adds a new one if it doesn't exist.
|
|
41
41
|
*/
|
|
42
|
-
updateOneOrAdd(search: Search,
|
|
42
|
+
updateOneOrAdd(search: Search, updater: Updater, add_arg?: Arg, context?: Context, id_gen?: boolean): Promise<boolean>;
|
|
43
43
|
}
|
|
44
44
|
export default CollectionManager;
|
|
@@ -52,8 +52,8 @@ class CollectionManager {
|
|
|
52
52
|
/**
|
|
53
53
|
* Asynchronously updates one entry in a database or adds a new one if it doesn't exist.
|
|
54
54
|
*/
|
|
55
|
-
async updateOneOrAdd(search,
|
|
56
|
-
return await this.db.updateOneOrAdd(this.collection, search,
|
|
55
|
+
async updateOneOrAdd(search, updater, add_arg = {}, context = {}, id_gen = true) {
|
|
56
|
+
return await this.db.updateOneOrAdd(this.collection, search, updater, add_arg, context, id_gen);
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
exports.default = CollectionManager;
|
package/dist/cjs/action.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Arg, Search, Updater } from "./types/arg.js";
|
|
2
2
|
import { DbFindOpts, DbOpts, FindOpts } from "./types/options.js";
|
|
3
|
-
import { Context } from "./types/types";
|
|
3
|
+
import { Context } from "./types/types.js";
|
|
4
4
|
import { SearchOptions } from "./types/searchOpts.js";
|
|
5
5
|
import Data from "./types/data.js";
|
|
6
6
|
/**
|
package/dist/cjs/action.js
CHANGED
|
@@ -3,10 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const gen_1 = __importDefault(require("./gen.js"));
|
|
7
|
+
const format_1 = require("./format.js");
|
|
6
8
|
const fs_1 = require("fs");
|
|
7
|
-
const
|
|
8
|
-
const format_js_1 = require("./format.js");
|
|
9
|
-
const index_js_1 = require("./file/index.js");
|
|
9
|
+
const index_1 = require("./file/index.js");
|
|
10
10
|
/**
|
|
11
11
|
* A class representing database actions on files.
|
|
12
12
|
* @class
|
|
@@ -68,8 +68,8 @@ class dbActionC {
|
|
|
68
68
|
const cpath = this._getCollectionPath(collection);
|
|
69
69
|
const file = cpath + getLastFile(cpath, this.options.maxFileSize);
|
|
70
70
|
if (id_gen)
|
|
71
|
-
arg._id = arg._id || (0,
|
|
72
|
-
const data = (0,
|
|
71
|
+
arg._id = arg._id || (0, gen_1.default)();
|
|
72
|
+
const data = (0, format_1.stringify)(arg);
|
|
73
73
|
(0, fs_1.appendFileSync)(file, data + "\n");
|
|
74
74
|
return arg;
|
|
75
75
|
}
|
|
@@ -87,7 +87,7 @@ class dbActionC {
|
|
|
87
87
|
let datas = [];
|
|
88
88
|
let totalEntries = 0;
|
|
89
89
|
for (let f of files) {
|
|
90
|
-
let data = await (0,
|
|
90
|
+
let data = await (0, index_1.find)(cpath + f, arg, context, findOpts);
|
|
91
91
|
if (options.reverse)
|
|
92
92
|
data.reverse();
|
|
93
93
|
if (options.max !== -1) {
|
|
@@ -114,7 +114,7 @@ class dbActionC {
|
|
|
114
114
|
const cpath = this._getCollectionPath(collection);
|
|
115
115
|
const files = getSortedFiles(cpath).map(f => f.f);
|
|
116
116
|
for (let f of files) {
|
|
117
|
-
let data = await (0,
|
|
117
|
+
let data = await (0, index_1.findOne)(cpath + f, arg, context, findOpts);
|
|
118
118
|
if (data)
|
|
119
119
|
return data;
|
|
120
120
|
}
|
|
@@ -125,28 +125,28 @@ class dbActionC {
|
|
|
125
125
|
*/
|
|
126
126
|
async update(collection, arg, updater, context = {}) {
|
|
127
127
|
this.checkCollection(collection);
|
|
128
|
-
return await (0,
|
|
128
|
+
return await (0, index_1.update)(this._getCollectionPath(collection), arg, updater, context);
|
|
129
129
|
}
|
|
130
130
|
/**
|
|
131
131
|
* Update the first matching entry in the specified database based on search criteria and an updater function or object.
|
|
132
132
|
*/
|
|
133
133
|
async updateOne(collection, arg, updater, context = {}) {
|
|
134
134
|
this.checkCollection(collection);
|
|
135
|
-
return await (0,
|
|
135
|
+
return await (0, index_1.update)(this._getCollectionPath(collection), arg, updater, context, true);
|
|
136
136
|
}
|
|
137
137
|
/**
|
|
138
138
|
* Remove entries from the specified database based on search criteria.
|
|
139
139
|
*/
|
|
140
140
|
async remove(collection, arg, context = {}) {
|
|
141
141
|
this.checkCollection(collection);
|
|
142
|
-
return await (0,
|
|
142
|
+
return await (0, index_1.remove)(this._getCollectionPath(collection), arg, context);
|
|
143
143
|
}
|
|
144
144
|
/**
|
|
145
145
|
* Remove the first matching entry from the specified database based on search criteria.
|
|
146
146
|
*/
|
|
147
147
|
async removeOne(collection, arg, context = {}) {
|
|
148
148
|
this.checkCollection(collection);
|
|
149
|
-
return await (0,
|
|
149
|
+
return await (0, index_1.remove)(this._getCollectionPath(collection), arg, context, true);
|
|
150
150
|
}
|
|
151
151
|
/**
|
|
152
152
|
* Removes a database collection from the file system.
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import CollectionManager from "../CollectionManager.js";
|
|
2
|
-
import { Remote
|
|
3
|
-
import { Arg, Search, Updater } from "../types/arg";
|
|
2
|
+
import { Remote } from "./remote.js";
|
|
3
|
+
import { Arg, Search, Updater } from "../types/arg.js";
|
|
4
4
|
import { DbFindOpts, FindOpts } from "../types/options.js";
|
|
5
|
-
import { Context } from "../types/types";
|
|
5
|
+
import { Context } from "../types/types.js";
|
|
6
6
|
import Data from "../types/data.js";
|
|
7
7
|
/**
|
|
8
8
|
* Represents a database management class for performing CRUD operations.
|
|
@@ -15,7 +15,7 @@ declare class DataBaseRemote {
|
|
|
15
15
|
/**
|
|
16
16
|
* Make a request to the remote database.
|
|
17
17
|
*/
|
|
18
|
-
_request<T>(type: string,
|
|
18
|
+
_request<T>(type: string, params?: any[]): Promise<T>;
|
|
19
19
|
/**
|
|
20
20
|
* Create a new instance of a CollectionManager class.
|
|
21
21
|
*/
|
|
@@ -3,9 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
6
|
+
const ky_1 = __importDefault(require("ky"));
|
|
7
|
+
const CollectionManager_1 = __importDefault(require("../CollectionManager.js"));
|
|
8
|
+
const function_1 = __importDefault(require("./function.js"));
|
|
9
9
|
/**
|
|
10
10
|
* Represents a database management class for performing CRUD operations.
|
|
11
11
|
* Uses a remote database.
|
|
@@ -19,127 +19,101 @@ class DataBaseRemote {
|
|
|
19
19
|
/**
|
|
20
20
|
* Make a request to the remote database.
|
|
21
21
|
*/
|
|
22
|
-
async _request(type,
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
async _request(type, params = []) {
|
|
23
|
+
const processed = (0, function_1.default)(params);
|
|
24
|
+
const data = {
|
|
25
|
+
db: this.remote.name,
|
|
26
|
+
params: processed.data,
|
|
27
|
+
keys: processed.keys
|
|
28
28
|
};
|
|
29
|
-
const res = await
|
|
30
|
-
|
|
31
|
-
body: data,
|
|
29
|
+
const res = await ky_1.default.post(this.remote.url + "/db/" + type, {
|
|
30
|
+
json: data,
|
|
32
31
|
headers: {
|
|
33
32
|
"Authorization": this.remote.auth
|
|
34
33
|
},
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
return res.body.result;
|
|
34
|
+
throwHttpErrors: false
|
|
35
|
+
}).json();
|
|
36
|
+
if (res.err)
|
|
37
|
+
throw new Error(res.msg);
|
|
38
|
+
return res.result;
|
|
41
39
|
}
|
|
42
40
|
/**
|
|
43
41
|
* Create a new instance of a CollectionManager class.
|
|
44
42
|
*/
|
|
45
43
|
c(collection) {
|
|
46
|
-
return new
|
|
44
|
+
return new CollectionManager_1.default(this, collection);
|
|
47
45
|
}
|
|
48
46
|
/**
|
|
49
47
|
* Get the names of all available databases.
|
|
50
48
|
*/
|
|
51
49
|
async getCollections() {
|
|
52
|
-
return await this._request("getCollections",
|
|
50
|
+
return await this._request("getCollections", []);
|
|
53
51
|
}
|
|
54
52
|
/**
|
|
55
53
|
* Check and create the specified collection if it doesn't exist.
|
|
56
54
|
*/
|
|
57
55
|
async checkCollection(collection) {
|
|
58
|
-
return await this._request("checkCollection",
|
|
56
|
+
return await this._request("checkCollection", [collection]);
|
|
59
57
|
}
|
|
60
58
|
/**
|
|
61
59
|
* Check if a collection exists.
|
|
62
60
|
*/
|
|
63
61
|
async issetCollection(collection) {
|
|
64
|
-
return await this._request("issetCollection",
|
|
62
|
+
return await this._request("issetCollection", [collection]);
|
|
65
63
|
}
|
|
66
64
|
/**
|
|
67
65
|
* Add data to a database.
|
|
68
66
|
*/
|
|
69
67
|
async add(collection, data, id_gen = true) {
|
|
70
|
-
return await this._request("add",
|
|
68
|
+
return await this._request("add", [collection, data, id_gen]);
|
|
71
69
|
}
|
|
72
70
|
/**
|
|
73
71
|
* Find data in a database.
|
|
74
72
|
*/
|
|
75
73
|
async find(collection, search, context = {}, options = {}, findOpts = {}) {
|
|
76
|
-
|
|
77
|
-
const findOptsRemote = {};
|
|
78
|
-
if (findOpts.select)
|
|
79
|
-
findOptsRemote.select = findOpts.select;
|
|
80
|
-
if (findOpts.exclude)
|
|
81
|
-
findOptsRemote.exclude = findOpts.exclude;
|
|
82
|
-
if (findOpts.transform)
|
|
83
|
-
findOptsRemote.transform = findOpts.transform.toString();
|
|
84
|
-
return await this._request("find", { collection, search: searchStr, options, context, findOpts });
|
|
74
|
+
return await this._request("find", [collection, search, context, options, findOpts]);
|
|
85
75
|
}
|
|
86
76
|
/**
|
|
87
77
|
* Find one data entry in a database.
|
|
88
78
|
*/
|
|
89
79
|
async findOne(collection, search, context = {}, findOpts = {}) {
|
|
90
|
-
|
|
91
|
-
const findOptsRemote = {};
|
|
92
|
-
if (findOpts.select)
|
|
93
|
-
findOptsRemote.select = findOpts.select;
|
|
94
|
-
if (findOpts.exclude)
|
|
95
|
-
findOptsRemote.exclude = findOpts.exclude;
|
|
96
|
-
if (findOpts.transform)
|
|
97
|
-
findOptsRemote.transform = findOpts.transform.toString();
|
|
98
|
-
return await this._request("findOne", { collection, search: searchStr, context, findOpts });
|
|
80
|
+
return await this._request("findOne", [collection, search, context, findOpts]);
|
|
99
81
|
}
|
|
100
82
|
/**
|
|
101
83
|
* Update data in a database.
|
|
102
84
|
*/
|
|
103
85
|
async update(collection, search, updater, context = {}) {
|
|
104
|
-
|
|
105
|
-
const argStr = typeof updater === "function" ? updater.toString() : updater;
|
|
106
|
-
return await this._request("update", { collection, search: searchStr, arg: argStr, context });
|
|
86
|
+
return await this._request("update", [collection, search, updater, context]);
|
|
107
87
|
}
|
|
108
88
|
/**
|
|
109
89
|
* Update one data entry in a database.
|
|
110
90
|
*/
|
|
111
91
|
async updateOne(collection, search, updater, context = {}) {
|
|
112
|
-
|
|
113
|
-
const argStr = typeof updater === "function" ? updater.toString() : updater;
|
|
114
|
-
return await this._request("updateOne", { collection, search: searchStr, arg: argStr, context });
|
|
92
|
+
return await this._request("updateOne", [collection, search, updater, context]);
|
|
115
93
|
}
|
|
116
94
|
/**
|
|
117
95
|
* Remove data from a database.
|
|
118
96
|
*/
|
|
119
97
|
async remove(collection, search, context = {}) {
|
|
120
|
-
|
|
121
|
-
return await this._request("remove", { collection, search: searchStr, context });
|
|
98
|
+
return await this._request("remove", [collection, search, context]);
|
|
122
99
|
}
|
|
123
100
|
/**
|
|
124
101
|
* Remove one data entry from a database.
|
|
125
102
|
*/
|
|
126
103
|
async removeOne(collection, search, context = {}) {
|
|
127
|
-
|
|
128
|
-
return await this._request("removeOne", { collection, search: searchStr, context });
|
|
104
|
+
return await this._request("removeOne", [collection, search, context]);
|
|
129
105
|
}
|
|
130
106
|
/**
|
|
131
107
|
* Asynchronously updates one entry in a database or adds a new one if it doesn't exist.
|
|
132
108
|
*/
|
|
133
109
|
async updateOneOrAdd(collection, search, arg, add_arg = {}, context = {}, id_gen = true) {
|
|
134
|
-
|
|
135
|
-
const argStr = typeof arg === "function" ? arg.toString() : arg;
|
|
136
|
-
return await this._request("updateOneOrAdd", { collection, search: searchStr, arg: argStr, add_arg, id_gen, context });
|
|
110
|
+
return await this._request("updateOneOrAdd", [collection, search, arg, add_arg, id_gen, context]);
|
|
137
111
|
}
|
|
138
112
|
/**
|
|
139
113
|
* Removes a database collection from the file system.
|
|
140
114
|
*/
|
|
141
115
|
async removeCollection(name) {
|
|
142
|
-
return await this._request("removeCollection",
|
|
116
|
+
return await this._request("removeCollection", [name]);
|
|
143
117
|
}
|
|
144
118
|
}
|
|
145
119
|
exports.default = DataBaseRemote;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Remote
|
|
1
|
+
import { Remote } from "./remote.js";
|
|
2
2
|
/**
|
|
3
3
|
* A class representing a graph database.
|
|
4
4
|
* Uses a remote database.
|
|
@@ -13,7 +13,7 @@ declare class GraphRemote {
|
|
|
13
13
|
/**
|
|
14
14
|
* Make a request to the remote database.
|
|
15
15
|
*/
|
|
16
|
-
_request(type: string,
|
|
16
|
+
_request(type: string, params?: any[]): Promise<any>;
|
|
17
17
|
/**
|
|
18
18
|
* Adds an edge between two nodes.
|
|
19
19
|
*/
|
package/dist/cjs/client/graph.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const
|
|
6
|
+
const ky_1 = __importDefault(require("ky"));
|
|
7
7
|
/**
|
|
8
8
|
* A class representing a graph database.
|
|
9
9
|
* Uses a remote database.
|
|
@@ -20,74 +20,75 @@ class GraphRemote {
|
|
|
20
20
|
/**
|
|
21
21
|
* Make a request to the remote database.
|
|
22
22
|
*/
|
|
23
|
-
async _request(type,
|
|
24
|
-
data
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
async _request(type, params = []) {
|
|
24
|
+
const data = {
|
|
25
|
+
db: this.remote.name,
|
|
26
|
+
params
|
|
27
|
+
};
|
|
28
|
+
const res = await ky_1.default.post(this.remote.url + "/db/" + type, {
|
|
29
|
+
json: data,
|
|
28
30
|
headers: {
|
|
29
31
|
"Authorization": this.remote.auth
|
|
30
32
|
},
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return res.body.result;
|
|
33
|
+
throwHttpErrors: false
|
|
34
|
+
}).json();
|
|
35
|
+
if (res.err)
|
|
36
|
+
throw new Error(res.msg);
|
|
37
|
+
return res.result;
|
|
37
38
|
}
|
|
38
39
|
/**
|
|
39
40
|
* Adds an edge between two nodes.
|
|
40
41
|
*/
|
|
41
42
|
async add(collection, nodeA, nodeB) {
|
|
42
|
-
return await this._request("add",
|
|
43
|
+
return await this._request("add", [collection, nodeA, nodeB]);
|
|
43
44
|
}
|
|
44
45
|
/**
|
|
45
46
|
* Removes an edge between two nodes.
|
|
46
47
|
*/
|
|
47
48
|
async remove(collection, nodeA, nodeB) {
|
|
48
|
-
return await this._request("remove",
|
|
49
|
+
return await this._request("remove", [collection, nodeA, nodeB]);
|
|
49
50
|
}
|
|
50
51
|
/**
|
|
51
52
|
* Finds all edges with either node equal to `node`.
|
|
52
53
|
*/
|
|
53
54
|
async find(collection, node) {
|
|
54
|
-
return await this._request("find",
|
|
55
|
+
return await this._request("find", [collection, node]);
|
|
55
56
|
}
|
|
56
57
|
/**
|
|
57
58
|
* Finds one edge with either node equal to `nodeA` and the other equal to `nodeB`.
|
|
58
59
|
*/
|
|
59
60
|
async findOne(collection, nodeA, nodeB) {
|
|
60
|
-
return await this._request("findOne",
|
|
61
|
+
return await this._request("findOne", [collection, nodeA, nodeB]);
|
|
61
62
|
}
|
|
62
63
|
/**
|
|
63
64
|
* Get all edges in the collection.
|
|
64
65
|
*/
|
|
65
66
|
async getAll(collection) {
|
|
66
|
-
return await this._request("getAll",
|
|
67
|
+
return await this._request("getAll", [collection]);
|
|
67
68
|
}
|
|
68
69
|
/**
|
|
69
70
|
* Get the names of all available databases.
|
|
70
71
|
*/
|
|
71
72
|
async getCollections() {
|
|
72
|
-
return await this._request("getCollections",
|
|
73
|
+
return await this._request("getCollections", []);
|
|
73
74
|
}
|
|
74
75
|
/**
|
|
75
76
|
* Check and create the specified collection if it doesn't exist.
|
|
76
77
|
*/
|
|
77
78
|
async checkCollection(collection) {
|
|
78
|
-
return await this._request("checkCollection",
|
|
79
|
+
return await this._request("checkCollection", [collection]);
|
|
79
80
|
}
|
|
80
81
|
/**
|
|
81
82
|
* Check if a collection exists.
|
|
82
83
|
*/
|
|
83
84
|
async issetCollection(collection) {
|
|
84
|
-
return await this._request("issetCollection",
|
|
85
|
+
return await this._request("issetCollection", [collection]);
|
|
85
86
|
}
|
|
86
87
|
/**
|
|
87
88
|
* Remove the specified collection.
|
|
88
89
|
*/
|
|
89
90
|
removeCollection(collection) {
|
|
90
|
-
return this._request("removeCollection",
|
|
91
|
+
return this._request("removeCollection", [collection]);
|
|
91
92
|
}
|
|
92
93
|
}
|
|
93
94
|
exports.default = GraphRemote;
|
package/dist/cjs/database.js
CHANGED
|
@@ -3,9 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
6
|
+
const action_1 = __importDefault(require("./action.js"));
|
|
7
|
+
const executor_1 = __importDefault(require("./executor.js"));
|
|
8
|
+
const CollectionManager_1 = __importDefault(require("./CollectionManager.js"));
|
|
9
9
|
/**
|
|
10
10
|
* Represents a database management class for performing CRUD operations.
|
|
11
11
|
* @class
|
|
@@ -14,14 +14,14 @@ class DataBase {
|
|
|
14
14
|
dbAction;
|
|
15
15
|
executor;
|
|
16
16
|
constructor(folder, options = {}) {
|
|
17
|
-
this.dbAction = new
|
|
18
|
-
this.executor = new
|
|
17
|
+
this.dbAction = new action_1.default(folder, options);
|
|
18
|
+
this.executor = new executor_1.default();
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
21
|
* Create a new instance of a CollectionManager class.
|
|
22
22
|
*/
|
|
23
23
|
c(collection) {
|
|
24
|
-
return new
|
|
24
|
+
return new CollectionManager_1.default(this, collection);
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
27
27
|
* Get the names of all available databases.
|
package/dist/cjs/file/find.js
CHANGED
|
@@ -6,40 +6,40 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.find = find;
|
|
7
7
|
exports.findOne = findOne;
|
|
8
8
|
const fs_1 = require("fs");
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
9
|
+
const utils_1 = require("./utils.js");
|
|
10
|
+
const format_1 = require("../format.js");
|
|
11
|
+
const hasFieldsAdvanced_1 = __importDefault(require("../utils/hasFieldsAdvanced.js"));
|
|
12
|
+
const updateFindObject_1 = __importDefault(require("../utils/updateFindObject.js"));
|
|
13
13
|
/**
|
|
14
14
|
* Processes a line of text from a file and checks if it matches the search criteria.
|
|
15
15
|
*/
|
|
16
16
|
async function findProcesLine(arg, line, context = {}, findOpts = {}) {
|
|
17
|
-
const ob = (0,
|
|
17
|
+
const ob = (0, format_1.parse)(line);
|
|
18
18
|
let res = false;
|
|
19
19
|
if (typeof arg === "function") {
|
|
20
20
|
if (arg(ob, context))
|
|
21
21
|
res = true;
|
|
22
22
|
}
|
|
23
23
|
else if (typeof arg === "object" && !Array.isArray(arg)) {
|
|
24
|
-
if ((0,
|
|
24
|
+
if ((0, hasFieldsAdvanced_1.default)(ob, arg))
|
|
25
25
|
res = true;
|
|
26
26
|
}
|
|
27
27
|
if (res)
|
|
28
|
-
return (0,
|
|
28
|
+
return (0, updateFindObject_1.default)(ob, findOpts);
|
|
29
29
|
return null;
|
|
30
30
|
}
|
|
31
31
|
/**
|
|
32
32
|
* Asynchronously finds entries in a file based on search criteria.
|
|
33
33
|
*/
|
|
34
34
|
async function find(file, arg, context = {}, findOpts = {}) {
|
|
35
|
-
file = (0,
|
|
35
|
+
file = (0, utils_1.pathRepair)(file);
|
|
36
36
|
return await new Promise(async (resolve) => {
|
|
37
37
|
if (!(0, fs_1.existsSync)(file)) {
|
|
38
38
|
await fs_1.promises.writeFile(file, "");
|
|
39
39
|
resolve(false);
|
|
40
40
|
return;
|
|
41
41
|
}
|
|
42
|
-
const rl = (0,
|
|
42
|
+
const rl = (0, utils_1.createRL)(file);
|
|
43
43
|
const resF = [];
|
|
44
44
|
for await (const line of rl) {
|
|
45
45
|
if (line == "" || !line)
|
|
@@ -57,14 +57,14 @@ async function find(file, arg, context = {}, findOpts = {}) {
|
|
|
57
57
|
* Asynchronously finds one entry in a file based on search criteria.
|
|
58
58
|
*/
|
|
59
59
|
async function findOne(file, arg, context = {}, findOpts = {}) {
|
|
60
|
-
file = (0,
|
|
60
|
+
file = (0, utils_1.pathRepair)(file);
|
|
61
61
|
return await new Promise(async (resolve) => {
|
|
62
62
|
if (!(0, fs_1.existsSync)(file)) {
|
|
63
63
|
await fs_1.promises.writeFile(file, "");
|
|
64
64
|
resolve(false);
|
|
65
65
|
return;
|
|
66
66
|
}
|
|
67
|
-
const rl = (0,
|
|
67
|
+
const rl = (0, utils_1.createRL)(file);
|
|
68
68
|
for await (const line of rl) {
|
|
69
69
|
if (line == "" || !line)
|
|
70
70
|
continue;
|
package/dist/cjs/file/index.js
CHANGED
|
@@ -18,8 +18,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
20
|
exports.remove = exports.update = void 0;
|
|
21
|
-
var
|
|
22
|
-
Object.defineProperty(exports, "update", { enumerable: true, get: function () { return __importDefault(
|
|
23
|
-
var
|
|
24
|
-
Object.defineProperty(exports, "remove", { enumerable: true, get: function () { return __importDefault(
|
|
21
|
+
var update_1 = require("./update.js");
|
|
22
|
+
Object.defineProperty(exports, "update", { enumerable: true, get: function () { return __importDefault(update_1).default; } });
|
|
23
|
+
var remove_1 = require("./remove.js");
|
|
24
|
+
Object.defineProperty(exports, "remove", { enumerable: true, get: function () { return __importDefault(remove_1).default; } });
|
|
25
25
|
__exportStar(require("./find.js"), exports);
|
package/dist/cjs/file/remove.js
CHANGED
|
@@ -4,28 +4,28 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const fs_1 = require("fs");
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
7
|
+
const utils_1 = require("./utils.js");
|
|
8
|
+
const format_1 = require("../format.js");
|
|
9
|
+
const hasFieldsAdvanced_1 = __importDefault(require("../utils/hasFieldsAdvanced.js"));
|
|
10
10
|
/**
|
|
11
11
|
* Removes entries from a file based on search criteria.
|
|
12
12
|
*/
|
|
13
13
|
async function removeWorker(file, search, context = {}, one = false) {
|
|
14
|
-
file = (0,
|
|
14
|
+
file = (0, utils_1.pathRepair)(file);
|
|
15
15
|
if (!(0, fs_1.existsSync)(file)) {
|
|
16
16
|
await fs_1.promises.writeFile(file, "");
|
|
17
17
|
return false;
|
|
18
18
|
}
|
|
19
19
|
await fs_1.promises.copyFile(file, file + ".tmp");
|
|
20
20
|
await fs_1.promises.writeFile(file, "");
|
|
21
|
-
const rl = (0,
|
|
21
|
+
const rl = (0, utils_1.createRL)(file + ".tmp");
|
|
22
22
|
let removed = false;
|
|
23
23
|
for await (let line of rl) {
|
|
24
24
|
if (one && removed) {
|
|
25
25
|
(0, fs_1.appendFileSync)(file, line + "\n");
|
|
26
26
|
continue;
|
|
27
27
|
}
|
|
28
|
-
const data = (0,
|
|
28
|
+
const data = (0, format_1.parse)(line);
|
|
29
29
|
if (typeof search === "function") {
|
|
30
30
|
if (search(data, context)) {
|
|
31
31
|
removed = true;
|
|
@@ -33,7 +33,7 @@ async function removeWorker(file, search, context = {}, one = false) {
|
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
else if (typeof search === "object" && !Array.isArray(search)) {
|
|
36
|
-
if ((0,
|
|
36
|
+
if ((0, hasFieldsAdvanced_1.default)(data, search)) {
|
|
37
37
|
removed = true;
|
|
38
38
|
continue;
|
|
39
39
|
}
|
package/dist/cjs/file/update.js
CHANGED
|
@@ -4,35 +4,35 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const fs_1 = require("fs");
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
7
|
+
const utils_1 = require("./utils.js");
|
|
8
|
+
const format_1 = require("../format.js");
|
|
9
|
+
const hasFieldsAdvanced_1 = __importDefault(require("../utils/hasFieldsAdvanced.js"));
|
|
10
|
+
const updateObject_1 = __importDefault(require("../utils/updateObject.js"));
|
|
11
11
|
/**
|
|
12
12
|
* Updates a file based on search criteria and an updater function or object.
|
|
13
13
|
*/
|
|
14
14
|
async function updateWorker(file, search, updater, context = {}, one = false) {
|
|
15
|
-
file = (0,
|
|
15
|
+
file = (0, utils_1.pathRepair)(file);
|
|
16
16
|
if (!(0, fs_1.existsSync)(file)) {
|
|
17
17
|
await fs_1.promises.writeFile(file, "");
|
|
18
18
|
return false;
|
|
19
19
|
}
|
|
20
20
|
await fs_1.promises.copyFile(file, file + ".tmp");
|
|
21
21
|
await fs_1.promises.writeFile(file, "");
|
|
22
|
-
const rl = (0,
|
|
22
|
+
const rl = (0, utils_1.createRL)(file + ".tmp");
|
|
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
|
-
const data = (0,
|
|
29
|
+
const data = (0, format_1.parse)(line);
|
|
30
30
|
let ob = false;
|
|
31
31
|
if (typeof search === "function") {
|
|
32
32
|
ob = search(data, context) || false;
|
|
33
33
|
}
|
|
34
34
|
else if (typeof search === "object" && !Array.isArray(search)) {
|
|
35
|
-
ob = (0,
|
|
35
|
+
ob = (0, hasFieldsAdvanced_1.default)(data, search);
|
|
36
36
|
}
|
|
37
37
|
if (ob) {
|
|
38
38
|
let updateObj = data;
|
|
@@ -42,9 +42,9 @@ async function updateWorker(file, search, updater, context = {}, one = false) {
|
|
|
42
42
|
updateObj = updateObjValue;
|
|
43
43
|
}
|
|
44
44
|
else if (typeof updater === "object" && !Array.isArray(updater)) {
|
|
45
|
-
updateObj = (0,
|
|
45
|
+
updateObj = (0, updateObject_1.default)(data, updater);
|
|
46
46
|
}
|
|
47
|
-
line = await (0,
|
|
47
|
+
line = await (0, format_1.stringify)(updateObj);
|
|
48
48
|
updated = true;
|
|
49
49
|
}
|
|
50
50
|
await fs_1.promises.appendFile(file, line + "\n");
|