
Product
Introducing Tier 1 Reachability: Precision CVE Triage for Enterprise Teams
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
@universal-packages/adapter-resolver
Advanced tools
Module loader based on adapter parameters.
npm install @universal-packages/adapter-resolver
class
Just instantiate the class and start resolving adapters.
import { AdapterResolver } from '@universal-packages/adapter-resolver'
const resolver = new AdapterResolver({ domain: 'token-registry', type: 'engine' })
const adapter = await resolver.resolve('redis')
console.log(adapter)
// > [class RedisEngine]
constructor
new AdapterResolver(options: AdapterResolverOptions)
Creates a new AdapterResolver instance.
Adapters need to follow the convention in order to be found. domain and name are use to infer the package name and type is used to infer the export name.
domain
String
The domain for which the adapter will work for example if the adapter is redis
and is meant to work with @universal-packages/token-registry
you provide here token-registry
.
type
String
The package needs to export something in the format <name><type>
, for example if the adapter is an "engine", you provide here engine
and it will internally will come up with different case variations of the format to find the export ex: redisEngine, RedisEngine, redis_engine.
internal
Object
optional
An object which keys match an internal adapter provided by the root library.
import { AdapterResolver } from '@universal-packages/adapter-resolver'
const resolver = new AdapterResolver({
domain: 'token-registry',
type: 'engine',
internal: { local: LocalAdapter }
})
const adapter = await resolver.resolve('local')
console.log(adapter)
// > [class LocalAdapter]
resolver.resolve(name: string): Promise<A>
Tries to infer an installed module name based on the provided name and resolver options, imports it and infers the desired export based on name and options.
import { AdapterResolver } from '@universal-packages/adapter-resolver'
const resolver = new AdapterResolver({ domain: 'token-registry', type: 'engine' })
const adapter = await resolver.resolve('redis')
console.log(adapter)
// > [class RedisEngine]
resolver.gather(): Promise<GatheredAdapters<A>>
Gather all the adapters of the configured type under the same domain.
import { AdapterResolver } from '@universal-packages/adapter-resolver'
const resolver = new AdapterResolver({ domain: 'token-registry', type: 'engine' })
const adapters = await resolver.gather()
console.log(adapters)
// > { redis: [class RedisEngine], local: [class LocalEngine] }
When using the internal
option, internal adapters will be mixed with the gathered adapters:
import { AdapterResolver } from '@universal-packages/adapter-resolver'
const resolver = new AdapterResolver({
domain: 'token-registry',
type: 'engine',
internal: { local: InternalAdapter }
})
const adapters = await resolver.gather()
console.log(adapters)
// > { local: [class InternalAdapter], redis: [class RedisEngine] }
This library is developed in TypeScript and shipped fully typed.
The development of this library happens in the open on GitHub, and we are grateful to the community for contributing bugfixes and improvements. Read below to learn how you can take part in improving this library.
FAQs
Module loader based on adapter parameters.
The npm package @universal-packages/adapter-resolver receives a total of 346 weekly downloads. As such, @universal-packages/adapter-resolver popularity was classified as not popular.
We found that @universal-packages/adapter-resolver demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
Research
/Security News
Ongoing npm supply chain attack spreads to DuckDB: multiple packages compromised with the same wallet-drainer malware.
Security News
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.