@wxn0brp/db 0.2.0 → 0.3.1
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/package.json +10 -13
- package/dist/cjs/CollectionManager.js +0 -59
- package/dist/cjs/action.js +0 -210
- package/dist/cjs/client/database.js +0 -119
- package/dist/cjs/client/function.js +0 -32
- package/dist/cjs/client/graph.js +0 -94
- package/dist/cjs/client/remote.js +0 -2
- package/dist/cjs/database.js +0 -113
- package/dist/cjs/executor.js +0 -47
- package/dist/cjs/file/customFileCpu.js +0 -79
- package/dist/cjs/file/find.js +0 -80
- package/dist/cjs/file/index.js +0 -21
- package/dist/cjs/file/remove.js +0 -46
- package/dist/cjs/file/update.js +0 -55
- package/dist/cjs/file/utils.js +0 -23
- package/dist/cjs/format.js +0 -30
- package/dist/cjs/gen.js +0 -137
- package/dist/cjs/graph.js +0 -90
- package/dist/cjs/index.js +0 -20
- package/dist/cjs/relation.js +0 -64
- package/dist/cjs/types/Id.js +0 -2
- package/dist/cjs/types/arg.js +0 -2
- package/dist/cjs/types/data.js +0 -2
- package/dist/cjs/types/fileCpu.js +0 -2
- package/dist/cjs/types/options.js +0 -2
- package/dist/cjs/types/searchOpts.js +0 -8
- package/dist/cjs/types/types.js +0 -2
- package/dist/cjs/types/updater.js +0 -5
- package/dist/cjs/utils/hasFields.js +0 -21
- package/dist/cjs/utils/hasFieldsAdvanced.js +0 -182
- package/dist/cjs/utils/updateFindObject.js +0 -31
- package/dist/cjs/utils/updateObject.js +0 -148
- package/dist/esm/CollectionManager.d.ts +0 -44
- package/dist/esm/action.d.ts +0 -68
- package/dist/esm/client/database.d.ts +0 -72
- package/dist/esm/client/function.d.ts +0 -5
- package/dist/esm/client/graph.d.ts +0 -54
- package/dist/esm/client/remote.d.ts +0 -15
- package/dist/esm/database.d.ts +0 -70
- package/dist/esm/executor.d.ts +0 -28
- package/dist/esm/file/customFileCpu.d.ts +0 -19
- package/dist/esm/file/find.d.ts +0 -11
- package/dist/esm/file/index.d.ts +0 -3
- package/dist/esm/file/remove.d.ts +0 -7
- package/dist/esm/file/update.d.ts +0 -7
- package/dist/esm/file/utils.d.ts +0 -8
- package/dist/esm/format.d.ts +0 -12
- package/dist/esm/gen.d.ts +0 -8
- package/dist/esm/graph.d.ts +0 -47
- package/dist/esm/index.d.ts +0 -14
- package/dist/esm/relation.d.ts +0 -34
- package/dist/esm/types/Id.d.ts +0 -3
- package/dist/esm/types/arg.d.ts +0 -12
- package/dist/esm/types/data.d.ts +0 -4
- package/dist/esm/types/fileCpu.d.ts +0 -51
- package/dist/esm/types/options.d.ts +0 -12
- package/dist/esm/types/searchOpts.d.ts +0 -62
- package/dist/esm/types/types.d.ts +0 -3
- package/dist/esm/types/updater.d.ts +0 -26
- package/dist/esm/utils/hasFields.d.ts +0 -7
- package/dist/esm/utils/hasFieldsAdvanced.d.ts +0 -5
- package/dist/esm/utils/updateFindObject.d.ts +0 -11
- package/dist/esm/utils/updateObject.d.ts +0 -7
- /package/dist/{cjs/CollectionManager.d.ts → CollectionManager.d.ts} +0 -0
- /package/dist/{esm/CollectionManager.js → CollectionManager.js} +0 -0
- /package/dist/{cjs/action.d.ts → action.d.ts} +0 -0
- /package/dist/{esm/action.js → action.js} +0 -0
- /package/dist/{cjs/client → client}/database.d.ts +0 -0
- /package/dist/{esm/client → client}/database.js +0 -0
- /package/dist/{cjs/client → client}/function.d.ts +0 -0
- /package/dist/{esm/client → client}/function.js +0 -0
- /package/dist/{cjs/client → client}/graph.d.ts +0 -0
- /package/dist/{esm/client → client}/graph.js +0 -0
- /package/dist/{cjs/client → client}/remote.d.ts +0 -0
- /package/dist/{esm/client → client}/remote.js +0 -0
- /package/dist/{cjs/database.d.ts → database.d.ts} +0 -0
- /package/dist/{esm/database.js → database.js} +0 -0
- /package/dist/{cjs/executor.d.ts → executor.d.ts} +0 -0
- /package/dist/{esm/executor.js → executor.js} +0 -0
- /package/dist/{cjs/file → file}/customFileCpu.d.ts +0 -0
- /package/dist/{esm/file → file}/customFileCpu.js +0 -0
- /package/dist/{cjs/file → file}/find.d.ts +0 -0
- /package/dist/{esm/file → file}/find.js +0 -0
- /package/dist/{cjs/file → file}/index.d.ts +0 -0
- /package/dist/{esm/file → file}/index.js +0 -0
- /package/dist/{cjs/file → file}/remove.d.ts +0 -0
- /package/dist/{esm/file → file}/remove.js +0 -0
- /package/dist/{cjs/file → file}/update.d.ts +0 -0
- /package/dist/{esm/file → file}/update.js +0 -0
- /package/dist/{cjs/file → file}/utils.d.ts +0 -0
- /package/dist/{esm/file → file}/utils.js +0 -0
- /package/dist/{cjs/format.d.ts → format.d.ts} +0 -0
- /package/dist/{esm/format.js → format.js} +0 -0
- /package/dist/{cjs/gen.d.ts → gen.d.ts} +0 -0
- /package/dist/{esm/gen.js → gen.js} +0 -0
- /package/dist/{cjs/graph.d.ts → graph.d.ts} +0 -0
- /package/dist/{esm/graph.js → graph.js} +0 -0
- /package/dist/{cjs/index.d.ts → index.d.ts} +0 -0
- /package/dist/{esm/index.js → index.js} +0 -0
- /package/dist/{cjs/relation.d.ts → relation.d.ts} +0 -0
- /package/dist/{esm/relation.js → relation.js} +0 -0
- /package/dist/{cjs/types → types}/Id.d.ts +0 -0
- /package/dist/{esm/types → types}/Id.js +0 -0
- /package/dist/{cjs/types → types}/arg.d.ts +0 -0
- /package/dist/{esm/types → types}/arg.js +0 -0
- /package/dist/{cjs/types → types}/data.d.ts +0 -0
- /package/dist/{esm/types → types}/data.js +0 -0
- /package/dist/{cjs/types → types}/fileCpu.d.ts +0 -0
- /package/dist/{esm/types → types}/fileCpu.js +0 -0
- /package/dist/{cjs/types → types}/options.d.ts +0 -0
- /package/dist/{esm/types → types}/options.js +0 -0
- /package/dist/{cjs/types → types}/searchOpts.d.ts +0 -0
- /package/dist/{esm/types → types}/searchOpts.js +0 -0
- /package/dist/{cjs/types → types}/types.d.ts +0 -0
- /package/dist/{esm/types → types}/types.js +0 -0
- /package/dist/{cjs/types → types}/updater.d.ts +0 -0
- /package/dist/{esm/types → types}/updater.js +0 -0
- /package/dist/{cjs/utils → utils}/hasFields.d.ts +0 -0
- /package/dist/{esm/utils → utils}/hasFields.js +0 -0
- /package/dist/{cjs/utils → utils}/hasFieldsAdvanced.d.ts +0 -0
- /package/dist/{esm/utils → utils}/hasFieldsAdvanced.js +0 -0
- /package/dist/{cjs/utils → utils}/updateFindObject.d.ts +0 -0
- /package/dist/{esm/utils → utils}/updateFindObject.js +0 -0
- /package/dist/{cjs/utils → utils}/updateObject.d.ts +0 -0
- /package/dist/{esm/utils → utils}/updateObject.js +0 -0
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wxn0brp/db",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"main": "dist/
|
|
5
|
-
"types": "dist/
|
|
3
|
+
"version": "0.3.1",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"types": "dist/index.d.ts",
|
|
6
6
|
"description": "A simple file-based database management system with support for CRUD operations, custom queries, and graph structures.",
|
|
7
7
|
"homepage": "https://github.com/wxn0brP/ValtheraDB",
|
|
8
8
|
"repository": {
|
|
@@ -30,25 +30,22 @@
|
|
|
30
30
|
"typescript": "^5.7.2"
|
|
31
31
|
},
|
|
32
32
|
"scripts": {
|
|
33
|
-
"build
|
|
34
|
-
"build:cjs": "tsc -p tsconfig.cjs.json && tsc-alias -p tsconfig.cjs.json",
|
|
35
|
-
"build": "npm run build:esm && npm run build:cjs",
|
|
33
|
+
"build": "tsc && tsc-alias",
|
|
36
34
|
"prepare": "npm run build",
|
|
37
|
-
"postversion": "git push && git push --tags"
|
|
35
|
+
"postversion": "git push && git push --tags",
|
|
36
|
+
"build:cdn": "npm run build && cd cdn && node index.js"
|
|
38
37
|
},
|
|
39
38
|
"files": [
|
|
40
39
|
"dist"
|
|
41
40
|
],
|
|
42
41
|
"exports": {
|
|
43
42
|
".": {
|
|
44
|
-
"types": "./dist/
|
|
45
|
-
"import": "./dist/
|
|
46
|
-
"require": "./dist/cjs/index.js"
|
|
43
|
+
"types": "./dist/index.d.ts",
|
|
44
|
+
"import": "./dist/index.js"
|
|
47
45
|
},
|
|
48
46
|
"./*": {
|
|
49
|
-
"types": "./dist
|
|
50
|
-
"import": "./dist
|
|
51
|
-
"require": "./dist/cjs/*"
|
|
47
|
+
"types": "./dist/*",
|
|
48
|
+
"import": "./dist/*"
|
|
52
49
|
}
|
|
53
50
|
}
|
|
54
51
|
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
class CollectionManager {
|
|
4
|
-
db;
|
|
5
|
-
collection;
|
|
6
|
-
constructor(db, collection) {
|
|
7
|
-
this.db = db;
|
|
8
|
-
this.collection = collection;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Add data to a database.
|
|
12
|
-
*/
|
|
13
|
-
async add(data, id_gen = true) {
|
|
14
|
-
return await this.db.add(this.collection, data, id_gen);
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Find data in a database.
|
|
18
|
-
*/
|
|
19
|
-
async find(search, context = {}, options = {}, findOpts = {}) {
|
|
20
|
-
return await this.db.find(this.collection, search, context, options, findOpts);
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Find one data entry in a database.
|
|
24
|
-
*/
|
|
25
|
-
async findOne(search, context = {}, findOpts = {}) {
|
|
26
|
-
return await this.db.findOne(this.collection, search, context, findOpts);
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Update data in a database.
|
|
30
|
-
*/
|
|
31
|
-
async update(search, updater, context = {}) {
|
|
32
|
-
return await this.db.update(this.collection, search, updater, context);
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Update one data entry in a database.
|
|
36
|
-
*/
|
|
37
|
-
async updateOne(search, updater, context = {}) {
|
|
38
|
-
return await this.db.updateOne(this.collection, search, updater, context);
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Remove data from a database.
|
|
42
|
-
*/
|
|
43
|
-
async remove(search, context = {}) {
|
|
44
|
-
return await this.db.remove(this.collection, search, context);
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Remove one data entry from a database.
|
|
48
|
-
*/
|
|
49
|
-
async removeOne(search, context = {}) {
|
|
50
|
-
return await this.db.removeOne(this.collection, search, context);
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Asynchronously updates one entry in a database or adds a new one if it doesn't exist.
|
|
54
|
-
*/
|
|
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
|
-
}
|
|
58
|
-
}
|
|
59
|
-
exports.default = CollectionManager;
|
package/dist/cjs/action.js
DELETED
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const gen_1 = __importDefault(require("./gen.js"));
|
|
7
|
-
const fs_1 = require("fs");
|
|
8
|
-
/**
|
|
9
|
-
* A class representing database actions on files.
|
|
10
|
-
* @class
|
|
11
|
-
*/
|
|
12
|
-
class dbActionC {
|
|
13
|
-
folder;
|
|
14
|
-
options;
|
|
15
|
-
fileCpu;
|
|
16
|
-
/**
|
|
17
|
-
* Creates a new instance of dbActionC.
|
|
18
|
-
* @constructor
|
|
19
|
-
* @param folder - The folder where database files are stored.
|
|
20
|
-
* @param options - The options object.
|
|
21
|
-
*/
|
|
22
|
-
constructor(folder, options, fileCpu) {
|
|
23
|
-
this.folder = folder;
|
|
24
|
-
this.options = {
|
|
25
|
-
maxFileSize: 2 * 1024 * 1024, //2 MB
|
|
26
|
-
...options,
|
|
27
|
-
};
|
|
28
|
-
this.fileCpu = fileCpu;
|
|
29
|
-
if (!(0, fs_1.existsSync)(folder))
|
|
30
|
-
(0, fs_1.mkdirSync)(folder, { recursive: true });
|
|
31
|
-
}
|
|
32
|
-
_getCollectionPath(collection) {
|
|
33
|
-
return this.folder + "/" + collection + "/";
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Get a list of available databases in the specified folder.
|
|
37
|
-
*/
|
|
38
|
-
async getCollections() {
|
|
39
|
-
const allCollections = await fs_1.promises.readdir(this.folder, { recursive: true, withFileTypes: true });
|
|
40
|
-
const collections = allCollections
|
|
41
|
-
.filter(dirent => dirent.isDirectory())
|
|
42
|
-
.map(dirent => {
|
|
43
|
-
if (dirent.parentPath === this.folder)
|
|
44
|
-
return dirent.name;
|
|
45
|
-
return dirent.parentPath.replace(this.folder + "/", "") + "/" + dirent.name;
|
|
46
|
-
});
|
|
47
|
-
return collections;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Check and create the specified collection if it doesn't exist.
|
|
51
|
-
*/
|
|
52
|
-
async checkCollection(collection) {
|
|
53
|
-
if (await this.issetCollection(collection))
|
|
54
|
-
return;
|
|
55
|
-
const cpath = this._getCollectionPath(collection);
|
|
56
|
-
await fs_1.promises.mkdir(cpath, { recursive: true });
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Check if a collection exists.
|
|
60
|
-
*/
|
|
61
|
-
async issetCollection(collection) {
|
|
62
|
-
const path = this._getCollectionPath(collection);
|
|
63
|
-
try {
|
|
64
|
-
await fs_1.promises.access(path);
|
|
65
|
-
return true;
|
|
66
|
-
}
|
|
67
|
-
catch {
|
|
68
|
-
return false;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Add a new entry to the specified database.
|
|
73
|
-
*/
|
|
74
|
-
async add(collection, arg, id_gen = true) {
|
|
75
|
-
this.checkCollection(collection);
|
|
76
|
-
const cpath = this._getCollectionPath(collection);
|
|
77
|
-
const file = cpath + await getLastFile(cpath, this.options.maxFileSize);
|
|
78
|
-
if (id_gen)
|
|
79
|
-
arg._id = arg._id || (0, gen_1.default)();
|
|
80
|
-
await this.fileCpu.add(file, arg);
|
|
81
|
-
return arg;
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Find entries in the specified database based on search criteria.
|
|
85
|
-
*/
|
|
86
|
-
async find(collection, arg, context = {}, options = {}, findOpts = {}) {
|
|
87
|
-
options.reverse = options.reverse || false;
|
|
88
|
-
options.max = options.max || -1;
|
|
89
|
-
this.checkCollection(collection);
|
|
90
|
-
const cpath = this._getCollectionPath(collection);
|
|
91
|
-
const files = await getSortedFiles(cpath);
|
|
92
|
-
if (options.reverse)
|
|
93
|
-
files.reverse();
|
|
94
|
-
let datas = [];
|
|
95
|
-
let totalEntries = 0;
|
|
96
|
-
for (let f of files) {
|
|
97
|
-
let data = await this.fileCpu.find(cpath + f, arg, context, findOpts);
|
|
98
|
-
if (options.reverse)
|
|
99
|
-
data.reverse();
|
|
100
|
-
if (options.max !== -1) {
|
|
101
|
-
if (totalEntries + data.length > options.max) {
|
|
102
|
-
let remainingEntries = options.max - totalEntries;
|
|
103
|
-
data = data.slice(0, remainingEntries);
|
|
104
|
-
totalEntries = options.max;
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
totalEntries += data.length;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
datas = datas.concat(data);
|
|
111
|
-
if (options.max !== -1 && totalEntries >= options.max)
|
|
112
|
-
break;
|
|
113
|
-
}
|
|
114
|
-
return datas;
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Find the first matching entry in the specified database based on search criteria.
|
|
118
|
-
*/
|
|
119
|
-
async findOne(collection, arg, context = {}, findOpts = {}) {
|
|
120
|
-
this.checkCollection(collection);
|
|
121
|
-
const cpath = this._getCollectionPath(collection);
|
|
122
|
-
const files = await getSortedFiles(cpath);
|
|
123
|
-
for (let f of files) {
|
|
124
|
-
let data = await this.fileCpu.findOne(cpath + f, arg, context, findOpts);
|
|
125
|
-
if (data)
|
|
126
|
-
return data;
|
|
127
|
-
}
|
|
128
|
-
return null;
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Update entries in the specified database based on search criteria and an updater function or object.
|
|
132
|
-
*/
|
|
133
|
-
async update(collection, arg, updater, context = {}) {
|
|
134
|
-
this.checkCollection(collection);
|
|
135
|
-
return await operationUpdater(this._getCollectionPath(collection), this.fileCpu.update.bind(this.fileCpu), false, arg, updater, context);
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Update the first matching entry in the specified database based on search criteria and an updater function or object.
|
|
139
|
-
*/
|
|
140
|
-
async updateOne(collection, arg, updater, context = {}) {
|
|
141
|
-
this.checkCollection(collection);
|
|
142
|
-
return await operationUpdater(this._getCollectionPath(collection), this.fileCpu.update.bind(this.fileCpu), true, arg, updater, context);
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Remove entries from the specified database based on search criteria.
|
|
146
|
-
*/
|
|
147
|
-
async remove(collection, arg, context = {}) {
|
|
148
|
-
this.checkCollection(collection);
|
|
149
|
-
return await operationUpdater(this._getCollectionPath(collection), this.fileCpu.remove.bind(this.fileCpu), false, arg, context);
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* Remove the first matching entry from the specified database based on search criteria.
|
|
153
|
-
*/
|
|
154
|
-
async removeOne(collection, arg, context = {}) {
|
|
155
|
-
this.checkCollection(collection);
|
|
156
|
-
return await operationUpdater(this._getCollectionPath(collection), this.fileCpu.remove.bind(this.fileCpu), true, arg, context);
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Removes a database collection from the file system.
|
|
160
|
-
*/
|
|
161
|
-
async removeCollection(collection) {
|
|
162
|
-
await fs_1.promises.rm(this.folder + "/" + collection, { recursive: true, force: true });
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* Get the last file in the specified directory.
|
|
167
|
-
*/
|
|
168
|
-
async function getLastFile(path, maxFileSize = 1024 * 1024) {
|
|
169
|
-
if (!(0, fs_1.existsSync)(path))
|
|
170
|
-
(0, fs_1.mkdirSync)(path, { recursive: true });
|
|
171
|
-
const files = await getSortedFiles(path);
|
|
172
|
-
if (files.length == 0) {
|
|
173
|
-
await fs_1.promises.writeFile(path + "/1.db", "");
|
|
174
|
-
return "1.db";
|
|
175
|
-
}
|
|
176
|
-
const last = files[files.length - 1];
|
|
177
|
-
const info = path + "/" + last;
|
|
178
|
-
if ((0, fs_1.statSync)(info).size < maxFileSize)
|
|
179
|
-
return last;
|
|
180
|
-
const num = parseInt(last.replace(".db", ""), 10) + 1;
|
|
181
|
-
await fs_1.promises.writeFile(path + "/" + num + ".db", "");
|
|
182
|
-
return num + ".db";
|
|
183
|
-
}
|
|
184
|
-
/**
|
|
185
|
-
* Get all files in a directory sorted by name.
|
|
186
|
-
*/
|
|
187
|
-
async function getSortedFiles(folder) {
|
|
188
|
-
const files = await fs_1.promises.readdir(folder, { withFileTypes: true });
|
|
189
|
-
return files
|
|
190
|
-
.filter(file => file.isFile() && !file.name.endsWith(".tmp"))
|
|
191
|
-
.map(file => file.name)
|
|
192
|
-
.filter(name => /^\d+\.db$/.test(name))
|
|
193
|
-
.sort((a, b) => {
|
|
194
|
-
const numA = parseInt(a, 10);
|
|
195
|
-
const numB = parseInt(b, 10);
|
|
196
|
-
return numA - numB;
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
async function operationUpdater(cpath, worker, one, ...args) {
|
|
200
|
-
const files = await getSortedFiles(cpath);
|
|
201
|
-
let update = false;
|
|
202
|
-
for (const file of files) {
|
|
203
|
-
const updated = await worker(cpath + file, one, ...args);
|
|
204
|
-
if (one && updated)
|
|
205
|
-
break;
|
|
206
|
-
update = update || updated;
|
|
207
|
-
}
|
|
208
|
-
return update;
|
|
209
|
-
}
|
|
210
|
-
exports.default = dbActionC;
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const ky_1 = __importDefault(require("ky"));
|
|
7
|
-
const CollectionManager_1 = __importDefault(require("../CollectionManager.js"));
|
|
8
|
-
const function_1 = __importDefault(require("./function.js"));
|
|
9
|
-
/**
|
|
10
|
-
* Represents a database management class for performing CRUD operations.
|
|
11
|
-
* Uses a remote database.
|
|
12
|
-
* @class
|
|
13
|
-
*/
|
|
14
|
-
class DataBaseRemote {
|
|
15
|
-
remote;
|
|
16
|
-
constructor(remote) {
|
|
17
|
-
this.remote = remote;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Make a request to the remote database.
|
|
21
|
-
*/
|
|
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
|
-
};
|
|
29
|
-
const res = await ky_1.default.post(this.remote.url + "/db/" + type, {
|
|
30
|
-
json: data,
|
|
31
|
-
headers: {
|
|
32
|
-
"Authorization": this.remote.auth
|
|
33
|
-
},
|
|
34
|
-
throwHttpErrors: false
|
|
35
|
-
}).json();
|
|
36
|
-
if (res.err)
|
|
37
|
-
throw new Error(res.msg);
|
|
38
|
-
return res.result;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Create a new instance of a CollectionManager class.
|
|
42
|
-
*/
|
|
43
|
-
c(collection) {
|
|
44
|
-
return new CollectionManager_1.default(this, collection);
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Get the names of all available databases.
|
|
48
|
-
*/
|
|
49
|
-
async getCollections() {
|
|
50
|
-
return await this._request("getCollections", []);
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Check and create the specified collection if it doesn't exist.
|
|
54
|
-
*/
|
|
55
|
-
async checkCollection(collection) {
|
|
56
|
-
return await this._request("checkCollection", [collection]);
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Check if a collection exists.
|
|
60
|
-
*/
|
|
61
|
-
async issetCollection(collection) {
|
|
62
|
-
return await this._request("issetCollection", [collection]);
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Add data to a database.
|
|
66
|
-
*/
|
|
67
|
-
async add(collection, data, id_gen = true) {
|
|
68
|
-
return await this._request("add", [collection, data, id_gen]);
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Find data in a database.
|
|
72
|
-
*/
|
|
73
|
-
async find(collection, search, context = {}, options = {}, findOpts = {}) {
|
|
74
|
-
return await this._request("find", [collection, search, context, options, findOpts]);
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Find one data entry in a database.
|
|
78
|
-
*/
|
|
79
|
-
async findOne(collection, search, context = {}, findOpts = {}) {
|
|
80
|
-
return await this._request("findOne", [collection, search, context, findOpts]);
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Update data in a database.
|
|
84
|
-
*/
|
|
85
|
-
async update(collection, search, updater, context = {}) {
|
|
86
|
-
return await this._request("update", [collection, search, updater, context]);
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Update one data entry in a database.
|
|
90
|
-
*/
|
|
91
|
-
async updateOne(collection, search, updater, context = {}) {
|
|
92
|
-
return await this._request("updateOne", [collection, search, updater, context]);
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Remove data from a database.
|
|
96
|
-
*/
|
|
97
|
-
async remove(collection, search, context = {}) {
|
|
98
|
-
return await this._request("remove", [collection, search, context]);
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Remove one data entry from a database.
|
|
102
|
-
*/
|
|
103
|
-
async removeOne(collection, search, context = {}) {
|
|
104
|
-
return await this._request("removeOne", [collection, search, context]);
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Asynchronously updates one entry in a database or adds a new one if it doesn't exist.
|
|
108
|
-
*/
|
|
109
|
-
async updateOneOrAdd(collection, search, arg, add_arg = {}, context = {}, id_gen = true) {
|
|
110
|
-
return await this._request("updateOneOrAdd", [collection, search, arg, add_arg, context, id_gen]);
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Removes a database collection from the file system.
|
|
114
|
-
*/
|
|
115
|
-
async removeCollection(name) {
|
|
116
|
-
return await this._request("removeCollection", [name]);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
exports.default = DataBaseRemote;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
function serializeFunctions(data) {
|
|
4
|
-
const functionKeys = [];
|
|
5
|
-
function convertFunctionToString(fn) {
|
|
6
|
-
return typeof fn === "function" ? fn.toString() : fn;
|
|
7
|
-
}
|
|
8
|
-
function traverseAndSerialize(obj, path = "") {
|
|
9
|
-
Object.keys(obj).forEach((key) => {
|
|
10
|
-
const value = obj[key];
|
|
11
|
-
const fullPath = path ? `${path}.${key.replace(/\./g, "[dot]")}` : key;
|
|
12
|
-
if (typeof value === "function") {
|
|
13
|
-
functionKeys.push(fullPath);
|
|
14
|
-
obj[key] = convertFunctionToString(value);
|
|
15
|
-
}
|
|
16
|
-
else if (Array.isArray(value)) {
|
|
17
|
-
value.forEach((item, index) => {
|
|
18
|
-
if (typeof item === "function") {
|
|
19
|
-
functionKeys.push(`${fullPath}[${index}]`);
|
|
20
|
-
value[index] = convertFunctionToString(item);
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
else if (typeof value === "object" && value !== null) {
|
|
25
|
-
traverseAndSerialize(value, fullPath);
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
traverseAndSerialize(data);
|
|
30
|
-
return { data, keys: functionKeys };
|
|
31
|
-
}
|
|
32
|
-
exports.default = serializeFunctions;
|
package/dist/cjs/client/graph.js
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const ky_1 = __importDefault(require("ky"));
|
|
7
|
-
/**
|
|
8
|
-
* A class representing a graph database.
|
|
9
|
-
* Uses a remote database.
|
|
10
|
-
* @class
|
|
11
|
-
*/
|
|
12
|
-
class GraphRemote {
|
|
13
|
-
remote;
|
|
14
|
-
/**
|
|
15
|
-
* Create a new database instance.
|
|
16
|
-
*/
|
|
17
|
-
constructor(remote) {
|
|
18
|
-
this.remote = remote;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Make a request to the remote database.
|
|
22
|
-
*/
|
|
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,
|
|
30
|
-
headers: {
|
|
31
|
-
"Authorization": this.remote.auth
|
|
32
|
-
},
|
|
33
|
-
throwHttpErrors: false
|
|
34
|
-
}).json();
|
|
35
|
-
if (res.err)
|
|
36
|
-
throw new Error(res.msg);
|
|
37
|
-
return res.result;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Adds an edge between two nodes.
|
|
41
|
-
*/
|
|
42
|
-
async add(collection, nodeA, nodeB) {
|
|
43
|
-
return await this._request("add", [collection, nodeA, nodeB]);
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Removes an edge between two nodes.
|
|
47
|
-
*/
|
|
48
|
-
async remove(collection, nodeA, nodeB) {
|
|
49
|
-
return await this._request("remove", [collection, nodeA, nodeB]);
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Finds all edges with either node equal to `node`.
|
|
53
|
-
*/
|
|
54
|
-
async find(collection, node) {
|
|
55
|
-
return await this._request("find", [collection, node]);
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Finds one edge with either node equal to `nodeA` and the other equal to `nodeB`.
|
|
59
|
-
*/
|
|
60
|
-
async findOne(collection, nodeA, nodeB) {
|
|
61
|
-
return await this._request("findOne", [collection, nodeA, nodeB]);
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Get all edges in the collection.
|
|
65
|
-
*/
|
|
66
|
-
async getAll(collection) {
|
|
67
|
-
return await this._request("getAll", [collection]);
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Get the names of all available databases.
|
|
71
|
-
*/
|
|
72
|
-
async getCollections() {
|
|
73
|
-
return await this._request("getCollections", []);
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Check and create the specified collection if it doesn't exist.
|
|
77
|
-
*/
|
|
78
|
-
async checkCollection(collection) {
|
|
79
|
-
return await this._request("checkCollection", [collection]);
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Check if a collection exists.
|
|
83
|
-
*/
|
|
84
|
-
async issetCollection(collection) {
|
|
85
|
-
return await this._request("issetCollection", [collection]);
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Remove the specified collection.
|
|
89
|
-
*/
|
|
90
|
-
removeCollection(collection) {
|
|
91
|
-
return this._request("removeCollection", [collection]);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
exports.default = GraphRemote;
|
package/dist/cjs/database.js
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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
|
-
const file_1 = __importDefault(require("./file/index.js"));
|
|
10
|
-
/**
|
|
11
|
-
* Represents a database management class for performing CRUD operations.
|
|
12
|
-
* @class
|
|
13
|
-
*/
|
|
14
|
-
class DataBase {
|
|
15
|
-
dbAction;
|
|
16
|
-
executor;
|
|
17
|
-
constructor(folder, options = {}, fileCpu) {
|
|
18
|
-
if (!fileCpu)
|
|
19
|
-
fileCpu = file_1.default;
|
|
20
|
-
this.dbAction = new action_1.default(folder, options, fileCpu);
|
|
21
|
-
this.executor = new executor_1.default();
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Create a new instance of a CollectionManager class.
|
|
25
|
-
*/
|
|
26
|
-
c(collection) {
|
|
27
|
-
return new CollectionManager_1.default(this, collection);
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Get the names of all available databases.
|
|
31
|
-
*/
|
|
32
|
-
async getCollections() {
|
|
33
|
-
return await this.dbAction.getCollections();
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Check and create the specified collection if it doesn't exist.
|
|
37
|
-
*/
|
|
38
|
-
async checkCollection(collection) {
|
|
39
|
-
await this.dbAction.checkCollection(collection);
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Check if a collection exists.
|
|
43
|
-
*/
|
|
44
|
-
async issetCollection(collection) {
|
|
45
|
-
return await this.dbAction.issetCollection(collection);
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Add data to a database.
|
|
49
|
-
*/
|
|
50
|
-
async add(collection, data, id_gen = true) {
|
|
51
|
-
return await this.executor.addOp(this.dbAction.add.bind(this.dbAction), collection, data, id_gen);
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Find data in a database.
|
|
55
|
-
*/
|
|
56
|
-
async find(collection, search, context = {}, options = {}, findOpts = {}) {
|
|
57
|
-
return await this.executor.addOp(this.dbAction.find.bind(this.dbAction), collection, search, context, options, findOpts);
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Find one data entry in a database.
|
|
61
|
-
*/
|
|
62
|
-
async findOne(collection, search, context = {}, findOpts = {}) {
|
|
63
|
-
return await this.executor.addOp(this.dbAction.findOne.bind(this.dbAction), collection, search, context, findOpts);
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Update data in a database.
|
|
67
|
-
*/
|
|
68
|
-
async update(collection, search, updater, context = {}) {
|
|
69
|
-
return await this.executor.addOp(this.dbAction.update.bind(this.dbAction), collection, search, updater, context);
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Update one data entry in a database.
|
|
73
|
-
*/
|
|
74
|
-
async updateOne(collection, search, updater, context = {}) {
|
|
75
|
-
return await this.executor.addOp(this.dbAction.updateOne.bind(this.dbAction), collection, search, updater, context);
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Remove data from a database.
|
|
79
|
-
*/
|
|
80
|
-
async remove(collection, search, context = {}) {
|
|
81
|
-
return await this.executor.addOp(this.dbAction.remove.bind(this.dbAction), collection, search, context);
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Remove one data entry from a database.
|
|
85
|
-
*/
|
|
86
|
-
async removeOne(collection, search, context = {}) {
|
|
87
|
-
return await this.executor.addOp(this.dbAction.removeOne.bind(this.dbAction), collection, search, context);
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Asynchronously updates one entry in a database or adds a new one if it doesn't exist.
|
|
91
|
-
*/
|
|
92
|
-
async updateOneOrAdd(collection, search, updater, add_arg = {}, context = {}, id_gen = true) {
|
|
93
|
-
const res = await this.updateOne(collection, search, updater, context);
|
|
94
|
-
if (!res) {
|
|
95
|
-
const assignData = [];
|
|
96
|
-
if (typeof search === "object" && !Array.isArray(search))
|
|
97
|
-
assignData.push(search);
|
|
98
|
-
if (typeof updater === "object" && !Array.isArray(updater))
|
|
99
|
-
assignData.push(updater);
|
|
100
|
-
if (typeof add_arg === "object" && !Array.isArray(add_arg))
|
|
101
|
-
assignData.push(add_arg);
|
|
102
|
-
await this.add(collection, Object.assign({}, ...assignData), id_gen);
|
|
103
|
-
}
|
|
104
|
-
return res;
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Removes a database collection from the file system.
|
|
108
|
-
*/
|
|
109
|
-
async removeCollection(collection) {
|
|
110
|
-
await this.dbAction.removeCollection(collection);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
exports.default = DataBase;
|