@azrico/webobject 1.1.7 → 1.1.10
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 +1 -1
- package/dist/src/WebObjects/ParentWebObject.js +15 -1
- package/dist/src/WebObjects/WebObject.d.ts +3 -2
- package/dist/src/WebObjects/WebObject.js +136 -4
- package/dist/src/WebObjects/WebObjectManager.js +71 -6
- package/dist/src/index.js +8 -1
- package/dist/src/structs/DummyObject.js +8 -1
- package/dist/src/structs/MapableObject.js +72 -2
- package/dist/src/structs/MetaObject.js +35 -1
- package/dist/src/structs/ObjectArray.js +43 -1
- package/dist/src/structs/ObjectManager.js +198 -7
- package/dist/src/structs/SimpleObject.d.ts +2 -1
- package/dist/src/structs/SimpleObject.js +472 -12
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export * from "./src/index";
|
|
@@ -1 +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;
|
|
@@ -28,10 +28,11 @@ export declare class WebObject extends SimpleObject {
|
|
|
28
28
|
/**
|
|
29
29
|
* You will post this to the server for saving
|
|
30
30
|
* automatically removes unchangable fields
|
|
31
|
-
* @param saveType
|
|
32
31
|
* @returns
|
|
33
32
|
*/
|
|
34
|
-
get_deltaObject(
|
|
33
|
+
get_deltaObject({ ...p }: {
|
|
34
|
+
[x: string]: any;
|
|
35
|
+
}): Promise<any>;
|
|
35
36
|
get manager(): WebObjectManager<this> | null;
|
|
36
37
|
get __web_path(): string;
|
|
37
38
|
get __web_type(): string;
|
|
@@ -1,13 +1,145 @@
|
|
|
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.WebObject=void 0;var _SimpleObject2=_interopRequireDefault(require("../structs/SimpleObject")),_object=require("@azrico/object");function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}}function ownKeys(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function _objectSpread(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?ownKeys(Object(b),!0).forEach(function(c){_defineProperty(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):ownKeys(Object(b)).forEach(function(c){Object.defineProperty(a,c,Object.getOwnPropertyDescriptor(b,c))});return 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),"meta_data",void 0),_defineProperty(_assertThisInitialized(a),"_id",void 0),_defineProperty(_assertThisInitialized(a),"get_managerClass",function(){return null}),_defineProperty(_assertThisInitialized(a),"get_type",function(){return a.__web_type}),_defineProperty(_assertThisInitialized(a),"get_webpath",function(){return a.__web_path}),a.meta_data=[],a}/* -------------------------------------------------------------------------- */ /* Meta data */ /* -------------------------------------------------------------------------- */ /**
|
|
1
|
+
import SimpleObject from "../structs/SimpleObject";
|
|
2
|
+
import { getInArray, object_equals, object_isEmpty, object_isTrue, setInArray, } from "@azrico/object";
|
|
3
|
+
export class WebObject extends SimpleObject {
|
|
4
|
+
static __web_path = "";
|
|
5
|
+
static __web_type = "";
|
|
6
|
+
meta_data;
|
|
7
|
+
_id;
|
|
8
|
+
constructor(isEditMode = true, is_readonly = false) {
|
|
9
|
+
super(isEditMode, is_readonly);
|
|
10
|
+
this.meta_data = [];
|
|
11
|
+
}
|
|
12
|
+
/* -------------------------------------------------------------------------- */
|
|
13
|
+
/* Meta data */
|
|
14
|
+
/* -------------------------------------------------------------------------- */
|
|
15
|
+
/**
|
|
2
16
|
* Update meta value of this object , meta data is stored in meta_data variable
|
|
3
17
|
* @param key
|
|
4
18
|
* @param value
|
|
5
19
|
* @param createIfNotExists should we create a new meta if key does not exist
|
|
6
20
|
* @param sendChange
|
|
7
21
|
* @returns
|
|
8
|
-
*/
|
|
22
|
+
*/
|
|
23
|
+
setMetaValue(key, value, createIfNotExists = true, sendChange = "auto") {
|
|
24
|
+
return WebObject.setMetaValue(this, key, value, createIfNotExists, sendChange);
|
|
25
|
+
}
|
|
26
|
+
getMeta(key) {
|
|
27
|
+
return WebObject.getMeta(this, key);
|
|
28
|
+
}
|
|
29
|
+
getMetaValue(key) {
|
|
30
|
+
return WebObject.getMetaValue(this, key);
|
|
31
|
+
}
|
|
32
|
+
/* -------------------------------------------------------------------------- */
|
|
33
|
+
static setMetaValue(o, key, value, createIfNotExists = true, sendChange = "auto") {
|
|
34
|
+
if (!o)
|
|
35
|
+
return false;
|
|
36
|
+
if (!o.canModify) {
|
|
37
|
+
WebObject.addError(o, "Readonly mode is set to true", `Cant use setMetaValue on ${key} when on readonly mode`, true);
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
const old_value = WebObject.getMetaValue(o, key);
|
|
41
|
+
if (object_equals(old_value, value))
|
|
42
|
+
return false;
|
|
43
|
+
const oldMeta = o.getValue("meta_data");
|
|
44
|
+
o.setValue("meta_data", setInArray(oldMeta, "key", key, "value", value, createIfNotExists));
|
|
45
|
+
if (sendChange !== false)
|
|
46
|
+
o.notifyChanged("meta", key, value);
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
static getMeta(o, key) {
|
|
50
|
+
if (o == null)
|
|
51
|
+
return null;
|
|
52
|
+
return getInArray(o.getValue("meta_data"), "key", key);
|
|
53
|
+
}
|
|
54
|
+
static getMetaValue(o, key) {
|
|
55
|
+
return WebObject.getMeta(o, key)?.value;
|
|
56
|
+
}
|
|
57
|
+
/* -------------------------------------------------------------------------- */
|
|
58
|
+
/* Save */
|
|
59
|
+
/* -------------------------------------------------------------------------- */
|
|
60
|
+
async Save() {
|
|
61
|
+
WebObject.addError(this, "Save not implented", "NOSAVE", true);
|
|
62
|
+
this.setSaveResult(false, "canceled");
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
canSave(deltaObj) {
|
|
66
|
+
const deltaRes = this.deltaIsValid(deltaObj);
|
|
67
|
+
if (deltaRes !== true)
|
|
68
|
+
return deltaRes;
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
deltaIsValid(d) {
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
static isResultValid(result_object) {
|
|
75
|
+
if (object_isEmpty(result_object))
|
|
76
|
+
return false;
|
|
77
|
+
if (object_isTrue(result_object.acknowledged)) {
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
9
83
|
* You will post this to the server for saving
|
|
10
84
|
* automatically removes unchangable fields
|
|
11
|
-
* @param saveType
|
|
12
85
|
* @returns
|
|
13
|
-
*/
|
|
86
|
+
*/
|
|
87
|
+
async get_deltaObject({ ...p }) {
|
|
88
|
+
const final_object = {};
|
|
89
|
+
const isChild = p.isChild;
|
|
90
|
+
const useDelta = p.useDelta;
|
|
91
|
+
const chkChangables = this.__changeables != null || this.__unchangeables != null;
|
|
92
|
+
//child objects usually dont update their __delta, so we read info from all of its properties
|
|
93
|
+
const dlt = !useDelta && isChild && chkChangables
|
|
94
|
+
? { ...this.allproperties }
|
|
95
|
+
: { ...this.__delta };
|
|
96
|
+
const allkeys = Object.keys(dlt);
|
|
97
|
+
const changableKeys = chkChangables
|
|
98
|
+
? allkeys.filter((s) => SimpleObject.canChangeKey(this, s))
|
|
99
|
+
: allkeys;
|
|
100
|
+
async function parseObj(obj) {
|
|
101
|
+
if (obj == null)
|
|
102
|
+
return undefined;
|
|
103
|
+
if (Array.isArray(obj))
|
|
104
|
+
return await Promise.all(obj.map(async (r) => await parseObj(r)));
|
|
105
|
+
if (obj instanceof WebObject &&
|
|
106
|
+
typeof obj.get_deltaObject === "function") {
|
|
107
|
+
//child elements have different kind of delta
|
|
108
|
+
const newobj_dlt = await obj.get_deltaObject({ isChild: true });
|
|
109
|
+
if (!object_isEmpty(newobj_dlt))
|
|
110
|
+
return newobj_dlt;
|
|
111
|
+
else
|
|
112
|
+
return obj;
|
|
113
|
+
}
|
|
114
|
+
return obj;
|
|
115
|
+
}
|
|
116
|
+
for (const key of changableKeys) {
|
|
117
|
+
final_object[key] = await parseObj(dlt[key]);
|
|
118
|
+
}
|
|
119
|
+
return final_object;
|
|
120
|
+
}
|
|
121
|
+
/* --------------------------------- Getters -------------------------------- */
|
|
122
|
+
get manager() {
|
|
123
|
+
return this.get_managerClass();
|
|
124
|
+
}
|
|
125
|
+
get __web_path() {
|
|
126
|
+
return this.constructor["__web_path"];
|
|
127
|
+
}
|
|
128
|
+
get __web_type() {
|
|
129
|
+
return this.constructor["__web_type"];
|
|
130
|
+
}
|
|
131
|
+
get_managerClass = () => null;
|
|
132
|
+
get_type = () => this.__web_type;
|
|
133
|
+
get_webpath = () => this.__web_path;
|
|
134
|
+
/* -------------------------------------------------------------------------- */
|
|
135
|
+
async onLoad(...p) {
|
|
136
|
+
return await this.manager?.onLoad(...p);
|
|
137
|
+
}
|
|
138
|
+
async onSave(...p) {
|
|
139
|
+
return await this.manager?.onSave(...p);
|
|
140
|
+
}
|
|
141
|
+
async onNew(...p) {
|
|
142
|
+
return await this.manager?.onNew(...p);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
export default WebObject;
|
|
@@ -1,22 +1,87 @@
|
|
|
1
|
-
|
|
1
|
+
import ObjectManager from "../structs/ObjectManager";
|
|
2
|
+
/**
|
|
2
3
|
* This class manages the events of an Simple Object
|
|
3
|
-
*/
|
|
4
|
+
*/
|
|
5
|
+
export class WebObjectManager extends ObjectManager {
|
|
6
|
+
/* -------------------------------------------------------------------------- */
|
|
7
|
+
/* Meta data */
|
|
8
|
+
/* -------------------------------------------------------------------------- */
|
|
9
|
+
/**
|
|
4
10
|
* Update meta value of this object , meta data is stored in meta_data variable
|
|
5
11
|
* @param key
|
|
6
12
|
* @param value
|
|
7
13
|
* @param createIfNotExists should we create a new meta if key does not exist
|
|
8
14
|
* @param sendChange
|
|
9
15
|
* @returns
|
|
10
|
-
*/
|
|
16
|
+
*/
|
|
17
|
+
setMetaValue(key, value, createIfNotExists = true, sendChange = "auto") {
|
|
18
|
+
return this.obj?.setMetaValue(key, value, createIfNotExists, sendChange);
|
|
19
|
+
}
|
|
20
|
+
getMeta(key) {
|
|
21
|
+
return this.obj?.getMeta(key);
|
|
22
|
+
}
|
|
23
|
+
getMetaValue(key) {
|
|
24
|
+
return this.obj?.getMetaValue(key);
|
|
25
|
+
}
|
|
26
|
+
/* -------------------------------------------------------------------------- */
|
|
27
|
+
async get_deltaObject() {
|
|
28
|
+
return (await this.obj?.get_deltaObject()) || {};
|
|
29
|
+
}
|
|
30
|
+
async Save() {
|
|
31
|
+
return (await this.obj?.Save()) || false;
|
|
32
|
+
}
|
|
33
|
+
/* -------------------------------------------------------------------------- */
|
|
34
|
+
/* Default Events */
|
|
35
|
+
/* -------------------------------------------------------------------------- */
|
|
36
|
+
/**
|
|
11
37
|
* Use this when you load new Object
|
|
12
38
|
* @param p
|
|
13
39
|
* @returns
|
|
14
|
-
*/
|
|
40
|
+
*/
|
|
41
|
+
async onNew(...p) {
|
|
42
|
+
if (this.isEditMode) {
|
|
43
|
+
this.obj?.setOriginal();
|
|
44
|
+
}
|
|
45
|
+
await this.event_run("on_new");
|
|
46
|
+
await this.event_run("on_change", true);
|
|
47
|
+
return await Promise.resolve(true);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
15
50
|
* Use this when you load data to the object
|
|
16
51
|
* @param p
|
|
17
52
|
* @returns
|
|
18
|
-
*/
|
|
53
|
+
*/
|
|
54
|
+
async onLoad(...p) {
|
|
55
|
+
if (this.isEditMode) {
|
|
56
|
+
this.obj?.setOriginal();
|
|
57
|
+
}
|
|
58
|
+
await this.event_run("on_load");
|
|
59
|
+
await this.event_run("on_change", true);
|
|
60
|
+
return await Promise.resolve(true);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
19
63
|
* Use this after succesful save to Database
|
|
20
64
|
* @param p
|
|
21
65
|
* @returns
|
|
22
|
-
*/
|
|
66
|
+
*/
|
|
67
|
+
async onSave(...p) {
|
|
68
|
+
if (this.isSaved && this.obj) {
|
|
69
|
+
this.apply_changes();
|
|
70
|
+
var srObject = this.obj.getSaveResult();
|
|
71
|
+
if (srObject.insertedId) {
|
|
72
|
+
this.obj._id = srObject.insertedId;
|
|
73
|
+
}
|
|
74
|
+
else if (srObject._id) {
|
|
75
|
+
this.obj._id = srObject._id;
|
|
76
|
+
}
|
|
77
|
+
if (srObject._index_value && !Number.isNaN(srObject._index_value)) {
|
|
78
|
+
this.obj._index_value = Number(srObject._index_value);
|
|
79
|
+
}
|
|
80
|
+
//this.loadValues(srObject);
|
|
81
|
+
}
|
|
82
|
+
await this.event_run("on_save");
|
|
83
|
+
await this.event_run("on_change", true);
|
|
84
|
+
return await Promise.resolve(true);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
export default WebObjectManager;
|
package/dist/src/index.js
CHANGED
|
@@ -1 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
export * from "./structs/SimpleObject";
|
|
2
|
+
export * from "./structs/ObjectArray";
|
|
3
|
+
export * from "./structs/MapableObject";
|
|
4
|
+
export * from "./structs/MetaObject";
|
|
5
|
+
export * from "./structs/DummyObject";
|
|
6
|
+
export * from "./structs/ObjectManager";
|
|
7
|
+
export * from "./WebObjects/WebObjectManager";
|
|
8
|
+
export * from "./WebObjects/WebObject";
|
|
@@ -1 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import { SimpleObject } from "./SimpleObject";
|
|
2
|
+
export class DummyObject extends SimpleObject {
|
|
3
|
+
constructor(initObject) {
|
|
4
|
+
super(false, true);
|
|
5
|
+
this.loadValues(initObject, true);
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export default DummyObject;
|
|
@@ -1,3 +1,73 @@
|
|
|
1
|
-
|
|
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
|
+
/**
|
|
2
6
|
* This object can be mapped and converted
|
|
3
|
-
*/
|
|
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;
|
|
@@ -1 +1,35 @@
|
|
|
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
|
+
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 +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;
|