qcobjects 2.5.115-beta → 2.5.118-beta

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/src/ObjectName.ts CHANGED
@@ -1,16 +1,16 @@
1
- /**
2
- * Returns the object or function name
3
- *
4
- * @param Object or function
5
- */
6
- export const ObjectName = function (o:any) {
7
- let ret = "";
8
- if (typeof o === "function" && Object.hasOwn(o, "name") && o.name !== "") {
9
- ret = o.name;
10
- } else if (typeof o !== "undefined" && typeof o.constructor === "function" && o.constructor.name !== "") {
11
- ret = o.constructor.name;
12
- } else if (typeof o !== "undefined" && typeof o.constructor === "object") {
13
- ret = o.constructor.toString().replace(/\[(.*?)\]/g, "$1").split(" ").slice(1).join("");
14
- }
15
- return ret;
16
- };
1
+ /**
2
+ * Returns the object or function name
3
+ *
4
+ * @param Object or function
5
+ */
6
+ export const ObjectName = function (o: any) {
7
+ let ret = "";
8
+ if (typeof o === "function" && Object.hasOwn(o, "name") && o.name !== "") {
9
+ ret = o.name;
10
+ } else if (typeof o !== "undefined" && typeof o.constructor === "function" && o.constructor.name !== "") {
11
+ ret = o.constructor.name;
12
+ } else if (typeof o !== "undefined" && typeof o.constructor === "object") {
13
+ ret = o.constructor.toString().replace(/\[(.*?)\]/g, "$1").split(" ").slice(1).join("");
14
+ }
15
+ return ret;
16
+ };
package/src/Package.ts CHANGED
@@ -1,7 +1,5 @@
1
- import { InheritClass } from "./InheritClass";
2
1
  import { __is_raw_class__ } from "./is_raw_class";
3
- import { _QC_PACKAGES } from "./PrimaryCollections";
4
- import { __register_class__ } from "./RegisterClass";
2
+ import {_QC_PACKAGES, set_QC_PACKAGE, __register_class__ } from "./PrimaryCollections";
5
3
 
6
4
  /**
7
5
  * Defines a package for Class classification
@@ -9,59 +7,39 @@ import { __register_class__ } from "./RegisterClass";
9
7
  * @param {Object} namespace
10
8
  * @param {Object} classes
11
9
  */
12
- export const Package = function (namespace: string, classes: any[] = []): any[] | undefined {
10
+ export const Package = (namespace: string, classes: any[] = []): any[] => {
11
+
13
12
  if (Object.hasOwn(_QC_PACKAGES, namespace) &&
14
- typeof (_QC_PACKAGES as any)[namespace] !== "undefined" &&
15
- Object.hasOwn((_QC_PACKAGES as any)[namespace], "length") &&
16
- (_QC_PACKAGES as any)[namespace].length > 0 &&
13
+ typeof _QC_PACKAGES[namespace] !== "undefined" &&
14
+ typeof _QC_PACKAGES[namespace] !== "string" &&
15
+ Object.hasOwn(_QC_PACKAGES[namespace], "length") &&
16
+ _QC_PACKAGES[namespace].length > 0 &&
17
17
  typeof classes !== "undefined" &&
18
18
  Object.hasOwn(classes, "length") &&
19
19
  classes.length > 0
20
20
  ) {
21
- classes.filter(
22
- function (_c1) {
23
- return __is_raw_class__(_c1);
24
- }
25
- ).map(<T>(_class_: any): T => {
26
- if (typeof _class_.__definition === "undefined") {
27
- _class_.__definition = {};
28
- }
29
- _class_.__definition.__namespace = namespace;
30
- _class_.__namespace = namespace;
31
- return _class_ as T;
21
+ classes.forEach((_class_: any) => {
22
+ __register_class__(_class_, namespace);
32
23
  });
33
- (_QC_PACKAGES as any)[namespace] = (_QC_PACKAGES as any)[namespace].concat(classes);
34
- } else if (typeof classes !== "undefined") {
35
- if (typeof classes === "object" && Object.hasOwn(classes, "length")) {
36
- classes.filter(
37
- function (_c1) {
38
- return __is_raw_class__(_c1);
39
- }
40
- ).map(<T>(_class_: any): T => {
41
- if (typeof _class_.__definition === "undefined") {
42
- _class_.__definition = {};
43
- }
44
- _class_.__definition.__namespace = namespace;
45
- _class_.__namespace = namespace;
46
- return _class_ as T;
47
- });
48
- } else if ((classes as any).prototype instanceof InheritClass) {
49
- if (typeof (classes as any).__definition === "undefined") {
50
- (classes as any).__definition = {};
51
- }
52
- (classes as any).__definition.__namespace = namespace;
53
- (classes as any).__namespace = namespace;
54
- }
55
- (_QC_PACKAGES as any)[namespace] = classes;
56
- }
57
- if (Object.hasOwn(_QC_PACKAGES, namespace)) {
58
- (_QC_PACKAGES as any)[namespace].map(<T>(_class_: any): T => {
24
+ set_QC_PACKAGE(namespace, _QC_PACKAGES[namespace].concat(classes));
25
+ } else if (typeof classes !== "undefined"
26
+ && typeof classes !== "undefined"
27
+ && Object.hasOwn(classes, "length")
28
+ && classes.length > 0) {
29
+ classes.forEach((_class_: any) => {
59
30
  __register_class__(_class_, namespace);
60
- return _class_ as T;
61
31
  });
32
+ set_QC_PACKAGE(namespace, classes);
33
+ } else if (__is_raw_class__(classes)) {
34
+ if (typeof (classes as any).__definition === "undefined") {
35
+ (classes as any).__definition = {};
36
+ }
37
+ (classes as any).__definition.__namespace = namespace;
38
+ (classes as any).__namespace = namespace;
39
+ __register_class__(classes, namespace);
40
+ set_QC_PACKAGE(namespace, [classes]);
41
+ } else {
42
+ throw new Error (`An error ocurred. It was not possible to add classes to ${namespace}.`);
62
43
  }
63
- return ((Object.hasOwn(_QC_PACKAGES, namespace)) ? ((_QC_PACKAGES as any)[namespace]) : (undefined)) as any[] | undefined;
44
+ return ((Object.hasOwn(_QC_PACKAGES, namespace)) ? (_QC_PACKAGES[namespace]) : []) as any[] | [];
64
45
  };
65
- Package.prototype.toString = function () {
66
- return "Package(namespace, classes) { [QCObjects native code] }";
67
- };
@@ -1,7 +1,98 @@
1
1
  import { T_QC_CLASSES, T_QC_PACKAGES } from "types";
2
+ import { __getType__ } from "./getType";
3
+ import { __make_global__ } from "./make_global";
2
4
 
3
- export var _QC_CLASSES:T_QC_CLASSES = {};
4
- export var _QC_PACKAGES:T_QC_PACKAGES = {};
5
- export var _QC_PACKAGES_IMPORTED:any[] = [];
6
- export var _QC_READY_LISTENERS:any[] = [];
5
+ export var _QC_CLASSES: T_QC_CLASSES = {};
6
+ export var _QC_PACKAGES: T_QC_PACKAGES = {};
7
+ export var _QC_PACKAGES_IMPORTED: any[] = [];
8
+ export var _QC_READY_LISTENERS: any[] = [];
9
+
10
+ export const __register_class__ = function (_class_: any, __namespace?: string): any {
11
+ const __classType = __getType__(_class_);
12
+ let name = _class_.name || __classType;
13
+ if (name.toLowerCase() === "function") {
14
+ name = __classType;
15
+ }
16
+ if (typeof _class_.__definition === "undefined") {
17
+ _class_.__definition = {};
18
+ }
19
+ _class_.__definition.__classType = __classType;
20
+ if (typeof __namespace !== "undefined") {
21
+ _class_.__definition.__namespace = __namespace;
22
+ }
23
+ _QC_CLASSES[name] = _class_;
24
+ __make_global__(_class_);
25
+ return _QC_CLASSES[name];
26
+ };
27
+
28
+ export const get_QC_CLASS = (name:string):any => {
29
+ return _QC_CLASSES[name];
30
+ };
31
+
32
+ const _get_packages_names = function <T>(_packages: any): T[] {
33
+ let _keys: any[] = [];
34
+ for (const _k of Object.keys(_packages)) {
35
+ if (
36
+ typeof _packages[_k] !== "undefined" &&
37
+ typeof _packages[_k] !== "function" &&
38
+ Object.hasOwn(_packages[_k], "length") &&
39
+ _packages[_k].length > 0
40
+ ) {
41
+ _keys.push(_k);
42
+ _keys = _keys.concat(_get_packages_names(_packages[_k]));
43
+ }
44
+ }
45
+ return _keys as T[];
46
+ };
47
+
48
+
49
+ export const getPackagesNamesList = (): any[] => {
50
+ return _get_packages_names(_QC_PACKAGES);
51
+ };
52
+
53
+ export const getPackagesList = (): any[] => {
54
+ return [...getPackagesNamesList()].map(<T>(packagename: string): T => {
55
+ const _classesList: any[] = _QC_PACKAGES[packagename] as any[];
56
+ let _ret_: any = undefined;
57
+ if (_classesList) {
58
+ _ret_ = {
59
+ packageName: packagename,
60
+ classesList: _classesList.filter(function (): boolean {
61
+ return true;
62
+ })
63
+ };
64
+ }
65
+ return _ret_ as T;
66
+ }).filter(function (_p: any): boolean {
67
+ return typeof _p !== "undefined";
68
+ });
69
+ };
70
+
71
+ export const getClassesList = (): any[] => {
72
+ let _classesList: any[] = [];
73
+ [...getPackagesList()].forEach(function <T>(_package_element: any): T {
74
+ _classesList = _classesList.concat(_package_element.classesList.map(
75
+ (_class_element: any) => {
76
+ return {
77
+ packageName: _package_element.packageName,
78
+ className: `${_package_element.packageName}.${__getType__(_class_element)}`,
79
+ classFactory: _class_element
80
+ };
81
+ }
82
+ ));
83
+ return _package_element as T;
84
+ });
85
+
86
+ return _classesList;
87
+ };
88
+
89
+ export const getClassesNamesList = (): any[] => {
90
+ return [...getClassesList()].map(<T>(_class_element: any): T => {
91
+ return _class_element.className as T;
92
+ });
93
+ };
94
+
95
+ export const set_QC_PACKAGE = (packageName: string, _qc_packages: any[]) => {
96
+ _QC_PACKAGES[packageName] = _qc_packages;
97
+ };
7
98
 
package/src/QCObjects.ts CHANGED
@@ -33,6 +33,8 @@
33
33
 
34
34
  export * as AssignPolyfill from "./assign";
35
35
  export * as __top__ from "./top";
36
+ export * as QCObjects from "./MainProcess";
37
+
36
38
  export {_top, resetTop} from "./top";
37
39
  export { _QC_CLASSES, _QC_PACKAGES, _QC_PACKAGES_IMPORTED, _QC_READY_LISTENERS } from "./PrimaryCollections";
38
40
  export { _DataStringify } from "./DataStringify";
@@ -99,4 +101,3 @@ export { __to_number } from "./mathFunctions";
99
101
  export {_top as global} from "./top";
100
102
  export {__make_global__} from "./make_global";
101
103
  export {get, set} from "./top";
102
- export * as QCObjects from "./MainProcess";
@@ -1,24 +1,7 @@
1
- import { __getType__ } from "./getType";
2
1
  import { __make_global__ } from "./make_global";
3
- import { _QC_CLASSES } from "./PrimaryCollections";
2
+ import { __register_class__ } from "./PrimaryCollections";
4
3
 
5
4
 
6
- export const __register_class__ = function (_class_:any, __namespace?:string):any {
7
- let name = _class_.name || __getType__(_class_);
8
- if (name.toLowerCase() === "function" && typeof _class_.__classType !== "undefined"){
9
- name = _class_.__classType;
10
- }
11
- if (typeof _class_.__definition === "undefined") {
12
- _class_.__definition = {};
13
- }
14
- _class_.__definition.__classType = name;
15
- if (typeof __namespace !== "undefined") {
16
- _class_.__definition.__namespace = __namespace;
17
- }
18
- (_QC_CLASSES as any)[name] = _class_;
19
- __make_global__((_QC_CLASSES as any)[name]);
20
- return (_QC_CLASSES as any)[name];
21
- };
22
5
 
23
6
  export const RegisterClass = function (_class_:any, __namespace?:string):any {
24
7
  return __register_class__(_class_, __namespace);
@@ -1,17 +1,14 @@
1
- import { _import_ } from "./_import_";
2
1
  import { CONFIG } from "./CONFIG";
3
2
  import { Export } from "./Export";
4
3
  import { logger } from "./Logger";
5
4
  import { isBrowser } from "./platform";
6
5
 
7
6
  export const findPackageNodePath = function (packagename:string):string|null {
8
-
9
7
  let sdkPath = null;
10
8
  if (!isBrowser) {
11
- let fs:any;
12
- (async () => {
13
- fs = await _import_("node:fs");
14
- })().then(() => {
9
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
10
+ const fs = require("fs");
11
+ try {
15
12
  let sdkPaths = [
16
13
  `${CONFIG.get("projectPath")}${CONFIG.get("relativeImportPath")}`,
17
14
  `${CONFIG.get("basePath")}${CONFIG.get("relativeImportPath")}`,
@@ -36,11 +33,11 @@ export const findPackageNodePath = function (packagename:string):string|null {
36
33
  sdkPath = "";
37
34
  logger.info(`${packagename} is not in a standard path.`);
38
35
  }
36
+ } catch (e) {
37
+ // do nothing
38
+ console.log(e);
39
+ }
39
40
 
40
- })
41
- .catch((e:any) => {
42
- throw new Error(e);
43
- });
44
41
  }
45
42
  return sdkPath;
46
43
  };
package/src/getType.ts CHANGED
@@ -1,36 +1,35 @@
1
1
  import { __is_raw_class__ } from "./is_raw_class";
2
2
  import { ObjectName } from "./ObjectName";
3
3
 
4
- /**
5
- * Determine the type of the Object for any QCObjects Object
6
- *
7
- * @param {Object} object
8
- */
9
- export const __getType__ = function __getType__(o_c:any):any {
10
- let _ret_ = "";
11
- switch (true) {
12
- case __is_raw_class__(o_c) && !!o_c.name:
13
- _ret_ = o_c.name;
14
- break;
15
- case typeof o_c === "object" &&
16
- (!!o_c.constructor &&
17
- !!o_c.constructor.name)
18
- && o_c.constructor.name !== "":
19
- _ret_ = o_c.constructor.name;
20
- break;
21
- case (!!o_c && !!o_c.__classType) && o_c.__classType !== "":
22
- _ret_ = o_c.__classType;
23
- break;
24
- case (!!o_c && !!o_c.__definition) && (!!o_c.__definition.__classType) && o_c.__definition.__classType !== "":
25
- _ret_ = o_c.__definition.__classType;
26
- break;
27
- case typeof o_c === "function" && !!o_c.name:
28
- _ret_ = o_c.name;
29
- break;
30
- default:
31
- _ret_ = ObjectName(o_c);
32
- break;
33
- }
34
- return _ret_;
35
- };
36
-
4
+ /**
5
+ * Determine the type of the Object for any QCObjects Object
6
+ *
7
+ * @param {Object} object
8
+ */
9
+ export const __getType__ = function __getType__(o_c: any): any {
10
+ let _ret_ = "";
11
+ switch (true) {
12
+ case typeof o_c === "object" &&
13
+ (!!o_c.constructor &&
14
+ !!o_c.constructor.name)
15
+ && o_c.constructor.name !== "":
16
+ _ret_ = o_c.constructor.name;
17
+ break;
18
+ case typeof o_c === "function" && !!o_c.name:
19
+ _ret_ = o_c.name;
20
+ break;
21
+ case __is_raw_class__(o_c) && !!o_c.name:
22
+ _ret_ = o_c.name;
23
+ break;
24
+ case (!!o_c && !!o_c.__classType) && o_c.__classType !== "":
25
+ _ret_ = o_c.__classType;
26
+ break;
27
+ case (!!o_c && !!o_c.__definition) && (!!o_c.__definition.__classType) && o_c.__definition.__classType !== "":
28
+ _ret_ = o_c.__definition.__classType;
29
+ break;
30
+ default:
31
+ _ret_ = ObjectName(o_c);
32
+ break;
33
+ }
34
+ return _ret_;
35
+ };
package/src/top.ts CHANGED
@@ -2,6 +2,12 @@ import { IComplexStorageCache, IComponent, IConfigService, IQCObjectsElement } f
2
2
  import { buildComponents } from "./ComponentFactory";
3
3
  import { _CastProps } from "./Cast";
4
4
  import { GlobalSettings } from "./globalSettings";
5
+ import { Class } from "./Class";
6
+ import { ClassFactory } from "./ClassFactory";
7
+ import { Export } from "./Export";
8
+ import { isBrowser } from "./platform";
9
+ import { _QC_CLASSES, getPackagesNamesList, getPackagesList, getClassesList, getClassesNamesList } from "./PrimaryCollections";
10
+ import { logger } from "./Logger";
5
11
 
6
12
  type QCObjects = {
7
13
  lastCache?:IComplexStorageCache,
@@ -124,3 +130,79 @@ export const get = (name:string, _defaultValue?:any):any => {
124
130
  };
125
131
 
126
132
  resetTop();
133
+
134
+ const _define_props = function (_top: any) {
135
+ if (!Object.hasOwn(_top, "PackagesList")) {
136
+ Object.defineProperty(_top, "PackagesList", {
137
+ // eslint-disable-next-line no-unused-vars
138
+ set:(value) => {
139
+ logger.debug("PackagesList is readonly");
140
+
141
+ },
142
+ get:():any => {
143
+ return getPackagesList();
144
+ }
145
+ });
146
+
147
+ }
148
+
149
+
150
+ if (!Object.hasOwn(_top, "PackagesNameList")) {
151
+ Object.defineProperty(_top, "PackagesNameList", {
152
+ // eslint-disable-next-line no-unused-vars
153
+ set:(val) => {
154
+ logger.debug("PackagesNameList is readonly");
155
+
156
+ },
157
+ get:():any =>{
158
+ return getPackagesNamesList();
159
+ }
160
+ });
161
+
162
+ }
163
+
164
+ if (!Object.hasOwn(_top, "ClassesList")) {
165
+ Object.defineProperty(_top, "ClassesList", {
166
+ // eslint-disable-next-line no-unused-vars
167
+ set:(value) => {
168
+ logger.debug("ClassesList is readonly");
169
+
170
+ },
171
+ get:(): any => {
172
+ return getClassesList();
173
+ }
174
+ });
175
+ }
176
+
177
+ if (!Object.hasOwn(_top, "ClassesNameList")) {
178
+ Object.defineProperty(_top, "ClassesNameList", {
179
+ // eslint-disable-next-line no-unused-vars
180
+ set(value):any {
181
+ logger.debug("ClassesNameList is readonly");
182
+
183
+ },
184
+ get:(): any => {
185
+ return getClassesNamesList();
186
+ }
187
+ });
188
+
189
+ }
190
+
191
+
192
+ };
193
+
194
+
195
+ if (isBrowser) {
196
+ // use of GLOBAL word is deprecated in node.js
197
+ // this is only for compatibility purpose with old versions of QCObjects in browsers
198
+ Class("GLOBAL", (_QC_CLASSES as any).global); // case insensitive for compatibility con old versions;
199
+ Export(ClassFactory("GLOBAL"));
200
+ }
201
+
202
+ if (isBrowser && typeof window !== "undefined") {
203
+ set("global", window);
204
+ } else if (isBrowser && typeof globalThis !== "undefined") {
205
+ set("global", globalThis);
206
+ }
207
+
208
+ _define_props(_top);