@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
@@ -0,0 +1,199 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "default", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return _default;
9
+ }
10
+ });
11
+ var _errorsJs = require("../util/errors.js");
12
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
13
+ try {
14
+ var info = gen[key](arg);
15
+ var value = info.value;
16
+ } catch (error) {
17
+ reject(error);
18
+ return;
19
+ }
20
+ if (info.done) {
21
+ resolve(value);
22
+ } else {
23
+ Promise.resolve(value).then(_next, _throw);
24
+ }
25
+ }
26
+ function _asyncToGenerator(fn) {
27
+ return function() {
28
+ var self = this, args = arguments;
29
+ return new Promise(function(resolve, reject) {
30
+ var gen = fn.apply(self, args);
31
+ function _next(value) {
32
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
33
+ }
34
+ function _throw(err) {
35
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
36
+ }
37
+ _next(undefined);
38
+ });
39
+ };
40
+ }
41
+ var __generator = (void 0) && (void 0).__generator || function(thisArg, body) {
42
+ var f, y, t, g, _ = {
43
+ label: 0,
44
+ sent: function() {
45
+ if (t[0] & 1) throw t[1];
46
+ return t[1];
47
+ },
48
+ trys: [],
49
+ ops: []
50
+ };
51
+ return g = {
52
+ next: verb(0),
53
+ "throw": verb(1),
54
+ "return": verb(2)
55
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
56
+ return this;
57
+ }), g;
58
+ function verb(n) {
59
+ return function(v) {
60
+ return step([
61
+ n,
62
+ v
63
+ ]);
64
+ };
65
+ }
66
+ function step(op) {
67
+ if (f) throw new TypeError("Generator is already executing.");
68
+ while(_)try {
69
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
70
+ if (y = 0, t) op = [
71
+ op[0] & 2,
72
+ t.value
73
+ ];
74
+ switch(op[0]){
75
+ case 0:
76
+ case 1:
77
+ t = op;
78
+ break;
79
+ case 4:
80
+ _.label++;
81
+ return {
82
+ value: op[1],
83
+ done: false
84
+ };
85
+ case 5:
86
+ _.label++;
87
+ y = op[1];
88
+ op = [
89
+ 0
90
+ ];
91
+ continue;
92
+ case 7:
93
+ op = _.ops.pop();
94
+ _.trys.pop();
95
+ continue;
96
+ default:
97
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
98
+ _ = 0;
99
+ continue;
100
+ }
101
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
102
+ _.label = op[1];
103
+ break;
104
+ }
105
+ if (op[0] === 6 && _.label < t[1]) {
106
+ _.label = t[1];
107
+ t = op;
108
+ break;
109
+ }
110
+ if (t && _.label < t[2]) {
111
+ _.label = t[2];
112
+ _.ops.push(op);
113
+ break;
114
+ }
115
+ if (t[2]) _.ops.pop();
116
+ _.trys.pop();
117
+ continue;
118
+ }
119
+ op = body.call(thisArg, _);
120
+ } catch (e) {
121
+ op = [
122
+ 6,
123
+ e
124
+ ];
125
+ y = 0;
126
+ } finally{
127
+ f = t = 0;
128
+ }
129
+ if (op[0] & 5) throw op[1];
130
+ return {
131
+ value: op[0] ? op[1] : void 0,
132
+ done: true
133
+ };
134
+ }
135
+ };
136
+ var _default = {
137
+ /**
138
+ * The order that this parser will run, in relation to other parsers.
139
+ *
140
+ * @type {number}
141
+ */ order: 100,
142
+ /**
143
+ * Whether to allow "empty" files. This includes zero-byte files, as well as empty JSON objects.
144
+ *
145
+ * @type {boolean}
146
+ */ allowEmpty: true,
147
+ /**
148
+ * Determines whether this parser can parse a given file reference.
149
+ * Parsers that match will be tried, in order, until one successfully parses the file.
150
+ * Parsers that don't match will be skipped, UNLESS none of the parsers match, in which case
151
+ * every parser will be tried.
152
+ *
153
+ * @type {RegExp|string|string[]|function}
154
+ */ canParse: ".json",
155
+ parse: /**
156
+ * Parses the given file as JSON
157
+ *
158
+ * @param {object} file - An object containing information about the referenced file
159
+ * @param {string} file.url - The full URL of the referenced file
160
+ * @param {string} file.extension - The lowercased file extension (e.g. ".txt", ".html", etc.)
161
+ * @param {*} file.data - The file contents. This will be whatever data type was returned by the resolver
162
+ * @returns {Promise}
163
+ */ function parse(file) {
164
+ return _asyncToGenerator(function() {
165
+ var data;
166
+ return __generator(this, function(_state) {
167
+ data = file.data;
168
+ if (Buffer.isBuffer(data)) {
169
+ data = data.toString();
170
+ }
171
+ if (typeof data === "string") {
172
+ if (data.trim().length === 0) {
173
+ return [
174
+ 2
175
+ ]; // This mirrors the YAML behavior
176
+ } else {
177
+ try {
178
+ return [
179
+ 2,
180
+ JSON.parse(data)
181
+ ];
182
+ } catch (e) {
183
+ throw new _errorsJs.ParserError(e.message, file.url);
184
+ }
185
+ }
186
+ } else {
187
+ // data is already a JavaScript value (object, array, number, null, NaN, etc.)
188
+ return [
189
+ 2,
190
+ data
191
+ ];
192
+ }
193
+ return [
194
+ 2
195
+ ];
196
+ });
197
+ })();
198
+ }
199
+ };
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "default", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return _default;
9
+ }
10
+ });
11
+ var _errorsJs = require("../util/errors.js");
12
+ var TEXT_REGEXP = /\.(txt|htm|html|md|xml|js|min|map|css|scss|less|svg)$/i;
13
+ var _default = {
14
+ /**
15
+ * The order that this parser will run, in relation to other parsers.
16
+ *
17
+ * @type {number}
18
+ */ order: 300,
19
+ /**
20
+ * Whether to allow "empty" files (zero bytes).
21
+ *
22
+ * @type {boolean}
23
+ */ allowEmpty: true,
24
+ /**
25
+ * The encoding that the text is expected to be in.
26
+ *
27
+ * @type {string}
28
+ */ encoding: "utf8",
29
+ /**
30
+ * Determines whether this parser can parse a given file reference.
31
+ * Parsers that return true will be tried, in order, until one successfully parses the file.
32
+ * Parsers that return false will be skipped, UNLESS all parsers returned false, in which case
33
+ * every parser will be tried.
34
+ *
35
+ * @param {object} file - An object containing information about the referenced file
36
+ * @param {string} file.url - The full URL of the referenced file
37
+ * @param {string} file.extension - The lowercased file extension (e.g. ".txt", ".html", etc.)
38
+ * @param {*} file.data - The file contents. This will be whatever data type was returned by the resolver
39
+ * @returns {boolean}
40
+ */ canParse: function canParse(file) {
41
+ // Use this parser if the file is a string or Buffer, and has a known text-based extension
42
+ return (typeof file.data === "string" || Buffer.isBuffer(file.data)) && TEXT_REGEXP.test(file.url);
43
+ },
44
+ /**
45
+ * Parses the given file as text
46
+ *
47
+ * @param {object} file - An object containing information about the referenced file
48
+ * @param {string} file.url - The full URL of the referenced file
49
+ * @param {string} file.extension - The lowercased file extension (e.g. ".txt", ".html", etc.)
50
+ * @param {*} file.data - The file contents. This will be whatever data type was returned by the resolver
51
+ * @returns {string}
52
+ */ parse: function parse(file) {
53
+ if (typeof file.data === "string") {
54
+ return file.data;
55
+ } else if (Buffer.isBuffer(file.data)) {
56
+ return file.data.toString(this.encoding);
57
+ } else {
58
+ throw new _errorsJs.ParserError("data is not text", file.url);
59
+ }
60
+ }
61
+ };
@@ -0,0 +1,239 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "default", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return _default;
9
+ }
10
+ });
11
+ var _errorsJs = require("../util/errors.js");
12
+ var _jsYaml = /*#__PURE__*/ _interopRequireWildcard(require("js-yaml"));
13
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
14
+ try {
15
+ var info = gen[key](arg);
16
+ var value = info.value;
17
+ } catch (error) {
18
+ reject(error);
19
+ return;
20
+ }
21
+ if (info.done) {
22
+ resolve(value);
23
+ } else {
24
+ Promise.resolve(value).then(_next, _throw);
25
+ }
26
+ }
27
+ function _asyncToGenerator(fn) {
28
+ return function() {
29
+ var self = this, args = arguments;
30
+ return new Promise(function(resolve, reject) {
31
+ var gen = fn.apply(self, args);
32
+ function _next(value) {
33
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
34
+ }
35
+ function _throw(err) {
36
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
37
+ }
38
+ _next(undefined);
39
+ });
40
+ };
41
+ }
42
+ function _getRequireWildcardCache(nodeInterop) {
43
+ if (typeof WeakMap !== "function") return null;
44
+ var cacheBabelInterop = new WeakMap();
45
+ var cacheNodeInterop = new WeakMap();
46
+ return (_getRequireWildcardCache = function(nodeInterop) {
47
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
48
+ })(nodeInterop);
49
+ }
50
+ function _interopRequireWildcard(obj, nodeInterop) {
51
+ if (!nodeInterop && obj && obj.__esModule) {
52
+ return obj;
53
+ }
54
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
55
+ return {
56
+ default: obj
57
+ };
58
+ }
59
+ var cache = _getRequireWildcardCache(nodeInterop);
60
+ if (cache && cache.has(obj)) {
61
+ return cache.get(obj);
62
+ }
63
+ var newObj = {};
64
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
65
+ for(var key in obj){
66
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
67
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
68
+ if (desc && (desc.get || desc.set)) {
69
+ Object.defineProperty(newObj, key, desc);
70
+ } else {
71
+ newObj[key] = obj[key];
72
+ }
73
+ }
74
+ }
75
+ newObj.default = obj;
76
+ if (cache) {
77
+ cache.set(obj, newObj);
78
+ }
79
+ return newObj;
80
+ }
81
+ var __generator = (void 0) && (void 0).__generator || function(thisArg, body) {
82
+ var f, y, t, g, _ = {
83
+ label: 0,
84
+ sent: function() {
85
+ if (t[0] & 1) throw t[1];
86
+ return t[1];
87
+ },
88
+ trys: [],
89
+ ops: []
90
+ };
91
+ return g = {
92
+ next: verb(0),
93
+ "throw": verb(1),
94
+ "return": verb(2)
95
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
96
+ return this;
97
+ }), g;
98
+ function verb(n) {
99
+ return function(v) {
100
+ return step([
101
+ n,
102
+ v
103
+ ]);
104
+ };
105
+ }
106
+ function step(op) {
107
+ if (f) throw new TypeError("Generator is already executing.");
108
+ while(_)try {
109
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
110
+ if (y = 0, t) op = [
111
+ op[0] & 2,
112
+ t.value
113
+ ];
114
+ switch(op[0]){
115
+ case 0:
116
+ case 1:
117
+ t = op;
118
+ break;
119
+ case 4:
120
+ _.label++;
121
+ return {
122
+ value: op[1],
123
+ done: false
124
+ };
125
+ case 5:
126
+ _.label++;
127
+ y = op[1];
128
+ op = [
129
+ 0
130
+ ];
131
+ continue;
132
+ case 7:
133
+ op = _.ops.pop();
134
+ _.trys.pop();
135
+ continue;
136
+ default:
137
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
138
+ _ = 0;
139
+ continue;
140
+ }
141
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
142
+ _.label = op[1];
143
+ break;
144
+ }
145
+ if (op[0] === 6 && _.label < t[1]) {
146
+ _.label = t[1];
147
+ t = op;
148
+ break;
149
+ }
150
+ if (t && _.label < t[2]) {
151
+ _.label = t[2];
152
+ _.ops.push(op);
153
+ break;
154
+ }
155
+ if (t[2]) _.ops.pop();
156
+ _.trys.pop();
157
+ continue;
158
+ }
159
+ op = body.call(thisArg, _);
160
+ } catch (e) {
161
+ op = [
162
+ 6,
163
+ e
164
+ ];
165
+ y = 0;
166
+ } finally{
167
+ f = t = 0;
168
+ }
169
+ if (op[0] & 5) throw op[1];
170
+ return {
171
+ value: op[0] ? op[1] : void 0,
172
+ done: true
173
+ };
174
+ }
175
+ };
176
+ var _default = {
177
+ /**
178
+ * The order that this parser will run, in relation to other parsers.
179
+ *
180
+ * @type {number}
181
+ */ order: 200,
182
+ /**
183
+ * Whether to allow "empty" files. This includes zero-byte files, as well as empty JSON objects.
184
+ *
185
+ * @type {boolean}
186
+ */ allowEmpty: true,
187
+ /**
188
+ * Determines whether this parser can parse a given file reference.
189
+ * Parsers that match will be tried, in order, until one successfully parses the file.
190
+ * Parsers that don't match will be skipped, UNLESS none of the parsers match, in which case
191
+ * every parser will be tried.
192
+ *
193
+ * @type {RegExp|string[]|function}
194
+ */ canParse: [
195
+ ".yaml",
196
+ ".yml",
197
+ ".json"
198
+ ],
199
+ parse: /**
200
+ * Parses the given file as YAML
201
+ *
202
+ * @param {object} file - An object containing information about the referenced file
203
+ * @param {string} file.url - The full URL of the referenced file
204
+ * @param {string} file.extension - The lowercased file extension (e.g. ".txt", ".html", etc.)
205
+ * @param {*} file.data - The file contents. This will be whatever data type was returned by the resolver
206
+ * @returns {Promise}
207
+ */ function parse(file) {
208
+ return _asyncToGenerator(function() {
209
+ var data;
210
+ return __generator(this, function(_state) {
211
+ data = file.data;
212
+ if (Buffer.isBuffer(data)) {
213
+ data = data.toString();
214
+ }
215
+ if (typeof data === "string") {
216
+ try {
217
+ return [
218
+ 2,
219
+ _jsYaml.default.load(data, {
220
+ schema: _jsYaml.JSON_SCHEMA
221
+ })
222
+ ];
223
+ } catch (e) {
224
+ throw new _errorsJs.ParserError(e.message, file.url);
225
+ }
226
+ } else {
227
+ // data is already a JavaScript value (object, array, number, null, NaN, etc.)
228
+ return [
229
+ 2,
230
+ data
231
+ ];
232
+ }
233
+ return [
234
+ 2
235
+ ];
236
+ });
237
+ })();
238
+ }
239
+ };