keyv 6.0.0-alpha.3 → 6.0.0-beta.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/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "keyv",
3
- "version": "6.0.0-alpha.3",
3
+ "version": "6.0.0-beta.1",
4
4
  "description": "Simple key-value storage with support for multiple backends",
5
5
  "type": "module",
6
- "main": "dist/index.js",
7
- "module": "dist/index.js",
8
- "types": "dist/index.d.ts",
6
+ "main": "./dist/index.mjs",
7
+ "module": "./dist/index.mjs",
8
+ "types": "./dist/index.d.mts",
9
9
  "exports": {
10
10
  ".": {
11
11
  "require": {
@@ -13,8 +13,8 @@
13
13
  "default": "./dist/index.cjs"
14
14
  },
15
15
  "import": {
16
- "types": "./dist/index.d.ts",
17
- "default": "./dist/index.js"
16
+ "types": "./dist/index.d.mts",
17
+ "default": "./dist/index.mjs"
18
18
  }
19
19
  }
20
20
  },
@@ -49,10 +49,16 @@
49
49
  "url": "https://github.com/jaredwray/keyv/issues"
50
50
  },
51
51
  "homepage": "https://github.com/jaredwray/keyv",
52
+ "dependencies": {
53
+ "hookified": "^2.0.1"
54
+ },
52
55
  "devDependencies": {
53
56
  "@biomejs/biome": "^2.3.13",
54
57
  "@faker-js/faker": "^10.2.0",
55
58
  "@vitest/coverage-v8": "^4.0.18",
59
+ "happy-dom": "^20.8.7",
60
+ "keyv-anyredis": "^3.3.0",
61
+ "keyv-file": "^5.3.3",
56
62
  "lru.min": "^1.1.1",
57
63
  "quick-lru": "^7.0.0",
58
64
  "rimraf": "^6.1.2",
@@ -65,10 +71,10 @@
65
71
  },
66
72
  "files": [
67
73
  "dist",
68
- "LISCENCE"
74
+ "LICENSE"
69
75
  ],
70
76
  "scripts": {
71
- "build": "rimraf ./dist && tsup src/index.ts --format cjs,esm --dts --clean",
77
+ "build": "tsdown",
72
78
  "lint": "biome check --write --error-on-warnings",
73
79
  "lint:ci": "biome check --error-on-warnings",
74
80
  "test": "pnpm lint && vitest run --coverage",
package/dist/index.d.ts DELETED
@@ -1,389 +0,0 @@
1
- type EventListener = (...arguments_: any[]) => void;
2
- declare class EventManager {
3
- _eventListeners: Map<string, EventListener[]>;
4
- _maxListeners: number;
5
- constructor();
6
- maxListeners(): number;
7
- addListener(event: string, listener: EventListener): void;
8
- on(event: string, listener: EventListener): this;
9
- removeListener(event: string, listener: EventListener): void;
10
- off(event: string, listener: EventListener): void;
11
- once(event: string, listener: EventListener): void;
12
- emit(event: string, ...arguments_: any[]): void;
13
- listeners(event: string): EventListener[];
14
- removeAllListeners(event?: string): void;
15
- setMaxListeners(n: number): void;
16
- }
17
-
18
- type HookHandler = (...arguments_: any[]) => void;
19
- declare class HooksManager extends EventManager {
20
- _hookHandlers: Map<string, HookHandler[]>;
21
- constructor();
22
- addHandler(event: string, handler: HookHandler): void;
23
- removeHandler(event: string, handler: HookHandler): void;
24
- trigger(event: string, data: any): void;
25
- get handlers(): Map<string, HookHandler[]>;
26
- }
27
-
28
- declare class StatsManager extends EventManager {
29
- enabled: boolean;
30
- hits: number;
31
- misses: number;
32
- sets: number;
33
- deletes: number;
34
- errors: number;
35
- constructor(enabled?: boolean);
36
- hit(): void;
37
- miss(): void;
38
- set(): void;
39
- delete(): void;
40
- hitsOrMisses<T>(array: Array<T | undefined>): void;
41
- reset(): void;
42
- }
43
-
44
- type KeyvSerializationAdapter = {
45
- stringify: (object: unknown) => string | Promise<string>;
46
- parse: <T>(data: string) => T | Promise<T>;
47
- };
48
- type KeyvCompressionAdapter = {
49
- compress(value: any, options?: any): Promise<any>;
50
- decompress(value: any, options?: any): Promise<any>;
51
- };
52
- type DeserializedData<Value> = {
53
- value?: Value;
54
- expires?: number | undefined;
55
- };
56
- declare enum KeyvHooks {
57
- PRE_SET = "preSet",
58
- POST_SET = "postSet",
59
- PRE_GET = "preGet",
60
- POST_GET = "postGet",
61
- PRE_GET_MANY = "preGetMany",
62
- POST_GET_MANY = "postGetMany",
63
- PRE_GET_RAW = "preGetRaw",
64
- POST_GET_RAW = "postGetRaw",
65
- PRE_GET_MANY_RAW = "preGetManyRaw",
66
- POST_GET_MANY_RAW = "postGetManyRaw",
67
- PRE_SET_RAW = "preSetRaw",
68
- POST_SET_RAW = "postSetRaw",
69
- PRE_SET_MANY_RAW = "preSetManyRaw",
70
- POST_SET_MANY_RAW = "postSetManyRaw",
71
- PRE_DELETE = "preDelete",
72
- POST_DELETE = "postDelete"
73
- }
74
- type KeyvEntry = {
75
- /**
76
- * Key to set.
77
- */
78
- key: string;
79
- /**
80
- * Value to set.
81
- */
82
- value: any;
83
- /**
84
- * Time to live in milliseconds.
85
- */
86
- ttl?: number;
87
- };
88
- type StoredDataNoRaw<Value> = Value | undefined;
89
- type StoredDataRaw<Value> = DeserializedData<Value> | undefined;
90
- type StoredData<Value> = StoredDataNoRaw<Value> | StoredDataRaw<Value>;
91
- type IEventEmitter = {
92
- on(event: string, listener: (...arguments_: any[]) => void): IEventEmitter;
93
- };
94
- type KeyvStorageAdapter = {
95
- opts: any;
96
- namespace?: string | undefined;
97
- get<Value>(key: string): Promise<StoredData<Value> | undefined>;
98
- set(key: string, value: any, ttl?: number): any;
99
- setMany?(values: Array<{
100
- key: string;
101
- value: any;
102
- ttl?: number;
103
- }>): Promise<void>;
104
- delete(key: string): Promise<boolean>;
105
- clear(): Promise<void>;
106
- has?(key: string): Promise<boolean>;
107
- hasMany?(keys: string[]): Promise<boolean[]>;
108
- getMany?<Value>(keys: string[]): Promise<Array<StoredData<Value | undefined>>>;
109
- disconnect?(): Promise<void>;
110
- deleteMany?(key: string[]): Promise<boolean>;
111
- iterator?<Value>(namespace?: string): AsyncGenerator<Array<string | Awaited<Value> | undefined>, void>;
112
- } & IEventEmitter;
113
- type KeyvOptions = {
114
- /**
115
- * Emit errors
116
- * @default true
117
- */
118
- emitErrors?: boolean;
119
- /**
120
- * Namespace for the current instance.
121
- * @default 'keyv'
122
- */
123
- namespace?: string;
124
- /**
125
- * A custom serialization adapter with stringify and parse methods.
126
- * @default KeyvJsonSerializer (built-in)
127
- */
128
- serialization?: KeyvSerializationAdapter | false;
129
- /**
130
- * The storage adapter instance to be used by Keyv.
131
- * @default new Map() - in-memory store
132
- */
133
- store?: KeyvStorageAdapter | Map<any, any> | any;
134
- /**
135
- * Default TTL in milliseconds. Can be overridden by specifying a TTL on `.set()`.
136
- * @default undefined
137
- */
138
- ttl?: number;
139
- /**
140
- * Enable compression option
141
- * @default false
142
- */
143
- compression?: KeyvCompressionAdapter | any;
144
- /**
145
- * Enable or disable statistics (default is false)
146
- * @default false
147
- */
148
- stats?: boolean;
149
- /**
150
- * Will enable throwing errors on methods in addition to emitting them.
151
- * @default false
152
- */
153
- throwOnErrors?: boolean;
154
- };
155
- /**
156
- * @deprecated Use `KeyvStorageAdapter` instead.
157
- */
158
- type KeyvStoreAdapter = KeyvStorageAdapter;
159
- /**
160
- * @deprecated Use `KeyvCompressionAdapter` instead.
161
- */
162
- type KeyvCompression = KeyvCompressionAdapter;
163
-
164
- declare class KeyvJsonSerializer implements KeyvSerializationAdapter {
165
- stringify(object: unknown): string;
166
- parse<T>(data: string): T;
167
- }
168
- declare const jsonSerializer: KeyvJsonSerializer;
169
-
170
- type IteratorFunction = (argument: any) => AsyncGenerator<any, void>;
171
- declare class Keyv<GenericValue = any> extends EventManager {
172
- iterator?: IteratorFunction;
173
- hooks: HooksManager;
174
- stats: StatsManager;
175
- /**
176
- * Time to live in milliseconds
177
- */
178
- private _ttl?;
179
- /**
180
- * Namespace
181
- */
182
- private _namespace?;
183
- /**
184
- * Store
185
- */
186
- private _store;
187
- private _serialization;
188
- private _compression;
189
- private _throwOnErrors;
190
- private _emitErrors;
191
- /**
192
- * Keyv Constructor
193
- * @param {KeyvStorageAdapter | KeyvOptions | Map<any, any>} store to be provided or just the options
194
- * @param {Omit<KeyvOptions, 'store'>} [options] if you provide the store you can then provide the Keyv Options
195
- */
196
- constructor(store?: KeyvStorageAdapter | KeyvOptions | Map<any, any>, options?: Omit<KeyvOptions, "store">);
197
- /**
198
- * Keyv Constructor
199
- * @param {KeyvOptions} options to be provided
200
- */
201
- constructor(options?: KeyvOptions);
202
- /**
203
- * Get the current store
204
- */
205
- get store(): KeyvStorageAdapter | Map<any, any> | any;
206
- /**
207
- * Set the current store. This will also set the namespace, event error handler, and generate the iterator. If the store is not valid it will throw an error.
208
- * @param {KeyvStorageAdapter | Map<any, any> | any} store the store to set
209
- */
210
- set store(store: KeyvStorageAdapter | Map<any, any> | any);
211
- /**
212
- * Get the current compression function
213
- * @returns {KeyvCompressionAdapter} The current compression function
214
- */
215
- get compression(): KeyvCompressionAdapter | undefined;
216
- /**
217
- * Set the current compression function
218
- * @param {KeyvCompressionAdapter} compress The compression function to set
219
- */
220
- set compression(compress: KeyvCompressionAdapter | undefined);
221
- /**
222
- * Get the current namespace.
223
- * @returns {string | undefined} The current namespace.
224
- */
225
- get namespace(): string | undefined;
226
- /**
227
- * Set the current namespace.
228
- * @param {string | undefined} namespace The namespace to set.
229
- */
230
- set namespace(namespace: string | undefined);
231
- /**
232
- * Get the current TTL.
233
- * @returns {number} The current TTL in milliseconds.
234
- */
235
- get ttl(): number | undefined;
236
- /**
237
- * Set the current TTL.
238
- * @param {number} ttl The TTL to set in milliseconds.
239
- */
240
- set ttl(ttl: number | undefined);
241
- /**
242
- * Get the current serialization adapter.
243
- * @returns {KeyvSerializationAdapter | undefined} The current serialization adapter.
244
- */
245
- get serialization(): KeyvSerializationAdapter | undefined;
246
- /**
247
- * Set the current serialization adapter.
248
- * @param {KeyvSerializationAdapter | undefined} serialization The serialization adapter to set.
249
- */
250
- set serialization(serialization: KeyvSerializationAdapter | false | undefined);
251
- /**
252
- * Get the current throwErrors value. This will enable or disable throwing errors on methods in addition to emitting them.
253
- * @return {boolean} The current throwOnErrors value.
254
- */
255
- get throwOnErrors(): boolean;
256
- /**
257
- * Set the current throwOnErrors value. This will enable or disable throwing errors on methods in addition to emitting them.
258
- * @param {boolean} value The throwOnErrors value to set.
259
- */
260
- set throwOnErrors(value: boolean);
261
- /**
262
- * Get the current emitErrors value. This will enable or disable emitting errors on methods.
263
- * @return {boolean} The current emitErrors value.
264
- * @default true
265
- */
266
- get emitErrors(): boolean;
267
- /**
268
- * Set the current emitErrors value. This will enable or disable emitting errors on methods.
269
- * @param {boolean} value The emitErrors value to set.
270
- */
271
- set emitErrors(value: boolean);
272
- generateIterator(iterator: IteratorFunction): IteratorFunction;
273
- _checkIterableAdapter(): boolean;
274
- _isValidStorageAdapter(store: KeyvStorageAdapter | any): boolean;
275
- /**
276
- * Get the Value of a Key
277
- * @param {string | string[]} key passing in a single key or multiple as an array
278
- * @param {{raw: boolean} | undefined} options can pass in to return the raw value by setting { raw: true }
279
- */
280
- get<Value = GenericValue>(key: string, options?: {
281
- raw: false;
282
- }): Promise<StoredDataNoRaw<Value>>;
283
- get<Value = GenericValue>(key: string, options?: {
284
- raw: true;
285
- }): Promise<StoredDataRaw<Value>>;
286
- get<Value = GenericValue>(key: string[], options?: {
287
- raw: false;
288
- }): Promise<Array<StoredDataNoRaw<Value>>>;
289
- get<Value = GenericValue>(key: string[], options?: {
290
- raw: true;
291
- }): Promise<Array<StoredDataRaw<Value>>>;
292
- /**
293
- * Get many values of keys
294
- * @param {string[]} keys passing in a single key or multiple as an array
295
- * @param {{raw: boolean} | undefined} options can pass in to return the raw value by setting { raw: true }
296
- */
297
- getMany<Value = GenericValue>(keys: string[], options?: {
298
- raw: false;
299
- }): Promise<Array<StoredDataNoRaw<Value>>>;
300
- getMany<Value = GenericValue>(keys: string[], options?: {
301
- raw: true;
302
- }): Promise<Array<StoredDataRaw<Value>>>;
303
- /**
304
- * Get the raw value of a key. This is the replacement for setting raw to true in the get() method.
305
- * @param {string} key the key to get
306
- * @returns {Promise<StoredDataRaw<Value> | undefined>} will return a StoredDataRaw<Value> or undefined if the key does not exist or is expired.
307
- */
308
- getRaw<Value = GenericValue>(key: string): Promise<StoredDataRaw<Value> | undefined>;
309
- /**
310
- * Get the raw values of many keys. This is the replacement for setting raw to true in the getMany() method.
311
- * @param {string[]} keys the keys to get
312
- * @returns {Promise<Array<StoredDataRaw<Value>>>} will return an array of StoredDataRaw<Value> or undefined if the key does not exist or is expired.
313
- */
314
- getManyRaw<Value = GenericValue>(keys: string[]): Promise<Array<StoredDataRaw<Value>>>;
315
- /**
316
- * Set an item to the store
317
- * @param {string | Array<KeyvEntry>} key the key to use. If you pass in an array of KeyvEntry it will set many items
318
- * @param {Value} value the value of the key
319
- * @param {number} [ttl] time to live in milliseconds
320
- * @returns {boolean} if it sets then it will return a true. On failure will return false.
321
- */
322
- set<Value = GenericValue>(key: string, value: Value, ttl?: number): Promise<boolean>;
323
- /**
324
- * Set a raw value to the store without wrapping or serialization. This is the write-side counterpart to getRaw().
325
- * The value should be a DeserializedData object with { value, expires? }.
326
- * @param {string} key the key to set
327
- * @param {DeserializedData<Value>} value the raw value envelope to store
328
- * @param {number} [ttl] time to live in milliseconds. If the raw value does not already have an expires field, it will be computed from ttl.
329
- * @returns {boolean} if it sets then it will return a true. On failure will return false.
330
- */
331
- setRaw<Value = GenericValue>(key: string, value: DeserializedData<Value>, ttl?: number): Promise<boolean>;
332
- /**
333
- * Set many items to the store
334
- * @param {Array<KeyvEntry>} entries the entries to set
335
- * @returns {boolean[]} will return an array of booleans if it sets then it will return a true. On failure will return false.
336
- */
337
- setMany<Value = GenericValue>(entries: KeyvEntry[]): Promise<boolean[]>;
338
- /**
339
- * Set many raw values to the store without wrapping or serialization. This is the write-side counterpart to getManyRaw().
340
- * Each entry's value should be a DeserializedData object with { value, expires? }.
341
- * @param {Array<{key: string, value: DeserializedData<Value>, ttl?: number}>} entries the raw entries to set
342
- * @returns {boolean[]} will return an array of booleans if it sets then it will return a true. On failure will return false.
343
- */
344
- setManyRaw<Value = GenericValue>(entries: Array<{
345
- key: string;
346
- value: DeserializedData<Value>;
347
- ttl?: number;
348
- }>): Promise<boolean[]>;
349
- /**
350
- * Delete an Entry
351
- * @param {string | string[]} key the key to be deleted. if an array it will delete many items
352
- * @returns {boolean} will return true if item or items are deleted. false if there is an error
353
- */
354
- delete(key: string | string[]): Promise<boolean>;
355
- /**
356
- * Delete many items from the store
357
- * @param {string[]} keys the keys to be deleted
358
- * @returns {boolean} will return true if item or items are deleted. false if there is an error
359
- */
360
- deleteMany(keys: string[]): Promise<boolean>;
361
- /**
362
- * Clear the store
363
- * @returns {void}
364
- */
365
- clear(): Promise<void>;
366
- /**
367
- * Has a key
368
- * @param {string} key the key to check
369
- * @returns {boolean} will return true if the key exists
370
- */
371
- has(key: string[]): Promise<boolean[]>;
372
- has(key: string): Promise<boolean>;
373
- /**
374
- * Check if many keys exist
375
- * @param {string[]} keys the keys to check
376
- * @returns {boolean[]} will return an array of booleans if the keys exist
377
- */
378
- hasMany(keys: string[]): Promise<boolean[]>;
379
- /**
380
- * Will disconnect the store. This is only available if the store has a disconnect method
381
- * @returns {Promise<void>}
382
- */
383
- disconnect(): Promise<void>;
384
- emit(event: string, ...arguments_: any[]): void;
385
- serializeData<T>(data: DeserializedData<T>): Promise<string | DeserializedData<T>>;
386
- deserializeData<T>(data: string | DeserializedData<T>): Promise<DeserializedData<T> | undefined>;
387
- }
388
-
389
- export { type DeserializedData, type IEventEmitter, Keyv, type KeyvCompression, type KeyvCompressionAdapter, type KeyvEntry, KeyvHooks, KeyvJsonSerializer, type KeyvOptions, type KeyvSerializationAdapter, type KeyvStorageAdapter, type KeyvStoreAdapter, type StoredData, type StoredDataNoRaw, type StoredDataRaw, Keyv as default, jsonSerializer };