npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@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