@azrico/webobject 1.0.10 → 1.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- export * from "./src/index";
1
+ "use strict";var _index=require("./src/index");Object.defineProperty(exports,"__esModule",{value:!0});Object.keys(_index).forEach(function(a){"default"===a||"__esModule"===a||a in exports&&exports[a]===_index[a]||Object.defineProperty(exports,a,{enumerable:!0,get:function get(){return _index[a]}})});
@@ -1,15 +1 @@
1
- import WebObject from "./WebObject";
2
- /**
3
- * This web object contains some more webobjects
4
- */
5
- export class ParentWebObject extends WebObject {
6
- __parent__table_id = "";
7
- #children_items = undefined;
8
- get __children() {
9
- return this.#children_items;
10
- }
11
- set __children(val) {
12
- this.#children_items = val;
13
- }
14
- }
15
- export default ParentWebObject;
1
+ "use strict";var _WebObject2=_interopRequireDefault(require("./WebObject"));function _typeof(a){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}Object.defineProperty(exports,"__esModule",{value:!0}),exports["default"]=exports.ParentWebObject=void 0;function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function _defineProperties(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,c.key,c)}function _createClass(a,b,c){return b&&_defineProperties(a.prototype,b),c&&_defineProperties(a,c),Object.defineProperty(a,"prototype",{writable:!1}),a}function _inherits(a,b){if("function"!=typeof b&&null!==b)throw new TypeError("Super expression must either be null or a function");a.prototype=Object.create(b&&b.prototype,{constructor:{value:a,writable:!0,configurable:!0}}),Object.defineProperty(a,"prototype",{writable:!1}),b&&_setPrototypeOf(a,b)}function _setPrototypeOf(a,b){return _setPrototypeOf=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(a,b){return a.__proto__=b,a},_setPrototypeOf(a,b)}function _createSuper(a){var b=_isNativeReflectConstruct();return function(){var c,d=_getPrototypeOf(a);if(b){var e=_getPrototypeOf(this).constructor;c=Reflect.construct(d,arguments,e)}else c=d.apply(this,arguments);return _possibleConstructorReturn(this,c)}}function _possibleConstructorReturn(a,b){if(b&&("object"===_typeof(b)||"function"==typeof b))return b;if(void 0!==b)throw new TypeError("Derived constructors may only return object or undefined");return _assertThisInitialized(a)}function _assertThisInitialized(a){if(void 0===a)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return a}function _isNativeReflectConstruct(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(a){return!1}}function _getPrototypeOf(a){return _getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(a){return a.__proto__||Object.getPrototypeOf(a)},_getPrototypeOf(a)}function _classPrivateFieldInitSpec(a,b,c){_checkPrivateRedeclaration(a,b),b.set(a,c)}function _checkPrivateRedeclaration(a,b){if(b.has(a))throw new TypeError("Cannot initialize the same private elements twice on an object")}function _defineProperty(a,b,c){return b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _classPrivateFieldSet(a,b,c){var d=_classExtractFieldDescriptor(a,b,"set");return _classApplyDescriptorSet(a,d,c),c}function _classApplyDescriptorSet(a,b,c){if(b.set)b.set.call(a,c);else{if(!b.writable)throw new TypeError("attempted to set read only private field");b.value=c}}function _classPrivateFieldGet(a,b){var c=_classExtractFieldDescriptor(a,b,"get");return _classApplyDescriptorGet(a,c)}function _classExtractFieldDescriptor(a,b,c){if(!b.has(a))throw new TypeError("attempted to "+c+" private field on non-instance");return b.get(a)}function _classApplyDescriptorGet(a,b){return b.get?b.get.call(a):b.value}var _children_items=/*#__PURE__*/new WeakMap,ParentWebObject=/*#__PURE__*/function(a){function b(){var a;_classCallCheck(this,b);for(var d=arguments.length,e=Array(d),f=0;f<d;f++)e[f]=arguments[f];return a=c.call.apply(c,[this].concat(e)),_defineProperty(_assertThisInitialized(a),"__parent__table_id",""),_classPrivateFieldInitSpec(_assertThisInitialized(a),_children_items,{writable:!0,value:void 0}),a}_inherits(b,a);var c=_createSuper(b);return _createClass(b,[{key:"__children",get:function get(){return _classPrivateFieldGet(this,_children_items)},set:function set(a){_classPrivateFieldSet(this,_children_items,a)}}]),b}(_WebObject2["default"]);exports.ParentWebObject=ParentWebObject;var _default=ParentWebObject;exports["default"]=_default;
@@ -1,9 +1,6 @@
1
- import EventfulObject from "../structs/EventfulObject";
1
+ import SimpleObject, { saveResultType, sendChangesType } from "../structs/SimpleObject";
2
2
  import MetaObject from "../structs/MetaObject";
3
- import { sendChangesType } from "../structs/EventfulObject";
4
- export declare type saveResultType = "normal" | "nothing" | "error" | "canceled";
5
- export declare type saveType = "normal" | "quick";
6
- export declare class WebObject extends EventfulObject {
3
+ export declare class WebObject extends SimpleObject {
7
4
  __saveResultObject?: any;
8
5
  __saveResultIsSuccess?: boolean;
9
6
  __saveResultType?: saveResultType;
@@ -1,207 +1,16 @@
1
- import { gfunc } from "@azrico/global";
2
- import { getInArray, object_equals, object_isEmpty, setInArray, } from "@azrico/object";
3
- import EventfulObject from "../structs/EventfulObject";
4
- export class WebObject extends EventfulObject {
5
- __saveResultObject;
6
- __saveResultIsSuccess;
7
- __saveResultType;
8
- static __web_path = "";
9
- static __web_type = "";
10
- meta_data;
11
- constructor(isEditMode = true, is_readonly = false) {
12
- super(isEditMode, is_readonly);
13
- }
14
- /* -------------------------------------------------------------------------- */
15
- /* Meta data */
16
- /* -------------------------------------------------------------------------- */
17
- /**
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports["default"]=exports.WebObject=void 0;var _SimpleObject2=_interopRequireDefault(require("../structs/SimpleObject")),_global=require("@azrico/global"),_object=require("@azrico/object");function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}}function _typeof(a){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}function _regeneratorRuntime(){"use strict";/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */function a(a,b,c){return Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}),a[b]}function b(a,b,e,f){var g=b&&b.prototype instanceof d?b:d,h=Object.create(g.prototype),j=new l(f||[]);return h._invoke=function(a,b,d){var e="suspendedStart";return function(f,g){if("executing"===e)throw new Error("Generator is already running");if("completed"===e){if("throw"===f)throw g;return n()}for(d.method=f,d.arg=g;;){var h=d.delegate;if(h){var j=i(h,d);if(j){if(j===v)continue;return j}}if("next"===d.method)d.sent=d._sent=d.arg;else if("throw"===d.method){if("suspendedStart"===e)throw e="completed",d.arg;d.dispatchException(d.arg)}else"return"===d.method&&d.abrupt("return",d.arg);e="executing";var k=c(a,b,d);if("normal"===k.type){if(e=d.done?"completed":"suspendedYield",k.arg===v)continue;return{value:k.arg,done:d.done}}"throw"===k.type&&(e="completed",d.method="throw",d.arg=k.arg)}}}(a,e,j),h}function c(a,b,c){try{return{type:"normal",arg:a.call(b,c)}}catch(a){return{type:"throw",arg:a}}}function d(){}function e(){}function f(){}function g(b){["next","throw","return"].forEach(function(c){a(b,c,function(a){return this._invoke(c,a)})})}function h(a,b){function d(e,f,g,h){var i=c(a[e],a,f);if("throw"!==i.type){var j=i.arg,k=j.value;return k&&"object"==_typeof(k)&&q.call(k,"__await")?b.resolve(k.__await).then(function(a){d("next",a,g,h)},function(a){d("throw",a,g,h)}):b.resolve(k).then(function(a){j.value=a,g(j)},function(a){return d("throw",a,g,h)})}h(i.arg)}var e;this._invoke=function(a,c){function f(){return new b(function(b,e){d(a,c,b,e)})}return e=e?e.then(f,f):f()}}function i(a,b){var d=a.iterator[b.method];if(void 0===d){if(b.delegate=null,"throw"===b.method){if(a.iterator["return"]&&(b.method="return",b.arg=void 0,i(a,b),"throw"===b.method))return v;b.method="throw",b.arg=new TypeError("The iterator does not provide a 'throw' method")}return v}var e=c(d,a.iterator,b.arg);if("throw"===e.type)return b.method="throw",b.arg=e.arg,b.delegate=null,v;var f=e.arg;return f?f.done?(b[a.resultName]=f.value,b.next=a.nextLoc,"return"!==b.method&&(b.method="next",b.arg=void 0),b.delegate=null,v):f:(b.method="throw",b.arg=new TypeError("iterator result is not an object"),b.delegate=null,v)}function j(a){var b={tryLoc:a[0]};1 in a&&(b.catchLoc=a[1]),2 in a&&(b.finallyLoc=a[2],b.afterLoc=a[3]),this.tryEntries.push(b)}function k(a){var b=a.completion||{};b.type="normal",delete b.arg,a.completion=b}function l(a){this.tryEntries=[{tryLoc:"root"}],a.forEach(j,this),this.reset(!0)}function m(a){if(a){var b=a[s];if(b)return b.call(a);if("function"==typeof a.next)return a;if(!isNaN(a.length)){var c=-1,d=function b(){for(;++c<a.length;)if(q.call(a,c))return b.value=a[c],b.done=!1,b;return b.value=void 0,b.done=!0,b};return d.next=d}}return{next:n}}function n(){return{value:void 0,done:!0}}_regeneratorRuntime=function(){return o};var o={},p=Object.prototype,q=p.hasOwnProperty,r="function"==typeof Symbol?Symbol:{},s=r.iterator||"@@iterator",t=r.asyncIterator||"@@asyncIterator",u=r.toStringTag||"@@toStringTag";try{a({},"")}catch(b){a=function(a,b,c){return a[b]=c}}o.wrap=b;var v={},w={};a(w,s,function(){return this});var x=Object.getPrototypeOf,y=x&&x(x(m([])));y&&y!==p&&q.call(y,s)&&(w=y);var z=f.prototype=d.prototype=Object.create(w);return e.prototype=f,a(z,"constructor",f),a(f,"constructor",e),e.displayName=a(f,u,"GeneratorFunction"),o.isGeneratorFunction=function(a){var b="function"==typeof a&&a.constructor;return!!b&&(b===e||"GeneratorFunction"===(b.displayName||b.name))},o.mark=function(b){return Object.setPrototypeOf?Object.setPrototypeOf(b,f):(b.__proto__=f,a(b,u,"GeneratorFunction")),b.prototype=Object.create(z),b},o.awrap=function(a){return{__await:a}},g(h.prototype),a(h.prototype,t,function(){return this}),o.AsyncIterator=h,o.async=function(a,c,d,e,f){void 0===f&&(f=Promise);var g=new h(b(a,c,d,e),f);return o.isGeneratorFunction(c)?g:g.next().then(function(a){return a.done?a.value:g.next()})},g(z),a(z,u,"Generator"),a(z,s,function(){return this}),a(z,"toString",function(){return"[object Generator]"}),o.keys=function(a){var b=[];for(var c in a)b.push(c);return b.reverse(),function c(){for(;b.length;){var d=b.pop();if(d in a)return c.value=d,c.done=!1,c}return c.done=!0,c}},o.values=m,l.prototype={constructor:l,reset:function reset(a){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(k),!a)for(var b in this)"t"===b.charAt(0)&&q.call(this,b)&&!isNaN(+b.slice(1))&&(this[b]=void 0)},stop:function stop(){this.done=!0;var a=this.tryEntries[0].completion;if("throw"===a.type)throw a.arg;return this.rval},dispatchException:function dispatchException(a){function b(b,d){return f.type="throw",f.arg=a,c.next=b,d&&(c.method="next",c.arg=void 0),!!d}if(this.done)throw a;for(var c=this,d=this.tryEntries.length-1;0<=d;--d){var e=this.tryEntries[d],f=e.completion;if("root"===e.tryLoc)return b("end");if(e.tryLoc<=this.prev){var g=q.call(e,"catchLoc"),h=q.call(e,"finallyLoc");if(g&&h){if(this.prev<e.catchLoc)return b(e.catchLoc,!0);if(this.prev<e.finallyLoc)return b(e.finallyLoc)}else if(!g){if(!h)throw new Error("try statement without catch or finally");if(this.prev<e.finallyLoc)return b(e.finallyLoc)}else if(this.prev<e.catchLoc)return b(e.catchLoc,!0)}}},abrupt:function abrupt(a,b){for(var c,d=this.tryEntries.length-1;0<=d;--d)if(c=this.tryEntries[d],c.tryLoc<=this.prev&&q.call(c,"finallyLoc")&&this.prev<c.finallyLoc){var e=c;break}e&&("break"===a||"continue"===a)&&e.tryLoc<=b&&b<=e.finallyLoc&&(e=null);var f=e?e.completion:{};return f.type=a,f.arg=b,e?(this.method="next",this.next=e.finallyLoc,v):this.complete(f)},complete:function complete(a,b){if("throw"===a.type)throw a.arg;return"break"===a.type||"continue"===a.type?this.next=a.arg:"return"===a.type?(this.rval=this.arg=a.arg,this.method="return",this.next="end"):"normal"===a.type&&b&&(this.next=b),v},finish:function finish(a){for(var b,c=this.tryEntries.length-1;0<=c;--c)if(b=this.tryEntries[c],b.finallyLoc===a)return this.complete(b.completion,b.afterLoc),k(b),v},catch:function _catch(a){for(var b,c=this.tryEntries.length-1;0<=c;--c)if(b=this.tryEntries[c],b.tryLoc===a){var d=b.completion;if("throw"===d.type){var e=d.arg;k(b)}return e}throw new Error("illegal catch attempt")},delegateYield:function delegateYield(a,b,c){return this.delegate={iterator:m(a),resultName:b,nextLoc:c},"next"===this.method&&(this.arg=void 0),v}},o}function asyncGeneratorStep(a,b,c,d,e,f,g){try{var h=a[f](g),i=h.value}catch(a){return void c(a)}h.done?b(i):Promise.resolve(i).then(d,e)}function _asyncToGenerator(a){return function(){var b=this,c=arguments;return new Promise(function(d,e){function f(a){asyncGeneratorStep(h,d,e,f,g,"next",a)}function g(a){asyncGeneratorStep(h,d,e,f,g,"throw",a)}var h=a.apply(b,c);f(void 0)})}}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function _defineProperties(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,c.key,c)}function _createClass(a,b,c){return b&&_defineProperties(a.prototype,b),c&&_defineProperties(a,c),Object.defineProperty(a,"prototype",{writable:!1}),a}function _inherits(a,b){if("function"!=typeof b&&null!==b)throw new TypeError("Super expression must either be null or a function");a.prototype=Object.create(b&&b.prototype,{constructor:{value:a,writable:!0,configurable:!0}}),Object.defineProperty(a,"prototype",{writable:!1}),b&&_setPrototypeOf(a,b)}function _setPrototypeOf(a,b){return _setPrototypeOf=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(a,b){return a.__proto__=b,a},_setPrototypeOf(a,b)}function _createSuper(a){var b=_isNativeReflectConstruct();return function(){var c,d=_getPrototypeOf(a);if(b){var e=_getPrototypeOf(this).constructor;c=Reflect.construct(d,arguments,e)}else c=d.apply(this,arguments);return _possibleConstructorReturn(this,c)}}function _possibleConstructorReturn(a,b){if(b&&("object"===_typeof(b)||"function"==typeof b))return b;if(void 0!==b)throw new TypeError("Derived constructors may only return object or undefined");return _assertThisInitialized(a)}function _assertThisInitialized(a){if(void 0===a)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return a}function _isNativeReflectConstruct(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(a){return!1}}function _getPrototypeOf(a){return _getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(a){return a.__proto__||Object.getPrototypeOf(a)},_getPrototypeOf(a)}function _defineProperty(a,b,c){return b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}var WebObject=/*#__PURE__*/function(a){function b(){var a,d=!(0<arguments.length&&void 0!==arguments[0])||arguments[0],e=!!(1<arguments.length&&void 0!==arguments[1])&&arguments[1];return _classCallCheck(this,b),a=c.call(this,d,e),_defineProperty(_assertThisInitialized(a),"__saveResultObject",void 0),_defineProperty(_assertThisInitialized(a),"__saveResultIsSuccess",void 0),_defineProperty(_assertThisInitialized(a),"__saveResultType",void 0),_defineProperty(_assertThisInitialized(a),"meta_data",void 0),a}/* -------------------------------------------------------------------------- */ /* Meta data */ /* -------------------------------------------------------------------------- */ /**
18
2
  * Update meta value of this object , meta data is stored in meta_data variable
19
3
  * @param key
20
4
  * @param value
21
5
  * @param createIfNotExists should we create a new meta if key does not exist
22
6
  * @param sendChange
23
7
  * @returns
24
- */
25
- setMetaValue(key, value, createIfNotExists = true, sendChange = "auto") {
26
- return WebObject.setMetaValue(this, key, value, createIfNotExists, sendChange);
27
- }
28
- getMeta(key) {
29
- return WebObject.getMeta(this, key);
30
- }
31
- getMetaValue(key) {
32
- return WebObject.getMetaValue(this, key);
33
- }
34
- /* -------------------------------------------------------------------------- */
35
- static setMetaValue(o, key, value, createIfNotExists = true, sendChange = "auto") {
36
- if (!o)
37
- return false;
38
- if (!o.canModify) {
39
- WebObject.addError(o, "Readonly mode is set to true", `Cant use setMetaValue on ${key} when on readonly mode`, true);
40
- return false;
41
- }
42
- const old_value = WebObject.getMetaValue(o, key);
43
- if (object_equals(old_value, value))
44
- return false;
45
- o.setValue("meta_data", setInArray(o.meta_data, "key", key, "value", value, createIfNotExists));
46
- if (sendChange !== false)
47
- o.notifyChanged("meta", key, value);
48
- return true;
49
- }
50
- static getMeta(o, key) {
51
- if (o == null)
52
- return null;
53
- return getInArray(o.getValue("meta_data"), "key", key);
54
- }
55
- static getMetaValue(o, key) {
56
- return WebObject.getMeta(o, key)?.value;
57
- }
58
- /* -------------------------------------------------------------------------- */
59
- /* Save */
60
- /* -------------------------------------------------------------------------- */
61
- async SaveWeb(putAction, putAddress, deltaObject, clearErrors = true, checkResult = true) {
62
- try {
63
- this.setSaveResult(null, "nothing");
64
- if (clearErrors)
65
- WebObject.clearErrors(this);
66
- if (!object_isEmpty(deltaObject)) {
67
- const canSaveResult = this.canSave(deltaObject);
68
- if (canSaveResult !== true) {
69
- this.addError("Save not allowed", String(canSaveResult), true);
70
- this.setSaveResult(false, "canceled");
71
- return false;
72
- }
73
- const resultObject = await gfunc.run_action(putAction, putAddress, deltaObject);
74
- let validResult = this.constructor["isResultValid"](resultObject);
75
- if (validResult || checkResult === false) {
76
- this.setSaveResult(resultObject, "normal");
77
- }
78
- else {
79
- this.setSaveResult(null, "error");
80
- WebObject.addError(this, "Save result is not valid", "the response from website was not a valid saveresult object !", true);
81
- }
82
- }
83
- else {
84
- /* nothing to save */
85
- this.setSaveResult(this, "nothing");
86
- }
87
- if (this.isSaved) {
88
- return this.getSaveResult();
89
- }
90
- return false;
91
- }
92
- catch (ex) {
93
- this.setSaveResult(null, "error");
94
- WebObject.addError(this, "Error when saving ! ", String(ex), true);
95
- }
96
- return false;
97
- }
98
- canSave(deltaObj) {
99
- const deltaRes = this.deltaIsValid(deltaObj);
100
- if (deltaRes !== true)
101
- return deltaRes;
102
- return true;
103
- }
104
- deltaIsValid(d) {
105
- return true;
106
- }
107
- /* -------------------------------------------------------------------------- */
108
- /* Default Events */
109
- /* -------------------------------------------------------------------------- */
110
- /**
8
+ */_inherits(b,a);var c=_createSuper(b);return _createClass(b,[{key:"setMetaValue",value:function setMetaValue(a,c){var d=!(2<arguments.length&&void 0!==arguments[2])||arguments[2],e=3<arguments.length&&void 0!==arguments[3]?arguments[3]:"auto";return b.setMetaValue(this,a,c,d,e)}},{key:"getMeta",value:function getMeta(a){return b.getMeta(this,a)}},{key:"getMetaValue",value:function getMetaValue(a){return b.getMetaValue(this,a)}/* -------------------------------------------------------------------------- */},{key:"SaveWeb",value:/* -------------------------------------------------------------------------- */ /* Save */ /* -------------------------------------------------------------------------- */function(){function a(){return c.apply(this,arguments)}var c=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function e(a,c,d){var f,g,h,i,j,k=arguments;return _regeneratorRuntime().wrap(function l(e){for(;1;)switch(e.prev=e.next){case 0:if(f=!(3<k.length&&void 0!==k[3])||k[3],g=!(4<k.length&&void 0!==k[4])||k[4],e.prev=2,this.setSaveResult(null,"nothing"),f&&b.clearErrors(this),(0,_object.object_isEmpty)(d)){e.next=18;break}if(h=this.canSave(d),!0===h){e.next=11;break}return b.addError(this,"Save not allowed",h+"",!0),this.setSaveResult(!1,"canceled"),e.abrupt("return",!1);case 11:return e.next=13,_global.gfunc.run_action(a,c,d);case 13:i=e.sent,j=this.constructor.isResultValid(i),j||!1===g?this.setSaveResult(i,"normal"):(this.setSaveResult(null,"error"),b.addError(this,"Save result is not valid","the response from website was not a valid saveresult object !",!0)),e.next=19;break;case 18:this.setSaveResult(this,"nothing");case 19:if(!this.isSaved){e.next=21;break}return e.abrupt("return",this.getSaveResult());case 21:return e.abrupt("return",!1);case 24:e.prev=24,e.t0=e["catch"](2),this.setSaveResult(null,"error"),b.addError(this,"Error when saving ! ",e.t0+"",!0);case 28:return e.abrupt("return",!1);case 29:case"end":return e.stop();}},e,this,[[2,24]])}));return a}()},{key:"canSave",value:function canSave(a){var b=this.deltaIsValid(a);return!0===b||b}},{key:"deltaIsValid",value:function deltaIsValid(a){return!0}/* -------------------------------------------------------------------------- */ /* Default Events */ /* -------------------------------------------------------------------------- */ /**
111
9
  * Use this when you load data to the object
112
10
  * @param p
113
11
  * @returns
114
- */
115
- async onLoad(...p) {
116
- if (this.isEditMode) {
117
- this.setOriginal();
118
- }
119
- return await Promise.resolve(true);
120
- }
121
- /**
12
+ */},{key:"onLoad",value:function(){function a(){return b.apply(this,arguments)}var b=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function a(){return _regeneratorRuntime().wrap(function b(a){for(;1;)switch(a.prev=a.next){case 0:return this.isEditMode&&this.setOriginal(),a.next=3,Promise.resolve(!0);case 3:return a.abrupt("return",a.sent);case 4:case"end":return a.stop();}},a,this)}));return a}()/**
122
13
  * Use this after succesful save to Database
123
14
  * @param p
124
15
  * @returns
125
- */
126
- async onSave(...p) {
127
- if (this.isSaved) {
128
- this.apply_changes();
129
- //var srObject = this.getSaveResult();
130
- //this.loadValues(srObject);
131
- }
132
- return await Promise.resolve(true);
133
- }
134
- /* -------------------------------------------------------------------------- */
135
- getID() {
136
- return this.__data_id || -1;
137
- }
138
- static getID(o) {
139
- if (o == null || o == undefined)
140
- return -1;
141
- if (o instanceof WebObject)
142
- return o.getID() ?? -1;
143
- switch (typeof o) {
144
- case "object":
145
- return o.__data_id || o.id || o.ID || -1;
146
- case "number":
147
- return o;
148
- }
149
- return -1;
150
- }
151
- /* -------------------------------------------------------------------------- */
152
- /* Save Results */
153
- /* -------------------------------------------------------------------------- */
154
- static isResultValid(result_object) {
155
- if (object_isEmpty(result_object))
156
- return false;
157
- switch (typeof result_object) {
158
- case "string":
159
- try {
160
- result_object = JSON.parse(result_object);
161
- return this.isResultValid(result_object);
162
- }
163
- catch {
164
- return false;
165
- }
166
- case "object":
167
- if (result_object.expected && result_object.result) {
168
- return object_equals(result_object.expected, result_object.result);
169
- }
170
- return Number(this.getID(result_object)) >= 0;
171
- case "number":
172
- return result_object > 0;
173
- case "boolean":
174
- return result_object === true;
175
- }
176
- return false;
177
- }
178
- get isSaved() {
179
- return Boolean(this.__saveResultIsSuccess ?? false);
180
- }
181
- setSaveResult(toObj, type) {
182
- this.__saveResultType = type;
183
- if (toObj === true) {
184
- }
185
- else if (toObj === false) {
186
- }
187
- else {
188
- if (toObj) {
189
- this.setSaveResultObject(toObj);
190
- }
191
- else {
192
- this.setSaveResultObject(null);
193
- }
194
- }
195
- this.__saveResultIsSuccess =
196
- (type === "normal" || type === "nothing") && toObj != null;
197
- }
198
- setSaveResultObject(toObj) {
199
- this.__saveResultObject = toObj;
200
- }
201
- getSaveResult() {
202
- if (this.isSaved)
203
- return this.__saveResultObject;
204
- return false;
205
- }
206
- }
207
- export default WebObject;
16
+ */},{key:"onSave",value:function(){function a(){return b.apply(this,arguments)}var b=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function a(){return _regeneratorRuntime().wrap(function b(a){for(;1;)switch(a.prev=a.next){case 0:return this.isSaved&&this.apply_changes(),a.next=3,Promise.resolve(!0);case 3:return a.abrupt("return",a.sent);case 4:case"end":return a.stop();}},a,this)}));return a}()/* -------------------------------------------------------------------------- */},{key:"getID",value:function getID(){return this.__data_id||-1}},{key:"isSaved",get:function get(){var a;return null!==(a=this.__saveResultIsSuccess)&&void 0!==a&&a}},{key:"setSaveResult",value:function setSaveResult(a,b){this.__saveResultType=b,!0===a||!1===a||(a?this.setSaveResultObject(a):this.setSaveResultObject(null)),this.__saveResultIsSuccess=("normal"===b||"nothing"===b)&&null!=a}},{key:"setSaveResultObject",value:function setSaveResultObject(a){this.__saveResultObject=a}},{key:"getSaveResult",value:function getSaveResult(){return!!this.isSaved&&this.__saveResultObject}}],[{key:"setMetaValue",value:function setMetaValue(a,c,d){var e=!(3<arguments.length&&void 0!==arguments[3])||arguments[3],f=4<arguments.length&&void 0!==arguments[4]?arguments[4]:"auto";if(!a)return!1;if(!a.canModify)return b.addError(a,"Readonly mode is set to true","Cant use setMetaValue on ".concat(c," when on readonly mode"),!0),!1;var g=b.getMetaValue(a,c);return!(0,_object.object_equals)(g,d)&&(a.setValue("meta_data",(0,_object.setInArray)(a.meta_data,"key",c,"value",d,e)),!1!==f&&a.notifyChanged("meta",c,d),!0)}},{key:"getMeta",value:function getMeta(a,b){return null==a?null:(0,_object.getInArray)(a.getValue("meta_data"),"key",b)}},{key:"getMetaValue",value:function getMetaValue(a,c){var d;return null===(d=b.getMeta(a,c))||void 0===d?void 0:d.value}},{key:"getID",value:function getID(a){var c;if(null==a||null==a)return-1;if(a instanceof b)return null!==(c=a.getID())&&void 0!==c?c:-1;switch(_typeof(a)){case"object":return a.__data_id||a.id||a.ID||-1;case"number":return a;}return-1}/* -------------------------------------------------------------------------- */ /* Save Results */ /* -------------------------------------------------------------------------- */},{key:"isResultValid",value:function isResultValid(a){if((0,_object.object_isEmpty)(a))return!1;switch(_typeof(a)){case"string":try{return a=JSON.parse(a),this.isResultValid(a)}catch(a){return!1}case"object":return a.expected&&a.result?(0,_object.object_equals)(a.expected,a.result):0<=+this.getID(a);case"number":return 0<a;case"boolean":return!0===a;}return!1}}]),b}(_SimpleObject2["default"]);exports.WebObject=WebObject,_defineProperty(WebObject,"__web_path",""),_defineProperty(WebObject,"__web_type","");var _default=WebObject;exports["default"]=_default;
@@ -1,6 +1,6 @@
1
1
  export * from "./structs/SimpleObject";
2
- export * from "./structs/EventfulObject";
3
2
  export * from "./structs/ObjectArray";
4
3
  export * from "./structs/MapableObject";
5
4
  export * from "./structs/MetaObject";
5
+ export * from "./structs/ObjectManager";
6
6
  export * from "./WebObjects/WebObject";
package/dist/src/index.js CHANGED
@@ -1,6 +1 @@
1
- export * from "./structs/SimpleObject";
2
- export * from "./structs/EventfulObject";
3
- export * from "./structs/ObjectArray";
4
- export * from "./structs/MapableObject";
5
- export * from "./structs/MetaObject";
6
- export * from "./WebObjects/WebObject";
1
+ "use strict";var _SimpleObject=require("./structs/SimpleObject");var _ObjectArray=require("./structs/ObjectArray");var _MapableObject=require("./structs/MapableObject");var _MetaObject=require("./structs/MetaObject");var _ObjectManager=require("./structs/ObjectManager");var _WebObject=require("./WebObjects/WebObject");Object.defineProperty(exports,"__esModule",{value:!0});Object.keys(_SimpleObject).forEach(function(a){"default"===a||"__esModule"===a||a in exports&&exports[a]===_SimpleObject[a]||Object.defineProperty(exports,a,{enumerable:!0,get:function get(){return _SimpleObject[a]}})});Object.keys(_ObjectArray).forEach(function(a){"default"===a||"__esModule"===a||a in exports&&exports[a]===_ObjectArray[a]||Object.defineProperty(exports,a,{enumerable:!0,get:function get(){return _ObjectArray[a]}})});Object.keys(_MapableObject).forEach(function(a){"default"===a||"__esModule"===a||a in exports&&exports[a]===_MapableObject[a]||Object.defineProperty(exports,a,{enumerable:!0,get:function get(){return _MapableObject[a]}})});Object.keys(_MetaObject).forEach(function(a){"default"===a||"__esModule"===a||a in exports&&exports[a]===_MetaObject[a]||Object.defineProperty(exports,a,{enumerable:!0,get:function get(){return _MetaObject[a]}})});Object.keys(_ObjectManager).forEach(function(a){"default"===a||"__esModule"===a||a in exports&&exports[a]===_ObjectManager[a]||Object.defineProperty(exports,a,{enumerable:!0,get:function get(){return _ObjectManager[a]}})});Object.keys(_WebObject).forEach(function(a){"default"===a||"__esModule"===a||a in exports&&exports[a]===_WebObject[a]||Object.defineProperty(exports,a,{enumerable:!0,get:function get(){return _WebObject[a]}})});
@@ -1,73 +1,3 @@
1
- import ObjectArray from "./ObjectArray";
2
- import { object_first } from "@azrico/object";
3
- import { string_equals_ignorecase } from "@azrico/string";
4
- import { uid } from "@azrico/uid";
5
- /**
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports["default"]=exports.MapableObject=void 0;var _ObjectArray=_interopRequireDefault(require("./ObjectArray")),_object=require("@azrico/object"),_string=require("@azrico/string"),_uid=require("@azrico/uid");function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}}function _construct(){return _construct=_isNativeReflectConstruct()?Reflect.construct.bind():function(b,c,d){var e=[null];e.push.apply(e,c);var a=Function.bind.apply(b,e),f=new a;return d&&_setPrototypeOf(f,d.prototype),f},_construct.apply(null,arguments)}function _isNativeReflectConstruct(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(a){return!1}}function _setPrototypeOf(a,b){return _setPrototypeOf=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(a,b){return a.__proto__=b,a},_setPrototypeOf(a,b)}function _typeof(a){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function _defineProperties(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,c.key,c)}function _createClass(a,b,c){return b&&_defineProperties(a.prototype,b),c&&_defineProperties(a,c),Object.defineProperty(a,"prototype",{writable:!1}),a}function _defineProperty(a,b,c){return b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}/**
6
2
  * This object can be mapped and converted
7
- */
8
- export class MapableObject {
9
- __uid;
10
- __data_id;
11
- __table_id;
12
- __row_number;
13
- constructor() {
14
- this.__uid = uid.localuid();
15
- }
16
- static mapto(maptoType, objectlist, isEditMode = true, ...p) {
17
- if (objectlist === undefined) {
18
- if (maptoType === undefined)
19
- return [];
20
- if (maptoType instanceof Object)
21
- return [];
22
- objectlist = maptoType;
23
- maptoType = this;
24
- }
25
- if (objectlist == null)
26
- return [];
27
- if (objectlist instanceof ObjectArray)
28
- objectlist = objectlist.getObjects();
29
- if (typeof objectlist != "object")
30
- objectlist = [objectlist];
31
- if (!Array.isArray(objectlist)) {
32
- return [this.ensure(maptoType, objectlist, isEditMode, ...p)];
33
- }
34
- return objectlist.map((r) => this.ensure(maptoType, r, isEditMode, ...p));
35
- }
36
- static ensure(maptoType, object, isEditMode, ...p) {
37
- if (object === undefined) {
38
- object = maptoType;
39
- maptoType = this;
40
- }
41
- if (Array.isArray(object))
42
- object = object_first(object);
43
- return object instanceof maptoType
44
- ? object
45
- : new maptoType(object, isEditMode, ...p);
46
- }
47
- /* -------------------------------------------------------------------------- */
48
- static map_rowindex(objectlist) {
49
- let index = 0;
50
- return (objectlist?.map((r, i) => {
51
- r.__row_number = ++index;
52
- return r;
53
- }) ?? []);
54
- }
55
- static map_tableid(objectlist) {
56
- let index = 0;
57
- return (objectlist?.map((r, i) => {
58
- r.__table_id = r.__uid ?? String(++index);
59
- return r;
60
- }) ?? []);
61
- }
62
- static equals(a, b) {
63
- console.warn("Dont use the default equals method !");
64
- if (a == undefined || b == undefined)
65
- return false;
66
- if (typeof a === "object")
67
- a = a.__uid;
68
- if (typeof b === "object")
69
- b = b.__uid;
70
- return string_equals_ignorecase(a, b);
71
- }
72
- }
73
- export default MapableObject;
3
+ */var MapableObject=/*#__PURE__*/function(){function a(){_classCallCheck(this,a),_defineProperty(this,"__uid",void 0),_defineProperty(this,"__data_id",void 0),_defineProperty(this,"__table_id",void 0),_defineProperty(this,"__row_number",void 0),this.__uid=_uid.uid.localuid()}return _createClass(a,null,[{key:"mapto",value:function mapto(a,b){for(var c=this,d=!(2<arguments.length&&void 0!==arguments[2])||arguments[2],e=arguments.length,f=Array(3<e?e-3:0),g=3;g<e;g++)f[g-3]=arguments[g];if(void 0===b){if(void 0===a)return[];if(a instanceof Object)return[];b=a,a=this}return null==b?[]:(b instanceof _ObjectArray["default"]&&(b=b.getObjects()),"object"!=_typeof(b)&&(b=[b]),Array.isArray(b)?b.map(function(b){return c.ensure.apply(c,[a,b,d].concat(f))}):[this.ensure.apply(this,[a,b,d].concat(f))])}},{key:"ensure",value:function ensure(a,b,c){void 0===b&&(b=a,a=this),Array.isArray(b)&&(b=(0,_object.object_first)(b));for(var d=arguments.length,e=Array(3<d?d-3:0),f=3;f<d;f++)e[f-3]=arguments[f];return b instanceof a?b:_construct(a,[b,c].concat(e))}/* -------------------------------------------------------------------------- */},{key:"map_rowindex",value:function map_rowindex(a){var b,c=0;return null!==(b=null===a||void 0===a?void 0:a.map(function(a){return a.__row_number=++c,a}))&&void 0!==b?b:[]}},{key:"map_tableid",value:function map_tableid(a){var b,c=0;return null!==(b=null===a||void 0===a?void 0:a.map(function(a){var b;return a.__table_id=null!==(b=a.__uid)&&void 0!==b?b:++c+"",a}))&&void 0!==b?b:[]}},{key:"equals",value:function equals(c,d){return(console.warn("Dont use the default equals method !"),null!=c&&null!=d)&&("object"===_typeof(c)&&(c=c.__uid),"object"===_typeof(d)&&(d=d.__uid),(0,_string.string_equals_ignorecase)(c,d))}}]),a}();exports.MapableObject=MapableObject;var _default=MapableObject;exports["default"]=_default;
@@ -1,35 +1 @@
1
- import { object_isExactlyEmpty } from "@azrico/object";
2
- import SimpleObject from "./SimpleObject";
3
- export class MetaObject extends SimpleObject {
4
- id;
5
- key = "";
6
- value;
7
- constructor(initObject, value) {
8
- super(true, false);
9
- if (typeof initObject === "object") {
10
- this.id = initObject.id;
11
- this.key = initObject.key;
12
- this.value = initObject.value;
13
- }
14
- else if (typeof initObject === "string") {
15
- this.key = initObject;
16
- this.value = value;
17
- }
18
- this.setOriginal();
19
- }
20
- async get_saveObject() {
21
- return await MetaObject.get_saveObject(this);
22
- }
23
- static async get_saveObject(obj) { }
24
- async Prepare() {
25
- this.key = String(this.key);
26
- return await Promise.resolve(true);
27
- }
28
- get isNew() {
29
- return this.id == null || Number(this.id) <= 0;
30
- }
31
- get isDeleted() {
32
- return object_isExactlyEmpty(this.value);
33
- }
34
- }
35
- export default MetaObject;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports["default"]=exports.MetaObject=void 0;var _object=require("@azrico/object"),_SimpleObject2=_interopRequireDefault(require("./SimpleObject"));function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}}function _regeneratorRuntime(){"use strict";/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */function a(a,b,c){return Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}),a[b]}function b(a,b,e,f){var g=b&&b.prototype instanceof d?b:d,h=Object.create(g.prototype),j=new l(f||[]);return h._invoke=function(a,b,d){var e="suspendedStart";return function(f,g){if("executing"===e)throw new Error("Generator is already running");if("completed"===e){if("throw"===f)throw g;return n()}for(d.method=f,d.arg=g;;){var h=d.delegate;if(h){var j=i(h,d);if(j){if(j===v)continue;return j}}if("next"===d.method)d.sent=d._sent=d.arg;else if("throw"===d.method){if("suspendedStart"===e)throw e="completed",d.arg;d.dispatchException(d.arg)}else"return"===d.method&&d.abrupt("return",d.arg);e="executing";var k=c(a,b,d);if("normal"===k.type){if(e=d.done?"completed":"suspendedYield",k.arg===v)continue;return{value:k.arg,done:d.done}}"throw"===k.type&&(e="completed",d.method="throw",d.arg=k.arg)}}}(a,e,j),h}function c(a,b,c){try{return{type:"normal",arg:a.call(b,c)}}catch(a){return{type:"throw",arg:a}}}function d(){}function e(){}function f(){}function g(b){["next","throw","return"].forEach(function(c){a(b,c,function(a){return this._invoke(c,a)})})}function h(a,b){function d(e,f,g,h){var i=c(a[e],a,f);if("throw"!==i.type){var j=i.arg,k=j.value;return k&&"object"==_typeof(k)&&q.call(k,"__await")?b.resolve(k.__await).then(function(a){d("next",a,g,h)},function(a){d("throw",a,g,h)}):b.resolve(k).then(function(a){j.value=a,g(j)},function(a){return d("throw",a,g,h)})}h(i.arg)}var e;this._invoke=function(a,c){function f(){return new b(function(b,e){d(a,c,b,e)})}return e=e?e.then(f,f):f()}}function i(a,b){var d=a.iterator[b.method];if(void 0===d){if(b.delegate=null,"throw"===b.method){if(a.iterator["return"]&&(b.method="return",b.arg=void 0,i(a,b),"throw"===b.method))return v;b.method="throw",b.arg=new TypeError("The iterator does not provide a 'throw' method")}return v}var e=c(d,a.iterator,b.arg);if("throw"===e.type)return b.method="throw",b.arg=e.arg,b.delegate=null,v;var f=e.arg;return f?f.done?(b[a.resultName]=f.value,b.next=a.nextLoc,"return"!==b.method&&(b.method="next",b.arg=void 0),b.delegate=null,v):f:(b.method="throw",b.arg=new TypeError("iterator result is not an object"),b.delegate=null,v)}function j(a){var b={tryLoc:a[0]};1 in a&&(b.catchLoc=a[1]),2 in a&&(b.finallyLoc=a[2],b.afterLoc=a[3]),this.tryEntries.push(b)}function k(a){var b=a.completion||{};b.type="normal",delete b.arg,a.completion=b}function l(a){this.tryEntries=[{tryLoc:"root"}],a.forEach(j,this),this.reset(!0)}function m(a){if(a){var b=a[s];if(b)return b.call(a);if("function"==typeof a.next)return a;if(!isNaN(a.length)){var c=-1,d=function b(){for(;++c<a.length;)if(q.call(a,c))return b.value=a[c],b.done=!1,b;return b.value=void 0,b.done=!0,b};return d.next=d}}return{next:n}}function n(){return{value:void 0,done:!0}}_regeneratorRuntime=function(){return o};var o={},p=Object.prototype,q=p.hasOwnProperty,r="function"==typeof Symbol?Symbol:{},s=r.iterator||"@@iterator",t=r.asyncIterator||"@@asyncIterator",u=r.toStringTag||"@@toStringTag";try{a({},"")}catch(b){a=function(a,b,c){return a[b]=c}}o.wrap=b;var v={},w={};a(w,s,function(){return this});var x=Object.getPrototypeOf,y=x&&x(x(m([])));y&&y!==p&&q.call(y,s)&&(w=y);var z=f.prototype=d.prototype=Object.create(w);return e.prototype=f,a(z,"constructor",f),a(f,"constructor",e),e.displayName=a(f,u,"GeneratorFunction"),o.isGeneratorFunction=function(a){var b="function"==typeof a&&a.constructor;return!!b&&(b===e||"GeneratorFunction"===(b.displayName||b.name))},o.mark=function(b){return Object.setPrototypeOf?Object.setPrototypeOf(b,f):(b.__proto__=f,a(b,u,"GeneratorFunction")),b.prototype=Object.create(z),b},o.awrap=function(a){return{__await:a}},g(h.prototype),a(h.prototype,t,function(){return this}),o.AsyncIterator=h,o.async=function(a,c,d,e,f){void 0===f&&(f=Promise);var g=new h(b(a,c,d,e),f);return o.isGeneratorFunction(c)?g:g.next().then(function(a){return a.done?a.value:g.next()})},g(z),a(z,u,"Generator"),a(z,s,function(){return this}),a(z,"toString",function(){return"[object Generator]"}),o.keys=function(a){var b=[];for(var c in a)b.push(c);return b.reverse(),function c(){for(;b.length;){var d=b.pop();if(d in a)return c.value=d,c.done=!1,c}return c.done=!0,c}},o.values=m,l.prototype={constructor:l,reset:function reset(a){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(k),!a)for(var b in this)"t"===b.charAt(0)&&q.call(this,b)&&!isNaN(+b.slice(1))&&(this[b]=void 0)},stop:function stop(){this.done=!0;var a=this.tryEntries[0].completion;if("throw"===a.type)throw a.arg;return this.rval},dispatchException:function dispatchException(a){function b(b,d){return f.type="throw",f.arg=a,c.next=b,d&&(c.method="next",c.arg=void 0),!!d}if(this.done)throw a;for(var c=this,d=this.tryEntries.length-1;0<=d;--d){var e=this.tryEntries[d],f=e.completion;if("root"===e.tryLoc)return b("end");if(e.tryLoc<=this.prev){var g=q.call(e,"catchLoc"),h=q.call(e,"finallyLoc");if(g&&h){if(this.prev<e.catchLoc)return b(e.catchLoc,!0);if(this.prev<e.finallyLoc)return b(e.finallyLoc)}else if(!g){if(!h)throw new Error("try statement without catch or finally");if(this.prev<e.finallyLoc)return b(e.finallyLoc)}else if(this.prev<e.catchLoc)return b(e.catchLoc,!0)}}},abrupt:function abrupt(a,b){for(var c,d=this.tryEntries.length-1;0<=d;--d)if(c=this.tryEntries[d],c.tryLoc<=this.prev&&q.call(c,"finallyLoc")&&this.prev<c.finallyLoc){var e=c;break}e&&("break"===a||"continue"===a)&&e.tryLoc<=b&&b<=e.finallyLoc&&(e=null);var f=e?e.completion:{};return f.type=a,f.arg=b,e?(this.method="next",this.next=e.finallyLoc,v):this.complete(f)},complete:function complete(a,b){if("throw"===a.type)throw a.arg;return"break"===a.type||"continue"===a.type?this.next=a.arg:"return"===a.type?(this.rval=this.arg=a.arg,this.method="return",this.next="end"):"normal"===a.type&&b&&(this.next=b),v},finish:function finish(a){for(var b,c=this.tryEntries.length-1;0<=c;--c)if(b=this.tryEntries[c],b.finallyLoc===a)return this.complete(b.completion,b.afterLoc),k(b),v},catch:function _catch(a){for(var b,c=this.tryEntries.length-1;0<=c;--c)if(b=this.tryEntries[c],b.tryLoc===a){var d=b.completion;if("throw"===d.type){var e=d.arg;k(b)}return e}throw new Error("illegal catch attempt")},delegateYield:function delegateYield(a,b,c){return this.delegate={iterator:m(a),resultName:b,nextLoc:c},"next"===this.method&&(this.arg=void 0),v}},o}function asyncGeneratorStep(a,b,c,d,e,f,g){try{var h=a[f](g),i=h.value}catch(a){return void c(a)}h.done?b(i):Promise.resolve(i).then(d,e)}function _asyncToGenerator(a){return function(){var b=this,c=arguments;return new Promise(function(d,e){function f(a){asyncGeneratorStep(h,d,e,f,g,"next",a)}function g(a){asyncGeneratorStep(h,d,e,f,g,"throw",a)}var h=a.apply(b,c);f(void 0)})}}function _typeof(a){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function _defineProperties(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,c.key,c)}function _createClass(a,b,c){return b&&_defineProperties(a.prototype,b),c&&_defineProperties(a,c),Object.defineProperty(a,"prototype",{writable:!1}),a}function _inherits(a,b){if("function"!=typeof b&&null!==b)throw new TypeError("Super expression must either be null or a function");a.prototype=Object.create(b&&b.prototype,{constructor:{value:a,writable:!0,configurable:!0}}),Object.defineProperty(a,"prototype",{writable:!1}),b&&_setPrototypeOf(a,b)}function _setPrototypeOf(a,b){return _setPrototypeOf=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(a,b){return a.__proto__=b,a},_setPrototypeOf(a,b)}function _createSuper(a){var b=_isNativeReflectConstruct();return function(){var c,d=_getPrototypeOf(a);if(b){var e=_getPrototypeOf(this).constructor;c=Reflect.construct(d,arguments,e)}else c=d.apply(this,arguments);return _possibleConstructorReturn(this,c)}}function _possibleConstructorReturn(a,b){if(b&&("object"===_typeof(b)||"function"==typeof b))return b;if(void 0!==b)throw new TypeError("Derived constructors may only return object or undefined");return _assertThisInitialized(a)}function _assertThisInitialized(a){if(void 0===a)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return a}function _isNativeReflectConstruct(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(a){return!1}}function _getPrototypeOf(a){return _getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(a){return a.__proto__||Object.getPrototypeOf(a)},_getPrototypeOf(a)}function _defineProperty(a,b,c){return b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}var MetaObject=/*#__PURE__*/function(a){function b(a,d){var e;return _classCallCheck(this,b),e=c.call(this,!0,!1),_defineProperty(_assertThisInitialized(e),"id",void 0),_defineProperty(_assertThisInitialized(e),"key",""),_defineProperty(_assertThisInitialized(e),"value",void 0),"object"===_typeof(a)?(e.id=a.id,e.key=a.key,e.value=a.value):"string"==typeof a&&(e.key=a,e.value=d),e.setOriginal(),e}_inherits(b,a);var c=_createSuper(b);return _createClass(b,[{key:"get_saveObject",value:function(){function a(){return c.apply(this,arguments)}var c=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function a(){return _regeneratorRuntime().wrap(function c(a){for(;1;)switch(a.prev=a.next){case 0:return a.next=2,b.get_saveObject(this);case 2:return a.abrupt("return",a.sent);case 3:case"end":return a.stop();}},a,this)}));return a}()},{key:"Prepare",value:function(){function a(){return b.apply(this,arguments)}var b=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function a(){return _regeneratorRuntime().wrap(function b(a){for(;1;)switch(a.prev=a.next){case 0:return this.key+="",a.next=3,Promise.resolve(!0);case 3:return a.abrupt("return",a.sent);case 4:case"end":return a.stop();}},a,this)}));return a}()},{key:"isNew",get:function get(){return null==this.id||0>=+this.id}},{key:"isDeleted",get:function get(){return(0,_object.object_isExactlyEmpty)(this.value)}}],[{key:"get_saveObject",value:function(){function a(a){return b.apply(this,arguments)}var b=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function b(a){return _regeneratorRuntime().wrap(function b(a){for(;1;)switch(a.prev=a.next){case 0:case"end":return a.stop();}},b)}));return a}()}]),b}(_SimpleObject2["default"]);exports.MetaObject=MetaObject;var _default=MetaObject;exports["default"]=_default;
@@ -1,43 +1 @@
1
- export class ObjectArray {
2
- /* -------------------------------------------------------------------------- */
3
- /* Values */
4
- /* -------------------------------------------------------------------------- */
5
- objArray = [];
6
- /* -------------------------------------------------------------------------- */
7
- /* Base */
8
- /* -------------------------------------------------------------------------- */
9
- constructor(initObject, mapto_type) {
10
- this.setObjects(initObject, mapto_type);
11
- }
12
- addObjects(initObject, mapto_type) {
13
- if (initObject == null)
14
- return false;
15
- let resultObjects = ObjectArray.flattenWebObjects(initObject);
16
- if (mapto_type)
17
- resultObjects = resultObjects.map((r) => r instanceof mapto_type ? r : new mapto_type(r));
18
- resultObjects.map((s) => this.objArray.push(s));
19
- return true;
20
- }
21
- setObjects(initObject, mapto_type) {
22
- this.objArray = [];
23
- this.addObjects(initObject, mapto_type);
24
- }
25
- getObjects() {
26
- return this.objArray;
27
- }
28
- static flattenWebObjects(inputData) {
29
- if (inputData instanceof ObjectArray) {
30
- return ObjectArray.flattenWebObjects(inputData.objArray);
31
- }
32
- else if (Array.isArray(inputData)) {
33
- let final_result = [];
34
- inputData.map((ind) => {
35
- ObjectArray.flattenWebObjects(ind).map((s) => final_result.push(s));
36
- });
37
- return final_result;
38
- }
39
- else
40
- return [inputData];
41
- }
42
- }
43
- export default ObjectArray;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports["default"]=exports.ObjectArray=void 0;function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function _defineProperties(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,c.key,c)}function _createClass(a,b,c){return b&&_defineProperties(a.prototype,b),c&&_defineProperties(a,c),Object.defineProperty(a,"prototype",{writable:!1}),a}function _defineProperty(a,b,c){return b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}var ObjectArray=/*#__PURE__*/function(){/* -------------------------------------------------------------------------- */ /* Values */ /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ /* Base */ /* -------------------------------------------------------------------------- */function a(b,c){_classCallCheck(this,a),_defineProperty(this,"objArray",[]),this.setObjects(b,c)}return _createClass(a,[{key:"addObjects",value:function addObjects(b,c){var d=this;if(null==b)return!1;var e=a.flattenWebObjects(b);return c&&(e=e.map(function(a){return a instanceof c?a:new c(a)})),e.map(function(a){return d.objArray.push(a)}),!0}},{key:"setObjects",value:function setObjects(a,b){this.objArray=[],this.addObjects(a,b)}},{key:"getObjects",value:function getObjects(){return this.objArray}}],[{key:"flattenWebObjects",value:function flattenWebObjects(b){if(b instanceof a)return a.flattenWebObjects(b.objArray);if(Array.isArray(b)){var c=[];return b.map(function(b){a.flattenWebObjects(b).map(function(a){return c.push(a)})}),c}return[b]}}]),a}();exports.ObjectArray=ObjectArray;var _default=ObjectArray;exports["default"]=_default;
@@ -1,33 +1,22 @@
1
1
  import SimpleObject from "./SimpleObject";
2
- export declare type sendChangesType = boolean | "auto";
3
2
  /**
4
- * this object supports onChange events
3
+ * This class manages the events of an Simple Object
5
4
  */
6
- export declare class EventfulObject extends SimpleObject {
7
- __errors?: any[];
8
- __options?: object;
9
- __showErrors?: boolean;
5
+ export declare class ObjectManager<ObjType extends SimpleObject> {
10
6
  __eventList: any;
11
7
  __eventPrefix?: string;
12
8
  __sendEvents: boolean;
13
- constructor(...p: any[]);
14
- /**
15
- *
16
- * @param key
17
- * @param value
18
- * @param subvalue
19
- * @returns true if changed , false if not changed
20
- */
21
- setValue(key: string, value: any, sendChange?: sendChangesType): boolean;
22
- setSubValue(key: string, subkey: string, subvalue: any, sendChange?: sendChangesType): boolean;
23
- pushValue(key: string, value: any, sendChange?: sendChangesType): boolean;
24
- notifyChanged(type: string, key: string, value?: any, subvalue?: string): void;
9
+ __currentObject?: ObjType | null;
10
+ __options?: object;
11
+ notifyChanged(type: string, key: string, value?: any, subvalue?: string): false | undefined;
12
+ getObject(): ObjType | undefined;
13
+ setObject(toObj: ObjType | undefined): boolean;
25
14
  event_run(eventName: string, ...params: any): Promise<void>;
26
15
  event_use(name: string, runEvent: (...inputdata: any) => any, onlyOn?: any, runOnce?: boolean): any;
27
16
  event_add(name: string, uname: string, runEvent: (...inputdata: any) => any, onlyOn?: any, runOnce?: boolean): Promise<void>;
28
17
  events_stop(): void;
29
18
  events_clear(): void;
30
- static events_clear(obj: EventfulObject): void;
19
+ static events_clear(obj: ObjectManager<any>): void;
31
20
  /**
32
21
  * Set an option to some value, if its already equal to the value it will be deleted instead
33
22
  * @param key
@@ -46,9 +35,5 @@ export declare class EventfulObject extends SimpleObject {
46
35
  */
47
36
  holdOption(key: string, value: any, nextvalue: any, action: Function): Promise<void>;
48
37
  getOption(key: string): any;
49
- addError(title: string, msg?: string, sendToRegister?: boolean): void;
50
- static addError(o: EventfulObject, title: string, message?: string, sendToRegister?: boolean): any[];
51
- static getErrors(o: EventfulObject): any[];
52
- static clearErrors(o: EventfulObject): boolean;
53
38
  }
54
- export default EventfulObject;
39
+ export default ObjectManager;
@@ -0,0 +1,15 @@
1
+ "use strict";function _typeof(a){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}Object.defineProperty(exports,"__esModule",{value:!0}),exports["default"]=exports.ObjectManager=void 0;var _object=require("@azrico/object"),_event=require("@azrico/event");function _regeneratorRuntime(){"use strict";/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */function a(a,b,c){return Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}),a[b]}function b(a,b,e,f){var g=b&&b.prototype instanceof d?b:d,h=Object.create(g.prototype),j=new l(f||[]);return h._invoke=function(a,b,d){var e="suspendedStart";return function(f,g){if("executing"===e)throw new Error("Generator is already running");if("completed"===e){if("throw"===f)throw g;return n()}for(d.method=f,d.arg=g;;){var h=d.delegate;if(h){var j=i(h,d);if(j){if(j===v)continue;return j}}if("next"===d.method)d.sent=d._sent=d.arg;else if("throw"===d.method){if("suspendedStart"===e)throw e="completed",d.arg;d.dispatchException(d.arg)}else"return"===d.method&&d.abrupt("return",d.arg);e="executing";var k=c(a,b,d);if("normal"===k.type){if(e=d.done?"completed":"suspendedYield",k.arg===v)continue;return{value:k.arg,done:d.done}}"throw"===k.type&&(e="completed",d.method="throw",d.arg=k.arg)}}}(a,e,j),h}function c(a,b,c){try{return{type:"normal",arg:a.call(b,c)}}catch(a){return{type:"throw",arg:a}}}function d(){}function e(){}function f(){}function g(b){["next","throw","return"].forEach(function(c){a(b,c,function(a){return this._invoke(c,a)})})}function h(a,b){function d(e,f,g,h){var i=c(a[e],a,f);if("throw"!==i.type){var j=i.arg,k=j.value;return k&&"object"==_typeof(k)&&q.call(k,"__await")?b.resolve(k.__await).then(function(a){d("next",a,g,h)},function(a){d("throw",a,g,h)}):b.resolve(k).then(function(a){j.value=a,g(j)},function(a){return d("throw",a,g,h)})}h(i.arg)}var e;this._invoke=function(a,c){function f(){return new b(function(b,e){d(a,c,b,e)})}return e=e?e.then(f,f):f()}}function i(a,b){var d=a.iterator[b.method];if(void 0===d){if(b.delegate=null,"throw"===b.method){if(a.iterator["return"]&&(b.method="return",b.arg=void 0,i(a,b),"throw"===b.method))return v;b.method="throw",b.arg=new TypeError("The iterator does not provide a 'throw' method")}return v}var e=c(d,a.iterator,b.arg);if("throw"===e.type)return b.method="throw",b.arg=e.arg,b.delegate=null,v;var f=e.arg;return f?f.done?(b[a.resultName]=f.value,b.next=a.nextLoc,"return"!==b.method&&(b.method="next",b.arg=void 0),b.delegate=null,v):f:(b.method="throw",b.arg=new TypeError("iterator result is not an object"),b.delegate=null,v)}function j(a){var b={tryLoc:a[0]};1 in a&&(b.catchLoc=a[1]),2 in a&&(b.finallyLoc=a[2],b.afterLoc=a[3]),this.tryEntries.push(b)}function k(a){var b=a.completion||{};b.type="normal",delete b.arg,a.completion=b}function l(a){this.tryEntries=[{tryLoc:"root"}],a.forEach(j,this),this.reset(!0)}function m(a){if(a){var b=a[s];if(b)return b.call(a);if("function"==typeof a.next)return a;if(!isNaN(a.length)){var c=-1,d=function b(){for(;++c<a.length;)if(q.call(a,c))return b.value=a[c],b.done=!1,b;return b.value=void 0,b.done=!0,b};return d.next=d}}return{next:n}}function n(){return{value:void 0,done:!0}}_regeneratorRuntime=function(){return o};var o={},p=Object.prototype,q=p.hasOwnProperty,r="function"==typeof Symbol?Symbol:{},s=r.iterator||"@@iterator",t=r.asyncIterator||"@@asyncIterator",u=r.toStringTag||"@@toStringTag";try{a({},"")}catch(b){a=function(a,b,c){return a[b]=c}}o.wrap=b;var v={},w={};a(w,s,function(){return this});var x=Object.getPrototypeOf,y=x&&x(x(m([])));y&&y!==p&&q.call(y,s)&&(w=y);var z=f.prototype=d.prototype=Object.create(w);return e.prototype=f,a(z,"constructor",f),a(f,"constructor",e),e.displayName=a(f,u,"GeneratorFunction"),o.isGeneratorFunction=function(a){var b="function"==typeof a&&a.constructor;return!!b&&(b===e||"GeneratorFunction"===(b.displayName||b.name))},o.mark=function(b){return Object.setPrototypeOf?Object.setPrototypeOf(b,f):(b.__proto__=f,a(b,u,"GeneratorFunction")),b.prototype=Object.create(z),b},o.awrap=function(a){return{__await:a}},g(h.prototype),a(h.prototype,t,function(){return this}),o.AsyncIterator=h,o.async=function(a,c,d,e,f){void 0===f&&(f=Promise);var g=new h(b(a,c,d,e),f);return o.isGeneratorFunction(c)?g:g.next().then(function(a){return a.done?a.value:g.next()})},g(z),a(z,u,"Generator"),a(z,s,function(){return this}),a(z,"toString",function(){return"[object Generator]"}),o.keys=function(a){var b=[];for(var c in a)b.push(c);return b.reverse(),function c(){for(;b.length;){var d=b.pop();if(d in a)return c.value=d,c.done=!1,c}return c.done=!0,c}},o.values=m,l.prototype={constructor:l,reset:function reset(a){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(k),!a)for(var b in this)"t"===b.charAt(0)&&q.call(this,b)&&!isNaN(+b.slice(1))&&(this[b]=void 0)},stop:function stop(){this.done=!0;var a=this.tryEntries[0].completion;if("throw"===a.type)throw a.arg;return this.rval},dispatchException:function dispatchException(a){function b(b,d){return f.type="throw",f.arg=a,c.next=b,d&&(c.method="next",c.arg=void 0),!!d}if(this.done)throw a;for(var c=this,d=this.tryEntries.length-1;0<=d;--d){var e=this.tryEntries[d],f=e.completion;if("root"===e.tryLoc)return b("end");if(e.tryLoc<=this.prev){var g=q.call(e,"catchLoc"),h=q.call(e,"finallyLoc");if(g&&h){if(this.prev<e.catchLoc)return b(e.catchLoc,!0);if(this.prev<e.finallyLoc)return b(e.finallyLoc)}else if(!g){if(!h)throw new Error("try statement without catch or finally");if(this.prev<e.finallyLoc)return b(e.finallyLoc)}else if(this.prev<e.catchLoc)return b(e.catchLoc,!0)}}},abrupt:function abrupt(a,b){for(var c,d=this.tryEntries.length-1;0<=d;--d)if(c=this.tryEntries[d],c.tryLoc<=this.prev&&q.call(c,"finallyLoc")&&this.prev<c.finallyLoc){var e=c;break}e&&("break"===a||"continue"===a)&&e.tryLoc<=b&&b<=e.finallyLoc&&(e=null);var f=e?e.completion:{};return f.type=a,f.arg=b,e?(this.method="next",this.next=e.finallyLoc,v):this.complete(f)},complete:function complete(a,b){if("throw"===a.type)throw a.arg;return"break"===a.type||"continue"===a.type?this.next=a.arg:"return"===a.type?(this.rval=this.arg=a.arg,this.method="return",this.next="end"):"normal"===a.type&&b&&(this.next=b),v},finish:function finish(a){for(var b,c=this.tryEntries.length-1;0<=c;--c)if(b=this.tryEntries[c],b.finallyLoc===a)return this.complete(b.completion,b.afterLoc),k(b),v},catch:function _catch(a){for(var b,c=this.tryEntries.length-1;0<=c;--c)if(b=this.tryEntries[c],b.tryLoc===a){var d=b.completion;if("throw"===d.type){var e=d.arg;k(b)}return e}throw new Error("illegal catch attempt")},delegateYield:function delegateYield(a,b,c){return this.delegate={iterator:m(a),resultName:b,nextLoc:c},"next"===this.method&&(this.arg=void 0),v}},o}function asyncGeneratorStep(a,b,c,d,e,f,g){try{var h=a[f](g),i=h.value}catch(a){return void c(a)}h.done?b(i):Promise.resolve(i).then(d,e)}function _asyncToGenerator(a){return function(){var b=this,c=arguments;return new Promise(function(d,e){function f(a){asyncGeneratorStep(h,d,e,f,g,"next",a)}function g(a){asyncGeneratorStep(h,d,e,f,g,"throw",a)}var h=a.apply(b,c);f(void 0)})}}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function _defineProperties(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,c.key,c)}function _createClass(a,b,c){return b&&_defineProperties(a.prototype,b),c&&_defineProperties(a,c),Object.defineProperty(a,"prototype",{writable:!1}),a}function _defineProperty(a,b,c){return b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}/**
2
+ * This class manages the events of an Simple Object
3
+ */var ObjectManager=/*#__PURE__*/function(){function a(){_classCallCheck(this,a),_defineProperty(this,"__eventList",void 0),_defineProperty(this,"__eventPrefix",void 0),_defineProperty(this,"__sendEvents",!0),_defineProperty(this,"__currentObject",void 0),_defineProperty(this,"__options",void 0)}return _createClass(a,[{key:"notifyChanged",value:function notifyChanged(a,b,c){var d=this.getObject();if(!d)return!1;void 0===c&&(c=d.getValue(b));var e=(a?"$".concat(a,"$"):"")+b;this.event_run("on_change",e,c)}/* -------------------------------------------------------------------------- */},{key:"getObject",value:function getObject(){var a;return null!==(a=this.__currentObject)&&void 0!==a?a:void 0}},{key:"setObject",value:function setObject(a){var b=this;return this.__currentObject=a,this.__currentObject&&(this.__currentObject.get_managerClass=function(){return b}),!0}/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ /* Events */ /* -------------------------------------------------------------------------- */},{key:"event_run",value:function(){function a(){return b.apply(this,arguments)}var b=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function b(a){var c,d,e,f=arguments;return _regeneratorRuntime().wrap(function g(b){for(;1;)switch(b.prev=b.next){case 0:if(this.__sendEvents){b.next=2;break}return b.abrupt("return");case 2:for(c=f.length,d=Array(1<c?c-1:0),e=1;e<c;e++)d[e-1]=f[e];return b.next=5,_event.EventManager.run.apply(_event.EventManager,[this,a].concat(d));case 5:case"end":return b.stop();}},b,this)}));return a}()},{key:"event_use",value:function event_use(a,b){var c=2<arguments.length&&void 0!==arguments[2]?arguments[2]:null,d=!!(3<arguments.length&&void 0!==arguments[3])&&arguments[3];return _event.EventManager.use(this,a,b,c,d)}},{key:"event_add",value:function(){function a(a,c,d){return b.apply(this,arguments)}var b=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function d(a,b,c){var e,f,g=arguments;return _regeneratorRuntime().wrap(function h(d){for(;1;)switch(d.prev=d.next){case 0:return e=3<g.length&&void 0!==g[3]?g[3]:null,f=!!(4<g.length&&void 0!==g[4])&&g[4],d.next=4,_event.EventManager.add(this,a,b,c,e,f);case 4:case"end":return d.stop();}},d,this)}));return a}()},{key:"events_stop",value:function events_stop(){this.__sendEvents=!1}},{key:"events_clear",value:function events_clear(){a.events_clear(this)}},{key:"toggleOption",value:/* -------------------------------------------------------------------------- */ /* Options */ /* -------------------------------------------------------------------------- */ /**
4
+ * Set an option to some value, if its already equal to the value it will be deleted instead
5
+ * @param key
6
+ * @param value
7
+ * @returns
8
+ */function toggleOption(a,b){var c=this.getOption(a);(0,_object.object_equals_loose)(c,b)?this.setOption(a,null):this.setOption(a,b)}},{key:"setOption",value:function setOption(a,b){return null==this.__options&&(this.__options={}),null==b?delete this.__options[a]:this.__options[a]=b,this.event_run("on_option_change",a,b)}/**
9
+ * Sets an option then does an action,
10
+ * after the action is run, updates the option again
11
+ * @param key
12
+ * @param value
13
+ * @param nextvalue
14
+ * @param action
15
+ */},{key:"holdOption",value:function(){function a(a,c,d,e){return b.apply(this,arguments)}var b=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function e(a,b,c,d){return _regeneratorRuntime().wrap(function f(e){for(;1;)switch(e.prev=e.next){case 0:if(e.prev=0,this.setOption(a,b),"function"!=typeof d){e.next=5;break}return e.next=5,d();case 5:return e.prev=5,this.setOption(a,c),e.finish(5);case 8:case"end":return e.stop();}},e,this,[[0,,5,8]])}));return a}()},{key:"getOption",value:function getOption(a){return null==this.__options?void 0:this.__options[a]}}],[{key:"events_clear",value:function events_clear(a){_event.EventManager.removeAll(a)}}]),a}();exports.ObjectManager=ObjectManager;var _default=ObjectManager;exports["default"]=_default;
@@ -1,12 +1,18 @@
1
1
  import { MapableObject } from "./MapableObject";
2
+ import ObjectManager from "./ObjectManager";
3
+ export declare type saveResultType = "normal" | "nothing" | "error" | "canceled";
4
+ export declare type saveType = "normal" | "quick";
5
+ export declare type sendChangesType = boolean | "auto";
2
6
  export declare class SimpleObject extends MapableObject {
7
+ static __cache_name: string;
3
8
  __originalobject?: this;
4
9
  __delta: Partial<this>;
5
10
  __changed: boolean;
6
11
  __lastChanged: string;
7
12
  __is_readonly: boolean;
8
13
  readonly __is_edit_mode: boolean;
9
- static __cache_name: string;
14
+ __errors?: any[];
15
+ __showErrors?: boolean;
10
16
  constructor(isEditMode?: boolean, is_readonly?: boolean);
11
17
  loadValues(initObject: any, fullUpdate?: boolean): boolean;
12
18
  static loadValues(obj: any, initObject: any, fullUpdate?: boolean): boolean;
@@ -50,11 +56,15 @@ export declare class SimpleObject extends MapableObject {
50
56
  get isEditMode(): boolean;
51
57
  get __cache_name(): string;
52
58
  get_lastChanged(): boolean;
59
+ get_managerClass: () => ObjectManager<this> | null;
53
60
  static isDeleted<T extends SimpleObject>(obj: T): boolean;
54
61
  getOriginal(): this | undefined;
55
62
  setOriginal(toObj?: null | 0 | any): this | undefined;
56
63
  static setOriginal<T>(obj: T, toObj?: null | 0 | any): T | undefined;
57
64
  static getOriginal<T extends SimpleObject>(obj: T): T | undefined;
65
+ static addError(o: SimpleObject, title: string, message?: string, sendToRegister?: boolean): any[];
66
+ static getErrors(o: SimpleObject): any[];
67
+ static clearErrors(o: SimpleObject): boolean;
58
68
  static delete_cache(): void;
59
69
  static get_canModify(o: SimpleObject): boolean;
60
70
  static equals(a?: SimpleObject | any, b?: SimpleObject | any): boolean;
@@ -1,291 +1,26 @@
1
- import { gcache } from "@azrico/global";
2
- import { object_clone, object_equals, object_isEmpty, object_removeKeys, prop_rn, } from "@azrico/object";
3
- import { MapableObject } from "./MapableObject";
4
- export class SimpleObject extends MapableObject {
5
- __originalobject;
6
- //changes
7
- __delta;
8
- __changed = false;
9
- __lastChanged = "";
10
- __is_readonly;
11
- __is_edit_mode;
12
- static __cache_name = "";
13
- constructor(isEditMode = true, is_readonly = false) {
14
- super();
15
- this.__delta = {};
16
- this.__is_edit_mode = isEditMode;
17
- this.__is_readonly = is_readonly || !this.__is_edit_mode;
18
- }
19
- /* -------------------------------------------------------------------------- */
20
- /* Load */
21
- /* -------------------------------------------------------------------------- */
22
- loadValues(initObject, fullUpdate = false) {
23
- SimpleObject.loadValues(this, initObject, fullUpdate);
24
- return true;
25
- }
26
- static loadValues(obj, initObject, fullUpdate = false) {
27
- if (initObject == null) {
28
- for (const key in obj) {
29
- delete obj[key];
30
- }
31
- }
32
- else if (typeof initObject == "object") {
33
- for (const key in initObject) {
34
- //if (fullUpdate != true) {
35
- // if (key.startsWith("_")) continue;
36
- //}
37
- if (key.startsWith("__"))
38
- continue;
39
- if (Object.prototype.hasOwnProperty.call(obj, key)) {
40
- obj[key] = initObject[key];
41
- }
42
- }
43
- }
44
- return true;
45
- }
46
- /* -------------------------------------------------------------------------- */
47
- static getValue(o, key, original = false) {
48
- if (o instanceof SimpleObject && typeof o.getValue === "function")
49
- return o.getValue(key, original);
50
- if (!original && o.__delta[key])
51
- return o.__delta[key];
52
- return o[key];
53
- }
54
- getValue(key, original = false) {
55
- if (!original && this.__delta[key])
56
- return this.__delta[key];
57
- return this[key];
58
- }
59
- get(key, original = false) {
60
- if (!original && this.__delta[key])
61
- return this.__delta[key];
62
- return this[key];
63
- }
64
- /**
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports["default"]=exports.SimpleObject=void 0;var _global=require("@azrico/global"),_object=require("@azrico/object"),_MapableObject2=require("./MapableObject"),_ObjectManager=_interopRequireDefault(require("./ObjectManager")),_string=require("@azrico/string");function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}}function _typeof(a){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function _defineProperties(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,c.key,c)}function _createClass(a,b,c){return b&&_defineProperties(a.prototype,b),c&&_defineProperties(a,c),Object.defineProperty(a,"prototype",{writable:!1}),a}function _inherits(a,b){if("function"!=typeof b&&null!==b)throw new TypeError("Super expression must either be null or a function");a.prototype=Object.create(b&&b.prototype,{constructor:{value:a,writable:!0,configurable:!0}}),Object.defineProperty(a,"prototype",{writable:!1}),b&&_setPrototypeOf(a,b)}function _setPrototypeOf(a,b){return _setPrototypeOf=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(a,b){return a.__proto__=b,a},_setPrototypeOf(a,b)}function _createSuper(a){var b=_isNativeReflectConstruct();return function(){var c,d=_getPrototypeOf(a);if(b){var e=_getPrototypeOf(this).constructor;c=Reflect.construct(d,arguments,e)}else c=d.apply(this,arguments);return _possibleConstructorReturn(this,c)}}function _possibleConstructorReturn(a,b){if(b&&("object"===_typeof(b)||"function"==typeof b))return b;if(void 0!==b)throw new TypeError("Derived constructors may only return object or undefined");return _assertThisInitialized(a)}function _assertThisInitialized(a){if(void 0===a)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return a}function _isNativeReflectConstruct(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(a){return!1}}function _getPrototypeOf(a){return _getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(a){return a.__proto__||Object.getPrototypeOf(a)},_getPrototypeOf(a)}function _defineProperty(a,b,c){return b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}var SimpleObject=/*#__PURE__*/function(a){//changes
2
+ function b(){var a,d=!(0<arguments.length&&void 0!==arguments[0])||arguments[0],e=!!(1<arguments.length&&void 0!==arguments[1])&&arguments[1];return _classCallCheck(this,b),a=c.call(this),_defineProperty(_assertThisInitialized(a),"__originalobject",void 0),_defineProperty(_assertThisInitialized(a),"__delta",void 0),_defineProperty(_assertThisInitialized(a),"__changed",!1),_defineProperty(_assertThisInitialized(a),"__lastChanged",""),_defineProperty(_assertThisInitialized(a),"__is_readonly",void 0),_defineProperty(_assertThisInitialized(a),"__is_edit_mode",void 0),_defineProperty(_assertThisInitialized(a),"__errors",void 0),_defineProperty(_assertThisInitialized(a),"__showErrors",void 0),_defineProperty(_assertThisInitialized(a),"get_managerClass",function(){return null}),a.__delta={},a.__is_edit_mode=d,a.__is_readonly=e||!a.__is_edit_mode,a}/* -------------------------------------------------------------------------- */ /* Load */ /* -------------------------------------------------------------------------- */_inherits(b,a);var c=_createSuper(b);return _createClass(b,[{key:"loadValues",value:function loadValues(a){var c=!!(1<arguments.length&&void 0!==arguments[1])&&arguments[1];return b.loadValues(this,a,c),!0}},{key:"getValue",value:function getValue(a){var b=!!(1<arguments.length&&void 0!==arguments[1])&&arguments[1];return!b&&this.__delta[a]?this.__delta[a]:this[a]}},{key:"get",value:function get(a){var b=!!(1<arguments.length&&void 0!==arguments[1])&&arguments[1];return!b&&this.__delta[a]?this.__delta[a]:this[a]}/**
65
3
  * set value
66
4
  * @param key
67
5
  * @param value
68
6
  * @return true if changed , false otherwise
69
- */
70
- setValue(key, value) {
71
- if (!this.canModify)
72
- throw Error("Cant use setValue when on readonly mode");
73
- let isValueChanged = false;
74
- try {
75
- const oldval = this.getValue(key);
76
- if (!object_equals(oldval, value, { ignoredStartingWords: "_" })) {
77
- this.__delta[key] = value;
78
- isValueChanged = true;
79
- }
80
- else
81
- isValueChanged = false;
82
- }
83
- finally {
84
- if (isValueChanged) {
85
- this.notifyChanged("", key, value);
86
- }
87
- }
88
- return isValueChanged;
89
- }
90
- /**
7
+ */},{key:"setValue",value:function setValue(a,b){if(!this.canModify)throw Error("Cant use setValue when on readonly mode");var c=!1;try{var d=this.getValue(a);(0,_object.object_equals)(d,b,{ignoredStartingWords:"_"})?c=!1:(this.__delta[a]=b,c=!0)}finally{c&&this.notifyChanged("",a,b)}return c}/**
91
8
  * set key of subObject
92
9
  * @param key
93
10
  * @param value
94
11
  * @param subvalue
95
12
  * @return true if changed , false otherwise
96
- */
97
- setSubValue(key, objKey, subvalue) {
98
- if (!this.canModify)
99
- throw Error("Cant use setValue when on readonly mode");
100
- let isValueChanged = false;
101
- try {
102
- //if accessing subval of an object, make sure the object is not null
103
- if (this.__delta[key] == null ||
104
- typeof this.__delta[key] != "object")
105
- this.__delta[key] = {};
106
- const subval = this.__delta[key][objKey];
107
- if (!object_equals(subval, subvalue, {
108
- ignoredStartingWords: "_",
109
- })) {
110
- this.__delta[key][objKey] = subvalue;
111
- isValueChanged = true;
112
- }
113
- else
114
- isValueChanged = false;
115
- }
116
- finally {
117
- if (isValueChanged) {
118
- this.notifyChanged("", key, objKey, subvalue);
119
- }
120
- }
121
- return isValueChanged;
122
- }
123
- //Push value on array
124
- pushValue(key, value) {
125
- if (value == null)
126
- return null;
127
- if (!this.get_canModify())
128
- throw Error("Cant use pushValue when on readonly mode");
129
- if (this.__delta[key] == null) {
130
- this.__delta[key] = this.getValue(key);
131
- }
132
- if (!Array.isArray(this.__delta[key]))
133
- throw Error("Cant use pushValue on non Array keys");
134
- let tempArray = this.__delta[key];
135
- tempArray.push(value);
136
- this.__delta[key] = tempArray;
137
- this.__changed = true;
138
- this.__lastChanged = `${key} : +${value}`;
139
- return tempArray;
140
- }
141
- notifyChanged(type, key, value, subvalue) {
142
- if (value === undefined)
143
- value = this.getValue(key);
144
- this.__changed = true;
145
- let lc = "";
146
- if (type)
147
- lc += `[${type}] `;
148
- if (subvalue) {
149
- lc += `${key}->${value} = ${subvalue}`;
150
- }
151
- else {
152
- lc += `${key} = ${value}`;
153
- }
154
- this.__lastChanged = lc;
155
- }
156
- /**
13
+ */},{key:"setSubValue",value:function setSubValue(a,b,c){if(!this.canModify)throw Error("Cant use setValue when on readonly mode");var d=!1;try{(null==this.__delta[a]||"object"!=_typeof(this.__delta[a]))&&(this.__delta[a]={});var e=this.__delta[a][b];(0,_object.object_equals)(e,c,{ignoredStartingWords:"_"})?d=!1:(this.__delta[a][b]=c,d=!0)}finally{d&&this.notifyChanged("",a,b,c)}return d}//Push value on array
14
+ },{key:"pushValue",value:function pushValue(a,b){if(null==b)return null;if(!this.canModify)throw Error("Cant use pushValue when on readonly mode");if(null==this.__delta[a]&&(this.__delta[a]=this.getValue(a)),!Array.isArray(this.__delta[a]))throw Error("Cant use pushValue on non Array keys");var c=this.__delta[a];return c.push(b),this.__delta[a]=c,this.__changed=!0,this.__lastChanged="".concat(a," : +").concat(b),c}},{key:"notifyChanged",value:function notifyChanged(a,b,c,d){void 0===c&&(c=this.getValue(b)),this.__changed=!0;var e="";a&&(e+="[".concat(a,"] ")),e+=d?"".concat(b,"->").concat(c," = ").concat(d):"".concat(b," = ").concat(c),this.__lastChanged=e;/* --------------------------- notify the manager --------------------------- */var f=this.get_managerClass();f instanceof _ObjectManager["default"]&&f.notifyChanged(a,b,c,d)}/**
157
15
  * Rename object property, mostly used to fix init_object to match legacy versions
158
16
  * @param o
159
17
  * @param f
160
18
  * @param t
161
19
  * @returns
162
- */
163
- rn(o, f, t) {
164
- if (typeof o == "object") {
165
- if (typeof f === "string" && typeof t === "string") {
166
- return prop_rn(o, f, t);
167
- }
168
- }
169
- if (typeof o === "string" && typeof f === "string") {
170
- return prop_rn(this, o, f);
171
- }
172
- return false;
173
- }
174
- /* -------------------------------------------------------------------------- */
175
- /* Changes */
176
- /* -------------------------------------------------------------------------- */
177
- /**
20
+ */},{key:"rn",value:function rn(a,b,c){return"object"==_typeof(a)&&"string"==typeof b&&"string"==typeof c?(0,_object.prop_rn)(a,b,c):"string"==typeof a&&"string"==typeof b&&(0,_object.prop_rn)(this,a,b)}/* -------------------------------------------------------------------------- */ /* Changes */ /* -------------------------------------------------------------------------- */ /**
178
21
  * Apply the changes and empty the delta object
179
- */
180
- apply_changes() {
181
- if (!this.isChanged) {
182
- console.warn("No changes to apply");
183
- }
184
- for (const key in this.__delta) {
185
- const nv = this.__delta[key];
186
- this[key] = nv;
187
- }
188
- this.__delta = {};
189
- this.__changed = false;
190
- }
191
- static setReadonly(objs, readonlyval = true) {
192
- let checkObjs = [];
193
- if (!objs)
194
- objs = [];
195
- if (!Array.isArray(objs))
196
- checkObjs = [objs];
197
- else
198
- checkObjs = objs;
199
- for (let index = 0; index < checkObjs.length; index++) {
200
- const element = checkObjs[index];
201
- element.__is_readonly = readonlyval;
202
- }
203
- }
204
- /* -------------------------------------------------------------------------- */
205
- /* Get/Check */
206
- /* -------------------------------------------------------------------------- */
207
- get isChanged() {
208
- return !object_isEmpty(this.__delta);
209
- }
210
- get isDeleted() {
211
- return false;
212
- }
213
- get d() {
214
- return this.__delta;
215
- }
216
- get canModify() {
217
- return !this.__is_readonly && this.isEditMode;
218
- }
219
- get isEditMode() {
220
- return this.__is_edit_mode !== false;
221
- }
222
- get __cache_name() {
223
- return this.constructor["__cache_name"];
224
- }
225
- get_lastChanged() {
226
- return !this.__lastChanged;
227
- }
228
- static isDeleted(obj) {
229
- if (obj instanceof SimpleObject)
230
- return obj.isDeleted === true;
231
- return false;
232
- }
233
- /* -------------------------------------------------------------------------- */
234
- /* Original */
235
- /* -------------------------------------------------------------------------- */
236
- getOriginal() {
237
- return this.__originalobject || undefined;
238
- }
239
- setOriginal(toObj = 0) {
240
- if (toObj === null) {
241
- delete this.__originalobject;
242
- return;
243
- }
244
- if (!this.isEditMode) {
245
- console.warn("Cant use setOriginal on non original objects ! this will create an infinite loop");
246
- return;
247
- }
248
- if (this.__is_readonly) {
249
- delete this.__originalobject;
250
- return;
251
- }
252
- if (toObj === 0) {
253
- toObj = this;
254
- }
255
- const cloneObject = object_clone(toObj);
256
- //this.__originalobject = cloneObject, ["__"];
257
- this.__originalobject = object_removeKeys(cloneObject, ["__"]);
258
- return this;
259
- }
260
- static setOriginal(obj, toObj = 0) {
261
- if (!(obj instanceof SimpleObject))
262
- return undefined;
263
- return obj.setOriginal(toObj);
264
- }
265
- static getOriginal(obj) {
266
- if (obj instanceof SimpleObject)
267
- return obj.getOriginal();
268
- return obj?.__originalobject;
269
- }
270
- /* -------------------------------------------------------------------------- */
271
- /* statics */
272
- /* -------------------------------------------------------------------------- */
273
- static delete_cache() {
274
- if (!this.__cache_name)
275
- return;
276
- gcache.delete_cache(this.__cache_name);
277
- }
278
- static get_canModify(o) {
279
- if (o instanceof SimpleObject)
280
- return o.canModify;
281
- return false;
282
- }
283
- /* -------------------------------------------------------------------------- */
284
- static equals(a, b) {
285
- console.warn("Dont use the default equals method !");
286
- if (a == undefined || b == undefined)
287
- return false;
288
- return a === b;
289
- }
290
- }
291
- export default SimpleObject;
22
+ */},{key:"apply_changes",value:function apply_changes(){for(var a in this.isChanged||console.warn("No changes to apply"),this.__delta){var b=this.__delta[a];this[a]=b}this.__delta={},this.__changed=!1}},{key:"isChanged",get:/* -------------------------------------------------------------------------- */ /* Get/Check */ /* -------------------------------------------------------------------------- */function get(){return!(0,_object.object_isEmpty)(this.__delta)}},{key:"isDeleted",get:function get(){return!1}},{key:"d",get:function get(){return this.__delta}},{key:"canModify",get:function get(){return!this.__is_readonly&&this.isEditMode}},{key:"isEditMode",get:function get(){return!1!==this.__is_edit_mode}},{key:"__cache_name",get:function get(){return this.constructor.__cache_name}},{key:"get_lastChanged",value:function get_lastChanged(){return!this.__lastChanged}},{key:"getOriginal",value:/* -------------------------------------------------------------------------- */ /* Original */ /* -------------------------------------------------------------------------- */function getOriginal(){return this.__originalobject||void 0}},{key:"setOriginal",value:function setOriginal(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:0;if(null===a)return void delete this.__originalobject;if(!this.isEditMode)return void console.warn("Cant use setOriginal on non original objects ! this will create an infinite loop");if(this.__is_readonly)return void delete this.__originalobject;0===a&&(a=this);var b=(0,_object.object_clone)(a);//this.__originalobject = cloneObject, ["__"];
23
+ return this.__originalobject=(0,_object.object_removeKeys)(b,["__"]),this}}],[{key:"loadValues",value:function loadValues(a,b){!!(2<arguments.length&&void 0!==arguments[2])&&arguments[2];if(null==b)for(var c in a)delete a[c];else if("object"==_typeof(b))for(var d in b)//if (fullUpdate != true) {
24
+ // if (key.startsWith("_")) continue;
25
+ //}
26
+ d.startsWith("__")||Object.prototype.hasOwnProperty.call(a,d)&&(a[d]=b[d]);return!0}/* -------------------------------------------------------------------------- */},{key:"getValue",value:function getValue(a,c){var d=!!(2<arguments.length&&void 0!==arguments[2])&&arguments[2];return a instanceof b&&"function"==typeof a.getValue?a.getValue(c,d):!d&&a.__delta[c]?a.__delta[c]:a[c]}},{key:"setReadonly",value:function setReadonly(a){var b=!(1<arguments.length&&void 0!==arguments[1])||arguments[1],c=[];a||(a=[]),c=Array.isArray(a)?a:[a];for(var d,e=0;e<c.length;e++)d=c[e],d.__is_readonly=b}},{key:"isDeleted",value:function isDeleted(a){return!!(a instanceof b)&&!0===a.isDeleted}},{key:"setOriginal",value:function setOriginal(a){var c=1<arguments.length&&void 0!==arguments[1]?arguments[1]:0;return a instanceof b?a.setOriginal(c):void 0}},{key:"getOriginal",value:function getOriginal(a){return a instanceof b?a.getOriginal():null===a||void 0===a?void 0:a.__originalobject}/* -------------------------------------------------------------------------- */ /* Errors */ /* -------------------------------------------------------------------------- */},{key:"addError",value:function addError(a,b,c){var d=!!(3<arguments.length&&void 0!==arguments[3])&&arguments[3];Array.isArray(a.__errors)||(a.__errors=[]);var e=(0,_string.combine_if_not_blank)(b," : ",c);return console.error("[ERR]",e),a.__errors.push(e),!1!==a.__showErrors&&d&&_global.gfunc.run_action("add_error",{title:b,message:c,type:"error"}),a.__errors}},{key:"getErrors",value:function getErrors(a){return a.__errors||[]}},{key:"clearErrors",value:function clearErrors(a){return a.__errors=[],!0}/* -------------------------------------------------------------------------- */ /* statics */ /* -------------------------------------------------------------------------- */},{key:"delete_cache",value:function delete_cache(){this.__cache_name&&_global.gcache.delete_cache(this.__cache_name)}},{key:"get_canModify",value:function get_canModify(a){return!!(a instanceof b)&&a.canModify}/* -------------------------------------------------------------------------- */},{key:"equals",value:function equals(c,a){return console.warn("Dont use the default equals method !"),null!=c&&null!=a&&c===a}}]),b}(_MapableObject2.MapableObject);exports.SimpleObject=SimpleObject,_defineProperty(SimpleObject,"__cache_name","");var _default=SimpleObject;exports["default"]=_default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azrico/webobject",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
4
4
  "description": "Stateful object",
5
5
  "author": "Azrideus",
6
6
  "license": "MIT",
@@ -1,159 +0,0 @@
1
- import { gfunc } from "@azrico/global";
2
- import { object_equals_loose } from "@azrico/object";
3
- import { EventManager } from "@azrico/event";
4
- import SimpleObject from "./SimpleObject";
5
- import { combine_if_not_blank } from "@azrico/string";
6
- /**
7
- * this object supports onChange events
8
- */
9
- export class EventfulObject extends SimpleObject {
10
- __errors;
11
- __options;
12
- __showErrors;
13
- __eventList;
14
- __eventPrefix;
15
- __sendEvents = true;
16
- constructor(...p) {
17
- super(...p);
18
- this.__eventList = {};
19
- }
20
- /**
21
- *
22
- * @param key
23
- * @param value
24
- * @param subvalue
25
- * @returns true if changed , false if not changed
26
- */
27
- setValue(key, value, sendChange = "auto") {
28
- const isValueChanged = super.setValue(key, value);
29
- if (sendChange === true || (isValueChanged && sendChange === "auto")) {
30
- this.notifyChanged("", key, value, undefined);
31
- }
32
- return isValueChanged;
33
- }
34
- setSubValue(key, subkey, subvalue, sendChange = "auto") {
35
- const isValueChanged = super.setSubValue(key, subkey, subvalue);
36
- if (sendChange === true || (isValueChanged && sendChange === "auto")) {
37
- this.notifyChanged(key, subkey, subvalue, undefined);
38
- }
39
- return isValueChanged;
40
- }
41
- pushValue(key, value, sendChange = "auto") {
42
- const isValueChanged = super.setValue(key, value);
43
- if (sendChange === true || (isValueChanged && sendChange === "auto")) {
44
- this.notifyChanged("", key, value, undefined);
45
- }
46
- return isValueChanged;
47
- }
48
- /* -------------------------------------------------------------------------- */
49
- notifyChanged(type, key, value, subvalue) {
50
- if (value === undefined)
51
- value = this.getValue(key);
52
- super.notifyChanged(type, key, value, subvalue);
53
- const typestr = (type ? `$${type}$` : "") + key;
54
- this.event_run("on_change", typestr, value);
55
- }
56
- /* -------------------------------------------------------------------------- */
57
- /* Events */
58
- /* -------------------------------------------------------------------------- */
59
- async event_run(eventName, ...params) {
60
- if (!this.__sendEvents)
61
- return;
62
- await EventManager.run(this, eventName, ...params);
63
- }
64
- event_use(name, runEvent, onlyOn = null, runOnce = false) {
65
- return EventManager.use(this, name, runEvent, onlyOn, runOnce);
66
- }
67
- async event_add(name, uname, runEvent, onlyOn = null, runOnce = false) {
68
- await EventManager.add(this, name, uname, runEvent, onlyOn, runOnce);
69
- }
70
- events_stop() {
71
- this.__sendEvents = false;
72
- }
73
- events_clear() {
74
- EventfulObject.events_clear(this);
75
- }
76
- static events_clear(obj) {
77
- EventManager.removeAll(obj);
78
- }
79
- /* -------------------------------------------------------------------------- */
80
- /* Options */
81
- /* -------------------------------------------------------------------------- */
82
- /**
83
- * Set an option to some value, if its already equal to the value it will be deleted instead
84
- * @param key
85
- * @param value
86
- * @returns
87
- */
88
- toggleOption(key, value) {
89
- var oldval = this.getOption(key);
90
- if (object_equals_loose(oldval, value)) {
91
- this.setOption(key, null);
92
- }
93
- else
94
- this.setOption(key, value);
95
- }
96
- setOption(key, value) {
97
- if (this.__options == null)
98
- this.__options = {};
99
- if (value == null) {
100
- delete this.__options[key];
101
- }
102
- else {
103
- this.__options[key] = value;
104
- }
105
- return this.event_run("on_option_change", key, value);
106
- }
107
- /**
108
- * Sets an option then does an action,
109
- * after the action is run, updates the option again
110
- * @param key
111
- * @param value
112
- * @param nextvalue
113
- * @param action
114
- */
115
- async holdOption(key, value, nextvalue, action) {
116
- try {
117
- this.setOption(key, value);
118
- if (typeof action === "function")
119
- await action();
120
- }
121
- finally {
122
- this.setOption(key, nextvalue);
123
- }
124
- }
125
- getOption(key) {
126
- if (this.__options == null)
127
- return undefined;
128
- return this.__options[key];
129
- }
130
- /* -------------------------------------------------------------------------- */
131
- /* Errors */
132
- /* -------------------------------------------------------------------------- */
133
- addError(title, msg = "", sendToRegister = false) {
134
- EventfulObject.addError(this, title, msg, sendToRegister);
135
- }
136
- static addError(o, title, message, sendToRegister = false) {
137
- if (!Array.isArray(o.__errors))
138
- o.__errors = [];
139
- const errStr = combine_if_not_blank(title, " : ", message);
140
- console.error("[ERR]", errStr);
141
- o.__errors.push(errStr);
142
- if (o.__showErrors !== false && sendToRegister) {
143
- gfunc.run_action("add_error", {
144
- title: title,
145
- message: message,
146
- type: "error",
147
- });
148
- }
149
- return o.__errors;
150
- }
151
- static getErrors(o) {
152
- return o.__errors || [];
153
- }
154
- static clearErrors(o) {
155
- o.__errors = [];
156
- return true;
157
- }
158
- }
159
- export default EventfulObject;