@keyv/etcd 2.0.0 → 2.1.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/dist/index.cjs ADDED
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ KeyvEtcd: () => KeyvEtcd,
24
+ default: () => src_default
25
+ });
26
+ module.exports = __toCommonJS(src_exports);
27
+ var import_node_events = require("events");
28
+ var import_etcd3 = require("etcd3");
29
+ var KeyvEtcd = class extends import_node_events.EventEmitter {
30
+ ttlSupport;
31
+ opts;
32
+ client;
33
+ lease;
34
+ namespace;
35
+ constructor(url, options) {
36
+ super();
37
+ this.ttlSupport = typeof options?.ttl === "number";
38
+ url ??= {};
39
+ if (typeof url === "string") {
40
+ url = { url };
41
+ }
42
+ if (url.uri) {
43
+ url = { url: url.uri, ...url };
44
+ }
45
+ if (url.ttl) {
46
+ this.ttlSupport = typeof url.ttl === "number";
47
+ }
48
+ this.opts = {
49
+ url: "127.0.0.1:2379",
50
+ ...url,
51
+ ...options,
52
+ dialect: "etcd"
53
+ };
54
+ this.opts.url = this.opts.url.replace(/^etcd:\/\//, "");
55
+ this.client = new import_etcd3.Etcd3({
56
+ hosts: this.opts.url
57
+ });
58
+ this.client.getRoles().catch((error) => this.emit("error", error));
59
+ if (this.ttlSupport) {
60
+ this.lease = this.client.lease(this.opts.ttl / 1e3, {
61
+ autoKeepAlive: false
62
+ });
63
+ }
64
+ }
65
+ async get(key) {
66
+ return this.client.get(key);
67
+ }
68
+ async getMany(keys) {
69
+ const promises = [];
70
+ for (const key of keys) {
71
+ promises.push(this.get(key));
72
+ }
73
+ return Promise.allSettled(promises).then((values) => {
74
+ const data = [];
75
+ for (const value of values) {
76
+ if (value.value === null) {
77
+ data.push(void 0);
78
+ } else {
79
+ data.push(value.value);
80
+ }
81
+ }
82
+ return data;
83
+ });
84
+ }
85
+ async set(key, value) {
86
+ let client = "client";
87
+ if (this.opts.ttl) {
88
+ client = "lease";
89
+ }
90
+ await this[client].put(key).value(value);
91
+ }
92
+ async delete(key) {
93
+ if (typeof key !== "string") {
94
+ return false;
95
+ }
96
+ return this.client.delete().key(key).then((key2) => key2.deleted !== "0");
97
+ }
98
+ async deleteMany(keys) {
99
+ const promises = [];
100
+ for (const key of keys) {
101
+ promises.push(this.delete(key));
102
+ }
103
+ return Promise.allSettled(promises).then((values) => values.every((x) => x.value === true));
104
+ }
105
+ async clear() {
106
+ const promise = this.namespace ? this.client.delete().prefix(this.namespace) : this.client.delete().all();
107
+ return promise.then(() => void 0);
108
+ }
109
+ async *iterator(namespace) {
110
+ const iterator = await this.client.getAll().prefix(namespace ? namespace + ":" : "").keys();
111
+ for await (const key of iterator) {
112
+ const value = await this.get(key);
113
+ yield [key, value];
114
+ }
115
+ }
116
+ async has(key) {
117
+ return this.client.get(key).exists();
118
+ }
119
+ async disconnect() {
120
+ this.client.close();
121
+ }
122
+ };
123
+ var src_default = KeyvEtcd;
124
+ // Annotate the CommonJS export names for ESM import in node:
125
+ 0 && (module.exports = {
126
+ KeyvEtcd
127
+ });
@@ -1,12 +1,20 @@
1
- import { EventEmitter } from 'events';
2
- import { Etcd3, type Lease } from 'etcd3';
3
- import type { StoredData } from 'keyv';
4
- import type { ClearOutput, DeleteManyOutput, DeleteOutput, GetOutput, HasOutput, SetOutput } from './types';
1
+ import { EventEmitter } from 'node:events';
2
+ import { Etcd3, Lease } from 'etcd3';
3
+ import { StoredData } from 'keyv';
4
+
5
+ type GetOutput<Value> = Promise<Value | undefined>;
6
+ type SetOutput = Promise<void>;
7
+ type DeleteOutput = Promise<boolean>;
8
+ type DeleteManyOutput = Promise<boolean>;
9
+ type ClearOutput = Promise<void>;
10
+ type HasOutput = Promise<boolean>;
11
+
5
12
  type KeyvEtcdOptions = {
6
13
  url?: string;
7
14
  uri?: string;
8
15
  ttl?: number;
9
16
  busyTimeout?: number;
17
+ dialect?: 'etcd';
10
18
  };
11
19
  declare class KeyvEtcd<Value = any> extends EventEmitter {
12
20
  ttlSupport: boolean;
@@ -25,4 +33,5 @@ declare class KeyvEtcd<Value = any> extends EventEmitter {
25
33
  has(key: string): HasOutput;
26
34
  disconnect(): Promise<void>;
27
35
  }
28
- export default KeyvEtcd;
36
+
37
+ export { KeyvEtcd, type KeyvEtcdOptions, KeyvEtcd as default };
@@ -1,12 +1,20 @@
1
- import { EventEmitter } from 'events';
2
- import { Etcd3, type Lease } from 'etcd3';
3
- import type { StoredData } from 'keyv';
4
- import type { ClearOutput, DeleteManyOutput, DeleteOutput, GetOutput, HasOutput, SetOutput } from './types';
1
+ import { EventEmitter } from 'node:events';
2
+ import { Etcd3, Lease } from 'etcd3';
3
+ import { StoredData } from 'keyv';
4
+
5
+ type GetOutput<Value> = Promise<Value | undefined>;
6
+ type SetOutput = Promise<void>;
7
+ type DeleteOutput = Promise<boolean>;
8
+ type DeleteManyOutput = Promise<boolean>;
9
+ type ClearOutput = Promise<void>;
10
+ type HasOutput = Promise<boolean>;
11
+
5
12
  type KeyvEtcdOptions = {
6
13
  url?: string;
7
14
  uri?: string;
8
15
  ttl?: number;
9
16
  busyTimeout?: number;
17
+ dialect?: 'etcd';
10
18
  };
11
19
  declare class KeyvEtcd<Value = any> extends EventEmitter {
12
20
  ttlSupport: boolean;
@@ -25,4 +33,5 @@ declare class KeyvEtcd<Value = any> extends EventEmitter {
25
33
  has(key: string): HasOutput;
26
34
  disconnect(): Promise<void>;
27
35
  }
28
- export default KeyvEtcd;
36
+
37
+ export { KeyvEtcd, type KeyvEtcdOptions, KeyvEtcd as default };
package/dist/index.js ADDED
@@ -0,0 +1,102 @@
1
+ // src/index.ts
2
+ import { EventEmitter } from "node:events";
3
+ import { Etcd3 } from "etcd3";
4
+ var KeyvEtcd = class extends EventEmitter {
5
+ ttlSupport;
6
+ opts;
7
+ client;
8
+ lease;
9
+ namespace;
10
+ constructor(url, options) {
11
+ super();
12
+ this.ttlSupport = typeof options?.ttl === "number";
13
+ url ??= {};
14
+ if (typeof url === "string") {
15
+ url = { url };
16
+ }
17
+ if (url.uri) {
18
+ url = { url: url.uri, ...url };
19
+ }
20
+ if (url.ttl) {
21
+ this.ttlSupport = typeof url.ttl === "number";
22
+ }
23
+ this.opts = {
24
+ url: "127.0.0.1:2379",
25
+ ...url,
26
+ ...options,
27
+ dialect: "etcd"
28
+ };
29
+ this.opts.url = this.opts.url.replace(/^etcd:\/\//, "");
30
+ this.client = new Etcd3({
31
+ hosts: this.opts.url
32
+ });
33
+ this.client.getRoles().catch((error) => this.emit("error", error));
34
+ if (this.ttlSupport) {
35
+ this.lease = this.client.lease(this.opts.ttl / 1e3, {
36
+ autoKeepAlive: false
37
+ });
38
+ }
39
+ }
40
+ async get(key) {
41
+ return this.client.get(key);
42
+ }
43
+ async getMany(keys) {
44
+ const promises = [];
45
+ for (const key of keys) {
46
+ promises.push(this.get(key));
47
+ }
48
+ return Promise.allSettled(promises).then((values) => {
49
+ const data = [];
50
+ for (const value of values) {
51
+ if (value.value === null) {
52
+ data.push(void 0);
53
+ } else {
54
+ data.push(value.value);
55
+ }
56
+ }
57
+ return data;
58
+ });
59
+ }
60
+ async set(key, value) {
61
+ let client = "client";
62
+ if (this.opts.ttl) {
63
+ client = "lease";
64
+ }
65
+ await this[client].put(key).value(value);
66
+ }
67
+ async delete(key) {
68
+ if (typeof key !== "string") {
69
+ return false;
70
+ }
71
+ return this.client.delete().key(key).then((key2) => key2.deleted !== "0");
72
+ }
73
+ async deleteMany(keys) {
74
+ const promises = [];
75
+ for (const key of keys) {
76
+ promises.push(this.delete(key));
77
+ }
78
+ return Promise.allSettled(promises).then((values) => values.every((x) => x.value === true));
79
+ }
80
+ async clear() {
81
+ const promise = this.namespace ? this.client.delete().prefix(this.namespace) : this.client.delete().all();
82
+ return promise.then(() => void 0);
83
+ }
84
+ async *iterator(namespace) {
85
+ const iterator = await this.client.getAll().prefix(namespace ? namespace + ":" : "").keys();
86
+ for await (const key of iterator) {
87
+ const value = await this.get(key);
88
+ yield [key, value];
89
+ }
90
+ }
91
+ async has(key) {
92
+ return this.client.get(key).exists();
93
+ }
94
+ async disconnect() {
95
+ this.client.close();
96
+ }
97
+ };
98
+ var src_default = KeyvEtcd;
99
+ export {
100
+ KeyvEtcd,
101
+ src_default as default
102
+ };
package/package.json CHANGED
@@ -1,89 +1,61 @@
1
1
  {
2
- "name": "@keyv/etcd",
3
- "version": "2.0.0",
4
- "description": "Etcd storage adapter for Keyv",
5
- "main": "dist/cjs/index.js",
6
- "module": "dist/esm/index.js",
7
- "types": "dist/esm/index.d.ts",
8
- "exports": {
9
- ".": {
10
- "require": "./dist/cjs/index.js",
11
- "import": "./dist/esm/index.js"
12
- }
13
- },
14
- "scripts": {
15
- "build": "rm -rf dist && tsc --project tsconfig.cjs.json && tsc --project tsconfig.esm.json",
16
- "prepare": "yarn build",
17
- "test": "xo --fix && vitest run --coverage",
18
- "test:ci": "xo && vitest --run --sequence.setupFiles=list",
19
- "clean": "rm -rf node_modules && rm -rf ./coverage"
20
- },
21
- "xo": {
22
- "rules": {
23
- "unicorn/prefer-module": "off",
24
- "unicorn/no-array-reduce": "off",
25
- "unicorn/prefer-object-from-entries": "off",
26
- "unicorn/prefer-node-protocol": "off",
27
- "n/file-extension-in-import": "off",
28
- "@typescript-eslint/use-unknown-in-catch-callback-variable": "off",
29
- "import/extensions": "off",
30
- "@typescript-eslint/no-confusing-void-expression": "off",
31
- "@typescript-eslint/promise-function-async": "off",
32
- "eslint-comments/no-unused-disable": "off",
33
- "unicorn/prefer-event-target": "off",
34
- "import/no-extraneous-dependencies": "off"
35
- }
36
- },
37
- "ava": {
38
- "require": [
39
- "requirable",
40
- "ts-node/register"
41
- ],
42
- "extensions": [
43
- "js",
44
- "ts"
45
- ]
46
- },
47
- "repository": {
48
- "type": "git",
49
- "url": "git+https://github.com/jaredwray/keyv.git"
50
- },
51
- "keywords": [
52
- "etcd",
53
- "keyv",
54
- "storage",
55
- "adapter",
56
- "key",
57
- "value",
58
- "store",
59
- "cache",
60
- "ttl"
61
- ],
62
- "author": "Jared Wray <me@jaredwray.com> (https://jaredwray.com)",
63
- "license": "MIT",
64
- "bugs": {
65
- "url": "https://github.com/jaredwray/keyv/issues"
66
- },
67
- "homepage": "https://github.com/jaredwray/keyv",
68
- "dependencies": {
69
- "etcd3": "^1.1.2"
70
- },
71
- "devDependencies": {
72
- "@keyv/test-suite": "*",
73
- "c8": "^10.1.2",
74
- "keyv": "^5.0.0",
75
- "requirable": "^1.0.5",
76
- "ts-node": "^10.9.2",
77
- "tsd": "^0.31.1",
78
- "typescript": "^5.5.4",
79
- "webpack": "^5.93.0",
80
- "xo": "^0.59.3"
81
- },
82
- "tsd": {
83
- "directory": "test"
84
- },
85
- "files": [
86
- "dist",
87
- "LICENSE"
88
- ]
89
- }
2
+ "name": "@keyv/etcd",
3
+ "version": "2.1.0",
4
+ "description": "Etcd storage adapter for Keyv",
5
+ "type": "module",
6
+ "main": "dist/index.cjs",
7
+ "module": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "require": "./dist/index.cjs",
12
+ "import": "./dist/index.js"
13
+ }
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/jaredwray/keyv.git"
18
+ },
19
+ "keywords": [
20
+ "etcd",
21
+ "keyv",
22
+ "storage",
23
+ "adapter",
24
+ "key",
25
+ "value",
26
+ "store",
27
+ "cache",
28
+ "ttl"
29
+ ],
30
+ "author": "Jared Wray <me@jaredwray.com> (https://jaredwray.com)",
31
+ "license": "MIT",
32
+ "bugs": {
33
+ "url": "https://github.com/jaredwray/keyv/issues"
34
+ },
35
+ "homepage": "https://github.com/jaredwray/keyv",
36
+ "dependencies": {
37
+ "etcd3": "^1.1.2"
38
+ },
39
+ "devDependencies": {
40
+ "@vitest/coverage-v8": "^2.1.8",
41
+ "rimraf": "^6.0.1",
42
+ "typescript": "^5.7.2",
43
+ "vitest": "^2.1.8",
44
+ "xo": "^0.60.0",
45
+ "@keyv/test-suite": "^2.0.3",
46
+ "keyv": "^5.2.1"
47
+ },
48
+ "tsd": {
49
+ "directory": "test"
50
+ },
51
+ "files": [
52
+ "dist",
53
+ "LICENSE"
54
+ ],
55
+ "scripts": {
56
+ "build": "rimraf ./dist && tsup src/index.ts --format cjs,esm --dts --clean",
57
+ "test": "xo --fix && vitest run --coverage",
58
+ "test:ci": "xo && vitest --run --sequence.setupFiles=list",
59
+ "clean": "rimraf ./node_modules ./coverage ./dist"
60
+ }
61
+ }
package/dist/cjs/index.js DELETED
@@ -1,111 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const events_1 = require("events");
4
- const etcd3_1 = require("etcd3");
5
- class KeyvEtcd extends events_1.EventEmitter {
6
- ttlSupport;
7
- opts;
8
- client;
9
- lease;
10
- namespace;
11
- constructor(url, options) {
12
- super();
13
- this.ttlSupport = typeof options?.ttl === 'number';
14
- url ??= {};
15
- if (typeof url === 'string') {
16
- url = { url };
17
- }
18
- if (url.uri) {
19
- url = { url: url.uri, ...url };
20
- }
21
- if (url.ttl) {
22
- this.ttlSupport = typeof url.ttl === 'number';
23
- }
24
- this.opts = {
25
- url: '127.0.0.1:2379',
26
- ...url,
27
- ...options,
28
- };
29
- this.opts.url = this.opts.url.replace(/^etcd:\/\//, '');
30
- this.client = new etcd3_1.Etcd3({
31
- hosts: this.opts.url,
32
- });
33
- // Https://github.com/microsoft/etcd3/issues/105
34
- this.client.getRoles().catch(error => this.emit('error', error));
35
- if (this.ttlSupport) {
36
- this.lease = this.client.lease(this.opts.ttl / 1000, {
37
- autoKeepAlive: false,
38
- });
39
- }
40
- }
41
- async get(key) {
42
- return this.client.get(key);
43
- }
44
- async getMany(keys) {
45
- const promises = [];
46
- for (const key of keys) {
47
- promises.push(this.get(key));
48
- }
49
- return Promise.allSettled(promises)
50
- .then(values => {
51
- const data = [];
52
- for (const value of values) {
53
- // @ts-expect-error - value is an object
54
- if (value.value === null) {
55
- data.push(undefined);
56
- }
57
- else {
58
- // @ts-expect-error - value is an object
59
- data.push(value.value);
60
- }
61
- }
62
- return data;
63
- });
64
- }
65
- async set(key, value) {
66
- let client = 'client';
67
- if (this.opts.ttl) {
68
- client = 'lease';
69
- }
70
- // @ts-expect-error - Value needs to be number, string or buffer
71
- await this[client].put(key).value(value);
72
- }
73
- async delete(key) {
74
- if (typeof key !== 'string') {
75
- return false;
76
- }
77
- return this.client.delete().key(key).then(key => key.deleted !== '0');
78
- }
79
- async deleteMany(keys) {
80
- const promises = [];
81
- for (const key of keys) {
82
- promises.push(this.delete(key));
83
- }
84
- // @ts-expect-error - x is an object
85
- return Promise.allSettled(promises).then(values => values.every(x => x.value === true));
86
- }
87
- async clear() {
88
- const promise = this.namespace
89
- ? this.client.delete().prefix(this.namespace)
90
- : this.client.delete().all();
91
- return promise.then(() => undefined);
92
- }
93
- async *iterator(namespace) {
94
- const iterator = await this.client
95
- .getAll()
96
- .prefix(namespace ? namespace + ':' : '')
97
- .keys();
98
- for await (const key of iterator) {
99
- const value = await this.get(key);
100
- yield [key, value];
101
- }
102
- }
103
- async has(key) {
104
- return this.client.get(key).exists();
105
- }
106
- async disconnect() {
107
- return this.client.close();
108
- }
109
- }
110
- exports.default = KeyvEtcd;
111
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;AAAA,mCAAoC;AACpC,iCAAwC;AAaxC,MAAM,QAAsB,SAAQ,qBAAY;IACxC,UAAU,CAAU;IACpB,IAAI,CAAkB;IACtB,MAAM,CAAQ;IACd,KAAK,CAAS;IACd,SAAS,CAAU;IAE1B,YAAY,GAA8B,EAAE,OAAyB;QACpE,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,UAAU,GAAG,OAAO,OAAO,EAAE,GAAG,KAAK,QAAQ,CAAC;QAEnD,GAAG,KAAK,EAAE,CAAC;QAEX,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;YAC7B,GAAG,GAAG,EAAC,GAAG,EAAC,CAAC;QACb,CAAC;QAED,IAAI,GAAG,CAAC,GAAG,EAAE,CAAC;YACb,GAAG,GAAG,EAAC,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,GAAG,GAAG,EAAC,CAAC;QAC9B,CAAC;QAED,IAAI,GAAG,CAAC,GAAG,EAAE,CAAC;YACb,IAAI,CAAC,UAAU,GAAG,OAAO,GAAG,CAAC,GAAG,KAAK,QAAQ,CAAC;QAC/C,CAAC;QAED,IAAI,CAAC,IAAI,GAAG;YACX,GAAG,EAAE,gBAAgB;YACrB,GAAG,GAAG;YACN,GAAG,OAAO;SACV,CAAC;QAEF,IAAI,CAAC,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,GAAI,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;QAEzD,IAAI,CAAC,MAAM,GAAG,IAAI,aAAK,CAAC;YACvB,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG;SACpB,CAAC,CAAC;QAEH,gDAAgD;QAChD,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,KAAK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AC;IACtC,CAAC;IAED,KAAK,CAAC,CAAE,QAAQ,CAAC,SAAkB;QAClC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM;aAChC,MAAM,EAAE;aACR,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,GAAG,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;aACxC,IAAI,EAAE,CAAC;QAET,IAAI,KAAK,EAAE,MAAM,GAAG,IAAI,QAAQ,EAAE,CAAC;YAClC,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAClC,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QACpB,CAAC;IACF,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,GAAW;QACpB,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC;IACtC,CAAC;IAED,KAAK,CAAC,UAAU;QACf,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IAC5B,CAAC;CACD;AAED,kBAAe,QAAQ,CAAC"}
@@ -1,8 +0,0 @@
1
- import { type StoredData } from 'keyv';
2
- export type GetOutput<Value> = Promise<Value | undefined>;
3
- export type GetManyOutput<Value> = Promise<Array<StoredData<Value | undefined> | undefined>>;
4
- export type SetOutput = Promise<void>;
5
- export type DeleteOutput = Promise<boolean>;
6
- export type DeleteManyOutput = Promise<boolean>;
7
- export type ClearOutput = Promise<void>;
8
- export type HasOutput = Promise<boolean>;
package/dist/cjs/types.js DELETED
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
package/dist/esm/index.js DELETED
@@ -1,109 +0,0 @@
1
- import { EventEmitter } from 'events';
2
- import { Etcd3 } from 'etcd3';
3
- class KeyvEtcd extends EventEmitter {
4
- ttlSupport;
5
- opts;
6
- client;
7
- lease;
8
- namespace;
9
- constructor(url, options) {
10
- super();
11
- this.ttlSupport = typeof options?.ttl === 'number';
12
- url ??= {};
13
- if (typeof url === 'string') {
14
- url = { url };
15
- }
16
- if (url.uri) {
17
- url = { url: url.uri, ...url };
18
- }
19
- if (url.ttl) {
20
- this.ttlSupport = typeof url.ttl === 'number';
21
- }
22
- this.opts = {
23
- url: '127.0.0.1:2379',
24
- ...url,
25
- ...options,
26
- };
27
- this.opts.url = this.opts.url.replace(/^etcd:\/\//, '');
28
- this.client = new Etcd3({
29
- hosts: this.opts.url,
30
- });
31
- // Https://github.com/microsoft/etcd3/issues/105
32
- this.client.getRoles().catch(error => this.emit('error', error));
33
- if (this.ttlSupport) {
34
- this.lease = this.client.lease(this.opts.ttl / 1000, {
35
- autoKeepAlive: false,
36
- });
37
- }
38
- }
39
- async get(key) {
40
- return this.client.get(key);
41
- }
42
- async getMany(keys) {
43
- const promises = [];
44
- for (const key of keys) {
45
- promises.push(this.get(key));
46
- }
47
- return Promise.allSettled(promises)
48
- .then(values => {
49
- const data = [];
50
- for (const value of values) {
51
- // @ts-expect-error - value is an object
52
- if (value.value === null) {
53
- data.push(undefined);
54
- }
55
- else {
56
- // @ts-expect-error - value is an object
57
- data.push(value.value);
58
- }
59
- }
60
- return data;
61
- });
62
- }
63
- async set(key, value) {
64
- let client = 'client';
65
- if (this.opts.ttl) {
66
- client = 'lease';
67
- }
68
- // @ts-expect-error - Value needs to be number, string or buffer
69
- await this[client].put(key).value(value);
70
- }
71
- async delete(key) {
72
- if (typeof key !== 'string') {
73
- return false;
74
- }
75
- return this.client.delete().key(key).then(key => key.deleted !== '0');
76
- }
77
- async deleteMany(keys) {
78
- const promises = [];
79
- for (const key of keys) {
80
- promises.push(this.delete(key));
81
- }
82
- // @ts-expect-error - x is an object
83
- return Promise.allSettled(promises).then(values => values.every(x => x.value === true));
84
- }
85
- async clear() {
86
- const promise = this.namespace
87
- ? this.client.delete().prefix(this.namespace)
88
- : this.client.delete().all();
89
- return promise.then(() => undefined);
90
- }
91
- async *iterator(namespace) {
92
- const iterator = await this.client
93
- .getAll()
94
- .prefix(namespace ? namespace + ':' : '')
95
- .keys();
96
- for await (const key of iterator) {
97
- const value = await this.get(key);
98
- yield [key, value];
99
- }
100
- }
101
- async has(key) {
102
- return this.client.get(key).exists();
103
- }
104
- async disconnect() {
105
- return this.client.close();
106
- }
107
- }
108
- export default KeyvEtcd;
109
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAC,KAAK,EAAa,MAAM,OAAO,CAAC;AAaxC,MAAM,QAAsB,SAAQ,YAAY;IACxC,UAAU,CAAU;IACpB,IAAI,CAAkB;IACtB,MAAM,CAAQ;IACd,KAAK,CAAS;IACd,SAAS,CAAU;IAE1B,YAAY,GAA8B,EAAE,OAAyB;QACpE,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,UAAU,GAAG,OAAO,OAAO,EAAE,GAAG,KAAK,QAAQ,CAAC;QAEnD,GAAG,KAAK,EAAE,CAAC;QAEX,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;YAC7B,GAAG,GAAG,EAAC,GAAG,EAAC,CAAC;QACb,CAAC;QAED,IAAI,GAAG,CAAC,GAAG,EAAE,CAAC;YACb,GAAG,GAAG,EAAC,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,GAAG,GAAG,EAAC,CAAC;QAC9B,CAAC;QAED,IAAI,GAAG,CAAC,GAAG,EAAE,CAAC;YACb,IAAI,CAAC,UAAU,GAAG,OAAO,GAAG,CAAC,GAAG,KAAK,QAAQ,CAAC;QAC/C,CAAC;QAED,IAAI,CAAC,IAAI,GAAG;YACX,GAAG,EAAE,gBAAgB;YACrB,GAAG,GA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,CAAC,CAAC;IACzF,CAAC;IAED,KAAK,CAAC,KAAK;QACV,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS;YAC7B,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC;YAC7C,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC;QAC9B,OAAO,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;IACtC,CAAC;IAED,KAAK,CAAC,CAAE,QAAQ,CAAC,SAAkB;QAClC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM;aAChC,MAAM,EAAE;aACR,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,GAAG,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;aACxC,IAAI,EAAE,CAAC;QAET,IAAI,KAAK,EAAE,MAAM,GAAG,IAAI,QAAQ,EAAE,CAAC;YAClC,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAClC,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QACpB,CAAC;IACF,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,GAAW;QACpB,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC;IACtC,CAAC;IAED,KAAK,CAAC,UAAU;QACf,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IAC5B,CAAC;CACD;AAED,eAAe,QAAQ,CAAC"}
@@ -1,8 +0,0 @@
1
- import { type StoredData } from 'keyv';
2
- export type GetOutput<Value> = Promise<Value | undefined>;
3
- export type GetManyOutput<Value> = Promise<Array<StoredData<Value | undefined> | undefined>>;
4
- export type SetOutput = Promise<void>;
5
- export type DeleteOutput = Promise<boolean>;
6
- export type DeleteManyOutput = Promise<boolean>;
7
- export type ClearOutput = Promise<void>;
8
- export type HasOutput = Promise<boolean>;
package/dist/esm/types.js DELETED
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}