keyv-registry 2.0.3 → 3.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.
Files changed (49) hide show
  1. package/README.md +54 -22
  2. package/dist/cjs/constants.d.cts +3 -0
  3. package/dist/cjs/constants.d.ts +3 -0
  4. package/dist/cjs/constants.js +37 -0
  5. package/dist/cjs/constants.js.map +1 -0
  6. package/dist/cjs/index.d.cts +2 -0
  7. package/dist/cjs/index.d.ts +2 -0
  8. package/dist/cjs/index.js +8 -0
  9. package/dist/cjs/index.js.map +1 -1
  10. package/dist/cjs/loadAdapter.js +14 -2
  11. package/dist/cjs/loadAdapter.js.map +1 -1
  12. package/dist/cjs/migrate-keyv5.d.cts +18 -0
  13. package/dist/cjs/migrate-keyv5.d.ts +18 -0
  14. package/dist/cjs/migrate-keyv5.js +554 -0
  15. package/dist/cjs/migrate-keyv5.js.map +1 -0
  16. package/dist/cjs/registry.js +2 -2
  17. package/dist/cjs/registry.js.map +1 -1
  18. package/dist/cjs/types.d.cts +4 -8
  19. package/dist/cjs/types.d.ts +4 -8
  20. package/dist/cjs/utils.d.cts +14 -1
  21. package/dist/cjs/utils.d.ts +14 -1
  22. package/dist/cjs/utils.js +24 -12
  23. package/dist/cjs/utils.js.map +1 -1
  24. package/dist/cjs/worker.d.cts +7 -0
  25. package/dist/cjs/worker.d.ts +7 -0
  26. package/dist/cjs/worker.js +66 -53
  27. package/dist/cjs/worker.js.map +1 -1
  28. package/dist/esm/constants.d.ts +3 -0
  29. package/dist/esm/constants.js +18 -0
  30. package/dist/esm/constants.js.map +1 -0
  31. package/dist/esm/index.d.ts +2 -0
  32. package/dist/esm/index.js +2 -0
  33. package/dist/esm/index.js.map +1 -1
  34. package/dist/esm/loadAdapter.js +14 -2
  35. package/dist/esm/loadAdapter.js.map +1 -1
  36. package/dist/esm/migrate-keyv5.d.ts +18 -0
  37. package/dist/esm/migrate-keyv5.js +74 -0
  38. package/dist/esm/migrate-keyv5.js.map +1 -0
  39. package/dist/esm/registry.js +2 -2
  40. package/dist/esm/registry.js.map +1 -1
  41. package/dist/esm/types.d.ts +4 -8
  42. package/dist/esm/types.js.map +1 -1
  43. package/dist/esm/utils.d.ts +14 -1
  44. package/dist/esm/utils.js +21 -12
  45. package/dist/esm/utils.js.map +1 -1
  46. package/dist/esm/worker.d.ts +7 -0
  47. package/dist/esm/worker.js +25 -21
  48. package/dist/esm/worker.js.map +1 -1
  49. package/package.json +7 -5
package/README.md CHANGED
@@ -19,13 +19,14 @@ Create Keyv stores from URI strings, resolving each adapter from the modules ins
19
19
  npm install keyv-registry
20
20
  ```
21
21
 
22
- Requires Node.js >=16.
22
+ Requires Node.js >=22.19.0 (keyv 6's floor). Adapters should be keyv 6 adapters (`@keyv/redis` 6, `@keyv/sqlite` 6, ...); keyv 6 also wraps keyv 5-era adapters.
23
23
 
24
24
  Adapters are not bundled. Install the one your protocol needs alongside it:
25
25
 
26
26
  ```bash
27
27
  npm install @keyv/redis # redis://, rediss://
28
28
  npm install keyv-file # file://
29
+ npm install keyv-duckdb # duckdb:// (0.2.0 or later)
29
30
  ```
30
31
 
31
32
  `memory://` is built in and needs no package.
@@ -59,7 +60,7 @@ const sqlite = await createStore('sqlite:///path/to/db.sqlite');
59
60
  // With options
60
61
  const store = await createStore('redis://localhost:6379', {
61
62
  namespace: 'myapp',
62
- ttl: 60000
63
+ ttl: 60000,
63
64
  });
64
65
  ```
65
66
 
@@ -97,19 +98,22 @@ const file = await createStore('file://~/data.json?writeDelay=100&pretty=true');
97
98
  Connection strings are passed to adapters via protocol-specific mappings. Different adapters expect connection information in different formats:
98
99
 
99
100
  **Direct URL passing** (adapter instantiated with URI string):
101
+
100
102
  - `redis://`, `rediss://` - Redis
101
103
  - `memcache://` - Memcached
102
104
 
103
105
  **URI option mapping** (wrapped in `{ uri }` object):
106
+
104
107
  - `postgresql://`, `postgres://` - PostgreSQL
105
108
  - `mysql://` - MySQL/MariaDB
106
109
  - `sqlite://` - SQLite
107
110
 
108
111
  **URL option mapping** (wrapped in `{ url }` object):
112
+
109
113
  - `mongodb://`, `mongodb+srv://` - MongoDB
110
114
  - `etcd://` - etcd
111
115
 
112
- Query parameters are always passed through and can be used for adapter-specific configuration. User options override both query parameters and protocol mappings.
116
+ **Where options go.** For `file://`, `sqlite://` and `duckdb://` the URI path is the file location. Query parameters are adapter options. Options passed in code win over query parameters and over the URI path. Keyv's own options passed in code (`namespace`, `ttl`, `serialization`, `compression`, `stats`, `sanitize`, `encryption`, `checkExpired`) go to `new Keyv(...)`; every other option goes to the adapter constructor.
113
117
 
114
118
  ### Custom Adapters
115
119
 
@@ -127,8 +131,8 @@ registerAdapter('file:', {
127
131
  package: '@my-org/keyv-file-encrypted',
128
132
  optionsMapper: (url) => ({
129
133
  filename: url.pathname,
130
- encryption: true
131
- })
134
+ encryption: true,
135
+ }),
132
136
  });
133
137
  ```
134
138
 
@@ -142,7 +146,7 @@ import KeyvRedis from '@keyv/redis';
142
146
 
143
147
  const customRedis = new KeyvRedis('redis://localhost:6379', {
144
148
  useUnlink: true,
145
- cluster: true
149
+ cluster: true,
146
150
  });
147
151
 
148
152
  // URI is ignored when store option is provided
@@ -153,27 +157,27 @@ const store = await createStore('redis://ignored', { store: customRedis });
153
157
 
154
158
  ### Official @keyv Adapters
155
159
 
156
- | Protocol | Package | Connection String Handling | Notes |
157
- |----------|---------|---------------------------|-------|
158
- | `redis://`, `rediss://` | `@keyv/redis` | Direct URL | Redis, supports TLS |
159
- | `postgresql://`, `postgres://` | `@keyv/postgres` | URI option | PostgreSQL |
160
- | `mysql://` | `@keyv/mysql` | URI option | MySQL/MariaDB |
161
- | `sqlite://` | `@keyv/sqlite` | URI option | SQLite |
162
- | `mongodb://`, `mongodb+srv://` | `@keyv/mongo` | URL option | MongoDB |
163
- | `memcache://` | `@keyv/memcache` | Direct URI | Memcached |
164
- | `etcd://` | `@keyv/etcd` | URL option | etcd |
160
+ | Protocol | Package | Connection String Handling | Notes |
161
+ | ------------------------------ | ---------------- | -------------------------- | ------------------- |
162
+ | `redis://`, `rediss://` | `@keyv/redis` | Direct URL | Redis, supports TLS |
163
+ | `postgresql://`, `postgres://` | `@keyv/postgres` | URI option | PostgreSQL |
164
+ | `mysql://` | `@keyv/mysql` | URI option | MySQL/MariaDB |
165
+ | `sqlite://` | `@keyv/sqlite` | URI option | SQLite |
166
+ | `mongodb://`, `mongodb+srv://` | `@keyv/mongo` | URL option | MongoDB |
167
+ | `memcache://` | `@keyv/memcache` | Direct URI | Memcached |
168
+ | `etcd://` | `@keyv/etcd` | URL option | etcd |
165
169
 
166
170
  ### Third-party Adapters
167
171
 
168
- | Protocol | Package | Notes |
169
- |----------|---------|-------|
170
- | `file://` | `keyv-file` | File-based JSON storage |
171
- | `duckdb://` | `keyv-duckdb` | DuckDB (planned) |
172
+ | Protocol | Package | Notes |
173
+ | ----------- | ------------- | ----------------------- |
174
+ | `file://` | `keyv-file` | File-based JSON storage |
175
+ | `duckdb://` | `keyv-duckdb` | DuckDB, 0.2.0 or later |
172
176
 
173
177
  ### Built-in
174
178
 
175
- | Protocol | Notes |
176
- |----------|-------|
179
+ | Protocol | Notes |
180
+ | ----------- | -------------------------------- |
177
181
  | `memory://` | In-memory Map, no package needed |
178
182
 
179
183
  ## API
@@ -183,6 +187,7 @@ const store = await createStore('redis://ignored', { store: customRedis });
183
187
  Create a Keyv store from a URI string.
184
188
 
185
189
  **Parameters:**
190
+
186
191
  - `uri` (string): Connection URI with protocol
187
192
  - `options` (object, optional): Keyv options
188
193
  - `store`: Pre-instantiated adapter (bypasses URI loading)
@@ -198,6 +203,7 @@ Create a Keyv store from a URI string.
198
203
  Register or override a protocol adapter.
199
204
 
200
205
  **Parameters:**
206
+
201
207
  - `protocol` (string): Protocol with or without trailing colon (e.g., `'redis:'` or `'redis'`)
202
208
  - `config` (object): Adapter configuration
203
209
  - `package`: npm package name, or `null` for built-in
@@ -229,7 +235,33 @@ await createStore('file://./data/cache.json');
229
235
  await createStore('file:///var/cache/myapp/data.json');
230
236
  ```
231
237
 
232
- Directories are created automatically if they don't exist.
238
+ Directories are created automatically if they don't exist, for `file://`, `sqlite://` and `duckdb://`. If a directory cannot be created, `createStore` rejects. Windows drive paths work as `file:///C:/data/x.json` or `file://C:/data/x.json`.
239
+
240
+ ## Errors
241
+
242
+ keyv-registry attaches no `error` listener. With keyv 6, a failing call then rejects. Attach `store.on('error', ...)` yourself to get fallback values (`undefined`, `false`) instead.
243
+
244
+ ## Upgrading from 2.x
245
+
246
+ - Node.js >=22.19.0 and keyv 6.
247
+ - keyv 6 has no default namespace, and its key separator is `::`. Data written through keyv-registry 2.x (keyv 5, default namespace `keyv`) reads as missing. Move it once with `migrateKeyv5Keys`:
248
+
249
+ ```typescript
250
+ import createStore, { migrateKeyv5Keys } from 'keyv-registry';
251
+
252
+ const store = await createStore('file://~/.cache/app/data.json');
253
+ const moved = await migrateKeyv5Keys(store); // number of entries moved
254
+ ```
255
+
256
+ It moves entries of the default `keyv` namespace only, keeps expiry times, skips expired entries, keeps the plain key if both exist, and is safe to run again. Plan to remove the call once your data is moved; it goes away in the next major.
257
+
258
+ - Run it at startup, before the store serves other traffic: it renames keys and switches `store.namespace` while it runs.
259
+ - A plain key that itself starts with `keyv:` is taken for a keyv 5 key.
260
+ - A store that cannot iterate (for example memcache) has nothing to find: it returns 0 and your old entries stay unread.
261
+ - If a store error occurs during the move, the old key is kept and the call rejects with the error as `cause`. Entries already moved stay moved; run it again after fixing the cause.
262
+
263
+ - Keyv option keys given in code or the URI are no longer passed to the adapter constructor.
264
+ - `duckdb://` now opens the file in the URI. 2.x ignored the path and used `~/.keyv-duckdb/store.duckdb`.
233
265
 
234
266
  ## License
235
267
 
@@ -0,0 +1,3 @@
1
+ /** Namespace keyv 5 used by default; keyv 6 has none. */
2
+ export declare const KEYV5_NAMESPACE = "keyv";
3
+ export declare const KEYV_OPTION_KEYS: ReadonlySet<string>;
@@ -0,0 +1,3 @@
1
+ /** Namespace keyv 5 used by default; keyv 6 has none. */
2
+ export declare const KEYV5_NAMESPACE = "keyv";
3
+ export declare const KEYV_OPTION_KEYS: ReadonlySet<string>;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: Object.getOwnPropertyDescriptor(all, name).get
9
+ });
10
+ }
11
+ _export(exports, {
12
+ get KEYV5_NAMESPACE () {
13
+ return KEYV5_NAMESPACE;
14
+ },
15
+ get KEYV_OPTION_KEYS () {
16
+ return KEYV_OPTION_KEYS;
17
+ }
18
+ });
19
+ var KEYV5_NAMESPACE = 'keyv';
20
+ /**
21
+ * Option keys that belong to `new Keyv(...)`; every other option goes to the adapter constructor.
22
+ * One entry per key of `KeyvOptions`: keyv@6.1.0 `dist/index.d.mts:586` namespace, `:593` serialization, `:598` store,
23
+ * `:603` ttl, `:608` compression, `:613` stats, `:620` sanitize, `:628` encryption, `:638` checkExpired.
24
+ * The `Record<keyof KeyvOptions, true>` type makes a key added by a later keyv a compile error here.
25
+ */ var KEYV_OPTION_FLAGS = {
26
+ namespace: true,
27
+ serialization: true,
28
+ store: true,
29
+ ttl: true,
30
+ compression: true,
31
+ stats: true,
32
+ sanitize: true,
33
+ encryption: true,
34
+ checkExpired: true
35
+ };
36
+ var KEYV_OPTION_KEYS = new Set(Object.keys(KEYV_OPTION_FLAGS));
37
+ /* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/kevin/Dev/open-source/keyv/keyv-registry/src/constants.ts"],"sourcesContent":["import type { KeyvOptions } from 'keyv';\n\n/** Namespace keyv 5 used by default; keyv 6 has none. */\nexport const KEYV5_NAMESPACE = 'keyv';\n\n/**\n * Option keys that belong to `new Keyv(...)`; every other option goes to the adapter constructor.\n * One entry per key of `KeyvOptions`: keyv@6.1.0 `dist/index.d.mts:586` namespace, `:593` serialization, `:598` store,\n * `:603` ttl, `:608` compression, `:613` stats, `:620` sanitize, `:628` encryption, `:638` checkExpired.\n * The `Record<keyof KeyvOptions, true>` type makes a key added by a later keyv a compile error here.\n */\nconst KEYV_OPTION_FLAGS: Record<keyof KeyvOptions, true> = {\n namespace: true,\n serialization: true,\n store: true,\n ttl: true,\n compression: true,\n stats: true,\n sanitize: true,\n encryption: true,\n checkExpired: true,\n};\n\nexport const KEYV_OPTION_KEYS: ReadonlySet<string> = new Set(Object.keys(KEYV_OPTION_FLAGS));\n"],"names":["KEYV5_NAMESPACE","KEYV_OPTION_KEYS","KEYV_OPTION_FLAGS","namespace","serialization","store","ttl","compression","stats","sanitize","encryption","checkExpired","Set","Object","keys"],"mappings":";;;;;;;;;;;QAGaA;eAAAA;;QAoBAC;eAAAA;;;AApBN,IAAMD,kBAAkB;AAE/B;;;;;CAKC,GACD,IAAME,oBAAqD;IACzDC,WAAW;IACXC,eAAe;IACfC,OAAO;IACPC,KAAK;IACLC,aAAa;IACbC,OAAO;IACPC,UAAU;IACVC,YAAY;IACZC,cAAc;AAChB;AAEO,IAAMV,mBAAwC,IAAIW,IAAIC,OAAOC,IAAI,CAACZ"}
@@ -1,6 +1,8 @@
1
1
  import type Keyv from 'keyv';
2
2
  import type { CreateStoreCallback, CreateStoreOptions } from './types.js';
3
+ export { KEYV5_NAMESPACE } from './constants.js';
3
4
  export { clearAdapterCache } from './loadAdapter.js';
5
+ export { default as migrateKeyv5Keys } from './migrate-keyv5.js';
4
6
  export { getRegistry, registerAdapter } from './registry.js';
5
7
  export type { AdapterConfig, CreateStoreCallback, CreateStoreOptions } from './types.js';
6
8
  /**
@@ -1,6 +1,8 @@
1
1
  import type Keyv from 'keyv';
2
2
  import type { CreateStoreCallback, CreateStoreOptions } from './types.js';
3
+ export { KEYV5_NAMESPACE } from './constants.js';
3
4
  export { clearAdapterCache } from './loadAdapter.js';
5
+ export { default as migrateKeyv5Keys } from './migrate-keyv5.js';
4
6
  export { getRegistry, registerAdapter } from './registry.js';
5
7
  export type { AdapterConfig, CreateStoreCallback, CreateStoreOptions } from './types.js';
6
8
  /**
package/dist/cjs/index.js CHANGED
@@ -9,6 +9,9 @@ function _export(target, all) {
9
9
  });
10
10
  }
11
11
  _export(exports, {
12
+ get KEYV5_NAMESPACE () {
13
+ return _constantsts.KEYV5_NAMESPACE;
14
+ },
12
15
  get clearAdapterCache () {
13
16
  return _loadAdapterts.clearAdapterCache;
14
17
  },
@@ -18,12 +21,17 @@ _export(exports, {
18
21
  get getRegistry () {
19
22
  return _registryts.getRegistry;
20
23
  },
24
+ get migrateKeyv5Keys () {
25
+ return _migratekeyv5ts.default;
26
+ },
21
27
  get registerAdapter () {
22
28
  return _registryts.registerAdapter;
23
29
  }
24
30
  });
25
31
  var _workerts = /*#__PURE__*/ _interop_require_default(require("./worker.js"));
32
+ var _constantsts = require("./constants.js");
26
33
  var _loadAdapterts = require("./loadAdapter.js");
34
+ var _migratekeyv5ts = /*#__PURE__*/ _interop_require_default(require("./migrate-keyv5.js"));
27
35
  var _registryts = require("./registry.js");
28
36
  function _interop_require_default(obj) {
29
37
  return obj && obj.__esModule ? obj : {
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/open-source/keyv/keyv-registry/src/index.ts"],"sourcesContent":["import type Keyv from 'keyv';\nimport type { CreateStoreCallback, CreateStoreOptions } from './types.ts';\nimport worker from './worker.ts';\n\nexport { clearAdapterCache } from './loadAdapter.ts';\nexport { getRegistry, registerAdapter } from './registry.ts';\nexport type { AdapterConfig, CreateStoreCallback, CreateStoreOptions } from './types.ts';\n\n/**\n * Create a Keyv store from a URI string\n *\n * Supports dual-boot API (callback or Promise):\n *\n * @example\n * // Promise API\n * const store = await createStore('redis://localhost:6379');\n * const file = await createStore('file://~/.cache/app/data.json');\n * const memory = await createStore('memory://');\n *\n * @example\n * // Callback API\n * createStore('redis://localhost:6379', (err, store) => {\n * if (err) throw err;\n * // use store\n * });\n *\n * @example\n * // With options\n * const store = await createStore('redis://localhost:6379', {\n * namespace: 'myapp',\n * ttl: 60000\n * });\n *\n * @example\n * // Pre-instantiated adapter passthrough\n * import KeyvRedis from '@keyv/redis';\n * const redis = new KeyvRedis('redis://localhost:6379');\n * const store = await createStore('redis://ignored', { store: redis });\n */\nexport default function createStore<T>(uri: string, callback: CreateStoreCallback<T>): void;\nexport default function createStore<T>(uri: string, options: CreateStoreOptions, callback: CreateStoreCallback<T>): void;\nexport default function createStore<T>(uri: string, options?: CreateStoreOptions): Promise<Keyv<T>>;\nexport default function createStore<T>(uri: string, options?: CreateStoreOptions | CreateStoreCallback<T>, callback?: CreateStoreCallback<T>): void | Promise<Keyv<T>> {\n callback = typeof options === 'function' ? options : callback;\n options = typeof options === 'function' ? {} : ((options || {}) as CreateStoreOptions);\n\n if (typeof callback === 'function') return worker(uri, options, callback);\n return new Promise((resolve, reject) => worker(uri, options, (err, store) => (err ? reject(err) : resolve(store as Keyv<T>))));\n}\n"],"names":["clearAdapterCache","createStore","getRegistry","registerAdapter","uri","options","callback","worker","Promise","resolve","reject","err","store"],"mappings":";;;;;;;;;;;QAISA;eAAAA,gCAAiB;;QAsC1B;eAAwBC;;QArCfC;eAAAA,uBAAW;;QAAEC;eAAAA,2BAAe;;;+DAHlB;6BAEe;0BACW;;;;;;AAqC9B,SAASF,YAAeG,GAAW,EAAEC,OAAqD,EAAEC,QAAiC;IAC1IA,WAAW,OAAOD,YAAY,aAAaA,UAAUC;IACrDD,UAAU,OAAOA,YAAY,aAAa,CAAC,IAAMA,WAAW,CAAC;IAE7D,IAAI,OAAOC,aAAa,YAAY,OAAOC,IAAAA,iBAAM,EAACH,KAAKC,SAASC;IAChE,OAAO,IAAIE,QAAQ,SAACC,SAASC;eAAWH,IAAAA,iBAAM,EAACH,KAAKC,SAAS,SAACM,KAAKC;mBAAWD,MAAMD,OAAOC,OAAOF,QAAQG;;;AAC5G"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/open-source/keyv/keyv-registry/src/index.ts"],"sourcesContent":["import type Keyv from 'keyv';\nimport type { CreateStoreCallback, CreateStoreOptions } from './types.ts';\nimport worker from './worker.ts';\n\nexport { KEYV5_NAMESPACE } from './constants.ts';\nexport { clearAdapterCache } from './loadAdapter.ts';\nexport { default as migrateKeyv5Keys } from './migrate-keyv5.ts';\nexport { getRegistry, registerAdapter } from './registry.ts';\nexport type { AdapterConfig, CreateStoreCallback, CreateStoreOptions } from './types.ts';\n\n/**\n * Create a Keyv store from a URI string\n *\n * Supports dual-boot API (callback or Promise):\n *\n * @example\n * // Promise API\n * const store = await createStore('redis://localhost:6379');\n * const file = await createStore('file://~/.cache/app/data.json');\n * const memory = await createStore('memory://');\n *\n * @example\n * // Callback API\n * createStore('redis://localhost:6379', (err, store) => {\n * if (err) throw err;\n * // use store\n * });\n *\n * @example\n * // With options\n * const store = await createStore('redis://localhost:6379', {\n * namespace: 'myapp',\n * ttl: 60000\n * });\n *\n * @example\n * // Pre-instantiated adapter passthrough\n * import KeyvRedis from '@keyv/redis';\n * const redis = new KeyvRedis('redis://localhost:6379');\n * const store = await createStore('redis://ignored', { store: redis });\n */\nexport default function createStore<T>(uri: string, callback: CreateStoreCallback<T>): void;\nexport default function createStore<T>(uri: string, options: CreateStoreOptions, callback: CreateStoreCallback<T>): void;\nexport default function createStore<T>(uri: string, options?: CreateStoreOptions): Promise<Keyv<T>>;\nexport default function createStore<T>(uri: string, options?: CreateStoreOptions | CreateStoreCallback<T>, callback?: CreateStoreCallback<T>): void | Promise<Keyv<T>> {\n callback = typeof options === 'function' ? options : callback;\n options = typeof options === 'function' ? {} : ((options || {}) as CreateStoreOptions);\n\n if (typeof callback === 'function') return worker(uri, options, callback);\n return new Promise((resolve, reject) => worker(uri, options, (err, store) => (err ? reject(err) : resolve(store as Keyv<T>))));\n}\n"],"names":["KEYV5_NAMESPACE","clearAdapterCache","createStore","getRegistry","migrateKeyv5Keys","registerAdapter","uri","options","callback","worker","Promise","resolve","reject","err","store"],"mappings":";;;;;;;;;;;QAISA;eAAAA,4BAAe;;QACfC;eAAAA,gCAAiB;;QAuC1B;eAAwBC;;QArCfC;eAAAA,uBAAW;;QADAC;eAAAA,uBAAgB;;QACdC;eAAAA,2BAAe;;;+DALlB;2BAEa;6BACE;qEACU;0BACC;;;;;;AAqC9B,SAASH,YAAeI,GAAW,EAAEC,OAAqD,EAAEC,QAAiC;IAC1IA,WAAW,OAAOD,YAAY,aAAaA,UAAUC;IACrDD,UAAU,OAAOA,YAAY,aAAa,CAAC,IAAMA,WAAW,CAAC;IAE7D,IAAI,OAAOC,aAAa,YAAY,OAAOC,IAAAA,iBAAM,EAACH,KAAKC,SAASC;IAChE,OAAO,IAAIE,QAAQ,SAACC,SAASC;eAAWH,IAAAA,iBAAM,EAACH,KAAKC,SAAS,SAACM,KAAKC;mBAAWD,MAAMD,OAAOC,OAAOF,QAAQG;;;AAC5G"}
@@ -28,6 +28,18 @@ function _interop_require_default(obj) {
28
28
  var _require = typeof require === 'undefined' ? _nodemodule.default.createRequire(require("url").pathToFileURL(__filename).toString()) : require;
29
29
  // Cache loaded adapters
30
30
  var adapterCache = new Map();
31
+ // Module-not-found for the adapter itself; a missing dependency of the adapter names another module
32
+ function isMissingModule(err, packageName) {
33
+ var e = err;
34
+ return ((e === null || e === void 0 ? void 0 : e.code) === 'MODULE_NOT_FOUND' || (e === null || e === void 0 ? void 0 : e.code) === 'ERR_MODULE_NOT_FOUND') && typeof e.message === 'string' && e.message.includes("'".concat(packageName, "'"));
35
+ }
36
+ // Keep the original error as `cause` (the `ErrorOptions` argument is not in this project's lib target)
37
+ function loadError(err, packageName) {
38
+ var message = isMissingModule(err, packageName) ? 'Adapter "'.concat(packageName, '" is not installed. Install it alongside this package: npm install ').concat(packageName) : 'Adapter "'.concat(packageName, '" failed to load: ').concat(err === null || err === void 0 ? void 0 : err.message);
39
+ var error = new Error(message);
40
+ error.cause = err;
41
+ return error;
42
+ }
31
43
  function loadAdapter(packageName, exportName, callback) {
32
44
  var cacheKey = "".concat(packageName, ":").concat(exportName !== null && exportName !== void 0 ? exportName : 'default');
33
45
  // Return cached adapter if available
@@ -40,8 +52,8 @@ function loadAdapter(packageName, exportName, callback) {
40
52
  var _mod_default;
41
53
  var mod = _require(packageName);
42
54
  Adapter = exportName ? mod[exportName] : (_mod_default = mod.default) !== null && _mod_default !== void 0 ? _mod_default : mod;
43
- } catch (unused) {
44
- callback(new Error('Adapter "'.concat(packageName, '" is not installed. Install it alongside this package: npm install ').concat(packageName)));
55
+ } catch (err) {
56
+ callback(loadError(err, packageName));
45
57
  return;
46
58
  }
47
59
  adapterCache.set(cacheKey, Adapter);
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/open-source/keyv/keyv-registry/src/loadAdapter.ts"],"sourcesContent":["import Module from 'node:module';\nimport type { LoadAdapterCallback } from './types.ts';\n\n// Create require function for ESM compatibility\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\n// Cache loaded adapters\nconst adapterCache = new Map<string, unknown>();\n\n/**\n * Load an adapter from the modules installed alongside the consumer\n */\nexport default function loadAdapter(packageName: string, exportName: string | undefined, callback: LoadAdapterCallback): void {\n const cacheKey = `${packageName}:${exportName ?? 'default'}`;\n\n // Return cached adapter if available\n if (adapterCache.has(cacheKey)) {\n callback(null, adapterCache.get(cacheKey));\n return;\n }\n\n let Adapter: unknown;\n try {\n const mod = _require(packageName);\n Adapter = exportName ? mod[exportName] : (mod.default ?? mod);\n } catch {\n callback(new Error(`Adapter \"${packageName}\" is not installed. Install it alongside this package: npm install ${packageName}`));\n return;\n }\n\n adapterCache.set(cacheKey, Adapter);\n callback(null, Adapter);\n}\n\n/**\n * Clear the adapter cache (useful for testing)\n */\nexport function clearAdapterCache(): void {\n adapterCache.clear();\n}\n"],"names":["clearAdapterCache","loadAdapter","_require","require","Module","createRequire","adapterCache","Map","packageName","exportName","callback","cacheKey","has","get","Adapter","mod","default","Error","set","clear"],"mappings":";;;;;;;;;;;QAqCgBA;eAAAA;;QA5BhB;;CAEC,GACD;eAAwBC;;;iEAZL;;;;;;AAGnB,gDAAgD;AAChD,IAAMC,WAAW,OAAOC,YAAY,cAAcC,mBAAM,CAACC,aAAa,CAAC,uDAAmBF;AAE1F,wBAAwB;AACxB,IAAMG,eAAe,IAAIC;AAKV,SAASN,YAAYO,WAAmB,EAAEC,UAA8B,EAAEC,QAA6B;IACpH,IAAMC,WAAW,AAbnB,AAaoB,UAAEH,aAAY,KAA2B,OAAxBC,uBAAAA,wBAAAA,aAAc;IAEjD,qCAAqC;IACrC,IAAIH,aAAaM,GAAG,CAACD,WAAW;QAC9BD,SAAS,MAAMJ,aAAaO,GAAG,CAACF;QAChC;IACF;IAEA,IAAIG;IACJ,IAAI;YAEwCC;QAD1C,IAAMA,MAAMb,SAASM;QACrBM,UAAUL,aAAaM,GAAG,CAACN,WAAW,IAAIM,eAAAA,IAAIC,OAAO,cAAXD,0BAAAA,eAAeA;IAC3D,EAAE,eAAM;QACNL,SAAS,IAAIO,MAAM,AAAC,YAA4FT,OAAjFA,aAAY,uEAAiF,OAAZA;QAChH;IACF;IAEAF,aAAaY,GAAG,CAACP,UAAUG;IAC3BJ,SAAS,MAAMI;AACjB;AAKO,SAASd;IACdM,aAAaa,KAAK;AACpB"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/open-source/keyv/keyv-registry/src/loadAdapter.ts"],"sourcesContent":["import Module from 'node:module';\nimport type { LoadAdapterCallback } from './types.ts';\n\n// Create require function for ESM compatibility\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\n// Cache loaded adapters\nconst adapterCache = new Map<string, unknown>();\n\n// Module-not-found for the adapter itself; a missing dependency of the adapter names another module\nfunction isMissingModule(err: unknown, packageName: string): boolean {\n const e = err as { code?: string; message?: string };\n return (e?.code === 'MODULE_NOT_FOUND' || e?.code === 'ERR_MODULE_NOT_FOUND') && typeof e.message === 'string' && e.message.includes(`'${packageName}'`);\n}\n\n// Keep the original error as `cause` (the `ErrorOptions` argument is not in this project's lib target)\nfunction loadError(err: unknown, packageName: string): Error {\n const message = isMissingModule(err, packageName) ? `Adapter \"${packageName}\" is not installed. Install it alongside this package: npm install ${packageName}` : `Adapter \"${packageName}\" failed to load: ${(err as Error)?.message}`;\n const error = new Error(message);\n (error as Error & { cause?: unknown }).cause = err;\n return error;\n}\n\n/**\n * Load an adapter from the modules installed alongside the consumer\n */\nexport default function loadAdapter(packageName: string, exportName: string | undefined, callback: LoadAdapterCallback): void {\n const cacheKey = `${packageName}:${exportName ?? 'default'}`;\n\n // Return cached adapter if available\n if (adapterCache.has(cacheKey)) {\n callback(null, adapterCache.get(cacheKey));\n return;\n }\n\n let Adapter: unknown;\n try {\n const mod = _require(packageName);\n Adapter = exportName ? mod[exportName] : (mod.default ?? mod);\n } catch (err) {\n callback(loadError(err, packageName));\n return;\n }\n\n adapterCache.set(cacheKey, Adapter);\n callback(null, Adapter);\n}\n\n/**\n * Clear the adapter cache (useful for testing)\n */\nexport function clearAdapterCache(): void {\n adapterCache.clear();\n}\n"],"names":["clearAdapterCache","loadAdapter","_require","require","Module","createRequire","adapterCache","Map","isMissingModule","err","packageName","e","code","message","includes","loadError","error","Error","cause","exportName","callback","cacheKey","has","get","Adapter","mod","default","set","clear"],"mappings":";;;;;;;;;;;QAmDgBA;eAAAA;;QA5BhB;;CAEC,GACD;eAAwBC;;;iEA1BL;;;;;;AAGnB,gDAAgD;AAChD,IAAMC,WAAW,OAAOC,YAAY,cAAcC,mBAAM,CAACC,aAAa,CAAC,uDAAmBF;AAE1F,wBAAwB;AACxB,IAAMG,eAAe,IAAIC;AAEzB,oGAAoG;AACpG,SAASC,gBAAgBC,GAAY,EAAEC,WAAmB;IACxD,IAAMC,IAAIF;IACV,OAAO,AAACE,CAAAA,CAAAA,cAAAA,wBAAAA,EAAGC,IAAI,MAAK,sBAAsBD,CAAAA,cAAAA,wBAAAA,EAAGC,IAAI,MAAK,sBAAqB,KAAM,OAAOD,EAAEE,OAAO,KAAK,YAAYF,EAAEE,OAAO,CAACC,QAAQ,CAAC,AAAC,IAAe,OAAZJ,aAAY;AACvJ;AAEA,uGAAuG;AACvG,SAASK,UAAUN,GAAY,EAAEC,WAAmB;IAClD,IAAMG,UAAUL,gBAAgBC,KAAKC,eAAe,AAAC,YAA4FA,OAAjFA,aAAY,uEAAiF,OAAZA,eAAgB,AAjBnK,AAiBoK,mBAAWA,aAAY,sBAA4C,OAAvBD,gBAAAA,0BAAD,AAACA,IAAeI,OAAO;IACpO,IAAMG,QAAQ,IAAIC,MAAMJ;IACvBG,MAAsCE,KAAK,GAAGT;IAC/C,OAAOO;AACT;AAKe,SAASf,YAAYS,WAAmB,EAAES,UAA8B,EAAEC,QAA6B;IACpH,IAAMC,WAAW,AA3BnB,AA2BoB,UAAEX,aAAY,KAA2B,OAAxBS,uBAAAA,wBAAAA,aAAc;IAEjD,qCAAqC;IACrC,IAAIb,aAAagB,GAAG,CAACD,WAAW;QAC9BD,SAAS,MAAMd,aAAaiB,GAAG,CAACF;QAChC;IACF;IAEA,IAAIG;IACJ,IAAI;YAEwCC;QAD1C,IAAMA,MAAMvB,SAASQ;QACrBc,UAAUL,aAAaM,GAAG,CAACN,WAAW,IAAIM,eAAAA,IAAIC,OAAO,cAAXD,0BAAAA,eAAeA;IAC3D,EAAE,OAAOhB,KAAK;QACZW,SAASL,UAAUN,KAAKC;QACxB;IACF;IAEAJ,aAAaqB,GAAG,CAACN,UAAUG;IAC3BJ,SAAS,MAAMI;AACjB;AAKO,SAASxB;IACdM,aAAasB,KAAK;AACpB"}
@@ -0,0 +1,18 @@
1
+ import type { Keyv } from 'keyv';
2
+ /**
3
+ * One-time move of entries keyv 5 wrote under its default `keyv` namespace to the plain keys keyv 6 reads.
4
+ *
5
+ * Works through the Keyv API only, on the instance the caller passes, so it covers every adapter that can iterate.
6
+ * Finds both old layouts: `keyv:<key>` with no namespace (keyv-file) and namespace `keyv` (sqlite `<key>`, redis `keyv:<key>`).
7
+ * Keeps the absolute expiry, skips expired entries, lets an existing plain key win, and is safe to run again.
8
+ *
9
+ * Call it at startup, before the store serves other traffic: it renames keys and switches `store.namespace` while it runs.
10
+ * A plain key that itself starts with `keyv:` is taken for a keyv 5 key.
11
+ * A store that cannot iterate (for example memcache) has nothing to find: it returns 0.
12
+ *
13
+ * Store errors: keyv hides them from the caller once any `error` listener is attached, so a temporary listener watches every read and write.
14
+ * If one is emitted, the old key is not deleted and the call rejects with the error as `cause`; entries already moved stay moved and a rerun repairs the rest.
15
+ *
16
+ * @returns the number of entries moved
17
+ */
18
+ export default function migrateKeyv5Keys(store: Keyv): Promise<number>;
@@ -0,0 +1,18 @@
1
+ import type { Keyv } from 'keyv';
2
+ /**
3
+ * One-time move of entries keyv 5 wrote under its default `keyv` namespace to the plain keys keyv 6 reads.
4
+ *
5
+ * Works through the Keyv API only, on the instance the caller passes, so it covers every adapter that can iterate.
6
+ * Finds both old layouts: `keyv:<key>` with no namespace (keyv-file) and namespace `keyv` (sqlite `<key>`, redis `keyv:<key>`).
7
+ * Keeps the absolute expiry, skips expired entries, lets an existing plain key win, and is safe to run again.
8
+ *
9
+ * Call it at startup, before the store serves other traffic: it renames keys and switches `store.namespace` while it runs.
10
+ * A plain key that itself starts with `keyv:` is taken for a keyv 5 key.
11
+ * A store that cannot iterate (for example memcache) has nothing to find: it returns 0.
12
+ *
13
+ * Store errors: keyv hides them from the caller once any `error` listener is attached, so a temporary listener watches every read and write.
14
+ * If one is emitted, the old key is not deleted and the call rejects with the error as `cause`; entries already moved stay moved and a rerun repairs the rest.
15
+ *
16
+ * @returns the number of entries moved
17
+ */
18
+ export default function migrateKeyv5Keys(store: Keyv): Promise<number>;