@marianmeres/kv 1.1.2 → 1.1.3
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 +34 -8
- package/dist/adapter/deno-kv.d.ts +1 -1
- package/dist/adapter/deno-kv.js +3 -4
- package/dist/kv.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -23,19 +23,25 @@ npm i @marianmeres/kv
|
|
|
23
23
|
```typescript
|
|
24
24
|
import { createKVClient } from '@marianmeres/kv';
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
// Basic usage with memory adapter (default)
|
|
27
|
+
const client = createKVClient("my-app-namespace:");
|
|
28
|
+
|
|
29
|
+
// Or specify a different adapter type
|
|
30
|
+
const redisClient = createKVClient(
|
|
31
|
+
"my-app-namespace:",
|
|
32
|
+
'redis', // 'redis' | 'postgres' | 'deno-kv' | 'memory'
|
|
33
|
+
{ db: myRedisClient } // adapter-specific options
|
|
30
34
|
);
|
|
31
35
|
|
|
32
|
-
//
|
|
33
|
-
await client.set('my:foo:key', { my: "value" })
|
|
36
|
+
// Use the client
|
|
37
|
+
await client.set('my:foo:key', { my: "value" });
|
|
34
38
|
await client.get('my:foo:key'); // { my: "value" }
|
|
35
39
|
await client.keys('my:*'); // ['my:foo:key']
|
|
36
40
|
```
|
|
37
41
|
|
|
38
|
-
|
|
42
|
+
**Important**: Namespace must end with a colon (`:`) or be an empty string.
|
|
43
|
+
|
|
44
|
+
## API
|
|
39
45
|
|
|
40
46
|
```typescript
|
|
41
47
|
client.set(key: string, value: any, options?): Promise<boolean>
|
|
@@ -49,4 +55,24 @@ client.getMultiple(keys: string[]): Promise<Record<string, any>>
|
|
|
49
55
|
client.transaction(operations: Operation[]): Promise<any[]>
|
|
50
56
|
client.expire(key: string, ttl: number): Promise<boolean>
|
|
51
57
|
client.ttl(key: string): Promise<Date | null | false>
|
|
52
|
-
```
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Adapter-Specific Limitations
|
|
61
|
+
|
|
62
|
+
### Deno KV
|
|
63
|
+
- **`delete()`**: Always returns `true`, even for non-existent keys (Deno.Kv limitation)
|
|
64
|
+
- **`expire()`**: Not supported - always returns `false`
|
|
65
|
+
- **`ttl()`**: Not supported - always returns `null`
|
|
66
|
+
- **Note**: TTL can be set during `set()` operation, but cannot be queried or modified after
|
|
67
|
+
|
|
68
|
+
### Redis
|
|
69
|
+
- **`keys()` and `clear()`**: Not supported in cluster mode (throws error)
|
|
70
|
+
- **Namespace**: Required (cannot be empty string)
|
|
71
|
+
|
|
72
|
+
### PostgreSQL
|
|
73
|
+
- Creates a table (default: `__kv`) in your database
|
|
74
|
+
- Supports optional TTL cleanup via `ttlCleanupIntervalSec` option
|
|
75
|
+
|
|
76
|
+
### Memory
|
|
77
|
+
- Data is not persisted (in-memory only)
|
|
78
|
+
- Supports optional TTL cleanup via `ttlCleanupIntervalSec` option
|
|
@@ -33,6 +33,6 @@ export declare class AdapterDenoKv extends AdapterAbstract {
|
|
|
33
33
|
transaction(operations: Operation[]): Promise<any[]>;
|
|
34
34
|
/** Not supported in Deno.Kv */
|
|
35
35
|
expire(key: string, ttl: number): Promise<boolean>;
|
|
36
|
-
/**
|
|
36
|
+
/** Not supported in Deno.Kv */
|
|
37
37
|
ttl(key: string): Promise<Date | null | false>;
|
|
38
38
|
}
|
package/dist/adapter/deno-kv.js
CHANGED
|
@@ -139,9 +139,9 @@ export class AdapterDenoKv extends AdapterAbstract {
|
|
|
139
139
|
async transaction(operations) {
|
|
140
140
|
this._assertInitialized();
|
|
141
141
|
const { db } = this.options;
|
|
142
|
-
this._assertInitialized();
|
|
143
142
|
// note: memory operations are atomic by nature
|
|
144
143
|
const results = [];
|
|
144
|
+
// ignoring Deno.Kv's atomic feature...
|
|
145
145
|
try {
|
|
146
146
|
for (const op of operations) {
|
|
147
147
|
switch (op.type) {
|
|
@@ -168,10 +168,9 @@ export class AdapterDenoKv extends AdapterAbstract {
|
|
|
168
168
|
this._assertInitialized();
|
|
169
169
|
return Promise.resolve(false);
|
|
170
170
|
}
|
|
171
|
-
/**
|
|
172
|
-
|
|
171
|
+
/** Not supported in Deno.Kv */
|
|
172
|
+
ttl(key) {
|
|
173
173
|
this._assertInitialized();
|
|
174
|
-
//
|
|
175
174
|
return Promise.resolve(null);
|
|
176
175
|
}
|
|
177
176
|
}
|
package/dist/kv.js
CHANGED
|
@@ -18,5 +18,5 @@ export function createKVClient(namespace = "", type = "redis", options = {}) {
|
|
|
18
18
|
return new AdapterDenoKv(namespace, options);
|
|
19
19
|
}
|
|
20
20
|
//
|
|
21
|
-
throw new TypeError(`Unsupported KV client type "${
|
|
21
|
+
throw new TypeError(`Unsupported KV client type "${type}"`);
|
|
22
22
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@marianmeres/kv",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/mod.js",
|
|
6
6
|
"types": "dist/mod.d.ts",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@marianmeres/clog": "^2.3.3",
|
|
18
18
|
"pg": "^8.16.3",
|
|
19
|
-
"redis": "^5.
|
|
19
|
+
"redis": "^5.10.0"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@types/node": "latest",
|