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

@ovotech/json-refs

v0.3.2

Published

Json Refs Resolver

Downloads

33

Readme

JSON Refs

Recursively downloads files referenced in a json-schema, and resolves all the references and provide a map to the referenced contents while its at it.

Usage

yarn add @ovotech/json-refs
import { resolveRefs } from '@ovotech/json-refs';

// Where the contents of https://example.com/assets/test.yml are
// UserResponse:
//   - type: 'object'

const schema = {
  test: { $ref: 'https://example.com/assets/test.yml#/UserResponse' },
};

const resolved = await resolveRefs(schema);

console.log(resolved);

Should output

{ schema:
   { test:
      { '$ref': 'https://example.com/assets/test.yaml#/UserResponse' } },
  refs:
   { 'https://example.com/assets/test.yaml': { UserResponse: { type: 'object' } },
     'https://example.com/assets/test.yaml#/UserResponse': { type: 'object' } },
  uris: [ 'https://example.com/assets/test.yaml' ] }

The resolved refs include all files with their parsed contents (yaml or json), as well as flat list of links to the individual refs. There is also a list of all the files downloaded or local file referenced in uris.

Behavior

First of all it would parse the schema, searching for $refs if the refs are in the file itself then it would just return those. If there are any external links, it would collect all the URLs present, and would download all of them in parallel. If there are any external links in the downloaded files, it would attempt another batch, until all resources are resolved.

Since it would fill in its internal reference library on each pass, circular references are allowed and would only be resolved once.

Api

resolveRefs

function async resolveRefs(schema: JsonPointerObject) => Promise<{
  schema: JsonPointerObject,
  refs: { [key: string]: JsonPointerObject,
  uris: string[]
}>

resolveRefsFile The same as resolveRefs, but start with downloading and or parsing the initial schema. Can take any url or path to a local file.

function async resolveRefsFile(file: string) => Promise<{
  schema: JsonPointerObject,
  refs: { [key: string]: JsonPointerObject,
  uris: string[]
}>

Running the tests

You can run the tests with:

yarn test

Coding style (linting, etc) tests

Style is maintained with prettier and eslint

yarn lint

Deployment

Deployment is preferment by lerna automatically on merge / push to master, but you'll need to bump the package version numbers yourself. Only updated packages with newer versions will be pushed to the npm registry.

Contributing

Have a bug? File an issue with a simple example that reproduces this so we can take a look & confirm.

Want to make a change? Submit a PR, explain why it's useful, and make sure you've updated the docs (this file) and the tests (see test folder).

License

This project is licensed under Apache 2 - see the LICENSE file for details