@apidevtools/json-schema-ref-parser 15.0.1 → 15.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/lib/parse.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as url from "./util/url.js";
2
- import * as plugins from "./util/plugins.js";
2
+ import { filter, all, sort, run } from "./util/plugins.js";
3
3
  import { ResolverError, ParserError, UnmatchedParserError, UnmatchedResolverError, isHandledError, } from "./util/errors.js";
4
4
  /**
5
5
  * Reads and parses the specified file path or URL.
@@ -52,12 +52,12 @@ async function parse(path, $refs, options) {
52
52
  async function readFile(file, options, $refs) {
53
53
  // console.log('Reading %s', file.url);
54
54
  // Find the resolvers that can read this file
55
- let resolvers = plugins.all(options.resolve);
56
- resolvers = plugins.filter(resolvers, "canRead", file);
55
+ let resolvers = all(options.resolve);
56
+ resolvers = filter(resolvers, "canRead", file, undefined, $refs);
57
57
  // Run the resolvers, in order, until one of them succeeds
58
- plugins.sort(resolvers);
58
+ sort(resolvers);
59
59
  try {
60
- const data = await plugins.run(resolvers, "read", file, $refs);
60
+ const data = await run(resolvers, "read", file, $refs);
61
61
  return data;
62
62
  }
63
63
  catch (err) {
@@ -95,13 +95,13 @@ async function parseFile(file, options, $refs) {
95
95
  // Find the parsers that can read this file type.
96
96
  // If none of the parsers are an exact match for this file, then we'll try ALL of them.
97
97
  // This handles situations where the file IS a supported type, just with an unknown extension.
98
- const allParsers = plugins.all(options.parse);
99
- const filteredParsers = plugins.filter(allParsers, "canParse", file);
98
+ const allParsers = all(options.parse);
99
+ const filteredParsers = filter(allParsers, "canParse", file);
100
100
  const parsers = filteredParsers.length > 0 ? filteredParsers : allParsers;
101
101
  // Run the parsers, in order, until one of them succeeds
102
- plugins.sort(parsers);
102
+ sort(parsers);
103
103
  try {
104
- const parser = await plugins.run(parsers, "parse", file, $refs);
104
+ const parser = await run(parsers, "parse", file, $refs);
105
105
  if (!parser.plugin.allowEmpty && isEmpty(parser.result)) {
106
106
  throw new SyntaxError(`Error parsing "${file.url}" as ${parser.plugin.name}. \nParsed value is empty`);
107
107
  }
@@ -13,7 +13,7 @@ export declare function all<S extends object = JSONSchema, O extends ParserOptio
13
13
  /**
14
14
  * Filters the given plugins, returning only the ones return `true` for the given method.
15
15
  */
16
- export declare function filter(plugins: Plugin[], method: any, file: any): Plugin[];
16
+ export declare function filter<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(plugins: Plugin[], method: keyof Plugin | keyof ResolverOptions<S>, file: FileInfo, callback?: (err?: Error, result?: any) => void, $refs?: $Refs<S, O>): Plugin[];
17
17
  /**
18
18
  * Sorts the given plugins, in place, by their `order` property.
19
19
  */
@@ -17,9 +17,9 @@ export function all(plugins) {
17
17
  /**
18
18
  * Filters the given plugins, returning only the ones return `true` for the given method.
19
19
  */
20
- export function filter(plugins, method, file) {
20
+ export function filter(plugins, method, file, callback, $refs) {
21
21
  return plugins.filter((plugin) => {
22
- return !!getResult(plugin, method, file);
22
+ return !!getResult(plugin, method, file, callback, $refs);
23
23
  });
24
24
  }
25
25
  /**
package/lib/parse.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as url from "./util/url.js";
2
- import * as plugins from "./util/plugins.js";
2
+ import { filter, all, sort, run } from "./util/plugins.js";
3
3
  import {
4
4
  ResolverError,
5
5
  ParserError,
@@ -77,13 +77,13 @@ async function readFile<S extends object = JSONSchema, O extends ParserOptions<S
77
77
  // console.log('Reading %s', file.url);
78
78
 
79
79
  // Find the resolvers that can read this file
80
- let resolvers = plugins.all(options.resolve);
81
- resolvers = plugins.filter(resolvers, "canRead", file);
80
+ let resolvers = all(options.resolve);
81
+ resolvers = filter(resolvers, "canRead", file, undefined, $refs);
82
82
 
83
83
  // Run the resolvers, in order, until one of them succeeds
84
- plugins.sort(resolvers);
84
+ sort(resolvers);
85
85
  try {
86
- const data = await plugins.run(resolvers, "read", file, $refs);
86
+ const data = await run(resolvers, "read", file, $refs);
87
87
  return data;
88
88
  } catch (err: any) {
89
89
  if (!err && options.continueOnError) {
@@ -123,14 +123,14 @@ async function parseFile<S extends object = JSONSchema, O extends ParserOptions<
123
123
  // Find the parsers that can read this file type.
124
124
  // If none of the parsers are an exact match for this file, then we'll try ALL of them.
125
125
  // This handles situations where the file IS a supported type, just with an unknown extension.
126
- const allParsers = plugins.all(options.parse);
127
- const filteredParsers = plugins.filter(allParsers, "canParse", file);
126
+ const allParsers = all(options.parse);
127
+ const filteredParsers = filter(allParsers, "canParse", file);
128
128
  const parsers = filteredParsers.length > 0 ? filteredParsers : allParsers;
129
129
 
130
130
  // Run the parsers, in order, until one of them succeeds
131
- plugins.sort(parsers);
131
+ sort(parsers);
132
132
  try {
133
- const parser = await plugins.run<S, O>(parsers, "parse", file, $refs);
133
+ const parser = await run<S, O>(parsers, "parse", file, $refs);
134
134
  if (!parser.plugin.allowEmpty && isEmpty(parser.result)) {
135
135
  throw new SyntaxError(`Error parsing "${file.url}" as ${parser.plugin.name}. \nParsed value is empty`);
136
136
  } else {
@@ -26,9 +26,15 @@ export function all<S extends object = JSONSchema, O extends ParserOptions<S> =
26
26
  /**
27
27
  * Filters the given plugins, returning only the ones return `true` for the given method.
28
28
  */
29
- export function filter(plugins: Plugin[], method: any, file: any) {
29
+ export function filter<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
30
+ plugins: Plugin[],
31
+ method: keyof Plugin | keyof ResolverOptions<S>,
32
+ file: FileInfo,
33
+ callback?: (err?: Error, result?: any) => void,
34
+ $refs?: $Refs<S, O>,
35
+ ) {
30
36
  return plugins.filter((plugin: Plugin) => {
31
- return !!getResult(plugin, method, file);
37
+ return !!getResult(plugin, method, file, callback, $refs);
32
38
  });
33
39
  }
34
40
 
@@ -40,8 +46,8 @@ export function sort(plugins: Plugin[]) {
40
46
  plugin.order = plugin.order || Number.MAX_SAFE_INTEGER;
41
47
  }
42
48
 
43
- return plugins.sort((a: any, b: any) => {
44
- return a.order - b.order;
49
+ return plugins.sort((a: Plugin, b: Plugin) => {
50
+ return a.order! - b.order!;
45
51
  });
46
52
  }
47
53
 
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@apidevtools/json-schema-ref-parser",
3
- "version": "15.0.1",
3
+ "version": "15.1.1",
4
4
  "description": "Parse, Resolve, and Dereference JSON Schema $ref pointers",
5
5
  "type": "module",
6
6
  "types": "dist/lib/index.d.ts",
7
7
  "module": "dist/lib/index.js",
8
+ "main": "dist/lib/index.js",
8
9
  "scripts": {
9
10
  "prepublishOnly": "yarn build",
10
11
  "lint": "eslint lib",