@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/dist/cjs/executor.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
/**
|
|
4
|
-
* A simple executor for queuing and executing asynchronous operations sequentially.
|
|
5
|
-
* @class
|
|
6
|
-
*/
|
|
7
|
-
class executorC {
|
|
8
|
-
quote;
|
|
9
|
-
isExecuting;
|
|
10
|
-
/**
|
|
11
|
-
* Create a new executor instance.
|
|
12
|
-
* @constructor
|
|
13
|
-
*/
|
|
14
|
-
constructor() {
|
|
15
|
-
this.quote = [];
|
|
16
|
-
this.isExecuting = false;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Add an asynchronous operation to the execution queue.
|
|
20
|
-
*/
|
|
21
|
-
async addOp(func, ...param) {
|
|
22
|
-
return await new Promise((resolve, reject) => {
|
|
23
|
-
this.quote.push({
|
|
24
|
-
func,
|
|
25
|
-
param,
|
|
26
|
-
resolve,
|
|
27
|
-
reject
|
|
28
|
-
});
|
|
29
|
-
this.execute();
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Execute the queued asynchronous operations sequentially.
|
|
34
|
-
*/
|
|
35
|
-
async execute() {
|
|
36
|
-
if (this.isExecuting)
|
|
37
|
-
return;
|
|
38
|
-
this.isExecuting = true;
|
|
39
|
-
while (this.quote.length > 0) {
|
|
40
|
-
let q = this.quote.shift();
|
|
41
|
-
let res = await q.func(...q.param);
|
|
42
|
-
q.resolve(res);
|
|
43
|
-
}
|
|
44
|
-
this.isExecuting = false;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
exports.default = executorC;
|
|
@@ -1,79 +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 hasFieldsAdvanced_1 = __importDefault(require("../utils/hasFieldsAdvanced.js"));
|
|
7
|
-
const updateFindObject_1 = __importDefault(require("../utils/updateFindObject.js"));
|
|
8
|
-
const utils_1 = require("./utils.js");
|
|
9
|
-
class CustomFileCpu {
|
|
10
|
-
_readFile;
|
|
11
|
-
_writeFile;
|
|
12
|
-
constructor(readFile, writeFile) {
|
|
13
|
-
this._readFile = readFile;
|
|
14
|
-
this._writeFile = writeFile;
|
|
15
|
-
}
|
|
16
|
-
async add(file, data) {
|
|
17
|
-
file = (0, utils_1.pathRepair)(file);
|
|
18
|
-
let entries = await this._readFile(file);
|
|
19
|
-
entries.push(data);
|
|
20
|
-
await this._writeFile(file, entries);
|
|
21
|
-
}
|
|
22
|
-
async addMany(file, data) {
|
|
23
|
-
file = (0, utils_1.pathRepair)(file);
|
|
24
|
-
let entries = await this._readFile(file);
|
|
25
|
-
entries = entries.concat(data);
|
|
26
|
-
await this._writeFile(file, entries);
|
|
27
|
-
}
|
|
28
|
-
async find(file, arg, context = {}, findOpts = {}) {
|
|
29
|
-
file = (0, utils_1.pathRepair)(file);
|
|
30
|
-
const entries = await this._readFile(file);
|
|
31
|
-
const results = entries.filter(entry => typeof arg === "function" ? arg(entry, context) : (0, hasFieldsAdvanced_1.default)(entry, arg));
|
|
32
|
-
return results.length ? results.map(res => (0, updateFindObject_1.default)(res, findOpts)) : false;
|
|
33
|
-
}
|
|
34
|
-
async findOne(file, arg, context = {}, findOpts = {}) {
|
|
35
|
-
file = (0, utils_1.pathRepair)(file);
|
|
36
|
-
const entries = await this._readFile(file);
|
|
37
|
-
const result = entries.find(entry => typeof arg === "function" ? arg(entry, context) : (0, hasFieldsAdvanced_1.default)(entry, arg));
|
|
38
|
-
return result ? (0, updateFindObject_1.default)(result, findOpts) : false;
|
|
39
|
-
}
|
|
40
|
-
async remove(file, one, arg, context = {}) {
|
|
41
|
-
file = (0, utils_1.pathRepair)(file);
|
|
42
|
-
let entries = await this._readFile(file);
|
|
43
|
-
let removed = false;
|
|
44
|
-
entries = entries.filter(entry => {
|
|
45
|
-
if (removed && one)
|
|
46
|
-
return true;
|
|
47
|
-
let match = typeof arg === "function" ? arg(entry, context) : (0, hasFieldsAdvanced_1.default)(entry, arg);
|
|
48
|
-
if (match) {
|
|
49
|
-
removed = true;
|
|
50
|
-
return false;
|
|
51
|
-
}
|
|
52
|
-
return true;
|
|
53
|
-
});
|
|
54
|
-
if (!removed)
|
|
55
|
-
return false;
|
|
56
|
-
await this._writeFile(file, entries);
|
|
57
|
-
return true;
|
|
58
|
-
}
|
|
59
|
-
async update(file, one, arg, updater, context = {}) {
|
|
60
|
-
file = (0, utils_1.pathRepair)(file);
|
|
61
|
-
let entries = await this._readFile(file);
|
|
62
|
-
let updated = false;
|
|
63
|
-
entries = entries.map(entry => {
|
|
64
|
-
if (updated && one)
|
|
65
|
-
return entry;
|
|
66
|
-
let match = typeof arg === "function" ? arg(entry, context) : (0, hasFieldsAdvanced_1.default)(entry, arg);
|
|
67
|
-
if (match) {
|
|
68
|
-
updated = true;
|
|
69
|
-
return typeof updater === "function" ? updater(entry, context) : { ...entry, ...updater };
|
|
70
|
-
}
|
|
71
|
-
return entry;
|
|
72
|
-
});
|
|
73
|
-
if (!updated)
|
|
74
|
-
return false;
|
|
75
|
-
await this._writeFile(file, entries);
|
|
76
|
-
return true;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
exports.default = CustomFileCpu;
|
package/dist/cjs/file/find.js
DELETED
|
@@ -1,80 +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
|
-
exports.find = find;
|
|
7
|
-
exports.findOne = findOne;
|
|
8
|
-
const fs_1 = require("fs");
|
|
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
|
-
/**
|
|
14
|
-
* Processes a line of text from a file and checks if it matches the search criteria.
|
|
15
|
-
*/
|
|
16
|
-
async function findProcesLine(arg, line, context = {}, findOpts = {}) {
|
|
17
|
-
const ob = (0, format_1.parse)(line);
|
|
18
|
-
let res = false;
|
|
19
|
-
if (typeof arg === "function") {
|
|
20
|
-
if (arg(ob, context))
|
|
21
|
-
res = true;
|
|
22
|
-
}
|
|
23
|
-
else if (typeof arg === "object" && !Array.isArray(arg)) {
|
|
24
|
-
if ((0, hasFieldsAdvanced_1.default)(ob, arg))
|
|
25
|
-
res = true;
|
|
26
|
-
}
|
|
27
|
-
if (res)
|
|
28
|
-
return (0, updateFindObject_1.default)(ob, findOpts);
|
|
29
|
-
return null;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Asynchronously finds entries in a file based on search criteria.
|
|
33
|
-
*/
|
|
34
|
-
async function find(file, arg, context = {}, findOpts = {}) {
|
|
35
|
-
file = (0, utils_1.pathRepair)(file);
|
|
36
|
-
return await new Promise(async (resolve) => {
|
|
37
|
-
if (!(0, fs_1.existsSync)(file)) {
|
|
38
|
-
await fs_1.promises.writeFile(file, "");
|
|
39
|
-
resolve(false);
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
const rl = (0, utils_1.createRL)(file);
|
|
43
|
-
const resF = [];
|
|
44
|
-
for await (const line of rl) {
|
|
45
|
-
if (line == "" || !line)
|
|
46
|
-
continue;
|
|
47
|
-
const res = await findProcesLine(arg, line, context, findOpts);
|
|
48
|
-
if (res)
|
|
49
|
-
resF.push(res);
|
|
50
|
-
}
|
|
51
|
-
;
|
|
52
|
-
resolve(resF);
|
|
53
|
-
rl.close();
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Asynchronously finds one entry in a file based on search criteria.
|
|
58
|
-
*/
|
|
59
|
-
async function findOne(file, arg, context = {}, findOpts = {}) {
|
|
60
|
-
file = (0, utils_1.pathRepair)(file);
|
|
61
|
-
return await new Promise(async (resolve) => {
|
|
62
|
-
if (!(0, fs_1.existsSync)(file)) {
|
|
63
|
-
await fs_1.promises.writeFile(file, "");
|
|
64
|
-
resolve(false);
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
const rl = (0, utils_1.createRL)(file);
|
|
68
|
-
for await (const line of rl) {
|
|
69
|
-
if (line == "" || !line)
|
|
70
|
-
continue;
|
|
71
|
-
const res = await findProcesLine(arg, line, context, findOpts);
|
|
72
|
-
if (res) {
|
|
73
|
-
resolve(res);
|
|
74
|
-
rl.close();
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
;
|
|
78
|
-
resolve(false);
|
|
79
|
-
});
|
|
80
|
-
}
|
package/dist/cjs/file/index.js
DELETED
|
@@ -1,21 +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 update_1 = __importDefault(require("./update.js"));
|
|
7
|
-
const remove_1 = __importDefault(require("./remove.js"));
|
|
8
|
-
const find_1 = require("./find.js");
|
|
9
|
-
const fs_1 = require("fs");
|
|
10
|
-
const format_1 = require("../format.js");
|
|
11
|
-
const vFileCpu = {
|
|
12
|
-
add: async (file, data) => {
|
|
13
|
-
const dataString = (0, format_1.stringify)(data);
|
|
14
|
-
(0, fs_1.appendFileSync)(file, dataString + "\n");
|
|
15
|
-
},
|
|
16
|
-
find: find_1.find,
|
|
17
|
-
findOne: find_1.findOne,
|
|
18
|
-
update: update_1.default,
|
|
19
|
-
remove: remove_1.default
|
|
20
|
-
};
|
|
21
|
-
exports.default = vFileCpu;
|
package/dist/cjs/file/remove.js
DELETED
|
@@ -1,46 +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 fs_1 = require("fs");
|
|
7
|
-
const utils_1 = require("./utils.js");
|
|
8
|
-
const format_1 = require("../format.js");
|
|
9
|
-
const hasFieldsAdvanced_1 = __importDefault(require("../utils/hasFieldsAdvanced.js"));
|
|
10
|
-
/**
|
|
11
|
-
* Removes entries from a file based on search criteria.
|
|
12
|
-
*/
|
|
13
|
-
async function removeWorker(file, one, search, context = {}) {
|
|
14
|
-
file = (0, utils_1.pathRepair)(file);
|
|
15
|
-
if (!(0, fs_1.existsSync)(file)) {
|
|
16
|
-
await fs_1.promises.writeFile(file, "");
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
19
|
-
await fs_1.promises.copyFile(file, file + ".tmp");
|
|
20
|
-
await fs_1.promises.writeFile(file, "");
|
|
21
|
-
const rl = (0, utils_1.createRL)(file + ".tmp");
|
|
22
|
-
let removed = false;
|
|
23
|
-
for await (let line of rl) {
|
|
24
|
-
if (one && removed) {
|
|
25
|
-
(0, fs_1.appendFileSync)(file, line + "\n");
|
|
26
|
-
continue;
|
|
27
|
-
}
|
|
28
|
-
const data = (0, format_1.parse)(line);
|
|
29
|
-
if (typeof search === "function") {
|
|
30
|
-
if (search(data, context)) {
|
|
31
|
-
removed = true;
|
|
32
|
-
continue;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
else if (typeof search === "object" && !Array.isArray(search)) {
|
|
36
|
-
if ((0, hasFieldsAdvanced_1.default)(data, search)) {
|
|
37
|
-
removed = true;
|
|
38
|
-
continue;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
(0, fs_1.appendFileSync)(file, line + "\n");
|
|
42
|
-
}
|
|
43
|
-
await fs_1.promises.writeFile(file + ".tmp", "");
|
|
44
|
-
return removed;
|
|
45
|
-
}
|
|
46
|
-
exports.default = removeWorker;
|
package/dist/cjs/file/update.js
DELETED
|
@@ -1,55 +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 fs_1 = require("fs");
|
|
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
|
-
/**
|
|
12
|
-
* Updates a file based on search criteria and an updater function or object.
|
|
13
|
-
*/
|
|
14
|
-
async function updateWorker(file, one, search, updater, context = {}) {
|
|
15
|
-
file = (0, utils_1.pathRepair)(file);
|
|
16
|
-
if (!(0, fs_1.existsSync)(file)) {
|
|
17
|
-
await fs_1.promises.writeFile(file, "");
|
|
18
|
-
return false;
|
|
19
|
-
}
|
|
20
|
-
await fs_1.promises.copyFile(file, file + ".tmp");
|
|
21
|
-
await fs_1.promises.writeFile(file, "");
|
|
22
|
-
const rl = (0, utils_1.createRL)(file + ".tmp");
|
|
23
|
-
let updated = false;
|
|
24
|
-
for await (let line of rl) {
|
|
25
|
-
if (one && updated) {
|
|
26
|
-
await fs_1.promises.appendFile(file, line + "\n");
|
|
27
|
-
continue;
|
|
28
|
-
}
|
|
29
|
-
const data = (0, format_1.parse)(line);
|
|
30
|
-
let ob = false;
|
|
31
|
-
if (typeof search === "function") {
|
|
32
|
-
ob = search(data, context) || false;
|
|
33
|
-
}
|
|
34
|
-
else if (typeof search === "object" && !Array.isArray(search)) {
|
|
35
|
-
ob = (0, hasFieldsAdvanced_1.default)(data, search);
|
|
36
|
-
}
|
|
37
|
-
if (ob) {
|
|
38
|
-
let updateObj = data;
|
|
39
|
-
if (typeof updater === "function") {
|
|
40
|
-
const updateObjValue = updater(data, context);
|
|
41
|
-
if (updateObjValue)
|
|
42
|
-
updateObj = updateObjValue;
|
|
43
|
-
}
|
|
44
|
-
else if (typeof updater === "object" && !Array.isArray(updater)) {
|
|
45
|
-
updateObj = (0, updateObject_1.default)(data, updater);
|
|
46
|
-
}
|
|
47
|
-
line = await (0, format_1.stringify)(updateObj);
|
|
48
|
-
updated = true;
|
|
49
|
-
}
|
|
50
|
-
await fs_1.promises.appendFile(file, line + "\n");
|
|
51
|
-
}
|
|
52
|
-
await fs_1.promises.writeFile(file + ".tmp", "");
|
|
53
|
-
return updated;
|
|
54
|
-
}
|
|
55
|
-
exports.default = updateWorker;
|
package/dist/cjs/file/utils.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.pathRepair = pathRepair;
|
|
4
|
-
exports.createRL = createRL;
|
|
5
|
-
const fs_1 = require("fs");
|
|
6
|
-
const readline_1 = require("readline");
|
|
7
|
-
/**
|
|
8
|
-
* Repairs a file path by replacing double slashes
|
|
9
|
-
*/
|
|
10
|
-
function pathRepair(path) {
|
|
11
|
-
return path.replaceAll("//", "/");
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Creates a Readline interface for reading large files with a specified high water mark.
|
|
15
|
-
*/
|
|
16
|
-
function createRL(file) {
|
|
17
|
-
const read_stream = (0, fs_1.createReadStream)(file, { highWaterMark: 10 * 1024 * 1024 }); //10MB
|
|
18
|
-
const rl = (0, readline_1.createInterface)({
|
|
19
|
-
input: read_stream,
|
|
20
|
-
crlfDelay: Infinity
|
|
21
|
-
});
|
|
22
|
-
return rl;
|
|
23
|
-
}
|
package/dist/cjs/format.js
DELETED
|
@@ -1,30 +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
|
-
exports.parse = parse;
|
|
7
|
-
exports.stringify = stringify;
|
|
8
|
-
const json5_1 = __importDefault(require("json5"));
|
|
9
|
-
/**
|
|
10
|
-
* Parses given string into a JSON object. If the string does not start with
|
|
11
|
-
* a {, it is wrapped in one. This allows for a shorthand when
|
|
12
|
-
* storing/reading data from a file.
|
|
13
|
-
*/
|
|
14
|
-
function parse(data) {
|
|
15
|
-
if (!data.startsWith("{"))
|
|
16
|
-
data = "{" + data + "}";
|
|
17
|
-
return json5_1.default.parse(data);
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Converts given object to a string. If the string is a valid json5, it is
|
|
21
|
-
* returned as is. If it is a valid json5 wrapped in {}, the curly brackets
|
|
22
|
-
* are removed. Otherwise the string is wrapped in {}.
|
|
23
|
-
*/
|
|
24
|
-
function stringify(data) {
|
|
25
|
-
data = json5_1.default.stringify(data);
|
|
26
|
-
if (data.startsWith("{")) {
|
|
27
|
-
data = data.slice(1, -1);
|
|
28
|
-
}
|
|
29
|
-
return data;
|
|
30
|
-
}
|
package/dist/cjs/gen.js
DELETED
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = genId;
|
|
4
|
-
const usedIdsMap = new Map();
|
|
5
|
-
let lastId;
|
|
6
|
-
const recentIdsTimestamps = [];
|
|
7
|
-
let startIndex = 0;
|
|
8
|
-
let lastGeneratedMs = 0;
|
|
9
|
-
let lastRandomValue = 0;
|
|
10
|
-
/**
|
|
11
|
-
* Generates a unique random identifier based on time and parts.
|
|
12
|
-
*
|
|
13
|
-
* @param {number[]} [parts] - an array of lengths of parts of the identifier
|
|
14
|
-
* @returns {Id} - a new unique identifier
|
|
15
|
-
*/
|
|
16
|
-
function genId(parts = null) {
|
|
17
|
-
if (parts === null)
|
|
18
|
-
parts = [1, 1];
|
|
19
|
-
const time = getTime();
|
|
20
|
-
const id = getUniqueRandom({
|
|
21
|
-
time,
|
|
22
|
-
partsSchema: parts,
|
|
23
|
-
s: 0,
|
|
24
|
-
});
|
|
25
|
-
return id;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Generates a unique random identifier based on time and parts.
|
|
29
|
-
*/
|
|
30
|
-
function getUniqueRandom(opts) {
|
|
31
|
-
while (true) {
|
|
32
|
-
let minValue = 0;
|
|
33
|
-
if (lastId) {
|
|
34
|
-
const parts = lastId.split("-");
|
|
35
|
-
const lastTime = parts.shift();
|
|
36
|
-
if (lastTime === opts.time) {
|
|
37
|
-
const int36 = parts.join("");
|
|
38
|
-
minValue = parseInt(int36, 36) + 1;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
const partsLengthSum = opts.partsSchema.reduce((acc, num) => acc + num, 0);
|
|
42
|
-
const partsData = generateBase36InRange(minValue, partsLengthSum);
|
|
43
|
-
const parts = splitStringByArray(opts.partsSchema, partsData);
|
|
44
|
-
const id = [opts.time, ...parts].join("-");
|
|
45
|
-
if (!usedIdsMap.has(id)) {
|
|
46
|
-
usedIdsMap.set(id, true);
|
|
47
|
-
setTimeout(() => usedIdsMap.delete(id), 1000);
|
|
48
|
-
lastId = id;
|
|
49
|
-
return id;
|
|
50
|
-
}
|
|
51
|
-
opts.s++;
|
|
52
|
-
if (opts.s >= partsLengthSum) {
|
|
53
|
-
opts.time = getTime();
|
|
54
|
-
opts.s = 0;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Tracks the current load of the application by counting the number of ids that have been generated in the last second.
|
|
60
|
-
* @returns The number of ids that have been generated in the last second.
|
|
61
|
-
*/
|
|
62
|
-
function trackLoad() {
|
|
63
|
-
const now = Date.now();
|
|
64
|
-
recentIdsTimestamps.push(now);
|
|
65
|
-
while (startIndex < recentIdsTimestamps.length && recentIdsTimestamps[startIndex] < now - 1) {
|
|
66
|
-
startIndex++;
|
|
67
|
-
}
|
|
68
|
-
return recentIdsTimestamps.length - startIndex;
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Generates a base-36 encoded string with a specified length based on a random value within a range.
|
|
72
|
-
*
|
|
73
|
-
* The function calculates a random value within the base-36 range determined by the provided
|
|
74
|
-
* `minValue` and `length`. It uses a bias mechanism to adjust the randomness based on the
|
|
75
|
-
* current load, ensuring unique generation over short periods. If the system load is low or
|
|
76
|
-
* the current millisecond has changed, a new random value is generated. Otherwise, the random
|
|
77
|
-
* value is incremented by a small amount with certain probabilities.
|
|
78
|
-
*
|
|
79
|
-
* @param minValue - The minimum value for the base-36 encoded number.
|
|
80
|
-
* @param length - The length of the resulting base-36 string.
|
|
81
|
-
* @returns A base-36 encoded string representation of the random value, padded to the specified length.
|
|
82
|
-
*/
|
|
83
|
-
function generateBase36InRange(minValue, length) {
|
|
84
|
-
const maxValue = Math.pow(36, length) - 1;
|
|
85
|
-
const load = trackLoad();
|
|
86
|
-
const currentMs = Date.now();
|
|
87
|
-
if (load < 3 || currentMs !== lastGeneratedMs) {
|
|
88
|
-
lastRandomValue = biasedRandomInRange(minValue, maxValue);
|
|
89
|
-
lastGeneratedMs = currentMs;
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
const rand = Math.random();
|
|
93
|
-
if (rand < 0.6) {
|
|
94
|
-
lastRandomValue += 1;
|
|
95
|
-
}
|
|
96
|
-
else if (rand < 0.9) {
|
|
97
|
-
lastRandomValue += 2;
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
lastRandomValue = biasedRandomInRange(lastRandomValue, maxValue);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
return lastRandomValue.toString(36).padStart(length, "0");
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Generates a random number between the specified range, but with a bias towards the lower
|
|
107
|
-
* end of the range. The bias is calculated as the cube root of the random value, which
|
|
108
|
-
* will make the random value more likely to be closer to the minimum value.
|
|
109
|
-
* @param min - The minimum value of the range.
|
|
110
|
-
* @param max - The maximum value of the range.
|
|
111
|
-
* @returns A random number between the specified range, with a bias towards the lower end.
|
|
112
|
-
*/
|
|
113
|
-
function biasedRandomInRange(min, max) {
|
|
114
|
-
let randomValue = min;
|
|
115
|
-
const bias = Math.pow(Math.random(), 3);
|
|
116
|
-
randomValue = Math.floor(min + (max - min) * bias);
|
|
117
|
-
return Math.min(randomValue, max);
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* Splits a string into an array of substrings, where each substring is determined by
|
|
121
|
-
* the values in the provided array.
|
|
122
|
-
*
|
|
123
|
-
* @param arr - An array of numbers, where each number represents the length of a substring.
|
|
124
|
-
* @param str - The string to split.
|
|
125
|
-
* @returns An array of substrings, where each element is a substring of the original string,
|
|
126
|
-
* determined by the corresponding element in the provided array.
|
|
127
|
-
*/
|
|
128
|
-
function splitStringByArray(arr, str) {
|
|
129
|
-
let start = 0;
|
|
130
|
-
return arr.map(length => str.slice(start, start += length));
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Gets the current time in a base36 string format.
|
|
134
|
-
*/
|
|
135
|
-
function getTime() {
|
|
136
|
-
return new Date().getTime().toString(36);
|
|
137
|
-
}
|
package/dist/cjs/graph.js
DELETED
|
@@ -1,90 +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 database_1 = __importDefault(require("./database.js"));
|
|
7
|
-
/**
|
|
8
|
-
* A class representing a graph database.
|
|
9
|
-
* @class
|
|
10
|
-
*/
|
|
11
|
-
class Graph {
|
|
12
|
-
db;
|
|
13
|
-
constructor(databaseFolder) {
|
|
14
|
-
this.db = new database_1.default(databaseFolder);
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Adds an edge between two nodes.
|
|
18
|
-
*/
|
|
19
|
-
async add(collection, nodeA, nodeB) {
|
|
20
|
-
const sortedNodes = [nodeA, nodeB].sort();
|
|
21
|
-
return await this.db.add(collection, {
|
|
22
|
-
a: sortedNodes[0],
|
|
23
|
-
b: sortedNodes[1]
|
|
24
|
-
}, false);
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Removes an edge between two nodes.
|
|
28
|
-
*/
|
|
29
|
-
async remove(collection, nodeA, nodeB) {
|
|
30
|
-
const sortedNodes = [nodeA, nodeB].sort();
|
|
31
|
-
const query = { a: sortedNodes[0], b: sortedNodes[1] };
|
|
32
|
-
return await this.db.removeOne(collection, query);
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Finds all edges with either node equal to `node`.
|
|
36
|
-
*/
|
|
37
|
-
async find(collection, node) {
|
|
38
|
-
const edges = [];
|
|
39
|
-
const edgesByANode = await this.db.find(collection, { a: node });
|
|
40
|
-
const edgesByBNode = await this.db.find(collection, { b: node });
|
|
41
|
-
if (edgesByANode)
|
|
42
|
-
edges.push(...edgesByANode);
|
|
43
|
-
if (edgesByBNode)
|
|
44
|
-
edges.push(...edgesByBNode);
|
|
45
|
-
return edges;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Finds one edge with either node equal to `nodeA` and the other equal to `nodeB`.
|
|
49
|
-
*/
|
|
50
|
-
async findOne(collection, nodeA, nodeB) {
|
|
51
|
-
const edgeAB = await this.db.findOne(collection, { a: nodeA, b: nodeB });
|
|
52
|
-
if (edgeAB)
|
|
53
|
-
return edgeAB;
|
|
54
|
-
const edgeBA = await this.db.findOne(collection, { a: nodeB, b: nodeA });
|
|
55
|
-
if (edgeBA)
|
|
56
|
-
return edgeBA;
|
|
57
|
-
return null;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Gets all edges in the database.
|
|
61
|
-
*/
|
|
62
|
-
async getAll(collection) {
|
|
63
|
-
return await this.db.find(collection, {});
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Get the names of all available databases.
|
|
67
|
-
*/
|
|
68
|
-
async getCollections() {
|
|
69
|
-
return await this.db.getCollections();
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Check and create the specified collection if it doesn't exist.
|
|
73
|
-
*/
|
|
74
|
-
async checkCollection(collection) {
|
|
75
|
-
await this.db.checkCollection(collection);
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Check if a collection exists.
|
|
79
|
-
*/
|
|
80
|
-
async issetCollection(collection) {
|
|
81
|
-
return await this.db.issetCollection(collection);
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Removes a database collection from the file system.
|
|
85
|
-
*/
|
|
86
|
-
removeCollection(collection) {
|
|
87
|
-
this.db.removeCollection(collection);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
exports.default = Graph;
|
package/dist/cjs/index.js
DELETED
|
@@ -1,20 +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
|
-
exports.CustomFileCpu = exports.genId = exports.Relation = exports.GraphRemote = exports.DataBaseRemote = exports.Graph = exports.DataBase = void 0;
|
|
7
|
-
const database_1 = __importDefault(require("./database.js"));
|
|
8
|
-
exports.DataBase = database_1.default;
|
|
9
|
-
const graph_1 = __importDefault(require("./graph.js"));
|
|
10
|
-
exports.Graph = graph_1.default;
|
|
11
|
-
const database_2 = __importDefault(require("./client/database.js"));
|
|
12
|
-
exports.DataBaseRemote = database_2.default;
|
|
13
|
-
const graph_2 = __importDefault(require("./client/graph.js"));
|
|
14
|
-
exports.GraphRemote = graph_2.default;
|
|
15
|
-
const gen_1 = __importDefault(require("./gen.js"));
|
|
16
|
-
exports.genId = gen_1.default;
|
|
17
|
-
const relation_1 = __importDefault(require("./relation.js"));
|
|
18
|
-
exports.Relation = relation_1.default;
|
|
19
|
-
const customFileCpu_1 = __importDefault(require("./file/customFileCpu.js"));
|
|
20
|
-
exports.CustomFileCpu = customFileCpu_1.default;
|