New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

potion-client

Package Overview
Dependencies
Maintainers
2
Versions
183
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

potion-client - npm Package Compare versions

Comparing version 3.0.0 to 3.0.1

10

CHANGELOG.md

@@ -0,1 +1,11 @@

<a name="3.0.1"></a>
## [3.0.1](https://github.com/biosustain/potion-node/compare/v3.0.0...v3.0.1) (2017-07-22)
### Bug Fixes
* fix Angular 4 body and params serialization ([b7111fc](https://github.com/biosustain/potion-node/commit/b7111fc))
<a name="3.0.0"></a>

@@ -2,0 +12,0 @@ # [3.0.0](https://github.com/biosustain/potion-node/compare/v2.5.0...v3.0.0) (2017-07-18)

54

ng.es5.js
import { __assign, __extends, __read, __spread, __values } from 'tslib';
import * as tslib_1 from 'tslib';
import { Inject, Injectable, InjectionToken, NgModule, Optional, SkipSelf, forwardRef } from '@angular/core';
import { HttpClient, HttpClientModule, HttpHeaders, HttpRequest, HttpResponse } from '@angular/common/http';
import { HttpClient, HttpClientModule, HttpHeaders, HttpParams, HttpRequest, HttpResponse } from '@angular/common/http';
import 'rxjs/add/operator/filter';

@@ -1368,22 +1368,31 @@ import 'rxjs/add/operator/map';

var _a = __assign({}, options), params = _a.params, body = _a.body, _b = _a.method, method = _b === void 0 ? 'GET' : _b;
// Create a HttpRequest
var /** @type {?} */ request = new HttpRequest(/** @type {?} */ (method), uri, {
var /** @type {?} */ init = {
// Potion expects all requests to have content type set to 'application/json'.
headers: new HttpHeaders({
'Content-Type': 'application/json'
'content-type': 'application/json'
}),
responseType: 'json'
});
if (body) {
// We need to convert the {body} to proper JSON when making POST/PUT/PATCH requests.
request = request.clone({
body: JSON.stringify(body)
});
}
};
// Convert {params} to HttpParams.
if (isJsObject(params)) {
request = request.clone({
setParams: omap(params, function (key) { return key; }, function (value) { return JSON.stringify(value); })
var /** @type {?} */ httpParams = new HttpParams();
try {
for (var _c = __values(Object.entries(params)), _d = _c.next(); !_d.done; _d = _c.next()) {
var _e = __read(_d.value, 2), key = _e[0], value = _e[1];
// HttpParams, like all http client classes, are immutable, hence the assignment
httpParams = httpParams.append(key, JSON.stringify(value));
}
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (_d && !_d.done && (_f = _c.return)) _f.call(_c);
}
finally { if (e_2) throw e_2.error; }
}
Object.assign(init, {
params: httpParams
});
}
var /** @type {?} */ request = method === 'POST' || method === 'PUT' || method === 'PATCH' ? new HttpRequest(/** @type {?} */ (method), uri, toJson(body), init) : new HttpRequest(/** @type {?} */ (method), uri, init);
return this.http.request(request)

@@ -1401,3 +1410,3 @@ .filter(function (event) { return event instanceof HttpResponse; })

}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
catch (e_3_1) { e_3 = { error: e_3_1 }; }
finally {

@@ -1407,3 +1416,3 @@ try {

}
finally { if (e_2) throw e_2.error; }
finally { if (e_3) throw e_3.error; }
}

@@ -1414,5 +1423,6 @@ return {

};
var e_2, _c;
var e_3, _c;
})
.toPromise();
var e_2, _f;
};

@@ -1451,2 +1461,14 @@ Potion.decorators = [

};
/**
* @param {?} value
* @return {?}
*/
function toJson(value) {
try {
return JSON.stringify(value);
}
catch (e) {
return;
}
}

@@ -1453,0 +1475,0 @@ /**

import { Inject, Injectable, InjectionToken, NgModule, Optional, SkipSelf, forwardRef } from '@angular/core';
import { HttpClient, HttpClientModule, HttpHeaders, HttpRequest, HttpResponse } from '@angular/common/http';
import { HttpClient, HttpClientModule, HttpHeaders, HttpParams, HttpRequest, HttpResponse } from '@angular/common/http';
import 'rxjs/add/operator/filter';

@@ -1219,22 +1219,21 @@ import 'rxjs/add/operator/map';

const { params, body, method = 'GET' } = Object.assign({}, options);
// Create a HttpRequest
let /** @type {?} */ request = new HttpRequest(/** @type {?} */ (method), uri, {
const /** @type {?} */ init = {
// Potion expects all requests to have content type set to 'application/json'.
headers: new HttpHeaders({
'Content-Type': 'application/json'
'content-type': 'application/json'
}),
responseType: 'json'
});
if (body) {
// We need to convert the {body} to proper JSON when making POST/PUT/PATCH requests.
request = request.clone({
body: JSON.stringify(body)
});
}
};
// Convert {params} to HttpParams.
if (isJsObject(params)) {
request = request.clone({
setParams: omap(params, key => key, value => JSON.stringify(value))
let /** @type {?} */ httpParams = new HttpParams();
for (const [key, value] of Object.entries(params)) {
// HttpParams, like all http client classes, are immutable, hence the assignment
httpParams = httpParams.append(key, JSON.stringify(value));
}
Object.assign(init, {
params: httpParams
});
}
const /** @type {?} */ request = method === 'POST' || method === 'PUT' || method === 'PATCH' ? new HttpRequest(/** @type {?} */ (method), uri, toJson(body), init) : new HttpRequest(/** @type {?} */ (method), uri, init);
return this.http.request(request)

@@ -1287,2 +1286,14 @@ .filter(event => event instanceof HttpResponse)

};
/**
* @param {?} value
* @return {?}
*/
function toJson(value) {
try {
return JSON.stringify(value);
}
catch (e) {
return;
}
}

@@ -1289,0 +1300,0 @@ /**

@@ -1366,22 +1366,31 @@ (function (global, factory) {

var _a = tslib_1.__assign({}, options), params = _a.params, body = _a.body, _b = _a.method, method = _b === void 0 ? 'GET' : _b;
// Create a HttpRequest
var /** @type {?} */ request = new _angular_common_http.HttpRequest(/** @type {?} */ (method), uri, {
var /** @type {?} */ init = {
// Potion expects all requests to have content type set to 'application/json'.
headers: new _angular_common_http.HttpHeaders({
'Content-Type': 'application/json'
'content-type': 'application/json'
}),
responseType: 'json'
});
if (body) {
// We need to convert the {body} to proper JSON when making POST/PUT/PATCH requests.
request = request.clone({
body: JSON.stringify(body)
});
}
};
// Convert {params} to HttpParams.
if (isJsObject(params)) {
request = request.clone({
setParams: omap(params, function (key) { return key; }, function (value) { return JSON.stringify(value); })
var /** @type {?} */ httpParams = new _angular_common_http.HttpParams();
try {
for (var _c = tslib_1.__values(Object.entries(params)), _d = _c.next(); !_d.done; _d = _c.next()) {
var _e = tslib_1.__read(_d.value, 2), key = _e[0], value = _e[1];
// HttpParams, like all http client classes, are immutable, hence the assignment
httpParams = httpParams.append(key, JSON.stringify(value));
}
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (_d && !_d.done && (_f = _c.return)) _f.call(_c);
}
finally { if (e_2) throw e_2.error; }
}
Object.assign(init, {
params: httpParams
});
}
var /** @type {?} */ request = method === 'POST' || method === 'PUT' || method === 'PATCH' ? new _angular_common_http.HttpRequest(/** @type {?} */ (method), uri, toJson(body), init) : new _angular_common_http.HttpRequest(/** @type {?} */ (method), uri, init);
return this.http.request(request)

@@ -1399,3 +1408,3 @@ .filter(function (event) { return event instanceof _angular_common_http.HttpResponse; })

}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
catch (e_3_1) { e_3 = { error: e_3_1 }; }
finally {

@@ -1405,3 +1414,3 @@ try {

}
finally { if (e_2) throw e_2.error; }
finally { if (e_3) throw e_3.error; }
}

@@ -1412,5 +1421,6 @@ return {

};
var e_2, _c;
var e_3, _c;
})
.toPromise();
var e_2, _f;
};

@@ -1449,2 +1459,14 @@ Potion.decorators = [

};
/**
* @param {?} value
* @return {?}
*/
function toJson(value) {
try {
return JSON.stringify(value);
}
catch (e) {
return;
}
}

@@ -1451,0 +1473,0 @@ /**

@@ -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 q){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 C)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 C){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 q?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 C(t)}function y(t,e){return a(t)?t instanceof F&&"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 $(){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 w(t){return J.getOwnMetadata(k,t)}function T(t,e){J.defineMetadata(k,e,t)}function I(t){return J.getOwnMetadata(H,t)}function x(t,e){J.defineMetadata(H,e,t)}function A(t){return J.getOwnMetadata(D,t.constructor)||Promise}function S(t,e){var r=J.getOwnMetadata(G,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(G,Object.assign(J.getOwnMetadata(G,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?I(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),w(f?this:this.constructor).fetch(p,h)}}function N(t,e,r){return t||new B(e,r)}var q=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}(),C=function(){function t(t){this.$uri=t}return t.prototype.matches=function(t){return a(t)&&this.$uri===t.uri},t}(),M=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}(),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"),H=Symbol("potion:uri"),D=Symbol("potion:promise"),G=Symbol("potion:readonly"),F=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=I(this);return w(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=I(this);return w(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 w(t).fetch(I(t),{method:"POST",body:this.toJSON(),cache:!0})},t.prototype.update=function(t){return void 0===t&&(t={}),w(this.constructor).fetch(this.uri,{cache:!0,method:"PATCH",body:t})},t.prototype.destroy=function(){var t=this.uri,e=w(this.constructor),r=e.cache;return e.fetch(t,{method:"DELETE"}).then(function(){r.get(t)&&r.remove(t)})},t}(),z=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 U,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),x(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 q)return r.pagination.update(t,i);var a=new q({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}(),L={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"})}},V=new r.InjectionToken("PotionResources"),W=new r.InjectionToken("PotionConfig"),B=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=$.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,f=void 0===s?"GET":s,p=new n.HttpRequest(f,t,{headers:new n.HttpHeaders({"Content-Type":"application/json"}),responseType:"json"});return u&&(p=p.clone({body:JSON.stringify(u)})),a(i)&&(p=p.clone({setParams:c(i,function(t){return t},function(t){return JSON.stringify(t)})})),this.http.request(p).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()},o.decorators=[{type:r.Injectable}],o.ctorParameters=function(){return[{type:n.HttpClient},{type:void 0,decorators:[{type:r.Optional},{type:r.Inject,args:[W]}]}]},o}(z),Y={provide:B,useFactory:N,deps:[[new r.Optional,new r.SkipSelf,B],n.HttpClient,[new r.Optional,new r.Inject(W)]]},Z=function(){function t(t,e){t.registerFromProvider(e||[])}return t.decorators=[{type:r.NgModule,args:[{imports:[n.HttpClientModule],providers:[Y]}]}],t.ctorParameters=function(){return[{type:B,decorators:[{type:r.Inject,args:[r.forwardRef(function(){return B})]}]},{type:Array,decorators:[{type:r.Optional},{type:r.Inject,args:[V]}]}]},t}();t.Item=F,t.readonly=R,t.Pagination=q,t.PotionBase=z,t.Route=L,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=Z,t.POTION_RESOURCES=V,t.POTION_CONFIG=W,t.Potion=B,t.POTION_PROVIDER_FACTORY=N,t.POTION_PROVIDER=Y,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)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})});
//# sourceMappingURL=ng.umd.min.js.map
{
"name": "potion-client",
"version": "3.0.0",
"version": "3.0.1",
"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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc