@mountainpass/waychaser 5.0.47 → 5.0.49
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 +2 -2
package/dist/waychaser.es.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
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])},e(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},t.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={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},a=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return a.next=s(0),a.throw=s(1),a.return=s(2),"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function s(s){return function(l){return function(s){if(t)throw new TypeError("Generator is already executing.");for(;a&&(a=0,s[0]&&(i=0)),i;)try{if(t=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return i.label++,{value:s[1],done:!1};case 5:i.label++,n=s[1],s=[0];continue;case 7:s=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){i=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){i.label=s[1];break}if(6===s[0]&&i.label<o[1]){i.label=o[1],o=s;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(s);break}o[2]&&i.ops.pop(),i.trys.pop();continue}s=r.call(e,i)}catch(e){s=[6,e],n=0}finally{t=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,l])}}}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))}function u(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}"function"==typeof SuppressedError&&SuppressedError;var c,f={exports:{}};var p,h,d=(c||(c=1,function(){f.exports=function(e,n){var i=this,s=Object.assign({decoder:a},n),l=0,c={},f="",p="^"+e.replace(o,function(e,t,n){if(!n)return y(e);var o=r[t]||t,i=";"==o||"&"==o;return n.split(",").map(function(e,r){var n=e.split(/[*:]/),a=n[0],s=(c[a]||"(")+".*?)";return l++,n[1]&&(s="((?:%..|.){1,"+n[1]+"})",c[a]="(\\"+l),f+="t=($["+l+"]||'').split('"+(n[1]?i?o+a+"=":o:",")+"').map(d);",f+='o["'+a+'"]='+(""===n[1]?"t;":"t.length>1?t:t[0];"),s=y(0===r?"+"===t?"":t:o)+(i?y(a)+"(?:="+s+")?":s),""===n[1]?"(?:"+s+")?":s}).join("")})+"$",h=RegExp(p),d=Function("$,d","var t,o={};"+f+"return o");function y(e){return e.replace(t,"\\$&")}i.template=e,i.match=function(e){var r=h.exec(e);return r&&d(r,s.decoder)},i.expand=function(r){return u(e,r,s)}},f.exports.expand=u;var e=/[!'()]/g,r={"":",","+":",","#":",","?":"&"},t=/[$-/?[-^{|}]/g,n=/\{([#&+./;?]?)((?:[-\w%.]+(\*|:\d+)?(?:,|(?=})))+)\}/g,o=RegExp(n.source+"|.[^{]*?","g");function i(r){return encodeURIComponent(r).replace(e,escape)}function a(e){try{return decodeURIComponent(e)}catch(r){return e}}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,t,o){return e.replace(n,function(e,n,a){var s=r[n]||n,u=";"==s||"&"==s,c=n&&","==s?encodeURI:o&&o.encoder||i,f=l(a.split(","),function(e){var r=e.split(/[*:]/),n=r[0],o=t[n];if(null!=o){if("object"==typeof o){if(r=n!=e,Array.isArray(o)?o=l(o,c,r?u?s+n+"=":s:","):(o=l(Object.keys(o),function(e){return c(e)+(r?"=":",")+c(o[e])},r&&(u||"/"==s)?s:","),r&&(u=0)),!o)return}else o=c(r[1]?o.slice(0,r[1]):o);return u?n+(o||"&"==s?"="+o:o):o}},s);return f||""===f?"+"!=n?n+f:f:""})}}()),f.exports),y=u(d),v={Template:y,expand:d.expand,parameters:function(e){return new y(e).match(e)}};var b,m,w=u(function(){if(h)return p;h=1;var e=Object.prototype.hasOwnProperty;return p=function r(t,n){var o=[];for(var i in t)if(e.call(t,i)){var a,s=t[i],l=encodeURIComponent(i);a="object"==typeof s?r(s,n?n+"["+l+"]":l):(n?n+"["+l+"]":l)+"="+encodeURIComponent(s),o.push(a)}return o.join("&")}}());var g=u(m?b:(m=1,b="object"==typeof self?self.FormData:window.FormData));function O(e,r,t){if(e){var n=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);return n.find(function(e){return r.includes(e.type)}).type}return t}function x(e){return e}function j(e,r){const t=(r=r||{}).delimiter||".",n=r.maxDepth,o=r.transformKey||x,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),h=(d=c)&&d.constructor&&"function"==typeof d.constructor.isBuffer&&d.constructor.isBuffer(d);var d;const y="[object Object]"===p||"[object Array]"===p,v=s?s+t+o(u):o(u);if(!f&&!h&&y&&Object.keys(c).length&&(!r.maxDepth||l<n))return e(c,v,l+1);i[v]=c})}(e),i}var k,A={};var E=function(){if(k)return A;k=1;var e=/~/,r=/~[01]/g;function t(e){switch(e){case"~1":return"/";case"~0":return"~"}throw new Error("Invalid tilde escape: "+e)}function n(n){return e.test(n)?n.replace(r,t):n}function o(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 i(e,r){if("object"!=typeof e)throw new Error("Invalid input object.");var t=(r=o(r)).length;if(1===t)return e;for(var i=1;i<t;){if(e=e[n(r[i++])],t===i)return e;if("object"!=typeof e||null===e)return}}function a(e,r,t){if("object"!=typeof e)throw new Error("Invalid input object.");if(0===(r=o(r)).length)throw new Error("Invalid JSON pointer for set.");return function(e,r,t){for(var o,i,a=1,s=r.length;a<s;){if("constructor"===r[a]||"prototype"===r[a]||"__proto__"===r[a])return e;if(o=n(r[a++]),i=s>a,void 0===e[o]&&(Array.isArray(e)&&"-"===o&&(o=e.length),i&&(""!==r[a]&&r[a]<1/0||"-"===r[a]?e[o]=[]:e[o]={})),!i)break;e=e[o]}var l=e[o];return void 0===t?delete e[o]:e[o]=t,l}(e,r,t)}return A.get=i,A.set=a,A.compile=function(e){var r=o(e);return{get:function(e){return i(e,r)},set:function(e,t){return a(e,r,t)}}},A}(),C=u(E);var P,I={};var T=(P||(P=1,Object.defineProperty(I,"__esModule",{value:!0}),I.ProblemDocument=void 0,I.ProblemDocument=class{constructor(e){Object.assign(this,e)}}),I),R=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=v.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&&C.get(this.response.fullContent,t.slice(1));if(void 0===n)return;if(r){var o=r(n);if(K(o))return new Z({defaultOptions:this.defaultOptions,baseResponse:this.response.response,content:o.content,fullContent:this.response.fullContent,anchor:t,parentOperations:this.response.allOperations,parameters:e});throw new X({problem:o.problem,response:new Z({defaultOptions:this.defaultOptions,baseResponse:this.response.response,content:n,fullContent:this.response.fullContent,parameters:e})})}return new Z({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 Z?(r=this.doInvokeAll((null==e?void 0:e.parameters)||{}),[2,Promise.all(r)]):[2,this.invoke(e).then(function(e){return[e]})]})})},t.prototype.doInvokeAll=function(e,r){var t=this,n=this.response,o=new v.Template(this.uri),i=Object.assign(v.parameters(this.uri),e),a=o.expand(i).replaceAll("%7B","{").replaceAll("%7D","}"),u=v.parameters(a),c=Object.keys(u);if(0===c.length)return[this.invokeAsFragment(e,r)];var f=u[c[0]],p=a.slice(1,a.indexOf(f)-1),h=""===p?n.content:C.get(n.content,p);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 X({response:this.response,problem:new T.ProblemDocument({type:"https://waychaser.io/fragment-uri-error",title:"The fragment URI does not match the content structure",uri:p,content:n.content,parameters:e})})},t.prototype.invoke=function(e){return o(this,void 0,void 0,function(){var r,t,n,o,s,l,u,c,f,p,h,d,y,v,b,m,x,j,k,A;return i(this,function(i){if(this.uri.startsWith("#/"))return[2,this.invokeAsFragment(null==e?void 0:e.parameters)];if(this.uri.includes("#/")&&(r=this.uri.slice(this.uri.indexOf("#/")+1),void 0!==(t=this.response.fullContent&&C.get(this.response.fullContent,r))))return[2,new Z({defaultOptions:this.defaultOptions,baseResponse:this.response.response,content:t,fullContent:this.response.fullContent,anchor:"#"+r,parentOperations:this.response.allOperations,parameters:null==e?void 0:e.parameters})];if(n=this.parameters||{},o=Object.assign({},this.defaultOptions.parameters,null==e?void 0:e.parameters),s=this.url(o),l={},Array.isArray(n))try{for(u=a(n),c=u.next();!c.done;c=u.next())h=c.value,l[h]=null==o?void 0:o[h]}catch(e){x={error:e}}finally{try{c&&!c.done&&(j=u.return)&&j.call(u)}finally{if(x)throw x.error}}else try{for(f=a(Object.keys(n)),p=f.next();!p.done;p=f.next())h=p.value,l[h]=null==o?void 0:o[h]}catch(e){k={error:e}}finally{try{p&&!p.done&&(A=f.return)&&A.call(f)}finally{if(k)throw k.error}}if(d=void 0,y={},(v=Object.assign({},e)).method=this.method,0!==Object.keys(this.parameters).length&&(E=this.method||"GET",!["GET","DELETE","TRACE","OPTIONS","HEAD"].includes(E))){switch(b=O(this.accept,["application/x-www-form-urlencoded","application/json","multipart/form-data"],"application/x-www-form-urlencoded")){case"application/x-www-form-urlencoded":d=w(l);break;case"application/json":d=JSON.stringify(l);break;case"multipart/form-data":for(m in d=new g,l)d.append(m,l[m])}"multipart/form-data"!==b&&(y={"content-type":b}),v.body=d,v.headers=Object.assign(y,null==e?void 0:e.headers)}return[2,ee(s.toString(),this.defaultOptions,v)];var E})})},t.prototype.url=function(e){var r=this.expandUrl(e);return new URL(r,this.response.url)},t.prototype.expandUrl=function(e){return v.expand(this.uri,j(e||{}))},t}(R),_=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?q({rel:e}):"object"==typeof e?q(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(q(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 q(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 R(Object.assign(e,{uri:l.replace(s,c.toFixed(0))})));try{for(var p=(r=void 0,a(f)),h=p.next();!h.done;h=p.next()){var d=h.value;i.push(d)}}catch(e){r={error:e}}finally{try{h&&!h.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 R(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}var N,D,F="application/hal+json",L="application/vnd.siren+json";function H(e,r){var t=e.split(/:(.+)/);if(t.length>1){var n=s(t,2),o=n[0],i=n[1];return r[o]?v.expand(r[o],{rel:i}):e}return e}function $(e,r,o){var i=r.href;r.templated;var a=n(r,["href","templated"]);return new R(t({rel:H(e,o),uri:i},a))}var B,J,M=function(){if(D)return N;D=1;var e=/^utf-?8|ascii|utf-?16-?le|ucs-?2|base-?64|latin-?1$/i,r=/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,t=/\s|\uFEFF|\xA0/,n=/\r?\n[\x20\x09]+/g,o=/[;,"]/,i=/[;,"]|\s/,a=/^[!#$%&'*+\-\.^_`|~\da-zA-Z]+$/,s=1,l=2,u=4;function c(e){return e.replace(r,"")}function f(e){return t.test(e)}function p(e,r){for(;f(e[r]);)r++;return r}function h(e){return i.test(e)||!a.test(e)}class d{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=c(e=(r=r||0)?e.slice(r):e).replace(n,"");for(var t=s,i=e.length,a=(r=0,null);r<i;)if(t===s){if(f(e[r])){r++;continue}if("<"!==e[r])throw new Error('Unexpected character "'+e[r]+'" at offset '+r);if(null!=a&&(null!=a.rel?this.refs.push(...d.expandRelations(a)):this.refs.push(a)),-1===(v=e.indexOf(">",r)))throw new Error("Expected end of URI delimiter at offset "+r);a={uri:e.slice(r+1,v)},r=v,t=l,r++}else if(t===l){if(f(e[r])){r++;continue}if(";"===e[r])t=u,r++;else{if(","!==e[r])throw new Error('Unexpected character "'+e[r]+'" at offset '+r);t=s,r++}}else{if(t!==u)throw new Error('Unknown parser state "'+t+'"');if(";"===e[r]||f(e[r])){r++;continue}-1===(v=e.indexOf("=",r))&&(v=e.indexOf(";",r)),-1===v&&(v=e.length);var h=c(e.slice(r,v)).toLowerCase(),y="";if('"'===e[r=p(e,r=v+1)])for(r++;r<i;){if('"'===e[r]){r++;break}"\\"===e[r]&&r++,y+=e[r],r++}else{for(var v=r+1;!o.test(e[v])&&v<i;)v++;y=e.slice(r,v),r=v}switch(a[h]&&d.isSingleOccurenceAttr(h)||("*"===h[h.length-1]?a[h]=d.parseExtendedValue(y):(y="type"===h?y.toLowerCase():y,null!=a[h]?Array.isArray(a[h])?a[h].push(y):a[h]=[a[h],y]:a[h]=y)),e[r]){case",":t=s;break;case";":t=u}r++}return null!=a&&(null!=a.rel?this.refs.push(...d.expandRelations(a)):this.refs.push(a)),a=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+"; "+d.formatAttribute(r,t[r])},"<"+t.uri+">"),e.push(r);return e.join(", ")}}return d.isCompatibleEncoding=function(r){return e.test(r)},d.parse=function(e,r){return(new d).parse(e,r)},d.isSingleOccurenceAttr=function(e){return"rel"===e||"type"===e||"media"===e||"title"===e||"title*"===e},d.isTokenAttr=function(e){return"rel"===e||"type"===e||"anchor"===e},d.escapeQuotes=function(e){return e.replace(/"/g,'\\"')},d.expandRelations=function(e){return e.rel.split(" ").map(function(r){var t=Object.assign({},e);return t.rel=r,t})},d.parseExtendedValue=function(e){var r=/([^']+)?(?:'([^']*)')?(.+)/.exec(e);return{language:r[2].toLowerCase(),encoding:d.isCompatibleEncoding(r[1])?null:r[1].toLowerCase(),value:d.isCompatibleEncoding(r[1])?decodeURIComponent(r[3]):r[3]}},d.formatExtendedAttribute=function(e,r){var t=(r.encoding||"utf-8").toUpperCase();return e+"="+t+"'"+(r.language||"en")+"'"+(Buffer.isBuffer(r.value)&&d.isCompatibleEncoding(t)?r.value.toString(t):Buffer.isBuffer(r.value)?r.value.toString("hex").replace(/[0-9a-f]{2}/gi,"%$1"):encodeURIComponent(r.value))},d.formatAttribute=function(e,r){return Array.isArray(r)?r.map(r=>d.formatAttribute(e,r)).join("; "):"*"===e[e.length-1]||"string"!=typeof r?d.formatExtendedAttribute(e,r):(d.isTokenAttr(e)?r=h(r)?'"'+d.escapeQuotes(r)+'"':d.escapeQuotes(r):h(r)&&(r='"'+(r=(r=encodeURIComponent(r)).replace(/%20/g," ").replace(/%2C/g,",").replace(/%3B/g,";"))+'"'),e+"="+r)},N=d}(),W=u(M);function G(e){return e?W.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 R(t({rel:r,uri:o,method:i,parameters:u,accept:null==a?void 0:a.value},l))}):[]}function Q(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),h=p.next();!h.done;h=p.next()){f[h.value.name]={}}}catch(e){r={error:e}}finally{try{h&&!h.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 V(e,r){var o=r.href;r.rel;var i=n(r,["href","rel"]);return new R(t({rel:e,uri:o},i))}function z(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,h=f.defaultHandlers,d=f.headers,y=f.contentParser,v=n(f,["handlers","defaultHandlers","headers","contentParser"]),b=Y(l(l([],s(p||o||[]),!1),s(h||i||[]),!1)),m=y?function(e){return y(e,u)}:u;return t(t(t({},c),v),{defaultHandlers:b,handlers:[],headers:t(t({},a),d),contentParser:m})}function K(e){return e.success}var Z=function(){function e(e){var r,t,n,o,i,s,l=e.handlers,u=e.defaultOptions,c=e.baseResponse,f=e.content,p=e.fullContent,h=e.anchor,d=e.parentOperations,y=e.parameters;this.response=c,this.anchor=h,this.parameters=y||{},this.fullContent=p||f,this.content=f,this.operations=_.create();var b=j({this:f});if(d&&h&&u){this.allOperations=d;try{for(var m=a(this.allOperations[h]||[]),w=m.next();!w.done;w=m.next()){var g=w.value;this.operations.push(new S(g,this,u,b))}}catch(e){r={error:e}}finally{try{w&&!w.done&&(t=m.return)&&t.call(m)}finally{if(r)throw r.error}}for(var O in this.allOperations)if(""!==O){var x=new v.Template(O),k=x.match(this.anchor);if(x.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[O])),C=E.next();!C.done;C=E.next()){g=C.value;this.operations.push(new S(g,this,A,b))}}catch(e){n={error:e}}finally{try{C&&!C.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,h=[],d=!1;try{for(var y=a(c),v=y.next();!v.done;v=y.next()){var b=v.value.handler(f,p,function(){d=!0});if(b)try{for(var m=(n=void 0,a(b)),w=m.next();!w.done;w=m.next()){var g=w.value;h.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(d)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(h),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 C=E.value,P=C.anchor||"";O[P]||(O[P]=[]),O[P].push(C)}}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:f,handlers:l}),this.operations=_.create();try{for(var P=a(this.allOperations[""]||[]),I=P.next();!I.done;I=P.next()){g=I.value;var T=new S(g,this,u,b);this.operations.push(T)}}catch(e){i={error:e}}finally{try{I&&!I.done&&(s=P.return)&&s.call(P)}finally{if(i)throw i.error}}}}return e.create=function(r,t,n,o){if(t instanceof T.ProblemDocument)throw new X({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(K(i))return new e({handlers:o.defaultHandlers,defaultOptions:n,baseResponse:r,content:i.content,parameters:o.parameters});throw new X({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}(),X=function(e){function t(r){var t=r.response,n=r.problem,o=this.constructor,i=e.call(this,n.detail)||this,a=o.prototype;return Object.setPrototypeOf?Object.setPrototypeOf(i,a):i.__proto__=a,i.problem=n,i.response=t,i}return r(t,e),t}(Error);function Y(e){return e.sort(function(e,r){return(r.q||1)-(e.q||1)})}function ee(e,r,n){return o(this,void 0,void 0,function(){var o,u,c,f,p,h,d,y,v,b,m,w,g,O,x,j,k,A,E,C,P,I,R,S,_,q;return i(this,function(i){switch(i.label){case 0:if(o=z(r,n),u=o.defaultHandlers,!o.fetch)throw new Error("No global fetch and fetch not provided in options");c=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 h=i.sort(function(e,r){return e.q-r.q}),d=new Set;return h.filter(function(e){var r=e.type;return!d.has(r)&&d.add(r)})}(u),f=c.map(function(e){return 1===e.q?e.type:"".concat(e.type,";q=").concat(e.q)}),p=(null===(q=null==n?void 0:n.headers)||void 0===q?void 0:q.accept)?[n.headers.accept]:[],h=l(l([],s(p),!1),s(f),!1).join(","),d=t(t({},o),{headers:t(t({},o.headers),{accept:h})}),y=!1;try{for(v=a(d.preInterceptors||[]),b=v.next();!b.done&&((0,b.value)(e,d,function(){return y=!0}),!y);b=v.next());}catch(e){C={error:e}}finally{try{b&&!b.done&&(P=v.return)&&P.call(v)}finally{if(C)throw C.error}}return[4,o.fetch(e.toString(),d)];case 1:m=i.sent(),i.label=2;case 2:return i.trys.push([2,4,,5]),[4,o.contentParser(m)];case 3:w=i.sent(),j=Z.create(m,w,r,o),y=!1;try{for(g=a(d.postInterceptors),O=g.next();!O.done&&((0,O.value)(j,function(){return y=!0}),!y);O=g.next());}catch(e){I={error:e}}finally{try{O&&!O.done&&(R=g.return)&&R.call(g)}finally{if(I)throw I.error}}return[2,j];case 4:x=i.sent(),j=new Z({handlers:o.defaultHandlers,defaultOptions:r,baseResponse:m,content:x,parameters:o.parameters}),k=x instanceof T.ProblemDocument?new X({response:j,problem:x}):new X({response:j,problem:new T.ProblemDocument({type:"https://waychaser.io/unexected-error",title:"An unexpected error occurred",error:x})}),y=!1;try{for(A=a(d.postErrorInterceptors),E=A.next();!E.done&&((0,E.value)(k,function(){return y=!0}),!y);E=A.next());}catch(e){S={error:e}}finally{try{E&&!E.done&&(_=A.return)&&_.call(A)}finally{if(S)throw S.error}}throw k;case 5:return[2]}})})}var re={fetch:"undefined"==typeof globalThis?null===(B="undefined"!=typeof globalThis||"undefined"!=typeof globalThis||"undefined"!=typeof globalThis?globalThis:void 0)||void 0===B?void 0:B.fetch:null===(J=globalThis.fetch)||void 0===J?void 0:J.bind(globalThis),handlers:[],defaultHandlers:Y([{handler:function(e){var r=null==e?void 0:e.headers.get("location");return r?[new R({rel:"related",uri:r})]:[]},mediaRanges:["*/*"],q:.4},{handler:function(e,r,t){return l(l([],s(G(e.headers.get("link"))),!1),s(G(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])===F&&r&&"object"==typeof r&&"_links"in r){var p=r,h={};if(p._links.curies)if(Array.isArray(p._links.curies))try{for(var d=a(p._links.curies),y=d.next();!y.done;y=d.next()){var v=y.value;h[v.name]=v.href}}catch(e){t={error:e}}finally{try{y&&!y.done&&(n=d.return)&&n.call(d)}finally{if(t)throw t.error}}else h[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($(w,x,h))}}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($(w,p._links[w],h))}}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:[F],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])===L?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 h=V(p.value,c);i.push(h)}}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=Q(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:[L],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 T.ProblemDocument({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 T.ProblemDocument(n),n);return[2,n]}i.label=2;case 2:return[2]}})})}};function te(e,r){var t=z(r,e),n=function(e,r){return ee(e,t,r)};return n.currentDefaults=t,n.defaults=function(e){return te(e,t)},n}var ne=Object.assign(function(e,r){return ee(e,re,r)},{currentDefaults:re,defaults:function(e){return te(e,re)}});export{X as WayChaserProblem,Z as WayChaserResponse,ee as _waychaser,K as isValidationSuccess,Y as sortHandlers,ne as waychaser};
|
|
1
|
+
function e(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var t,r={exports:{}};var n=(t||(t=1,function(){r.exports=function(e,r){var s=this,i=Object.assign({decoder:a},r),c=0,p={},l="",f="^"+e.replace(o,function(e,r,n){if(!n)return m(e);var s=t[r]||r,o=";"==s||"&"==s;return n.split(",").map(function(e,t){var n=e.split(/[*:]/),i=n[0],a=(p[i]||"(")+".*?)";return c++,n[1]&&(a="((?:%..|.){1,"+n[1]+"})",p[i]="(\\"+c),l+="t=($["+c+"]||'').split('"+(n[1]?o?s+i+"=":s:",")+"').map(d);",l+='o["'+i+'"]='+(""===n[1]?"t;":"t.length>1?t:t[0];"),a=m(0===t?"+"===r?"":r:s)+(o?m(i)+"(?:="+a+")?":a),""===n[1]?"(?:"+a+")?":a}).join("")})+"$",h=RegExp(f),d=Function("$,d","var t,o={};"+l+"return o");function m(e){return e.replace(n,"\\$&")}s.template=e,s.match=function(e){var t=h.exec(e);return t&&d(t,i.decoder)},s.expand=function(t){return u(e,t,i)}},r.exports.expand=u;var e=/[!'()]/g,t={"":",","+":",","#":",","?":"&"},n=/[$-/?[-^{|}]/g,s=/\{([#&+./;?]?)((?:[-\w%.]+(\*|:\d+)?(?:,|(?=})))+)\}/g,o=RegExp(s.source+"|.[^{]*?","g");function i(t){return encodeURIComponent(t).replace(e,escape)}function a(e){try{return decodeURIComponent(e)}catch(t){return e}}function c(e){return null!=e}function p(e,t,r){return(e=e.map(t).filter(c)).length&&e.join(r)}function u(e,r,n){return e.replace(s,function(e,s,o){var a=t[s]||s,c=";"==a||"&"==a,u=s&&","==a?encodeURI:n&&n.encoder||i,l=p(o.split(","),function(e){var t=e.split(/[*:]/),n=t[0],s=r[n];if(null!=s){if("object"==typeof s){if(t=n!=e,Array.isArray(s)?s=p(s,u,t?c?a+n+"=":a:","):(s=p(Object.keys(s),function(e){return u(e)+(t?"=":",")+u(s[e])},t&&(c||"/"==a)?a:","),t&&(c=0)),!s)return}else s=u(t[1]?s.slice(0,t[1]):s);return c?n+(s||"&"==a?"="+s:s):s}},a);return l||""===l?"+"!=s?s+l:l:""})}}()),r.exports),s=e(n);const o={Template:s,expand:n.expand,parameters:e=>new s(e).match(e)};var i,a;var c,p,u=e(function(){if(a)return i;a=1;var e=Object.prototype.hasOwnProperty;return i=function t(r,n){var s=[];for(var o in r)if(e.call(r,o)){var i,a=r[o],c=encodeURIComponent(o);i="object"==typeof a?t(a,n?n+"["+c+"]":c):(n?n+"["+c+"]":c)+"="+encodeURIComponent(a),s.push(i)}return s.join("&")}}());var l=e(p?c:(p=1,c="object"==typeof self?self.FormData:window.FormData));function f(e,t,r){if(e){const r=function(e){return e.split(",").map(e=>{const t=e.split(";"),r=t.shift(),n=r?.split("/"),s={type:r,parentType:n?.[0],subType:n?.[1],q:1};for(const e of t){const t=e.split("=");"q"===e[0]&&(s[t[0]]=Number.parseFloat(t[1]))}return s}).sort((e,t)=>e.q>t.q?-1:e.q<t.q||"*"===e.parentType&&"*"!==t.parentType?1:"*"!==e.parentType&&"*"===t.parentType?-1:"*"===e.subType&&"*"!==t.subType?1:"*"!==e.subType&&"*"===t.subType?-1:0).map(e=>({type:e.type||""})).filter(e=>""!==e.type)}(e);return r.find(e=>t.includes(e.type)).type}return r}function h(e){return e}function d(e,t){const r=(t=t||{}).delimiter||".",n=t.maxDepth,s=t.transformKey||h,o={};return function e(i,a,c){c=c||1,Object.keys(i).forEach(function(p){const u=i[p],l=t.safe&&Array.isArray(u),f=Object.prototype.toString.call(u),h=(d=u)&&d.constructor&&"function"==typeof d.constructor.isBuffer&&d.constructor.isBuffer(d);var d;const m="[object Object]"===f||"[object Array]"===f,y=a?a+r+s(p):s(p);if(!l&&!h&&m&&Object.keys(u).length&&(!t.maxDepth||c<n))return e(u,y,c+1);o[y]=u})}(e),o}var m,y={};var b=function(){if(m)return y;m=1;var e=/~/,t=/~[01]/g;function r(e){switch(e){case"~1":return"/";case"~0":return"~"}throw new Error("Invalid tilde escape: "+e)}function n(n){return e.test(n)?n.replace(t,r):n}function s(e){if("string"==typeof e){if(""===(e=e.split("/"))[0])return e;throw new Error("Invalid JSON pointer.")}if(Array.isArray(e)){for(const t of e)if("string"!=typeof t&&"number"!=typeof t)throw new Error("Invalid JSON pointer. Must be of type string or number.");return e}throw new Error("Invalid JSON pointer.")}function o(e,t){if("object"!=typeof e)throw new Error("Invalid input object.");var r=(t=s(t)).length;if(1===r)return e;for(var o=1;o<r;){if(e=e[n(t[o++])],r===o)return e;if("object"!=typeof e||null===e)return}}function i(e,t,r){if("object"!=typeof e)throw new Error("Invalid input object.");if(0===(t=s(t)).length)throw new Error("Invalid JSON pointer for set.");return function(e,t,r){for(var s,o,i=1,a=t.length;i<a;){if("constructor"===t[i]||"prototype"===t[i]||"__proto__"===t[i])return e;if(s=n(t[i++]),o=a>i,void 0===e[s]&&(Array.isArray(e)&&"-"===s&&(s=e.length),o&&(""!==t[i]&&t[i]<1/0||"-"===t[i]?e[s]=[]:e[s]={})),!o)break;e=e[s]}var c=e[s];return void 0===r?delete e[s]:e[s]=r,c}(e,t,r)}return y.get=o,y.set=i,y.compile=function(e){var t=s(e);return{get:function(e){return o(e,t)},set:function(e,r){return i(e,t,r)}}},y}(),g=e(b);var w,v={};var O=(w||(w=1,Object.defineProperty(v,"__esModule",{value:!0}),v.ProblemDocument=void 0,v.ProblemDocument=class{constructor(e){Object.assign(this,e)}}),v);class j{constructor({rel:e,uri:t,method:r,parameters:n,accept:s,anchor:o,...i}){this.rel=e,this.uri=t,this.method=r,this.parameters=n||{},this.accept=s,this.anchor=o,Object.assign(this,i)}}class k extends j{constructor(e,t,r,n){super(e),this.response=t,this.defaultOptions=r,this.uri.includes("{this.")&&(this.uri=o.expand(this.uri,n))}invokeAsFragment(e,t){if(this.uri.startsWith("#/")){const r=this.expandUrl(e).toString(),n=this.response.fullContent&&g.get(this.response.fullContent,r.slice(1));if(void 0===n)return;if(t){const s=t(n);if(H(s))return new B({defaultOptions:this.defaultOptions,baseResponse:this.response.response,content:s.content,fullContent:this.response.fullContent,anchor:r,parentOperations:this.response.allOperations,parameters:e});throw new J({problem:s.problem,response:new B({defaultOptions:this.defaultOptions,baseResponse:this.response.response,content:n,fullContent:this.response.fullContent,parameters:e})})}return new B({defaultOptions:this.defaultOptions,baseResponse:this.response.response,content:n,fullContent:this.response.fullContent,anchor:r,parentOperations:this.response.allOperations,parameters:e})}}async invokeAll(e){if(this.uri.startsWith("#/")&&this.response instanceof B){const t=this.doInvokeAll(e?.parameters||{});return Promise.all(t)}return this.invoke(e).then(e=>[e])}doInvokeAll(e,t){const r=this.response,n=new o.Template(this.uri),s=Object.assign(o.parameters(this.uri),e),i=n.expand(s).replaceAll("%7B","{").replaceAll("%7D","}"),a=o.parameters(i),c=Object.keys(a);if(0===c.length)return[this.invokeAsFragment(e,t)];{const n=a[c[0]],s=i.slice(1,i.indexOf(n)-1),o=""===s?r.content:g.get(r.content,s);if(o){return(Array.isArray(o)?[...Array.from({length:o.length}).keys()]:Object.keys(o)).flatMap(r=>{const n=Object.assign({},e,{[c[0]]:r});return this.doInvokeAll(n,t)})}throw new J({response:this.response,problem:new O.ProblemDocument({type:"https://waychaser.io/fragment-uri-error",title:"The fragment URI does not match the content structure",uri:s,content:r.content,parameters:e})})}}async invoke(e){if(this.uri.startsWith("#/"))return this.invokeAsFragment(e?.parameters);if(this.uri.includes("#/")){const t=this.uri.slice(this.uri.indexOf("#/")+1),r=this.response.fullContent&&g.get(this.response.fullContent,t);if(void 0!==r)return new B({defaultOptions:this.defaultOptions,baseResponse:this.response.response,content:r,fullContent:this.response.fullContent,anchor:"#"+t,parentOperations:this.response.allOperations,parameters:e?.parameters})}{const r=this.parameters||{},n=Object.assign({},this.defaultOptions.parameters,e?.parameters),s=this.url(n),o={};if(Array.isArray(r))for(const e of r)o[e]=n?.[e];else for(const e of Object.keys(r))o[e]=n?.[e];let i,a={};const c=Object.assign({},e);if(c.method=this.method,0!==Object.keys(this.parameters).length&&(t=this.method||"GET",!["GET","DELETE","TRACE","OPTIONS","HEAD"].includes(t))){const t=f(this.accept,["application/x-www-form-urlencoded","application/json","multipart/form-data"],"application/x-www-form-urlencoded");switch(t){case"application/x-www-form-urlencoded":i=u(o);break;case"application/json":i=JSON.stringify(o);break;case"multipart/form-data":i=new l;for(const e in o)i.append(e,o[e])}"multipart/form-data"!==t&&(a={"content-type":t}),c.body=i,c.headers=Object.assign(a,e?.headers)}return W(s.toString(),this.defaultOptions,c)}var t}url(e){const t=this.expandUrl(e);return new URL(t,this.response.url)}expandUrl(e){return o.expand(this.uri,d(e||{}))}}class x extends Array{constructor(e){super(),e&&this.push(...e)}static get[Symbol.species](){return Array}static create(){return Object.create(x.prototype)}find(e,t){const r=Array.prototype.find.bind(this);return r("string"==typeof e?A({rel:e}):"object"==typeof e?A(e):e,t)}filter(e,t){if("string"==typeof e)return this.filter({rel:e},t);if("object"==typeof e)return this.filter(A(e),t);{const t=Array.prototype.filter.bind(this)(e);return Object.setPrototypeOf(t,x.prototype),t}}invoke(e,t){const r=this.find(e);return r?r.invoke(t):void 0}invokeAll(e,t){const r=this.filter(e);return Promise.all(r.map(e=>e.invokeAll(t))).then(e=>e.flat())}}function A(e){return t=>{for(const r in e)if(e[r]!==t[r])return!1;return!0}}function E(e){const t=[],r=/{\[(\d+)..(\d+)]}/,n=e.uri.toString(),s=n.match(r);if(s)for(let o=Number.parseInt(s[1]);o<=Number.parseInt(s[2]);++o){const s=E(new j(Object.assign(e,{uri:n.replace(r,o.toFixed(0))})));for(const e of s)t.push(e)}else{const n=e.anchor,s=n?.match(r);if(n&&s)for(let o=Number.parseInt(s[1]);o<=Number.parseInt(s[2]);++o){const s=E(new j(Object.assign(e,{anchor:n.replace(r,o.toFixed(0))})));for(const e of s)t.push(e)}else t.push(e)}return t}const C="application/hal+json",I="application/vnd.siren+json";function R(e,t){const r=e.split(/:(.+)/);if(r.length>1){const[n,s]=r;return t[n]?o.expand(t[n],{rel:s}):e}return e}function T(e,t,r){const{href:n,templated:s,...o}=t;return new j({rel:R(e,r),uri:n,...o})}var q,U;var _=function(){if(U)return q;U=1;var e=/^utf-?8|ascii|utf-?16-?le|ucs-?2|base-?64|latin-?1$/i,t=/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,r=/\s|\uFEFF|\xA0/,n=/\r?\n[\x20\x09]+/g,s=/[;,"]/,o=/[;,"]|\s/,i=/^[!#$%&'*+\-\.^_`|~\da-zA-Z]+$/,a=1,c=2,p=4;function u(e){return e.replace(t,"")}function l(e){return r.test(e)}function f(e,t){for(;l(e[t]);)t++;return t}function h(e){return o.test(e)||!i.test(e)}class d{constructor(e){this.refs=[],e&&this.parse(e)}rel(e){for(var t=[],r=e.toLowerCase(),n=0;n<this.refs.length;n++)"string"==typeof this.refs[n].rel&&this.refs[n].rel.toLowerCase()===r&&t.push(this.refs[n]);return t}get(e,t){e=e.toLowerCase(),t=t.toLowerCase();for(var r=[],n=0;n<this.refs.length;n++)"string"==typeof this.refs[n][e]&&this.refs[n][e].toLowerCase()===t&&r.push(this.refs[n]);return r}set(e){return this.refs.push(e),this}setUnique(e){return this.refs.some(t=>{return r=t,n=e,Object.keys(r).length===Object.keys(n).length&&Object.keys(r).every(e=>e in n&&r[e]===n[e]);var r,n})||this.refs.push(e),this}has(e,t){e=e.toLowerCase(),t=t.toLowerCase();for(var r=0;r<this.refs.length;r++)if("string"==typeof this.refs[r][e]&&this.refs[r][e].toLowerCase()===t)return!0;return!1}parse(e,t){e=u(e=(t=t||0)?e.slice(t):e).replace(n,"");for(var r=a,o=e.length,i=(t=0,null);t<o;)if(r===a){if(l(e[t])){t++;continue}if("<"!==e[t])throw new Error('Unexpected character "'+e[t]+'" at offset '+t);if(null!=i&&(null!=i.rel?this.refs.push(...d.expandRelations(i)):this.refs.push(i)),-1===(y=e.indexOf(">",t)))throw new Error("Expected end of URI delimiter at offset "+t);i={uri:e.slice(t+1,y)},t=y,r=c,t++}else if(r===c){if(l(e[t])){t++;continue}if(";"===e[t])r=p,t++;else{if(","!==e[t])throw new Error('Unexpected character "'+e[t]+'" at offset '+t);r=a,t++}}else{if(r!==p)throw new Error('Unknown parser state "'+r+'"');if(";"===e[t]||l(e[t])){t++;continue}-1===(y=e.indexOf("=",t))&&(y=e.indexOf(";",t)),-1===y&&(y=e.length);var h=u(e.slice(t,y)).toLowerCase(),m="";if('"'===e[t=f(e,t=y+1)])for(t++;t<o;){if('"'===e[t]){t++;break}"\\"===e[t]&&t++,m+=e[t],t++}else{for(var y=t+1;!s.test(e[y])&&y<o;)y++;m=e.slice(t,y),t=y}switch(i[h]&&d.isSingleOccurenceAttr(h)||("*"===h[h.length-1]?i[h]=d.parseExtendedValue(m):(m="type"===h?m.toLowerCase():m,null!=i[h]?Array.isArray(i[h])?i[h].push(m):i[h]=[i[h],m]:i[h]=m)),e[t]){case",":r=a;break;case";":r=p}t++}return null!=i&&(null!=i.rel?this.refs.push(...d.expandRelations(i)):this.refs.push(i)),i=null,this}toString(){for(var e=[],t="",r=null,n=0;n<this.refs.length;n++)r=this.refs[n],t=Object.keys(this.refs[n]).reduce(function(e,t){return"uri"===t?e:e+"; "+d.formatAttribute(t,r[t])},"<"+r.uri+">"),e.push(t);return e.join(", ")}}return d.isCompatibleEncoding=function(t){return e.test(t)},d.parse=function(e,t){return(new d).parse(e,t)},d.isSingleOccurenceAttr=function(e){return"rel"===e||"type"===e||"media"===e||"title"===e||"title*"===e},d.isTokenAttr=function(e){return"rel"===e||"type"===e||"anchor"===e},d.escapeQuotes=function(e){return e.replace(/"/g,'\\"')},d.expandRelations=function(e){return e.rel.split(" ").map(function(t){var r=Object.assign({},e);return r.rel=t,r})},d.parseExtendedValue=function(e){var t=/([^']+)?(?:'([^']*)')?(.+)/.exec(e);return{language:t[2].toLowerCase(),encoding:d.isCompatibleEncoding(t[1])?null:t[1].toLowerCase(),value:d.isCompatibleEncoding(t[1])?decodeURIComponent(t[3]):t[3]}},d.formatExtendedAttribute=function(e,t){var r=(t.encoding||"utf-8").toUpperCase();return e+"="+r+"'"+(t.language||"en")+"'"+(Buffer.isBuffer(t.value)&&d.isCompatibleEncoding(r)?t.value.toString(r):Buffer.isBuffer(t.value)?t.value.toString("hex").replace(/[0-9a-f]{2}/gi,"%$1"):encodeURIComponent(t.value))},d.formatAttribute=function(e,t){return Array.isArray(t)?t.map(t=>d.formatAttribute(e,t)).join("; "):"*"===e[e.length-1]||"string"!=typeof t?d.formatExtendedAttribute(e,t):(d.isTokenAttr(e)?t=h(t)?'"'+d.escapeQuotes(t)+'"':d.escapeQuotes(t):h(t)&&(t='"'+(t=(t=encodeURIComponent(t)).replace(/%20/g," ").replace(/%2C/g,",").replace(/%3B/g,";"))+'"'),e+"="+t)},q=d}(),P=e(_);function N(e){if(e){return P.parse(e).refs.map(e=>{const{rel:t,uri:r,method:n,"accept*":s,"params*":o,...i}=e,a=o?.value?JSON.parse(o?.value):void 0;return new j({rel:t,uri:r,method:n,parameters:a,accept:s?.value,...i})})}return[]}function S(e){const{name:t,href:r,fields:n,type:s,...o}=e,i={};if(n)for(const e of n)i[e.name]={};return{rel:t,uri:r,accept:s,parameters:n&&i,...o}}function D(e){const t=[];if(e&&"object"==typeof e&&"actions"in e){const r=e;if(r.actions)for(const e of r.actions){const r=S(e);t.push(r)}}return t}function F(e,t){const{href:r,rel:n,...s}=t;return new j({rel:e,uri:r,...s})}function L(e){const t=[];if(e&&"object"==typeof e&&"links"in e){const r=e;if(r.links)for(const e of r.links)for(const r of e.rel){const n=F(r,e);t.push(n)}}return t}function $(e,t){const{handlers:r,defaultHandlers:n,headers:s,contentParser:o,...i}=e,{handlers:a,defaultHandlers:c,headers:p,contentParser:u,...l}=t||{};return{...i,...l,defaultHandlers:M([...a||r||[],...c||n||[]]),handlers:[],headers:{...s,...p},contentParser:u?e=>u(e,o):o}}function H(e){return e.success}class B{constructor({handlers:e,defaultOptions:t,baseResponse:r,content:n,fullContent:s,anchor:i,parentOperations:a,parameters:c}){this.response=r,this.anchor=i,this.parameters=c||{},this.fullContent=s||n,this.content=n,this.operations=x.create();const p=d({this:n});if(a&&i&&t){this.allOperations=a;for(const e of this.allOperations[i]||[])this.operations.push(new k(e,this,t,p));for(const e in this.allOperations)if(""!==e){const r=new o.Template(e),n=r.match(this.anchor);if(r.expand(n)===this.anchor){const r=Object.assign({},t,{parameters:Object.assign(n,t.parameters)});for(const t of this.allOperations[e])this.operations.push(new k(t,this,r,p))}}}else if(r&&e&&t){this.allOperations=function({handlers:e,baseResponse:t,content:r}){const n=[];let s=!1;for(const o of e){const e=o.handler(t,r,()=>{s=!0});if(e)for(const t of e)n.push(t);if(s)break}const o={};for(const e of n){const t=E(e);for(const e of t){const t=e.anchor||"";o[t]||(o[t]=[]),o[t].push(e)}}return o}({baseResponse:r,content:n,handlers:e}),this.operations=x.create();for(const e of this.allOperations[""]||[]){const r=new k(e,this,t,p);this.operations.push(r)}}}static create(e,t,r,n){if(t instanceof O.ProblemDocument)throw new J({response:new B({handlers:n.defaultHandlers,defaultOptions:r,baseResponse:e,content:t,parameters:n.parameters}),problem:t});if(n.validator){const s=n.validator(t);if(H(s))return new B({handlers:n.defaultHandlers,defaultOptions:r,baseResponse:e,content:s.content,parameters:n.parameters});throw new J({response:new B({handlers:n.defaultHandlers,defaultOptions:r,baseResponse:e,content:t,parameters:n.parameters}),problem:s.problem})}return new B({handlers:n.defaultHandlers,defaultOptions:r,baseResponse:e,content:t,parameters:n.parameters})}get ops(){return this.operations}invoke(e,t){return this.operations.invoke(e,t)}invokeAll(e,t){return this.operations.invokeAll(e,t)}get body(){throw new Error("Not Implemented. Use `.content` instead")}get bodyUsed(){return!0}get headers(){return this.response?.headers}get ok(){return!!this.response&&this.response.ok}get redirected(){return!!this.response&&this.response.redirected}get status(){return this.response?.status}get statusText(){return this.response?.statusText}get type(){return this.response?.type}get url(){return this.response?.url}arrayBuffer(){throw new Error("Not Implemented. Use `.content` instead")}blob(){throw new Error("Not Implemented. Use `.content` instead")}clone(){throw new Error("Not Implemented")}formData(){throw new Error("Not Implemented. Use `.content` instead")}text(){throw new Error("Not Implemented. Use `.content` instead")}}class J extends Error{constructor({response:e,problem:t}){super(t.detail);const r=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,r):this.__proto__=r,this.problem=t,this.response=e}}function M(e){return e.sort((e,t)=>(t.q||1)-(e.q||1))}async function W(e,t,r){const n=$(t,r),s=n.defaultHandlers;if(!n.fetch)throw new Error("No global fetch and fetch not provided in options");const o=function(e){const t=[];for(const r of e)for(const e of r.mediaRanges)"object"==typeof e?r.q?t.push({type:e.mediaType,q:r.q*(e.q||1)}):t.push({type:e.mediaType,q:e.q||1}):r.q?t.push({type:e,q:r.q}):t.push({type:e,q:1});const r=t.sort((e,t)=>e.q-t.q),n=new Set;return r.filter(e=>{const t=e.type;return!n.has(t)&&n.add(t)})}(s).map(e=>1===e.q?e.type:`${e.type};q=${e.q}`),i=[...r?.headers?.accept?[r.headers.accept]:[],...o].join(","),a={...n,headers:{...n.headers,accept:i}};let c=!1;for(const t of a.preInterceptors||[])if(t(e,a,()=>c=!0),c)break;const p=await n.fetch(e.toString(),a);try{const e=await n.contentParser(p),r=B.create(p,e,t,n);c=!1;for(const e of a.postInterceptors)if(e(r,()=>c=!0),c)break;return r}catch(e){const r=new B({handlers:n.defaultHandlers,defaultOptions:t,baseResponse:p,content:e,parameters:n.parameters}),s=e instanceof O.ProblemDocument?new J({response:r,problem:e}):new J({response:r,problem:new O.ProblemDocument({type:"https://waychaser.io/unexected-error",title:"An unexpected error occurred",error:e})});c=!1;for(const e of a.postErrorInterceptors)if(e(s,()=>c=!0),c)break;throw s}}const Q={fetch:"undefined"==typeof globalThis?("undefined"!=typeof globalThis||"undefined"!=typeof globalThis||"undefined"!=typeof globalThis?globalThis:void 0)?.fetch:globalThis.fetch?.bind(globalThis),handlers:[],defaultHandlers:M([{handler:function(e){const t=e?.headers.get("location");return t?[new j({rel:"related",uri:t})]:[]},mediaRanges:["*/*"],q:.4},{handler:function(e,t,r){return[...N(e.headers.get("link")),...N(e.headers.get("link-template"))]},mediaRanges:["*/*"],q:.5},{handler:function(e,t){const r=[],n=e.headers.get("content-type")?.split(";");if(n?.[0]===C&&t&&"object"==typeof t&&"_links"in t){const e=t,n={};if(e._links.curies)if(Array.isArray(e._links.curies))for(const t of e._links.curies)n[t.name]=t.href;else n[e._links.curies.name]=e._links.curies.href;for(const t of Object.keys(e._links).filter(e=>"curies"!==e))if(Array.isArray(e._links[t]))for(const s of e._links[t])r.push(T(t,s,n));else r.push(T(t,e._links[t],n))}return r},mediaRanges:[C],q:.5},{handler:function(e,t){const r=e.headers.get("content-type")?.split(";");return r?.[0]===I?[...L(t),...D(t)]:[]},mediaRanges:[I],q:.5}]),preInterceptors:[],postInterceptors:[],postErrorInterceptors:[],contentParser:async e=>{if(e.headers.get("content-length")&&"0"!==e.headers.get("content-length")){const t=await e.text(),r=e.headers.get("content-type")?.split(";")?.[0];if(r?.endsWith("json")){const e=function(e,t){try{return JSON.parse(e)}catch(r){throw new O.ProblemDocument({type:"https://waychaser.io/invalid-json",title:"JSON response could not be parsed",detail:`The response document with content type '${t}' could not be parsed as json`,content:e,error:r})}}(t,r);if("application/problem+json"===r)throw Object.assign(new O.ProblemDocument(e),e);return e}}}};function G(e,t){const r=$(t,e),n=(e,t)=>W(e,r,t);return n.currentDefaults=r,n.defaults=e=>G(e,r),n}const V=Object.assign((e,t)=>W(e,Q,t),{currentDefaults:Q,defaults:e=>G(e,Q)});export{J as WayChaserProblem,B as WayChaserResponse,W as _waychaser,H as isValidationSuccess,M as sortHandlers,V as waychaser};
|