@adminforth/key-value-adapter-leveldb 1.0.1
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/LICENSE +21 -0
- package/dist/index.js +39 -0
- package/dist/types.js +1 -0
- package/index.ts +33 -0
- package/package.json +24 -0
- package/tsconfig.json +12 -0
- package/types.ts +4 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Devforth.io
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { Level } from 'level';
|
|
11
|
+
export default class LevelDBKeyValueAdapter {
|
|
12
|
+
constructor(options) {
|
|
13
|
+
this.options = options;
|
|
14
|
+
this.db = new Level(this.options.dbPath, this.options.dbOptions || {});
|
|
15
|
+
}
|
|
16
|
+
set(key, value, expiresInSeconds) {
|
|
17
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
yield this.db.put(key, value);
|
|
19
|
+
if (!expiresInSeconds)
|
|
20
|
+
return;
|
|
21
|
+
setTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
yield this.db.del(key).catch(() => null);
|
|
23
|
+
}), (expiresInSeconds || 0) * 1000);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
get(key) {
|
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
const value = yield this.db.get(key).catch(() => null);
|
|
29
|
+
if (value === undefined)
|
|
30
|
+
return null;
|
|
31
|
+
return value;
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
delete(key) {
|
|
35
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
yield this.db.del(key);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/index.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { KeyValueAdapter } from "adminforth";
|
|
2
|
+
import { AdapterOptions } from "./types.js";
|
|
3
|
+
import { Level } from 'level';
|
|
4
|
+
|
|
5
|
+
export default class LevelDBKeyValueAdapter implements KeyValueAdapter {
|
|
6
|
+
options: AdapterOptions;
|
|
7
|
+
private db: Level;
|
|
8
|
+
|
|
9
|
+
constructor(options: AdapterOptions) {
|
|
10
|
+
this.options = options;
|
|
11
|
+
this.db = new Level(this.options.dbPath, this.options.dbOptions || {});
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async set(key, value, expiresInSeconds?) {
|
|
15
|
+
await this.db.put(key, value);
|
|
16
|
+
|
|
17
|
+
if (!expiresInSeconds) return;
|
|
18
|
+
setTimeout(async () => {
|
|
19
|
+
await this.db.del(key).catch(() => null);
|
|
20
|
+
}, (expiresInSeconds || 0) * 1000);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async get(key) {
|
|
24
|
+
const value = await this.db.get(key).catch(() => null);
|
|
25
|
+
if (value === undefined) return null;
|
|
26
|
+
return value;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async delete(key) {
|
|
30
|
+
await this.db.del(key);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@adminforth/key-value-adapter-leveldb",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"types": "dist/index.d.ts",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc && npm version patch",
|
|
9
|
+
"rollout": "npm run build && npm publish --access public",
|
|
10
|
+
"prepare": "npm link adminforth"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [],
|
|
13
|
+
"author": "",
|
|
14
|
+
"license": "ISC",
|
|
15
|
+
"description": "",
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"file-type": "^20.5.0",
|
|
18
|
+
"level": "^10.0.0",
|
|
19
|
+
"typescript": "^5.8.3"
|
|
20
|
+
},
|
|
21
|
+
"peerDependencies": {
|
|
22
|
+
"adminforth": "next"
|
|
23
|
+
}
|
|
24
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include*/
|
|
4
|
+
"module": "node16", /* Specify what module code is generated. */
|
|
5
|
+
"outDir": "./dist", /* Specify an output folder for all emitted files. */
|
|
6
|
+
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. */
|
|
7
|
+
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
|
|
8
|
+
"strict": false, /* Enable all strict type-checking options. */
|
|
9
|
+
"skipLibCheck": true, /* Skip type checking all .d.ts files. */
|
|
10
|
+
},
|
|
11
|
+
"exclude": ["node_modules", "dist", "custom"], /* Exclude files from compilation. */
|
|
12
|
+
}
|
package/types.ts
ADDED