# @polywrap/uri-resolver-extensions-js

> Polywrap URI resolver extensions

Latest version **0.12.2** (published 2023-08-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install @polywrap/uri-resolver-extensions-js
pnpm add @polywrap/uri-resolver-extensions-js
yarn add @polywrap/uri-resolver-extensions-js
bun add @polywrap/uri-resolver-extensions-js
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.12.2 |
| Published | 2023-08-21 |
| First published | 2022-09-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 110.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Maintainers | polywrap-build-bot, dorgjelli |

## Links

- npm: https://www.npmjs.com/package/@polywrap/uri-resolver-extensions-js
- Repository: https://github.com/polywrap/javascript-client
- npm.io page: https://npm.io/package/@polywrap/uri-resolver-extensions-js

## Dependencies (5)

- [@polywrap/result](https://npm.io/package/@polywrap/result.md) 0.12.2
- [@polywrap/core-js](https://npm.io/package/@polywrap/core-js.md) 0.12.2
- [@polywrap/wasm-js](https://npm.io/package/@polywrap/wasm-js.md) 0.12.2
- [@polywrap/uri-resolvers-js](https://npm.io/package/@polywrap/uri-resolvers-js.md) 0.12.2
- [@polywrap/wrap-manifest-types-js](https://npm.io/package/@polywrap/wrap-manifest-types-js.md) 0.12.2

## Recent versions

- 0.12.2 (latest) — 2023-08-21
- 0.12.0-pre.1 (pre) — 2023-07-12
- 0.12.1 — 2023-08-20
- 0.12.0 — 2023-07-26
- 0.11.0 — 2023-06-27
- 0.10.1 — 2023-04-29
- 0.10.0 — 2023-04-14
- 0.10.0-pre.14 — 2023-04-13
- 0.9.7 — 2023-03-28
- 0.10.0-pre.13 — 2023-03-18
- 0.10.0-pre.12 — 2023-03-14
- 0.10.0-pre.11 — 2023-03-06
- 0.10.0-pre.10 — 2023-03-01
- 0.9.6 — 2023-02-19
- 0.10.0-pre.8 — 2023-02-16
- … 14 more at https://npm.io/package/@polywrap/uri-resolver-extensions-js/versions

## README

# @polywrap/uri-resolver-extensions-js

<a href="https://www.npmjs.com/package/@polywrap/uri-resolver-extensions-js" target="_blank" rel="noopener noreferrer">
<img src="https://img.shields.io/npm/v/@polywrap/uri-resolver-extensions-js.svg" alt="npm"/>
</a>

<br/>
<br/>
Polywrap URI resolver extensions to customize resolution in the Polywrap Client.

## Installation

```bash
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.

```ts
  const clientConfig: CoreClientConfig = {
    interfaces: new UriMap<Uri[]>([
      [
        Uri.from("wrapscan.io/polywrap/uri-resolver@1.0"),
        [
          Uri.from("wrapscan.io/polywrap/file-system-uri-resolver@1.0.0"),
          Uri.from("wrapscan.io/polywrap/http-uri-resolver@1.0.0"),
          Uri.from("wrapscan.io/polywrap/ipfs-uri-resolver-async@1.0.0"),
          Uri.from("wrapscan.io/polywrap/wrapscan-uri-resolver@1.0.0"),
        ],
      ],
    ]),
    resolver: RecursiveResolver.from(
      [
        StaticResolver.from([
          ...redirects,
          ...wrappers,
          ...packages,
        ]),
        new ExtendableUriResolver(),
      ]
    )
  };
```

# Reference

## ExtendableUriResolver

```ts
/**
 * A Uri Resolver that delegates resolution to wrappers implementing the
 * URI Resolver Extension Interface.
 * */
export class ExtendableUriResolver extends UriResolverAggregatorBase<
  Error,
  Error
> 
```

### Properties

#### extInterfaceUri (static)

```ts
  /** The supported interface URIs to which resolver-ext implementations should be registered */
  public static defaultExtInterfaceUris: Uri[] = [
    Uri.from("wrapscan.io/polywrap/uri-resolver@1.0"),
  ];
```

#### extInterfaceUri

```ts
  /** The active interface URIs to which implementations should be registered */
  public readonly extInterfaceUris: Uri[];
```

### constructor

```ts
  /**
   * 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

```ts
  /**
   * 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

```ts
  /**
   * 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)

```ts
  /**
   * A utility function for generating step descriptions to facilitate resolution context updates
   *
   * @returns text describing the URI resolution step
   * */
  protected getStepDescription = (): string 
```

## UriResolverExtensionFileReader

```ts
/** An IFileReader that reads files by invoking URI Resolver Extension wrappers */
export class UriResolverExtensionFileReader implements IFileReader 
```

### constructor

```ts
  /**
   * 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

```ts
  /**
   * 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

```ts
/**
 * An IUriResolver that delegates resolution to a wrapper that implements
 * the URI Resolver Extension Interface
 * */
export class UriResolverWrapper implements IUriResolver<unknown> 
```

### constructor

```ts
  /**
   * construct a UriResolverWrapper
   *
   * @param implementationUri - URI that resolves to a URI Resolver Extension implementation
   * */
  constructor(public readonly implementationUri: Uri) 
```

### Methods

#### tryResolverUri

```ts
  /**
   * 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](https://github.com/polywrap/javascript-client). Contributions from the community are welcomed!

### Build

```bash
nvm use && yarn install && yarn build
```

### Test

```bash
yarn test
```

---
_Source: https://npm.io/package/@polywrap/uri-resolver-extensions-js · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
