@wxn0brp/db-storage-csv 0.110.0 → 0.120.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/README.md CHANGED
@@ -34,4 +34,4 @@ const singleFileDB = createCsvValthera({
34
34
 
35
35
  ## License
36
36
 
37
- MIT
37
+ MIT
package/dist/action.js CHANGED
@@ -20,10 +20,31 @@ export class DbStorageCsv extends CustomActionsBase {
20
20
  async read(file) {
21
21
  const path = this._getPath(file);
22
22
  const data = await readFile(path, "utf-8");
23
- return parse(data, { columns: true });
23
+ const records = parse(data, {
24
+ columns: true,
25
+ cast: true,
26
+ });
27
+ for (const record of records) {
28
+ for (const key of Object.keys(record)) {
29
+ const val = record[key];
30
+ if (val === "") {
31
+ delete record[key];
32
+ }
33
+ else if (typeof val === "string" &&
34
+ (val.startsWith("{") || val.startsWith("["))) {
35
+ try {
36
+ record[key] = JSON.parse(val);
37
+ }
38
+ catch { }
39
+ }
40
+ }
41
+ }
42
+ return records;
24
43
  }
25
44
  async write(file, data) {
26
- const string = stringify(data, { header: true });
45
+ const string = stringify(data, {
46
+ header: true,
47
+ });
27
48
  const path = this._getPath(file);
28
49
  await writeFile(path, string);
29
50
  }
@@ -32,6 +53,7 @@ export class DbStorageCsv extends CustomActionsBase {
32
53
  if (this.opts.file) {
33
54
  try {
34
55
  await access(path);
56
+ return false;
35
57
  }
36
58
  catch (error) {
37
59
  await writeFile(path, "");
@@ -40,9 +62,12 @@ export class DbStorageCsv extends CustomActionsBase {
40
62
  else if (this.opts.dir) {
41
63
  try {
42
64
  await access(path);
65
+ return false;
43
66
  }
44
67
  catch (error) {
45
- await mkdir(path.split("/").slice(0, -1).join("/"), { recursive: true });
68
+ await mkdir(path.split("/").slice(0, -1).join("/"), {
69
+ recursive: true,
70
+ });
46
71
  await writeFile(path, "");
47
72
  }
48
73
  }
@@ -60,10 +85,20 @@ export class DbStorageCsv extends CustomActionsBase {
60
85
  }
61
86
  async getCollections() {
62
87
  if (this.opts.file) {
63
- return [this.opts.file];
88
+ return [
89
+ this.opts.file,
90
+ ];
64
91
  }
65
92
  else if (this.opts.dir) {
66
- return await readdir(this.opts.dir, { recursive: true });
93
+ try {
94
+ const files = await readdir(this.opts.dir, {
95
+ recursive: true,
96
+ });
97
+ return files.map(f => (f.endsWith(".csv") ? f.slice(0, -4) : f));
98
+ }
99
+ catch {
100
+ return [];
101
+ }
67
102
  }
68
103
  else {
69
104
  return [];
package/dist/index.js CHANGED
@@ -3,6 +3,6 @@ import { DbStorageCsv } from "./action.js";
3
3
  export function createCsvValthera(opts) {
4
4
  const csvStorage = new DbStorageCsv(opts);
5
5
  return new ValtheraClass({
6
- dbAction: csvStorage
6
+ adapter: csvStorage,
7
7
  });
8
8
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wxn0brp/db-storage-csv",
3
- "version": "0.110.0",
3
+ "version": "0.120.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "description": "ValtheraDB Storage CSV",
@@ -19,16 +19,17 @@
19
19
  "csv"
20
20
  ],
21
21
  "peerDependencies": {
22
- "@wxn0brp/db-core": ">=0.11.0"
22
+ "@wxn0brp/db-core": "^0.12.0"
23
23
  },
24
24
  "dependencies": {
25
- "csv": "^6.5.1"
25
+ "csv": "^6.6.3"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@types/bun": "*",
29
- "@wxn0brp/db-core": "^0.11.0",
29
+ "@wxn0brp/biome": "*",
30
+ "@wxn0brp/db-core": "^0.12.0",
30
31
  "tsc-alias": "^1",
31
- "typescript": "^6"
32
+ "typescript": "^7"
32
33
  },
33
34
  "files": [
34
35
  "dist"