@universal-packages/adapter-resolver
Advanced tools
Comparing version 1.0.0 to 1.1.0
{ | ||
"name": "@universal-packages/adapter-resolver", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Module loader based on adapter parameters.", | ||
@@ -5,0 +5,0 @@ "author": "David De Anda <david@universal-packages.com> (https://github.com/universal-packages)", |
@@ -37,4 +37,15 @@ # Adapter Resolver | ||
To help infer the module name for example if the adapter is `redis` and is meant to work with `@universal-packages/token-registry` you can just provide here `token-registry`. | ||
- **`internal`** `Object` | ||
An object which keys match an internal adapter provided by the root library. | ||
```js | ||
import { resolveAdapter } from '@universal-packages/adapter-resolver' | ||
const adapter = await resolveAdapter('local', { internal: { local: LocalAdapter } }) | ||
console.log(adapter) | ||
// > [class LocalAdapter] | ||
``` | ||
- **`type`** `String` | ||
To help infer the export name, for example ff the adapter is an "engine", you can provide here `engine` and it will internally will come up with different case variations to try to find the export ex: redisEngine, RedisEngine, redis_engine. | ||
To help infer the export name, for example if the adapter is an "engine", you can provide here `engine` and it will internally will come up with different case variations to try to find the export ex: redisEngine, RedisEngine, redis_engine. | ||
@@ -41,0 +52,0 @@ ## Typescript |
import { ResolveAdapterOptions } from './types'; | ||
export declare function resolveAdapter<P = any>(name: string, options?: ResolveAdapterOptions): Promise<P>; | ||
export declare function resolveAdapter<A = any>(name: string, options?: ResolveAdapterOptions<A>): Promise<A>; |
@@ -30,2 +30,6 @@ "use strict"; | ||
async function resolveAdapter(name, options) { | ||
if (options?.internal) { | ||
if (options.internal[name]) | ||
return options.internal[name]; | ||
} | ||
const packageJson = (0, package_json_1.readPackageJson)(); | ||
@@ -32,0 +36,0 @@ const dependencyNames = Object.keys({ ...packageJson.dependencies, ...packageJson.devDependencies }); |
@@ -1,4 +0,5 @@ | ||
export interface ResolveAdapterOptions { | ||
export interface ResolveAdapterOptions<A = any> { | ||
domain?: string; | ||
internal?: Record<string, A>; | ||
type?: string; | ||
} |
Sorry, the diff of this file is not supported yet
11603
91
65