@wxn0brp/db 0.3.3 → 0.4.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/dist/action.js +1 -1
- package/dist/database.js +2 -2
- package/dist/file/customFileCpu.d.ts +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/memory.d.ts +4 -0
- package/dist/memory.js +122 -0
- package/dist/types/options.d.ts +4 -0
- package/package.json +2 -2
package/dist/action.js
CHANGED
|
@@ -196,9 +196,9 @@ async function operationUpdater(cpath, worker, one, ...args) {
|
|
|
196
196
|
let update = false;
|
|
197
197
|
for (const file of files) {
|
|
198
198
|
const updated = await worker(cpath + file, one, ...args);
|
|
199
|
+
update = update || updated;
|
|
199
200
|
if (one && updated)
|
|
200
201
|
break;
|
|
201
|
-
update = update || updated;
|
|
202
202
|
}
|
|
203
203
|
return update;
|
|
204
204
|
}
|
package/dist/database.js
CHANGED
|
@@ -12,8 +12,8 @@ class DataBase {
|
|
|
12
12
|
constructor(folder, options = {}, fileCpu) {
|
|
13
13
|
if (!fileCpu)
|
|
14
14
|
fileCpu = vFileCpu;
|
|
15
|
-
this.dbAction = new dbActionC(folder, options, fileCpu);
|
|
16
|
-
this.executor = new executorC();
|
|
15
|
+
this.dbAction = options.dbAction || new dbActionC(folder, options, fileCpu);
|
|
16
|
+
this.executor = options.executor || new executorC();
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
19
19
|
* Create a new instance of a CollectionManager class.
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,8 @@ 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
|
-
|
|
8
|
+
import ValtheraMemory from "./memory.js";
|
|
9
|
+
export { DataBase, DataBase as Valthera, Graph, DataBaseRemote, DataBaseRemote as ValtheraRemote, GraphRemote, Relation, genId, CustomFileCpu, ValtheraMemory, };
|
|
9
10
|
import type Id from "./types/Id.js";
|
|
10
11
|
import type { Arg, Search, Updater } from "./types/arg.js";
|
|
11
12
|
import type { DbFindOpts, FindOpts, DbOpts } from "./types/options.js";
|
package/dist/index.js
CHANGED
|
@@ -5,4 +5,5 @@ 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
|
-
|
|
8
|
+
import ValtheraMemory from "./memory.js";
|
|
9
|
+
export { DataBase, DataBase as Valthera, Graph, DataBaseRemote, DataBaseRemote as ValtheraRemote, GraphRemote, Relation, genId, CustomFileCpu, ValtheraMemory, };
|
package/dist/memory.d.ts
ADDED
package/dist/memory.js
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import DataBase from "./database.js";
|
|
2
|
+
import CustomFileCpu from "./file/customFileCpu.js";
|
|
3
|
+
import genId from "./gen.js";
|
|
4
|
+
class MemoryAction {
|
|
5
|
+
folder;
|
|
6
|
+
options;
|
|
7
|
+
fileCpu;
|
|
8
|
+
memory;
|
|
9
|
+
/**
|
|
10
|
+
* Creates a new instance of dbActionC.
|
|
11
|
+
* @constructor
|
|
12
|
+
* @param folder - The folder where database files are stored.
|
|
13
|
+
* @param options - The options object.
|
|
14
|
+
*/
|
|
15
|
+
constructor() {
|
|
16
|
+
this.memory = new Map();
|
|
17
|
+
this.fileCpu = new CustomFileCpu(this._readMemory.bind(this), this._writeMemory.bind(this));
|
|
18
|
+
}
|
|
19
|
+
_readMemory(key) {
|
|
20
|
+
if (!this.memory.has(key))
|
|
21
|
+
return [];
|
|
22
|
+
return this.memory.get(key);
|
|
23
|
+
}
|
|
24
|
+
_writeMemory(key, data) {
|
|
25
|
+
this.memory.set(key, data);
|
|
26
|
+
}
|
|
27
|
+
_getCollectionPath(collection) {
|
|
28
|
+
return this.folder + "/" + collection + "/";
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Get a list of available databases in the specified folder.
|
|
32
|
+
*/
|
|
33
|
+
async getCollections() {
|
|
34
|
+
const collections = Array.from(this.memory.keys());
|
|
35
|
+
return collections;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Check and create the specified collection if it doesn't exist.
|
|
39
|
+
*/
|
|
40
|
+
async checkCollection(collection) {
|
|
41
|
+
if (this.issetCollection(collection))
|
|
42
|
+
return;
|
|
43
|
+
this.memory.set(collection, []);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Check if a collection exists.
|
|
47
|
+
*/
|
|
48
|
+
async issetCollection(collection) {
|
|
49
|
+
return this.memory.has(collection);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Add a new entry to the specified database.
|
|
53
|
+
*/
|
|
54
|
+
async add(collection, arg, id_gen = true) {
|
|
55
|
+
await this.checkCollection(collection);
|
|
56
|
+
if (id_gen)
|
|
57
|
+
arg._id = arg._id || genId();
|
|
58
|
+
await this.fileCpu.add(collection, arg);
|
|
59
|
+
return arg;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Find entries in the specified database based on search criteria.
|
|
63
|
+
*/
|
|
64
|
+
async find(collection, arg, context = {}, options = {}, findOpts = {}) {
|
|
65
|
+
options.reverse = options.reverse || false;
|
|
66
|
+
options.max = options.max || -1;
|
|
67
|
+
await this.checkCollection(collection);
|
|
68
|
+
let data = await this.fileCpu.find(collection, arg, context, findOpts);
|
|
69
|
+
if (options.reverse)
|
|
70
|
+
data.reverse();
|
|
71
|
+
if (options.max !== -1 && data.length > options.max)
|
|
72
|
+
data = data.slice(0, options.max);
|
|
73
|
+
return data;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Find the first matching entry in the specified database based on search criteria.
|
|
77
|
+
*/
|
|
78
|
+
async findOne(collection, arg, context = {}, findOpts = {}) {
|
|
79
|
+
await this.checkCollection(collection);
|
|
80
|
+
let data = await this.fileCpu.findOne(collection, arg, context, findOpts);
|
|
81
|
+
return data || null;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Update entries in the specified database based on search criteria and an updater function or object.
|
|
85
|
+
*/
|
|
86
|
+
async update(collection, arg, updater, context = {}) {
|
|
87
|
+
await this.checkCollection(collection);
|
|
88
|
+
return await this.fileCpu.update(collection, false, arg, updater, context);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Update the first matching entry in the specified database based on search criteria and an updater function or object.
|
|
92
|
+
*/
|
|
93
|
+
async updateOne(collection, arg, updater, context = {}) {
|
|
94
|
+
await this.checkCollection(collection);
|
|
95
|
+
return await this.fileCpu.update(collection, true, arg, updater, context);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Remove entries from the specified database based on search criteria.
|
|
99
|
+
*/
|
|
100
|
+
async remove(collection, arg, context = {}) {
|
|
101
|
+
await this.checkCollection(collection);
|
|
102
|
+
return await this.fileCpu.remove(collection, false, arg, context);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Remove the first matching entry from the specified database based on search criteria.
|
|
106
|
+
*/
|
|
107
|
+
async removeOne(collection, arg, context = {}) {
|
|
108
|
+
await this.checkCollection(collection);
|
|
109
|
+
return await this.fileCpu.remove(collection, true, arg, context);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Removes a database collection from the file system.
|
|
113
|
+
*/
|
|
114
|
+
async removeCollection(collection) {
|
|
115
|
+
this.memory.delete(collection);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
export default class ValtheraMemory extends DataBase {
|
|
119
|
+
constructor(...args) {
|
|
120
|
+
super("", { dbAction: new MemoryAction() });
|
|
121
|
+
}
|
|
122
|
+
}
|
package/dist/types/options.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wxn0brp/db",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
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.",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
},
|
|
32
32
|
"scripts": {
|
|
33
33
|
"build": "tsc && tsc-alias",
|
|
34
|
-
"prepare": "npm run build",
|
|
34
|
+
"prepare": "rm -rf dist && npm run build",
|
|
35
35
|
"postversion": "git push && git push --tags",
|
|
36
36
|
"build:cdn": "npm run build && cd cdn && node index.js"
|
|
37
37
|
},
|