@wxn0brp/db-storage-dir 0.90.0 → 0.100.0
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 +11 -11
- package/dist/action.js +21 -21
- package/dist/action.utils.d.ts +1 -1
- package/dist/action.utils.js +3 -3
- package/dist/file/find.d.ts +3 -5
- package/dist/file/find.js +6 -5
- package/dist/file/index.js +2 -2
- package/dist/file/remove.d.ts +2 -3
- package/dist/file/remove.js +2 -1
- package/dist/file/update.d.ts +2 -3
- package/dist/file/update.js +2 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/package.json +3 -3
- package/dist/version.js +0 -1
package/dist/action.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ActionsBase } from "@wxn0brp/db-core/base/actions";
|
|
2
2
|
import { Data } from "@wxn0brp/db-core/types/data";
|
|
3
3
|
import { FileCpu } from "@wxn0brp/db-core/types/fileCpu";
|
|
4
|
-
import
|
|
4
|
+
import * as Query from "@wxn0brp/db-core/types/query";
|
|
5
5
|
import { FileActionsUtils } from "./action.utils.js";
|
|
6
6
|
import { DbDirOpts } from "./types.js";
|
|
7
7
|
/**
|
|
@@ -32,41 +32,41 @@ export declare class FileActions extends ActionsBase {
|
|
|
32
32
|
/**
|
|
33
33
|
* Check and create the specified collection if it doesn't exist.
|
|
34
34
|
*/
|
|
35
|
-
ensureCollection(
|
|
35
|
+
ensureCollection(collection: string): Promise<boolean>;
|
|
36
36
|
/**
|
|
37
37
|
* Check if a collection exists.
|
|
38
38
|
*/
|
|
39
|
-
issetCollection(
|
|
39
|
+
issetCollection(collection: string): Promise<boolean>;
|
|
40
40
|
/**
|
|
41
41
|
* Add a new entry to the specified database.
|
|
42
42
|
*/
|
|
43
|
-
add(query:
|
|
43
|
+
add(query: Query.AddQuery): Promise<import("@wxn0brp/db-core/types/arg").Arg<Data>>;
|
|
44
44
|
/**
|
|
45
45
|
* Find entries in the specified database based on search criteria.
|
|
46
46
|
*/
|
|
47
|
-
find(query:
|
|
47
|
+
find(query: Query.FindQuery): Promise<Data[]>;
|
|
48
48
|
/**
|
|
49
49
|
* Find the first matching entry in the specified database based on search criteria.
|
|
50
50
|
*/
|
|
51
|
-
findOne(query:
|
|
51
|
+
findOne(query: Query.FindOneQuery): Promise<Data>;
|
|
52
52
|
/**
|
|
53
53
|
* Update entries in the specified database based on search criteria and an updater function or object.
|
|
54
54
|
*/
|
|
55
|
-
update(query:
|
|
55
|
+
update(query: Query.UpdateQuery): Promise<any[]>;
|
|
56
56
|
/**
|
|
57
57
|
* Update the first matching entry in the specified database based on search criteria and an updater function or object.
|
|
58
58
|
*/
|
|
59
|
-
updateOne(query:
|
|
59
|
+
updateOne(query: Query.UpdateQuery): Promise<any>;
|
|
60
60
|
/**
|
|
61
61
|
* Remove entries from the specified database based on search criteria.
|
|
62
62
|
*/
|
|
63
|
-
remove(query:
|
|
63
|
+
remove(query: Query.RemoveQuery): Promise<any[]>;
|
|
64
64
|
/**
|
|
65
65
|
* Remove the first matching entry from the specified database based on search criteria.
|
|
66
66
|
*/
|
|
67
|
-
removeOne(query:
|
|
67
|
+
removeOne(query: Query.RemoveQuery): Promise<any>;
|
|
68
68
|
/**
|
|
69
69
|
* Removes a database collection from the file system.
|
|
70
70
|
*/
|
|
71
|
-
removeCollection(
|
|
71
|
+
removeCollection(collection: string): Promise<boolean>;
|
|
72
72
|
}
|
package/dist/action.js
CHANGED
|
@@ -59,7 +59,7 @@ export class FileActions extends ActionsBase {
|
|
|
59
59
|
/**
|
|
60
60
|
* Check and create the specified collection if it doesn't exist.
|
|
61
61
|
*/
|
|
62
|
-
async ensureCollection(
|
|
62
|
+
async ensureCollection(collection) {
|
|
63
63
|
if (await this.issetCollection(collection))
|
|
64
64
|
return;
|
|
65
65
|
const c_path = this._getCollectionPath(collection);
|
|
@@ -69,7 +69,7 @@ export class FileActions extends ActionsBase {
|
|
|
69
69
|
/**
|
|
70
70
|
* Check if a collection exists.
|
|
71
71
|
*/
|
|
72
|
-
async issetCollection(
|
|
72
|
+
async issetCollection(collection) {
|
|
73
73
|
const path = this._getCollectionPath(collection);
|
|
74
74
|
try {
|
|
75
75
|
await promises.access(path);
|
|
@@ -84,18 +84,18 @@ export class FileActions extends ActionsBase {
|
|
|
84
84
|
*/
|
|
85
85
|
async add(query) {
|
|
86
86
|
const { collection, data } = query;
|
|
87
|
-
await this.ensureCollection(
|
|
87
|
+
await this.ensureCollection(collection);
|
|
88
88
|
const c_path = this._getCollectionPath(collection);
|
|
89
89
|
const file = c_path + await this.utils.getLastFile(c_path, this.options.maxFileSize, query);
|
|
90
90
|
await addId(query, this);
|
|
91
|
-
await this.fileCpu.add(file,
|
|
91
|
+
await this.fileCpu.add(file, query);
|
|
92
92
|
return data;
|
|
93
93
|
}
|
|
94
94
|
/**
|
|
95
95
|
* Find entries in the specified database based on search criteria.
|
|
96
96
|
*/
|
|
97
97
|
async find(query) {
|
|
98
|
-
await this.ensureCollection(query);
|
|
98
|
+
await this.ensureCollection(query.collection);
|
|
99
99
|
const c_path = this._getCollectionPath(query.collection);
|
|
100
100
|
let files = await this.utils.getSortedFiles(c_path, query);
|
|
101
101
|
if (files.length == 0)
|
|
@@ -108,12 +108,12 @@ export class FileActions extends ActionsBase {
|
|
|
108
108
|
* Find the first matching entry in the specified database based on search criteria.
|
|
109
109
|
*/
|
|
110
110
|
async findOne(query) {
|
|
111
|
-
const { collection
|
|
112
|
-
await this.ensureCollection(
|
|
111
|
+
const { collection } = query;
|
|
112
|
+
await this.ensureCollection(collection);
|
|
113
113
|
const c_path = this._getCollectionPath(collection);
|
|
114
114
|
const files = await this.utils.getSortedFiles(c_path, query);
|
|
115
115
|
for (let f of files) {
|
|
116
|
-
let data = await this.fileCpu.findOne(c_path + f,
|
|
116
|
+
let data = await this.fileCpu.findOne(c_path + f, query);
|
|
117
117
|
if (data)
|
|
118
118
|
return data;
|
|
119
119
|
}
|
|
@@ -123,40 +123,40 @@ export class FileActions extends ActionsBase {
|
|
|
123
123
|
* Update entries in the specified database based on search criteria and an updater function or object.
|
|
124
124
|
*/
|
|
125
125
|
async update(query) {
|
|
126
|
-
const { collection
|
|
127
|
-
await this.ensureCollection(
|
|
128
|
-
return await this.utils.operationUpdater(this._getCollectionPath(collection), this.fileCpu.update.bind(this.fileCpu), false, query
|
|
126
|
+
const { collection } = query;
|
|
127
|
+
await this.ensureCollection(collection);
|
|
128
|
+
return await this.utils.operationUpdater(this._getCollectionPath(collection), this.fileCpu.update.bind(this.fileCpu), false, query);
|
|
129
129
|
}
|
|
130
130
|
/**
|
|
131
131
|
* Update the first matching entry in the specified database based on search criteria and an updater function or object.
|
|
132
132
|
*/
|
|
133
133
|
async updateOne(query) {
|
|
134
|
-
const { collection
|
|
135
|
-
await this.ensureCollection(
|
|
136
|
-
const res = await this.utils.operationUpdater(this._getCollectionPath(collection), this.fileCpu.update.bind(this.fileCpu), true, query
|
|
134
|
+
const { collection } = query;
|
|
135
|
+
await this.ensureCollection(collection);
|
|
136
|
+
const res = await this.utils.operationUpdater(this._getCollectionPath(collection), this.fileCpu.update.bind(this.fileCpu), true, query);
|
|
137
137
|
return res[0];
|
|
138
138
|
}
|
|
139
139
|
/**
|
|
140
140
|
* Remove entries from the specified database based on search criteria.
|
|
141
141
|
*/
|
|
142
142
|
async remove(query) {
|
|
143
|
-
const { collection
|
|
144
|
-
await this.ensureCollection(query);
|
|
145
|
-
return await this.utils.operationUpdater(this._getCollectionPath(collection), this.fileCpu.remove.bind(this.fileCpu), false, query
|
|
143
|
+
const { collection } = query;
|
|
144
|
+
await this.ensureCollection(query.collection);
|
|
145
|
+
return await this.utils.operationUpdater(this._getCollectionPath(collection), this.fileCpu.remove.bind(this.fileCpu), false, query);
|
|
146
146
|
}
|
|
147
147
|
/**
|
|
148
148
|
* Remove the first matching entry from the specified database based on search criteria.
|
|
149
149
|
*/
|
|
150
150
|
async removeOne(query) {
|
|
151
|
-
const { collection
|
|
152
|
-
await this.ensureCollection(query);
|
|
153
|
-
const res = await this.utils.operationUpdater(this._getCollectionPath(collection), this.fileCpu.remove.bind(this.fileCpu), true, query
|
|
151
|
+
const { collection } = query;
|
|
152
|
+
await this.ensureCollection(query.collection);
|
|
153
|
+
const res = await this.utils.operationUpdater(this._getCollectionPath(collection), this.fileCpu.remove.bind(this.fileCpu), true, query);
|
|
154
154
|
return res[0];
|
|
155
155
|
}
|
|
156
156
|
/**
|
|
157
157
|
* Removes a database collection from the file system.
|
|
158
158
|
*/
|
|
159
|
-
async removeCollection(
|
|
159
|
+
async removeCollection(collection) {
|
|
160
160
|
await promises.rm(this.folder + "/" + collection, { recursive: true, force: true });
|
|
161
161
|
return true;
|
|
162
162
|
}
|
package/dist/action.utils.d.ts
CHANGED
|
@@ -8,5 +8,5 @@ export declare class FileActionsUtils {
|
|
|
8
8
|
* Get all files in a directory sorted by name.
|
|
9
9
|
*/
|
|
10
10
|
getSortedFiles(folder: string, query: VQuery): Promise<string[]>;
|
|
11
|
-
operationUpdater(c_path: string, worker: (file: string,
|
|
11
|
+
operationUpdater(c_path: string, worker: (file: string, config: VQuery, one: boolean) => Promise<boolean>, one: boolean, config: VQuery): Promise<any[]>;
|
|
12
12
|
}
|
package/dist/action.utils.js
CHANGED
|
@@ -42,11 +42,11 @@ export class FileActionsUtils {
|
|
|
42
42
|
query.control.dir.sortedFiles = sorted;
|
|
43
43
|
return sorted;
|
|
44
44
|
}
|
|
45
|
-
async operationUpdater(c_path, worker, one,
|
|
46
|
-
const files = await this.getSortedFiles(c_path,
|
|
45
|
+
async operationUpdater(c_path, worker, one, config) {
|
|
46
|
+
const files = await this.getSortedFiles(c_path, config);
|
|
47
47
|
let update = [];
|
|
48
48
|
for (const file of files) {
|
|
49
|
-
const updated = await worker(c_path + file,
|
|
49
|
+
const updated = await worker(c_path + file, config, one);
|
|
50
50
|
update.push(updated);
|
|
51
51
|
if (one && updated)
|
|
52
52
|
break;
|
package/dist/file/find.d.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { FindOpts } from "@wxn0brp/db-core/types/options";
|
|
3
|
-
import { VContext } from "@wxn0brp/db-core/types/types";
|
|
1
|
+
import { FindOneQuery, FindQuery } from "@wxn0brp/db-core/types/query";
|
|
4
2
|
/**
|
|
5
3
|
* Asynchronously finds entries in a file based on search criteria.
|
|
6
4
|
*/
|
|
7
|
-
export declare function find(file: string,
|
|
5
|
+
export declare function find(file: string, config: FindQuery): Promise<any[]>;
|
|
8
6
|
/**
|
|
9
7
|
* Asynchronously finds one entry in a file based on search criteria.
|
|
10
8
|
*/
|
|
11
|
-
export declare function findOne(file: string,
|
|
9
|
+
export declare function findOne(file: string, config: FindOneQuery): Promise<any | false>;
|
package/dist/file/find.js
CHANGED
|
@@ -7,9 +7,10 @@ import { createRL } from "./utils.js";
|
|
|
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(config, line) {
|
|
11
11
|
const ob = parseData(line);
|
|
12
12
|
let res = false;
|
|
13
|
+
const { search, context, findOpts = {} } = config;
|
|
13
14
|
if (typeof search === "function") {
|
|
14
15
|
if (search(ob, context))
|
|
15
16
|
res = true;
|
|
@@ -25,7 +26,7 @@ async function findProcesLine(search, line, context = {}, findOpts = {}) {
|
|
|
25
26
|
/**
|
|
26
27
|
* Asynchronously finds entries in a file based on search criteria.
|
|
27
28
|
*/
|
|
28
|
-
export async function find(file,
|
|
29
|
+
export async function find(file, config) {
|
|
29
30
|
file = pathRepair(file);
|
|
30
31
|
return await new Promise(async (resolve) => {
|
|
31
32
|
if (!existsSync(file)) {
|
|
@@ -41,7 +42,7 @@ export async function find(file, search, context = {}, findOpts = {}) {
|
|
|
41
42
|
const trimmed = line.trim();
|
|
42
43
|
if (!trimmed)
|
|
43
44
|
continue;
|
|
44
|
-
const res = await findProcesLine(
|
|
45
|
+
const res = await findProcesLine(config, trimmed);
|
|
45
46
|
if (res)
|
|
46
47
|
results.push(res);
|
|
47
48
|
}
|
|
@@ -53,7 +54,7 @@ export async function find(file, search, context = {}, findOpts = {}) {
|
|
|
53
54
|
/**
|
|
54
55
|
* Asynchronously finds one entry in a file based on search criteria.
|
|
55
56
|
*/
|
|
56
|
-
export async function findOne(file,
|
|
57
|
+
export async function findOne(file, config) {
|
|
57
58
|
file = pathRepair(file);
|
|
58
59
|
return await new Promise(async (resolve) => {
|
|
59
60
|
if (!existsSync(file)) {
|
|
@@ -68,7 +69,7 @@ export async function findOne(file, search, context = {}, findOpts = {}) {
|
|
|
68
69
|
const trimmed = line.trim();
|
|
69
70
|
if (!trimmed)
|
|
70
71
|
continue;
|
|
71
|
-
const res = await findProcesLine(
|
|
72
|
+
const res = await findProcesLine(config, trimmed);
|
|
72
73
|
if (res) {
|
|
73
74
|
resolve(res);
|
|
74
75
|
rl.close();
|
package/dist/file/index.js
CHANGED
|
@@ -4,8 +4,8 @@ import { find, findOne } from "./find.js";
|
|
|
4
4
|
import { remove } from "./remove.js";
|
|
5
5
|
import { update } from "./update.js";
|
|
6
6
|
export const vFileCpu = {
|
|
7
|
-
add: async (file,
|
|
8
|
-
const dataString = stringifyData(data);
|
|
7
|
+
add: async (file, config) => {
|
|
8
|
+
const dataString = stringifyData(config.data);
|
|
9
9
|
appendFileSync(file, dataString + "\n");
|
|
10
10
|
},
|
|
11
11
|
find,
|
package/dist/file/remove.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { VContext } from "@wxn0brp/db-core/types/types";
|
|
1
|
+
import { RemoveQuery } from "@wxn0brp/db-core/types/query";
|
|
3
2
|
/**
|
|
4
3
|
* Removes entries from a file based on search criteria.
|
|
5
4
|
*/
|
|
6
|
-
export declare function remove(file: string,
|
|
5
|
+
export declare function remove(file: string, config: RemoveQuery, one: boolean): Promise<any[]>;
|
package/dist/file/remove.js
CHANGED
|
@@ -6,7 +6,7 @@ import { createRL } from "./utils.js";
|
|
|
6
6
|
/**
|
|
7
7
|
* Removes entries from a file based on search criteria.
|
|
8
8
|
*/
|
|
9
|
-
export async function remove(file,
|
|
9
|
+
export async function remove(file, config, one) {
|
|
10
10
|
file = pathRepair(file);
|
|
11
11
|
if (!existsSync(file)) {
|
|
12
12
|
await promises.writeFile(file, "");
|
|
@@ -15,6 +15,7 @@ export async function remove(file, one, search, context = {}) {
|
|
|
15
15
|
await promises.copyFile(file, file + ".tmp");
|
|
16
16
|
await promises.writeFile(file, "");
|
|
17
17
|
const rl = createRL(file + ".tmp");
|
|
18
|
+
const { search, context } = config;
|
|
18
19
|
let removed = [];
|
|
19
20
|
for await (let line of rl) {
|
|
20
21
|
if (!line)
|
package/dist/file/update.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { VContext } from "@wxn0brp/db-core/types/types";
|
|
1
|
+
import { UpdateQuery } from "@wxn0brp/db-core/types/query";
|
|
3
2
|
/**
|
|
4
3
|
* Updates a file based on search criteria and an updater function or object.
|
|
5
4
|
*/
|
|
6
|
-
export declare function update(file: string,
|
|
5
|
+
export declare function update(file: string, config: UpdateQuery, one: boolean): Promise<any[]>;
|
package/dist/file/update.js
CHANGED
|
@@ -7,7 +7,7 @@ import { createRL } from "./utils.js";
|
|
|
7
7
|
/**
|
|
8
8
|
* Updates a file based on search criteria and an updater function or object.
|
|
9
9
|
*/
|
|
10
|
-
export async function update(file,
|
|
10
|
+
export async function update(file, config, one) {
|
|
11
11
|
file = pathRepair(file);
|
|
12
12
|
if (!existsSync(file)) {
|
|
13
13
|
await promises.writeFile(file, "");
|
|
@@ -16,6 +16,7 @@ export async function update(file, one, search, updater, context = {}) {
|
|
|
16
16
|
await promises.copyFile(file, file + ".tmp");
|
|
17
17
|
await promises.writeFile(file, "");
|
|
18
18
|
const rl = createRL(file + ".tmp");
|
|
19
|
+
const { search, updater, context } = config;
|
|
19
20
|
let updated = [];
|
|
20
21
|
for await (let line of rl) {
|
|
21
22
|
if (!line)
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FileActions } from "./action.js";
|
|
2
2
|
import { DbDirOpts } from "./types.js";
|
|
3
|
-
export * from "./file/index.js";
|
|
4
3
|
export * from "./action.js";
|
|
4
|
+
export * from "./file/index.js";
|
|
5
5
|
export declare function createFileActions(folder: string, options?: DbDirOpts): FileActions;
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { vFileCpu } from "./file/index.js";
|
|
2
1
|
import { FileActions } from "./action.js";
|
|
3
|
-
|
|
2
|
+
import { vFileCpu } from "./file/index.js";
|
|
4
3
|
export * from "./action.js";
|
|
4
|
+
export * from "./file/index.js";
|
|
5
5
|
export function createFileActions(folder, options = {}) {
|
|
6
6
|
return new FileActions(folder, options, vFileCpu);
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wxn0brp/db-storage-dir",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.100.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"author": "wxn0brP",
|
|
@@ -21,11 +21,11 @@
|
|
|
21
21
|
"json5": "^2.2.3"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
|
-
"@wxn0brp/db-core": "~0.
|
|
24
|
+
"@wxn0brp/db-core": "~0.10.0"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@types/bun": "*",
|
|
28
|
-
"@wxn0brp/db-core": "~0.
|
|
28
|
+
"@wxn0brp/db-core": "~0.10.0",
|
|
29
29
|
"tsc-alias": "*",
|
|
30
30
|
"typescript": "*"
|
|
31
31
|
},
|
package/dist/version.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const version = "0.90.0";
|