@azrico/webobject 1.5.58 → 1.5.61

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.
Files changed (33) hide show
  1. package/README.md +9 -9
  2. package/dist/index.d.ts +1 -0
  3. package/dist/index.js +1 -0
  4. package/dist/src/WebObjects/ParentWebObject.d.ts +24 -0
  5. package/dist/src/WebObjects/ParentWebObject.js +77 -0
  6. package/dist/src/WebObjects/WebObject.d.ts +153 -0
  7. package/dist/src/WebObjects/WebObject.js +654 -0
  8. package/dist/src/WebObjects/WebObjectHelper.d.ts +9 -0
  9. package/dist/src/WebObjects/WebObjectHelper.js +18 -0
  10. package/dist/src/WebObjects/WebObjectHelper.test.d.ts +1 -0
  11. package/dist/src/WebObjects/WebObjectHelper.test.js +45 -0
  12. package/dist/src/WebObjects/WebObjectManager.d.ts +68 -0
  13. package/dist/src/WebObjects/WebObjectManager.js +290 -0
  14. package/dist/src/WebObjects/WebObjectPathHelper.d.ts +36 -0
  15. package/dist/src/WebObjects/WebObjectPathHelper.js +84 -0
  16. package/dist/src/WebObjects/WebObjectPathHelper.test.d.ts +1 -0
  17. package/dist/src/WebObjects/WebObjectPathHelper.test.js +31 -0
  18. package/dist/src/index.d.ts +10 -0
  19. package/dist/src/index.js +10 -0
  20. package/dist/src/structs/DummyObject.d.ts +5 -0
  21. package/dist/src/structs/DummyObject.js +8 -0
  22. package/dist/src/structs/MapableObject.d.ts +43 -0
  23. package/dist/src/structs/MapableObject.js +77 -0
  24. package/dist/src/structs/MetaObject.d.ts +15 -0
  25. package/dist/src/structs/MetaObject.js +35 -0
  26. package/dist/src/structs/ObjectArray.d.ts +10 -0
  27. package/dist/src/structs/ObjectArray.js +43 -0
  28. package/dist/src/structs/ObjectManager.d.ts +136 -0
  29. package/dist/src/structs/ObjectManager.js +332 -0
  30. package/dist/src/structs/ObjectWithTemp.d.ts +16 -0
  31. package/dist/src/structs/ObjectWithTemp.js +35 -0
  32. package/dist/src/structs/SimpleObject.js +1138 -0
  33. package/package.json +1 -1
@@ -0,0 +1,77 @@
1
+ import { object_ensure, object_isEmpty } from "@azrico/object";
2
+ import ObjectArray from "./ObjectArray";
3
+ import { string_equals_ignorecase } from "@azrico/string";
4
+ import { uid } from "@azrico/uid";
5
+ import ObjectWithTemp from "./ObjectWithTemp";
6
+ /**
7
+ * This object can be mapped and converted
8
+ */
9
+ export class MapableObject extends ObjectWithTemp {
10
+ __uid;
11
+ __table_id;
12
+ __parent__table_id;
13
+ __row_number;
14
+ constructor() {
15
+ super();
16
+ this.__uid = uid.localuid();
17
+ this.__table_id = this.__uid;
18
+ }
19
+ getUID() {
20
+ return MapableObject.getUID(this);
21
+ }
22
+ /* -------------------------------------------------------------------------- */
23
+ static getUID(o) {
24
+ return o.__uid;
25
+ }
26
+ static mapto(maptoType, objectlist, is_readonly = true, ...p) {
27
+ if (objectlist === undefined) {
28
+ if (maptoType === undefined)
29
+ return [];
30
+ if (maptoType instanceof Object)
31
+ return [];
32
+ objectlist = maptoType;
33
+ maptoType = this;
34
+ }
35
+ if (object_isEmpty(objectlist))
36
+ return [];
37
+ if (objectlist instanceof ObjectArray)
38
+ objectlist = objectlist.getObjects();
39
+ if (!Array.isArray(objectlist)) {
40
+ objectlist = [objectlist];
41
+ }
42
+ return objectlist.map((r) => this.ensure(maptoType, r, is_readonly, ...p));
43
+ }
44
+ static ensure(maptoType, object, is_readonly, ...p) {
45
+ if (object === undefined) {
46
+ object = maptoType;
47
+ maptoType = this;
48
+ }
49
+ return object_ensure(maptoType, object, is_readonly, ...p);
50
+ }
51
+ /* -------------------------------------------------------------------------- */
52
+ static map_rowindex(objectlist) {
53
+ let index = 0;
54
+ return (objectlist?.map((r, i) => {
55
+ r.__row_number = ++index;
56
+ return r;
57
+ }) ?? []);
58
+ }
59
+ static map_tableid(objectlist) {
60
+ let index = 0;
61
+ return (objectlist?.map((r, i) => {
62
+ r.__table_id = r.__uid ?? String(++index);
63
+ return r;
64
+ }) ?? []);
65
+ }
66
+ static equals(a, b) {
67
+ console.warn("Dont use the default equals method !");
68
+ if (a == undefined || b == undefined)
69
+ return false;
70
+ if (typeof a === "object")
71
+ a = a.__uid;
72
+ if (typeof b === "object")
73
+ b = b.__uid;
74
+ return string_equals_ignorecase(a, b);
75
+ }
76
+ }
77
+ export default MapableObject;
@@ -0,0 +1,15 @@
1
+ import SimpleObject from "./SimpleObject";
2
+ export declare class MetaObject extends SimpleObject {
3
+ id?: number;
4
+ key: string;
5
+ value: any;
6
+ constructor(initObject: string, value: string);
7
+ constructor(initObject: string, value: object);
8
+ constructor(initObject: object, value: undefined);
9
+ get_saveObject(): Promise<void>;
10
+ static get_saveObject(obj: MetaObject): Promise<void>;
11
+ Prepare(): Promise<boolean>;
12
+ get isNew(): boolean;
13
+ get isDeleted(): boolean;
14
+ }
15
+ export default MetaObject;
@@ -0,0 +1,35 @@
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(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;
@@ -0,0 +1,10 @@
1
+ type wobjInput<T> = ObjectArray<any> | ObjectArray<any>[] | T | T[];
2
+ export declare class ObjectArray<T> {
3
+ objArray: T[];
4
+ constructor(initObject?: wobjInput<T>, mapto_type?: any);
5
+ addObjects(initObject?: wobjInput<T>, mapto_type?: any): boolean;
6
+ setObjects(initObject?: wobjInput<T>, mapto_type?: any): void;
7
+ getObjects(): T[];
8
+ static flattenWebObjects<T>(inputData: wobjInput<T>): T[];
9
+ }
10
+ export default ObjectArray;
@@ -0,0 +1,43 @@
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;
@@ -0,0 +1,136 @@
1
+ import { PropOf, WriteablePropOf } from "@azrico/types";
2
+ import SimpleObject, { WithManager } from "./SimpleObject";
3
+ import { saveResultType, sendChangesType } from "./SimpleObject";
4
+ import { ClassType } from "@azrico/types";
5
+ import RawObject from "./MapableObject";
6
+ /**
7
+ * This class manages the events of an Simple Object
8
+ */
9
+ export declare class ObjectManager<ObjType extends SimpleObject> extends RawObject {
10
+ __eventList: any;
11
+ __eventPrefix?: string;
12
+ __stopEvents?: boolean;
13
+ protected static readonly __object_type: () => typeof SimpleObject | ClassType<SimpleObject>;
14
+ protected __last_object_data: {
15
+ [key: string]: string;
16
+ };
17
+ protected __currentObject?: ObjType | null;
18
+ protected __options?: object;
19
+ __object_nullable: boolean;
20
+ constructor(defaultObject?: ObjType);
21
+ notifyChanged(type: string, key: PropOf<ObjType> | string, value?: any, subvalue?: string): Promise<false | any[] | undefined>;
22
+ /**
23
+ * Get the object this manager is managing
24
+ * @returns the object
25
+ */
26
+ get obj(): WithManager<ObjType> | undefined;
27
+ /**
28
+ * Get the object this manager is managing
29
+ * @returns the object
30
+ */
31
+ getObject(): WithManager<ObjType> | undefined;
32
+ /**
33
+ * Set the object this manager is managing
34
+ * @param toObj
35
+ * @returns
36
+ */
37
+ setObject(toObj: ObjType | undefined): boolean;
38
+ get d(): any;
39
+ get isChanged(): boolean;
40
+ get isDeleted(): boolean;
41
+ get isArchived(): boolean;
42
+ get isLocked(): boolean;
43
+ get canModify(): boolean;
44
+ get isNew(): boolean;
45
+ get isSaved(): boolean;
46
+ getSaveResult(): any | null;
47
+ getSaveResultType(): saveResultType | null;
48
+ setSaveResult(toObj: any, type: saveResultType): saveResultType | undefined;
49
+ apply_changes(): boolean;
50
+ get(key: PropOf<ObjType>, original?: boolean): import("@azrico/types").PropType<ObjType, any> | null;
51
+ useProperty(key: PropOf<ObjType>): Pick<this, any>;
52
+ /**
53
+ * set value
54
+ * @param key
55
+ * @param value
56
+ * @return true if changed , false otherwise
57
+ */
58
+ set(key: WriteablePropOf<ObjType>, value: any): Promise<boolean>;
59
+ /**
60
+ * set key of subObject
61
+ * @param key
62
+ * @param value
63
+ * @param subvalue
64
+ * @return true if changed , false otherwise
65
+ */
66
+ setSubValue(key: PropOf<ObjType>, objKey: string, subvalue: any): Promise<boolean>;
67
+ pushValue(key: PropOf<ObjType>, value: any): Promise<false | NonNullable<Awaited<ObjType[any]>>>;
68
+ setTemp(key: string, value: any, sendChanges?: sendChangesType): Promise<boolean>;
69
+ setObjectTemp(key: string, value: any, sendChanges?: sendChangesType): Promise<boolean>;
70
+ getObjectTemp(key: string): any;
71
+ getIndexOrID(): number | string;
72
+ getIndex(): number;
73
+ getID(): string;
74
+ event_run(eventName: string, ...params: any): Promise<any[] | undefined>;
75
+ event_use(name: string, runEvent: (...inputdata: any) => any, onlyOn?: any, runOnce?: boolean): any;
76
+ /**
77
+ * only useful for getter functions that dont rely on states
78
+ * @param name
79
+ * @param runEvent
80
+ * @param onlyOn
81
+ * @returns
82
+ */
83
+ event_use_getter(name: string, runEvent: (...inputdata: any) => any, onlyOn?: any): any;
84
+ event_remove(name: string, uname: string): boolean;
85
+ event_add(name: string, uname: string, runEvent: (...inputdata: any) => any, onlyOn?: any, runOnce?: boolean): Promise<void>;
86
+ events_start(): void;
87
+ events_stop(): void;
88
+ events_clear(): void;
89
+ clear_changes(): boolean;
90
+ clear_cache(): boolean;
91
+ static events_clear(obj: ObjectManager<any>): void;
92
+ /**
93
+ * Set an option to some value, if its already equal to the value it will be deleted instead
94
+ * @param key
95
+ * @param value
96
+ * @returns
97
+ */
98
+ toggleOption(key: string, value: any): Promise<void>;
99
+ getOption(key: string): any;
100
+ /**
101
+ * updates `__options` and runs the `event_run`
102
+ * @param key
103
+ * @param value
104
+ * @returns true if changed, false otherwise
105
+ */
106
+ setOption(key: string, value: any): Promise<boolean>;
107
+ /**
108
+ * use an option and detect its changes in real time. similar to React state
109
+ * @param key name of the option
110
+ * @returns value of the option
111
+ */
112
+ useOption(key: string): any;
113
+ /**
114
+ * Sets an option then does an action,
115
+ * after the action is run, updates the option again
116
+ * @param key
117
+ * @param value
118
+ * @param nextvalue
119
+ * @param action
120
+ */
121
+ holdOption(key: string, value: any, nextvalue: any, action: Function): Promise<void>;
122
+ /**
123
+ * @returns isChanged
124
+ */
125
+ useIsChanged(): any;
126
+ checkIsChanged(): Promise<void>;
127
+ addError(title?: string, message?: string, sendToRegister?: boolean | "auto"): any[] | undefined;
128
+ getErrors(): any[];
129
+ clearErrors(): boolean;
130
+ static addError(o?: ObjectManager<any>, title?: string, message?: string, sendToRegister?: boolean | "auto"): any[] | undefined;
131
+ static getErrors(o: ObjectManager<any>): any[];
132
+ static clearErrors(o: ObjectManager<any>): boolean;
133
+ getObjectType(): typeof SimpleObject;
134
+ static getObjectType(): typeof SimpleObject | ClassType<SimpleObject>;
135
+ }
136
+ export default ObjectManager;
@@ -0,0 +1,332 @@
1
+ import { EventManager } from "@azrico/event";
2
+ import SimpleObject from "./SimpleObject";
3
+ import { combine_if_not_blank } from "@azrico/string";
4
+ import { gfunc } from "@azrico/global";
5
+ import { fn_eval, object_equals_loose, } from "@azrico/object";
6
+ import RawObject from "./MapableObject";
7
+ /**
8
+ * This class manages the events of an Simple Object
9
+ */
10
+ export class ObjectManager extends RawObject {
11
+ __eventList = {};
12
+ __eventPrefix;
13
+ __stopEvents;
14
+ static __object_type;
15
+ __last_object_data = {};
16
+ __currentObject;
17
+ __options;
18
+ //can the current object be set to null safely?
19
+ __object_nullable = false;
20
+ constructor(defaultObject) {
21
+ super();
22
+ this.setObject(defaultObject);
23
+ }
24
+ async notifyChanged(type, key, value, subvalue) {
25
+ const obj = this.getObject();
26
+ if (!obj)
27
+ return false;
28
+ if (value === undefined && type != "meta")
29
+ value = obj.get(key);
30
+ const typestr = (type ? `$${type}$` : "") + String(key);
31
+ return await this.event_run("on_change", typestr, value);
32
+ }
33
+ /* -------------------------------------------------------------------------- */
34
+ /**
35
+ * Get the object this manager is managing
36
+ * @returns the object
37
+ */
38
+ get obj() {
39
+ return this.__currentObject ?? undefined;
40
+ }
41
+ /**
42
+ * Get the object this manager is managing
43
+ * @returns the object
44
+ */
45
+ getObject() {
46
+ return this.__currentObject ?? undefined;
47
+ }
48
+ /**
49
+ * Set the object this manager is managing
50
+ * @param toObj
51
+ * @returns
52
+ */
53
+ setObject(toObj) {
54
+ this.__currentObject = toObj;
55
+ if (this.obj) {
56
+ this.obj.get_managerClass = () => this;
57
+ // this.obj.set_managerClass(this);
58
+ }
59
+ if (toObj == null && !this.__object_nullable) {
60
+ console.warn("setObject was used to set null. try to use empty objects instead of null");
61
+ }
62
+ return true;
63
+ }
64
+ /* -------------------------------------------------------------------------- */
65
+ /* Child functions */
66
+ /* -------------------------------------------------------------------------- */
67
+ get d() {
68
+ return this.obj?.d || {};
69
+ }
70
+ get isChanged() {
71
+ return this.obj != null && this.obj.isChanged;
72
+ }
73
+ get isDeleted() {
74
+ return this.obj == null || this.obj.isDeleted;
75
+ }
76
+ get isArchived() {
77
+ return this.obj == null || this.obj.isArchived;
78
+ }
79
+ get isLocked() {
80
+ return this.obj == null || this.obj.isLocked;
81
+ }
82
+ get canModify() {
83
+ return !this.obj?.canModify;
84
+ }
85
+ get isNew() {
86
+ return this.obj == null || this.obj.isNew;
87
+ }
88
+ get isSaved() {
89
+ return this.obj?.isSaved || false;
90
+ }
91
+ getSaveResult() {
92
+ return this.obj?.getSaveResult() || null;
93
+ }
94
+ getSaveResultType() {
95
+ return this.obj?.getSaveResultType() || null;
96
+ }
97
+ setSaveResult(toObj, type) {
98
+ return this.obj?.setSaveResult(toObj, type);
99
+ }
100
+ apply_changes() {
101
+ return this.obj?.apply_changes() || false;
102
+ }
103
+ get(key, original = false) {
104
+ const thisobj = this.obj;
105
+ if (thisobj == null || typeof thisobj.get != "function") {
106
+ if (!this.__object_nullable)
107
+ console.error("cant use get when object is not defined. maybe you have to use New() ?");
108
+ return null;
109
+ }
110
+ return thisobj.get(key, original);
111
+ }
112
+ useProperty(key) {
113
+ return EventManager.useProperty(this, key);
114
+ }
115
+ /**
116
+ * set value
117
+ * @param key
118
+ * @param value
119
+ * @return true if changed , false otherwise
120
+ */
121
+ async set(key, value) {
122
+ const thisobj = this.obj;
123
+ if (thisobj == null || typeof thisobj.set != "function") {
124
+ if (!this.__object_nullable)
125
+ console.error("cant use set when object is not defined. maybe you have to use New() ?");
126
+ return false;
127
+ }
128
+ return (await thisobj.set(key, value)) || false;
129
+ }
130
+ /**
131
+ * set key of subObject
132
+ * @param key
133
+ * @param value
134
+ * @param subvalue
135
+ * @return true if changed , false otherwise
136
+ */
137
+ async setSubValue(key, objKey, subvalue) {
138
+ return ((await this.obj?.setSubValue(key, objKey, subvalue)) ?? false);
139
+ }
140
+ //Push value on array
141
+ async pushValue(key, value) {
142
+ return (await this.obj?.pushValue(key, value)) ?? false;
143
+ }
144
+ //set temp value of object
145
+ async setTemp(key, value, sendChanges = false) {
146
+ await this.setObjectTemp(key, value, sendChanges);
147
+ return await super.setTemp(key, value);
148
+ }
149
+ //set temp value of object
150
+ async setObjectTemp(key, value, sendChanges = false) {
151
+ return (await this.obj?.setTemp(key, value, sendChanges)) ?? false;
152
+ }
153
+ //get temp value of object
154
+ getObjectTemp(key) {
155
+ return this.obj?.getTemp(key) ?? undefined;
156
+ }
157
+ /* -------------------------------------------------------------------------- */
158
+ getIndexOrID() {
159
+ return this.obj?.getIndexOrID() || -1;
160
+ }
161
+ getIndex() {
162
+ return this.obj?.getIndex() || -1;
163
+ }
164
+ getID() {
165
+ return this.obj?.getID() || "";
166
+ }
167
+ /* -------------------------------------------------------------------------- */
168
+ /* Events */
169
+ /* -------------------------------------------------------------------------- */
170
+ async event_run(eventName, ...params) {
171
+ if (this.__stopEvents === true)
172
+ return;
173
+ return await EventManager.run(this, eventName, ...params);
174
+ }
175
+ event_use(name, runEvent, onlyOn = null, runOnce = false) {
176
+ return EventManager.use(this, name, runEvent, onlyOn, runOnce);
177
+ }
178
+ /**
179
+ * only useful for getter functions that dont rely on states
180
+ * @param name
181
+ * @param runEvent
182
+ * @param onlyOn
183
+ * @returns
184
+ */
185
+ event_use_getter(name, runEvent, onlyOn = null) {
186
+ return EventManager.use_getter(this, name, runEvent, onlyOn);
187
+ }
188
+ event_remove(name, uname) {
189
+ return EventManager.remove(this, name, uname);
190
+ }
191
+ async event_add(name, uname, runEvent, onlyOn = null, runOnce = false) {
192
+ await EventManager.add(this, name, uname, runEvent, onlyOn, runOnce);
193
+ }
194
+ events_start() {
195
+ delete this.__stopEvents;
196
+ }
197
+ events_stop() {
198
+ this.__stopEvents = true;
199
+ }
200
+ events_clear() {
201
+ ObjectManager.events_clear(this);
202
+ }
203
+ clear_changes() {
204
+ return this.obj?.clear_changes() ?? false;
205
+ }
206
+ clear_cache() {
207
+ return this.obj?.clear_cache() ?? false;
208
+ }
209
+ static events_clear(obj) {
210
+ EventManager.removeAll(obj);
211
+ }
212
+ /* -------------------------------------------------------------------------- */
213
+ /* Options */
214
+ /* -------------------------------------------------------------------------- */
215
+ /**
216
+ * Set an option to some value, if its already equal to the value it will be deleted instead
217
+ * @param key
218
+ * @param value
219
+ * @returns
220
+ */
221
+ async toggleOption(key, value) {
222
+ var oldval = this.getOption(key);
223
+ if (object_equals_loose(oldval, value)) {
224
+ await this.setOption(key, null);
225
+ }
226
+ else
227
+ await this.setOption(key, value);
228
+ }
229
+ getOption(key) {
230
+ if (this.__options == null)
231
+ return undefined;
232
+ key = key.toLowerCase();
233
+ return this.__options[key];
234
+ }
235
+ /**
236
+ * updates `__options` and runs the `event_run`
237
+ * @param key
238
+ * @param value
239
+ * @returns true if changed, false otherwise
240
+ */
241
+ async setOption(key, value) {
242
+ if (this.__options == null)
243
+ this.__options = {};
244
+ key = key.toLowerCase();
245
+ const isChanged = this.__options[key] !== value;
246
+ if (value == null) {
247
+ delete this.__options[key];
248
+ }
249
+ else {
250
+ this.__options[key] = value;
251
+ }
252
+ await this.event_run("on_option_change", key, value);
253
+ return isChanged;
254
+ }
255
+ /**
256
+ * use an option and detect its changes in real time. similar to React state
257
+ * @param key name of the option
258
+ * @returns value of the option
259
+ */
260
+ useOption(key) {
261
+ return this.event_use_getter("on_option_change", () => this.getOption(key), [key]);
262
+ }
263
+ /**
264
+ * Sets an option then does an action,
265
+ * after the action is run, updates the option again
266
+ * @param key
267
+ * @param value
268
+ * @param nextvalue
269
+ * @param action
270
+ */
271
+ async holdOption(key, value, nextvalue, action) {
272
+ try {
273
+ this.setOption(key, value);
274
+ if (typeof action === "function")
275
+ await action();
276
+ }
277
+ finally {
278
+ this.setOption(key, nextvalue);
279
+ }
280
+ }
281
+ /* ------------------------------ useIsChanged; ----------------------------- */
282
+ /**
283
+ * @returns isChanged
284
+ */
285
+ useIsChanged() {
286
+ return this.useOption("ischanged");
287
+ }
288
+ async checkIsChanged() {
289
+ await this.setOption("ischanged", this.isChanged);
290
+ }
291
+ /* -------------------------------------------------------------------------- */
292
+ /* Errors */
293
+ /* -------------------------------------------------------------------------- */
294
+ addError(title, message, sendToRegister = "auto") {
295
+ return ObjectManager.addError(this, title, message, sendToRegister);
296
+ }
297
+ getErrors() {
298
+ return ObjectManager.getErrors(this);
299
+ }
300
+ clearErrors() {
301
+ return ObjectManager.clearErrors(this);
302
+ }
303
+ static addError(o, title, message, sendToRegister = "auto") {
304
+ if (o && o.obj) {
305
+ return SimpleObject.addError(o.obj, title, message, sendToRegister);
306
+ }
307
+ const errStr = combine_if_not_blank(title, " : ", message);
308
+ console.error("[REGISTER-ERROR]", errStr);
309
+ gfunc.run_action("add_error", {
310
+ title: title,
311
+ message: message,
312
+ type: "error",
313
+ });
314
+ }
315
+ static getErrors(o) {
316
+ const obj = o.obj;
317
+ return obj != null ? SimpleObject.getErrors(o.obj) : [];
318
+ }
319
+ static clearErrors(o) {
320
+ return SimpleObject.clearErrors(o.obj);
321
+ }
322
+ /* -------------------------------------------------------------------------- */
323
+ /* get __object_type */
324
+ /* -------------------------------------------------------------------------- */
325
+ getObjectType() {
326
+ return this.constructor["getObjectType"]();
327
+ }
328
+ static getObjectType() {
329
+ return fn_eval(this.__object_type);
330
+ }
331
+ }
332
+ export default ObjectManager;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * This object supports temp values
3
+ */
4
+ export declare class ObjectWithTemp {
5
+ #private;
6
+ protected __temp: any;
7
+ constructor();
8
+ getTemp: (key: string) => any;
9
+ setTemp(key: string, value: any): Promise<boolean>;
10
+ /**
11
+ * clear and discard all temp values
12
+ * @returns
13
+ */
14
+ clear_cache(): boolean;
15
+ }
16
+ export default ObjectWithTemp;