keyv-registry 1.0.3 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -3
- package/dist/cjs/loadAdapter.d.cts +1 -1
- package/dist/cjs/loadAdapter.d.ts +1 -1
- package/dist/cjs/loadAdapter.js +7 -25
- package/dist/cjs/loadAdapter.js.map +1 -1
- package/dist/esm/loadAdapter.d.ts +1 -1
- package/dist/esm/loadAdapter.js +7 -25
- package/dist/esm/loadAdapter.js.map +1 -1
- package/package.json +13 -3
package/README.md
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
# keyv-registry
|
|
2
2
|
|
|
3
|
-
Protocol-based Keyv adapter registry
|
|
3
|
+
Protocol-based Keyv adapter registry.
|
|
4
4
|
|
|
5
|
-
Create Keyv stores from URI strings
|
|
5
|
+
Create Keyv stores from URI strings, resolving each adapter from the modules installed alongside your application.
|
|
6
6
|
|
|
7
7
|
## Features
|
|
8
8
|
|
|
9
9
|
- **URI-based configuration**: Use familiar connection strings like `redis://localhost:6379`
|
|
10
|
-
- **
|
|
10
|
+
- **No bundled adapters**: install only the adapter you use; keyv-registry itself depends on nothing but keyv
|
|
11
11
|
- **Extensible registry**: Register custom protocols or override defaults
|
|
12
12
|
- **Dual-boot API**: Supports both Promise and callback patterns
|
|
13
13
|
- **URI parameter mapping**: Query params automatically converted to adapter options
|
|
@@ -19,6 +19,17 @@ Create Keyv stores from URI strings with automatic adapter resolution and on-dem
|
|
|
19
19
|
npm install keyv-registry
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
+
Adapters are not bundled. Install the one your protocol needs alongside it:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npm install @keyv/redis # redis://, rediss://
|
|
26
|
+
npm install keyv-file # file://
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
`memory://` is built in and needs no package.
|
|
30
|
+
|
|
31
|
+
Adapters are resolved with `require()`, so an adapter only has to be installed somewhere Node resolves from your application: your project's `node_modules`, or globally beside a globally installed CLI. A protocol whose adapter is missing fails with the name of the package to install.
|
|
32
|
+
|
|
22
33
|
## Usage
|
|
23
34
|
|
|
24
35
|
### Promise API
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { LoadAdapterCallback } from './types.js';
|
|
2
2
|
/**
|
|
3
|
-
* Load an adapter
|
|
3
|
+
* Load an adapter from the modules installed alongside the consumer
|
|
4
4
|
*/
|
|
5
5
|
export default function loadAdapter(packageName: string, exportName: string | undefined, callback: LoadAdapterCallback): void;
|
|
6
6
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { LoadAdapterCallback } from './types.js';
|
|
2
2
|
/**
|
|
3
|
-
* Load an adapter
|
|
3
|
+
* Load an adapter from the modules installed alongside the consumer
|
|
4
4
|
*/
|
|
5
5
|
export default function loadAdapter(packageName: string, exportName: string | undefined, callback: LoadAdapterCallback): void;
|
|
6
6
|
/**
|
package/dist/cjs/loadAdapter.js
CHANGED
|
@@ -13,15 +13,12 @@ _export(exports, {
|
|
|
13
13
|
return clearAdapterCache;
|
|
14
14
|
},
|
|
15
15
|
get /**
|
|
16
|
-
* Load an adapter
|
|
16
|
+
* Load an adapter from the modules installed alongside the consumer
|
|
17
17
|
*/ default () {
|
|
18
18
|
return loadAdapter;
|
|
19
19
|
}
|
|
20
20
|
});
|
|
21
21
|
var _nodemodule = /*#__PURE__*/ _interop_require_default(require("node:module"));
|
|
22
|
-
var _nodepath = /*#__PURE__*/ _interop_require_default(require("node:path"));
|
|
23
|
-
var _nodeurl = /*#__PURE__*/ _interop_require_default(require("node:url"));
|
|
24
|
-
var _installmodulelinked = /*#__PURE__*/ _interop_require_default(require("install-module-linked"));
|
|
25
22
|
function _interop_require_default(obj) {
|
|
26
23
|
return obj && obj.__esModule ? obj : {
|
|
27
24
|
default: obj
|
|
@@ -29,9 +26,6 @@ function _interop_require_default(obj) {
|
|
|
29
26
|
}
|
|
30
27
|
// Create require function for ESM compatibility
|
|
31
28
|
var _require = typeof require === 'undefined' ? _nodemodule.default.createRequire(require("url").pathToFileURL(__filename).toString()) : require;
|
|
32
|
-
// Determine node_modules path
|
|
33
|
-
var _dirname = _nodepath.default.dirname(typeof __filename === 'undefined' ? _nodeurl.default.fileURLToPath(require("url").pathToFileURL(__filename).toString()) : __filename);
|
|
34
|
-
var nodeModulesPath = _nodepath.default.join(_dirname, '..', '..', 'node_modules');
|
|
35
29
|
// Cache loaded adapters
|
|
36
30
|
var adapterCache = new Map();
|
|
37
31
|
function loadAdapter(packageName, exportName, callback) {
|
|
@@ -41,29 +35,17 @@ function loadAdapter(packageName, exportName, callback) {
|
|
|
41
35
|
callback(null, adapterCache.get(cacheKey));
|
|
42
36
|
return;
|
|
43
37
|
}
|
|
44
|
-
|
|
38
|
+
var Adapter;
|
|
45
39
|
try {
|
|
46
40
|
var _mod_default;
|
|
47
41
|
var mod = _require(packageName);
|
|
48
|
-
|
|
49
|
-
adapterCache.set(cacheKey, Adapter);
|
|
50
|
-
callback(null, Adapter);
|
|
51
|
-
return;
|
|
42
|
+
Adapter = exportName ? mod[exportName] : (_mod_default = mod.default) !== null && _mod_default !== void 0 ? _mod_default : mod;
|
|
52
43
|
} catch (unused) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
if (err) return callback(err);
|
|
56
|
-
try {
|
|
57
|
-
var _mod_default;
|
|
58
|
-
var mod = _require(packageName);
|
|
59
|
-
var Adapter = exportName ? mod[exportName] : (_mod_default = mod.default) !== null && _mod_default !== void 0 ? _mod_default : mod;
|
|
60
|
-
adapterCache.set(cacheKey, Adapter);
|
|
61
|
-
callback(null, Adapter);
|
|
62
|
-
} catch (loadErr) {
|
|
63
|
-
callback(loadErr);
|
|
64
|
-
}
|
|
65
|
-
});
|
|
44
|
+
callback(new Error('Adapter "'.concat(packageName, '" is not installed. Install it alongside this package: npm install ').concat(packageName)));
|
|
45
|
+
return;
|
|
66
46
|
}
|
|
47
|
+
adapterCache.set(cacheKey, Adapter);
|
|
48
|
+
callback(null, Adapter);
|
|
67
49
|
}
|
|
68
50
|
function clearAdapterCache() {
|
|
69
51
|
adapterCache.clear();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/keyv/keyv-registry/src/loadAdapter.ts"],"sourcesContent":["import Module from 'node:module';\nimport
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/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,6 +1,6 @@
|
|
|
1
1
|
import type { LoadAdapterCallback } from './types.js';
|
|
2
2
|
/**
|
|
3
|
-
* Load an adapter
|
|
3
|
+
* Load an adapter from the modules installed alongside the consumer
|
|
4
4
|
*/
|
|
5
5
|
export default function loadAdapter(packageName: string, exportName: string | undefined, callback: LoadAdapterCallback): void;
|
|
6
6
|
/**
|
package/dist/esm/loadAdapter.js
CHANGED
|
@@ -1,16 +1,10 @@
|
|
|
1
1
|
import Module from 'node:module';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import url from 'node:url';
|
|
4
|
-
import installModule from 'install-module-linked';
|
|
5
2
|
// Create require function for ESM compatibility
|
|
6
3
|
const _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;
|
|
7
|
-
// Determine node_modules path
|
|
8
|
-
const _dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);
|
|
9
|
-
const nodeModulesPath = path.join(_dirname, '..', '..', 'node_modules');
|
|
10
4
|
// Cache loaded adapters
|
|
11
5
|
const adapterCache = new Map();
|
|
12
6
|
/**
|
|
13
|
-
* Load an adapter
|
|
7
|
+
* Load an adapter from the modules installed alongside the consumer
|
|
14
8
|
*/ export default function loadAdapter(packageName, exportName, callback) {
|
|
15
9
|
const cacheKey = `${packageName}:${exportName !== null && exportName !== void 0 ? exportName : 'default'}`;
|
|
16
10
|
// Return cached adapter if available
|
|
@@ -18,29 +12,17 @@ const adapterCache = new Map();
|
|
|
18
12
|
callback(null, adapterCache.get(cacheKey));
|
|
19
13
|
return;
|
|
20
14
|
}
|
|
21
|
-
|
|
15
|
+
let Adapter;
|
|
22
16
|
try {
|
|
23
17
|
var _mod_default;
|
|
24
18
|
const mod = _require(packageName);
|
|
25
|
-
|
|
26
|
-
adapterCache.set(cacheKey, Adapter);
|
|
27
|
-
callback(null, Adapter);
|
|
28
|
-
return;
|
|
19
|
+
Adapter = exportName ? mod[exportName] : (_mod_default = mod.default) !== null && _mod_default !== void 0 ? _mod_default : mod;
|
|
29
20
|
} catch {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if (err) return callback(err);
|
|
33
|
-
try {
|
|
34
|
-
var _mod_default;
|
|
35
|
-
const mod = _require(packageName);
|
|
36
|
-
const Adapter = exportName ? mod[exportName] : (_mod_default = mod.default) !== null && _mod_default !== void 0 ? _mod_default : mod;
|
|
37
|
-
adapterCache.set(cacheKey, Adapter);
|
|
38
|
-
callback(null, Adapter);
|
|
39
|
-
} catch (loadErr) {
|
|
40
|
-
callback(loadErr);
|
|
41
|
-
}
|
|
42
|
-
});
|
|
21
|
+
callback(new Error(`Adapter "${packageName}" is not installed. Install it alongside this package: npm install ${packageName}`));
|
|
22
|
+
return;
|
|
43
23
|
}
|
|
24
|
+
adapterCache.set(cacheKey, Adapter);
|
|
25
|
+
callback(null, Adapter);
|
|
44
26
|
}
|
|
45
27
|
/**
|
|
46
28
|
* Clear the adapter cache (useful for testing)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/keyv/keyv-registry/src/loadAdapter.ts"],"sourcesContent":["import Module from 'node:module';\nimport
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/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":["Module","_require","require","createRequire","url","adapterCache","Map","loadAdapter","packageName","exportName","callback","cacheKey","has","get","Adapter","mod","default","Error","set","clearAdapterCache","clear"],"mappings":"AAAA,OAAOA,YAAY,cAAc;AAGjC,gDAAgD;AAChD,MAAMC,WAAW,OAAOC,YAAY,cAAcF,OAAOG,aAAa,CAAC,YAAYC,GAAG,IAAIF;AAE1F,wBAAwB;AACxB,MAAMG,eAAe,IAAIC;AAEzB;;CAEC,GACD,eAAe,SAASC,YAAYC,WAAmB,EAAEC,UAA8B,EAAEC,QAA6B;IACpH,MAAMC,WAAW,GAAGH,YAAY,CAAC,EAAEC,uBAAAA,wBAAAA,aAAc,WAAW;IAE5D,qCAAqC;IACrC,IAAIJ,aAAaO,GAAG,CAACD,WAAW;QAC9BD,SAAS,MAAML,aAAaQ,GAAG,CAACF;QAChC;IACF;IAEA,IAAIG;IACJ,IAAI;YAEwCC;QAD1C,MAAMA,MAAMd,SAASO;QACrBM,UAAUL,aAAaM,GAAG,CAACN,WAAW,IAAIM,eAAAA,IAAIC,OAAO,cAAXD,0BAAAA,eAAeA;IAC3D,EAAE,OAAM;QACNL,SAAS,IAAIO,MAAM,CAAC,SAAS,EAAET,YAAY,mEAAmE,EAAEA,aAAa;QAC7H;IACF;IAEAH,aAAaa,GAAG,CAACP,UAAUG;IAC3BJ,SAAS,MAAMI;AACjB;AAEA;;CAEC,GACD,OAAO,SAASK;IACdd,aAAae,KAAK;AACpB"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "keyv-registry",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "Protocol-based Keyv adapter registry
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "Protocol-based Keyv adapter registry",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"keyv",
|
|
7
7
|
"registry",
|
|
@@ -44,17 +44,27 @@
|
|
|
44
44
|
"version": "tsds version"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"install-module-linked": "^1.0.0",
|
|
48
47
|
"keyv": "^5.0.0"
|
|
49
48
|
},
|
|
50
49
|
"devDependencies": {
|
|
50
|
+
"@keyv/etcd": "*",
|
|
51
|
+
"@keyv/redis": "*",
|
|
52
|
+
"@keyv/sqlite": "*",
|
|
51
53
|
"@types/mocha": "*",
|
|
52
54
|
"@types/node": "*",
|
|
55
|
+
"fs-remove-compat": "^1.0.4",
|
|
56
|
+
"keyv-file": "*",
|
|
53
57
|
"node-version-use": "*",
|
|
54
58
|
"ts-dev-stack": "*",
|
|
55
59
|
"tsds-config": "*"
|
|
56
60
|
},
|
|
57
61
|
"engines": {
|
|
58
62
|
"node": ">=16"
|
|
63
|
+
},
|
|
64
|
+
"allowScripts": {
|
|
65
|
+
"node-filename-to-dist-paths": true,
|
|
66
|
+
"node-semvers": true,
|
|
67
|
+
"node-version-use": true,
|
|
68
|
+
"thread-sleep-compat": true
|
|
59
69
|
}
|
|
60
70
|
}
|