potion-client
Advanced tools
Comparing version 2.1.0 to 2.1.1
@@ -742,2 +742,5 @@ import { __assign, __extends, __read, __spread, __values } from 'tslib'; | ||
PotionBase.prototype.register = function (uri, resource, options) { | ||
if (!isFunction(resource)) { | ||
throw new TypeError("An error occurred while trying to register a resource for " + uri + ". " + resource + " is not a function."); | ||
} | ||
decorateCtorWithPotionInstance(resource, this); | ||
@@ -744,0 +747,0 @@ decorateCtorWithPotionURI(resource, uri); |
@@ -636,2 +636,5 @@ import { module as module$1 } from 'angular'; | ||
register(uri, resource, options) { | ||
if (!isFunction(resource)) { | ||
throw new TypeError(`An error occurred while trying to register a resource for ${uri}. ${resource} is not a function.`); | ||
} | ||
decorateCtorWithPotionInstance(resource, this); | ||
@@ -638,0 +641,0 @@ decorateCtorWithPotionURI(resource, uri); |
@@ -743,2 +743,5 @@ (function (global, factory) { | ||
PotionBase.prototype.register = function (uri, resource, options) { | ||
if (!isFunction(resource)) { | ||
throw new TypeError("An error occurred while trying to register a resource for " + uri + ". " + resource + " is not a function."); | ||
} | ||
decorateCtorWithPotionInstance(resource, this); | ||
@@ -745,0 +748,0 @@ decorateCtorWithPotionURI(resource, uri); |
@@ -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.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 Object.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 Object.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 U){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 q)return r.find(function(e){return t.matches(e.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);!function(e,n){if(n instanceof q){var i=r.find(function(t){return n.matches(t.uri)});Object.assign(t,(u={},u[e]=i,u))}else o(n)&&Object.assign(t,(a={},a[e]=f(n,r),a));var u,a}(a[0],a[1])}}catch(t){s={error:t}}finally{try{u&&!u.done&&(c=i.return)&&c.call(i)}finally{if(s)throw s.error}}return t}return t;var s,c}function p(t){var r=[];if(o(t)&&Object.keys(t).length>0){if(M.has(t))return[];t.uri&&r.push(t);var n=Array.isArray(t)||t instanceof U?t:Object.values(t);try{for(var i=e.__values(n),u=i.next();!u.done;u=i.next()){var a=u.value;r.push.apply(r,e.__spread(p(a)))}}catch(t){h={error:t}}finally{try{u&&!u.done&&(d=i.return)&&d.call(i)}finally{if(h)throw h.error}}}var s=[];try{for(var c=e.__values(r),f=c.next();!f.done;f=c.next())!function(t){-1===s.findIndex(function(e){return t.uri===e.uri})&&s.push(t)}(f.value)}catch(t){l={error:t}}finally{try{f&&!f.done&&(g=c.return)&&g.call(c)}finally{if(l)throw l.error}}return s;var h,d,l,g}function h(t){return new q(t)}function d(t,e){return o(t)?t instanceof R&&"string"==typeof t.uri?{$ref:""+O(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 g(t,e){var r=t.indexOf(e+"/");return-1!==r?l(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 v(t,e){var r=y(t,e);return!!r&&null!==g(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 P(t,e){return t.includes(e)?t.substring(e.length):t}function O(t,e){return"string"!=typeof e||t.includes(e)?t:""+e+t}function _(t){return C.getOwnMetadata(J,t)}function $(t,e){C.defineMetadata(J,e,t)}function j(t){return C.getOwnMetadata(D,t)}function w(t,e){C.defineMetadata(D,e,t)}function T(t){return C.getOwnMetadata(G,t.constructor)||Promise}function A(t,e){C.defineMetadata(G,e,t)}function S(t,e){var r=C.getOwnMetadata(k,t);return r&&r[e]}function x(t,e){var r=u(t)?t:u(t.constructor)?t.constructor:null;if(null!==r){C.defineMetadata(k,Object.assign(C.getOwnMetadata(k,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 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.search=e:["POST","PUT","PATCH"].includes(r)&&(h.data=e),_(f?this:this.constructor).fetch(p,h)}}function I(){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.search,s=n.data,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={data:t.data};return e&&(r.headers=e()),r})},r}(z),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}var R=function(){function t(t){void 0===t&&(t={}),this.$id=null,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 _(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 _(this).fetch(a,{method:"GET",search:t,paginate:i,cache:u})},t.first=function(t){function e(t){return t[0]}return this.query(t).then(e)},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(j(t),{method:"POST",data:this.toJSON(),cache:!0})},t.prototype.update=function(t){return void 0===t&&(t={}),_(this.constructor).fetch(this.uri,{cache:!0,method:"PATCH",data:t})},t.prototype.destroy=function(){function t(){n.get(e)&&n.remove(e)}var e=this.uri,r=_(this.constructor),n=r.cache;return r.fetch(e,{method:"DELETE"}).then(t)},t}(),U=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.search),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.search.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}(),q=function(){function t(t){this.$uri=t}return t.prototype.matches=function(t){return this.$uri===t},t}(),M=new WeakSet,N=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}(),C=function(){return"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0}().Reflect;!function(){if(!C||!C.getMetadata)throw new Error("Dependency error. reflect-metadata shim is required when using potion-node library")}();var J=Symbol("potion"),D=Symbol("potion:uri"),G=Symbol("potion:promise"),k=Symbol("potion:readonly"),z=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 N,this.host=n,this.prefix=o}return t.prototype.register=function(t,e,r){return $(e,this),w(e,t),r&&Array.isArray(r.readonly)&&r.readonly.forEach(function(t){return x(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=P(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,i=n.Promise,o=n.prefix,u=P(t,o);t=O(t,o);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.search?a():e.cache&&this.cache.has(u)?this.cache.get(u):(this.requests.has(u)||this.requests.set(u,a().then(function(t){return r.requests.delete(u),t},function(e){r.requests.delete(u);var n=s(e,t);return i.reject(n)})),this.requests.get(u))},t.prototype.serialize=function(t){var r=this.prefix,n=t.search;return e.__assign({},t,{search:d(t.paginate?e.__assign({page:1,perPage:25},n):n,r),data:d(t.data,r)})},t.prototype.deserialize=function(t,e,r){var n=this,i=t.data,o=t.headers;return this.fromPotionJSON(i,r.origin).then(function(t){if(r.paginate){var i=o["x-total-count"]||t.length;if(r.pagination instanceof U)return r.pagination.update(t,i);var u=new U({uri:e,potion:n},t,i,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 Object.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=P(b({$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},f=l(i);return null!==f?Object.assign(c,{id:f}):Object.assign(c,{id:g(u,s)}),o.resolve(c)}return o.reject(new Error("URI '"+u+"' is an uninterpretable or unknown Potion resource."))},t}(),H={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"})}},L=r.module("potion",[]).provider("potion",I);t.potion=L,t.Item=R,t.readonly=x,t.Pagination=U,t.PotionBase=z,t.Route=H,t.route=E,t.findPotionResource=y,t.fromSchemaJSON=c,t.getPotionID=g,t.getPotionURI=b,t.hasTypeAndId=m,t.isPotionURI=v,t.parsePotionID=l,t.removePrefixFromURI=P,t.addPrefixToURI=O,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.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 Object.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 Object.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 U){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 q)return r.find(function(e){return t.matches(e.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);!function(e,n){if(n instanceof q){var i=r.find(function(t){return n.matches(t.uri)});Object.assign(t,(u={},u[e]=i,u))}else o(n)&&Object.assign(t,(a={},a[e]=f(n,r),a));var u,a}(a[0],a[1])}}catch(t){s={error:t}}finally{try{u&&!u.done&&(c=i.return)&&c.call(i)}finally{if(s)throw s.error}}return t}return t;var s,c}function p(t){var r=[];if(o(t)&&Object.keys(t).length>0){if(M.has(t))return[];t.uri&&r.push(t);var n=Array.isArray(t)||t instanceof U?t:Object.values(t);try{for(var i=e.__values(n),u=i.next();!u.done;u=i.next()){var a=u.value;r.push.apply(r,e.__spread(p(a)))}}catch(t){h={error:t}}finally{try{u&&!u.done&&(d=i.return)&&d.call(i)}finally{if(h)throw h.error}}}var s=[];try{for(var c=e.__values(r),f=c.next();!f.done;f=c.next())!function(t){-1===s.findIndex(function(e){return t.uri===e.uri})&&s.push(t)}(f.value)}catch(t){l={error:t}}finally{try{f&&!f.done&&(g=c.return)&&g.call(c)}finally{if(l)throw l.error}}return s;var h,d,l,g}function h(t){return new q(t)}function d(t,e){return o(t)?t instanceof R&&"string"==typeof t.uri?{$ref:""+O(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 g(t,e){var r=t.indexOf(e+"/");return-1!==r?l(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 v(t,e){var r=y(t,e);return!!r&&null!==g(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 P(t,e){return t.includes(e)?t.substring(e.length):t}function O(t,e){return"string"!=typeof e||t.includes(e)?t:""+e+t}function _(t){return C.getOwnMetadata(J,t)}function $(t,e){C.defineMetadata(J,e,t)}function j(t){return C.getOwnMetadata(D,t)}function w(t,e){C.defineMetadata(D,e,t)}function T(t){return C.getOwnMetadata(G,t.constructor)||Promise}function A(t,e){C.defineMetadata(G,e,t)}function S(t,e){var r=C.getOwnMetadata(k,t);return r&&r[e]}function E(t,e){var r=u(t)?t:u(t.constructor)?t.constructor:null;if(null!==r){C.defineMetadata(k,Object.assign(C.getOwnMetadata(k,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.search=e:["POST","PUT","PATCH"].includes(r)&&(h.data=e),_(f?this:this.constructor).fetch(p,h)}}function I(){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.search,s=n.data,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={data:t.data};return e&&(r.headers=e()),r})},r}(z),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}var R=function(){function t(t){void 0===t&&(t={}),this.$id=null,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 _(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 _(this).fetch(a,{method:"GET",search:t,paginate:i,cache:u})},t.first=function(t){function e(t){return t[0]}return this.query(t).then(e)},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(j(t),{method:"POST",data:this.toJSON(),cache:!0})},t.prototype.update=function(t){return void 0===t&&(t={}),_(this.constructor).fetch(this.uri,{cache:!0,method:"PATCH",data:t})},t.prototype.destroy=function(){function t(){n.get(e)&&n.remove(e)}var e=this.uri,r=_(this.constructor),n=r.cache;return r.fetch(e,{method:"DELETE"}).then(t)},t}(),U=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.search),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.search.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}(),q=function(){function t(t){this.$uri=t}return t.prototype.matches=function(t){return this.$uri===t},t}(),M=new WeakSet,N=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}(),C=function(){return"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0}().Reflect;!function(){if(!C||!C.getMetadata)throw new Error("Dependency error. reflect-metadata shim is required when using potion-node library")}();var J=Symbol("potion"),D=Symbol("potion:uri"),G=Symbol("potion:promise"),k=Symbol("potion:readonly"),z=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 N,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=P(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,i=n.Promise,o=n.prefix,u=P(t,o);t=O(t,o);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.search?a():e.cache&&this.cache.has(u)?this.cache.get(u):(this.requests.has(u)||this.requests.set(u,a().then(function(t){return r.requests.delete(u),t},function(e){r.requests.delete(u);var n=s(e,t);return i.reject(n)})),this.requests.get(u))},t.prototype.serialize=function(t){var r=this.prefix,n=t.search;return e.__assign({},t,{search:d(t.paginate?e.__assign({page:1,perPage:25},n):n,r),data:d(t.data,r)})},t.prototype.deserialize=function(t,e,r){var n=this,i=t.data,o=t.headers;return this.fromPotionJSON(i,r.origin).then(function(t){if(r.paginate){var i=o["x-total-count"]||t.length;if(r.pagination instanceof U)return r.pagination.update(t,i);var u=new U({uri:e,potion:n},t,i,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 Object.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=P(b({$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},f=l(i);return null!==f?Object.assign(c,{id:f}):Object.assign(c,{id:g(u,s)}),o.resolve(c)}return o.reject(new Error("URI '"+u+"' is an uninterpretable or unknown Potion resource."))},t}(),H={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"})}},L=r.module("potion",[]).provider("potion",I);t.potion=L,t.Item=R,t.readonly=E,t.Pagination=U,t.PotionBase=z,t.Route=H,t.route=x,t.findPotionResource=y,t.fromSchemaJSON=c,t.getPotionID=g,t.getPotionURI=b,t.hasTypeAndId=m,t.isPotionURI=v,t.parsePotionID=l,t.removePrefixFromURI=P,t.addPrefixToURI=O,t.toPotionJSON=d,t.toCamelCase=i,t.toSnakeCase=n,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=angularjs.umd.min.js.map |
@@ -0,1 +1,6 @@ | ||
<a name="2.1.1"></a> | ||
## [2.1.1](https://github.com/biosustain/potion-node/compare/v2.1.0...v2.1.1) (2017-06-05) | ||
<a name="2.1.0"></a> | ||
@@ -2,0 +7,0 @@ # [2.1.0](https://github.com/biosustain/potion-node/compare/v2.0.2...v2.1.0) (2017-06-03) |
@@ -738,2 +738,5 @@ import { __assign, __extends, __read, __spread, __values } from 'tslib'; | ||
PotionBase.prototype.register = function (uri, resource, options) { | ||
if (!isFunction(resource)) { | ||
throw new TypeError("An error occurred while trying to register a resource for " + uri + ". " + resource + " is not a function."); | ||
} | ||
decorateCtorWithPotionInstance(resource, this); | ||
@@ -740,0 +743,0 @@ decorateCtorWithPotionURI(resource, uri); |
@@ -631,2 +631,5 @@ /** | ||
register(uri, resource, options) { | ||
if (!isFunction(resource)) { | ||
throw new TypeError(`An error occurred while trying to register a resource for ${uri}. ${resource} is not a function.`); | ||
} | ||
decorateCtorWithPotionInstance(resource, this); | ||
@@ -633,0 +636,0 @@ decorateCtorWithPotionURI(resource, uri); |
@@ -741,2 +741,5 @@ (function (global, factory) { | ||
PotionBase.prototype.register = function (uri, resource, options) { | ||
if (!isFunction(resource)) { | ||
throw new TypeError("An error occurred while trying to register a resource for " + uri + ". " + resource + " is not a function."); | ||
} | ||
decorateCtorWithPotionInstance(resource, this); | ||
@@ -743,0 +746,0 @@ decorateCtorWithPotionURI(resource, uri); |
@@ -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.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 Object.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 Object.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 E){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.find(function(e){return t.matches(e.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);!function(e,n){if(n instanceof I){var o=r.find(function(t){return n.matches(t.uri)});Object.assign(t,(u={},u[e]=o,u))}else i(n)&&Object.assign(t,(a={},a[e]=c(n,r),a));var u,a}(a[0],a[1])}}catch(t){s={error:t}}finally{try{u&&!u.done&&(f=o.return)&&f.call(o)}finally{if(s)throw s.error}}return t}return t;var s,f}function f(t){var r=[];if(i(t)&&Object.keys(t).length>0){if(R.has(t))return[];t.uri&&r.push(t);var n=Array.isArray(t)||t instanceof E?t:Object.values(t);try{for(var o=e.__values(n),u=o.next();!u.done;u=o.next()){var a=u.value;r.push.apply(r,e.__spread(f(a)))}}catch(t){p={error:t}}finally{try{u&&!u.done&&(d=o.return)&&d.call(o)}finally{if(p)throw p.error}}}var s=[];try{for(var c=e.__values(r),h=c.next();!h.done;h=c.next())!function(t){-1===s.findIndex(function(e){return t.uri===e.uri})&&s.push(t)}(h.value)}catch(t){l={error:t}}finally{try{h&&!h.done&&(y=c.return)&&y.call(c)}finally{if(l)throw l.error}}return s;var p,d,l,y}function h(t){return new I(t)}function p(t,e){return i(t)?t instanceof x&&"string"==typeof t.uri?{$ref:""+O(t.uri,e)}:t instanceof Date?{$date:t.getTime()}:Array.isArray(t)?t.map(function(t){return p(t,e)}):u(t,function(t){return r(t)},function(t){return p(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 O(t,e){return"string"!=typeof e||t.includes(e)?t:""+e+t}function P(t){return N.getOwnMetadata(q,t)}function _(t,e){N.defineMetadata(q,e,t)}function j(t){return N.getOwnMetadata(C,t)}function $(t,e){N.defineMetadata(C,e,t)}function w(t){return N.getOwnMetadata(J,t.constructor)||Promise}function T(t,e){var r=N.getOwnMetadata(M,t);return r&&r[e]}function A(t,e){var r=o(t)?t:o(t.constructor)?t.constructor:null;if(null!==r){N.defineMetadata(M,Object.assign(N.getOwnMetadata(M,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),h=""+(f?j(this):this.uri)+t,p={method:r,paginate:a,cache:c};return"GET"===r?p.search=e:["POST","PUT","PATCH"].includes(r)&&(p.data=e),P(f?this:this.constructor).fetch(h,p)}}var x=function(){function t(t){void 0===t&&(t={}),this.$id=null,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 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=j(this);return P(this).fetch(a,{method:"GET",search:t,paginate:i,cache:u})},t.first=function(t){function e(t){return t[0]}return this.query(t).then(e)},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(j(t),{method:"POST",data:this.toJSON(),cache:!0})},t.prototype.update=function(t){return void 0===t&&(t={}),P(this.constructor).fetch(this.uri,{cache:!0,method:"PATCH",data:t})},t.prototype.destroy=function(){function t(){n.get(e)&&n.remove(e)}var e=this.uri,r=P(this.constructor),n=r.cache;return r.fetch(e,{method:"DELETE"}).then(t)},t}(),E=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.search),s=a.page,c=void 0===s?1:s,f=a.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.search.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 this.$uri===t},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}(),N=function(){return"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 q=Symbol("potion"),C=Symbol("potion:uri"),J=Symbol("potion:promise"),M=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){return _(e,this),$(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,i=n.Promise,o=n.prefix,u=b(t,o);t=O(t,o);var s=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.search?s():e.cache&&this.cache.has(u)?this.cache.get(u):(this.requests.has(u)||this.requests.set(u,s().then(function(t){return r.requests.delete(u),t},function(e){r.requests.delete(u);var n=a(e,t);return i.reject(n)})),this.requests.get(u))},t.prototype.serialize=function(t){var r=this.prefix,n=t.search;return e.__assign({},t,{search:p(t.paginate?e.__assign({page:1,perPage:25},n):n,r),data:p(t.data,r)})},t.prototype.deserialize=function(t,e,r){var n=this,i=t.data,o=t.headers;return this.fromPotionJSON(i,r.origin).then(function(t){if(r.paginate){var i=o["x-total-count"]||t.length;if(r.pagination instanceof E)return r.pagination.update(t,i);var u=new E({uri:e,potion:n},t,i,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(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 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 Object.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},f=d(i);return null!==f?Object.assign(c,{id:f}):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.search,a=n.data,s=n.cache,c=void 0===s||s,f=new Headers,h={method:o,cache:c?"default":"no-cache",credentials:"include"};if(a&&(f.set("Accept","application/json"),f.set("Content-Type","application/json"),h.body=JSON.stringify(a)),Object.assign(h,{headers:f}),u){var p=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===p&&(t+="?"),t+=m+"="+b,p<l&&(t+="&"),p++}}catch(t){O={error:t}}finally{try{g&&!g.done&&(P=y.return)&&P.call(y)}finally{if(O)throw O.error}}}return fetch(new Request(t,h),h).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,data:t}},function(t){return t})}var r=new Error(t.statusText);throw Object.assign(r,{response:t}),r});var O,P},r}(k);t.Potion=G,t.Item=x,t.readonly=A,t.Pagination=E,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=O,t.toPotionJSON=p,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.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 Object.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 Object.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 E){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.find(function(e){return t.matches(e.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);!function(e,n){if(n instanceof I){var o=r.find(function(t){return n.matches(t.uri)});Object.assign(t,(u={},u[e]=o,u))}else i(n)&&Object.assign(t,(a={},a[e]=c(n,r),a));var u,a}(a[0],a[1])}}catch(t){s={error:t}}finally{try{u&&!u.done&&(f=o.return)&&f.call(o)}finally{if(s)throw s.error}}return t}return t;var s,f}function f(t){var r=[];if(i(t)&&Object.keys(t).length>0){if(R.has(t))return[];t.uri&&r.push(t);var n=Array.isArray(t)||t instanceof E?t:Object.values(t);try{for(var o=e.__values(n),u=o.next();!u.done;u=o.next()){var a=u.value;r.push.apply(r,e.__spread(f(a)))}}catch(t){p={error:t}}finally{try{u&&!u.done&&(d=o.return)&&d.call(o)}finally{if(p)throw p.error}}}var s=[];try{for(var c=e.__values(r),h=c.next();!h.done;h=c.next())!function(t){-1===s.findIndex(function(e){return t.uri===e.uri})&&s.push(t)}(h.value)}catch(t){l={error:t}}finally{try{h&&!h.done&&(y=c.return)&&y.call(c)}finally{if(l)throw l.error}}return s;var p,d,l,y}function h(t){return new I(t)}function p(t,e){return i(t)?t instanceof x&&"string"==typeof t.uri?{$ref:""+O(t.uri,e)}:t instanceof Date?{$date:t.getTime()}:Array.isArray(t)?t.map(function(t){return p(t,e)}):u(t,function(t){return r(t)},function(t){return p(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 O(t,e){return"string"!=typeof e||t.includes(e)?t:""+e+t}function P(t){return N.getOwnMetadata(q,t)}function _(t,e){N.defineMetadata(q,e,t)}function j(t){return N.getOwnMetadata(C,t)}function $(t,e){N.defineMetadata(C,e,t)}function w(t){return N.getOwnMetadata(J,t.constructor)||Promise}function T(t,e){var r=N.getOwnMetadata(M,t);return r&&r[e]}function A(t,e){var r=o(t)?t:o(t.constructor)?t.constructor:null;if(null!==r){N.defineMetadata(M,Object.assign(N.getOwnMetadata(M,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),h=""+(f?j(this):this.uri)+t,p={method:r,paginate:a,cache:c};return"GET"===r?p.search=e:["POST","PUT","PATCH"].includes(r)&&(p.data=e),P(f?this:this.constructor).fetch(h,p)}}var x=function(){function t(t){void 0===t&&(t={}),this.$id=null,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 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=j(this);return P(this).fetch(a,{method:"GET",search:t,paginate:i,cache:u})},t.first=function(t){function e(t){return t[0]}return this.query(t).then(e)},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(j(t),{method:"POST",data:this.toJSON(),cache:!0})},t.prototype.update=function(t){return void 0===t&&(t={}),P(this.constructor).fetch(this.uri,{cache:!0,method:"PATCH",data:t})},t.prototype.destroy=function(){function t(){n.get(e)&&n.remove(e)}var e=this.uri,r=P(this.constructor),n=r.cache;return r.fetch(e,{method:"DELETE"}).then(t)},t}(),E=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.search),s=a.page,c=void 0===s?1:s,f=a.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.search.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 this.$uri===t},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}(),N=function(){return"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 q=Symbol("potion"),C=Symbol("potion:uri"),J=Symbol("potion:promise"),M=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 _(e,this),$(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,i=n.Promise,o=n.prefix,u=b(t,o);t=O(t,o);var s=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.search?s():e.cache&&this.cache.has(u)?this.cache.get(u):(this.requests.has(u)||this.requests.set(u,s().then(function(t){return r.requests.delete(u),t},function(e){r.requests.delete(u);var n=a(e,t);return i.reject(n)})),this.requests.get(u))},t.prototype.serialize=function(t){var r=this.prefix,n=t.search;return e.__assign({},t,{search:p(t.paginate?e.__assign({page:1,perPage:25},n):n,r),data:p(t.data,r)})},t.prototype.deserialize=function(t,e,r){var n=this,i=t.data,o=t.headers;return this.fromPotionJSON(i,r.origin).then(function(t){if(r.paginate){var i=o["x-total-count"]||t.length;if(r.pagination instanceof E)return r.pagination.update(t,i);var u=new E({uri:e,potion:n},t,i,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(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 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 Object.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},f=d(i);return null!==f?Object.assign(c,{id:f}):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.search,a=n.data,s=n.cache,c=void 0===s||s,f=new Headers,h={method:o,cache:c?"default":"no-cache",credentials:"include"};if(a&&(f.set("Accept","application/json"),f.set("Content-Type","application/json"),h.body=JSON.stringify(a)),Object.assign(h,{headers:f}),u){var p=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===p&&(t+="?"),t+=m+"="+b,p<l&&(t+="&"),p++}}catch(t){O={error:t}}finally{try{g&&!g.done&&(P=y.return)&&P.call(y)}finally{if(O)throw O.error}}}return fetch(new Request(t,h),h).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,data:t}},function(t){return t})}var r=new Error(t.statusText);throw Object.assign(r,{response:t}),r});var O,P},r}(k);t.Potion=G,t.Item=x,t.readonly=A,t.Pagination=E,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=O,t.toPotionJSON=p,t.toCamelCase=n,t.toSnakeCase=r,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=fetch.umd.min.js.map |
@@ -951,2 +951,5 @@ import { __assign, __extends, __read, __spread, __values } from 'tslib'; | ||
PotionBase.prototype.register = function (uri, resource, options) { | ||
if (!isFunction(resource)) { | ||
throw new TypeError("An error occurred while trying to register a resource for " + uri + ". " + resource + " is not a function."); | ||
} | ||
decorateCtorWithPotionInstance(resource, this); | ||
@@ -953,0 +956,0 @@ decorateCtorWithPotionURI(resource, uri); |
@@ -830,2 +830,5 @@ import { Inject, Injectable, InjectionToken, NgModule, Optional, SkipSelf, forwardRef } from '@angular/core'; | ||
register(uri, resource, options) { | ||
if (!isFunction(resource)) { | ||
throw new TypeError(`An error occurred while trying to register a resource for ${uri}. ${resource} is not a function.`); | ||
} | ||
decorateCtorWithPotionInstance(resource, this); | ||
@@ -832,0 +835,0 @@ decorateCtorWithPotionURI(resource, uri); |
@@ -950,2 +950,5 @@ (function (global, factory) { | ||
PotionBase.prototype.register = function (uri, resource, options) { | ||
if (!isFunction(resource)) { | ||
throw new TypeError("An error occurred while trying to register a resource for " + uri + ". " + resource + " is not a function."); | ||
} | ||
decorateCtorWithPotionInstance(resource, this); | ||
@@ -952,0 +955,0 @@ decorateCtorWithPotionURI(resource, uri); |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("tslib"),require("@angular/core"),require("@angular/http"),require("rxjs/add/operator/map"),require("rxjs/add/operator/toPromise")):"function"==typeof define&&define.amd?define(["exports","tslib","@angular/core","@angular/http","rxjs/add/operator/map","rxjs/add/operator/toPromise"],t):t(e.potionClient=e.potionClient||{},e.tslib,e.ng.core,e.ng.http)}(this,function(e,t,r,n){"use strict";function o(e,t){return void 0===t&&(t="_"),e.replace(/\.?([A-Z0-9]+)/g,function(e,r){return""+t+r.toLowerCase()}).replace(/^_/,"")}function i(e){return e.replace(/_([a-z0-9])/g,function(e){return e[1].toUpperCase()})}function a(e){return"object"==typeof e&&null!==e}function u(e){return 0===Object.keys(e).length}function s(e){return"function"==typeof e}function c(e,r,n){return a(e)&&!Array.isArray(e)?Object.entries(e).map(function(e){var o=t.__read(e,2),i=o[0],a=o[1];return[s(r)?r(i):i,s(n)?n(a):a]}).reduce(function(e,r){var n=t.__read(r,2),o=n[0],i=n[1];return Object.assign(e,(a={},a[o]=i,a));var a},{}):e}function f(e,t){var r="An error occurred while Potion tried to retrieve a resource";return e instanceof Error?e.message:"string"==typeof e?e:"string"==typeof t?r+" from '"+t+"'.":r+"."}function p(e){return Array.isArray(e)?e.map(function(e){return"object"==typeof e?p(e):e}):a(e)?Object.entries(e).map(function(e){var r=t.__read(e,2),n=r[0],o=r[1];return[i(n),"object"==typeof o?p(o):o]}).reduce(function(e,r){var n=t.__read(r,2),o=n[0],i=n[1];return Object.assign(e,(a={},a[o]=i,a));var a},{}):e}function h(e,r){if("object"!=typeof e||null===e)return e;if(q.has(e))return e;if(e instanceof C){var n=e.toArray().map(function(e){return h(e,r)});return e.update(n,e.total)}if(Array.isArray(e))return e.map(function(e){return h(e,r)});if(e instanceof U)return r.find(function(t){return e.matches(t.uri)});if(Object.keys(e).length>0){!Array.isArray(e)&&e.uri&&q.add(e);try{for(var o=t.__values(Object.entries(e)),i=o.next();!i.done;i=o.next()){var u=t.__read(i.value,2);!function(t,n){if(n instanceof U){var o=r.find(function(e){return n.matches(e.uri)});Object.assign(e,(i={},i[t]=o,i))}else a(n)&&Object.assign(e,(u={},u[t]=h(n,r),u));var i,u}(u[0],u[1])}}catch(e){s={error:e}}finally{try{i&&!i.done&&(c=o.return)&&c.call(o)}finally{if(s)throw s.error}}return e}return e;var s,c}function d(e){var r=[];if(a(e)&&Object.keys(e).length>0){if(q.has(e))return[];e.uri&&r.push(e);var n=Array.isArray(e)||e instanceof C?e:Object.values(e);try{for(var o=t.__values(n),i=o.next();!i.done;i=o.next()){var u=i.value;r.push.apply(r,t.__spread(d(u)))}}catch(e){p={error:e}}finally{try{i&&!i.done&&(h=o.return)&&h.call(o)}finally{if(p)throw p.error}}}var s=[];try{for(var c=t.__values(r),f=c.next();!f.done;f=c.next())!function(e){-1===s.findIndex(function(t){return e.uri===t.uri})&&s.push(e)}(f.value)}catch(e){l={error:e}}finally{try{f&&!f.done&&(y=c.return)&&y.call(c)}finally{if(l)throw l.error}}return s;var p,h,l,y}function l(e){return new U(e)}function y(e,t){return a(e)?e instanceof F&&"string"==typeof e.uri?{$ref:""+j(e.uri,t)}:e instanceof Date?{$date:e.getTime()}:Array.isArray(e)?e.map(function(e){return y(e,t)}):c(e,function(e){return o(e)},function(e){return y(e,t)}):e}function g(e){return"string"==typeof e&&e.length>0?/^\d+$/.test(e)?parseInt(e,10):e:Number.isInteger(e)?e:null}function v(e,t){var r=e.indexOf(t+"/");return-1!==r?g(e.substring(r).split("/").pop()):null}function m(e,r){var n=Object.entries(r).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 O(e,t){var r=m(e,t);return!!r&&null!==v(e,r.resourceURI)}function P(e){var t=e.$type,r=e.$id;return("string"==typeof r||Number.isInteger(r))&&"string"==typeof t}function _(e){var t=e.$uri,r=e.$ref,n=e.$type,o=e.$id;return"string"==typeof t?decodeURIComponent(t):"string"==typeof r?decodeURIComponent(r):P({$type:n,$id:o})?"/"+n+"/"+o:""}function b(e,t){return e.includes(t)?e.substring(t.length):e}function j(e,t){return"string"!=typeof t||e.includes(t)?e:""+t+e}function w(){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}function $(e){return J.getOwnMetadata(k,e)}function I(e,t){J.defineMetadata(k,t,e)}function T(e){return J.getOwnMetadata(H,e)}function x(e,t){J.defineMetadata(H,t,e)}function S(e){return J.getOwnMetadata(D,e.constructor)||Promise}function R(e,t){var r=J.getOwnMetadata(G,e);return r&&r[t]}function A(e,t){var r=s(e)?e:s(e.constructor)?e.constructor:null;if(null!==r){J.defineMetadata(G,Object.assign(J.getOwnMetadata(G,r)||{},(n={},n[t]=!0,n)),r);var n}}function E(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,c=void 0===u||u,f=s(this),p=""+(f?T(this):this.uri)+e,h={method:r,paginate:a,cache:c};return"GET"===r?h.search=t:["POST","PUT","PATCH"].includes(r)&&(h.data=t),$(f?this:this.constructor).fetch(p,h)}}function N(e,t,r,n){return e||new Q(t,r,n)}var C=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.search),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.search.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}(),U=function(){function e(e){this.$uri=e}return e.prototype.matches=function(e){return this.$uri===e},e}(),q=new WeakSet,M=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}(),J=function(){return"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"),H=Symbol("potion:uri"),D=Symbol("potion:promise"),G=Symbol("potion:readonly"),F=function(){function e(e){void 0===e&&(e={}),this.$id=null,Object.assign(this,e)}return e.fetch=function(e,t){var r=(void 0===t?{}:t).cache,n=void 0===r||r,o=T(this);return $(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=T(this);return $(this).fetch(u,{method:"GET",search:e,paginate:o,cache:a})},e.first=function(e){function t(e){return e[0]}return this.query(e).then(t)},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,t={};return Object.keys(this).filter(function(t){return!t.startsWith("$")&&!R(e.constructor,t)}).forEach(function(r){t[r]=e[r]}),t},e.prototype.save=function(){if(this.uri||this.id)return this.update(this.toJSON());var e=this.constructor;return $(e).fetch(T(e),{method:"POST",data:this.toJSON(),cache:!0})},e.prototype.update=function(e){return void 0===e&&(e={}),$(this.constructor).fetch(this.uri,{cache:!0,method:"PATCH",data:e})},e.prototype.destroy=function(){function e(){n.get(t)&&n.remove(t)}var t=this.uri,r=$(this.constructor),n=r.cache;return r.fetch(t,{method:"DELETE"}).then(e)},e}(),L=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=S(this),this.requests=new Map,this.cache=a||new M,this.host=n,this.prefix=i}return e.prototype.register=function(e,t,r){return I(t,this),x(t,e),r&&Array.isArray(r.readonly)&&r.readonly.forEach(function(e){return A(t,e)}),this.resources[e]=t,t},e.prototype.registerAs=function(e,t){var r=this;return function(n){return r.register(e,n,t),n}},e.prototype.request=function(e,t){},e.prototype.fetch=function(e,r,n){var o=b(e,this.prefix),i=t.__assign({},r,n,{origin:[]});return O(e,this.resources)&&Object.assign(i,{origin:[o]}),this.resolve(e,i).then(function(e){return h(e,d(e)),e})},e.prototype.resolve=function(e,t){var r=this,n=this,o=n.Promise,i=n.prefix,a=b(e,i);e=j(e,i);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.search?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=f(t,e);return o.reject(n)})),this.requests.get(a))},e.prototype.serialize=function(e){var r=this.prefix,n=e.search;return t.__assign({},e,{search:y(e.paginate?t.__assign({page:1,perPage:25},n):n,r),data:y(e.data,r)})},e.prototype.deserialize=function(e,t,r){var n=this,o=e.data,i=e.headers;return this.fromPotionJSON(o,r.origin).then(function(e){if(r.paginate){var o=i["x-total-count"]||e.length;if(r.pagination instanceof C)return r.pagination.update(e,o);var a=new C({uri:t,potion:n},e,o,r);return Object.assign(r,{pagination:a}),a}return e})},e.prototype.fromPotionJSON=function(e,r){var n=this,o=this.Promise;if("object"==typeof e&&null!==e){if(Array.isArray(e))return o.all(e.map(function(e){return n.fromPotionJSON(e,r)}));if("string"==typeof e.$uri||P(e))return this.parseURI(e).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(e,r);return n.cache.has(s)?o.all([f,n.cache.get(s)]).then(function(e){var r=t.__read(e,2),n=r[0],o=r[1];return Object.assign(o,n,c),o}):n.cache.put(s,f.then(function(e){return Reflect.construct(a,[t.__assign({},e,c)])}))});if("string"==typeof e.$schema)return o.resolve(p(e));if(1===Object.keys(e).length){if("string"==typeof e.$ref)return"#"===e.$ref?o.resolve(e.$ref):this.parseURI(e).then(function(e){var t=e.uri;return r.includes(t)?o.resolve(l(t)):n.resolve(t,{cache:!0,method:"GET",origin:r})});if(void 0!==e.$date)return o.resolve(new Date(e.$date))}return this.parsePotionJSONProperties(e,r)}return o.resolve(e)},e.prototype.parsePotionJSONProperties=function(e,r){var n=this,o=this.Promise,a=Object.entries(e),u=a.map(function(e){var o=t.__read(e,2)[1];return n.fromPotionJSON(o,r)}),s=a.map(function(e){return i(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),o=n[0],i=n[1];return Object.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=b(_({$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},f=g(o);return null!==f?Object.assign(c,{id:f}):Object.assign(c,{id:v(a,s)}),i.resolve(c)}return i.reject(new Error("URI '"+a+"' is an uninterpretable or unknown Potion resource."))},e}(),z={GET:function(e){return E(e,{method:"GET"})},DELETE:function(e){return E(e,{method:"DELETE"})},POST:function(e){return E(e,{method:"POST"})},PATCH:function(e){return E(e,{method:"PATCH"})},PUT:function(e){return E(e,{method:"PUT"})}},V=function(e){function r(){return null!==e&&e.apply(this,arguments)||this}return t.__extends(r,e),r.prototype.encodeKey=function(e){return encodeURIComponent(e)},r.prototype.encodeValue=function(e){return encodeURIComponent(JSON.stringify(e))},r}(n.QueryEncoder),W=new r.InjectionToken("PotionResources"),B=new r.InjectionToken("PotionConfig"),K=new r.InjectionToken("PotionHttp"),Q=function(e){function r(r,n,o){var i=e.call(this,t.__assign({},n))||this;return i.http=o||r,i}return t.__extends(r,e),r.prototype.registerFromProvider=function(e){if(e=w.apply(void 0,t.__spread(e.filter(function(e){return!u(e)}))),!u(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 s=t.__read(a,2),c=s[0],f=s[1];this.register(i,c,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},r.prototype.request=function(e,r){var o=t.__assign({},r),i=o.search,a=o.data,u=o.method,s=void 0===u?"GET":u,c=new n.RequestOptions({method:s,url:e});if(a){var f=new n.Headers;f.set("Content-Type","application/json; charset=utf-8"),c=c.merge({body:JSON.stringify(a),headers:f})}if(i){var p=new n.URLSearchParams("",new V);try{for(var h=t.__values(Object.entries(i)),d=h.next();!d.done;d=h.next()){var l=t.__read(d.value,2),y=l[0],g=l[1];p.append(y,g)}}catch(e){v={error:e}}finally{try{d&&!d.done&&(m=h.return)&&m.call(h)}finally{if(v)throw v.error}}c=c.merge({search:p})}return this.http.request(e,c).map(function(e){var r,o={};if(e instanceof n.Response){if(e.headers instanceof n.Headers)try{for(var i=t.__values(e.headers.keys()),a=i.next();!a.done;a=i.next()){var u=a.value;o[u.toLowerCase()]=e.headers.get(u)}}catch(e){s={error:e}}finally{try{a&&!a.done&&(c=i.return)&&c.call(i)}finally{if(s)throw s.error}}else o=e.headers||{};r=e.text().length>0?e.json():null}else r=e;return{headers:o,data:r};var s,c}).toPromise();var v,m},r}(L);Q.decorators=[{type:r.Injectable}],Q.ctorParameters=function(){return[{type:n.Http},{type:void 0,decorators:[{type:r.Optional},{type:r.Inject,args:[B]}]},{type:void 0,decorators:[{type:r.Optional},{type:r.Inject,args:[K]}]}]};var Y={provide:Q,useFactory:N,deps:[[new r.Optional,new r.SkipSelf,Q],n.Http,[new r.Optional,new r.Inject(B)],[new r.Optional,new r.Inject(K)]]},Z=function(){function e(e,t){e.registerFromProvider(t||[])}return e}();Z.decorators=[{type:r.NgModule,args:[{imports:[n.HttpModule],providers:[Y]}]}],Z.ctorParameters=function(){return[{type:Q,decorators:[{type:r.Inject,args:[r.forwardRef(function(){return Q})]}]},{type:Array,decorators:[{type:r.Optional},{type:r.Inject,args:[W]}]}]},e.Item=F,e.readonly=A,e.Pagination=C,e.PotionBase=L,e.Route=z,e.route=E,e.findPotionResource=m,e.fromSchemaJSON=p,e.getPotionID=v,e.getPotionURI=_,e.hasTypeAndId=P,e.isPotionURI=O,e.parsePotionID=g,e.removePrefixFromURI=b,e.addPrefixToURI=j,e.toPotionJSON=y,e.toCamelCase=i,e.toSnakeCase=o,e.PotionModule=Z,e.POTION_RESOURCES=W,e.POTION_CONFIG=B,e.POTION_HTTP=K,e.Potion=Q,e.POTION_PROVIDER_FACTORY=N,e.POTION_PROVIDER=Y,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("tslib"),require("@angular/core"),require("@angular/http"),require("rxjs/add/operator/map"),require("rxjs/add/operator/toPromise")):"function"==typeof define&&define.amd?define(["exports","tslib","@angular/core","@angular/http","rxjs/add/operator/map","rxjs/add/operator/toPromise"],t):t(e.potionClient=e.potionClient||{},e.tslib,e.ng.core,e.ng.http)}(this,function(e,t,r,n){"use strict";function o(e,t){return void 0===t&&(t="_"),e.replace(/\.?([A-Z0-9]+)/g,function(e,r){return""+t+r.toLowerCase()}).replace(/^_/,"")}function i(e){return e.replace(/_([a-z0-9])/g,function(e){return e[1].toUpperCase()})}function a(e){return"object"==typeof e&&null!==e}function u(e){return 0===Object.keys(e).length}function s(e){return"function"==typeof e}function c(e,r,n){return a(e)&&!Array.isArray(e)?Object.entries(e).map(function(e){var o=t.__read(e,2),i=o[0],a=o[1];return[s(r)?r(i):i,s(n)?n(a):a]}).reduce(function(e,r){var n=t.__read(r,2),o=n[0],i=n[1];return Object.assign(e,(a={},a[o]=i,a));var a},{}):e}function f(e,t){var r="An error occurred while Potion tried to retrieve a resource";return e instanceof Error?e.message:"string"==typeof e?e:"string"==typeof t?r+" from '"+t+"'.":r+"."}function p(e){return Array.isArray(e)?e.map(function(e){return"object"==typeof e?p(e):e}):a(e)?Object.entries(e).map(function(e){var r=t.__read(e,2),n=r[0],o=r[1];return[i(n),"object"==typeof o?p(o):o]}).reduce(function(e,r){var n=t.__read(r,2),o=n[0],i=n[1];return Object.assign(e,(a={},a[o]=i,a));var a},{}):e}function h(e,r){if("object"!=typeof e||null===e)return e;if(q.has(e))return e;if(e instanceof C){var n=e.toArray().map(function(e){return h(e,r)});return e.update(n,e.total)}if(Array.isArray(e))return e.map(function(e){return h(e,r)});if(e instanceof U)return r.find(function(t){return e.matches(t.uri)});if(Object.keys(e).length>0){!Array.isArray(e)&&e.uri&&q.add(e);try{for(var o=t.__values(Object.entries(e)),i=o.next();!i.done;i=o.next()){var u=t.__read(i.value,2);!function(t,n){if(n instanceof U){var o=r.find(function(e){return n.matches(e.uri)});Object.assign(e,(i={},i[t]=o,i))}else a(n)&&Object.assign(e,(u={},u[t]=h(n,r),u));var i,u}(u[0],u[1])}}catch(e){s={error:e}}finally{try{i&&!i.done&&(c=o.return)&&c.call(o)}finally{if(s)throw s.error}}return e}return e;var s,c}function d(e){var r=[];if(a(e)&&Object.keys(e).length>0){if(q.has(e))return[];e.uri&&r.push(e);var n=Array.isArray(e)||e instanceof C?e:Object.values(e);try{for(var o=t.__values(n),i=o.next();!i.done;i=o.next()){var u=i.value;r.push.apply(r,t.__spread(d(u)))}}catch(e){p={error:e}}finally{try{i&&!i.done&&(h=o.return)&&h.call(o)}finally{if(p)throw p.error}}}var s=[];try{for(var c=t.__values(r),f=c.next();!f.done;f=c.next())!function(e){-1===s.findIndex(function(t){return e.uri===t.uri})&&s.push(e)}(f.value)}catch(e){l={error:e}}finally{try{f&&!f.done&&(y=c.return)&&y.call(c)}finally{if(l)throw l.error}}return s;var p,h,l,y}function l(e){return new U(e)}function y(e,t){return a(e)?e instanceof F&&"string"==typeof e.uri?{$ref:""+j(e.uri,t)}:e instanceof Date?{$date:e.getTime()}:Array.isArray(e)?e.map(function(e){return y(e,t)}):c(e,function(e){return o(e)},function(e){return y(e,t)}):e}function g(e){return"string"==typeof e&&e.length>0?/^\d+$/.test(e)?parseInt(e,10):e:Number.isInteger(e)?e:null}function v(e,t){var r=e.indexOf(t+"/");return-1!==r?g(e.substring(r).split("/").pop()):null}function m(e,r){var n=Object.entries(r).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 O(e,t){var r=m(e,t);return!!r&&null!==v(e,r.resourceURI)}function P(e){var t=e.$type,r=e.$id;return("string"==typeof r||Number.isInteger(r))&&"string"==typeof t}function _(e){var t=e.$uri,r=e.$ref,n=e.$type,o=e.$id;return"string"==typeof t?decodeURIComponent(t):"string"==typeof r?decodeURIComponent(r):P({$type:n,$id:o})?"/"+n+"/"+o:""}function b(e,t){return e.includes(t)?e.substring(t.length):e}function j(e,t){return"string"!=typeof t||e.includes(t)?e:""+t+e}function w(){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}function $(e){return J.getOwnMetadata(k,e)}function I(e,t){J.defineMetadata(k,t,e)}function T(e){return J.getOwnMetadata(H,e)}function x(e,t){J.defineMetadata(H,t,e)}function S(e){return J.getOwnMetadata(D,e.constructor)||Promise}function A(e,t){var r=J.getOwnMetadata(G,e);return r&&r[t]}function R(e,t){var r=s(e)?e:s(e.constructor)?e.constructor:null;if(null!==r){J.defineMetadata(G,Object.assign(J.getOwnMetadata(G,r)||{},(n={},n[t]=!0,n)),r);var n}}function E(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,c=void 0===u||u,f=s(this),p=""+(f?T(this):this.uri)+e,h={method:r,paginate:a,cache:c};return"GET"===r?h.search=t:["POST","PUT","PATCH"].includes(r)&&(h.data=t),$(f?this:this.constructor).fetch(p,h)}}function N(e,t,r,n){return e||new Q(t,r,n)}var C=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.search),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.search.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}(),U=function(){function e(e){this.$uri=e}return e.prototype.matches=function(e){return this.$uri===e},e}(),q=new WeakSet,M=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}(),J=function(){return"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"),H=Symbol("potion:uri"),D=Symbol("potion:promise"),G=Symbol("potion:readonly"),F=function(){function e(e){void 0===e&&(e={}),this.$id=null,Object.assign(this,e)}return e.fetch=function(e,t){var r=(void 0===t?{}:t).cache,n=void 0===r||r,o=T(this);return $(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=T(this);return $(this).fetch(u,{method:"GET",search:e,paginate:o,cache:a})},e.first=function(e){function t(e){return e[0]}return this.query(e).then(t)},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,t={};return Object.keys(this).filter(function(t){return!t.startsWith("$")&&!A(e.constructor,t)}).forEach(function(r){t[r]=e[r]}),t},e.prototype.save=function(){if(this.uri||this.id)return this.update(this.toJSON());var e=this.constructor;return $(e).fetch(T(e),{method:"POST",data:this.toJSON(),cache:!0})},e.prototype.update=function(e){return void 0===e&&(e={}),$(this.constructor).fetch(this.uri,{cache:!0,method:"PATCH",data:e})},e.prototype.destroy=function(){function e(){n.get(t)&&n.remove(t)}var t=this.uri,r=$(this.constructor),n=r.cache;return r.fetch(t,{method:"DELETE"}).then(e)},e}(),L=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=S(this),this.requests=new Map,this.cache=a||new M,this.host=n,this.prefix=i}return e.prototype.register=function(e,t,r){if(!s(t))throw new TypeError("An error occurred while trying to register a resource for "+e+". "+t+" is not a function.");return I(t,this),x(t,e),r&&Array.isArray(r.readonly)&&r.readonly.forEach(function(e){return R(t,e)}),this.resources[e]=t,t},e.prototype.registerAs=function(e,t){var r=this;return function(n){return r.register(e,n,t),n}},e.prototype.request=function(e,t){},e.prototype.fetch=function(e,r,n){var o=b(e,this.prefix),i=t.__assign({},r,n,{origin:[]});return O(e,this.resources)&&Object.assign(i,{origin:[o]}),this.resolve(e,i).then(function(e){return h(e,d(e)),e})},e.prototype.resolve=function(e,t){var r=this,n=this,o=n.Promise,i=n.prefix,a=b(e,i);e=j(e,i);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.search?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=f(t,e);return o.reject(n)})),this.requests.get(a))},e.prototype.serialize=function(e){var r=this.prefix,n=e.search;return t.__assign({},e,{search:y(e.paginate?t.__assign({page:1,perPage:25},n):n,r),data:y(e.data,r)})},e.prototype.deserialize=function(e,t,r){var n=this,o=e.data,i=e.headers;return this.fromPotionJSON(o,r.origin).then(function(e){if(r.paginate){var o=i["x-total-count"]||e.length;if(r.pagination instanceof C)return r.pagination.update(e,o);var a=new C({uri:t,potion:n},e,o,r);return Object.assign(r,{pagination:a}),a}return e})},e.prototype.fromPotionJSON=function(e,r){var n=this,o=this.Promise;if("object"==typeof e&&null!==e){if(Array.isArray(e))return o.all(e.map(function(e){return n.fromPotionJSON(e,r)}));if("string"==typeof e.$uri||P(e))return this.parseURI(e).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(e,r);return n.cache.has(s)?o.all([f,n.cache.get(s)]).then(function(e){var r=t.__read(e,2),n=r[0],o=r[1];return Object.assign(o,n,c),o}):n.cache.put(s,f.then(function(e){return Reflect.construct(a,[t.__assign({},e,c)])}))});if("string"==typeof e.$schema)return o.resolve(p(e));if(1===Object.keys(e).length){if("string"==typeof e.$ref)return"#"===e.$ref?o.resolve(e.$ref):this.parseURI(e).then(function(e){var t=e.uri;return r.includes(t)?o.resolve(l(t)):n.resolve(t,{cache:!0,method:"GET",origin:r})});if(void 0!==e.$date)return o.resolve(new Date(e.$date))}return this.parsePotionJSONProperties(e,r)}return o.resolve(e)},e.prototype.parsePotionJSONProperties=function(e,r){var n=this,o=this.Promise,a=Object.entries(e),u=a.map(function(e){var o=t.__read(e,2)[1];return n.fromPotionJSON(o,r)}),s=a.map(function(e){return i(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),o=n[0],i=n[1];return Object.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=b(_({$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},f=g(o);return null!==f?Object.assign(c,{id:f}):Object.assign(c,{id:v(a,s)}),i.resolve(c)}return i.reject(new Error("URI '"+a+"' is an uninterpretable or unknown Potion resource."))},e}(),z={GET:function(e){return E(e,{method:"GET"})},DELETE:function(e){return E(e,{method:"DELETE"})},POST:function(e){return E(e,{method:"POST"})},PATCH:function(e){return E(e,{method:"PATCH"})},PUT:function(e){return E(e,{method:"PUT"})}},V=function(e){function r(){return null!==e&&e.apply(this,arguments)||this}return t.__extends(r,e),r.prototype.encodeKey=function(e){return encodeURIComponent(e)},r.prototype.encodeValue=function(e){return encodeURIComponent(JSON.stringify(e))},r}(n.QueryEncoder),W=new r.InjectionToken("PotionResources"),B=new r.InjectionToken("PotionConfig"),K=new r.InjectionToken("PotionHttp"),Q=function(e){function r(r,n,o){var i=e.call(this,t.__assign({},n))||this;return i.http=o||r,i}return t.__extends(r,e),r.prototype.registerFromProvider=function(e){if(e=w.apply(void 0,t.__spread(e.filter(function(e){return!u(e)}))),!u(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 s=t.__read(a,2),c=s[0],f=s[1];this.register(i,c,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},r.prototype.request=function(e,r){var o=t.__assign({},r),i=o.search,a=o.data,u=o.method,s=void 0===u?"GET":u,c=new n.RequestOptions({method:s,url:e});if(a){var f=new n.Headers;f.set("Content-Type","application/json; charset=utf-8"),c=c.merge({body:JSON.stringify(a),headers:f})}if(i){var p=new n.URLSearchParams("",new V);try{for(var h=t.__values(Object.entries(i)),d=h.next();!d.done;d=h.next()){var l=t.__read(d.value,2),y=l[0],g=l[1];p.append(y,g)}}catch(e){v={error:e}}finally{try{d&&!d.done&&(m=h.return)&&m.call(h)}finally{if(v)throw v.error}}c=c.merge({search:p})}return this.http.request(e,c).map(function(e){var r,o={};if(e instanceof n.Response){if(e.headers instanceof n.Headers)try{for(var i=t.__values(e.headers.keys()),a=i.next();!a.done;a=i.next()){var u=a.value;o[u.toLowerCase()]=e.headers.get(u)}}catch(e){s={error:e}}finally{try{a&&!a.done&&(c=i.return)&&c.call(i)}finally{if(s)throw s.error}}else o=e.headers||{};r=e.text().length>0?e.json():null}else r=e;return{headers:o,data:r};var s,c}).toPromise();var v,m},r}(L);Q.decorators=[{type:r.Injectable}],Q.ctorParameters=function(){return[{type:n.Http},{type:void 0,decorators:[{type:r.Optional},{type:r.Inject,args:[B]}]},{type:void 0,decorators:[{type:r.Optional},{type:r.Inject,args:[K]}]}]};var Y={provide:Q,useFactory:N,deps:[[new r.Optional,new r.SkipSelf,Q],n.Http,[new r.Optional,new r.Inject(B)],[new r.Optional,new r.Inject(K)]]},Z=function(){function e(e,t){e.registerFromProvider(t||[])}return e}();Z.decorators=[{type:r.NgModule,args:[{imports:[n.HttpModule],providers:[Y]}]}],Z.ctorParameters=function(){return[{type:Q,decorators:[{type:r.Inject,args:[r.forwardRef(function(){return Q})]}]},{type:Array,decorators:[{type:r.Optional},{type:r.Inject,args:[W]}]}]},e.Item=F,e.readonly=R,e.Pagination=C,e.PotionBase=L,e.Route=z,e.route=E,e.findPotionResource=m,e.fromSchemaJSON=p,e.getPotionID=v,e.getPotionURI=_,e.hasTypeAndId=P,e.isPotionURI=O,e.parsePotionID=g,e.removePrefixFromURI=b,e.addPrefixToURI=j,e.toPotionJSON=y,e.toCamelCase=i,e.toSnakeCase=o,e.PotionModule=Z,e.POTION_RESOURCES=W,e.POTION_CONFIG=B,e.POTION_HTTP=K,e.Potion=Q,e.POTION_PROVIDER_FACTORY=N,e.POTION_PROVIDER=Y,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=ng.umd.min.js.map |
{ | ||
"name": "potion-client", | ||
"version": "2.1.0", | ||
"version": "2.1.1", | ||
"description": "A ES6 client for APIs written in Flask-Potion", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -85,4 +85,4 @@ # Potion | ||
As a rule of thumb, in the `next` branch, you should **always** make a pre release, | ||
allowing for publish the stable version in the `master` branch: | ||
As a rule of thumb, you should **always** make a pre release only in the `next` branch, | ||
allowing for publishing the stable version from the `master` branch: | ||
```bash | ||
@@ -89,0 +89,0 @@ # Make a patch pre release so that: |
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
1222848
11503