potion-client
Advanced tools
Comparing version 3.0.1 to 3.0.2
@@ -380,3 +380,3 @@ import { __assign, __extends, __read, __spread, __values } from 'tslib'; | ||
function replaceSelfReferences(json, roots) { | ||
if (typeof json !== 'object' || json === null) { | ||
if (typeof json !== 'object' || json === null || json.hasOwnProperty('$schema')) { | ||
return json; | ||
@@ -452,3 +452,3 @@ } | ||
} | ||
if (set.has(json)) { | ||
if (set.has(json) || json.hasOwnProperty('$schema')) { | ||
// If we find the root in the set it means there is no need to continue. | ||
@@ -455,0 +455,0 @@ return new Map(); |
@@ -322,3 +322,3 @@ import { module as module$1 } from 'angular'; | ||
function replaceSelfReferences(json, roots) { | ||
if (typeof json !== 'object' || json === null) { | ||
if (typeof json !== 'object' || json === null || json.hasOwnProperty('$schema')) { | ||
return json; | ||
@@ -383,3 +383,3 @@ } | ||
} | ||
if (set.has(json)) { | ||
if (set.has(json) || json.hasOwnProperty('$schema')) { | ||
// If we find the root in the set it means there is no need to continue. | ||
@@ -386,0 +386,0 @@ return new Map(); |
@@ -381,3 +381,3 @@ (function (global, factory) { | ||
function replaceSelfReferences(json, roots) { | ||
if (typeof json !== 'object' || json === null) { | ||
if (typeof json !== 'object' || json === null || json.hasOwnProperty('$schema')) { | ||
return json; | ||
@@ -453,3 +453,3 @@ } | ||
} | ||
if (set.has(json)) { | ||
if (set.has(json) || json.hasOwnProperty('$schema')) { | ||
// If we find the root in the set it means there is no need to continue. | ||
@@ -456,0 +456,0 @@ return new Map(); |
@@ -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 u(t){return"function"==typeof t}function a(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,(u={},u[i]=o,u));var u},{}):t}function s(t,e){var r="An error occurred while Potion tried to retrieve a resource";return t instanceof Error?t.message:"string"==typeof t?t:"string"==typeof e?r+" from '"+e+"'.":r+"."}function c(t){return Array.isArray(t)?t.map(function(t){return"object"==typeof t?c(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?c(o):o]}).reduce(function(t,r){var n=e.__read(r,2),i=n[0],o=n[1];return e.__assign({},t,(u={},u[i]=o,u));var u},{}):t}function f(t,r){if("object"!=typeof t||null===t)return t;if(M.has(t))return t;if(t instanceof R){var n=t.toArray().map(function(t){return f(t,r)});return t.update(n,t.total)}if(Array.isArray(t))return t.map(function(t){return f(t,r)});if(t instanceof U)return r.get(t.$uri);if(Object.keys(t).length>0){!Array.isArray(t)&&t.uri&&M.add(t);try{for(var i=e.__values(Object.entries(t)),u=i.next();!u.done;u=i.next()){var a=e.__read(u.value,2),s=a[0],c=a[1];if(c instanceof U){var p=r.get(c.$uri);Object.assign(t,(l={},l[s]=p,l))}else o(c)?Object.assign(t,(y={},y[s]=f(c,r),y)):"string"==typeof c&&"#"===c&&Object.assign(t,(g={},g[s]=r.get("#"),g))}}catch(t){h={error:t}}finally{try{u&&!u.done&&(d=i.return)&&d.call(i)}finally{if(h)throw h.error}}return t}return t;var h,d,l,y,g}function p(t,r){var n=new Map;if(o(t)&&Object.keys(t).length>0){if(r||n.set("#",t),M.has(t))return new Map;t.uri&&!n.has(t.uri)&&n.set(t.uri,t);var i=Array.isArray(t)||t instanceof R?t:Object.values(t);try{for(var u=e.__values(i),a=u.next();!a.done;a=u.next()){var s=p(a.value,!0);try{for(var c=e.__values(s.entries()),f=c.next();!f.done;f=c.next()){var h=e.__read(f.value,2),d=h[0],l=h[1];n.set(d,l)}}catch(t){v={error:t}}finally{try{f&&!f.done&&(m=c.return)&&m.call(c)}finally{if(v)throw v.error}}}}catch(t){y={error:t}}finally{try{a&&!a.done&&(g=u.return)&&g.call(u)}finally{if(y)throw y.error}}}return n;var y,g,v,m}function h(t){return new U(t)}function d(t,e){return o(t)?t instanceof I&&"string"==typeof t.uri?{$ref:""+P(t.uri,e)}:t instanceof Date?{$date:t.getTime()}:Array.isArray(t)?t.map(function(t){return d(t,e)}):a(t,function(t){return n(t)},function(t){return d(t,e)}):t}function l(t){return"string"==typeof t&&t.length>0?/^\d+$/.test(t)?parseInt(t,10):t:Number.isInteger(t)?t:null}function y(t,e){var r=t.indexOf(e+"/");return-1!==r?l(t.substring(r).split("/").pop()):null}function g(t,r){var n=Object.entries(r).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=g(t,e);return!!r&&null!==y(t,r.resourceURI)}function m(t){var e=t.$type,r=t.$id;return("string"==typeof r||Number.isInteger(r))&&"string"==typeof e}function b(t){var e=t.$uri,r=t.$ref,n=t.$type,i=t.$id;return"string"==typeof e?decodeURIComponent(e):"string"==typeof r?decodeURIComponent(r):m({$type:n,$id:i})?"/"+n+"/"+i:""}function _(t,e){return t.includes(e)?t.substring(e.length):t}function P(t,e){return"string"!=typeof e||t.includes(e)?t:""+e+t}function O(t){return N.getOwnMetadata(C,t)}function $(t,e){N.defineMetadata(C,e,t)}function j(t){return N.getOwnMetadata(J,t)}function w(t,e){N.defineMetadata(J,e,t)}function T(t){return N.getOwnMetadata(D,t.constructor)||Promise}function A(t,e){N.defineMetadata(D,e,t)}function S(t,e){var r=N.getOwnMetadata(G,t);return r&&r[e]}function E(t,e){var r=u(t)?t:u(t.constructor)?t.constructor:null;if(null!==r){N.defineMetadata(G,Object.assign(N.getOwnMetadata(G,r)||{},(n={},n[e]=!0,n)),r);var n}}function x(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),p=""+(f?j(this):this.uri)+t,h={method:r,paginate:a,cache:c};return"GET"===r?h.params=e:["POST","PUT","PATCH"].includes(r)&&(h.body=e),O(f?this:this.constructor).fetch(p,h)}}var I=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=j(this);return O(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,u=void 0===o||o,a=j(this);return O(this).fetch(a,{method:"GET",params:t,paginate:i,cache:u})},t.first=function(t){return this.query(t).then(function(t){return t[0]})},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,e={};return Object.keys(this).filter(function(e){return!e.startsWith("$")&&!S(t.constructor,e)}).forEach(function(r){e[r]=t[r]}),e},t.prototype.save=function(){if(this.uri||this.id)return this.update(this.toJSON());var t=this.constructor;return O(t).fetch(j(t),{method:"POST",body:this.toJSON(),cache:!0})},t.prototype.update=function(t){return void 0===t&&(t={}),O(this.constructor).fetch(this.uri,{cache:!0,method:"PATCH",body:t})},t.prototype.destroy=function(){var t=this.uri,e=O(this.constructor),r=e.cache;return e.fetch(t,{method:"DELETE"}).then(function(){r.get(t)&&r.remove(t)})},t}(),R=function(){function t(t,r,n,i){var o=t.potion,u=t.uri;this.items=r,this.options=i,this.potion=o,this.uri=u;var a=e.__assign({},this.options.params),s=a.page,c=void 0===s?1:s,f=a.perPage,p=void 0===f?25:f;this.$page=c,this.$perPage=p,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}(),U=function(){function t(t){this.$uri=t}return t.prototype.matches=function(t){return o(t)&&this.$uri===t.uri},t}(),M=new WeakSet,q=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}(),N=("undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0).Reflect;!function(){if(!N||!N.getMetadata)throw new Error("Dependency error. reflect-metadata shim is required when using potion-node library")}();var C=Symbol("potion"),J=Symbol("potion:uri"),D=Symbol("potion:promise"),G=Symbol("potion:readonly"),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,u=e.cache;this.resources={},this.Promise=T(this),this.requests=new Map,this.cache=u||new q,this.host=n,this.prefix=o}return t.prototype.register=function(t,e,r){if(!u(e))throw new TypeError("An error occurred while trying to register a resource for "+t+". "+e+" is not a function.");return $(e,this),w(e,t),r&&Array.isArray(r.readonly)&&r.readonly.forEach(function(t){return E(e,t)}),this.resources[t]=e,e},t.prototype.registerAs=function(t,e){var r=this;return function(n){return r.register(t,n,e),n}},t.prototype.fetch=function(t,r,n){var i=_(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 f(t,p(t)),t})},t.prototype.resolve=function(t,e){var r=this,n=this.prefix,i=this.Promise,o=_(t,n);t=P(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=s(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:d(t.paginate?e.__assign({page:1,perPage:25},n):n,r),body:d(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 R)return r.pagination.update(t,o);var u=new R({uri:e,potion:n},t,o,r);return Object.assign(r,{pagination:u}),u}return t})},t.prototype.fromPotionJSON=function(t,r){var n=this,i=this.Promise;if("object"==typeof t&&null!==t){if(Array.isArray(t))return i.all(t.map(function(t){return n.fromPotionJSON(t,r)}));if("string"==typeof t.$uri||m(t))return this.parseURI(t).then(function(o){var u=o.resource,a=o.id,s=o.uri,c={$id:a,$uri:s};r.includes(s)||r.push(s);var f=n.parsePotionJSONProperties(t,r);return n.cache.has(s)?i.all([f,n.cache.get(s)]).then(function(t){var r=e.__read(t,2),n=r[0],i=r[1];return Object.assign(i,n,c),i}):n.cache.put(s,f.then(function(t){return Reflect.construct(u,[e.__assign({},t,c)])}))});if("string"==typeof t.$schema)return i.resolve(c(t));if(1===Object.keys(t).length){if("string"==typeof t.$ref)return"#"===t.$ref?i.resolve(t.$ref):this.parseURI(t).then(function(t){var e=t.uri;return r.includes(e)?i.resolve(h(e)):n.resolve(e,{cache:!0,method:"GET",origin:r})});if(void 0!==t.$date)return i.resolve(new Date(t.$date))}return this.parsePotionJSONProperties(t,r)}return i.resolve(t)},t.prototype.parsePotionJSONProperties=function(t,r){var n=this,o=this.Promise,u=Object.entries(t),a=u.map(function(t){var i=e.__read(t,2)[1];return n.fromPotionJSON(i,r)}),s=u.map(function(t){return i(e.__read(t,1)[0])});return o.all(a).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,(u={},u[i]=o,u));var u},{})})},t.prototype.parseURI=function(t){var e=t.$ref,r=t.$uri,n=t.$type,i=t.$id,o=this.Promise,u=_(b({$ref:e,$uri:r,$type:n,$id:i}),this.prefix),a=g(u,this.resources);if(a){var s=a.resourceURI,c={resource:a.resource,uri:u,id:l(i)};return null===c.id&&Object.assign(c,{id:y(u,s)}),o.resolve(c)}return o.reject(new Error("URI '"+u+"' is an uninterpretable or unknown Potion resource."))},t}(),z={GET:function(t){return x(t,{method:"GET"})},DELETE:function(t){return x(t,{method:"DELETE"})},POST:function(t){return x(t,{method:"POST"})},PATCH:function(t){return x(t,{method:"PATCH"})},PUT:function(t){return x(t,{method:"PUT"})}},H=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"),u=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,u=void 0===o?"GET":o,a=n.params,s=n.body,c=n.cache;return i({url:t,method:u,data:s,cache:void 0===c||c,params:a}).then(function(t){var e=t.headers,r={body:t.data};return e&&(r.headers=e()),r})},r}(k),a=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 A(u,n),new u(e.__assign({cache:new a},t))}],this});t.potion=H,t.Item=I,t.readonly=E,t.Pagination=R,t.PotionBase=k,t.Route=z,t.route=x,t.findPotionResource=g,t.fromSchemaJSON=c,t.getPotionID=y,t.getPotionURI=b,t.hasTypeAndId=m,t.isPotionURI=v,t.parsePotionID=l,t.removePrefixFromURI=_,t.addPrefixToURI=P,t.toPotionJSON=d,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 u(t){return"function"==typeof t}function a(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,(u={},u[i]=o,u));var u},{}):t}function s(t,e){var r="An error occurred while Potion tried to retrieve a resource";return t instanceof Error?t.message:"string"==typeof t?t:"string"==typeof e?r+" from '"+e+"'.":r+"."}function c(t){return Array.isArray(t)?t.map(function(t){return"object"==typeof t?c(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?c(o):o]}).reduce(function(t,r){var n=e.__read(r,2),i=n[0],o=n[1];return e.__assign({},t,(u={},u[i]=o,u));var u},{}):t}function f(t,r){if("object"!=typeof t||null===t||t.hasOwnProperty("$schema"))return t;if(M.has(t))return t;if(t instanceof R){var n=t.toArray().map(function(t){return f(t,r)});return t.update(n,t.total)}if(Array.isArray(t))return t.map(function(t){return f(t,r)});if(t instanceof U)return r.get(t.$uri);if(Object.keys(t).length>0){!Array.isArray(t)&&t.uri&&M.add(t);try{for(var i=e.__values(Object.entries(t)),u=i.next();!u.done;u=i.next()){var a=e.__read(u.value,2),s=a[0],c=a[1];if(c instanceof U){var p=r.get(c.$uri);Object.assign(t,(l={},l[s]=p,l))}else o(c)?Object.assign(t,(y={},y[s]=f(c,r),y)):"string"==typeof c&&"#"===c&&Object.assign(t,(g={},g[s]=r.get("#"),g))}}catch(t){h={error:t}}finally{try{u&&!u.done&&(d=i.return)&&d.call(i)}finally{if(h)throw h.error}}return t}return t;var h,d,l,y,g}function p(t,r){var n=new Map;if(o(t)&&Object.keys(t).length>0){if(r||n.set("#",t),M.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 R?t:Object.values(t);try{for(var u=e.__values(i),a=u.next();!a.done;a=u.next()){var s=p(a.value,!0);try{for(var c=e.__values(s.entries()),f=c.next();!f.done;f=c.next()){var h=e.__read(f.value,2),d=h[0],l=h[1];n.set(d,l)}}catch(t){v={error:t}}finally{try{f&&!f.done&&(m=c.return)&&m.call(c)}finally{if(v)throw v.error}}}}catch(t){y={error:t}}finally{try{a&&!a.done&&(g=u.return)&&g.call(u)}finally{if(y)throw y.error}}}return n;var y,g,v,m}function h(t){return new U(t)}function d(t,e){return o(t)?t instanceof I&&"string"==typeof t.uri?{$ref:""+P(t.uri,e)}:t instanceof Date?{$date:t.getTime()}:Array.isArray(t)?t.map(function(t){return d(t,e)}):a(t,function(t){return n(t)},function(t){return d(t,e)}):t}function l(t){return"string"==typeof t&&t.length>0?/^\d+$/.test(t)?parseInt(t,10):t:Number.isInteger(t)?t:null}function y(t,e){var r=t.indexOf(e+"/");return-1!==r?l(t.substring(r).split("/").pop()):null}function g(t,r){var n=Object.entries(r).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=g(t,e);return!!r&&null!==y(t,r.resourceURI)}function m(t){var e=t.$type,r=t.$id;return("string"==typeof r||Number.isInteger(r))&&"string"==typeof e}function b(t){var e=t.$uri,r=t.$ref,n=t.$type,i=t.$id;return"string"==typeof e?decodeURIComponent(e):"string"==typeof r?decodeURIComponent(r):m({$type:n,$id:i})?"/"+n+"/"+i:""}function _(t,e){return t.includes(e)?t.substring(e.length):t}function P(t,e){return"string"!=typeof e||t.includes(e)?t:""+e+t}function O(t){return N.getOwnMetadata(C,t)}function $(t,e){N.defineMetadata(C,e,t)}function j(t){return N.getOwnMetadata(J,t)}function w(t,e){N.defineMetadata(J,e,t)}function T(t){return N.getOwnMetadata(D,t.constructor)||Promise}function A(t,e){N.defineMetadata(D,e,t)}function S(t,e){var r=N.getOwnMetadata(G,t);return r&&r[e]}function E(t,e){var r=u(t)?t:u(t.constructor)?t.constructor:null;if(null!==r){N.defineMetadata(G,Object.assign(N.getOwnMetadata(G,r)||{},(n={},n[e]=!0,n)),r);var n}}function x(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),p=""+(f?j(this):this.uri)+t,h={method:r,paginate:a,cache:c};return"GET"===r?h.params=e:["POST","PUT","PATCH"].includes(r)&&(h.body=e),O(f?this:this.constructor).fetch(p,h)}}var I=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=j(this);return O(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,u=void 0===o||o,a=j(this);return O(this).fetch(a,{method:"GET",params:t,paginate:i,cache:u})},t.first=function(t){return this.query(t).then(function(t){return t[0]})},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,e={};return Object.keys(this).filter(function(e){return!e.startsWith("$")&&!S(t.constructor,e)}).forEach(function(r){e[r]=t[r]}),e},t.prototype.save=function(){if(this.uri||this.id)return this.update(this.toJSON());var t=this.constructor;return O(t).fetch(j(t),{method:"POST",body:this.toJSON(),cache:!0})},t.prototype.update=function(t){return void 0===t&&(t={}),O(this.constructor).fetch(this.uri,{cache:!0,method:"PATCH",body:t})},t.prototype.destroy=function(){var t=this.uri,e=O(this.constructor),r=e.cache;return e.fetch(t,{method:"DELETE"}).then(function(){r.get(t)&&r.remove(t)})},t}(),R=function(){function t(t,r,n,i){var o=t.potion,u=t.uri;this.items=r,this.options=i,this.potion=o,this.uri=u;var a=e.__assign({},this.options.params),s=a.page,c=void 0===s?1:s,f=a.perPage,p=void 0===f?25:f;this.$page=c,this.$perPage=p,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}(),U=function(){function t(t){this.$uri=t}return t.prototype.matches=function(t){return o(t)&&this.$uri===t.uri},t}(),M=new WeakSet,q=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}(),N=("undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0).Reflect;!function(){if(!N||!N.getMetadata)throw new Error("Dependency error. reflect-metadata shim is required when using potion-node library")}();var C=Symbol("potion"),J=Symbol("potion:uri"),D=Symbol("potion:promise"),G=Symbol("potion:readonly"),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,u=e.cache;this.resources={},this.Promise=T(this),this.requests=new Map,this.cache=u||new q,this.host=n,this.prefix=o}return t.prototype.register=function(t,e,r){if(!u(e))throw new TypeError("An error occurred while trying to register a resource for "+t+". "+e+" is not a function.");return $(e,this),w(e,t),r&&Array.isArray(r.readonly)&&r.readonly.forEach(function(t){return E(e,t)}),this.resources[t]=e,e},t.prototype.registerAs=function(t,e){var r=this;return function(n){return r.register(t,n,e),n}},t.prototype.fetch=function(t,r,n){var i=_(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 f(t,p(t)),t})},t.prototype.resolve=function(t,e){var r=this,n=this.prefix,i=this.Promise,o=_(t,n);t=P(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=s(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:d(t.paginate?e.__assign({page:1,perPage:25},n):n,r),body:d(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 R)return r.pagination.update(t,o);var u=new R({uri:e,potion:n},t,o,r);return Object.assign(r,{pagination:u}),u}return t})},t.prototype.fromPotionJSON=function(t,r){var n=this,i=this.Promise;if("object"==typeof t&&null!==t){if(Array.isArray(t))return i.all(t.map(function(t){return n.fromPotionJSON(t,r)}));if("string"==typeof t.$uri||m(t))return this.parseURI(t).then(function(o){var u=o.resource,a=o.id,s=o.uri,c={$id:a,$uri:s};r.includes(s)||r.push(s);var f=n.parsePotionJSONProperties(t,r);return n.cache.has(s)?i.all([f,n.cache.get(s)]).then(function(t){var r=e.__read(t,2),n=r[0],i=r[1];return Object.assign(i,n,c),i}):n.cache.put(s,f.then(function(t){return Reflect.construct(u,[e.__assign({},t,c)])}))});if("string"==typeof t.$schema)return i.resolve(c(t));if(1===Object.keys(t).length){if("string"==typeof t.$ref)return"#"===t.$ref?i.resolve(t.$ref):this.parseURI(t).then(function(t){var e=t.uri;return r.includes(e)?i.resolve(h(e)):n.resolve(e,{cache:!0,method:"GET",origin:r})});if(void 0!==t.$date)return i.resolve(new Date(t.$date))}return this.parsePotionJSONProperties(t,r)}return i.resolve(t)},t.prototype.parsePotionJSONProperties=function(t,r){var n=this,o=this.Promise,u=Object.entries(t),a=u.map(function(t){var i=e.__read(t,2)[1];return n.fromPotionJSON(i,r)}),s=u.map(function(t){return i(e.__read(t,1)[0])});return o.all(a).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,(u={},u[i]=o,u));var u},{})})},t.prototype.parseURI=function(t){var e=t.$ref,r=t.$uri,n=t.$type,i=t.$id,o=this.Promise,u=_(b({$ref:e,$uri:r,$type:n,$id:i}),this.prefix),a=g(u,this.resources);if(a){var s=a.resourceURI,c={resource:a.resource,uri:u,id:l(i)};return null===c.id&&Object.assign(c,{id:y(u,s)}),o.resolve(c)}return o.reject(new Error("URI '"+u+"' is an uninterpretable or unknown Potion resource."))},t}(),z={GET:function(t){return x(t,{method:"GET"})},DELETE:function(t){return x(t,{method:"DELETE"})},POST:function(t){return x(t,{method:"POST"})},PATCH:function(t){return x(t,{method:"PATCH"})},PUT:function(t){return x(t,{method:"PUT"})}},H=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"),u=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,u=void 0===o?"GET":o,a=n.params,s=n.body,c=n.cache;return i({url:t,method:u,data:s,cache:void 0===c||c,params:a}).then(function(t){var e=t.headers,r={body:t.data};return e&&(r.headers=e()),r})},r}(k),a=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 A(u,n),new u(e.__assign({cache:new a},t))}],this});t.potion=H,t.Item=I,t.readonly=E,t.Pagination=R,t.PotionBase=k,t.Route=z,t.route=x,t.findPotionResource=g,t.fromSchemaJSON=c,t.getPotionID=y,t.getPotionURI=b,t.hasTypeAndId=m,t.isPotionURI=v,t.parsePotionID=l,t.removePrefixFromURI=_,t.addPrefixToURI=P,t.toPotionJSON=d,t.toCamelCase=i,t.toSnakeCase=n,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=angularjs.umd.min.js.map |
@@ -0,1 +1,11 @@ | ||
<a name="3.0.2"></a> | ||
## [3.0.2](https://github.com/biosustain/potion-node/compare/v3.0.1...v3.0.2) (2017-07-24) | ||
### Bug Fixes | ||
* do not try to find roots and resolve references in schemas ([4ae9c07](https://github.com/biosustain/potion-node/commit/4ae9c07)) | ||
<a name="3.0.1"></a> | ||
@@ -2,0 +12,0 @@ ## [3.0.1](https://github.com/biosustain/potion-node/compare/v3.0.0...v3.0.1) (2017-07-22) |
@@ -378,3 +378,3 @@ import { __assign, __extends, __read, __spread, __values } from 'tslib'; | ||
function replaceSelfReferences(json, roots) { | ||
if (typeof json !== 'object' || json === null) { | ||
if (typeof json !== 'object' || json === null || json.hasOwnProperty('$schema')) { | ||
return json; | ||
@@ -450,3 +450,3 @@ } | ||
} | ||
if (set.has(json)) { | ||
if (set.has(json) || json.hasOwnProperty('$schema')) { | ||
// If we find the root in the set it means there is no need to continue. | ||
@@ -453,0 +453,0 @@ return new Map(); |
@@ -319,3 +319,3 @@ /** | ||
function replaceSelfReferences(json, roots) { | ||
if (typeof json !== 'object' || json === null) { | ||
if (typeof json !== 'object' || json === null || json.hasOwnProperty('$schema')) { | ||
return json; | ||
@@ -380,3 +380,3 @@ } | ||
} | ||
if (set.has(json)) { | ||
if (set.has(json) || json.hasOwnProperty('$schema')) { | ||
// If we find the root in the set it means there is no need to continue. | ||
@@ -383,0 +383,0 @@ return new Map(); |
@@ -381,3 +381,3 @@ (function (global, factory) { | ||
function replaceSelfReferences(json, roots) { | ||
if (typeof json !== 'object' || json === null) { | ||
if (typeof json !== 'object' || json === null || json.hasOwnProperty('$schema')) { | ||
return json; | ||
@@ -453,3 +453,3 @@ } | ||
} | ||
if (set.has(json)) { | ||
if (set.has(json) || json.hasOwnProperty('$schema')) { | ||
// If we find the root in the set it means there is no need to continue. | ||
@@ -456,0 +456,0 @@ return new Map(); |
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("tslib")):"function"==typeof define&&define.amd?define(["exports","tslib"],e):e(t.potionClient={},t.tslib)}(this,function(t,e){"use strict";function r(t,e){return void 0===e&&(e="_"),t.replace(/\.?([A-Z0-9]+)/g,function(t,r){return""+e+r.toLowerCase()}).replace(/^_/,"")}function n(t){return t.replace(/_([a-z0-9])/g,function(t){return t[1].toUpperCase()})}function i(t){return"object"==typeof t&&null!==t}function o(t){return"function"==typeof t}function u(t,r,n){return i(t)&&!Array.isArray(t)?Object.entries(t).map(function(t){var i=e.__read(t,2),u=i[0],a=i[1];return[o(r)?r(u):u,o(n)?n(a):a]}).reduce(function(t,r){var n=e.__read(r,2),i=n[0],o=n[1];return e.__assign({},t,(u={},u[i]=o,u));var u},{}):t}function a(t,e){var r="An error occurred while Potion tried to retrieve a resource";return t instanceof Error?t.message:"string"==typeof t?t:"string"==typeof e?r+" from '"+e+"'.":r+"."}function s(t){return Array.isArray(t)?t.map(function(t){return"object"==typeof t?s(t):t}):i(t)?Object.entries(t).map(function(t){var r=e.__read(t,2),i=r[0],o=r[1];return[n(i),"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,(u={},u[i]=o,u));var u},{}):t}function c(t,r){if("object"!=typeof t||null===t)return t;if(R.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 I)return r.get(t.$uri);if(Object.keys(t).length>0){!Array.isArray(t)&&t.uri&&R.add(t);try{for(var o=e.__values(Object.entries(t)),u=o.next();!u.done;u=o.next()){var a=e.__read(u.value,2),s=a[0],f=a[1];if(f instanceof I){var p=r.get(f.$uri);Object.assign(t,(l={},l[s]=p,l))}else i(f)?Object.assign(t,(y={},y[s]=c(f,r),y)):"string"==typeof f&&"#"===f&&Object.assign(t,(g={},g[s]=r.get("#"),g))}}catch(t){h={error:t}}finally{try{u&&!u.done&&(d=o.return)&&d.call(o)}finally{if(h)throw h.error}}return t}return t;var h,d,l,y,g}function f(t,r){var n=new Map;if(i(t)&&Object.keys(t).length>0){if(r||n.set("#",t),R.has(t))return new Map;t.uri&&!n.has(t.uri)&&n.set(t.uri,t);var o=Array.isArray(t)||t instanceof x?t:Object.values(t);try{for(var u=e.__values(o),a=u.next();!a.done;a=u.next()){var s=f(a.value,!0);try{for(var c=e.__values(s.entries()),p=c.next();!p.done;p=c.next()){var h=e.__read(p.value,2),d=h[0],l=h[1];n.set(d,l)}}catch(t){v={error:t}}finally{try{p&&!p.done&&(m=c.return)&&m.call(c)}finally{if(v)throw v.error}}}}catch(t){y={error:t}}finally{try{a&&!a.done&&(g=u.return)&&g.call(u)}finally{if(y)throw y.error}}}return n;var y,g,v,m}function p(t){return new I(t)}function h(t,e){return i(t)?t instanceof E&&"string"==typeof t.uri?{$ref:""+_(t.uri,e)}:t instanceof Date?{$date:t.getTime()}:Array.isArray(t)?t.map(function(t){return h(t,e)}):u(t,function(t){return r(t)},function(t){return h(t,e)}):t}function d(t){return"string"==typeof t&&t.length>0?/^\d+$/.test(t)?parseInt(t,10):t:Number.isInteger(t)?t:null}function l(t,e){var r=t.indexOf(e+"/");return-1!==r?d(t.substring(r).split("/").pop()):null}function y(t,r){var n=Object.entries(r).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 g(t,e){var r=y(t,e);return!!r&&null!==l(t,r.resourceURI)}function v(t){var e=t.$type,r=t.$id;return("string"==typeof r||Number.isInteger(r))&&"string"==typeof e}function m(t){var e=t.$uri,r=t.$ref,n=t.$type,i=t.$id;return"string"==typeof e?decodeURIComponent(e):"string"==typeof r?decodeURIComponent(r):v({$type:n,$id:i})?"/"+n+"/"+i:""}function b(t,e){return t.includes(e)?t.substring(e.length):t}function _(t,e){return"string"!=typeof e||t.includes(e)?t:""+e+t}function P(t){return M.getOwnMetadata(N,t)}function O(t,e){M.defineMetadata(N,e,t)}function $(t){return M.getOwnMetadata(q,t)}function j(t,e){M.defineMetadata(q,e,t)}function w(t){return M.getOwnMetadata(C,t.constructor)||Promise}function T(t,e){var r=M.getOwnMetadata(J,t);return r&&r[e]}function A(t,e){var r=o(t)?t:o(t.constructor)?t.constructor:null;if(null!==r){M.defineMetadata(J,Object.assign(M.getOwnMetadata(J,r)||{},(n={},n[e]=!0,n)),r);var n}}function S(t,e){var r=(void 0===e?{}:e).method;return function(e,n){var i=void 0===n?{}:n,u=i.paginate,a=void 0!==u&&u,s=i.cache,c=void 0===s||s,f=o(this),p=""+(f?$(this):this.uri)+t,h={method:r,paginate:a,cache:c};return"GET"===r?h.params=e:["POST","PUT","PATCH"].includes(r)&&(h.body=e),P(f?this:this.constructor).fetch(p,h)}}var E=function(){function t(t){this.$id=null,i(t)&&Object.assign(this,t)}return t.fetch=function(t,e){var r=(void 0===e?{}:e).cache,n=void 0===r||r,i=$(this);return P(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,u=void 0===o||o,a=$(this);return P(this).fetch(a,{method:"GET",params:t,paginate:i,cache:u})},t.first=function(t){return this.query(t).then(function(t){return t[0]})},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,e={};return Object.keys(this).filter(function(e){return!e.startsWith("$")&&!T(t.constructor,e)}).forEach(function(r){e[r]=t[r]}),e},t.prototype.save=function(){if(this.uri||this.id)return this.update(this.toJSON());var t=this.constructor;return P(t).fetch($(t),{method:"POST",body:this.toJSON(),cache:!0})},t.prototype.update=function(t){return void 0===t&&(t={}),P(this.constructor).fetch(this.uri,{cache:!0,method:"PATCH",body:t})},t.prototype.destroy=function(){var t=this.uri,e=P(this.constructor),r=e.cache;return e.fetch(t,{method:"DELETE"}).then(function(){r.get(t)&&r.remove(t)})},t}(),x=function(){function t(t,r,n,i){var o=t.potion,u=t.uri;this.items=r,this.options=i,this.potion=o,this.uri=u;var a=e.__assign({},this.options.params),s=a.page,c=void 0===s?1:s,f=a.perPage,p=void 0===f?25:f;this.$page=c,this.$perPage=p,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}(),I=function(){function t(t){this.$uri=t}return t.prototype.matches=function(t){return i(t)&&this.$uri===t.uri},t}(),R=new WeakSet,U=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}(),M=("undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0).Reflect;!function(){if(!M||!M.getMetadata)throw new Error("Dependency error. reflect-metadata shim is required when using potion-node library")}();var N=Symbol("potion"),q=Symbol("potion:uri"),C=Symbol("potion:promise"),J=Symbol("potion:readonly"),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,u=e.cache;this.resources={},this.Promise=w(this),this.requests=new Map,this.cache=u||new U,this.host=n,this.prefix=o}return t.prototype.register=function(t,e,r){if(!o(e))throw new TypeError("An error occurred while trying to register a resource for "+t+". "+e+" is not a function.");return O(e,this),j(e,t),r&&Array.isArray(r.readonly)&&r.readonly.forEach(function(t){return A(e,t)}),this.resources[t]=e,e},t.prototype.registerAs=function(t,e){var r=this;return function(n){return r.register(t,n,e),n}},t.prototype.fetch=function(t,r,n){var i=b(t,this.prefix),o=e.__assign({},r,n,{origin:[]});return g(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=b(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=a(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 u=new x({uri:e,potion:n},t,o,r);return Object.assign(r,{pagination:u}),u}return t})},t.prototype.fromPotionJSON=function(t,r){var n=this,i=this.Promise;if("object"==typeof t&&null!==t){if(Array.isArray(t))return i.all(t.map(function(t){return n.fromPotionJSON(t,r)}));if("string"==typeof t.$uri||v(t))return this.parseURI(t).then(function(o){var u=o.resource,a=o.id,s=o.uri,c={$id:a,$uri:s};r.includes(s)||r.push(s);var f=n.parsePotionJSONProperties(t,r);return n.cache.has(s)?i.all([f,n.cache.get(s)]).then(function(t){var r=e.__read(t,2),n=r[0],i=r[1];return Object.assign(i,n,c),i}):n.cache.put(s,f.then(function(t){return Reflect.construct(u,[e.__assign({},t,c)])}))});if("string"==typeof t.$schema)return i.resolve(s(t));if(1===Object.keys(t).length){if("string"==typeof t.$ref)return"#"===t.$ref?i.resolve(t.$ref):this.parseURI(t).then(function(t){var e=t.uri;return r.includes(e)?i.resolve(p(e)):n.resolve(e,{cache:!0,method:"GET",origin:r})});if(void 0!==t.$date)return i.resolve(new Date(t.$date))}return this.parsePotionJSONProperties(t,r)}return i.resolve(t)},t.prototype.parsePotionJSONProperties=function(t,r){var i=this,o=this.Promise,u=Object.entries(t),a=u.map(function(t){var n=e.__read(t,2)[1];return i.fromPotionJSON(n,r)}),s=u.map(function(t){return n(e.__read(t,1)[0])});return o.all(a).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,(u={},u[i]=o,u));var u},{})})},t.prototype.parseURI=function(t){var e=t.$ref,r=t.$uri,n=t.$type,i=t.$id,o=this.Promise,u=b(m({$ref:e,$uri:r,$type:n,$id:i}),this.prefix),a=y(u,this.resources);if(a){var s=a.resourceURI,c={resource:a.resource,uri:u,id:d(i)};return null===c.id&&Object.assign(c,{id:l(u,s)}),o.resolve(c)}return o.reject(new Error("URI '"+u+"' is an uninterpretable or unknown Potion resource."))},t}(),D={GET:function(t){return S(t,{method:"GET"})},DELETE:function(t){return S(t,{method:"DELETE"})},POST:function(t){return S(t,{method:"POST"})},PATCH:function(t){return S(t,{method:"PATCH"})},PUT:function(t){return S(t,{method:"PUT"})}},G=function(t){function r(r){return t.call(this,e.__assign({},r))||this}return e.__extends(r,t),r.prototype.request=function(t,r){var n=e.__assign({},r),i=n.method,o=void 0===i?"GET":i,u=n.params,a=n.body,s=n.cache,c=void 0===s||s,f=new Headers,p={method:o,cache:c?"default":"no-cache",credentials:"include"};if(a&&(f.set("Accept","application/json"),f.set("Content-Type","application/json"),p.body=JSON.stringify(a)),Object.assign(p,{headers:f}),u){var h=1,d=Object.entries(u),l=d.length;try{for(var y=e.__values(d),g=y.next();!g.done;g=y.next()){var v=e.__read(g.value,2),m=v[0],b=v[1];1===h&&(t+="?"),t+=m+"="+b,h<l&&(t+="&"),h++}}catch(t){_={error:t}}finally{try{g&&!g.done&&(P=y.return)&&P.call(y)}finally{if(_)throw _.error}}}return fetch(new Request(t,p),p).then(function(t){if(t.ok){var e={};return t.headers&&t.headers.forEach(function(t,r){e[r]=t}),t.json().then(function(t){return{headers:e,body:t}},function(t){return t})}var r=new Error(t.statusText);throw Object.assign(r,{response:t}),r});var _,P},r}(k);t.Potion=G,t.Item=E,t.readonly=A,t.Pagination=x,t.PotionBase=k,t.Route=D,t.route=S,t.findPotionResource=y,t.fromSchemaJSON=s,t.getPotionID=l,t.getPotionURI=m,t.hasTypeAndId=v,t.isPotionURI=g,t.parsePotionID=d,t.removePrefixFromURI=b,t.addPrefixToURI=_,t.toPotionJSON=h,t.toCamelCase=n,t.toSnakeCase=r,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("tslib")):"function"==typeof define&&define.amd?define(["exports","tslib"],e):e(t.potionClient={},t.tslib)}(this,function(t,e){"use strict";function r(t,e){return void 0===e&&(e="_"),t.replace(/\.?([A-Z0-9]+)/g,function(t,r){return""+e+r.toLowerCase()}).replace(/^_/,"")}function n(t){return t.replace(/_([a-z0-9])/g,function(t){return t[1].toUpperCase()})}function i(t){return"object"==typeof t&&null!==t}function o(t){return"function"==typeof t}function a(t,r,n){return i(t)&&!Array.isArray(t)?Object.entries(t).map(function(t){var i=e.__read(t,2),a=i[0],u=i[1];return[o(r)?r(a):a,o(n)?n(u):u]}).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 u(t,e){var r="An error occurred while Potion tried to retrieve a resource";return t instanceof Error?t.message:"string"==typeof t?t:"string"==typeof e?r+" from '"+e+"'.":r+"."}function s(t){return Array.isArray(t)?t.map(function(t){return"object"==typeof t?s(t):t}):i(t)?Object.entries(t).map(function(t){var r=e.__read(t,2),i=r[0],o=r[1];return[n(i),"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(R.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 I)return r.get(t.$uri);if(Object.keys(t).length>0){!Array.isArray(t)&&t.uri&&R.add(t);try{for(var o=e.__values(Object.entries(t)),a=o.next();!a.done;a=o.next()){var u=e.__read(a.value,2),s=u[0],f=u[1];if(f instanceof I){var p=r.get(f.$uri);Object.assign(t,(l={},l[s]=p,l))}else i(f)?Object.assign(t,(y={},y[s]=c(f,r),y)):"string"==typeof f&&"#"===f&&Object.assign(t,(g={},g[s]=r.get("#"),g))}}catch(t){h={error:t}}finally{try{a&&!a.done&&(d=o.return)&&d.call(o)}finally{if(h)throw h.error}}return t}return t;var h,d,l,y,g}function f(t,r){var n=new Map;if(i(t)&&Object.keys(t).length>0){if(r||n.set("#",t),R.has(t)||t.hasOwnProperty("$schema"))return new Map;t.uri&&!n.has(t.uri)&&n.set(t.uri,t);var o=Array.isArray(t)||t instanceof x?t:Object.values(t);try{for(var a=e.__values(o),u=a.next();!u.done;u=a.next()){var s=f(u.value,!0);try{for(var c=e.__values(s.entries()),p=c.next();!p.done;p=c.next()){var h=e.__read(p.value,2),d=h[0],l=h[1];n.set(d,l)}}catch(t){v={error:t}}finally{try{p&&!p.done&&(m=c.return)&&m.call(c)}finally{if(v)throw v.error}}}}catch(t){y={error:t}}finally{try{u&&!u.done&&(g=a.return)&&g.call(a)}finally{if(y)throw y.error}}}return n;var y,g,v,m}function p(t){return new I(t)}function h(t,e){return i(t)?t instanceof E&&"string"==typeof t.uri?{$ref:""+_(t.uri,e)}:t instanceof Date?{$date:t.getTime()}:Array.isArray(t)?t.map(function(t){return h(t,e)}):a(t,function(t){return r(t)},function(t){return h(t,e)}):t}function d(t){return"string"==typeof t&&t.length>0?/^\d+$/.test(t)?parseInt(t,10):t:Number.isInteger(t)?t:null}function l(t,e){var r=t.indexOf(e+"/");return-1!==r?d(t.substring(r).split("/").pop()):null}function y(t,r){var n=Object.entries(r).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 g(t,e){var r=y(t,e);return!!r&&null!==l(t,r.resourceURI)}function v(t){var e=t.$type,r=t.$id;return("string"==typeof r||Number.isInteger(r))&&"string"==typeof e}function m(t){var e=t.$uri,r=t.$ref,n=t.$type,i=t.$id;return"string"==typeof e?decodeURIComponent(e):"string"==typeof r?decodeURIComponent(r):v({$type:n,$id:i})?"/"+n+"/"+i:""}function b(t,e){return t.includes(e)?t.substring(e.length):t}function _(t,e){return"string"!=typeof e||t.includes(e)?t:""+e+t}function P(t){return M.getOwnMetadata(N,t)}function O(t,e){M.defineMetadata(N,e,t)}function $(t){return M.getOwnMetadata(q,t)}function j(t,e){M.defineMetadata(q,e,t)}function w(t){return M.getOwnMetadata(C,t.constructor)||Promise}function T(t,e){var r=M.getOwnMetadata(J,t);return r&&r[e]}function A(t,e){var r=o(t)?t:o(t.constructor)?t.constructor:null;if(null!==r){M.defineMetadata(J,Object.assign(M.getOwnMetadata(J,r)||{},(n={},n[e]=!0,n)),r);var n}}function S(t,e){var r=(void 0===e?{}:e).method;return function(e,n){var i=void 0===n?{}:n,a=i.paginate,u=void 0!==a&&a,s=i.cache,c=void 0===s||s,f=o(this),p=""+(f?$(this):this.uri)+t,h={method:r,paginate:u,cache:c};return"GET"===r?h.params=e:["POST","PUT","PATCH"].includes(r)&&(h.body=e),P(f?this:this.constructor).fetch(p,h)}}var E=function(){function t(t){this.$id=null,i(t)&&Object.assign(this,t)}return t.fetch=function(t,e){var r=(void 0===e?{}:e).cache,n=void 0===r||r,i=$(this);return P(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=$(this);return P(this).fetch(u,{method:"GET",params:t,paginate:i,cache:a})},t.first=function(t){return this.query(t).then(function(t){return t[0]})},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,e={};return Object.keys(this).filter(function(e){return!e.startsWith("$")&&!T(t.constructor,e)}).forEach(function(r){e[r]=t[r]}),e},t.prototype.save=function(){if(this.uri||this.id)return this.update(this.toJSON());var t=this.constructor;return P(t).fetch($(t),{method:"POST",body:this.toJSON(),cache:!0})},t.prototype.update=function(t){return void 0===t&&(t={}),P(this.constructor).fetch(this.uri,{cache:!0,method:"PATCH",body:t})},t.prototype.destroy=function(){var t=this.uri,e=P(this.constructor),r=e.cache;return e.fetch(t,{method:"DELETE"}).then(function(){r.get(t)&&r.remove(t)})},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,p=void 0===f?25:f;this.$page=c,this.$perPage=p,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}(),I=function(){function t(t){this.$uri=t}return t.prototype.matches=function(t){return i(t)&&this.$uri===t.uri},t}(),R=new WeakSet,U=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}(),M=("undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0).Reflect;!function(){if(!M||!M.getMetadata)throw new Error("Dependency error. reflect-metadata shim is required when using potion-node library")}();var N=Symbol("potion"),q=Symbol("potion:uri"),C=Symbol("potion:promise"),J=Symbol("potion:readonly"),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=w(this),this.requests=new Map,this.cache=a||new U,this.host=n,this.prefix=o}return t.prototype.register=function(t,e,r){if(!o(e))throw new TypeError("An error occurred while trying to register a resource for "+t+". "+e+" is not a function.");return O(e,this),j(e,t),r&&Array.isArray(r.readonly)&&r.readonly.forEach(function(t){return A(e,t)}),this.resources[t]=e,e},t.prototype.registerAs=function(t,e){var r=this;return function(n){return r.register(t,n,e),n}},t.prototype.fetch=function(t,r,n){var i=b(t,this.prefix),o=e.__assign({},r,n,{origin:[]});return g(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=b(t,n);t=_(t,n);var a=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?a():e.cache&&this.cache.has(o)?this.cache.get(o):(this.requests.has(o)||this.requests.set(o,a().then(function(t){return r.requests.delete(o),t},function(e){r.requests.delete(o);var n=u(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){var n=this,i=this.Promise;if("object"==typeof t&&null!==t){if(Array.isArray(t))return i.all(t.map(function(t){return n.fromPotionJSON(t,r)}));if("string"==typeof t.$uri||v(t))return this.parseURI(t).then(function(o){var a=o.resource,u=o.id,s=o.uri,c={$id:u,$uri:s};r.includes(s)||r.push(s);var f=n.parsePotionJSONProperties(t,r);return n.cache.has(s)?i.all([f,n.cache.get(s)]).then(function(t){var r=e.__read(t,2),n=r[0],i=r[1];return Object.assign(i,n,c),i}):n.cache.put(s,f.then(function(t){return Reflect.construct(a,[e.__assign({},t,c)])}))});if("string"==typeof t.$schema)return i.resolve(s(t));if(1===Object.keys(t).length){if("string"==typeof t.$ref)return"#"===t.$ref?i.resolve(t.$ref):this.parseURI(t).then(function(t){var e=t.uri;return r.includes(e)?i.resolve(p(e)):n.resolve(e,{cache:!0,method:"GET",origin:r})});if(void 0!==t.$date)return i.resolve(new Date(t.$date))}return this.parsePotionJSONProperties(t,r)}return i.resolve(t)},t.prototype.parsePotionJSONProperties=function(t,r){var i=this,o=this.Promise,a=Object.entries(t),u=a.map(function(t){var n=e.__read(t,2)[1];return i.fromPotionJSON(n,r)}),s=a.map(function(t){return n(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=b(m({$ref:e,$uri:r,$type:n,$id:i}),this.prefix),u=y(a,this.resources);if(u){var s=u.resourceURI,c={resource:u.resource,uri:a,id:d(i)};return null===c.id&&Object.assign(c,{id:l(a,s)}),o.resolve(c)}return o.reject(new Error("URI '"+a+"' is an uninterpretable or unknown Potion resource."))},t}(),D={GET:function(t){return S(t,{method:"GET"})},DELETE:function(t){return S(t,{method:"DELETE"})},POST:function(t){return S(t,{method:"POST"})},PATCH:function(t){return S(t,{method:"PATCH"})},PUT:function(t){return S(t,{method:"PUT"})}},G=function(t){function r(r){return t.call(this,e.__assign({},r))||this}return e.__extends(r,t),r.prototype.request=function(t,r){var n=e.__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,p={method:o,cache:c?"default":"no-cache",credentials:"include"};if(u&&(f.set("Accept","application/json"),f.set("Content-Type","application/json"),p.body=JSON.stringify(u)),Object.assign(p,{headers:f}),a){var h=1,d=Object.entries(a),l=d.length;try{for(var y=e.__values(d),g=y.next();!g.done;g=y.next()){var v=e.__read(g.value,2),m=v[0],b=v[1];1===h&&(t+="?"),t+=m+"="+b,h<l&&(t+="&"),h++}}catch(t){_={error:t}}finally{try{g&&!g.done&&(P=y.return)&&P.call(y)}finally{if(_)throw _.error}}}return fetch(new Request(t,p),p).then(function(t){if(t.ok){var e={};return t.headers&&t.headers.forEach(function(t,r){e[r]=t}),t.json().then(function(t){return{headers:e,body:t}},function(t){return t})}var r=new Error(t.statusText);throw Object.assign(r,{response:t}),r});var _,P},r}(k);t.Potion=G,t.Item=E,t.readonly=A,t.Pagination=x,t.PotionBase=k,t.Route=D,t.route=S,t.findPotionResource=y,t.fromSchemaJSON=s,t.getPotionID=l,t.getPotionURI=m,t.hasTypeAndId=v,t.isPotionURI=g,t.parsePotionID=d,t.removePrefixFromURI=b,t.addPrefixToURI=_,t.toPotionJSON=h,t.toCamelCase=n,t.toSnakeCase=r,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=fetch.umd.min.js.map |
@@ -292,3 +292,3 @@ import { __assign, __extends, __read, __spread, __values } from 'tslib'; | ||
function replaceSelfReferences(json, roots) { | ||
if (typeof json !== 'object' || json === null) { | ||
if (typeof json !== 'object' || json === null || json.hasOwnProperty('$schema')) { | ||
return json; | ||
@@ -365,3 +365,3 @@ } | ||
} | ||
if (set.has(json)) { | ||
if (set.has(json) || json.hasOwnProperty('$schema')) { | ||
// If we find the root in the set it means there is no need to continue. | ||
@@ -368,0 +368,0 @@ return new Map(); |
@@ -247,3 +247,3 @@ import { Inject, Injectable, InjectionToken, NgModule, Optional, SkipSelf, forwardRef } from '@angular/core'; | ||
function replaceSelfReferences(json, roots) { | ||
if (typeof json !== 'object' || json === null) { | ||
if (typeof json !== 'object' || json === null || json.hasOwnProperty('$schema')) { | ||
return json; | ||
@@ -309,3 +309,3 @@ } | ||
} | ||
if (set.has(json)) { | ||
if (set.has(json) || json.hasOwnProperty('$schema')) { | ||
// If we find the root in the set it means there is no need to continue. | ||
@@ -312,0 +312,0 @@ return new Map(); |
@@ -290,3 +290,3 @@ (function (global, factory) { | ||
function replaceSelfReferences(json, roots) { | ||
if (typeof json !== 'object' || json === null) { | ||
if (typeof json !== 'object' || json === null || json.hasOwnProperty('$schema')) { | ||
return json; | ||
@@ -363,3 +363,3 @@ } | ||
} | ||
if (set.has(json)) { | ||
if (set.has(json) || json.hasOwnProperty('$schema')) { | ||
// If we find the root in the set it means there is no need to continue. | ||
@@ -366,0 +366,0 @@ return new Map(); |
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("tslib"),require("@angular/core"),require("@angular/common/http"),require("rxjs/add/operator/filter"),require("rxjs/add/operator/map"),require("rxjs/add/operator/toPromise")):"function"==typeof define&&define.amd?define(["exports","tslib","@angular/core","@angular/common/http","rxjs/add/operator/filter","rxjs/add/operator/map","rxjs/add/operator/toPromise"],e):e(t.potionClient={},t.tslib,t.ng.core,t.ng.common.http)}(this,function(t,e,r,n){"use strict";function o(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 a(t){return"object"==typeof t&&null!==t}function u(t){return 0===Object.keys(t).length}function s(t){return"function"==typeof t}function c(t,r,n){return a(t)&&!Array.isArray(t)?Object.entries(t).map(function(t){var o=e.__read(t,2),i=o[0],a=o[1];return[s(r)?r(i):i,s(n)?n(a):a]}).reduce(function(t,r){var n=e.__read(r,2),o=n[0],i=n[1];return e.__assign({},t,(a={},a[o]=i,a));var a},{}):t}function f(t,e){var r="An error occurred while Potion tried to retrieve a resource";return t instanceof Error?t.message:"string"==typeof t?t:"string"==typeof e?r+" from '"+e+"'.":r+"."}function p(t){return Array.isArray(t)?t.map(function(t){return"object"==typeof t?p(t):t}):a(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?p(o):o]}).reduce(function(t,r){var n=e.__read(r,2),o=n[0],i=n[1];return e.__assign({},t,(a={},a[o]=i,a));var a},{}):t}function h(t,r){if("object"!=typeof t||null===t)return t;if(M.has(t))return t;if(t instanceof C){var n=t.toArray().map(function(t){return h(t,r)});return t.update(n,t.total)}if(Array.isArray(t))return t.map(function(t){return h(t,r)});if(t instanceof U)return r.get(t.$uri);if(Object.keys(t).length>0){!Array.isArray(t)&&t.uri&&M.add(t);try{for(var o=e.__values(Object.entries(t)),i=o.next();!i.done;i=o.next()){var u=e.__read(i.value,2),s=u[0],c=u[1];if(c instanceof U){var f=r.get(c.$uri);Object.assign(t,(l={},l[s]=f,l))}else a(c)?Object.assign(t,(y={},y[s]=h(c,r),y)):"string"==typeof c&&"#"===c&&Object.assign(t,(g={},g[s]=r.get("#"),g))}}catch(t){p={error:t}}finally{try{i&&!i.done&&(d=o.return)&&d.call(o)}finally{if(p)throw p.error}}return t}return t;var p,d,l,y,g}function d(t,r){var n=new Map;if(a(t)&&Object.keys(t).length>0){if(r||n.set("#",t),M.has(t))return new Map;t.uri&&!n.has(t.uri)&&n.set(t.uri,t);var o=Array.isArray(t)||t instanceof C?t:Object.values(t);try{for(var i=e.__values(o),u=i.next();!u.done;u=i.next()){var s=d(u.value,!0);try{for(var c=e.__values(s.entries()),f=c.next();!f.done;f=c.next()){var p=e.__read(f.value,2),h=p[0],l=p[1];n.set(h,l)}}catch(t){v={error:t}}finally{try{f&&!f.done&&(m=c.return)&&m.call(c)}finally{if(v)throw v.error}}}}catch(t){y={error:t}}finally{try{u&&!u.done&&(g=i.return)&&g.call(i)}finally{if(y)throw y.error}}}return n;var y,g,v,m}function l(t){return new U(t)}function y(t,e){return a(t)?t instanceof z&&"string"==typeof t.uri?{$ref:""+j(t.uri,e)}:t instanceof Date?{$date:t.getTime()}:Array.isArray(t)?t.map(function(t){return y(t,e)}):c(t,function(t){return o(t)},function(t){return y(t,e)}):t}function g(t){return"string"==typeof t&&t.length>0?/^\d+$/.test(t)?parseInt(t,10):t:Number.isInteger(t)?t:null}function v(t,e){var r=t.indexOf(e+"/");return-1!==r?g(t.substring(r).split("/").pop()):null}function m(t,r){var n=Object.entries(r).find(function(r){var n=e.__read(r,1)[0];return 0===t.indexOf(n+"/")});if(n){var o=e.__read(n,2);return{resourceURI:o[0],resource:o[1]}}}function b(t,e){var r=m(t,e);return!!r&&null!==v(t,r.resourceURI)}function _(t){var e=t.$type,r=t.$id;return("string"==typeof r||Number.isInteger(r))&&"string"==typeof e}function P(t){var e=t.$uri,r=t.$ref,n=t.$type,o=t.$id;return"string"==typeof e?decodeURIComponent(e):"string"==typeof r?decodeURIComponent(r):_({$type:n,$id:o})?"/"+n+"/"+o:""}function O(t,e){return t.includes(e)?t.substring(e.length):t}function j(t,e){return"string"!=typeof e||t.includes(e)?t:""+e+t}function w(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];var n={};try{for(var o=e.__values(t),i=o.next();!i.done;i=o.next()){var a=i.value;Object.assign(n,a)}}catch(t){u={error:t}}finally{try{i&&!i.done&&(s=o.return)&&s.call(o)}finally{if(u)throw u.error}}return n;var u,s}function $(t){return J.getOwnMetadata(k,t)}function T(t,e){J.defineMetadata(k,e,t)}function x(t){return J.getOwnMetadata(D,t)}function I(t,e){J.defineMetadata(D,e,t)}function A(t){return J.getOwnMetadata(G,t.constructor)||Promise}function S(t,e){var r=J.getOwnMetadata(F,t);return r&&r[e]}function R(t,e){var r=s(t)?t:s(t.constructor)?t.constructor:null;if(null!==r){J.defineMetadata(F,Object.assign(J.getOwnMetadata(F,r)||{},(n={},n[e]=!0,n)),r);var n}}function E(t,e){var r=(void 0===e?{}:e).method;return function(e,n){var o=void 0===n?{}:n,i=o.paginate,a=void 0!==i&&i,u=o.cache,c=void 0===u||u,f=s(this),p=""+(f?x(this):this.uri)+t,h={method:r,paginate:a,cache:c};return"GET"===r?h.params=e:["POST","PUT","PATCH"].includes(r)&&(h.body=e),$(f?this:this.constructor).fetch(p,h)}}function q(t,e,r){return t||new Y(e,r)}function N(t){try{return JSON.stringify(t)}catch(t){return}}var C=function(){function t(t,r,n,o){var i=t.potion,a=t.uri;this.items=r,this.options=o,this.potion=i,this.uri=a;var u=e.__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(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}(),U=function(){function t(t){this.$uri=t}return t.prototype.matches=function(t){return a(t)&&this.$uri===t.uri},t}(),M=new WeakSet,H=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}(),J=("undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0).Reflect;!function(){if(!J||!J.getMetadata)throw new Error("Dependency error. reflect-metadata shim is required when using potion-node library")}();var k=Symbol("potion"),D=Symbol("potion:uri"),G=Symbol("potion:promise"),F=Symbol("potion:readonly"),z=function(){function t(t){this.$id=null,a(t)&&Object.assign(this,t)}return t.fetch=function(t,e){var r=(void 0===e?{}:e).cache,n=void 0===r||r,o=x(this);return $(this).fetch(o+"/"+t,{method:"GET",cache:n})},t.query=function(t,e){var r=void 0===e?{}:e,n=r.paginate,o=void 0!==n&&n,i=r.cache,a=void 0===i||i,u=x(this);return $(this).fetch(u,{method:"GET",params:t,paginate:o,cache:a})},t.first=function(t){return this.query(t).then(function(t){return t[0]})},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,e={};return Object.keys(this).filter(function(e){return!e.startsWith("$")&&!S(t.constructor,e)}).forEach(function(r){e[r]=t[r]}),e},t.prototype.save=function(){if(this.uri||this.id)return this.update(this.toJSON());var t=this.constructor;return $(t).fetch(x(t),{method:"POST",body:this.toJSON(),cache:!0})},t.prototype.update=function(t){return void 0===t&&(t={}),$(this.constructor).fetch(this.uri,{cache:!0,method:"PATCH",body:t})},t.prototype.destroy=function(){var t=this.uri,e=$(this.constructor),r=e.cache;return e.fetch(t,{method:"DELETE"}).then(function(){r.get(t)&&r.remove(t)})},t}(),L=function(){function t(t){var e=void 0===t?{}:t,r=e.host,n=void 0===r?"":r,o=e.prefix,i=void 0===o?"":o,a=e.cache;this.resources={},this.Promise=A(this),this.requests=new Map,this.cache=a||new H,this.host=n,this.prefix=i}return t.prototype.register=function(t,e,r){if(!s(e))throw new TypeError("An error occurred while trying to register a resource for "+t+". "+e+" is not a function.");return T(e,this),I(e,t),r&&Array.isArray(r.readonly)&&r.readonly.forEach(function(t){return R(e,t)}),this.resources[t]=e,e},t.prototype.registerAs=function(t,e){var r=this;return function(n){return r.register(t,n,e),n}},t.prototype.request=function(t,e){},t.prototype.fetch=function(t,r,n){var o=O(t,this.prefix),i=e.__assign({},r,n,{origin:[]});return b(t,this.resources)&&Object.assign(i,{origin:[o]}),this.resolve(t,i).then(function(t){return h(t,d(t)),t})},t.prototype.resolve=function(t,e){var r=this,n=this.prefix,o=this.Promise,i=O(t,n);t=j(t,n);var a=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?a():e.cache&&this.cache.has(i)?this.cache.get(i):(this.requests.has(i)||this.requests.set(i,a().then(function(t){return r.requests.delete(i),t},function(e){r.requests.delete(i);var n=f(e,t);return o.reject(n)})),this.requests.get(i))},t.prototype.serialize=function(t){var r=this.prefix,n=t.params;return e.__assign({},t,{params:y(t.paginate?e.__assign({page:1,perPage:25},n):n,r),body:y(t.body,r)})},t.prototype.deserialize=function(t,e,r){var n=this,o=t.headers,i=t.body;return this.fromPotionJSON(i,r.origin).then(function(t){if(r.paginate){var i=o["x-total-count"]||t.length;if(r.pagination instanceof C)return r.pagination.update(t,i);var a=new C({uri:e,potion:n},t,i,r);return Object.assign(r,{pagination:a}),a}return t})},t.prototype.fromPotionJSON=function(t,r){var n=this,o=this.Promise;if("object"==typeof t&&null!==t){if(Array.isArray(t))return o.all(t.map(function(t){return n.fromPotionJSON(t,r)}));if("string"==typeof t.$uri||_(t))return this.parseURI(t).then(function(i){var a=i.resource,u=i.id,s=i.uri,c={$id:u,$uri:s};r.includes(s)||r.push(s);var f=n.parsePotionJSONProperties(t,r);return n.cache.has(s)?o.all([f,n.cache.get(s)]).then(function(t){var r=e.__read(t,2),n=r[0],o=r[1];return Object.assign(o,n,c),o}):n.cache.put(s,f.then(function(t){return Reflect.construct(a,[e.__assign({},t,c)])}))});if("string"==typeof t.$schema)return o.resolve(p(t));if(1===Object.keys(t).length){if("string"==typeof t.$ref)return"#"===t.$ref?o.resolve(t.$ref):this.parseURI(t).then(function(t){var e=t.uri;return r.includes(e)?o.resolve(l(e)):n.resolve(e,{cache:!0,method:"GET",origin:r})});if(void 0!==t.$date)return o.resolve(new Date(t.$date))}return this.parsePotionJSONProperties(t,r)}return o.resolve(t)},t.prototype.parsePotionJSONProperties=function(t,r){var n=this,o=this.Promise,a=Object.entries(t),u=a.map(function(t){var o=e.__read(t,2)[1];return n.fromPotionJSON(o,r)}),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),o=n[0],i=n[1];return e.__assign({},t,(a={},a[o]=i,a));var a},{})})},t.prototype.parseURI=function(t){var e=t.$ref,r=t.$uri,n=t.$type,o=t.$id,i=this.Promise,a=O(P({$ref:e,$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:g(o)};return null===c.id&&Object.assign(c,{id:v(a,s)}),i.resolve(c)}return i.reject(new Error("URI '"+a+"' is an uninterpretable or unknown Potion resource."))},t}(),V={GET:function(t){return E(t,{method:"GET"})},DELETE:function(t){return E(t,{method:"DELETE"})},POST:function(t){return E(t,{method:"POST"})},PATCH:function(t){return E(t,{method:"PATCH"})},PUT:function(t){return E(t,{method:"PUT"})}},W=new r.InjectionToken("PotionResources"),B=new r.InjectionToken("PotionConfig"),Y=function(t){function o(r,n){var o=t.call(this,e.__assign({},n))||this;return o.http=r,o}return e.__extends(o,t),o.prototype.registerFromProvider=function(t){if(t=w.apply(void 0,e.__spread(t.filter(function(t){return!u(t)}))),!u(t))try{for(var r=e.__values(Object.entries(t)),n=r.next();!n.done;n=r.next()){var o=e.__read(n.value,2),i=o[0],a=o[1];if(!this.resources.hasOwnProperty(i))if(Array.isArray(a)){var s=e.__read(a,2),c=s[0],f=s[1];this.register(i,c,f)}else this.register(i,a)}}catch(t){p={error:t}}finally{try{n&&!n.done&&(h=r.return)&&h.call(r)}finally{if(p)throw p.error}}var p,h},o.prototype.request=function(t,r){var o=e.__assign({},r),i=o.params,u=o.body,s=o.method,c=void 0===s?"GET":s,f={headers:new n.HttpHeaders({"content-type":"application/json"}),responseType:"json"};if(a(i)){var p=new n.HttpParams;try{for(var h=e.__values(Object.entries(i)),d=h.next();!d.done;d=h.next()){var l=e.__read(d.value,2),y=l[0],g=l[1];p=p.append(y,JSON.stringify(g))}}catch(t){m={error:t}}finally{try{d&&!d.done&&(b=h.return)&&b.call(h)}finally{if(m)throw m.error}}Object.assign(f,{params:p})}var v="POST"===c||"PUT"===c||"PATCH"===c?new n.HttpRequest(c,t,N(u),f):new n.HttpRequest(c,t,f);return this.http.request(v).filter(function(t){return t instanceof n.HttpResponse}).map(function(t){var r=t.body,n={};try{for(var o=e.__values(t.headers.keys()),i=o.next();!i.done;i=o.next()){var a=i.value;n[a]=t.headers.get(a)}}catch(t){u={error:t}}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 m,b},o.decorators=[{type:r.Injectable}],o.ctorParameters=function(){return[{type:n.HttpClient},{type:void 0,decorators:[{type:r.Optional},{type:r.Inject,args:[B]}]}]},o}(L),Z={provide:Y,useFactory:q,deps:[[new r.Optional,new r.SkipSelf,Y],n.HttpClient,[new r.Optional,new r.Inject(B)]]},K=function(){function t(t,e){t.registerFromProvider(e||[])}return t.decorators=[{type:r.NgModule,args:[{imports:[n.HttpClientModule],providers:[Z]}]}],t.ctorParameters=function(){return[{type:Y,decorators:[{type:r.Inject,args:[r.forwardRef(function(){return Y})]}]},{type:Array,decorators:[{type:r.Optional},{type:r.Inject,args:[W]}]}]},t}();t.Item=z,t.readonly=R,t.Pagination=C,t.PotionBase=L,t.Route=V,t.route=E,t.findPotionResource=m,t.fromSchemaJSON=p,t.getPotionID=v,t.getPotionURI=P,t.hasTypeAndId=_,t.isPotionURI=b,t.parsePotionID=g,t.removePrefixFromURI=O,t.addPrefixToURI=j,t.toPotionJSON=y,t.toCamelCase=i,t.toSnakeCase=o,t.PotionModule=K,t.POTION_RESOURCES=W,t.POTION_CONFIG=B,t.Potion=Y,t.POTION_PROVIDER_FACTORY=q,t.POTION_PROVIDER=Z,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("tslib"),require("@angular/core"),require("@angular/common/http"),require("rxjs/add/operator/filter"),require("rxjs/add/operator/map"),require("rxjs/add/operator/toPromise")):"function"==typeof define&&define.amd?define(["exports","tslib","@angular/core","@angular/common/http","rxjs/add/operator/filter","rxjs/add/operator/map","rxjs/add/operator/toPromise"],e):e(t.potionClient={},t.tslib,t.ng.core,t.ng.common.http)}(this,function(t,e,r,n){"use strict";function o(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 a(t){return"object"==typeof t&&null!==t}function u(t){return 0===Object.keys(t).length}function s(t){return"function"==typeof t}function c(t,r,n){return a(t)&&!Array.isArray(t)?Object.entries(t).map(function(t){var o=e.__read(t,2),i=o[0],a=o[1];return[s(r)?r(i):i,s(n)?n(a):a]}).reduce(function(t,r){var n=e.__read(r,2),o=n[0],i=n[1];return e.__assign({},t,(a={},a[o]=i,a));var a},{}):t}function f(t,e){var r="An error occurred while Potion tried to retrieve a resource";return t instanceof Error?t.message:"string"==typeof t?t:"string"==typeof e?r+" from '"+e+"'.":r+"."}function p(t){return Array.isArray(t)?t.map(function(t){return"object"==typeof t?p(t):t}):a(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?p(o):o]}).reduce(function(t,r){var n=e.__read(r,2),o=n[0],i=n[1];return e.__assign({},t,(a={},a[o]=i,a));var a},{}):t}function h(t,r){if("object"!=typeof t||null===t||t.hasOwnProperty("$schema"))return t;if(M.has(t))return t;if(t instanceof C){var n=t.toArray().map(function(t){return h(t,r)});return t.update(n,t.total)}if(Array.isArray(t))return t.map(function(t){return h(t,r)});if(t instanceof U)return r.get(t.$uri);if(Object.keys(t).length>0){!Array.isArray(t)&&t.uri&&M.add(t);try{for(var o=e.__values(Object.entries(t)),i=o.next();!i.done;i=o.next()){var u=e.__read(i.value,2),s=u[0],c=u[1];if(c instanceof U){var f=r.get(c.$uri);Object.assign(t,(l={},l[s]=f,l))}else a(c)?Object.assign(t,(y={},y[s]=h(c,r),y)):"string"==typeof c&&"#"===c&&Object.assign(t,(g={},g[s]=r.get("#"),g))}}catch(t){p={error:t}}finally{try{i&&!i.done&&(d=o.return)&&d.call(o)}finally{if(p)throw p.error}}return t}return t;var p,d,l,y,g}function d(t,r){var n=new Map;if(a(t)&&Object.keys(t).length>0){if(r||n.set("#",t),M.has(t)||t.hasOwnProperty("$schema"))return new Map;t.uri&&!n.has(t.uri)&&n.set(t.uri,t);var o=Array.isArray(t)||t instanceof C?t:Object.values(t);try{for(var i=e.__values(o),u=i.next();!u.done;u=i.next()){var s=d(u.value,!0);try{for(var c=e.__values(s.entries()),f=c.next();!f.done;f=c.next()){var p=e.__read(f.value,2),h=p[0],l=p[1];n.set(h,l)}}catch(t){v={error:t}}finally{try{f&&!f.done&&(m=c.return)&&m.call(c)}finally{if(v)throw v.error}}}}catch(t){y={error:t}}finally{try{u&&!u.done&&(g=i.return)&&g.call(i)}finally{if(y)throw y.error}}}return n;var y,g,v,m}function l(t){return new U(t)}function y(t,e){return a(t)?t instanceof z&&"string"==typeof t.uri?{$ref:""+j(t.uri,e)}:t instanceof Date?{$date:t.getTime()}:Array.isArray(t)?t.map(function(t){return y(t,e)}):c(t,function(t){return o(t)},function(t){return y(t,e)}):t}function g(t){return"string"==typeof t&&t.length>0?/^\d+$/.test(t)?parseInt(t,10):t:Number.isInteger(t)?t:null}function v(t,e){var r=t.indexOf(e+"/");return-1!==r?g(t.substring(r).split("/").pop()):null}function m(t,r){var n=Object.entries(r).find(function(r){var n=e.__read(r,1)[0];return 0===t.indexOf(n+"/")});if(n){var o=e.__read(n,2);return{resourceURI:o[0],resource:o[1]}}}function b(t,e){var r=m(t,e);return!!r&&null!==v(t,r.resourceURI)}function P(t){var e=t.$type,r=t.$id;return("string"==typeof r||Number.isInteger(r))&&"string"==typeof e}function _(t){var e=t.$uri,r=t.$ref,n=t.$type,o=t.$id;return"string"==typeof e?decodeURIComponent(e):"string"==typeof r?decodeURIComponent(r):P({$type:n,$id:o})?"/"+n+"/"+o:""}function O(t,e){return t.includes(e)?t.substring(e.length):t}function j(t,e){return"string"!=typeof e||t.includes(e)?t:""+e+t}function w(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];var n={};try{for(var o=e.__values(t),i=o.next();!i.done;i=o.next()){var a=i.value;Object.assign(n,a)}}catch(t){u={error:t}}finally{try{i&&!i.done&&(s=o.return)&&s.call(o)}finally{if(u)throw u.error}}return n;var u,s}function $(t){return J.getOwnMetadata(k,t)}function T(t,e){J.defineMetadata(k,e,t)}function x(t){return J.getOwnMetadata(D,t)}function I(t,e){J.defineMetadata(D,e,t)}function A(t){return J.getOwnMetadata(G,t.constructor)||Promise}function S(t,e){var r=J.getOwnMetadata(F,t);return r&&r[e]}function R(t,e){var r=s(t)?t:s(t.constructor)?t.constructor:null;if(null!==r){J.defineMetadata(F,Object.assign(J.getOwnMetadata(F,r)||{},(n={},n[e]=!0,n)),r);var n}}function E(t,e){var r=(void 0===e?{}:e).method;return function(e,n){var o=void 0===n?{}:n,i=o.paginate,a=void 0!==i&&i,u=o.cache,c=void 0===u||u,f=s(this),p=""+(f?x(this):this.uri)+t,h={method:r,paginate:a,cache:c};return"GET"===r?h.params=e:["POST","PUT","PATCH"].includes(r)&&(h.body=e),$(f?this:this.constructor).fetch(p,h)}}function q(t,e,r){return t||new Y(e,r)}function N(t){try{return JSON.stringify(t)}catch(t){return}}var C=function(){function t(t,r,n,o){var i=t.potion,a=t.uri;this.items=r,this.options=o,this.potion=i,this.uri=a;var u=e.__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(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}(),U=function(){function t(t){this.$uri=t}return t.prototype.matches=function(t){return a(t)&&this.$uri===t.uri},t}(),M=new WeakSet,H=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}(),J=("undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0).Reflect;!function(){if(!J||!J.getMetadata)throw new Error("Dependency error. reflect-metadata shim is required when using potion-node library")}();var k=Symbol("potion"),D=Symbol("potion:uri"),G=Symbol("potion:promise"),F=Symbol("potion:readonly"),z=function(){function t(t){this.$id=null,a(t)&&Object.assign(this,t)}return t.fetch=function(t,e){var r=(void 0===e?{}:e).cache,n=void 0===r||r,o=x(this);return $(this).fetch(o+"/"+t,{method:"GET",cache:n})},t.query=function(t,e){var r=void 0===e?{}:e,n=r.paginate,o=void 0!==n&&n,i=r.cache,a=void 0===i||i,u=x(this);return $(this).fetch(u,{method:"GET",params:t,paginate:o,cache:a})},t.first=function(t){return this.query(t).then(function(t){return t[0]})},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,e={};return Object.keys(this).filter(function(e){return!e.startsWith("$")&&!S(t.constructor,e)}).forEach(function(r){e[r]=t[r]}),e},t.prototype.save=function(){if(this.uri||this.id)return this.update(this.toJSON());var t=this.constructor;return $(t).fetch(x(t),{method:"POST",body:this.toJSON(),cache:!0})},t.prototype.update=function(t){return void 0===t&&(t={}),$(this.constructor).fetch(this.uri,{cache:!0,method:"PATCH",body:t})},t.prototype.destroy=function(){var t=this.uri,e=$(this.constructor),r=e.cache;return e.fetch(t,{method:"DELETE"}).then(function(){r.get(t)&&r.remove(t)})},t}(),L=function(){function t(t){var e=void 0===t?{}:t,r=e.host,n=void 0===r?"":r,o=e.prefix,i=void 0===o?"":o,a=e.cache;this.resources={},this.Promise=A(this),this.requests=new Map,this.cache=a||new H,this.host=n,this.prefix=i}return t.prototype.register=function(t,e,r){if(!s(e))throw new TypeError("An error occurred while trying to register a resource for "+t+". "+e+" is not a function.");return T(e,this),I(e,t),r&&Array.isArray(r.readonly)&&r.readonly.forEach(function(t){return R(e,t)}),this.resources[t]=e,e},t.prototype.registerAs=function(t,e){var r=this;return function(n){return r.register(t,n,e),n}},t.prototype.request=function(t,e){},t.prototype.fetch=function(t,r,n){var o=O(t,this.prefix),i=e.__assign({},r,n,{origin:[]});return b(t,this.resources)&&Object.assign(i,{origin:[o]}),this.resolve(t,i).then(function(t){return h(t,d(t)),t})},t.prototype.resolve=function(t,e){var r=this,n=this.prefix,o=this.Promise,i=O(t,n);t=j(t,n);var a=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?a():e.cache&&this.cache.has(i)?this.cache.get(i):(this.requests.has(i)||this.requests.set(i,a().then(function(t){return r.requests.delete(i),t},function(e){r.requests.delete(i);var n=f(e,t);return o.reject(n)})),this.requests.get(i))},t.prototype.serialize=function(t){var r=this.prefix,n=t.params;return e.__assign({},t,{params:y(t.paginate?e.__assign({page:1,perPage:25},n):n,r),body:y(t.body,r)})},t.prototype.deserialize=function(t,e,r){var n=this,o=t.headers,i=t.body;return this.fromPotionJSON(i,r.origin).then(function(t){if(r.paginate){var i=o["x-total-count"]||t.length;if(r.pagination instanceof C)return r.pagination.update(t,i);var a=new C({uri:e,potion:n},t,i,r);return Object.assign(r,{pagination:a}),a}return t})},t.prototype.fromPotionJSON=function(t,r){var n=this,o=this.Promise;if("object"==typeof t&&null!==t){if(Array.isArray(t))return o.all(t.map(function(t){return n.fromPotionJSON(t,r)}));if("string"==typeof t.$uri||P(t))return this.parseURI(t).then(function(i){var a=i.resource,u=i.id,s=i.uri,c={$id:u,$uri:s};r.includes(s)||r.push(s);var f=n.parsePotionJSONProperties(t,r);return n.cache.has(s)?o.all([f,n.cache.get(s)]).then(function(t){var r=e.__read(t,2),n=r[0],o=r[1];return Object.assign(o,n,c),o}):n.cache.put(s,f.then(function(t){return Reflect.construct(a,[e.__assign({},t,c)])}))});if("string"==typeof t.$schema)return o.resolve(p(t));if(1===Object.keys(t).length){if("string"==typeof t.$ref)return"#"===t.$ref?o.resolve(t.$ref):this.parseURI(t).then(function(t){var e=t.uri;return r.includes(e)?o.resolve(l(e)):n.resolve(e,{cache:!0,method:"GET",origin:r})});if(void 0!==t.$date)return o.resolve(new Date(t.$date))}return this.parsePotionJSONProperties(t,r)}return o.resolve(t)},t.prototype.parsePotionJSONProperties=function(t,r){var n=this,o=this.Promise,a=Object.entries(t),u=a.map(function(t){var o=e.__read(t,2)[1];return n.fromPotionJSON(o,r)}),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),o=n[0],i=n[1];return e.__assign({},t,(a={},a[o]=i,a));var a},{})})},t.prototype.parseURI=function(t){var e=t.$ref,r=t.$uri,n=t.$type,o=t.$id,i=this.Promise,a=O(_({$ref:e,$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:g(o)};return null===c.id&&Object.assign(c,{id:v(a,s)}),i.resolve(c)}return i.reject(new Error("URI '"+a+"' is an uninterpretable or unknown Potion resource."))},t}(),V={GET:function(t){return E(t,{method:"GET"})},DELETE:function(t){return E(t,{method:"DELETE"})},POST:function(t){return E(t,{method:"POST"})},PATCH:function(t){return E(t,{method:"PATCH"})},PUT:function(t){return E(t,{method:"PUT"})}},W=new r.InjectionToken("PotionResources"),B=new r.InjectionToken("PotionConfig"),Y=function(t){function o(r,n){var o=t.call(this,e.__assign({},n))||this;return o.http=r,o}return e.__extends(o,t),o.prototype.registerFromProvider=function(t){if(t=w.apply(void 0,e.__spread(t.filter(function(t){return!u(t)}))),!u(t))try{for(var r=e.__values(Object.entries(t)),n=r.next();!n.done;n=r.next()){var o=e.__read(n.value,2),i=o[0],a=o[1];if(!this.resources.hasOwnProperty(i))if(Array.isArray(a)){var s=e.__read(a,2),c=s[0],f=s[1];this.register(i,c,f)}else this.register(i,a)}}catch(t){p={error:t}}finally{try{n&&!n.done&&(h=r.return)&&h.call(r)}finally{if(p)throw p.error}}var p,h},o.prototype.request=function(t,r){var o=e.__assign({},r),i=o.params,u=o.body,s=o.method,c=void 0===s?"GET":s,f={headers:new n.HttpHeaders({"content-type":"application/json"}),responseType:"json"};if(a(i)){var p=new n.HttpParams;try{for(var h=e.__values(Object.entries(i)),d=h.next();!d.done;d=h.next()){var l=e.__read(d.value,2),y=l[0],g=l[1];p=p.append(y,JSON.stringify(g))}}catch(t){m={error:t}}finally{try{d&&!d.done&&(b=h.return)&&b.call(h)}finally{if(m)throw m.error}}Object.assign(f,{params:p})}var v="POST"===c||"PUT"===c||"PATCH"===c?new n.HttpRequest(c,t,N(u),f):new n.HttpRequest(c,t,f);return this.http.request(v).filter(function(t){return t instanceof n.HttpResponse}).map(function(t){var r=t.body,n={};try{for(var o=e.__values(t.headers.keys()),i=o.next();!i.done;i=o.next()){var a=i.value;n[a]=t.headers.get(a)}}catch(t){u={error:t}}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 m,b},o.decorators=[{type:r.Injectable}],o.ctorParameters=function(){return[{type:n.HttpClient},{type:void 0,decorators:[{type:r.Optional},{type:r.Inject,args:[B]}]}]},o}(L),Z={provide:Y,useFactory:q,deps:[[new r.Optional,new r.SkipSelf,Y],n.HttpClient,[new r.Optional,new r.Inject(B)]]},K=function(){function t(t,e){t.registerFromProvider(e||[])}return t.decorators=[{type:r.NgModule,args:[{imports:[n.HttpClientModule],providers:[Z]}]}],t.ctorParameters=function(){return[{type:Y,decorators:[{type:r.Inject,args:[r.forwardRef(function(){return Y})]}]},{type:Array,decorators:[{type:r.Optional},{type:r.Inject,args:[W]}]}]},t}();t.Item=z,t.readonly=R,t.Pagination=C,t.PotionBase=L,t.Route=V,t.route=E,t.findPotionResource=m,t.fromSchemaJSON=p,t.getPotionID=v,t.getPotionURI=_,t.hasTypeAndId=P,t.isPotionURI=b,t.parsePotionID=g,t.removePrefixFromURI=O,t.addPrefixToURI=j,t.toPotionJSON=y,t.toCamelCase=i,t.toSnakeCase=o,t.PotionModule=K,t.POTION_RESOURCES=W,t.POTION_CONFIG=B,t.Potion=Y,t.POTION_PROVIDER_FACTORY=q,t.POTION_PROVIDER=Z,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=ng.umd.min.js.map |
{ | ||
"name": "potion-client", | ||
"version": "3.0.1", | ||
"version": "3.0.2", | ||
"description": "A ES6 client for APIs written in Flask-Potion", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
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 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
1222253
11347