@json-schema-tools/reference-resolver 1.2.3 → 1.2.4

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.
@@ -41,7 +41,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
41
41
  Object.defineProperty(exports, "__esModule", { value: true });
42
42
  var errors_1 = require("./errors");
43
43
  var isomorphic_fetch_1 = __importDefault(require("isomorphic-fetch"));
44
- var fetchHandler = function (uri) { return __awaiter(void 0, void 0, void 0, function () {
44
+ var fetchHandler = function (uri, root) { return __awaiter(void 0, void 0, void 0, function () {
45
45
  var schemaReq, e_1, e_2;
46
46
  return __generator(this, function (_a) {
47
47
  switch (_a.label) {
package/build/index.js CHANGED
@@ -72,6 +72,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
72
72
  var reference_resolver_1 = __importDefault(require("./reference-resolver"));
73
73
  var fs = __importStar(require("fs"));
74
74
  var default_protocol_handler_map_1 = __importDefault(require("./default-protocol-handler-map"));
75
+ var path_1 = __importDefault(require("path"));
75
76
  var fileExistsAndReadable = function (f) {
76
77
  return new Promise(function (resolve) {
77
78
  return fs.access(f, fs.constants.F_OK | fs.constants.R_OK, function (e) {
@@ -85,18 +86,30 @@ var fileExistsAndReadable = function (f) {
85
86
  var readFile = function (f) {
86
87
  return new Promise(function (resolve) { return fs.readFile(f, "utf8", function (err, data) { return resolve(data); }); });
87
88
  };
88
- var nodeProtocolHandlerMap = __assign(__assign({}, default_protocol_handler_map_1.default), { "file": function (uri) { return __awaiter(void 0, void 0, void 0, function () {
89
- var fileContents;
90
- return __generator(this, function (_a) {
91
- switch (_a.label) {
92
- case 0: return [4 /*yield*/, fileExistsAndReadable(uri)];
89
+ var nodeProtocolHandlerMap = __assign(__assign({}, default_protocol_handler_map_1.default), { "file": function (uri, root) { return __awaiter(void 0, void 0, void 0, function () {
90
+ var filePath, ref, _a, fileContents;
91
+ return __generator(this, function (_b) {
92
+ switch (_b.label) {
93
+ case 0:
94
+ filePath = uri;
95
+ ref = root.$ref;
96
+ _a = ref && ref !== uri;
97
+ if (!_a) return [3 /*break*/, 2];
98
+ return [4 /*yield*/, fileExistsAndReadable(ref)];
93
99
  case 1:
94
- if (!((_a.sent()) === true)) return [3 /*break*/, 3];
95
- return [4 /*yield*/, readFile(uri)];
100
+ _a = (_b.sent());
101
+ _b.label = 2;
96
102
  case 2:
97
- fileContents = _a.sent();
103
+ if (_a)
104
+ filePath = path_1.default.parse(ref).dir + "/" + uri;
105
+ return [4 /*yield*/, fileExistsAndReadable(filePath)];
106
+ case 3:
107
+ if (!((_b.sent()) === true)) return [3 /*break*/, 5];
108
+ return [4 /*yield*/, readFile(filePath)];
109
+ case 4:
110
+ fileContents = _b.sent();
98
111
  return [2 /*return*/, JSON.parse(fileContents)];
99
- case 3: return [2 /*return*/];
112
+ case 5: return [2 /*return*/];
100
113
  }
101
114
  });
102
115
  }); } });
@@ -1,6 +1,6 @@
1
1
  import { JSONSchema } from "@json-schema-tools/meta-schema";
2
2
  export interface ProtocolHandlerMap {
3
- [protocol: string]: (uri: string) => Promise<JSONSchema | undefined>;
3
+ [protocol: string]: (uri: string, root: JSONSchema) => Promise<JSONSchema | undefined>;
4
4
  }
5
5
  export default class ReferenceResolver {
6
6
  protocolHandlerMap: ProtocolHandlerMap;
@@ -73,7 +73,7 @@ var ReferenceResolver = /** @class */ (function () {
73
73
  _b.label = 1;
74
74
  case 1:
75
75
  _b.trys.push([1, 3, , 4]);
76
- return [4 /*yield*/, this.protocolHandlerMap.file(hashlessRef)];
76
+ return [4 /*yield*/, this.protocolHandlerMap.file(hashlessRef, root)];
77
77
  case 2:
78
78
  relativePathSchema = _b.sent();
79
79
  return [3 /*break*/, 4];
@@ -97,7 +97,7 @@ var ReferenceResolver = /** @class */ (function () {
97
97
  if (!(_i < _a.length)) return [3 /*break*/, 8];
98
98
  protocol = _a[_i];
99
99
  if (!hashlessRef.startsWith(protocol)) return [3 /*break*/, 7];
100
- return [4 /*yield*/, this.protocolHandlerMap[protocol](hashlessRef)];
100
+ return [4 /*yield*/, this.protocolHandlerMap[protocol](hashlessRef, root)];
101
101
  case 6:
102
102
  maybeSchema = _b.sent();
103
103
  if (maybeSchema !== undefined) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@json-schema-tools/reference-resolver",
3
- "version": "1.2.3",
3
+ "version": "1.2.4",
4
4
  "description": "",
5
5
  "main": "build/index.js",
6
6
  "browser": "build/index-web.js",
package/CHANGELOG.md DELETED
@@ -1,261 +0,0 @@
1
- ## [1.2.3](https://github.com/json-schema-tools/reference-resolver/compare/1.2.2...1.2.3) (2021-06-24)
2
-
3
-
4
- ### Bug Fixes
5
-
6
- * bump meta-schema dep ([0853284](https://github.com/json-schema-tools/reference-resolver/commit/08532840d0f3526ac2daee9c512d421f2f8b5216))
7
-
8
- ## [1.2.2](https://github.com/json-schema-tools/reference-resolver/compare/1.2.1...1.2.2) (2021-06-08)
9
-
10
-
11
- ### Bug Fixes
12
-
13
- * lock typescript version ([92fa412](https://github.com/json-schema-tools/reference-resolver/commit/92fa412653268d4faca5686abfe5f3121b6d4005))
14
- * update deps ([f506b20](https://github.com/json-schema-tools/reference-resolver/commit/f506b20694d48032e2893f3ef25d602fe13cf591))
15
-
16
- ## [1.2.1](https://github.com/json-schema-tools/reference-resolver/compare/1.2.0...1.2.1) (2021-05-10)
17
-
18
-
19
- ### Bug Fixes
20
-
21
- * npm audit fix ([04a0d8b](https://github.com/json-schema-tools/reference-resolver/commit/04a0d8b0ab8fda33ce1ebac74eefe42ad95a98a2))
22
- * update typedoc config ([c876ef2](https://github.com/json-schema-tools/reference-resolver/commit/c876ef2458d99010fdbb68835a37b27ef83eba94))
23
-
24
- # [1.2.0](https://github.com/json-schema-tools/reference-resolver/compare/1.1.1...1.2.0) (2021-05-10)
25
-
26
-
27
- ### Features
28
-
29
- * custom protocols alt ([61ef640](https://github.com/json-schema-tools/reference-resolver/commit/61ef640430de7d077368eb929c6e3b91ffbc8ddf))
30
-
31
- ## [1.1.1](https://github.com/json-schema-tools/reference-resolver/compare/1.1.0...1.1.1) (2020-11-03)
32
-
33
-
34
- ### Bug Fixes
35
-
36
- * refactor code into shared method ([794a8ce](https://github.com/json-schema-tools/reference-resolver/commit/794a8ce0bb22519af0c04992df74e2da7cabc09c))
37
- * return a promise once again ([772302d](https://github.com/json-schema-tools/reference-resolver/commit/772302da07e808f56053be7cde679e6aa52bd8a9))
38
- * use hashless ref for urls ([f278761](https://github.com/json-schema-tools/reference-resolver/commit/f278761c9c934a38de415c9756f2c40b29c8d1cd))
39
-
40
- # [1.1.0](https://github.com/json-schema-tools/reference-resolver/compare/1.0.7...1.1.0) (2020-10-28)
41
-
42
-
43
- ### Bug Fixes
44
-
45
- * make test coverage 100 and fix test case ([84da5c8](https://github.com/json-schema-tools/reference-resolver/commit/84da5c89d282cd99972d745ce52b19517882ccb9))
46
-
47
-
48
- ### Features
49
-
50
- * handle hash fragment of json pointers ([dd85381](https://github.com/json-schema-tools/reference-resolver/commit/dd85381c2b9e08ba9bca4d5beeee351f921c6043))
51
-
52
- ## [1.0.7](https://github.com/json-schema-tools/reference-resolver/compare/1.0.6...1.0.7) (2020-10-27)
53
-
54
-
55
- ### Bug Fixes
56
-
57
- * browser build mock fs not working still ([ffadb24](https://github.com/json-schema-tools/reference-resolver/commit/ffadb240f205d46f8981388188a9abc52e12c28a))
58
-
59
- ## [1.0.6](https://github.com/json-schema-tools/reference-resolver/compare/1.0.5...1.0.6) (2020-10-27)
60
-
61
-
62
- ### Bug Fixes
63
-
64
- * update readme ([e9d42d6](https://github.com/json-schema-tools/reference-resolver/commit/e9d42d61d5651d8988a1d1db317d90aaf4d51a47))
65
-
66
- ## [1.0.5](https://github.com/json-schema-tools/reference-resolver/compare/1.0.4...1.0.5) (2020-10-27)
67
-
68
-
69
- ### Bug Fixes
70
-
71
- * restore browser support ([61e766c](https://github.com/json-schema-tools/reference-resolver/commit/61e766c8fb89a5b413011779188ea39bf64409fc))
72
-
73
- ## [1.0.4](https://github.com/json-schema-tools/reference-resolver/compare/1.0.3...1.0.4) (2020-10-23)
74
-
75
-
76
- ### Bug Fixes
77
-
78
- * oc name ([1d7bcd5](https://github.com/json-schema-tools/reference-resolver/commit/1d7bcd5fbd2db6dab09b9ce8b8fdbea0b202cc1f))
79
-
80
- ## [1.0.3](https://github.com/json-schema-tools/reference-resolver/compare/1.0.2...1.0.3) (2020-10-23)
81
-
82
-
83
- ### Bug Fixes
84
-
85
- * add funding ([959d046](https://github.com/json-schema-tools/reference-resolver/commit/959d046457a270281d2cabfcdd0b97c72033b78b))
86
-
87
- ## [1.0.2](https://github.com/json-schema-tools/reference-resolver/compare/1.0.1...1.0.2) (2020-10-17)
88
-
89
-
90
- ### Bug Fixes
91
-
92
- * add more tests to clarify file reference relativity ([485fcbb](https://github.com/json-schema-tools/reference-resolver/commit/485fcbbe7bfd2c149249becb204784ece789a71d))
93
- * handle filepath error checks differently ([8e7e69f](https://github.com/json-schema-tools/reference-resolver/commit/8e7e69f2b42723fdacb6b5ce0918253a9bd2464c))
94
- * update node version ([1779adb](https://github.com/json-schema-tools/reference-resolver/commit/1779adb0a10e6d2b796ffebaf884254076977065))
95
- * update remaining deps ([d4e2b62](https://github.com/json-schema-tools/reference-resolver/commit/d4e2b62296b955df2cfdc741d5d225995d768b21))
96
- * update typing deps ([b7c0678](https://github.com/json-schema-tools/reference-resolver/commit/b7c06786c8ae74bc173acec0a2088bf9f5e5c199))
97
-
98
- ## [1.0.1](https://github.com/json-schema-tools/reference-resolver/compare/1.0.0...1.0.1) (2020-10-17)
99
-
100
-
101
- ### Bug Fixes
102
-
103
- * add badges to readme ([7386eb6](https://github.com/json-schema-tools/reference-resolver/commit/7386eb603eb234749238f4c59fb304896fa3d668))
104
-
105
- # 1.0.0 (2020-07-23)
106
-
107
-
108
- ### Bug Fixes
109
-
110
- * update doc configs ([cc1ce8a](https://github.com/json-schema-tools/reference-resolver/commit/cc1ce8a587d1b3d9eae0bb8aaf8d266450f37746))
111
- * update package-lock ([310627b](https://github.com/json-schema-tools/reference-resolver/commit/310627b56e23ae306bc4a648d396a53dbbee5efe))
112
-
113
-
114
- ### Features
115
-
116
- * first commit ([2b3da1a](https://github.com/json-schema-tools/reference-resolver/commit/2b3da1a9bf39695ebd8b2c387790ccea9c87f4fa))
117
-
118
- # [1.1.0](https://github.com/json-schema-tools/dereferencer/compare/1.0.15...1.1.0) (2020-07-21)
119
-
120
-
121
- ### Bug Fixes
122
-
123
- * remove hold ([df2f3bb](https://github.com/json-schema-tools/dereferencer/commit/df2f3bb325a112b11f21e0901511b48471c2b009))
124
- * update package json meta a little bit ([cb257fe](https://github.com/json-schema-tools/dereferencer/commit/cb257fe0dd9e5273c062fc5fb91b9896929c72ab))
125
-
126
-
127
- ### Features
128
-
129
- * update to new meta schema and traverse ([b42fb4a](https://github.com/json-schema-tools/dereferencer/commit/b42fb4a82d32918f01c9a2631290923ec5c2c406))
130
-
131
- ## [1.0.15](https://github.com/json-schema-tools/dereferencer/compare/1.0.14...1.0.15) (2020-07-20)
132
-
133
-
134
- ### Bug Fixes
135
-
136
- * update docs ([2027221](https://github.com/json-schema-tools/dereferencer/commit/202722104d999aa096995762f240d11dc30080a7))
137
- * update to latest traverse ([ed5e95a](https://github.com/json-schema-tools/dereferencer/commit/ed5e95a164d9b4f708cf34ef8206b7e35f086b4b))
138
-
139
- ## [1.0.14](https://github.com/json-schema-tools/dereferencer/compare/1.0.13...1.0.14) (2020-07-15)
140
-
141
-
142
- ### Bug Fixes
143
-
144
- * update to new traverse ([45ab188](https://github.com/json-schema-tools/dereferencer/commit/45ab188e5cab557e84c9cc588e0d60d64f822ddf))
145
-
146
- ## [1.0.13](https://github.com/json-schema-tools/dereferencer/compare/1.0.12...1.0.13) (2020-07-07)
147
-
148
-
149
- ### Bug Fixes
150
-
151
- * remove definitions key after dereffing ([ed43c3f](https://github.com/json-schema-tools/dereferencer/commit/ed43c3f8f36d83a576713f1300e8b91d65ae9e59))
152
-
153
- ## [1.0.12](https://github.com/json-schema-tools/dereferencer/compare/1.0.11...1.0.12) (2020-07-07)
154
-
155
-
156
- ### Bug Fixes
157
-
158
- * update traverse again ([e4286c7](https://github.com/json-schema-tools/dereferencer/commit/e4286c76cae8cdbbb453a14ece8bf969b3bf270f))
159
-
160
- ## [1.0.11](https://github.com/json-schema-tools/dereferencer/compare/1.0.10...1.0.11) (2020-07-07)
161
-
162
-
163
- ### Bug Fixes
164
-
165
- * update traverse with cycle fix ([2371305](https://github.com/json-schema-tools/dereferencer/commit/2371305e66b69194327050f163f598d3c0b8968a))
166
-
167
- ## [1.0.10](https://github.com/json-schema-tools/dereferencer/compare/1.0.9...1.0.10) (2020-07-06)
168
-
169
-
170
- ### Bug Fixes
171
-
172
- * gh-pages fixup ([b65d3da](https://github.com/json-schema-tools/dereferencer/commit/b65d3da8e09ee92ae7505e3f7a4edfadac2e3ba7))
173
-
174
- ## [1.0.9](https://github.com/json-schema-tools/dereferencer/compare/1.0.8...1.0.9) (2020-07-06)
175
-
176
-
177
- ### Bug Fixes
178
-
179
- * add test that infinite loops. bed time fuck this shit ([d269fe5](https://github.com/json-schema-tools/dereferencer/commit/d269fe5208082286bac97291492425294f142ef2))
180
- * pre-refactoring ([cf25929](https://github.com/json-schema-tools/dereferencer/commit/cf25929886e73d029f9cff22d6f1cd1cb55ea12a))
181
- * remove commented out garbage ([b2ede0a](https://github.com/json-schema-tools/dereferencer/commit/b2ede0a312009473ceeec1511adcb6a2a25536c0))
182
- * tests passing but logs after tests finish still somehow ([06f2a07](https://github.com/json-schema-tools/dereferencer/commit/06f2a077771b0610884573cfa734e796a797b15b))
183
-
184
- ## [1.0.8](https://github.com/json-schema-tools/dereferencer/compare/1.0.7...1.0.8) (2020-07-03)
185
-
186
-
187
- ### Bug Fixes
188
-
189
- * add comment ([f38a026](https://github.com/json-schema-tools/dereferencer/commit/f38a0268ab9107a101cd606318a0894b14139873))
190
- * add recursive functionality - almost fully working ([baab2be](https://github.com/json-schema-tools/dereferencer/commit/baab2be1d2ebd14e91f27a03a58a25abd6282674))
191
- * make non-recursive mode work proper ([64b1141](https://github.com/json-schema-tools/dereferencer/commit/64b11411be83c5658d7bb67815a47946c6ce144d))
192
- * tests passing now ([8979faa](https://github.com/json-schema-tools/dereferencer/commit/8979faae59990b611c7894923e1a6ba646281c46))
193
- * update deps ([e480e35](https://github.com/json-schema-tools/dereferencer/commit/e480e35630a3b76d551c5e35853bdd0d20547a60))
194
- * update readme ([aef5e13](https://github.com/json-schema-tools/dereferencer/commit/aef5e13ae3b2401eb7192365a94e7bbf634d3dd1))
195
-
196
- ## [1.0.7](https://github.com/json-schema-tools/dereferencer/compare/1.0.6...1.0.7) (2020-07-01)
197
-
198
-
199
- ### Bug Fixes
200
-
201
- * make docs work again ([8c76a2c](https://github.com/json-schema-tools/dereferencer/commit/8c76a2cb834f04eccc6adeb29acb32a66c9b16a7))
202
-
203
- ## [1.0.6](https://github.com/json-schema-tools/dereferencer/compare/1.0.5...1.0.6) (2020-07-01)
204
-
205
-
206
- ### Bug Fixes
207
-
208
- * add node version file ([5eb3576](https://github.com/json-schema-tools/dereferencer/commit/5eb35760d511801482ce24240d6016a284a1cd10))
209
- * update deps ([baa45bf](https://github.com/json-schema-tools/dereferencer/commit/baa45bf612da0023ea9f6af60f8fd41b7fcbeacf))
210
-
211
- ## [1.0.5](https://github.com/json-schema-tools/dereferencer/compare/1.0.4...1.0.5) (2020-06-30)
212
-
213
-
214
- ### Bug Fixes
215
-
216
- * update random shit ([6e11447](https://github.com/json-schema-tools/dereferencer/commit/6e11447593455f0d9118558fe89bfdd83b61ff87))
217
-
218
- ## [1.0.4](https://github.com/json-schema-tools/dereferencer/compare/1.0.3...1.0.4) (2020-06-30)
219
-
220
-
221
- ### Bug Fixes
222
-
223
- * all systems go ([6d051ff](https://github.com/json-schema-tools/dereferencer/commit/6d051ff83a50e2603b61547643b2434d711006af))
224
- * update deps ([4d7dbc7](https://github.com/json-schema-tools/dereferencer/commit/4d7dbc7d587e20b3358f564c98503d857f4daa0e))
225
-
226
- ## [1.0.3](https://github.com/json-schema-tools/dereferencer/compare/1.0.2...1.0.3) (2020-06-27)
227
-
228
-
229
- ### Bug Fixes
230
-
231
- * docs have wrong title ([3fa6316](https://github.com/json-schema-tools/dereferencer/commit/3fa6316dcc5e07b6ce554e948e0840c1a9ffb26d))
232
-
233
- ## [1.0.2](https://github.com/json-schema-tools/dereferencer/compare/1.0.1...1.0.2) (2020-06-27)
234
-
235
-
236
- ### Bug Fixes
237
-
238
- * formatted json proper ([c8d6b34](https://github.com/json-schema-tools/dereferencer/commit/c8d6b34a23b5d597ec4628081ba5ed267ae03b6d))
239
- * improve typedocs ([b0d21ec](https://github.com/json-schema-tools/dereferencer/commit/b0d21ec1878b74b9517e72e218caf48d67ade3fa))
240
- * jsdoc formatting ([9d4f832](https://github.com/json-schema-tools/dereferencer/commit/9d4f832a9397629be9835ab5114a941d1232c750))
241
-
242
- ## [1.0.1](https://github.com/json-schema-tools/dereferencer/compare/1.0.0...1.0.1) (2020-06-26)
243
-
244
-
245
- ### Bug Fixes
246
-
247
- * add funding ([ffda6d9](https://github.com/json-schema-tools/dereferencer/commit/ffda6d963b9d63856f55a7c3614a83b4967482ed))
248
- * put hold in parallel with test and build ([479ed2f](https://github.com/json-schema-tools/dereferencer/commit/479ed2f646d4b7ee821bd9d51a613d88fba4bffc))
249
-
250
- # 1.0.0 (2020-06-26)
251
-
252
-
253
- ### Bug Fixes
254
-
255
- * add circle context ([ebb1b1c](https://github.com/json-schema-tools/dereferencer/commit/ebb1b1cb6cbdc8876c189229dd5e0c62b93e0c4d))
256
- * add missing build stuffs ([103c2da](https://github.com/json-schema-tools/dereferencer/commit/103c2da3374fd9fcab73c6064389934738e79be5))
257
-
258
-
259
- ### Features
260
-
261
- * pretty epic atm ([ffae51d](https://github.com/json-schema-tools/dereferencer/commit/ffae51d03f8a07598a53d8a58028ab9454e25735))