@keyv/etcd 2.0.0 → 2.0.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 ADDED
@@ -0,0 +1,126 @@
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_events = require("events");
28
+ var import_etcd3 = require("etcd3");
29
+ var KeyvEtcd = class extends import_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
+ };
53
+ this.opts.url = this.opts.url.replace(/^etcd:\/\//, "");
54
+ this.client = new import_etcd3.Etcd3({
55
+ hosts: this.opts.url
56
+ });
57
+ this.client.getRoles().catch((error) => this.emit("error", error));
58
+ if (this.ttlSupport) {
59
+ this.lease = this.client.lease(this.opts.ttl / 1e3, {
60
+ autoKeepAlive: false
61
+ });
62
+ }
63
+ }
64
+ async get(key) {
65
+ return this.client.get(key);
66
+ }
67
+ async getMany(keys) {
68
+ const promises = [];
69
+ for (const key of keys) {
70
+ promises.push(this.get(key));
71
+ }
72
+ return Promise.allSettled(promises).then((values) => {
73
+ const data = [];
74
+ for (const value of values) {
75
+ if (value.value === null) {
76
+ data.push(void 0);
77
+ } else {
78
+ data.push(value.value);
79
+ }
80
+ }
81
+ return data;
82
+ });
83
+ }
84
+ async set(key, value) {
85
+ let client = "client";
86
+ if (this.opts.ttl) {
87
+ client = "lease";
88
+ }
89
+ await this[client].put(key).value(value);
90
+ }
91
+ async delete(key) {
92
+ if (typeof key !== "string") {
93
+ return false;
94
+ }
95
+ return this.client.delete().key(key).then((key2) => key2.deleted !== "0");
96
+ }
97
+ async deleteMany(keys) {
98
+ const promises = [];
99
+ for (const key of keys) {
100
+ promises.push(this.delete(key));
101
+ }
102
+ return Promise.allSettled(promises).then((values) => values.every((x) => x.value === true));
103
+ }
104
+ async clear() {
105
+ const promise = this.namespace ? this.client.delete().prefix(this.namespace) : this.client.delete().all();
106
+ return promise.then(() => void 0);
107
+ }
108
+ async *iterator(namespace) {
109
+ const iterator = await this.client.getAll().prefix(namespace ? namespace + ":" : "").keys();
110
+ for await (const key of iterator) {
111
+ const value = await this.get(key);
112
+ yield [key, value];
113
+ }
114
+ }
115
+ async has(key) {
116
+ return this.client.get(key).exists();
117
+ }
118
+ async disconnect() {
119
+ return this.client.close();
120
+ }
121
+ };
122
+ var src_default = KeyvEtcd;
123
+ // Annotate the CommonJS export names for ESM import in node:
124
+ 0 && (module.exports = {
125
+ KeyvEtcd
126
+ });
@@ -1,7 +1,14 @@
1
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';
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;
@@ -25,4 +32,5 @@ declare class KeyvEtcd<Value = any> extends EventEmitter {
25
32
  has(key: string): HasOutput;
26
33
  disconnect(): Promise<void>;
27
34
  }
28
- export default KeyvEtcd;
35
+
36
+ export { KeyvEtcd, KeyvEtcd as default };
@@ -1,7 +1,14 @@
1
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';
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;
@@ -25,4 +32,5 @@ declare class KeyvEtcd<Value = any> extends EventEmitter {
25
32
  has(key: string): HasOutput;
26
33
  disconnect(): Promise<void>;
27
34
  }
28
- export default KeyvEtcd;
35
+
36
+ export { KeyvEtcd, KeyvEtcd as default };
package/dist/index.js ADDED
@@ -0,0 +1,101 @@
1
+ // src/index.ts
2
+ import { EventEmitter } from "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
+ };
28
+ this.opts.url = this.opts.url.replace(/^etcd:\/\//, "");
29
+ this.client = new Etcd3({
30
+ hosts: this.opts.url
31
+ });
32
+ this.client.getRoles().catch((error) => this.emit("error", error));
33
+ if (this.ttlSupport) {
34
+ this.lease = this.client.lease(this.opts.ttl / 1e3, {
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).then((values) => {
48
+ const data = [];
49
+ for (const value of values) {
50
+ if (value.value === null) {
51
+ data.push(void 0);
52
+ } else {
53
+ data.push(value.value);
54
+ }
55
+ }
56
+ return data;
57
+ });
58
+ }
59
+ async set(key, value) {
60
+ let client = "client";
61
+ if (this.opts.ttl) {
62
+ client = "lease";
63
+ }
64
+ await this[client].put(key).value(value);
65
+ }
66
+ async delete(key) {
67
+ if (typeof key !== "string") {
68
+ return false;
69
+ }
70
+ return this.client.delete().key(key).then((key2) => key2.deleted !== "0");
71
+ }
72
+ async deleteMany(keys) {
73
+ const promises = [];
74
+ for (const key of keys) {
75
+ promises.push(this.delete(key));
76
+ }
77
+ return Promise.allSettled(promises).then((values) => values.every((x) => x.value === true));
78
+ }
79
+ async clear() {
80
+ const promise = this.namespace ? this.client.delete().prefix(this.namespace) : this.client.delete().all();
81
+ return promise.then(() => void 0);
82
+ }
83
+ async *iterator(namespace) {
84
+ const iterator = await this.client.getAll().prefix(namespace ? namespace + ":" : "").keys();
85
+ for await (const key of iterator) {
86
+ const value = await this.get(key);
87
+ yield [key, value];
88
+ }
89
+ }
90
+ async has(key) {
91
+ return this.client.get(key).exists();
92
+ }
93
+ async disconnect() {
94
+ return this.client.close();
95
+ }
96
+ };
97
+ var src_default = KeyvEtcd;
98
+ export {
99
+ KeyvEtcd,
100
+ src_default as default
101
+ };
package/package.json CHANGED
@@ -1,18 +1,19 @@
1
1
  {
2
2
  "name": "@keyv/etcd",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
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",
5
+ "type": "module",
6
+ "main": "dist/index.cjs",
7
+ "module": "dist/index.js",
8
+ "types": "dist/index.d.ts",
8
9
  "exports": {
9
10
  ".": {
10
- "require": "./dist/cjs/index.js",
11
- "import": "./dist/esm/index.js"
11
+ "require": "./dist/index.cjs",
12
+ "import": "./dist/index.js"
12
13
  }
13
14
  },
14
15
  "scripts": {
15
- "build": "rm -rf dist && tsc --project tsconfig.cjs.json && tsc --project tsconfig.esm.json",
16
+ "build": "rm -rf dist && tsup src/index.ts --format cjs,esm --dts --clean",
16
17
  "prepare": "yarn build",
17
18
  "test": "xo --fix && vitest run --coverage",
18
19
  "test:ci": "xo && vitest --run --sequence.setupFiles=list",
@@ -20,6 +21,7 @@
20
21
  },
21
22
  "xo": {
22
23
  "rules": {
24
+ "import/no-named-as-default": "off",
23
25
  "unicorn/prefer-module": "off",
24
26
  "unicorn/no-array-reduce": "off",
25
27
  "unicorn/prefer-object-from-entries": "off",
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,IA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,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,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,GA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,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":""}