@apidevtools/json-schema-ref-parser 11.5.2 → 11.5.3

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.
@@ -1,5 +1,5 @@
1
1
  import type { FileInfo, JSONSchema } from "../types/index.js";
2
- import type $RefParserOptions from "../options.js";
2
+ import type { ParserOptions } from "../options.js";
3
3
  import type { ResolverOptions } from "../types/index.js";
4
4
  import type $Refs from "../refs.js";
5
5
  import type { Plugin } from "../types/index.js";
@@ -10,14 +10,16 @@ import type { Plugin } from "../types/index.js";
10
10
  *
11
11
  * @returns
12
12
  */
13
- export function all<S extends JSONSchema = JSONSchema>(plugins: $RefParserOptions<S>["resolve"]): Plugin[] {
14
- return Object.keys(plugins)
13
+ export function all<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
14
+ plugins: O["resolve"],
15
+ ): Plugin[] {
16
+ return (Object.keys(plugins || {}) as (keyof ResolverOptions<S>)[])
15
17
  .filter((key) => {
16
- return typeof plugins[key] === "object";
18
+ return typeof plugins![key] === "object";
17
19
  })
18
20
  .map((key) => {
19
- (plugins[key] as ResolverOptions<S>)!.name = key;
20
- return plugins[key] as Plugin;
21
+ (plugins![key] as ResolverOptions<S>)!.name = key;
22
+ return plugins![key] as Plugin;
21
23
  });
22
24
  }
23
25
 
@@ -43,7 +45,7 @@ export function sort(plugins: Plugin[]) {
43
45
  });
44
46
  }
45
47
 
46
- export interface PluginResult<S extends JSONSchema = JSONSchema> {
48
+ export interface PluginResult<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>> {
47
49
  plugin: Plugin;
48
50
  result?: string | Buffer | S;
49
51
  error?: any;
@@ -57,17 +59,17 @@ export interface PluginResult<S extends JSONSchema = JSONSchema> {
57
59
  * If the promise rejects, or the callback is called with an error, then the next plugin is called.
58
60
  * If ALL plugins fail, then the last error is thrown.
59
61
  */
60
- export async function run<S extends JSONSchema = JSONSchema>(
62
+ export async function run<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
61
63
  plugins: Plugin[],
62
64
  method: keyof Plugin | keyof ResolverOptions<S>,
63
65
  file: FileInfo,
64
- $refs: $Refs<S>,
66
+ $refs: $Refs<S, O>,
65
67
  ) {
66
68
  let plugin: Plugin;
67
- let lastError: PluginResult<S>;
69
+ let lastError: PluginResult<S, O>;
68
70
  let index = 0;
69
71
 
70
- return new Promise<PluginResult<S>>((resolve, reject) => {
72
+ return new Promise<PluginResult<S, O>>((resolve, reject) => {
71
73
  runNextPlugin();
72
74
 
73
75
  function runNextPlugin() {
@@ -94,7 +96,7 @@ export async function run<S extends JSONSchema = JSONSchema>(
94
96
  }
95
97
  }
96
98
 
97
- function callback(err: PluginResult<S>["error"], result: PluginResult<S>["result"]) {
99
+ function callback(err: PluginResult<S, O>["error"], result: PluginResult<S, O>["result"]) {
98
100
  if (err) {
99
101
  onError(err);
100
102
  } else {
@@ -102,7 +104,7 @@ export async function run<S extends JSONSchema = JSONSchema>(
102
104
  }
103
105
  }
104
106
 
105
- function onSuccess(result: PluginResult<S>["result"]) {
107
+ function onSuccess(result: PluginResult<S, O>["result"]) {
106
108
  // console.log(' success');
107
109
  resolve({
108
110
  plugin,
@@ -110,7 +112,7 @@ export async function run<S extends JSONSchema = JSONSchema>(
110
112
  });
111
113
  }
112
114
 
113
- function onError(error: PluginResult<S>["error"]) {
115
+ function onError(error: PluginResult<S, O>["error"]) {
114
116
  // console.log(' %s', err.message || err);
115
117
  lastError = {
116
118
  plugin,
@@ -127,12 +129,12 @@ export async function run<S extends JSONSchema = JSONSchema>(
127
129
  * If the value is a RegExp, then it will be tested against the file URL.
128
130
  * If the value is an array, then it will be compared against the file extension.
129
131
  */
130
- function getResult<S extends JSONSchema = JSONSchema>(
132
+ function getResult<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
131
133
  obj: Plugin,
132
134
  prop: keyof Plugin | keyof ResolverOptions<S>,
133
135
  file: FileInfo,
134
136
  callback?: (err?: Error, result?: any) => void,
135
- $refs?: any,
137
+ $refs?: $Refs<S, O>,
136
138
  ) {
137
139
  const value = obj[prop as keyof typeof obj] as unknown;
138
140
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apidevtools/json-schema-ref-parser",
3
- "version": "11.5.2",
3
+ "version": "11.5.3",
4
4
  "description": "Parse, Resolve, and Dereference JSON Schema $ref pointers",
5
5
  "keywords": [
6
6
  "json",