@wxn0brp/db-storage-dir 0.1.2 → 0.1.4
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 +1 -1
- package/dist/action.js +3 -4
- package/dist/file/find.d.ts +2 -2
- package/dist/file/find.js +17 -11
- package/dist/file/remove.js +7 -2
- package/dist/file/update.js +7 -2
- package/dist/version.js +1 -1
- package/package.json +4 -4
package/dist/action.d.ts
CHANGED
|
@@ -34,7 +34,7 @@ export declare class FileActions extends dbActionBase {
|
|
|
34
34
|
/**
|
|
35
35
|
* Add a new entry to the specified database.
|
|
36
36
|
*/
|
|
37
|
-
add({ collection, data
|
|
37
|
+
add({ collection, data }: VQuery): Promise<import("@wxn0brp/db-core/types/arg").Arg>;
|
|
38
38
|
/**
|
|
39
39
|
* Find entries in the specified database based on search criteria.
|
|
40
40
|
*/
|
package/dist/action.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import dbActionBase from "@wxn0brp/db-core/base/actions";
|
|
2
|
-
import
|
|
2
|
+
import { addId } from "@wxn0brp/db-core/helpers/addId";
|
|
3
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";
|
|
@@ -73,12 +73,11 @@ export class FileActions extends dbActionBase {
|
|
|
73
73
|
/**
|
|
74
74
|
* Add a new entry to the specified database.
|
|
75
75
|
*/
|
|
76
|
-
async add({ collection, data
|
|
76
|
+
async add({ collection, data }) {
|
|
77
77
|
await this.ensureCollection(arguments[0]);
|
|
78
78
|
const c_path = this._getCollectionPath(collection);
|
|
79
79
|
const file = c_path + await getLastFile(c_path, this.options.maxFileSize);
|
|
80
|
-
|
|
81
|
-
data._id = data._id || gen();
|
|
80
|
+
await addId(arguments[0], this);
|
|
82
81
|
await this.fileCpu.add(file, data);
|
|
83
82
|
return data;
|
|
84
83
|
}
|
package/dist/file/find.d.ts
CHANGED
|
@@ -4,8 +4,8 @@ import { VContext } from "@wxn0brp/db-core/types/types";
|
|
|
4
4
|
/**
|
|
5
5
|
* Asynchronously finds entries in a file based on search criteria.
|
|
6
6
|
*/
|
|
7
|
-
export declare function find(file: string,
|
|
7
|
+
export declare function find(file: string, search: Search, context?: VContext, 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,
|
|
11
|
+
export declare function findOne(file: string, search: Search, context?: VContext, findOpts?: FindOpts): Promise<any | false>;
|
package/dist/file/find.js
CHANGED
|
@@ -7,15 +7,15 @@ import { pathRepair } from "@wxn0brp/db-core/customFileCpu";
|
|
|
7
7
|
/**
|
|
8
8
|
* Processes a line of text from a file and checks if it matches the search criteria.
|
|
9
9
|
*/
|
|
10
|
-
async function findProcesLine(
|
|
10
|
+
async function findProcesLine(search, line, context = {}, findOpts = {}) {
|
|
11
11
|
const ob = parseData(line);
|
|
12
12
|
let res = false;
|
|
13
|
-
if (typeof
|
|
14
|
-
if (
|
|
13
|
+
if (typeof search === "function") {
|
|
14
|
+
if (search(ob, context))
|
|
15
15
|
res = true;
|
|
16
16
|
}
|
|
17
|
-
else if (typeof
|
|
18
|
-
if (hasFieldsAdvanced(ob,
|
|
17
|
+
else if (typeof search === "object" && !Array.isArray(search)) {
|
|
18
|
+
if (hasFieldsAdvanced(ob, search))
|
|
19
19
|
res = true;
|
|
20
20
|
}
|
|
21
21
|
if (res)
|
|
@@ -25,7 +25,7 @@ async function findProcesLine(arg, line, context = {}, findOpts = {}) {
|
|
|
25
25
|
/**
|
|
26
26
|
* Asynchronously finds entries in a file based on search criteria.
|
|
27
27
|
*/
|
|
28
|
-
export async function find(file,
|
|
28
|
+
export async function find(file, search, context = {}, findOpts = {}) {
|
|
29
29
|
file = pathRepair(file);
|
|
30
30
|
return await new Promise(async (resolve) => {
|
|
31
31
|
if (!existsSync(file)) {
|
|
@@ -36,9 +36,12 @@ export async function find(file, arg, context = {}, findOpts = {}) {
|
|
|
36
36
|
const rl = createRL(file);
|
|
37
37
|
const resF = [];
|
|
38
38
|
for await (const line of rl) {
|
|
39
|
-
if (
|
|
39
|
+
if (!line)
|
|
40
40
|
continue;
|
|
41
|
-
const
|
|
41
|
+
const trimmed = line.trim();
|
|
42
|
+
if (!trimmed)
|
|
43
|
+
continue;
|
|
44
|
+
const res = await findProcesLine(search, trimmed, context, findOpts);
|
|
42
45
|
if (res)
|
|
43
46
|
resF.push(res);
|
|
44
47
|
}
|
|
@@ -50,7 +53,7 @@ export async function find(file, arg, context = {}, findOpts = {}) {
|
|
|
50
53
|
/**
|
|
51
54
|
* Asynchronously finds one entry in a file based on search criteria.
|
|
52
55
|
*/
|
|
53
|
-
export async function findOne(file,
|
|
56
|
+
export async function findOne(file, search, context = {}, findOpts = {}) {
|
|
54
57
|
file = pathRepair(file);
|
|
55
58
|
return await new Promise(async (resolve) => {
|
|
56
59
|
if (!existsSync(file)) {
|
|
@@ -60,9 +63,12 @@ export async function findOne(file, arg, context = {}, findOpts = {}) {
|
|
|
60
63
|
}
|
|
61
64
|
const rl = createRL(file);
|
|
62
65
|
for await (const line of rl) {
|
|
63
|
-
if (
|
|
66
|
+
if (!line)
|
|
67
|
+
continue;
|
|
68
|
+
const trimmed = line.trim();
|
|
69
|
+
if (!trimmed)
|
|
64
70
|
continue;
|
|
65
|
-
const res = await findProcesLine(
|
|
71
|
+
const res = await findProcesLine(search, trimmed, context, findOpts);
|
|
66
72
|
if (res) {
|
|
67
73
|
resolve(res);
|
|
68
74
|
rl.close();
|
package/dist/file/remove.js
CHANGED
|
@@ -17,11 +17,16 @@ async function removeWorker(file, one, search, context = {}) {
|
|
|
17
17
|
const rl = createRL(file + ".tmp");
|
|
18
18
|
let removed = false;
|
|
19
19
|
for await (let line of rl) {
|
|
20
|
+
if (!line)
|
|
21
|
+
continue;
|
|
22
|
+
const trimmed = line.trim();
|
|
20
23
|
if (one && removed) {
|
|
21
|
-
appendFileSync(file,
|
|
24
|
+
appendFileSync(file, trimmed + "\n");
|
|
22
25
|
continue;
|
|
23
26
|
}
|
|
24
|
-
|
|
27
|
+
if (!trimmed)
|
|
28
|
+
continue;
|
|
29
|
+
const data = parseData(trimmed);
|
|
25
30
|
if (typeof search === "function") {
|
|
26
31
|
if (search(data, context)) {
|
|
27
32
|
removed = true;
|
package/dist/file/update.js
CHANGED
|
@@ -18,11 +18,16 @@ async function updateWorker(file, one, search, updater, context = {}) {
|
|
|
18
18
|
const rl = createRL(file + ".tmp");
|
|
19
19
|
let updated = false;
|
|
20
20
|
for await (let line of rl) {
|
|
21
|
+
if (!line)
|
|
22
|
+
continue;
|
|
23
|
+
const trimmed = line.trim();
|
|
21
24
|
if (one && updated) {
|
|
22
|
-
await promises.appendFile(file,
|
|
25
|
+
await promises.appendFile(file, trimmed + "\n");
|
|
23
26
|
continue;
|
|
24
27
|
}
|
|
25
|
-
|
|
28
|
+
if (!trimmed)
|
|
29
|
+
continue;
|
|
30
|
+
const data = parseData(trimmed);
|
|
26
31
|
let ob = false;
|
|
27
32
|
if (typeof search === "function") {
|
|
28
33
|
ob = search(data, context) || false;
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = "0.1.
|
|
1
|
+
export const version = "0.1.4";
|
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.4",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"author": "wxn0brP",
|
|
@@ -16,11 +16,11 @@
|
|
|
16
16
|
"json5": "^2.2.3"
|
|
17
17
|
},
|
|
18
18
|
"peerDependencies": {
|
|
19
|
-
"@wxn0brp/db-core": ">=0.2.
|
|
19
|
+
"@wxn0brp/db-core": ">=0.2.4"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@types/bun": "*",
|
|
23
|
-
"@wxn0brp/db-core": "^0.2.
|
|
23
|
+
"@wxn0brp/db-core": "^0.2.4",
|
|
24
24
|
"tsc-alias": "*",
|
|
25
25
|
"typescript": "*"
|
|
26
26
|
},
|
|
@@ -39,4 +39,4 @@
|
|
|
39
39
|
"default": "./dist/*.js"
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
|
-
}
|
|
42
|
+
}
|