@meanie/angular-api
Advanced tools
Comparing version 3.3.0 to 3.4.0
{ | ||
"name": "@meanie/angular-api", | ||
"description": "An Angular service for interaction with API's", | ||
"version": "3.3.0", | ||
"version": "3.4.0", | ||
"homepage": "https://github.com/meanie/angular-api", | ||
@@ -6,0 +6,0 @@ "author": { |
@@ -7,3 +7,3 @@ /** | ||
*/ | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
@@ -365,3 +365,3 @@ (function (window, angular, undefined) { | ||
})(window, window.angular); | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
@@ -410,13 +410,7 @@ (function (window, angular, undefined) { | ||
if (angular.isArray(obj[key])) { | ||
var _ret = function () { | ||
var arr = obj[key]; | ||
//eslint-disable-next-line no-unused-vars | ||
return { | ||
v: arr.map(function (value, key) { | ||
return copyProperty(arr, key); | ||
}) | ||
}; | ||
}(); | ||
if ((typeof _ret === 'undefined' ? 'undefined' : _typeof(_ret)) === "object") return _ret.v; | ||
var arr = obj[key]; | ||
//eslint-disable-next-line no-unused-vars | ||
return arr.map(function (value, key) { | ||
return copyProperty(arr, key); | ||
}); | ||
} | ||
@@ -538,2 +532,21 @@ if (obj[key] && angular.isFunction(obj[key].clone)) { | ||
/** | ||
* Get a (deep) property by key | ||
*/ | ||
$baseModel.prototype.get = function (path) { | ||
//Initialize object | ||
var obj = this; | ||
//Split path in object keys to traverse | ||
var keys = path.split('.'); | ||
for (var i = 0; i < keys.length && obj !== undefined; i++) { | ||
var key = keys[i]; | ||
obj = obj !== null ? obj[key] : undefined; | ||
} | ||
//Return reference | ||
return obj; | ||
}; | ||
/** | ||
* Extract a subset of data from the model | ||
@@ -934,10 +947,8 @@ */ | ||
if (angular.isDefined(val) && val !== null) { | ||
(function () { | ||
var encodedVal = $url.encodeUriSegment(val); | ||
regex = new RegExp(':' + urlParam + '(\\W|$)', 'g'); | ||
//eslint-disable-next-line no-unused-vars | ||
url = url.replace(regex, function (match, tail) { | ||
return encodedVal + tail; | ||
}); | ||
})(); | ||
var encodedVal = $url.encodeUriSegment(val); | ||
regex = new RegExp(':' + urlParam + '(\\W|$)', 'g'); | ||
//eslint-disable-next-line no-unused-vars | ||
url = url.replace(regex, function (match, tail) { | ||
return encodedVal + tail; | ||
}); | ||
} | ||
@@ -944,0 +955,0 @@ |
@@ -1,2 +0,2 @@ | ||
var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t};!function(t,n,e){"use strict";n.module("Api.Action.Service",["Url.Service"]).factory("$apiAction",["$q","$injector","$log","$url",function(t,e,r,i){function o(t){return t?e.has(t)?t:("$baseModel"!==t&&r.warn("Unknown model class/service:",t),null):null}function s(t,e){if(n.extend(this,t),this.url=i.concat(e.url,this.url||""),this.model=this.model||e.model||!1,this.method=this.method||"GET",this.enforceDataFormat=e.enforceDataFormat||!1,e.config)for(var r in e.config)e.config.hasOwnProperty(r)&&(this[r]=e.config[r]);"undefined"==typeof this.params&&(this.params=e.params),this.params=this.params||{},this.model=o(this.model)}return s.prototype.hasBody=function(){return/^(POST|PUT|PATCH)$/i.test(this.method)},s.prototype.expectsArray=function(){return Boolean(this.isArray)},s.prototype.expectsModel=function(){return this.model&&Boolean(this.isModel)},s.prototype.convertToModel=function(t){var r=this;if(n.isArray(t))return t.map(function(t){return r.convertToModel(t)});if(!t||null===t)return null;var i=e.get(this.model);return new i(t)},s.prototype.parseData=function(t){var e=this.expectsArray(),i=this.expectsModel(),o=n.isArray(t);return o!==e&&(r.warn("Expected",e?"array":"object","as response, got",o?"array":"undefined"==typeof t?"undefined":_typeof(t),"for",this.method,this.url),this.enforceDataFormat&&(t=e?[]:{})),e&&!t?[]:i?this.convertToModel(t):t},s.prototype.successInterceptor=function(t){var n=t.data,e=this.dataKey;if(e){if("undefined"==typeof n[e])throw new Error("Unknown data key: "+e);return n[e]=this.parseData(n[e]),n}return this.parseData(n)},s.prototype.errorInterceptor=function(n){return t.reject(n)},function(t,n){return new s(t,n)}}])}(window,window.angular),function(t,n,e){"use strict";n.module("Api.Service",["Api.Endpoint.Service"]).provider("$api",function(){this.defaults={verbose:!1,enforceDataFormat:!1,baseUrl:"/",actions:{query:{method:"GET",isArray:!0,isModel:!0},get:{method:"GET",isModel:!0},create:{method:"POST"},update:{method:"PUT"},"delete":{method:"DELETE"}},params:{id:"@id"},model:"",config:{},stripTrailingSlashes:!0},this.endpoints={},this.setVerbose=function(t){return this.defaults.verbose=!!t,this},this.setBaseUrl=function(t){return this.defaults.baseUrl=t.replace(/:([0-9]+)/,"\\:$1"),this},this.setEnforceDataFormat=function(t){return this.defaults.enforceDataFormat=!!t,this},this.setDefaultActions=function(t){return this.defaults.actions=t||{},this},this.setDefaultParams=function(t){return this.defaults.params=t||{},this},this.setDefaultModel=function(t){return this.defaults.model=t||!1,this},this.setConfig=function(t,n){return this.defaults.config[t]=n,this},this.stripTrailingSlashes=function(t){return this.defaults.stripTrailingSlashes=!!t,this},this.registerEndpoint=function(t,n){return t&&(this.endpoints[t]=n||{}),this},this.$get=["$log","$apiEndpoint",function(t,e){var r=this,i=function(t){return this[t]};return n.forEach(this.endpoints,function(o,s){i[s]&&t.warn("API endpoint",s,"is being overwritten."),o=n.extend({},r.defaults,o),o.verbose&&t.info("API endpoint",s+":",o),i[s]=e(s,o)}),i}]})}(window,window.angular);var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t};!function(t,n,e){"use strict";n.module("BaseModel.Service",[]).factory("$baseModel",["$window","$log","$injector",function(t,e,r){function i(t){var n=/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}).*/;if(t.match(n)){var e=a(t,a.ISO_8601,!0);if(e.isValid())return e}return null}function o(t,e){if(n.isArray(t[e])){var r=function(){var n=t[e];return{v:n.map(function(t,e){return o(n,e)})}}();if("object"===("undefined"==typeof r?"undefined":_typeof(r)))return r.v}return t[e]&&n.isFunction(t[e].clone)?t[e].clone():n.copy(t[e])}function s(t,n){var e=n;Object.defineProperty(this,"$parent",{enumerable:!1,get:function(){return e},set:function(t){e=t}}),this.fromJSON(t)}var a=void 0;return r.has("moment")?a=r.get("moment"):"undefined"!=typeof t.moment&&(a=t.moment),s.prototype.convertToModel=function(t,i,o){var a=this;if("boolean"==typeof i&&(o=i,i=null),"undefined"==typeof this[t]&&(o?this[t]=[]:this[t]=null),i&&this[t]){if("string"==typeof i){if(!r.has(i))return e.warn("Unknown model",i,"specified for sub model conversion");i=r.get(i)}this[t]instanceof i||(n.isArray(this[t])?this[t]=this[t].map(function(t){return new i(t,a)}):n.isString(this[t])&&s.isId(this[t])?this[t]=new i({id:this[t]},this):this[t]=new i(this[t],this))}},s.prototype.fromJSON=function(t){var e=this;return n.isObject(t)&&n.forEach(t,function(t,n){e[n]=s.valueFromJSON(t)},this),this},s.prototype.toJSON=function(t){var e={};return t&&n.isObject(t)&&n.forEach(t,function(t,n){e[n]=s.valueToJSON(t)}),n.forEach(this,function(t,n){e.hasOwnProperty(n)||(e[n]=s.valueToJSON(t))}),e},s.prototype.extract=function(t){var e=this;if("string"==typeof t)return o(this,t);var r={};return n.isArray(t)&&t.length?n.forEach(t,function(t){r[t]=o(e,t)}):n.forEach(this,function(t,n){"$$"!==n.substr(0,2)&&(r[n]=o(e,n))}),r},s.prototype.merge=function(t){var e=this;return t&&n.isObject(t)&&n.forEach(t,function(n,r){e[r]=o(t,r)}),this},s.prototype.clear=function(){for(var t in this)this.hasOwnProperty(t)&&delete this[t];return this},s.prototype.clone=function(t,n){var e=this.constructor,r=new e(this.extract(),this.$parent);return t&&delete r.id,n&&"object"===("undefined"==typeof n?"undefined":_typeof(n))&&Object.assign(r,n),r},s.prototype.isSame=function(t){return!!t&&(n.isObject(t)?!!t.id&&(this.id&&t.id&&this.id===t.id):this.id===t)},s.prototype.copyProperty=function(t,e){this[e]&&n.isFunction(this[e].clone)?t[e]=this[e].clone():t[e]=n.copy(this[e])},s.prototype.setParent=function(t){this.$parent=t},s.valueFromJSON=function(t){if(n.isArray(t))return t.map(s.valueFromJSON);if(a&&n.isString(t)){var e=i(t);return e||t}if(t&&n.isObject(t)){if(t._isAMomentObject)return t.clone();var r={};for(var o in t)t.hasOwnProperty(o)&&(r[o]=s.valueFromJSON(t[o]));return r}return t},s.valueToJSON=function(t){if(n.isArray(t))return t.map(s.valueToJSON);if(t&&n.isObject(t)){if(n.isFunction(t.toJSON))return t.toJSON();var e={};for(var r in t)t.hasOwnProperty(r)&&"$$"!==r.substr(0,2)&&(e[r]=s.valueToJSON(t[r]));return e}return t},s.onlyId=function(t){return n.isArray(t)?t.map(s.onlyId):t&&"object"===("undefined"==typeof t?"undefined":_typeof(t))&&t.id?t.id:t},s.strip=function(t){for(var e=arguments.length,r=Array(e>1?e-1:0),i=1;i<e;i++)r[i-1]=arguments[i];return n.isArray(t)?t.map(function(t){return s.strip.apply(s,[t].concat(r))}):t&&"object"===("undefined"==typeof t?"undefined":_typeof(t))?(n.forEach(t,function(n,e){r.includes(e)||delete t[e]}),t):t},s.stripIds=function(t){return n.isArray(t)?t.map(function(t){return s.stripIds(t)}):t&&"object"===("undefined"==typeof t?"undefined":_typeof(t))?("undefined"!=typeof t.id&&delete t.id,n.forEach(t,function(t){t&&"object"===("undefined"==typeof t?"undefined":_typeof(t))&&s.stripIds(t)}),t):t},s.isId=function(t){return t.match(/^[a-f\d]{24}$/i)},s}])}(window,window.angular),function(t,n,e){"use strict";n.module("Api.Endpoint.Service",["Api.Action.Service","Api.Request.Service","Url.Service"]).factory("$apiEndpoint",["$url","$apiAction","$apiRequest",function(t,e,r){function i(i,o){var s=this;o.actions=o.actions||{},o.url=t.concat(o.baseUrl,o.url||t.concat(i,":id")),this.$config=o,this.$actions={},n.forEach(o.actions,function(t,i){s.$actions[i]=e(t||{},o),s[i]=n.bind(s,r,s.$actions[i])})}return function(t,n){return new i(t,n)}}])}(window,window.angular),function(t,n,e){"use strict";n.module("Api.Request.Service",["Url.Service"]).factory("$apiRequest",["$http","$url",function(t,r){function i(t){return t&&"hasOwnProperty"!==t&&/^(\.[a-zA-Z_$@][0-9a-zA-Z_$@]*)+$/.test("."+t)}function o(t,n){if(!i(n))throw new Error("Invalid dotted path:"+n);for(var r=n.split("."),o=0;o<r.length&&t!==e;o++){var s=r[o];t=null!==t?t[s]:e}return t}function s(t,e,r){var i={};return n.forEach(t||{},function(t,e){n.isFunction(t)&&(t=t()),n.isString(t)&&"@"===t.charAt(0)&&(t=o(r,t.substr(1))),i[e]=t}),n.extend(i,e||{})}function a(t){var e={};return n.forEach(t.split(/\W/),function(n){if("hasOwnProperty"===n)throw new Error("Invalid parameter name: hasOwnProperty");n&&!/^\\d+$/.test(n)&&new RegExp("(^|[^\\\\]):"+n+"(\\W|$)").test(t)&&(e[n]=!0)}),e}function u(t,n){return n&&(t=t.replace(/\/+$/,"")||"/"),t.replace(/\/\.(?=\w+($|\?))/,".").replace(/\/\\\./,"/.")}function c(t,e,i,o){return t=t.replace(/\\:/g,":"),n.forEach(i,function(i,o){var s=e.hasOwnProperty(o)?e[o]:null,a=void 0;n.isDefined(s)&&null!==s?!function(){var n=r.encodeUriSegment(s);a=new RegExp(":"+o+"(\\W|$)","g"),t=t.replace(a,function(t,e){return n+e})}():(a=new RegExp("(/?):"+o+"(\\W|$)","g"),t=t.replace(a,function(t,n,e){return"/"===e.charAt(0)?e:n+e}))}),u(t,o)}function f(t,e,r,i){var o={},u=["params","model","isArray","isModel","successInterceptor","errorInterceptor","stripTrailingSlashes"];if(n.forEach(t,function(t,e){u.indexOf(e)===-1&&(o[e]=n.copy(t))}),i&&n.isObject(i)&&n.forEach(i,function(t,e){o[e]=n.copy(t)}),t.hasBody()&&r&&n.isObject(r)&&(n.isFunction(r.toJSON)?o.data=r.toJSON():n.isArray(r)?o.data=r:o.data=n.extend({},r)),e=n.copy(e),e&&n.isObject(e))for(var f in e)e.hasOwnProperty(f)&&n.isObject(e[f])&&n.isFunction(e[f].toJSON)&&(e[f]=e[f].toJSON());e=s(t.params,e,r);var p=a(o.url);return o.url=c(t.url,e,p,t.stripTrailingSlashes),n.forEach(e,function(t,n){p[n]||(o.params=o.params||{},o.params[n]=t)}),o}return function(n,e,r,i){n.hasBody()&&e&&!r&&(r=e,e=null);var o=f(n,e,r,i);return t(o).then(function(t){return n.successInterceptor(t)})["catch"](function(t){return n.errorInterceptor(t)})}}])}(window,window.angular); | ||
var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};!function(t,r,n){"use strict";r.module("Api.Action.Service",["Url.Service"]).factory("$apiAction",["$q","$injector","$log","$url",function(t,n,e,i){function o(t){return t?n.has(t)?t:("$baseModel"!==t&&e.warn("Unknown model class/service:",t),null):null}function s(t,n){if(r.extend(this,t),this.url=i.concat(n.url,this.url||""),this.model=this.model||n.model||!1,this.method=this.method||"GET",this.enforceDataFormat=n.enforceDataFormat||!1,n.config)for(var e in n.config)n.config.hasOwnProperty(e)&&(this[e]=n.config[e]);void 0===this.params&&(this.params=n.params),this.params=this.params||{},this.model=o(this.model)}return s.prototype.hasBody=function(){return/^(POST|PUT|PATCH)$/i.test(this.method)},s.prototype.expectsArray=function(){return Boolean(this.isArray)},s.prototype.expectsModel=function(){return this.model&&Boolean(this.isModel)},s.prototype.convertToModel=function(t){var e=this;return r.isArray(t)?t.map(function(t){return e.convertToModel(t)}):t&&null!==t?new(n.get(this.model))(t):null},s.prototype.parseData=function(t){var n=this.expectsArray(),i=this.expectsModel(),o=r.isArray(t);return o!==n&&(e.warn("Expected",n?"array":"object","as response, got",o?"array":void 0===t?"undefined":_typeof(t),"for",this.method,this.url),this.enforceDataFormat&&(t=n?[]:{})),n&&!t?[]:i?this.convertToModel(t):t},s.prototype.successInterceptor=function(t){var r=t.data,n=this.dataKey;if(n){if(void 0===r[n])throw new Error("Unknown data key: "+n);return r[n]=this.parseData(r[n]),r}return this.parseData(r)},s.prototype.errorInterceptor=function(r){return t.reject(r)},function(t,r){return new s(t,r)}}])}(window,window.angular),function(t,r,n){"use strict";r.module("Api.Service",["Api.Endpoint.Service"]).provider("$api",function(){this.defaults={verbose:!1,enforceDataFormat:!1,baseUrl:"/",actions:{query:{method:"GET",isArray:!0,isModel:!0},get:{method:"GET",isModel:!0},create:{method:"POST"},update:{method:"PUT"},delete:{method:"DELETE"}},params:{id:"@id"},model:"",config:{},stripTrailingSlashes:!0},this.endpoints={},this.setVerbose=function(t){return this.defaults.verbose=!!t,this},this.setBaseUrl=function(t){return this.defaults.baseUrl=t.replace(/:([0-9]+)/,"\\:$1"),this},this.setEnforceDataFormat=function(t){return this.defaults.enforceDataFormat=!!t,this},this.setDefaultActions=function(t){return this.defaults.actions=t||{},this},this.setDefaultParams=function(t){return this.defaults.params=t||{},this},this.setDefaultModel=function(t){return this.defaults.model=t||!1,this},this.setConfig=function(t,r){return this.defaults.config[t]=r,this},this.stripTrailingSlashes=function(t){return this.defaults.stripTrailingSlashes=!!t,this},this.registerEndpoint=function(t,r){return t&&(this.endpoints[t]=r||{}),this},this.$get=["$log","$apiEndpoint",function(t,n){var e=this,i=function(t){return this[t]};return r.forEach(this.endpoints,function(o,s){i[s]&&t.warn("API endpoint",s,"is being overwritten."),(o=r.extend({},e.defaults,o)).verbose&&t.info("API endpoint",s+":",o),i[s]=n(s,o)}),i}]})}(window,window.angular);var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};!function(t,r,n){"use strict";r.module("BaseModel.Service",[]).factory("$baseModel",["$window","$log","$injector",function(t,n,e){function i(t){var r=/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}).*/;if(t.match(r)){var n=a(t,a.ISO_8601,!0);if(n.isValid())return n}return null}function o(t,n){if(r.isArray(t[n])){var e=t[n];return e.map(function(t,r){return o(e,r)})}return t[n]&&r.isFunction(t[n].clone)?t[n].clone():r.copy(t[n])}function s(t,r){var n=r;Object.defineProperty(this,"$parent",{enumerable:!1,get:function(){return n},set:function(t){n=t}}),this.fromJSON(t)}var a=void 0;return e.has("moment")?a=e.get("moment"):void 0!==t.moment&&(a=t.moment),s.prototype.convertToModel=function(t,i,o){var a=this;if("boolean"==typeof i&&(o=i,i=null),void 0===this[t]&&(this[t]=o?[]:null),i&&this[t]){if("string"==typeof i){if(!e.has(i))return n.warn("Unknown model",i,"specified for sub model conversion");i=e.get(i)}this[t]instanceof i||(r.isArray(this[t])?this[t]=this[t].map(function(t){return new i(t,a)}):r.isString(this[t])&&s.isId(this[t])?this[t]=new i({id:this[t]},this):this[t]=new i(this[t],this))}},s.prototype.fromJSON=function(t){var n=this;return r.isObject(t)&&r.forEach(t,function(t,r){n[r]=s.valueFromJSON(t)},this),this},s.prototype.toJSON=function(t){var n={};return t&&r.isObject(t)&&r.forEach(t,function(t,r){n[r]=s.valueToJSON(t)}),r.forEach(this,function(t,r){n.hasOwnProperty(r)||(n[r]=s.valueToJSON(t))}),n},s.prototype.get=function(t){for(var r=this,n=t.split("."),e=0;e<n.length&&void 0!==r;e++){var i=n[e];r=null!==r?r[i]:void 0}return r},s.prototype.extract=function(t){var n=this;if("string"==typeof t)return o(this,t);var e={};return r.isArray(t)&&t.length?r.forEach(t,function(t){e[t]=o(n,t)}):r.forEach(this,function(t,r){"$$"!==r.substr(0,2)&&(e[r]=o(n,r))}),e},s.prototype.merge=function(t){var n=this;return t&&r.isObject(t)&&r.forEach(t,function(r,e){n[e]=o(t,e)}),this},s.prototype.clear=function(){for(var t in this)this.hasOwnProperty(t)&&delete this[t];return this},s.prototype.clone=function(t,r){var n=new(0,this.constructor)(this.extract(),this.$parent);return t&&delete n.id,r&&"object"===(void 0===r?"undefined":_typeof(r))&&Object.assign(n,r),n},s.prototype.isSame=function(t){return!!t&&(r.isObject(t)?!!t.id&&(this.id&&t.id&&this.id===t.id):this.id===t)},s.prototype.copyProperty=function(t,n){this[n]&&r.isFunction(this[n].clone)?t[n]=this[n].clone():t[n]=r.copy(this[n])},s.prototype.setParent=function(t){this.$parent=t},s.valueFromJSON=function(t){if(r.isArray(t))return t.map(s.valueFromJSON);if(a&&r.isString(t))return i(t)||t;if(t&&r.isObject(t)){if(t._isAMomentObject)return t.clone();var n={};for(var e in t)t.hasOwnProperty(e)&&(n[e]=s.valueFromJSON(t[e]));return n}return t},s.valueToJSON=function(t){if(r.isArray(t))return t.map(s.valueToJSON);if(t&&r.isObject(t)){if(r.isFunction(t.toJSON))return t.toJSON();var n={};for(var e in t)t.hasOwnProperty(e)&&"$$"!==e.substr(0,2)&&(n[e]=s.valueToJSON(t[e]));return n}return t},s.onlyId=function(t){return r.isArray(t)?t.map(s.onlyId):t&&"object"===(void 0===t?"undefined":_typeof(t))&&t.id?t.id:t},s.strip=function(t){for(var n=arguments.length,e=Array(n>1?n-1:0),i=1;i<n;i++)e[i-1]=arguments[i];return r.isArray(t)?t.map(function(t){return s.strip.apply(s,[t].concat(e))}):t&&"object"===(void 0===t?"undefined":_typeof(t))?(r.forEach(t,function(r,n){e.includes(n)||delete t[n]}),t):t},s.stripIds=function(t){return r.isArray(t)?t.map(function(t){return s.stripIds(t)}):t&&"object"===(void 0===t?"undefined":_typeof(t))?(void 0!==t.id&&delete t.id,r.forEach(t,function(t){t&&"object"===(void 0===t?"undefined":_typeof(t))&&s.stripIds(t)}),t):t},s.isId=function(t){return t.match(/^[a-f\d]{24}$/i)},s}])}(window,window.angular),function(t,r,n){"use strict";r.module("Api.Endpoint.Service",["Api.Action.Service","Api.Request.Service","Url.Service"]).factory("$apiEndpoint",["$url","$apiAction","$apiRequest",function(t,n,e){function i(i,o){var s=this;o.actions=o.actions||{},o.url=t.concat(o.baseUrl,o.url||t.concat(i,":id")),this.$config=o,this.$actions={},r.forEach(o.actions,function(t,i){s.$actions[i]=n(t||{},o),s[i]=r.bind(s,e,s.$actions[i])})}return function(t,r){return new i(t,r)}}])}(window,window.angular),function(t,r,n){"use strict";r.module("Api.Request.Service",["Url.Service"]).factory("$apiRequest",["$http","$url",function(t,e){function i(t){return t&&"hasOwnProperty"!==t&&/^(\.[a-zA-Z_$@][0-9a-zA-Z_$@]*)+$/.test("."+t)}function o(t,r){if(!i(r))throw new Error("Invalid dotted path:"+r);for(var e=r.split("."),o=0;o<e.length&&t!==n;o++){var s=e[o];t=null!==t?t[s]:n}return t}function s(t,n,e){var i={};return r.forEach(t||{},function(t,n){r.isFunction(t)&&(t=t()),r.isString(t)&&"@"===t.charAt(0)&&(t=o(e,t.substr(1))),i[n]=t}),r.extend(i,n||{})}function a(t){var n={};return r.forEach(t.split(/\W/),function(r){if("hasOwnProperty"===r)throw new Error("Invalid parameter name: hasOwnProperty");r&&!/^\\d+$/.test(r)&&new RegExp("(^|[^\\\\]):"+r+"(\\W|$)").test(t)&&(n[r]=!0)}),n}function u(t,r){return r&&(t=t.replace(/\/+$/,"")||"/"),t.replace(/\/\.(?=\w+($|\?))/,".").replace(/\/\\\./,"/.")}function c(t,n,i,o){return t=t.replace(/\\:/g,":"),r.forEach(i,function(i,o){var s=n.hasOwnProperty(o)?n[o]:null,a=void 0;if(r.isDefined(s)&&null!==s){var u=e.encodeUriSegment(s);a=new RegExp(":"+o+"(\\W|$)","g"),t=t.replace(a,function(t,r){return u+r})}else a=new RegExp("(/?):"+o+"(\\W|$)","g"),t=t.replace(a,function(t,r,n){return"/"===n.charAt(0)?n:r+n})}),u(t,o)}function f(t,n,e,i){var o={},u=["params","model","isArray","isModel","successInterceptor","errorInterceptor","stripTrailingSlashes"];if(r.forEach(t,function(t,n){-1===u.indexOf(n)&&(o[n]=r.copy(t))}),i&&r.isObject(i)&&r.forEach(i,function(t,n){o[n]=r.copy(t)}),t.hasBody()&&e&&r.isObject(e)&&(r.isFunction(e.toJSON)?o.data=e.toJSON():r.isArray(e)?o.data=e:o.data=r.extend({},e)),(n=r.copy(n))&&r.isObject(n))for(var f in n)n.hasOwnProperty(f)&&r.isObject(n[f])&&r.isFunction(n[f].toJSON)&&(n[f]=n[f].toJSON());n=s(t.params,n,e);var p=a(o.url);return o.url=c(t.url,n,p,t.stripTrailingSlashes),r.forEach(n,function(t,r){p[r]||(o.params=o.params||{},o.params[r]=t)}),o}return function(r,n,e,i){r.hasBody()&&n&&!e&&(e=n,n=null);var o=f(r,n,e,i);return t(o).then(function(t){return r.successInterceptor(t)}).catch(function(t){return r.errorInterceptor(t)})}}])}(window,window.angular); | ||
//# sourceMappingURL=angular-api.min.js.map |
@@ -162,2 +162,21 @@ | ||
/** | ||
* Get a (deep) property by key | ||
*/ | ||
$baseModel.prototype.get = function(path) { | ||
//Initialize object | ||
let obj = this; | ||
//Split path in object keys to traverse | ||
const keys = path.split('.'); | ||
for (let i = 0; i < keys.length && obj !== undefined; i++) { | ||
const key = keys[i]; | ||
obj = (obj !== null) ? obj[key] : undefined; | ||
} | ||
//Return reference | ||
return obj; | ||
}; | ||
/** | ||
* Extract a subset of data from the model | ||
@@ -164,0 +183,0 @@ */ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
1950
106225