potion-client
Advanced tools
Comparing version 4.0.0-2 to 4.0.0-3
@@ -480,5 +480,3 @@ import { __assign, __awaiter, __extends, __generator, __read, __spread, __values } from 'tslib'; | ||
var ref = roots.get(value.$uri); | ||
Object.assign(json, (_a = {}, | ||
_a[key] = ref, | ||
_a)); | ||
Object.assign(json, (_a = {}, _a[key] = ref, _a)); | ||
} | ||
@@ -499,10 +497,6 @@ else if (value instanceof LazyPromiseRef) { | ||
else if (isJsObject(value)) { | ||
Object.assign(json, (_b = {}, | ||
_b[key] = replaceReferences(value, roots), | ||
_b)); | ||
Object.assign(json, (_b = {}, _b[key] = replaceReferences(value, roots), _b)); | ||
} | ||
else if (isString(value) && value === '#') { | ||
Object.assign(json, (_c = {}, | ||
_c[key] = roots.get('#'), | ||
_c)); | ||
Object.assign(json, (_c = {}, _c[key] = roots.get('#'), _c)); | ||
} | ||
@@ -509,0 +503,0 @@ var _a, _b, _c; |
@@ -483,5 +483,3 @@ (function (global, factory) { | ||
var ref = roots.get(value.$uri); | ||
Object.assign(json, (_a = {}, | ||
_a[key] = ref, | ||
_a)); | ||
Object.assign(json, (_a = {}, _a[key] = ref, _a)); | ||
} | ||
@@ -502,10 +500,6 @@ else if (value instanceof LazyPromiseRef) { | ||
else if (isJsObject(value)) { | ||
Object.assign(json, (_b = {}, | ||
_b[key] = replaceReferences(value, roots), | ||
_b)); | ||
Object.assign(json, (_b = {}, _b[key] = replaceReferences(value, roots), _b)); | ||
} | ||
else if (isString(value) && value === '#') { | ||
Object.assign(json, (_c = {}, | ||
_c[key] = roots.get('#'), | ||
_c)); | ||
Object.assign(json, (_c = {}, _c[key] = roots.get('#'), _c)); | ||
} | ||
@@ -512,0 +506,0 @@ var _a, _b, _c; |
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("tslib"),require("angular")):"function"==typeof define&&define.amd?define(["exports","tslib","angular"],e):e(t.potionClient={},t.tslib,t.angular)}(this,function(t,e,r){"use strict";function n(t,e){return void 0===e&&(e="_"),t.replace(/\.?([A-Z0-9]+)/g,function(t,r){return""+e+r.toLowerCase()}).replace(/^_/,"")}function i(t){return t.replace(/_([a-z0-9])/g,function(t){return t[1].toUpperCase()})}function o(t){return"object"==typeof t&&null!==t}function a(t){return"string"==typeof t}function u(t){return"function"==typeof t}function s(t){return Array.isArray(t)?t.map(function(t){return"object"==typeof t?s(t):t}):o(t)?Object.entries(t).map(function(t){var r=e.__read(t,2),n=r[0],o=r[1];return[i(n),"object"==typeof o?s(o):o]}).reduce(function(t,r){var n=e.__read(r,2),i=n[0],o=n[1];return e.__assign({},t,(a={},a[i]=o,a));var a},{}):t}function c(t,r){if("object"!=typeof t||null===t||t.hasOwnProperty("$schema"))return t;if(S.has(t))return t;if(t instanceof A){var n=t.toArray().map(function(t){return c(t,r)});return t.update(n,t.total)}if(Array.isArray(t))return t.map(function(t){return c(t,r)});if(t instanceof T)return r.get(t.$uri);if(Object.keys(t).length>0){!Array.isArray(t)&&t.uri&&S.add(t);try{for(var i=e.__values(Object.entries(t)),u=i.next();!u.done;u=i.next()){var s=e.__read(u.value,2);!function(e,n){if(n instanceof T){var i=r.get(n.$uri);Object.assign(t,(s={},s[e]=i,s))}else if(n instanceof x){var u;Object.defineProperty(t,e,{get:function(){return u||(u=n.getter(!0))}})}else o(n)?Object.assign(t,(f={},f[e]=c(n,r),f)):a(n)&&"#"===n&&Object.assign(t,(h={},h[e]=r.get("#"),h));var s,f,h}(s[0],s[1])}}catch(t){f={error:t}}finally{try{u&&!u.done&&(h=i.return)&&h.call(i)}finally{if(f)throw f.error}}return t}return t;var f,h}function f(t,r){var n=new Map;if(o(t)&&Object.keys(t).length>0){if(r||n.set("#",t),S.has(t)||t.hasOwnProperty("$schema"))return new Map;t.uri&&!n.has(t.uri)&&n.set(t.uri,t);var i=Array.isArray(t)||t instanceof A?t:Object.values(t);try{for(var a=e.__values(i),u=a.next();!u.done;u=a.next()){var s=f(u.value,!0);try{for(var c=e.__values(s.entries()),h=c.next();!h.done;h=c.next()){var p=e.__read(h.value,2),d=p[0],l=p[1];n.set(d,l)}}catch(t){g={error:t}}finally{try{h&&!h.done&&(m=c.return)&&m.call(c)}finally{if(g)throw g.error}}}}catch(t){v={error:t}}finally{try{u&&!u.done&&(y=a.return)&&y.call(a)}finally{if(v)throw v.error}}}return n;var v,y,g,m}function h(t,r){return o(t)?t instanceof j&&a(t.uri)?{$ref:""+_(t.uri,r)}:t instanceof Date?{$date:t.getTime()}:Array.isArray(t)?t.map(function(t){return h(t,r)}):function(t,r,n){return o(t)&&!Array.isArray(t)?Object.entries(t).map(function(t){var i=e.__read(t,2),o=i[0],a=i[1];return[u(r)?r(o):o,u(n)?n(a):a]}).reduce(function(t,r){var n=e.__read(r,2),i=n[0],o=n[1];return e.__assign({},t,(a={},a[i]=o,a));var a},{}):t}(t,function(t){return n(t)},function(t){return h(t,r)}):t}function p(t){return a(t)&&t.length>0?/^\d+$/.test(t)?parseInt(t,10):t:Number.isInteger(t)?t:null}function d(t,e){var r=t.indexOf(e+"/");return-1!==r?p(t.substring(r).split("/").pop()):null}function l(t,r){if(a(t)){var n=Object.entries(r).sort(function(t,r){var n=e.__read(t,1)[0];return e.__read(r,1)[0].length-n.length}).find(function(r){var n=e.__read(r,1)[0];return 0===t.indexOf(n)});if(n){var i=e.__read(n,2);return{resourceURI:i[0],resource:i[1]}}}}function v(t,e){var r=l(t,e);return!!r&&null!==d(t,r.resourceURI)}function y(t){var e=t.$type,r=t.$id;return(a(r)||Number.isInteger(r))&&a(e)}function g(t){var e=t.$uri,r=t.$ref,n=t.$type,i=t.$id;return a(e)?decodeURIComponent(e):a(r)?decodeURIComponent(r):y({$type:n,$id:i})?"/"+n+"/"+i:""}function m(t,e){return t.includes(e)?t.substring(e.length):t}function _(t,e){return a(e)&&!t.includes(e)?""+e+t:t}function b(t){return I.getOwnMetadata(M,t)}function P(t){return I.getOwnMetadata(R,t)}function O(t,r){var n=u(t)?t:u(t.constructor)?t.constructor:null;if(n){var i=I.getOwnMetadata(q,n);I.defineMetadata(q,e.__assign({},i,(o={},o[r]=!0,o)),n)}var o}function $(t,e){var r=I.getOwnMetadata(N,t);if(o(r)&&a(e)){var n=Object.keys(r).find(function(t){return t===e||e.includes(t)});if(n)return r[n]}return!1}function w(t,e){var r=(void 0===e?{}:e).method;return function(e,n){var i=void 0===n?{}:n,o=i.paginate,a=void 0!==o&&o,s=i.cache,c=void 0===s||s,f=u(this),h=""+(f?P(this):this.uri)+t,p={method:r,paginate:a,cache:c};return"GET"===r?p.params=e:["POST","PUT","PATCH"].includes(r)&&(p.body=e),b(f?this:this.constructor).fetch(h,p)}}var j=function(){function t(t){this.$id=null,o(t)&&Object.assign(this,t)}return t.fetch=function(t,e){var r=(void 0===e?{}:e).cache,n=void 0===r||r,i=P(this);return b(this).fetch(i+"/"+t,{method:"GET",cache:n})},t.query=function(t,e){var r=void 0===e?{}:e,n=r.paginate,i=void 0!==n&&n,o=r.cache,a=void 0===o||o,u=P(this);return b(this).fetch(u,{method:"GET",params:t,paginate:i,cache:a})},t.first=function(t){return e.__awaiter(this,void 0,void 0,function(){var r,n;return e.__generator(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,this.query(t)];case 1:return r=e.sent(),[2,r[0]];case 2:throw n=e.sent();case 3:return[2]}})})},Object.defineProperty(t.prototype,"uri",{get:function(){return this.$uri},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"id",{get:function(){return this.$id},enumerable:!0,configurable:!0}),t.prototype.equals=function(e){return e instanceof t&&(this.id===e.id&&this.constructor.name===e.constructor.name)},t.prototype.toJSON=function(){var t=this;return Object.entries(this).filter(function(r){var n=e.__read(r,1)[0];return!n.startsWith("$")&&!function(t,e){var r=I.getOwnMetadata(q,t.constructor);return r&&r[e]}(t,n)&&!$(t.constructor,n)}).reduce(function(t,r){var n=e.__read(r,2),i=n[0],o=n[1];return e.__assign({},t,(a={},a[i]=o,a));var a},{})},t.prototype.save=function(){return e.__awaiter(this,void 0,void 0,function(){var t,r,n,i,o,a,u;return e.__generator(this,function(e){switch(e.label){case 0:t=this.toJSON(),e.label=1;case 1:return e.trys.push([1,6,,7]),this.uri||this.id?[4,this.update(t)]:[3,3];case 2:return r=e.sent(),[2,r];case 3:return n=this.constructor,i=b(n),o=P(n),[4,i.fetch(o,{method:"POST",body:t,cache:!0})];case 4:return a=e.sent(),[2,a];case 5:return[3,7];case 6:throw u=e.sent();case 7:return[2]}})})},t.prototype.update=function(t){return void 0===t&&(t={}),e.__awaiter(this,void 0,void 0,function(){var r;return e.__generator(this,function(e){return r=b(this.constructor),[2,r.fetch(this.uri,{cache:!0,method:"PATCH",body:t})]})})},t.prototype.destroy=function(){return e.__awaiter(this,void 0,void 0,function(){var t,r,n,i;return e.__generator(this,function(e){switch(e.label){case 0:t=this.uri,r=b(this.constructor),n=r.cache,e.label=1;case 1:return e.trys.push([1,3,,4]),[4,r.fetch(t,{method:"DELETE"})];case 2:return e.sent(),n.get(t)&&n.remove(t),[3,4];case 3:throw i=e.sent();case 4:return[2]}})})},t}(),A=function(){function t(t,r,n,i){var o=t.potion,a=t.uri;this.items=r,this.options=i,this.potion=o,this.uri=a;var u=e.__assign({},this.options.params),s=u.page,c=void 0===s?1:s,f=u.perPage,h=void 0===f?25:f;this.$page=c,this.$perPage=h,this.$total=parseInt(n,10)}return Object.defineProperty(t,Symbol.species,{get:function(){return t},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"page",{get:function(){return this.$page},set:function(t){this.changePageTo(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"perPage",{get:function(){return this.$perPage},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"pages",{get:function(){return Math.ceil(this.$total/this.$perPage)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"total",{get:function(){return this.$total},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"length",{get:function(){return this.items.length},enumerable:!0,configurable:!0}),t.prototype[Symbol.iterator]=function(){return this.items.values()},t.prototype.toArray=function(){return this.items.slice(0)},t.prototype.at=function(t){return this.items[t]},t.prototype.changePageTo=function(t){var e=this.options.pagination;return this.options.params.page=t,this.$page=t,this.potion.fetch(this.uri,this.options,{pagination:e})},t.prototype.update=function(t,r){return(n=this.items).splice.apply(n,e.__spread([0,this.items.length],t)),this.$total=r,this;var n},t}(),T=function(){function t(t){this.$uri=t}return t.prototype.matches=function(t){return o(t)&&this.$uri===t.uri},t}(),x=function(){return function(t){this.getter=t}}(),S=new WeakSet,E=function(){function t(){this.items=new Map}return t.prototype.has=function(t){return this.items.has(t)},t.prototype.get=function(t){return this.items.get(t)},t.prototype.put=function(t,e){return this.items.set(t,e).get(t)},t.prototype.remove=function(t){this.items.delete(t)},t}(),I=("undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0).Reflect;!function(){if(!I||!I.getMetadata)throw new Error("Dependency error. reflect-metadata shim is required when using potion-node library")}();var M=Symbol("potion:instance"),R=Symbol("potion:uri"),U=Symbol("potion:promise"),q=Symbol("potion:readonly"),N=Symbol("potion:async"),C=function(){function t(t){var e=void 0===t?{}:t,r=e.host,n=void 0===r?"":r,i=e.prefix,o=void 0===i?"":i,a=e.cache;this.resources={},this.Promise=function(t){return I.getOwnMetadata(U,t.constructor)||Promise}(this),this.requests=new Map,this.cache=a||new E,this.host=n,this.prefix=o}return t.prototype.register=function(t,r,n){if(!u(r))throw new TypeError("An error occurred while trying to register a resource for "+t+". "+r+" is not a function.");if(function(t,e){I.defineMetadata(M,e,t)}(r,this),function(t,e){I.defineMetadata(R,e,t)}(r,t),n&&Array.isArray(n.readonly))try{for(var i=e.__values(n.readonly),o=i.next();!o.done;o=i.next())O(r,c=o.value)}catch(t){f={error:t}}finally{try{o&&!o.done&&(h=i.return)&&h.call(i)}finally{if(f)throw f.error}}if(n&&Array.isArray(n.async))try{for(var a=e.__values(n.async),s=a.next();!s.done;s=a.next()){var c=s.value;!function(t,r){var n=u(t)?t:u(t.constructor)?t.constructor:null;if(n){var i=I.getOwnMetadata(N,n);I.defineMetadata(N,e.__assign({},i,(o={},o[r]=!0,o)),n)}var o}(r,c)}}catch(t){p={error:t}}finally{try{s&&!s.done&&(d=a.return)&&d.call(a)}finally{if(p)throw p.error}}return this.resources[t]=r,r;var f,h,p,d},t.prototype.registerAs=function(t,e){var r=this;return function(n){return r.register(t,n,e),n}},t.prototype.resource=function(t){var e=l(t,this.resources);if(e)return e.resource},t.prototype.fetch=function(t,r,n){var i=m(t,this.prefix),o=e.__assign({},r,n,{origin:[]});return v(t,this.resources)&&Object.assign(o,{origin:[i]}),this.resolve(t,o).then(function(t){return c(t,f(t)),t})},t.prototype.resolve=function(t,e){var r=this,n=this.prefix,i=this.Promise,o=m(t,n);t=_(t,n);var u=function(){return r.request(""+r.host+t,r.serialize(e)).then(function(n){return r.deserialize(n,t,e)})};return"GET"!==e.method||e.paginate||e.params?u():e.cache&&this.cache.has(o)?this.cache.get(o):(this.requests.has(o)||this.requests.set(o,u().then(function(t){return r.requests.delete(o),t},function(e){r.requests.delete(o);var n=function(t,e){var r="An error occurred while Potion tried to retrieve a resource";return t instanceof Error?t.message:a(t)?t:a(e)?r+" from '"+e+"'.":r+"."}(e,t);return i.reject(n)})),this.requests.get(o))},t.prototype.serialize=function(t){var r=this.prefix,n=t.params;return e.__assign({},t,{params:h(t.paginate?e.__assign({page:1,perPage:25},n):n,r),body:h(t.body,r)})},t.prototype.deserialize=function(t,e,r){var n=this,i=t.headers,o=t.body;return this.fromPotionJSON(o,r.origin).then(function(t){if(r.paginate){var o=i["x-total-count"]||t.length;if(r.pagination instanceof A)return r.pagination.update(t,o);var a=new A({uri:e,potion:n},t,o,r);return Object.assign(r,{pagination:a}),a}return t})},t.prototype.fromPotionJSON=function(t,r,n){var i=this,o=void 0===n?{}:n,u=o.rootUri,c=o.key,f=o.replaceRefs,h=this.Promise;if("object"==typeof t&&null!==t){if(Array.isArray(t)){var p=this.resource(u),d=function(e){return h.all(t.map(function(t){return i.fromPotionJSON(t,r,{replaceRefs:e})}))};return p&&$(p,c)?h.resolve(new x(d)):d(!1)}if(a(t.$uri)||y(t))return this.parseURI(t).then(function(n){var o=n.resource,a=n.id,u=n.uri,s={$id:a,$uri:u};r.includes(u)||r.push(u);var c=i.parsePotionJSONProperties(t,r);return i.cache.has(u)?h.all([c,i.cache.get(u)]).then(function(t){var r=e.__read(t,2),n=r[0],i=r[1];return Object.assign(i,n,s),i}):i.cache.put(u,c.then(function(t){return Reflect.construct(o,[e.__assign({},t,s)])}))});if(a(t.$schema))return h.resolve(s(t));if(1===Object.keys(t).length){if(a(t.$ref))return"#"===t.$ref?h.resolve(t.$ref):this.parseURI(t).then(function(t){var e=t.uri;if(r.includes(e))return h.resolve(function(t){return new T(t)}(e));var n=i.resource(u),o=function(){return i.fetch(e,{cache:!0,method:"GET"},{origin:r})};return n&&$(n,c||e)?new x(o):f?o():i.resolve(e,{cache:!0,method:"GET",origin:r})});if(void 0!==t.$date)return h.resolve(new Date(t.$date))}return this.parsePotionJSONProperties(t,r)}return h.resolve(t)},t.prototype.parsePotionJSONProperties=function(t,r){var n=this,o=this.Promise,a=Object.entries(t),u=a.map(function(i){var o=e.__read(i,2),a=o[0],u=o[1];return n.fromPotionJSON(u,r,{key:a,rootUri:t.$uri})}),s=a.map(function(t){return i(e.__read(t,1)[0])});return o.all(u).then(function(t){return t.map(function(t,e){return[s[e],t]}).reduce(function(t,r){var n=e.__read(r,2),i=n[0],o=n[1];return e.__assign({},t,(a={},a[i]=o,a));var a},{})})},t.prototype.parseURI=function(t){var e=t.$ref,r=t.$uri,n=t.$type,i=t.$id,o=this.Promise,a=m(g({$ref:e,$uri:r,$type:n,$id:i}),this.prefix),u=l(a,this.resources);if(u){var s=u.resourceURI,c={resource:u.resource,uri:a,id:p(i)};return null===c.id&&Object.assign(c,{id:d(a,s)}),o.resolve(c)}return o.reject(new Error("URI '"+a+"' is an uninterpretable or unknown Potion resource."))},t}(),J={GET:function(t){return w(t,{method:"GET"})},DELETE:function(t){return w(t,{method:"DELETE"})},POST:function(t){return w(t,{method:"POST"})},PATCH:function(t){return w(t,{method:"PATCH"})},PUT:function(t){return w(t,{method:"PUT"})}},k=r.module("potion",[]).provider("potion",function(){var t={};return this.config=function(e){return o(e)?(Object.assign(t,e),t):t},this.$get=["$cacheFactory","$q","$http",function(r,n,i){var o=r.get("potion")||r("potion"),a=function(t){function r(){return null!==t&&t.apply(this,arguments)||this}return e.__extends(r,t),r.prototype.request=function(t,r){var n=e.__assign({},r),o=n.method,a=void 0===o?"GET":o,u=n.params,s=n.body,c=n.cache;return i({url:t,method:a,data:s,cache:void 0===c||c,params:u}).then(function(t){var e=t.headers,r={body:t.data};return e&&(r.headers=e()),r})},r}(C),u=function(){function t(){}return t.prototype.has=function(t){return void 0!==o.get(t)},t.prototype.get=function(t){return o.get(t)},t.prototype.put=function(t,e){return o.put(t,e),o.get(t)},t.prototype.remove=function(t){o.remove(t)},t}();return function(t,e){I.defineMetadata(U,e,t)}(a,n),new a(e.__assign({cache:new u},t))}],this});t.potion=k,t.Item=j,t.readonly=O,t.Pagination=A,t.PotionBase=C,t.Route=J,t.route=w,t.findPotionResource=l,t.fromSchemaJSON=s,t.getPotionID=d,t.getPotionURI=g,t.hasTypeAndId=y,t.isPotionURI=v,t.parsePotionID=p,t.removePrefixFromURI=m,t.addPrefixToURI=_,t.toPotionJSON=h,t.toCamelCase=i,t.toSnakeCase=n,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("tslib"),require("angular")):"function"==typeof define&&define.amd?define(["exports","tslib","angular"],e):e(t.potionClient={},t.tslib,t.angular)}(this,function(t,e,r){"use strict";function n(t,e){return void 0===e&&(e="_"),t.replace(/\.?([A-Z0-9]+)/g,function(t,r){return""+e+r.toLowerCase()}).replace(/^_/,"")}function i(t){return t.replace(/_([a-z0-9])/g,function(t){return t[1].toUpperCase()})}function o(t){return"object"==typeof t&&null!==t}function a(t){return"string"==typeof t}function u(t){return"function"==typeof t}function s(t){return Array.isArray(t)?t.map(function(t){return"object"==typeof t?s(t):t}):o(t)?Object.entries(t).map(function(t){var r=e.__read(t,2),n=r[0],o=r[1];return[i(n),"object"==typeof o?s(o):o]}).reduce(function(t,r){var n=e.__read(r,2),i=n[0],o=n[1];return e.__assign({},t,(a={},a[i]=o,a));var a},{}):t}function c(t,r){if("object"!=typeof t||null===t||t.hasOwnProperty("$schema"))return t;if(I.has(t))return t;if(t instanceof x){var n=t.toArray().map(function(t){return c(t,r)});return t.update(n,t.total)}if(Array.isArray(t))return t.map(function(t){return c(t,r)});if(t instanceof S)return r.get(t.$uri);if(Object.keys(t).length>0){!Array.isArray(t)&&t.uri&&I.add(t);var i=function(e,n){if(n instanceof S){var i=r.get(n.$uri);Object.assign(t,(s={},s[e]=i,s))}else if(n instanceof E){var u;Object.defineProperty(t,e,{get:function(){return u||(u=n.getter(!0))}})}else o(n)?Object.assign(t,(f={},f[e]=c(n,r),f)):a(n)&&"#"===n&&Object.assign(t,(h={},h[e]=r.get("#"),h));var s,f,h};try{for(var u=e.__values(Object.entries(t)),s=u.next();!s.done;s=u.next()){var f=e.__read(s.value,2);i(f[0],f[1])}}catch(t){h={error:t}}finally{try{s&&!s.done&&(p=u.return)&&p.call(u)}finally{if(h)throw h.error}}return t}return t;var h,p}function f(t,r){var n=new Map;if(o(t)&&Object.keys(t).length>0){if(r||n.set("#",t),I.has(t)||t.hasOwnProperty("$schema"))return new Map;t.uri&&!n.has(t.uri)&&n.set(t.uri,t);var i=Array.isArray(t)||t instanceof x?t:Object.values(t);try{for(var a=e.__values(i),u=a.next();!u.done;u=a.next()){var s=f(u.value,!0);try{for(var c=e.__values(s.entries()),h=c.next();!h.done;h=c.next()){var p=e.__read(h.value,2),d=p[0],l=p[1];n.set(d,l)}}catch(t){g={error:t}}finally{try{h&&!h.done&&(m=c.return)&&m.call(c)}finally{if(g)throw g.error}}}}catch(t){v={error:t}}finally{try{u&&!u.done&&(y=a.return)&&y.call(a)}finally{if(v)throw v.error}}}return n;var v,y,g,m}function h(t,r){return o(t)?t instanceof T&&a(t.uri)?{$ref:""+_(t.uri,r)}:t instanceof Date?{$date:t.getTime()}:Array.isArray(t)?t.map(function(t){return h(t,r)}):function(t,r,n){return o(t)&&!Array.isArray(t)?Object.entries(t).map(function(t){var i=e.__read(t,2),o=i[0],a=i[1];return[u(r)?r(o):o,u(n)?n(a):a]}).reduce(function(t,r){var n=e.__read(r,2),i=n[0],o=n[1];return e.__assign({},t,(a={},a[i]=o,a));var a},{}):t}(t,function(t){return n(t)},function(t){return h(t,r)}):t}function p(t){return a(t)&&t.length>0?/^\d+$/.test(t)?parseInt(t,10):t:Number.isInteger(t)?t:null}function d(t,e){var r=t.indexOf(e+"/");if(-1!==r){return p(t.substring(r).split("/").pop())}return null}function l(t,r){if(a(t)){var n=Object.entries(r).sort(function(t,r){var n=e.__read(t,1)[0];return e.__read(r,1)[0].length-n.length}).find(function(r){var n=e.__read(r,1)[0];return 0===t.indexOf(n)});if(n){var i=e.__read(n,2);return{resourceURI:i[0],resource:i[1]}}}}function v(t,e){var r=l(t,e);return!!r&&null!==d(t,r.resourceURI)}function y(t){var e=t.$type,r=t.$id;return(a(r)||Number.isInteger(r))&&a(e)}function g(t){var e=t.$uri,r=t.$ref,n=t.$type,i=t.$id;return a(e)?decodeURIComponent(e):a(r)?decodeURIComponent(r):y({$type:n,$id:i})?"/"+n+"/"+i:""}function m(t,e){return t.includes(e)?t.substring(e.length):t}function _(t,e){return a(e)&&!t.includes(e)?""+e+t:t}function b(t){return R.getOwnMetadata(U,t)}function P(t){return R.getOwnMetadata(q,t)}function O(t,r){var n=u(t)?t:u(t.constructor)?t.constructor:null;if(n){var i=R.getOwnMetadata(C,n);R.defineMetadata(C,e.__assign({},i,(o={},o[r]=!0,o)),n)}var o}function $(t,e){var r=R.getOwnMetadata(J,t);if(o(r)&&a(e)){var n=Object.keys(r).find(function(t){return t===e||e.includes(t)});if(n)return r[n]}return!1}function w(t,r){var n=u(t)?t:u(t.constructor)?t.constructor:null;if(n){var i=R.getOwnMetadata(J,n);R.defineMetadata(J,e.__assign({},i,(o={},o[r]=!0,o)),n)}var o}function j(t,e){var r=(void 0===e?{}:e).method;return function(e,n){var i=void 0===n?{}:n,o=i.paginate,a=void 0!==o&&o,s=i.cache,c=void 0===s||s,f=u(this),h=""+(f?P(this):this.uri)+t,p={method:r,paginate:a,cache:c};return"GET"===r?p.params=e:["POST","PUT","PATCH"].includes(r)&&(p.body=e),b(f?this:this.constructor).fetch(h,p)}}function A(){var t={};return this.config=function(e){return o(e)?(Object.assign(t,e),t):t},this.$get=["$cacheFactory","$q","$http",function(r,n,i){var o=r.get("potion")||r("potion"),a=function(t){function r(){return null!==t&&t.apply(this,arguments)||this}return e.__extends(r,t),r.prototype.request=function(t,r){var n=e.__assign({},r),o=n.method,a=void 0===o?"GET":o,u=n.params,s=n.body,c=n.cache;return i({url:t,method:a,data:s,cache:void 0===c||c,params:u}).then(function(t){var e=t.headers,r={body:t.data};return e&&(r.headers=e()),r})},r}(k),u=function(){function t(){}return t.prototype.has=function(t){return void 0!==o.get(t)},t.prototype.get=function(t){return o.get(t)},t.prototype.put=function(t,e){return o.put(t,e),o.get(t)},t.prototype.remove=function(t){o.remove(t)},t}();return function(t,e){R.defineMetadata(N,e,t)}(a,n),new a(e.__assign({cache:new u},t))}],this}var T=function(){function t(t){this.$id=null,o(t)&&Object.assign(this,t)}return t.fetch=function(t,e){var r=(void 0===e?{}:e).cache,n=void 0===r||r,i=P(this);return b(this).fetch(i+"/"+t,{method:"GET",cache:n})},t.query=function(t,e){var r=void 0===e?{}:e,n=r.paginate,i=void 0!==n&&n,o=r.cache,a=void 0===o||o,u=P(this);return b(this).fetch(u,{method:"GET",params:t,paginate:i,cache:a})},t.first=function(t){return e.__awaiter(this,void 0,void 0,function(){var r,n;return e.__generator(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,this.query(t)];case 1:return r=e.sent(),[2,r[0]];case 2:throw n=e.sent();case 3:return[2]}})})},Object.defineProperty(t.prototype,"uri",{get:function(){return this.$uri},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"id",{get:function(){return this.$id},enumerable:!0,configurable:!0}),t.prototype.equals=function(e){return e instanceof t&&(this.id===e.id&&this.constructor.name===e.constructor.name)},t.prototype.toJSON=function(){var t=this;return Object.entries(this).filter(function(r){var n=e.__read(r,1)[0];return!n.startsWith("$")&&!function(t,e){var r=R.getOwnMetadata(C,t.constructor);return r&&r[e]}(t,n)&&!$(t.constructor,n)}).reduce(function(t,r){var n=e.__read(r,2),i=n[0],o=n[1];return e.__assign({},t,(a={},a[i]=o,a));var a},{})},t.prototype.save=function(){return e.__awaiter(this,void 0,void 0,function(){var t,r,n,i,o,a,u;return e.__generator(this,function(e){switch(e.label){case 0:t=this.toJSON(),e.label=1;case 1:return e.trys.push([1,6,,7]),this.uri||this.id?[4,this.update(t)]:[3,3];case 2:return r=e.sent(),[2,r];case 3:return n=this.constructor,i=b(n),o=P(n),[4,i.fetch(o,{method:"POST",body:t,cache:!0})];case 4:return a=e.sent(),[2,a];case 5:return[3,7];case 6:throw u=e.sent();case 7:return[2]}})})},t.prototype.update=function(t){return void 0===t&&(t={}),e.__awaiter(this,void 0,void 0,function(){var r;return e.__generator(this,function(e){return r=b(this.constructor),[2,r.fetch(this.uri,{cache:!0,method:"PATCH",body:t})]})})},t.prototype.destroy=function(){return e.__awaiter(this,void 0,void 0,function(){var t,r,n,i;return e.__generator(this,function(e){switch(e.label){case 0:t=this.uri,r=b(this.constructor),n=r.cache,e.label=1;case 1:return e.trys.push([1,3,,4]),[4,r.fetch(t,{method:"DELETE"})];case 2:return e.sent(),n.get(t)&&n.remove(t),[3,4];case 3:throw i=e.sent();case 4:return[2]}})})},t}(),x=function(){function t(t,r,n,i){var o=t.potion,a=t.uri;this.items=r,this.options=i,this.potion=o,this.uri=a;var u=e.__assign({},this.options.params),s=u.page,c=void 0===s?1:s,f=u.perPage,h=void 0===f?25:f;this.$page=c,this.$perPage=h,this.$total=parseInt(n,10)}return Object.defineProperty(t,Symbol.species,{get:function(){return t},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"page",{get:function(){return this.$page},set:function(t){this.changePageTo(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"perPage",{get:function(){return this.$perPage},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"pages",{get:function(){return Math.ceil(this.$total/this.$perPage)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"total",{get:function(){return this.$total},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"length",{get:function(){return this.items.length},enumerable:!0,configurable:!0}),t.prototype[Symbol.iterator]=function(){return this.items.values()},t.prototype.toArray=function(){return this.items.slice(0)},t.prototype.at=function(t){return this.items[t]},t.prototype.changePageTo=function(t){var e=this.options.pagination;return this.options.params.page=t,this.$page=t,this.potion.fetch(this.uri,this.options,{pagination:e})},t.prototype.update=function(t,r){return(n=this.items).splice.apply(n,e.__spread([0,this.items.length],t)),this.$total=r,this;var n},t}(),S=function(){function t(t){this.$uri=t}return t.prototype.matches=function(t){return o(t)&&this.$uri===t.uri},t}(),E=function(){return function(t){this.getter=t}}(),I=new WeakSet,M=function(){function t(){this.items=new Map}return t.prototype.has=function(t){return this.items.has(t)},t.prototype.get=function(t){return this.items.get(t)},t.prototype.put=function(t,e){return this.items.set(t,e).get(t)},t.prototype.remove=function(t){this.items.delete(t)},t}(),R=("undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0).Reflect;!function(){if(!R||!R.getMetadata)throw new Error("Dependency error. reflect-metadata shim is required when using potion-node library")}();var U=Symbol("potion:instance"),q=Symbol("potion:uri"),N=Symbol("potion:promise"),C=Symbol("potion:readonly"),J=Symbol("potion:async"),k=function(){function t(t){var e=void 0===t?{}:t,r=e.host,n=void 0===r?"":r,i=e.prefix,o=void 0===i?"":i,a=e.cache;this.resources={},this.Promise=function(t){return R.getOwnMetadata(N,t.constructor)||Promise}(this),this.requests=new Map,this.cache=a||new M,this.host=n,this.prefix=o}return t.prototype.register=function(t,r,n){if(!u(r))throw new TypeError("An error occurred while trying to register a resource for "+t+". "+r+" is not a function.");if(function(t,e){R.defineMetadata(U,e,t)}(r,this),function(t,e){R.defineMetadata(q,e,t)}(r,t),n&&Array.isArray(n.readonly))try{for(var i=e.__values(n.readonly),o=i.next();!o.done;o=i.next()){O(r,c=o.value)}}catch(t){f={error:t}}finally{try{o&&!o.done&&(h=i.return)&&h.call(i)}finally{if(f)throw f.error}}if(n&&Array.isArray(n.async))try{for(var a=e.__values(n.async),s=a.next();!s.done;s=a.next()){var c=s.value;w(r,c)}}catch(t){p={error:t}}finally{try{s&&!s.done&&(d=a.return)&&d.call(a)}finally{if(p)throw p.error}}return this.resources[t]=r,r;var f,h,p,d},t.prototype.registerAs=function(t,e){var r=this;return function(n){return r.register(t,n,e),n}},t.prototype.resource=function(t){var e=l(t,this.resources);if(e)return e.resource},t.prototype.fetch=function(t,r,n){var i=m(t,this.prefix),o=e.__assign({},r,n,{origin:[]});return v(t,this.resources)&&Object.assign(o,{origin:[i]}),this.resolve(t,o).then(function(t){return c(t,f(t)),t})},t.prototype.resolve=function(t,e){var r=this,n=this.prefix,i=this.Promise,o=m(t,n);t=_(t,n);var u=function(){return r.request(""+r.host+t,r.serialize(e)).then(function(n){return r.deserialize(n,t,e)})};return"GET"!==e.method||e.paginate||e.params?u():e.cache&&this.cache.has(o)?this.cache.get(o):(this.requests.has(o)||this.requests.set(o,u().then(function(t){return r.requests.delete(o),t},function(e){r.requests.delete(o);var n=function(t,e){var r="An error occurred while Potion tried to retrieve a resource";return t instanceof Error?t.message:a(t)?t:a(e)?r+" from '"+e+"'.":r+"."}(e,t);return i.reject(n)})),this.requests.get(o))},t.prototype.serialize=function(t){var r=this.prefix,n=t.params;return e.__assign({},t,{params:h(t.paginate?e.__assign({page:1,perPage:25},n):n,r),body:h(t.body,r)})},t.prototype.deserialize=function(t,e,r){var n=this,i=t.headers,o=t.body;return this.fromPotionJSON(o,r.origin).then(function(t){if(r.paginate){var o=i["x-total-count"]||t.length;if(r.pagination instanceof x)return r.pagination.update(t,o);var a=new x({uri:e,potion:n},t,o,r);return Object.assign(r,{pagination:a}),a}return t})},t.prototype.fromPotionJSON=function(t,r,n){var i=this,o=void 0===n?{}:n,u=o.rootUri,c=o.key,f=o.replaceRefs,h=this.Promise;if("object"==typeof t&&null!==t){if(Array.isArray(t)){var p=this.resource(u),d=function(e){return h.all(t.map(function(t){return i.fromPotionJSON(t,r,{replaceRefs:e})}))};return p&&$(p,c)?h.resolve(new E(d)):d(!1)}if(a(t.$uri)||y(t))return this.parseURI(t).then(function(n){var o=n.resource,a=n.id,u=n.uri,s={$id:a,$uri:u};r.includes(u)||r.push(u);var c=i.parsePotionJSONProperties(t,r);return i.cache.has(u)?h.all([c,i.cache.get(u)]).then(function(t){var r=e.__read(t,2),n=r[0],i=r[1];return Object.assign(i,n,s),i}):i.cache.put(u,c.then(function(t){return Reflect.construct(o,[e.__assign({},t,s)])}))});if(a(t.$schema))return h.resolve(s(t));if(1===Object.keys(t).length){if(a(t.$ref))return"#"===t.$ref?h.resolve(t.$ref):this.parseURI(t).then(function(t){var e=t.uri;if(r.includes(e))return h.resolve(function(t){return new S(t)}(e));var n=i.resource(u),o=function(){return i.fetch(e,{cache:!0,method:"GET"},{origin:r})};return n&&$(n,c||e)?new E(o):f?o():i.resolve(e,{cache:!0,method:"GET",origin:r})});if(void 0!==t.$date)return h.resolve(new Date(t.$date))}return this.parsePotionJSONProperties(t,r)}return h.resolve(t)},t.prototype.parsePotionJSONProperties=function(t,r){var n=this,o=this.Promise,a=Object.entries(t),u=a.map(function(i){var o=e.__read(i,2),a=o[0],u=o[1];return n.fromPotionJSON(u,r,{key:a,rootUri:t.$uri})}),s=a.map(function(t){return i(e.__read(t,1)[0])});return o.all(u).then(function(t){return t.map(function(t,e){return[s[e],t]}).reduce(function(t,r){var n=e.__read(r,2),i=n[0],o=n[1];return e.__assign({},t,(a={},a[i]=o,a));var a},{})})},t.prototype.parseURI=function(t){var e=t.$ref,r=t.$uri,n=t.$type,i=t.$id,o=this.Promise,a=m(g({$ref:e,$uri:r,$type:n,$id:i}),this.prefix),u=l(a,this.resources);if(u){var s=u.resourceURI,c={resource:u.resource,uri:a,id:p(i)};return null===c.id&&Object.assign(c,{id:d(a,s)}),o.resolve(c)}return o.reject(new Error("URI '"+a+"' is an uninterpretable or unknown Potion resource."))},t}(),G={GET:function(t){return j(t,{method:"GET"})},DELETE:function(t){return j(t,{method:"DELETE"})},POST:function(t){return j(t,{method:"POST"})},PATCH:function(t){return j(t,{method:"PATCH"})},PUT:function(t){return j(t,{method:"PUT"})}},D=r.module("potion",[]).provider("potion",A);t.potion=D,t.Item=T,t.readonly=O,t.Pagination=x,t.PotionBase=k,t.Route=G,t.route=j,t.findPotionResource=l,t.fromSchemaJSON=s,t.getPotionID=d,t.getPotionURI=g,t.hasTypeAndId=y,t.isPotionURI=v,t.parsePotionID=p,t.removePrefixFromURI=m,t.addPrefixToURI=_,t.toPotionJSON=h,t.toCamelCase=i,t.toSnakeCase=n,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=angularjs.umd.min.js.map |
@@ -0,1 +1,11 @@ | ||
<a name="4.0.0-3"></a> | ||
# [4.0.0-3](https://github.com/biosustain/potion-node/compare/v4.0.0-2...v4.0.0-3) (2017-11-18) | ||
### Features | ||
* update deps ([bcac2b3](https://github.com/biosustain/potion-node/commit/bcac2b3)) | ||
<a name="4.0.0-2"></a> | ||
@@ -2,0 +12,0 @@ # [4.0.0-2](https://github.com/biosustain/potion-node/compare/v4.0.0-1...v4.0.0-2) (2017-11-18) |
@@ -479,5 +479,3 @@ import { __assign, __awaiter, __extends, __generator, __read, __spread, __values } from 'tslib'; | ||
var ref = roots.get(value.$uri); | ||
Object.assign(json, (_a = {}, | ||
_a[key] = ref, | ||
_a)); | ||
Object.assign(json, (_a = {}, _a[key] = ref, _a)); | ||
} | ||
@@ -498,10 +496,6 @@ else if (value instanceof LazyPromiseRef) { | ||
else if (isJsObject(value)) { | ||
Object.assign(json, (_b = {}, | ||
_b[key] = replaceReferences(value, roots), | ||
_b)); | ||
Object.assign(json, (_b = {}, _b[key] = replaceReferences(value, roots), _b)); | ||
} | ||
else if (isString(value) && value === '#') { | ||
Object.assign(json, (_c = {}, | ||
_c[key] = roots.get('#'), | ||
_c)); | ||
Object.assign(json, (_c = {}, _c[key] = roots.get('#'), _c)); | ||
} | ||
@@ -508,0 +502,0 @@ var _a, _b, _c; |
@@ -483,5 +483,3 @@ (function (global, factory) { | ||
var ref = roots.get(value.$uri); | ||
Object.assign(json, (_a = {}, | ||
_a[key] = ref, | ||
_a)); | ||
Object.assign(json, (_a = {}, _a[key] = ref, _a)); | ||
} | ||
@@ -502,10 +500,6 @@ else if (value instanceof LazyPromiseRef) { | ||
else if (isJsObject(value)) { | ||
Object.assign(json, (_b = {}, | ||
_b[key] = replaceReferences(value, roots), | ||
_b)); | ||
Object.assign(json, (_b = {}, _b[key] = replaceReferences(value, roots), _b)); | ||
} | ||
else if (isString(value) && value === '#') { | ||
Object.assign(json, (_c = {}, | ||
_c[key] = roots.get('#'), | ||
_c)); | ||
Object.assign(json, (_c = {}, _c[key] = roots.get('#'), _c)); | ||
} | ||
@@ -512,0 +506,0 @@ var _a, _b, _c; |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("tslib")):"function"==typeof define&&define.amd?define(["exports","tslib"],t):t(e.potionClient={},e.tslib)}(this,function(e,t){"use strict";function r(e,t){return void 0===t&&(t="_"),e.replace(/\.?([A-Z0-9]+)/g,function(e,r){return""+t+r.toLowerCase()}).replace(/^_/,"")}function n(e){return e.replace(/_([a-z0-9])/g,function(e){return e[1].toUpperCase()})}function i(e){return"object"==typeof e&&null!==e}function o(e){return"string"==typeof e}function a(e){return"function"==typeof e}function u(e){return Array.isArray(e)?e.map(function(e){return"object"==typeof e?u(e):e}):i(e)?Object.entries(e).map(function(e){var r=t.__read(e,2),i=r[0],o=r[1];return[n(i),"object"==typeof o?u(o):o]}).reduce(function(e,r){var n=t.__read(r,2),i=n[0],o=n[1];return t.__assign({},e,(a={},a[i]=o,a));var a},{}):e}function s(e,r){if("object"!=typeof e||null===e||e.hasOwnProperty("$schema"))return e;if(x.has(e))return e;if(e instanceof j){var n=e.toArray().map(function(e){return s(e,r)});return e.update(n,e.total)}if(Array.isArray(e))return e.map(function(e){return s(e,r)});if(e instanceof T)return r.get(e.$uri);if(Object.keys(e).length>0){!Array.isArray(e)&&e.uri&&x.add(e);try{for(var a=t.__values(Object.entries(e)),u=a.next();!u.done;u=a.next()){var c=t.__read(u.value,2);!function(t,n){if(n instanceof T){var a=r.get(n.$uri);Object.assign(e,(c={},c[t]=a,c))}else if(n instanceof A){var u;Object.defineProperty(e,t,{get:function(){return u||(u=n.getter(!0))}})}else i(n)?Object.assign(e,(f={},f[t]=s(n,r),f)):o(n)&&"#"===n&&Object.assign(e,(h={},h[t]=r.get("#"),h));var c,f,h}(c[0],c[1])}}catch(e){f={error:e}}finally{try{u&&!u.done&&(h=a.return)&&h.call(a)}finally{if(f)throw f.error}}return e}return e;var f,h}function c(e,r){var n=new Map;if(i(e)&&Object.keys(e).length>0){if(r||n.set("#",e),x.has(e)||e.hasOwnProperty("$schema"))return new Map;e.uri&&!n.has(e.uri)&&n.set(e.uri,e);var o=Array.isArray(e)||e instanceof j?e:Object.values(e);try{for(var a=t.__values(o),u=a.next();!u.done;u=a.next()){var s=c(u.value,!0);try{for(var f=t.__values(s.entries()),h=f.next();!h.done;h=f.next()){var p=t.__read(h.value,2),d=p[0],l=p[1];n.set(d,l)}}catch(e){g={error:e}}finally{try{h&&!h.done&&(m=f.return)&&m.call(f)}finally{if(g)throw g.error}}}}catch(e){v={error:e}}finally{try{u&&!u.done&&(y=a.return)&&y.call(a)}finally{if(v)throw v.error}}}return n;var v,y,g,m}function f(e,n){return i(e)?e instanceof $&&o(e.uri)?{$ref:""+m(e.uri,n)}:e instanceof Date?{$date:e.getTime()}:Array.isArray(e)?e.map(function(e){return f(e,n)}):function(e,r,n){return i(e)&&!Array.isArray(e)?Object.entries(e).map(function(e){var i=t.__read(e,2),o=i[0],u=i[1];return[a(r)?r(o):o,a(n)?n(u):u]}).reduce(function(e,r){var n=t.__read(r,2),i=n[0],o=n[1];return t.__assign({},e,(a={},a[i]=o,a));var a},{}):e}(e,function(e){return r(e)},function(e){return f(e,n)}):e}function h(e){return o(e)&&e.length>0?/^\d+$/.test(e)?parseInt(e,10):e:Number.isInteger(e)?e:null}function p(e,t){var r=e.indexOf(t+"/");return-1!==r?h(e.substring(r).split("/").pop()):null}function d(e,r){if(o(e)){var n=Object.entries(r).sort(function(e,r){var n=t.__read(e,1)[0];return t.__read(r,1)[0].length-n.length}).find(function(r){var n=t.__read(r,1)[0];return 0===e.indexOf(n)});if(n){var i=t.__read(n,2);return{resourceURI:i[0],resource:i[1]}}}}function l(e,t){var r=d(e,t);return!!r&&null!==p(e,r.resourceURI)}function v(e){var t=e.$type,r=e.$id;return(o(r)||Number.isInteger(r))&&o(t)}function y(e){var t=e.$uri,r=e.$ref,n=e.$type,i=e.$id;return o(t)?decodeURIComponent(t):o(r)?decodeURIComponent(r):v({$type:n,$id:i})?"/"+n+"/"+i:""}function g(e,t){return e.includes(t)?e.substring(t.length):e}function m(e,t){return o(t)&&!e.includes(t)?""+t+e:e}function _(e){return E.getOwnMetadata(I,e)}function b(e){return E.getOwnMetadata(R,e)}function P(e,r){var n=a(e)?e:a(e.constructor)?e.constructor:null;if(n){var i=E.getOwnMetadata(M,n);E.defineMetadata(M,t.__assign({},i,(o={},o[r]=!0,o)),n)}var o}function O(e,t){var r=E.getOwnMetadata(q,e);if(i(r)&&o(t)){var n=Object.keys(r).find(function(e){return e===t||t.includes(e)});if(n)return r[n]}return!1}function w(e,t){var r=(void 0===t?{}:t).method;return function(t,n){var i=void 0===n?{}:n,o=i.paginate,u=void 0!==o&&o,s=i.cache,c=void 0===s||s,f=a(this),h=""+(f?b(this):this.uri)+e,p={method:r,paginate:u,cache:c};return"GET"===r?p.params=t:["POST","PUT","PATCH"].includes(r)&&(p.body=t),_(f?this:this.constructor).fetch(h,p)}}var $=function(){function e(e){this.$id=null,i(e)&&Object.assign(this,e)}return e.fetch=function(e,t){var r=(void 0===t?{}:t).cache,n=void 0===r||r,i=b(this);return _(this).fetch(i+"/"+e,{method:"GET",cache:n})},e.query=function(e,t){var r=void 0===t?{}:t,n=r.paginate,i=void 0!==n&&n,o=r.cache,a=void 0===o||o,u=b(this);return _(this).fetch(u,{method:"GET",params:e,paginate:i,cache:a})},e.first=function(e){return t.__awaiter(this,void 0,void 0,function(){var r,n;return t.__generator(this,function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,this.query(e)];case 1:return r=t.sent(),[2,r[0]];case 2:throw n=t.sent();case 3:return[2]}})})},Object.defineProperty(e.prototype,"uri",{get:function(){return this.$uri},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"id",{get:function(){return this.$id},enumerable:!0,configurable:!0}),e.prototype.equals=function(t){return t instanceof e&&(this.id===t.id&&this.constructor.name===t.constructor.name)},e.prototype.toJSON=function(){var e=this;return Object.entries(this).filter(function(r){var n=t.__read(r,1)[0];return!n.startsWith("$")&&!function(e,t){var r=E.getOwnMetadata(M,e.constructor);return r&&r[t]}(e,n)&&!O(e.constructor,n)}).reduce(function(e,r){var n=t.__read(r,2),i=n[0],o=n[1];return t.__assign({},e,(a={},a[i]=o,a));var a},{})},e.prototype.save=function(){return t.__awaiter(this,void 0,void 0,function(){var e,r,n,i,o,a,u;return t.__generator(this,function(t){switch(t.label){case 0:e=this.toJSON(),t.label=1;case 1:return t.trys.push([1,6,,7]),this.uri||this.id?[4,this.update(e)]:[3,3];case 2:return r=t.sent(),[2,r];case 3:return n=this.constructor,i=_(n),o=b(n),[4,i.fetch(o,{method:"POST",body:e,cache:!0})];case 4:return a=t.sent(),[2,a];case 5:return[3,7];case 6:throw u=t.sent();case 7:return[2]}})})},e.prototype.update=function(e){return void 0===e&&(e={}),t.__awaiter(this,void 0,void 0,function(){var r;return t.__generator(this,function(t){return r=_(this.constructor),[2,r.fetch(this.uri,{cache:!0,method:"PATCH",body:e})]})})},e.prototype.destroy=function(){return t.__awaiter(this,void 0,void 0,function(){var e,r,n,i;return t.__generator(this,function(t){switch(t.label){case 0:e=this.uri,r=_(this.constructor),n=r.cache,t.label=1;case 1:return t.trys.push([1,3,,4]),[4,r.fetch(e,{method:"DELETE"})];case 2:return t.sent(),n.get(e)&&n.remove(e),[3,4];case 3:throw i=t.sent();case 4:return[2]}})})},e}(),j=function(){function e(e,r,n,i){var o=e.potion,a=e.uri;this.items=r,this.options=i,this.potion=o,this.uri=a;var u=t.__assign({},this.options.params),s=u.page,c=void 0===s?1:s,f=u.perPage,h=void 0===f?25:f;this.$page=c,this.$perPage=h,this.$total=parseInt(n,10)}return Object.defineProperty(e,Symbol.species,{get:function(){return e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"page",{get:function(){return this.$page},set:function(e){this.changePageTo(e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"perPage",{get:function(){return this.$perPage},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"pages",{get:function(){return Math.ceil(this.$total/this.$perPage)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"total",{get:function(){return this.$total},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"length",{get:function(){return this.items.length},enumerable:!0,configurable:!0}),e.prototype[Symbol.iterator]=function(){return this.items.values()},e.prototype.toArray=function(){return this.items.slice(0)},e.prototype.at=function(e){return this.items[e]},e.prototype.changePageTo=function(e){var t=this.options.pagination;return this.options.params.page=e,this.$page=e,this.potion.fetch(this.uri,this.options,{pagination:t})},e.prototype.update=function(e,r){return(n=this.items).splice.apply(n,t.__spread([0,this.items.length],e)),this.$total=r,this;var n},e}(),T=function(){function e(e){this.$uri=e}return e.prototype.matches=function(e){return i(e)&&this.$uri===e.uri},e}(),A=function(){return function(e){this.getter=e}}(),x=new WeakSet,S=function(){function e(){this.items=new Map}return e.prototype.has=function(e){return this.items.has(e)},e.prototype.get=function(e){return this.items.get(e)},e.prototype.put=function(e,t){return this.items.set(e,t).get(e)},e.prototype.remove=function(e){this.items.delete(e)},e}(),E=("undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0).Reflect;!function(){if(!E||!E.getMetadata)throw new Error("Dependency error. reflect-metadata shim is required when using potion-node library")}();var I=Symbol("potion:instance"),R=Symbol("potion:uri"),U=Symbol("potion:promise"),M=Symbol("potion:readonly"),q=Symbol("potion:async"),N=function(){function e(e){var t=void 0===e?{}:e,r=t.host,n=void 0===r?"":r,i=t.prefix,o=void 0===i?"":i,a=t.cache;this.resources={},this.Promise=function(e){return E.getOwnMetadata(U,e.constructor)||Promise}(this),this.requests=new Map,this.cache=a||new S,this.host=n,this.prefix=o}return e.prototype.register=function(e,r,n){if(!a(r))throw new TypeError("An error occurred while trying to register a resource for "+e+". "+r+" is not a function.");if(function(e,t){E.defineMetadata(I,t,e)}(r,this),function(e,t){E.defineMetadata(R,t,e)}(r,e),n&&Array.isArray(n.readonly))try{for(var i=t.__values(n.readonly),o=i.next();!o.done;o=i.next())P(r,c=o.value)}catch(e){f={error:e}}finally{try{o&&!o.done&&(h=i.return)&&h.call(i)}finally{if(f)throw f.error}}if(n&&Array.isArray(n.async))try{for(var u=t.__values(n.async),s=u.next();!s.done;s=u.next()){var c=s.value;!function(e,r){var n=a(e)?e:a(e.constructor)?e.constructor:null;if(n){var i=E.getOwnMetadata(q,n);E.defineMetadata(q,t.__assign({},i,(o={},o[r]=!0,o)),n)}var o}(r,c)}}catch(e){p={error:e}}finally{try{s&&!s.done&&(d=u.return)&&d.call(u)}finally{if(p)throw p.error}}return this.resources[e]=r,r;var f,h,p,d},e.prototype.registerAs=function(e,t){var r=this;return function(n){return r.register(e,n,t),n}},e.prototype.resource=function(e){var t=d(e,this.resources);if(t)return t.resource},e.prototype.fetch=function(e,r,n){var i=g(e,this.prefix),o=t.__assign({},r,n,{origin:[]});return l(e,this.resources)&&Object.assign(o,{origin:[i]}),this.resolve(e,o).then(function(e){return s(e,c(e)),e})},e.prototype.resolve=function(e,t){var r=this,n=this.prefix,i=this.Promise,a=g(e,n);e=m(e,n);var u=function(){return r.request(""+r.host+e,r.serialize(t)).then(function(n){return r.deserialize(n,e,t)})};return"GET"!==t.method||t.paginate||t.params?u():t.cache&&this.cache.has(a)?this.cache.get(a):(this.requests.has(a)||this.requests.set(a,u().then(function(e){return r.requests.delete(a),e},function(t){r.requests.delete(a);var n=function(e,t){var r="An error occurred while Potion tried to retrieve a resource";return e instanceof Error?e.message:o(e)?e:o(t)?r+" from '"+t+"'.":r+"."}(t,e);return i.reject(n)})),this.requests.get(a))},e.prototype.serialize=function(e){var r=this.prefix,n=e.params;return t.__assign({},e,{params:f(e.paginate?t.__assign({page:1,perPage:25},n):n,r),body:f(e.body,r)})},e.prototype.deserialize=function(e,t,r){var n=this,i=e.headers,o=e.body;return this.fromPotionJSON(o,r.origin).then(function(e){if(r.paginate){var o=i["x-total-count"]||e.length;if(r.pagination instanceof j)return r.pagination.update(e,o);var a=new j({uri:t,potion:n},e,o,r);return Object.assign(r,{pagination:a}),a}return e})},e.prototype.fromPotionJSON=function(e,r,n){var i=this,a=void 0===n?{}:n,s=a.rootUri,c=a.key,f=a.replaceRefs,h=this.Promise;if("object"==typeof e&&null!==e){if(Array.isArray(e)){var p=this.resource(s),d=function(t){return h.all(e.map(function(e){return i.fromPotionJSON(e,r,{replaceRefs:t})}))};return p&&O(p,c)?h.resolve(new A(d)):d(!1)}if(o(e.$uri)||v(e))return this.parseURI(e).then(function(n){var o=n.resource,a=n.id,u=n.uri,s={$id:a,$uri:u};r.includes(u)||r.push(u);var c=i.parsePotionJSONProperties(e,r);return i.cache.has(u)?h.all([c,i.cache.get(u)]).then(function(e){var r=t.__read(e,2),n=r[0],i=r[1];return Object.assign(i,n,s),i}):i.cache.put(u,c.then(function(e){return Reflect.construct(o,[t.__assign({},e,s)])}))});if(o(e.$schema))return h.resolve(u(e));if(1===Object.keys(e).length){if(o(e.$ref))return"#"===e.$ref?h.resolve(e.$ref):this.parseURI(e).then(function(e){var t=e.uri;if(r.includes(t))return h.resolve(function(e){return new T(e)}(t));var n=i.resource(s),o=function(){return i.fetch(t,{cache:!0,method:"GET"},{origin:r})};return n&&O(n,c||t)?new A(o):f?o():i.resolve(t,{cache:!0,method:"GET",origin:r})});if(void 0!==e.$date)return h.resolve(new Date(e.$date))}return this.parsePotionJSONProperties(e,r)}return h.resolve(e)},e.prototype.parsePotionJSONProperties=function(e,r){var i=this,o=this.Promise,a=Object.entries(e),u=a.map(function(n){var o=t.__read(n,2),a=o[0],u=o[1];return i.fromPotionJSON(u,r,{key:a,rootUri:e.$uri})}),s=a.map(function(e){return n(t.__read(e,1)[0])});return o.all(u).then(function(e){return e.map(function(e,t){return[s[t],e]}).reduce(function(e,r){var n=t.__read(r,2),i=n[0],o=n[1];return t.__assign({},e,(a={},a[i]=o,a));var a},{})})},e.prototype.parseURI=function(e){var t=e.$ref,r=e.$uri,n=e.$type,i=e.$id,o=this.Promise,a=g(y({$ref:t,$uri:r,$type:n,$id:i}),this.prefix),u=d(a,this.resources);if(u){var s=u.resourceURI,c={resource:u.resource,uri:a,id:h(i)};return null===c.id&&Object.assign(c,{id:p(a,s)}),o.resolve(c)}return o.reject(new Error("URI '"+a+"' is an uninterpretable or unknown Potion resource."))},e}(),C={GET:function(e){return w(e,{method:"GET"})},DELETE:function(e){return w(e,{method:"DELETE"})},POST:function(e){return w(e,{method:"POST"})},PATCH:function(e){return w(e,{method:"PATCH"})},PUT:function(e){return w(e,{method:"PUT"})}},J=function(e){function r(r){return e.call(this,t.__assign({},r))||this}return t.__extends(r,e),r.prototype.request=function(e,r){var n=t.__assign({},r),i=n.method,o=void 0===i?"GET":i,a=n.params,u=n.body,s=n.cache,c=void 0===s||s,f=new Headers,h={method:o,cache:c?"default":"no-cache",credentials:"include"};if(u&&(f.set("Accept","application/json"),f.set("Content-Type","application/json"),h.body=JSON.stringify(u)),Object.assign(h,{headers:f}),a){var p=1,d=Object.entries(a),l=d.length;try{for(var v=t.__values(d),y=v.next();!y.done;y=v.next()){var g=t.__read(y.value,2),m=g[0],_=g[1];1===p&&(e+="?"),e+=m+"="+_,p<l&&(e+="&"),p++}}catch(e){b={error:e}}finally{try{y&&!y.done&&(P=v.return)&&P.call(v)}finally{if(b)throw b.error}}}return fetch(new Request(e,h),h).then(function(e){if(e.ok){var t={};return e.headers&&e.headers.forEach(function(e,r){t[r]=e}),e.json().then(function(e){return{headers:t,body:e}},function(e){return e})}var r=new Error(e.statusText);throw Object.assign(r,{response:e}),r});var b,P},r}(N);e.Potion=J,e.Item=$,e.readonly=P,e.Pagination=j,e.PotionBase=N,e.Route=C,e.route=w,e.findPotionResource=d,e.fromSchemaJSON=u,e.getPotionID=p,e.getPotionURI=y,e.hasTypeAndId=v,e.isPotionURI=l,e.parsePotionID=h,e.removePrefixFromURI=g,e.addPrefixToURI=m,e.toPotionJSON=f,e.toCamelCase=n,e.toSnakeCase=r,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("tslib")):"function"==typeof define&&define.amd?define(["exports","tslib"],t):t(e.potionClient={},e.tslib)}(this,function(e,t){"use strict";function r(e,t){return void 0===t&&(t="_"),e.replace(/\.?([A-Z0-9]+)/g,function(e,r){return""+t+r.toLowerCase()}).replace(/^_/,"")}function n(e){return e.replace(/_([a-z0-9])/g,function(e){return e[1].toUpperCase()})}function i(e){return"object"==typeof e&&null!==e}function o(e){return"string"==typeof e}function a(e){return"function"==typeof e}function u(e){return Array.isArray(e)?e.map(function(e){return"object"==typeof e?u(e):e}):i(e)?Object.entries(e).map(function(e){var r=t.__read(e,2),i=r[0],o=r[1];return[n(i),"object"==typeof o?u(o):o]}).reduce(function(e,r){var n=t.__read(r,2),i=n[0],o=n[1];return t.__assign({},e,(a={},a[i]=o,a));var a},{}):e}function s(e,r){if("object"!=typeof e||null===e||e.hasOwnProperty("$schema"))return e;if(S.has(e))return e;if(e instanceof T){var n=e.toArray().map(function(e){return s(e,r)});return e.update(n,e.total)}if(Array.isArray(e))return e.map(function(e){return s(e,r)});if(e instanceof A)return r.get(e.$uri);if(Object.keys(e).length>0){!Array.isArray(e)&&e.uri&&S.add(e);var a=function(t,n){if(n instanceof A){var a=r.get(n.$uri);Object.assign(e,(c={},c[t]=a,c))}else if(n instanceof x){var u;Object.defineProperty(e,t,{get:function(){return u||(u=n.getter(!0))}})}else i(n)?Object.assign(e,(f={},f[t]=s(n,r),f)):o(n)&&"#"===n&&Object.assign(e,(h={},h[t]=r.get("#"),h));var c,f,h};try{for(var u=t.__values(Object.entries(e)),c=u.next();!c.done;c=u.next()){var f=t.__read(c.value,2);a(f[0],f[1])}}catch(e){h={error:e}}finally{try{c&&!c.done&&(p=u.return)&&p.call(u)}finally{if(h)throw h.error}}return e}return e;var h,p}function c(e,r){var n=new Map;if(i(e)&&Object.keys(e).length>0){if(r||n.set("#",e),S.has(e)||e.hasOwnProperty("$schema"))return new Map;e.uri&&!n.has(e.uri)&&n.set(e.uri,e);var o=Array.isArray(e)||e instanceof T?e:Object.values(e);try{for(var a=t.__values(o),u=a.next();!u.done;u=a.next()){var s=c(u.value,!0);try{for(var f=t.__values(s.entries()),h=f.next();!h.done;h=f.next()){var p=t.__read(h.value,2),d=p[0],l=p[1];n.set(d,l)}}catch(e){g={error:e}}finally{try{h&&!h.done&&(m=f.return)&&m.call(f)}finally{if(g)throw g.error}}}}catch(e){v={error:e}}finally{try{u&&!u.done&&(y=a.return)&&y.call(a)}finally{if(v)throw v.error}}}return n;var v,y,g,m}function f(e,n){return i(e)?e instanceof j&&o(e.uri)?{$ref:""+m(e.uri,n)}:e instanceof Date?{$date:e.getTime()}:Array.isArray(e)?e.map(function(e){return f(e,n)}):function(e,r,n){return i(e)&&!Array.isArray(e)?Object.entries(e).map(function(e){var i=t.__read(e,2),o=i[0],u=i[1];return[a(r)?r(o):o,a(n)?n(u):u]}).reduce(function(e,r){var n=t.__read(r,2),i=n[0],o=n[1];return t.__assign({},e,(a={},a[i]=o,a));var a},{}):e}(e,function(e){return r(e)},function(e){return f(e,n)}):e}function h(e){return o(e)&&e.length>0?/^\d+$/.test(e)?parseInt(e,10):e:Number.isInteger(e)?e:null}function p(e,t){var r=e.indexOf(t+"/");if(-1!==r){return h(e.substring(r).split("/").pop())}return null}function d(e,r){if(o(e)){var n=Object.entries(r).sort(function(e,r){var n=t.__read(e,1)[0];return t.__read(r,1)[0].length-n.length}).find(function(r){var n=t.__read(r,1)[0];return 0===e.indexOf(n)});if(n){var i=t.__read(n,2);return{resourceURI:i[0],resource:i[1]}}}}function l(e,t){var r=d(e,t);return!!r&&null!==p(e,r.resourceURI)}function v(e){var t=e.$type,r=e.$id;return(o(r)||Number.isInteger(r))&&o(t)}function y(e){var t=e.$uri,r=e.$ref,n=e.$type,i=e.$id;return o(t)?decodeURIComponent(t):o(r)?decodeURIComponent(r):v({$type:n,$id:i})?"/"+n+"/"+i:""}function g(e,t){return e.includes(t)?e.substring(t.length):e}function m(e,t){return o(t)&&!e.includes(t)?""+t+e:e}function _(e){return I.getOwnMetadata(R,e)}function b(e){return I.getOwnMetadata(U,e)}function P(e,r){var n=a(e)?e:a(e.constructor)?e.constructor:null;if(n){var i=I.getOwnMetadata(q,n);I.defineMetadata(q,t.__assign({},i,(o={},o[r]=!0,o)),n)}var o}function O(e,t){var r=I.getOwnMetadata(N,e);if(i(r)&&o(t)){var n=Object.keys(r).find(function(e){return e===t||t.includes(e)});if(n)return r[n]}return!1}function w(e,r){var n=a(e)?e:a(e.constructor)?e.constructor:null;if(n){var i=I.getOwnMetadata(N,n);I.defineMetadata(N,t.__assign({},i,(o={},o[r]=!0,o)),n)}var o}function $(e,t){var r=(void 0===t?{}:t).method;return function(t,n){var i=void 0===n?{}:n,o=i.paginate,u=void 0!==o&&o,s=i.cache,c=void 0===s||s,f=a(this),h=""+(f?b(this):this.uri)+e,p={method:r,paginate:u,cache:c};return"GET"===r?p.params=t:["POST","PUT","PATCH"].includes(r)&&(p.body=t),_(f?this:this.constructor).fetch(h,p)}}var j=function(){function e(e){this.$id=null,i(e)&&Object.assign(this,e)}return e.fetch=function(e,t){var r=(void 0===t?{}:t).cache,n=void 0===r||r,i=b(this);return _(this).fetch(i+"/"+e,{method:"GET",cache:n})},e.query=function(e,t){var r=void 0===t?{}:t,n=r.paginate,i=void 0!==n&&n,o=r.cache,a=void 0===o||o,u=b(this);return _(this).fetch(u,{method:"GET",params:e,paginate:i,cache:a})},e.first=function(e){return t.__awaiter(this,void 0,void 0,function(){var r,n;return t.__generator(this,function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,this.query(e)];case 1:return r=t.sent(),[2,r[0]];case 2:throw n=t.sent();case 3:return[2]}})})},Object.defineProperty(e.prototype,"uri",{get:function(){return this.$uri},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"id",{get:function(){return this.$id},enumerable:!0,configurable:!0}),e.prototype.equals=function(t){return t instanceof e&&(this.id===t.id&&this.constructor.name===t.constructor.name)},e.prototype.toJSON=function(){var e=this;return Object.entries(this).filter(function(r){var n=t.__read(r,1)[0];return!n.startsWith("$")&&!function(e,t){var r=I.getOwnMetadata(q,e.constructor);return r&&r[t]}(e,n)&&!O(e.constructor,n)}).reduce(function(e,r){var n=t.__read(r,2),i=n[0],o=n[1];return t.__assign({},e,(a={},a[i]=o,a));var a},{})},e.prototype.save=function(){return t.__awaiter(this,void 0,void 0,function(){var e,r,n,i,o,a,u;return t.__generator(this,function(t){switch(t.label){case 0:e=this.toJSON(),t.label=1;case 1:return t.trys.push([1,6,,7]),this.uri||this.id?[4,this.update(e)]:[3,3];case 2:return r=t.sent(),[2,r];case 3:return n=this.constructor,i=_(n),o=b(n),[4,i.fetch(o,{method:"POST",body:e,cache:!0})];case 4:return a=t.sent(),[2,a];case 5:return[3,7];case 6:throw u=t.sent();case 7:return[2]}})})},e.prototype.update=function(e){return void 0===e&&(e={}),t.__awaiter(this,void 0,void 0,function(){var r;return t.__generator(this,function(t){return r=_(this.constructor),[2,r.fetch(this.uri,{cache:!0,method:"PATCH",body:e})]})})},e.prototype.destroy=function(){return t.__awaiter(this,void 0,void 0,function(){var e,r,n,i;return t.__generator(this,function(t){switch(t.label){case 0:e=this.uri,r=_(this.constructor),n=r.cache,t.label=1;case 1:return t.trys.push([1,3,,4]),[4,r.fetch(e,{method:"DELETE"})];case 2:return t.sent(),n.get(e)&&n.remove(e),[3,4];case 3:throw i=t.sent();case 4:return[2]}})})},e}(),T=function(){function e(e,r,n,i){var o=e.potion,a=e.uri;this.items=r,this.options=i,this.potion=o,this.uri=a;var u=t.__assign({},this.options.params),s=u.page,c=void 0===s?1:s,f=u.perPage,h=void 0===f?25:f;this.$page=c,this.$perPage=h,this.$total=parseInt(n,10)}return Object.defineProperty(e,Symbol.species,{get:function(){return e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"page",{get:function(){return this.$page},set:function(e){this.changePageTo(e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"perPage",{get:function(){return this.$perPage},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"pages",{get:function(){return Math.ceil(this.$total/this.$perPage)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"total",{get:function(){return this.$total},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"length",{get:function(){return this.items.length},enumerable:!0,configurable:!0}),e.prototype[Symbol.iterator]=function(){return this.items.values()},e.prototype.toArray=function(){return this.items.slice(0)},e.prototype.at=function(e){return this.items[e]},e.prototype.changePageTo=function(e){var t=this.options.pagination;return this.options.params.page=e,this.$page=e,this.potion.fetch(this.uri,this.options,{pagination:t})},e.prototype.update=function(e,r){return(n=this.items).splice.apply(n,t.__spread([0,this.items.length],e)),this.$total=r,this;var n},e}(),A=function(){function e(e){this.$uri=e}return e.prototype.matches=function(e){return i(e)&&this.$uri===e.uri},e}(),x=function(){return function(e){this.getter=e}}(),S=new WeakSet,E=function(){function e(){this.items=new Map}return e.prototype.has=function(e){return this.items.has(e)},e.prototype.get=function(e){return this.items.get(e)},e.prototype.put=function(e,t){return this.items.set(e,t).get(e)},e.prototype.remove=function(e){this.items.delete(e)},e}(),I=("undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0).Reflect;!function(){if(!I||!I.getMetadata)throw new Error("Dependency error. reflect-metadata shim is required when using potion-node library")}();var R=Symbol("potion:instance"),U=Symbol("potion:uri"),M=Symbol("potion:promise"),q=Symbol("potion:readonly"),N=Symbol("potion:async"),C=function(){function e(e){var t=void 0===e?{}:e,r=t.host,n=void 0===r?"":r,i=t.prefix,o=void 0===i?"":i,a=t.cache;this.resources={},this.Promise=function(e){return I.getOwnMetadata(M,e.constructor)||Promise}(this),this.requests=new Map,this.cache=a||new E,this.host=n,this.prefix=o}return e.prototype.register=function(e,r,n){if(!a(r))throw new TypeError("An error occurred while trying to register a resource for "+e+". "+r+" is not a function.");if(function(e,t){I.defineMetadata(R,t,e)}(r,this),function(e,t){I.defineMetadata(U,t,e)}(r,e),n&&Array.isArray(n.readonly))try{for(var i=t.__values(n.readonly),o=i.next();!o.done;o=i.next()){P(r,c=o.value)}}catch(e){f={error:e}}finally{try{o&&!o.done&&(h=i.return)&&h.call(i)}finally{if(f)throw f.error}}if(n&&Array.isArray(n.async))try{for(var u=t.__values(n.async),s=u.next();!s.done;s=u.next()){var c=s.value;w(r,c)}}catch(e){p={error:e}}finally{try{s&&!s.done&&(d=u.return)&&d.call(u)}finally{if(p)throw p.error}}return this.resources[e]=r,r;var f,h,p,d},e.prototype.registerAs=function(e,t){var r=this;return function(n){return r.register(e,n,t),n}},e.prototype.resource=function(e){var t=d(e,this.resources);if(t)return t.resource},e.prototype.fetch=function(e,r,n){var i=g(e,this.prefix),o=t.__assign({},r,n,{origin:[]});return l(e,this.resources)&&Object.assign(o,{origin:[i]}),this.resolve(e,o).then(function(e){return s(e,c(e)),e})},e.prototype.resolve=function(e,t){var r=this,n=this.prefix,i=this.Promise,a=g(e,n);e=m(e,n);var u=function(){return r.request(""+r.host+e,r.serialize(t)).then(function(n){return r.deserialize(n,e,t)})};return"GET"!==t.method||t.paginate||t.params?u():t.cache&&this.cache.has(a)?this.cache.get(a):(this.requests.has(a)||this.requests.set(a,u().then(function(e){return r.requests.delete(a),e},function(t){r.requests.delete(a);var n=function(e,t){var r="An error occurred while Potion tried to retrieve a resource";return e instanceof Error?e.message:o(e)?e:o(t)?r+" from '"+t+"'.":r+"."}(t,e);return i.reject(n)})),this.requests.get(a))},e.prototype.serialize=function(e){var r=this.prefix,n=e.params;return t.__assign({},e,{params:f(e.paginate?t.__assign({page:1,perPage:25},n):n,r),body:f(e.body,r)})},e.prototype.deserialize=function(e,t,r){var n=this,i=e.headers,o=e.body;return this.fromPotionJSON(o,r.origin).then(function(e){if(r.paginate){var o=i["x-total-count"]||e.length;if(r.pagination instanceof T)return r.pagination.update(e,o);var a=new T({uri:t,potion:n},e,o,r);return Object.assign(r,{pagination:a}),a}return e})},e.prototype.fromPotionJSON=function(e,r,n){var i=this,a=void 0===n?{}:n,s=a.rootUri,c=a.key,f=a.replaceRefs,h=this.Promise;if("object"==typeof e&&null!==e){if(Array.isArray(e)){var p=this.resource(s),d=function(t){return h.all(e.map(function(e){return i.fromPotionJSON(e,r,{replaceRefs:t})}))};return p&&O(p,c)?h.resolve(new x(d)):d(!1)}if(o(e.$uri)||v(e))return this.parseURI(e).then(function(n){var o=n.resource,a=n.id,u=n.uri,s={$id:a,$uri:u};r.includes(u)||r.push(u);var c=i.parsePotionJSONProperties(e,r);return i.cache.has(u)?h.all([c,i.cache.get(u)]).then(function(e){var r=t.__read(e,2),n=r[0],i=r[1];return Object.assign(i,n,s),i}):i.cache.put(u,c.then(function(e){return Reflect.construct(o,[t.__assign({},e,s)])}))});if(o(e.$schema))return h.resolve(u(e));if(1===Object.keys(e).length){if(o(e.$ref))return"#"===e.$ref?h.resolve(e.$ref):this.parseURI(e).then(function(e){var t=e.uri;if(r.includes(t))return h.resolve(function(e){return new A(e)}(t));var n=i.resource(s),o=function(){return i.fetch(t,{cache:!0,method:"GET"},{origin:r})};return n&&O(n,c||t)?new x(o):f?o():i.resolve(t,{cache:!0,method:"GET",origin:r})});if(void 0!==e.$date)return h.resolve(new Date(e.$date))}return this.parsePotionJSONProperties(e,r)}return h.resolve(e)},e.prototype.parsePotionJSONProperties=function(e,r){var i=this,o=this.Promise,a=Object.entries(e),u=a.map(function(n){var o=t.__read(n,2),a=o[0],u=o[1];return i.fromPotionJSON(u,r,{key:a,rootUri:e.$uri})}),s=a.map(function(e){return n(t.__read(e,1)[0])});return o.all(u).then(function(e){return e.map(function(e,t){return[s[t],e]}).reduce(function(e,r){var n=t.__read(r,2),i=n[0],o=n[1];return t.__assign({},e,(a={},a[i]=o,a));var a},{})})},e.prototype.parseURI=function(e){var t=e.$ref,r=e.$uri,n=e.$type,i=e.$id,o=this.Promise,a=g(y({$ref:t,$uri:r,$type:n,$id:i}),this.prefix),u=d(a,this.resources);if(u){var s=u.resourceURI,c={resource:u.resource,uri:a,id:h(i)};return null===c.id&&Object.assign(c,{id:p(a,s)}),o.resolve(c)}return o.reject(new Error("URI '"+a+"' is an uninterpretable or unknown Potion resource."))},e}(),J={GET:function(e){return $(e,{method:"GET"})},DELETE:function(e){return $(e,{method:"DELETE"})},POST:function(e){return $(e,{method:"POST"})},PATCH:function(e){return $(e,{method:"PATCH"})},PUT:function(e){return $(e,{method:"PUT"})}},k=function(e){function r(r){return e.call(this,t.__assign({},r))||this}return t.__extends(r,e),r.prototype.request=function(e,r){var n=t.__assign({},r),i=n.method,o=void 0===i?"GET":i,a=n.params,u=n.body,s=n.cache,c=void 0===s||s,f=new Headers,h={method:o,cache:c?"default":"no-cache",credentials:"include"};if(u&&(f.set("Accept","application/json"),f.set("Content-Type","application/json"),h.body=JSON.stringify(u)),Object.assign(h,{headers:f}),a){var p=1,d=Object.entries(a),l=d.length;try{for(var v=t.__values(d),y=v.next();!y.done;y=v.next()){var g=t.__read(y.value,2),m=g[0],_=g[1];1===p&&(e+="?"),e+=m+"="+_,p<l&&(e+="&"),p++}}catch(e){b={error:e}}finally{try{y&&!y.done&&(P=v.return)&&P.call(v)}finally{if(b)throw b.error}}}return fetch(new Request(e,h),h).then(function(e){if(e.ok){var t={};return e.headers&&e.headers.forEach(function(e,r){t[r]=e}),e.json().then(function(e){return{headers:t,body:e}},function(e){return e})}var r=new Error(e.statusText);throw Object.assign(r,{response:e}),r});var b,P},r}(C);e.Potion=k,e.Item=j,e.readonly=P,e.Pagination=T,e.PotionBase=C,e.Route=J,e.route=$,e.findPotionResource=d,e.fromSchemaJSON=u,e.getPotionID=p,e.getPotionURI=y,e.hasTypeAndId=v,e.isPotionURI=l,e.parsePotionID=h,e.removePrefixFromURI=g,e.addPrefixToURI=m,e.toPotionJSON=f,e.toCamelCase=n,e.toSnakeCase=r,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=fetch.umd.min.js.map |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("tslib"),require("@angular/core"),require("@angular/common/http"),require("rxjs/operators/filter"),require("rxjs/operators/map")):"function"==typeof define&&define.amd?define(["exports","tslib","@angular/core","@angular/common/http","rxjs/operators/filter","rxjs/operators/map"],t):t(e.potionClient={},e.tslib,e.ng.core,e.ng.common.http,e.Rx.operators,e.Rx.operators)}(this,function(e,t,r,n,o,i){"use strict";function a(e,t){return void 0===t&&(t="_"),e.replace(/\.?([A-Z0-9]+)/g,function(e,r){return""+t+r.toLowerCase()}).replace(/^_/,"")}function u(e){return e.replace(/_([a-z0-9])/g,function(e){return e[1].toUpperCase()})}function s(e){return"object"==typeof e&&null!==e}function c(e){return 0===Object.keys(e).length}function f(e){return"string"==typeof e}function p(e){return"function"==typeof e}function h(e){return Array.isArray(e)?e.map(function(e){return"object"==typeof e?h(e):e}):s(e)?Object.entries(e).map(function(e){var r=t.__read(e,2),n=r[0],o=r[1];return[u(n),"object"==typeof o?h(o):o]}).reduce(function(e,r){var n=t.__read(r,2),o=n[0],i=n[1];return t.__assign({},e,(a={},a[o]=i,a));var a},{}):e}function l(e,r){if("object"!=typeof e||null===e||e.hasOwnProperty("$schema"))return e;if(M.has(e))return e;if(e instanceof R){var n=e.toArray().map(function(e){return l(e,r)});return e.update(n,e.total)}if(Array.isArray(e))return e.map(function(e){return l(e,r)});if(e instanceof S)return r.get(e.$uri);if(Object.keys(e).length>0){!Array.isArray(e)&&e.uri&&M.add(e);try{for(var o=t.__values(Object.entries(e)),i=o.next();!i.done;i=o.next()){var a=t.__read(i.value,2);!function(t,n){if(n instanceof S){var o=r.get(n.$uri);Object.assign(e,(a={},a[t]=o,a))}else if(n instanceof E){var i;Object.defineProperty(e,t,{get:function(){return i||(i=n.getter(!0))}})}else s(n)?Object.assign(e,(u={},u[t]=l(n,r),u)):f(n)&&"#"===n&&Object.assign(e,(c={},c[t]=r.get("#"),c));var a,u,c}(a[0],a[1])}}catch(e){u={error:e}}finally{try{i&&!i.done&&(c=o.return)&&c.call(o)}finally{if(u)throw u.error}}return e}return e;var u,c}function d(e,r){var n=new Map;if(s(e)&&Object.keys(e).length>0){if(r||n.set("#",e),M.has(e)||e.hasOwnProperty("$schema"))return new Map;e.uri&&!n.has(e.uri)&&n.set(e.uri,e);var o=Array.isArray(e)||e instanceof R?e:Object.values(e);try{for(var i=t.__values(o),a=i.next();!a.done;a=i.next()){var u=d(a.value,!0);try{for(var c=t.__values(u.entries()),f=c.next();!f.done;f=c.next()){var p=t.__read(f.value,2),h=p[0],l=p[1];n.set(h,l)}}catch(e){g={error:e}}finally{try{f&&!f.done&&(m=c.return)&&m.call(c)}finally{if(g)throw g.error}}}}catch(e){y={error:e}}finally{try{a&&!a.done&&(v=i.return)&&v.call(i)}finally{if(y)throw y.error}}}return n;var y,v,g,m}function y(e,r){return s(e)?e instanceof D&&f(e.uri)?{$ref:""+w(e.uri,r)}:e instanceof Date?{$date:e.getTime()}:Array.isArray(e)?e.map(function(e){return y(e,r)}):function(e,r,n){return s(e)&&!Array.isArray(e)?Object.entries(e).map(function(e){var o=t.__read(e,2),i=o[0],a=o[1];return[p(r)?r(i):i,p(n)?n(a):a]}).reduce(function(e,r){var n=t.__read(r,2),o=n[0],i=n[1];return t.__assign({},e,(a={},a[o]=i,a));var a},{}):e}(e,function(e){return a(e)},function(e){return y(e,r)}):e}function v(e){return f(e)&&e.length>0?/^\d+$/.test(e)?parseInt(e,10):e:Number.isInteger(e)?e:null}function g(e,t){var r=e.indexOf(t+"/");return-1!==r?v(e.substring(r).split("/").pop()):null}function m(e,r){if(f(e)){var n=Object.entries(r).sort(function(e,r){var n=t.__read(e,1)[0];return t.__read(r,1)[0].length-n.length}).find(function(r){var n=t.__read(r,1)[0];return 0===e.indexOf(n)});if(n){var o=t.__read(n,2);return{resourceURI:o[0],resource:o[1]}}}}function _(e,t){var r=m(e,t);return!!r&&null!==g(e,r.resourceURI)}function b(e){var t=e.$type,r=e.$id;return(f(r)||Number.isInteger(r))&&f(t)}function O(e){var t=e.$uri,r=e.$ref,n=e.$type,o=e.$id;return f(t)?decodeURIComponent(t):f(r)?decodeURIComponent(r):b({$type:n,$id:o})?"/"+n+"/"+o:""}function P(e,t){return e.includes(t)?e.substring(t.length):e}function w(e,t){return f(t)&&!e.includes(t)?""+t+e:e}function j(e){return U.getOwnMetadata(q,e)}function $(e){return U.getOwnMetadata(C,e)}function T(e,r){var n=p(e)?e:p(e.constructor)?e.constructor:null;if(n){var o=U.getOwnMetadata(H,n);U.defineMetadata(H,t.__assign({},o,(i={},i[r]=!0,i)),n)}var i}function x(e,t){var r=U.getOwnMetadata(J,e);if(s(r)&&f(t)){var n=Object.keys(r).find(function(e){return e===t||t.includes(e)});if(n)return r[n]}return!1}function I(e,t){var r=(void 0===t?{}:t).method;return function(t,n){var o=void 0===n?{}:n,i=o.paginate,a=void 0!==i&&i,u=o.cache,s=void 0===u||u,c=p(this),f=""+(c?$(this):this.uri)+e,h={method:r,paginate:a,cache:s};return"GET"===r?h.params=t:["POST","PUT","PATCH"].includes(r)&&(h.body=t),j(c?this:this.constructor).fetch(f,h)}}function A(e,t,r){return e||new V(t,r)}var R=function(){function e(e,r,n,o){var i=e.potion,a=e.uri;this.items=r,this.options=o,this.potion=i,this.uri=a;var u=t.__assign({},this.options.params),s=u.page,c=void 0===s?1:s,f=u.perPage,p=void 0===f?25:f;this.$page=c,this.$perPage=p,this.$total=parseInt(n,10)}return Object.defineProperty(e,Symbol.species,{get:function(){return e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"page",{get:function(){return this.$page},set:function(e){this.changePageTo(e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"perPage",{get:function(){return this.$perPage},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"pages",{get:function(){return Math.ceil(this.$total/this.$perPage)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"total",{get:function(){return this.$total},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"length",{get:function(){return this.items.length},enumerable:!0,configurable:!0}),e.prototype[Symbol.iterator]=function(){return this.items.values()},e.prototype.toArray=function(){return this.items.slice(0)},e.prototype.at=function(e){return this.items[e]},e.prototype.changePageTo=function(e){var t=this.options.pagination;return this.options.params.page=e,this.$page=e,this.potion.fetch(this.uri,this.options,{pagination:t})},e.prototype.update=function(e,r){return(n=this.items).splice.apply(n,t.__spread([0,this.items.length],e)),this.$total=r,this;var n},e}(),S=function(){function e(e){this.$uri=e}return e.prototype.matches=function(e){return s(e)&&this.$uri===e.uri},e}(),E=function(){return function(e){this.getter=e}}(),M=new WeakSet,N=function(){function e(){this.items=new Map}return e.prototype.has=function(e){return this.items.has(e)},e.prototype.get=function(e){return this.items.get(e)},e.prototype.put=function(e,t){return this.items.set(e,t).get(e)},e.prototype.remove=function(e){this.items.delete(e)},e}(),U=("undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0).Reflect;!function(){if(!U||!U.getMetadata)throw new Error("Dependency error. reflect-metadata shim is required when using potion-node library")}();var q=Symbol("potion:instance"),C=Symbol("potion:uri"),k=Symbol("potion:promise"),H=Symbol("potion:readonly"),J=Symbol("potion:async"),D=function(){function e(e){this.$id=null,s(e)&&Object.assign(this,e)}return e.fetch=function(e,t){var r=(void 0===t?{}:t).cache,n=void 0===r||r,o=$(this);return j(this).fetch(o+"/"+e,{method:"GET",cache:n})},e.query=function(e,t){var r=void 0===t?{}:t,n=r.paginate,o=void 0!==n&&n,i=r.cache,a=void 0===i||i,u=$(this);return j(this).fetch(u,{method:"GET",params:e,paginate:o,cache:a})},e.first=function(e){return t.__awaiter(this,void 0,void 0,function(){var r,n;return t.__generator(this,function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,this.query(e)];case 1:return r=t.sent(),[2,r[0]];case 2:throw n=t.sent();case 3:return[2]}})})},Object.defineProperty(e.prototype,"uri",{get:function(){return this.$uri},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"id",{get:function(){return this.$id},enumerable:!0,configurable:!0}),e.prototype.equals=function(t){return t instanceof e&&(this.id===t.id&&this.constructor.name===t.constructor.name)},e.prototype.toJSON=function(){var e=this;return Object.entries(this).filter(function(r){var n=t.__read(r,1)[0];return!n.startsWith("$")&&!function(e,t){var r=U.getOwnMetadata(H,e.constructor);return r&&r[t]}(e,n)&&!x(e.constructor,n)}).reduce(function(e,r){var n=t.__read(r,2),o=n[0],i=n[1];return t.__assign({},e,(a={},a[o]=i,a));var a},{})},e.prototype.save=function(){return t.__awaiter(this,void 0,void 0,function(){var e,r,n,o,i,a,u;return t.__generator(this,function(t){switch(t.label){case 0:e=this.toJSON(),t.label=1;case 1:return t.trys.push([1,6,,7]),this.uri||this.id?[4,this.update(e)]:[3,3];case 2:return r=t.sent(),[2,r];case 3:return n=this.constructor,o=j(n),i=$(n),[4,o.fetch(i,{method:"POST",body:e,cache:!0})];case 4:return a=t.sent(),[2,a];case 5:return[3,7];case 6:throw u=t.sent();case 7:return[2]}})})},e.prototype.update=function(e){return void 0===e&&(e={}),t.__awaiter(this,void 0,void 0,function(){var r;return t.__generator(this,function(t){return r=j(this.constructor),[2,r.fetch(this.uri,{cache:!0,method:"PATCH",body:e})]})})},e.prototype.destroy=function(){return t.__awaiter(this,void 0,void 0,function(){var e,r,n,o;return t.__generator(this,function(t){switch(t.label){case 0:e=this.uri,r=j(this.constructor),n=r.cache,t.label=1;case 1:return t.trys.push([1,3,,4]),[4,r.fetch(e,{method:"DELETE"})];case 2:return t.sent(),n.get(e)&&n.remove(e),[3,4];case 3:throw o=t.sent();case 4:return[2]}})})},e}(),G=function(){function e(e){var t=void 0===e?{}:e,r=t.host,n=void 0===r?"":r,o=t.prefix,i=void 0===o?"":o,a=t.cache;this.resources={},this.Promise=function(e){return U.getOwnMetadata(k,e.constructor)||Promise}(this),this.requests=new Map,this.cache=a||new N,this.host=n,this.prefix=i}return e.prototype.register=function(e,r,n){if(!p(r))throw new TypeError("An error occurred while trying to register a resource for "+e+". "+r+" is not a function.");if(function(e,t){U.defineMetadata(q,t,e)}(r,this),function(e,t){U.defineMetadata(C,t,e)}(r,e),n&&Array.isArray(n.readonly))try{for(var o=t.__values(n.readonly),i=o.next();!i.done;i=o.next())T(r,s=i.value)}catch(e){c={error:e}}finally{try{i&&!i.done&&(f=o.return)&&f.call(o)}finally{if(c)throw c.error}}if(n&&Array.isArray(n.async))try{for(var a=t.__values(n.async),u=a.next();!u.done;u=a.next()){var s=u.value;!function(e,r){var n=p(e)?e:p(e.constructor)?e.constructor:null;if(n){var o=U.getOwnMetadata(J,n);U.defineMetadata(J,t.__assign({},o,(i={},i[r]=!0,i)),n)}var i}(r,s)}}catch(e){h={error:e}}finally{try{u&&!u.done&&(l=a.return)&&l.call(a)}finally{if(h)throw h.error}}return this.resources[e]=r,r;var c,f,h,l},e.prototype.registerAs=function(e,t){var r=this;return function(n){return r.register(e,n,t),n}},e.prototype.resource=function(e){var t=m(e,this.resources);if(t)return t.resource},e.prototype.fetch=function(e,r,n){var o=P(e,this.prefix),i=t.__assign({},r,n,{origin:[]});return _(e,this.resources)&&Object.assign(i,{origin:[o]}),this.resolve(e,i).then(function(e){return l(e,d(e)),e})},e.prototype.resolve=function(e,t){var r=this,n=this.prefix,o=this.Promise,i=P(e,n);e=w(e,n);var a=function(){return r.request(""+r.host+e,r.serialize(t)).then(function(n){return r.deserialize(n,e,t)})};return"GET"!==t.method||t.paginate||t.params?a():t.cache&&this.cache.has(i)?this.cache.get(i):(this.requests.has(i)||this.requests.set(i,a().then(function(e){return r.requests.delete(i),e},function(t){r.requests.delete(i);var n=function(e,t){var r="An error occurred while Potion tried to retrieve a resource";return e instanceof Error?e.message:f(e)?e:f(t)?r+" from '"+t+"'.":r+"."}(t,e);return o.reject(n)})),this.requests.get(i))},e.prototype.serialize=function(e){var r=this.prefix,n=e.params;return t.__assign({},e,{params:y(e.paginate?t.__assign({page:1,perPage:25},n):n,r),body:y(e.body,r)})},e.prototype.deserialize=function(e,t,r){var n=this,o=e.headers,i=e.body;return this.fromPotionJSON(i,r.origin).then(function(e){if(r.paginate){var i=o["x-total-count"]||e.length;if(r.pagination instanceof R)return r.pagination.update(e,i);var a=new R({uri:t,potion:n},e,i,r);return Object.assign(r,{pagination:a}),a}return e})},e.prototype.fromPotionJSON=function(e,r,n){var o=this,i=void 0===n?{}:n,a=i.rootUri,u=i.key,s=i.replaceRefs,c=this.Promise;if("object"==typeof e&&null!==e){if(Array.isArray(e)){var p=this.resource(a),l=function(t){return c.all(e.map(function(e){return o.fromPotionJSON(e,r,{replaceRefs:t})}))};return p&&x(p,u)?c.resolve(new E(l)):l(!1)}if(f(e.$uri)||b(e))return this.parseURI(e).then(function(n){var i=n.resource,a=n.id,u=n.uri,s={$id:a,$uri:u};r.includes(u)||r.push(u);var f=o.parsePotionJSONProperties(e,r);return o.cache.has(u)?c.all([f,o.cache.get(u)]).then(function(e){var r=t.__read(e,2),n=r[0],o=r[1];return Object.assign(o,n,s),o}):o.cache.put(u,f.then(function(e){return Reflect.construct(i,[t.__assign({},e,s)])}))});if(f(e.$schema))return c.resolve(h(e));if(1===Object.keys(e).length){if(f(e.$ref))return"#"===e.$ref?c.resolve(e.$ref):this.parseURI(e).then(function(e){var t=e.uri;if(r.includes(t))return c.resolve(function(e){return new S(e)}(t));var n=o.resource(a),i=function(){return o.fetch(t,{cache:!0,method:"GET"},{origin:r})};return n&&x(n,u||t)?new E(i):s?i():o.resolve(t,{cache:!0,method:"GET",origin:r})});if(void 0!==e.$date)return c.resolve(new Date(e.$date))}return this.parsePotionJSONProperties(e,r)}return c.resolve(e)},e.prototype.parsePotionJSONProperties=function(e,r){var n=this,o=this.Promise,i=Object.entries(e),a=i.map(function(o){var i=t.__read(o,2),a=i[0],u=i[1];return n.fromPotionJSON(u,r,{key:a,rootUri:e.$uri})}),s=i.map(function(e){return u(t.__read(e,1)[0])});return o.all(a).then(function(e){return e.map(function(e,t){return[s[t],e]}).reduce(function(e,r){var n=t.__read(r,2),o=n[0],i=n[1];return t.__assign({},e,(a={},a[o]=i,a));var a},{})})},e.prototype.parseURI=function(e){var t=e.$ref,r=e.$uri,n=e.$type,o=e.$id,i=this.Promise,a=P(O({$ref:t,$uri:r,$type:n,$id:o}),this.prefix),u=m(a,this.resources);if(u){var s=u.resourceURI,c={resource:u.resource,uri:a,id:v(o)};return null===c.id&&Object.assign(c,{id:g(a,s)}),i.resolve(c)}return i.reject(new Error("URI '"+a+"' is an uninterpretable or unknown Potion resource."))},e}(),F={GET:function(e){return I(e,{method:"GET"})},DELETE:function(e){return I(e,{method:"DELETE"})},POST:function(e){return I(e,{method:"POST"})},PATCH:function(e){return I(e,{method:"PATCH"})},PUT:function(e){return I(e,{method:"PUT"})}},z=new r.InjectionToken("PotionResources"),L=new r.InjectionToken("PotionConfig"),V=function(e){function a(r,n){var o=e.call(this,t.__assign({},n))||this;return o.http=r,o}return t.__extends(a,e),a.prototype.registerFromProvider=function(e){if(e=function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];var n={};try{for(var o=t.__values(e),i=o.next();!i.done;i=o.next()){var a=i.value;Object.assign(n,a)}}catch(e){u={error:e}}finally{try{i&&!i.done&&(s=o.return)&&s.call(o)}finally{if(u)throw u.error}}return n;var u,s}.apply(void 0,t.__spread(e.filter(function(e){return!c(e)}))),!c(e))try{for(var r=t.__values(Object.entries(e)),n=r.next();!n.done;n=r.next()){var o=t.__read(n.value,2),i=o[0],a=o[1];if(!this.resources.hasOwnProperty(i))if(Array.isArray(a)){var u=t.__read(a,2),s=u[0],f=u[1];this.register(i,s,f)}else this.register(i,a)}}catch(e){p={error:e}}finally{try{n&&!n.done&&(h=r.return)&&h.call(r)}finally{if(p)throw p.error}}var p,h},a.prototype.request=function(e,r){var a=t.__assign({},r),u=a.params,c=a.body,f=a.method,p=void 0===f?"GET":f,h={headers:new n.HttpHeaders({"content-type":"application/json"}),responseType:"json"};if(s(u)){var l=new n.HttpParams;try{for(var d=t.__values(Object.entries(u)),y=d.next();!y.done;y=d.next()){var v=t.__read(y.value,2),g=v[0],m=v[1];l=l.append(g,JSON.stringify(m))}}catch(e){b={error:e}}finally{try{y&&!y.done&&(O=d.return)&&O.call(d)}finally{if(b)throw b.error}}Object.assign(h,{params:l})}var _="POST"===p||"PUT"===p||"PATCH"===p?new n.HttpRequest(p,e,function(e){try{return JSON.stringify(e)}catch(e){return}}(c),h):new n.HttpRequest(p,e,h);return this.http.request(_).pipe(o.filter(function(e){return e instanceof n.HttpResponse}),i.map(function(e){var r=e.body,n={};try{for(var o=t.__values(e.headers.keys()),i=o.next();!i.done;i=o.next()){var a=i.value;n[a]=e.headers.get(a)}}catch(e){u={error:e}}finally{try{i&&!i.done&&(s=o.return)&&s.call(o)}finally{if(u)throw u.error}}return{headers:n,body:r};var u,s})).toPromise();var b,O},a.decorators=[{type:r.Injectable}],a.ctorParameters=function(){return[{type:n.HttpClient},{type:void 0,decorators:[{type:r.Optional},{type:r.Inject,args:[L]}]}]},a}(G),W={provide:V,useFactory:A,deps:[[new r.Optional,new r.SkipSelf,V],n.HttpClient,[new r.Optional,new r.Inject(L)]]},B=function(){function e(e,t){e.registerFromProvider(t||[])}return e.decorators=[{type:r.NgModule,args:[{imports:[n.HttpClientModule],providers:[W]}]}],e.ctorParameters=function(){return[{type:V,decorators:[{type:r.Inject,args:[r.forwardRef(function(){return V})]}]},{type:Array,decorators:[{type:r.Optional},{type:r.Inject,args:[z]}]}]},e}();e.Item=D,e.readonly=T,e.Pagination=R,e.PotionBase=G,e.Route=F,e.route=I,e.findPotionResource=m,e.fromSchemaJSON=h,e.getPotionID=g,e.getPotionURI=O,e.hasTypeAndId=b,e.isPotionURI=_,e.parsePotionID=v,e.removePrefixFromURI=P,e.addPrefixToURI=w,e.toPotionJSON=y,e.toCamelCase=u,e.toSnakeCase=a,e.PotionModule=B,e.POTION_RESOURCES=z,e.POTION_CONFIG=L,e.Potion=V,e.POTION_PROVIDER_FACTORY=A,e.POTION_PROVIDER=W,e.ɵa=f,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("tslib"),require("@angular/core"),require("@angular/common/http"),require("rxjs/operators/filter"),require("rxjs/operators/map")):"function"==typeof define&&define.amd?define(["exports","tslib","@angular/core","@angular/common/http","rxjs/operators/filter","rxjs/operators/map"],t):t(e.potionClient={},e.tslib,e.ng.core,e.ng.common.http,e.Rx.operators,e.Rx.operators)}(this,function(e,t,r,n,i,o){"use strict";function a(e,t){return void 0===t&&(t="_"),e.replace(/\.?([A-Z0-9]+)/g,function(e,r){return""+t+r.toLowerCase()}).replace(/^_/,"")}function u(e){return e.replace(/_([a-z0-9])/g,function(e){return e[1].toUpperCase()})}function s(e){return"object"==typeof e&&null!==e}function c(e){return 0===Object.keys(e).length}function f(e){return"string"==typeof e}function p(e){return"function"==typeof e}function h(e){return Array.isArray(e)?e.map(function(e){return"object"==typeof e?h(e):e}):s(e)?Object.entries(e).map(function(e){var r=t.__read(e,2),n=r[0],i=r[1];return[u(n),"object"==typeof i?h(i):i]}).reduce(function(e,r){var n=t.__read(r,2),i=n[0],o=n[1];return t.__assign({},e,(a={},a[i]=o,a));var a},{}):e}function l(e,r){if("object"!=typeof e||null===e||e.hasOwnProperty("$schema"))return e;if(N.has(e))return e;if(e instanceof S){var n=e.toArray().map(function(e){return l(e,r)});return e.update(n,e.total)}if(Array.isArray(e))return e.map(function(e){return l(e,r)});if(e instanceof E)return r.get(e.$uri);if(Object.keys(e).length>0){!Array.isArray(e)&&e.uri&&N.add(e);var i=function(t,n){if(n instanceof E){var i=r.get(n.$uri);Object.assign(e,(a={},a[t]=i,a))}else if(n instanceof M){var o;Object.defineProperty(e,t,{get:function(){return o||(o=n.getter(!0))}})}else s(n)?Object.assign(e,(u={},u[t]=l(n,r),u)):f(n)&&"#"===n&&Object.assign(e,(c={},c[t]=r.get("#"),c));var a,u,c};try{for(var o=t.__values(Object.entries(e)),a=o.next();!a.done;a=o.next()){var u=t.__read(a.value,2);i(u[0],u[1])}}catch(e){c={error:e}}finally{try{a&&!a.done&&(p=o.return)&&p.call(o)}finally{if(c)throw c.error}}return e}return e;var c,p}function d(e,r){var n=new Map;if(s(e)&&Object.keys(e).length>0){if(r||n.set("#",e),N.has(e)||e.hasOwnProperty("$schema"))return new Map;e.uri&&!n.has(e.uri)&&n.set(e.uri,e);var i=Array.isArray(e)||e instanceof S?e:Object.values(e);try{for(var o=t.__values(i),a=o.next();!a.done;a=o.next()){var u=d(a.value,!0);try{for(var c=t.__values(u.entries()),f=c.next();!f.done;f=c.next()){var p=t.__read(f.value,2),h=p[0],l=p[1];n.set(h,l)}}catch(e){g={error:e}}finally{try{f&&!f.done&&(m=c.return)&&m.call(c)}finally{if(g)throw g.error}}}}catch(e){y={error:e}}finally{try{a&&!a.done&&(v=o.return)&&v.call(o)}finally{if(y)throw y.error}}}return n;var y,v,g,m}function y(e,r){return s(e)?e instanceof G&&f(e.uri)?{$ref:""+w(e.uri,r)}:e instanceof Date?{$date:e.getTime()}:Array.isArray(e)?e.map(function(e){return y(e,r)}):function(e,r,n){return s(e)&&!Array.isArray(e)?Object.entries(e).map(function(e){var i=t.__read(e,2),o=i[0],a=i[1];return[p(r)?r(o):o,p(n)?n(a):a]}).reduce(function(e,r){var n=t.__read(r,2),i=n[0],o=n[1];return t.__assign({},e,(a={},a[i]=o,a));var a},{}):e}(e,function(e){return a(e)},function(e){return y(e,r)}):e}function v(e){return f(e)&&e.length>0?/^\d+$/.test(e)?parseInt(e,10):e:Number.isInteger(e)?e:null}function g(e,t){var r=e.indexOf(t+"/");if(-1!==r){return v(e.substring(r).split("/").pop())}return null}function m(e,r){if(f(e)){var n=Object.entries(r).sort(function(e,r){var n=t.__read(e,1)[0];return t.__read(r,1)[0].length-n.length}).find(function(r){var n=t.__read(r,1)[0];return 0===e.indexOf(n)});if(n){var i=t.__read(n,2);return{resourceURI:i[0],resource:i[1]}}}}function _(e,t){var r=m(e,t);return!!r&&null!==g(e,r.resourceURI)}function b(e){var t=e.$type,r=e.$id;return(f(r)||Number.isInteger(r))&&f(t)}function O(e){var t=e.$uri,r=e.$ref,n=e.$type,i=e.$id;return f(t)?decodeURIComponent(t):f(r)?decodeURIComponent(r):b({$type:n,$id:i})?"/"+n+"/"+i:""}function P(e,t){return e.includes(t)?e.substring(t.length):e}function w(e,t){return f(t)&&!e.includes(t)?""+t+e:e}function j(e){return q.getOwnMetadata(C,e)}function $(e){return q.getOwnMetadata(k,e)}function T(e,r){var n=p(e)?e:p(e.constructor)?e.constructor:null;if(n){var i=q.getOwnMetadata(J,n);q.defineMetadata(J,t.__assign({},i,(o={},o[r]=!0,o)),n)}var o}function x(e,t){var r=q.getOwnMetadata(D,e);if(s(r)&&f(t)){var n=Object.keys(r).find(function(e){return e===t||t.includes(e)});if(n)return r[n]}return!1}function I(e,r){var n=p(e)?e:p(e.constructor)?e.constructor:null;if(n){var i=q.getOwnMetadata(D,n);q.defineMetadata(D,t.__assign({},i,(o={},o[r]=!0,o)),n)}var o}function A(e,t){var r=(void 0===t?{}:t).method;return function(t,n){var i=void 0===n?{}:n,o=i.paginate,a=void 0!==o&&o,u=i.cache,s=void 0===u||u,c=p(this),f=""+(c?$(this):this.uri)+e,h={method:r,paginate:a,cache:s};return"GET"===r?h.params=t:["POST","PUT","PATCH"].includes(r)&&(h.body=t),j(c?this:this.constructor).fetch(f,h)}}function R(e,t,r){return e||new W(t,r)}var S=function(){function e(e,r,n,i){var o=e.potion,a=e.uri;this.items=r,this.options=i,this.potion=o,this.uri=a;var u=t.__assign({},this.options.params),s=u.page,c=void 0===s?1:s,f=u.perPage,p=void 0===f?25:f;this.$page=c,this.$perPage=p,this.$total=parseInt(n,10)}return Object.defineProperty(e,Symbol.species,{get:function(){return e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"page",{get:function(){return this.$page},set:function(e){this.changePageTo(e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"perPage",{get:function(){return this.$perPage},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"pages",{get:function(){return Math.ceil(this.$total/this.$perPage)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"total",{get:function(){return this.$total},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"length",{get:function(){return this.items.length},enumerable:!0,configurable:!0}),e.prototype[Symbol.iterator]=function(){return this.items.values()},e.prototype.toArray=function(){return this.items.slice(0)},e.prototype.at=function(e){return this.items[e]},e.prototype.changePageTo=function(e){var t=this.options.pagination;return this.options.params.page=e,this.$page=e,this.potion.fetch(this.uri,this.options,{pagination:t})},e.prototype.update=function(e,r){return(n=this.items).splice.apply(n,t.__spread([0,this.items.length],e)),this.$total=r,this;var n},e}(),E=function(){function e(e){this.$uri=e}return e.prototype.matches=function(e){return s(e)&&this.$uri===e.uri},e}(),M=function(){return function(e){this.getter=e}}(),N=new WeakSet,U=function(){function e(){this.items=new Map}return e.prototype.has=function(e){return this.items.has(e)},e.prototype.get=function(e){return this.items.get(e)},e.prototype.put=function(e,t){return this.items.set(e,t).get(e)},e.prototype.remove=function(e){this.items.delete(e)},e}(),q=("undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0).Reflect;!function(){if(!q||!q.getMetadata)throw new Error("Dependency error. reflect-metadata shim is required when using potion-node library")}();var C=Symbol("potion:instance"),k=Symbol("potion:uri"),H=Symbol("potion:promise"),J=Symbol("potion:readonly"),D=Symbol("potion:async"),G=function(){function e(e){this.$id=null,s(e)&&Object.assign(this,e)}return e.fetch=function(e,t){var r=(void 0===t?{}:t).cache,n=void 0===r||r,i=$(this);return j(this).fetch(i+"/"+e,{method:"GET",cache:n})},e.query=function(e,t){var r=void 0===t?{}:t,n=r.paginate,i=void 0!==n&&n,o=r.cache,a=void 0===o||o,u=$(this);return j(this).fetch(u,{method:"GET",params:e,paginate:i,cache:a})},e.first=function(e){return t.__awaiter(this,void 0,void 0,function(){var r,n;return t.__generator(this,function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,this.query(e)];case 1:return r=t.sent(),[2,r[0]];case 2:throw n=t.sent();case 3:return[2]}})})},Object.defineProperty(e.prototype,"uri",{get:function(){return this.$uri},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"id",{get:function(){return this.$id},enumerable:!0,configurable:!0}),e.prototype.equals=function(t){return t instanceof e&&(this.id===t.id&&this.constructor.name===t.constructor.name)},e.prototype.toJSON=function(){var e=this;return Object.entries(this).filter(function(r){var n=t.__read(r,1)[0];return!n.startsWith("$")&&!function(e,t){var r=q.getOwnMetadata(J,e.constructor);return r&&r[t]}(e,n)&&!x(e.constructor,n)}).reduce(function(e,r){var n=t.__read(r,2),i=n[0],o=n[1];return t.__assign({},e,(a={},a[i]=o,a));var a},{})},e.prototype.save=function(){return t.__awaiter(this,void 0,void 0,function(){var e,r,n,i,o,a,u;return t.__generator(this,function(t){switch(t.label){case 0:e=this.toJSON(),t.label=1;case 1:return t.trys.push([1,6,,7]),this.uri||this.id?[4,this.update(e)]:[3,3];case 2:return r=t.sent(),[2,r];case 3:return n=this.constructor,i=j(n),o=$(n),[4,i.fetch(o,{method:"POST",body:e,cache:!0})];case 4:return a=t.sent(),[2,a];case 5:return[3,7];case 6:throw u=t.sent();case 7:return[2]}})})},e.prototype.update=function(e){return void 0===e&&(e={}),t.__awaiter(this,void 0,void 0,function(){var r;return t.__generator(this,function(t){return r=j(this.constructor),[2,r.fetch(this.uri,{cache:!0,method:"PATCH",body:e})]})})},e.prototype.destroy=function(){return t.__awaiter(this,void 0,void 0,function(){var e,r,n,i;return t.__generator(this,function(t){switch(t.label){case 0:e=this.uri,r=j(this.constructor),n=r.cache,t.label=1;case 1:return t.trys.push([1,3,,4]),[4,r.fetch(e,{method:"DELETE"})];case 2:return t.sent(),n.get(e)&&n.remove(e),[3,4];case 3:throw i=t.sent();case 4:return[2]}})})},e}(),F=function(){function e(e){var t=void 0===e?{}:e,r=t.host,n=void 0===r?"":r,i=t.prefix,o=void 0===i?"":i,a=t.cache;this.resources={},this.Promise=function(e){return q.getOwnMetadata(H,e.constructor)||Promise}(this),this.requests=new Map,this.cache=a||new U,this.host=n,this.prefix=o}return e.prototype.register=function(e,r,n){if(!p(r))throw new TypeError("An error occurred while trying to register a resource for "+e+". "+r+" is not a function.");if(function(e,t){q.defineMetadata(C,t,e)}(r,this),function(e,t){q.defineMetadata(k,t,e)}(r,e),n&&Array.isArray(n.readonly))try{for(var i=t.__values(n.readonly),o=i.next();!o.done;o=i.next()){T(r,s=o.value)}}catch(e){c={error:e}}finally{try{o&&!o.done&&(f=i.return)&&f.call(i)}finally{if(c)throw c.error}}if(n&&Array.isArray(n.async))try{for(var a=t.__values(n.async),u=a.next();!u.done;u=a.next()){var s=u.value;I(r,s)}}catch(e){h={error:e}}finally{try{u&&!u.done&&(l=a.return)&&l.call(a)}finally{if(h)throw h.error}}return this.resources[e]=r,r;var c,f,h,l},e.prototype.registerAs=function(e,t){var r=this;return function(n){return r.register(e,n,t),n}},e.prototype.resource=function(e){var t=m(e,this.resources);if(t)return t.resource},e.prototype.fetch=function(e,r,n){var i=P(e,this.prefix),o=t.__assign({},r,n,{origin:[]});return _(e,this.resources)&&Object.assign(o,{origin:[i]}),this.resolve(e,o).then(function(e){return l(e,d(e)),e})},e.prototype.resolve=function(e,t){var r=this,n=this.prefix,i=this.Promise,o=P(e,n);e=w(e,n);var a=function(){return r.request(""+r.host+e,r.serialize(t)).then(function(n){return r.deserialize(n,e,t)})};return"GET"!==t.method||t.paginate||t.params?a():t.cache&&this.cache.has(o)?this.cache.get(o):(this.requests.has(o)||this.requests.set(o,a().then(function(e){return r.requests.delete(o),e},function(t){r.requests.delete(o);var n=function(e,t){var r="An error occurred while Potion tried to retrieve a resource";return e instanceof Error?e.message:f(e)?e:f(t)?r+" from '"+t+"'.":r+"."}(t,e);return i.reject(n)})),this.requests.get(o))},e.prototype.serialize=function(e){var r=this.prefix,n=e.params;return t.__assign({},e,{params:y(e.paginate?t.__assign({page:1,perPage:25},n):n,r),body:y(e.body,r)})},e.prototype.deserialize=function(e,t,r){var n=this,i=e.headers,o=e.body;return this.fromPotionJSON(o,r.origin).then(function(e){if(r.paginate){var o=i["x-total-count"]||e.length;if(r.pagination instanceof S)return r.pagination.update(e,o);var a=new S({uri:t,potion:n},e,o,r);return Object.assign(r,{pagination:a}),a}return e})},e.prototype.fromPotionJSON=function(e,r,n){var i=this,o=void 0===n?{}:n,a=o.rootUri,u=o.key,s=o.replaceRefs,c=this.Promise;if("object"==typeof e&&null!==e){if(Array.isArray(e)){var p=this.resource(a),l=function(t){return c.all(e.map(function(e){return i.fromPotionJSON(e,r,{replaceRefs:t})}))};return p&&x(p,u)?c.resolve(new M(l)):l(!1)}if(f(e.$uri)||b(e))return this.parseURI(e).then(function(n){var o=n.resource,a=n.id,u=n.uri,s={$id:a,$uri:u};r.includes(u)||r.push(u);var f=i.parsePotionJSONProperties(e,r);return i.cache.has(u)?c.all([f,i.cache.get(u)]).then(function(e){var r=t.__read(e,2),n=r[0],i=r[1];return Object.assign(i,n,s),i}):i.cache.put(u,f.then(function(e){return Reflect.construct(o,[t.__assign({},e,s)])}))});if(f(e.$schema))return c.resolve(h(e));if(1===Object.keys(e).length){if(f(e.$ref))return"#"===e.$ref?c.resolve(e.$ref):this.parseURI(e).then(function(e){var t=e.uri;if(r.includes(t))return c.resolve(function(e){return new E(e)}(t));var n=i.resource(a),o=function(){return i.fetch(t,{cache:!0,method:"GET"},{origin:r})};return n&&x(n,u||t)?new M(o):s?o():i.resolve(t,{cache:!0,method:"GET",origin:r})});if(void 0!==e.$date)return c.resolve(new Date(e.$date))}return this.parsePotionJSONProperties(e,r)}return c.resolve(e)},e.prototype.parsePotionJSONProperties=function(e,r){var n=this,i=this.Promise,o=Object.entries(e),a=o.map(function(i){var o=t.__read(i,2),a=o[0],u=o[1];return n.fromPotionJSON(u,r,{key:a,rootUri:e.$uri})}),s=o.map(function(e){return u(t.__read(e,1)[0])});return i.all(a).then(function(e){return e.map(function(e,t){return[s[t],e]}).reduce(function(e,r){var n=t.__read(r,2),i=n[0],o=n[1];return t.__assign({},e,(a={},a[i]=o,a));var a},{})})},e.prototype.parseURI=function(e){var t=e.$ref,r=e.$uri,n=e.$type,i=e.$id,o=this.Promise,a=P(O({$ref:t,$uri:r,$type:n,$id:i}),this.prefix),u=m(a,this.resources);if(u){var s=u.resourceURI,c={resource:u.resource,uri:a,id:v(i)};return null===c.id&&Object.assign(c,{id:g(a,s)}),o.resolve(c)}return o.reject(new Error("URI '"+a+"' is an uninterpretable or unknown Potion resource."))},e}(),z={GET:function(e){return A(e,{method:"GET"})},DELETE:function(e){return A(e,{method:"DELETE"})},POST:function(e){return A(e,{method:"POST"})},PATCH:function(e){return A(e,{method:"PATCH"})},PUT:function(e){return A(e,{method:"PUT"})}},L=new r.InjectionToken("PotionResources"),V=new r.InjectionToken("PotionConfig"),W=function(e){function a(r,n){var i=e.call(this,t.__assign({},n))||this;return i.http=r,i}return t.__extends(a,e),a.prototype.registerFromProvider=function(e){if(e=function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];var n={};try{for(var i=t.__values(e),o=i.next();!o.done;o=i.next()){var a=o.value;Object.assign(n,a)}}catch(e){u={error:e}}finally{try{o&&!o.done&&(s=i.return)&&s.call(i)}finally{if(u)throw u.error}}return n;var u,s}.apply(void 0,t.__spread(e.filter(function(e){return!c(e)}))),!c(e))try{for(var r=t.__values(Object.entries(e)),n=r.next();!n.done;n=r.next()){var i=t.__read(n.value,2),o=i[0],a=i[1];if(!this.resources.hasOwnProperty(o))if(Array.isArray(a)){var u=t.__read(a,2),s=u[0],f=u[1];this.register(o,s,f)}else this.register(o,a)}}catch(e){p={error:e}}finally{try{n&&!n.done&&(h=r.return)&&h.call(r)}finally{if(p)throw p.error}}var p,h},a.prototype.request=function(e,r){var a=t.__assign({},r),u=a.params,c=a.body,f=a.method,p=void 0===f?"GET":f,h={headers:new n.HttpHeaders({"content-type":"application/json"}),responseType:"json"};if(s(u)){var l=new n.HttpParams;try{for(var d=t.__values(Object.entries(u)),y=d.next();!y.done;y=d.next()){var v=t.__read(y.value,2),g=v[0],m=v[1];l=l.append(g,JSON.stringify(m))}}catch(e){b={error:e}}finally{try{y&&!y.done&&(O=d.return)&&O.call(d)}finally{if(b)throw b.error}}Object.assign(h,{params:l})}var _="POST"===p||"PUT"===p||"PATCH"===p?new n.HttpRequest(p,e,function(e){try{return JSON.stringify(e)}catch(e){return}}(c),h):new n.HttpRequest(p,e,h);return this.http.request(_).pipe(i.filter(function(e){return e instanceof n.HttpResponse}),o.map(function(e){var r=e.body,n={};try{for(var i=t.__values(e.headers.keys()),o=i.next();!o.done;o=i.next()){var a=o.value;n[a]=e.headers.get(a)}}catch(e){u={error:e}}finally{try{o&&!o.done&&(s=i.return)&&s.call(i)}finally{if(u)throw u.error}}return{headers:n,body:r};var u,s})).toPromise();var b,O},a.decorators=[{type:r.Injectable}],a.ctorParameters=function(){return[{type:n.HttpClient},{type:void 0,decorators:[{type:r.Optional},{type:r.Inject,args:[V]}]}]},a}(F),B={provide:W,useFactory:R,deps:[[new r.Optional,new r.SkipSelf,W],n.HttpClient,[new r.Optional,new r.Inject(V)]]},Y=function(){function e(e,t){e.registerFromProvider(t||[])}return e.decorators=[{type:r.NgModule,args:[{imports:[n.HttpClientModule],providers:[B]}]}],e.ctorParameters=function(){return[{type:W,decorators:[{type:r.Inject,args:[r.forwardRef(function(){return W})]}]},{type:Array,decorators:[{type:r.Optional},{type:r.Inject,args:[L]}]}]},e}();e.Item=G,e.readonly=T,e.Pagination=S,e.PotionBase=F,e.Route=z,e.route=A,e.findPotionResource=m,e.fromSchemaJSON=h,e.getPotionID=g,e.getPotionURI=O,e.hasTypeAndId=b,e.isPotionURI=_,e.parsePotionID=v,e.removePrefixFromURI=P,e.addPrefixToURI=w,e.toPotionJSON=y,e.toCamelCase=u,e.toSnakeCase=a,e.PotionModule=Y,e.POTION_RESOURCES=L,e.POTION_CONFIG=V,e.Potion=W,e.POTION_PROVIDER_FACTORY=R,e.POTION_PROVIDER=B,e.ɵa=f,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=ng.umd.min.js.map |
{ | ||
"name": "potion-client", | ||
"version": "4.0.0-2", | ||
"version": "4.0.0-3", | ||
"description": "A ES6 client for APIs written in Flask-Potion", | ||
@@ -12,7 +12,7 @@ "keywords": [ | ||
], | ||
"homepage": "", | ||
"homepage": "http://potion.readthedocs.io", | ||
"license": "MIT", | ||
"author": { | ||
"name": "Roland Groza", | ||
"email": "rolandjitsu@gmail.com " | ||
"email": "rolandjitsu@gmail.com" | ||
}, | ||
@@ -51,14 +51,14 @@ "main": "./ng.umd.js", | ||
"devDependencies": { | ||
"@angular/common": "^5.0.0", | ||
"@angular/compiler": "^5.0.0", | ||
"@angular/compiler-cli": "^5.0.0", | ||
"@angular/core": "^5.0.0", | ||
"@angular/platform-browser": "^5.0.0", | ||
"@angular/platform-browser-dynamic": "^5.0.0", | ||
"@types/angular": "^1.6.38", | ||
"@angular/common": "^5.0.2", | ||
"@angular/compiler": "^5.0.2", | ||
"@angular/compiler-cli": "^5.0.2", | ||
"@angular/core": "^5.0.2", | ||
"@angular/platform-browser": "^5.0.2", | ||
"@angular/platform-browser-dynamic": "^5.0.2", | ||
"@types/angular": "^1.6.39", | ||
"@types/angular-mocks": "^1.5.11", | ||
"@types/fetch-mock": "^5.12.2", | ||
"@types/jasmine": "^2.6.2", | ||
"@types/jasmine": "^2.8.2", | ||
"@types/jquery": "^3.2.16", | ||
"@types/node": "^8.0.47", | ||
"@types/node": "^8.0.53", | ||
"@types/reflect-metadata": "^0.0.5", | ||
@@ -68,3 +68,3 @@ "angular": "^1.6.6", | ||
"camelcase": "^4.1.0", | ||
"conventional-changelog-cli": "^1.3.4", | ||
"conventional-changelog-cli": "^1.3.5", | ||
"core-js": "^2.5.1", | ||
@@ -80,3 +80,3 @@ "fetch-mock": "^5.13.1", | ||
"karma-typescript": "^3.0.8", | ||
"rollup": "^0.50.0", | ||
"rollup": "^0.51.7", | ||
"rollup-plugin-sourcemaps": "^0.4.2", | ||
@@ -83,0 +83,0 @@ "rollup-plugin-uglify": "^2.0.1", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
4
1433855
13854