@wxn0brp/db-storage-dir 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.
- package/dist/action.d.ts +4 -4
- package/dist/action.js +18 -18
- package/dist/index.d.ts +4 -0
- package/dist/index.js +6 -0
- package/dist/version.js +1 -1
- package/package.json +8 -5
package/dist/action.d.ts
CHANGED
|
@@ -7,12 +7,12 @@ import { VQuery } from "@wxn0brp/db-core/types/query";
|
|
|
7
7
|
* A class representing database actions on files.
|
|
8
8
|
* @class
|
|
9
9
|
*/
|
|
10
|
-
declare class
|
|
10
|
+
export declare class FileActions extends dbActionBase {
|
|
11
|
+
fileCpu: FileCpu;
|
|
11
12
|
folder: string;
|
|
12
13
|
options: DbOpts;
|
|
13
|
-
fileCpu: FileCpu;
|
|
14
14
|
/**
|
|
15
|
-
* Creates a new instance of
|
|
15
|
+
* Creates a new instance of FileActions.
|
|
16
16
|
* @constructor
|
|
17
17
|
* @param folder - The folder where database files are stored.
|
|
18
18
|
* @param options - The options object.
|
|
@@ -66,4 +66,4 @@ declare class dbActionC extends dbActionBase {
|
|
|
66
66
|
collection: any;
|
|
67
67
|
}): Promise<boolean>;
|
|
68
68
|
}
|
|
69
|
-
export default
|
|
69
|
+
export default FileActions;
|
package/dist/action.js
CHANGED
|
@@ -7,24 +7,24 @@ import { resolve, sep } from "path";
|
|
|
7
7
|
* A class representing database actions on files.
|
|
8
8
|
* @class
|
|
9
9
|
*/
|
|
10
|
-
class
|
|
10
|
+
export class FileActions extends dbActionBase {
|
|
11
|
+
fileCpu;
|
|
11
12
|
folder;
|
|
12
13
|
options;
|
|
13
|
-
fileCpu;
|
|
14
14
|
/**
|
|
15
|
-
* Creates a new instance of
|
|
15
|
+
* Creates a new instance of FileActions.
|
|
16
16
|
* @constructor
|
|
17
17
|
* @param folder - The folder where database files are stored.
|
|
18
18
|
* @param options - The options object.
|
|
19
19
|
*/
|
|
20
20
|
constructor(folder, options, fileCpu) {
|
|
21
21
|
super();
|
|
22
|
+
this.fileCpu = fileCpu;
|
|
22
23
|
this.folder = folder;
|
|
23
24
|
this.options = {
|
|
24
25
|
maxFileSize: 2 * 1024 * 1024, //2 MB
|
|
25
26
|
...options,
|
|
26
27
|
};
|
|
27
|
-
this.fileCpu = fileCpu;
|
|
28
28
|
if (!existsSync(folder))
|
|
29
29
|
mkdirSync(folder, { recursive: true });
|
|
30
30
|
}
|
|
@@ -53,8 +53,8 @@ class dbActionC extends dbActionBase {
|
|
|
53
53
|
async ensureCollection({ collection }) {
|
|
54
54
|
if (await this.issetCollection(collection))
|
|
55
55
|
return;
|
|
56
|
-
const
|
|
57
|
-
await promises.mkdir(
|
|
56
|
+
const c_path = this._getCollectionPath(collection);
|
|
57
|
+
await promises.mkdir(c_path, { recursive: true });
|
|
58
58
|
return true;
|
|
59
59
|
}
|
|
60
60
|
/**
|
|
@@ -75,8 +75,8 @@ class dbActionC extends dbActionBase {
|
|
|
75
75
|
*/
|
|
76
76
|
async add({ collection, data, id_gen = true }) {
|
|
77
77
|
await this.ensureCollection(arguments[0]);
|
|
78
|
-
const
|
|
79
|
-
const file =
|
|
78
|
+
const c_path = this._getCollectionPath(collection);
|
|
79
|
+
const file = c_path + await getLastFile(c_path, this.options.maxFileSize);
|
|
80
80
|
if (id_gen)
|
|
81
81
|
data._id = data._id || gen();
|
|
82
82
|
await this.fileCpu.add(file, data);
|
|
@@ -87,11 +87,11 @@ class dbActionC extends dbActionBase {
|
|
|
87
87
|
*/
|
|
88
88
|
async find(query) {
|
|
89
89
|
await this.ensureCollection(query);
|
|
90
|
-
const
|
|
91
|
-
let files = await getSortedFiles(
|
|
90
|
+
const c_path = this._getCollectionPath(query.collection);
|
|
91
|
+
let files = await getSortedFiles(c_path);
|
|
92
92
|
if (files.length == 0)
|
|
93
93
|
return [];
|
|
94
|
-
files = files.map(file =>
|
|
94
|
+
files = files.map(file => c_path + file);
|
|
95
95
|
const data = await findUtil(query, this.fileCpu, files);
|
|
96
96
|
return data || [];
|
|
97
97
|
}
|
|
@@ -100,10 +100,10 @@ class dbActionC extends dbActionBase {
|
|
|
100
100
|
*/
|
|
101
101
|
async findOne({ collection, search, context = {}, findOpts = {} }) {
|
|
102
102
|
await this.ensureCollection(arguments[0]);
|
|
103
|
-
const
|
|
104
|
-
const files = await getSortedFiles(
|
|
103
|
+
const c_path = this._getCollectionPath(collection);
|
|
104
|
+
const files = await getSortedFiles(c_path);
|
|
105
105
|
for (let f of files) {
|
|
106
|
-
let data = await this.fileCpu.findOne(
|
|
106
|
+
let data = await this.fileCpu.findOne(c_path + f, search, context, findOpts);
|
|
107
107
|
if (data)
|
|
108
108
|
return data;
|
|
109
109
|
}
|
|
@@ -179,15 +179,15 @@ async function getSortedFiles(folder) {
|
|
|
179
179
|
return numA - numB;
|
|
180
180
|
});
|
|
181
181
|
}
|
|
182
|
-
async function operationUpdater(
|
|
183
|
-
const files = await getSortedFiles(
|
|
182
|
+
async function operationUpdater(c_path, worker, one, ...args) {
|
|
183
|
+
const files = await getSortedFiles(c_path);
|
|
184
184
|
let update = false;
|
|
185
185
|
for (const file of files) {
|
|
186
|
-
const updated = await worker(
|
|
186
|
+
const updated = await worker(c_path + file, one, ...args);
|
|
187
187
|
update = update || updated;
|
|
188
188
|
if (one && updated)
|
|
189
189
|
break;
|
|
190
190
|
}
|
|
191
191
|
return update;
|
|
192
192
|
}
|
|
193
|
-
export default
|
|
193
|
+
export default FileActions;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = "0.1.
|
|
1
|
+
export const version = "0.1.2";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wxn0brp/db-storage-dir",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"author": "wxn0brP",
|
|
@@ -13,13 +13,16 @@
|
|
|
13
13
|
},
|
|
14
14
|
"homepage": "https://github.com/wxn0brP/ValtheraDB",
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@wxn0brp/db-core": ">=0.2.0",
|
|
17
16
|
"json5": "^2.2.3"
|
|
18
17
|
},
|
|
18
|
+
"peerDependencies": {
|
|
19
|
+
"@wxn0brp/db-core": ">=0.2.3"
|
|
20
|
+
},
|
|
19
21
|
"devDependencies": {
|
|
20
|
-
"@types/
|
|
21
|
-
"
|
|
22
|
-
"
|
|
22
|
+
"@types/bun": "*",
|
|
23
|
+
"@wxn0brp/db-core": "^0.2.3",
|
|
24
|
+
"tsc-alias": "*",
|
|
25
|
+
"typescript": "*"
|
|
23
26
|
},
|
|
24
27
|
"files": [
|
|
25
28
|
"dist"
|