@hinkal/common 0.1.64 → 0.1.65
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("../../error-handling/logError.cjs"),c=require("./BaseCacheDevice.cjs");class l extends c.BaseCacheDevice{filePath;constructor(e){super(),this.filePath=e,console.log("constructor read:"),this.readFileFromDevice()}readFileFromDevice(){if(this.filePath)try{const e=require("fs");if(console.log("filepath exists",e.existsSync(this.filePath)),e.existsSync(this.filePath)){const t=JSON.parse(e.readFileSync(this.filePath).toString());Object.entries(t).forEach(([r,o])=>{console.log("readfile key",r),this.setInMemory(r,o)})}}catch(e){s.logError("FileCacheDevice Constructor Error",{err:e})}}get(e){return this.getInMemory(e)}set(e,t){if(console.log("set read:"),this.readFileFromDevice(),console.log("set in memory",e),this.setInMemory(e,t),this.filePath)try{require("fs").writeFileSync(this.filePath,JSON.stringify(Object.fromEntries(this.inMemoryCache)))}catch(i){s.logError("FileCacheDevice set function",{err:i})}}}exports.FileCacheDevice=l;
|
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
import { logError as
|
|
2
|
-
import { BaseCacheDevice as
|
|
3
|
-
class
|
|
1
|
+
import { logError as s } from "../../error-handling/logError.mjs";
|
|
2
|
+
import { BaseCacheDevice as c } from "./BaseCacheDevice.mjs";
|
|
3
|
+
class a extends c {
|
|
4
4
|
filePath;
|
|
5
5
|
constructor(e) {
|
|
6
|
-
super(), this.filePath = e, this.readFileFromDevice();
|
|
6
|
+
super(), this.filePath = e, console.log("constructor read:"), this.readFileFromDevice();
|
|
7
7
|
}
|
|
8
8
|
readFileFromDevice() {
|
|
9
9
|
if (this.filePath)
|
|
10
10
|
try {
|
|
11
11
|
const e = require("fs");
|
|
12
|
-
if (e.existsSync(this.filePath)) {
|
|
12
|
+
if (console.log("filepath exists", e.existsSync(this.filePath)), e.existsSync(this.filePath)) {
|
|
13
13
|
const t = JSON.parse(e.readFileSync(this.filePath).toString());
|
|
14
|
-
Object.entries(t).forEach(([
|
|
15
|
-
this.setInMemory(
|
|
14
|
+
Object.entries(t).forEach(([r, o]) => {
|
|
15
|
+
console.log("readfile key", r), this.setInMemory(r, o);
|
|
16
16
|
});
|
|
17
17
|
}
|
|
18
18
|
} catch (e) {
|
|
19
|
-
|
|
19
|
+
s("FileCacheDevice Constructor Error", { err: e });
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
get(e) {
|
|
23
23
|
return this.getInMemory(e);
|
|
24
24
|
}
|
|
25
25
|
set(e, t) {
|
|
26
|
-
if (this.readFileFromDevice(), this.setInMemory(e, t), this.filePath)
|
|
26
|
+
if (console.log("set read:"), this.readFileFromDevice(), console.log("set in memory", e), this.setInMemory(e, t), this.filePath)
|
|
27
27
|
try {
|
|
28
28
|
require("fs").writeFileSync(this.filePath, JSON.stringify(Object.fromEntries(this.inMemoryCache)));
|
|
29
29
|
} catch (i) {
|
|
30
|
-
|
|
30
|
+
s("FileCacheDevice set function", { err: i });
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
export {
|
|
35
|
-
|
|
35
|
+
a as FileCacheDevice
|
|
36
36
|
};
|