@apidevtools/json-schema-ref-parser 11.2.2 → 11.2.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.
@@ -60,7 +60,6 @@ function bundle(parser, options) {
60
60
  function crawl(parent, key, path, pathFromRoot, indirections, inventory, $refs, options) {
61
61
  const obj = key === null ? parent : parent[key];
62
62
  if (obj && typeof obj === "object" && !ArrayBuffer.isView(obj)) {
63
- // @ts-expect-error TS(2554): Expected 2 arguments, but got 1.
64
63
  if (ref_js_1.default.isAllowed$Ref(obj)) {
65
64
  inventory$Ref(parent, key, path, pathFromRoot, indirections, inventory, $refs, options);
66
65
  }
@@ -88,7 +87,6 @@ function crawl(parent, key, path, pathFromRoot, indirections, inventory, $refs,
88
87
  const keyPath = pointer_js_1.default.join(path, key);
89
88
  const keyPathFromRoot = pointer_js_1.default.join(pathFromRoot, key);
90
89
  const value = obj[key];
91
- // @ts-expect-error TS(2554): Expected 2 arguments, but got 1.
92
90
  if (ref_js_1.default.isAllowed$Ref(value)) {
93
91
  inventory$Ref(obj, key, path, keyPathFromRoot, indirections, inventory, $refs, options);
94
92
  }
@@ -1,15 +1,9 @@
1
1
  import $Refs from "./refs.js";
2
2
  import { JSONParserError, InvalidPointerError, MissingPointerError, ResolverError, ParserError, UnmatchedParserError, UnmatchedResolverError } from "./util/errors.js";
3
3
  import type { ParserOptions } from "./options.js";
4
- import type { $RefsCallback, JSONSchema, SchemaCallback } from "./types/index.js";
5
- export { JSONParserError };
6
- export { InvalidPointerError };
7
- export { MissingPointerError };
8
- export { ResolverError };
9
- export { ParserError };
10
- export { UnmatchedParserError };
11
- export { UnmatchedResolverError };
12
- type RefParserSchema = string | JSONSchema;
4
+ import type { Plugin, $RefsCallback, JSONSchema, SchemaCallback, HTTPResolverOptions, FileInfo, ResolverOptions, JSONSchemaObject } from "./types/index.js";
5
+ export { JSONSchemaObject, ResolverOptions, ParserError, UnmatchedResolverError, ResolverError, HTTPResolverOptions, FileInfo, UnmatchedParserError, ParserOptions, MissingPointerError, InvalidPointerError, JSONParserError, Plugin, };
6
+ export type RefParserSchema = string | JSONSchema;
13
7
  /**
14
8
  * This class parses a JSON schema, builds a map of its JSON references and their resolved values,
15
9
  * and provides methods for traversing, manipulating, and dereferencing those references.
package/dist/lib/index.js CHANGED
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.dereference = exports.bundle = exports.resolve = exports.parse = exports.$RefParser = exports.UnmatchedResolverError = exports.UnmatchedParserError = exports.ParserError = exports.ResolverError = exports.MissingPointerError = exports.InvalidPointerError = exports.JSONParserError = void 0;
29
+ exports.dereference = exports.bundle = exports.resolve = exports.parse = exports.$RefParser = exports.JSONParserError = exports.InvalidPointerError = exports.MissingPointerError = exports.UnmatchedParserError = exports.ResolverError = exports.UnmatchedResolverError = exports.ParserError = void 0;
30
30
  const refs_js_1 = __importDefault(require("./refs.js"));
31
31
  const parse_js_1 = __importDefault(require("./parse.js"));
32
32
  const normalize_args_js_1 = __importDefault(require("./normalize-args.js"));
@@ -41,8 +41,7 @@ exports.default = {
41
41
  return js_yaml_1.default.load(data, { schema: js_yaml_2.JSON_SCHEMA });
42
42
  }
43
43
  catch (e) {
44
- // @ts-expect-error TS(2571): Object is of type 'unknown'.
45
- throw new errors_js_1.ParserError(e.message, file.url);
44
+ throw new errors_js_1.ParserError(e?.message || "Parser Error", file.url);
46
45
  }
47
46
  }
48
47
  else {
@@ -36,7 +36,7 @@ declare class Pointer {
36
36
  * Resolving a single pointer may require resolving multiple $Refs.
37
37
  */
38
38
  indirections: number;
39
- constructor($ref: any, path: any, friendlyPath: any);
39
+ constructor($ref: any, path: any, friendlyPath?: string);
40
40
  /**
41
41
  * Resolves the value of a nested property within the given object.
42
42
  *
@@ -50,7 +50,7 @@ declare class Pointer {
50
50
  * the {@link Pointer#$ref} and {@link Pointer#path} will reflect the resolution path
51
51
  * of the resolved value.
52
52
  */
53
- resolve(obj: any, options: any, pathFromRoot: any): this;
53
+ resolve(obj: any, options?: $RefParserOptions, pathFromRoot?: string): this;
54
54
  /**
55
55
  * Sets the value of a nested property within the given object.
56
56
  *
@@ -82,6 +82,6 @@ declare class Pointer {
82
82
  * @param tokens - The token(s) to append (e.g. ["name", "first"])
83
83
  * @returns
84
84
  */
85
- static join(base: any, tokens: any): any;
85
+ static join(base: string, tokens: string | string[]): string;
86
86
  }
87
87
  export default Pointer;
@@ -76,7 +76,7 @@ class Pointer {
76
76
  return this;
77
77
  }
78
78
  const token = tokens[i];
79
- if (this.value[token] === undefined || this.value[token] === null) {
79
+ if (this.value[token] === undefined || (this.value[token] === null && i === tokens.length - 1)) {
80
80
  this.value = null;
81
81
  throw new errors_js_1.MissingPointerError(token, decodeURI(this.originalPath));
82
82
  }
package/dist/lib/ref.d.ts CHANGED
@@ -2,7 +2,8 @@ import Pointer from "./pointer.js";
2
2
  import type { JSONParserError, MissingPointerError, ParserError, ResolverError } from "./util/errors.js";
3
3
  import type $Refs from "./refs.js";
4
4
  import type $RefParserOptions from "./options.js";
5
- type $RefError = JSONParserError | ResolverError | ParserError | MissingPointerError;
5
+ import type { JSONSchema } from "./types";
6
+ export type $RefError = JSONParserError | ResolverError | ParserError | MissingPointerError;
6
7
  /**
7
8
  * This class represents a single JSON reference and its resolved value.
8
9
  *
@@ -56,7 +57,7 @@ declare class $Ref {
56
57
  * @param options
57
58
  * @returns
58
59
  */
59
- exists(path: string, options: any): boolean;
60
+ exists(path: string, options?: $RefParserOptions): boolean;
60
61
  /**
61
62
  * Resolves the given JSON reference within this {@link $Ref#value} and returns the resolved value.
62
63
  *
@@ -64,7 +65,7 @@ declare class $Ref {
64
65
  * @param options
65
66
  * @returns - Returns the resolved value
66
67
  */
67
- get(path: any, options: any): any;
68
+ get(path: any, options: $RefParserOptions): any;
68
69
  /**
69
70
  * Resolves the given JSON reference within this {@link $Ref#value}.
70
71
  *
@@ -82,14 +83,14 @@ declare class $Ref {
82
83
  * @param path - The full path of the property to set, optionally with a JSON pointer in the hash
83
84
  * @param value - The value to assign
84
85
  */
85
- set(path: any, value: any): void;
86
+ set(path: string, value: any): void;
86
87
  /**
87
88
  * Determines whether the given value is a JSON reference.
88
89
  *
89
90
  * @param value - The value to inspect
90
91
  * @returns
91
92
  */
92
- static is$Ref(value: any): value is {
93
+ static is$Ref(value: unknown): value is {
93
94
  $ref: string;
94
95
  length?: number;
95
96
  };
@@ -99,7 +100,7 @@ declare class $Ref {
99
100
  * @param value - The value to inspect
100
101
  * @returns
101
102
  */
102
- static isExternal$Ref(value: any): boolean;
103
+ static isExternal$Ref(value: unknown): boolean;
103
104
  /**
104
105
  * Determines whether the given value is a JSON reference, and whether it is allowed by the options.
105
106
  * For example, if it references an external file, then options.resolve.external must be true.
@@ -108,7 +109,7 @@ declare class $Ref {
108
109
  * @param options
109
110
  * @returns
110
111
  */
111
- static isAllowed$Ref(value: any, options: any): true | undefined;
112
+ static isAllowed$Ref(value: unknown, options?: $RefParserOptions): true | undefined;
112
113
  /**
113
114
  * Determines whether the given value is a JSON reference that "extends" its resolved value.
114
115
  * That is, it has extra properties (in addition to "$ref"), so rather than simply pointing to
@@ -143,7 +144,7 @@ declare class $Ref {
143
144
  * @param value - The value to inspect
144
145
  * @returns
145
146
  */
146
- static isExtended$Ref(value: any): boolean;
147
+ static isExtended$Ref(value: unknown): boolean;
147
148
  /**
148
149
  * Returns the resolved value of a JSON Reference.
149
150
  * If necessary, the resolved value is merged with the JSON Reference to create a new object
@@ -175,6 +176,6 @@ declare class $Ref {
175
176
  * @param resolvedValue - The resolved value, which can be any type
176
177
  * @returns - Returns the dereferenced value
177
178
  */
178
- static dereference($ref: $Ref, resolvedValue: any): any;
179
+ static dereference($ref: $Ref, resolvedValue: JSONSchema): JSONSchema;
179
180
  }
180
181
  export default $Ref;
package/dist/lib/ref.js CHANGED
@@ -102,7 +102,6 @@ class $Ref {
102
102
  * @param value - The value to assign
103
103
  */
104
104
  set(path, value) {
105
- // @ts-expect-error TS(2554): Expected 3 arguments, but got 2.
106
105
  const pointer = new pointer_js_1.default(this, path);
107
106
  this.value = pointer.set(this.value, value);
108
107
  }
@@ -113,7 +112,12 @@ class $Ref {
113
112
  * @returns
114
113
  */
115
114
  static is$Ref(value) {
116
- return value && typeof value === "object" && typeof value.$ref === "string" && value.$ref.length > 0;
115
+ return (Boolean(value) &&
116
+ typeof value === "object" &&
117
+ value !== null &&
118
+ "$ref" in value &&
119
+ typeof value.$ref === "string" &&
120
+ value.$ref.length > 0);
117
121
  }
118
122
  /**
119
123
  * Determines whether the given value is an external JSON reference.
@@ -22,8 +22,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
25
28
  Object.defineProperty(exports, "__esModule", { value: true });
26
- const fs_1 = require("fs");
29
+ const fs_1 = __importDefault(require("fs"));
27
30
  const ono_1 = require("@jsdevtools/ono");
28
31
  const url = __importStar(require("../util/url.js"));
29
32
  const errors_js_1 = require("../util/errors.js");
@@ -52,8 +55,7 @@ exports.default = {
52
55
  throw new errors_js_1.ResolverError(ono_1.ono.uri(err, `Malformed URI: ${file.url}`), file.url);
53
56
  }
54
57
  try {
55
- const data = await fs_1.promises.readFile(path);
56
- return data;
58
+ return await fs_1.default.promises.readFile(path);
57
59
  }
58
60
  catch (err) {
59
61
  throw new errors_js_1.ResolverError((0, ono_1.ono)(err, `Error opening file "${path}"`), path);
@@ -12,7 +12,7 @@ export declare class JSONParserError extends Error {
12
12
  export declare class JSONParserErrorGroup extends Error {
13
13
  files: $RefParser;
14
14
  constructor(parser: $RefParser);
15
- static getParserErrors(parser: any): any[];
15
+ static getParserErrors(parser: any): JSONParserError[];
16
16
  get errors(): Array<JSONParserError | InvalidPointerError | ResolverError | ParserError | MissingPointerError | UnmatchedParserError | UnmatchedResolverError>;
17
17
  }
18
18
  export declare class ParserError extends JSONParserError {
@@ -29,9 +29,7 @@ class JSONParserErrorGroup extends Error {
29
29
  static getParserErrors(parser) {
30
30
  const errors = [];
31
31
  for (const $ref of Object.values(parser.$refs._$refs)) {
32
- // @ts-expect-error TS(2571): Object is of type 'unknown'.
33
32
  if ($ref.errors) {
34
- // @ts-expect-error TS(2571): Object is of type 'unknown'.
35
33
  errors.push(...$ref.errors);
36
34
  }
37
35
  }
@@ -79,7 +79,7 @@ export declare function isFileSystemPath(path: string | undefined): boolean;
79
79
  * @param path
80
80
  * @returns
81
81
  */
82
- export declare function fromFileSystemPath(path: any): any;
82
+ export declare function fromFileSystemPath(path: string): string;
83
83
  /**
84
84
  * Converts a URL to a local filesystem path.
85
85
  */
@@ -35,9 +35,11 @@ const jsonPointerSlash = /~1/g;
35
35
  const jsonPointerTilde = /~0/g;
36
36
  const path_2 = require("path");
37
37
  const is_windows_1 = require("./is-windows");
38
- const projectDir = (0, path_2.join)(__dirname, "..", "..");
39
38
  // RegExp patterns to URL-encode special characters in local filesystem paths
40
- const urlEncodePatterns = [/\?/g, "%3F", /#/g, "%23"];
39
+ const urlEncodePatterns = [
40
+ [/\?/g, "%3F"],
41
+ [/#/g, "%23"],
42
+ ];
41
43
  // RegExp patterns to URL-decode special characters for local filesystem paths
42
44
  const urlDecodePatterns = [/%23/g, "#", /%24/g, "$", /%26/g, "&", /%2C/g, ",", /%40/g, "@"];
43
45
  const parse = (u) => new URL(u);
@@ -207,12 +209,13 @@ function fromFileSystemPath(path) {
207
209
  // Step 1: On Windows, replace backslashes with forward slashes,
208
210
  // rather than encoding them as "%5C"
209
211
  if ((0, is_windows_1.isWindows)()) {
212
+ const projectDir = cwd();
210
213
  const upperPath = path.toUpperCase();
211
214
  const projectDirPosixPath = (0, convert_path_to_posix_1.default)(projectDir);
212
215
  const posixUpper = projectDirPosixPath.toUpperCase();
213
216
  const hasProjectDir = upperPath.includes(posixUpper);
214
217
  const hasProjectUri = upperPath.includes(posixUpper);
215
- const isAbsolutePath = path_1.win32.isAbsolute(path);
218
+ const isAbsolutePath = path_1.win32?.isAbsolute(path);
216
219
  if (!(hasProjectDir || hasProjectUri || isAbsolutePath)) {
217
220
  path = (0, path_2.join)(projectDir, path);
218
221
  }
@@ -223,8 +226,8 @@ function fromFileSystemPath(path) {
223
226
  // Step 3: Manually encode characters that are not encoded by `encodeURI`.
224
227
  // This includes characters such as "#" and "?", which have special meaning in URLs,
225
228
  // but are just normal characters in a filesystem path.
226
- for (let i = 0; i < urlEncodePatterns.length; i += 2) {
227
- path = path.replace(urlEncodePatterns[i], urlEncodePatterns[i + 1]);
229
+ for (const pattern of urlEncodePatterns) {
230
+ path = path.replace(pattern[0], pattern[1]);
228
231
  }
229
232
  return path;
230
233
  }
package/lib/bundle.ts CHANGED
@@ -49,7 +49,6 @@ function crawl(
49
49
  const obj = key === null ? parent : parent[key];
50
50
 
51
51
  if (obj && typeof obj === "object" && !ArrayBuffer.isView(obj)) {
52
- // @ts-expect-error TS(2554): Expected 2 arguments, but got 1.
53
52
  if ($Ref.isAllowed$Ref(obj)) {
54
53
  inventory$Ref(parent, key, path, pathFromRoot, indirections, inventory, $refs, options);
55
54
  } else {
@@ -76,7 +75,6 @@ function crawl(
76
75
  const keyPathFromRoot = Pointer.join(pathFromRoot, key);
77
76
  const value = obj[key];
78
77
 
79
- // @ts-expect-error TS(2554): Expected 2 arguments, but got 1.
80
78
  if ($Ref.isAllowed$Ref(value)) {
81
79
  inventory$Ref(obj, key, path, keyPathFromRoot, indirections, inventory, $refs, options);
82
80
  } else {
package/lib/index.ts CHANGED
@@ -19,17 +19,34 @@ import {
19
19
  import { ono } from "@jsdevtools/ono";
20
20
  import maybe from "./util/maybe.js";
21
21
  import type { ParserOptions } from "./options.js";
22
- import type { $RefsCallback, JSONSchema, SchemaCallback } from "./types/index.js";
22
+ import type {
23
+ Plugin,
24
+ $RefsCallback,
25
+ JSONSchema,
26
+ SchemaCallback,
27
+ HTTPResolverOptions,
28
+ FileInfo,
29
+ ResolverOptions,
30
+ JSONSchemaObject,
31
+ } from "./types/index.js";
23
32
 
24
- export { JSONParserError };
25
- export { InvalidPointerError };
26
- export { MissingPointerError };
27
- export { ResolverError };
28
- export { ParserError };
29
- export { UnmatchedParserError };
30
- export { UnmatchedResolverError };
33
+ export {
34
+ JSONSchemaObject,
35
+ ResolverOptions,
36
+ ParserError,
37
+ UnmatchedResolverError,
38
+ ResolverError,
39
+ HTTPResolverOptions,
40
+ FileInfo,
41
+ UnmatchedParserError,
42
+ ParserOptions,
43
+ MissingPointerError,
44
+ InvalidPointerError,
45
+ JSONParserError,
46
+ Plugin,
47
+ };
31
48
 
32
- type RefParserSchema = string | JSONSchema;
49
+ export type RefParserSchema = string | JSONSchema;
33
50
 
34
51
  /**
35
52
  * This class parses a JSON schema, builds a map of its JSON references and their resolved values,
@@ -41,9 +41,8 @@ export default {
41
41
  if (typeof data === "string") {
42
42
  try {
43
43
  return yaml.load(data, { schema: JSON_SCHEMA });
44
- } catch (e) {
45
- // @ts-expect-error TS(2571): Object is of type 'unknown'.
46
- throw new ParserError(e.message, file.url);
44
+ } catch (e: any) {
45
+ throw new ParserError(e?.message || "Parser Error", file.url);
47
46
  }
48
47
  } else {
49
48
  // data is already a JavaScript value (object, array, number, null, NaN, etc.)
package/lib/pointer.ts CHANGED
@@ -49,7 +49,7 @@ class Pointer {
49
49
  */
50
50
  indirections: number;
51
51
 
52
- constructor($ref: any, path: any, friendlyPath: any) {
52
+ constructor($ref: any, path: any, friendlyPath?: string) {
53
53
  this.$ref = $ref;
54
54
 
55
55
  this.path = path;
@@ -76,7 +76,7 @@ class Pointer {
76
76
  * the {@link Pointer#$ref} and {@link Pointer#path} will reflect the resolution path
77
77
  * of the resolved value.
78
78
  */
79
- resolve(obj: any, options: any, pathFromRoot: any) {
79
+ resolve(obj: any, options?: $RefParserOptions, pathFromRoot?: string) {
80
80
  const tokens = Pointer.parse(this.path, this.originalPath);
81
81
 
82
82
  // Crawl the object, one token at a time
@@ -93,7 +93,7 @@ class Pointer {
93
93
  }
94
94
 
95
95
  const token = tokens[i];
96
- if (this.value[token] === undefined || this.value[token] === null) {
96
+ if (this.value[token] === undefined || (this.value[token] === null && i === tokens.length - 1)) {
97
97
  this.value = null;
98
98
  throw new MissingPointerError(token, decodeURI(this.originalPath));
99
99
  } else {
@@ -198,7 +198,7 @@ class Pointer {
198
198
  * @param tokens - The token(s) to append (e.g. ["name", "first"])
199
199
  * @returns
200
200
  */
201
- static join(base: any, tokens: any) {
201
+ static join(base: string, tokens: string | string[]) {
202
202
  // Ensure that the base path contains a hash
203
203
  if (base.indexOf("#") === -1) {
204
204
  base += "#";
package/lib/ref.ts CHANGED
@@ -4,8 +4,9 @@ import { InvalidPointerError, isHandledError, normalizeError } from "./util/erro
4
4
  import { safePointerToPath, stripHash, getHash } from "./util/url.js";
5
5
  import type $Refs from "./refs.js";
6
6
  import type $RefParserOptions from "./options.js";
7
+ import type { JSONSchema } from "./types";
7
8
 
8
- type $RefError = JSONParserError | ResolverError | ParserError | MissingPointerError;
9
+ export type $RefError = JSONParserError | ResolverError | ParserError | MissingPointerError;
9
10
 
10
11
  /**
11
12
  * This class represents a single JSON reference and its resolved value.
@@ -86,7 +87,7 @@ class $Ref {
86
87
  * @param options
87
88
  * @returns
88
89
  */
89
- exists(path: string, options: any) {
90
+ exists(path: string, options?: $RefParserOptions) {
90
91
  try {
91
92
  this.resolve(path, options);
92
93
  return true;
@@ -102,7 +103,7 @@ class $Ref {
102
103
  * @param options
103
104
  * @returns - Returns the resolved value
104
105
  */
105
- get(path: any, options: any) {
106
+ get(path: any, options: $RefParserOptions) {
106
107
  return this.resolve(path, options)?.value;
107
108
  }
108
109
 
@@ -144,8 +145,7 @@ class $Ref {
144
145
  * @param path - The full path of the property to set, optionally with a JSON pointer in the hash
145
146
  * @param value - The value to assign
146
147
  */
147
- set(path: any, value: any) {
148
- // @ts-expect-error TS(2554): Expected 3 arguments, but got 2.
148
+ set(path: string, value: any) {
149
149
  const pointer = new Pointer(this, path);
150
150
  this.value = pointer.set(this.value, value);
151
151
  }
@@ -156,8 +156,15 @@ class $Ref {
156
156
  * @param value - The value to inspect
157
157
  * @returns
158
158
  */
159
- static is$Ref(value: any): value is { $ref: string; length?: number } {
160
- return value && typeof value === "object" && typeof value.$ref === "string" && value.$ref.length > 0;
159
+ static is$Ref(value: unknown): value is { $ref: string; length?: number } {
160
+ return (
161
+ Boolean(value) &&
162
+ typeof value === "object" &&
163
+ value !== null &&
164
+ "$ref" in value &&
165
+ typeof value.$ref === "string" &&
166
+ value.$ref.length > 0
167
+ );
161
168
  }
162
169
 
163
170
  /**
@@ -166,7 +173,7 @@ class $Ref {
166
173
  * @param value - The value to inspect
167
174
  * @returns
168
175
  */
169
- static isExternal$Ref(value: any): boolean {
176
+ static isExternal$Ref(value: unknown): boolean {
170
177
  return $Ref.is$Ref(value) && value.$ref![0] !== "#";
171
178
  }
172
179
 
@@ -178,7 +185,7 @@ class $Ref {
178
185
  * @param options
179
186
  * @returns
180
187
  */
181
- static isAllowed$Ref(value: any, options: any) {
188
+ static isAllowed$Ref(value: unknown, options?: $RefParserOptions) {
182
189
  if (this.is$Ref(value)) {
183
190
  if (value.$ref.substring(0, 2) === "#/" || value.$ref === "#") {
184
191
  // It's a JSON Pointer reference, which is always allowed
@@ -224,7 +231,7 @@ class $Ref {
224
231
  * @param value - The value to inspect
225
232
  * @returns
226
233
  */
227
- static isExtended$Ref(value: any) {
234
+ static isExtended$Ref(value: unknown) {
228
235
  return $Ref.is$Ref(value) && Object.keys(value).length > 1;
229
236
  }
230
237
 
@@ -259,7 +266,7 @@ class $Ref {
259
266
  * @param resolvedValue - The resolved value, which can be any type
260
267
  * @returns - Returns the dereferenced value
261
268
  */
262
- static dereference($ref: $Ref, resolvedValue: any) {
269
+ static dereference($ref: $Ref, resolvedValue: JSONSchema): JSONSchema {
263
270
  if (resolvedValue && typeof resolvedValue === "object" && $Ref.isExtended$Ref($ref)) {
264
271
  const merged = {};
265
272
  for (const key of Object.keys($ref)) {
@@ -1,4 +1,4 @@
1
- import { promises as fs } from "fs";
1
+ import fs from "fs";
2
2
  import { ono } from "@jsdevtools/ono";
3
3
  import * as url from "../util/url.js";
4
4
  import { ResolverError } from "../util/errors.js";
@@ -31,8 +31,7 @@ export default {
31
31
  throw new ResolverError(ono.uri(err, `Malformed URI: ${file.url}`), file.url);
32
32
  }
33
33
  try {
34
- const data = await fs.readFile(path);
35
- return data;
34
+ return await fs.promises.readFile(path);
36
35
  } catch (err: any) {
37
36
  throw new ResolverError(ono(err, `Error opening file "${path}"`), path);
38
37
  }
@@ -1,6 +1,7 @@
1
1
  import { Ono } from "@jsdevtools/ono";
2
2
  import { stripHash, toFileSystemPath } from "./url.js";
3
3
  import type $RefParser from "../index.js";
4
+ import type $Ref from "../ref";
4
5
 
5
6
  export type JSONParserErrorType =
6
7
  | "EUNKNOWN"
@@ -51,10 +52,8 @@ export class JSONParserErrorGroup extends Error {
51
52
  static getParserErrors(parser: any) {
52
53
  const errors = [];
53
54
 
54
- for (const $ref of Object.values(parser.$refs._$refs)) {
55
- // @ts-expect-error TS(2571): Object is of type 'unknown'.
55
+ for (const $ref of Object.values(parser.$refs._$refs) as $Ref[]) {
56
56
  if ($ref.errors) {
57
- // @ts-expect-error TS(2571): Object is of type 'unknown'.
58
57
  errors.push(...$ref.errors);
59
58
  }
60
59
  }
package/lib/util/url.ts CHANGED
@@ -9,9 +9,11 @@ const jsonPointerTilde = /~0/g;
9
9
  import { join } from "path";
10
10
  import { isWindows } from "./is-windows";
11
11
 
12
- const projectDir = join(__dirname, "..", "..");
13
12
  // RegExp patterns to URL-encode special characters in local filesystem paths
14
- const urlEncodePatterns = [/\?/g, "%3F", /#/g, "%23"];
13
+ const urlEncodePatterns = [
14
+ [/\?/g, "%3F"],
15
+ [/#/g, "%23"],
16
+ ] as [RegExp, string][];
15
17
 
16
18
  // RegExp patterns to URL-decode special characters for local filesystem paths
17
19
  const urlDecodePatterns = [/%23/g, "#", /%24/g, "$", /%26/g, "&", /%2C/g, ",", /%40/g, "@"];
@@ -179,16 +181,17 @@ export function isFileSystemPath(path: string | undefined) {
179
181
  * @param path
180
182
  * @returns
181
183
  */
182
- export function fromFileSystemPath(path: any) {
184
+ export function fromFileSystemPath(path: string) {
183
185
  // Step 1: On Windows, replace backslashes with forward slashes,
184
186
  // rather than encoding them as "%5C"
185
187
  if (isWindows()) {
188
+ const projectDir = cwd();
186
189
  const upperPath = path.toUpperCase();
187
190
  const projectDirPosixPath = convertPathToPosix(projectDir);
188
191
  const posixUpper = projectDirPosixPath.toUpperCase();
189
192
  const hasProjectDir = upperPath.includes(posixUpper);
190
193
  const hasProjectUri = upperPath.includes(posixUpper);
191
- const isAbsolutePath = win32.isAbsolute(path);
194
+ const isAbsolutePath = win32?.isAbsolute(path);
192
195
 
193
196
  if (!(hasProjectDir || hasProjectUri || isAbsolutePath)) {
194
197
  path = join(projectDir, path);
@@ -202,8 +205,8 @@ export function fromFileSystemPath(path: any) {
202
205
  // Step 3: Manually encode characters that are not encoded by `encodeURI`.
203
206
  // This includes characters such as "#" and "?", which have special meaning in URLs,
204
207
  // but are just normal characters in a filesystem path.
205
- for (let i = 0; i < urlEncodePatterns.length; i += 2) {
206
- path = path.replace(urlEncodePatterns[i], urlEncodePatterns[i + 1]);
208
+ for (const pattern of urlEncodePatterns) {
209
+ path = path.replace(pattern[0], pattern[1]);
207
210
  }
208
211
 
209
212
  return path;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apidevtools/json-schema-ref-parser",
3
- "version": "11.2.2",
3
+ "version": "11.2.3",
4
4
  "description": "Parse, Resolve, and Dereference JSON Schema $ref pointers",
5
5
  "keywords": [
6
6
  "json",