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