@wxn0brp/db 0.1.0 → 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.
- package/README.md +2 -2
- package/dist/cjs/action.d.ts +3 -1
- package/dist/cjs/action.js +10 -11
- package/dist/cjs/database.d.ts +2 -1
- package/dist/cjs/database.js +5 -2
- package/dist/cjs/file/customFileCpu.d.ts +21 -0
- package/dist/cjs/file/customFileCpu.js +104 -0
- package/dist/cjs/file/find.d.ts +2 -2
- package/dist/cjs/file/index.d.ts +3 -3
- package/dist/cjs/file/index.js +16 -20
- package/dist/cjs/index.d.ts +3 -2
- package/dist/cjs/index.js +3 -1
- package/dist/cjs/types/fileCpu.d.ts +51 -0
- package/dist/cjs/types/fileCpu.js +2 -0
- package/dist/esm/action.d.ts +3 -1
- package/dist/esm/action.js +11 -12
- package/dist/esm/database.d.ts +2 -1
- package/dist/esm/database.js +5 -2
- package/dist/esm/file/customFileCpu.d.ts +21 -0
- package/dist/esm/file/customFileCpu.js +99 -0
- package/dist/esm/file/find.d.ts +2 -2
- package/dist/esm/file/index.d.ts +3 -3
- package/dist/esm/file/index.js +16 -3
- package/dist/esm/index.d.ts +3 -2
- package/dist/esm/index.js +2 -1
- package/dist/esm/types/fileCpu.d.ts +51 -0
- package/dist/esm/types/fileCpu.js +1 -0
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# @wxn0brp/db
|
|
1
|
+
# ValtheraDB (@wxn0brp/db)
|
|
2
2
|
|
|
3
3
|
A lightweight file-based database management system that supports CRUD operations, custom queries, and graph structures.
|
|
4
4
|
|
|
@@ -20,7 +20,7 @@ import { DataBase, Graph, DataBaseRemote, GraphRemote, Relation, genId } from "@
|
|
|
20
20
|
|
|
21
21
|
## Documentation
|
|
22
22
|
|
|
23
|
-
Website: [https://wxn0brp.github.io/
|
|
23
|
+
Website: [https://wxn0brp.github.io/ValtheraDB/](https://wxn0brp.github.io/ValtheraDB/)
|
|
24
24
|
|
|
25
25
|
For detailed information, refer to the following resources:
|
|
26
26
|
|
package/dist/cjs/action.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { DbFindOpts, DbOpts, FindOpts } from "./types/options.js";
|
|
|
3
3
|
import { Context } from "./types/types.js";
|
|
4
4
|
import { SearchOptions } from "./types/searchOpts.js";
|
|
5
5
|
import Data from "./types/data.js";
|
|
6
|
+
import FileCpu from "./types/fileCpu.js";
|
|
6
7
|
/**
|
|
7
8
|
* A class representing database actions on files.
|
|
8
9
|
* @class
|
|
@@ -10,13 +11,14 @@ import Data from "./types/data.js";
|
|
|
10
11
|
declare class dbActionC {
|
|
11
12
|
folder: string;
|
|
12
13
|
options: DbOpts;
|
|
14
|
+
fileCpu: FileCpu;
|
|
13
15
|
/**
|
|
14
16
|
* Creates a new instance of dbActionC.
|
|
15
17
|
* @constructor
|
|
16
18
|
* @param folder - The folder where database files are stored.
|
|
17
19
|
* @param options - The options object.
|
|
18
20
|
*/
|
|
19
|
-
constructor(folder: string, options: DbOpts);
|
|
21
|
+
constructor(folder: string, options: DbOpts, fileCpu: FileCpu);
|
|
20
22
|
_getCollectionPath(collection: string): string;
|
|
21
23
|
/**
|
|
22
24
|
* Get a list of available databases in the specified folder.
|
package/dist/cjs/action.js
CHANGED
|
@@ -4,9 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const gen_1 = __importDefault(require("./gen.js"));
|
|
7
|
-
const format_1 = require("./format.js");
|
|
8
7
|
const fs_1 = require("fs");
|
|
9
|
-
const index_1 = require("./file/index.js");
|
|
10
8
|
/**
|
|
11
9
|
* A class representing database actions on files.
|
|
12
10
|
* @class
|
|
@@ -14,18 +12,20 @@ const index_1 = require("./file/index.js");
|
|
|
14
12
|
class dbActionC {
|
|
15
13
|
folder;
|
|
16
14
|
options;
|
|
15
|
+
fileCpu;
|
|
17
16
|
/**
|
|
18
17
|
* Creates a new instance of dbActionC.
|
|
19
18
|
* @constructor
|
|
20
19
|
* @param folder - The folder where database files are stored.
|
|
21
20
|
* @param options - The options object.
|
|
22
21
|
*/
|
|
23
|
-
constructor(folder, options) {
|
|
22
|
+
constructor(folder, options, fileCpu) {
|
|
24
23
|
this.folder = folder;
|
|
25
24
|
this.options = {
|
|
26
25
|
maxFileSize: 2 * 1024 * 1024, //2 MB
|
|
27
26
|
...options,
|
|
28
27
|
};
|
|
28
|
+
this.fileCpu = fileCpu;
|
|
29
29
|
if (!(0, fs_1.existsSync)(folder))
|
|
30
30
|
(0, fs_1.mkdirSync)(folder, { recursive: true });
|
|
31
31
|
}
|
|
@@ -69,8 +69,7 @@ class dbActionC {
|
|
|
69
69
|
const file = cpath + getLastFile(cpath, this.options.maxFileSize);
|
|
70
70
|
if (id_gen)
|
|
71
71
|
arg._id = arg._id || (0, gen_1.default)();
|
|
72
|
-
|
|
73
|
-
(0, fs_1.appendFileSync)(file, data + "\n");
|
|
72
|
+
await this.fileCpu.add(file, arg);
|
|
74
73
|
return arg;
|
|
75
74
|
}
|
|
76
75
|
/**
|
|
@@ -87,7 +86,7 @@ class dbActionC {
|
|
|
87
86
|
let datas = [];
|
|
88
87
|
let totalEntries = 0;
|
|
89
88
|
for (let f of files) {
|
|
90
|
-
let data = await
|
|
89
|
+
let data = await this.fileCpu.find(cpath + f, arg, context, findOpts);
|
|
91
90
|
if (options.reverse)
|
|
92
91
|
data.reverse();
|
|
93
92
|
if (options.max !== -1) {
|
|
@@ -114,7 +113,7 @@ class dbActionC {
|
|
|
114
113
|
const cpath = this._getCollectionPath(collection);
|
|
115
114
|
const files = getSortedFiles(cpath).map(f => f.f);
|
|
116
115
|
for (let f of files) {
|
|
117
|
-
let data = await
|
|
116
|
+
let data = await this.fileCpu.findOne(cpath + f, arg, context, findOpts);
|
|
118
117
|
if (data)
|
|
119
118
|
return data;
|
|
120
119
|
}
|
|
@@ -125,28 +124,28 @@ class dbActionC {
|
|
|
125
124
|
*/
|
|
126
125
|
async update(collection, arg, updater, context = {}) {
|
|
127
126
|
this.checkCollection(collection);
|
|
128
|
-
return await
|
|
127
|
+
return await this.fileCpu.update(this._getCollectionPath(collection), arg, updater, context);
|
|
129
128
|
}
|
|
130
129
|
/**
|
|
131
130
|
* Update the first matching entry in the specified database based on search criteria and an updater function or object.
|
|
132
131
|
*/
|
|
133
132
|
async updateOne(collection, arg, updater, context = {}) {
|
|
134
133
|
this.checkCollection(collection);
|
|
135
|
-
return await
|
|
134
|
+
return await this.fileCpu.update(this._getCollectionPath(collection), arg, updater, context, true);
|
|
136
135
|
}
|
|
137
136
|
/**
|
|
138
137
|
* Remove entries from the specified database based on search criteria.
|
|
139
138
|
*/
|
|
140
139
|
async remove(collection, arg, context = {}) {
|
|
141
140
|
this.checkCollection(collection);
|
|
142
|
-
return await
|
|
141
|
+
return await this.fileCpu.remove(this._getCollectionPath(collection), arg, context);
|
|
143
142
|
}
|
|
144
143
|
/**
|
|
145
144
|
* Remove the first matching entry from the specified database based on search criteria.
|
|
146
145
|
*/
|
|
147
146
|
async removeOne(collection, arg, context = {}) {
|
|
148
147
|
this.checkCollection(collection);
|
|
149
|
-
return await
|
|
148
|
+
return await this.fileCpu.remove(this._getCollectionPath(collection), arg, context, true);
|
|
150
149
|
}
|
|
151
150
|
/**
|
|
152
151
|
* Removes a database collection from the file system.
|
package/dist/cjs/database.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { DbFindOpts, DbOpts, FindOpts } from "./types/options.js";
|
|
|
5
5
|
import { Arg, Search, Updater } from "./types/arg.js";
|
|
6
6
|
import Data from "./types/data.js";
|
|
7
7
|
import { Context } from "./types/types.js";
|
|
8
|
+
import FileCpu from "./types/fileCpu.js";
|
|
8
9
|
/**
|
|
9
10
|
* Represents a database management class for performing CRUD operations.
|
|
10
11
|
* @class
|
|
@@ -12,7 +13,7 @@ import { Context } from "./types/types.js";
|
|
|
12
13
|
declare class DataBase {
|
|
13
14
|
dbAction: dbActionC;
|
|
14
15
|
executor: executorC;
|
|
15
|
-
constructor(folder: string, options?: DbOpts);
|
|
16
|
+
constructor(folder: string, options?: DbOpts, fileCpu?: FileCpu);
|
|
16
17
|
/**
|
|
17
18
|
* Create a new instance of a CollectionManager class.
|
|
18
19
|
*/
|
package/dist/cjs/database.js
CHANGED
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const action_1 = __importDefault(require("./action.js"));
|
|
7
7
|
const executor_1 = __importDefault(require("./executor.js"));
|
|
8
8
|
const CollectionManager_1 = __importDefault(require("./CollectionManager.js"));
|
|
9
|
+
const file_1 = __importDefault(require("./file/index.js"));
|
|
9
10
|
/**
|
|
10
11
|
* Represents a database management class for performing CRUD operations.
|
|
11
12
|
* @class
|
|
@@ -13,8 +14,10 @@ const CollectionManager_1 = __importDefault(require("./CollectionManager.js"));
|
|
|
13
14
|
class DataBase {
|
|
14
15
|
dbAction;
|
|
15
16
|
executor;
|
|
16
|
-
constructor(folder, options = {}) {
|
|
17
|
-
|
|
17
|
+
constructor(folder, options = {}, fileCpu) {
|
|
18
|
+
if (!fileCpu)
|
|
19
|
+
fileCpu = file_1.default;
|
|
20
|
+
this.dbAction = new action_1.default(folder, options, fileCpu);
|
|
18
21
|
this.executor = new executor_1.default();
|
|
19
22
|
}
|
|
20
23
|
/**
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Context } from "vm";
|
|
2
|
+
import { Search, Updater } from "../types/arg.js";
|
|
3
|
+
import Data from "../types/data.js";
|
|
4
|
+
import FileCpu from "../types/fileCpu.js";
|
|
5
|
+
import { FindOpts } from "../types/options.js";
|
|
6
|
+
type WriteFile = (file: string, data: any[]) => Promise<void>;
|
|
7
|
+
type ReadFile = (file: string) => Promise<any[]>;
|
|
8
|
+
declare class CustomFileCpu implements FileCpu {
|
|
9
|
+
_readFile: ReadFile;
|
|
10
|
+
_writeFile: WriteFile;
|
|
11
|
+
constructor(readFile: ReadFile, writeFile: WriteFile);
|
|
12
|
+
add(file: string, data: Data): Promise<void>;
|
|
13
|
+
addMany(file: string, data: Data[]): Promise<void>;
|
|
14
|
+
find(file: string, arg: Search, context?: Context, findOpts?: FindOpts): Promise<any[] | false>;
|
|
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>;
|
|
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>;
|
|
19
|
+
update(cpath: string, arg: Search, updater: Updater, context?: Context, one?: boolean): Promise<boolean>;
|
|
20
|
+
}
|
|
21
|
+
export default CustomFileCpu;
|
|
@@ -0,0 +1,104 @@
|
|
|
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
|
+
const fs_1 = require("fs");
|
|
10
|
+
class CustomFileCpu {
|
|
11
|
+
_readFile;
|
|
12
|
+
_writeFile;
|
|
13
|
+
constructor(readFile, writeFile) {
|
|
14
|
+
this._readFile = readFile;
|
|
15
|
+
this._writeFile = writeFile;
|
|
16
|
+
}
|
|
17
|
+
async add(file, data) {
|
|
18
|
+
file = (0, utils_1.pathRepair)(file);
|
|
19
|
+
let entries = await this._readFile(file);
|
|
20
|
+
entries.push(data);
|
|
21
|
+
await this._writeFile(file, entries);
|
|
22
|
+
}
|
|
23
|
+
async addMany(file, data) {
|
|
24
|
+
file = (0, utils_1.pathRepair)(file);
|
|
25
|
+
let entries = await this._readFile(file);
|
|
26
|
+
entries = entries.concat(data);
|
|
27
|
+
await this._writeFile(file, entries);
|
|
28
|
+
}
|
|
29
|
+
async find(file, arg, context = {}, findOpts = {}) {
|
|
30
|
+
file = (0, utils_1.pathRepair)(file);
|
|
31
|
+
const entries = await this._readFile(file);
|
|
32
|
+
const results = entries.filter(entry => typeof arg === "function" ? arg(entry, context) : (0, hasFieldsAdvanced_1.default)(entry, arg));
|
|
33
|
+
return results.length ? results.map(res => (0, updateFindObject_1.default)(res, findOpts)) : false;
|
|
34
|
+
}
|
|
35
|
+
async findOne(file, arg, context = {}, findOpts = {}) {
|
|
36
|
+
file = (0, utils_1.pathRepair)(file);
|
|
37
|
+
const entries = await this._readFile(file);
|
|
38
|
+
const result = entries.find(entry => typeof arg === "function" ? arg(entry, context) : (0, hasFieldsAdvanced_1.default)(entry, arg));
|
|
39
|
+
return result ? (0, updateFindObject_1.default)(result, findOpts) : false;
|
|
40
|
+
}
|
|
41
|
+
async removeWorker(file, arg, context = {}, one = false) {
|
|
42
|
+
file = (0, utils_1.pathRepair)(file);
|
|
43
|
+
let entries = await this._readFile(file);
|
|
44
|
+
let removed = false;
|
|
45
|
+
entries = entries.filter(entry => {
|
|
46
|
+
if (removed && one)
|
|
47
|
+
return true;
|
|
48
|
+
let match = typeof arg === "function" ? arg(entry, context) : (0, hasFieldsAdvanced_1.default)(entry, arg);
|
|
49
|
+
if (match) {
|
|
50
|
+
removed = true;
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
return true;
|
|
54
|
+
});
|
|
55
|
+
if (!removed)
|
|
56
|
+
return false;
|
|
57
|
+
await this._writeFile(file, entries);
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
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);
|
|
74
|
+
let entries = await this._readFile(file);
|
|
75
|
+
let updated = false;
|
|
76
|
+
entries = entries.map(entry => {
|
|
77
|
+
if (updated && one)
|
|
78
|
+
return entry;
|
|
79
|
+
let match = typeof arg === "function" ? arg(entry, context) : (0, hasFieldsAdvanced_1.default)(entry, arg);
|
|
80
|
+
if (match) {
|
|
81
|
+
updated = true;
|
|
82
|
+
return typeof updater === "function" ? updater(entry, context) : { ...entry, ...updater };
|
|
83
|
+
}
|
|
84
|
+
return entry;
|
|
85
|
+
});
|
|
86
|
+
if (!updated)
|
|
87
|
+
return false;
|
|
88
|
+
await this._writeFile(file, entries);
|
|
89
|
+
return true;
|
|
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
|
+
}
|
|
103
|
+
}
|
|
104
|
+
exports.default = CustomFileCpu;
|
package/dist/cjs/file/find.d.ts
CHANGED
|
@@ -4,8 +4,8 @@ import { FindOpts } from "../types/options.js";
|
|
|
4
4
|
/**
|
|
5
5
|
* Asynchronously finds entries in a file based on search criteria.
|
|
6
6
|
*/
|
|
7
|
-
export declare function find(file: string, arg: Search, context?: Context, findOpts?: FindOpts): Promise<
|
|
7
|
+
export declare function find(file: string, arg: Search, context?: Context, findOpts?: FindOpts): Promise<any[] | false>;
|
|
8
8
|
/**
|
|
9
9
|
* Asynchronously finds one entry in a file based on search criteria.
|
|
10
10
|
*/
|
|
11
|
-
export declare function findOne(file: string, arg: Search, context?: Context, findOpts?: FindOpts): Promise<
|
|
11
|
+
export declare function findOne(file: string, arg: Search, context?: Context, findOpts?: FindOpts): Promise<any | false>;
|
package/dist/cjs/file/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export
|
|
1
|
+
import FileCpu from "../types/fileCpu.js";
|
|
2
|
+
declare const vFileCpu: FileCpu;
|
|
3
|
+
export default vFileCpu;
|
package/dist/cjs/file/index.js
CHANGED
|
@@ -1,25 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
4
|
};
|
|
19
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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/index.d.ts
CHANGED
|
@@ -4,10 +4,11 @@ import DataBaseRemote from "./client/database.js";
|
|
|
4
4
|
import GraphRemote from "./client/graph.js";
|
|
5
5
|
import genId from "./gen.js";
|
|
6
6
|
import Relation from "./relation.js";
|
|
7
|
-
|
|
7
|
+
import CustomFileCpu from "./file/customFileCpu.js";
|
|
8
|
+
export { DataBase, Graph, DataBaseRemote, GraphRemote, Relation, genId, CustomFileCpu, };
|
|
8
9
|
import type Id from "./types/Id.js";
|
|
9
10
|
import type { Arg, Search, Updater } from "./types/arg.js";
|
|
10
11
|
import type { DbFindOpts, FindOpts, DbOpts } from "./types/options.js";
|
|
11
12
|
import type Data from "./types/data.js";
|
|
12
13
|
import type { SearchOptions } from "./types/searchOpts.js";
|
|
13
|
-
export type { Id, Arg, Search, Updater, DbFindOpts, FindOpts, DbOpts, Data, SearchOptions };
|
|
14
|
+
export type { Id, Arg, Search, Updater, DbFindOpts, FindOpts, DbOpts, Data, SearchOptions, };
|
package/dist/cjs/index.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.genId = exports.Relation = exports.GraphRemote = exports.DataBaseRemote = exports.Graph = exports.DataBase = void 0;
|
|
6
|
+
exports.CustomFileCpu = exports.genId = exports.Relation = exports.GraphRemote = exports.DataBaseRemote = exports.Graph = exports.DataBase = void 0;
|
|
7
7
|
const database_1 = __importDefault(require("./database.js"));
|
|
8
8
|
exports.DataBase = database_1.default;
|
|
9
9
|
const graph_1 = __importDefault(require("./graph.js"));
|
|
@@ -16,3 +16,5 @@ const gen_1 = __importDefault(require("./gen.js"));
|
|
|
16
16
|
exports.genId = gen_1.default;
|
|
17
17
|
const relation_1 = __importDefault(require("./relation.js"));
|
|
18
18
|
exports.Relation = relation_1.default;
|
|
19
|
+
const customFileCpu_1 = __importDefault(require("./file/customFileCpu.js"));
|
|
20
|
+
exports.CustomFileCpu = customFileCpu_1.default;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Search, Updater } from "./arg.js";
|
|
2
|
+
import Data from "./data.js";
|
|
3
|
+
import { FindOpts } from "./options.js";
|
|
4
|
+
import { Context } from "./types.js";
|
|
5
|
+
interface FileCpu {
|
|
6
|
+
/**
|
|
7
|
+
* Asynchronously adds an entry to a file.
|
|
8
|
+
* @param file The path to the file.
|
|
9
|
+
* @param data The data to add.
|
|
10
|
+
* @returns A promise resolving to `void`.
|
|
11
|
+
*/
|
|
12
|
+
add(file: string, data: Data): Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* Asynchronously finds multiple entries in a file based on search criteria.
|
|
15
|
+
* @param file The path to the file.
|
|
16
|
+
* @param arg The search criteria.
|
|
17
|
+
* @param context Additional context for the search.
|
|
18
|
+
* @param findOpts Additional options for searching.
|
|
19
|
+
* @returns A promise resolving to an array of found entries, or `false` if the file does not exist.
|
|
20
|
+
*/
|
|
21
|
+
find(file: string, arg: Search, context?: Context, findOpts?: FindOpts): Promise<any[] | false>;
|
|
22
|
+
/**
|
|
23
|
+
* Asynchronously finds one entry in a file based on search criteria.
|
|
24
|
+
* @param file The path to the file.
|
|
25
|
+
* @param arg The search criteria.
|
|
26
|
+
* @param context Additional context for the search.
|
|
27
|
+
* @param findOpts Additional options for searching.
|
|
28
|
+
* @returns A promise resolving to the found entry or `false` if not found.
|
|
29
|
+
*/
|
|
30
|
+
findOne(file: string, arg: Search, context?: Context, findOpts?: FindOpts): Promise<any | false>;
|
|
31
|
+
/**
|
|
32
|
+
* Asynchronously removes entries from a file based on search criteria.
|
|
33
|
+
* @param cpath The path to the directory containing the files.
|
|
34
|
+
* @param arg The search criteria.
|
|
35
|
+
* @param context Additional context for the operation.
|
|
36
|
+
* @param one If `true`, removes only the first matching entry.
|
|
37
|
+
* @returns A promise resolving to `true` if at least one entry was removed, otherwise `false`.
|
|
38
|
+
*/
|
|
39
|
+
remove(cpath: string, arg: Search, context?: Context, one?: boolean): Promise<boolean>;
|
|
40
|
+
/**
|
|
41
|
+
* Asynchronously updates entries in a file based on search criteria and an updater function or object.
|
|
42
|
+
* @param cpath The path to the directory containing the files.
|
|
43
|
+
* @param arg The search criteria.
|
|
44
|
+
* @param updater The updater function or object.
|
|
45
|
+
* @param context Additional context for the operation.
|
|
46
|
+
* @param one If `true`, updates only the first matching entry.
|
|
47
|
+
* @returns A promise resolving to `true` if at least one entry was updated, otherwise `false`.
|
|
48
|
+
*/
|
|
49
|
+
update(cpath: string, arg: Search, updater: Updater, context?: Context, one?: boolean): Promise<boolean>;
|
|
50
|
+
}
|
|
51
|
+
export default FileCpu;
|
package/dist/esm/action.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { DbFindOpts, DbOpts, FindOpts } from "./types/options.js";
|
|
|
3
3
|
import { Context } from "./types/types.js";
|
|
4
4
|
import { SearchOptions } from "./types/searchOpts.js";
|
|
5
5
|
import Data from "./types/data.js";
|
|
6
|
+
import FileCpu from "./types/fileCpu.js";
|
|
6
7
|
/**
|
|
7
8
|
* A class representing database actions on files.
|
|
8
9
|
* @class
|
|
@@ -10,13 +11,14 @@ import Data from "./types/data.js";
|
|
|
10
11
|
declare class dbActionC {
|
|
11
12
|
folder: string;
|
|
12
13
|
options: DbOpts;
|
|
14
|
+
fileCpu: FileCpu;
|
|
13
15
|
/**
|
|
14
16
|
* Creates a new instance of dbActionC.
|
|
15
17
|
* @constructor
|
|
16
18
|
* @param folder - The folder where database files are stored.
|
|
17
19
|
* @param options - The options object.
|
|
18
20
|
*/
|
|
19
|
-
constructor(folder: string, options: DbOpts);
|
|
21
|
+
constructor(folder: string, options: DbOpts, fileCpu: FileCpu);
|
|
20
22
|
_getCollectionPath(collection: string): string;
|
|
21
23
|
/**
|
|
22
24
|
* Get a list of available databases in the specified folder.
|
package/dist/esm/action.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import gen from "./gen.js";
|
|
2
|
-
import {
|
|
3
|
-
import { existsSync, mkdirSync, readdirSync, appendFileSync, rmSync, writeFileSync, statSync } from "fs";
|
|
4
|
-
import { find as _find, findOne as _findOne, update as _update, remove as _remove } from "./file/index.js";
|
|
2
|
+
import { existsSync, mkdirSync, readdirSync, rmSync, writeFileSync, statSync } from "fs";
|
|
5
3
|
/**
|
|
6
4
|
* A class representing database actions on files.
|
|
7
5
|
* @class
|
|
@@ -9,18 +7,20 @@ import { find as _find, findOne as _findOne, update as _update, remove as _remov
|
|
|
9
7
|
class dbActionC {
|
|
10
8
|
folder;
|
|
11
9
|
options;
|
|
10
|
+
fileCpu;
|
|
12
11
|
/**
|
|
13
12
|
* Creates a new instance of dbActionC.
|
|
14
13
|
* @constructor
|
|
15
14
|
* @param folder - The folder where database files are stored.
|
|
16
15
|
* @param options - The options object.
|
|
17
16
|
*/
|
|
18
|
-
constructor(folder, options) {
|
|
17
|
+
constructor(folder, options, fileCpu) {
|
|
19
18
|
this.folder = folder;
|
|
20
19
|
this.options = {
|
|
21
20
|
maxFileSize: 2 * 1024 * 1024, //2 MB
|
|
22
21
|
...options,
|
|
23
22
|
};
|
|
23
|
+
this.fileCpu = fileCpu;
|
|
24
24
|
if (!existsSync(folder))
|
|
25
25
|
mkdirSync(folder, { recursive: true });
|
|
26
26
|
}
|
|
@@ -64,8 +64,7 @@ class dbActionC {
|
|
|
64
64
|
const file = cpath + getLastFile(cpath, this.options.maxFileSize);
|
|
65
65
|
if (id_gen)
|
|
66
66
|
arg._id = arg._id || gen();
|
|
67
|
-
|
|
68
|
-
appendFileSync(file, data + "\n");
|
|
67
|
+
await this.fileCpu.add(file, arg);
|
|
69
68
|
return arg;
|
|
70
69
|
}
|
|
71
70
|
/**
|
|
@@ -82,7 +81,7 @@ class dbActionC {
|
|
|
82
81
|
let datas = [];
|
|
83
82
|
let totalEntries = 0;
|
|
84
83
|
for (let f of files) {
|
|
85
|
-
let data = await
|
|
84
|
+
let data = await this.fileCpu.find(cpath + f, arg, context, findOpts);
|
|
86
85
|
if (options.reverse)
|
|
87
86
|
data.reverse();
|
|
88
87
|
if (options.max !== -1) {
|
|
@@ -109,7 +108,7 @@ class dbActionC {
|
|
|
109
108
|
const cpath = this._getCollectionPath(collection);
|
|
110
109
|
const files = getSortedFiles(cpath).map(f => f.f);
|
|
111
110
|
for (let f of files) {
|
|
112
|
-
let data = await
|
|
111
|
+
let data = await this.fileCpu.findOne(cpath + f, arg, context, findOpts);
|
|
113
112
|
if (data)
|
|
114
113
|
return data;
|
|
115
114
|
}
|
|
@@ -120,28 +119,28 @@ class dbActionC {
|
|
|
120
119
|
*/
|
|
121
120
|
async update(collection, arg, updater, context = {}) {
|
|
122
121
|
this.checkCollection(collection);
|
|
123
|
-
return await
|
|
122
|
+
return await this.fileCpu.update(this._getCollectionPath(collection), arg, updater, context);
|
|
124
123
|
}
|
|
125
124
|
/**
|
|
126
125
|
* Update the first matching entry in the specified database based on search criteria and an updater function or object.
|
|
127
126
|
*/
|
|
128
127
|
async updateOne(collection, arg, updater, context = {}) {
|
|
129
128
|
this.checkCollection(collection);
|
|
130
|
-
return await
|
|
129
|
+
return await this.fileCpu.update(this._getCollectionPath(collection), arg, updater, context, true);
|
|
131
130
|
}
|
|
132
131
|
/**
|
|
133
132
|
* Remove entries from the specified database based on search criteria.
|
|
134
133
|
*/
|
|
135
134
|
async remove(collection, arg, context = {}) {
|
|
136
135
|
this.checkCollection(collection);
|
|
137
|
-
return await
|
|
136
|
+
return await this.fileCpu.remove(this._getCollectionPath(collection), arg, context);
|
|
138
137
|
}
|
|
139
138
|
/**
|
|
140
139
|
* Remove the first matching entry from the specified database based on search criteria.
|
|
141
140
|
*/
|
|
142
141
|
async removeOne(collection, arg, context = {}) {
|
|
143
142
|
this.checkCollection(collection);
|
|
144
|
-
return await
|
|
143
|
+
return await this.fileCpu.remove(this._getCollectionPath(collection), arg, context, true);
|
|
145
144
|
}
|
|
146
145
|
/**
|
|
147
146
|
* Removes a database collection from the file system.
|
package/dist/esm/database.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { DbFindOpts, DbOpts, FindOpts } from "./types/options.js";
|
|
|
5
5
|
import { Arg, Search, Updater } from "./types/arg.js";
|
|
6
6
|
import Data from "./types/data.js";
|
|
7
7
|
import { Context } from "./types/types.js";
|
|
8
|
+
import FileCpu from "./types/fileCpu.js";
|
|
8
9
|
/**
|
|
9
10
|
* Represents a database management class for performing CRUD operations.
|
|
10
11
|
* @class
|
|
@@ -12,7 +13,7 @@ import { Context } from "./types/types.js";
|
|
|
12
13
|
declare class DataBase {
|
|
13
14
|
dbAction: dbActionC;
|
|
14
15
|
executor: executorC;
|
|
15
|
-
constructor(folder: string, options?: DbOpts);
|
|
16
|
+
constructor(folder: string, options?: DbOpts, fileCpu?: FileCpu);
|
|
16
17
|
/**
|
|
17
18
|
* Create a new instance of a CollectionManager class.
|
|
18
19
|
*/
|
package/dist/esm/database.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import dbActionC from "./action.js";
|
|
2
2
|
import executorC from "./executor.js";
|
|
3
3
|
import CollectionManager from "./CollectionManager.js";
|
|
4
|
+
import vFileCpu from "./file/index.js";
|
|
4
5
|
/**
|
|
5
6
|
* Represents a database management class for performing CRUD operations.
|
|
6
7
|
* @class
|
|
@@ -8,8 +9,10 @@ import CollectionManager from "./CollectionManager.js";
|
|
|
8
9
|
class DataBase {
|
|
9
10
|
dbAction;
|
|
10
11
|
executor;
|
|
11
|
-
constructor(folder, options = {}) {
|
|
12
|
-
|
|
12
|
+
constructor(folder, options = {}, fileCpu) {
|
|
13
|
+
if (!fileCpu)
|
|
14
|
+
fileCpu = vFileCpu;
|
|
15
|
+
this.dbAction = new dbActionC(folder, options, fileCpu);
|
|
13
16
|
this.executor = new executorC();
|
|
14
17
|
}
|
|
15
18
|
/**
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Context } from "vm";
|
|
2
|
+
import { Search, Updater } from "../types/arg.js";
|
|
3
|
+
import Data from "../types/data.js";
|
|
4
|
+
import FileCpu from "../types/fileCpu.js";
|
|
5
|
+
import { FindOpts } from "../types/options.js";
|
|
6
|
+
type WriteFile = (file: string, data: any[]) => Promise<void>;
|
|
7
|
+
type ReadFile = (file: string) => Promise<any[]>;
|
|
8
|
+
declare class CustomFileCpu implements FileCpu {
|
|
9
|
+
_readFile: ReadFile;
|
|
10
|
+
_writeFile: WriteFile;
|
|
11
|
+
constructor(readFile: ReadFile, writeFile: WriteFile);
|
|
12
|
+
add(file: string, data: Data): Promise<void>;
|
|
13
|
+
addMany(file: string, data: Data[]): Promise<void>;
|
|
14
|
+
find(file: string, arg: Search, context?: Context, findOpts?: FindOpts): Promise<any[] | false>;
|
|
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>;
|
|
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>;
|
|
19
|
+
update(cpath: string, arg: Search, updater: Updater, context?: Context, one?: boolean): Promise<boolean>;
|
|
20
|
+
}
|
|
21
|
+
export default CustomFileCpu;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import hasFieldsAdvanced from "../utils/hasFieldsAdvanced.js";
|
|
2
|
+
import updateFindObject from "../utils/updateFindObject.js";
|
|
3
|
+
import { pathRepair } from "./utils.js";
|
|
4
|
+
import { readdirSync } from "fs";
|
|
5
|
+
class CustomFileCpu {
|
|
6
|
+
_readFile;
|
|
7
|
+
_writeFile;
|
|
8
|
+
constructor(readFile, writeFile) {
|
|
9
|
+
this._readFile = readFile;
|
|
10
|
+
this._writeFile = writeFile;
|
|
11
|
+
}
|
|
12
|
+
async add(file, data) {
|
|
13
|
+
file = pathRepair(file);
|
|
14
|
+
let entries = await this._readFile(file);
|
|
15
|
+
entries.push(data);
|
|
16
|
+
await this._writeFile(file, entries);
|
|
17
|
+
}
|
|
18
|
+
async addMany(file, data) {
|
|
19
|
+
file = pathRepair(file);
|
|
20
|
+
let entries = await this._readFile(file);
|
|
21
|
+
entries = entries.concat(data);
|
|
22
|
+
await this._writeFile(file, entries);
|
|
23
|
+
}
|
|
24
|
+
async find(file, arg, context = {}, findOpts = {}) {
|
|
25
|
+
file = pathRepair(file);
|
|
26
|
+
const entries = await this._readFile(file);
|
|
27
|
+
const results = entries.filter(entry => typeof arg === "function" ? arg(entry, context) : hasFieldsAdvanced(entry, arg));
|
|
28
|
+
return results.length ? results.map(res => updateFindObject(res, findOpts)) : false;
|
|
29
|
+
}
|
|
30
|
+
async findOne(file, arg, context = {}, findOpts = {}) {
|
|
31
|
+
file = pathRepair(file);
|
|
32
|
+
const entries = await this._readFile(file);
|
|
33
|
+
const result = entries.find(entry => typeof arg === "function" ? arg(entry, context) : hasFieldsAdvanced(entry, arg));
|
|
34
|
+
return result ? updateFindObject(result, findOpts) : false;
|
|
35
|
+
}
|
|
36
|
+
async removeWorker(file, arg, context = {}, one = false) {
|
|
37
|
+
file = pathRepair(file);
|
|
38
|
+
let entries = await this._readFile(file);
|
|
39
|
+
let removed = false;
|
|
40
|
+
entries = entries.filter(entry => {
|
|
41
|
+
if (removed && one)
|
|
42
|
+
return true;
|
|
43
|
+
let match = typeof arg === "function" ? arg(entry, context) : hasFieldsAdvanced(entry, arg);
|
|
44
|
+
if (match) {
|
|
45
|
+
removed = true;
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
return true;
|
|
49
|
+
});
|
|
50
|
+
if (!removed)
|
|
51
|
+
return false;
|
|
52
|
+
await this._writeFile(file, entries);
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
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);
|
|
69
|
+
let entries = await this._readFile(file);
|
|
70
|
+
let updated = false;
|
|
71
|
+
entries = entries.map(entry => {
|
|
72
|
+
if (updated && one)
|
|
73
|
+
return entry;
|
|
74
|
+
let match = typeof arg === "function" ? arg(entry, context) : hasFieldsAdvanced(entry, arg);
|
|
75
|
+
if (match) {
|
|
76
|
+
updated = true;
|
|
77
|
+
return typeof updater === "function" ? updater(entry, context) : { ...entry, ...updater };
|
|
78
|
+
}
|
|
79
|
+
return entry;
|
|
80
|
+
});
|
|
81
|
+
if (!updated)
|
|
82
|
+
return false;
|
|
83
|
+
await this._writeFile(file, entries);
|
|
84
|
+
return true;
|
|
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
|
+
}
|
|
98
|
+
}
|
|
99
|
+
export default CustomFileCpu;
|
package/dist/esm/file/find.d.ts
CHANGED
|
@@ -4,8 +4,8 @@ import { FindOpts } from "../types/options.js";
|
|
|
4
4
|
/**
|
|
5
5
|
* Asynchronously finds entries in a file based on search criteria.
|
|
6
6
|
*/
|
|
7
|
-
export declare function find(file: string, arg: Search, context?: Context, findOpts?: FindOpts): Promise<
|
|
7
|
+
export declare function find(file: string, arg: Search, context?: Context, findOpts?: FindOpts): Promise<any[] | false>;
|
|
8
8
|
/**
|
|
9
9
|
* Asynchronously finds one entry in a file based on search criteria.
|
|
10
10
|
*/
|
|
11
|
-
export declare function findOne(file: string, arg: Search, context?: Context, findOpts?: FindOpts): Promise<
|
|
11
|
+
export declare function findOne(file: string, arg: Search, context?: Context, findOpts?: FindOpts): Promise<any | false>;
|
package/dist/esm/file/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export
|
|
1
|
+
import FileCpu from "../types/fileCpu.js";
|
|
2
|
+
declare const vFileCpu: FileCpu;
|
|
3
|
+
export default vFileCpu;
|
package/dist/esm/file/index.js
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import update from "./update.js";
|
|
2
|
+
import remove from "./remove.js";
|
|
3
|
+
import { find, findOne } from "./find.js";
|
|
4
|
+
import { appendFileSync } from "fs";
|
|
5
|
+
import { stringify } from "../format.js";
|
|
6
|
+
const vFileCpu = {
|
|
7
|
+
add: async (file, data) => {
|
|
8
|
+
const dataString = stringify(data);
|
|
9
|
+
appendFileSync(file, dataString + "\n");
|
|
10
|
+
},
|
|
11
|
+
find,
|
|
12
|
+
findOne,
|
|
13
|
+
update,
|
|
14
|
+
remove
|
|
15
|
+
};
|
|
16
|
+
export default vFileCpu;
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -4,10 +4,11 @@ import DataBaseRemote from "./client/database.js";
|
|
|
4
4
|
import GraphRemote from "./client/graph.js";
|
|
5
5
|
import genId from "./gen.js";
|
|
6
6
|
import Relation from "./relation.js";
|
|
7
|
-
|
|
7
|
+
import CustomFileCpu from "./file/customFileCpu.js";
|
|
8
|
+
export { DataBase, Graph, DataBaseRemote, GraphRemote, Relation, genId, CustomFileCpu, };
|
|
8
9
|
import type Id from "./types/Id.js";
|
|
9
10
|
import type { Arg, Search, Updater } from "./types/arg.js";
|
|
10
11
|
import type { DbFindOpts, FindOpts, DbOpts } from "./types/options.js";
|
|
11
12
|
import type Data from "./types/data.js";
|
|
12
13
|
import type { SearchOptions } from "./types/searchOpts.js";
|
|
13
|
-
export type { Id, Arg, Search, Updater, DbFindOpts, FindOpts, DbOpts, Data, SearchOptions };
|
|
14
|
+
export type { Id, Arg, Search, Updater, DbFindOpts, FindOpts, DbOpts, Data, SearchOptions, };
|
package/dist/esm/index.js
CHANGED
|
@@ -4,4 +4,5 @@ import DataBaseRemote from "./client/database.js";
|
|
|
4
4
|
import GraphRemote from "./client/graph.js";
|
|
5
5
|
import genId from "./gen.js";
|
|
6
6
|
import Relation from "./relation.js";
|
|
7
|
-
|
|
7
|
+
import CustomFileCpu from "./file/customFileCpu.js";
|
|
8
|
+
export { DataBase, Graph, DataBaseRemote, GraphRemote, Relation, genId, CustomFileCpu, };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Search, Updater } from "./arg.js";
|
|
2
|
+
import Data from "./data.js";
|
|
3
|
+
import { FindOpts } from "./options.js";
|
|
4
|
+
import { Context } from "./types.js";
|
|
5
|
+
interface FileCpu {
|
|
6
|
+
/**
|
|
7
|
+
* Asynchronously adds an entry to a file.
|
|
8
|
+
* @param file The path to the file.
|
|
9
|
+
* @param data The data to add.
|
|
10
|
+
* @returns A promise resolving to `void`.
|
|
11
|
+
*/
|
|
12
|
+
add(file: string, data: Data): Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* Asynchronously finds multiple entries in a file based on search criteria.
|
|
15
|
+
* @param file The path to the file.
|
|
16
|
+
* @param arg The search criteria.
|
|
17
|
+
* @param context Additional context for the search.
|
|
18
|
+
* @param findOpts Additional options for searching.
|
|
19
|
+
* @returns A promise resolving to an array of found entries, or `false` if the file does not exist.
|
|
20
|
+
*/
|
|
21
|
+
find(file: string, arg: Search, context?: Context, findOpts?: FindOpts): Promise<any[] | false>;
|
|
22
|
+
/**
|
|
23
|
+
* Asynchronously finds one entry in a file based on search criteria.
|
|
24
|
+
* @param file The path to the file.
|
|
25
|
+
* @param arg The search criteria.
|
|
26
|
+
* @param context Additional context for the search.
|
|
27
|
+
* @param findOpts Additional options for searching.
|
|
28
|
+
* @returns A promise resolving to the found entry or `false` if not found.
|
|
29
|
+
*/
|
|
30
|
+
findOne(file: string, arg: Search, context?: Context, findOpts?: FindOpts): Promise<any | false>;
|
|
31
|
+
/**
|
|
32
|
+
* Asynchronously removes entries from a file based on search criteria.
|
|
33
|
+
* @param cpath The path to the directory containing the files.
|
|
34
|
+
* @param arg The search criteria.
|
|
35
|
+
* @param context Additional context for the operation.
|
|
36
|
+
* @param one If `true`, removes only the first matching entry.
|
|
37
|
+
* @returns A promise resolving to `true` if at least one entry was removed, otherwise `false`.
|
|
38
|
+
*/
|
|
39
|
+
remove(cpath: string, arg: Search, context?: Context, one?: boolean): Promise<boolean>;
|
|
40
|
+
/**
|
|
41
|
+
* Asynchronously updates entries in a file based on search criteria and an updater function or object.
|
|
42
|
+
* @param cpath The path to the directory containing the files.
|
|
43
|
+
* @param arg The search criteria.
|
|
44
|
+
* @param updater The updater function or object.
|
|
45
|
+
* @param context Additional context for the operation.
|
|
46
|
+
* @param one If `true`, updates only the first matching entry.
|
|
47
|
+
* @returns A promise resolving to `true` if at least one entry was updated, otherwise `false`.
|
|
48
|
+
*/
|
|
49
|
+
update(cpath: string, arg: Search, updater: Updater, context?: Context, one?: boolean): Promise<boolean>;
|
|
50
|
+
}
|
|
51
|
+
export default FileCpu;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
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.",
|
|
7
|
-
"homepage": "https://github.com/wxn0brP/
|
|
7
|
+
"homepage": "https://github.com/wxn0brP/ValtheraDB",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
10
|
-
"url": "https://github.com/wxn0brP/
|
|
10
|
+
"url": "https://github.com/wxn0brP/ValtheraDB.git"
|
|
11
11
|
},
|
|
12
12
|
"keywords": [
|
|
13
13
|
"database",
|
|
@@ -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
|
}
|