@apidevtools/json-schema-ref-parser 11.7.2 → 11.8.2

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.
Files changed (46) hide show
  1. package/README.md +4 -8
  2. package/cjs/bundle.js +304 -0
  3. package/cjs/dereference.js +258 -0
  4. package/cjs/index.js +603 -0
  5. package/cjs/normalize-args.js +64 -0
  6. package/cjs/options.js +125 -0
  7. package/cjs/package.json +3 -0
  8. package/cjs/parse.js +338 -0
  9. package/cjs/parsers/binary.js +54 -0
  10. package/cjs/parsers/json.js +199 -0
  11. package/cjs/parsers/text.js +61 -0
  12. package/cjs/parsers/yaml.js +239 -0
  13. package/cjs/pointer.js +290 -0
  14. package/cjs/ref.js +333 -0
  15. package/cjs/refs.js +214 -0
  16. package/cjs/resolve-external.js +333 -0
  17. package/cjs/resolvers/file.js +106 -0
  18. package/cjs/resolvers/http.js +184 -0
  19. package/cjs/util/errors.js +401 -0
  20. package/cjs/util/plugins.js +159 -0
  21. package/cjs/util/projectDir.cjs +6 -0
  22. package/cjs/util/url.js +228 -0
  23. package/dist/lib/bundle.js +17 -7
  24. package/dist/lib/dereference.js +20 -8
  25. package/dist/lib/index.d.ts +6 -6
  26. package/dist/lib/index.js +17 -7
  27. package/dist/lib/options.d.ts +9 -2
  28. package/dist/lib/parse.d.ts +1 -1
  29. package/dist/lib/parse.js +17 -7
  30. package/dist/lib/pointer.js +25 -9
  31. package/dist/lib/refs.js +17 -7
  32. package/dist/lib/resolve-external.js +17 -7
  33. package/dist/lib/resolvers/file.js +17 -7
  34. package/dist/lib/resolvers/http.js +17 -7
  35. package/dist/lib/util/errors.d.ts +6 -2
  36. package/dist/lib/util/errors.js +7 -3
  37. package/dist/lib/util/plugins.d.ts +2 -2
  38. package/dist/lib/util/url.js +20 -9
  39. package/lib/dereference.ts +4 -1
  40. package/lib/index.ts +6 -12
  41. package/lib/options.ts +7 -0
  42. package/lib/pointer.ts +13 -2
  43. package/lib/util/errors.ts +14 -5
  44. package/lib/util/plugins.ts +6 -7
  45. package/lib/util/url.ts +3 -2
  46. package/package.json +31 -31
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
37
  };
@@ -73,6 +83,7 @@ class Pointer {
73
83
  */
74
84
  resolve(obj, options, pathFromRoot) {
75
85
  const tokens = Pointer.parse(this.path, this.originalPath);
86
+ const found = [];
76
87
  // Crawl the object, one token at a time
77
88
  this.value = unwrapOrThrow(obj);
78
89
  for (let i = 0; i < tokens.length; i++) {
@@ -100,11 +111,16 @@ class Pointer {
100
111
  continue;
101
112
  }
102
113
  this.value = null;
103
- throw new errors_js_1.MissingPointerError(token, decodeURI(this.originalPath));
114
+ const path = this.$ref.path || "";
115
+ const targetRef = this.path.replace(path, "");
116
+ const targetFound = Pointer.join("", found);
117
+ const parentPath = pathFromRoot?.replace(path, "");
118
+ throw new errors_js_1.MissingPointerError(token, decodeURI(this.originalPath), targetRef, targetFound, parentPath);
104
119
  }
105
120
  else {
106
121
  this.value = this.value[token];
107
122
  }
123
+ found.push(token);
108
124
  }
109
125
  // Resolve the final value
110
126
  if (!this.value || (this.value.$ref && url.resolve(this.path, this.value.$ref) !== pathFromRoot)) {
@@ -178,7 +194,7 @@ class Pointer {
178
194
  split[i] = safeDecodeURIComponent(split[i].replace(escapedSlash, "/").replace(escapedTilde, "~"));
179
195
  }
180
196
  if (split[0] !== "") {
181
- throw new errors_js_1.InvalidPointerError(split, originalPath === undefined ? path : originalPath);
197
+ throw new errors_js_1.InvalidPointerError(pointer, originalPath === undefined ? path : originalPath);
182
198
  }
183
199
  return split.slice(1);
184
200
  }
package/dist/lib/refs.js CHANGED
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
37
  };
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
37
  };
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
37
  };
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  Object.defineProperty(exports, "__esModule", { value: true });
26
36
  const ono_1 = require("@jsdevtools/ono");
27
37
  const url = __importStar(require("../util/url.js"));
@@ -41,7 +41,11 @@ export declare class UnmatchedResolverError extends JSONParserError {
41
41
  export declare class MissingPointerError extends JSONParserError {
42
42
  code: JSONParserErrorType;
43
43
  name: string;
44
- constructor(token: any, path: any);
44
+ targetToken: any;
45
+ targetRef: string;
46
+ targetFound: string;
47
+ parentPath: string;
48
+ constructor(token: any, path: any, targetRef: any, targetFound: any, parentPath: any);
45
49
  }
46
50
  export declare class TimeoutError extends JSONParserError {
47
51
  code: JSONParserErrorType;
@@ -51,7 +55,7 @@ export declare class TimeoutError extends JSONParserError {
51
55
  export declare class InvalidPointerError extends JSONParserError {
52
56
  code: JSONParserErrorType;
53
57
  name: string;
54
- constructor(pointer: any, path: any);
58
+ constructor(pointer: string, path: string);
55
59
  }
56
60
  export declare function isHandledError(err: any): err is JSONParserError;
57
61
  export declare function normalizeError(err: any): any;
@@ -78,10 +78,14 @@ class UnmatchedResolverError extends JSONParserError {
78
78
  }
79
79
  exports.UnmatchedResolverError = UnmatchedResolverError;
80
80
  class MissingPointerError extends JSONParserError {
81
- constructor(token, path) {
82
- super(`Token "${token}" does not exist.`, (0, url_js_1.stripHash)(path));
83
- this.code = "EUNMATCHEDRESOLVER";
81
+ constructor(token, path, targetRef, targetFound, parentPath) {
82
+ super(`Missing $ref pointer "${(0, url_js_1.getHash)(path)}". Token "${token}" does not exist.`, (0, url_js_1.stripHash)(path));
83
+ this.code = "EMISSINGPOINTER";
84
84
  this.name = "MissingPointerError";
85
+ this.targetToken = token;
86
+ this.targetRef = targetRef;
87
+ this.targetFound = targetFound;
88
+ this.parentPath = parentPath;
85
89
  }
86
90
  }
87
91
  exports.MissingPointerError = MissingPointerError;
@@ -18,7 +18,7 @@ export declare function filter(plugins: Plugin[], method: any, file: any): Plugi
18
18
  * Sorts the given plugins, in place, by their `order` property.
19
19
  */
20
20
  export declare function sort(plugins: Plugin[]): Plugin[];
21
- export interface PluginResult<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>> {
21
+ export interface PluginResult<S extends object = JSONSchema> {
22
22
  plugin: Plugin;
23
23
  result?: string | Buffer | S;
24
24
  error?: any;
@@ -31,4 +31,4 @@ export interface PluginResult<S extends object = JSONSchema, O extends ParserOpt
31
31
  * If the promise rejects, or the callback is called with an error, then the next plugin is called.
32
32
  * If ALL plugins fail, then the last error is thrown.
33
33
  */
34
- export declare function run<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(plugins: Plugin[], method: keyof Plugin | keyof ResolverOptions<S>, file: FileInfo, $refs: $Refs<S, O>): Promise<PluginResult<S, O>>;
34
+ export declare function run<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(plugins: Plugin[], method: keyof Plugin | keyof ResolverOptions<S>, file: FileInfo, $refs: $Refs<S, O>): Promise<PluginResult<S>>;
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
37
  };
@@ -63,10 +73,11 @@ exports.parse = parse;
63
73
  * @returns
64
74
  */
65
75
  function resolve(from, to) {
66
- const fromUrl = new URL((0, convert_path_to_posix_1.default)(from), "resolve://");
76
+ // we use a non-existent URL to check if its a relative URL
77
+ const fromUrl = new URL((0, convert_path_to_posix_1.default)(from), "https://aaa.nonexistanturl.com");
67
78
  const resolvedUrl = new URL((0, convert_path_to_posix_1.default)(to), fromUrl);
68
79
  const endSpaces = to.match(/(\s*)$/)?.[1] || "";
69
- if (resolvedUrl.protocol === "resolve:") {
80
+ if (resolvedUrl.hostname === "aaa.nonexistanturl.com") {
70
81
  // `from` is a relative URL.
71
82
  const { pathname, search, hash } = resolvedUrl;
72
83
  return pathname + search + hash + endSpaces;
@@ -272,7 +272,8 @@ function dereference$Ref<S extends object = JSONSchema, O extends ParserOptions<
272
272
 
273
273
  /**
274
274
  * Called when a circular reference is found.
275
- * It sets the {@link $Refs#circular} flag, and throws an error if options.dereference.circular is false.
275
+ * It sets the {@link $Refs#circular} flag, executes the options.dereference.onCircular callback,
276
+ * and throws an error if options.dereference.circular is false.
276
277
  *
277
278
  * @param keyPath - The JSON Reference path of the circular reference
278
279
  * @param $refs
@@ -281,6 +282,8 @@ function dereference$Ref<S extends object = JSONSchema, O extends ParserOptions<
281
282
  */
282
283
  function foundCircularReference(keyPath: any, $refs: any, options: any) {
283
284
  $refs.circular = true;
285
+ options?.dereference?.onCircular?.(keyPath);
286
+
284
287
  if (!options.dereference.circular) {
285
288
  throw ono.reference(`Circular $ref pointer found at ${keyPath}`);
286
289
  }
package/lib/index.ts CHANGED
@@ -144,10 +144,8 @@ export class $RefParser<S extends object = JSONSchema, O extends ParserOptions<S
144
144
  }
145
145
  }
146
146
 
147
- public static parse<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
148
- schema: S | string | unknown,
149
- ): Promise<S>;
150
- public static parse<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
147
+ public static parse<S extends object = JSONSchema>(schema: S | string | unknown): Promise<S>;
148
+ public static parse<S extends object = JSONSchema>(
151
149
  schema: S | string | unknown,
152
150
  callback: SchemaCallback<S>,
153
151
  ): Promise<void>;
@@ -269,10 +267,8 @@ export class $RefParser<S extends object = JSONSchema, O extends ParserOptions<S
269
267
  * @param options (optional)
270
268
  * @param callback (optional) A callback that will receive the bundled schema object
271
269
  */
272
- public static bundle<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
273
- schema: S | string | unknown,
274
- ): Promise<S>;
275
- public static bundle<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
270
+ public static bundle<S extends object = JSONSchema>(schema: S | string | unknown): Promise<S>;
271
+ public static bundle<S extends object = JSONSchema>(
276
272
  schema: S | string | unknown,
277
273
  callback: SchemaCallback<S>,
278
274
  ): Promise<void>;
@@ -343,10 +339,8 @@ export class $RefParser<S extends object = JSONSchema, O extends ParserOptions<S
343
339
  * @param options (optional)
344
340
  * @param callback (optional) A callback that will receive the dereferenced schema object
345
341
  */
346
- public static dereference<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
347
- schema: S | string | unknown,
348
- ): Promise<S>;
349
- public static dereference<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
342
+ public static dereference<S extends object = JSONSchema>(schema: S | string | unknown): Promise<S>;
343
+ public static dereference<S extends object = JSONSchema>(
350
344
  schema: S | string | unknown,
351
345
  callback: SchemaCallback<S>,
352
346
  ): Promise<void>;
package/lib/options.ts CHANGED
@@ -29,6 +29,13 @@ export interface DereferenceOptions {
29
29
  */
30
30
  excludedPathMatcher?(path: string): boolean;
31
31
 
32
+ /**
33
+ * Callback invoked during circular reference detection.
34
+ *
35
+ * @argument {string} path - The path that is circular (ie. the `$ref` string)
36
+ */
37
+ onCircular?(path: string): void;
38
+
32
39
  /**
33
40
  * Callback invoked during dereferencing.
34
41
  *
package/lib/pointer.ts CHANGED
@@ -88,6 +88,7 @@ class Pointer<S extends object = JSONSchema, O extends ParserOptions<S> = Parser
88
88
  */
89
89
  resolve(obj: S, options?: O, pathFromRoot?: string) {
90
90
  const tokens = Pointer.parse(this.path, this.originalPath);
91
+ const found: any = [];
91
92
 
92
93
  // Crawl the object, one token at a time
93
94
  this.value = unwrapOrThrow(obj);
@@ -103,6 +104,7 @@ class Pointer<S extends object = JSONSchema, O extends ParserOptions<S> = Parser
103
104
  }
104
105
 
105
106
  const token = tokens[i];
107
+
106
108
  if (this.value[token] === undefined || (this.value[token] === null && i === tokens.length - 1)) {
107
109
  // one final case is if the entry itself includes slashes, and was parsed out as a token - we can join the remaining tokens and try again
108
110
  let didFindSubstringSlashMatch = false;
@@ -120,10 +122,19 @@ class Pointer<S extends object = JSONSchema, O extends ParserOptions<S> = Parser
120
122
  }
121
123
 
122
124
  this.value = null;
123
- throw new MissingPointerError(token, decodeURI(this.originalPath));
125
+
126
+ const path = this.$ref.path || "";
127
+
128
+ const targetRef = this.path.replace(path, "");
129
+ const targetFound = Pointer.join("", found);
130
+ const parentPath = pathFromRoot?.replace(path, "");
131
+
132
+ throw new MissingPointerError(token, decodeURI(this.originalPath), targetRef, targetFound, parentPath);
124
133
  } else {
125
134
  this.value = this.value[token];
126
135
  }
136
+
137
+ found.push(token);
127
138
  }
128
139
 
129
140
  // Resolve the final value
@@ -210,7 +221,7 @@ class Pointer<S extends object = JSONSchema, O extends ParserOptions<S> = Parser
210
221
  }
211
222
 
212
223
  if (split[0] !== "") {
213
- throw new InvalidPointerError(split, originalPath === undefined ? path : originalPath);
224
+ throw new InvalidPointerError(pointer, originalPath === undefined ? path : originalPath);
214
225
  }
215
226
 
216
227
  return split.slice(1);
@@ -1,5 +1,5 @@
1
1
  import { Ono } from "@jsdevtools/ono";
2
- import { stripHash, toFileSystemPath } from "./url.js";
2
+ import { getHash, stripHash, toFileSystemPath } from "./url.js";
3
3
  import type $RefParser from "../index.js";
4
4
  import type { ParserOptions } from "../index.js";
5
5
  import type { JSONSchema } from "../index.js";
@@ -121,10 +121,19 @@ export class UnmatchedResolverError extends JSONParserError {
121
121
  }
122
122
 
123
123
  export class MissingPointerError extends JSONParserError {
124
- code = "EUNMATCHEDRESOLVER" as JSONParserErrorType;
124
+ code = "EMISSINGPOINTER" as JSONParserErrorType;
125
125
  name = "MissingPointerError";
126
- constructor(token: any, path: any) {
127
- super(`Token "${token}" does not exist.`, stripHash(path));
126
+ public targetToken: any;
127
+ public targetRef: string;
128
+ public targetFound: string;
129
+ public parentPath: string;
130
+ constructor(token: any, path: any, targetRef: any, targetFound: any, parentPath: any) {
131
+ super(`Missing $ref pointer "${getHash(path)}". Token "${token}" does not exist.`, stripHash(path));
132
+
133
+ this.targetToken = token;
134
+ this.targetRef = targetRef;
135
+ this.targetFound = targetFound;
136
+ this.parentPath = parentPath;
128
137
  }
129
138
  }
130
139
 
@@ -139,7 +148,7 @@ export class TimeoutError extends JSONParserError {
139
148
  export class InvalidPointerError extends JSONParserError {
140
149
  code = "EUNMATCHEDRESOLVER" as JSONParserErrorType;
141
150
  name = "InvalidPointerError";
142
- constructor(pointer: any, path: any) {
151
+ constructor(pointer: string, path: string) {
143
152
  super(`Invalid $ref pointer "${pointer}". Pointers must begin with "#/"`, stripHash(path));
144
153
  }
145
154
  }
@@ -45,8 +45,7 @@ export function sort(plugins: Plugin[]) {
45
45
  });
46
46
  }
47
47
 
48
- // @ts-ignore
49
- export interface PluginResult<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>> {
48
+ export interface PluginResult<S extends object = JSONSchema> {
50
49
  plugin: Plugin;
51
50
  result?: string | Buffer | S;
52
51
  error?: any;
@@ -67,10 +66,10 @@ export async function run<S extends object = JSONSchema, O extends ParserOptions
67
66
  $refs: $Refs<S, O>,
68
67
  ) {
69
68
  let plugin: Plugin;
70
- let lastError: PluginResult<S, O>;
69
+ let lastError: PluginResult<S>;
71
70
  let index = 0;
72
71
 
73
- return new Promise<PluginResult<S, O>>((resolve, reject) => {
72
+ return new Promise<PluginResult<S>>((resolve, reject) => {
74
73
  runNextPlugin();
75
74
 
76
75
  function runNextPlugin() {
@@ -97,7 +96,7 @@ export async function run<S extends object = JSONSchema, O extends ParserOptions
97
96
  }
98
97
  }
99
98
 
100
- function callback(err: PluginResult<S, O>["error"], result: PluginResult<S, O>["result"]) {
99
+ function callback(err: PluginResult<S>["error"], result: PluginResult<S>["result"]) {
101
100
  if (err) {
102
101
  onError(err);
103
102
  } else {
@@ -105,7 +104,7 @@ export async function run<S extends object = JSONSchema, O extends ParserOptions
105
104
  }
106
105
  }
107
106
 
108
- function onSuccess(result: PluginResult<S, O>["result"]) {
107
+ function onSuccess(result: PluginResult<S>["result"]) {
109
108
  // console.log(' success');
110
109
  resolve({
111
110
  plugin,
@@ -113,7 +112,7 @@ export async function run<S extends object = JSONSchema, O extends ParserOptions
113
112
  });
114
113
  }
115
114
 
116
- function onError(error: PluginResult<S, O>["error"]) {
115
+ function onError(error: PluginResult<S>["error"]) {
117
116
  // console.log(' %s', err.message || err);
118
117
  lastError = {
119
118
  plugin,
package/lib/util/url.ts CHANGED
@@ -26,10 +26,11 @@ export const parse = (u: string | URL) => new URL(u);
26
26
  * @returns
27
27
  */
28
28
  export function resolve(from: string, to: string) {
29
- const fromUrl = new URL(convertPathToPosix(from), "resolve://");
29
+ // we use a non-existent URL to check if its a relative URL
30
+ const fromUrl = new URL(convertPathToPosix(from), "https://aaa.nonexistanturl.com");
30
31
  const resolvedUrl = new URL(convertPathToPosix(to), fromUrl);
31
32
  const endSpaces = to.match(/(\s*)$/)?.[1] || "";
32
- if (resolvedUrl.protocol === "resolve:") {
33
+ if (resolvedUrl.hostname === "aaa.nonexistanturl.com") {
33
34
  // `from` is a relative URL.
34
35
  const { pathname, search, hash } = resolvedUrl;
35
36
  return pathname + search + hash + endSpaces;
package/package.json CHANGED
@@ -1,7 +1,19 @@
1
1
  {
2
2
  "name": "@apidevtools/json-schema-ref-parser",
3
- "version": "11.7.2",
3
+ "version": "11.8.2",
4
4
  "description": "Parse, Resolve, and Dereference JSON Schema $ref pointers",
5
+ "scripts": {
6
+ "prepublishOnly": "yarn build",
7
+ "lint": "eslint lib",
8
+ "build": "rimraf dist && tsc",
9
+ "typecheck": "tsc --noEmit",
10
+ "prettier": "prettier --write \"**/*.+(js|jsx|ts|tsx|har||json|css|md)\"",
11
+ "test": "vitest --coverage",
12
+ "test:node": "yarn test",
13
+ "test:browser": "cross-env BROWSER=\"true\" yarn test",
14
+ "test:update": "vitest -u",
15
+ "test:watch": "vitest -w"
16
+ },
5
17
  "keywords": [
6
18
  "json",
7
19
  "schema",
@@ -54,42 +66,30 @@
54
66
  "dist",
55
67
  "cjs"
56
68
  ],
57
- "scripts": {
58
- "prepublishOnly": "yarn build",
59
- "lint": "eslint lib",
60
- "build": "rimraf dist && tsc",
61
- "typecheck": "tsc --noEmit",
62
- "prettier": "prettier --write \"**/*.+(js|jsx|ts|tsx|har||json|css|md)\"",
63
- "test": "vitest --coverage",
64
- "test:node": "yarn test",
65
- "test:browser": "cross-env BROWSER=\"true\" yarn test",
66
- "test:update": "vitest -u",
67
- "test:watch": "vitest -w"
68
- },
69
69
  "devDependencies": {
70
- "@eslint/compat": "^1.1.1",
71
- "@eslint/js": "^9.8.0",
72
- "@types/eslint": "9.6.0",
70
+ "@eslint/compat": "^1.2.5",
71
+ "@eslint/js": "^9.18.0",
72
+ "@types/eslint": "^9.6.1",
73
73
  "@types/js-yaml": "^4.0.9",
74
74
  "@types/node": "^22",
75
- "@typescript-eslint/eslint-plugin": "^8.0.0",
76
- "@typescript-eslint/parser": "^8.0.0",
77
- "@vitest/coverage-v8": "^2.0.5",
75
+ "@typescript-eslint/eslint-plugin": "^8.21.0",
76
+ "@typescript-eslint/parser": "^8.21.0",
77
+ "@vitest/coverage-v8": "^3.0.4",
78
78
  "cross-env": "^7.0.3",
79
- "eslint": "^9.8.0",
80
- "eslint-config-prettier": "^9.1.0",
79
+ "eslint": "^9.18.0",
80
+ "eslint-config-prettier": "^10.0.1",
81
81
  "eslint-config-standard": "^17.1.0",
82
- "eslint-plugin-import": "^2.29.1",
83
- "eslint-plugin-prettier": "^5.2.1",
84
- "eslint-plugin-promise": "^7.0.0",
85
- "eslint-plugin-unused-imports": "^4.0.1",
86
- "globals": "^15.9.0",
87
- "jsdom": "^24.1.1",
88
- "prettier": "^3.3.3",
82
+ "eslint-plugin-import": "^2.31.0",
83
+ "eslint-plugin-prettier": "^5.2.3",
84
+ "eslint-plugin-promise": "^7.2.1",
85
+ "eslint-plugin-unused-imports": "^4.1.4",
86
+ "globals": "^15.14.0",
87
+ "jsdom": "^26.0.0",
88
+ "prettier": "^3.4.2",
89
89
  "rimraf": "^6.0.1",
90
- "typescript": "^5.5.4",
91
- "typescript-eslint": "^8.0.0",
92
- "vitest": "^2.0.5"
90
+ "typescript": "^5.7.3",
91
+ "typescript-eslint": "^8.21.0",
92
+ "vitest": "^3.0.4"
93
93
  },
94
94
  "dependencies": {
95
95
  "@jsdevtools/ono": "^7.1.3",