@wxn0brp/db-storage-dir 0.0.1 → 0.1.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.d.ts +2 -2
- package/dist/action.js +16 -57
- package/dist/version.js +1 -1
- package/package.json +4 -4
package/dist/action.d.ts
CHANGED
|
@@ -26,7 +26,7 @@ declare class dbActionC extends dbActionBase {
|
|
|
26
26
|
/**
|
|
27
27
|
* Check and create the specified collection if it doesn't exist.
|
|
28
28
|
*/
|
|
29
|
-
|
|
29
|
+
ensureCollection({ collection }: VQuery): Promise<boolean>;
|
|
30
30
|
/**
|
|
31
31
|
* Check if a collection exists.
|
|
32
32
|
*/
|
|
@@ -38,7 +38,7 @@ declare class dbActionC extends dbActionBase {
|
|
|
38
38
|
/**
|
|
39
39
|
* Find entries in the specified database based on search criteria.
|
|
40
40
|
*/
|
|
41
|
-
find(
|
|
41
|
+
find(query: VQuery): Promise<Data[]>;
|
|
42
42
|
/**
|
|
43
43
|
* Find the first matching entry in the specified database based on search criteria.
|
|
44
44
|
*/
|
package/dist/action.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import dbActionBase from "@wxn0brp/db-core/base/actions";
|
|
2
2
|
import gen from "@wxn0brp/db-core/helpers/gen";
|
|
3
|
-
import {
|
|
3
|
+
import { findUtil } from "@wxn0brp/db-core/utils/action";
|
|
4
4
|
import { existsSync, mkdirSync, promises, statSync } from "fs";
|
|
5
5
|
import { resolve, sep } from "path";
|
|
6
6
|
/**
|
|
@@ -50,7 +50,7 @@ class dbActionC extends dbActionBase {
|
|
|
50
50
|
/**
|
|
51
51
|
* Check and create the specified collection if it doesn't exist.
|
|
52
52
|
*/
|
|
53
|
-
async
|
|
53
|
+
async ensureCollection({ collection }) {
|
|
54
54
|
if (await this.issetCollection(collection))
|
|
55
55
|
return;
|
|
56
56
|
const cpath = this._getCollectionPath(collection);
|
|
@@ -74,7 +74,7 @@ class dbActionC extends dbActionBase {
|
|
|
74
74
|
* Add a new entry to the specified database.
|
|
75
75
|
*/
|
|
76
76
|
async add({ collection, data, id_gen = true }) {
|
|
77
|
-
await this.
|
|
77
|
+
await this.ensureCollection(arguments[0]);
|
|
78
78
|
const cpath = this._getCollectionPath(collection);
|
|
79
79
|
const file = cpath + await getLastFile(cpath, this.options.maxFileSize);
|
|
80
80
|
if (id_gen)
|
|
@@ -85,62 +85,21 @@ class dbActionC extends dbActionBase {
|
|
|
85
85
|
/**
|
|
86
86
|
* Find entries in the specified database based on search criteria.
|
|
87
87
|
*/
|
|
88
|
-
async find(
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
const cpath = this._getCollectionPath(collection);
|
|
88
|
+
async find(query) {
|
|
89
|
+
await this.ensureCollection(query);
|
|
90
|
+
const cpath = this._getCollectionPath(query.collection);
|
|
92
91
|
let files = await getSortedFiles(cpath);
|
|
93
|
-
if (
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
for (const f of files) {
|
|
99
|
-
let entries = await this.fileCpu.find(cpath + f, search, context, findOpts);
|
|
100
|
-
if (reverse && !sortBy)
|
|
101
|
-
entries.reverse();
|
|
102
|
-
if (!sortBy) {
|
|
103
|
-
if (offset > skippedEntries) {
|
|
104
|
-
const remainingSkip = offset - skippedEntries;
|
|
105
|
-
if (entries.length <= remainingSkip) {
|
|
106
|
-
skippedEntries += entries.length;
|
|
107
|
-
continue;
|
|
108
|
-
}
|
|
109
|
-
entries = entries.slice(remainingSkip);
|
|
110
|
-
skippedEntries = offset;
|
|
111
|
-
}
|
|
112
|
-
if (max !== -1) {
|
|
113
|
-
if (totalEntries + entries.length > max) {
|
|
114
|
-
const remaining = max - totalEntries;
|
|
115
|
-
entries = entries.slice(0, remaining);
|
|
116
|
-
totalEntries = max;
|
|
117
|
-
}
|
|
118
|
-
else {
|
|
119
|
-
totalEntries += entries.length;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
datas.push(...entries);
|
|
123
|
-
if (max !== -1 && totalEntries >= max)
|
|
124
|
-
break;
|
|
125
|
-
}
|
|
126
|
-
else {
|
|
127
|
-
datas.push(...entries);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
if (sortBy) {
|
|
131
|
-
const dir = sortAsc ? 1 : -1;
|
|
132
|
-
datas.sort((a, b) => compareSafe(a[sortBy], b[sortBy]) * dir);
|
|
133
|
-
const start = offset;
|
|
134
|
-
const end = max !== -1 ? offset + max : undefined;
|
|
135
|
-
datas = datas.slice(start, end);
|
|
136
|
-
}
|
|
137
|
-
return datas;
|
|
92
|
+
if (files.length == 0)
|
|
93
|
+
return [];
|
|
94
|
+
files = files.map(file => cpath + file);
|
|
95
|
+
const data = await findUtil(query, this.fileCpu, files);
|
|
96
|
+
return data || [];
|
|
138
97
|
}
|
|
139
98
|
/**
|
|
140
99
|
* Find the first matching entry in the specified database based on search criteria.
|
|
141
100
|
*/
|
|
142
101
|
async findOne({ collection, search, context = {}, findOpts = {} }) {
|
|
143
|
-
await this.
|
|
102
|
+
await this.ensureCollection(arguments[0]);
|
|
144
103
|
const cpath = this._getCollectionPath(collection);
|
|
145
104
|
const files = await getSortedFiles(cpath);
|
|
146
105
|
for (let f of files) {
|
|
@@ -154,28 +113,28 @@ class dbActionC extends dbActionBase {
|
|
|
154
113
|
* Update entries in the specified database based on search criteria and an updater function or object.
|
|
155
114
|
*/
|
|
156
115
|
async update({ collection, search, updater, context = {} }) {
|
|
157
|
-
await this.
|
|
116
|
+
await this.ensureCollection(arguments[0]);
|
|
158
117
|
return await operationUpdater(this._getCollectionPath(collection), this.fileCpu.update.bind(this.fileCpu), false, search, updater, context);
|
|
159
118
|
}
|
|
160
119
|
/**
|
|
161
120
|
* Update the first matching entry in the specified database based on search criteria and an updater function or object.
|
|
162
121
|
*/
|
|
163
122
|
async updateOne({ collection, search, updater, context = {} }) {
|
|
164
|
-
await this.
|
|
123
|
+
await this.ensureCollection(arguments[0]);
|
|
165
124
|
return await operationUpdater(this._getCollectionPath(collection), this.fileCpu.update.bind(this.fileCpu), true, search, updater, context);
|
|
166
125
|
}
|
|
167
126
|
/**
|
|
168
127
|
* Remove entries from the specified database based on search criteria.
|
|
169
128
|
*/
|
|
170
129
|
async remove({ collection, search, context = {} }) {
|
|
171
|
-
await this.
|
|
130
|
+
await this.ensureCollection(arguments[0]);
|
|
172
131
|
return await operationUpdater(this._getCollectionPath(collection), this.fileCpu.remove.bind(this.fileCpu), false, search, context);
|
|
173
132
|
}
|
|
174
133
|
/**
|
|
175
134
|
* Remove the first matching entry from the specified database based on search criteria.
|
|
176
135
|
*/
|
|
177
136
|
async removeOne({ collection, search, context = {} }) {
|
|
178
|
-
await this.
|
|
137
|
+
await this.ensureCollection(arguments[0]);
|
|
179
138
|
return await operationUpdater(this._getCollectionPath(collection), this.fileCpu.remove.bind(this.fileCpu), true, search, context);
|
|
180
139
|
}
|
|
181
140
|
/**
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = "0.
|
|
1
|
+
export const version = "0.1.1";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wxn0brp/db-storage-dir",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"author": "wxn0brP",
|
|
@@ -13,11 +13,11 @@
|
|
|
13
13
|
},
|
|
14
14
|
"homepage": "https://github.com/wxn0brP/ValtheraDB",
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"
|
|
17
|
-
"
|
|
16
|
+
"@wxn0brp/db-core": ">=0.2.0",
|
|
17
|
+
"json5": "^2.2.3"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"@types/node": "^
|
|
20
|
+
"@types/node": "^24.1.0",
|
|
21
21
|
"tsc-alias": "^1.8.10",
|
|
22
22
|
"typescript": "^5.7.3"
|
|
23
23
|
},
|