@keyv/etcd 2.1.0 → 6.0.0-alpha.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/dist/index.cjs +20 -15
- package/dist/index.d.cts +1 -2
- package/dist/index.d.ts +1 -2
- package/dist/index.js +18 -13
- package/package.json +25 -15
package/dist/index.cjs
CHANGED
|
@@ -18,23 +18,21 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
|
|
20
20
|
// src/index.ts
|
|
21
|
-
var
|
|
22
|
-
__export(
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
23
|
KeyvEtcd: () => KeyvEtcd,
|
|
24
|
-
default: () =>
|
|
24
|
+
default: () => index_default
|
|
25
25
|
});
|
|
26
|
-
module.exports = __toCommonJS(
|
|
26
|
+
module.exports = __toCommonJS(index_exports);
|
|
27
27
|
var import_node_events = require("events");
|
|
28
28
|
var import_etcd3 = require("etcd3");
|
|
29
29
|
var KeyvEtcd = class extends import_node_events.EventEmitter {
|
|
30
|
-
ttlSupport;
|
|
31
30
|
opts;
|
|
32
31
|
client;
|
|
33
32
|
lease;
|
|
34
33
|
namespace;
|
|
35
34
|
constructor(url, options) {
|
|
36
35
|
super();
|
|
37
|
-
this.ttlSupport = typeof options?.ttl === "number";
|
|
38
36
|
url ??= {};
|
|
39
37
|
if (typeof url === "string") {
|
|
40
38
|
url = { url };
|
|
@@ -42,21 +40,22 @@ var KeyvEtcd = class extends import_node_events.EventEmitter {
|
|
|
42
40
|
if (url.uri) {
|
|
43
41
|
url = { url: url.uri, ...url };
|
|
44
42
|
}
|
|
45
|
-
if (url.ttl) {
|
|
46
|
-
this.ttlSupport = typeof url.ttl === "number";
|
|
47
|
-
}
|
|
48
43
|
this.opts = {
|
|
49
44
|
url: "127.0.0.1:2379",
|
|
50
45
|
...url,
|
|
51
46
|
...options,
|
|
52
47
|
dialect: "etcd"
|
|
53
48
|
};
|
|
54
|
-
|
|
49
|
+
if (this.opts.url) {
|
|
50
|
+
this.opts.url = this.opts.url?.replace(/^etcd:\/\//, "");
|
|
51
|
+
} else {
|
|
52
|
+
this.opts.url = "127.0.0.1:2379";
|
|
53
|
+
}
|
|
55
54
|
this.client = new import_etcd3.Etcd3({
|
|
56
55
|
hosts: this.opts.url
|
|
57
56
|
});
|
|
58
57
|
this.client.getRoles().catch((error) => this.emit("error", error));
|
|
59
|
-
if (this.
|
|
58
|
+
if (typeof this.opts.ttl === "number") {
|
|
60
59
|
this.lease = this.client.lease(this.opts.ttl / 1e3, {
|
|
61
60
|
autoKeepAlive: false
|
|
62
61
|
});
|
|
@@ -87,7 +86,7 @@ var KeyvEtcd = class extends import_node_events.EventEmitter {
|
|
|
87
86
|
if (this.opts.ttl) {
|
|
88
87
|
client = "lease";
|
|
89
88
|
}
|
|
90
|
-
await this[client]
|
|
89
|
+
await this[client]?.put(key).value(value);
|
|
91
90
|
}
|
|
92
91
|
async delete(key) {
|
|
93
92
|
if (typeof key !== "string") {
|
|
@@ -100,14 +99,19 @@ var KeyvEtcd = class extends import_node_events.EventEmitter {
|
|
|
100
99
|
for (const key of keys) {
|
|
101
100
|
promises.push(this.delete(key));
|
|
102
101
|
}
|
|
103
|
-
return Promise.allSettled(promises).then(
|
|
102
|
+
return Promise.allSettled(promises).then(
|
|
103
|
+
(values) => (
|
|
104
|
+
// @ts-expect-error - x is an object
|
|
105
|
+
values.every((x) => x.value === true)
|
|
106
|
+
)
|
|
107
|
+
);
|
|
104
108
|
}
|
|
105
109
|
async clear() {
|
|
106
110
|
const promise = this.namespace ? this.client.delete().prefix(this.namespace) : this.client.delete().all();
|
|
107
111
|
return promise.then(() => void 0);
|
|
108
112
|
}
|
|
109
113
|
async *iterator(namespace) {
|
|
110
|
-
const iterator = await this.client.getAll().prefix(namespace ? namespace
|
|
114
|
+
const iterator = await this.client.getAll().prefix(namespace ? `${namespace}:` : "").keys();
|
|
111
115
|
for await (const key of iterator) {
|
|
112
116
|
const value = await this.get(key);
|
|
113
117
|
yield [key, value];
|
|
@@ -120,8 +124,9 @@ var KeyvEtcd = class extends import_node_events.EventEmitter {
|
|
|
120
124
|
this.client.close();
|
|
121
125
|
}
|
|
122
126
|
};
|
|
123
|
-
var
|
|
127
|
+
var index_default = KeyvEtcd;
|
|
124
128
|
// Annotate the CommonJS export names for ESM import in node:
|
|
125
129
|
0 && (module.exports = {
|
|
126
130
|
KeyvEtcd
|
|
127
131
|
});
|
|
132
|
+
/* c8 ignore next -- @preserve */
|
package/dist/index.d.cts
CHANGED
|
@@ -14,10 +14,9 @@ type KeyvEtcdOptions = {
|
|
|
14
14
|
uri?: string;
|
|
15
15
|
ttl?: number;
|
|
16
16
|
busyTimeout?: number;
|
|
17
|
-
dialect?:
|
|
17
|
+
dialect?: "etcd";
|
|
18
18
|
};
|
|
19
19
|
declare class KeyvEtcd<Value = any> extends EventEmitter {
|
|
20
|
-
ttlSupport: boolean;
|
|
21
20
|
opts: KeyvEtcdOptions;
|
|
22
21
|
client: Etcd3;
|
|
23
22
|
lease?: Lease;
|
package/dist/index.d.ts
CHANGED
|
@@ -14,10 +14,9 @@ type KeyvEtcdOptions = {
|
|
|
14
14
|
uri?: string;
|
|
15
15
|
ttl?: number;
|
|
16
16
|
busyTimeout?: number;
|
|
17
|
-
dialect?:
|
|
17
|
+
dialect?: "etcd";
|
|
18
18
|
};
|
|
19
19
|
declare class KeyvEtcd<Value = any> extends EventEmitter {
|
|
20
|
-
ttlSupport: boolean;
|
|
21
20
|
opts: KeyvEtcdOptions;
|
|
22
21
|
client: Etcd3;
|
|
23
22
|
lease?: Lease;
|
package/dist/index.js
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
import { EventEmitter } from "
|
|
2
|
+
import { EventEmitter } from "events";
|
|
3
3
|
import { Etcd3 } from "etcd3";
|
|
4
4
|
var KeyvEtcd = class extends EventEmitter {
|
|
5
|
-
ttlSupport;
|
|
6
5
|
opts;
|
|
7
6
|
client;
|
|
8
7
|
lease;
|
|
9
8
|
namespace;
|
|
10
9
|
constructor(url, options) {
|
|
11
10
|
super();
|
|
12
|
-
this.ttlSupport = typeof options?.ttl === "number";
|
|
13
11
|
url ??= {};
|
|
14
12
|
if (typeof url === "string") {
|
|
15
13
|
url = { url };
|
|
@@ -17,21 +15,22 @@ var KeyvEtcd = class extends EventEmitter {
|
|
|
17
15
|
if (url.uri) {
|
|
18
16
|
url = { url: url.uri, ...url };
|
|
19
17
|
}
|
|
20
|
-
if (url.ttl) {
|
|
21
|
-
this.ttlSupport = typeof url.ttl === "number";
|
|
22
|
-
}
|
|
23
18
|
this.opts = {
|
|
24
19
|
url: "127.0.0.1:2379",
|
|
25
20
|
...url,
|
|
26
21
|
...options,
|
|
27
22
|
dialect: "etcd"
|
|
28
23
|
};
|
|
29
|
-
|
|
24
|
+
if (this.opts.url) {
|
|
25
|
+
this.opts.url = this.opts.url?.replace(/^etcd:\/\//, "");
|
|
26
|
+
} else {
|
|
27
|
+
this.opts.url = "127.0.0.1:2379";
|
|
28
|
+
}
|
|
30
29
|
this.client = new Etcd3({
|
|
31
30
|
hosts: this.opts.url
|
|
32
31
|
});
|
|
33
32
|
this.client.getRoles().catch((error) => this.emit("error", error));
|
|
34
|
-
if (this.
|
|
33
|
+
if (typeof this.opts.ttl === "number") {
|
|
35
34
|
this.lease = this.client.lease(this.opts.ttl / 1e3, {
|
|
36
35
|
autoKeepAlive: false
|
|
37
36
|
});
|
|
@@ -62,7 +61,7 @@ var KeyvEtcd = class extends EventEmitter {
|
|
|
62
61
|
if (this.opts.ttl) {
|
|
63
62
|
client = "lease";
|
|
64
63
|
}
|
|
65
|
-
await this[client]
|
|
64
|
+
await this[client]?.put(key).value(value);
|
|
66
65
|
}
|
|
67
66
|
async delete(key) {
|
|
68
67
|
if (typeof key !== "string") {
|
|
@@ -75,14 +74,19 @@ var KeyvEtcd = class extends EventEmitter {
|
|
|
75
74
|
for (const key of keys) {
|
|
76
75
|
promises.push(this.delete(key));
|
|
77
76
|
}
|
|
78
|
-
return Promise.allSettled(promises).then(
|
|
77
|
+
return Promise.allSettled(promises).then(
|
|
78
|
+
(values) => (
|
|
79
|
+
// @ts-expect-error - x is an object
|
|
80
|
+
values.every((x) => x.value === true)
|
|
81
|
+
)
|
|
82
|
+
);
|
|
79
83
|
}
|
|
80
84
|
async clear() {
|
|
81
85
|
const promise = this.namespace ? this.client.delete().prefix(this.namespace) : this.client.delete().all();
|
|
82
86
|
return promise.then(() => void 0);
|
|
83
87
|
}
|
|
84
88
|
async *iterator(namespace) {
|
|
85
|
-
const iterator = await this.client.getAll().prefix(namespace ? namespace
|
|
89
|
+
const iterator = await this.client.getAll().prefix(namespace ? `${namespace}:` : "").keys();
|
|
86
90
|
for await (const key of iterator) {
|
|
87
91
|
const value = await this.get(key);
|
|
88
92
|
yield [key, value];
|
|
@@ -95,8 +99,9 @@ var KeyvEtcd = class extends EventEmitter {
|
|
|
95
99
|
this.client.close();
|
|
96
100
|
}
|
|
97
101
|
};
|
|
98
|
-
var
|
|
102
|
+
var index_default = KeyvEtcd;
|
|
99
103
|
export {
|
|
100
104
|
KeyvEtcd,
|
|
101
|
-
|
|
105
|
+
index_default as default
|
|
102
106
|
};
|
|
107
|
+
/* c8 ignore next -- @preserve */
|
package/package.json
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@keyv/etcd",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0-alpha.1",
|
|
4
4
|
"description": "Etcd storage adapter for Keyv",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"main": "dist/index.
|
|
7
|
-
"module": "dist/index.js",
|
|
8
|
-
"types": "dist/index.d.ts",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
|
-
"require":
|
|
12
|
-
|
|
11
|
+
"require": {
|
|
12
|
+
"types": "./dist/index.d.cts",
|
|
13
|
+
"default": "./dist/index.cjs"
|
|
14
|
+
},
|
|
15
|
+
"import": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"default": "./dist/index.js"
|
|
18
|
+
}
|
|
13
19
|
}
|
|
14
20
|
},
|
|
15
21
|
"repository": {
|
|
@@ -37,13 +43,15 @@
|
|
|
37
43
|
"etcd3": "^1.1.2"
|
|
38
44
|
},
|
|
39
45
|
"devDependencies": {
|
|
40
|
-
"@
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"@keyv/test-suite": "^
|
|
46
|
-
|
|
46
|
+
"@biomejs/biome": "^2.3.10",
|
|
47
|
+
"@vitest/coverage-v8": "^4.0.16",
|
|
48
|
+
"rimraf": "^6.1.2",
|
|
49
|
+
"typescript": "^5.9.3",
|
|
50
|
+
"vitest": "^4.0.16",
|
|
51
|
+
"@keyv/test-suite": "^6.0.0-alpha.1"
|
|
52
|
+
},
|
|
53
|
+
"peerDependencies": {
|
|
54
|
+
"keyv": "^6.0.0-alpha.1"
|
|
47
55
|
},
|
|
48
56
|
"tsd": {
|
|
49
57
|
"directory": "test"
|
|
@@ -54,8 +62,10 @@
|
|
|
54
62
|
],
|
|
55
63
|
"scripts": {
|
|
56
64
|
"build": "rimraf ./dist && tsup src/index.ts --format cjs,esm --dts --clean",
|
|
57
|
-
"
|
|
58
|
-
"
|
|
65
|
+
"lint": "biome check --write --error-on-warnings",
|
|
66
|
+
"lint:ci": "biome check --error-on-warnings",
|
|
67
|
+
"test": "pnpm lint && vitest run --coverage",
|
|
68
|
+
"test:ci": "pnpm lint:ci && vitest --run --sequence.setupFiles=list --coverage",
|
|
59
69
|
"clean": "rimraf ./node_modules ./coverage ./dist"
|
|
60
70
|
}
|
|
61
71
|
}
|