@mountainpass/waychaser 5.0.46 → 5.0.48
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 +1 -1
- package/dist/augment-options.js +20 -57
- package/dist/augment-options.js.map +1 -1
- package/dist/expand-operation.js +18 -53
- package/dist/expand-operation.js.map +1 -1
- package/dist/handlers/hal/de-curie.js +6 -25
- package/dist/handlers/hal/de-curie.js.map +1 -1
- package/dist/handlers/hal/hal-handler.js +16 -65
- package/dist/handlers/hal/hal-handler.js.map +1 -1
- package/dist/handlers/hal/map-hal-link-to-operation.js +5 -30
- package/dist/handlers/hal/map-hal-link-to-operation.js.map +1 -1
- package/dist/handlers/link-header/link-header-handler.js +20 -63
- package/dist/handlers/link-header/link-header-handler.js.map +1 -1
- package/dist/handlers/location-header/location-header-handler.js +4 -7
- package/dist/handlers/location-header/location-header-handler.js.map +1 -1
- package/dist/handlers/siren/map-siren-action-to-operation.js +12 -53
- package/dist/handlers/siren/map-siren-action-to-operation.js.map +1 -1
- package/dist/handlers/siren/map-siren-link-to-operation.js +4 -29
- package/dist/handlers/siren/map-siren-link-to-operation.js.map +1 -1
- package/dist/handlers/siren/siren-action-handler.js +7 -32
- package/dist/handlers/siren/siren-action-handler.js.map +1 -1
- package/dist/handlers/siren/siren-handler.js +10 -39
- package/dist/handlers/siren/siren-handler.js.map +1 -1
- package/dist/handlers/siren/siren-link-handler.js +8 -43
- package/dist/handlers/siren/siren-link-handler.js.map +1 -1
- package/dist/operation-array.d.ts +1 -0
- package/dist/operation-array.js +27 -70
- package/dist/operation-array.js.map +1 -1
- package/dist/operation.js +128 -272
- package/dist/operation.js.map +1 -1
- package/dist/src/augment-options.d.ts +30 -0
- package/dist/src/expand-operation.d.ts +5 -0
- package/dist/src/handlers/hal/de-curie.d.ts +9 -0
- package/dist/src/handlers/hal/hal-handler.d.ts +6 -0
- package/dist/src/handlers/hal/map-hal-link-to-operation.d.ts +7 -0
- package/dist/src/handlers/link-header/link-header-handler.d.ts +7 -0
- package/dist/src/handlers/location-header/location-header-handler.d.ts +5 -0
- package/dist/src/handlers/siren/map-siren-action-to-operation.d.ts +6 -0
- package/dist/src/handlers/siren/map-siren-link-to-operation.d.ts +13 -0
- package/dist/src/handlers/siren/siren-action-handler.d.ts +5 -0
- package/dist/src/handlers/siren/siren-handler.d.ts +6 -0
- package/dist/src/handlers/siren/siren-link-handler.d.ts +6 -0
- package/dist/src/operation-array.d.ts +13 -0
- package/dist/src/operation.d.ts +24 -0
- package/dist/src/util/media-types.d.ts +5 -0
- package/dist/src/util/method-can-have-body.d.ts +4 -0
- package/dist/src/util/parse-accept.d.ts +6 -0
- package/dist/src/util/parse-operations.d.ts +14 -0
- package/dist/src/util/preferred-content-type.d.ts +6 -0
- package/dist/src/util/uri-template-lite.d.ts +5 -0
- package/dist/src/waychaser.d.ts +131 -0
- package/dist/util/media-types.js +2 -4
- package/dist/util/media-types.js.map +1 -1
- package/dist/util/method-can-have-body.js +1 -4
- package/dist/util/method-can-have-body.js.map +1 -1
- package/dist/util/parse-accept.js +17 -42
- package/dist/util/parse-accept.js.map +1 -1
- package/dist/util/parse-operations.js +22 -78
- package/dist/util/parse-operations.js.map +1 -1
- package/dist/util/preferred-content-type.js +4 -7
- package/dist/util/preferred-content-type.js.map +1 -1
- package/dist/util/uri-template-lite.js +6 -42
- package/dist/util/uri-template-lite.js.map +1 -1
- package/dist/waychaser.es.js +475 -922
- package/dist/waychaser.es.min.js +1 -1
- package/dist/waychaser.js +212 -480
- package/dist/waychaser.js.map +1 -1
- package/package.json +3 -3
package/dist/waychaser.es.js
CHANGED
|
@@ -1,139 +1,3 @@
|
|
|
1
|
-
/******************************************************************************
|
|
2
|
-
Copyright (c) Microsoft Corporation.
|
|
3
|
-
|
|
4
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
5
|
-
purpose with or without fee is hereby granted.
|
|
6
|
-
|
|
7
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
8
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
9
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
10
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
11
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
12
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
13
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
14
|
-
***************************************************************************** */
|
|
15
|
-
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
16
|
-
|
|
17
|
-
var extendStatics = function(d, b) {
|
|
18
|
-
extendStatics = Object.setPrototypeOf ||
|
|
19
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
20
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
21
|
-
return extendStatics(d, b);
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
function __extends(d, b) {
|
|
25
|
-
if (typeof b !== "function" && b !== null)
|
|
26
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
27
|
-
extendStatics(d, b);
|
|
28
|
-
function __() { this.constructor = d; }
|
|
29
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
var __assign = function() {
|
|
33
|
-
__assign = Object.assign || function __assign(t) {
|
|
34
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
35
|
-
s = arguments[i];
|
|
36
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
37
|
-
}
|
|
38
|
-
return t;
|
|
39
|
-
};
|
|
40
|
-
return __assign.apply(this, arguments);
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
function __rest(s, e) {
|
|
44
|
-
var t = {};
|
|
45
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
46
|
-
t[p] = s[p];
|
|
47
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
48
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
49
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
50
|
-
t[p[i]] = s[p[i]];
|
|
51
|
-
}
|
|
52
|
-
return t;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
56
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
57
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
58
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
59
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
60
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
61
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function __generator(thisArg, body) {
|
|
66
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
67
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
68
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
69
|
-
function step(op) {
|
|
70
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
71
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
72
|
-
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;
|
|
73
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
74
|
-
switch (op[0]) {
|
|
75
|
-
case 0: case 1: t = op; break;
|
|
76
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
77
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
78
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
79
|
-
default:
|
|
80
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
81
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
82
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
83
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
84
|
-
if (t[2]) _.ops.pop();
|
|
85
|
-
_.trys.pop(); continue;
|
|
86
|
-
}
|
|
87
|
-
op = body.call(thisArg, _);
|
|
88
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
89
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function __values(o) {
|
|
94
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
95
|
-
if (m) return m.call(o);
|
|
96
|
-
if (o && typeof o.length === "number") return {
|
|
97
|
-
next: function () {
|
|
98
|
-
if (o && i >= o.length) o = void 0;
|
|
99
|
-
return { value: o && o[i++], done: !o };
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
function __read(o, n) {
|
|
106
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
107
|
-
if (!m) return o;
|
|
108
|
-
var i = m.call(o), r, ar = [], e;
|
|
109
|
-
try {
|
|
110
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
111
|
-
}
|
|
112
|
-
catch (error) { e = { error: error }; }
|
|
113
|
-
finally {
|
|
114
|
-
try {
|
|
115
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
116
|
-
}
|
|
117
|
-
finally { if (e) throw e.error; }
|
|
118
|
-
}
|
|
119
|
-
return ar;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
function __spreadArray(to, from, pack) {
|
|
123
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
124
|
-
if (ar || !(i in from)) {
|
|
125
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
126
|
-
ar[i] = from[i];
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
133
|
-
var e = new Error(message);
|
|
134
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
135
|
-
};
|
|
136
|
-
|
|
137
1
|
function getDefaultExportFromCjs (x) {
|
|
138
2
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
139
3
|
}
|
|
@@ -288,11 +152,11 @@ function requireUriTemplateLite () {
|
|
|
288
152
|
var uriTemplateLiteExports = requireUriTemplateLite();
|
|
289
153
|
var Template = /*@__PURE__*/getDefaultExportFromCjs(uriTemplateLiteExports);
|
|
290
154
|
|
|
291
|
-
|
|
292
|
-
Template
|
|
155
|
+
const URI = {
|
|
156
|
+
Template,
|
|
293
157
|
expand: uriTemplateLiteExports.expand,
|
|
294
|
-
parameters
|
|
295
|
-
|
|
158
|
+
parameters(url) {
|
|
159
|
+
const template = new Template(url);
|
|
296
160
|
return template.match(url);
|
|
297
161
|
}
|
|
298
162
|
};
|
|
@@ -360,38 +224,27 @@ var FormData = /*@__PURE__*/getDefaultExportFromCjs(browserExports);
|
|
|
360
224
|
* @param {string} accept
|
|
361
225
|
*/
|
|
362
226
|
function parseAccept(accept) {
|
|
363
|
-
|
|
227
|
+
const entries = accept.split(',');
|
|
364
228
|
return entries
|
|
365
|
-
.map(
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
subType: types === null || types === void 0 ? void 0 : types[1],
|
|
229
|
+
.map(entry => {
|
|
230
|
+
const fields = entry.split(';');
|
|
231
|
+
const type = fields.shift();
|
|
232
|
+
const types = type?.split('/');
|
|
233
|
+
const parsedEntry = {
|
|
234
|
+
type,
|
|
235
|
+
parentType: types?.[0],
|
|
236
|
+
subType: types?.[1],
|
|
374
237
|
q: 1
|
|
375
238
|
};
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
if (field[0] === 'q') {
|
|
381
|
-
parsedEntry[parsedFields[0]] = Number.parseFloat(parsedFields[1]);
|
|
382
|
-
}
|
|
239
|
+
for (const field of fields) {
|
|
240
|
+
const parsedFields = field.split('=');
|
|
241
|
+
if (field[0] === 'q') {
|
|
242
|
+
parsedEntry[parsedFields[0]] = Number.parseFloat(parsedFields[1]);
|
|
383
243
|
}
|
|
384
244
|
}
|
|
385
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
386
|
-
finally {
|
|
387
|
-
try {
|
|
388
|
-
if (fields_1_1 && !fields_1_1.done && (_a = fields_1.return)) _a.call(fields_1);
|
|
389
|
-
}
|
|
390
|
-
finally { if (e_1) throw e_1.error; }
|
|
391
|
-
}
|
|
392
245
|
return parsedEntry;
|
|
393
246
|
})
|
|
394
|
-
.sort(
|
|
247
|
+
.sort((first, second) => {
|
|
395
248
|
// It is expected to return a negative value if first argument is less than second argument, zero if they're
|
|
396
249
|
// equal and a positive value otherwise
|
|
397
250
|
if (first.q > second.q) {
|
|
@@ -416,12 +269,12 @@ function parseAccept(accept) {
|
|
|
416
269
|
return 0;
|
|
417
270
|
}
|
|
418
271
|
})
|
|
419
|
-
.map(
|
|
272
|
+
.map(entry => {
|
|
420
273
|
return {
|
|
421
274
|
type: entry.type || ''
|
|
422
275
|
};
|
|
423
276
|
})
|
|
424
|
-
.filter(
|
|
277
|
+
.filter(entry => entry.type !== '');
|
|
425
278
|
}
|
|
426
279
|
|
|
427
280
|
/**
|
|
@@ -431,8 +284,8 @@ function parseAccept(accept) {
|
|
|
431
284
|
*/
|
|
432
285
|
function preferredContentType(accept, supportedContentTypes, defaultType) {
|
|
433
286
|
if (accept) {
|
|
434
|
-
|
|
435
|
-
|
|
287
|
+
const acceptable = parseAccept(accept);
|
|
288
|
+
const acceptableMediaTypes = acceptable.find(row => {
|
|
436
289
|
return supportedContentTypes.includes(row.type);
|
|
437
290
|
});
|
|
438
291
|
return acceptableMediaTypes.type;
|
|
@@ -675,9 +528,8 @@ function requireLib () {
|
|
|
675
528
|
|
|
676
529
|
var libExports = requireLib();
|
|
677
530
|
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
var rel = _a.rel, uri = _a.uri, method = _a.method, parameters = _a.parameters, accept = _a.accept, anchor = _a.anchor, otherProperties = __rest(_a, ["rel", "uri", "method", "parameters", "accept", "anchor"]);
|
|
531
|
+
class Operation {
|
|
532
|
+
constructor({ rel, uri, method, parameters, accept, anchor, ...otherProperties }) {
|
|
681
533
|
this.rel = rel;
|
|
682
534
|
this.uri = uri;
|
|
683
535
|
this.method = method;
|
|
@@ -686,84 +538,74 @@ var Operation = /** @class */ (function () {
|
|
|
686
538
|
this.anchor = anchor;
|
|
687
539
|
Object.assign(this, otherProperties);
|
|
688
540
|
}
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
if (_this.uri.includes('{this.')) {
|
|
698
|
-
_this.uri = URI.expand(_this.uri, thisContext);
|
|
541
|
+
}
|
|
542
|
+
class InvocableOperation extends Operation {
|
|
543
|
+
constructor(operation, response, defaultOptions, thisContext) {
|
|
544
|
+
super(operation);
|
|
545
|
+
this.response = response;
|
|
546
|
+
this.defaultOptions = defaultOptions;
|
|
547
|
+
if (this.uri.includes('{this.')) {
|
|
548
|
+
this.uri = URI.expand(this.uri, thisContext);
|
|
699
549
|
}
|
|
700
|
-
return _this;
|
|
701
550
|
// const pathParameters = URI.parameters(operation.uri)
|
|
702
551
|
// for (const key in pathParameters) {
|
|
703
552
|
// this.parameters[key] = {}
|
|
704
553
|
// }
|
|
705
554
|
}
|
|
706
|
-
|
|
555
|
+
invokeAsFragment(parameters, validator) {
|
|
707
556
|
if (this.uri.startsWith('#/')) {
|
|
708
|
-
|
|
709
|
-
|
|
557
|
+
const anchor = this.expandUrl(parameters).toString();
|
|
558
|
+
const fragmentContent = this.response.fullContent && pointer.get(this.response.fullContent, anchor.slice(1));
|
|
710
559
|
if (fragmentContent === undefined) {
|
|
711
560
|
return undefined;
|
|
712
561
|
}
|
|
713
562
|
if (validator) {
|
|
714
|
-
|
|
563
|
+
const validationResult = validator(fragmentContent);
|
|
715
564
|
if (isValidationSuccess(validationResult)) {
|
|
716
|
-
return new WayChaserResponse({ defaultOptions: this.defaultOptions, baseResponse: this.response.response, content: validationResult.content, fullContent: this.response.fullContent, anchor
|
|
565
|
+
return new WayChaserResponse({ defaultOptions: this.defaultOptions, baseResponse: this.response.response, content: validationResult.content, fullContent: this.response.fullContent, anchor, parentOperations: this.response.allOperations, parameters });
|
|
717
566
|
}
|
|
718
567
|
else {
|
|
719
568
|
throw new WayChaserProblem({
|
|
720
569
|
problem: validationResult.problem,
|
|
721
|
-
response: new WayChaserResponse({ defaultOptions: this.defaultOptions, baseResponse: this.response.response, content: fragmentContent, fullContent: this.response.fullContent, parameters
|
|
570
|
+
response: new WayChaserResponse({ defaultOptions: this.defaultOptions, baseResponse: this.response.response, content: fragmentContent, fullContent: this.response.fullContent, parameters })
|
|
722
571
|
});
|
|
723
572
|
}
|
|
724
573
|
}
|
|
725
574
|
else {
|
|
726
|
-
return new WayChaserResponse({ defaultOptions: this.defaultOptions, baseResponse: this.response.response, content: fragmentContent, fullContent: this.response.fullContent, anchor
|
|
575
|
+
return new WayChaserResponse({ defaultOptions: this.defaultOptions, baseResponse: this.response.response, content: fragmentContent, fullContent: this.response.fullContent, anchor, parentOperations: this.response.allOperations, parameters });
|
|
727
576
|
}
|
|
728
577
|
}
|
|
729
|
-
}
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
return
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
});
|
|
742
|
-
});
|
|
743
|
-
};
|
|
744
|
-
InvocableOperation.prototype.doInvokeAll = function (parameters, validator) {
|
|
745
|
-
var _this = this;
|
|
746
|
-
var response = this.response;
|
|
578
|
+
}
|
|
579
|
+
async invokeAll(options) {
|
|
580
|
+
if (this.uri.startsWith('#/') && this.response instanceof WayChaserResponse) {
|
|
581
|
+
const result = this.doInvokeAll(options?.parameters || {});
|
|
582
|
+
return Promise.all(result);
|
|
583
|
+
}
|
|
584
|
+
else {
|
|
585
|
+
return this.invoke(options).then(result => [result]);
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
doInvokeAll(parameters, validator) {
|
|
589
|
+
const response = this.response;
|
|
747
590
|
// expand the URI with whatever parameters have been passed in
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
591
|
+
const template = new URI.Template(this.uri);
|
|
592
|
+
const uriParameters = Object.assign(URI.parameters(this.uri), parameters);
|
|
593
|
+
const currentUri = template.expand(uriParameters).replaceAll('%7B', "{").replaceAll('%7D', "}");
|
|
751
594
|
// get unfilled parameters
|
|
752
|
-
|
|
753
|
-
|
|
595
|
+
const currentUriParameters = URI.parameters(currentUri);
|
|
596
|
+
const keys = Object.keys(currentUriParameters);
|
|
754
597
|
if (keys.length === 0) {
|
|
755
598
|
return [this.invokeAsFragment(parameters, validator)];
|
|
756
599
|
}
|
|
757
600
|
else {
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
if (
|
|
762
|
-
|
|
763
|
-
return indices.flatMap(
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
return _this.doInvokeAll(extendedParameters, validator);
|
|
601
|
+
const field = currentUriParameters[keys[0]];
|
|
602
|
+
const parentUri = currentUri.slice(1, currentUri.indexOf(field) - 1);
|
|
603
|
+
const parent = parentUri === '' ? response.content : pointer.get(response.content, parentUri);
|
|
604
|
+
if (parent) {
|
|
605
|
+
const indices = Array.isArray(parent) ? [...Array.from({ length: parent.length }).keys()] : Object.keys(parent);
|
|
606
|
+
return indices.flatMap(index => {
|
|
607
|
+
const extendedParameters = Object.assign({}, parameters, { [keys[0]]: index });
|
|
608
|
+
return this.doInvokeAll(extendedParameters, validator);
|
|
767
609
|
});
|
|
768
610
|
}
|
|
769
611
|
else {
|
|
@@ -773,129 +615,108 @@ var InvocableOperation = /** @class */ (function (_super) {
|
|
|
773
615
|
type: "https://waychaser.io/fragment-uri-error",
|
|
774
616
|
title: "The fragment URI does not match the content structure",
|
|
775
617
|
uri: parentUri, content: response.content,
|
|
776
|
-
parameters
|
|
618
|
+
parameters
|
|
777
619
|
}),
|
|
778
620
|
});
|
|
779
621
|
}
|
|
780
622
|
}
|
|
781
|
-
}
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
623
|
+
}
|
|
624
|
+
async invoke(options) {
|
|
625
|
+
if (this.uri.startsWith('#/')) {
|
|
626
|
+
return this.invokeAsFragment(options?.parameters);
|
|
627
|
+
}
|
|
628
|
+
else if (this.uri.includes('#/')) {
|
|
629
|
+
// URI has both a path and a fragment (e.g., /addresses?q=...#/0)
|
|
630
|
+
// Resolve the fragment against the current response's content
|
|
631
|
+
const fragment = this.uri.slice(this.uri.indexOf('#/') + 1);
|
|
632
|
+
const fragmentContent = this.response.fullContent && pointer.get(this.response.fullContent, fragment);
|
|
633
|
+
if (fragmentContent !== undefined) {
|
|
634
|
+
return new WayChaserResponse({ defaultOptions: this.defaultOptions, baseResponse: this.response.response, content: fragmentContent, fullContent: this.response.fullContent, anchor: '#' + fragment, parentOperations: this.response.allOperations, parameters: options?.parameters });
|
|
635
|
+
}
|
|
636
|
+
// Fall through to HTTP request if fragment resolution fails
|
|
637
|
+
}
|
|
638
|
+
{
|
|
639
|
+
const parameterSpecs = this.parameters || {};
|
|
640
|
+
const parameters = Object.assign({}, this.defaultOptions.parameters, options?.parameters);
|
|
641
|
+
const invokeUrl = this.url(parameters);
|
|
642
|
+
const body = {};
|
|
643
|
+
/* istanbul ignore if reason: TODO */
|
|
644
|
+
if (Array.isArray(parameterSpecs)) {
|
|
645
|
+
for (const key of parameterSpecs) {
|
|
646
|
+
body[key] = parameters?.[key];
|
|
789
647
|
}
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
return [2 /*return*/, new WayChaserResponse({ defaultOptions: this.defaultOptions, baseResponse: this.response.response, content: fragmentContent, fullContent: this.response.fullContent, anchor: '#' + fragment, parentOperations: this.response.allOperations, parameters: options === null || options === void 0 ? void 0 : options.parameters })];
|
|
795
|
-
}
|
|
796
|
-
// Fall through to HTTP request if fragment resolution fails
|
|
648
|
+
}
|
|
649
|
+
else {
|
|
650
|
+
for (const key of Object.keys(parameterSpecs)) {
|
|
651
|
+
body[key] = parameters?.[key];
|
|
797
652
|
}
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
try {
|
|
814
|
-
if (parameterSpecs_1_1 && !parameterSpecs_1_1.done && (_c = parameterSpecs_1.return)) _c.call(parameterSpecs_1);
|
|
815
|
-
}
|
|
816
|
-
finally { if (e_1) throw e_1.error; }
|
|
817
|
-
}
|
|
653
|
+
}
|
|
654
|
+
let encodedContent;
|
|
655
|
+
let headers = {};
|
|
656
|
+
const requestOptions = Object.assign({}, options);
|
|
657
|
+
requestOptions.method = this.method;
|
|
658
|
+
if (Object.keys(this.parameters).length !== 0 && methodCanHaveBody(this.method || 'GET')) {
|
|
659
|
+
const contentType = preferredContentType(this.accept, [
|
|
660
|
+
'application/x-www-form-urlencoded',
|
|
661
|
+
'application/json',
|
|
662
|
+
'multipart/form-data'
|
|
663
|
+
], 'application/x-www-form-urlencoded');
|
|
664
|
+
switch (contentType) {
|
|
665
|
+
case 'application/x-www-form-urlencoded': {
|
|
666
|
+
encodedContent = qsStringify(body);
|
|
667
|
+
break;
|
|
818
668
|
}
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
key = _b.value;
|
|
823
|
-
body[key] = parameters === null || parameters === void 0 ? void 0 : parameters[key];
|
|
824
|
-
}
|
|
825
|
-
}
|
|
826
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
827
|
-
finally {
|
|
828
|
-
try {
|
|
829
|
-
if (_b && !_b.done && (_d = _a.return)) _d.call(_a);
|
|
830
|
-
}
|
|
831
|
-
finally { if (e_2) throw e_2.error; }
|
|
832
|
-
}
|
|
669
|
+
case 'application/json': {
|
|
670
|
+
encodedContent = JSON.stringify(body);
|
|
671
|
+
break;
|
|
833
672
|
}
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
if (Object.keys(this.parameters).length !== 0 && methodCanHaveBody(this.method || 'GET')) {
|
|
839
|
-
contentType = preferredContentType(this.accept, [
|
|
840
|
-
'application/x-www-form-urlencoded',
|
|
841
|
-
'application/json',
|
|
842
|
-
'multipart/form-data'
|
|
843
|
-
], 'application/x-www-form-urlencoded');
|
|
844
|
-
switch (contentType) {
|
|
845
|
-
case 'application/x-www-form-urlencoded': {
|
|
846
|
-
encodedContent = qsStringify(body);
|
|
847
|
-
break;
|
|
848
|
-
}
|
|
849
|
-
case 'application/json': {
|
|
850
|
-
encodedContent = JSON.stringify(body);
|
|
851
|
-
break;
|
|
852
|
-
}
|
|
853
|
-
case 'multipart/form-data': {
|
|
854
|
-
encodedContent = new FormData();
|
|
855
|
-
for (name_1 in body) {
|
|
856
|
-
encodedContent.append(name_1, body[name_1]);
|
|
857
|
-
}
|
|
858
|
-
break;
|
|
859
|
-
}
|
|
673
|
+
case 'multipart/form-data': {
|
|
674
|
+
encodedContent = new FormData();
|
|
675
|
+
for (const name in body) {
|
|
676
|
+
encodedContent.append(name, body[name]);
|
|
860
677
|
}
|
|
861
|
-
|
|
862
|
-
headers = {
|
|
863
|
-
'content-type': contentType
|
|
864
|
-
};
|
|
865
|
-
}
|
|
866
|
-
// else fetch adds the right content-type header for us
|
|
867
|
-
// with the boundaries
|
|
868
|
-
requestOptions.body = encodedContent;
|
|
869
|
-
requestOptions.headers = Object.assign(headers, options === null || options === void 0 ? void 0 : options.headers);
|
|
678
|
+
break;
|
|
870
679
|
}
|
|
871
|
-
return [2 /*return*/, _waychaser(invokeUrl.toString(), this.defaultOptions, requestOptions)];
|
|
872
680
|
}
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
681
|
+
if (contentType !== 'multipart/form-data') {
|
|
682
|
+
headers = {
|
|
683
|
+
'content-type': contentType
|
|
684
|
+
};
|
|
685
|
+
}
|
|
686
|
+
// else fetch adds the right content-type header for us
|
|
687
|
+
// with the boundaries
|
|
688
|
+
requestOptions.body = encodedContent;
|
|
689
|
+
requestOptions.headers = Object.assign(headers, options?.headers);
|
|
690
|
+
}
|
|
691
|
+
return _waychaser(invokeUrl.toString(), this.defaultOptions, requestOptions);
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
url(parameters) {
|
|
695
|
+
const expandedUri = this.expandUrl(parameters);
|
|
696
|
+
const invokeUrl = new URL(expandedUri, this.response.url);
|
|
879
697
|
return invokeUrl;
|
|
880
|
-
}
|
|
881
|
-
|
|
698
|
+
}
|
|
699
|
+
expandUrl(parameters) {
|
|
882
700
|
return URI.expand(this.uri, flatten(parameters || {}));
|
|
883
|
-
}
|
|
884
|
-
|
|
885
|
-
}(Operation));
|
|
701
|
+
}
|
|
702
|
+
}
|
|
886
703
|
|
|
887
704
|
// const foo: Array<InvocableOperation> = []
|
|
888
705
|
// foo.filter())
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
706
|
+
class OperationArray extends Array {
|
|
707
|
+
constructor(items) {
|
|
708
|
+
super();
|
|
709
|
+
if (items)
|
|
710
|
+
this.push(...items);
|
|
711
|
+
}
|
|
712
|
+
static get [Symbol.species]() {
|
|
713
|
+
return Array;
|
|
893
714
|
}
|
|
894
|
-
|
|
715
|
+
static create() {
|
|
895
716
|
return Object.create(OperationArray.prototype);
|
|
896
|
-
}
|
|
897
|
-
|
|
898
|
-
|
|
717
|
+
}
|
|
718
|
+
find(query, thisArgument) {
|
|
719
|
+
const finder = Array.prototype.find.bind(this);
|
|
899
720
|
if (typeof query === 'string') {
|
|
900
721
|
return finder(objectFinder({ rel: query }), thisArgument);
|
|
901
722
|
}
|
|
@@ -905,8 +726,8 @@ var OperationArray = /** @class */ (function (_super) {
|
|
|
905
726
|
else {
|
|
906
727
|
return finder(query, thisArgument);
|
|
907
728
|
}
|
|
908
|
-
}
|
|
909
|
-
|
|
729
|
+
}
|
|
730
|
+
filter(query, thisArgument) {
|
|
910
731
|
if (typeof query === 'string') {
|
|
911
732
|
return this.filter({ rel: query }, thisArgument);
|
|
912
733
|
}
|
|
@@ -914,26 +735,23 @@ var OperationArray = /** @class */ (function (_super) {
|
|
|
914
735
|
return this.filter(objectFinder(query), thisArgument);
|
|
915
736
|
}
|
|
916
737
|
else {
|
|
917
|
-
|
|
738
|
+
const filtered = Array.prototype.filter.bind(this)(query);
|
|
918
739
|
Object.setPrototypeOf(filtered, OperationArray.prototype);
|
|
919
740
|
return filtered;
|
|
920
741
|
}
|
|
921
|
-
}
|
|
922
|
-
|
|
923
|
-
|
|
742
|
+
}
|
|
743
|
+
invoke(relationship, options) {
|
|
744
|
+
const operation = this.find(relationship);
|
|
924
745
|
return operation ? operation.invoke(options) : undefined;
|
|
925
|
-
}
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
return Promise.all(operations.map(
|
|
929
|
-
|
|
930
|
-
})).then(function (arrayOfArrays) {
|
|
931
|
-
var flat = arrayOfArrays.flat();
|
|
746
|
+
}
|
|
747
|
+
invokeAll(relationship, options) {
|
|
748
|
+
const operations = this.filter(relationship);
|
|
749
|
+
return Promise.all(operations.map(operation => operation.invokeAll(options))).then(arrayOfArrays => {
|
|
750
|
+
const flat = arrayOfArrays.flat();
|
|
932
751
|
return flat;
|
|
933
752
|
});
|
|
934
|
-
}
|
|
935
|
-
|
|
936
|
-
}(Array));
|
|
753
|
+
}
|
|
754
|
+
}
|
|
937
755
|
// ideally we'd just subclass Array, and that works most of the time, BUT sometimes in firefox, instead of it
|
|
938
756
|
// giving us an ObjectArray, we get a plain old Array, without our invoke method or customised find method.
|
|
939
757
|
// FU JavaScript, FU.
|
|
@@ -941,8 +759,8 @@ var OperationArray = /** @class */ (function (_super) {
|
|
|
941
759
|
* @param query
|
|
942
760
|
*/
|
|
943
761
|
function objectFinder(query) {
|
|
944
|
-
return
|
|
945
|
-
for (
|
|
762
|
+
return (o) => {
|
|
763
|
+
for (const key in query) {
|
|
946
764
|
if (query[key] !== o[key]) {
|
|
947
765
|
return false;
|
|
948
766
|
}
|
|
@@ -955,54 +773,33 @@ function objectFinder(query) {
|
|
|
955
773
|
* @param operation
|
|
956
774
|
*/
|
|
957
775
|
function expandOperation(operation) {
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
var matches = originalUrl.match(rangeRegex);
|
|
776
|
+
const expandedOperations = [];
|
|
777
|
+
const rangeRegex = /{\[(\d+)..(\d+)]}/;
|
|
778
|
+
const originalUrl = operation.uri.toString();
|
|
779
|
+
const matches = originalUrl.match(rangeRegex);
|
|
963
780
|
if (matches) {
|
|
964
|
-
for (
|
|
965
|
-
|
|
781
|
+
for (let index = Number.parseInt(matches[1]); index <= Number.parseInt(matches[2]); ++index) {
|
|
782
|
+
const newOp = new Operation(Object.assign(operation, {
|
|
966
783
|
uri: originalUrl.replace(rangeRegex, index.toFixed(0))
|
|
967
784
|
}));
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
var operation_1 = thisExpandedOperations_1_1.value;
|
|
972
|
-
expandedOperations.push(operation_1);
|
|
973
|
-
}
|
|
974
|
-
}
|
|
975
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
976
|
-
finally {
|
|
977
|
-
try {
|
|
978
|
-
if (thisExpandedOperations_1_1 && !thisExpandedOperations_1_1.done && (_a = thisExpandedOperations_1.return)) _a.call(thisExpandedOperations_1);
|
|
979
|
-
}
|
|
980
|
-
finally { if (e_1) throw e_1.error; }
|
|
785
|
+
const thisExpandedOperations = expandOperation(newOp);
|
|
786
|
+
for (const operation of thisExpandedOperations) {
|
|
787
|
+
expandedOperations.push(operation);
|
|
981
788
|
}
|
|
982
789
|
}
|
|
983
790
|
}
|
|
984
791
|
else {
|
|
985
|
-
|
|
986
|
-
|
|
792
|
+
const originalAnchor = operation.anchor;
|
|
793
|
+
const anchorMatches = originalAnchor?.match(rangeRegex);
|
|
987
794
|
if (originalAnchor &&
|
|
988
795
|
anchorMatches) {
|
|
989
|
-
for (
|
|
990
|
-
|
|
796
|
+
for (let index = Number.parseInt(anchorMatches[1]); index <= Number.parseInt(anchorMatches[2]); ++index) {
|
|
797
|
+
const newOp = new Operation(Object.assign(operation, {
|
|
991
798
|
anchor: originalAnchor.replace(rangeRegex, index.toFixed(0))
|
|
992
799
|
}));
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
var operation_2 = thisExpandedOperations_2_1.value;
|
|
997
|
-
expandedOperations.push(operation_2);
|
|
998
|
-
}
|
|
999
|
-
}
|
|
1000
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
1001
|
-
finally {
|
|
1002
|
-
try {
|
|
1003
|
-
if (thisExpandedOperations_2_1 && !thisExpandedOperations_2_1.done && (_b = thisExpandedOperations_2.return)) _b.call(thisExpandedOperations_2);
|
|
1004
|
-
}
|
|
1005
|
-
finally { if (e_2) throw e_2.error; }
|
|
800
|
+
const thisExpandedOperations = expandOperation(newOp);
|
|
801
|
+
for (const operation of thisExpandedOperations) {
|
|
802
|
+
expandedOperations.push(operation);
|
|
1006
803
|
}
|
|
1007
804
|
}
|
|
1008
805
|
}
|
|
@@ -1020,80 +817,38 @@ function expandOperation(operation) {
|
|
|
1020
817
|
* @param root0.baseResponse
|
|
1021
818
|
* @param root0.content
|
|
1022
819
|
*/
|
|
1023
|
-
function parseOperations(
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
});
|
|
1035
|
-
if (handledOperations) {
|
|
1036
|
-
try {
|
|
1037
|
-
for (var handledOperations_1 = (e_2 = void 0, __values(handledOperations)), handledOperations_1_1 = handledOperations_1.next(); !handledOperations_1_1.done; handledOperations_1_1 = handledOperations_1.next()) {
|
|
1038
|
-
var operation = handledOperations_1_1.value;
|
|
1039
|
-
operations.push(operation);
|
|
1040
|
-
}
|
|
1041
|
-
}
|
|
1042
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
1043
|
-
finally {
|
|
1044
|
-
try {
|
|
1045
|
-
if (handledOperations_1_1 && !handledOperations_1_1.done && (_c = handledOperations_1.return)) _c.call(handledOperations_1);
|
|
1046
|
-
}
|
|
1047
|
-
finally { if (e_2) throw e_2.error; }
|
|
1048
|
-
}
|
|
1049
|
-
}
|
|
1050
|
-
if (stop) {
|
|
1051
|
-
break;
|
|
820
|
+
function parseOperations({ handlers, baseResponse, content }) {
|
|
821
|
+
const operations = [];
|
|
822
|
+
let stop = false;
|
|
823
|
+
for (const handler of handlers) {
|
|
824
|
+
// TODO only call handers for the current media type
|
|
825
|
+
const handledOperations = handler.handler(baseResponse, content, () => {
|
|
826
|
+
stop = true;
|
|
827
|
+
});
|
|
828
|
+
if (handledOperations) {
|
|
829
|
+
for (const operation of handledOperations) {
|
|
830
|
+
operations.push(operation);
|
|
1052
831
|
}
|
|
1053
832
|
}
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
finally {
|
|
1057
|
-
try {
|
|
1058
|
-
if (handlers_1_1 && !handlers_1_1.done && (_b = handlers_1.return)) _b.call(handlers_1);
|
|
833
|
+
if (stop) {
|
|
834
|
+
break;
|
|
1059
835
|
}
|
|
1060
|
-
finally { if (e_1) throw e_1.error; }
|
|
1061
836
|
}
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
var operation_1 = expanded_1_1.value;
|
|
1070
|
-
var anchor = operation_1.anchor || '';
|
|
1071
|
-
if (!expandedOperations[anchor]) {
|
|
1072
|
-
expandedOperations[anchor] = [];
|
|
1073
|
-
}
|
|
1074
|
-
expandedOperations[anchor].push(operation_1);
|
|
1075
|
-
}
|
|
837
|
+
const expandedOperations = {};
|
|
838
|
+
for (const operation of operations) {
|
|
839
|
+
const expanded = expandOperation(operation);
|
|
840
|
+
for (const operation of expanded) {
|
|
841
|
+
const anchor = operation.anchor || '';
|
|
842
|
+
if (!expandedOperations[anchor]) {
|
|
843
|
+
expandedOperations[anchor] = [];
|
|
1076
844
|
}
|
|
1077
|
-
|
|
1078
|
-
finally {
|
|
1079
|
-
try {
|
|
1080
|
-
if (expanded_1_1 && !expanded_1_1.done && (_e = expanded_1.return)) _e.call(expanded_1);
|
|
1081
|
-
}
|
|
1082
|
-
finally { if (e_4) throw e_4.error; }
|
|
1083
|
-
}
|
|
1084
|
-
}
|
|
1085
|
-
}
|
|
1086
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
1087
|
-
finally {
|
|
1088
|
-
try {
|
|
1089
|
-
if (operations_1_1 && !operations_1_1.done && (_d = operations_1.return)) _d.call(operations_1);
|
|
845
|
+
expandedOperations[anchor].push(operation);
|
|
1090
846
|
}
|
|
1091
|
-
finally { if (e_3) throw e_3.error; }
|
|
1092
847
|
}
|
|
1093
848
|
return expandedOperations;
|
|
1094
849
|
}
|
|
1095
850
|
|
|
1096
|
-
|
|
851
|
+
const MediaTypes = {
|
|
1097
852
|
HAL: 'application/hal+json',
|
|
1098
853
|
SIREN: 'application/vnd.siren+json'
|
|
1099
854
|
};
|
|
@@ -1114,10 +869,10 @@ function deCurie(relationship, curies) {
|
|
|
1114
869
|
// ⚠️ NOTE TO SELF: never use 'http' or 'https' as a curie name or hilarity will not ensue 😬
|
|
1115
870
|
// ⚠️ ALSO NOTE TO SELF: never use ':' in a curie name or hilarity will not ensue 😬
|
|
1116
871
|
// I'm going to assume that if there are multiple ':' characters, then we ignore all but the first
|
|
1117
|
-
|
|
872
|
+
const splitRelationship = relationship.split(/:(.+)/);
|
|
1118
873
|
if (splitRelationship.length > 1) {
|
|
1119
|
-
|
|
1120
|
-
|
|
874
|
+
const [curieName, curieRemainder] = splitRelationship;
|
|
875
|
+
const rval = curies[curieName]
|
|
1121
876
|
? URI.expand(curies[curieName], { rel: curieRemainder })
|
|
1122
877
|
: relationship;
|
|
1123
878
|
return rval;
|
|
@@ -1135,8 +890,8 @@ function deCurie(relationship, curies) {
|
|
|
1135
890
|
function mapHalLinkToOperation(relationship, link, curies) {
|
|
1136
891
|
// we don't need to copy `templated` across, because when we invoke an operation, we always
|
|
1137
892
|
// assume it's a template and expand it with the passed parameters
|
|
1138
|
-
|
|
1139
|
-
return new Operation(
|
|
893
|
+
const { href, templated: _templated, ...otherProperties } = link;
|
|
894
|
+
return new Operation({ rel: deCurie(relationship, curies), uri: href, ...otherProperties });
|
|
1140
895
|
}
|
|
1141
896
|
|
|
1142
897
|
/**
|
|
@@ -1144,67 +899,35 @@ function mapHalLinkToOperation(relationship, link, curies) {
|
|
|
1144
899
|
* @param content
|
|
1145
900
|
*/
|
|
1146
901
|
function halHandler(response, content) {
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
var contentType = (_d = response.headers.get('content-type')) === null || _d === void 0 ? void 0 : _d.split(';');
|
|
1151
|
-
if ((contentType === null || contentType === void 0 ? void 0 : contentType[0]) === MediaTypes.HAL &&
|
|
902
|
+
const operations = [];
|
|
903
|
+
const contentType = response.headers.get('content-type')?.split(';');
|
|
904
|
+
if (contentType?.[0] === MediaTypes.HAL &&
|
|
1152
905
|
content &&
|
|
1153
906
|
typeof content === 'object' &&
|
|
1154
907
|
'_links' in content) {
|
|
1155
|
-
|
|
908
|
+
const body = content;
|
|
1156
909
|
// if there are curies in the Hal Links, we need to load them first, so we can expand them wherever they are used
|
|
1157
910
|
// we also want to convert them to a map, for easy lookup
|
|
1158
|
-
|
|
911
|
+
const curies = {};
|
|
1159
912
|
if (body._links.curies) {
|
|
1160
913
|
if (Array.isArray(body._links.curies)) {
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
var curie = _f.value;
|
|
1164
|
-
curies[curie.name] = curie.href;
|
|
1165
|
-
}
|
|
1166
|
-
}
|
|
1167
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1168
|
-
finally {
|
|
1169
|
-
try {
|
|
1170
|
-
if (_f && !_f.done && (_a = _e.return)) _a.call(_e);
|
|
1171
|
-
}
|
|
1172
|
-
finally { if (e_1) throw e_1.error; }
|
|
914
|
+
for (const curie of body._links.curies) {
|
|
915
|
+
curies[curie.name] = curie.href;
|
|
1173
916
|
}
|
|
1174
917
|
}
|
|
1175
918
|
else {
|
|
1176
919
|
curies[body._links.curies.name] = body._links.curies.href;
|
|
1177
920
|
}
|
|
1178
921
|
}
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
try {
|
|
1184
|
-
for (var _j = (e_3 = void 0, __values(body._links[key])), _k = _j.next(); !_k.done; _k = _j.next()) {
|
|
1185
|
-
var link = _k.value;
|
|
1186
|
-
operations.push(mapHalLinkToOperation(key, link, curies));
|
|
1187
|
-
}
|
|
1188
|
-
}
|
|
1189
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
1190
|
-
finally {
|
|
1191
|
-
try {
|
|
1192
|
-
if (_k && !_k.done && (_c = _j.return)) _c.call(_j);
|
|
1193
|
-
}
|
|
1194
|
-
finally { if (e_3) throw e_3.error; }
|
|
1195
|
-
}
|
|
1196
|
-
}
|
|
1197
|
-
else {
|
|
1198
|
-
operations.push(mapHalLinkToOperation(key, body._links[key], curies));
|
|
922
|
+
for (const key of Object.keys(body._links).filter(relationship => relationship !== 'curies')) {
|
|
923
|
+
if (Array.isArray(body._links[key])) {
|
|
924
|
+
for (const link of body._links[key]) {
|
|
925
|
+
operations.push(mapHalLinkToOperation(key, link, curies));
|
|
1199
926
|
}
|
|
1200
927
|
}
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
finally {
|
|
1204
|
-
try {
|
|
1205
|
-
if (_h && !_h.done && (_b = _g.return)) _b.call(_g);
|
|
928
|
+
else {
|
|
929
|
+
operations.push(mapHalLinkToOperation(key, body._links[key], curies));
|
|
1206
930
|
}
|
|
1207
|
-
finally { if (e_2) throw e_2.error; }
|
|
1208
931
|
}
|
|
1209
932
|
}
|
|
1210
933
|
return operations;
|
|
@@ -1635,20 +1358,30 @@ var LinkHeader = /*@__PURE__*/getDefaultExportFromCjs(linkExports);
|
|
|
1635
1358
|
* @param stopper
|
|
1636
1359
|
*/
|
|
1637
1360
|
function linkHeaderHandler(response, _content, _stopper) {
|
|
1638
|
-
return
|
|
1361
|
+
return [
|
|
1362
|
+
...parseHeader(response.headers.get('link')),
|
|
1363
|
+
...parseHeader(response.headers.get('link-template'))
|
|
1364
|
+
];
|
|
1639
1365
|
}
|
|
1640
1366
|
/**
|
|
1641
1367
|
* @param linkHeader
|
|
1642
1368
|
*/
|
|
1643
1369
|
function parseHeader(linkHeader) {
|
|
1644
1370
|
if (linkHeader) {
|
|
1645
|
-
|
|
1646
|
-
return links.refs.map(
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
? JSON.parse(parameters
|
|
1371
|
+
const links = LinkHeader.parse(linkHeader);
|
|
1372
|
+
return links.refs.map(reference => {
|
|
1373
|
+
const { rel, uri, method, 'accept*': accept, 'params*': parameters, ...otherProperties } = reference;
|
|
1374
|
+
const parsedParameters = parameters?.value
|
|
1375
|
+
? JSON.parse(parameters?.value)
|
|
1650
1376
|
: undefined;
|
|
1651
|
-
return new Operation(
|
|
1377
|
+
return new Operation({
|
|
1378
|
+
rel,
|
|
1379
|
+
uri,
|
|
1380
|
+
method,
|
|
1381
|
+
parameters: parsedParameters,
|
|
1382
|
+
accept: accept?.value,
|
|
1383
|
+
...otherProperties
|
|
1384
|
+
});
|
|
1652
1385
|
});
|
|
1653
1386
|
}
|
|
1654
1387
|
else {
|
|
@@ -1661,51 +1394,35 @@ function parseHeader(linkHeader) {
|
|
|
1661
1394
|
* @returns {object} the link objection that the @{param action} maps to
|
|
1662
1395
|
*/
|
|
1663
1396
|
function mapSirenActionToOperation(action) {
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
var bodyParameters = {};
|
|
1397
|
+
const { name, href, fields, type, ...otherProperties } = action;
|
|
1398
|
+
const bodyParameters = {};
|
|
1667
1399
|
if (fields) {
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
var parameter = fields_1_1.value;
|
|
1671
|
-
bodyParameters[parameter.name] = {};
|
|
1672
|
-
}
|
|
1673
|
-
}
|
|
1674
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1675
|
-
finally {
|
|
1676
|
-
try {
|
|
1677
|
-
if (fields_1_1 && !fields_1_1.done && (_a = fields_1.return)) _a.call(fields_1);
|
|
1678
|
-
}
|
|
1679
|
-
finally { if (e_1) throw e_1.error; }
|
|
1400
|
+
for (const parameter of fields) {
|
|
1401
|
+
bodyParameters[parameter.name] = {};
|
|
1680
1402
|
}
|
|
1681
1403
|
}
|
|
1682
|
-
return
|
|
1404
|
+
return {
|
|
1405
|
+
rel: name,
|
|
1406
|
+
uri: href,
|
|
1407
|
+
accept: type,
|
|
1408
|
+
parameters: fields && bodyParameters,
|
|
1409
|
+
...otherProperties
|
|
1410
|
+
};
|
|
1683
1411
|
}
|
|
1684
1412
|
|
|
1685
1413
|
/**
|
|
1686
1414
|
* @param content
|
|
1687
1415
|
*/
|
|
1688
1416
|
function sirenActionHandler(content) {
|
|
1689
|
-
|
|
1690
|
-
var operations = [];
|
|
1417
|
+
const operations = [];
|
|
1691
1418
|
if (content &&
|
|
1692
1419
|
typeof content === 'object' &&
|
|
1693
1420
|
'actions' in content) {
|
|
1694
|
-
|
|
1421
|
+
const body = content;
|
|
1695
1422
|
if (body.actions) {
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
var operation = mapSirenActionToOperation(action);
|
|
1700
|
-
operations.push(operation);
|
|
1701
|
-
}
|
|
1702
|
-
}
|
|
1703
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1704
|
-
finally {
|
|
1705
|
-
try {
|
|
1706
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1707
|
-
}
|
|
1708
|
-
finally { if (e_1) throw e_1.error; }
|
|
1423
|
+
for (const action of body.actions) {
|
|
1424
|
+
const operation = mapSirenActionToOperation(action);
|
|
1425
|
+
operations.push(operation);
|
|
1709
1426
|
}
|
|
1710
1427
|
}
|
|
1711
1428
|
}
|
|
@@ -1724,8 +1441,8 @@ function mapSirenLinkToOperation(relationship, link) {
|
|
|
1724
1441
|
// we don't need to copy `rel` across, because we already have that from the {@param relationship}.
|
|
1725
1442
|
// Also `rel` in `link` is an array, which is not what we're after.
|
|
1726
1443
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
1727
|
-
|
|
1728
|
-
return new Operation(
|
|
1444
|
+
const { href, rel, ...otherProperties } = link;
|
|
1445
|
+
return new Operation({ rel: relationship, uri: href, ...otherProperties });
|
|
1729
1446
|
}
|
|
1730
1447
|
|
|
1731
1448
|
/**
|
|
@@ -1733,39 +1450,18 @@ function mapSirenLinkToOperation(relationship, link) {
|
|
|
1733
1450
|
* @param content
|
|
1734
1451
|
*/
|
|
1735
1452
|
function sirenLinkHandler(content) {
|
|
1736
|
-
|
|
1737
|
-
var operations = [];
|
|
1453
|
+
const operations = [];
|
|
1738
1454
|
if (content &&
|
|
1739
1455
|
typeof content === 'object' &&
|
|
1740
1456
|
'links' in content) {
|
|
1741
|
-
|
|
1457
|
+
const body = content;
|
|
1742
1458
|
if (body.links) {
|
|
1743
|
-
|
|
1744
|
-
for (
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
for (var _e = (e_2 = void 0, __values(link.rel)), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
1748
|
-
var relationship = _f.value;
|
|
1749
|
-
var mappedLink = mapSirenLinkToOperation(relationship, link);
|
|
1750
|
-
operations.push(mappedLink);
|
|
1751
|
-
}
|
|
1752
|
-
}
|
|
1753
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
1754
|
-
finally {
|
|
1755
|
-
try {
|
|
1756
|
-
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
|
1757
|
-
}
|
|
1758
|
-
finally { if (e_2) throw e_2.error; }
|
|
1759
|
-
}
|
|
1459
|
+
for (const link of body.links) {
|
|
1460
|
+
for (const relationship of link.rel) {
|
|
1461
|
+
const mappedLink = mapSirenLinkToOperation(relationship, link);
|
|
1462
|
+
operations.push(mappedLink);
|
|
1760
1463
|
}
|
|
1761
1464
|
}
|
|
1762
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1763
|
-
finally {
|
|
1764
|
-
try {
|
|
1765
|
-
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
1766
|
-
}
|
|
1767
|
-
finally { if (e_1) throw e_1.error; }
|
|
1768
|
-
}
|
|
1769
1465
|
}
|
|
1770
1466
|
}
|
|
1771
1467
|
return operations;
|
|
@@ -1776,10 +1472,12 @@ function sirenLinkHandler(content) {
|
|
|
1776
1472
|
* @param content
|
|
1777
1473
|
*/
|
|
1778
1474
|
function sirenHandler(response, content) {
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1475
|
+
const contentType = response.headers.get('content-type')?.split(';');
|
|
1476
|
+
if (contentType?.[0] === MediaTypes.SIREN) {
|
|
1477
|
+
return [
|
|
1478
|
+
...(sirenLinkHandler(content)),
|
|
1479
|
+
...(sirenActionHandler(content))
|
|
1480
|
+
];
|
|
1783
1481
|
}
|
|
1784
1482
|
return [];
|
|
1785
1483
|
}
|
|
@@ -1788,7 +1486,7 @@ function sirenHandler(response, content) {
|
|
|
1788
1486
|
* @param response
|
|
1789
1487
|
*/
|
|
1790
1488
|
function locationHeaderHandler(response) {
|
|
1791
|
-
|
|
1489
|
+
const locationHeader = response?.headers.get('location');
|
|
1792
1490
|
if (locationHeader) {
|
|
1793
1491
|
return [new Operation({ rel: 'related', uri: locationHeader })];
|
|
1794
1492
|
}
|
|
@@ -1800,74 +1498,65 @@ function locationHeaderHandler(response) {
|
|
|
1800
1498
|
* @param additionalOptions
|
|
1801
1499
|
*/
|
|
1802
1500
|
function augmentOptions(baseOptions, additionalOptions) {
|
|
1803
|
-
|
|
1804
|
-
|
|
1501
|
+
const { handlers: baseHandlers, defaultHandlers: baseDefaultHandlers, headers: baseHeaders, contentParser: baseContentParser, ...baseOther } = baseOptions;
|
|
1502
|
+
const { handlers: additionalHandlers, defaultHandlers: additionalDefaultHandlers, headers: additionalHeaders, contentParser: additionalContentParser, ...additionalOther } = additionalOptions || {};
|
|
1805
1503
|
// if additional has default, don't use base default
|
|
1806
1504
|
// if additional has handlers, don;'t use base handlers
|
|
1807
1505
|
// augment({ dh: [XXX] }, { h: [YYY] }) => { h: [], dh: [YYY, XXX] }
|
|
1808
1506
|
// augment({ dh: [XXX] }, { h: [YYY], dh: [] }) => { h: [], dh: [YYY] }
|
|
1809
1507
|
// augment({ dh: [YYY, XXX] }, { h: [ZZZ] }) => { h: [], dh: [ZZZ, YYY, XXX] }
|
|
1810
1508
|
// augment({ dh: [YYY, XXX] }, { h: [ZZZ], dh: [] }) => { h: [], dh: [ZZZ] }
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1509
|
+
const mergedHandlers = sortHandlers([
|
|
1510
|
+
...(additionalHandlers || baseHandlers || []),
|
|
1511
|
+
...(additionalDefaultHandlers || baseDefaultHandlers || [])
|
|
1512
|
+
]);
|
|
1513
|
+
const mergedContentParser = additionalContentParser ? (response) => additionalContentParser(response, baseContentParser) : baseContentParser;
|
|
1514
|
+
return {
|
|
1515
|
+
...baseOther,
|
|
1516
|
+
...additionalOther,
|
|
1517
|
+
defaultHandlers: mergedHandlers,
|
|
1518
|
+
handlers: [],
|
|
1519
|
+
headers: {
|
|
1520
|
+
...baseHeaders,
|
|
1521
|
+
...additionalHeaders
|
|
1522
|
+
},
|
|
1523
|
+
contentParser: mergedContentParser
|
|
1524
|
+
};
|
|
1814
1525
|
}
|
|
1815
1526
|
|
|
1816
|
-
|
|
1527
|
+
/* global Response */
|
|
1817
1528
|
/**
|
|
1818
1529
|
* @param result
|
|
1819
1530
|
*/
|
|
1820
1531
|
function isValidationSuccess(result) {
|
|
1821
1532
|
return result.success;
|
|
1822
1533
|
}
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
var e_1, _b, e_2, _c, e_3, _d;
|
|
1826
|
-
var handlers = _a.handlers, defaultOptions = _a.defaultOptions, baseResponse = _a.baseResponse, content = _a.content, fullContent = _a.fullContent, anchor = _a.anchor, parentOperations = _a.parentOperations, parameters = _a.parameters;
|
|
1534
|
+
class WayChaserResponse {
|
|
1535
|
+
constructor({ handlers, defaultOptions, baseResponse, content, fullContent, anchor, parentOperations, parameters }) {
|
|
1827
1536
|
this.response = baseResponse;
|
|
1828
1537
|
this.anchor = anchor;
|
|
1829
1538
|
this.parameters = parameters || {};
|
|
1830
1539
|
this.fullContent = fullContent || content;
|
|
1831
1540
|
this.content = content;
|
|
1832
1541
|
this.operations = OperationArray.create();
|
|
1833
|
-
|
|
1542
|
+
const thisContext = flatten({ this: content });
|
|
1834
1543
|
if (parentOperations && anchor && defaultOptions) {
|
|
1835
1544
|
this.allOperations = parentOperations;
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
var operation = _f.value;
|
|
1839
|
-
this.operations.push(new InvocableOperation(operation, this, defaultOptions, thisContext));
|
|
1840
|
-
}
|
|
1841
|
-
}
|
|
1842
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1843
|
-
finally {
|
|
1844
|
-
try {
|
|
1845
|
-
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
|
1846
|
-
}
|
|
1847
|
-
finally { if (e_1) throw e_1.error; }
|
|
1545
|
+
for (const operation of this.allOperations[anchor] || []) {
|
|
1546
|
+
this.operations.push(new InvocableOperation(operation, this, defaultOptions, thisContext));
|
|
1848
1547
|
}
|
|
1849
1548
|
// not only do we need to go through the operations with a matching anchor
|
|
1850
1549
|
// we also need to go though anchors that could match this.anchor
|
|
1851
|
-
for (
|
|
1550
|
+
for (const key in this.allOperations) {
|
|
1852
1551
|
if (key !== '') {
|
|
1853
1552
|
// need to see if key could match this.anchor
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1553
|
+
const template = new URI.Template(key);
|
|
1554
|
+
const parameters = template.match(this.anchor);
|
|
1555
|
+
const expandedAnchor = template.expand(parameters);
|
|
1857
1556
|
if (expandedAnchor === this.anchor) {
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
var operation = _h.value;
|
|
1862
|
-
this.operations.push(new InvocableOperation(operation, this, expandedOptions, thisContext));
|
|
1863
|
-
}
|
|
1864
|
-
}
|
|
1865
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
1866
|
-
finally {
|
|
1867
|
-
try {
|
|
1868
|
-
if (_h && !_h.done && (_c = _g.return)) _c.call(_g);
|
|
1869
|
-
}
|
|
1870
|
-
finally { if (e_2) throw e_2.error; }
|
|
1557
|
+
const expandedOptions = Object.assign({}, defaultOptions, { parameters: Object.assign(parameters, defaultOptions.parameters) });
|
|
1558
|
+
for (const operation of this.allOperations[key]) {
|
|
1559
|
+
this.operations.push(new InvocableOperation(operation, this, expandedOptions, thisContext));
|
|
1871
1560
|
}
|
|
1872
1561
|
}
|
|
1873
1562
|
}
|
|
@@ -1875,24 +1564,14 @@ var WayChaserResponse = /** @class */ (function () {
|
|
|
1875
1564
|
}
|
|
1876
1565
|
else if (baseResponse && handlers && defaultOptions) {
|
|
1877
1566
|
this.allOperations = parseOperations({
|
|
1878
|
-
baseResponse
|
|
1879
|
-
content
|
|
1880
|
-
handlers
|
|
1567
|
+
baseResponse,
|
|
1568
|
+
content,
|
|
1569
|
+
handlers
|
|
1881
1570
|
});
|
|
1882
1571
|
this.operations = OperationArray.create();
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
var op = new InvocableOperation(operation, this, defaultOptions, thisContext);
|
|
1887
|
-
this.operations.push(op);
|
|
1888
|
-
}
|
|
1889
|
-
}
|
|
1890
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
1891
|
-
finally {
|
|
1892
|
-
try {
|
|
1893
|
-
if (_k && !_k.done && (_d = _j.return)) _d.call(_j);
|
|
1894
|
-
}
|
|
1895
|
-
finally { if (e_3) throw e_3.error; }
|
|
1572
|
+
for (const operation of this.allOperations[''] || []) {
|
|
1573
|
+
const op = new InvocableOperation(operation, this, defaultOptions, thisContext);
|
|
1574
|
+
this.operations.push(op);
|
|
1896
1575
|
}
|
|
1897
1576
|
}
|
|
1898
1577
|
}
|
|
@@ -1904,159 +1583,108 @@ var WayChaserResponse = /** @class */ (function () {
|
|
|
1904
1583
|
* @returns
|
|
1905
1584
|
* @throws {WayChaserProblem}
|
|
1906
1585
|
*/
|
|
1907
|
-
|
|
1586
|
+
static create(baseResponse, content, defaultOptions, mergedOptions) {
|
|
1908
1587
|
if (content instanceof libExports.ProblemDocument) {
|
|
1909
1588
|
throw new WayChaserProblem({
|
|
1910
|
-
response: new WayChaserResponse({ handlers: mergedOptions.defaultHandlers, defaultOptions
|
|
1589
|
+
response: new WayChaserResponse({ handlers: mergedOptions.defaultHandlers, defaultOptions, baseResponse, content, parameters: mergedOptions.parameters }),
|
|
1911
1590
|
problem: content,
|
|
1912
1591
|
});
|
|
1913
1592
|
}
|
|
1914
1593
|
else {
|
|
1915
1594
|
if (mergedOptions.validator) {
|
|
1916
|
-
|
|
1595
|
+
const validationResult = mergedOptions.validator(content);
|
|
1917
1596
|
if (isValidationSuccess(validationResult)) {
|
|
1918
|
-
return new WayChaserResponse({ handlers: mergedOptions.defaultHandlers, defaultOptions
|
|
1597
|
+
return new WayChaserResponse({ handlers: mergedOptions.defaultHandlers, defaultOptions, baseResponse, content: validationResult.content, parameters: mergedOptions.parameters });
|
|
1919
1598
|
}
|
|
1920
1599
|
else {
|
|
1921
1600
|
throw new WayChaserProblem({
|
|
1922
|
-
response: new WayChaserResponse({ handlers: mergedOptions.defaultHandlers, defaultOptions
|
|
1601
|
+
response: new WayChaserResponse({ handlers: mergedOptions.defaultHandlers, defaultOptions, baseResponse, content, parameters: mergedOptions.parameters }),
|
|
1923
1602
|
problem: validationResult.problem,
|
|
1924
1603
|
});
|
|
1925
1604
|
}
|
|
1926
1605
|
}
|
|
1927
1606
|
else {
|
|
1928
|
-
return new WayChaserResponse({ handlers: mergedOptions.defaultHandlers, defaultOptions
|
|
1607
|
+
return new WayChaserResponse({ handlers: mergedOptions.defaultHandlers, defaultOptions, baseResponse, content, parameters: mergedOptions.parameters });
|
|
1929
1608
|
}
|
|
1930
1609
|
}
|
|
1931
|
-
}
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
enumerable: false,
|
|
1937
|
-
configurable: true
|
|
1938
|
-
});
|
|
1939
|
-
WayChaserResponse.prototype.invoke = function (relationship, options) {
|
|
1610
|
+
}
|
|
1611
|
+
get ops() {
|
|
1612
|
+
return this.operations;
|
|
1613
|
+
}
|
|
1614
|
+
invoke(relationship, options) {
|
|
1940
1615
|
return this.operations.invoke(relationship, options);
|
|
1941
|
-
}
|
|
1942
|
-
|
|
1616
|
+
}
|
|
1617
|
+
invokeAll(relationship, options) {
|
|
1943
1618
|
return this.operations.invokeAll(relationship, options);
|
|
1944
|
-
}
|
|
1945
|
-
|
|
1946
|
-
get: function () {
|
|
1947
|
-
throw new Error('Not Implemented. Use `.content` instead');
|
|
1948
|
-
},
|
|
1949
|
-
enumerable: false,
|
|
1950
|
-
configurable: true
|
|
1951
|
-
});
|
|
1952
|
-
Object.defineProperty(WayChaserResponse.prototype, "bodyUsed", {
|
|
1953
|
-
get: function () {
|
|
1954
|
-
return true;
|
|
1955
|
-
},
|
|
1956
|
-
enumerable: false,
|
|
1957
|
-
configurable: true
|
|
1958
|
-
});
|
|
1959
|
-
Object.defineProperty(WayChaserResponse.prototype, "headers", {
|
|
1960
|
-
get: function () {
|
|
1961
|
-
var _a;
|
|
1962
|
-
return (_a = this.response) === null || _a === void 0 ? void 0 : _a.headers;
|
|
1963
|
-
},
|
|
1964
|
-
enumerable: false,
|
|
1965
|
-
configurable: true
|
|
1966
|
-
});
|
|
1967
|
-
Object.defineProperty(WayChaserResponse.prototype, "ok", {
|
|
1968
|
-
get: function () {
|
|
1969
|
-
return this.response ? this.response.ok : false;
|
|
1970
|
-
},
|
|
1971
|
-
enumerable: false,
|
|
1972
|
-
configurable: true
|
|
1973
|
-
});
|
|
1974
|
-
Object.defineProperty(WayChaserResponse.prototype, "redirected", {
|
|
1975
|
-
get: function () {
|
|
1976
|
-
return this.response ? this.response.redirected : false;
|
|
1977
|
-
},
|
|
1978
|
-
enumerable: false,
|
|
1979
|
-
configurable: true
|
|
1980
|
-
});
|
|
1981
|
-
Object.defineProperty(WayChaserResponse.prototype, "status", {
|
|
1982
|
-
get: function () {
|
|
1983
|
-
var _a;
|
|
1984
|
-
return (_a = this.response) === null || _a === void 0 ? void 0 : _a.status;
|
|
1985
|
-
},
|
|
1986
|
-
enumerable: false,
|
|
1987
|
-
configurable: true
|
|
1988
|
-
});
|
|
1989
|
-
Object.defineProperty(WayChaserResponse.prototype, "statusText", {
|
|
1990
|
-
get: function () {
|
|
1991
|
-
var _a;
|
|
1992
|
-
return (_a = this.response) === null || _a === void 0 ? void 0 : _a.statusText;
|
|
1993
|
-
},
|
|
1994
|
-
enumerable: false,
|
|
1995
|
-
configurable: true
|
|
1996
|
-
});
|
|
1997
|
-
Object.defineProperty(WayChaserResponse.prototype, "type", {
|
|
1998
|
-
get: function () {
|
|
1999
|
-
var _a;
|
|
2000
|
-
return (_a = this.response) === null || _a === void 0 ? void 0 : _a.type;
|
|
2001
|
-
},
|
|
2002
|
-
enumerable: false,
|
|
2003
|
-
configurable: true
|
|
2004
|
-
});
|
|
2005
|
-
Object.defineProperty(WayChaserResponse.prototype, "url", {
|
|
2006
|
-
get: function () {
|
|
2007
|
-
var _a;
|
|
2008
|
-
return (_a = this.response) === null || _a === void 0 ? void 0 : _a.url;
|
|
2009
|
-
},
|
|
2010
|
-
enumerable: false,
|
|
2011
|
-
configurable: true
|
|
2012
|
-
});
|
|
2013
|
-
WayChaserResponse.prototype.arrayBuffer = function () {
|
|
1619
|
+
}
|
|
1620
|
+
get body() {
|
|
2014
1621
|
throw new Error('Not Implemented. Use `.content` instead');
|
|
2015
|
-
}
|
|
2016
|
-
|
|
1622
|
+
}
|
|
1623
|
+
get bodyUsed() {
|
|
1624
|
+
return true;
|
|
1625
|
+
}
|
|
1626
|
+
get headers() {
|
|
1627
|
+
return this.response?.headers;
|
|
1628
|
+
}
|
|
1629
|
+
get ok() {
|
|
1630
|
+
return this.response ? this.response.ok : false;
|
|
1631
|
+
}
|
|
1632
|
+
get redirected() {
|
|
1633
|
+
return this.response ? this.response.redirected : false;
|
|
1634
|
+
}
|
|
1635
|
+
get status() {
|
|
1636
|
+
return this.response?.status;
|
|
1637
|
+
}
|
|
1638
|
+
get statusText() {
|
|
1639
|
+
return this.response?.statusText;
|
|
1640
|
+
}
|
|
1641
|
+
get type() {
|
|
1642
|
+
return this.response?.type;
|
|
1643
|
+
}
|
|
1644
|
+
get url() {
|
|
1645
|
+
return this.response?.url;
|
|
1646
|
+
}
|
|
1647
|
+
arrayBuffer() {
|
|
2017
1648
|
throw new Error('Not Implemented. Use `.content` instead');
|
|
2018
|
-
}
|
|
2019
|
-
|
|
1649
|
+
}
|
|
1650
|
+
blob() {
|
|
1651
|
+
throw new Error('Not Implemented. Use `.content` instead');
|
|
1652
|
+
}
|
|
1653
|
+
clone() {
|
|
2020
1654
|
throw new Error('Not Implemented');
|
|
2021
|
-
}
|
|
2022
|
-
|
|
1655
|
+
}
|
|
1656
|
+
formData() {
|
|
2023
1657
|
throw new Error('Not Implemented. Use `.content` instead');
|
|
2024
|
-
}
|
|
1658
|
+
}
|
|
2025
1659
|
// async json() {
|
|
2026
1660
|
// throw new Error('Not Implemented. Use `.content` instead')
|
|
2027
1661
|
// }
|
|
2028
|
-
|
|
1662
|
+
text() {
|
|
2029
1663
|
throw new Error('Not Implemented. Use `.content` instead');
|
|
2030
|
-
}
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
__extends(WayChaserProblem, _super);
|
|
2035
|
-
function WayChaserProblem(_a) {
|
|
2036
|
-
var response = _a.response, problem = _a.problem;
|
|
2037
|
-
var _newTarget = this.constructor;
|
|
1664
|
+
}
|
|
1665
|
+
}
|
|
1666
|
+
class WayChaserProblem extends Error {
|
|
1667
|
+
constructor({ response, problem }) {
|
|
2038
1668
|
// 'Error' breaks prototype chain here
|
|
2039
|
-
|
|
1669
|
+
super(problem.detail);
|
|
2040
1670
|
// restore prototype chain
|
|
2041
|
-
|
|
1671
|
+
const actualProto = new.target.prototype;
|
|
2042
1672
|
if (Object.setPrototypeOf) {
|
|
2043
|
-
Object.setPrototypeOf(
|
|
1673
|
+
Object.setPrototypeOf(this, actualProto);
|
|
2044
1674
|
}
|
|
2045
1675
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2046
1676
|
else {
|
|
2047
|
-
|
|
1677
|
+
this.__proto__ = actualProto;
|
|
2048
1678
|
}
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
return _this;
|
|
1679
|
+
this.problem = problem;
|
|
1680
|
+
this.response = response;
|
|
2052
1681
|
}
|
|
2053
|
-
|
|
2054
|
-
}(Error));
|
|
1682
|
+
}
|
|
2055
1683
|
/**
|
|
2056
1684
|
* @param handlers
|
|
2057
1685
|
*/
|
|
2058
1686
|
function sortHandlers(handlers) {
|
|
2059
|
-
return handlers.sort(
|
|
1687
|
+
return handlers.sort((a, b) => {
|
|
2060
1688
|
// -ve if less
|
|
2061
1689
|
// e.g. a.q = 0.3, b.q = 0.4, then a.q - b.q = 0.3 - 0.4 = -0.1
|
|
2062
1690
|
return (b.q || 1) - (a.q || 1);
|
|
@@ -2067,54 +1695,33 @@ function sortHandlers(handlers) {
|
|
|
2067
1695
|
* @param handlers
|
|
2068
1696
|
*/
|
|
2069
1697
|
function allMediaRanges(handlers) {
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
if (handlerSpec.q) {
|
|
2080
|
-
rval.push({ type: range.mediaType, q: handlerSpec.q * (range.q || 1) });
|
|
2081
|
-
}
|
|
2082
|
-
else {
|
|
2083
|
-
rval.push({ type: range.mediaType, q: (range.q || 1) });
|
|
2084
|
-
}
|
|
2085
|
-
}
|
|
2086
|
-
else {
|
|
2087
|
-
if (handlerSpec.q) {
|
|
2088
|
-
rval.push({ type: range, q: handlerSpec.q });
|
|
2089
|
-
}
|
|
2090
|
-
else {
|
|
2091
|
-
rval.push({ type: range, q: 1 });
|
|
2092
|
-
}
|
|
2093
|
-
}
|
|
1698
|
+
const rval = [];
|
|
1699
|
+
for (const handlerSpec of handlers) {
|
|
1700
|
+
for (const range of handlerSpec.mediaRanges) {
|
|
1701
|
+
if (typeof range === 'object') {
|
|
1702
|
+
if (handlerSpec.q) {
|
|
1703
|
+
rval.push({ type: range.mediaType, q: handlerSpec.q * (range.q || 1) });
|
|
1704
|
+
}
|
|
1705
|
+
else {
|
|
1706
|
+
rval.push({ type: range.mediaType, q: (range.q || 1) });
|
|
2094
1707
|
}
|
|
2095
1708
|
}
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
1709
|
+
else {
|
|
1710
|
+
if (handlerSpec.q) {
|
|
1711
|
+
rval.push({ type: range, q: handlerSpec.q });
|
|
1712
|
+
}
|
|
1713
|
+
else {
|
|
1714
|
+
rval.push({ type: range, q: 1 });
|
|
2100
1715
|
}
|
|
2101
|
-
finally { if (e_5) throw e_5.error; }
|
|
2102
1716
|
}
|
|
2103
1717
|
}
|
|
2104
1718
|
}
|
|
2105
|
-
|
|
2106
|
-
finally {
|
|
2107
|
-
try {
|
|
2108
|
-
if (handlers_1_1 && !handlers_1_1.done && (_a = handlers_1.return)) _a.call(handlers_1);
|
|
2109
|
-
}
|
|
2110
|
-
finally { if (e_4) throw e_4.error; }
|
|
2111
|
-
}
|
|
2112
|
-
var sorted = rval.sort(function (a, b) {
|
|
1719
|
+
const sorted = rval.sort((a, b) => {
|
|
2113
1720
|
return a.q - b.q;
|
|
2114
1721
|
});
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
1722
|
+
const seen = new Set();
|
|
1723
|
+
const filtered = sorted.filter(item => {
|
|
1724
|
+
const k = item.type;
|
|
2118
1725
|
return seen.has(k) ? false : seen.add(k);
|
|
2119
1726
|
});
|
|
2120
1727
|
return filtered;
|
|
@@ -2126,113 +1733,73 @@ function allMediaRanges(handlers) {
|
|
|
2126
1733
|
* @returns {Promise<WayChaserResponse<Content>>}
|
|
2127
1734
|
* @throws {TypeError | AbortError | WayChaserProblem}
|
|
2128
1735
|
*/
|
|
2129
|
-
function _waychaser(uriOrRequest, defaultOptions, options) {
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
baseResponse = _l.sent();
|
|
2171
|
-
_l.label = 2;
|
|
2172
|
-
case 2:
|
|
2173
|
-
_l.trys.push([2, 4, , 5]);
|
|
2174
|
-
return [4 /*yield*/, mergedOptions.contentParser(baseResponse)
|
|
2175
|
-
// content is
|
|
2176
|
-
// 1. unknown,
|
|
2177
|
-
// 4. undefined
|
|
2178
|
-
];
|
|
2179
|
-
case 3:
|
|
2180
|
-
content = _l.sent();
|
|
2181
|
-
response = WayChaserResponse.create(baseResponse, content, defaultOptions, mergedOptions);
|
|
2182
|
-
stop = false;
|
|
2183
|
-
try {
|
|
2184
|
-
for (_c = __values(updateOptions.postInterceptors), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
2185
|
-
interceptor = _d.value;
|
|
2186
|
-
interceptor(response, function () { return (stop = true); });
|
|
2187
|
-
if (stop) {
|
|
2188
|
-
break;
|
|
2189
|
-
}
|
|
2190
|
-
}
|
|
2191
|
-
}
|
|
2192
|
-
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
2193
|
-
finally {
|
|
2194
|
-
try {
|
|
2195
|
-
if (_d && !_d.done && (_h = _c.return)) _h.call(_c);
|
|
2196
|
-
}
|
|
2197
|
-
finally { if (e_7) throw e_7.error; }
|
|
2198
|
-
}
|
|
2199
|
-
return [2 /*return*/, response];
|
|
2200
|
-
case 4:
|
|
2201
|
-
error_1 = _l.sent();
|
|
2202
|
-
response = new WayChaserResponse({ handlers: mergedOptions.defaultHandlers, defaultOptions: defaultOptions, baseResponse: baseResponse, content: error_1, parameters: mergedOptions.parameters });
|
|
2203
|
-
wayChaserProblem = error_1 instanceof libExports.ProblemDocument ? new WayChaserProblem({
|
|
2204
|
-
response: response,
|
|
2205
|
-
problem: error_1,
|
|
2206
|
-
}) : new WayChaserProblem({
|
|
2207
|
-
response: response,
|
|
2208
|
-
problem: new libExports.ProblemDocument({
|
|
2209
|
-
type: "https://waychaser.io/unexected-error",
|
|
2210
|
-
title: "An unexpected error occurred",
|
|
2211
|
-
error: error_1
|
|
2212
|
-
}),
|
|
2213
|
-
});
|
|
2214
|
-
stop = false;
|
|
2215
|
-
try {
|
|
2216
|
-
for (_e = __values(updateOptions.postErrorInterceptors), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
2217
|
-
interceptor = _f.value;
|
|
2218
|
-
interceptor(wayChaserProblem, function () { return (stop = true); });
|
|
2219
|
-
if (stop) {
|
|
2220
|
-
break;
|
|
2221
|
-
}
|
|
2222
|
-
}
|
|
2223
|
-
}
|
|
2224
|
-
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
2225
|
-
finally {
|
|
2226
|
-
try {
|
|
2227
|
-
if (_f && !_f.done && (_j = _e.return)) _j.call(_e);
|
|
2228
|
-
}
|
|
2229
|
-
finally { if (e_8) throw e_8.error; }
|
|
2230
|
-
}
|
|
2231
|
-
throw wayChaserProblem;
|
|
2232
|
-
case 5: return [2 /*return*/];
|
|
1736
|
+
async function _waychaser(uriOrRequest, defaultOptions, options) {
|
|
1737
|
+
const mergedOptions = augmentOptions(defaultOptions, options);
|
|
1738
|
+
const mergedHandlers = mergedOptions.defaultHandlers;
|
|
1739
|
+
if (!mergedOptions.fetch) {
|
|
1740
|
+
throw new Error('No global fetch and fetch not provided in options');
|
|
1741
|
+
}
|
|
1742
|
+
const defaultAcceptRanges = allMediaRanges(mergedHandlers);
|
|
1743
|
+
const defaultAcceptStrings = defaultAcceptRanges.map(accept => {
|
|
1744
|
+
return accept.q === 1 ? accept.type : `${accept.type};q=${accept.q}`;
|
|
1745
|
+
});
|
|
1746
|
+
const additionalAcceptHeader = options?.headers?.['accept']
|
|
1747
|
+
? [options.headers['accept']]
|
|
1748
|
+
: [];
|
|
1749
|
+
const fullAcceptHeader = [
|
|
1750
|
+
...additionalAcceptHeader,
|
|
1751
|
+
...defaultAcceptStrings
|
|
1752
|
+
].join(',');
|
|
1753
|
+
const updateOptions = {
|
|
1754
|
+
...mergedOptions,
|
|
1755
|
+
headers: { ...mergedOptions.headers, accept: fullAcceptHeader }
|
|
1756
|
+
};
|
|
1757
|
+
let stop = false;
|
|
1758
|
+
for (const interceptor of updateOptions.preInterceptors || []) {
|
|
1759
|
+
interceptor(uriOrRequest, updateOptions, () => (stop = true));
|
|
1760
|
+
if (stop) {
|
|
1761
|
+
break;
|
|
1762
|
+
}
|
|
1763
|
+
}
|
|
1764
|
+
const baseResponse = await mergedOptions.fetch(uriOrRequest.toString(), updateOptions);
|
|
1765
|
+
try {
|
|
1766
|
+
// TODO allow lazy loading of the content
|
|
1767
|
+
const content = await mergedOptions.contentParser(baseResponse);
|
|
1768
|
+
// content is
|
|
1769
|
+
// 1. unknown,
|
|
1770
|
+
// 4. undefined
|
|
1771
|
+
const response = WayChaserResponse.create(baseResponse, content, defaultOptions, mergedOptions);
|
|
1772
|
+
stop = false;
|
|
1773
|
+
for (const interceptor of updateOptions.postInterceptors) {
|
|
1774
|
+
interceptor(response, () => (stop = true));
|
|
1775
|
+
if (stop) {
|
|
1776
|
+
break;
|
|
2233
1777
|
}
|
|
1778
|
+
}
|
|
1779
|
+
return response;
|
|
1780
|
+
}
|
|
1781
|
+
catch (error) {
|
|
1782
|
+
const response = new WayChaserResponse({ handlers: mergedOptions.defaultHandlers, defaultOptions, baseResponse, content: error, parameters: mergedOptions.parameters });
|
|
1783
|
+
const wayChaserProblem = error instanceof libExports.ProblemDocument ? new WayChaserProblem({
|
|
1784
|
+
response,
|
|
1785
|
+
problem: error,
|
|
1786
|
+
}) : new WayChaserProblem({
|
|
1787
|
+
response,
|
|
1788
|
+
problem: new libExports.ProblemDocument({
|
|
1789
|
+
type: "https://waychaser.io/unexected-error",
|
|
1790
|
+
title: "An unexpected error occurred",
|
|
1791
|
+
error
|
|
1792
|
+
}),
|
|
2234
1793
|
});
|
|
2235
|
-
|
|
1794
|
+
stop = false;
|
|
1795
|
+
for (const interceptor of updateOptions.postErrorInterceptors) {
|
|
1796
|
+
interceptor(wayChaserProblem, () => (stop = true));
|
|
1797
|
+
if (stop) {
|
|
1798
|
+
break;
|
|
1799
|
+
}
|
|
1800
|
+
}
|
|
1801
|
+
throw wayChaserProblem;
|
|
1802
|
+
}
|
|
2236
1803
|
}
|
|
2237
1804
|
/**
|
|
2238
1805
|
*
|
|
@@ -2262,14 +1829,13 @@ function tryParseJson(content, contentType) {
|
|
|
2262
1829
|
throw new libExports.ProblemDocument({
|
|
2263
1830
|
type: "https://waychaser.io/invalid-json",
|
|
2264
1831
|
title: "JSON response could not be parsed",
|
|
2265
|
-
detail:
|
|
2266
|
-
content
|
|
2267
|
-
error: error
|
|
1832
|
+
detail: `The response document with content type '${contentType}' could not be parsed as json`,
|
|
1833
|
+
content, error
|
|
2268
1834
|
});
|
|
2269
1835
|
}
|
|
2270
1836
|
}
|
|
2271
|
-
|
|
2272
|
-
fetch: typeof globalThis === 'undefined' ?
|
|
1837
|
+
const wayChaserDefaults = {
|
|
1838
|
+
fetch: typeof globalThis === 'undefined' ? getGlobal()?.fetch : globalThis.fetch?.bind(globalThis),
|
|
2273
1839
|
handlers: [],
|
|
2274
1840
|
defaultHandlers: sortHandlers([
|
|
2275
1841
|
{ handler: locationHeaderHandler, mediaRanges: ['*/*'], q: 0.4 },
|
|
@@ -2280,44 +1846,33 @@ var wayChaserDefaults = {
|
|
|
2280
1846
|
preInterceptors: [],
|
|
2281
1847
|
postInterceptors: [],
|
|
2282
1848
|
postErrorInterceptors: [],
|
|
2283
|
-
contentParser:
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
jsonContent = tryParseJson(content, contentType);
|
|
2297
|
-
if (contentType === 'application/problem+json') {
|
|
2298
|
-
throw Object.assign(new libExports.ProblemDocument(jsonContent), jsonContent);
|
|
2299
|
-
}
|
|
2300
|
-
else {
|
|
2301
|
-
return [2 /*return*/, jsonContent];
|
|
2302
|
-
}
|
|
2303
|
-
}
|
|
2304
|
-
_c.label = 2;
|
|
2305
|
-
case 2: return [2 /*return*/];
|
|
1849
|
+
contentParser: async (response) => {
|
|
1850
|
+
if (response.headers.get('content-length') &&
|
|
1851
|
+
response.headers.get('content-length') !== '0') {
|
|
1852
|
+
const content = await response.text();
|
|
1853
|
+
const contentType = response.headers.get('content-type')?.split(';')?.[0];
|
|
1854
|
+
if (contentType?.endsWith('json')) {
|
|
1855
|
+
const jsonContent = tryParseJson(content, contentType);
|
|
1856
|
+
if (contentType === 'application/problem+json') {
|
|
1857
|
+
throw Object.assign(new libExports.ProblemDocument(jsonContent), jsonContent);
|
|
1858
|
+
}
|
|
1859
|
+
else {
|
|
1860
|
+
return jsonContent;
|
|
1861
|
+
}
|
|
2306
1862
|
}
|
|
2307
|
-
}
|
|
2308
|
-
|
|
1863
|
+
}
|
|
1864
|
+
// else no content. Returning undefined
|
|
1865
|
+
}
|
|
2309
1866
|
};
|
|
2310
1867
|
/**
|
|
2311
1868
|
* @param newDefaults
|
|
2312
1869
|
* @param oldDefaults
|
|
2313
1870
|
*/
|
|
2314
1871
|
function _defaults(newDefaults, oldDefaults) {
|
|
2315
|
-
|
|
2316
|
-
|
|
1872
|
+
const mergedOptions = augmentOptions(oldDefaults, newDefaults);
|
|
1873
|
+
const defaultedWaychaser = (uriOrRequest, options) => _waychaser(uriOrRequest, mergedOptions, options);
|
|
2317
1874
|
defaultedWaychaser.currentDefaults = mergedOptions;
|
|
2318
|
-
defaultedWaychaser.defaults =
|
|
2319
|
-
return _defaults(newDefaults, mergedOptions);
|
|
2320
|
-
};
|
|
1875
|
+
defaultedWaychaser.defaults = (newDefaults) => _defaults(newDefaults, mergedOptions);
|
|
2321
1876
|
return defaultedWaychaser;
|
|
2322
1877
|
}
|
|
2323
1878
|
/**
|
|
@@ -2327,13 +1882,11 @@ function _defaults(newDefaults, oldDefaults) {
|
|
|
2327
1882
|
* @returns WayChaserResponse<Content>
|
|
2328
1883
|
* @throws TypeError | AbortError | WayChaserResponseProblem | Error
|
|
2329
1884
|
*/
|
|
2330
|
-
|
|
1885
|
+
const waychaser = Object.assign((uriOrRequest, options) => {
|
|
2331
1886
|
return _waychaser(uriOrRequest, wayChaserDefaults, options);
|
|
2332
1887
|
}, {
|
|
2333
1888
|
currentDefaults: wayChaserDefaults,
|
|
2334
|
-
defaults:
|
|
2335
|
-
return _defaults(newDefaults, wayChaserDefaults);
|
|
2336
|
-
}
|
|
1889
|
+
defaults: (newDefaults) => _defaults(newDefaults, wayChaserDefaults)
|
|
2337
1890
|
});
|
|
2338
1891
|
|
|
2339
1892
|
export { WayChaserProblem, WayChaserResponse, _waychaser, isValidationSuccess, sortHandlers, waychaser };
|