@mountainpass/waychaser 5.0.12 → 5.0.13

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 CHANGED
@@ -71,7 +71,7 @@ try {
71
71
  ```html
72
72
  <script
73
73
  type="text/javascript"
74
- src="https://unpkg.com/@mountainpass/waychaser@5.0.12"
74
+ src="https://unpkg.com/@mountainpass/waychaser@5.0.13"
75
75
  ></script>
76
76
 
77
77
  ...
@@ -330,8 +330,7 @@ var qsStringify = function queryStringify (obj, prefix) {
330
330
  };
331
331
 
332
332
  /* eslint-env browser */
333
-
334
- var browser = typeof self == 'object' ? self.FormData : window.FormData;
333
+ var browser = typeof self === 'object' ? self.FormData : window.FormData;
335
334
 
336
335
  // negotiated (https://www.npmjs.com/package/negotiated) doesn't working in IE 11 due to missing regex polyfill stuff
337
336
  /**
@@ -660,7 +659,7 @@ function get (obj, pointer) {
660
659
  for (var p = 1; p < len;) {
661
660
  obj = obj[untilde(pointer[p++])];
662
661
  if (len === p) return obj
663
- if (typeof obj !== 'object') return undefined
662
+ if (typeof obj !== 'object' || obj === null) return undefined
664
663
  }
665
664
  }
666
665
 
@@ -1311,6 +1310,21 @@ function needsQuotes( value ) {
1311
1310
  !TOKEN_PATTERN.test( value )
1312
1311
  }
1313
1312
 
1313
+ /**
1314
+ * Shallow compares two objects to check if their properties match.
1315
+ * @param {object} object1 First object to compare.
1316
+ * @param {object} object2 Second object to compare.
1317
+ * @returns {boolean} Do the objects have matching properties.
1318
+ */
1319
+ function shallowCompareObjects( object1, object2 ) {
1320
+ return (
1321
+ Object.keys( object1 ).length === Object.keys( object2 ).length &&
1322
+ Object.keys( object1 ).every(
1323
+ ( key ) => key in object2 && object1[ key ] === object2[ key ]
1324
+ )
1325
+ );
1326
+ }
1327
+
1314
1328
  class Link {
1315
1329
 
1316
1330
  /**
@@ -1341,7 +1355,7 @@ class Link {
1341
1355
  var type = value.toLowerCase();
1342
1356
 
1343
1357
  for( var i = 0; i < this.refs.length; i++ ) {
1344
- if( this.refs[ i ].rel.toLowerCase() === type ) {
1358
+ if( typeof this.refs[ i ].rel === 'string' && this.refs[ i ].rel.toLowerCase() === type ) {
1345
1359
  links.push( this.refs[ i ] );
1346
1360
  }
1347
1361
  }
@@ -1359,11 +1373,12 @@ class Link {
1359
1373
  get( attr, value ) {
1360
1374
 
1361
1375
  attr = attr.toLowerCase();
1376
+ value = value.toLowerCase();
1362
1377
 
1363
1378
  var links = [];
1364
1379
 
1365
1380
  for( var i = 0; i < this.refs.length; i++ ) {
1366
- if( this.refs[ i ][ attr ] === value ) {
1381
+ if( typeof this.refs[ i ][ attr ] === 'string' && this.refs[ i ][ attr ].toLowerCase() === value ) {
1367
1382
  links.push( this.refs[ i ] );
1368
1383
  }
1369
1384
  }
@@ -1372,17 +1387,32 @@ class Link {
1372
1387
 
1373
1388
  }
1374
1389
 
1390
+ /** Sets a reference. */
1375
1391
  set( link ) {
1376
1392
  this.refs.push( link );
1377
1393
  return this
1378
1394
  }
1379
1395
 
1396
+ /**
1397
+ * Sets a reference if a reference with similar properties isn’t already set.
1398
+ */
1399
+ setUnique( link ) {
1400
+
1401
+ if( !this.refs.some(( ref ) => shallowCompareObjects( ref, link )) ) {
1402
+ this.refs.push( link );
1403
+ }
1404
+
1405
+ return this
1406
+
1407
+ }
1408
+
1380
1409
  has( attr, value ) {
1381
1410
 
1382
1411
  attr = attr.toLowerCase();
1412
+ value = value.toLowerCase();
1383
1413
 
1384
1414
  for( var i = 0; i < this.refs.length; i++ ) {
1385
- if( this.refs[ i ][ attr ] === value ) {
1415
+ if( typeof this.refs[ i ][ attr ] === 'string' && this.refs[ i ][ attr ].toLowerCase() === value ) {
1386
1416
  return true
1387
1417
  }
1388
1418
  }
@@ -1444,7 +1474,8 @@ class Link {
1444
1474
  continue
1445
1475
  }
1446
1476
  var end = value.indexOf( '=', offset );
1447
- if( end === -1 ) throw new Error( 'Expected attribute delimiter at offset ' + offset )
1477
+ if( end === -1 ) end = value.indexOf( ';', offset );
1478
+ if( end === -1 ) end = value.length;
1448
1479
  var attr = trim( value.slice( offset, end ) ).toLowerCase();
1449
1480
  var attrValue = '';
1450
1481
  offset = end + 1;
@@ -1570,7 +1601,7 @@ Link.expandRelations = function( ref ) {
1570
1601
  * @return {Object}
1571
1602
  */
1572
1603
  Link.parseExtendedValue = function( value ) {
1573
- var parts = /([^']+)?(?:'([^']+)')?(.+)/.exec( value );
1604
+ var parts = /([^']+)?(?:'([^']*)')?(.+)/.exec( value );
1574
1605
  return {
1575
1606
  language: parts[2].toLowerCase(),
1576
1607
  encoding: Link.isCompatibleEncoding( parts[1] ) ?
@@ -1588,7 +1619,7 @@ Link.parseExtendedValue = function( value ) {
1588
1619
  */
1589
1620
  Link.formatExtendedAttribute = function( attr, data ) {
1590
1621
 
1591
- var encoding = ( data.encoding || 'utf-8' ).toUpperCase();
1622
+ var encoding = ( data.encoding || 'utf-8' ).toUpperCase();
1592
1623
  var language = data.language || 'en';
1593
1624
 
1594
1625
  var encodedValue = '';
@@ -12,4 +12,4 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
12
12
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
13
13
  PERFORMANCE OF THIS SOFTWARE.
14
14
  ***************************************************************************** */
15
- var e=function(r,t){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,r){e.__proto__=r}||function(e,r){for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(e[t]=r[t])})(r,t)};function r(r,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=r}e(r,t),r.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}var t=function(){return(t=Object.assign||function(e){for(var r,t=1,n=arguments.length;t<n;t++)for(var o in r=arguments[t])Object.prototype.hasOwnProperty.call(r,o)&&(e[o]=r[o]);return e}).apply(this,arguments)};function n(e,r){var t={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&r.indexOf(n)<0&&(t[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)r.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(t[n[o]]=e[n[o]])}return t}function o(e,r,t,n){return new(t||(t=Promise))((function(o,i){function a(e){try{l(n.next(e))}catch(e){i(e)}}function s(e){try{l(n.throw(e))}catch(e){i(e)}}function l(e){var r;e.done?o(e.value):(r=e.value,r instanceof t?r:new t((function(e){e(r)}))).then(a,s)}l((n=n.apply(e,r||[])).next())}))}function i(e,r){var t,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(t)throw new TypeError("Generator is already executing.");for(;a;)try{if(t=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,n=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=r.call(e,a)}catch(e){i=[6,e],n=0}finally{t=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}}function a(e){var r="function"==typeof Symbol&&Symbol.iterator,t=r&&e[r],n=0;if(t)return t.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(r?"Object is not iterable.":"Symbol.iterator is not defined.")}function s(e,r){var t="function"==typeof Symbol&&e[Symbol.iterator];if(!t)return e;var n,o,i=t.call(e),a=[];try{for(;(void 0===r||r-- >0)&&!(n=i.next()).done;)a.push(n.value)}catch(e){o={error:e}}finally{try{n&&!n.done&&(t=i.return)&&t.call(i)}finally{if(o)throw o.error}}return a}function l(e,r,t){if(t||2===arguments.length)for(var n,o=0,i=r.length;o<i;o++)!n&&o in r||(n||(n=Array.prototype.slice.call(r,0,o)),n[o]=r[o]);return e.concat(n||Array.prototype.slice.call(r))}var u="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},c={};!function(e){var r=/[!'()]/g,t={"":",","+":",","#":",","?":"&"},n=/[$-\/?[-^{|}]/g,o=/\{([#&+.\/;?]?)((?:[-\w%.]+(\*|:\d+)?,?)+)\}/g,i=RegExp(o.source+"|.[^{]*?","g");function a(e){return encodeURIComponent(e).replace(r,escape)}function s(e){return null!=e}function l(e,r,t){return(e=e.map(r).filter(s)).length&&e.join(t)}function u(e,r){return e.replace(o,(function(e,n,o){var i=t[n]||n,s=";"==i||"&"==i,u=n&&","==i?encodeURI:a,c=l(o.split(","),(function(e){var t=e.split(/[*:]/),n=t[0],o=r[n];if(null!=o){if("object"==typeof o){if(t=n!=e,Array.isArray(o)?o=l(o,u,t?s?i+n+"=":i:","):(o=l(Object.keys(o),(function(e){return u(e)+(t?"=":",")+u(o[e])}),t&&(s||"/"==i)?i:","),t&&(s=0)),!o)return}else o=u(t[1]?o.slice(0,t[1]):o);return s?n+(o||"&"==i?"="+o:o):o}}),i);return c||""===c?"+"!=n?n+c:c:""}))}e.expand=u,e.Template=function(e){var r=this,o=0,a={},s="",l="^"+e.replace(i,(function(e,r,n){if(!n)return p(e);var i=t[r]||r,l=";"==i||"&"==i,u=n.split(",").map((function(e){var r=e.split(/[*:]/),t=r[0],n=(a[t]||"(")+".*?)";return o++,r[1]&&(n="((?:%..|.){1,"+r[1]+"})",a[t]="(\\"+o),s+="t=($["+o+"]||'').split('"+i+"').map(decodeURIComponent);",s+='o["'+t+'"]=t.length>1?t:t[0];',l?p(t)+"(?:="+n+")?":"&"==i?p(t+"=")+n:n})).join(p(i));return"+"!=r?p(r)+u:u}))+"$",c=RegExp(l),f=Function("$","var t,o={};"+s+"return o");function p(e){return e.replace(n,"\\$&")}r.template=e,r.match=function(e){var r=c.exec(e);return r&&f(r)},r.expand=u.bind(r,e)}}(u.URI||(u.URI={}));const f=function(){const e="undefined"==typeof window?c.URI||global.URI:window.URI||c.URI;return e.parameters=function(e){return new f.Template(e).match(e)},e}();var p=Object.prototype.hasOwnProperty,d=function e(r,t){var n=[];for(var o in r)if(p.call(r,o)){var i,a=r[o],s=encodeURIComponent(o);i="object"==typeof a?e(a,t?t+"["+s+"]":s):(t?t+"["+s+"]":s)+"="+encodeURIComponent(a),n.push(i)}return n.join("&")},h="object"==typeof self?self.FormData:window.FormData;function y(e,r,t){if(e){return function(e){return e.split(",").map((function(e){var r,t,n=e.split(";"),o=n.shift(),i=null==o?void 0:o.split("/"),s={type:o,parentType:null==i?void 0:i[0],subType:null==i?void 0:i[1],q:1};try{for(var l=a(n),u=l.next();!u.done;u=l.next()){var c=u.value,f=c.split("=");"q"===c[0]&&(s[f[0]]=Number.parseFloat(f[1]))}}catch(e){r={error:e}}finally{try{u&&!u.done&&(t=l.return)&&t.call(l)}finally{if(r)throw r.error}}return s})).sort((function(e,r){return e.q>r.q?-1:e.q<r.q||"*"===e.parentType&&"*"!==r.parentType?1:"*"!==e.parentType&&"*"===r.parentType?-1:"*"===e.subType&&"*"!==r.subType?1:"*"!==e.subType&&"*"===r.subType?-1:0})).map((function(e){return{type:e.type||""}})).filter((function(e){return""!==e.type}))}(e).find((e=>r.includes(e.type))).type}return t}var v=w;function b(e){return e&&e.constructor&&"function"==typeof e.constructor.isBuffer&&e.constructor.isBuffer(e)}function m(e){return e}function w(e,r){const t=(r=r||{}).delimiter||".",n=r.maxDepth,o=r.transformKey||m,i={};return function e(a,s,l){l=l||1,Object.keys(a).forEach((function(u){const c=a[u],f=r.safe&&Array.isArray(c),p=Object.prototype.toString.call(c),d=b(c),h="[object Object]"===p||"[object Array]"===p,y=s?s+t+o(u):o(u);if(!f&&!d&&h&&Object.keys(c).length&&(!r.maxDepth||l<n))return e(c,y,l+1);i[y]=c}))}(e),i}w.flatten=w,w.unflatten=function e(r,t){const n=(t=t||{}).delimiter||".",o=t.overwrite||!1,i=t.transformKey||m,a={};if(b(r)||"[object Object]"!==Object.prototype.toString.call(r))return r;function s(e){const r=Number(e);return isNaN(r)||-1!==e.indexOf(".")||t.object?e:r}return r=Object.keys(r).reduce((function(e,o){const i=Object.prototype.toString.call(r[o]);return!("[object Object]"===i||"[object Array]"===i)||function(e){const r=Object.prototype.toString.call(e),t="[object Array]"===r,n="[object Object]"===r;if(!e)return!0;if(t)return!e.length;if(n)return!Object.keys(e).length}(r[o])?(e[o]=r[o],e):function(e,r,t){return Object.keys(t).reduce((function(r,o){return r[e+n+o]=t[o],r}),r)}(o,e,w(r[o],t))}),{}),Object.keys(r).forEach((function(l){const u=l.split(n).map(i);let c=s(u.shift()),f=s(u[0]),p=a;for(;void 0!==f;){if("__proto__"===c)return;const e=Object.prototype.toString.call(p[c]),r="[object Object]"===e||"[object Array]"===e;if(!o&&!r&&void 0!==p[c])return;(o&&!r||!o&&null==p[c])&&(p[c]="number"!=typeof f||t.object?{}:[]),p=p[c],u.length>0&&(c=s(u.shift()),f=s(u[0]))}p[c]=e(r[l],t)})),a};var g={},O=/~/,x=/~[01]/g;function j(e){switch(e){case"~1":return"/";case"~0":return"~"}throw new Error("Invalid tilde escape: "+e)}function k(e){return O.test(e)?e.replace(x,j):e}function A(e){if("string"==typeof e){if(""===(e=e.split("/"))[0])return e;throw new Error("Invalid JSON pointer.")}if(Array.isArray(e)){for(const r of e)if("string"!=typeof r&&"number"!=typeof r)throw new Error("Invalid JSON pointer. Must be of type string or number.");return e}throw new Error("Invalid JSON pointer.")}function E(e,r){if("object"!=typeof e)throw new Error("Invalid input object.");var t=(r=A(r)).length;if(1===t)return e;for(var n=1;n<t;){if(e=e[k(r[n++])],t===n)return e;if("object"!=typeof e)return}}function I(e,r,t){if("object"!=typeof e)throw new Error("Invalid input object.");if(0===(r=A(r)).length)throw new Error("Invalid JSON pointer for set.");return function(e,r,t){for(var n,o,i=1,a=r.length;i<a;){if("constructor"===r[i]||"prototype"===r[i]||"__proto__"===r[i])return e;if(n=k(r[i++]),o=a>i,void 0===e[n]&&(Array.isArray(e)&&"-"===n&&(n=e.length),o&&(""!==r[i]&&r[i]<1/0||"-"===r[i]?e[n]=[]:e[n]={})),!o)break;e=e[n]}var s=e[n];return void 0===t?delete e[n]:e[n]=t,s}(e,r,t)}g.get=E,g.set=I,g.compile=function(e){var r=A(e);return{get:function(e){return E(e,r)},set:function(e,t){return I(e,r,t)}}};var R={};Object.defineProperty(R,"__esModule",{value:!0});var P=R.ProblemDocument=void 0;P=R.ProblemDocument=class{constructor(e){Object.assign(this,e)}};var S=function(e){var r=e.rel,t=e.uri,o=e.method,i=e.parameters,a=e.accept,s=e.anchor,l=n(e,["rel","uri","method","parameters","accept","anchor"]);this.rel=r,this.uri=t,this.method=o,this.parameters=i||{},this.accept=a,this.anchor=s,Object.assign(this,l)},C=function(e){function t(r,t,n,o){var i=e.call(this,r)||this;return i.response=t,i.defaultOptions=n,i.uri.includes("{this.")&&(i.uri=f.expand(i.uri,o)),i}return r(t,e),t.prototype.invokeAsFragment=function(e,r){if(this.uri.startsWith("#/")){var t=this.expandUrl(e).toString(),n=this.response.fullContent&&g.get(this.response.fullContent,t.slice(1));if(void 0===n)return;if(r){var o=r(n);if(se(o))return new le({defaultOptions:this.defaultOptions,baseResponse:this.response.response,content:o.content,fullContent:this.response.fullContent,anchor:t,parentOperations:this.response.allOperations,parameters:e});throw new ue({problem:o.problem,response:new le({defaultOptions:this.defaultOptions,baseResponse:this.response.response,content:n,fullContent:this.response.fullContent,parameters:e})})}return new le({defaultOptions:this.defaultOptions,baseResponse:this.response.response,content:n,fullContent:this.response.fullContent,anchor:t,parentOperations:this.response.allOperations,parameters:e})}},t.prototype.invokeAll=function(e){return o(this,void 0,void 0,(function(){var r;return i(this,(function(t){return this.uri.startsWith("#/")&&this.response instanceof le?(r=this.doInvokeAll((null==e?void 0:e.parameters)||{}),[2,Promise.all(r)]):[2,Promise.all([this.invoke(e)])]}))}))},t.prototype.doInvokeAll=function(e,r){var t=this,n=this.response,o=new f.Template(this.uri),i=Object.assign(f.parameters(this.uri),e),a=o.expand(i).replace(/%7B/g,"{").replace(/%7D/g,"}"),u=f.parameters(a),c=Object.keys(u);if(0!==c.length){var p=u[c[0]],d=a.slice(1,a.indexOf(p)-1),h=""===d?n.content:g.get(n.content,d);if(h)return(Array.isArray(h)?l([],s(Array.from({length:h.length}).keys()),!1):Object.keys(h)).flatMap((function(n){var o,i=Object.assign({},e,((o={})[c[0]]=n,o));return t.doInvokeAll(i,r)}));throw new ue({response:this.response,problem:new P({type:"https://waychaser.io/fragment-uri-error",title:"The fragment URI does not match the content structure",uri:d,content:n.content,parameters:e})})}return[this.invokeAsFragment(e,r)]},t.prototype.invoke=function(e){return o(this,void 0,void 0,(function(){var r,t,n,o,s,l,u,c,f,p,v,b,m,w,g,O,x,j;return i(this,(function(i){if(this.uri.startsWith("#/"))return[2,this.invokeAsFragment(null==e?void 0:e.parameters)];if(r=this.parameters||{},t=Object.assign({},this.defaultOptions.parameters,null==e?void 0:e.parameters),n=this.url(t),o={},Array.isArray(r))try{for(s=a(r),l=s.next();!l.done;l=s.next())f=l.value,o[f]=null==t?void 0:t[f]}catch(e){g={error:e}}finally{try{l&&!l.done&&(O=s.return)&&O.call(s)}finally{if(g)throw g.error}}else try{for(u=a(Object.keys(r)),c=u.next();!c.done;c=u.next())f=c.value,o[f]=null==t?void 0:t[f]}catch(e){x={error:e}}finally{try{c&&!c.done&&(j=u.return)&&j.call(u)}finally{if(x)throw x.error}}if(p=void 0,v={},(b=Object.assign({},e)).method=this.method,0!==Object.keys(this.parameters).length&&(k=this.method||"GET",!["GET","DELETE","TRACE","OPTIONS","HEAD"].includes(k))){switch(m=y(this.accept,["application/x-www-form-urlencoded","application/json","multipart/form-data"],"application/x-www-form-urlencoded")){case"application/x-www-form-urlencoded":p=d(o);break;case"application/json":p=JSON.stringify(o);break;case"multipart/form-data":for(w in p=new h,o)p.append(w,o[w])}"multipart/form-data"!==m&&(v={"content-type":m}),b.body=p,b.headers=Object.assign(v,null==e?void 0:e.headers)}return[2,fe(n.toString(),this.defaultOptions,b)];var k}))}))},t.prototype.url=function(e){var r=this.expandUrl(e);return new URL(r,this.response.url)},t.prototype.expandUrl=function(e){return f.expand(this.uri,v(e||{}))},t}(S),_=function(e){function t(r){return e.apply(this,l([],s(r||[]),!1))||this}return r(t,e),t.create=function(){return Object.create(t.prototype)},t.prototype.find=function(e,r){var t=Array.prototype.find.bind(this);return t("string"==typeof e?T({rel:e}):"object"==typeof e?T(e):e,r)},t.prototype.filter=function(e,r){if("string"==typeof e)return this.filter({rel:e},r);if("object"==typeof e)return this.filter(T(e),r);var n=Array.prototype.filter.bind(this)(e);return Object.setPrototypeOf(n,t.prototype),n},t.prototype.invoke=function(e,r){var t=this.find(e);return t?t.invoke(r):void 0},t.prototype.invokeAll=function(e,r){var t=this.filter(e);return Promise.all(t.map((function(e){return e.invokeAll(r)}))).then((function(e){return e.flat()}))},t}(Array);function T(e){return function(r){for(var t in e)if(e[t]!==r[t])return!1;return!0}}function U(e){var r,t,n,o,i=[],s=/{\[(\d+)..(\d+)]}/,l=e.uri.toString(),u=l.match(s);if(u)for(var c=Number.parseInt(u[1]);c<=Number.parseInt(u[2]);++c){var f=U(new S(Object.assign(e,{uri:l.replace(s,c.toFixed(0))})));try{for(var p=(r=void 0,a(f)),d=p.next();!d.done;d=p.next()){var h=d.value;i.push(h)}}catch(e){r={error:e}}finally{try{d&&!d.done&&(t=p.return)&&t.call(p)}finally{if(r)throw r.error}}}else{var y=e.anchor,v=null==y?void 0:y.match(s);if(y&&v)for(c=Number.parseInt(v[1]);c<=Number.parseInt(v[2]);++c){f=U(new S(Object.assign(e,{anchor:y.replace(s,c.toFixed(0))})));try{for(var b=(n=void 0,a(f)),m=b.next();!m.done;m=b.next()){var w=m.value;i.push(w)}}catch(e){n={error:e}}finally{try{m&&!m.done&&(o=b.return)&&o.call(b)}finally{if(n)throw n.error}}}else i.push(e)}return i}const q="application/hal+json",N="application/vnd.siren+json";function F(e,r){const t=e.split(/:(.+)/);if(t.length>1){const[n,o]=t;return r[n]?f.expand(r[n],{rel:o}):e}return e}function H(e,r,t){const{href:n,templated:o,...i}=r;return new S({rel:F(e,t),uri:n,...i})}var D=/^utf-?8|ascii|utf-?16-?le|ucs-?2|base-?64|latin-?1$/i,L=/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,$=/\s|\uFEFF|\xA0/,B=/\r?\n[\x20\x09]+/g,J=/[;,"]/,W=/[;,"]|\s/,G=/^[!#$%&'*+\-\.^_`|~\da-zA-Z]+$/,M=1,Q=2,K=4;function V(e){return e.replace(L,"")}function z(e){return $.test(e)}function Z(e,r){for(;z(e[r]);)r++;return r}function X(e){return W.test(e)||!G.test(e)}class Y{constructor(e){this.refs=[],e&&this.parse(e)}rel(e){for(var r=[],t=e.toLowerCase(),n=0;n<this.refs.length;n++)this.refs[n].rel.toLowerCase()===t&&r.push(this.refs[n]);return r}get(e,r){e=e.toLowerCase();for(var t=[],n=0;n<this.refs.length;n++)this.refs[n][e]===r&&t.push(this.refs[n]);return t}set(e){return this.refs.push(e),this}has(e,r){e=e.toLowerCase();for(var t=0;t<this.refs.length;t++)if(this.refs[t][e]===r)return!0;return!1}parse(e,r){e=V(e=(r=r||0)?e.slice(r):e).replace(B,"");for(var t=M,n=e.length,o=(r=0,null);r<n;)if(t===M){if(z(e[r])){r++;continue}if("<"!==e[r])throw new Error('Unexpected character "'+e[r]+'" at offset '+r);if(null!=o&&(null!=o.rel?this.refs.push(...Y.expandRelations(o)):this.refs.push(o)),-1===(s=e.indexOf(">",r)))throw new Error("Expected end of URI delimiter at offset "+r);o={uri:e.slice(r+1,s)},r=s,t=Q,r++}else if(t===Q){if(z(e[r])){r++;continue}if(";"===e[r])t=K,r++;else{if(","!==e[r])throw new Error('Unexpected character "'+e[r]+'" at offset '+r);t=M,r++}}else{if(t!==K)throw new Error('Unknown parser state "'+t+'"');if(";"===e[r]||z(e[r])){r++;continue}if(-1===(s=e.indexOf("=",r)))throw new Error("Expected attribute delimiter at offset "+r);var i=V(e.slice(r,s)).toLowerCase(),a="";if('"'===e[r=Z(e,r=s+1)])for(r++;r<n;){if('"'===e[r]){r++;break}"\\"===e[r]&&r++,a+=e[r],r++}else{for(var s=r+1;!J.test(e[s])&&s<n;)s++;a=e.slice(r,s),r=s}switch(o[i]&&Y.isSingleOccurenceAttr(i)||("*"===i[i.length-1]?o[i]=Y.parseExtendedValue(a):(a="type"===i?a.toLowerCase():a,null!=o[i]?Array.isArray(o[i])?o[i].push(a):o[i]=[o[i],a]:o[i]=a)),e[r]){case",":t=M;break;case";":t=K}r++}return null!=o&&(null!=o.rel?this.refs.push(...Y.expandRelations(o)):this.refs.push(o)),o=null,this}toString(){for(var e=[],r="",t=null,n=0;n<this.refs.length;n++)t=this.refs[n],r=Object.keys(this.refs[n]).reduce((function(e,r){return"uri"===r?e:e+"; "+Y.formatAttribute(r,t[r])}),"<"+t.uri+">"),e.push(r);return e.join(", ")}}Y.isCompatibleEncoding=function(e){return D.test(e)},Y.parse=function(e,r){return(new Y).parse(e,r)},Y.isSingleOccurenceAttr=function(e){return"rel"===e||"type"===e||"media"===e||"title"===e||"title*"===e},Y.isTokenAttr=function(e){return"rel"===e||"type"===e||"anchor"===e},Y.escapeQuotes=function(e){return e.replace(/"/g,'\\"')},Y.expandRelations=function(e){return e.rel.split(" ").map((function(r){var t=Object.assign({},e);return t.rel=r,t}))},Y.parseExtendedValue=function(e){var r=/([^']+)?(?:'([^']+)')?(.+)/.exec(e);return{language:r[2].toLowerCase(),encoding:Y.isCompatibleEncoding(r[1])?null:r[1].toLowerCase(),value:Y.isCompatibleEncoding(r[1])?decodeURIComponent(r[3]):r[3]}},Y.formatExtendedAttribute=function(e,r){var t=(r.encoding||"utf-8").toUpperCase();return e+"="+t+"'"+(r.language||"en")+"'"+(Buffer.isBuffer(r.value)&&Y.isCompatibleEncoding(t)?r.value.toString(t):Buffer.isBuffer(r.value)?r.value.toString("hex").replace(/[0-9a-f]{2}/gi,"%$1"):encodeURIComponent(r.value))},Y.formatAttribute=function(e,r){return Array.isArray(r)?r.map((r=>Y.formatAttribute(e,r))).join("; "):"*"===e[e.length-1]||"string"!=typeof r?Y.formatExtendedAttribute(e,r):(Y.isTokenAttr(e)?r=X(r)?'"'+Y.escapeQuotes(r)+'"':Y.escapeQuotes(r):X(r)&&(r='"'+(r=(r=encodeURIComponent(r)).replace(/%20/g," ").replace(/%2C/g,",").replace(/%3B/g,";"))+'"'),e+"="+r)};var ee,re,te=Y;function ne(e){return e?te.parse(e).refs.map((function(e){var r=e.rel,o=e.uri,i=e.method,a=e["accept*"],s=e["params*"],l=n(e,["rel","uri","method","accept*","params*"]),u=(null==s?void 0:s.value)?JSON.parse(null==s?void 0:s.value):void 0;return new S(t({rel:r,uri:o,method:i,parameters:u,accept:null==a?void 0:a.value},l))})):[]}function oe(e){var r,o,i=e.name,s=e.href,l=e.fields,u=e.type,c=n(e,["name","href","fields","type"]),f={};if(l)try{for(var p=a(l),d=p.next();!d.done;d=p.next()){f[d.value.name]={}}}catch(e){r={error:e}}finally{try{d&&!d.done&&(o=p.return)&&o.call(p)}finally{if(r)throw r.error}}return t({rel:i,uri:s,accept:u,parameters:l&&f},c)}function ie(e,r){var o=r.href;r.rel;var i=n(r,["href","rel"]);return new S(t({rel:e,uri:o},i))}function ae(e,r){var o=e.handlers,i=e.defaultHandlers,a=e.headers,u=e.contentParser,c=n(e,["handlers","defaultHandlers","headers","contentParser"]),f=r||{},p=f.handlers,d=f.defaultHandlers,h=f.headers,y=f.contentParser,v=n(f,["handlers","defaultHandlers","headers","contentParser"]),b=ce(l(l([],s(p||o||[]),!1),s(d||i||[]),!1)),m=y?function(e){return y(e,u)}:u;return t(t(t({},c),v),{defaultHandlers:b,handlers:[],headers:t(t({},a),h),contentParser:m})}function se(e){return e.success}var le=function(){function e(e){var r,t,n,o,i,s,l=e.handlers,u=e.defaultOptions,c=e.baseResponse,p=e.content,d=e.fullContent,h=e.anchor,y=e.parentOperations,b=e.parameters;this.response=c,this.anchor=h,this.parameters=b||{},this.fullContent=d||p,this.content=p,this.operations=_.create();var m=v({this:p});if(y&&h&&u){this.allOperations=y;try{for(var w=a(this.allOperations[h]||[]),g=w.next();!g.done;g=w.next()){var O=g.value;this.operations.push(new C(O,this,u,m))}}catch(e){r={error:e}}finally{try{g&&!g.done&&(t=w.return)&&t.call(w)}finally{if(r)throw r.error}}for(var x in this.allOperations)if(""!==x){var j=new f.Template(x),k=j.match(this.anchor);if(j.expand(k)===this.anchor){var A=Object.assign({},u,{parameters:Object.assign(k,u.parameters)});try{for(var E=(n=void 0,a(this.allOperations[x])),I=E.next();!I.done;I=E.next()){O=I.value;this.operations.push(new C(O,this,A,m))}}catch(e){n={error:e}}finally{try{I&&!I.done&&(o=E.return)&&o.call(E)}finally{if(n)throw n.error}}}}}else if(c&&l&&u){this.allOperations=function(e){var r,t,n,o,i,s,l,u,c=e.handlers,f=e.baseResponse,p=e.content,d=[],h=!1;try{for(var y=a(c),v=y.next();!v.done;v=y.next()){var b=v.value.handler(f,p,(function(){h=!0}));if(b)try{for(var m=(n=void 0,a(b)),w=m.next();!w.done;w=m.next()){var g=w.value;d.push(g)}}catch(e){n={error:e}}finally{try{w&&!w.done&&(o=m.return)&&o.call(m)}finally{if(n)throw n.error}}if(h)break}}catch(e){r={error:e}}finally{try{v&&!v.done&&(t=y.return)&&t.call(y)}finally{if(r)throw r.error}}var O={};try{for(var x=a(d),j=x.next();!j.done;j=x.next()){var k=U(g=j.value);try{for(var A=(l=void 0,a(k)),E=A.next();!E.done;E=A.next()){var I=E.value,R=I.anchor||"";O[R]||(O[R]=[]),O[R].push(I)}}catch(e){l={error:e}}finally{try{E&&!E.done&&(u=A.return)&&u.call(A)}finally{if(l)throw l.error}}}}catch(e){i={error:e}}finally{try{j&&!j.done&&(s=x.return)&&s.call(x)}finally{if(i)throw i.error}}return O}({baseResponse:c,content:p,handlers:l}),this.operations=_.create();try{for(var R=a(this.allOperations[""]||[]),P=R.next();!P.done;P=R.next()){O=P.value;var S=new C(O,this,u,m);this.operations.push(S)}}catch(e){i={error:e}}finally{try{P&&!P.done&&(s=R.return)&&s.call(R)}finally{if(i)throw i.error}}}}return e.create=function(r,t,n,o){if(t instanceof P)throw new ue({response:new e({handlers:o.defaultHandlers,defaultOptions:n,baseResponse:r,content:t,parameters:o.parameters}),problem:t});if(o.validator){var i=o.validator(t);if(se(i))return new e({handlers:o.defaultHandlers,defaultOptions:n,baseResponse:r,content:i.content,parameters:o.parameters});throw new ue({response:new e({handlers:o.defaultHandlers,defaultOptions:n,baseResponse:r,content:t,parameters:o.parameters}),problem:i.problem})}return new e({handlers:o.defaultHandlers,defaultOptions:n,baseResponse:r,content:t,parameters:o.parameters})},Object.defineProperty(e.prototype,"ops",{get:function(){return this.operations},enumerable:!1,configurable:!0}),e.prototype.invoke=function(e,r){return this.operations.invoke(e,r)},e.prototype.invokeAll=function(e,r){return this.operations.invokeAll(e,r)},Object.defineProperty(e.prototype,"body",{get:function(){throw new Error("Not Implemented. Use `.content` instead")},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"bodyUsed",{get:function(){return!0},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"headers",{get:function(){var e;return null===(e=this.response)||void 0===e?void 0:e.headers},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"ok",{get:function(){return!!this.response&&this.response.ok},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"redirected",{get:function(){return!!this.response&&this.response.redirected},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"status",{get:function(){var e;return null===(e=this.response)||void 0===e?void 0:e.status},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"statusText",{get:function(){var e;return null===(e=this.response)||void 0===e?void 0:e.statusText},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"type",{get:function(){var e;return null===(e=this.response)||void 0===e?void 0:e.type},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"url",{get:function(){var e;return null===(e=this.response)||void 0===e?void 0:e.url},enumerable:!1,configurable:!0}),e.prototype.arrayBuffer=function(){throw new Error("Not Implemented. Use `.content` instead")},e.prototype.blob=function(){throw new Error("Not Implemented. Use `.content` instead")},e.prototype.clone=function(){throw new Error("Not Implemented")},e.prototype.formData=function(){throw new Error("Not Implemented. Use `.content` instead")},e.prototype.text=function(){throw new Error("Not Implemented. Use `.content` instead")},e}(),ue=function(e){function t(r){var t=this.constructor,n=r.response,o=r.problem,i=e.call(this,o.detail)||this,a=t.prototype;return Object.setPrototypeOf?Object.setPrototypeOf(i,a):i.__proto__=a,i.problem=o,i.response=n,i}return r(t,e),t}(Error);function ce(e){return e.sort((function(e,r){return(r.q||1)-(e.q||1)}))}function fe(e,r,n){var u;return o(this,void 0,void 0,(function(){var o,c,f,p,d,h,y,v,b,m,w,g,O,x,j,k,A,E,I,R,S,C,_,T,U;return i(this,(function(i){switch(i.label){case 0:if(o=ae(r,n),c=o.defaultHandlers,!o.fetch)throw new Error("No global fetch and fetch not provided in options");f=function(e){var r,t,n,o,i=[];try{for(var s=a(e),l=s.next();!l.done;l=s.next()){var u=l.value;try{for(var c=(n=void 0,a(u.mediaRanges)),f=c.next();!f.done;f=c.next()){var p=f.value;"object"==typeof p?u.q?i.push({type:p.mediaType,q:u.q*(p.q||1)}):i.push({type:p.mediaType,q:p.q||1}):u.q?i.push({type:p,q:u.q}):i.push({type:p,q:1})}}catch(e){n={error:e}}finally{try{f&&!f.done&&(o=c.return)&&o.call(c)}finally{if(n)throw n.error}}}}catch(e){r={error:e}}finally{try{l&&!l.done&&(t=s.return)&&t.call(s)}finally{if(r)throw r.error}}var d=i.sort((function(e,r){return e.q-r.q})),h=new Set;return d.filter((function(e){var r=e.type;return!h.has(r)&&h.add(r)}))}(c),p=f.map((function(e){return 1===e.q?e.type:"".concat(e.type,";q=").concat(e.q)})),d=(null===(u=null==n?void 0:n.headers)||void 0===u?void 0:u.accept)?[n.headers.accept]:[],h=l(l([],s(d),!1),s(p),!1).join(","),y=t(t({},o),{headers:t(t({},o.headers),{accept:h})}),v=!1;try{for(b=a(y.preInterceptors||[]),m=b.next();!m.done&&((0,m.value)(e,y,(function(){return v=!0})),!v);m=b.next());}catch(e){R={error:e}}finally{try{m&&!m.done&&(S=b.return)&&S.call(b)}finally{if(R)throw R.error}}return[4,o.fetch(e.toString(),y)];case 1:w=i.sent(),i.label=2;case 2:return i.trys.push([2,4,,5]),[4,o.contentParser(w)];case 3:g=i.sent(),k=le.create(w,g,r,o),v=!1;try{for(O=a(y.postInterceptors),x=O.next();!x.done&&((0,x.value)(k,(function(){return v=!0})),!v);x=O.next());}catch(e){C={error:e}}finally{try{x&&!x.done&&(_=O.return)&&_.call(O)}finally{if(C)throw C.error}}return[2,k];case 4:j=i.sent(),k=new le({handlers:o.defaultHandlers,defaultOptions:r,baseResponse:w,content:j,parameters:o.parameters}),A=new ue(j instanceof P?{response:k,problem:j}:{response:k,problem:new P({type:"https://waychaser.io/unexected-error",title:"An unexpected error occurred",error:j})}),v=!1;try{for(E=a(y.postErrorInterceptors),I=E.next();!I.done&&((0,I.value)(A,(function(){return v=!0})),!v);I=E.next());}catch(e){T={error:e}}finally{try{I&&!I.done&&(U=E.return)&&U.call(E)}finally{if(T)throw T.error}}throw A;case 5:return[2]}}))}))}var pe={fetch:"undefined"!=typeof window?null===(ee=window.fetch)||void 0===ee?void 0:ee.bind(window):null===(re="undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0)||void 0===re?void 0:re.fetch,handlers:[],defaultHandlers:ce([{handler:function(e){var r=null==e?void 0:e.headers.get("location");return r?[new S({rel:"related",uri:r})]:[]},mediaRanges:["*/*"],q:.4},{handler:function(e,r,t){return l(l([],s(ne(e.headers.get("link"))),!1),s(ne(e.headers.get("link-template"))),!1)},mediaRanges:["*/*"],q:.5},{handler:function(e,r){var t,n,o,i,s,l,u,c=[],f=null===(u=e.headers.get("content-type"))||void 0===u?void 0:u.split(";");if((null==f?void 0:f[0])===q&&r&&"object"==typeof r&&"_links"in r){var p=r,d={};if(p._links.curies)if(Array.isArray(p._links.curies))try{for(var h=a(p._links.curies),y=h.next();!y.done;y=h.next()){var v=y.value;d[v.name]=v.href}}catch(e){t={error:e}}finally{try{y&&!y.done&&(n=h.return)&&n.call(h)}finally{if(t)throw t.error}}else d[p._links.curies.name]=p._links.curies.href;try{for(var b=a(Object.keys(p._links).filter((function(e){return"curies"!==e}))),m=b.next();!m.done;m=b.next()){var w=m.value;if(Array.isArray(p._links[w]))try{for(var g=(s=void 0,a(p._links[w])),O=g.next();!O.done;O=g.next()){var x=O.value;c.push(H(w,x,d))}}catch(e){s={error:e}}finally{try{O&&!O.done&&(l=g.return)&&l.call(g)}finally{if(s)throw s.error}}else c.push(H(w,p._links[w],d))}}catch(e){o={error:e}}finally{try{m&&!m.done&&(i=b.return)&&i.call(b)}finally{if(o)throw o.error}}}return c},mediaRanges:[q],q:.5},{handler:function(e,r){var t,n=null===(t=e.headers.get("content-type"))||void 0===t?void 0:t.split(";");return(null==n?void 0:n[0])===N?l(l([],s(function(e){var r,t,n,o,i=[];if(e&&"object"==typeof e&&"links"in e){var s=e;if(s.links)try{for(var l=a(s.links),u=l.next();!u.done;u=l.next()){var c=u.value;try{for(var f=(n=void 0,a(c.rel)),p=f.next();!p.done;p=f.next()){var d=ie(p.value,c);i.push(d)}}catch(e){n={error:e}}finally{try{p&&!p.done&&(o=f.return)&&o.call(f)}finally{if(n)throw n.error}}}}catch(e){r={error:e}}finally{try{u&&!u.done&&(t=l.return)&&t.call(l)}finally{if(r)throw r.error}}}return i}(r)),!1),s(function(e){var r,t,n=[];if(e&&"object"==typeof e&&"actions"in e){var o=e;if(o.actions)try{for(var i=a(o.actions),s=i.next();!s.done;s=i.next()){var l=oe(s.value);n.push(l)}}catch(e){r={error:e}}finally{try{s&&!s.done&&(t=i.return)&&t.call(i)}finally{if(r)throw r.error}}}return n}(r)),!1):[]},mediaRanges:[N],q:.5}]),preInterceptors:[],postInterceptors:[],postErrorInterceptors:[],contentParser:function(e){return o(void 0,void 0,void 0,(function(){var r,t,n,o,a;return i(this,(function(i){switch(i.label){case 0:return e.headers.get("content-length")&&"0"!==e.headers.get("content-length")?[4,e.text()]:[3,2];case 1:if(r=i.sent(),null==(t=null===(a=null===(o=e.headers.get("content-type"))||void 0===o?void 0:o.split(";"))||void 0===a?void 0:a[0])?void 0:t.endsWith("json")){if(n=function(e,r){try{return JSON.parse(e)}catch(t){throw new P({type:"https://waychaser.io/invalid-json",title:"JSON response could not be parsed",detail:"The response document with content type '".concat(r,"' could not be parsed as json"),content:e,error:t})}}(r,t),"application/problem+json"===t)throw Object.assign(new P(n),n);return[2,n]}i.label=2;case 2:return[2]}}))}))}};function de(e,r){var t=ae(r,e),n=function(e,r){return fe(e,t,r)};return n.currentDefaults=t,n.defaults=function(e){return de(e,t)},n}var he=Object.assign((function(e,r){return fe(e,pe,r)}),{currentDefaults:pe,defaults:function(e){return de(e,pe)}});export{ue as WayChaserProblem,le as WayChaserResponse,fe as _waychaser,se as isValidationSuccess,ce as sortHandlers,he as waychaser};
15
+ var e=function(r,t){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,r){e.__proto__=r}||function(e,r){for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(e[t]=r[t])})(r,t)};function r(r,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=r}e(r,t),r.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}var t=function(){return(t=Object.assign||function(e){for(var r,t=1,n=arguments.length;t<n;t++)for(var o in r=arguments[t])Object.prototype.hasOwnProperty.call(r,o)&&(e[o]=r[o]);return e}).apply(this,arguments)};function n(e,r){var t={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&r.indexOf(n)<0&&(t[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)r.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(t[n[o]]=e[n[o]])}return t}function o(e,r,t,n){return new(t||(t=Promise))((function(o,i){function a(e){try{l(n.next(e))}catch(e){i(e)}}function s(e){try{l(n.throw(e))}catch(e){i(e)}}function l(e){var r;e.done?o(e.value):(r=e.value,r instanceof t?r:new t((function(e){e(r)}))).then(a,s)}l((n=n.apply(e,r||[])).next())}))}function i(e,r){var t,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(t)throw new TypeError("Generator is already executing.");for(;a;)try{if(t=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,n=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=r.call(e,a)}catch(e){i=[6,e],n=0}finally{t=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}}function a(e){var r="function"==typeof Symbol&&Symbol.iterator,t=r&&e[r],n=0;if(t)return t.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(r?"Object is not iterable.":"Symbol.iterator is not defined.")}function s(e,r){var t="function"==typeof Symbol&&e[Symbol.iterator];if(!t)return e;var n,o,i=t.call(e),a=[];try{for(;(void 0===r||r-- >0)&&!(n=i.next()).done;)a.push(n.value)}catch(e){o={error:e}}finally{try{n&&!n.done&&(t=i.return)&&t.call(i)}finally{if(o)throw o.error}}return a}function l(e,r,t){if(t||2===arguments.length)for(var n,o=0,i=r.length;o<i;o++)!n&&o in r||(n||(n=Array.prototype.slice.call(r,0,o)),n[o]=r[o]);return e.concat(n||Array.prototype.slice.call(r))}var u="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},c={};!function(e){var r=/[!'()]/g,t={"":",","+":",","#":",","?":"&"},n=/[$-\/?[-^{|}]/g,o=/\{([#&+.\/;?]?)((?:[-\w%.]+(\*|:\d+)?,?)+)\}/g,i=RegExp(o.source+"|.[^{]*?","g");function a(e){return encodeURIComponent(e).replace(r,escape)}function s(e){return null!=e}function l(e,r,t){return(e=e.map(r).filter(s)).length&&e.join(t)}function u(e,r){return e.replace(o,(function(e,n,o){var i=t[n]||n,s=";"==i||"&"==i,u=n&&","==i?encodeURI:a,c=l(o.split(","),(function(e){var t=e.split(/[*:]/),n=t[0],o=r[n];if(null!=o){if("object"==typeof o){if(t=n!=e,Array.isArray(o)?o=l(o,u,t?s?i+n+"=":i:","):(o=l(Object.keys(o),(function(e){return u(e)+(t?"=":",")+u(o[e])}),t&&(s||"/"==i)?i:","),t&&(s=0)),!o)return}else o=u(t[1]?o.slice(0,t[1]):o);return s?n+(o||"&"==i?"="+o:o):o}}),i);return c||""===c?"+"!=n?n+c:c:""}))}e.expand=u,e.Template=function(e){var r=this,o=0,a={},s="",l="^"+e.replace(i,(function(e,r,n){if(!n)return p(e);var i=t[r]||r,l=";"==i||"&"==i,u=n.split(",").map((function(e){var r=e.split(/[*:]/),t=r[0],n=(a[t]||"(")+".*?)";return o++,r[1]&&(n="((?:%..|.){1,"+r[1]+"})",a[t]="(\\"+o),s+="t=($["+o+"]||'').split('"+i+"').map(decodeURIComponent);",s+='o["'+t+'"]=t.length>1?t:t[0];',l?p(t)+"(?:="+n+")?":"&"==i?p(t+"=")+n:n})).join(p(i));return"+"!=r?p(r)+u:u}))+"$",c=RegExp(l),f=Function("$","var t,o={};"+s+"return o");function p(e){return e.replace(n,"\\$&")}r.template=e,r.match=function(e){var r=c.exec(e);return r&&f(r)},r.expand=u.bind(r,e)}}(u.URI||(u.URI={}));const f=function(){const e="undefined"==typeof window?c.URI||global.URI:window.URI||c.URI;return e.parameters=function(e){return new f.Template(e).match(e)},e}();var p=Object.prototype.hasOwnProperty,d=function e(r,t){var n=[];for(var o in r)if(p.call(r,o)){var i,a=r[o],s=encodeURIComponent(o);i="object"==typeof a?e(a,t?t+"["+s+"]":s):(t?t+"["+s+"]":s)+"="+encodeURIComponent(a),n.push(i)}return n.join("&")},h="object"==typeof self?self.FormData:window.FormData;function y(e,r,t){if(e){return function(e){return e.split(",").map((function(e){var r,t,n=e.split(";"),o=n.shift(),i=null==o?void 0:o.split("/"),s={type:o,parentType:null==i?void 0:i[0],subType:null==i?void 0:i[1],q:1};try{for(var l=a(n),u=l.next();!u.done;u=l.next()){var c=u.value,f=c.split("=");"q"===c[0]&&(s[f[0]]=Number.parseFloat(f[1]))}}catch(e){r={error:e}}finally{try{u&&!u.done&&(t=l.return)&&t.call(l)}finally{if(r)throw r.error}}return s})).sort((function(e,r){return e.q>r.q?-1:e.q<r.q||"*"===e.parentType&&"*"!==r.parentType?1:"*"!==e.parentType&&"*"===r.parentType?-1:"*"===e.subType&&"*"!==r.subType?1:"*"!==e.subType&&"*"===r.subType?-1:0})).map((function(e){return{type:e.type||""}})).filter((function(e){return""!==e.type}))}(e).find((e=>r.includes(e.type))).type}return t}var v=w;function b(e){return e&&e.constructor&&"function"==typeof e.constructor.isBuffer&&e.constructor.isBuffer(e)}function m(e){return e}function w(e,r){const t=(r=r||{}).delimiter||".",n=r.maxDepth,o=r.transformKey||m,i={};return function e(a,s,l){l=l||1,Object.keys(a).forEach((function(u){const c=a[u],f=r.safe&&Array.isArray(c),p=Object.prototype.toString.call(c),d=b(c),h="[object Object]"===p||"[object Array]"===p,y=s?s+t+o(u):o(u);if(!f&&!d&&h&&Object.keys(c).length&&(!r.maxDepth||l<n))return e(c,y,l+1);i[y]=c}))}(e),i}w.flatten=w,w.unflatten=function e(r,t){const n=(t=t||{}).delimiter||".",o=t.overwrite||!1,i=t.transformKey||m,a={};if(b(r)||"[object Object]"!==Object.prototype.toString.call(r))return r;function s(e){const r=Number(e);return isNaN(r)||-1!==e.indexOf(".")||t.object?e:r}return r=Object.keys(r).reduce((function(e,o){const i=Object.prototype.toString.call(r[o]);return!("[object Object]"===i||"[object Array]"===i)||function(e){const r=Object.prototype.toString.call(e),t="[object Array]"===r,n="[object Object]"===r;if(!e)return!0;if(t)return!e.length;if(n)return!Object.keys(e).length}(r[o])?(e[o]=r[o],e):function(e,r,t){return Object.keys(t).reduce((function(r,o){return r[e+n+o]=t[o],r}),r)}(o,e,w(r[o],t))}),{}),Object.keys(r).forEach((function(l){const u=l.split(n).map(i);let c=s(u.shift()),f=s(u[0]),p=a;for(;void 0!==f;){if("__proto__"===c)return;const e=Object.prototype.toString.call(p[c]),r="[object Object]"===e||"[object Array]"===e;if(!o&&!r&&void 0!==p[c])return;(o&&!r||!o&&null==p[c])&&(p[c]="number"!=typeof f||t.object?{}:[]),p=p[c],u.length>0&&(c=s(u.shift()),f=s(u[0]))}p[c]=e(r[l],t)})),a};var g={},O=/~/,x=/~[01]/g;function j(e){switch(e){case"~1":return"/";case"~0":return"~"}throw new Error("Invalid tilde escape: "+e)}function k(e){return O.test(e)?e.replace(x,j):e}function A(e){if("string"==typeof e){if(""===(e=e.split("/"))[0])return e;throw new Error("Invalid JSON pointer.")}if(Array.isArray(e)){for(const r of e)if("string"!=typeof r&&"number"!=typeof r)throw new Error("Invalid JSON pointer. Must be of type string or number.");return e}throw new Error("Invalid JSON pointer.")}function E(e,r){if("object"!=typeof e)throw new Error("Invalid input object.");var t=(r=A(r)).length;if(1===t)return e;for(var n=1;n<t;){if(e=e[k(r[n++])],t===n)return e;if("object"!=typeof e||null===e)return}}function I(e,r,t){if("object"!=typeof e)throw new Error("Invalid input object.");if(0===(r=A(r)).length)throw new Error("Invalid JSON pointer for set.");return function(e,r,t){for(var n,o,i=1,a=r.length;i<a;){if("constructor"===r[i]||"prototype"===r[i]||"__proto__"===r[i])return e;if(n=k(r[i++]),o=a>i,void 0===e[n]&&(Array.isArray(e)&&"-"===n&&(n=e.length),o&&(""!==r[i]&&r[i]<1/0||"-"===r[i]?e[n]=[]:e[n]={})),!o)break;e=e[n]}var s=e[n];return void 0===t?delete e[n]:e[n]=t,s}(e,r,t)}g.get=E,g.set=I,g.compile=function(e){var r=A(e);return{get:function(e){return E(e,r)},set:function(e,t){return I(e,r,t)}}};var R={};Object.defineProperty(R,"__esModule",{value:!0});var C=R.ProblemDocument=void 0;C=R.ProblemDocument=class{constructor(e){Object.assign(this,e)}};var P=function(e){var r=e.rel,t=e.uri,o=e.method,i=e.parameters,a=e.accept,s=e.anchor,l=n(e,["rel","uri","method","parameters","accept","anchor"]);this.rel=r,this.uri=t,this.method=o,this.parameters=i||{},this.accept=a,this.anchor=s,Object.assign(this,l)},S=function(e){function t(r,t,n,o){var i=e.call(this,r)||this;return i.response=t,i.defaultOptions=n,i.uri.includes("{this.")&&(i.uri=f.expand(i.uri,o)),i}return r(t,e),t.prototype.invokeAsFragment=function(e,r){if(this.uri.startsWith("#/")){var t=this.expandUrl(e).toString(),n=this.response.fullContent&&g.get(this.response.fullContent,t.slice(1));if(void 0===n)return;if(r){var o=r(n);if(se(o))return new le({defaultOptions:this.defaultOptions,baseResponse:this.response.response,content:o.content,fullContent:this.response.fullContent,anchor:t,parentOperations:this.response.allOperations,parameters:e});throw new ue({problem:o.problem,response:new le({defaultOptions:this.defaultOptions,baseResponse:this.response.response,content:n,fullContent:this.response.fullContent,parameters:e})})}return new le({defaultOptions:this.defaultOptions,baseResponse:this.response.response,content:n,fullContent:this.response.fullContent,anchor:t,parentOperations:this.response.allOperations,parameters:e})}},t.prototype.invokeAll=function(e){return o(this,void 0,void 0,(function(){var r;return i(this,(function(t){return this.uri.startsWith("#/")&&this.response instanceof le?(r=this.doInvokeAll((null==e?void 0:e.parameters)||{}),[2,Promise.all(r)]):[2,Promise.all([this.invoke(e)])]}))}))},t.prototype.doInvokeAll=function(e,r){var t=this,n=this.response,o=new f.Template(this.uri),i=Object.assign(f.parameters(this.uri),e),a=o.expand(i).replace(/%7B/g,"{").replace(/%7D/g,"}"),u=f.parameters(a),c=Object.keys(u);if(0!==c.length){var p=u[c[0]],d=a.slice(1,a.indexOf(p)-1),h=""===d?n.content:g.get(n.content,d);if(h)return(Array.isArray(h)?l([],s(Array.from({length:h.length}).keys()),!1):Object.keys(h)).flatMap((function(n){var o,i=Object.assign({},e,((o={})[c[0]]=n,o));return t.doInvokeAll(i,r)}));throw new ue({response:this.response,problem:new C({type:"https://waychaser.io/fragment-uri-error",title:"The fragment URI does not match the content structure",uri:d,content:n.content,parameters:e})})}return[this.invokeAsFragment(e,r)]},t.prototype.invoke=function(e){return o(this,void 0,void 0,(function(){var r,t,n,o,s,l,u,c,f,p,v,b,m,w,g,O,x,j;return i(this,(function(i){if(this.uri.startsWith("#/"))return[2,this.invokeAsFragment(null==e?void 0:e.parameters)];if(r=this.parameters||{},t=Object.assign({},this.defaultOptions.parameters,null==e?void 0:e.parameters),n=this.url(t),o={},Array.isArray(r))try{for(s=a(r),l=s.next();!l.done;l=s.next())f=l.value,o[f]=null==t?void 0:t[f]}catch(e){g={error:e}}finally{try{l&&!l.done&&(O=s.return)&&O.call(s)}finally{if(g)throw g.error}}else try{for(u=a(Object.keys(r)),c=u.next();!c.done;c=u.next())f=c.value,o[f]=null==t?void 0:t[f]}catch(e){x={error:e}}finally{try{c&&!c.done&&(j=u.return)&&j.call(u)}finally{if(x)throw x.error}}if(p=void 0,v={},(b=Object.assign({},e)).method=this.method,0!==Object.keys(this.parameters).length&&(k=this.method||"GET",!["GET","DELETE","TRACE","OPTIONS","HEAD"].includes(k))){switch(m=y(this.accept,["application/x-www-form-urlencoded","application/json","multipart/form-data"],"application/x-www-form-urlencoded")){case"application/x-www-form-urlencoded":p=d(o);break;case"application/json":p=JSON.stringify(o);break;case"multipart/form-data":for(w in p=new h,o)p.append(w,o[w])}"multipart/form-data"!==m&&(v={"content-type":m}),b.body=p,b.headers=Object.assign(v,null==e?void 0:e.headers)}return[2,fe(n.toString(),this.defaultOptions,b)];var k}))}))},t.prototype.url=function(e){var r=this.expandUrl(e);return new URL(r,this.response.url)},t.prototype.expandUrl=function(e){return f.expand(this.uri,v(e||{}))},t}(P),_=function(e){function t(r){return e.apply(this,l([],s(r||[]),!1))||this}return r(t,e),t.create=function(){return Object.create(t.prototype)},t.prototype.find=function(e,r){var t=Array.prototype.find.bind(this);return t("string"==typeof e?T({rel:e}):"object"==typeof e?T(e):e,r)},t.prototype.filter=function(e,r){if("string"==typeof e)return this.filter({rel:e},r);if("object"==typeof e)return this.filter(T(e),r);var n=Array.prototype.filter.bind(this)(e);return Object.setPrototypeOf(n,t.prototype),n},t.prototype.invoke=function(e,r){var t=this.find(e);return t?t.invoke(r):void 0},t.prototype.invokeAll=function(e,r){var t=this.filter(e);return Promise.all(t.map((function(e){return e.invokeAll(r)}))).then((function(e){return e.flat()}))},t}(Array);function T(e){return function(r){for(var t in e)if(e[t]!==r[t])return!1;return!0}}function U(e){var r,t,n,o,i=[],s=/{\[(\d+)..(\d+)]}/,l=e.uri.toString(),u=l.match(s);if(u)for(var c=Number.parseInt(u[1]);c<=Number.parseInt(u[2]);++c){var f=U(new P(Object.assign(e,{uri:l.replace(s,c.toFixed(0))})));try{for(var p=(r=void 0,a(f)),d=p.next();!d.done;d=p.next()){var h=d.value;i.push(h)}}catch(e){r={error:e}}finally{try{d&&!d.done&&(t=p.return)&&t.call(p)}finally{if(r)throw r.error}}}else{var y=e.anchor,v=null==y?void 0:y.match(s);if(y&&v)for(c=Number.parseInt(v[1]);c<=Number.parseInt(v[2]);++c){f=U(new P(Object.assign(e,{anchor:y.replace(s,c.toFixed(0))})));try{for(var b=(n=void 0,a(f)),m=b.next();!m.done;m=b.next()){var w=m.value;i.push(w)}}catch(e){n={error:e}}finally{try{m&&!m.done&&(o=b.return)&&o.call(b)}finally{if(n)throw n.error}}}else i.push(e)}return i}const q="application/hal+json",N="application/vnd.siren+json";function F(e,r){const t=e.split(/:(.+)/);if(t.length>1){const[n,o]=t;return r[n]?f.expand(r[n],{rel:o}):e}return e}function L(e,r,t){const{href:n,templated:o,...i}=r;return new P({rel:F(e,t),uri:n,...i})}var H=/^utf-?8|ascii|utf-?16-?le|ucs-?2|base-?64|latin-?1$/i,D=/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,$=/\s|\uFEFF|\xA0/,B=/\r?\n[\x20\x09]+/g,J=/[;,"]/,W=/[;,"]|\s/,G=/^[!#$%&'*+\-\.^_`|~\da-zA-Z]+$/,M=1,Q=2,K=4;function V(e){return e.replace(D,"")}function z(e){return $.test(e)}function Z(e,r){for(;z(e[r]);)r++;return r}function X(e){return W.test(e)||!G.test(e)}class Y{constructor(e){this.refs=[],e&&this.parse(e)}rel(e){for(var r=[],t=e.toLowerCase(),n=0;n<this.refs.length;n++)"string"==typeof this.refs[n].rel&&this.refs[n].rel.toLowerCase()===t&&r.push(this.refs[n]);return r}get(e,r){e=e.toLowerCase(),r=r.toLowerCase();for(var t=[],n=0;n<this.refs.length;n++)"string"==typeof this.refs[n][e]&&this.refs[n][e].toLowerCase()===r&&t.push(this.refs[n]);return t}set(e){return this.refs.push(e),this}setUnique(e){return this.refs.some((r=>{return t=r,n=e,Object.keys(t).length===Object.keys(n).length&&Object.keys(t).every((e=>e in n&&t[e]===n[e]));var t,n}))||this.refs.push(e),this}has(e,r){e=e.toLowerCase(),r=r.toLowerCase();for(var t=0;t<this.refs.length;t++)if("string"==typeof this.refs[t][e]&&this.refs[t][e].toLowerCase()===r)return!0;return!1}parse(e,r){e=V(e=(r=r||0)?e.slice(r):e).replace(B,"");for(var t=M,n=e.length,o=(r=0,null);r<n;)if(t===M){if(z(e[r])){r++;continue}if("<"!==e[r])throw new Error('Unexpected character "'+e[r]+'" at offset '+r);if(null!=o&&(null!=o.rel?this.refs.push(...Y.expandRelations(o)):this.refs.push(o)),-1===(s=e.indexOf(">",r)))throw new Error("Expected end of URI delimiter at offset "+r);o={uri:e.slice(r+1,s)},r=s,t=Q,r++}else if(t===Q){if(z(e[r])){r++;continue}if(";"===e[r])t=K,r++;else{if(","!==e[r])throw new Error('Unexpected character "'+e[r]+'" at offset '+r);t=M,r++}}else{if(t!==K)throw new Error('Unknown parser state "'+t+'"');if(";"===e[r]||z(e[r])){r++;continue}-1===(s=e.indexOf("=",r))&&(s=e.indexOf(";",r)),-1===s&&(s=e.length);var i=V(e.slice(r,s)).toLowerCase(),a="";if('"'===e[r=Z(e,r=s+1)])for(r++;r<n;){if('"'===e[r]){r++;break}"\\"===e[r]&&r++,a+=e[r],r++}else{for(var s=r+1;!J.test(e[s])&&s<n;)s++;a=e.slice(r,s),r=s}switch(o[i]&&Y.isSingleOccurenceAttr(i)||("*"===i[i.length-1]?o[i]=Y.parseExtendedValue(a):(a="type"===i?a.toLowerCase():a,null!=o[i]?Array.isArray(o[i])?o[i].push(a):o[i]=[o[i],a]:o[i]=a)),e[r]){case",":t=M;break;case";":t=K}r++}return null!=o&&(null!=o.rel?this.refs.push(...Y.expandRelations(o)):this.refs.push(o)),o=null,this}toString(){for(var e=[],r="",t=null,n=0;n<this.refs.length;n++)t=this.refs[n],r=Object.keys(this.refs[n]).reduce((function(e,r){return"uri"===r?e:e+"; "+Y.formatAttribute(r,t[r])}),"<"+t.uri+">"),e.push(r);return e.join(", ")}}Y.isCompatibleEncoding=function(e){return H.test(e)},Y.parse=function(e,r){return(new Y).parse(e,r)},Y.isSingleOccurenceAttr=function(e){return"rel"===e||"type"===e||"media"===e||"title"===e||"title*"===e},Y.isTokenAttr=function(e){return"rel"===e||"type"===e||"anchor"===e},Y.escapeQuotes=function(e){return e.replace(/"/g,'\\"')},Y.expandRelations=function(e){return e.rel.split(" ").map((function(r){var t=Object.assign({},e);return t.rel=r,t}))},Y.parseExtendedValue=function(e){var r=/([^']+)?(?:'([^']*)')?(.+)/.exec(e);return{language:r[2].toLowerCase(),encoding:Y.isCompatibleEncoding(r[1])?null:r[1].toLowerCase(),value:Y.isCompatibleEncoding(r[1])?decodeURIComponent(r[3]):r[3]}},Y.formatExtendedAttribute=function(e,r){var t=(r.encoding||"utf-8").toUpperCase();return e+"="+t+"'"+(r.language||"en")+"'"+(Buffer.isBuffer(r.value)&&Y.isCompatibleEncoding(t)?r.value.toString(t):Buffer.isBuffer(r.value)?r.value.toString("hex").replace(/[0-9a-f]{2}/gi,"%$1"):encodeURIComponent(r.value))},Y.formatAttribute=function(e,r){return Array.isArray(r)?r.map((r=>Y.formatAttribute(e,r))).join("; "):"*"===e[e.length-1]||"string"!=typeof r?Y.formatExtendedAttribute(e,r):(Y.isTokenAttr(e)?r=X(r)?'"'+Y.escapeQuotes(r)+'"':Y.escapeQuotes(r):X(r)&&(r='"'+(r=(r=encodeURIComponent(r)).replace(/%20/g," ").replace(/%2C/g,",").replace(/%3B/g,";"))+'"'),e+"="+r)};var ee,re,te=Y;function ne(e){return e?te.parse(e).refs.map((function(e){var r=e.rel,o=e.uri,i=e.method,a=e["accept*"],s=e["params*"],l=n(e,["rel","uri","method","accept*","params*"]),u=(null==s?void 0:s.value)?JSON.parse(null==s?void 0:s.value):void 0;return new P(t({rel:r,uri:o,method:i,parameters:u,accept:null==a?void 0:a.value},l))})):[]}function oe(e){var r,o,i=e.name,s=e.href,l=e.fields,u=e.type,c=n(e,["name","href","fields","type"]),f={};if(l)try{for(var p=a(l),d=p.next();!d.done;d=p.next()){f[d.value.name]={}}}catch(e){r={error:e}}finally{try{d&&!d.done&&(o=p.return)&&o.call(p)}finally{if(r)throw r.error}}return t({rel:i,uri:s,accept:u,parameters:l&&f},c)}function ie(e,r){var o=r.href;r.rel;var i=n(r,["href","rel"]);return new P(t({rel:e,uri:o},i))}function ae(e,r){var o=e.handlers,i=e.defaultHandlers,a=e.headers,u=e.contentParser,c=n(e,["handlers","defaultHandlers","headers","contentParser"]),f=r||{},p=f.handlers,d=f.defaultHandlers,h=f.headers,y=f.contentParser,v=n(f,["handlers","defaultHandlers","headers","contentParser"]),b=ce(l(l([],s(p||o||[]),!1),s(d||i||[]),!1)),m=y?function(e){return y(e,u)}:u;return t(t(t({},c),v),{defaultHandlers:b,handlers:[],headers:t(t({},a),h),contentParser:m})}function se(e){return e.success}var le=function(){function e(e){var r,t,n,o,i,s,l=e.handlers,u=e.defaultOptions,c=e.baseResponse,p=e.content,d=e.fullContent,h=e.anchor,y=e.parentOperations,b=e.parameters;this.response=c,this.anchor=h,this.parameters=b||{},this.fullContent=d||p,this.content=p,this.operations=_.create();var m=v({this:p});if(y&&h&&u){this.allOperations=y;try{for(var w=a(this.allOperations[h]||[]),g=w.next();!g.done;g=w.next()){var O=g.value;this.operations.push(new S(O,this,u,m))}}catch(e){r={error:e}}finally{try{g&&!g.done&&(t=w.return)&&t.call(w)}finally{if(r)throw r.error}}for(var x in this.allOperations)if(""!==x){var j=new f.Template(x),k=j.match(this.anchor);if(j.expand(k)===this.anchor){var A=Object.assign({},u,{parameters:Object.assign(k,u.parameters)});try{for(var E=(n=void 0,a(this.allOperations[x])),I=E.next();!I.done;I=E.next()){O=I.value;this.operations.push(new S(O,this,A,m))}}catch(e){n={error:e}}finally{try{I&&!I.done&&(o=E.return)&&o.call(E)}finally{if(n)throw n.error}}}}}else if(c&&l&&u){this.allOperations=function(e){var r,t,n,o,i,s,l,u,c=e.handlers,f=e.baseResponse,p=e.content,d=[],h=!1;try{for(var y=a(c),v=y.next();!v.done;v=y.next()){var b=v.value.handler(f,p,(function(){h=!0}));if(b)try{for(var m=(n=void 0,a(b)),w=m.next();!w.done;w=m.next()){var g=w.value;d.push(g)}}catch(e){n={error:e}}finally{try{w&&!w.done&&(o=m.return)&&o.call(m)}finally{if(n)throw n.error}}if(h)break}}catch(e){r={error:e}}finally{try{v&&!v.done&&(t=y.return)&&t.call(y)}finally{if(r)throw r.error}}var O={};try{for(var x=a(d),j=x.next();!j.done;j=x.next()){var k=U(g=j.value);try{for(var A=(l=void 0,a(k)),E=A.next();!E.done;E=A.next()){var I=E.value,R=I.anchor||"";O[R]||(O[R]=[]),O[R].push(I)}}catch(e){l={error:e}}finally{try{E&&!E.done&&(u=A.return)&&u.call(A)}finally{if(l)throw l.error}}}}catch(e){i={error:e}}finally{try{j&&!j.done&&(s=x.return)&&s.call(x)}finally{if(i)throw i.error}}return O}({baseResponse:c,content:p,handlers:l}),this.operations=_.create();try{for(var R=a(this.allOperations[""]||[]),C=R.next();!C.done;C=R.next()){O=C.value;var P=new S(O,this,u,m);this.operations.push(P)}}catch(e){i={error:e}}finally{try{C&&!C.done&&(s=R.return)&&s.call(R)}finally{if(i)throw i.error}}}}return e.create=function(r,t,n,o){if(t instanceof C)throw new ue({response:new e({handlers:o.defaultHandlers,defaultOptions:n,baseResponse:r,content:t,parameters:o.parameters}),problem:t});if(o.validator){var i=o.validator(t);if(se(i))return new e({handlers:o.defaultHandlers,defaultOptions:n,baseResponse:r,content:i.content,parameters:o.parameters});throw new ue({response:new e({handlers:o.defaultHandlers,defaultOptions:n,baseResponse:r,content:t,parameters:o.parameters}),problem:i.problem})}return new e({handlers:o.defaultHandlers,defaultOptions:n,baseResponse:r,content:t,parameters:o.parameters})},Object.defineProperty(e.prototype,"ops",{get:function(){return this.operations},enumerable:!1,configurable:!0}),e.prototype.invoke=function(e,r){return this.operations.invoke(e,r)},e.prototype.invokeAll=function(e,r){return this.operations.invokeAll(e,r)},Object.defineProperty(e.prototype,"body",{get:function(){throw new Error("Not Implemented. Use `.content` instead")},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"bodyUsed",{get:function(){return!0},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"headers",{get:function(){var e;return null===(e=this.response)||void 0===e?void 0:e.headers},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"ok",{get:function(){return!!this.response&&this.response.ok},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"redirected",{get:function(){return!!this.response&&this.response.redirected},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"status",{get:function(){var e;return null===(e=this.response)||void 0===e?void 0:e.status},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"statusText",{get:function(){var e;return null===(e=this.response)||void 0===e?void 0:e.statusText},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"type",{get:function(){var e;return null===(e=this.response)||void 0===e?void 0:e.type},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"url",{get:function(){var e;return null===(e=this.response)||void 0===e?void 0:e.url},enumerable:!1,configurable:!0}),e.prototype.arrayBuffer=function(){throw new Error("Not Implemented. Use `.content` instead")},e.prototype.blob=function(){throw new Error("Not Implemented. Use `.content` instead")},e.prototype.clone=function(){throw new Error("Not Implemented")},e.prototype.formData=function(){throw new Error("Not Implemented. Use `.content` instead")},e.prototype.text=function(){throw new Error("Not Implemented. Use `.content` instead")},e}(),ue=function(e){function t(r){var t=this.constructor,n=r.response,o=r.problem,i=e.call(this,o.detail)||this,a=t.prototype;return Object.setPrototypeOf?Object.setPrototypeOf(i,a):i.__proto__=a,i.problem=o,i.response=n,i}return r(t,e),t}(Error);function ce(e){return e.sort((function(e,r){return(r.q||1)-(e.q||1)}))}function fe(e,r,n){var u;return o(this,void 0,void 0,(function(){var o,c,f,p,d,h,y,v,b,m,w,g,O,x,j,k,A,E,I,R,P,S,_,T,U;return i(this,(function(i){switch(i.label){case 0:if(o=ae(r,n),c=o.defaultHandlers,!o.fetch)throw new Error("No global fetch and fetch not provided in options");f=function(e){var r,t,n,o,i=[];try{for(var s=a(e),l=s.next();!l.done;l=s.next()){var u=l.value;try{for(var c=(n=void 0,a(u.mediaRanges)),f=c.next();!f.done;f=c.next()){var p=f.value;"object"==typeof p?u.q?i.push({type:p.mediaType,q:u.q*(p.q||1)}):i.push({type:p.mediaType,q:p.q||1}):u.q?i.push({type:p,q:u.q}):i.push({type:p,q:1})}}catch(e){n={error:e}}finally{try{f&&!f.done&&(o=c.return)&&o.call(c)}finally{if(n)throw n.error}}}}catch(e){r={error:e}}finally{try{l&&!l.done&&(t=s.return)&&t.call(s)}finally{if(r)throw r.error}}var d=i.sort((function(e,r){return e.q-r.q})),h=new Set;return d.filter((function(e){var r=e.type;return!h.has(r)&&h.add(r)}))}(c),p=f.map((function(e){return 1===e.q?e.type:"".concat(e.type,";q=").concat(e.q)})),d=(null===(u=null==n?void 0:n.headers)||void 0===u?void 0:u.accept)?[n.headers.accept]:[],h=l(l([],s(d),!1),s(p),!1).join(","),y=t(t({},o),{headers:t(t({},o.headers),{accept:h})}),v=!1;try{for(b=a(y.preInterceptors||[]),m=b.next();!m.done&&((0,m.value)(e,y,(function(){return v=!0})),!v);m=b.next());}catch(e){R={error:e}}finally{try{m&&!m.done&&(P=b.return)&&P.call(b)}finally{if(R)throw R.error}}return[4,o.fetch(e.toString(),y)];case 1:w=i.sent(),i.label=2;case 2:return i.trys.push([2,4,,5]),[4,o.contentParser(w)];case 3:g=i.sent(),k=le.create(w,g,r,o),v=!1;try{for(O=a(y.postInterceptors),x=O.next();!x.done&&((0,x.value)(k,(function(){return v=!0})),!v);x=O.next());}catch(e){S={error:e}}finally{try{x&&!x.done&&(_=O.return)&&_.call(O)}finally{if(S)throw S.error}}return[2,k];case 4:j=i.sent(),k=new le({handlers:o.defaultHandlers,defaultOptions:r,baseResponse:w,content:j,parameters:o.parameters}),A=new ue(j instanceof C?{response:k,problem:j}:{response:k,problem:new C({type:"https://waychaser.io/unexected-error",title:"An unexpected error occurred",error:j})}),v=!1;try{for(E=a(y.postErrorInterceptors),I=E.next();!I.done&&((0,I.value)(A,(function(){return v=!0})),!v);I=E.next());}catch(e){T={error:e}}finally{try{I&&!I.done&&(U=E.return)&&U.call(E)}finally{if(T)throw T.error}}throw A;case 5:return[2]}}))}))}var pe={fetch:"undefined"!=typeof window?null===(ee=window.fetch)||void 0===ee?void 0:ee.bind(window):null===(re="undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0)||void 0===re?void 0:re.fetch,handlers:[],defaultHandlers:ce([{handler:function(e){var r=null==e?void 0:e.headers.get("location");return r?[new P({rel:"related",uri:r})]:[]},mediaRanges:["*/*"],q:.4},{handler:function(e,r,t){return l(l([],s(ne(e.headers.get("link"))),!1),s(ne(e.headers.get("link-template"))),!1)},mediaRanges:["*/*"],q:.5},{handler:function(e,r){var t,n,o,i,s,l,u,c=[],f=null===(u=e.headers.get("content-type"))||void 0===u?void 0:u.split(";");if((null==f?void 0:f[0])===q&&r&&"object"==typeof r&&"_links"in r){var p=r,d={};if(p._links.curies)if(Array.isArray(p._links.curies))try{for(var h=a(p._links.curies),y=h.next();!y.done;y=h.next()){var v=y.value;d[v.name]=v.href}}catch(e){t={error:e}}finally{try{y&&!y.done&&(n=h.return)&&n.call(h)}finally{if(t)throw t.error}}else d[p._links.curies.name]=p._links.curies.href;try{for(var b=a(Object.keys(p._links).filter((function(e){return"curies"!==e}))),m=b.next();!m.done;m=b.next()){var w=m.value;if(Array.isArray(p._links[w]))try{for(var g=(s=void 0,a(p._links[w])),O=g.next();!O.done;O=g.next()){var x=O.value;c.push(L(w,x,d))}}catch(e){s={error:e}}finally{try{O&&!O.done&&(l=g.return)&&l.call(g)}finally{if(s)throw s.error}}else c.push(L(w,p._links[w],d))}}catch(e){o={error:e}}finally{try{m&&!m.done&&(i=b.return)&&i.call(b)}finally{if(o)throw o.error}}}return c},mediaRanges:[q],q:.5},{handler:function(e,r){var t,n=null===(t=e.headers.get("content-type"))||void 0===t?void 0:t.split(";");return(null==n?void 0:n[0])===N?l(l([],s(function(e){var r,t,n,o,i=[];if(e&&"object"==typeof e&&"links"in e){var s=e;if(s.links)try{for(var l=a(s.links),u=l.next();!u.done;u=l.next()){var c=u.value;try{for(var f=(n=void 0,a(c.rel)),p=f.next();!p.done;p=f.next()){var d=ie(p.value,c);i.push(d)}}catch(e){n={error:e}}finally{try{p&&!p.done&&(o=f.return)&&o.call(f)}finally{if(n)throw n.error}}}}catch(e){r={error:e}}finally{try{u&&!u.done&&(t=l.return)&&t.call(l)}finally{if(r)throw r.error}}}return i}(r)),!1),s(function(e){var r,t,n=[];if(e&&"object"==typeof e&&"actions"in e){var o=e;if(o.actions)try{for(var i=a(o.actions),s=i.next();!s.done;s=i.next()){var l=oe(s.value);n.push(l)}}catch(e){r={error:e}}finally{try{s&&!s.done&&(t=i.return)&&t.call(i)}finally{if(r)throw r.error}}}return n}(r)),!1):[]},mediaRanges:[N],q:.5}]),preInterceptors:[],postInterceptors:[],postErrorInterceptors:[],contentParser:function(e){return o(void 0,void 0,void 0,(function(){var r,t,n,o,a;return i(this,(function(i){switch(i.label){case 0:return e.headers.get("content-length")&&"0"!==e.headers.get("content-length")?[4,e.text()]:[3,2];case 1:if(r=i.sent(),null==(t=null===(a=null===(o=e.headers.get("content-type"))||void 0===o?void 0:o.split(";"))||void 0===a?void 0:a[0])?void 0:t.endsWith("json")){if(n=function(e,r){try{return JSON.parse(e)}catch(t){throw new C({type:"https://waychaser.io/invalid-json",title:"JSON response could not be parsed",detail:"The response document with content type '".concat(r,"' could not be parsed as json"),content:e,error:t})}}(r,t),"application/problem+json"===t)throw Object.assign(new C(n),n);return[2,n]}i.label=2;case 2:return[2]}}))}))}};function de(e,r){var t=ae(r,e),n=function(e,r){return fe(e,t,r)};return n.currentDefaults=t,n.defaults=function(e){return de(e,t)},n}var he=Object.assign((function(e,r){return fe(e,pe,r)}),{currentDefaults:pe,defaults:function(e){return de(e,pe)}});export{ue as WayChaserProblem,le as WayChaserResponse,fe as _waychaser,se as isValidationSuccess,ce as sortHandlers,he as waychaser};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mountainpass/waychaser",
3
- "version": "5.0.12",
3
+ "version": "5.0.13",
4
4
  "description": "Client library for HATEOAS level 3 RESTful APIs that provide hypermedia controls",
5
5
  "repository": {
6
6
  "type": "git",