0.0.44-0.0.44-alpha.2.0 • Published 6 years ago

@stoplight/resolver v0.0.44-0.0.44-alpha.2.0

Weekly downloads
21
License
MIT
Repository
github
Last release
6 years ago

Stoplight Resolver

The Stoplight resolver recursively resolves JSON pointers and remote authorities.

Features

  • Performant. Hot paths are memoized, only one crawl is needed, and remote authorities are resolved concurrently.
  • Caching. Results from remote authorities are cached.
  • Immutable. The original object is not changed, and structural sharing is used to only change relevant bits.
  • Reference equality. Pointers to the same location will resolve to the same object in memory.
  • Flexible. Bring your own readers for http://, file://, mongo://, custom://... etc.
  • Reliable. Well tested to handle all sorts of circular reference scenarios.

Usage

All relevant types and options can be found in src/types.ts.

// some example http library
const request = require('request');

// fs in node.. in general this library works just fine in the browser though
const fs = require('fs');

// readers can do anything, so long as they have a read function that returns a promise that resolves to a value
const httpReader = {
  async read(ref) {
    return request(ref.toString());
  },
};

// this would obviously only be possible in node
const fileReader {
  async read(ref) {
    return fs.read(ref.toString(true));
  },
};

const source = {
  definitions: {
    someOASFile: {
      $ref: './main.oas2.yml#/definitions/user',
    },
    someMarkdownFile: {
      $ref: 'https://foo.com/intro.md',
    },
  },
};

// set our resolver, passing in our scheme -> reader mapping
const resolver = new Resolver({
  readers: {
    http: httpReader,
    https: httpReader,
    file: fileReader,
  },
});

const resolved = await resolver.resolve(source);

console.log(resolved.result);
// {
//   definitions: {
//     someOASFile: // .. whatever data is in the file located in the location definitions.foo in file './main.oas2.yml#/definitions/user'
//     someMarkdownFile: // .. whatever data is returned from https://foo.com/intro.md
//   },
// }
0.0.44-alpha.1

6 years ago

0.0.44-alpha.0

6 years ago

0.0.43

6 years ago

0.0.42

6 years ago

0.0.41

6 years ago

0.0.40

6 years ago

0.0.39

6 years ago

0.0.38

6 years ago

0.0.38-alpha.1

6 years ago

0.0.37-beta.1

6 years ago

0.0.37-beta.0

6 years ago

0.0.36

6 years ago

0.0.35

6 years ago

0.0.34

6 years ago

0.0.33

6 years ago

0.0.32

6 years ago

0.0.32-beta.2

6 years ago

0.0.32-beta.1

6 years ago

0.0.32-beta.0

6 years ago

0.0.31

6 years ago

0.0.30

6 years ago

0.0.30-0

6 years ago

0.0.29

6 years ago

0.0.29-beta.0

6 years ago

0.0.28

6 years ago

0.0.28-beta.1

6 years ago

0.0.28-beta.0

6 years ago

0.0.27

6 years ago

0.0.26

6 years ago

0.0.25

6 years ago

0.0.24

6 years ago

0.0.23

6 years ago

0.0.22

6 years ago

0.0.21

6 years ago

0.0.20

6 years ago

0.0.19

6 years ago

0.0.18

6 years ago

0.0.17

6 years ago

0.0.16

6 years ago

0.0.15

6 years ago

0.0.12

6 years ago

0.0.11-30

6 years ago

0.0.11-29

6 years ago

0.0.11-28

6 years ago

0.0.11-27

6 years ago

0.0.11-26

6 years ago

0.0.11-25

6 years ago

0.0.11-24

6 years ago

0.0.11-23

6 years ago

0.0.11-22

6 years ago

0.0.11-21

6 years ago

0.0.11-20

6 years ago

0.0.11-19

6 years ago

0.0.11-18

6 years ago

0.0.11-17

6 years ago

0.0.11-16

6 years ago

0.0.11-15

6 years ago

0.0.11-14

6 years ago

0.0.11-13

6 years ago

0.0.11-12

6 years ago

0.0.11-10

6 years ago

0.0.11-8

6 years ago

0.0.11-7

6 years ago

0.0.11-4

6 years ago

0.0.11-3

6 years ago