@polywrap/uri-resolver-extensions-js
Polywrap URI resolver extensions to customize resolution in the Polywrap Client.
Installation
npm install --save @polywrap/uri-resolver-extensions-js
Usage
If you build a configuration for the Polywrap client using the ClientConfigBuilder
in the @polywrap/client-config-builder-js
package, the ExtendableUriResovler
is included by default. In that case you only need to register implementations of the URI Resolver Extension interface.
Otherwise, you must also add the ExtendableUriResolver
to your resolver.
const clientConfig: CoreClientConfig = {
interfaces: [
{
interface: Uri.from("wrap://ens/uri-resolver.core.polywrap.eth"),
implementations: [
Uri.from("wrap://ens/fs-resolver.polywrap.eth"),
Uri.from("wrap://ens/ipfs-resolver.polywrap.eth"),
Uri.from("wrap://ens/ens-resolver.polywrap.eth")
]
}
],
resolver: RecursiveResolver.from(
PackageToWrapperCacheResolver.from(
[
StaticResolver.from([
...redirects,
...wrappers,
...packages,
]),
new ExtendableUriResolver(),
],
new WrapperCache()
)
)
};
Reference
ExtendableUriResolver
export class ExtendableUriResolver extends UriResolverAggregatorBase<
Error,
Error
>
Properties
extInterfaceUri (static)
public static defaultExtInterfaceUris: Uri[] = [
Uri.from("wrap://ens/wraps.eth:uri-resolver-ext@1.1.0"),
Uri.from("wrap://ens/wraps.eth:uri-resolver-ext@1.0.0"),
];
extInterfaceUri
public readonly extInterfaceUris: Uri[];
constructor
constructor(
extInterfaceUris: Uri[] = ExtendableUriResolver.defaultExtInterfaceUris,
resolverName = "ExtendableUriResolver"
)
Methods
getUriResolvers
async getUriResolvers(
uri: Uri,
client: CoreClient,
resolutionContext: IUriResolutionContext
): Promise<Result<IUriResolver<unknown>[], Error>>
tryResolverUri
async tryResolveUri(
uri: Uri,
client: CoreClient,
resolutionContext: IUriResolutionContext
): Promise<Result<UriPackageOrWrapper, Error>>
getStepDescription (protected)
protected getStepDescription = (): string
UriResolverExtensionFileReader
export class UriResolverExtensionFileReader implements IFileReader
constructor
constructor(
private readonly _resolverExtensionUri: Uri,
private readonly _wrapperUri: Uri,
private readonly _client: CoreClient
)
Methods
readFile
async readFile(filePath: string): Promise<Result<Uint8Array, Error>>
UriResolverWrapper
export class UriResolverWrapper extends ResolverWithHistory<unknown>
constructor
constructor(public readonly implementationUri: Uri)
Methods
getStepDescription
protected getStepDescription = (): string
tryResolveUriWithImplementation
const tryResolveUriWithImplementation = async (
uri: Uri,
implementationUri: Uri,
client: CoreClient,
resolutionContext: IUriResolutionContext
): Promise<
Result<UriResolverInterface.MaybeUriOrManifest | undefined, unknown>
>
_tryResolverUri (protected)
protected async _tryResolveUri(
uri: Uri,
client: CoreClient,
resolutionContext: IUriResolutionContext
): Promise<Result<UriPackageOrWrapper, unknown>>
Development
This package is open-source. It lives within the Polywrap toolchain monorepo. Contributions from the community are welcomed!
Build
nvm use && yarn install && yarn build
Test
yarn test
``