@adminforth/storage-adapter-local 1.0.4 → 1.0.5

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.
Files changed (3) hide show
  1. package/dist/index.js +33 -2
  2. package/index.ts +31 -2
  3. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -73,12 +73,43 @@ class AdminForthStorageAdapterLocalFilesystem {
73
73
  }
74
74
  markKeyForDeletation(key) {
75
75
  return __awaiter(this, void 0, void 0, function* () {
76
- throw new Error("Method \"markKeyForDeletation\" is deprecated, use markKeyForDeletion instead");
76
+ console.error("Method \"markKeyForDeletation\" is deprecated, use markKeyForDeletion instead");
77
+ const metadata = yield this.metadataDb.get(key).catch((e) => {
78
+ console.error(`Could not read metadata from db: ${e}`);
79
+ throw new Error(`Could not read metadata from db: ${e}`);
80
+ });
81
+ if (!metadata) {
82
+ console.error(`Metadata for key ${key} not found`);
83
+ return;
84
+ }
85
+ const metadataParsed = JSON.parse(metadata);
86
+ try {
87
+ yield this.candidatesForDeletionDb.get(key);
88
+ // if key already exists, do nothing
89
+ return;
90
+ }
91
+ catch (e) {
92
+ // if key does not exist, continue
93
+ }
94
+ try {
95
+ yield this.candidatesForDeletionDb.put(key, metadataParsed.createdAt);
96
+ }
97
+ catch (e) {
98
+ console.error(`Could not write metadata to db: ${e}`);
99
+ throw new Error(`Could not write metadata to db: ${e}`);
100
+ }
77
101
  });
78
102
  }
79
103
  markKeyForNotDeletation(key) {
80
104
  return __awaiter(this, void 0, void 0, function* () {
81
- throw new Error("Method \"markKeyForNotDeletation\" is deprecated, use markKeyForNotDeletion instead");
105
+ console.error("Method \"markKeyForNotDeletation\" is deprecated, use markKeyForNotDeletion instead");
106
+ try {
107
+ // if key exists, delete it
108
+ yield this.candidatesForDeletionDb.del(key);
109
+ }
110
+ catch (e) {
111
+ // if key does not exist, do nothing
112
+ }
82
113
  });
83
114
  }
84
115
  markKeyForDeletion(key) {
package/index.ts CHANGED
@@ -99,11 +99,40 @@ export default class AdminForthStorageAdapterLocalFilesystem implements StorageA
99
99
  }
100
100
 
101
101
  async markKeyForDeletation(key: string): Promise<void> {
102
- throw new Error("Method \"markKeyForDeletation\" is deprecated, use markKeyForDeletion instead");
102
+ console.error("Method \"markKeyForDeletation\" is deprecated, use markKeyForDeletion instead");
103
+ const metadata = await this.metadataDb.get(key).catch((e) => {
104
+ console.error(`Could not read metadata from db: ${e}`);
105
+ throw new Error(`Could not read metadata from db: ${e}`);
106
+ });
107
+ if (!metadata) {
108
+ console.error(`Metadata for key ${key} not found`);
109
+ return;
110
+ }
111
+ const metadataParsed = JSON.parse(metadata);
112
+
113
+ try {
114
+ await this.candidatesForDeletionDb.get(key);
115
+ // if key already exists, do nothing
116
+ return;
117
+ } catch (e) {
118
+ // if key does not exist, continue
119
+ }
120
+ try {
121
+ await this.candidatesForDeletionDb.put(key, metadataParsed.createdAt)
122
+ } catch (e) {
123
+ console.error(`Could not write metadata to db: ${e}`);
124
+ throw new Error(`Could not write metadata to db: ${e}`);
125
+ }
103
126
  }
104
127
 
105
128
  async markKeyForNotDeletation(key: string): Promise<void> {
106
- throw new Error("Method \"markKeyForNotDeletation\" is deprecated, use markKeyForNotDeletion instead");
129
+ console.error("Method \"markKeyForNotDeletation\" is deprecated, use markKeyForNotDeletion instead");
130
+ try {
131
+ // if key exists, delete it
132
+ await this.candidatesForDeletionDb.del(key);
133
+ } catch (e) {
134
+ // if key does not exist, do nothing
135
+ }
107
136
  }
108
137
 
109
138
  async markKeyForDeletion(key: string): Promise<void> {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adminforth/storage-adapter-local",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",