@wxn0brp/db 0.1.1 → 0.1.2
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.
|
@@ -13,7 +13,9 @@ declare class CustomFileCpu implements FileCpu {
|
|
|
13
13
|
addMany(file: string, data: Data[]): Promise<void>;
|
|
14
14
|
find(file: string, arg: Search, context?: Context, findOpts?: FindOpts): Promise<any[] | false>;
|
|
15
15
|
findOne(file: string, arg: Search, context?: Context, findOpts?: FindOpts): Promise<any | false>;
|
|
16
|
+
removeWorker(file: string, arg: Search, context?: Context, one?: boolean): Promise<boolean>;
|
|
16
17
|
remove(cpath: string, arg: Search, context?: Context, one?: boolean): Promise<boolean>;
|
|
18
|
+
updateWorker(file: string, arg: Search, updater: Updater, context?: Context, one?: boolean): Promise<boolean>;
|
|
17
19
|
update(cpath: string, arg: Search, updater: Updater, context?: Context, one?: boolean): Promise<boolean>;
|
|
18
20
|
}
|
|
19
21
|
export default CustomFileCpu;
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const hasFieldsAdvanced_1 = __importDefault(require("../utils/hasFieldsAdvanced.js"));
|
|
7
7
|
const updateFindObject_1 = __importDefault(require("../utils/updateFindObject.js"));
|
|
8
8
|
const utils_1 = require("./utils.js");
|
|
9
|
+
const fs_1 = require("fs");
|
|
9
10
|
class CustomFileCpu {
|
|
10
11
|
_readFile;
|
|
11
12
|
_writeFile;
|
|
@@ -37,8 +38,8 @@ class CustomFileCpu {
|
|
|
37
38
|
const result = entries.find(entry => typeof arg === "function" ? arg(entry, context) : (0, hasFieldsAdvanced_1.default)(entry, arg));
|
|
38
39
|
return result ? (0, updateFindObject_1.default)(result, findOpts) : false;
|
|
39
40
|
}
|
|
40
|
-
async
|
|
41
|
-
|
|
41
|
+
async removeWorker(file, arg, context = {}, one = false) {
|
|
42
|
+
file = (0, utils_1.pathRepair)(file);
|
|
42
43
|
let entries = await this._readFile(file);
|
|
43
44
|
let removed = false;
|
|
44
45
|
entries = entries.filter(entry => {
|
|
@@ -56,8 +57,20 @@ class CustomFileCpu {
|
|
|
56
57
|
await this._writeFile(file, entries);
|
|
57
58
|
return true;
|
|
58
59
|
}
|
|
59
|
-
async
|
|
60
|
-
|
|
60
|
+
async remove(cpath, arg, context = {}, one = false) {
|
|
61
|
+
let files = (0, fs_1.readdirSync)(cpath).filter(file => !/\.tmp$/.test(file));
|
|
62
|
+
files.reverse();
|
|
63
|
+
let remove = false;
|
|
64
|
+
for (const file of files) {
|
|
65
|
+
const removed = await this.removeWorker(cpath + file, arg, context, one);
|
|
66
|
+
if (one && removed)
|
|
67
|
+
break;
|
|
68
|
+
remove = remove || removed;
|
|
69
|
+
}
|
|
70
|
+
return remove;
|
|
71
|
+
}
|
|
72
|
+
async updateWorker(file, arg, updater, context = {}, one = false) {
|
|
73
|
+
file = (0, utils_1.pathRepair)(file);
|
|
61
74
|
let entries = await this._readFile(file);
|
|
62
75
|
let updated = false;
|
|
63
76
|
entries = entries.map(entry => {
|
|
@@ -75,5 +88,17 @@ class CustomFileCpu {
|
|
|
75
88
|
await this._writeFile(file, entries);
|
|
76
89
|
return true;
|
|
77
90
|
}
|
|
91
|
+
async update(cpath, arg, updater, context = {}, one = false) {
|
|
92
|
+
let files = (0, fs_1.readdirSync)(cpath).filter(file => !/\.tmp$/.test(file));
|
|
93
|
+
files.reverse();
|
|
94
|
+
let update = false;
|
|
95
|
+
for (const file of files) {
|
|
96
|
+
const updated = await this.updateWorker(cpath + file, arg, updater, context, one);
|
|
97
|
+
if (one && updated)
|
|
98
|
+
return true;
|
|
99
|
+
update = update || updated;
|
|
100
|
+
}
|
|
101
|
+
return update;
|
|
102
|
+
}
|
|
78
103
|
}
|
|
79
104
|
exports.default = CustomFileCpu;
|
|
@@ -13,7 +13,9 @@ declare class CustomFileCpu implements FileCpu {
|
|
|
13
13
|
addMany(file: string, data: Data[]): Promise<void>;
|
|
14
14
|
find(file: string, arg: Search, context?: Context, findOpts?: FindOpts): Promise<any[] | false>;
|
|
15
15
|
findOne(file: string, arg: Search, context?: Context, findOpts?: FindOpts): Promise<any | false>;
|
|
16
|
+
removeWorker(file: string, arg: Search, context?: Context, one?: boolean): Promise<boolean>;
|
|
16
17
|
remove(cpath: string, arg: Search, context?: Context, one?: boolean): Promise<boolean>;
|
|
18
|
+
updateWorker(file: string, arg: Search, updater: Updater, context?: Context, one?: boolean): Promise<boolean>;
|
|
17
19
|
update(cpath: string, arg: Search, updater: Updater, context?: Context, one?: boolean): Promise<boolean>;
|
|
18
20
|
}
|
|
19
21
|
export default CustomFileCpu;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import hasFieldsAdvanced from "../utils/hasFieldsAdvanced.js";
|
|
2
2
|
import updateFindObject from "../utils/updateFindObject.js";
|
|
3
3
|
import { pathRepair } from "./utils.js";
|
|
4
|
+
import { readdirSync } from "fs";
|
|
4
5
|
class CustomFileCpu {
|
|
5
6
|
_readFile;
|
|
6
7
|
_writeFile;
|
|
@@ -32,8 +33,8 @@ class CustomFileCpu {
|
|
|
32
33
|
const result = entries.find(entry => typeof arg === "function" ? arg(entry, context) : hasFieldsAdvanced(entry, arg));
|
|
33
34
|
return result ? updateFindObject(result, findOpts) : false;
|
|
34
35
|
}
|
|
35
|
-
async
|
|
36
|
-
|
|
36
|
+
async removeWorker(file, arg, context = {}, one = false) {
|
|
37
|
+
file = pathRepair(file);
|
|
37
38
|
let entries = await this._readFile(file);
|
|
38
39
|
let removed = false;
|
|
39
40
|
entries = entries.filter(entry => {
|
|
@@ -51,8 +52,20 @@ class CustomFileCpu {
|
|
|
51
52
|
await this._writeFile(file, entries);
|
|
52
53
|
return true;
|
|
53
54
|
}
|
|
54
|
-
async
|
|
55
|
-
|
|
55
|
+
async remove(cpath, arg, context = {}, one = false) {
|
|
56
|
+
let files = readdirSync(cpath).filter(file => !/\.tmp$/.test(file));
|
|
57
|
+
files.reverse();
|
|
58
|
+
let remove = false;
|
|
59
|
+
for (const file of files) {
|
|
60
|
+
const removed = await this.removeWorker(cpath + file, arg, context, one);
|
|
61
|
+
if (one && removed)
|
|
62
|
+
break;
|
|
63
|
+
remove = remove || removed;
|
|
64
|
+
}
|
|
65
|
+
return remove;
|
|
66
|
+
}
|
|
67
|
+
async updateWorker(file, arg, updater, context = {}, one = false) {
|
|
68
|
+
file = pathRepair(file);
|
|
56
69
|
let entries = await this._readFile(file);
|
|
57
70
|
let updated = false;
|
|
58
71
|
entries = entries.map(entry => {
|
|
@@ -70,5 +83,17 @@ class CustomFileCpu {
|
|
|
70
83
|
await this._writeFile(file, entries);
|
|
71
84
|
return true;
|
|
72
85
|
}
|
|
86
|
+
async update(cpath, arg, updater, context = {}, one = false) {
|
|
87
|
+
let files = readdirSync(cpath).filter(file => !/\.tmp$/.test(file));
|
|
88
|
+
files.reverse();
|
|
89
|
+
let update = false;
|
|
90
|
+
for (const file of files) {
|
|
91
|
+
const updated = await this.updateWorker(cpath + file, arg, updater, context, one);
|
|
92
|
+
if (one && updated)
|
|
93
|
+
return true;
|
|
94
|
+
update = update || updated;
|
|
95
|
+
}
|
|
96
|
+
return update;
|
|
97
|
+
}
|
|
73
98
|
}
|
|
74
99
|
export default CustomFileCpu;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wxn0brp/db",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"main": "dist/esm/index.js",
|
|
5
5
|
"types": "dist/esm/index.d.ts",
|
|
6
6
|
"description": "A simple file-based database management system with support for CRUD operations, custom queries, and graph structures.",
|
|
@@ -41,14 +41,14 @@
|
|
|
41
41
|
],
|
|
42
42
|
"exports": {
|
|
43
43
|
".": {
|
|
44
|
+
"types": "./dist/esm/index.d.ts",
|
|
44
45
|
"import": "./dist/esm/index.js",
|
|
45
|
-
"require": "./dist/cjs/index.js"
|
|
46
|
-
"types": "./dist/esm/index.d.ts"
|
|
46
|
+
"require": "./dist/cjs/index.js"
|
|
47
47
|
},
|
|
48
48
|
"./*": {
|
|
49
|
+
"types": "./dist/esm/*",
|
|
49
50
|
"import": "./dist/esm/*",
|
|
50
|
-
"require": "./dist/cjs/*"
|
|
51
|
-
"types": "./dist/esm/*"
|
|
51
|
+
"require": "./dist/cjs/*"
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
}
|