@polywrap/uri-resolver-extensions-js
v0.12.2
Published
Polywrap URI resolver extensions
Downloads
140
Readme
@polywrap/uri-resolver-extensions-js
Installation
npm install --save @polywrap/uri-resolver-extensions-js
Usage
If you build a configuration for the Polywrap client using the PolywrapClientConfigBuilder
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: new UriMap<Uri[]>([
[
Uri.from("wrapscan.io/polywrap/[email protected]"),
[
Uri.from("wrapscan.io/polywrap/[email protected]"),
Uri.from("wrapscan.io/polywrap/[email protected]"),
Uri.from("wrapscan.io/polywrap/[email protected]"),
Uri.from("wrapscan.io/polywrap/[email protected]"),
],
],
]),
resolver: RecursiveResolver.from(
[
StaticResolver.from([
...redirects,
...wrappers,
...packages,
]),
new ExtendableUriResolver(),
]
)
};
Reference
ExtendableUriResolver
/**
* A Uri Resolver that delegates resolution to wrappers implementing the
* URI Resolver Extension Interface.
* */
export class ExtendableUriResolver extends UriResolverAggregatorBase<
Error,
Error
>
Properties
extInterfaceUri (static)
/** The supported interface URIs to which resolver-ext implementations should be registered */
public static defaultExtInterfaceUris: Uri[] = [
Uri.from("wrapscan.io/polywrap/[email protected]"),
];
extInterfaceUri
/** The active interface URIs to which implementations should be registered */
public readonly extInterfaceUris: Uri[];
constructor
/**
* Create an ExtendableUriResolver
*
* @param extInterfaceUris - URI Resolver Interface URIs
* @param resolverName - Name to use in resolution history output
* */
constructor(
extInterfaceUris: Uri[] = ExtendableUriResolver.defaultExtInterfaceUris,
resolverName = "ExtendableUriResolver"
)
Methods
getUriResolvers
/**
* Get a list of URI Resolvers
*
* @param uri - the URI to query for resolvers
* @param client - a CoreClient instance that can be used to make an invocation
* @param resolutionContext - the current URI resolution context
*
* @returns a list of IUriResolver or an error
* */
async getUriResolvers(
uri: Uri,
client: CoreClient,
resolutionContext: IUriResolutionContext
): Promise<Result<IUriResolver<unknown>[], Error>>
tryResolverUri
/**
* Resolve a URI to a wrap package, a wrapper, or a URI.
* Attempts resolution with each the URI Resolver Extension wrappers sequentially.
*
* @param uri - the URI to resolve
* @param client - a CoreClient instance that may be used to invoke a wrapper that implements the UriResolver interface
* @param resolutionContext - the current URI resolution context
* @returns A Promise with a Result containing either a wrap package, a wrapper, or a URI if successful
*/
async tryResolveUri(
uri: Uri,
client: CoreClient,
resolutionContext: IUriResolutionContext
): Promise<Result<UriPackageOrWrapper, Error>>
getStepDescription (protected)
/**
* A utility function for generating step descriptions to facilitate resolution context updates
*
* @returns text describing the URI resolution step
* */
protected getStepDescription = (): string
UriResolverExtensionFileReader
/** An IFileReader that reads files by invoking URI Resolver Extension wrappers */
export class UriResolverExtensionFileReader implements IFileReader
constructor
/**
* Construct a UriResolverExtensionFileReader
*
* @param _resolverExtensionUri - URI of the URI Resolver Extension wrapper
* @param _wrapperUri - URI of the wrap package to read from
* @param _client - A CoreClient instance
* */
constructor(
private readonly _resolverExtensionUri: Uri,
private readonly _wrapperUri: Uri,
private readonly _client: CoreClient
)
Methods
readFile
/**
* Read a file
*
* @param filePath - the file's path from the wrap package root
*
* @returns a Result containing a buffer if successful, or an error
* */
async readFile(filePath: string): Promise<Result<Uint8Array, Error>>
UriResolverWrapper
/**
* An IUriResolver that delegates resolution to a wrapper that implements
* the URI Resolver Extension Interface
* */
export class UriResolverWrapper implements IUriResolver<unknown>
constructor
/**
* construct a UriResolverWrapper
*
* @param implementationUri - URI that resolves to a URI Resolver Extension implementation
* */
constructor(public readonly implementationUri: Uri)
Methods
tryResolverUri
/**
* Attempt to resolve a URI by invoking a URI Resolver Extension wrapper, then
* parse the result to a wrap package, a wrapper, or a URI
*
* @param uri - the URI to resolve
* @param client - a CoreClient instance that may be used to invoke a wrapper that implements the UriResolver interface
* @param resolutionContext - the current URI resolution context
* @returns A Promise with a Result containing either a wrap package, a wrapper, or a URI if successful
*/
async tryResolveUri(
uri: Uri,
client: CoreClient,
resolutionContext: IUriResolutionContext
): Promise<Result<UriPackageOrWrapper, unknown>>
Development
This package is open-source. It lives within the Polywrap JavaScript Client repository. Contributions from the community are welcomed!
Build
nvm use && yarn install && yarn build
Test
yarn test