@apidevtools/json-schema-ref-parser 11.8.2 → 11.9.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.
- package/README.md +3 -3
- package/dist/lib/dereference.js +21 -0
- package/dist/lib/options.d.ts +10 -0
- package/lib/dereference.ts +24 -0
- package/lib/options.ts +10 -0
- package/lib/util/errors.ts +1 -1
- package/package.json +1 -1
- package/cjs/bundle.js +0 -304
- package/cjs/dereference.js +0 -258
- package/cjs/index.js +0 -603
- package/cjs/normalize-args.js +0 -64
- package/cjs/options.js +0 -125
- package/cjs/package.json +0 -3
- package/cjs/parse.js +0 -338
- package/cjs/parsers/binary.js +0 -54
- package/cjs/parsers/json.js +0 -199
- package/cjs/parsers/text.js +0 -61
- package/cjs/parsers/yaml.js +0 -239
- package/cjs/pointer.js +0 -290
- package/cjs/ref.js +0 -333
- package/cjs/refs.js +0 -214
- package/cjs/resolve-external.js +0 -333
- package/cjs/resolvers/file.js +0 -106
- package/cjs/resolvers/http.js +0 -184
- package/cjs/util/errors.js +0 -401
- package/cjs/util/plugins.js +0 -159
- package/cjs/util/projectDir.cjs +0 -6
- package/cjs/util/url.js +0 -228
package/cjs/util/plugins.js
DELETED
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Returns the given plugins as an array, rather than an object map.
|
|
3
|
-
* All other methods in this module expect an array of plugins rather than an object map.
|
|
4
|
-
*
|
|
5
|
-
* @param {object} plugins - A map of plugin objects
|
|
6
|
-
* @return {object[]}
|
|
7
|
-
*/ "use strict";
|
|
8
|
-
Object.defineProperty(exports, "__esModule", {
|
|
9
|
-
value: true
|
|
10
|
-
});
|
|
11
|
-
function _export(target, all) {
|
|
12
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: all[name]
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
_export(exports, {
|
|
18
|
-
all: function() {
|
|
19
|
-
return all;
|
|
20
|
-
},
|
|
21
|
-
filter: function() {
|
|
22
|
-
return filter;
|
|
23
|
-
},
|
|
24
|
-
sort: function() {
|
|
25
|
-
return sort;
|
|
26
|
-
},
|
|
27
|
-
run: function() {
|
|
28
|
-
return run;
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
function _instanceof(left, right) {
|
|
32
|
-
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
33
|
-
return !!right[Symbol.hasInstance](left);
|
|
34
|
-
} else {
|
|
35
|
-
return left instanceof right;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
function all(plugins) {
|
|
39
|
-
return Object.keys(plugins).filter(function(key) {
|
|
40
|
-
return typeof plugins[key] === "object";
|
|
41
|
-
}).map(function(key) {
|
|
42
|
-
plugins[key].name = key;
|
|
43
|
-
return plugins[key];
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
function filter(plugins, method, file) {
|
|
47
|
-
return plugins.filter(function(plugin) {
|
|
48
|
-
return !!getResult(plugin, method, file);
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
function sort(plugins) {
|
|
52
|
-
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
53
|
-
try {
|
|
54
|
-
for(var _iterator = plugins[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
55
|
-
var plugin = _step.value;
|
|
56
|
-
plugin.order = plugin.order || Number.MAX_SAFE_INTEGER;
|
|
57
|
-
}
|
|
58
|
-
} catch (err) {
|
|
59
|
-
_didIteratorError = true;
|
|
60
|
-
_iteratorError = err;
|
|
61
|
-
} finally{
|
|
62
|
-
try {
|
|
63
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
64
|
-
_iterator.return();
|
|
65
|
-
}
|
|
66
|
-
} finally{
|
|
67
|
-
if (_didIteratorError) {
|
|
68
|
-
throw _iteratorError;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return plugins.sort(function(a, b) {
|
|
73
|
-
return a.order - b.order;
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
function run(plugins, method, file, $refs) {
|
|
77
|
-
var plugin, lastError, index = 0;
|
|
78
|
-
return new Promise(function(resolve, reject) {
|
|
79
|
-
var runNextPlugin = function runNextPlugin() {
|
|
80
|
-
plugin = plugins[index++];
|
|
81
|
-
if (!plugin) {
|
|
82
|
-
// There are no more functions, so re-throw the last error
|
|
83
|
-
return reject(lastError);
|
|
84
|
-
}
|
|
85
|
-
try {
|
|
86
|
-
// console.log(' %s', plugin.name);
|
|
87
|
-
var result = getResult(plugin, method, file, callback, $refs);
|
|
88
|
-
if (result && typeof result.then === "function") {
|
|
89
|
-
// A promise was returned
|
|
90
|
-
result.then(onSuccess, onError);
|
|
91
|
-
} else if (result !== undefined) {
|
|
92
|
-
// A synchronous result was returned
|
|
93
|
-
onSuccess(result);
|
|
94
|
-
} else if (index === plugins.length) {
|
|
95
|
-
throw new Error("No promise has been returned or callback has been called.");
|
|
96
|
-
}
|
|
97
|
-
} catch (e) {
|
|
98
|
-
onError(e);
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
var callback = function callback(err, result) {
|
|
102
|
-
if (err) {
|
|
103
|
-
onError(err);
|
|
104
|
-
} else {
|
|
105
|
-
onSuccess(result);
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
var onSuccess = function onSuccess(result) {
|
|
109
|
-
// console.log(' success');
|
|
110
|
-
resolve({
|
|
111
|
-
plugin: plugin,
|
|
112
|
-
result: result
|
|
113
|
-
});
|
|
114
|
-
};
|
|
115
|
-
var onError = function onError(error) {
|
|
116
|
-
// console.log(' %s', err.message || err);
|
|
117
|
-
lastError = {
|
|
118
|
-
plugin: plugin,
|
|
119
|
-
error: error
|
|
120
|
-
};
|
|
121
|
-
runNextPlugin();
|
|
122
|
-
};
|
|
123
|
-
runNextPlugin();
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* Returns the value of the given property.
|
|
128
|
-
* If the property is a function, then the result of the function is returned.
|
|
129
|
-
* If the value is a RegExp, then it will be tested against the file URL.
|
|
130
|
-
* If the value is an aray, then it will be compared against the file extension.
|
|
131
|
-
*
|
|
132
|
-
* @param {object} obj - The object whose property/method is called
|
|
133
|
-
* @param {string} prop - The name of the property/method to invoke
|
|
134
|
-
* @param {object} file - A file info object, which will be passed to the method
|
|
135
|
-
* @param {function} [callback] - A callback function, which will be passed to the method
|
|
136
|
-
* @returns {*}
|
|
137
|
-
*/ function getResult(obj, prop, file, callback, $refs) {
|
|
138
|
-
var value = obj[prop];
|
|
139
|
-
if (typeof value === "function") {
|
|
140
|
-
return value.apply(obj, [
|
|
141
|
-
file,
|
|
142
|
-
callback,
|
|
143
|
-
$refs
|
|
144
|
-
]);
|
|
145
|
-
}
|
|
146
|
-
if (!callback) {
|
|
147
|
-
// The synchronous plugin functions (canParse and canRead)
|
|
148
|
-
// allow a "shorthand" syntax, where the user can match
|
|
149
|
-
// files by RegExp or by file extension.
|
|
150
|
-
if (_instanceof(value, RegExp)) {
|
|
151
|
-
return value.test(file.url);
|
|
152
|
-
} else if (typeof value === "string") {
|
|
153
|
-
return value === file.extension;
|
|
154
|
-
} else if (Array.isArray(value)) {
|
|
155
|
-
return value.indexOf(file.extension) !== -1;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
return value;
|
|
159
|
-
}
|
package/cjs/util/projectDir.cjs
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
const nodePath = require("path");
|
|
2
|
-
|
|
3
|
-
// Webpack 4 (used by browser tests) can't transpile import.meta.url
|
|
4
|
-
// So export the project directory using __dirname from a .cjs module
|
|
5
|
-
const projectDir = nodePath.resolve(__dirname, "..", "..");
|
|
6
|
-
module.exports = projectDir
|
package/cjs/util/url.js
DELETED
|
@@ -1,228 +0,0 @@
|
|
|
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;
|
|
59
|
-
// RegExp patterns to URL-encode special characters in local filesystem paths
|
|
60
|
-
var urlEncodePatterns = [
|
|
61
|
-
/\?/g,
|
|
62
|
-
"%3F",
|
|
63
|
-
/\#/g,
|
|
64
|
-
"%23"
|
|
65
|
-
];
|
|
66
|
-
// 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
|
-
};
|
|
82
|
-
function resolve(from, to) {
|
|
83
|
-
var resolvedUrl = new URL(to, new URL(from, "resolve://"));
|
|
84
|
-
if (resolvedUrl.protocol === "resolve:") {
|
|
85
|
-
// `from` is a relative URL.
|
|
86
|
-
var pathname = resolvedUrl.pathname, search = resolvedUrl.search, hash = resolvedUrl.hash;
|
|
87
|
-
return pathname + search + hash;
|
|
88
|
-
}
|
|
89
|
-
return resolvedUrl.toString();
|
|
90
|
-
}
|
|
91
|
-
function cwd() {
|
|
92
|
-
if (typeof window !== "undefined") {
|
|
93
|
-
return location.href;
|
|
94
|
-
}
|
|
95
|
-
var path = process.cwd();
|
|
96
|
-
var lastChar = path.slice(-1);
|
|
97
|
-
if (lastChar === "/" || lastChar === "\\") {
|
|
98
|
-
return path;
|
|
99
|
-
} else {
|
|
100
|
-
return path + "/";
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
function getProtocol(path) {
|
|
104
|
-
var match = protocolPattern.exec(path);
|
|
105
|
-
if (match) {
|
|
106
|
-
return match[1].toLowerCase();
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
function getExtension(path) {
|
|
110
|
-
var lastDot = path.lastIndexOf(".");
|
|
111
|
-
if (lastDot >= 0) {
|
|
112
|
-
return stripQuery(path.substr(lastDot).toLowerCase());
|
|
113
|
-
}
|
|
114
|
-
return "";
|
|
115
|
-
}
|
|
116
|
-
function stripQuery(path) {
|
|
117
|
-
var queryIndex = path.indexOf("?");
|
|
118
|
-
if (queryIndex >= 0) {
|
|
119
|
-
path = path.substr(0, queryIndex);
|
|
120
|
-
}
|
|
121
|
-
return path;
|
|
122
|
-
}
|
|
123
|
-
function getHash(path) {
|
|
124
|
-
var hashIndex = path.indexOf("#");
|
|
125
|
-
if (hashIndex >= 0) {
|
|
126
|
-
return path.substr(hashIndex);
|
|
127
|
-
}
|
|
128
|
-
return "#";
|
|
129
|
-
}
|
|
130
|
-
function stripHash(path) {
|
|
131
|
-
var hashIndex = path.indexOf("#");
|
|
132
|
-
if (hashIndex >= 0) {
|
|
133
|
-
path = path.substr(0, hashIndex);
|
|
134
|
-
}
|
|
135
|
-
return path;
|
|
136
|
-
}
|
|
137
|
-
function isHttp(path) {
|
|
138
|
-
var protocol = getProtocol(path);
|
|
139
|
-
if (protocol === "http" || protocol === "https") {
|
|
140
|
-
return true;
|
|
141
|
-
} else if (protocol === undefined) {
|
|
142
|
-
// There is no protocol. If we're running in a browser, then assume it's HTTP.
|
|
143
|
-
return typeof window !== "undefined";
|
|
144
|
-
} else {
|
|
145
|
-
// It's some other protocol, such as "ftp://", "mongodb://", etc.
|
|
146
|
-
return false;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
function isFileSystemPath(path) {
|
|
150
|
-
if (process.browser) {
|
|
151
|
-
// We're running in a browser, so assume that all paths are URLs.
|
|
152
|
-
// This way, even relative paths will be treated as URLs rather than as filesystem paths
|
|
153
|
-
return false;
|
|
154
|
-
}
|
|
155
|
-
var protocol = getProtocol(path);
|
|
156
|
-
return protocol === undefined || protocol === "file";
|
|
157
|
-
}
|
|
158
|
-
function fromFileSystemPath(path) {
|
|
159
|
-
// Step 1: On Windows, replace backslashes with forward slashes,
|
|
160
|
-
// rather than encoding them as "%5C"
|
|
161
|
-
if (isWindows) {
|
|
162
|
-
var hasProjectDir = path.toUpperCase().includes(_projectDirCjs.default.replace(/\\/g, "\\").toUpperCase());
|
|
163
|
-
var hasProjectUri = path.toUpperCase().includes(_projectDirCjs.default.replace(/\\/g, "/").toUpperCase());
|
|
164
|
-
if (hasProjectDir || hasProjectUri) {
|
|
165
|
-
path = path.replace(/\\/g, "/");
|
|
166
|
-
} else {
|
|
167
|
-
path = "".concat(_projectDirCjs.default, "/").concat(path).replace(/\\/g, "/");
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
// Step 2: `encodeURI` will take care of MOST characters
|
|
171
|
-
path = encodeURI(path);
|
|
172
|
-
// Step 3: Manually encode characters that are not encoded by `encodeURI`.
|
|
173
|
-
// This includes characters such as "#" and "?", which have special meaning in URLs,
|
|
174
|
-
// but are just normal characters in a filesystem path.
|
|
175
|
-
for(var i = 0; i < urlEncodePatterns.length; i += 2){
|
|
176
|
-
path = path.replace(urlEncodePatterns[i], urlEncodePatterns[i + 1]);
|
|
177
|
-
}
|
|
178
|
-
return path;
|
|
179
|
-
}
|
|
180
|
-
function toFileSystemPath(path, keepFileProtocol) {
|
|
181
|
-
// Step 1: `decodeURI` will decode characters such as Cyrillic characters, spaces, etc.
|
|
182
|
-
path = decodeURI(path);
|
|
183
|
-
// Step 2: Manually decode characters that are not decoded by `decodeURI`.
|
|
184
|
-
// This includes characters such as "#" and "?", which have special meaning in URLs,
|
|
185
|
-
// but are just normal characters in a filesystem path.
|
|
186
|
-
for(var i = 0; i < urlDecodePatterns.length; i += 2){
|
|
187
|
-
path = path.replace(urlDecodePatterns[i], urlDecodePatterns[i + 1]);
|
|
188
|
-
}
|
|
189
|
-
// Step 3: If it's a "file://" URL, then format it consistently
|
|
190
|
-
// or convert it to a local filesystem path
|
|
191
|
-
var isFileUrl = path.substr(0, 7).toLowerCase() === "file://";
|
|
192
|
-
if (isFileUrl) {
|
|
193
|
-
// Strip-off the protocol, and the initial "/", if there is one
|
|
194
|
-
path = path[7] === "/" ? path.substr(8) : path.substr(7);
|
|
195
|
-
// insert a colon (":") after the drive letter on Windows
|
|
196
|
-
if (isWindows && path[1] === "/") {
|
|
197
|
-
path = path[0] + ":" + path.substr(1);
|
|
198
|
-
}
|
|
199
|
-
if (keepFileProtocol) {
|
|
200
|
-
// Return the consistently-formatted "file://" URL
|
|
201
|
-
path = "file:///" + path;
|
|
202
|
-
} else {
|
|
203
|
-
// Convert the "file://" URL to a local filesystem path.
|
|
204
|
-
// On Windows, it will start with something like "C:/".
|
|
205
|
-
// On Posix, it will start with "/"
|
|
206
|
-
isFileUrl = false;
|
|
207
|
-
path = isWindows ? path : "/" + path;
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
// Step 4: Normalize Windows paths (unless it's a "file://" URL)
|
|
211
|
-
if (isWindows && !isFileUrl) {
|
|
212
|
-
// Replace forward slashes with backslashes
|
|
213
|
-
path = path.replace(forwardSlashPattern, "\\");
|
|
214
|
-
// Capitalize the drive letter
|
|
215
|
-
if (path.substr(1, 2) === ":\\") {
|
|
216
|
-
path = path[0].toUpperCase() + path.substr(1);
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
return path;
|
|
220
|
-
}
|
|
221
|
-
function safePointerToPath(pointer) {
|
|
222
|
-
if (pointer.length <= 1 || pointer[0] !== "#" || pointer[1] !== "/") {
|
|
223
|
-
return [];
|
|
224
|
-
}
|
|
225
|
-
return pointer.slice(2).split("/").map(function(value) {
|
|
226
|
-
return decodeURIComponent(value).replace(jsonPointerSlash, "/").replace(jsonPointerTilde, "~");
|
|
227
|
-
});
|
|
228
|
-
}
|