qcobjects 2.4.107-ts → 2.4.108-ts

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 (197) hide show
  1. package/.hintrc +5 -0
  2. package/VERSION +1 -1
  3. package/build/ArrayCollection.js +136 -0
  4. package/build/BackendMicroservice.js +211 -0
  5. package/build/Base64.js +100 -0
  6. package/build/CONFIG.js +85 -0
  7. package/build/Cast.js +53 -0
  8. package/build/Class.js +284 -0
  9. package/build/ClassFactory.js +38 -0
  10. package/build/ComplexStorageCache.js +91 -0
  11. package/build/Component.js +1133 -0
  12. package/build/ComponentFactory.js +113 -0
  13. package/build/ConfigSettings.js +39 -0
  14. package/build/Controller.js +81 -0
  15. package/build/Crypt.js +87 -0
  16. package/build/DDO.js +81 -0
  17. package/build/DOMCreateElement.js +15 -0
  18. package/build/DataStringify.js +22 -0
  19. package/build/DefaultTemplateHandler.js +57 -0
  20. package/build/DocumentLayout.js +20 -0
  21. package/build/Effect.js +46 -0
  22. package/build/Export.js +11 -0
  23. package/build/Import.js +140 -0
  24. package/build/IncrementInstanceID.js +11 -0
  25. package/build/InheritClass.js +194 -0
  26. package/build/LegacyCopy.js +31 -0
  27. package/build/Logger.js +33 -0
  28. package/build/MainProcess.js +549 -0
  29. package/build/NamespaceRef.js +29 -0
  30. package/build/New.js +17 -0
  31. package/build/ObjectName.js +22 -0
  32. package/build/Package.js +67 -0
  33. package/build/PrimaryCollections.js +7 -0
  34. package/build/Processor.js +81 -0
  35. package/build/QCObjects.js +182 -4843
  36. package/build/Ready.js +49 -0
  37. package/build/RegisterClass.js +28 -0
  38. package/build/Service.js +112 -0
  39. package/build/SourceCSS.js +56 -0
  40. package/build/SourceJS.js +73 -0
  41. package/build/Tag.js +77 -0
  42. package/build/Timer.js +30 -0
  43. package/build/Toggle.js +59 -0
  44. package/build/TransitionEffect.js +65 -0
  45. package/build/VO.js +11 -0
  46. package/build/View.js +18 -0
  47. package/build/WidgetsFactory.js +537 -0
  48. package/build/assign.js +32 -0
  49. package/build/asyncLoad.js +43 -0
  50. package/build/basePath.js +32 -0
  51. package/build/captureFalseTouch.js +32 -0
  52. package/build/componentLoader.js +258 -0
  53. package/build/defaultProcessors.js +130 -0
  54. package/build/domain.js +4 -0
  55. package/build/findPackageNodePath.js +47 -0
  56. package/build/getType.js +38 -0
  57. package/build/globalSettings.js +115 -0
  58. package/build/index.d.ts +1045 -0
  59. package/build/index.js +24 -4
  60. package/build/index.mjs +1 -1
  61. package/build/introspection.js +86 -0
  62. package/build/isQCObjects.js +20 -0
  63. package/build/is_a.js +19 -0
  64. package/build/is_forbidden_name.js +15 -0
  65. package/build/is_raw_class.js +7 -0
  66. package/build/loadSDK.js +63 -0
  67. package/build/localStorage.js +19 -0
  68. package/build/make_global.js +24 -0
  69. package/build/mathFunctions.js +7 -0
  70. package/build/platform.js +28 -0
  71. package/build/range.js +17 -0
  72. package/build/routings.js +21 -0
  73. package/build/secretKey.js +5 -0
  74. package/build/serviceLoader.js +300 -0
  75. package/build/shortCode.js +14 -0
  76. package/build/subelements.js +8 -0
  77. package/build/super.js +20 -0
  78. package/build/tag_filter.js +4 -0
  79. package/build/top.js +23 -0
  80. package/build/uniqueID.js +5 -0
  81. package/build/waitUntil.js +31 -0
  82. package/build-esbuild.js +62 -0
  83. package/eslint.config.mjs +87 -0
  84. package/package.json +26 -23
  85. package/public/browser/index.js +6502 -0
  86. package/public/browser/index.js.map +7 -0
  87. package/public/cjs/index.cjs +6586 -0
  88. package/public/cjs/index.cjs.map +7 -0
  89. package/public/esm/index.mjs +6494 -0
  90. package/public/esm/index.mjs.map +7 -0
  91. package/spec/helpers/mock-sdk.helper.ts +5 -0
  92. package/spec/mocks/qcobjects-sdk.mock.ts +1 -0
  93. package/spec/support/jasmine.json +3 -3
  94. package/spec/testsClassFactorySpec.ts +40 -0
  95. package/spec/{testsConfigSpec.js → testsConfigSpec.ts} +2 -2
  96. package/spec/{testsGlobalFeaturesSpec.js → testsGlobalFeaturesSpec.ts} +10 -8
  97. package/spec/{testsSpec.js → testsSpec.ts} +11 -10
  98. package/spec/{testsTypeSpec.js → testsTypeSpec.ts} +5 -3
  99. package/src/ArrayCollection.ts +143 -0
  100. package/src/BackendMicroservice.ts +229 -0
  101. package/src/Base64.ts +92 -0
  102. package/src/CONFIG.ts +96 -0
  103. package/src/Cast.ts +46 -0
  104. package/src/Class.ts +303 -0
  105. package/src/ClassFactory.ts +34 -0
  106. package/src/ComplexStorageCache.ts +97 -0
  107. package/src/Component.ts +1222 -0
  108. package/src/ComponentFactory.ts +122 -0
  109. package/src/ConfigSettings.ts +62 -0
  110. package/src/Controller.ts +90 -0
  111. package/src/Crypt.ts +87 -0
  112. package/src/DDO.ts +93 -0
  113. package/src/DOMCreateElement.ts +12 -0
  114. package/src/DataStringify.ts +19 -0
  115. package/src/DefaultTemplateHandler.ts +55 -0
  116. package/src/DocumentLayout.ts +16 -0
  117. package/src/Effect.ts +56 -0
  118. package/src/Export.ts +8 -0
  119. package/src/Import.ts +135 -0
  120. package/src/IncrementInstanceID.ts +8 -0
  121. package/src/InheritClass.ts +210 -0
  122. package/src/LegacyCopy.ts +27 -0
  123. package/src/Logger.ts +32 -0
  124. package/src/MainProcess.ts +629 -0
  125. package/src/NamespaceRef.ts +26 -0
  126. package/src/New.ts +15 -0
  127. package/src/ObjectName.ts +16 -0
  128. package/src/Package.ts +67 -0
  129. package/src/PrimaryCollections.ts +7 -0
  130. package/src/Processor.ts +93 -0
  131. package/src/QCObjects.ts +100 -0
  132. package/src/Ready.ts +44 -0
  133. package/src/RegisterClass.ts +26 -0
  134. package/src/Service.ts +127 -0
  135. package/src/SourceCSS.ts +59 -0
  136. package/src/SourceJS.ts +76 -0
  137. package/src/Tag.ts +76 -0
  138. package/src/Timer.ts +42 -0
  139. package/src/Toggle.ts +65 -0
  140. package/src/TransitionEffect.ts +80 -0
  141. package/src/VO.ts +8 -0
  142. package/src/View.ts +17 -0
  143. package/src/WidgetsFactory.ts +543 -0
  144. package/src/assign.ts +33 -0
  145. package/src/asyncLoad.ts +42 -0
  146. package/src/basePath.ts +29 -0
  147. package/src/captureFalseTouch.ts +29 -0
  148. package/src/componentLoader.ts +252 -0
  149. package/src/defaultProcessors.ts +145 -0
  150. package/src/domain.ts +1 -0
  151. package/src/findPackageNodePath.ts +43 -0
  152. package/src/getType.ts +36 -0
  153. package/src/globalSettings.ts +118 -0
  154. package/src/index.mts +1 -1
  155. package/src/index.ts +1 -1
  156. package/src/introspection.ts +80 -0
  157. package/src/isQCObjects.ts +19 -0
  158. package/src/is_a.ts +16 -0
  159. package/src/is_forbidden_name.ts +12 -0
  160. package/src/is_raw_class.ts +3 -0
  161. package/src/loadSDK.ts +59 -0
  162. package/src/localStorage.ts +17 -0
  163. package/src/make_global.ts +19 -0
  164. package/src/mathFunctions.ts +3 -0
  165. package/src/platform.ts +30 -0
  166. package/src/range.ts +15 -0
  167. package/src/routings.ts +18 -0
  168. package/src/secretKey.ts +3 -0
  169. package/src/serviceLoader.ts +306 -0
  170. package/src/shortCode.ts +11 -0
  171. package/src/subelements.ts +4 -0
  172. package/src/super.ts +17 -0
  173. package/src/tag_filter.ts +1 -0
  174. package/src/top.ts +111 -0
  175. package/src/types/global/index.d.ts +597 -0
  176. package/src/uniqueID.ts +3 -0
  177. package/src/waitUntil.ts +26 -0
  178. package/tsconfig.d.json +35 -8
  179. package/tsconfig.jasmine.json +39 -0
  180. package/tsconfig.json +46 -12
  181. package/.eslintignore +0 -5
  182. package/.eslintrc.cjs +0 -21
  183. package/.eslintrc.json +0 -24
  184. package/browser/QCObjects.js +0 -2
  185. package/browser/QCObjects.js.map +0 -7
  186. package/browser/chunks/chunk-O2PFFZVJ.js +0 -713
  187. package/browser/chunks/chunk-O2PFFZVJ.js.map +0 -7
  188. package/browser/chunks/chunk-TBLBK5VV.js +0 -713
  189. package/browser/chunks/chunk-TBLBK5VV.js.map +0 -7
  190. package/browser/chunks/chunk-ZYLXOA35.js +0 -713
  191. package/browser/chunks/chunk-ZYLXOA35.js.map +0 -7
  192. package/browser/index.js +0 -2
  193. package/browser/index.js.map +0 -7
  194. package/spec/testsClassFactorySpec.js +0 -41
  195. package/src/QCObjects.js +0 -5247
  196. package/src/index.d.ts +0 -8
  197. package/types/index.d.ts +0 -472
package/src/CONFIG.ts ADDED
@@ -0,0 +1,96 @@
1
+ import { setBasePath } from "./basePath";
2
+ import { _CastProps } from "./Cast";
3
+ import { _Crypt, _CryptObject, _DecryptObject } from "./Crypt";
4
+ import { _DataStringify } from "./DataStringify";
5
+ import { logger } from "./Logger";
6
+ import { GlobalProcessor as Processor } from "./Processor";
7
+ import { _secretKey } from "./secretKey";
8
+ import { Package } from "./Package";
9
+ import { InheritClass } from "./InheritClass";
10
+ import { ICONFIG } from "types";
11
+ import { ConfigSettings } from "./ConfigSettings";
12
+
13
+
14
+ export class CONFIG extends InheritClass implements ICONFIG {
15
+
16
+ get _CONFIG_ENC(): string {
17
+ return ConfigSettings.instance._CONFIG_ENC;
18
+ }
19
+
20
+ get _CONFIG(): unknown {
21
+ return ConfigSettings.instance._CONFIG as unknown;
22
+ }
23
+
24
+ set(name: string, value: unknown) {
25
+ logger.debug(`CONFIG.set ${name}: ${value as string}`);
26
+ // hack to force update basePath from CONFIG
27
+ if (name === "basePath") {
28
+ setBasePath(value as string);
29
+ }
30
+ let _conf;
31
+ try {
32
+ _conf = (
33
+ function (config): any {
34
+ if (config._CONFIG_ENC === null) {
35
+ config._CONFIG_ENC = _Crypt.encrypt(_DataStringify({}), _secretKey);
36
+ }
37
+ const _protectedEnc = config._CONFIG_ENC.valueOf();
38
+ const _protectedConf = config._CONFIG?.valueOf();
39
+ return _CastProps(_protectedConf, _DecryptObject(_protectedEnc));
40
+ }
41
+ )(ConfigSettings.instance);
42
+ } catch (e) {
43
+ _conf = {};
44
+ console.error(e);
45
+ logger.debug("failed to encrypt config");
46
+ }
47
+
48
+ _conf[name] = value;
49
+ ConfigSettings.instance._CONFIG_ENC = _CryptObject(_conf);
50
+ ConfigSettings.instance.set(name, value);
51
+ }
52
+
53
+ get(name: string, _default?: unknown): any {
54
+ let _value;
55
+ try {
56
+ const _conf = (
57
+ function (config): any {
58
+ if (config._CONFIG_ENC === null) {
59
+ config._CONFIG_ENC = _Crypt.encrypt(_DataStringify({}), _secretKey);
60
+ }
61
+ const _protectedEnc = config._CONFIG_ENC.valueOf();
62
+ const _protectedConf = config._CONFIG.valueOf();
63
+ return _CastProps(_protectedConf, _DecryptObject(_protectedEnc));
64
+ }
65
+ )(ConfigSettings.instance);
66
+ if (typeof _conf[name] !== "undefined") {
67
+ _value = _conf[name];
68
+ }
69
+ } catch (e) {
70
+ console.error(e);
71
+ logger.debug("Something wrong when trying to get CONFIG values");
72
+ logger.debug("No config value for: " + name);
73
+ _value = _default;
74
+ }
75
+ return Processor.processObject(_value) || _default;
76
+ }
77
+
78
+ private static _instance:CONFIG;
79
+ static get instance ():CONFIG {
80
+ if (typeof CONFIG._instance === "undefined") {
81
+ CONFIG._instance = new CONFIG();
82
+ }
83
+ return CONFIG._instance;
84
+ }
85
+
86
+ static set(name: string, value: unknown) {
87
+ (CONFIG.instance.set(name, value));
88
+ }
89
+ static get(name: string, value?: unknown): any {
90
+ return (CONFIG.instance.get(name, value));
91
+ }
92
+
93
+ }
94
+
95
+
96
+ Package("com.qcobjects", [CONFIG]);
package/src/Cast.ts ADDED
@@ -0,0 +1,46 @@
1
+ import { logger } from "./Logger";
2
+
3
+ /**
4
+ * Casts an object to another object class type
5
+ *
6
+ * @param {Object} obj_source
7
+ * @param {Object} obj_dest
8
+ */
9
+ export const _Cast = function (obj_source: any, obj_dest: any):any {
10
+ for (const v in obj_source) {
11
+ if (typeof obj_source[v] !== "undefined") {
12
+ try {
13
+ obj_dest[v] = obj_source[v];
14
+ } catch (e:any) {
15
+ logger.debug(`An error ocurred: ${e}.`);
16
+ logger.warn(`Unable to cast ${(typeof obj_source).toString()}.${typeof v.toString()} to ${(typeof obj_dest).toString()}.${typeof v.toString()}`);
17
+ }
18
+ }
19
+ }
20
+ return obj_dest;
21
+ };
22
+
23
+ /**
24
+ * Casts an object to another object class type. Only properties
25
+ *
26
+ * @param {Object} obj_source
27
+ * @param {Object} obj_dest
28
+ */
29
+ export const _CastProps = function (obj_source: any, obj_dest: any):any {
30
+ for (const v in obj_source) {
31
+ if (typeof obj_source[v] !== "undefined" && typeof obj_source[v] !== "function") {
32
+ try {
33
+ obj_dest[v] = obj_source[v];
34
+ } catch (e:any) {
35
+ logger.debug(`An error ocurred: ${e}.`);
36
+ }
37
+ } else if (typeof obj_source[v] === "function") {
38
+ try {
39
+ obj_dest[v] = obj_source[v].bind(obj_dest);
40
+ } catch (e:any) {
41
+ logger.warn(e);
42
+ }
43
+ }
44
+ }
45
+ return obj_dest;
46
+ };
package/src/Class.ts ADDED
@@ -0,0 +1,303 @@
1
+ import { _QC_CLASSES } from "./PrimaryCollections";
2
+ import { _Cast, _CastProps } from "./Cast";
3
+ import { _DOMCreateElement } from "./DOMCreateElement";
4
+ import { __getType__ } from "./getType";
5
+ import { __instanceID, IncrementInstanceID } from "./IncrementInstanceID";
6
+ import { _methods_ } from "./introspection";
7
+ import { is_a } from "./is_a";
8
+ import { __is__forbidden_name__ } from "./is_forbidden_name";
9
+ import { _LegacyCopy } from "./LegacyCopy";
10
+ import { logger } from "./Logger";
11
+ import { isBrowser } from "./platform";
12
+ import { IQCObjectsElement, TBody, TClass } from "types";
13
+ import { InheritClass } from "./InheritClass";
14
+ import { _top } from "./top";
15
+
16
+ /**
17
+ * Creates new object class of another object
18
+ *
19
+ * @param {String} name
20
+ * @param {Object} type
21
+ * @param {Object} definition
22
+ *
23
+ * @example
24
+ * Class (name, type, definition)
25
+ * Class (name, type)
26
+ * Class (name, definition)
27
+ * Class ()
28
+ *
29
+ *
30
+ * const MyClass = Class ("MyComponent", Component, {
31
+ * name: "one_component",
32
+ * method1 : () => {console.log ("done") }
33
+ * })
34
+ * const myClassInstance = new MyClass ({name: "one_component"})
35
+ *
36
+ * const MyClass = Class ("MyService",{
37
+ * name: "myservice",
38
+ * })
39
+ *
40
+ * const myClassInstance = new MyClass ({name: "myservice"})
41
+ */
42
+
43
+
44
+
45
+ export const Class: TClass = (name?: string, _type?: unknown, _definition?: unknown): InheritClass => {
46
+ const _types_ = {};
47
+ let type: unknown, definition: unknown;
48
+
49
+ switch (true) {
50
+ case !name && !_type && !_definition:
51
+ return class { } as unknown as InheritClass;
52
+ case !!name && !_type && !_definition:
53
+ type = class { };
54
+ definition = {};
55
+ break;
56
+ case !!name && !_type && !!_definition:
57
+ type = class { };
58
+ definition = _definition;
59
+ break;
60
+ case !!name && !!_type && !!_definition:
61
+ type = _type;
62
+ definition = _definition;
63
+ break;
64
+ default:
65
+ return class { } as unknown as InheritClass;
66
+ }
67
+ if (typeof name !== "string") {
68
+ throw new Error("Class name must be a string");
69
+ }
70
+
71
+ if (typeof type !== "function") {
72
+ throw new Error("Class type must be a function or class");
73
+ }
74
+
75
+ if (__is__forbidden_name__(name)) {
76
+ throw new Error(`${name} is not an allowed word in the name of a class`);
77
+ }
78
+
79
+ if (typeof (type as any).__definition === "object"
80
+ && (type as any).__definition
81
+ && Object.keys((type as any).__definition).length !== 0) {
82
+ (definition as any).__definition = Object.assign(_LegacyCopy((type as any).__definition,["name"]), type);
83
+ }
84
+
85
+ (_types_ as any)[type.name] = type;
86
+
87
+ if (typeof definition === "undefined" || definition === null) {
88
+ definition = {};
89
+ } else {
90
+ definition = { ...definition };
91
+ }
92
+
93
+ /* hack to prevent duplicate __instanceID */
94
+ if (typeof (definition as any).__instanceID !== "undefined") {
95
+ delete (definition as any).__instanceID;
96
+ }
97
+
98
+ _QC_CLASSES[name] = class extends (_types_ as any)[type.name] {
99
+ __instanceID!: number;
100
+ __namespace?: string | undefined;
101
+ __definition: any = {
102
+ ...(definition as any)
103
+ };
104
+ childs: any;
105
+ private _body: TBody;
106
+ public get body(): TBody {
107
+ return this._body;
108
+ }
109
+ public set body(value: TBody) {
110
+ this._body = value;
111
+ }
112
+
113
+ static get __classType(): any {
114
+ return (Object.getPrototypeOf(this.constructor) as Function).name;
115
+ }
116
+
117
+ get __classType(): string {
118
+ return this.constructor.name;
119
+ }
120
+
121
+ static hierarchy(__class__: any): any[] {
122
+ const __classType = function (o_c: any): any {
123
+ return (Object.hasOwn(o_c, "__classType")) ? (o_c.__classType) : (__getType__.call(__class__, o_c));
124
+ };
125
+ const __hierarchy__proto__ = (c: any): any[] => {
126
+ return (typeof c !== "undefined" && typeof c.__proto__ !== "undefined" && c.__proto__ !== null) ? (((__classType(c) !== "") ? ([__classType(c)]) : ([])).concat(__hierarchy__proto__(c.__proto__))) : ([]);
127
+ };
128
+
129
+ if (typeof __class__ === "undefined" || __class__ === null) {
130
+ __class__ = this;
131
+ }
132
+ let __hierarchy = [];
133
+ __hierarchy.push(__classType(__class__));
134
+ __hierarchy = __hierarchy.concat(__hierarchy__proto__(__class__.__proto__));
135
+ return __hierarchy;
136
+ }
137
+
138
+ static getParentClass(): any {
139
+ return Object.getPrototypeOf(this.prototype.constructor);
140
+ }
141
+
142
+ constructor(_o_?: any) {
143
+ super(_o_ || {});
144
+
145
+ const self = this;
146
+ IncrementInstanceID();
147
+ if (!(self as any).__instanceID) {
148
+ Object.defineProperty(self, "__instanceID", {
149
+ value: __instanceID,
150
+ writable: false
151
+ });
152
+ }
153
+
154
+ if (typeof self.__definition !== "undefined") {
155
+ Object.keys(self.__definition).filter(function (k) {
156
+ return isNaN(k as any) && !["name", "__instanceID", "__classType", "__definition"].includes(k);
157
+ }).forEach(function (key) {
158
+ if (typeof self.__definition[key] === "function") {
159
+ self[key] = self.__definition[key].bind(self);
160
+ } else {
161
+ self[key] = self.__definition[key];
162
+ }
163
+ });
164
+ }
165
+ _methods_(_QC_CLASSES[self.__classType]).map(function <T>(m: unknown): T {
166
+ self[(m as Function).name] = (m as Function).bind(self);
167
+ return m as T;
168
+ });
169
+ _methods_(self.__definition).map(function (m): any {
170
+ self[(m as Function).name] = (m as Function).bind(self);
171
+ return m;
172
+ });
173
+
174
+ if (self.body) {
175
+ if (typeof self.__definition === "undefined" || (!Object.hasOwn(self.__definition, "body")) || typeof self.__definition.body === "undefined") {
176
+ try {
177
+ if (isBrowser) {
178
+ self.body = _DOMCreateElement(self.__definition.__classType);
179
+ } else {
180
+ self.body = {};
181
+ }
182
+ } catch (e: any) {
183
+ logger.debug(`An error ocurred: ${e}.`);
184
+ self.body = {};
185
+ }
186
+ } else if (Object.hasOwn(self.__definition, "body")) {
187
+ self.body = self.__definition.body;
188
+ }
189
+ }
190
+
191
+
192
+ try {
193
+ if (typeof self.__new__ === "function") {
194
+ self.__new__.call(self, _o_);
195
+ } else if (typeof super.__new__ === "function") {
196
+ self.__new__ = super.__new__.bind(self);
197
+ self.__new__.call(self, _o_);
198
+ }
199
+ if (typeof self === "object" && Object.hasOwn(self, "_new_") && typeof (self._new_ as any).isCalled === "undefined") {
200
+ try {
201
+ self._new_(_o_);
202
+ (self._new_ as any).isCalled = true;
203
+ } catch (e: any) {
204
+ logger.warn(`${self.__classType}._new_() failed with error: ${e}`);
205
+ }
206
+ }
207
+ } catch (e: any) {
208
+ logger.warn(e);
209
+ }
210
+ }
211
+
212
+ __new__(_o_: any) {
213
+ _CastProps(_o_, this);
214
+ }
215
+
216
+ // eslint-disable-next-line no-unused-vars
217
+ _new_(_o_?: any) { }
218
+
219
+ getClass(): any {
220
+ return Object.getPrototypeOf(this.constructor);
221
+ }
222
+
223
+ css(_css: any): any {
224
+ if (typeof this.body !== "undefined" && typeof this?.body !== "string" && typeof (this?.body as HTMLElement)?.style !== "undefined") {
225
+ logger.debug("body style");
226
+ if (this.body) {
227
+ (this.body as any).style = _Cast(_css, (this?.body as HTMLElement)?.style);
228
+ }
229
+ }
230
+ return (typeof this.body !== "string") ? (this?.body as HTMLElement)?.style : {};
231
+ }
232
+
233
+ hierarchy(): any {
234
+ const __instance__ = this;
235
+ return this.getClass().hierarchy(__instance__);
236
+ }
237
+
238
+
239
+ append(_child?: any) {
240
+ const child: any = _child || this.body;
241
+ logger.debug("append: start");
242
+ if (is_a(child, "Component")) {
243
+ logger.debug("append: child is a Component");
244
+ logger.debug(`appending the body of ${child.name}`);
245
+ }
246
+ if (typeof this.body !== "undefined") {
247
+ logger.debug("append element");
248
+ if (arguments.length > 0) {
249
+ logger.debug("append to element");
250
+ if (typeof this.body !== "string") {
251
+ if (typeof (this.body as IQCObjectsElement)?.append !== "undefined") {
252
+ (this?.body as IQCObjectsElement)?.append(child);
253
+ } else {
254
+ throw Error("body.append is undefined. That means the body is not well formed.");
255
+ }
256
+ } else {
257
+ this.append(child);
258
+ }
259
+ if (typeof this.childs === "undefined") {
260
+ this.childs = [];
261
+ }
262
+ this.childs.push(child);
263
+ } else {
264
+ if (isBrowser) {
265
+ logger.debug("append to body");
266
+ document.body.append(child);
267
+ }
268
+ }
269
+ }
270
+ }
271
+
272
+ attachIn(tag: any) {
273
+ if (isBrowser) {
274
+ const tags = (document as any).subelements(tag);
275
+ for (let i = 0, j = tags.length; i < j; i++) {
276
+ tags[i].append(this as any);
277
+ }
278
+ } else {
279
+ throw new Error("attachIn not yet implemented for non browser platforms");
280
+ }
281
+ }
282
+
283
+ };
284
+
285
+ // remove the keys from definition that exist in the prototype
286
+
287
+ _QC_CLASSES[name] = _CastProps(definition, _QC_CLASSES[name]);
288
+ _QC_CLASSES[name].__definition = definition;
289
+ _QC_CLASSES[name].__definition.__classType = name;
290
+ _QC_CLASSES[name].__definition.__new__ = function __new__(_o_: any) {
291
+ _CastProps(_o_, this);
292
+ };
293
+
294
+ (_top as any)[name] = _QC_CLASSES[name];
295
+
296
+ return _QC_CLASSES[name] as InheritClass;
297
+ };
298
+ if (typeof Class.prototype !== "undefined") {
299
+ Class.prototype.toString = function () {
300
+ return "Class(name, type, definition) { [QCObjects native code] }";
301
+ };
302
+ }
303
+
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Returns the QCObjects Class Factory of a given ClassName
3
+ *
4
+ * @param {String} name
5
+ */
6
+
7
+ import { __is_raw_class__ } from "./is_raw_class";
8
+ import { _QC_CLASSES, _QC_PACKAGES } from "./PrimaryCollections";
9
+ import { TClassFactory } from "types";
10
+
11
+ export const ClassFactory:TClassFactory = (className:string):any => {
12
+ let _classFactory;
13
+ if (typeof className === "undefined" || className === null) {
14
+ throw Error ("You need to pass a parameter {className}");
15
+ }
16
+ if (className !== null && className.indexOf(".") > -1) {
17
+ const packageName = className.split(".").slice(0, className.split(".").length - 1).join(".");
18
+ const _className = className.split(".").slice(-1).join("");
19
+ const _package = _QC_PACKAGES[packageName] || [];
20
+ const packageClasses = _package.filter((classFactory:any) => {
21
+ return (__is_raw_class__(classFactory));
22
+ }).reverse();
23
+ if (packageClasses.length > 0) {
24
+ _classFactory = packageClasses[0];
25
+ } else {
26
+ throw Error(`Class ${_className} not found. Found classes: ${JSON.stringify(packageClasses)} in package ${packageName}`);
27
+ }
28
+ } else if (className !== null && Object.hasOwn(_QC_CLASSES, className)) {
29
+ _classFactory = _QC_CLASSES[className];
30
+ } else {
31
+ throw Error(`Unable to determine class ${className}. Unable to retrieve the class factory.`);
32
+ }
33
+ return _classFactory;
34
+ };
@@ -0,0 +1,97 @@
1
+ import { Base64 } from "./Base64";
2
+ import { _DataStringify } from "./DataStringify";
3
+ import { logger } from "./Logger";
4
+
5
+ export class ComplexStorageCache {
6
+
7
+ constructor(params: { index: any; load: any; alternate: any; }) {
8
+ let load, alternate;
9
+ const object = params.index;
10
+ if (typeof object !== "undefined") {
11
+ load = params.load;
12
+ alternate = params.alternate;
13
+ const cachedObjectID = this.getID(object);
14
+ const cachedResponse = localStorage.getItem(cachedObjectID as string);
15
+ if (this.isEmpty(cachedResponse)) {
16
+ const cachedNewResponse = load.call(null, {
17
+ cachedObjectID,
18
+ cachedResponse,
19
+ "cache": this
20
+ });
21
+ this.save(object, cachedNewResponse);
22
+ logger.debug("RESPONSE OF {{cachedObjectID}} CACHED".replace("{{cachedObjectID}}", cachedObjectID as string));
23
+ } else {
24
+ alternate.call(null, {
25
+ cachedObjectID,
26
+ cachedResponse,
27
+ "cache": this
28
+ });
29
+ logger.debug("RESPONSE OF {{cachedObjectID}} IS ALREADY CACHED ".replace("{{cachedObjectID}}", cachedObjectID as string));
30
+ }
31
+
32
+ } else {
33
+ throw new Error("ComplexStorageCache: index is undefined");
34
+ }
35
+ return this;
36
+ }
37
+
38
+ getItem(cachedObjectID: string):any {
39
+ const retrievedObject = localStorage.getItem(cachedObjectID);
40
+ if (!this.isEmpty(retrievedObject)) {
41
+ return JSON.parse(retrievedObject as string);
42
+ } else {
43
+ return null;
44
+ }
45
+ }
46
+
47
+
48
+ setItem(cachedObjectID: string, value: any) {
49
+ localStorage.setItem(cachedObjectID, _DataStringify(value));
50
+ }
51
+
52
+ isEmpty(object: string | number | null) {
53
+ let r = false;
54
+ switch (true) {
55
+ case (typeof object === "undefined"):
56
+ case (typeof object === "string" && object === ""):
57
+ case (typeof object === "string" && object === "undefined"):
58
+ case (typeof object === "number" && object === 0):
59
+ case (object === null):
60
+ r = true;
61
+ break;
62
+ default:
63
+ r = false;
64
+ }
65
+ return r;
66
+ }
67
+
68
+
69
+ getID(object: any) {
70
+ let cachedObjectID;
71
+ if (typeof object !== "undefined") {
72
+ cachedObjectID = "cachedObject_" + Base64.encode(_DataStringify(object).replace(/\{|\}|,/g, "_"));
73
+ }
74
+ return cachedObjectID;
75
+ }
76
+
77
+ save(object: any, cachedNewResponse: any) {
78
+ const cachedObjectID = this.getID(object);
79
+ logger.debug("CACHING THE RESPONSE OF {{cachedObjectID}} ".replace("{{cachedObjectID}}", cachedObjectID as string));
80
+ this.setItem(cachedObjectID as string, cachedNewResponse);
81
+ }
82
+
83
+ getCached(object: any):any {
84
+ const cachedObjectID = this.getID(object);
85
+ return this.getItem(cachedObjectID as string);
86
+ }
87
+
88
+ clear() {
89
+ Object.keys(localStorage).filter(function (k) {
90
+ return k.startsWith("cachedObject_");
91
+ }).map(function (c):any {
92
+ localStorage.removeItem(c);
93
+ return c;
94
+ });
95
+ }
96
+
97
+ }