qcobjects 2.4.105-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.
- package/.hintrc +5 -0
- package/VERSION +1 -1
- package/build/ArrayCollection.js +136 -0
- package/build/BackendMicroservice.js +211 -0
- package/build/Base64.js +100 -0
- package/build/CONFIG.js +85 -0
- package/build/Cast.js +53 -0
- package/build/Class.js +284 -0
- package/build/ClassFactory.js +38 -0
- package/build/ComplexStorageCache.js +91 -0
- package/build/Component.js +1133 -0
- package/build/ComponentFactory.js +113 -0
- package/build/ConfigSettings.js +39 -0
- package/build/Controller.js +81 -0
- package/build/Crypt.js +87 -0
- package/build/DDO.js +81 -0
- package/build/DOMCreateElement.js +15 -0
- package/build/DataStringify.js +22 -0
- package/build/DefaultTemplateHandler.js +57 -0
- package/build/DocumentLayout.js +20 -0
- package/build/Effect.js +46 -0
- package/build/Export.js +11 -0
- package/build/Import.js +140 -0
- package/build/IncrementInstanceID.js +11 -0
- package/build/InheritClass.js +194 -0
- package/build/LegacyCopy.js +31 -0
- package/build/Logger.js +33 -0
- package/build/MainProcess.js +549 -0
- package/build/NamespaceRef.js +29 -0
- package/build/New.js +17 -0
- package/build/ObjectName.js +22 -0
- package/build/Package.js +67 -0
- package/build/PrimaryCollections.js +7 -0
- package/build/Processor.js +81 -0
- package/build/QCObjects.js +182 -4843
- package/build/Ready.js +49 -0
- package/build/RegisterClass.js +28 -0
- package/build/Service.js +112 -0
- package/build/SourceCSS.js +56 -0
- package/build/SourceJS.js +73 -0
- package/build/Tag.js +77 -0
- package/build/Timer.js +30 -0
- package/build/Toggle.js +59 -0
- package/build/TransitionEffect.js +65 -0
- package/build/VO.js +11 -0
- package/build/View.js +18 -0
- package/build/WidgetsFactory.js +537 -0
- package/build/assign.js +32 -0
- package/build/asyncLoad.js +43 -0
- package/build/basePath.js +32 -0
- package/build/captureFalseTouch.js +32 -0
- package/build/componentLoader.js +258 -0
- package/build/defaultProcessors.js +130 -0
- package/build/domain.js +4 -0
- package/build/findPackageNodePath.js +47 -0
- package/build/getType.js +38 -0
- package/build/globalSettings.js +115 -0
- package/build/index.d.ts +1045 -0
- package/build/index.js +24 -4
- package/build/index.mjs +1 -1
- package/build/introspection.js +86 -0
- package/build/isQCObjects.js +20 -0
- package/build/is_a.js +19 -0
- package/build/is_forbidden_name.js +15 -0
- package/build/is_raw_class.js +7 -0
- package/build/loadSDK.js +63 -0
- package/build/localStorage.js +19 -0
- package/build/make_global.js +24 -0
- package/build/mathFunctions.js +7 -0
- package/build/platform.js +28 -0
- package/build/range.js +17 -0
- package/build/routings.js +21 -0
- package/build/secretKey.js +5 -0
- package/build/serviceLoader.js +300 -0
- package/build/shortCode.js +14 -0
- package/build/subelements.js +8 -0
- package/build/super.js +20 -0
- package/build/tag_filter.js +4 -0
- package/build/top.js +23 -0
- package/build/uniqueID.js +5 -0
- package/build/waitUntil.js +31 -0
- package/build-esbuild.js +62 -0
- package/eslint.config.mjs +87 -0
- package/package.json +25 -22
- package/public/browser/index.js +6502 -0
- package/public/browser/index.js.map +7 -0
- package/public/cjs/index.cjs +6586 -0
- package/public/cjs/index.cjs.map +7 -0
- package/public/esm/index.mjs +6494 -0
- package/public/esm/index.mjs.map +7 -0
- package/spec/helpers/mock-sdk.helper.ts +5 -0
- package/spec/mocks/qcobjects-sdk.mock.ts +1 -0
- package/spec/support/jasmine.json +3 -3
- package/spec/testsClassFactorySpec.ts +40 -0
- package/spec/{testsConfigSpec.js → testsConfigSpec.ts} +2 -2
- package/spec/{testsGlobalFeaturesSpec.js → testsGlobalFeaturesSpec.ts} +10 -8
- package/spec/{testsSpec.js → testsSpec.ts} +11 -10
- package/spec/{testsTypeSpec.js → testsTypeSpec.ts} +5 -3
- package/src/ArrayCollection.ts +143 -0
- package/src/BackendMicroservice.ts +229 -0
- package/src/Base64.ts +92 -0
- package/src/CONFIG.ts +96 -0
- package/src/Cast.ts +46 -0
- package/src/Class.ts +303 -0
- package/src/ClassFactory.ts +34 -0
- package/src/ComplexStorageCache.ts +97 -0
- package/src/Component.ts +1222 -0
- package/src/ComponentFactory.ts +122 -0
- package/src/ConfigSettings.ts +62 -0
- package/src/Controller.ts +90 -0
- package/src/Crypt.ts +87 -0
- package/src/DDO.ts +93 -0
- package/src/DOMCreateElement.ts +12 -0
- package/src/DataStringify.ts +19 -0
- package/src/DefaultTemplateHandler.ts +55 -0
- package/src/DocumentLayout.ts +16 -0
- package/src/Effect.ts +56 -0
- package/src/Export.ts +8 -0
- package/src/Import.ts +135 -0
- package/src/IncrementInstanceID.ts +8 -0
- package/src/InheritClass.ts +210 -0
- package/src/LegacyCopy.ts +27 -0
- package/src/Logger.ts +32 -0
- package/src/MainProcess.ts +629 -0
- package/src/NamespaceRef.ts +26 -0
- package/src/New.ts +15 -0
- package/src/ObjectName.ts +16 -0
- package/src/Package.ts +67 -0
- package/src/PrimaryCollections.ts +7 -0
- package/src/Processor.ts +93 -0
- package/src/QCObjects.ts +100 -0
- package/src/Ready.ts +44 -0
- package/src/RegisterClass.ts +26 -0
- package/src/Service.ts +127 -0
- package/src/SourceCSS.ts +59 -0
- package/src/SourceJS.ts +76 -0
- package/src/Tag.ts +76 -0
- package/src/Timer.ts +42 -0
- package/src/Toggle.ts +65 -0
- package/src/TransitionEffect.ts +80 -0
- package/src/VO.ts +8 -0
- package/src/View.ts +17 -0
- package/src/WidgetsFactory.ts +543 -0
- package/src/assign.ts +33 -0
- package/src/asyncLoad.ts +42 -0
- package/src/basePath.ts +29 -0
- package/src/captureFalseTouch.ts +29 -0
- package/src/componentLoader.ts +252 -0
- package/src/defaultProcessors.ts +145 -0
- package/src/domain.ts +1 -0
- package/src/findPackageNodePath.ts +43 -0
- package/src/getType.ts +36 -0
- package/src/globalSettings.ts +118 -0
- package/src/index.mts +1 -1
- package/src/index.ts +1 -1
- package/src/introspection.ts +80 -0
- package/src/isQCObjects.ts +19 -0
- package/src/is_a.ts +16 -0
- package/src/is_forbidden_name.ts +12 -0
- package/src/is_raw_class.ts +3 -0
- package/src/loadSDK.ts +59 -0
- package/src/localStorage.ts +17 -0
- package/src/make_global.ts +19 -0
- package/src/mathFunctions.ts +3 -0
- package/src/platform.ts +30 -0
- package/src/range.ts +15 -0
- package/src/routings.ts +18 -0
- package/src/secretKey.ts +3 -0
- package/src/serviceLoader.ts +306 -0
- package/src/shortCode.ts +11 -0
- package/src/subelements.ts +4 -0
- package/src/super.ts +17 -0
- package/src/tag_filter.ts +1 -0
- package/src/top.ts +111 -0
- package/src/types/global/index.d.ts +597 -0
- package/src/uniqueID.ts +3 -0
- package/src/waitUntil.ts +26 -0
- package/tsconfig.d.json +35 -8
- package/tsconfig.jasmine.json +39 -0
- package/tsconfig.json +46 -12
- package/.eslintignore +0 -5
- package/.eslintrc.cjs +0 -21
- package/.eslintrc.json +0 -24
- package/browser/QCObjects.js +0 -2
- package/browser/QCObjects.js.map +0 -7
- package/browser/chunks/chunk-O2PFFZVJ.js +0 -713
- package/browser/chunks/chunk-O2PFFZVJ.js.map +0 -7
- package/browser/chunks/chunk-TBLBK5VV.js +0 -713
- package/browser/chunks/chunk-TBLBK5VV.js.map +0 -7
- package/browser/chunks/chunk-ZYLXOA35.js +0 -713
- package/browser/chunks/chunk-ZYLXOA35.js.map +0 -7
- package/browser/index.js +0 -2
- package/browser/index.js.map +0 -7
- package/spec/testsClassFactorySpec.js +0 -41
- package/src/QCObjects.js +0 -5247
- package/src/index.d.ts +0 -8
- package/types/index.d.ts +0 -472
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
export const _protected_code_ = function (_:any) {
|
|
2
|
+
const __oldtoString = (typeof _.prototype !== "undefined") ? (_.prototype.toString) : (function () {
|
|
3
|
+
return "";
|
|
4
|
+
});
|
|
5
|
+
if (typeof _.prototype !== "undefined") {
|
|
6
|
+
_.prototype.toString = function ():string {
|
|
7
|
+
const _protected_symbols = [
|
|
8
|
+
"__qcobjects__",
|
|
9
|
+
"__qcobjects_sdk__",
|
|
10
|
+
"__loaded__",
|
|
11
|
+
"ComplexStorageCache",
|
|
12
|
+
"css",
|
|
13
|
+
"append",
|
|
14
|
+
"attachIn",
|
|
15
|
+
"debug",
|
|
16
|
+
"info",
|
|
17
|
+
"warn",
|
|
18
|
+
"QC_Append",
|
|
19
|
+
"set",
|
|
20
|
+
"get",
|
|
21
|
+
"done",
|
|
22
|
+
"componentDone",
|
|
23
|
+
"_new_",
|
|
24
|
+
"__new__",
|
|
25
|
+
"Class",
|
|
26
|
+
"ClassFactory",
|
|
27
|
+
"New",
|
|
28
|
+
"Export",
|
|
29
|
+
"Package",
|
|
30
|
+
"Import",
|
|
31
|
+
"subelements",
|
|
32
|
+
"componentLoader",
|
|
33
|
+
"buildComponents",
|
|
34
|
+
"Controller",
|
|
35
|
+
"View",
|
|
36
|
+
"VO",
|
|
37
|
+
"Service",
|
|
38
|
+
"serviceLoader",
|
|
39
|
+
"JSONService",
|
|
40
|
+
"ConfigService",
|
|
41
|
+
"SourceJS",
|
|
42
|
+
"SourceCSS",
|
|
43
|
+
"ArrayList",
|
|
44
|
+
"ArrayCollection",
|
|
45
|
+
"Effect",
|
|
46
|
+
"Timer",
|
|
47
|
+
"sum",
|
|
48
|
+
"avg",
|
|
49
|
+
"table",
|
|
50
|
+
"max",
|
|
51
|
+
"min",
|
|
52
|
+
"range",
|
|
53
|
+
"matrix",
|
|
54
|
+
"matrix2d",
|
|
55
|
+
"matrix3d",
|
|
56
|
+
"unique",
|
|
57
|
+
"uniqueId",
|
|
58
|
+
"shortCode",
|
|
59
|
+
"NamespaceRef"
|
|
60
|
+
];
|
|
61
|
+
let _ret_;
|
|
62
|
+
if (_protected_symbols.includes(this.name)) {
|
|
63
|
+
_ret_ = this.name + "{ [QCObjects native code] }";
|
|
64
|
+
} else {
|
|
65
|
+
_ret_ = __oldtoString.call(this);
|
|
66
|
+
}
|
|
67
|
+
return _ret_ as string;
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
(_protected_code_)(Function);
|
|
72
|
+
export const _methods_ = function <T>(_:any):T[] {
|
|
73
|
+
const _m = [];
|
|
74
|
+
for (const i in _) {
|
|
75
|
+
if ((typeof _[i]).toLowerCase() === "function") {
|
|
76
|
+
_m.push(_[i]);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return _m as T[];
|
|
80
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { InheritClass } from "./InheritClass";
|
|
2
|
+
|
|
3
|
+
export const isQCObjects_Object = function (_:any):boolean {
|
|
4
|
+
return (!!((typeof _ === "object" &&
|
|
5
|
+
Object.hasOwn(_, "__classType") &&
|
|
6
|
+
(!!_.__instanceID) &&
|
|
7
|
+
Object.hasOwn(_, "__definition") &&
|
|
8
|
+
typeof _.__definition !== "undefined"
|
|
9
|
+
))) || _ instanceof InheritClass;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const isQCObjects_Class = function (_:any):boolean {
|
|
13
|
+
return (!!((typeof _ === "function" &&
|
|
14
|
+
(!_.__instanceID) &&
|
|
15
|
+
(!!_.__definition) &&
|
|
16
|
+
typeof _.__definition !== "undefined" &&
|
|
17
|
+
!!_.__definition.__classType
|
|
18
|
+
))) || _.prototype instanceof InheritClass;
|
|
19
|
+
};
|
package/src/is_a.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { __getType__ } from "./getType";
|
|
2
|
+
import { isQCObjects_Class, isQCObjects_Object } from "./isQCObjects";
|
|
3
|
+
import { ObjectName } from "./ObjectName";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Returns if a class or object is from a determinated type
|
|
7
|
+
* @param {Object} object
|
|
8
|
+
* @param {String} typeName
|
|
9
|
+
*/
|
|
10
|
+
export const is_a = function is_a(obj:any, typeName:string) {
|
|
11
|
+
return !!((typeof obj !== "undefined" && obj !== null &&
|
|
12
|
+
(((isQCObjects_Class(obj) || isQCObjects_Object(obj)) && (obj.hierarchy().includes(typeName))) ||
|
|
13
|
+
__getType__(obj) === typeName ||
|
|
14
|
+
ObjectName(obj) === typeName ||
|
|
15
|
+
typeof obj === typeName)));
|
|
16
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal use to determine the forbidden names for classes
|
|
3
|
+
* Reserved words
|
|
4
|
+
*
|
|
5
|
+
* @param {String} name
|
|
6
|
+
* @param {Object} type
|
|
7
|
+
* @param {Object} definition
|
|
8
|
+
*/
|
|
9
|
+
export const __is__forbidden_name__ = function (name:string) {
|
|
10
|
+
return (["__proto__", "prototype", "Object", "Map", "defineProperty", "indexOf", "toString", "__instanceID", "function", "Function"].indexOf(name) !== -1);
|
|
11
|
+
};
|
|
12
|
+
|
package/src/loadSDK.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { CONFIG } from "./CONFIG";
|
|
2
|
+
import { findPackageNodePath } from "./findPackageNodePath";
|
|
3
|
+
import { Import } from "./Import";
|
|
4
|
+
import { logger } from "./Logger";
|
|
5
|
+
import { _require_, isBrowser, isNodeCommonJS } from "./platform";
|
|
6
|
+
|
|
7
|
+
function loadSDK() {
|
|
8
|
+
if (CONFIG.get("useSDK")) {
|
|
9
|
+
(function () {
|
|
10
|
+
const remoteImportsPath = CONFIG.get("remoteImportsPath");
|
|
11
|
+
const external = (!CONFIG.get("useLocalSDK"));
|
|
12
|
+
CONFIG.set("remoteImportsPath", CONFIG.get("remoteSDKPath"));
|
|
13
|
+
|
|
14
|
+
let tryImportingSDK = false;
|
|
15
|
+
let sdkName = "QCObjects-SDK";
|
|
16
|
+
if (isBrowser) {
|
|
17
|
+
tryImportingSDK = true;
|
|
18
|
+
} else {
|
|
19
|
+
const sdkPath = findPackageNodePath("qcobjects-sdk");
|
|
20
|
+
if (sdkPath !== null) {
|
|
21
|
+
sdkName = "qcobjects-sdk";
|
|
22
|
+
tryImportingSDK = true;
|
|
23
|
+
} else if (sdkPath !== ""){
|
|
24
|
+
sdkName = "node_modules/qcobjects-sdk/QCObjects-SDK";
|
|
25
|
+
tryImportingSDK = true;
|
|
26
|
+
} else {
|
|
27
|
+
tryImportingSDK = false;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (tryImportingSDK) {
|
|
32
|
+
logger.info("Importing SDK... " + sdkName);
|
|
33
|
+
if (isNodeCommonJS && typeof require !== "undefined") {
|
|
34
|
+
const sdk = _require_("qcobjects-sdk");
|
|
35
|
+
if (sdk) {
|
|
36
|
+
logger.debug("QCObjects SDK was loaded OK.");
|
|
37
|
+
} else {
|
|
38
|
+
logger.debug("QCObjects SDK could not be imported.");
|
|
39
|
+
}
|
|
40
|
+
} else {
|
|
41
|
+
Import(sdkName, function () {
|
|
42
|
+
if (external) {
|
|
43
|
+
logger.debug("QCObjects-SDK.js loaded from remote location");
|
|
44
|
+
} else {
|
|
45
|
+
logger.debug("QCObjects-SDK.js loaded from local");
|
|
46
|
+
}
|
|
47
|
+
CONFIG.set("remoteImportsPath", remoteImportsPath);
|
|
48
|
+
}, external)
|
|
49
|
+
?.catch((e: any) => { throw new Error(`An error ocurred when trying to import: ${e}`); });
|
|
50
|
+
}
|
|
51
|
+
} else {
|
|
52
|
+
logger.debug("SDK has not been imported as it is not available at the moment");
|
|
53
|
+
}
|
|
54
|
+
})();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export default loadSDK;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export var localStorage:any = window.localStorage;
|
|
2
|
+
if (typeof localStorage === "undefined") {
|
|
3
|
+
|
|
4
|
+
/* Polyfill for localStorage */
|
|
5
|
+
localStorage = {
|
|
6
|
+
getItem(name:string):any {
|
|
7
|
+
return (Object.hasOwn(this, name)) ? (this[name]) : (null);
|
|
8
|
+
},
|
|
9
|
+
setItem(name:string, value:any) {
|
|
10
|
+
this[name] = value;
|
|
11
|
+
},
|
|
12
|
+
removeItem(name:string) {
|
|
13
|
+
delete this[name];
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
/* end Polyfill for localStorage */
|
|
17
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { isBrowser } from "./platform";
|
|
2
|
+
import { _top } from "./top";
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
export const __make_global__ = function (f:any) {
|
|
6
|
+
if (typeof f !== "undefined") {
|
|
7
|
+
if (isBrowser) {
|
|
8
|
+
try {
|
|
9
|
+
(_top as any)[f.name] = f;
|
|
10
|
+
window[f.name] = f;
|
|
11
|
+
} catch (e:any) { throw Error (`An error ocurred: ${e}`); }
|
|
12
|
+
} else if (typeof global !== "undefined") {
|
|
13
|
+
if (!Object.hasOwn(global, f.name)) {
|
|
14
|
+
(global as any)[f.name] = f;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
};
|
package/src/platform.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { logger } from "./Logger";
|
|
2
|
+
|
|
3
|
+
export const isDeno:boolean = (typeof window !== "undefined" && "Deno" in window);
|
|
4
|
+
export const isBrowser:boolean = (typeof window !== "undefined" && typeof window.self !== "undefined" && window === window.self) && !isDeno;
|
|
5
|
+
export const isNodeCommonJS:boolean = (typeof module !== "undefined");
|
|
6
|
+
// eslint-disable-next-line no-unused-vars
|
|
7
|
+
export const deno_require = (name:string):void => { /* not yet implemented */};
|
|
8
|
+
export const _require_ = (name:string):any => {
|
|
9
|
+
|
|
10
|
+
return (isDeno)?(deno_require(name)):(
|
|
11
|
+
( (name):any => {
|
|
12
|
+
let r;
|
|
13
|
+
try {
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
15
|
+
r = require(name);
|
|
16
|
+
} catch (e:any) {
|
|
17
|
+
logger.debug(`An error ocurred importing module. ${e}`);
|
|
18
|
+
r = {export:{}};
|
|
19
|
+
}
|
|
20
|
+
return r;
|
|
21
|
+
} ) (name)
|
|
22
|
+
);
|
|
23
|
+
};
|
|
24
|
+
declare const cordova: any;
|
|
25
|
+
|
|
26
|
+
export const is_phonegap:boolean = (
|
|
27
|
+
function () {
|
|
28
|
+
return (typeof cordova !== "undefined");
|
|
29
|
+
}
|
|
30
|
+
)();
|
package/src/range.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { _protected_code_ } from "./introspection";
|
|
2
|
+
|
|
3
|
+
export const range = function (start:number, stop = 0, step = 1) {
|
|
4
|
+
if (stop === 0 || typeof stop === "undefined") {
|
|
5
|
+
stop = start;
|
|
6
|
+
start = 0;
|
|
7
|
+
}
|
|
8
|
+
return Array.from({
|
|
9
|
+
length: (stop - start) / step + 1
|
|
10
|
+
}, function (_, i) {
|
|
11
|
+
return start + (i * step);
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
(_protected_code_)(range);
|
|
15
|
+
|
package/src/routings.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { TComponentRouting } from "types";
|
|
2
|
+
|
|
3
|
+
export const __routing_params__ = function (routing:TComponentRouting, routingPath:string):object {
|
|
4
|
+
const standardRoutingPath = routing.path.replace(/{(.*?)}/g, "(?<$1>.*)"); // allowing {param}
|
|
5
|
+
return {
|
|
6
|
+
...[...routingPath.matchAll((new RegExp(standardRoutingPath, "g")))][0].groups
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const __valid_routings__ = function (routings:TComponentRouting[], routingPath:string):TComponentRouting[] {
|
|
11
|
+
return routings.filter(function (routing) {
|
|
12
|
+
const standardRoutingPath = routing.path.replace(/{(.*?)}/g, "(?<$1>.*)");
|
|
13
|
+
return (new RegExp(standardRoutingPath, "g")).test(routingPath);
|
|
14
|
+
}).reverse();
|
|
15
|
+
};
|
|
16
|
+
export const __valid_routing_way__ = function (validRoutingWays:string[], routingWay:string) {
|
|
17
|
+
return validRoutingWays.includes(routingWay);
|
|
18
|
+
};
|
package/src/secretKey.ts
ADDED
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
import { IService, TCacheController } from "types";
|
|
2
|
+
import { asyncLoad } from "./asyncLoad";
|
|
3
|
+
import { ComplexStorageCache } from "./ComplexStorageCache";
|
|
4
|
+
import { _DataStringify } from "./DataStringify";
|
|
5
|
+
import { logger } from "./Logger";
|
|
6
|
+
import { _require_, isBrowser } from "./platform";
|
|
7
|
+
import { _top } from "./top";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Loads a simple component from a template
|
|
11
|
+
*
|
|
12
|
+
* @author: Jean Machuca <correojean@gmail.com>
|
|
13
|
+
* @param service a Service object
|
|
14
|
+
*/
|
|
15
|
+
export const serviceLoader = function (service:IService, _async = false):Promise<unknown>|undefined {
|
|
16
|
+
const _serviceLoaderInBrowser = function (service:IService):Promise<unknown> {
|
|
17
|
+
var _promise = new Promise(
|
|
18
|
+
function (resolve, reject) {
|
|
19
|
+
|
|
20
|
+
logger.debug("LOADING SERVICE DATA {{DATA}} FROM {{URL}}".replace("{{DATA}}", _DataStringify(service.data)).replace("{{URL}}", service.url));
|
|
21
|
+
const xhr = new XMLHttpRequest();
|
|
22
|
+
xhr.withCredentials = service.withCredentials;
|
|
23
|
+
const xhrasync = true; // always async because xhr sync is deprecated
|
|
24
|
+
xhr.open(service.method, service.url, xhrasync);
|
|
25
|
+
for (const header in service.headers) {
|
|
26
|
+
try {
|
|
27
|
+
if (typeof service.headers[header] !== "function") {
|
|
28
|
+
xhr.setRequestHeader(header, service.headers[header]);
|
|
29
|
+
}
|
|
30
|
+
} catch (e:any) {
|
|
31
|
+
logger.debug("Something went wrong when assign the header " + header);
|
|
32
|
+
logger.debug(`An error ocurred: ${e}`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
xhr.onload = function () {
|
|
36
|
+
if (xhr.status === 200) {
|
|
37
|
+
const response = xhr.responseText;
|
|
38
|
+
logger.debug("Data received {{DATA}}".replace("{{DATA}}", _DataStringify(response)));
|
|
39
|
+
logger.debug("CREATING SERVICE {{NAME}}".replace("{{NAME}}", service.name));
|
|
40
|
+
service.template = response;
|
|
41
|
+
if (service.cached && (typeof cache !== "undefined")) {
|
|
42
|
+
cache.save(service.name, service.template);
|
|
43
|
+
}
|
|
44
|
+
if (typeof service.done === "function") {
|
|
45
|
+
var standardResponse = {
|
|
46
|
+
"request": xhr,
|
|
47
|
+
service
|
|
48
|
+
};
|
|
49
|
+
service.done.call(service, standardResponse);
|
|
50
|
+
resolve.call(_promise, standardResponse);
|
|
51
|
+
}
|
|
52
|
+
} else {
|
|
53
|
+
if (typeof service.fail === "function") {
|
|
54
|
+
var standardResponse = {
|
|
55
|
+
"request": xhr,
|
|
56
|
+
service
|
|
57
|
+
};
|
|
58
|
+
service.fail.call(service, standardResponse);
|
|
59
|
+
reject.call(_promise, standardResponse);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const _directLoad = function () {
|
|
65
|
+
logger.debug("SENDING THE NORMAL REQUEST ");
|
|
66
|
+
try {
|
|
67
|
+
xhr.send(_DataStringify(service.data));
|
|
68
|
+
} catch (e:any) {
|
|
69
|
+
logger.debug("SOMETHING WRONG WITH REQUEST ");
|
|
70
|
+
logger.debug(`An error ocurred: ${e}`);
|
|
71
|
+
reject.call(_promise, {
|
|
72
|
+
request: xhr,
|
|
73
|
+
service
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
if (service.cached) {
|
|
79
|
+
var cache = new ComplexStorageCache({
|
|
80
|
+
index: service.data,
|
|
81
|
+
load() {
|
|
82
|
+
_directLoad.call(this);
|
|
83
|
+
},
|
|
84
|
+
alternate(cacheController:TCacheController) {
|
|
85
|
+
if (service.method === "GET") {
|
|
86
|
+
service.template = cacheController.cache.getCached(service.name);
|
|
87
|
+
if (typeof service.done === "function") {
|
|
88
|
+
const standardResponse = {
|
|
89
|
+
"request": xhr,
|
|
90
|
+
service
|
|
91
|
+
};
|
|
92
|
+
service.done.call(service, standardResponse);
|
|
93
|
+
resolve.call(_promise, standardResponse);
|
|
94
|
+
}
|
|
95
|
+
} else {
|
|
96
|
+
_directLoad();
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
(_top as any).lastCache = cache;
|
|
102
|
+
} else {
|
|
103
|
+
_directLoad();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return xhr;
|
|
107
|
+
}
|
|
108
|
+
);
|
|
109
|
+
return _promise;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const _serviceLoaderInNode = function (service:IService) {
|
|
113
|
+
var _promise = new Promise(
|
|
114
|
+
function (resolve, reject) {
|
|
115
|
+
if (typeof URL === "undefined") {
|
|
116
|
+
global.URL = (_require_("url")).URL;
|
|
117
|
+
// eslint-disable-next-line no-unused-vars
|
|
118
|
+
const URL = global.URL;
|
|
119
|
+
}
|
|
120
|
+
const serviceURL = new URL(service.url);
|
|
121
|
+
var req;
|
|
122
|
+
service.useHTTP2 = Object.hasOwn(service, "useHTTP2") && service.useHTTP2;
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
const captureEvents = function (req:any) {
|
|
126
|
+
logger.debug("LOADING SERVICE DATA (non-browser) {{DATA}} FROM {{URL}}".replace("{{DATA}}", _DataStringify(service.data)).replace("{{URL}}", service.url));
|
|
127
|
+
let dataXML:any;
|
|
128
|
+
const standardResponse = {
|
|
129
|
+
"http2Client": client,
|
|
130
|
+
"request": req,
|
|
131
|
+
service,
|
|
132
|
+
"responseHeaders": null
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
if (typeof service.data === "object" && service.data !== null) {
|
|
136
|
+
if (service.useHTTP2) {
|
|
137
|
+
try {
|
|
138
|
+
logger.debug("Sending data...");
|
|
139
|
+
const buffer = new Buffer(_DataStringify(service.data));
|
|
140
|
+
req.write(buffer);
|
|
141
|
+
} catch (e:any) {
|
|
142
|
+
logger.debug("It was not possible to send any data");
|
|
143
|
+
logger.debug(`An error ocurred: ${e}`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
dataXML = "";
|
|
149
|
+
req.on("response", (responseHeaders:any) => {
|
|
150
|
+
logger.debug("receiving response...");
|
|
151
|
+
standardResponse.responseHeaders = responseHeaders;
|
|
152
|
+
/*
|
|
153
|
+
for (const name in responseHeaders) {
|
|
154
|
+
logger.debug(`${name}: ${responseHeaders[name]}`);
|
|
155
|
+
}
|
|
156
|
+
*/
|
|
157
|
+
dataXML = "";
|
|
158
|
+
});
|
|
159
|
+
req.on("data", (chunk:any) => {
|
|
160
|
+
logger.debug("receiving data...");
|
|
161
|
+
// do something with the data
|
|
162
|
+
dataXML += "" + chunk.toString();
|
|
163
|
+
service.template = dataXML;
|
|
164
|
+
});
|
|
165
|
+
if (service.useHTTP2) {
|
|
166
|
+
req.resume();
|
|
167
|
+
}
|
|
168
|
+
req.on("end", () => {
|
|
169
|
+
logger.debug("ending call...");
|
|
170
|
+
service.template = dataXML;
|
|
171
|
+
if (Object.hasOwn(service, "useHTTP2") && service.useHTTP2) {
|
|
172
|
+
client.destroy();
|
|
173
|
+
} else {
|
|
174
|
+
req.destroy();
|
|
175
|
+
}
|
|
176
|
+
service.done.call(service, standardResponse);
|
|
177
|
+
resolve.call(_promise, standardResponse);
|
|
178
|
+
});
|
|
179
|
+
if (service.useHTTP2) {
|
|
180
|
+
req.end();
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
try {
|
|
186
|
+
let requestOptions;
|
|
187
|
+
if (service.useHTTP2) {
|
|
188
|
+
logger.debug("using http2");
|
|
189
|
+
const http2 = _require_("http2");
|
|
190
|
+
var client = (http2).connect(serviceURL.origin);
|
|
191
|
+
requestOptions = Object.assign({
|
|
192
|
+
":method": service.method,
|
|
193
|
+
":path": serviceURL.pathname
|
|
194
|
+
}, service.options);
|
|
195
|
+
requestOptions = Object.assign(requestOptions, service.headers);
|
|
196
|
+
req = client.request(requestOptions);
|
|
197
|
+
req.setEncoding("utf8");
|
|
198
|
+
captureEvents(req);
|
|
199
|
+
} else {
|
|
200
|
+
if (serviceURL.protocol === "http:") {
|
|
201
|
+
const http = _require_("http");
|
|
202
|
+
const request = (http).request;
|
|
203
|
+
requestOptions = Object.assign({
|
|
204
|
+
"url": service.url,
|
|
205
|
+
headers: service.headers
|
|
206
|
+
}, service.options);
|
|
207
|
+
req = request(service.url);
|
|
208
|
+
captureEvents(req);
|
|
209
|
+
} else if (serviceURL.protocol === "https:") {
|
|
210
|
+
const https = _require_("https");
|
|
211
|
+
requestOptions = Object.assign({
|
|
212
|
+
hostname: serviceURL.hostname,
|
|
213
|
+
port: serviceURL.port,
|
|
214
|
+
path: serviceURL.pathname,
|
|
215
|
+
method: service.method,
|
|
216
|
+
headers: service.headers
|
|
217
|
+
}, service.options);
|
|
218
|
+
const _req_ = (https).request(requestOptions, function (req:any) {
|
|
219
|
+
captureEvents(req);
|
|
220
|
+
});
|
|
221
|
+
_req_.end();
|
|
222
|
+
} else {
|
|
223
|
+
const e = "Protocol not supported: " + serviceURL.protocol;
|
|
224
|
+
logger.debug(e);
|
|
225
|
+
throw new Error(e);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
} catch (e:any) {
|
|
231
|
+
logger.debug(e);
|
|
232
|
+
service.fail.call(service, e);
|
|
233
|
+
reject.call(_promise, e);
|
|
234
|
+
|
|
235
|
+
}
|
|
236
|
+
}).catch( (e:any) => {
|
|
237
|
+
logger.debug(`Something happened when trying to call the service: ${service.name}. Error: ${e}`);
|
|
238
|
+
service.fail.call(service, e);
|
|
239
|
+
});
|
|
240
|
+
return _promise;
|
|
241
|
+
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
const _serviceLoaderMockup = function (service:IService) {
|
|
245
|
+
var _promise = new Promise(
|
|
246
|
+
function (resolve) {
|
|
247
|
+
logger.debug(`Calling mockup service ${service.name} ...`);
|
|
248
|
+
const standardResponse = {
|
|
249
|
+
"request": null,
|
|
250
|
+
service,
|
|
251
|
+
"responseHeaders": service.responseHeaders
|
|
252
|
+
};
|
|
253
|
+
if (typeof service.mockup === "function") {
|
|
254
|
+
service.mockup.call(service, standardResponse);
|
|
255
|
+
} else {
|
|
256
|
+
service.done.call(service, standardResponse);
|
|
257
|
+
}
|
|
258
|
+
resolve.call(_promise, standardResponse);
|
|
259
|
+
});
|
|
260
|
+
return _promise;
|
|
261
|
+
};
|
|
262
|
+
const _serviceLoaderLocal = function (service:IService) {
|
|
263
|
+
var _promise = new Promise(
|
|
264
|
+
function (resolve) {
|
|
265
|
+
logger.debug(`Calling local service ${service.name} ...`);
|
|
266
|
+
const standardResponse = {
|
|
267
|
+
"request": null,
|
|
268
|
+
service,
|
|
269
|
+
"responseHeaders": service.responseHeaders
|
|
270
|
+
};
|
|
271
|
+
if (typeof service.local === "function") {
|
|
272
|
+
service.local.call(service, standardResponse);
|
|
273
|
+
} else {
|
|
274
|
+
service.done.call(service, standardResponse);
|
|
275
|
+
}
|
|
276
|
+
resolve.call(_promise, standardResponse);
|
|
277
|
+
});
|
|
278
|
+
return _promise;
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
let _ret_: Promise<unknown>;
|
|
282
|
+
switch (service.kind) {
|
|
283
|
+
case "rest":
|
|
284
|
+
if (isBrowser) {
|
|
285
|
+
if (typeof _async !== "undefined" && _async) {
|
|
286
|
+
_ret_ = asyncLoad(_serviceLoaderInBrowser, [service, _async]);
|
|
287
|
+
} else {
|
|
288
|
+
_ret_ = _serviceLoaderInBrowser(service);
|
|
289
|
+
}
|
|
290
|
+
} else {
|
|
291
|
+
_ret_ = _serviceLoaderInNode(service);
|
|
292
|
+
}
|
|
293
|
+
break;
|
|
294
|
+
case "mockup":
|
|
295
|
+
_ret_ = _serviceLoaderMockup(service);
|
|
296
|
+
break;
|
|
297
|
+
case "local":
|
|
298
|
+
_ret_ = _serviceLoaderLocal(service);
|
|
299
|
+
break;
|
|
300
|
+
default:
|
|
301
|
+
logger.debug(`The value of the kind property of the service ${service.name} is not valid`);
|
|
302
|
+
_ret_ = Promise.resolve();
|
|
303
|
+
break;
|
|
304
|
+
}
|
|
305
|
+
return _ret_;
|
|
306
|
+
};
|
package/src/shortCode.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { _Crypt } from "./Crypt";
|
|
2
|
+
|
|
3
|
+
export const shortCode = function () {
|
|
4
|
+
const length = 1000;
|
|
5
|
+
const code1 = _Crypt.encrypt((Math.random() * length).toString().replace(".", ""), (new Date()).getTime().toString());
|
|
6
|
+
const code2 = _Crypt.encrypt((Math.random() * length).toString().replace(".", ""), (new Date((new Date()).getTime() - 1000 * 1000)).getTime().toString());
|
|
7
|
+
const shortCode = [...code2].map((o1:any, index:any):any => {
|
|
8
|
+
return [...code1][index] === o1 ? null : o1;
|
|
9
|
+
}).filter((c:any) => c !== null).join("");
|
|
10
|
+
return shortCode;
|
|
11
|
+
};
|
package/src/super.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ClassFactory } from "./ClassFactory";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns a method from a superior QCObjects Class
|
|
5
|
+
* It is useful for Class Inheritance in the _new_ and __new__ method constructors
|
|
6
|
+
* @example _super_('MySuperClass','MySuperMethod').call(this,params) #where this is the current instance and params are method parameters
|
|
7
|
+
*
|
|
8
|
+
* @param {String} className
|
|
9
|
+
* @param {String} classMethodName
|
|
10
|
+
* @param {Object} params
|
|
11
|
+
*/
|
|
12
|
+
export const _super_ = function <T>(className: string, classMethodName: string):T {
|
|
13
|
+
return (ClassFactory(className))[classMethodName] as T;
|
|
14
|
+
};
|
|
15
|
+
_super_.prototype.toString = function () {
|
|
16
|
+
return "_super_(className,classMethodName,params) { [QCObjects native code] }";
|
|
17
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const _tag_filter_ = "quick-component:not([loaded]),component:not([loaded])";
|