@wxn0brp/db 0.0.5 → 0.0.6
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 +3 -0
- package/dist/cjs/CollectionManager.d.ts +43 -0
- package/dist/cjs/CollectionManager.js +59 -0
- package/dist/cjs/action.d.ts +71 -0
- package/dist/cjs/action.js +199 -0
- package/dist/cjs/database.d.ts +77 -0
- package/dist/cjs/database.js +118 -0
- package/dist/cjs/executor.d.ts +28 -0
- package/{executor.js → dist/cjs/executor.js} +47 -54
- package/dist/cjs/file/find.d.ts +11 -0
- package/dist/cjs/file/find.js +80 -0
- package/dist/cjs/file/index.d.ts +3 -0
- package/dist/cjs/file/index.js +25 -0
- package/dist/cjs/file/remove.d.ts +7 -0
- package/dist/cjs/file/remove.js +61 -0
- package/dist/cjs/file/update.d.ts +7 -0
- package/dist/cjs/file/update.js +68 -0
- package/dist/cjs/file/utils.d.ts +8 -0
- package/dist/cjs/file/utils.js +23 -0
- package/dist/cjs/format.d.ts +18 -0
- package/dist/cjs/format.js +36 -0
- package/dist/cjs/gen.d.ts +5 -0
- package/dist/cjs/gen.js +78 -0
- package/dist/cjs/graph.d.ts +47 -0
- package/dist/cjs/graph.js +90 -0
- package/{index.d.ts → dist/cjs/index.d.ts} +2 -2
- package/dist/cjs/index.js +18 -0
- package/dist/cjs/relation.d.ts +64 -0
- package/{relation.js → dist/cjs/relation.js} +26 -45
- package/dist/cjs/remote/client/database.d.ts +71 -0
- package/dist/cjs/remote/client/database.js +145 -0
- package/dist/cjs/remote/client/function.d.ts +5 -0
- package/dist/cjs/remote/client/function.js +32 -0
- package/dist/cjs/remote/client/graph.d.ts +54 -0
- package/dist/cjs/remote/client/graph.js +93 -0
- package/dist/cjs/remote/client/remote.d.ts +16 -0
- package/dist/cjs/remote/client/remote.js +2 -0
- package/dist/cjs/remote/server/auth.d.ts +31 -0
- package/dist/cjs/remote/server/auth.js +99 -0
- package/dist/cjs/remote/server/db.d.ts +2 -0
- package/dist/cjs/remote/server/db.js +223 -0
- package/dist/cjs/remote/server/function.d.ts +2 -0
- package/dist/cjs/remote/server/function.js +89 -0
- package/dist/cjs/remote/server/graph.d.ts +2 -0
- package/dist/cjs/remote/server/graph.js +145 -0
- package/dist/cjs/remote/server/index.d.ts +1 -0
- package/dist/cjs/remote/server/index.js +66 -0
- package/dist/cjs/remote/server/initDataBases.d.ts +1 -0
- package/dist/cjs/remote/server/initDataBases.js +25 -0
- package/dist/cjs/remote/server/pathUtils.d.ts +1 -0
- package/dist/cjs/remote/server/pathUtils.js +12 -0
- package/dist/cjs/remote/server/secret.d.ts +1 -0
- package/dist/cjs/remote/server/secret.js +25 -0
- package/dist/cjs/remote/serverMgmt/index.d.ts +1 -0
- package/dist/cjs/remote/serverMgmt/index.js +87 -0
- package/dist/cjs/types/Id.d.ts +3 -0
- package/dist/cjs/types/Id.js +2 -0
- package/dist/cjs/types/arg.d.ts +6 -0
- package/dist/cjs/types/arg.js +2 -0
- package/dist/cjs/types/data.d.ts +4 -0
- package/dist/cjs/types/data.js +2 -0
- package/dist/cjs/types/options.d.ts +12 -0
- package/dist/cjs/types/options.js +2 -0
- package/dist/cjs/types/searchOpts.d.ts +61 -0
- package/dist/cjs/types/searchOpts.js +8 -0
- package/dist/cjs/types/types.d.ts +6 -0
- package/dist/cjs/types/types.js +2 -0
- package/dist/cjs/utils/hasFields.d.ts +8 -0
- package/dist/cjs/utils/hasFields.js +22 -0
- package/dist/cjs/utils/hasFieldsAdvanced.d.ts +5 -0
- package/dist/cjs/utils/hasFieldsAdvanced.js +182 -0
- package/dist/cjs/utils/updateFindObject.d.ts +11 -0
- package/dist/cjs/utils/updateFindObject.js +32 -0
- package/dist/cjs/utils/updateObject.d.ts +8 -0
- package/dist/cjs/utils/updateObject.js +18 -0
- package/dist/esm/CollectionManager.d.ts +43 -0
- package/dist/esm/CollectionManager.js +57 -0
- package/dist/esm/action.d.ts +71 -0
- package/dist/esm/action.js +194 -0
- package/dist/esm/database.d.ts +77 -0
- package/dist/esm/database.js +113 -0
- package/dist/esm/executor.d.ts +28 -0
- package/dist/esm/executor.js +45 -0
- package/dist/esm/file/find.d.ts +11 -0
- package/dist/esm/file/find.js +73 -0
- package/dist/esm/file/index.d.ts +3 -0
- package/{file → dist/esm/file}/index.js +1 -1
- package/dist/esm/file/remove.d.ts +7 -0
- package/dist/esm/file/remove.js +56 -0
- package/dist/esm/file/update.d.ts +7 -0
- package/dist/esm/file/update.js +63 -0
- package/dist/esm/file/utils.d.ts +8 -0
- package/{file → dist/esm/file}/utils.js +3 -11
- package/dist/esm/format.d.ts +18 -0
- package/{format.js → dist/esm/format.js} +29 -29
- package/dist/esm/gen.d.ts +5 -0
- package/dist/esm/gen.js +75 -0
- package/dist/esm/graph.d.ts +47 -0
- package/dist/esm/graph.js +85 -0
- package/dist/esm/index.d.ts +7 -0
- package/{index.js → dist/esm/index.js} +1 -9
- package/dist/esm/relation.d.ts +64 -0
- package/dist/esm/relation.js +65 -0
- package/dist/esm/remote/client/database.d.ts +71 -0
- package/dist/esm/remote/client/database.js +140 -0
- package/dist/esm/remote/client/function.d.ts +5 -0
- package/dist/esm/remote/client/function.js +30 -0
- package/dist/esm/remote/client/graph.d.ts +54 -0
- package/dist/esm/remote/client/graph.js +88 -0
- package/dist/esm/remote/client/remote.d.ts +16 -0
- package/dist/esm/remote/client/remote.js +1 -0
- package/dist/esm/remote/server/auth.d.ts +31 -0
- package/{remote → dist/esm/remote}/server/auth.js +31 -44
- package/dist/esm/remote/server/db.d.ts +2 -0
- package/dist/esm/remote/server/db.js +218 -0
- package/dist/esm/remote/server/function.d.ts +2 -0
- package/dist/esm/remote/server/function.js +87 -0
- package/dist/esm/remote/server/graph.d.ts +2 -0
- package/{remote → dist/esm/remote}/server/graph.js +62 -55
- package/dist/esm/remote/server/gui/css/main.css +130 -0
- package/dist/esm/remote/server/gui/css/scrool.css +81 -0
- package/dist/esm/remote/server/gui/css/style.css +61 -0
- package/dist/esm/remote/server/gui/favicon.svg +12 -0
- package/dist/esm/remote/server/gui/html/data.html +15 -0
- package/dist/esm/remote/server/gui/html/main.html +46 -0
- package/dist/esm/remote/server/gui/html/nav.html +25 -0
- package/dist/esm/remote/server/gui/html/popup.html +51 -0
- package/dist/esm/remote/server/gui/index.html +49 -0
- package/dist/esm/remote/server/gui/js/api.js +166 -0
- package/dist/esm/remote/server/gui/js/index.js +17 -0
- package/dist/esm/remote/server/gui/js/loadHTML.js +16 -0
- package/dist/esm/remote/server/gui/js/popUp.js +72 -0
- package/dist/esm/remote/server/gui/js/queryApi.js +51 -0
- package/dist/esm/remote/server/gui/js/queryDb.js +79 -0
- package/dist/esm/remote/server/gui/js/queryGraph.js +144 -0
- package/dist/esm/remote/server/gui/js/render.js +64 -0
- package/dist/esm/remote/server/gui/js/templates.js +31 -0
- package/dist/esm/remote/server/gui/js/utils.js +36 -0
- package/dist/esm/remote/server/gui/js/vars.js +9 -0
- package/dist/esm/remote/server/gui/libs/core.js +176 -0
- package/dist/esm/remote/server/gui/libs/d3.v7.min.js +2 -0
- package/dist/esm/remote/server/gui/libs/handlebars.min.js +29 -0
- package/dist/esm/remote/server/gui/libs/json5.min.js +1 -0
- package/dist/esm/remote/server/index.d.ts +1 -0
- package/dist/esm/remote/server/index.js +61 -0
- package/dist/esm/remote/server/initDataBases.d.ts +1 -0
- package/dist/esm/remote/server/initDataBases.js +20 -0
- package/dist/esm/remote/server/pathUtils.d.ts +1 -0
- package/{remote → dist/esm/remote}/server/pathUtils.js +2 -3
- package/dist/esm/remote/server/secret.d.ts +1 -0
- package/{remote → dist/esm/remote}/server/secret.js +3 -7
- package/dist/esm/remote/serverMgmt/index.d.ts +1 -0
- package/{remote → dist/esm/remote}/serverMgmt/index.js +27 -31
- package/dist/esm/types/Id.d.ts +3 -0
- package/dist/esm/types/Id.js +1 -0
- package/dist/esm/types/arg.d.ts +6 -0
- package/dist/esm/types/arg.js +1 -0
- package/dist/esm/types/data.d.ts +4 -0
- package/dist/esm/types/data.js +1 -0
- package/dist/esm/types/options.d.ts +12 -0
- package/dist/esm/types/options.js +1 -0
- package/dist/esm/types/searchOpts.d.ts +61 -0
- package/dist/esm/types/searchOpts.js +7 -0
- package/dist/esm/types/types.d.ts +6 -0
- package/dist/esm/types/types.js +1 -0
- package/dist/esm/utils/hasFields.d.ts +8 -0
- package/{utils → dist/esm/utils}/hasFields.js +4 -4
- package/dist/esm/utils/hasFieldsAdvanced.d.ts +5 -0
- package/dist/esm/utils/hasFieldsAdvanced.js +176 -0
- package/dist/esm/utils/updateFindObject.d.ts +11 -0
- package/{utils → dist/esm/utils}/updateFindObject.js +11 -16
- package/dist/esm/utils/updateObject.d.ts +8 -0
- package/{utils → dist/esm/utils}/updateObject.js +4 -4
- package/package.json +55 -36
- package/CollectionManager.js +0 -119
- package/action.js +0 -258
- package/database.d.ts +0 -44
- package/database.js +0 -203
- package/docs/database.md +0 -140
- package/docs/graph.md +0 -86
- package/docs/relation.md +0 -51
- package/docs/remote.md +0 -30
- package/docs/remote_server.md +0 -35
- package/docs/search_opts.md +0 -227
- package/file/find.js +0 -89
- package/file/remove.js +0 -74
- package/file/update.js +0 -83
- package/gen.d.ts +0 -1
- package/gen.js +0 -97
- package/graph.d.ts +0 -27
- package/graph.js +0 -140
- package/relation.d.ts +0 -23
- package/remote/client/database.d.ts +0 -41
- package/remote/client/database.js +0 -228
- package/remote/client/graph.d.ts +0 -31
- package/remote/client/graph.js +0 -148
- package/remote/server/db.js +0 -197
- package/remote/server/function.js +0 -43
- package/remote/server/index.js +0 -63
- package/remote/server/initDataBases.js +0 -20
- package/test/hasFieldsAdvanced.test.js +0 -70
- package/utils/hasFieldsAdvanced.js +0 -184
- /package/{remote → dist/cjs/remote}/server/gui/css/main.css +0 -0
- /package/{remote → dist/cjs/remote}/server/gui/css/scrool.css +0 -0
- /package/{remote → dist/cjs/remote}/server/gui/css/style.css +0 -0
- /package/{remote → dist/cjs/remote}/server/gui/favicon.svg +0 -0
- /package/{remote → dist/cjs/remote}/server/gui/html/data.html +0 -0
- /package/{remote → dist/cjs/remote}/server/gui/html/main.html +0 -0
- /package/{remote → dist/cjs/remote}/server/gui/html/nav.html +0 -0
- /package/{remote → dist/cjs/remote}/server/gui/html/popup.html +0 -0
- /package/{remote → dist/cjs/remote}/server/gui/index.html +0 -0
- /package/{remote → dist/cjs/remote}/server/gui/js/api.js +0 -0
- /package/{remote → dist/cjs/remote}/server/gui/js/index.js +0 -0
- /package/{remote → dist/cjs/remote}/server/gui/js/loadHTML.js +0 -0
- /package/{remote → dist/cjs/remote}/server/gui/js/popUp.js +0 -0
- /package/{remote → dist/cjs/remote}/server/gui/js/queryApi.js +0 -0
- /package/{remote → dist/cjs/remote}/server/gui/js/queryDb.js +0 -0
- /package/{remote → dist/cjs/remote}/server/gui/js/queryGraph.js +0 -0
- /package/{remote → dist/cjs/remote}/server/gui/js/render.js +0 -0
- /package/{remote → dist/cjs/remote}/server/gui/js/templates.js +0 -0
- /package/{remote → dist/cjs/remote}/server/gui/js/utils.js +0 -0
- /package/{remote → dist/cjs/remote}/server/gui/js/vars.js +0 -0
- /package/{remote → dist/cjs/remote}/server/gui/libs/core.js +0 -0
- /package/{remote → dist/cjs/remote}/server/gui/libs/d3.v7.min.js +0 -0
- /package/{remote → dist/cjs/remote}/server/gui/libs/handlebars.min.js +0 -0
- /package/{remote → dist/cjs/remote}/server/gui/libs/json5.min.js +0 -0
package/gen.js
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
const usedIdsMap = new Map();
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Generates a unique identifier based on specified parts.
|
|
5
|
-
* @function
|
|
6
|
-
* @param {number|number[]} parts - The number of parts or an array of parts.
|
|
7
|
-
* @param {number} [fill=1] - The fill value for each part (default: 1).
|
|
8
|
-
* @returns {string} The generated unique identifier.
|
|
9
|
-
*/
|
|
10
|
-
export default function genId(parts, fill=1){
|
|
11
|
-
parts = changeInputToPartsArray(parts, fill);
|
|
12
|
-
const time = getTime();
|
|
13
|
-
const id = getUniqueRandom(time, parts);
|
|
14
|
-
return id;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Generates a unique random identifier based on time and parts.
|
|
19
|
-
* @private
|
|
20
|
-
* @param {string} time - The current time in a base36 string format.
|
|
21
|
-
* @param {number[]} parts - An array of parts to be used for generating the identifier.
|
|
22
|
-
* @param {number} [s=0] - Recursion counter for handling collision (default: 0).
|
|
23
|
-
* @returns {string} The unique random identifier.
|
|
24
|
-
*/
|
|
25
|
-
function getUniqueRandom(time, partsA, s=0){
|
|
26
|
-
const parts = partsA.map(l => getRandom(l));
|
|
27
|
-
const id = [time, ...parts].join("-");
|
|
28
|
-
if(usedIdsMap.has(id)){
|
|
29
|
-
s++;
|
|
30
|
-
if(s < 25) return getUniqueRandom(time, partsA, s);
|
|
31
|
-
partsA = addOneToPods(partsA);
|
|
32
|
-
time = getTime();
|
|
33
|
-
return getUniqueRandom(time, partsA);
|
|
34
|
-
}
|
|
35
|
-
usedIdsMap.set(id, Date.now() + 2000);
|
|
36
|
-
|
|
37
|
-
usedIdsMap.forEach((value, key) => {
|
|
38
|
-
if(value < Date.now()) usedIdsMap.delete(key);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
return id;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Generates a random string of base36 characters.
|
|
46
|
-
* @private
|
|
47
|
-
* @param {string} unix - The Unix timestamp used for generating the random string.
|
|
48
|
-
* @returns {string} The random string.
|
|
49
|
-
*/
|
|
50
|
-
function getRandom(unix){
|
|
51
|
-
return (Math.floor(Math.random() * Math.pow(36, unix))).toString(36);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Gets the current time in a base36 string format.
|
|
56
|
-
* @private
|
|
57
|
-
* @returns {string} The current time in base36.
|
|
58
|
-
*/
|
|
59
|
-
function getTime(){
|
|
60
|
-
return Math.floor(new Date().getTime() / 1000).toString(36);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Adds one to each part of the input array.
|
|
65
|
-
* @private
|
|
66
|
-
* @param {number[]} array - The input array.
|
|
67
|
-
* @returns {number[]} An array with one added to each element.
|
|
68
|
-
*/
|
|
69
|
-
function addOneToPods(array){
|
|
70
|
-
const sum = array.reduce((acc, current) => acc + current, 0);
|
|
71
|
-
const num = sum + 1;
|
|
72
|
-
const len = array.length;
|
|
73
|
-
|
|
74
|
-
const result = [];
|
|
75
|
-
const quotient = Math.floor(num / len);
|
|
76
|
-
const remainder = num % len;
|
|
77
|
-
|
|
78
|
-
for(let i=0; i<len; i++){
|
|
79
|
-
if(i < remainder) result.push(quotient + 1);
|
|
80
|
-
else result.push(quotient);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return result;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Converts input to an array of parts.
|
|
88
|
-
* @private
|
|
89
|
-
* @param {number|number[]} parts - The number of parts or an array of parts.
|
|
90
|
-
* @param {number} [fill=1] - The fill value for each part (default: 1).
|
|
91
|
-
* @returns {number[]} An array of parts.
|
|
92
|
-
*/
|
|
93
|
-
function changeInputToPartsArray(parts, fill=1){
|
|
94
|
-
if(Array.isArray(parts)) return parts;
|
|
95
|
-
if(typeof parts == "number") return Array(parts).fill(fill);
|
|
96
|
-
return [1, 1];
|
|
97
|
-
}
|
package/graph.d.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import DataBase from "./database.js";
|
|
2
|
-
|
|
3
|
-
declare class Graph {
|
|
4
|
-
db: DataBase;
|
|
5
|
-
|
|
6
|
-
constructor(databaseFolder: string);
|
|
7
|
-
|
|
8
|
-
add(collection: string, nodeA: string, nodeB: string): Promise<object>;
|
|
9
|
-
|
|
10
|
-
remove(collection: string, nodeA: string, nodeB: string): Promise<boolean>;
|
|
11
|
-
|
|
12
|
-
find(collection: string, node: string): Promise<object[]>;
|
|
13
|
-
|
|
14
|
-
findOne(collection: string, nodeA: string, nodeB: string): Promise<object | null>;
|
|
15
|
-
|
|
16
|
-
getAll(collection: string): Promise<object[]>;
|
|
17
|
-
|
|
18
|
-
getCollections(): Promise<string[]>;
|
|
19
|
-
|
|
20
|
-
checkCollection(collection: string): Promise<void>;
|
|
21
|
-
|
|
22
|
-
issetCollection(collection: string): Promise<boolean>;
|
|
23
|
-
|
|
24
|
-
removeCollection(collection: string): void;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export default Graph;
|
package/graph.js
DELETED
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import DataBase from "./database.js";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* A class representing a graph database.
|
|
5
|
-
* @class
|
|
6
|
-
*/
|
|
7
|
-
class Graph{
|
|
8
|
-
/**
|
|
9
|
-
* Initializes the graph database.
|
|
10
|
-
* @constructor
|
|
11
|
-
* @param {string} databaseFolder - The folder where the database is stored.
|
|
12
|
-
*/
|
|
13
|
-
constructor(databaseFolder){
|
|
14
|
-
this.db = new DataBase(databaseFolder);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Adds an edge between two nodes.
|
|
19
|
-
* @async
|
|
20
|
-
* @function
|
|
21
|
-
* @param {string} collection - The name of the collection.
|
|
22
|
-
* @param {string} nodeA - The first node.
|
|
23
|
-
* @param {string} nodeB - The second node.
|
|
24
|
-
* @returns {Promise<Object>} A promise that resolves with the added edge.
|
|
25
|
-
*/
|
|
26
|
-
async add(collection, nodeA, nodeB){
|
|
27
|
-
const sortedNodes = [nodeA, nodeB].sort();
|
|
28
|
-
return await this.db.add(collection, {
|
|
29
|
-
a: sortedNodes[0],
|
|
30
|
-
b: sortedNodes[1]
|
|
31
|
-
}, false);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Removes an edge between two nodes.
|
|
36
|
-
* @async
|
|
37
|
-
* @function
|
|
38
|
-
* @param {string} collection - The name of the collection.
|
|
39
|
-
* @param {string} nodeA - The first node.
|
|
40
|
-
* @param {string} nodeB - The second node.
|
|
41
|
-
* @returns {Promise<boolean>} A promise that resolves when the edge is removed.
|
|
42
|
-
*/
|
|
43
|
-
async remove(collection, nodeA, nodeB){
|
|
44
|
-
const sortedNodes = [nodeA, nodeB].sort();
|
|
45
|
-
const query = { a: sortedNodes[0], b: sortedNodes[1] };
|
|
46
|
-
return await this.db.removeOne(collection, query);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Finds all edges with either node equal to `node`.
|
|
51
|
-
* @async
|
|
52
|
-
* @function
|
|
53
|
-
* @param {string} collection - The name of the collection.
|
|
54
|
-
* @param {string} node - The node to search for.
|
|
55
|
-
* @returns {Promise<Object[]>} A promise that resolves with the found edges.
|
|
56
|
-
*/
|
|
57
|
-
async find(collection, node){
|
|
58
|
-
const edges = [];
|
|
59
|
-
const edgesByANode = await this.db.find(collection, { a: node });
|
|
60
|
-
const edgesByBNode = await this.db.find(collection, { b: node });
|
|
61
|
-
|
|
62
|
-
if(edgesByANode) edges.push(...edgesByANode);
|
|
63
|
-
if(edgesByBNode) edges.push(...edgesByBNode);
|
|
64
|
-
|
|
65
|
-
return edges;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Finds one edge with either node equal to `nodeA` and the other equal to `nodeB`.
|
|
70
|
-
* @async
|
|
71
|
-
* @function
|
|
72
|
-
* @param {string} collection - The name of the collection.
|
|
73
|
-
* @param {string} nodeA - The first node.
|
|
74
|
-
* @param {string} nodeB - The second node.
|
|
75
|
-
* @returns {Promise<Object|null>} A promise that resolves with the found edge or null if not found.
|
|
76
|
-
*/
|
|
77
|
-
async findOne(collection, nodeA, nodeB){
|
|
78
|
-
const edgeAB = await this.db.findOne(collection, { a: nodeA, b: nodeB });
|
|
79
|
-
if(edgeAB) return edgeAB;
|
|
80
|
-
|
|
81
|
-
const edgeBA = await this.db.findOne(collection, { a: nodeB, b: nodeA });
|
|
82
|
-
if(edgeBA) return edgeBA;
|
|
83
|
-
|
|
84
|
-
return null;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Gets all edges in the database.
|
|
89
|
-
* @async
|
|
90
|
-
* @function
|
|
91
|
-
* @param {string} collection - The name of the collection.
|
|
92
|
-
* @returns {Promise<Object[]>} A promise that resolves with all edges in the database.
|
|
93
|
-
*/
|
|
94
|
-
async getAll(collection){
|
|
95
|
-
return await this.db.find(collection, {});
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Get the names of all available databases.
|
|
100
|
-
*
|
|
101
|
-
* @function
|
|
102
|
-
* @returns {string[]} An array of database names.
|
|
103
|
-
*/
|
|
104
|
-
async getCollections(){
|
|
105
|
-
return await this.db.getCollections();
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Check and create the specified collection if it doesn't exist.
|
|
110
|
-
*
|
|
111
|
-
* @function
|
|
112
|
-
* @param {string} collection - The collection to check.
|
|
113
|
-
*/
|
|
114
|
-
async checkCollection(collection){
|
|
115
|
-
await this.db.checkCollection(collection);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Check if a collection exists.
|
|
120
|
-
*
|
|
121
|
-
* @function
|
|
122
|
-
* @param {string} collection - The name of the collection.
|
|
123
|
-
* @returns {boolean} True if the collection exists, false otherwise.
|
|
124
|
-
*/
|
|
125
|
-
async issetCollection(collection){
|
|
126
|
-
return await this.db.issetCollection(collection);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Removes a database collection from the file system.
|
|
131
|
-
*
|
|
132
|
-
* @param {string} collection - The name of the collection to remove.
|
|
133
|
-
* @return {void}
|
|
134
|
-
*/
|
|
135
|
-
removeCollection(collection){
|
|
136
|
-
this.db.removeCollection(collection);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
export default Graph;
|
package/relation.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import DataBase from "./database.js";
|
|
2
|
-
|
|
3
|
-
interface RelationConfig {
|
|
4
|
-
from: string;
|
|
5
|
-
localField: string;
|
|
6
|
-
foreignField: string;
|
|
7
|
-
as?: string;
|
|
8
|
-
multiple?: boolean;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
declare class Relation {
|
|
12
|
-
constructor(databases: Record<string, DataBase>);
|
|
13
|
-
|
|
14
|
-
private _resolvePath(path: string): { db: DataBase; collection: string };
|
|
15
|
-
|
|
16
|
-
private _processItemRelations(item: object, relations: Record<string, any>): Promise<object>;
|
|
17
|
-
|
|
18
|
-
find(path: string, search: object, relations?: Record<string, RelationConfig>, options?: object): Promise<Array<object>>;
|
|
19
|
-
|
|
20
|
-
findOne(path: string, search: object, relations?: Record<string, RelationConfig>): Promise<object | null>;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export default Relation;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import CollectionManager from "../../CollectionManager.js";
|
|
2
|
-
|
|
3
|
-
declare class DataBaseRemote {
|
|
4
|
-
remote: {
|
|
5
|
-
name: string;
|
|
6
|
-
auth: string;
|
|
7
|
-
url: string;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
constructor(remote: { name: string; auth: string; url: string });
|
|
11
|
-
|
|
12
|
-
private _request(type: string, data: object): Promise<any>;
|
|
13
|
-
|
|
14
|
-
c(collection: string): CollectionManager;
|
|
15
|
-
|
|
16
|
-
getCollections(): Promise<string[]>;
|
|
17
|
-
|
|
18
|
-
checkCollection(collection: string): Promise<void>;
|
|
19
|
-
|
|
20
|
-
issetCollection(collection: string): Promise<boolean>;
|
|
21
|
-
|
|
22
|
-
add(collection: string, data: object, id_gen?: boolean): Promise<object>;
|
|
23
|
-
|
|
24
|
-
find(collection: string, search: object | string, context?: object, options?: object, findOpts?: object): Promise<object[]>;
|
|
25
|
-
|
|
26
|
-
findOne(collection: string, search: object | string, context?: object, findOpts?: object): Promise<object | null>;
|
|
27
|
-
|
|
28
|
-
update(collection: string, search: object | string, arg: object | string, context?: object): Promise<boolean>;
|
|
29
|
-
|
|
30
|
-
updateOne(collection: string, search: object | string, arg: object | string, context?: object): Promise<boolean>;
|
|
31
|
-
|
|
32
|
-
remove(collection: string, search: object | string, context?: object): Promise<boolean>;
|
|
33
|
-
|
|
34
|
-
removeOne(collection: string, search: object | string, context?: object): Promise<boolean>;
|
|
35
|
-
|
|
36
|
-
updateOneOrAdd(collection: string, search: object | string, arg: object | string, add_arg?: object | string, context?: object, id_gen?: boolean): Promise<boolean>;
|
|
37
|
-
|
|
38
|
-
removeCollection(name: string): Promise<void>;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export default DataBaseRemote;
|
|
@@ -1,228 +0,0 @@
|
|
|
1
|
-
import got from "got";
|
|
2
|
-
import CollectionManager from "../../CollectionManager.js";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Represents a database management class for performing CRUD operations.
|
|
6
|
-
* Uses a remote database.
|
|
7
|
-
* @class
|
|
8
|
-
*/
|
|
9
|
-
class DataBaseRemote{
|
|
10
|
-
/**
|
|
11
|
-
* Create a new database instance.
|
|
12
|
-
* @constructor
|
|
13
|
-
* @param {object} remote - The remote database object.
|
|
14
|
-
* @param {string} remote.name - The name of the database.
|
|
15
|
-
* @param {string} remote.auth - The authentication token.
|
|
16
|
-
* @param {string} remote.url - The URL of the remote database.
|
|
17
|
-
*/
|
|
18
|
-
constructor(remote){
|
|
19
|
-
this.remote = remote;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Make a request to the remote database.
|
|
24
|
-
* @async
|
|
25
|
-
* @function
|
|
26
|
-
* @param {string} type - The type of the request.
|
|
27
|
-
* @param {object} data - The data to send with the request.
|
|
28
|
-
* @returns {Promise<*>} A Promise that resolves with the result of the request.
|
|
29
|
-
* @throws {Error} If the request failed.
|
|
30
|
-
*/
|
|
31
|
-
async _request(type, data){
|
|
32
|
-
data.db = this.remote.name;
|
|
33
|
-
const res = await got.post(this.remote.url + "/db/database/" + type, {
|
|
34
|
-
json: data,
|
|
35
|
-
headers: {
|
|
36
|
-
"Authorization": this.remote.auth
|
|
37
|
-
},
|
|
38
|
-
responseType: "json"
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
if(res.body.err) throw new Error(res.body.msg);
|
|
42
|
-
return res.body.result;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Create a new instance of a CollectionManager class.
|
|
47
|
-
* @function
|
|
48
|
-
* @param {string} collection - The name of the collection.
|
|
49
|
-
* @returns {CollectionManager} A new instance of CollectionManager.
|
|
50
|
-
*/
|
|
51
|
-
c(collection){
|
|
52
|
-
return new CollectionManager(this, collection);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Get the names of all available databases.
|
|
57
|
-
*
|
|
58
|
-
* @function
|
|
59
|
-
* @returns {string[]} An array of database names.
|
|
60
|
-
*/
|
|
61
|
-
async getCollections(){
|
|
62
|
-
return await this._request("getCollections", {});
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Check and create the specified collection if it doesn't exist.
|
|
67
|
-
*
|
|
68
|
-
* @function
|
|
69
|
-
* @param {string} collection - The collection to check.
|
|
70
|
-
*/
|
|
71
|
-
async checkCollection(collection){
|
|
72
|
-
return await this._request("checkCollection", { collection });
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Check if a collection exists.
|
|
77
|
-
*
|
|
78
|
-
* @function
|
|
79
|
-
* @param {string} collection - The name of the collection.
|
|
80
|
-
* @returns {boolean} True if the collection exists, false otherwise.
|
|
81
|
-
*/
|
|
82
|
-
async issetCollection(collection){
|
|
83
|
-
return await this._request("issetCollection", { collection });
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Add data to a database.
|
|
88
|
-
*
|
|
89
|
-
* @async
|
|
90
|
-
* @function
|
|
91
|
-
* @param {string} collection - The name of the collection.
|
|
92
|
-
* @param {Object} data - The data to add.
|
|
93
|
-
* @param {boolean} id_gen - Whether to generate an ID for the entry. Default is true.
|
|
94
|
-
* @returns {Promise<Object>} A Promise that resolves with the added data.
|
|
95
|
-
*/
|
|
96
|
-
async add(collection, data, id_gen=true){
|
|
97
|
-
return await this._request("add", { collection, data, id_gen });
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Find data in a database.
|
|
102
|
-
*
|
|
103
|
-
* @async
|
|
104
|
-
* @function
|
|
105
|
-
* @param {string} collection - Name of the database collection.
|
|
106
|
-
* @param {function|Object} search - The query. It can be an object or a function.
|
|
107
|
-
* @param {Object} context - The context object (for functions).
|
|
108
|
-
* @param {Object} options - The options for the search.
|
|
109
|
-
* @param {number} options.max - The maximum number of entries to return. Default is -1, meaning no limit.
|
|
110
|
-
* @param {boolean} options.reverse - Whether to reverse the order of returned entries. Default is false.
|
|
111
|
-
* @param {Object} findOpts - Update result object with findOpts options.
|
|
112
|
-
* @returns {Promise<Array<Object>>} A Promise that resolves with the matching data.
|
|
113
|
-
*/
|
|
114
|
-
async find(collection, search, context={}, options={}, findOpts={}){
|
|
115
|
-
if(typeof search === "function") search = search.toString();
|
|
116
|
-
return await this._request("find", { collection, search, options, context, findOpts });
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Find one data entry in a database.
|
|
121
|
-
*
|
|
122
|
-
* @async
|
|
123
|
-
* @function
|
|
124
|
-
* @param {string} collection - Name of the database collection.
|
|
125
|
-
* @param {function|Object} search - The query. It can be an object or a function.
|
|
126
|
-
* @param {Object} context - The context object (for functions).
|
|
127
|
-
* @param {Object} findOpts - Update result object with findOpts options.
|
|
128
|
-
* @returns {Promise<Object|null>} A Promise that resolves with the first matching data entry.
|
|
129
|
-
*/
|
|
130
|
-
async findOne(collection, search, context={}, findOpts={}){
|
|
131
|
-
if(typeof search === "function") search = search.toString();
|
|
132
|
-
return await this._request("findOne", { collection, search, context, findOpts });
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* Update data in a database.
|
|
137
|
-
*
|
|
138
|
-
* @async
|
|
139
|
-
* @function
|
|
140
|
-
* @param {string} collection - Name of the database collection.
|
|
141
|
-
* @param {function|Object} search - The query. It can be an object or a function.
|
|
142
|
-
* @param {function|Object} arg - Update arguments.
|
|
143
|
-
* @param {Object} context - The context object (for functions).
|
|
144
|
-
* @returns {Promise<boolean>} A Promise that resolves when the data is updated.
|
|
145
|
-
*/
|
|
146
|
-
async update(collection, search, arg, context={}){
|
|
147
|
-
if(typeof search === "function") search = search.toString();
|
|
148
|
-
if(typeof arg === "function") arg = arg.toString();
|
|
149
|
-
return await this._request("update", { collection, search, arg, context });
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Update one data entry in a database.
|
|
154
|
-
*
|
|
155
|
-
* @async
|
|
156
|
-
* @function
|
|
157
|
-
* @param {string} collection - Name of the database collection.
|
|
158
|
-
* @param {function|Object} search - The query. It can be an object or a function.
|
|
159
|
-
* @param {function|Object} arg - The query.
|
|
160
|
-
* @param {Object} context - The context object (for functions).
|
|
161
|
-
* @returns {Promise<boolean>} A Promise that resolves when the data entry is updated.
|
|
162
|
-
*/
|
|
163
|
-
async updateOne(collection, search, arg, context={}){
|
|
164
|
-
if(typeof search === "function") search = search.toString();
|
|
165
|
-
if(typeof arg === "function") arg = arg.toString();
|
|
166
|
-
return await this._request("updateOne", { collection, search, arg, context });
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Remove data from a database.
|
|
171
|
-
*
|
|
172
|
-
* @async
|
|
173
|
-
* @function
|
|
174
|
-
* @param {string} collection - Name of the database collection.
|
|
175
|
-
* @param {function|Object} search - The query. It can be an object or a function.
|
|
176
|
-
* @param {Object} context - The context object (for functions).
|
|
177
|
-
* @returns {Promise<boolean>} A Promise that resolves when the data is removed.
|
|
178
|
-
*/
|
|
179
|
-
async remove(collection, search, context={}){
|
|
180
|
-
if(typeof search === "function") search = search.toString();
|
|
181
|
-
return await this._request("remove", { collection, search, context });
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Remove one data entry from a database.
|
|
186
|
-
*
|
|
187
|
-
* @async
|
|
188
|
-
* @function
|
|
189
|
-
* @param {string} collection - Name of the database collection.
|
|
190
|
-
* @param {function|Object} search - The query. It can be an object or a function.
|
|
191
|
-
* @param {Object} context - The context object (for functions).
|
|
192
|
-
* @returns {Promise<boolean>} A Promise that resolves when the data entry is removed.
|
|
193
|
-
*/
|
|
194
|
-
async removeOne(collection, search, context={}){
|
|
195
|
-
if(typeof search === "function") search = search.toString();
|
|
196
|
-
return await this._request("removeOne", { collection, search, context });
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* Asynchronously updates one entry in a database or adds a new one if it doesn't exist.
|
|
201
|
-
*
|
|
202
|
-
* @param {string} collection - Name of the database collection.
|
|
203
|
-
* @param {function|Object} search - The query. It can be an object or a function.
|
|
204
|
-
* @param {function|Object} arg - The search criteria for the update.
|
|
205
|
-
* @param {function|Object} add_arg - The arguments to be added to the new entry.
|
|
206
|
-
* @param {Object} context - The context object (for functions).
|
|
207
|
-
* @param {boolean} id_gen - Whether to generate an ID for the entry. Default is true.
|
|
208
|
-
* @return {Promise<boolean>} A Promise that resolves to `true` if the entry was updated, or `false` if it was added.
|
|
209
|
-
*/
|
|
210
|
-
async updateOneOrAdd(collection, search, arg, add_arg={}, context={}, id_gen=true){
|
|
211
|
-
if(typeof search === "function") search = search.toString();
|
|
212
|
-
if(typeof arg === "function") arg = arg.toString();
|
|
213
|
-
if(typeof add_arg === "function") add_arg = add_arg.toString();
|
|
214
|
-
return await this._request("updateOneOrAdd", { collection, search, arg, add_arg, id_gen, context });
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
* Removes a database collection from the file system.
|
|
219
|
-
*
|
|
220
|
-
* @param {string} collection - The name of the collection to remove.
|
|
221
|
-
* @return {void}
|
|
222
|
-
*/
|
|
223
|
-
removeCollection(name){
|
|
224
|
-
return this._request("removeCollection", { name });
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
export default DataBaseRemote;
|
package/remote/client/graph.d.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
declare class GraphRemote {
|
|
2
|
-
remote: {
|
|
3
|
-
name: string;
|
|
4
|
-
auth: string;
|
|
5
|
-
url: string;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
constructor(remote: { name: string; auth: string; url: string });
|
|
9
|
-
|
|
10
|
-
private _request(type: string, data: object): Promise<any>;
|
|
11
|
-
|
|
12
|
-
add(collection: string, nodeA: string, nodeB: string): Promise<object>;
|
|
13
|
-
|
|
14
|
-
remove(collection: string, nodeA: string, nodeB: string): Promise<boolean>;
|
|
15
|
-
|
|
16
|
-
find(collection: string, node: string): Promise<object[]>;
|
|
17
|
-
|
|
18
|
-
findOne(collection: string, nodeA: string, nodeB: string): Promise<object | null>;
|
|
19
|
-
|
|
20
|
-
getAll(collection: string): Promise<object[]>;
|
|
21
|
-
|
|
22
|
-
getCollections(): Promise<string[]>;
|
|
23
|
-
|
|
24
|
-
checkCollection(collection: string): Promise<void>;
|
|
25
|
-
|
|
26
|
-
issetCollection(collection: string): Promise<boolean>;
|
|
27
|
-
|
|
28
|
-
removeCollection(collection: string): void;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export default GraphRemote;
|