@marianmeres/kv 1.1.1 → 1.1.2
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/dist/adapter/deno-kv.d.ts +1 -3
- package/dist/adapter/deno-kv.js +17 -11
- package/package.json +1 -1
|
@@ -27,9 +27,7 @@ export declare class AdapterDenoKv extends AdapterAbstract {
|
|
|
27
27
|
clear(pattern: string): Promise<number>;
|
|
28
28
|
/** Will set multiple kv pairs in one batch */
|
|
29
29
|
setMultiple(keyValuePairs: [string, any][], options?: Partial<SetOptions>): Promise<boolean[]>;
|
|
30
|
-
/** Will get multiple keys in one batch.
|
|
31
|
-
* NOTE: Deno.Kv supports list, so that should be probably used
|
|
32
|
-
*/
|
|
30
|
+
/** Will get multiple keys in one batch. */
|
|
33
31
|
getMultiple(keys: string[]): Promise<Record<string, any>>;
|
|
34
32
|
/** */
|
|
35
33
|
transaction(operations: Operation[]): Promise<any[]>;
|
package/dist/adapter/deno-kv.js
CHANGED
|
@@ -44,18 +44,16 @@ export class AdapterDenoKv extends AdapterAbstract {
|
|
|
44
44
|
if (value === undefined)
|
|
45
45
|
value = null;
|
|
46
46
|
// Deno.Kv does not require this, but for the consistency with other adapters
|
|
47
|
-
// let's just stringify (the toJSON may do magic
|
|
47
|
+
// let's just stringify (the toJSON may do magic, so we want consistent behavior
|
|
48
|
+
// across adapters)
|
|
48
49
|
value = JSON.stringify(value);
|
|
49
50
|
await db.set(this.#denoKvKey(key), value, {
|
|
50
51
|
expireIn: ttl ? ttl * 1000 : undefined,
|
|
51
52
|
});
|
|
52
53
|
return true;
|
|
53
54
|
}
|
|
54
|
-
/** Will
|
|
55
|
-
|
|
56
|
-
this._assertInitialized();
|
|
57
|
-
const { db } = this.options;
|
|
58
|
-
const row = await db.get(this.#denoKvKey(key));
|
|
55
|
+
/** Will return the internal value */
|
|
56
|
+
#parseValue(row) {
|
|
59
57
|
try {
|
|
60
58
|
return JSON.parse(`${row?.value ?? null}`);
|
|
61
59
|
}
|
|
@@ -63,6 +61,13 @@ export class AdapterDenoKv extends AdapterAbstract {
|
|
|
63
61
|
return row?.value;
|
|
64
62
|
}
|
|
65
63
|
}
|
|
64
|
+
/** Will get the key from the underlying store */
|
|
65
|
+
async get(key) {
|
|
66
|
+
this._assertInitialized();
|
|
67
|
+
const { db } = this.options;
|
|
68
|
+
const row = await db.get(this.#denoKvKey(key));
|
|
69
|
+
return this.#parseValue(row);
|
|
70
|
+
}
|
|
66
71
|
/** Will check if the key exists in the underlying store */
|
|
67
72
|
async exists(key) {
|
|
68
73
|
this._assertInitialized();
|
|
@@ -118,14 +123,15 @@ export class AdapterDenoKv extends AdapterAbstract {
|
|
|
118
123
|
}
|
|
119
124
|
return results;
|
|
120
125
|
}
|
|
121
|
-
/** Will get multiple keys in one batch.
|
|
122
|
-
* NOTE: Deno.Kv supports list, so that should be probably used
|
|
123
|
-
*/
|
|
126
|
+
/** Will get multiple keys in one batch. */
|
|
124
127
|
async getMultiple(keys) {
|
|
125
128
|
this._assertInitialized();
|
|
129
|
+
const { db } = this.options;
|
|
126
130
|
const result = {};
|
|
127
|
-
|
|
128
|
-
|
|
131
|
+
const denoKvKeys = keys.map((k) => this.#denoKvKey(k));
|
|
132
|
+
const results = await db.getMany(denoKvKeys);
|
|
133
|
+
for (const [index, row] of results.entries()) {
|
|
134
|
+
result[keys[index]] = this.#parseValue(row);
|
|
129
135
|
}
|
|
130
136
|
return result;
|
|
131
137
|
}
|