@wxn0brp/db-storage-csv 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 +4 -5
- package/dist/action.js +11 -12
- package/package.json +4 -4
package/dist/action.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { CustomActionsBase } from "@wxn0brp/db-core/base/custom";
|
|
2
|
-
import { VQuery } from "@wxn0brp/db-core/types/query";
|
|
3
2
|
export interface Opts {
|
|
4
3
|
file?: string;
|
|
5
4
|
dir?: string;
|
|
@@ -7,11 +6,11 @@ export interface Opts {
|
|
|
7
6
|
export declare class DbStorageCsv extends CustomActionsBase {
|
|
8
7
|
opts: Opts;
|
|
9
8
|
constructor(opts: Opts);
|
|
10
|
-
_getPath(
|
|
9
|
+
_getPath(collection: string): string;
|
|
11
10
|
read(file: string): Promise<unknown[]>;
|
|
12
11
|
write(file: string, data: any): Promise<void>;
|
|
13
|
-
ensureCollection(
|
|
14
|
-
issetCollection(
|
|
12
|
+
ensureCollection(collection: string): Promise<boolean>;
|
|
13
|
+
issetCollection(collection: string): Promise<boolean>;
|
|
15
14
|
getCollections(): Promise<string[]>;
|
|
16
|
-
removeCollection(
|
|
15
|
+
removeCollection(collection: string): Promise<boolean>;
|
|
17
16
|
}
|
package/dist/action.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { CustomFileCpu } from "@wxn0brp/db-core";
|
|
2
2
|
import { CustomActionsBase } from "@wxn0brp/db-core/base/custom";
|
|
3
|
-
import { access, mkdir, readdir, rm } from "fs/promises";
|
|
4
3
|
import { parse, stringify } from "csv/sync";
|
|
5
|
-
import { readFile, writeFile } from "fs/promises";
|
|
4
|
+
import { access, mkdir, readdir, readFile, rm, writeFile } from "fs/promises";
|
|
6
5
|
export class DbStorageCsv extends CustomActionsBase {
|
|
7
6
|
opts;
|
|
8
7
|
constructor(opts) {
|
|
@@ -10,26 +9,26 @@ export class DbStorageCsv extends CustomActionsBase {
|
|
|
10
9
|
this.opts = opts;
|
|
11
10
|
this.fileCpu = new CustomFileCpu(this.read.bind(this), this.write.bind(this));
|
|
12
11
|
}
|
|
13
|
-
_getPath(
|
|
12
|
+
_getPath(collection) {
|
|
14
13
|
if (this.opts.file) {
|
|
15
14
|
return this.opts.file;
|
|
16
15
|
}
|
|
17
16
|
else if (this.opts.dir) {
|
|
18
|
-
return this.opts.dir + "/" +
|
|
17
|
+
return this.opts.dir + "/" + collection + ".csv";
|
|
19
18
|
}
|
|
20
19
|
}
|
|
21
20
|
async read(file) {
|
|
22
|
-
const path = this._getPath(
|
|
21
|
+
const path = this._getPath(file);
|
|
23
22
|
const data = await readFile(path, "utf-8");
|
|
24
23
|
return parse(data, { columns: true });
|
|
25
24
|
}
|
|
26
25
|
async write(file, data) {
|
|
27
26
|
const string = stringify(data, { header: true });
|
|
28
|
-
const path = this._getPath(
|
|
27
|
+
const path = this._getPath(file);
|
|
29
28
|
await writeFile(path, string);
|
|
30
29
|
}
|
|
31
|
-
async ensureCollection(
|
|
32
|
-
const path = this._getPath(
|
|
30
|
+
async ensureCollection(collection) {
|
|
31
|
+
const path = this._getPath(collection);
|
|
33
32
|
if (this.opts.file) {
|
|
34
33
|
try {
|
|
35
34
|
await access(path);
|
|
@@ -49,8 +48,8 @@ export class DbStorageCsv extends CustomActionsBase {
|
|
|
49
48
|
}
|
|
50
49
|
return true;
|
|
51
50
|
}
|
|
52
|
-
async issetCollection(
|
|
53
|
-
const path = this._getPath(
|
|
51
|
+
async issetCollection(collection) {
|
|
52
|
+
const path = this._getPath(collection);
|
|
54
53
|
try {
|
|
55
54
|
await access(path);
|
|
56
55
|
return true;
|
|
@@ -70,8 +69,8 @@ export class DbStorageCsv extends CustomActionsBase {
|
|
|
70
69
|
return [];
|
|
71
70
|
}
|
|
72
71
|
}
|
|
73
|
-
async removeCollection(
|
|
74
|
-
await rm(this._getPath(
|
|
72
|
+
async removeCollection(collection) {
|
|
73
|
+
await rm(this._getPath(collection));
|
|
75
74
|
return true;
|
|
76
75
|
}
|
|
77
76
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wxn0brp/db-storage-csv",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.100.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"description": "ValtheraDB Storage CSV",
|
|
@@ -19,14 +19,14 @@
|
|
|
19
19
|
"csv"
|
|
20
20
|
],
|
|
21
21
|
"peerDependencies": {
|
|
22
|
-
"@wxn0brp/db-core": ">=0.
|
|
22
|
+
"@wxn0brp/db-core": ">=0.10.0"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"csv": "^6.
|
|
25
|
+
"csv": "^6.5.1"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@types/node": "*",
|
|
29
|
-
"@wxn0brp/db-core": "^0.
|
|
29
|
+
"@wxn0brp/db-core": "^0.10.0",
|
|
30
30
|
"tsc-alias": "*",
|
|
31
31
|
"typescript": "*"
|
|
32
32
|
},
|