fastkv 0.1.1 → 1.0.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 +8 -6
- package/dist/index.d.mts +12 -8
- package/dist/index.d.ts +12 -8
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +6 -2
package/README.md
CHANGED
|
@@ -6,8 +6,9 @@
|
|
|
6
6
|
|
|
7
7
|
FastKV is a key-value store which offers the following features:
|
|
8
8
|
|
|
9
|
-
-
|
|
10
|
-
-
|
|
9
|
+
- Supports temporary in-memory storage 🕒
|
|
10
|
+
- Supports persistent storage with JSON files 📁
|
|
11
|
+
- Lightweight with no dependencies ⚡
|
|
11
12
|
|
|
12
13
|
## Installation
|
|
13
14
|
|
|
@@ -28,19 +29,20 @@ import { KV } from 'fastkv';
|
|
|
28
29
|
|
|
29
30
|
// For TypeScript users, the KV supports generics:
|
|
30
31
|
// const example = new KV<string>();
|
|
32
|
+
// Or: example.get<string>('my-key-name');
|
|
31
33
|
|
|
32
34
|
const kv = new KV('./db.json'); // Save the data. Path resolves with process.cwd()
|
|
33
35
|
const cache = new KV('::memory::'); // Keep the data in the system's memory.
|
|
34
36
|
|
|
35
37
|
// Set data
|
|
36
|
-
|
|
38
|
+
kv.set('userSettings', { theme: 'dark' }); // -> KV
|
|
37
39
|
|
|
38
40
|
// Retreive data by a key
|
|
39
|
-
|
|
41
|
+
kv.get('userSettings'); // -> { theme: 'dark' }
|
|
40
42
|
|
|
41
43
|
// Retreive all data
|
|
42
|
-
|
|
44
|
+
kv.all(); // -> [{ key: 'userSettings', value: { theme: 'dark' } }]
|
|
43
45
|
|
|
44
46
|
// Clear the store
|
|
45
|
-
|
|
47
|
+
kv.clear(); // -> KV
|
|
46
48
|
```
|
package/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
type Entry<T> = {
|
|
2
|
+
key: string;
|
|
3
|
+
value: T;
|
|
4
|
+
};
|
|
1
5
|
/**
|
|
2
6
|
* Represents a key-value store.
|
|
3
7
|
* Initializing with `::memory::` uses in-memory storage.
|
|
@@ -14,25 +18,25 @@ declare class KV<T = any> {
|
|
|
14
18
|
* Sets a value to a key.
|
|
15
19
|
* @param key - The name of the key.
|
|
16
20
|
* @param value - The value to store.
|
|
17
|
-
* @returns
|
|
21
|
+
* @returns The value.
|
|
18
22
|
*/
|
|
19
|
-
set(key: string, value: T):
|
|
23
|
+
set(key: string, value: T): T;
|
|
20
24
|
/**
|
|
21
25
|
* Gets data by a key.
|
|
22
26
|
* @param key - The existing key's name.
|
|
23
|
-
* @returns
|
|
27
|
+
* @returns The found data, or null.
|
|
24
28
|
*/
|
|
25
|
-
get(key: string):
|
|
29
|
+
get<U = T>(key: string): U | null;
|
|
26
30
|
/**
|
|
27
31
|
* Gets all data in the store.
|
|
28
|
-
* @returns
|
|
32
|
+
* @returns An array of Entry objects [{ key: string, value: T }].
|
|
29
33
|
*/
|
|
30
|
-
all():
|
|
34
|
+
all(): Entry<T>[];
|
|
31
35
|
/**
|
|
32
36
|
* Clears all data in the store.
|
|
33
|
-
* @returns
|
|
37
|
+
* @returns The KV instance.
|
|
34
38
|
*/
|
|
35
|
-
clear():
|
|
39
|
+
clear(): this;
|
|
36
40
|
}
|
|
37
41
|
declare const _default: KV<any>;
|
|
38
42
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
type Entry<T> = {
|
|
2
|
+
key: string;
|
|
3
|
+
value: T;
|
|
4
|
+
};
|
|
1
5
|
/**
|
|
2
6
|
* Represents a key-value store.
|
|
3
7
|
* Initializing with `::memory::` uses in-memory storage.
|
|
@@ -14,25 +18,25 @@ declare class KV<T = any> {
|
|
|
14
18
|
* Sets a value to a key.
|
|
15
19
|
* @param key - The name of the key.
|
|
16
20
|
* @param value - The value to store.
|
|
17
|
-
* @returns
|
|
21
|
+
* @returns The value.
|
|
18
22
|
*/
|
|
19
|
-
set(key: string, value: T):
|
|
23
|
+
set(key: string, value: T): T;
|
|
20
24
|
/**
|
|
21
25
|
* Gets data by a key.
|
|
22
26
|
* @param key - The existing key's name.
|
|
23
|
-
* @returns
|
|
27
|
+
* @returns The found data, or null.
|
|
24
28
|
*/
|
|
25
|
-
get(key: string):
|
|
29
|
+
get<U = T>(key: string): U | null;
|
|
26
30
|
/**
|
|
27
31
|
* Gets all data in the store.
|
|
28
|
-
* @returns
|
|
32
|
+
* @returns An array of Entry objects [{ key: string, value: T }].
|
|
29
33
|
*/
|
|
30
|
-
all():
|
|
34
|
+
all(): Entry<T>[];
|
|
31
35
|
/**
|
|
32
36
|
* Clears all data in the store.
|
|
33
|
-
* @returns
|
|
37
|
+
* @returns The KV instance.
|
|
34
38
|
*/
|
|
35
|
-
clear():
|
|
39
|
+
clear(): this;
|
|
36
40
|
}
|
|
37
41
|
declare const _default: KV<any>;
|
|
38
42
|
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var l=Object.create;var e=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var y=Object.getPrototypeOf,f=Object.prototype.hasOwnProperty;var d=(r,t)=>{for(var i in t)e(r,i,{get:t[i],enumerable:!0})},c=(r,t,i,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of m(t))!f.call(r,s)&&s!==i&&e(r,s,{get:()=>t[s],enumerable:!(o=p(t,s))||o.enumerable});return r};var u=(r,t,i)=>(i=r!=null?l(y(r)):{},c(t||!r||!r.__esModule?e(i,"default",{value:r,enumerable:!0}):i,r)),g=r=>c(e({},"__esModule",{value:!0}),r);var b={};d(b,{KV:()=>n,default:()=>T});module.exports=g(b);var h=u(require("fs")),a=u(require("path")),n=class{#t;#r;constructor(t="::memory::"){this.#t=t,this.#r={},t!=="::memory::"&&(this.#t=a.default.resolve(process.cwd(),this.#t),this.#r=this.#s())}#s(){if(this.#t==="::memory::")return{};try{let t=h.default.readFileSync(this.#t,"utf8");return JSON.parse(t)||{}}catch{return{}}}#i(){this.#t!=="::memory::"&&h.default.writeFileSync(this.#t,JSON.stringify(this.#r),"utf8")}set(t,i){return this.#r[t]=i,this.#i(),i}get(t){return this.#r[t]??null}all(){return Object.entries(this.#r).map(([t,i])=>({key:t,value:i}))}clear(){return this.#r={},this.#i(),this}},T=new n;0&&(module.exports={KV});
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import s from"node:fs";import e from"node:path";var i=class{#t;#r;constructor(t="::memory::"){this.#t=t,this.#r={},t!=="::memory::"&&(this.#t=e.resolve(process.cwd(),this.#t),this.#r=this.#s())}#s(){if(this.#t==="::memory::")return{};try{let t=s.readFileSync(this.#t,"utf8");return JSON.parse(t)||{}}catch{return{}}}#i(){this.#t!=="::memory::"&&s.writeFileSync(this.#t,JSON.stringify(this.#r),"utf8")}set(t,r){return this.#r[t]=r,this.#i(),r}get(t){return this.#r[t]??null}all(){return Object.entries(this.#r).map(([t,r])=>({key:t,value:r}))}clear(){return this.#r={},this.#i(),this}},a=new i;export{i as KV,a as default};
|
package/package.json
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fastkv",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
7
|
"description": "A key-value store, helpful for caches in apps.",
|
|
8
8
|
"main": "dist/index.js",
|
|
9
|
+
"repository": {
|
|
10
|
+
"url": "https://github.com/m1-dev/fastkv"
|
|
11
|
+
},
|
|
9
12
|
"keywords": [
|
|
10
13
|
"kv",
|
|
11
14
|
"database",
|
|
@@ -20,6 +23,7 @@
|
|
|
20
23
|
},
|
|
21
24
|
"scripts": {
|
|
22
25
|
"build": "tsup",
|
|
23
|
-
"lint": "tsc --noEmit true"
|
|
26
|
+
"lint": "tsc --noEmit true",
|
|
27
|
+
"prepublish": "pnpm run build"
|
|
24
28
|
}
|
|
25
29
|
}
|