@apidevtools/json-schema-ref-parser 10.0.0 → 10.1.0

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 (103) hide show
  1. package/dist/lib/bundle.d.ts +10 -0
  2. package/dist/lib/bundle.js +265 -0
  3. package/dist/lib/dereference.d.ts +9 -0
  4. package/dist/lib/dereference.js +206 -0
  5. package/dist/lib/index.d.ts +206 -0
  6. package/dist/lib/index.js +223 -0
  7. package/dist/lib/normalize-args.d.ts +10 -0
  8. package/dist/lib/normalize-args.js +42 -0
  9. package/dist/lib/options.d.ts +77 -0
  10. package/dist/lib/options.js +119 -0
  11. package/dist/lib/parse.d.ts +8 -0
  12. package/dist/lib/parse.js +177 -0
  13. package/dist/lib/parsers/binary.d.ts +3 -0
  14. package/dist/lib/parsers/binary.js +35 -0
  15. package/dist/lib/parsers/json.d.ts +3 -0
  16. package/dist/lib/parsers/json.js +57 -0
  17. package/dist/lib/parsers/text.d.ts +3 -0
  18. package/dist/lib/parsers/text.js +42 -0
  19. package/dist/lib/parsers/yaml.d.ts +3 -0
  20. package/dist/lib/parsers/yaml.js +65 -0
  21. package/dist/lib/pointer.d.ts +87 -0
  22. package/dist/lib/pointer.js +256 -0
  23. package/dist/lib/ref.d.ts +181 -0
  24. package/dist/lib/ref.js +239 -0
  25. package/dist/lib/refs.d.ts +127 -0
  26. package/dist/lib/refs.js +223 -0
  27. package/dist/lib/resolve-external.d.ts +14 -0
  28. package/dist/lib/resolve-external.js +148 -0
  29. package/dist/lib/resolvers/file.d.ts +3 -0
  30. package/dist/lib/resolvers/file.js +76 -0
  31. package/dist/lib/resolvers/http.d.ts +3 -0
  32. package/dist/lib/resolvers/http.js +159 -0
  33. package/dist/lib/types/index.d.ts +104 -0
  34. package/dist/lib/types/index.js +2 -0
  35. package/dist/lib/util/errors.d.ts +50 -0
  36. package/dist/lib/util/errors.js +106 -0
  37. package/dist/lib/util/maybe.d.ts +3 -0
  38. package/dist/lib/util/maybe.js +24 -0
  39. package/dist/lib/util/next.d.ts +2 -0
  40. package/dist/lib/util/next.js +16 -0
  41. package/dist/lib/util/plugins.d.ts +36 -0
  42. package/dist/lib/util/plugins.js +144 -0
  43. package/dist/lib/util/url.d.ts +93 -0
  44. package/{cjs → dist/lib}/util/url.js +134 -102
  45. package/dist/vite.config.d.ts +2 -0
  46. package/dist/vite.config.js +23 -0
  47. package/lib/{bundle.js → bundle.ts} +105 -101
  48. package/lib/{dereference.js → dereference.ts} +113 -52
  49. package/lib/index.ts +413 -0
  50. package/lib/{normalize-args.js → normalize-args.ts} +7 -14
  51. package/lib/options.ts +202 -0
  52. package/lib/parse.ts +153 -0
  53. package/lib/parsers/binary.ts +39 -0
  54. package/lib/parsers/{json.js → json.ts} +9 -22
  55. package/lib/parsers/text.ts +46 -0
  56. package/lib/parsers/{yaml.js → yaml.ts} +15 -19
  57. package/lib/pointer.ts +296 -0
  58. package/lib/ref.ts +288 -0
  59. package/lib/refs.ts +238 -0
  60. package/lib/{resolve-external.js → resolve-external.ts} +39 -36
  61. package/lib/resolvers/file.ts +40 -0
  62. package/lib/resolvers/http.ts +136 -0
  63. package/lib/tsconfig.json +103 -0
  64. package/lib/types/index.ts +135 -0
  65. package/lib/util/errors.ts +141 -0
  66. package/lib/util/maybe.ts +22 -0
  67. package/lib/util/next.ts +13 -0
  68. package/lib/util/{plugins.js → plugins.ts} +58 -57
  69. package/lib/util/{url.js → url.ts} +64 -83
  70. package/package.json +44 -45
  71. package/cjs/bundle.js +0 -304
  72. package/cjs/dereference.js +0 -258
  73. package/cjs/index.js +0 -603
  74. package/cjs/normalize-args.js +0 -64
  75. package/cjs/options.js +0 -125
  76. package/cjs/package.json +0 -3
  77. package/cjs/parse.js +0 -338
  78. package/cjs/parsers/binary.js +0 -54
  79. package/cjs/parsers/json.js +0 -199
  80. package/cjs/parsers/text.js +0 -61
  81. package/cjs/parsers/yaml.js +0 -239
  82. package/cjs/pointer.js +0 -290
  83. package/cjs/ref.js +0 -333
  84. package/cjs/refs.js +0 -214
  85. package/cjs/resolve-external.js +0 -333
  86. package/cjs/resolvers/file.js +0 -106
  87. package/cjs/resolvers/http.js +0 -184
  88. package/cjs/util/errors.js +0 -401
  89. package/cjs/util/plugins.js +0 -159
  90. package/cjs/util/projectDir.cjs +0 -6
  91. package/lib/index.d.ts +0 -496
  92. package/lib/index.js +0 -290
  93. package/lib/options.js +0 -128
  94. package/lib/parse.js +0 -162
  95. package/lib/parsers/binary.js +0 -53
  96. package/lib/parsers/text.js +0 -64
  97. package/lib/pointer.js +0 -293
  98. package/lib/ref.js +0 -292
  99. package/lib/refs.js +0 -196
  100. package/lib/resolvers/file.js +0 -63
  101. package/lib/resolvers/http.js +0 -155
  102. package/lib/util/errors.js +0 -134
  103. package/lib/util/projectDir.cjs +0 -6
@@ -0,0 +1,93 @@
1
+ export declare const parse: (u: any) => URL;
2
+ /**
3
+ * Returns resolved target URL relative to a base URL in a manner similar to that of a Web browser resolving an anchor tag HREF.
4
+ *
5
+ * @returns
6
+ */
7
+ export declare function resolve(from: any, to: any): string;
8
+ /**
9
+ * Returns the current working directory (in Node) or the current page URL (in browsers).
10
+ *
11
+ * @returns
12
+ */
13
+ export declare function cwd(): string;
14
+ /**
15
+ * Returns the protocol of the given URL, or `undefined` if it has no protocol.
16
+ *
17
+ * @param path
18
+ * @returns
19
+ */
20
+ export declare function getProtocol(path: any): string | undefined;
21
+ /**
22
+ * Returns the lowercased file extension of the given URL,
23
+ * or an empty string if it has no extension.
24
+ *
25
+ * @param path
26
+ * @returns
27
+ */
28
+ export declare function getExtension(path: any): any;
29
+ /**
30
+ * Removes the query, if any, from the given path.
31
+ *
32
+ * @param path
33
+ * @returns
34
+ */
35
+ export declare function stripQuery(path: any): any;
36
+ /**
37
+ * Returns the hash (URL fragment), of the given path.
38
+ * If there is no hash, then the root hash ("#") is returned.
39
+ *
40
+ * @param path
41
+ * @returns
42
+ */
43
+ export declare function getHash(path: any): any;
44
+ /**
45
+ * Removes the hash (URL fragment), if any, from the given path.
46
+ *
47
+ * @param path
48
+ * @returns
49
+ */
50
+ export declare function stripHash(path: any): any;
51
+ /**
52
+ * Determines whether the given path is an HTTP(S) URL.
53
+ *
54
+ * @param path
55
+ * @returns
56
+ */
57
+ export declare function isHttp(path: any): boolean;
58
+ /**
59
+ * Determines whether the given path is a filesystem path.
60
+ * This includes "file://" URLs.
61
+ *
62
+ * @param path
63
+ * @returns
64
+ */
65
+ export declare function isFileSystemPath(path: any): boolean;
66
+ /**
67
+ * Converts a filesystem path to a properly-encoded URL.
68
+ *
69
+ * This is intended to handle situations where JSON Schema $Ref Parser is called
70
+ * with a filesystem path that contains characters which are not allowed in URLs.
71
+ *
72
+ * @example
73
+ * The following filesystem paths would be converted to the following URLs:
74
+ *
75
+ * <"!@#$%^&*+=?'>.json ==> %3C%22!@%23$%25%5E&*+=%3F\'%3E.json
76
+ * C:\\My Documents\\File (1).json ==> C:/My%20Documents/File%20(1).json
77
+ * file://Project #42/file.json ==> file://Project%20%2342/file.json
78
+ *
79
+ * @param path
80
+ * @returns
81
+ */
82
+ export declare function fromFileSystemPath(path: any): any;
83
+ /**
84
+ * Converts a URL to a local filesystem path.
85
+ */
86
+ export declare function toFileSystemPath(path: string | undefined, keepFileProtocol?: boolean): string;
87
+ /**
88
+ * Converts a $ref pointer to a valid JSON Path.
89
+ *
90
+ * @param pointer
91
+ * @returns
92
+ */
93
+ export declare function safePointerToPath(pointer: any): any;
@@ -1,170 +1,186 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
6
- for(var name in all)Object.defineProperty(target, name, {
7
- enumerable: true,
8
- get: all[name]
9
- });
10
- }
11
- _export(exports, {
12
- parse: function() {
13
- return parse;
14
- },
15
- resolve: function() {
16
- return resolve;
17
- },
18
- cwd: function() {
19
- return cwd;
20
- },
21
- getProtocol: function() {
22
- return getProtocol;
23
- },
24
- getExtension: function() {
25
- return getExtension;
26
- },
27
- stripQuery: function() {
28
- return stripQuery;
29
- },
30
- getHash: function() {
31
- return getHash;
32
- },
33
- stripHash: function() {
34
- return stripHash;
35
- },
36
- isHttp: function() {
37
- return isHttp;
38
- },
39
- isFileSystemPath: function() {
40
- return isFileSystemPath;
41
- },
42
- fromFileSystemPath: function() {
43
- return fromFileSystemPath;
44
- },
45
- toFileSystemPath: function() {
46
- return toFileSystemPath;
47
- },
48
- safePointerToPath: function() {
49
- return safePointerToPath;
50
- }
51
- });
52
- var _projectDirCjs = /*#__PURE__*/ _interopRequireDefault(require("./projectDir.cjs"));
53
- function _interopRequireDefault(obj) {
54
- return obj && obj.__esModule ? obj : {
55
- default: obj
56
- };
57
- }
58
- var isWindows = /^win/.test(globalThis.process ? globalThis.process.platform : undefined), forwardSlashPattern = /\//g, protocolPattern = /^(\w{2,}):\/\//i, jsonPointerSlash = /~1/g, jsonPointerTilde = /~0/g;
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.safePointerToPath = exports.toFileSystemPath = exports.fromFileSystemPath = exports.isFileSystemPath = exports.isHttp = exports.stripHash = exports.getHash = exports.stripQuery = exports.getExtension = exports.getProtocol = exports.cwd = exports.resolve = exports.parse = void 0;
4
+ const isWindows = /^win/.test(globalThis.process ? globalThis.process.platform : ""), forwardSlashPattern = /\//g, protocolPattern = /^(\w{2,}):\/\//i, jsonPointerSlash = /~1/g, jsonPointerTilde = /~0/g;
5
+ const path_1 = require("path");
6
+ const projectDir = (0, path_1.join)(__dirname, "..", "..");
59
7
  // RegExp patterns to URL-encode special characters in local filesystem paths
60
- var urlEncodePatterns = [
61
- /\?/g,
62
- "%3F",
63
- /\#/g,
64
- "%23"
65
- ];
8
+ const urlEncodePatterns = [/\?/g, "%3F", /#/g, "%23"];
66
9
  // RegExp patterns to URL-decode special characters for local filesystem paths
67
- var urlDecodePatterns = [
68
- /\%23/g,
69
- "#",
70
- /\%24/g,
71
- "$",
72
- /\%26/g,
73
- "&",
74
- /\%2C/g,
75
- ",",
76
- /\%40/g,
77
- "@"
78
- ];
79
- var parse = function(u) {
80
- return new URL(u);
81
- };
10
+ const urlDecodePatterns = [/%23/g, "#", /%24/g, "$", /%26/g, "&", /%2C/g, ",", /%40/g, "@"];
11
+ const parse = (u) => new URL(u);
12
+ exports.parse = parse;
13
+ /**
14
+ * Returns resolved target URL relative to a base URL in a manner similar to that of a Web browser resolving an anchor tag HREF.
15
+ *
16
+ * @returns
17
+ */
82
18
  function resolve(from, to) {
83
- var resolvedUrl = new URL(to, new URL(from, "resolve://"));
19
+ const resolvedUrl = new URL(to, new URL(from, "resolve://"));
84
20
  if (resolvedUrl.protocol === "resolve:") {
85
21
  // `from` is a relative URL.
86
- var pathname = resolvedUrl.pathname, search = resolvedUrl.search, hash = resolvedUrl.hash;
22
+ const { pathname, search, hash } = resolvedUrl;
87
23
  return pathname + search + hash;
88
24
  }
89
25
  return resolvedUrl.toString();
90
26
  }
27
+ exports.resolve = resolve;
28
+ /**
29
+ * Returns the current working directory (in Node) or the current page URL (in browsers).
30
+ *
31
+ * @returns
32
+ */
91
33
  function cwd() {
92
34
  if (typeof window !== "undefined") {
93
35
  return location.href;
94
36
  }
95
- var path = process.cwd();
96
- var lastChar = path.slice(-1);
37
+ const path = process.cwd();
38
+ const lastChar = path.slice(-1);
97
39
  if (lastChar === "/" || lastChar === "\\") {
98
40
  return path;
99
- } else {
41
+ }
42
+ else {
100
43
  return path + "/";
101
44
  }
102
45
  }
46
+ exports.cwd = cwd;
47
+ /**
48
+ * Returns the protocol of the given URL, or `undefined` if it has no protocol.
49
+ *
50
+ * @param path
51
+ * @returns
52
+ */
103
53
  function getProtocol(path) {
104
- var match = protocolPattern.exec(path);
54
+ const match = protocolPattern.exec(path);
105
55
  if (match) {
106
56
  return match[1].toLowerCase();
107
57
  }
108
58
  }
59
+ exports.getProtocol = getProtocol;
60
+ /**
61
+ * Returns the lowercased file extension of the given URL,
62
+ * or an empty string if it has no extension.
63
+ *
64
+ * @param path
65
+ * @returns
66
+ */
109
67
  function getExtension(path) {
110
- var lastDot = path.lastIndexOf(".");
68
+ const lastDot = path.lastIndexOf(".");
111
69
  if (lastDot >= 0) {
112
70
  return stripQuery(path.substr(lastDot).toLowerCase());
113
71
  }
114
72
  return "";
115
73
  }
74
+ exports.getExtension = getExtension;
75
+ /**
76
+ * Removes the query, if any, from the given path.
77
+ *
78
+ * @param path
79
+ * @returns
80
+ */
116
81
  function stripQuery(path) {
117
- var queryIndex = path.indexOf("?");
82
+ const queryIndex = path.indexOf("?");
118
83
  if (queryIndex >= 0) {
119
84
  path = path.substr(0, queryIndex);
120
85
  }
121
86
  return path;
122
87
  }
88
+ exports.stripQuery = stripQuery;
89
+ /**
90
+ * Returns the hash (URL fragment), of the given path.
91
+ * If there is no hash, then the root hash ("#") is returned.
92
+ *
93
+ * @param path
94
+ * @returns
95
+ */
123
96
  function getHash(path) {
124
- var hashIndex = path.indexOf("#");
97
+ const hashIndex = path.indexOf("#");
125
98
  if (hashIndex >= 0) {
126
99
  return path.substr(hashIndex);
127
100
  }
128
101
  return "#";
129
102
  }
103
+ exports.getHash = getHash;
104
+ /**
105
+ * Removes the hash (URL fragment), if any, from the given path.
106
+ *
107
+ * @param path
108
+ * @returns
109
+ */
130
110
  function stripHash(path) {
131
- var hashIndex = path.indexOf("#");
111
+ const hashIndex = path.indexOf("#");
132
112
  if (hashIndex >= 0) {
133
113
  path = path.substr(0, hashIndex);
134
114
  }
135
115
  return path;
136
116
  }
117
+ exports.stripHash = stripHash;
118
+ /**
119
+ * Determines whether the given path is an HTTP(S) URL.
120
+ *
121
+ * @param path
122
+ * @returns
123
+ */
137
124
  function isHttp(path) {
138
- var protocol = getProtocol(path);
125
+ const protocol = getProtocol(path);
139
126
  if (protocol === "http" || protocol === "https") {
140
127
  return true;
141
- } else if (protocol === undefined) {
128
+ }
129
+ else if (protocol === undefined) {
142
130
  // There is no protocol. If we're running in a browser, then assume it's HTTP.
143
131
  return typeof window !== "undefined";
144
- } else {
132
+ }
133
+ else {
145
134
  // It's some other protocol, such as "ftp://", "mongodb://", etc.
146
135
  return false;
147
136
  }
148
137
  }
138
+ exports.isHttp = isHttp;
139
+ /**
140
+ * Determines whether the given path is a filesystem path.
141
+ * This includes "file://" URLs.
142
+ *
143
+ * @param path
144
+ * @returns
145
+ */
149
146
  function isFileSystemPath(path) {
150
- if (process.browser) {
147
+ // @ts-ignore
148
+ if (typeof window !== "undefined" || process.browser) {
151
149
  // We're running in a browser, so assume that all paths are URLs.
152
150
  // This way, even relative paths will be treated as URLs rather than as filesystem paths
153
151
  return false;
154
152
  }
155
- var protocol = getProtocol(path);
153
+ const protocol = getProtocol(path);
156
154
  return protocol === undefined || protocol === "file";
157
155
  }
156
+ exports.isFileSystemPath = isFileSystemPath;
157
+ /**
158
+ * Converts a filesystem path to a properly-encoded URL.
159
+ *
160
+ * This is intended to handle situations where JSON Schema $Ref Parser is called
161
+ * with a filesystem path that contains characters which are not allowed in URLs.
162
+ *
163
+ * @example
164
+ * The following filesystem paths would be converted to the following URLs:
165
+ *
166
+ * <"!@#$%^&*+=?'>.json ==> %3C%22!@%23$%25%5E&*+=%3F\'%3E.json
167
+ * C:\\My Documents\\File (1).json ==> C:/My%20Documents/File%20(1).json
168
+ * file://Project #42/file.json ==> file://Project%20%2342/file.json
169
+ *
170
+ * @param path
171
+ * @returns
172
+ */
158
173
  function fromFileSystemPath(path) {
159
174
  // Step 1: On Windows, replace backslashes with forward slashes,
160
175
  // rather than encoding them as "%5C"
161
176
  if (isWindows) {
162
- var hasProjectDir = path.toUpperCase().includes(_projectDirCjs.default.replace(/\\/g, "\\").toUpperCase());
163
- var hasProjectUri = path.toUpperCase().includes(_projectDirCjs.default.replace(/\\/g, "/").toUpperCase());
177
+ const hasProjectDir = path.toUpperCase().includes(projectDir.replace(/\\/g, "\\").toUpperCase());
178
+ const hasProjectUri = path.toUpperCase().includes(projectDir.replace(/\\/g, "/").toUpperCase());
164
179
  if (hasProjectDir || hasProjectUri) {
165
180
  path = path.replace(/\\/g, "/");
166
- } else {
167
- path = "".concat(_projectDirCjs.default, "/").concat(path).replace(/\\/g, "/");
181
+ }
182
+ else {
183
+ path = `${projectDir}/${path}`.replace(/\\/g, "/");
168
184
  }
169
185
  }
170
186
  // Step 2: `encodeURI` will take care of MOST characters
@@ -172,23 +188,27 @@ function fromFileSystemPath(path) {
172
188
  // Step 3: Manually encode characters that are not encoded by `encodeURI`.
173
189
  // This includes characters such as "#" and "?", which have special meaning in URLs,
174
190
  // but are just normal characters in a filesystem path.
175
- for(var i = 0; i < urlEncodePatterns.length; i += 2){
191
+ for (let i = 0; i < urlEncodePatterns.length; i += 2) {
176
192
  path = path.replace(urlEncodePatterns[i], urlEncodePatterns[i + 1]);
177
193
  }
178
194
  return path;
179
195
  }
196
+ exports.fromFileSystemPath = fromFileSystemPath;
197
+ /**
198
+ * Converts a URL to a local filesystem path.
199
+ */
180
200
  function toFileSystemPath(path, keepFileProtocol) {
181
201
  // Step 1: `decodeURI` will decode characters such as Cyrillic characters, spaces, etc.
182
202
  path = decodeURI(path);
183
203
  // Step 2: Manually decode characters that are not decoded by `decodeURI`.
184
204
  // This includes characters such as "#" and "?", which have special meaning in URLs,
185
205
  // but are just normal characters in a filesystem path.
186
- for(var i = 0; i < urlDecodePatterns.length; i += 2){
206
+ for (let i = 0; i < urlDecodePatterns.length; i += 2) {
187
207
  path = path.replace(urlDecodePatterns[i], urlDecodePatterns[i + 1]);
188
208
  }
189
209
  // Step 3: If it's a "file://" URL, then format it consistently
190
210
  // or convert it to a local filesystem path
191
- var isFileUrl = path.substr(0, 7).toLowerCase() === "file://";
211
+ let isFileUrl = path.substr(0, 7).toLowerCase() === "file://";
192
212
  if (isFileUrl) {
193
213
  // Strip-off the protocol, and the initial "/", if there is one
194
214
  path = path[7] === "/" ? path.substr(8) : path.substr(7);
@@ -199,7 +219,8 @@ function toFileSystemPath(path, keepFileProtocol) {
199
219
  if (keepFileProtocol) {
200
220
  // Return the consistently-formatted "file://" URL
201
221
  path = "file:///" + path;
202
- } else {
222
+ }
223
+ else {
203
224
  // Convert the "file://" URL to a local filesystem path.
204
225
  // On Windows, it will start with something like "C:/".
205
226
  // On Posix, it will start with "/"
@@ -218,11 +239,22 @@ function toFileSystemPath(path, keepFileProtocol) {
218
239
  }
219
240
  return path;
220
241
  }
242
+ exports.toFileSystemPath = toFileSystemPath;
243
+ /**
244
+ * Converts a $ref pointer to a valid JSON Path.
245
+ *
246
+ * @param pointer
247
+ * @returns
248
+ */
221
249
  function safePointerToPath(pointer) {
222
250
  if (pointer.length <= 1 || pointer[0] !== "#" || pointer[1] !== "/") {
223
251
  return [];
224
252
  }
225
- return pointer.slice(2).split("/").map(function(value) {
253
+ return pointer
254
+ .slice(2)
255
+ .split("/")
256
+ .map((value) => {
226
257
  return decodeURIComponent(value).replace(jsonPointerSlash, "/").replace(jsonPointerTilde, "~");
227
258
  });
228
259
  }
260
+ exports.safePointerToPath = safePointerToPath;
@@ -0,0 +1,2 @@
1
+ declare const _default: import("vitest/dist/config").UserConfigExport;
2
+ export default _default;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const config_1 = require("vitest/config");
4
+ const isBrowser = process.env.BROWSER === "true";
5
+ exports.default = (0, config_1.defineConfig)({
6
+ test: {
7
+ environment: isBrowser ? "jsdom" : "node",
8
+ dir: "test",
9
+ exclude: ["**/__IGNORED__/**"],
10
+ watch: false,
11
+ globalSetup: isBrowser ? ["./test/fixtures/server.ts"] : undefined,
12
+ setupFiles: isBrowser ? ["./test/fixtures/polyfill.ts"] : undefined,
13
+ testTimeout: 5000,
14
+ globals: true,
15
+ passWithNoTests: true,
16
+ reporters: ["verbose"],
17
+ coverage: { reporter: ["lcov", "html", "text"] },
18
+ deps: {
19
+ fallbackCJS: true,
20
+ registerNodeLoader: true,
21
+ },
22
+ },
23
+ });