@keyv/bigmap 1.0.2 → 1.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/README.md CHANGED
@@ -4,8 +4,8 @@
4
4
 
5
5
  [![build](https://github.com/jaredwray/keyv/actions/workflows/tests.yaml/badge.svg)](https://github.com/jaredwray/keyv/actions/workflows/tests.yaml)
6
6
  [![codecov](https://codecov.io/gh/jaredwray/keyv/branch/main/graph/badge.svg?token=bRzR3RyOXZ)](https://codecov.io/gh/jaredwray/keyv)
7
- [![npm](https://img.shields.io/npm/v/@keyv/redis.svg)](https://www.npmjs.com/package/@keyv/redis)
8
- [![npm](https://img.shields.io/npm/dm/@keyv/redis)](https://npmjs.com/package/@keyv/redis)
7
+ [![npm](https://img.shields.io/npm/v/@keyv/bigmap.svg)](https://www.npmjs.com/package/@keyv/bigmap)
8
+ [![npm](https://img.shields.io/npm/dm/@keyv/bigmap)](https://npmjs.com/package/@keyv/bigmap)
9
9
 
10
10
  # Features
11
11
  * Based on the Map interface and uses the same API.
@@ -14,13 +14,52 @@
14
14
  * Uses a hash `djb2Hash` for fast key lookups.
15
15
  * Ability to use your own hash function.
16
16
  * Built in Typescript and Generics for type safety.
17
- * Used as default in-memory store for `Keyv`.
18
- * Used as in-memory store for `@keyv/fs`.
19
17
  * Used in `@cacheable/memory` for scalable in-memory caching.
20
18
  * Maintained regularly with a focus on performance and reliability.
21
19
 
22
20
  # Table of Contents
23
21
 
22
+ - [Features](#features)
23
+ - [Installation](#installation)
24
+ - [Overview](#overview)
25
+ - [Basic Usage](#basic-usage)
26
+ - [Custom Store Size](#custom-store-size)
27
+ - [Custom Hash Function](#custom-hash-function)
28
+ - [Iteration](#iteration)
29
+ - [For...of Loop](#forof-loop)
30
+ - [forEach](#foreach)
31
+ - [Keys, Values, and Entries](#keys-values-and-entries)
32
+ - [Advanced Features](#advanced-features)
33
+ - [Type Safety with Generics](#type-safety-with-generics)
34
+ - [Large-Scale Data](#large-scale-data)
35
+ - [Using with Keyv](#using-with-keyv)
36
+ - [`createKeyv(options?)`](#createkeyvoptions)
37
+ - [With Custom Options](#with-custom-options)
38
+ - [Type Safety](#type-safety)
39
+ - [Integration with Keyv Ecosystem](#integration-with-keyv-ecosystem)
40
+ - [API](#api)
41
+ - [Constructor](#constructor)
42
+ - [Properties](#properties)
43
+ - [Methods](#methods)
44
+ - [`set(key, value)`](#setkey-value)
45
+ - [`get(key)`](#getkey)
46
+ - [`has(key)`](#haskey)
47
+ - [`delete(key)`](#deletekey)
48
+ - [`clear()`](#clear)
49
+ - [`forEach(callbackfn, thisArg?)`](#foreachcallbackfn-thisarg)
50
+ - [`keys()`](#keys)
51
+ - [`values()`](#values)
52
+ - [`entries()`](#entries)
53
+ - [`[Symbol.iterator]()`](#symboliterator)
54
+ - [`getStore(key)`](#getstorekey)
55
+ - [`getStoreMap(index)`](#getstoremapindex)
56
+ - [`initStore()`](#initstore)
57
+ - [Types](#types)
58
+ - [`StoreHashFunction`](#storehashfunction)
59
+ - [`defaultHashFunction(key, storeSize)`](#defaulthashfunctionkey-storesize)
60
+ - [`djb2Hash(string, min?, max?)`](#djb2hashstring-min-max)
61
+ - [Contributing](#contributing)
62
+ - [License](#license)
24
63
 
25
64
  # Installation
26
65
 
@@ -28,9 +67,523 @@
28
67
  npm install --save keyv @keyv/bigmap
29
68
  ```
30
69
 
31
- # Usage
70
+ # Overview
32
71
 
33
- # Benchmarks
72
+ BigMap is a scalable Map implementation that overcomes JavaScript's built-in Map limit of approximately 17 million entries. It uses a distributed hash approach with multiple internal Map instances.
73
+
74
+ # Basic Usage
75
+
76
+ ```typescript
77
+ import { BigMap } from '@keyv/bigmap';
78
+
79
+ // Create a new BigMap
80
+ const bigMap = new BigMap<string, number>();
81
+
82
+ // Set values
83
+ bigMap.set('key1', 100);
84
+ bigMap.set('key2', 200);
85
+
86
+ // Get values
87
+ const value = bigMap.get('key1'); // 100
88
+
89
+ // Check if key exists
90
+ bigMap.has('key1'); // true
91
+
92
+ // Delete a key
93
+ bigMap.delete('key1'); // true
94
+
95
+ // Get size
96
+ console.log(bigMap.size); // 1
97
+
98
+ // Clear all entries
99
+ bigMap.clear();
100
+ ```
101
+
102
+ ## Custom Store Size
103
+
104
+ By default, BigMap uses 4 internal Map instances. You can configure this:
105
+
106
+ ```typescript
107
+ const bigMap = new BigMap<string, number>({ storeSize: 10 });
108
+ ```
109
+
110
+ **Note:** Changing the `storeSize` after initialization will clear all entries.
111
+
112
+ ## Custom Hash Function
113
+
114
+ Provide your own hash function for key distribution:
115
+
116
+ ```typescript
117
+ const customHashFunction = (key: string, storeSize: number) => {
118
+ return key.length % storeSize;
119
+ };
120
+
121
+ const bigMap = new BigMap<string, string>({
122
+ storeHashFunction: customHashFunction
123
+ });
124
+ ```
125
+
126
+ ## Iteration
127
+
128
+ BigMap supports all standard Map iteration methods:
129
+
130
+ ### For...of Loop
131
+
132
+ ```typescript
133
+ const bigMap = new BigMap<string, number>();
134
+ bigMap.set('a', 1);
135
+ bigMap.set('b', 2);
136
+
137
+ for (const [key, value] of bigMap) {
138
+ console.log(key, value);
139
+ }
140
+ ```
141
+
142
+ ## forEach
143
+
144
+ ```typescript
145
+ bigMap.forEach((value, key) => {
146
+ console.log(key, value);
147
+ });
148
+
149
+ // With custom context
150
+ const context = { sum: 0 };
151
+ bigMap.forEach(function(value) {
152
+ this.sum += value;
153
+ }, context);
154
+ ```
155
+
156
+ ## Keys, Values, and Entries
157
+
158
+ ```typescript
159
+ // Iterate over keys
160
+ for (const key of bigMap.keys()) {
161
+ console.log(key);
162
+ }
163
+
164
+ // Iterate over values
165
+ for (const value of bigMap.values()) {
166
+ console.log(value);
167
+ }
168
+
169
+ // Iterate over entries
170
+ for (const [key, value] of bigMap.entries()) {
171
+ console.log(key, value);
172
+ }
173
+ ```
174
+
175
+ ## Advanced Features
176
+
177
+ ### Type Safety with Generics
178
+
179
+ ```typescript
180
+ interface User {
181
+ id: number;
182
+ name: string;
183
+ }
184
+
185
+ const userMap = new BigMap<string, User>();
186
+ userMap.set('user1', { id: 1, name: 'Alice' });
187
+ ```
188
+
189
+ ### Large-Scale Data
190
+
191
+ BigMap is designed to handle millions of entries:
192
+
193
+ ```typescript
194
+ const bigMap = new BigMap<string, number>({ storeSize: 16 });
195
+
196
+ // Add 20+ million entries without hitting Map limits
197
+ for (let i = 0; i < 20000000; i++) {
198
+ bigMap.set(`key${i}`, i);
199
+ }
200
+
201
+ console.log(bigMap.size); // 20000000
202
+ ```
203
+
204
+ ## Using with Keyv
205
+
206
+ BigMap can be used as a storage adapter for [Keyv](https://github.com/jaredwray/keyv), providing a scalable in-memory store with TTL support.
207
+
208
+ ### `createKeyv(options?)`
209
+
210
+ The `createKeyv` function creates a Keyv instance with BigMap as the storage adapter.
211
+
212
+ **Parameters:**
213
+ - `options` (optional): BigMap configuration options
214
+ - `storeSize` (number): Number of internal Map instances. Default: `4`
215
+ - `storeHashFunction` (StoreHashFunction): Custom hash function for key distribution
216
+
217
+ **Returns:** `Keyv` instance with BigMap adapter
218
+
219
+ **Example:**
220
+
221
+ ```typescript
222
+ import { createKeyv } from '@keyv/bigmap';
223
+
224
+ // Basic usage
225
+ const keyv = createKeyv();
226
+
227
+ // Set with TTL (in milliseconds)
228
+ await keyv.set('user:123', { name: 'Alice', age: 30 }, 60000); // Expires in 60 seconds
229
+
230
+ // Get value
231
+ const user = await keyv.get('user:123');
232
+ console.log(user); // { name: 'Alice', age: 30 }
233
+
234
+ // Check if key exists
235
+ const exists = await keyv.has('user:123');
236
+
237
+ // Delete key
238
+ await keyv.delete('user:123');
239
+
240
+ // Clear all keys
241
+ await keyv.clear();
242
+ ```
243
+
244
+ ### With Custom Options
245
+
246
+ ```typescript
247
+ import { createKeyv } from '@keyv/bigmap';
248
+
249
+ // Create with custom store size for better performance with millions of keys
250
+ const keyv = createKeyv({ storeSize: 16 });
251
+
252
+ // With custom hash function
253
+ const keyv = createKeyv({
254
+ storeSize: 8,
255
+ storeHashFunction: (key, storeSize) => {
256
+ // Custom distribution logic
257
+ return key.length % storeSize;
258
+ }
259
+ });
260
+ ```
261
+
262
+ ### Type Safety
263
+
264
+ ```typescript
265
+ import { createKeyv } from '@keyv/bigmap';
266
+
267
+ interface Product {
268
+ id: string;
269
+ name: string;
270
+ price: number;
271
+ }
272
+
273
+ const keyv = createKeyv<string, Product>();
274
+
275
+ await keyv.set('product:1', {
276
+ id: '1',
277
+ name: 'Laptop',
278
+ price: 999
279
+ });
280
+
281
+ const product = await keyv.get<Product>('product:1');
282
+ ```
283
+
284
+ ### Integration with Keyv Ecosystem
285
+
286
+ BigMap works seamlessly with the Keyv ecosystem:
287
+
288
+ ```typescript
289
+ import { createKeyv } from '@keyv/bigmap';
290
+
291
+ const cache = createKeyv({ storeSize: 16 });
292
+
293
+ // Use with namespaces
294
+ const users = cache.namespace('users');
295
+ const products = cache.namespace('products');
296
+
297
+ await users.set('123', { name: 'Alice' });
298
+ await products.set('456', { name: 'Laptop' });
299
+
300
+ // Iterate over keys
301
+ for await (const [key, value] of cache.iterator()) {
302
+ console.log(key, value);
303
+ }
304
+ ```
305
+
306
+ # API
307
+
308
+ # Constructor
309
+
310
+ `new BigMap<K, V>(options?)`
311
+
312
+ Creates a new BigMap instance.
313
+
314
+ **Parameters:**
315
+ - `options` (optional): Configuration options
316
+ - `storeSize` (number): Number of internal Map instances to use. Default: `4`. Must be at least 1.
317
+ - `storeHashFunction` (StoreHashFunction): Custom hash function for key distribution. Default: `defaultHashFunction`
318
+
319
+ **Example:**
320
+ ```typescript
321
+ const bigMap = new BigMap<string, number>();
322
+ const customBigMap = new BigMap<string, number>({
323
+ storeSize: 10,
324
+ storeHashFunction: (key, storeSize) => key.length % storeSize
325
+ });
326
+ ```
327
+
328
+ ## Properties
329
+
330
+ | Property | Type | Access | Description |
331
+ |----------|------|--------|-------------|
332
+ | `size` | `number` | Read-only | Gets the total number of entries in the BigMap. |
333
+ | `storeSize` | `number` | Read/Write | Gets or sets the number of internal Map instances. **Note:** Setting this will clear all entries. Default: `4` |
334
+ | `storeHashFunction` | `StoreHashFunction \| undefined` | Read/Write | Gets or sets the hash function used for key distribution. |
335
+ | `store` | `Array<Map<K, V>>` | Read-only | Gets the internal array of Map instances. |
336
+
337
+ **Examples:**
338
+ ```typescript
339
+ const bigMap = new BigMap<string, number>();
340
+
341
+ // size property
342
+ bigMap.set('key1', 100);
343
+ console.log(bigMap.size); // 1
344
+
345
+ // storeSize property
346
+ console.log(bigMap.storeSize); // 4 (default)
347
+ bigMap.storeSize = 8; // Changes size and clears all entries
348
+
349
+ // storeHashFunction property
350
+ bigMap.storeHashFunction = (key, storeSize) => key.length % storeSize;
351
+
352
+ // store property
353
+ console.log(bigMap.store.length); // 8
354
+ ```
355
+
356
+ # Methods
357
+
358
+ ## `set(key, value)`
359
+
360
+ Sets the value for a key in the map.
361
+
362
+ **Parameters:**
363
+ - `key` (K): The key to set
364
+ - `value` (V): The value to associate with the key
365
+
366
+ **Returns:** `Map<K, V>` - The internal Map instance where the key was stored
367
+
368
+ **Example:**
369
+ ```typescript
370
+ bigMap.set('user123', { name: 'Alice' });
371
+ ```
372
+
373
+ ## `get(key)`
374
+
375
+ Gets the value associated with a key.
376
+
377
+ **Parameters:**
378
+ - `key` (K): The key to retrieve
379
+
380
+ **Returns:** `V | undefined` - The value, or undefined if not found
381
+
382
+ **Example:**
383
+ ```typescript
384
+ const value = bigMap.get('user123');
385
+ ```
386
+
387
+ ## `has(key)`
388
+
389
+ Checks if a key exists in the map.
390
+
391
+ **Parameters:**
392
+ - `key` (K): The key to check
393
+
394
+ **Returns:** `boolean` - True if the key exists, false otherwise
395
+
396
+ **Example:**
397
+ ```typescript
398
+ if (bigMap.has('user123')) {
399
+ console.log('User exists');
400
+ }
401
+ ```
402
+
403
+ ## `delete(key)`
404
+
405
+ Deletes a key-value pair from the map.
406
+
407
+ **Parameters:**
408
+ - `key` (K): The key to delete
409
+
410
+ **Returns:** `boolean` - True if the entry was deleted, false if the key was not found
411
+
412
+ **Example:**
413
+ ```typescript
414
+ const deleted = bigMap.delete('user123');
415
+ ```
416
+
417
+ ## `clear()`
418
+
419
+ Removes all entries from the map.
420
+
421
+ **Returns:** `void`
422
+
423
+ **Example:**
424
+ ```typescript
425
+ bigMap.clear();
426
+ console.log(bigMap.size); // 0
427
+ ```
428
+
429
+ ## `forEach(callbackfn, thisArg?)`
430
+
431
+ Executes a provided function once for each key-value pair.
432
+
433
+ **Parameters:**
434
+ - `callbackfn` (function): Function to execute for each entry
435
+ - `value` (V): The value of the current entry
436
+ - `key` (K): The key of the current entry
437
+ - `map` (Map<K, V>): The BigMap instance
438
+ - `thisArg` (optional): Value to use as `this` when executing the callback
439
+
440
+ **Returns:** `void`
441
+
442
+ **Example:**
443
+ ```typescript
444
+ bigMap.forEach((value, key) => {
445
+ console.log(`${key}: ${value}`);
446
+ });
447
+
448
+ // With custom context
449
+ const context = { total: 0 };
450
+ bigMap.forEach(function(value) {
451
+ this.total += value;
452
+ }, context);
453
+ ```
454
+
455
+ ## `keys()`
456
+
457
+ Returns an iterator of all keys in the map.
458
+
459
+ **Returns:** `IterableIterator<K>`
460
+
461
+ **Example:**
462
+ ```typescript
463
+ for (const key of bigMap.keys()) {
464
+ console.log(key);
465
+ }
466
+ ```
467
+
468
+ ## `values()`
469
+
470
+ Returns an iterator of all values in the map.
471
+
472
+ **Returns:** `IterableIterator<V>`
473
+
474
+ **Example:**
475
+ ```typescript
476
+ for (const value of bigMap.values()) {
477
+ console.log(value);
478
+ }
479
+ ```
480
+
481
+ ## `entries()`
482
+
483
+ Returns an iterator of all key-value pairs in the map.
484
+
485
+ **Returns:** `IterableIterator<[K, V]>`
486
+
487
+ **Example:**
488
+ ```typescript
489
+ for (const [key, value] of bigMap.entries()) {
490
+ console.log(key, value);
491
+ }
492
+ ```
493
+
494
+ ## `[Symbol.iterator]()`
495
+
496
+ Returns an iterator for the map (same as `entries()`). Enables `for...of` loops.
497
+
498
+ **Returns:** `IterableIterator<[K, V]>`
499
+
500
+ **Example:**
501
+ ```typescript
502
+ for (const [key, value] of bigMap) {
503
+ console.log(key, value);
504
+ }
505
+ ```
506
+
507
+ ## `getStore(key)`
508
+
509
+ Gets the internal Map instance for a specific key.
510
+
511
+ **Parameters:**
512
+ - `key` (K): The key to find the store for
513
+
514
+ **Returns:** `Map<K, V>` - The internal Map instance
515
+
516
+ **Example:**
517
+ ```typescript
518
+ const store = bigMap.getStore('user123');
519
+ ```
520
+
521
+ ## `getStoreMap(index)`
522
+
523
+ Gets the internal Map instance at a specific index.
524
+
525
+ **Parameters:**
526
+ - `index` (number): The index of the Map to retrieve (0 to storeSize - 1)
527
+
528
+ **Returns:** `Map<K, V>` - The Map at the specified index
529
+
530
+ **Throws:** Error if index is out of bounds
531
+
532
+ **Example:**
533
+ ```typescript
534
+ const firstMap = bigMap.getStoreMap(0);
535
+ ```
536
+
537
+ ## `initStore()`
538
+
539
+ Initializes the internal store with empty Map instances. Called automatically during construction.
540
+
541
+ **Returns:** `void`
542
+
543
+ # Types
544
+
545
+ ## `StoreHashFunction`
546
+
547
+ Type definition for custom hash functions.
548
+
549
+ ```typescript
550
+ type StoreHashFunction = (key: string, storeSize: number) => number;
551
+ ```
552
+
553
+ **Parameters:**
554
+ - `key` (string): The key to hash (converted to string)
555
+ - `storeSize` (number): The number of stores (adjusted for zero-based index)
556
+
557
+ **Returns:** `number` - The index of the store to use (0 to storeSize - 1)
558
+
559
+ ## `defaultHashFunction(key, storeSize)`
560
+
561
+ The default hash function using DJB2 algorithm.
562
+
563
+ **Example:**
564
+ ```typescript
565
+ import { defaultHashFunction } from '@keyv/bigmap';
566
+
567
+ const index = defaultHashFunction('myKey', 4);
568
+ ```
569
+
570
+ ## `djb2Hash(string, min?, max?)`
571
+
572
+ DJB2 hash algorithm implementation.
573
+
574
+ **Parameters:**
575
+ - `string` (string): The string to hash
576
+ - `min` (number): Minimum value. Default: `0`
577
+ - `max` (number): Maximum value. Default: `10`
578
+
579
+ **Returns:** `number` - Hash value within the specified range
580
+
581
+ **Example:**
582
+ ```typescript
583
+ import { djb2Hash } from '@keyv/bigmap';
584
+
585
+ const hash = djb2Hash('myKey', 0, 10);
586
+ ```
34
587
 
35
588
  # Contributing
36
589
 
package/dist/index.cjs CHANGED
@@ -21,11 +21,15 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
23
  BigMap: () => BigMap,
24
+ Keyv: () => import_keyv2.Keyv,
25
+ createKeyv: () => createKeyv,
24
26
  defaultHashFunction: () => defaultHashFunction,
25
27
  djb2Hash: () => djb2Hash
26
28
  });
27
29
  module.exports = __toCommonJS(index_exports);
28
30
  var import_hookified = require("hookified");
31
+ var import_keyv = require("keyv");
32
+ var import_keyv2 = require("keyv");
29
33
  function defaultHashFunction(key, storeSize) {
30
34
  return djb2Hash(key, 0, storeSize - 1);
31
35
  }
@@ -136,10 +140,7 @@ var BigMap = class extends import_hookified.Hookified {
136
140
  return this.getStoreMap(0);
137
141
  }
138
142
  const storeSize = this._storeSize - 1;
139
- const index = this._storeHashFunction ? this._storeHashFunction(String(key), storeSize) : (
140
- /* c8 ignore next */
141
- defaultHashFunction(String(key), storeSize)
142
- );
143
+ const index = this._storeHashFunction ? this._storeHashFunction(String(key), storeSize) : defaultHashFunction(String(key), storeSize);
143
144
  return this.getStoreMap(index);
144
145
  }
145
146
  /**
@@ -212,7 +213,9 @@ var BigMap = class extends import_hookified.Hookified {
212
213
  */
213
214
  forEach(callbackfn, thisArg) {
214
215
  this._store.forEach((store) => {
215
- store.forEach(callbackfn, thisArg);
216
+ store.forEach((value, key) => {
217
+ callbackfn.call(thisArg, value, key, this);
218
+ });
216
219
  });
217
220
  }
218
221
  /**
@@ -256,9 +259,16 @@ var BigMap = class extends import_hookified.Hookified {
256
259
  return size;
257
260
  }
258
261
  };
262
+ function createKeyv(options) {
263
+ const adapter = new BigMap(options);
264
+ const keyv = new import_keyv.Keyv({ store: adapter });
265
+ return keyv;
266
+ }
259
267
  // Annotate the CommonJS export names for ESM import in node:
260
268
  0 && (module.exports = {
261
269
  BigMap,
270
+ Keyv,
271
+ createKeyv,
262
272
  defaultHashFunction,
263
273
  djb2Hash
264
274
  });
package/dist/index.d.cts CHANGED
@@ -1,4 +1,6 @@
1
1
  import { HookifiedOptions, Hookified } from 'hookified';
2
+ import { Keyv } from 'keyv';
3
+ export { Keyv } from 'keyv';
2
4
 
3
5
  type MapInterfacee<K, V> = {
4
6
  readonly size: number;
@@ -145,5 +147,11 @@ declare class BigMap<K, V> extends Hookified implements MapInterfacee<K, V> {
145
147
  */
146
148
  get size(): number;
147
149
  }
150
+ /**
151
+ * Will create a Keyv instance with the BigMap adapter. This will also set the namespace and useKeyPrefix to false.
152
+ * @param {BigMapOptions} options - Options for the BigMap adapter such as storeSize and storeHashFunction.
153
+ * @returns {Keyv} - Keyv instance with the BigMap adapter
154
+ */
155
+ declare function createKeyv<K = string, V = unknown>(options?: BigMapOptions): Keyv;
148
156
 
149
- export { BigMap, type BigMapOptions, type MapInterfacee, type StoreHashFunction, defaultHashFunction, djb2Hash };
157
+ export { BigMap, type BigMapOptions, type MapInterfacee, type StoreHashFunction, createKeyv, defaultHashFunction, djb2Hash };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  import { HookifiedOptions, Hookified } from 'hookified';
2
+ import { Keyv } from 'keyv';
3
+ export { Keyv } from 'keyv';
2
4
 
3
5
  type MapInterfacee<K, V> = {
4
6
  readonly size: number;
@@ -145,5 +147,11 @@ declare class BigMap<K, V> extends Hookified implements MapInterfacee<K, V> {
145
147
  */
146
148
  get size(): number;
147
149
  }
150
+ /**
151
+ * Will create a Keyv instance with the BigMap adapter. This will also set the namespace and useKeyPrefix to false.
152
+ * @param {BigMapOptions} options - Options for the BigMap adapter such as storeSize and storeHashFunction.
153
+ * @returns {Keyv} - Keyv instance with the BigMap adapter
154
+ */
155
+ declare function createKeyv<K = string, V = unknown>(options?: BigMapOptions): Keyv;
148
156
 
149
- export { BigMap, type BigMapOptions, type MapInterfacee, type StoreHashFunction, defaultHashFunction, djb2Hash };
157
+ export { BigMap, type BigMapOptions, type MapInterfacee, type StoreHashFunction, createKeyv, defaultHashFunction, djb2Hash };
package/dist/index.js CHANGED
@@ -1,5 +1,7 @@
1
1
  // src/index.ts
2
2
  import { Hookified } from "hookified";
3
+ import { Keyv } from "keyv";
4
+ import { Keyv as Keyv2 } from "keyv";
3
5
  function defaultHashFunction(key, storeSize) {
4
6
  return djb2Hash(key, 0, storeSize - 1);
5
7
  }
@@ -110,10 +112,7 @@ var BigMap = class extends Hookified {
110
112
  return this.getStoreMap(0);
111
113
  }
112
114
  const storeSize = this._storeSize - 1;
113
- const index = this._storeHashFunction ? this._storeHashFunction(String(key), storeSize) : (
114
- /* c8 ignore next */
115
- defaultHashFunction(String(key), storeSize)
116
- );
115
+ const index = this._storeHashFunction ? this._storeHashFunction(String(key), storeSize) : defaultHashFunction(String(key), storeSize);
117
116
  return this.getStoreMap(index);
118
117
  }
119
118
  /**
@@ -186,7 +185,9 @@ var BigMap = class extends Hookified {
186
185
  */
187
186
  forEach(callbackfn, thisArg) {
188
187
  this._store.forEach((store) => {
189
- store.forEach(callbackfn, thisArg);
188
+ store.forEach((value, key) => {
189
+ callbackfn.call(thisArg, value, key, this);
190
+ });
190
191
  });
191
192
  }
192
193
  /**
@@ -230,8 +231,15 @@ var BigMap = class extends Hookified {
230
231
  return size;
231
232
  }
232
233
  };
234
+ function createKeyv(options) {
235
+ const adapter = new BigMap(options);
236
+ const keyv = new Keyv({ store: adapter });
237
+ return keyv;
238
+ }
233
239
  export {
234
240
  BigMap,
241
+ Keyv2 as Keyv,
242
+ createKeyv,
235
243
  defaultHashFunction,
236
244
  djb2Hash
237
245
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@keyv/bigmap",
3
- "version": "1.0.2",
3
+ "version": "1.1.0",
4
4
  "description": "Bigmap for Keyv",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -32,16 +32,19 @@
32
32
  },
33
33
  "homepage": "https://github.com/jaredwray/keyv",
34
34
  "dependencies": {
35
- "hookified": "^1.12.1"
35
+ "hookified": "^1.12.2"
36
36
  },
37
37
  "devDependencies": {
38
- "@biomejs/biome": "^2.2.4",
39
- "@faker-js/faker": "^10.0.0",
38
+ "@biomejs/biome": "^2.2.6",
39
+ "@faker-js/faker": "^10.1.0",
40
40
  "@vitest/coverage-v8": "^3.2.4",
41
41
  "rimraf": "^6.0.1",
42
42
  "tsd": "^0.33.0",
43
43
  "vitest": "^3.2.4"
44
44
  },
45
+ "peerDependencies": {
46
+ "keyv": "^5.5.3"
47
+ },
45
48
  "tsd": {
46
49
  "directory": "test"
47
50
  },