maishu-toolkit
Advanced tools
Comparing version 1.3.5 to 1.3.6
/*! | ||
* ~ | ||
* maishu-toolkit v1.3.4 | ||
* maishu-toolkit v1.3.5 | ||
* https://github.com/ansiboy/toolkit | ||
@@ -255,2 +255,6 @@ * | ||
return new Error(msg); | ||
}, | ||
queryResultTypeError: function queryResultTypeError() { | ||
var msg = "Query result type error."; | ||
return new Error(msg); | ||
} | ||
@@ -461,3 +465,4 @@ }); | ||
dataItems: dataItems | ||
} | ||
}, | ||
selectArguments: args | ||
}); | ||
@@ -628,8 +633,2 @@ | ||
} | ||
}, { | ||
key: "queryResultTypeError", | ||
value: function queryResultTypeError() { | ||
var msg = 'Type of the query result is expected as Array or DataSourceSelectResult.'; | ||
return new Error(msg); | ||
} | ||
}]); | ||
@@ -636,0 +635,0 @@ |
/*! | ||
* ~ | ||
* maishu-toolkit v1.3.4 | ||
* maishu-toolkit v1.3.5 | ||
* https://github.com/ansiboy/toolkit | ||
@@ -10,3 +10,3 @@ * | ||
*/ | ||
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var r=t();for(var n in r)("object"==typeof exports?exports:e)[n]=r[n]}}("undefined"==typeof window?global:window,(function(){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=2)}([function(e,t,r){"use strict";function n(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}Object.defineProperty(t,"__esModule",{value:!0}),t.errors=t.Errors=void 0;var o=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)}var t,r,o;return t=e,(r=[{key:"argumentNull",value:function(e){var t=new Error("Argument ".concat(e," cannt be null or emtpy."));return t.name="argumentNull",t}},{key:"routeDataFieldNull",value:function(e){var t="The ".concat(e," field of route data cannt be null."),r=new Error(t);return r.name="routeDataFieldNull",r}},{key:"argumentFieldNull",value:function(e,t){var r="The ".concat(e," field of ").concat(t," cannt be null."),n=new Error(r);return n.name="argumentFieldNull",n}},{key:"argumentTypeIncorrect",value:function(e,t){var r="Argument ".concat(e," type error, expected type is ").concat(t,"."),n=new Error(r);return n.name="argumentTypeIncorrect",n}},{key:"queryResultTypeError",value:function(){return new Error("Type of the query result is expected as Array or DataSourceSelectResult.")}}])&&n(t.prototype,r),o&&n(t,o),e}();t.Errors=o;var u=new o;t.errors=u},function(e,t,r){"use strict";function n(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}Object.defineProperty(t,"__esModule",{value:!0}),t.Callback=void 0;var o=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.funcs=new Array}var t,r,o;return t=e,o=[{key:"create",value:function(){return new e}}],(r=[{key:"add",value:function(e){this.funcs.push(e)}},{key:"remove",value:function(e){this.funcs=this.funcs.filter((function(t){return t!=e}))}},{key:"fire",value:function(e){this.funcs.forEach((function(t){return t(e)}))}}])&&n(t.prototype,r),o&&n(t,o),e}();t.Callback=o},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),Object.defineProperty(t,"guid",{enumerable:!0,get:function(){return n.guid}}),Object.defineProperty(t,"pathContact",{enumerable:!0,get:function(){return o.pathContact}}),Object.defineProperty(t,"Errors",{enumerable:!0,get:function(){return u.Errors}}),Object.defineProperty(t,"errors",{enumerable:!0,get:function(){return u.errors}}),Object.defineProperty(t,"Callback",{enumerable:!0,get:function(){return a.Callback}}),Object.defineProperty(t,"DataSource",{enumerable:!0,get:function(){return i.DataSource}}),Object.defineProperty(t,"DataSourceSelectArguments",{enumerable:!0,get:function(){return i.DataSourceSelectArguments}}),Object.defineProperty(t,"parseUrl",{enumerable:!0,get:function(){return c.parseUrl}});var n=r(3),o=r(4),u=r(0),a=r(1),i=r(5),c=r(6)},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.guid=function(){function e(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}return e()+e()+"-"+e()+"-"+e()+"-"+e()+"-"+e()+e()+e()}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.pathContact=function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];if(0==(t=t||[]).length)return"";if(1==t.length)return t[0];var n=t.join("/");return n=n.replace(/\/+/g,"/")}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.ArrayDataSource=t.DataSourceSelectArguments=t.DataSource=void 0;var n=r(0),o=r(1);function u(e){return(u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function a(e,t){return!t||"object"!==u(t)&&"function"!=typeof t?function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e):t}function i(e){return(i=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function c(e,t){return(c=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function l(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function s(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}var f=function(e,t,r,n){return new(r||(r=Promise))((function(o,u){function a(e){try{c(n.next(e))}catch(e){u(e)}}function i(e){try{c(n.throw(e))}catch(e){u(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,i)}c((n=n.apply(e,t||[])).next())}))},d=Object.assign(n.errors,{dataSourceCanntInsert:function(){return new Error("DataSource can not insert.")},dataSourceCanntDelete:function(){return new Error("DataSource can not delete.")},dataSourceCanntUpdate:function(){return new Error("DataSource can not update.")},primaryKeyNull:function(e){var t="Primary key named '".concat(e,"' value is null.");return new Error(t)}}),y=function(){function e(t){l(this,e),this.inserting=new o.Callback,this.inserted=new o.Callback,this.deleting=new o.Callback,this.deleted=new o.Callback,this.updating=new o.Callback,this.updated=new o.Callback,this.selecting=new o.Callback,this.selected=new o.Callback,this.error=new o.Callback,this.args=t,this.primaryKeys=t.primaryKeys||[]}var t,r,n;return t=e,(r=[{key:"executeInsert",value:function(e,t){return this.args.insert(e,t)}},{key:"executeDelete",value:function(e,t){return this.args.delete(e,t)}},{key:"executeUpdate",value:function(e,t){return this.args.update(e,t)}},{key:"executeSelect",value:function(e){return e=e||{},this.args.select(e)}},{key:"insert",value:function(e,t,r){var n=this;if(!this.canInsert)throw d.dataSourceCanntInsert();if(!e)throw d.argumentNull("item");return"number"==typeof t&&(r=t,t=null),this.inserting.fire({sender:this,dataItem:e,index:r}),this.executeInsert(e,t).then((function(t){return Object.assign(e,t),n.inserted.fire({sender:n,dataItem:e,index:r}),t})).catch((function(e){throw n.processError(e,"insert"),e}))}},{key:"delete",value:function(e,t){var r=this;if(!this.canDelete)throw d.dataSourceCanntDelete();if(!e)throw d.argumentNull("item");return this.checkPrimaryKeys(e),this.deleting.fire({sender:this,dataItem:e}),this.executeDelete(e,t).then((function(t){return r.deleted.fire({sender:r,dataItem:e}),t})).catch((function(e){throw r.processError(e,"delete"),e}))}},{key:"update",value:function(e,t){var r=this;if(!this.canUpdate)throw d.dataSourceCanntUpdate();if(!e)throw d.argumentNull("item");return this.checkPrimaryKeys(e),this.updating.fire({sender:this,dataItem:e}),this.executeUpdate(e,t).then((function(t){return Object.assign(e,t),r.updated.fire({sender:r,dataItem:e}),t})).catch((function(e){throw r.processError(e,"update"),e}))}},{key:"isSameItem",value:function(e,t){if(null==e)throw d.argumentNull("theItem");if(null==t)throw d.argumentNull("otherItem");if(0==this.primaryKeys.length)return e==t;this.checkPrimaryKeys(e),this.checkPrimaryKeys(t);var r=!0,n=!1,o=void 0;try{for(var u,a=this.primaryKeys[Symbol.iterator]();!(r=(u=a.next()).done);r=!0){var i=u.value;if(e[i]!=t[i])return!1}}catch(e){n=!0,o=e}finally{try{r||null==a.return||a.return()}finally{if(n)throw o}}return!0}},{key:"checkPrimaryKeys",value:function(e){for(var t in e)if(null==e[t]&&this.primaryKeys.indexOf(t)>=0)throw d.primaryKeyNull(t)}},{key:"select",value:function(e){var t=this;return e=e||{},this.selecting.fire({sender:this,selectArguments:e}),this.executeSelect(e).then((function(e){var r,n;if(Array.isArray(e))r=e,n=e.length;else{if(void 0===e.dataItems||void 0===e.totalRowCount)throw d.queryResultTypeError();r=e.dataItems,n=e.totalRowCount}return t.selected.fire({sender:t,selectResult:{totalRowCount:n,dataItems:r}}),{totalRowCount:n,dataItems:r}})).catch((function(e){throw t.processError(e,"select"),e}))}},{key:"processError",value:function(e,t){if(e.method=t,this.error.fire({sender:this,error:e}),!e.handled)throw e}},{key:"canDelete",get:function(){return null!=this.args.delete&&this.primaryKeys.length>0}},{key:"canInsert",get:function(){return null!=this.args.insert&&this.primaryKeys.length>0}},{key:"canUpdate",get:function(){return null!=this.args.update&&this.primaryKeys.length>0}}])&&s(t.prototype,r),n&&s(t,n),e}();t.DataSource=y;t.DataSourceSelectArguments=function e(){l(this,e),this.startRowIndex=0,this.maximumRows=2147483647};var h=function(e){function t(e){return l(this,t),a(this,i(t).call(this,{select:function(t){return f(this,void 0,void 0,regeneratorRuntime.mark((function r(){var n,o;return regeneratorRuntime.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return t.sortExpression,n=e.slice(t.startRowIndex,t.startRowIndex+t.maximumRows),o={dataItems:n,totalRowCount:e.length},r.abrupt("return",o);case 4:case"end":return r.stop()}}),r)})))}}))}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&c(e,t)}(t,e),t}(y);t.ArrayDataSource=h},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.parseUrl=function(e){var t=e.indexOf("?");return t<0?{}:function(e){var t,r=/\+/g,n=/([^&=]+)=?([^&]*)/g,o=function(e){return decodeURIComponent(e.replace(r," "))},u={};for(;t=n.exec(e);)u[o(t[1])]=o(t[2]);return u}(e.substr(t+1))}}])})); | ||
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var r=t();for(var n in r)("object"==typeof exports?exports:e)[n]=r[n]}}("undefined"==typeof window?global:window,(function(){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=2)}([function(e,t,r){"use strict";function n(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}Object.defineProperty(t,"__esModule",{value:!0}),t.errors=t.Errors=void 0;var o=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)}var t,r,o;return t=e,(r=[{key:"argumentNull",value:function(e){var t=new Error("Argument ".concat(e," cannt be null or emtpy."));return t.name="argumentNull",t}},{key:"routeDataFieldNull",value:function(e){var t="The ".concat(e," field of route data cannt be null."),r=new Error(t);return r.name="routeDataFieldNull",r}},{key:"argumentFieldNull",value:function(e,t){var r="The ".concat(e," field of ").concat(t," cannt be null."),n=new Error(r);return n.name="argumentFieldNull",n}},{key:"argumentTypeIncorrect",value:function(e,t){var r="Argument ".concat(e," type error, expected type is ").concat(t,"."),n=new Error(r);return n.name="argumentTypeIncorrect",n}}])&&n(t.prototype,r),o&&n(t,o),e}();t.Errors=o;var u=new o;t.errors=u},function(e,t,r){"use strict";function n(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}Object.defineProperty(t,"__esModule",{value:!0}),t.Callback=void 0;var o=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.funcs=new Array}var t,r,o;return t=e,o=[{key:"create",value:function(){return new e}}],(r=[{key:"add",value:function(e){this.funcs.push(e)}},{key:"remove",value:function(e){this.funcs=this.funcs.filter((function(t){return t!=e}))}},{key:"fire",value:function(e){this.funcs.forEach((function(t){return t(e)}))}}])&&n(t.prototype,r),o&&n(t,o),e}();t.Callback=o},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),Object.defineProperty(t,"guid",{enumerable:!0,get:function(){return n.guid}}),Object.defineProperty(t,"pathContact",{enumerable:!0,get:function(){return o.pathContact}}),Object.defineProperty(t,"Errors",{enumerable:!0,get:function(){return u.Errors}}),Object.defineProperty(t,"errors",{enumerable:!0,get:function(){return u.errors}}),Object.defineProperty(t,"Callback",{enumerable:!0,get:function(){return a.Callback}}),Object.defineProperty(t,"DataSource",{enumerable:!0,get:function(){return i.DataSource}}),Object.defineProperty(t,"DataSourceSelectArguments",{enumerable:!0,get:function(){return i.DataSourceSelectArguments}}),Object.defineProperty(t,"parseUrl",{enumerable:!0,get:function(){return c.parseUrl}});var n=r(3),o=r(4),u=r(0),a=r(1),i=r(5),c=r(6)},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.guid=function(){function e(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}return e()+e()+"-"+e()+"-"+e()+"-"+e()+"-"+e()+e()+e()}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.pathContact=function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];if(0==(t=t||[]).length)return"";if(1==t.length)return t[0];var n=t.join("/");return n=n.replace(/\/+/g,"/")}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.ArrayDataSource=t.DataSourceSelectArguments=t.DataSource=void 0;var n=r(0),o=r(1);function u(e){return(u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function a(e,t){return!t||"object"!==u(t)&&"function"!=typeof t?function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e):t}function i(e){return(i=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function c(e,t){return(c=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function l(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function s(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}var f=function(e,t,r,n){return new(r||(r=Promise))((function(o,u){function a(e){try{c(n.next(e))}catch(e){u(e)}}function i(e){try{c(n.throw(e))}catch(e){u(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,i)}c((n=n.apply(e,t||[])).next())}))},d=Object.assign(n.errors,{dataSourceCanntInsert:function(){return new Error("DataSource can not insert.")},dataSourceCanntDelete:function(){return new Error("DataSource can not delete.")},dataSourceCanntUpdate:function(){return new Error("DataSource can not update.")},primaryKeyNull:function(e){var t="Primary key named '".concat(e,"' value is null.");return new Error(t)},queryResultTypeError:function(){return new Error("Query result type error.")}}),y=function(){function e(t){l(this,e),this.inserting=new o.Callback,this.inserted=new o.Callback,this.deleting=new o.Callback,this.deleted=new o.Callback,this.updating=new o.Callback,this.updated=new o.Callback,this.selecting=new o.Callback,this.selected=new o.Callback,this.error=new o.Callback,this.args=t,this.primaryKeys=t.primaryKeys||[]}var t,r,n;return t=e,(r=[{key:"executeInsert",value:function(e,t){return this.args.insert(e,t)}},{key:"executeDelete",value:function(e,t){return this.args.delete(e,t)}},{key:"executeUpdate",value:function(e,t){return this.args.update(e,t)}},{key:"executeSelect",value:function(e){return e=e||{},this.args.select(e)}},{key:"insert",value:function(e,t,r){var n=this;if(!this.canInsert)throw d.dataSourceCanntInsert();if(!e)throw d.argumentNull("item");return"number"==typeof t&&(r=t,t=null),this.inserting.fire({sender:this,dataItem:e,index:r}),this.executeInsert(e,t).then((function(t){return Object.assign(e,t),n.inserted.fire({sender:n,dataItem:e,index:r}),t})).catch((function(e){throw n.processError(e,"insert"),e}))}},{key:"delete",value:function(e,t){var r=this;if(!this.canDelete)throw d.dataSourceCanntDelete();if(!e)throw d.argumentNull("item");return this.checkPrimaryKeys(e),this.deleting.fire({sender:this,dataItem:e}),this.executeDelete(e,t).then((function(t){return r.deleted.fire({sender:r,dataItem:e}),t})).catch((function(e){throw r.processError(e,"delete"),e}))}},{key:"update",value:function(e,t){var r=this;if(!this.canUpdate)throw d.dataSourceCanntUpdate();if(!e)throw d.argumentNull("item");return this.checkPrimaryKeys(e),this.updating.fire({sender:this,dataItem:e}),this.executeUpdate(e,t).then((function(t){return Object.assign(e,t),r.updated.fire({sender:r,dataItem:e}),t})).catch((function(e){throw r.processError(e,"update"),e}))}},{key:"isSameItem",value:function(e,t){if(null==e)throw d.argumentNull("theItem");if(null==t)throw d.argumentNull("otherItem");if(0==this.primaryKeys.length)return e==t;this.checkPrimaryKeys(e),this.checkPrimaryKeys(t);var r=!0,n=!1,o=void 0;try{for(var u,a=this.primaryKeys[Symbol.iterator]();!(r=(u=a.next()).done);r=!0){var i=u.value;if(e[i]!=t[i])return!1}}catch(e){n=!0,o=e}finally{try{r||null==a.return||a.return()}finally{if(n)throw o}}return!0}},{key:"checkPrimaryKeys",value:function(e){for(var t in e)if(null==e[t]&&this.primaryKeys.indexOf(t)>=0)throw d.primaryKeyNull(t)}},{key:"select",value:function(e){var t=this;return e=e||{},this.selecting.fire({sender:this,selectArguments:e}),this.executeSelect(e).then((function(r){var n,o;if(Array.isArray(r))n=r,o=r.length;else{if(void 0===r.dataItems||void 0===r.totalRowCount)throw d.queryResultTypeError();n=r.dataItems,o=r.totalRowCount}return t.selected.fire({sender:t,selectResult:{totalRowCount:o,dataItems:n},selectArguments:e}),{totalRowCount:o,dataItems:n}})).catch((function(e){throw t.processError(e,"select"),e}))}},{key:"processError",value:function(e,t){if(e.method=t,this.error.fire({sender:this,error:e}),!e.handled)throw e}},{key:"canDelete",get:function(){return null!=this.args.delete&&this.primaryKeys.length>0}},{key:"canInsert",get:function(){return null!=this.args.insert&&this.primaryKeys.length>0}},{key:"canUpdate",get:function(){return null!=this.args.update&&this.primaryKeys.length>0}}])&&s(t.prototype,r),n&&s(t,n),e}();t.DataSource=y;t.DataSourceSelectArguments=function e(){l(this,e),this.startRowIndex=0,this.maximumRows=2147483647};var h=function(e){function t(e){return l(this,t),a(this,i(t).call(this,{select:function(t){return f(this,void 0,void 0,regeneratorRuntime.mark((function r(){var n,o;return regeneratorRuntime.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return t.sortExpression,n=e.slice(t.startRowIndex,t.startRowIndex+t.maximumRows),o={dataItems:n,totalRowCount:e.length},r.abrupt("return",o);case 4:case"end":return r.stop()}}),r)})))}}))}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&c(e,t)}(t,e),t}(y);t.ArrayDataSource=h},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.parseUrl=function(e){var t=e.indexOf("?");return t<0?{}:function(e){var t,r=/\+/g,n=/([^&=]+)=?([^&]*)/g,o=function(e){return decodeURIComponent(e.replace(r," "))},u={};for(;t=n.exec(e);)u[o(t[1])]=o(t[2]);return u}(e.substr(t+1))}}])})); | ||
//# sourceMappingURL=index.es5.min.js.map |
/*! | ||
* ~ | ||
* maishu-toolkit v1.3.4 | ||
* maishu-toolkit v1.3.5 | ||
* https://github.com/ansiboy/toolkit | ||
@@ -177,2 +177,6 @@ * | ||
return new Error(msg); | ||
}, | ||
queryResultTypeError() { | ||
let msg = `Query result type error.`; | ||
return new Error(msg); | ||
} | ||
@@ -306,3 +310,3 @@ }); | ||
} | ||
this.selected.fire({ sender: this, selectResult: { totalRowCount, dataItems } }); | ||
this.selected.fire({ sender: this, selectResult: { totalRowCount, dataItems }, selectArguments: args }); | ||
return { totalRowCount, dataItems }; | ||
@@ -386,6 +390,2 @@ }).catch(exc => { | ||
} | ||
queryResultTypeError() { | ||
let msg = 'Type of the query result is expected as Array or DataSourceSelectResult.'; | ||
return new Error(msg); | ||
} | ||
} | ||
@@ -392,0 +392,0 @@ let errors = new Errors(); |
/*! | ||
* ~ | ||
* maishu-toolkit v1.3.4 | ||
* maishu-toolkit v1.3.5 | ||
* https://github.com/ansiboy/toolkit | ||
@@ -10,3 +10,3 @@ * | ||
*/ | ||
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var r=t();for(var n in r)("object"==typeof exports?exports:e)[n]=r[n]}}("undefined"==typeof window?global:window,(function(){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var i=t[n]={i:n,l:!1,exports:{}};return e[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)r.d(n,i,function(t){return e[t]}.bind(null,i));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=0)}([function(e,t,r){"use strict";function n(){function e(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}return e()+e()+"-"+e()+"-"+e()+"-"+e()+"-"+e()+e()+e()}function i(...e){if(0==(e=e||[]).length)return"";if(1==e.length)return e[0];let t=e.join("/");return t=t.replace(/\/+/g,"/"),t}r.r(t);class s{argumentNull(e){let t=new Error(`Argument ${e} cannt be null or emtpy.`);return t.name="argumentNull",t}routeDataFieldNull(e){let t=new Error(`The ${e} field of route data cannt be null.`);return t.name="routeDataFieldNull",t}argumentFieldNull(e,t){let r=new Error(`The ${e} field of ${t} cannt be null.`);return r.name="argumentFieldNull",r}argumentTypeIncorrect(e,t){let r=new Error(`Argument ${e} type error, expected type is ${t}.`);return r.name="argumentTypeIncorrect",r}queryResultTypeError(){return new Error("Type of the query result is expected as Array or DataSourceSelectResult.")}}let u=new s;class a{constructor(){this.funcs=new Array}add(e){this.funcs.push(e)}remove(e){this.funcs=this.funcs.filter(t=>t!=e)}fire(e){this.funcs.forEach(t=>t(e))}static create(){return new a}}let o=Object.assign(u,{dataSourceCanntInsert:()=>new Error("DataSource can not insert."),dataSourceCanntDelete:()=>new Error("DataSource can not delete."),dataSourceCanntUpdate:()=>new Error("DataSource can not update."),primaryKeyNull:e=>new Error(`Primary key named '${e}' value is null.`)});class l{constructor(e){this.inserting=new a,this.inserted=new a,this.deleting=new a,this.deleted=new a,this.updating=new a,this.updated=new a,this.selecting=new a,this.selected=new a,this.error=new a,this.args=e,this.primaryKeys=e.primaryKeys||[]}get canDelete(){return null!=this.args.delete&&this.primaryKeys.length>0}get canInsert(){return null!=this.args.insert&&this.primaryKeys.length>0}get canUpdate(){return null!=this.args.update&&this.primaryKeys.length>0}executeInsert(e,t){return this.args.insert(e,t)}executeDelete(e,t){return this.args.delete(e,t)}executeUpdate(e,t){return this.args.update(e,t)}executeSelect(e){return e=e||{},this.args.select(e)}insert(e,t,r){if(!this.canInsert)throw o.dataSourceCanntInsert();if(!e)throw o.argumentNull("item");return"number"==typeof t&&(r=t,t=null),this.inserting.fire({sender:this,dataItem:e,index:r}),this.executeInsert(e,t).then(t=>(Object.assign(e,t),this.inserted.fire({sender:this,dataItem:e,index:r}),t)).catch(e=>{throw this.processError(e,"insert"),e})}delete(e,t){if(!this.canDelete)throw o.dataSourceCanntDelete();if(!e)throw o.argumentNull("item");return this.checkPrimaryKeys(e),this.deleting.fire({sender:this,dataItem:e}),this.executeDelete(e,t).then(t=>(this.deleted.fire({sender:this,dataItem:e}),t)).catch(e=>{throw this.processError(e,"delete"),e})}update(e,t){if(!this.canUpdate)throw o.dataSourceCanntUpdate();if(!e)throw o.argumentNull("item");return this.checkPrimaryKeys(e),this.updating.fire({sender:this,dataItem:e}),this.executeUpdate(e,t).then(t=>(Object.assign(e,t),this.updated.fire({sender:this,dataItem:e}),t)).catch(e=>{throw this.processError(e,"update"),e})}isSameItem(e,t){if(null==e)throw o.argumentNull("theItem");if(null==t)throw o.argumentNull("otherItem");if(0==this.primaryKeys.length)return e==t;this.checkPrimaryKeys(e),this.checkPrimaryKeys(t);for(let r of this.primaryKeys)if(e[r]!=t[r])return!1;return!0}checkPrimaryKeys(e){for(let t in e)if(null==e[t]&&this.primaryKeys.indexOf(t)>=0)throw o.primaryKeyNull(t)}select(e){return e=e||{},this.selecting.fire({sender:this,selectArguments:e}),this.executeSelect(e).then(e=>{let t,r;if(Array.isArray(e))t=e,r=e.length;else{if(void 0===e.dataItems||void 0===e.totalRowCount)throw o.queryResultTypeError();t=e.dataItems,r=e.totalRowCount}return this.selected.fire({sender:this,selectResult:{totalRowCount:r,dataItems:t}}),{totalRowCount:r,dataItems:t}}).catch(e=>{throw this.processError(e,"select"),e})}processError(e,t){if(e.method=t,this.error.fire({sender:this,error:e}),!e.handled)throw e}}class c{constructor(){this.startRowIndex=0,this.maximumRows=2147483647}}function d(e){let t=e.indexOf("?");return t<0?{}:function(e){let t,r=/\+/g,n=/([^&=]+)=?([^&]*)/g,i=function(e){return decodeURIComponent(e.replace(r," "))},s={};for(;t=n.exec(e);)s[i(t[1])]=i(t[2]);return s}(e.substr(t+1))}r.d(t,"guid",(function(){return n})),r.d(t,"pathContact",(function(){return i})),r.d(t,"Errors",(function(){return s})),r.d(t,"errors",(function(){return u})),r.d(t,"Callback",(function(){return a})),r.d(t,"DataSource",(function(){return l})),r.d(t,"DataSourceSelectArguments",(function(){return c})),r.d(t,"parseUrl",(function(){return d}))}])})); | ||
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var r=t();for(var n in r)("object"==typeof exports?exports:e)[n]=r[n]}}("undefined"==typeof window?global:window,(function(){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var i=t[n]={i:n,l:!1,exports:{}};return e[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)r.d(n,i,function(t){return e[t]}.bind(null,i));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=0)}([function(e,t,r){"use strict";function n(){function e(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}return e()+e()+"-"+e()+"-"+e()+"-"+e()+"-"+e()+e()+e()}function i(...e){if(0==(e=e||[]).length)return"";if(1==e.length)return e[0];let t=e.join("/");return t=t.replace(/\/+/g,"/"),t}r.r(t);class s{argumentNull(e){let t=new Error(`Argument ${e} cannt be null or emtpy.`);return t.name="argumentNull",t}routeDataFieldNull(e){let t=new Error(`The ${e} field of route data cannt be null.`);return t.name="routeDataFieldNull",t}argumentFieldNull(e,t){let r=new Error(`The ${e} field of ${t} cannt be null.`);return r.name="argumentFieldNull",r}argumentTypeIncorrect(e,t){let r=new Error(`Argument ${e} type error, expected type is ${t}.`);return r.name="argumentTypeIncorrect",r}}let u=new s;class a{constructor(){this.funcs=new Array}add(e){this.funcs.push(e)}remove(e){this.funcs=this.funcs.filter(t=>t!=e)}fire(e){this.funcs.forEach(t=>t(e))}static create(){return new a}}let o=Object.assign(u,{dataSourceCanntInsert:()=>new Error("DataSource can not insert."),dataSourceCanntDelete:()=>new Error("DataSource can not delete."),dataSourceCanntUpdate:()=>new Error("DataSource can not update."),primaryKeyNull:e=>new Error(`Primary key named '${e}' value is null.`),queryResultTypeError:()=>new Error("Query result type error.")});class l{constructor(e){this.inserting=new a,this.inserted=new a,this.deleting=new a,this.deleted=new a,this.updating=new a,this.updated=new a,this.selecting=new a,this.selected=new a,this.error=new a,this.args=e,this.primaryKeys=e.primaryKeys||[]}get canDelete(){return null!=this.args.delete&&this.primaryKeys.length>0}get canInsert(){return null!=this.args.insert&&this.primaryKeys.length>0}get canUpdate(){return null!=this.args.update&&this.primaryKeys.length>0}executeInsert(e,t){return this.args.insert(e,t)}executeDelete(e,t){return this.args.delete(e,t)}executeUpdate(e,t){return this.args.update(e,t)}executeSelect(e){return e=e||{},this.args.select(e)}insert(e,t,r){if(!this.canInsert)throw o.dataSourceCanntInsert();if(!e)throw o.argumentNull("item");return"number"==typeof t&&(r=t,t=null),this.inserting.fire({sender:this,dataItem:e,index:r}),this.executeInsert(e,t).then(t=>(Object.assign(e,t),this.inserted.fire({sender:this,dataItem:e,index:r}),t)).catch(e=>{throw this.processError(e,"insert"),e})}delete(e,t){if(!this.canDelete)throw o.dataSourceCanntDelete();if(!e)throw o.argumentNull("item");return this.checkPrimaryKeys(e),this.deleting.fire({sender:this,dataItem:e}),this.executeDelete(e,t).then(t=>(this.deleted.fire({sender:this,dataItem:e}),t)).catch(e=>{throw this.processError(e,"delete"),e})}update(e,t){if(!this.canUpdate)throw o.dataSourceCanntUpdate();if(!e)throw o.argumentNull("item");return this.checkPrimaryKeys(e),this.updating.fire({sender:this,dataItem:e}),this.executeUpdate(e,t).then(t=>(Object.assign(e,t),this.updated.fire({sender:this,dataItem:e}),t)).catch(e=>{throw this.processError(e,"update"),e})}isSameItem(e,t){if(null==e)throw o.argumentNull("theItem");if(null==t)throw o.argumentNull("otherItem");if(0==this.primaryKeys.length)return e==t;this.checkPrimaryKeys(e),this.checkPrimaryKeys(t);for(let r of this.primaryKeys)if(e[r]!=t[r])return!1;return!0}checkPrimaryKeys(e){for(let t in e)if(null==e[t]&&this.primaryKeys.indexOf(t)>=0)throw o.primaryKeyNull(t)}select(e){return e=e||{},this.selecting.fire({sender:this,selectArguments:e}),this.executeSelect(e).then(t=>{let r,n;if(Array.isArray(t))r=t,n=t.length;else{if(void 0===t.dataItems||void 0===t.totalRowCount)throw o.queryResultTypeError();r=t.dataItems,n=t.totalRowCount}return this.selected.fire({sender:this,selectResult:{totalRowCount:n,dataItems:r},selectArguments:e}),{totalRowCount:n,dataItems:r}}).catch(e=>{throw this.processError(e,"select"),e})}processError(e,t){if(e.method=t,this.error.fire({sender:this,error:e}),!e.handled)throw e}}class c{constructor(){this.startRowIndex=0,this.maximumRows=2147483647}}function d(e){let t=e.indexOf("?");return t<0?{}:function(e){let t,r=/\+/g,n=/([^&=]+)=?([^&]*)/g,i=function(e){return decodeURIComponent(e.replace(r," "))},s={};for(;t=n.exec(e);)s[i(t[1])]=i(t[2]);return s}(e.substr(t+1))}r.d(t,"guid",(function(){return n})),r.d(t,"pathContact",(function(){return i})),r.d(t,"Errors",(function(){return s})),r.d(t,"errors",(function(){return u})),r.d(t,"Callback",(function(){return a})),r.d(t,"DataSource",(function(){return l})),r.d(t,"DataSourceSelectArguments",(function(){return c})),r.d(t,"parseUrl",(function(){return d}))}])})); | ||
//# sourceMappingURL=index.min.js.map |
@@ -75,2 +75,6 @@ "use strict"; | ||
return new Error(msg); | ||
}, | ||
queryResultTypeError: function queryResultTypeError() { | ||
var msg = "Query result type error."; | ||
return new Error(msg); | ||
} | ||
@@ -281,3 +285,4 @@ }); | ||
dataItems: dataItems | ||
} | ||
}, | ||
selectArguments: args | ||
}); | ||
@@ -284,0 +289,0 @@ |
@@ -56,8 +56,2 @@ "use strict"; | ||
} | ||
}, { | ||
key: "queryResultTypeError", | ||
value: function queryResultTypeError() { | ||
var msg = 'Type of the query result is expected as Array or DataSourceSelectResult.'; | ||
return new Error(msg); | ||
} | ||
}]); | ||
@@ -64,0 +58,0 @@ |
@@ -47,2 +47,3 @@ import { Callback } from "./callback"; | ||
selectResult: DataSourceSelectResult<T>; | ||
selectArguments: DataSourceSelectArguments; | ||
}>; | ||
@@ -49,0 +50,0 @@ error: Callback<{ |
@@ -25,2 +25,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new Error(msg); | ||
}, | ||
queryResultTypeError() { | ||
let msg = `Query result type error.`; | ||
return new Error(msg); | ||
} | ||
@@ -154,3 +158,3 @@ }); | ||
} | ||
this.selected.fire({ sender: this, selectResult: { totalRowCount, dataItems } }); | ||
this.selected.fire({ sender: this, selectResult: { totalRowCount, dataItems }, selectArguments: args }); | ||
return { totalRowCount, dataItems }; | ||
@@ -157,0 +161,0 @@ }).catch(exc => { |
@@ -6,4 +6,3 @@ export declare class Errors { | ||
argumentTypeIncorrect(argumentName: string, expectedType: string): Error; | ||
queryResultTypeError(): Error; | ||
} | ||
export declare let errors: Errors; |
@@ -29,7 +29,3 @@ export class Errors { | ||
} | ||
queryResultTypeError() { | ||
let msg = 'Type of the query result is expected as Array or DataSourceSelectResult.'; | ||
return new Error(msg); | ||
} | ||
} | ||
export let errors = new Errors(); |
{ | ||
"name": "maishu-toolkit", | ||
"version": "1.3.5", | ||
"version": "1.3.6", | ||
"main": "./dist/index.js", | ||
@@ -5,0 +5,0 @@ "types": "./out/index.d.ts", |
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
224681
2221