@keyv/etcd 2.0.0-rc.1 → 2.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/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017-2021 Luke Childs
4
+ Copyright (c) 2021-2022 Jared Wray
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # @keyv/etcd [<img width="100" align="right" src="https://jaredwray.com/images/keyv.svg" alt="keyv">](https://github.com/jaredwra/keyv)
1
+ # @keyv/etcd [<img width="100" align="right" src="https://jaredwray.com/images/keyv-symbol.svg" alt="keyv">](https://github.com/jaredwra/keyv)
2
2
 
3
3
  > Etcd storage adapter for Keyv
4
4
 
@@ -17,12 +17,13 @@ npm install --save keyv @keyv/etcd
17
17
  ## Usage
18
18
 
19
19
  ```js
20
- const Keyv = require('keyv');
20
+ import Keyv from 'keyv';
21
+ import KeyvEtcd from '@keyv/etcd';
21
22
 
22
- const keyv = new Keyv('etcd://localhost:2379');
23
+ const keyv = new Keyv(new KeyvEtcd('etcd://localhost:2379'));
23
24
  keyv.on('error', handleConnectionError);
24
25
  ```
25
26
 
26
27
  ## License
27
28
 
28
- Copyright (c) 2022 Jared Wray
29
+ [MIT © Jared Wray](LICENSE)
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { EventEmitter } from 'events';
3
2
  import { Etcd3, type Lease } from 'etcd3';
4
3
  import type { StoredData } from 'keyv';
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { EventEmitter } from 'events';
3
2
  import { Etcd3, type Lease } from 'etcd3';
4
3
  import type { StoredData } from 'keyv';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@keyv/etcd",
3
- "version": "2.0.0-rc.1",
3
+ "version": "2.0.0",
4
4
  "description": "Etcd storage adapter for Keyv",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -12,7 +12,7 @@
12
12
  }
13
13
  },
14
14
  "scripts": {
15
- "build": "tsc --project tsconfig.csj.json && tsc --project tsconfig.esm.json",
15
+ "build": "rm -rf dist && tsc --project tsconfig.cjs.json && tsc --project tsconfig.esm.json",
16
16
  "prepare": "yarn build",
17
17
  "test": "xo --fix && vitest run --coverage",
18
18
  "test:ci": "xo && vitest --run --sequence.setupFiles=list",
@@ -24,6 +24,8 @@
24
24
  "unicorn/no-array-reduce": "off",
25
25
  "unicorn/prefer-object-from-entries": "off",
26
26
  "unicorn/prefer-node-protocol": "off",
27
+ "n/file-extension-in-import": "off",
28
+ "@typescript-eslint/use-unknown-in-catch-callback-variable": "off",
27
29
  "import/extensions": "off",
28
30
  "@typescript-eslint/no-confusing-void-expression": "off",
29
31
  "@typescript-eslint/promise-function-async": "off",
@@ -68,19 +70,20 @@
68
70
  },
69
71
  "devDependencies": {
70
72
  "@keyv/test-suite": "*",
71
- "c8": "^9.1.0",
72
- "keyv": "^5.0.0-rc.1",
73
+ "c8": "^10.1.2",
74
+ "keyv": "^5.0.0",
73
75
  "requirable": "^1.0.5",
74
76
  "ts-node": "^10.9.2",
75
- "tsd": "^0.31.0",
76
- "typescript": "^5.4.5",
77
- "webpack": "^5.91.0",
78
- "xo": "^0.58.0"
77
+ "tsd": "^0.31.1",
78
+ "typescript": "^5.5.4",
79
+ "webpack": "^5.93.0",
80
+ "xo": "^0.59.3"
79
81
  },
80
82
  "tsd": {
81
83
  "directory": "test"
82
84
  },
83
85
  "files": [
84
- "dist"
86
+ "dist",
87
+ "LICENSE"
85
88
  ]
86
89
  }
package/dist/index.d.ts DELETED
@@ -1,29 +0,0 @@
1
- /// <reference types="node" />
2
- import { EventEmitter } from 'events';
3
- import { Etcd3, type Lease } from 'etcd3';
4
- import type { StoredData } from 'keyv';
5
- import type { ClearOutput, DeleteManyOutput, DeleteOutput, GetOutput, HasOutput, SetOutput } from './types';
6
- type KeyvEtcdOptions = {
7
- url?: string;
8
- uri?: string;
9
- ttl?: number;
10
- busyTimeout?: number;
11
- };
12
- declare class KeyvEtcd<Value = any> extends EventEmitter {
13
- ttlSupport: boolean;
14
- opts: KeyvEtcdOptions;
15
- client: Etcd3;
16
- lease?: Lease;
17
- namespace?: string;
18
- constructor(url?: KeyvEtcdOptions | string, options?: KeyvEtcdOptions);
19
- get(key: string): GetOutput<Value>;
20
- getMany(keys: string[]): Promise<Array<StoredData<Value>>>;
21
- set(key: string, value: Value): SetOutput;
22
- delete(key: string): DeleteOutput;
23
- deleteMany(keys: string[]): DeleteManyOutput;
24
- clear(): ClearOutput;
25
- iterator(namespace?: string): AsyncGenerator<(string | Awaited<Value> | undefined)[], void, unknown>;
26
- has(key: string): HasOutput;
27
- disconnect(): Promise<void>;
28
- }
29
- export = KeyvEtcd;
package/dist/index.js DELETED
@@ -1,161 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
12
- var __asyncValues = (this && this.__asyncValues) || function (o) {
13
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
14
- var m = o[Symbol.asyncIterator], i;
15
- return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
16
- function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
17
- function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
18
- };
19
- var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
20
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
21
- var g = generator.apply(thisArg, _arguments || []), i, q = [];
22
- return i = {}, verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
23
- function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
24
- function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
25
- function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
26
- function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
27
- function fulfill(value) { resume("next", value); }
28
- function reject(value) { resume("throw", value); }
29
- function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
30
- };
31
- const events_1 = require("events");
32
- const etcd3_1 = require("etcd3");
33
- class KeyvEtcd extends events_1.EventEmitter {
34
- constructor(url, options) {
35
- super();
36
- this.ttlSupport = typeof (options === null || options === void 0 ? void 0 : options.ttl) === 'number';
37
- url !== null && url !== void 0 ? url : (url = {});
38
- if (typeof url === 'string') {
39
- url = { url };
40
- }
41
- if (url.uri) {
42
- url = Object.assign({ url: url.uri }, url);
43
- }
44
- if (url.ttl) {
45
- this.ttlSupport = typeof url.ttl === 'number';
46
- }
47
- this.opts = Object.assign(Object.assign({ url: '127.0.0.1:2379' }, url), options);
48
- this.opts.url = this.opts.url.replace(/^etcd:\/\//, '');
49
- this.client = new etcd3_1.Etcd3({
50
- hosts: this.opts.url,
51
- });
52
- // Https://github.com/microsoft/etcd3/issues/105
53
- this.client.getRoles().catch(error => this.emit('error', error));
54
- if (this.ttlSupport) {
55
- this.lease = this.client.lease(this.opts.ttl / 1000, {
56
- autoKeepAlive: false,
57
- });
58
- }
59
- }
60
- get(key) {
61
- return __awaiter(this, void 0, void 0, function* () {
62
- return this.client.get(key);
63
- });
64
- }
65
- getMany(keys) {
66
- return __awaiter(this, void 0, void 0, function* () {
67
- const promises = [];
68
- for (const key of keys) {
69
- promises.push(this.get(key));
70
- }
71
- return Promise.allSettled(promises)
72
- .then(values => {
73
- const data = [];
74
- for (const value of values) {
75
- // @ts-expect-error - value is an object
76
- if (value.value === null) {
77
- data.push(undefined);
78
- }
79
- else {
80
- // @ts-expect-error - value is an object
81
- data.push(value.value);
82
- }
83
- }
84
- return data;
85
- });
86
- });
87
- }
88
- set(key, value) {
89
- return __awaiter(this, void 0, void 0, function* () {
90
- let client = 'client';
91
- if (this.opts.ttl) {
92
- client = 'lease';
93
- }
94
- // @ts-expect-error - Value needs to be number, string or buffer
95
- return this[client].put(key).value(value);
96
- });
97
- }
98
- delete(key) {
99
- return __awaiter(this, void 0, void 0, function* () {
100
- if (typeof key !== 'string') {
101
- return false;
102
- }
103
- return this.client.delete().key(key).then(key => key.deleted !== '0');
104
- });
105
- }
106
- deleteMany(keys) {
107
- return __awaiter(this, void 0, void 0, function* () {
108
- const promises = [];
109
- for (const key of keys) {
110
- promises.push(this.delete(key));
111
- }
112
- // @ts-expect-error - x is an object
113
- return Promise.allSettled(promises).then(values => values.every(x => x.value === true));
114
- });
115
- }
116
- clear() {
117
- return __awaiter(this, void 0, void 0, function* () {
118
- const promise = this.namespace
119
- ? this.client.delete().prefix(this.namespace)
120
- : this.client.delete().all();
121
- return promise.then(() => undefined);
122
- });
123
- }
124
- iterator(namespace) {
125
- return __asyncGenerator(this, arguments, function* iterator_1() {
126
- var _a, e_1, _b, _c;
127
- const iterator = yield __await(this.client
128
- .getAll()
129
- .prefix(namespace ? namespace + ':' : '')
130
- .keys());
131
- try {
132
- for (var _d = true, iterator_2 = __asyncValues(iterator), iterator_2_1; iterator_2_1 = yield __await(iterator_2.next()), _a = iterator_2_1.done, !_a; _d = true) {
133
- _c = iterator_2_1.value;
134
- _d = false;
135
- const key = _c;
136
- const value = yield __await(this.get(key));
137
- yield yield __await([key, value]);
138
- }
139
- }
140
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
141
- finally {
142
- try {
143
- if (!_d && !_a && (_b = iterator_2.return)) yield __await(_b.call(iterator_2));
144
- }
145
- finally { if (e_1) throw e_1.error; }
146
- }
147
- });
148
- }
149
- has(key) {
150
- return __awaiter(this, void 0, void 0, function* () {
151
- return this.client.get(key).exists();
152
- });
153
- }
154
- disconnect() {
155
- return __awaiter(this, void 0, void 0, function* () {
156
- return this.client.close();
157
- });
158
- }
159
- }
160
- module.exports = KeyvEtcd;
161
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/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CAAC,CAAC,SAAS,GAAG,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;iBACxC,IAAI,EAAE,CAAA,CAAC;;gBAET,KAAwB,eAAA,aAAA,cAAA,QAAQ,CAAA,cAAA,2FAAE,CAAC;oBAAX,wBAAQ;oBAAR,WAAQ;oBAArB,MAAM,GAAG,KAAA,CAAA;oBACnB,MAAM,KAAK,GAAG,cAAM,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA,CAAC;oBAClC,oBAAM,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA,CAAC;gBACpB,CAAC;;;;;;;;;QACF,CAAC;KAAA;IAEK,GAAG,CAAC,GAAW;;YACpB,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC;QACtC,CAAC;KAAA;IAEK,UAAU;;YACf,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QAC5B,CAAC;KAAA;CACD;AAED,iBAAS,QAAQ,CAAC"}
package/dist/types.d.ts DELETED
@@ -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<any>;
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/types.js DELETED
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=types.js.map
package/dist/types.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}