maishu-router
Advanced tools
Comparing version 1.1.0 to 1.1.1
1215
dist/index.js
@@ -1,107 +0,3 @@ | ||
(function webpackUniversalModuleDefinition(root, factory) { | ||
if(typeof exports === 'object' && typeof module === 'object') | ||
module.exports = factory(); | ||
else if(typeof define === 'function' && define.amd) | ||
define([], factory); | ||
else { | ||
var a = factory(); | ||
for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i]; | ||
} | ||
})(typeof window === 'undefined' ? global : window, function() { | ||
return /******/ (function(modules) { // webpackBootstrap | ||
/******/ // The module cache | ||
/******/ var installedModules = {}; | ||
/******/ | ||
/******/ // The require function | ||
/******/ function __webpack_require__(moduleId) { | ||
/******/ | ||
/******/ // Check if module is in cache | ||
/******/ if(installedModules[moduleId]) { | ||
/******/ return installedModules[moduleId].exports; | ||
/******/ } | ||
/******/ // Create a new module (and put it into the cache) | ||
/******/ var module = installedModules[moduleId] = { | ||
/******/ i: moduleId, | ||
/******/ l: false, | ||
/******/ exports: {} | ||
/******/ }; | ||
/******/ | ||
/******/ // Execute the module function | ||
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); | ||
/******/ | ||
/******/ // Flag the module as loaded | ||
/******/ module.l = true; | ||
/******/ | ||
/******/ // Return the exports of the module | ||
/******/ return module.exports; | ||
/******/ } | ||
/******/ | ||
/******/ | ||
/******/ // expose the modules object (__webpack_modules__) | ||
/******/ __webpack_require__.m = modules; | ||
/******/ | ||
/******/ // expose the module cache | ||
/******/ __webpack_require__.c = installedModules; | ||
/******/ | ||
/******/ // define getter function for harmony exports | ||
/******/ __webpack_require__.d = function(exports, name, getter) { | ||
/******/ if(!__webpack_require__.o(exports, name)) { | ||
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); | ||
/******/ } | ||
/******/ }; | ||
/******/ | ||
/******/ // define __esModule on exports | ||
/******/ __webpack_require__.r = function(exports) { | ||
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { | ||
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); | ||
/******/ } | ||
/******/ Object.defineProperty(exports, '__esModule', { value: true }); | ||
/******/ }; | ||
/******/ | ||
/******/ // create a fake namespace object | ||
/******/ // mode & 1: value is a module id, require it | ||
/******/ // mode & 2: merge all properties of value into the ns | ||
/******/ // mode & 4: return value when already ns object | ||
/******/ // mode & 8|1: behave like require | ||
/******/ __webpack_require__.t = function(value, mode) { | ||
/******/ if(mode & 1) value = __webpack_require__(value); | ||
/******/ if(mode & 8) return value; | ||
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; | ||
/******/ var ns = Object.create(null); | ||
/******/ __webpack_require__.r(ns); | ||
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); | ||
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); | ||
/******/ return ns; | ||
/******/ }; | ||
/******/ | ||
/******/ // getDefaultExport function for compatibility with non-harmony modules | ||
/******/ __webpack_require__.n = function(module) { | ||
/******/ var getter = module && module.__esModule ? | ||
/******/ function getDefault() { return module['default']; } : | ||
/******/ function getModuleExports() { return module; }; | ||
/******/ __webpack_require__.d(getter, 'a', getter); | ||
/******/ return getter; | ||
/******/ }; | ||
/******/ | ||
/******/ // Object.prototype.hasOwnProperty.call | ||
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; | ||
/******/ | ||
/******/ // __webpack_public_path__ | ||
/******/ __webpack_require__.p = ""; | ||
/******/ | ||
/******/ | ||
/******/ // Load entry module and return exports | ||
/******/ return __webpack_require__(__webpack_require__.s = "./out/index.js"); | ||
/******/ }) | ||
/************************************************************************/ | ||
/******/ ({ | ||
/***/ "./node_modules/maishu-toolkit/dist/index.js": | ||
/*!***************************************************!*\ | ||
!*** ./node_modules/maishu-toolkit/dist/index.js ***! | ||
\***************************************************/ | ||
/*! no static exports found */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
/* WEBPACK VAR INJECTION */(function(global) {/*! | ||
!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=3)}([function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.errors=void 0;const n=r(4);class i extends n.Errors{invalidRouteSegment(e){let t=new Error(`Route segment ${e} is invalid.`);return t.name=i.prototype.invalidRouteSegment.name,t}routeItemExists(e){let t=new Error(`Route '${e}' is exists.`);return t.name=i.prototype.routeItemExists.name,t}invalidPath(e){let t=new Error(`Path '${e}' is invalid path.`);return t.name=i.prototype.invalidPath.name,t}}t.errors=new i},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Router=void 0;const n=r(0),i=r(6),s=r(7);t.Router=class{constructor(e,t){if(!e)throw n.errors.argumentNull("pattern");t=t||{},this._pattern=e,this._items=new s.RouterItems(e);for(let e=0;e<this._items.all.length;e++){let r=this._items.all[e].name;null!=r&&null!=t[r]&&(this._items.all[e].regexp=t[r])}}match(e){let t=new i.PathSegment(e),r=this._items;do{if(!(r.current.isWildcards?r.current.regexp.test(t.else):r.current.regexp.test(t.current))){if(r.current.isOption)continue;return null}r.current.value=r.current.isWildcards?t.else:t.current,t.moveNext()}while(null!=r.moveNext());let n={};for(let e=0;e<r.all.length;e++){let t=r.all[e].name,i=r.all[e].value;null!=t&&(n[t]=i)}return n}item(e){return this._items.all.filter(t=>t.name==e)[0]}get items(){return this._items}get pattern(){return this._pattern}}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.RouterItem=void 0;const n=r(0);t.RouterItem=class{constructor(e){this._isOption=!1,this._isWildcards=!1,this._name=null;let t=/[*|:|?]{0,1}(\S+)/.exec(e);if(!t)throw n.errors.invalidRouteSegment(e);switch(e[0]){case"*":this._isWildcards=!0,this._regexp=/\S+/,this._name=t[1];break;case":":this._regexp=/\S+/,this._name=t[1];break;case"?":this._regexp=/\S+/,this._name=t[1],this._isOption=!0;break;default:this._regexp=new RegExp(e)}}get isOption(){return this._isOption}get isWildcards(){return this._isWildcards}get name(){return this._name}get regexp(){return this._regexp}set regexp(e){this._regexp=e}get value(){return this._value}set value(e){this._value=e}}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.createRouter=t.RouterItem=t.Router=void 0;const n=r(1);var i=r(1);Object.defineProperty(t,"Router",{enumerable:!0,get:function(){return i.Router}});var s=r(2);Object.defineProperty(t,"RouterItem",{enumerable:!0,get:function(){return s.RouterItem}}),t.createRouter=function(e,t){return new n.Router(e,t)}},function(e,t,r){(function(t){ | ||
/*! | ||
* ~ | ||
@@ -115,1132 +11,51 @@ * maishu-toolkit v1.6.5 | ||
*/ | ||
(function webpackUniversalModuleDefinition(root, factory) { | ||
if(true) | ||
module.exports = factory(); | ||
else { var i, a; } | ||
})(typeof window === 'undefined' ? global : window, function() { | ||
return /******/ (function(modules) { // webpackBootstrap | ||
/******/ // The module cache | ||
/******/ var installedModules = {}; | ||
/******/ | ||
/******/ // The require function | ||
/******/ function __webpack_require__(moduleId) { | ||
/******/ | ||
/******/ // Check if module is in cache | ||
/******/ if(installedModules[moduleId]) { | ||
/******/ return installedModules[moduleId].exports; | ||
/******/ } | ||
/******/ // Create a new module (and put it into the cache) | ||
/******/ var module = installedModules[moduleId] = { | ||
/******/ i: moduleId, | ||
/******/ l: false, | ||
/******/ exports: {} | ||
/******/ }; | ||
/******/ | ||
/******/ // Execute the module function | ||
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); | ||
/******/ | ||
/******/ // Flag the module as loaded | ||
/******/ module.l = true; | ||
/******/ | ||
/******/ // Return the exports of the module | ||
/******/ return module.exports; | ||
/******/ } | ||
/******/ | ||
/******/ | ||
/******/ // expose the modules object (__webpack_modules__) | ||
/******/ __webpack_require__.m = modules; | ||
/******/ | ||
/******/ // expose the module cache | ||
/******/ __webpack_require__.c = installedModules; | ||
/******/ | ||
/******/ // define getter function for harmony exports | ||
/******/ __webpack_require__.d = function(exports, name, getter) { | ||
/******/ if(!__webpack_require__.o(exports, name)) { | ||
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); | ||
/******/ } | ||
/******/ }; | ||
/******/ | ||
/******/ // define __esModule on exports | ||
/******/ __webpack_require__.r = function(exports) { | ||
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { | ||
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); | ||
/******/ } | ||
/******/ Object.defineProperty(exports, '__esModule', { value: true }); | ||
/******/ }; | ||
/******/ | ||
/******/ // create a fake namespace object | ||
/******/ // mode & 1: value is a module id, require it | ||
/******/ // mode & 2: merge all properties of value into the ns | ||
/******/ // mode & 4: return value when already ns object | ||
/******/ // mode & 8|1: behave like require | ||
/******/ __webpack_require__.t = function(value, mode) { | ||
/******/ if(mode & 1) value = __webpack_require__(value); | ||
/******/ if(mode & 8) return value; | ||
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; | ||
/******/ var ns = Object.create(null); | ||
/******/ __webpack_require__.r(ns); | ||
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); | ||
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); | ||
/******/ return ns; | ||
/******/ }; | ||
/******/ | ||
/******/ // getDefaultExport function for compatibility with non-harmony modules | ||
/******/ __webpack_require__.n = function(module) { | ||
/******/ var getter = module && module.__esModule ? | ||
/******/ function getDefault() { return module['default']; } : | ||
/******/ function getModuleExports() { return module; }; | ||
/******/ __webpack_require__.d(getter, 'a', getter); | ||
/******/ return getter; | ||
/******/ }; | ||
/******/ | ||
/******/ // Object.prototype.hasOwnProperty.call | ||
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; | ||
/******/ | ||
/******/ // __webpack_public_path__ | ||
/******/ __webpack_require__.p = ""; | ||
/******/ | ||
/******/ | ||
/******/ // Load entry module and return exports | ||
/******/ return __webpack_require__(__webpack_require__.s = "./out/index.js"); | ||
/******/ }) | ||
/************************************************************************/ | ||
/******/ ({ | ||
/***/ "./out/assign-deep.js": | ||
var r;"undefined"==typeof window||window,r=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="./out/index.js")}({"./out/assign-deep.js": | ||
/*!****************************!*\ | ||
!*** ./out/assign-deep.js ***! | ||
\****************************/ | ||
/*! exports provided: objectAssignDeep, objectAssignDeepInto, withOptions */ | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
"use strict"; | ||
__webpack_require__.r(__webpack_exports__); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "objectAssignDeep", function() { return objectAssignDeep; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "objectAssignDeepInto", function() { return objectAssignDeepInto; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "withOptions", function() { return withOptions; }); | ||
/* | ||
* OBJECT ASSIGN DEEP | ||
* Allows deep cloning of plain objects that contain primitives, nested plain objects, or nested plain arrays. | ||
*/ | ||
/* | ||
* A unified way of returning a string that describes the type of the given variable. | ||
*/ | ||
function getTypeOf(input) { | ||
if (input === null) { | ||
return 'null'; | ||
} | ||
else if (typeof input === 'undefined') { | ||
return 'undefined'; | ||
} | ||
else if (typeof input === 'object') { | ||
return (Array.isArray(input) ? 'array' : 'object'); | ||
} | ||
return typeof input; | ||
} | ||
/* | ||
* Branching logic which calls the correct function to clone the given value base on its type. | ||
*/ | ||
function cloneValue(value) { | ||
// The value is an object so lets clone it. | ||
if (getTypeOf(value) === 'object') { | ||
return quickCloneObject(value); | ||
} | ||
// The value is an array so lets clone it. | ||
else if (getTypeOf(value) === 'array') { | ||
return quickCloneArray(value); | ||
} | ||
// Any other value can just be copied. | ||
return value; | ||
} | ||
/* | ||
* Enumerates the given array and returns a new array, with each of its values cloned (i.e. references broken). | ||
*/ | ||
function quickCloneArray(input) { | ||
return input.map(cloneValue); | ||
} | ||
/* | ||
* Enumerates the properties of the given object (ignoring the prototype chain) and returns a new object, with each of | ||
* its values cloned (i.e. references broken). | ||
*/ | ||
function quickCloneObject(input) { | ||
const output = {}; | ||
for (const key in input) { | ||
if (!input.hasOwnProperty(key)) { | ||
continue; | ||
} | ||
output[key] = cloneValue(input[key]); | ||
} | ||
return output; | ||
} | ||
/* | ||
* Does the actual deep merging. | ||
*/ | ||
function executeDeepMerge(target, _objects = [], _options = {}) { | ||
const options = { | ||
arrayBehaviour: _options.arrayBehaviour || 'replace', | ||
}; | ||
// Ensure we have actual objects for each. | ||
const objects = _objects.map(object => object || {}); | ||
const output = target || {}; | ||
// Enumerate the objects and their keys. | ||
for (let oindex = 0; oindex < objects.length; oindex++) { | ||
const object = objects[oindex]; | ||
const keys = Object.keys(object); | ||
for (let kindex = 0; kindex < keys.length; kindex++) { | ||
const key = keys[kindex]; | ||
const value = object[key]; | ||
const type = getTypeOf(value); | ||
const existingValueType = getTypeOf(output[key]); | ||
if (type === 'object') { | ||
if (existingValueType !== 'undefined') { | ||
const existingValue = (existingValueType === 'object' ? output[key] : {}); | ||
output[key] = executeDeepMerge({}, [existingValue, quickCloneObject(value)], options); | ||
} | ||
else { | ||
output[key] = quickCloneObject(value); | ||
} | ||
} | ||
else if (type === 'array') { | ||
if (existingValueType === 'array') { | ||
const newValue = quickCloneArray(value); | ||
output[key] = (options.arrayBehaviour === 'merge' ? output[key].concat(newValue) : newValue); | ||
} | ||
else { | ||
output[key] = quickCloneArray(value); | ||
} | ||
} | ||
else { | ||
output[key] = value; | ||
} | ||
} | ||
} | ||
return output; | ||
} | ||
/* | ||
* Merge all the supplied objects into the target object, breaking all references, including those of nested objects | ||
* and arrays, and even objects nested inside arrays. The first parameter is not mutated unlike Object.assign(). | ||
* Properties in later objects will always overwrite. | ||
*/ | ||
function objectAssignDeep(target, ...objects) { | ||
return executeDeepMerge(target, objects); | ||
} | ||
; | ||
/* | ||
* Same as objectAssignDeep() except it doesn't mutate the target object and returns an entirely new object. | ||
*/ | ||
function objectAssignDeepInto(...objects) { | ||
return executeDeepMerge({}, objects); | ||
} | ||
; | ||
/* | ||
* Allows an options object to be passed in to customise the behaviour of the function. | ||
*/ | ||
let withOptions = function objectAssignDeepInto(target, objects, options) { | ||
return executeDeepMerge(target, objects, options); | ||
}; | ||
/***/ }), | ||
/***/ "./out/callback.js": | ||
/*! exports provided: objectAssignDeep, objectAssignDeepInto, withOptions */function(e,t,r){"use strict";function n(e){return null===e?"null":void 0===e?"undefined":"object"==typeof e?Array.isArray(e)?"array":"object":typeof e}function i(e){return"object"===n(e)?u(e):"array"===n(e)?s(e):e}function s(e){return e.map(i)}function u(e){const t={};for(const r in e)e.hasOwnProperty(r)&&(t[r]=i(e[r]));return t}function o(e,t=[],r={}){const i={arrayBehaviour:r.arrayBehaviour||"replace"},a=t.map(e=>e||{}),l=e||{};for(let e=0;e<a.length;e++){const t=a[e],r=Object.keys(t);for(let e=0;e<r.length;e++){const a=r[e],c=t[a],d=n(c),f=n(l[a]);if("object"===d)if("undefined"!==f){const e="object"===f?l[a]:{};l[a]=o({},[e,u(c)],i)}else l[a]=u(c);else if("array"===d)if("array"===f){const e=s(c);l[a]="merge"===i.arrayBehaviour?l[a].concat(e):e}else l[a]=s(c);else l[a]=c}}return l}function a(e,...t){return o(e,t)}function l(...e){return o({},e)}r.r(t),r.d(t,"objectAssignDeep",(function(){return a})),r.d(t,"objectAssignDeepInto",(function(){return l})),r.d(t,"withOptions",(function(){return c}));let c=function(e,t,r){return o(e,t,r)}},"./out/callback.js": | ||
/*!*************************!*\ | ||
!*** ./out/callback.js ***! | ||
\*************************/ | ||
/*! exports provided: Callback */ | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
"use strict"; | ||
__webpack_require__.r(__webpack_exports__); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Callback", function() { return Callback; }); | ||
class Callback { | ||
constructor() { | ||
this.funcs = new Array(); | ||
} | ||
add(func) { | ||
this.funcs.push(func); | ||
} | ||
remove(func) { | ||
this.funcs = this.funcs.filter(o => o != func); | ||
} | ||
fire(args) { | ||
this.funcs.forEach(o => o(args)); | ||
} | ||
static create() { | ||
return new Callback(); | ||
} | ||
} | ||
/***/ }), | ||
/***/ "./out/data.js": | ||
/*! exports provided: Callback */function(e,t,r){"use strict";r.r(t),r.d(t,"Callback",(function(){return n}));class n{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 n}}},"./out/data.js": | ||
/*!*********************!*\ | ||
!*** ./out/data.js ***! | ||
\*********************/ | ||
/*! exports provided: DataSource, DataSourceSelectArguments */ | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
"use strict"; | ||
__webpack_require__.r(__webpack_exports__); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "DataSource", function() { return DataSource; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "DataSourceSelectArguments", function() { return DataSourceSelectArguments; }); | ||
/* harmony import */ var _errors__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./errors */ "./out/errors.js"); | ||
/* harmony import */ var _callback__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./callback */ "./out/callback.js"); | ||
let errors = Object.assign(_errors__WEBPACK_IMPORTED_MODULE_0__["errors"], { | ||
dataSourceCanntInsert() { | ||
return new Error("DataSource can not insert."); | ||
}, | ||
dataSourceCanntDelete() { | ||
return new Error("DataSource can not delete."); | ||
}, | ||
dataSourceCanntUpdate() { | ||
return new Error("DataSource can not update."); | ||
}, | ||
primaryKeyNull(key) { | ||
let msg = `Primary key named '${key}' value is null.`; | ||
return new Error(msg); | ||
}, | ||
queryResultTypeError() { | ||
let msg = `Query result type error.`; | ||
return new Error(msg); | ||
} | ||
}); | ||
class DataSource { | ||
constructor(args) { | ||
this.inserting = new _callback__WEBPACK_IMPORTED_MODULE_1__["Callback"](); //callbacks1<DataSource<T>, T, number>(); | ||
this.inserted = new _callback__WEBPACK_IMPORTED_MODULE_1__["Callback"](); | ||
this.deleting = new _callback__WEBPACK_IMPORTED_MODULE_1__["Callback"](); //callbacks<DataSource<T>, T>(); | ||
this.deleted = new _callback__WEBPACK_IMPORTED_MODULE_1__["Callback"](); //callbacks<DataSource<T>, T>(); | ||
this.updating = new _callback__WEBPACK_IMPORTED_MODULE_1__["Callback"](); | ||
this.updated = new _callback__WEBPACK_IMPORTED_MODULE_1__["Callback"](); | ||
this.selecting = new _callback__WEBPACK_IMPORTED_MODULE_1__["Callback"](); | ||
this.selected = new _callback__WEBPACK_IMPORTED_MODULE_1__["Callback"](); //callbacks<DataSource<T>, DataSourceSelectResult<T>>(); | ||
this.error = new _callback__WEBPACK_IMPORTED_MODULE_1__["Callback"](); //callbacks<this, DataSourceError>(); | ||
this.args = args; | ||
this.primaryKeys = args.primaryKeys || []; | ||
} | ||
; //callbacks<DataSource<T>, DataSourceSelectArguments>(); | ||
get canDelete() { | ||
return this.args.delete != null && this.primaryKeys.length > 0; | ||
} | ||
get canInsert() { | ||
return this.args.insert != null && this.primaryKeys.length > 0; | ||
} | ||
get canUpdate() { | ||
return this.args.update != null && this.primaryKeys.length > 0; | ||
} | ||
executeInsert(item, args) { | ||
return this.args.insert(item, args); | ||
} | ||
executeDelete(item, args) { | ||
return this.args.delete(item, args); | ||
} | ||
executeUpdate(item, args) { | ||
return this.args.update(item, args); | ||
} | ||
executeSelect(args) { | ||
args = args || {}; | ||
return this.args.select(args); | ||
} | ||
insert(item, args, index) { | ||
if (!this.canInsert) | ||
throw errors.dataSourceCanntInsert(); | ||
if (!item) | ||
throw errors.argumentNull("item"); | ||
if (typeof args == 'number') { | ||
index = args; | ||
args = null; | ||
} | ||
this.inserting.fire({ sender: this, dataItem: item, index }); | ||
return this.executeInsert(item, args).then((data) => { | ||
Object.assign(item, data); | ||
this.inserted.fire({ sender: this, dataItem: item, index }); | ||
return data; | ||
}).catch(exc => { | ||
this.processError(exc, 'insert'); | ||
throw exc; | ||
}); | ||
} | ||
delete(item, args) { | ||
if (!this.canDelete) | ||
throw errors.dataSourceCanntDelete(); | ||
if (!item) | ||
throw errors.argumentNull("item"); | ||
this.checkPrimaryKeys(item); | ||
this.deleting.fire({ sender: this, dataItem: item }); | ||
return this.executeDelete(item, args).then((data) => { | ||
this.deleted.fire({ sender: this, dataItem: item }); | ||
return data; | ||
}).catch(exc => { | ||
this.processError(exc, 'delete'); | ||
throw exc; | ||
}); | ||
} | ||
update(item, args) { | ||
if (!this.canUpdate) | ||
throw errors.dataSourceCanntUpdate(); | ||
if (!item) | ||
throw errors.argumentNull("item"); | ||
this.checkPrimaryKeys(item); | ||
this.updating.fire({ sender: this, dataItem: item }); | ||
return this.executeUpdate(item, args).then((data) => { | ||
Object.assign(item, data); | ||
this.updated.fire({ sender: this, dataItem: item }); | ||
return data; | ||
}).catch((exc) => { | ||
this.processError(exc, 'update'); | ||
throw exc; | ||
}); | ||
} | ||
isSameItem(theItem, otherItem) { | ||
if (theItem == null) | ||
throw errors.argumentNull('theItem'); | ||
if (otherItem == null) | ||
throw errors.argumentNull('otherItem'); | ||
if (this.primaryKeys.length == 0) | ||
return theItem == otherItem; | ||
this.checkPrimaryKeys(theItem); | ||
this.checkPrimaryKeys(otherItem); | ||
for (let pk of this.primaryKeys) { | ||
if (theItem[pk] != otherItem[pk]) | ||
return false; | ||
} | ||
return true; | ||
} | ||
checkPrimaryKeys(item) { | ||
for (let key in item) { | ||
if (item[key] == null && this.primaryKeys.indexOf(key) >= 0) | ||
throw errors.primaryKeyNull(key); | ||
} | ||
} | ||
select(args) { | ||
args = args || {}; | ||
// fireCallback(this.selecting, this, args); | ||
this.selecting.fire({ sender: this, selectArguments: args }); | ||
return this.executeSelect(args).then((data) => { | ||
let dataItems; | ||
let totalRowCount; | ||
if (Array.isArray(data)) { | ||
dataItems = data; | ||
totalRowCount = data.length; | ||
} | ||
else if (data.dataItems !== undefined && data.totalRowCount !== undefined) { | ||
dataItems = data.dataItems; | ||
totalRowCount = data.totalRowCount; | ||
} | ||
else { | ||
throw errors.queryResultTypeError(); | ||
} | ||
this.selected.fire({ sender: this, selectResult: { totalRowCount, dataItems }, selectArguments: args }); | ||
return { totalRowCount, dataItems }; | ||
}).catch(exc => { | ||
this.processError(exc, 'select'); | ||
throw exc; | ||
}); | ||
} | ||
processError(exc, method) { | ||
exc.method = method; | ||
this.error.fire({ sender: this, error: exc }); | ||
if (!exc.handled) | ||
throw exc; | ||
} | ||
} | ||
class DataSourceSelectArguments { | ||
constructor() { | ||
this.startRowIndex = 0; | ||
this.maximumRows = 2147483647; | ||
} | ||
} | ||
/***/ }), | ||
/***/ "./out/deep-equal.js": | ||
/*! exports provided: DataSource, DataSourceSelectArguments */function(e,t,r){"use strict";r.r(t),r.d(t,"DataSource",(function(){return u})),r.d(t,"DataSourceSelectArguments",(function(){return o}));var n=r(/*! ./errors */"./out/errors.js"),i=r(/*! ./callback */"./out/callback.js");let s=Object.assign(n.errors,{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 u{constructor(e){this.inserting=new i.Callback,this.inserted=new i.Callback,this.deleting=new i.Callback,this.deleted=new i.Callback,this.updating=new i.Callback,this.updated=new i.Callback,this.selecting=new i.Callback,this.selected=new i.Callback,this.error=new i.Callback,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 s.dataSourceCanntInsert();if(!e)throw s.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 s.dataSourceCanntDelete();if(!e)throw s.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 s.dataSourceCanntUpdate();if(!e)throw s.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 s.argumentNull("theItem");if(null==t)throw s.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 s.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 s.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 o{constructor(){this.startRowIndex=0,this.maximumRows=2147483647}}},"./out/deep-equal.js": | ||
/*!***************************!*\ | ||
!*** ./out/deep-equal.js ***! | ||
\***************************/ | ||
/*! exports provided: deepEqual */ | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
"use strict"; | ||
__webpack_require__.r(__webpack_exports__); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "deepEqual", function() { return deepEqual; }); | ||
function deepEqual(x, y) { | ||
if (x === y) { | ||
return true; | ||
} | ||
if ((typeof x == "object" && x != null) && (typeof y == "object" && y != null)) { | ||
if (Object.keys(x).length != Object.keys(y).length) | ||
return false; | ||
for (var prop in x) { | ||
if (y.hasOwnProperty(prop)) { | ||
if (!deepEqual(x[prop], y[prop])) | ||
return false; | ||
} | ||
else | ||
return false; | ||
} | ||
return true; | ||
} | ||
return false; | ||
} | ||
/***/ }), | ||
/***/ "./out/errors.js": | ||
/*! exports provided: deepEqual */function(e,t,r){"use strict";function n(e,t){if(e===t)return!0;if("object"==typeof e&&null!=e&&"object"==typeof t&&null!=t){if(Object.keys(e).length!=Object.keys(t).length)return!1;for(var r in e){if(!t.hasOwnProperty(r))return!1;if(!n(e[r],t[r]))return!1}return!0}return!1}r.r(t),r.d(t,"deepEqual",(function(){return n}))},"./out/errors.js": | ||
/*!***********************!*\ | ||
!*** ./out/errors.js ***! | ||
\***********************/ | ||
/*! exports provided: Errors, errors */ | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
"use strict"; | ||
__webpack_require__.r(__webpack_exports__); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Errors", function() { return Errors; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "errors", function() { return errors; }); | ||
class Errors { | ||
argumentNull(argumentName) { | ||
let error = new Error(`Argument ${argumentName} cannt be null or emtpy.`); | ||
let name = "argumentNull"; | ||
error.name = name; | ||
return error; | ||
} | ||
routeDataFieldNull(fieldName) { | ||
let msg = `The ${fieldName} field of route data cannt be null.`; | ||
let error = new Error(msg); | ||
let name = "routeDataFieldNull"; | ||
error.name = name; | ||
return error; | ||
} | ||
argumentFieldNull(fieldName, argumentName) { | ||
let msg = `The ${fieldName} field of ${argumentName} cannt be null.`; | ||
let error = new Error(msg); | ||
let name = "argumentFieldNull"; | ||
error.name = name; | ||
return error; | ||
} | ||
argumentTypeIncorrect(argumentName, expectedType) { | ||
let msg = `Argument ${argumentName} type error, expected type is ${expectedType}.`; | ||
let error = new Error(msg); | ||
let name = "argumentTypeIncorrect"; | ||
error.name = name; | ||
return error; | ||
} | ||
} | ||
let errors = new Errors(); | ||
/***/ }), | ||
/***/ "./out/format.js": | ||
/*! exports provided: Errors, errors */function(e,t,r){"use strict";r.r(t),r.d(t,"Errors",(function(){return n})),r.d(t,"errors",(function(){return i}));class n{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 i=new n},"./out/format.js": | ||
/*!***********************!*\ | ||
!*** ./out/format.js ***! | ||
\***********************/ | ||
/*! exports provided: formatDate, formatString */ | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
"use strict"; | ||
__webpack_require__.r(__webpack_exports__); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "formatDate", function() { return formatDate; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "formatString", function() { return formatString; }); | ||
function formatDate(date, showHourMinutes) { | ||
if (typeof date == "string") | ||
return date; | ||
let d = date; | ||
if (showHourMinutes) | ||
return `${d.getFullYear()}-${d.getMonth()}-${d.getDate()} ${d.getHours() + 1}:${d.getMinutes()}`; | ||
return `${d.getFullYear()}-${d.getMonth()}-${d.getDate()}`; | ||
} | ||
function formatString(pattern, ...args) { | ||
let a = pattern; | ||
for (let k in args) { | ||
a = a.replace("{" + k + "}", args[k]); | ||
} | ||
return a; | ||
} | ||
/***/ }), | ||
/***/ "./out/guid.js": | ||
/*! exports provided: formatDate, formatString */function(e,t,r){"use strict";function n(e,t){if("string"==typeof e)return e;let r=e;return t?`${r.getFullYear()}-${r.getMonth()}-${r.getDate()} ${r.getHours()+1}:${r.getMinutes()}`:`${r.getFullYear()}-${r.getMonth()}-${r.getDate()}`}function i(e,...t){let r=e;for(let e in t)r=r.replace("{"+e+"}",t[e]);return r}r.r(t),r.d(t,"formatDate",(function(){return n})),r.d(t,"formatString",(function(){return i}))},"./out/guid.js": | ||
/*!*********************!*\ | ||
!*** ./out/guid.js ***! | ||
\*********************/ | ||
/*! exports provided: guid */ | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
"use strict"; | ||
__webpack_require__.r(__webpack_exports__); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "guid", function() { return guid; }); | ||
function guid() { | ||
function s4() { | ||
return Math.floor((1 + Math.random()) * 0x10000) | ||
.toString(16) | ||
.substring(1); | ||
} | ||
return s4() + s4() + '-' + s4() + '-' + s4() + '-' + | ||
s4() + '-' + s4() + s4() + s4(); | ||
} | ||
/***/ }), | ||
/***/ "./out/html.js": | ||
/*! exports provided: guid */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()}r.r(t),r.d(t,"guid",(function(){return n}))},"./out/html.js": | ||
/*!*********************!*\ | ||
!*** ./out/html.js ***! | ||
\*********************/ | ||
/*! exports provided: HTML */ | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
"use strict"; | ||
__webpack_require__.r(__webpack_exports__); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "HTML", function() { return HTML; }); | ||
/* harmony import */ var _errors__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./errors */ "./out/errors.js"); | ||
class HTML { | ||
static addClassName(element, addonClassName) { | ||
if (element == null) | ||
throw _errors__WEBPACK_IMPORTED_MODULE_0__["errors"].argumentNull('element'); | ||
if (!addonClassName) | ||
throw _errors__WEBPACK_IMPORTED_MODULE_0__["errors"].argumentNull('addonClassName'); | ||
let sourceClassName; | ||
if (typeof element == 'string') | ||
sourceClassName = element; | ||
else | ||
sourceClassName = element.className; | ||
sourceClassName = sourceClassName || ''; | ||
console.assert(addonClassName != null); | ||
if (sourceClassName.indexOf(addonClassName) >= 0) | ||
return sourceClassName; | ||
let className = `${sourceClassName} ${addonClassName}`; | ||
if (typeof element != 'string') | ||
element.className = className; | ||
return className; | ||
} | ||
static removeClassName(element, targetClassName) { | ||
let sourceClassName; | ||
if (typeof element == 'string') | ||
sourceClassName = element; | ||
else | ||
sourceClassName = element.className || ''; | ||
if (sourceClassName.indexOf(targetClassName) < 0) | ||
return sourceClassName; | ||
sourceClassName = sourceClassName || ''; | ||
sourceClassName = sourceClassName.replace(new RegExp(targetClassName, 'g'), ''); | ||
sourceClassName = sourceClassName.trim(); | ||
if (typeof element != 'string') | ||
element.className = sourceClassName; | ||
return sourceClassName; | ||
} | ||
} | ||
/***/ }), | ||
/***/ "./out/index.js": | ||
/*! exports provided: HTML */function(e,t,r){"use strict";r.r(t),r.d(t,"HTML",(function(){return i}));var n=r(/*! ./errors */"./out/errors.js");class i{static addClassName(e,t){if(null==e)throw n.errors.argumentNull("element");if(!t)throw n.errors.argumentNull("addonClassName");let r;if(r="string"==typeof e?e:e.className,r=r||"",console.assert(null!=t),r.indexOf(t)>=0)return r;let i=`${r} ${t}`;return"string"!=typeof e&&(e.className=i),i}static removeClassName(e,t){let r;return r="string"==typeof e?e:e.className||"",r.indexOf(t)<0||(r=r||"",r=r.replace(new RegExp(t,"g"),""),r=r.trim(),"string"!=typeof e&&(e.className=r)),r}}},"./out/index.js": | ||
/*!**********************!*\ | ||
!*** ./out/index.js ***! | ||
\**********************/ | ||
/*! exports provided: guid, pathConcat, Errors, errors, Callback, DataSource, DataSourceSelectArguments, parseUrl, deepEqual, objectAssignDeep, formatDate, formatString, HTML, ValueStore */ | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
"use strict"; | ||
__webpack_require__.r(__webpack_exports__); | ||
/* harmony import */ var _guid__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./guid */ "./out/guid.js"); | ||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "guid", function() { return _guid__WEBPACK_IMPORTED_MODULE_0__["guid"]; }); | ||
/* harmony import */ var _path__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./path */ "./out/path.js"); | ||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "pathConcat", function() { return _path__WEBPACK_IMPORTED_MODULE_1__["pathConcat"]; }); | ||
/* harmony import */ var _errors__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./errors */ "./out/errors.js"); | ||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "Errors", function() { return _errors__WEBPACK_IMPORTED_MODULE_2__["Errors"]; }); | ||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "errors", function() { return _errors__WEBPACK_IMPORTED_MODULE_2__["errors"]; }); | ||
/* harmony import */ var _callback__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./callback */ "./out/callback.js"); | ||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "Callback", function() { return _callback__WEBPACK_IMPORTED_MODULE_3__["Callback"]; }); | ||
/* harmony import */ var _data__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./data */ "./out/data.js"); | ||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "DataSource", function() { return _data__WEBPACK_IMPORTED_MODULE_4__["DataSource"]; }); | ||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "DataSourceSelectArguments", function() { return _data__WEBPACK_IMPORTED_MODULE_4__["DataSourceSelectArguments"]; }); | ||
/* harmony import */ var _url__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./url */ "./out/url.js"); | ||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "parseUrl", function() { return _url__WEBPACK_IMPORTED_MODULE_5__["parseUrl"]; }); | ||
/* harmony import */ var _deep_equal__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./deep-equal */ "./out/deep-equal.js"); | ||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "deepEqual", function() { return _deep_equal__WEBPACK_IMPORTED_MODULE_6__["deepEqual"]; }); | ||
/* harmony import */ var _assign_deep__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./assign-deep */ "./out/assign-deep.js"); | ||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "objectAssignDeep", function() { return _assign_deep__WEBPACK_IMPORTED_MODULE_7__["objectAssignDeep"]; }); | ||
/* harmony import */ var _format__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./format */ "./out/format.js"); | ||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "formatDate", function() { return _format__WEBPACK_IMPORTED_MODULE_8__["formatDate"]; }); | ||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "formatString", function() { return _format__WEBPACK_IMPORTED_MODULE_8__["formatString"]; }); | ||
/* harmony import */ var _html__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./html */ "./out/html.js"); | ||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "HTML", function() { return _html__WEBPACK_IMPORTED_MODULE_9__["HTML"]; }); | ||
/* harmony import */ var _value_store__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./value-store */ "./out/value-store.js"); | ||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ValueStore", function() { return _value_store__WEBPACK_IMPORTED_MODULE_10__["ValueStore"]; }); | ||
/***/ }), | ||
/***/ "./out/path.js": | ||
/*! exports provided: guid, pathConcat, Errors, errors, Callback, DataSource, DataSourceSelectArguments, parseUrl, deepEqual, objectAssignDeep, formatDate, formatString, HTML, ValueStore */function(e,t,r){"use strict";r.r(t);var n=r(/*! ./guid */"./out/guid.js");r.d(t,"guid",(function(){return n.guid}));var i=r(/*! ./path */"./out/path.js");r.d(t,"pathConcat",(function(){return i.pathConcat}));var s=r(/*! ./errors */"./out/errors.js");r.d(t,"Errors",(function(){return s.Errors})),r.d(t,"errors",(function(){return s.errors}));var u=r(/*! ./callback */"./out/callback.js");r.d(t,"Callback",(function(){return u.Callback}));var o=r(/*! ./data */"./out/data.js");r.d(t,"DataSource",(function(){return o.DataSource})),r.d(t,"DataSourceSelectArguments",(function(){return o.DataSourceSelectArguments}));var a=r(/*! ./url */"./out/url.js");r.d(t,"parseUrl",(function(){return a.parseUrl}));var l=r(/*! ./deep-equal */"./out/deep-equal.js");r.d(t,"deepEqual",(function(){return l.deepEqual}));var c=r(/*! ./assign-deep */"./out/assign-deep.js");r.d(t,"objectAssignDeep",(function(){return c.objectAssignDeep}));var d=r(/*! ./format */"./out/format.js");r.d(t,"formatDate",(function(){return d.formatDate})),r.d(t,"formatString",(function(){return d.formatString}));var f=r(/*! ./html */"./out/html.js");r.d(t,"HTML",(function(){return f.HTML}));var h=r(/*! ./value-store */"./out/value-store.js");r.d(t,"ValueStore",(function(){return h.ValueStore}))},"./out/path.js": | ||
/*!*********************!*\ | ||
!*** ./out/path.js ***! | ||
\*********************/ | ||
/*! exports provided: pathConcat */ | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
"use strict"; | ||
__webpack_require__.r(__webpack_exports__); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "pathConcat", function() { return pathConcat; }); | ||
/** 连接多个路径 */ | ||
function pathConcat(...paths) { | ||
paths = paths || []; | ||
if (paths.length == 0) | ||
return ""; | ||
if (paths.length == 1) { | ||
return paths[0]; | ||
} | ||
let str = paths.join("/"); | ||
// 将一个或多个的 / 或者 变为一个 /,例如:/shop/test// 转换为 /shop/test/ | ||
// 或者 D:\shop\test\ 转换为 D:/shop/test/ | ||
str = str.replace(/(\/+|\\+)/g, '/'); | ||
//====================================================== | ||
// fixed 把 http:// https:// 变为 http:/ https:/ 的 BUG | ||
str = str.replace("http:/", "http://"); | ||
str = str.replace("https:/", "https://"); | ||
//====================================================== | ||
return str; | ||
} | ||
/***/ }), | ||
/***/ "./out/url.js": | ||
/*! exports provided: pathConcat */function(e,t,r){"use strict";function n(...e){if(0==(e=e||[]).length)return"";if(1==e.length)return e[0];let t=e.join("/");return t=t.replace(/(\/+|\\+)/g,"/"),t=t.replace("http:/","http://"),t=t.replace("https:/","https://"),t}r.r(t),r.d(t,"pathConcat",(function(){return n}))},"./out/url.js": | ||
/*!********************!*\ | ||
!*** ./out/url.js ***! | ||
\********************/ | ||
/*! exports provided: parseUrl */ | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
"use strict"; | ||
__webpack_require__.r(__webpack_exports__); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "parseUrl", function() { return parseUrl; }); | ||
function parseUrl(url) { | ||
let i = url.indexOf("?"); | ||
if (i < 0) | ||
return {}; | ||
let query = url.substr(i + 1); | ||
return pareeUrlQuery(query); | ||
} | ||
function pareeUrlQuery(query) { | ||
let match, pl = /\+/g, // Regex for replacing addition symbol with a space | ||
search = /([^&=]+)=?([^&]*)/g, decode = function (s) { | ||
return decodeURIComponent(s.replace(pl, " ")); | ||
}; | ||
let urlParams = {}; | ||
while (match = search.exec(query)) | ||
urlParams[decode(match[1])] = decode(match[2]); | ||
return urlParams; | ||
} | ||
/***/ }), | ||
/***/ "./out/value-store.js": | ||
/*! exports provided: parseUrl */function(e,t,r){"use strict";function n(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.r(t),r.d(t,"parseUrl",(function(){return n}))},"./out/value-store.js": | ||
/*!****************************!*\ | ||
!*** ./out/value-store.js ***! | ||
\****************************/ | ||
/*! exports provided: ValueStore */ | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
"use strict"; | ||
__webpack_require__.r(__webpack_exports__); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ValueStore", function() { return ValueStore; }); | ||
/** | ||
* 实现数据的存储,以及数据修改的通知 | ||
*/ | ||
class ValueStore { | ||
constructor(value) { | ||
this.items = new Array(); | ||
this._value = value; | ||
} | ||
attach(func, sender) { | ||
if (this.value !== undefined) { | ||
func(this.value, sender); | ||
} | ||
return this.add(func, sender); | ||
} | ||
add(func, sender) { | ||
this.items.push({ func, sender }); | ||
return func; | ||
} | ||
remove(func) { | ||
this.items = this.items.filter(o => o.func != func); | ||
} | ||
fire(value) { | ||
this.items.forEach(o => o.func(value, o.sender)); | ||
} | ||
get value() { | ||
if (this._value === undefined) | ||
return null; | ||
return this._value; | ||
} | ||
set value(value) { | ||
this._value = value; | ||
this.fire(value); | ||
} | ||
} | ||
/***/ }) | ||
/******/ }); | ||
}); | ||
//# sourceMappingURL=index.js.map | ||
/* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! (webpack)/buildin/global.js */ "C:\\Users\\ansib\\AppData\\Roaming\\npm\\node_modules\\webpack\\buildin\\global.js"))) | ||
/***/ }), | ||
/***/ "./out/errors.js": | ||
/*!***********************!*\ | ||
!*** ./out/errors.js ***! | ||
\***********************/ | ||
/*! no static exports found */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.errors = void 0; | ||
const maishu_toolkit_1 = __webpack_require__(/*! maishu-toolkit */ "./node_modules/maishu-toolkit/dist/index.js"); | ||
class MyErrors extends maishu_toolkit_1.Errors { | ||
invalidRouteSegment(routeSegment) { | ||
let error = new Error(`Route segment ${routeSegment} is invalid.`); | ||
error.name = MyErrors.prototype.invalidRouteSegment.name; | ||
return error; | ||
} | ||
routeItemExists(name) { | ||
let error = new Error(`Route '${name}' is exists.`); | ||
error.name = MyErrors.prototype.routeItemExists.name; | ||
return error; | ||
} | ||
invalidPath(path) { | ||
let error = new Error(`Path '${path}' is invalid path.`); | ||
error.name = MyErrors.prototype.invalidPath.name; | ||
return error; | ||
} | ||
} | ||
exports.errors = new MyErrors(); | ||
/***/ }), | ||
/***/ "./out/index.js": | ||
/*!**********************!*\ | ||
!*** ./out/index.js ***! | ||
\**********************/ | ||
/*! no static exports found */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createRouter = exports.RouterItem = exports.Router = void 0; | ||
const route_1 = __webpack_require__(/*! ./route */ "./out/route.js"); | ||
var route_2 = __webpack_require__(/*! ./route */ "./out/route.js"); | ||
Object.defineProperty(exports, "Router", { enumerable: true, get: function () { return route_2.Router; } }); | ||
var route_item_1 = __webpack_require__(/*! ./route-item */ "./out/route-item.js"); | ||
Object.defineProperty(exports, "RouterItem", { enumerable: true, get: function () { return route_item_1.RouterItem; } }); | ||
function createRouter(pattern, rules) { | ||
let router = new route_1.Router(pattern, rules); | ||
return router; | ||
} | ||
exports.createRouter = createRouter; | ||
/***/ }), | ||
/***/ "./out/path-segment.js": | ||
/*!*****************************!*\ | ||
!*** ./out/path-segment.js ***! | ||
\*****************************/ | ||
/*! no static exports found */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.PathSegment = void 0; | ||
const errors_1 = __webpack_require__(/*! ./errors */ "./out/errors.js"); | ||
/** 路径分割,用于比较两个路径 */ | ||
class PathSegment { | ||
constructor(path) { | ||
this._index = 0; | ||
this.segments = path.split("/").filter(o => o); | ||
if (this.segments.length == 0) | ||
throw errors_1.errors.invalidPath(path); | ||
} | ||
moveNext() { | ||
if (this._index >= this.segments.length - 1) | ||
return null; | ||
this._index = this._index + 1; | ||
return this._index; | ||
} | ||
get current() { | ||
return this.segments[this._index]; | ||
} | ||
get index() { | ||
return this._index; | ||
} | ||
get else() { | ||
let arr = this.segments.slice(this.index); | ||
return arr.join("/"); | ||
} | ||
} | ||
exports.PathSegment = PathSegment; | ||
/***/ }), | ||
/***/ "./out/route-item-collection.js": | ||
/*!**************************************!*\ | ||
!*** ./out/route-item-collection.js ***! | ||
\**************************************/ | ||
/*! no static exports found */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.RouterItems = void 0; | ||
const errors_1 = __webpack_require__(/*! ./errors */ "./out/errors.js"); | ||
const route_item_1 = __webpack_require__(/*! ./route-item */ "./out/route-item.js"); | ||
class RouterItems { | ||
constructor(routerString) { | ||
this._items = []; | ||
this._index = 0; | ||
let arr = routerString.split("/").filter(o => o); | ||
for (let i = 0; i < arr.length; i++) { | ||
let item = new route_item_1.RouterItem(arr[i]); | ||
let isExists = this._items.filter(o => o.name == item.name).length > 0; | ||
if (isExists) | ||
throw errors_1.errors.routeItemExists(arr[i]); | ||
this._items.push(item); | ||
} | ||
} | ||
get all() { | ||
return this._items; | ||
} | ||
moveNext() { | ||
if (this._index >= this._items.length - 1) | ||
return null; | ||
this._index = this._index + 1; | ||
return this._index; | ||
} | ||
reset() { | ||
this._index = 0; | ||
} | ||
get index() { | ||
return this._index; | ||
} | ||
get current() { | ||
return this._items[this._index]; | ||
} | ||
} | ||
exports.RouterItems = RouterItems; | ||
/***/ }), | ||
/***/ "./out/route-item.js": | ||
/*!***************************!*\ | ||
!*** ./out/route-item.js ***! | ||
\***************************/ | ||
/*! no static exports found */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.RouterItem = void 0; | ||
const errors_1 = __webpack_require__(/*! ./errors */ "./out/errors.js"); | ||
class RouterItem { | ||
constructor(routeSegment) { | ||
this._isOption = false; | ||
this._isWildcards = false; | ||
this._name = null; | ||
let regexp = /[*|:|?]{0,1}(\S+)/; | ||
let m = regexp.exec(routeSegment); | ||
if (!m) | ||
throw errors_1.errors.invalidRouteSegment(routeSegment); | ||
switch (routeSegment[0]) { | ||
case '*': | ||
this._isWildcards = true; | ||
this._regexp = /\S+/; | ||
this._name = m[1]; | ||
break; | ||
case ':': | ||
this._regexp = /\S+/; | ||
this._name = m[1]; | ||
break; | ||
case '?': | ||
this._regexp = /\S+/; | ||
this._name = m[1]; | ||
this._isOption = true; | ||
break; | ||
default: | ||
this._regexp = new RegExp(routeSegment); | ||
break; | ||
} | ||
} | ||
get isOption() { | ||
return this._isOption; | ||
} | ||
get isWildcards() { | ||
return this._isWildcards; | ||
} | ||
get name() { | ||
return this._name; | ||
} | ||
get regexp() { | ||
return this._regexp; | ||
} | ||
set regexp(value) { | ||
this._regexp = value; | ||
} | ||
get value() { | ||
return this._value; | ||
} | ||
set value(value) { | ||
this._value = value; | ||
} | ||
} | ||
exports.RouterItem = RouterItem; | ||
/***/ }), | ||
/***/ "./out/route.js": | ||
/*!**********************!*\ | ||
!*** ./out/route.js ***! | ||
\**********************/ | ||
/*! no static exports found */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Router = void 0; | ||
const errors_1 = __webpack_require__(/*! ./errors */ "./out/errors.js"); | ||
const path_segment_1 = __webpack_require__(/*! ./path-segment */ "./out/path-segment.js"); | ||
const route_item_collection_1 = __webpack_require__(/*! ./route-item-collection */ "./out/route-item-collection.js"); | ||
class Router { | ||
constructor(pattern, rules) { | ||
if (!pattern) | ||
throw errors_1.errors.argumentNull("pattern"); | ||
rules = rules || {}; | ||
this._pattern = pattern; | ||
this._items = new route_item_collection_1.RouterItems(pattern); | ||
for (let i = 0; i < this._items.all.length; i++) { | ||
let name = this._items.all[i].name; | ||
if (name != null && rules[name] != null) { | ||
this._items.all[i].regexp = rules[name]; | ||
} | ||
} | ||
} | ||
match(path) { | ||
let p = new path_segment_1.PathSegment(path); | ||
let c = this._items; | ||
do { | ||
let testOK = c.current.isWildcards ? c.current.regexp.test(p.else) : c.current.regexp.test(p.current); | ||
if (!testOK) { | ||
if (c.current.isOption) | ||
continue; | ||
else | ||
return null; | ||
} | ||
c.current.value = c.current.isWildcards ? p.else : p.current; | ||
p.moveNext(); | ||
} while (c.moveNext() != null); | ||
let r = {}; | ||
for (let i = 0; i < c.all.length; i++) { | ||
let name = c.all[i].name; | ||
let value = c.all[i].value; | ||
if (name == null) | ||
continue; | ||
r[name] = value; | ||
} | ||
return r; | ||
} | ||
item(name) { | ||
let r = this._items.all.filter(o => o.name == name)[0]; | ||
return r; | ||
} | ||
get items() { | ||
return this._items; | ||
} | ||
get pattern() { | ||
return this._pattern; | ||
} | ||
} | ||
exports.Router = Router; | ||
/***/ }), | ||
/***/ "C:\\Users\\ansib\\AppData\\Roaming\\npm\\node_modules\\webpack\\buildin\\global.js": | ||
/*!***********************************!*\ | ||
!*** (webpack)/buildin/global.js ***! | ||
\***********************************/ | ||
/*! no static exports found */ | ||
/***/ (function(module, exports) { | ||
var g; | ||
// This works in non-strict mode | ||
g = (function() { | ||
return this; | ||
})(); | ||
try { | ||
// This works if eval is allowed (see CSP) | ||
g = g || new Function("return this")(); | ||
} catch (e) { | ||
// This works if the window reference is available | ||
if (typeof window === "object") g = window; | ||
} | ||
// g can still be undefined, but nothing to do about it... | ||
// We return undefined, instead of nothing here, so it's | ||
// easier to handle this case. if(!global) { ...} | ||
module.exports = g; | ||
/***/ }) | ||
/******/ }); | ||
}); | ||
/*! exports provided: ValueStore */function(e,t,r){"use strict";r.r(t),r.d(t,"ValueStore",(function(){return n}));class n{constructor(e){this.items=new Array,this._value=e}attach(e,t){return void 0!==this.value&&e(this.value,t),this.add(e,t)}add(e,t){return this.items.push({func:e,sender:t}),e}remove(e){this.items=this.items.filter(t=>t.func!=e)}fire(e){this.items.forEach(t=>t.func(e,t.sender))}get value(){return void 0===this._value?null:this._value}set value(e){this._value=e,this.fire(e)}}}})},e.exports=r()}).call(this,r(5))},function(e,t){var r;r=function(){return this}();try{r=r||new Function("return this")()}catch(e){"object"==typeof window&&(r=window)}e.exports=r},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.PathSegment=void 0;const n=r(0);t.PathSegment=class{constructor(e){if(this._index=0,this.segments=e.split("/").filter(e=>e),0==this.segments.length)throw n.errors.invalidPath(e)}moveNext(){return this._index>=this.segments.length-1?null:(this._index=this._index+1,this._index)}get current(){return this.segments[this._index]}get index(){return this._index}get else(){return this.segments.slice(this.index).join("/")}}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.RouterItems=void 0;const n=r(0),i=r(2);t.RouterItems=class{constructor(e){this._items=[],this._index=0;let t=e.split("/").filter(e=>e);for(let e=0;e<t.length;e++){let r=new i.RouterItem(t[e]);if(this._items.filter(e=>e.name==r.name).length>0)throw n.errors.routeItemExists(t[e]);this._items.push(r)}}get all(){return this._items}moveNext(){return this._index>=this._items.length-1?null:(this._index=this._index+1,this._index)}reset(){this._index=0}get index(){return this._index}get current(){return this._items[this._index]}}}])})); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "maishu-router", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"dependencies": { | ||
@@ -5,0 +5,0 @@ "@types/node": "^14.14.37", |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
91777
428