qcobjects 2.4.107-ts → 2.5.101-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 +26 -23
- 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 @@
|
|
|
1
|
+
export default {}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/* eslint-disable no-undef */
|
|
3
|
+
import {Class, ClassFactory, logger, Package, __make_global__, _top, _QC_PACKAGES, _QC_CLASSES, global} from "./../src/QCObjects";
|
|
4
|
+
|
|
5
|
+
describe("qcobjects", function () {
|
|
6
|
+
logger.debugEnabled=true;
|
|
7
|
+
logger.infoEnabled=true;
|
|
8
|
+
logger.warnEnabled=true;
|
|
9
|
+
|
|
10
|
+
it("Class Factory using Class Function, no parent class Spec", () => {
|
|
11
|
+
const MyClass = Class ("MyClass", class {}, {});
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
expect(ClassFactory("MyClass")).toBe( MyClass );
|
|
15
|
+
logger.debug("Class Factory using Class Function, no parent class Spec... OK");
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it("Global Class Factory using Class Function, no parent class Spec", () => {
|
|
19
|
+
const classFactory = Class ("MyClass", class {}, {});
|
|
20
|
+
Package("com.qcobjects", [classFactory]);
|
|
21
|
+
|
|
22
|
+
expect((global as any).MyClass).toBe( classFactory );
|
|
23
|
+
logger.debug("Global Class Factory using Class Function, no parent class Spec... OK");
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("Class Factory inside a package, no parent class Spec", () => {
|
|
27
|
+
Package("com.qcobjects.tests",[
|
|
28
|
+
Class("MyNewClass",class {},{
|
|
29
|
+
propertyName1:"propertyValue1",
|
|
30
|
+
})
|
|
31
|
+
]);
|
|
32
|
+
|
|
33
|
+
const classFactory = ClassFactory("com.qcobjects.tests.MyNewClass");
|
|
34
|
+
|
|
35
|
+
expect(ClassFactory("MyNewClass")).toBe( classFactory );
|
|
36
|
+
logger.debug("Class Factory inside a package, no parent class Spec... OK");
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
});
|
|
40
|
+
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/* eslint-disable no-undef */
|
|
3
|
+
import {CONFIG, logger} from "./../src/QCObjects";
|
|
3
4
|
|
|
4
|
-
describe("
|
|
5
|
-
require("../src/QCObjects.js");
|
|
5
|
+
describe("qcobjects", function () {
|
|
6
6
|
logger.debugEnabled=true;
|
|
7
7
|
logger.infoEnabled=true;
|
|
8
8
|
logger.warnEnabled=true;
|
|
@@ -1,28 +1,30 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { __getType__, logger, global } from "../src/QCObjects";
|
|
4
|
+
|
|
2
5
|
/* eslint-disable no-undef */
|
|
3
6
|
|
|
4
|
-
describe("
|
|
5
|
-
require("../src/QCObjects.js");
|
|
6
|
-
logger.debugEnabled=true;
|
|
7
|
-
logger.infoEnabled=true;
|
|
8
|
-
logger.warnEnabled=true;
|
|
7
|
+
describe("qcobjects", function () {
|
|
9
8
|
|
|
10
9
|
it("Existence of global.ClassesList Spec", function () {
|
|
11
|
-
|
|
10
|
+
logger.debugEnabled=true;
|
|
11
|
+
logger.infoEnabled=true;
|
|
12
|
+
logger.warnEnabled=true;
|
|
13
|
+
let classesList:any[] = global.ClassesList;
|
|
12
14
|
expect(__getType__(classesList)).toBe("Array");
|
|
13
15
|
|
|
14
16
|
logger.debug("Existence of global.ClassesList Spec... OK");
|
|
15
17
|
});
|
|
16
18
|
|
|
17
19
|
it("Existence of global.PackagesNameList Spec", function () {
|
|
18
|
-
let packagesNameList = global.PackagesNameList;
|
|
20
|
+
let packagesNameList:any[] = global.PackagesNameList;
|
|
19
21
|
expect(__getType__(packagesNameList)).toBe("Array");
|
|
20
22
|
|
|
21
23
|
logger.debug("Existence of global.PackagesNameList Spec... OK");
|
|
22
24
|
});
|
|
23
25
|
|
|
24
26
|
it("Existence of global.PackagesList Spec", function () {
|
|
25
|
-
let packagesList = global.PackagesList;
|
|
27
|
+
let packagesList:any[] = global.PackagesList;
|
|
26
28
|
expect(__getType__(packagesList)).toBe("Array");
|
|
27
29
|
|
|
28
30
|
logger.debug("Existence of global.PackagesList Spec... OK");
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { _DataStringify, Class, ClassFactory, Component, CONFIG, Effect, logger, New, global, InheritClass, __getType__ } from "../src/QCObjects";
|
|
4
|
+
|
|
5
|
+
|
|
2
6
|
/* eslint-disable no-undef */
|
|
3
7
|
|
|
4
|
-
|
|
5
|
-
|
|
8
|
+
|
|
9
|
+
describe("qcobjects", function () {
|
|
6
10
|
logger.debugEnabled=true;
|
|
7
11
|
logger.infoEnabled=true;
|
|
8
12
|
logger.warnEnabled=true;
|
|
9
13
|
|
|
10
14
|
it("Class Declaration Test Spec", function () {
|
|
11
|
-
Class("Main", Object, {
|
|
15
|
+
const Main = Class("Main", Object, {
|
|
12
16
|
_new_: () => {
|
|
13
17
|
}
|
|
14
18
|
});
|
|
@@ -18,6 +22,7 @@ describe("QCObjects Main Test", function () {
|
|
|
18
22
|
});
|
|
19
23
|
|
|
20
24
|
it("Main intance Test Spec", function () {
|
|
25
|
+
class Main extends InheritClass {}
|
|
21
26
|
let __main__ = New(Main, {});
|
|
22
27
|
expect(typeof __main__.__instanceID).toEqual("number");
|
|
23
28
|
expect(__main__.__classType).toEqual("Main");
|
|
@@ -25,7 +30,7 @@ describe("QCObjects Main Test", function () {
|
|
|
25
30
|
});
|
|
26
31
|
|
|
27
32
|
it("Existence of Component Class", function () {
|
|
28
|
-
expect(Component).toEqual(ClassFactory("Component"));
|
|
33
|
+
expect(Component as unknown as InheritClass).toEqual(ClassFactory("Component"));
|
|
29
34
|
logger.debug("Existence of Component Class... OK");
|
|
30
35
|
});
|
|
31
36
|
|
|
@@ -40,18 +45,14 @@ describe("QCObjects Main Test", function () {
|
|
|
40
45
|
});
|
|
41
46
|
|
|
42
47
|
it("Existence of CONFIG global Class", function () {
|
|
43
|
-
expect(
|
|
48
|
+
expect(__getType__(CONFIG)).toEqual("CONFIG");
|
|
44
49
|
logger.debug("Existence of CONFIG global Class... OK");
|
|
45
50
|
});
|
|
46
51
|
|
|
47
52
|
it("global as QCObjects global", function () {
|
|
48
|
-
expect(
|
|
53
|
+
expect(__getType__(global)).not.toEqual("");
|
|
49
54
|
logger.debug("global as QCObjects global... OK");
|
|
50
55
|
});
|
|
51
56
|
|
|
52
|
-
it("Existence of QCObjects SDK", function () {
|
|
53
|
-
expect(!!global._sdk_).toEqual(true);
|
|
54
|
-
logger.debug("Existence of QCObjects SDK... OK");
|
|
55
|
-
});
|
|
56
57
|
|
|
57
58
|
});
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { __getType__, Class, ClassFactory, logger } from "../src/QCObjects";
|
|
4
|
+
|
|
2
5
|
/* eslint-disable no-undef */
|
|
3
6
|
|
|
4
|
-
describe("
|
|
5
|
-
require("../src/QCObjects");
|
|
7
|
+
describe("qcobjects", function () {
|
|
6
8
|
logger.debugEnabled=true;
|
|
7
9
|
logger.infoEnabled=true;
|
|
8
10
|
logger.warnEnabled=true;
|
|
@@ -13,8 +15,8 @@ describe("Type Spec", function () {
|
|
|
13
15
|
return "method1";
|
|
14
16
|
}
|
|
15
17
|
}
|
|
16
|
-
|
|
17
18
|
Class("Main", CustomType, {});
|
|
19
|
+
const Main = ClassFactory("Main");
|
|
18
20
|
class CustomMain extends Main {}
|
|
19
21
|
var main = new CustomMain();
|
|
20
22
|
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { IArrayCollection, IArrayList } from "types";
|
|
2
|
+
import { ClassFactory } from "./ClassFactory";
|
|
3
|
+
import { logger } from "./Logger";
|
|
4
|
+
import { New } from "./New";
|
|
5
|
+
import { __to_number } from "./mathFunctions";
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
export class ArrayList extends Array implements IArrayList {
|
|
9
|
+
prototype: any;
|
|
10
|
+
|
|
11
|
+
unique ():any[] {
|
|
12
|
+
return this.filter(function (value:any, index:any, self:any) {
|
|
13
|
+
return self.indexOf(value) === index;
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
table(): void {
|
|
18
|
+
console.table(this);
|
|
19
|
+
};
|
|
20
|
+
sum(): number {
|
|
21
|
+
return this.reduce( (prev:any, current:any):number => {
|
|
22
|
+
return (__to_number(prev)) + (__to_number(current));
|
|
23
|
+
}, 0) as number;
|
|
24
|
+
}
|
|
25
|
+
avg(): number {
|
|
26
|
+
return (this.length < 1) ? (0) : (this.reduce( (prev:any, current:any):number => {
|
|
27
|
+
return (((__to_number(prev)) + (__to_number(current))) / 2);
|
|
28
|
+
})) as number;
|
|
29
|
+
}
|
|
30
|
+
min(): number {
|
|
31
|
+
return this.reduce( (prev:any, current:any):number => {
|
|
32
|
+
return (__to_number(prev) <= __to_number(current)) ? (prev) : (current);
|
|
33
|
+
}, Infinity) as number;
|
|
34
|
+
}
|
|
35
|
+
max(): number {
|
|
36
|
+
return this.reduce( (prev:any, current:any):number => {
|
|
37
|
+
return (__to_number(prev) >= __to_number(current)) ? (prev) : (current);
|
|
38
|
+
}, 0) as number;
|
|
39
|
+
}
|
|
40
|
+
sortBy(propName: string, sortAsc?: boolean): any[] {
|
|
41
|
+
const sort_function = (sortAsc) ? (
|
|
42
|
+
function (prev:any, current:any) {
|
|
43
|
+
return current[propName] < prev[propName] ? 1 : -1;
|
|
44
|
+
}
|
|
45
|
+
) : (
|
|
46
|
+
function (prev:any, current:any) {
|
|
47
|
+
return current[propName] > prev[propName] ? 1 : -1;
|
|
48
|
+
}
|
|
49
|
+
);
|
|
50
|
+
return this.sort(sort_function);
|
|
51
|
+
}
|
|
52
|
+
matrix(length: number, fillValue?: number): any[] {
|
|
53
|
+
const x_func = () => {
|
|
54
|
+
return fillValue;
|
|
55
|
+
};
|
|
56
|
+
return Array.from({
|
|
57
|
+
length: length
|
|
58
|
+
}, x_func);
|
|
59
|
+
}
|
|
60
|
+
matrix2d(length: number, fillValue?: number): any[][] {
|
|
61
|
+
const y_func = function () {
|
|
62
|
+
return fillValue;
|
|
63
|
+
};
|
|
64
|
+
const x_func = function () {
|
|
65
|
+
return Array.from({
|
|
66
|
+
length
|
|
67
|
+
}, y_func);
|
|
68
|
+
};
|
|
69
|
+
return Array.from({
|
|
70
|
+
length
|
|
71
|
+
}, x_func);
|
|
72
|
+
}
|
|
73
|
+
matrix3d(length: number, fillValue?: number): any[][][] {
|
|
74
|
+
const y_func = function () {
|
|
75
|
+
return Array.from({
|
|
76
|
+
length
|
|
77
|
+
}, function () {
|
|
78
|
+
return fillValue;
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
const x_func = function () {
|
|
82
|
+
return Array.from({
|
|
83
|
+
length
|
|
84
|
+
}, y_func);
|
|
85
|
+
};
|
|
86
|
+
return Array.from({
|
|
87
|
+
length
|
|
88
|
+
}, x_func);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export class ArrayCollection implements IArrayCollection {
|
|
95
|
+
source :ArrayList = New(ArrayList, []);
|
|
96
|
+
changed(prop: string, value: any) {
|
|
97
|
+
logger.debug("VALUE CHANGED");
|
|
98
|
+
logger.debug(prop);
|
|
99
|
+
logger.debug(value);
|
|
100
|
+
}
|
|
101
|
+
push(value: any) {
|
|
102
|
+
const self = this;
|
|
103
|
+
logger.debug("VALUE ADDED");
|
|
104
|
+
logger.debug(value);
|
|
105
|
+
self.source.push(value);
|
|
106
|
+
}
|
|
107
|
+
pop() {
|
|
108
|
+
const self = this;
|
|
109
|
+
logger.debug("VALUE POPPED");
|
|
110
|
+
self.source.pop();
|
|
111
|
+
}
|
|
112
|
+
_new_(source: ArrayList) {
|
|
113
|
+
const self = this;
|
|
114
|
+
let _index = 0;
|
|
115
|
+
self.source = New(ClassFactory("ArrayList"), source);
|
|
116
|
+
for (const _k in self.source) {
|
|
117
|
+
if (!isNaN(_k as any)) {
|
|
118
|
+
logger.debug("binding " + _k.toString());
|
|
119
|
+
(function (_pname:any) {
|
|
120
|
+
Object.defineProperty(self, _pname, {
|
|
121
|
+
set(value) {
|
|
122
|
+
logger.debug("setting " + _pname + "=" + value);
|
|
123
|
+
self.source[_pname] = value;
|
|
124
|
+
self.changed(_pname, value);
|
|
125
|
+
},
|
|
126
|
+
get():unknown {
|
|
127
|
+
return self.source[_pname];
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
})(_k);
|
|
131
|
+
_index++;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
}
|
|
135
|
+
self.source.length = _index;
|
|
136
|
+
Object.defineProperty(self, "length", {
|
|
137
|
+
get() {
|
|
138
|
+
return self.source.length;
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import { Http2Stream } from "http2";
|
|
2
|
+
import { Stream } from "stream";
|
|
3
|
+
import { _basePath_ } from "./basePath";
|
|
4
|
+
import { _DataStringify } from "./DataStringify";
|
|
5
|
+
import { _domain_ } from "./domain";
|
|
6
|
+
import { InheritClass } from "./InheritClass";
|
|
7
|
+
import { logger } from "./Logger";
|
|
8
|
+
import { Package } from "./Package";
|
|
9
|
+
|
|
10
|
+
export class BackendMicroservice extends InheritClass {
|
|
11
|
+
stream: any;
|
|
12
|
+
route: any;
|
|
13
|
+
headers: any;
|
|
14
|
+
request: any;
|
|
15
|
+
|
|
16
|
+
constructor({
|
|
17
|
+
domain = _domain_,
|
|
18
|
+
basePath = _basePath_,
|
|
19
|
+
body = null,
|
|
20
|
+
stream = null,
|
|
21
|
+
request = null
|
|
22
|
+
}) {
|
|
23
|
+
super({
|
|
24
|
+
domain,
|
|
25
|
+
basePath,
|
|
26
|
+
body,
|
|
27
|
+
stream,
|
|
28
|
+
request
|
|
29
|
+
});
|
|
30
|
+
logger.debug("Initializing BackendMicroservice...");
|
|
31
|
+
const microservice = this;
|
|
32
|
+
if (typeof this.body === "undefined") {
|
|
33
|
+
this.body = null;
|
|
34
|
+
}
|
|
35
|
+
if (typeof body !== "undefined") {
|
|
36
|
+
this.body = body;
|
|
37
|
+
}
|
|
38
|
+
this.cors();
|
|
39
|
+
microservice.stream = stream;
|
|
40
|
+
(stream as any)?.on("data", (data: any) => {
|
|
41
|
+
// data from POST, GET
|
|
42
|
+
const requestMethod = (request as any)?.method.toLowerCase();
|
|
43
|
+
const supportedMethods = {
|
|
44
|
+
"post": microservice.post.bind(microservice),
|
|
45
|
+
};
|
|
46
|
+
if (Object.hasOwn(supportedMethods, requestMethod)) {
|
|
47
|
+
(supportedMethods as any)[requestMethod].call(microservice, data);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// data from POST, GET
|
|
52
|
+
const requestMethod = (request as any)?.method.toLowerCase();
|
|
53
|
+
const supportedMethods = {
|
|
54
|
+
"get": microservice.get.bind(microservice),
|
|
55
|
+
"head": microservice.head.bind(microservice),
|
|
56
|
+
"put": microservice.put.bind(microservice),
|
|
57
|
+
"delete": microservice.delete.bind(microservice),
|
|
58
|
+
"connect": microservice.connect.bind(microservice),
|
|
59
|
+
"options": microservice.options.bind(microservice),
|
|
60
|
+
"trace": microservice.trace.bind(microservice),
|
|
61
|
+
"patch": microservice.patch.bind(microservice)
|
|
62
|
+
};
|
|
63
|
+
if (Object.hasOwn(supportedMethods, requestMethod)) {
|
|
64
|
+
(supportedMethods as any)[requestMethod].call(microservice);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
cors() {
|
|
71
|
+
if (this.route.cors) {
|
|
72
|
+
logger.debug("Validating CORS...");
|
|
73
|
+
const {
|
|
74
|
+
allow_origins,
|
|
75
|
+
allow_credentials,
|
|
76
|
+
allow_methods,
|
|
77
|
+
allow_headers
|
|
78
|
+
} = this.route.cors;
|
|
79
|
+
const microservice = this;
|
|
80
|
+
if (typeof microservice.headers !== "object") {
|
|
81
|
+
microservice.headers = {};
|
|
82
|
+
}
|
|
83
|
+
if (typeof microservice.route.responseHeaders !== "object") {
|
|
84
|
+
microservice.route.responseHeaders = {};
|
|
85
|
+
}
|
|
86
|
+
if (typeof allow_origins !== "undefined") {
|
|
87
|
+
logger.debug("CORS: allow_origins available. Validating origins...");
|
|
88
|
+
// an example of allow_origins is ['https://example.com','http://www.example.com']
|
|
89
|
+
if (allow_origins === "*" || (typeof microservice.request.headers.origin === "undefined") || [...allow_origins].indexOf(microservice.request.headers.origin) !== -1) {
|
|
90
|
+
// for compatibility with all browsers allways return a wildcard when the origin is allowed
|
|
91
|
+
logger.debug("CORS: Adding header Access-Control-Allow-Origin=*");
|
|
92
|
+
microservice.route.responseHeaders["Access-Control-Allow-Origin"] = "*";
|
|
93
|
+
} else {
|
|
94
|
+
logger.debug("CORS: Origin is not allowed: " + microservice.request.headers.origin);
|
|
95
|
+
logger.debug("CORS: Forcing to finish the response...");
|
|
96
|
+
this.body = {};
|
|
97
|
+
try {
|
|
98
|
+
this.done();
|
|
99
|
+
} catch (e:any) {
|
|
100
|
+
logger.debug(`It was not possible to finish the call to the microservice: ${e}`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
} else {
|
|
104
|
+
logger.debug("CORS: no allow_origins available. Allowing all origins...");
|
|
105
|
+
logger.debug("CORS: Adding header Access-Control-Allow-Origin=*");
|
|
106
|
+
microservice.route.responseHeaders["Access-Control-Allow-Origin"] = "*";
|
|
107
|
+
}
|
|
108
|
+
if (typeof allow_credentials !== "undefined") {
|
|
109
|
+
logger.debug(`CORS: allow_credentials present. Allowing ${allow_credentials}...`);
|
|
110
|
+
microservice.route.responseHeaders["Access-Control-Allow-Credentials"] = allow_credentials.toString();
|
|
111
|
+
} else {
|
|
112
|
+
logger.debug("CORS: No allow_credentials present. Allowing all credentials.");
|
|
113
|
+
microservice.route.responseHeaders["Access-Control-Allow-Credentials"] = "true";
|
|
114
|
+
}
|
|
115
|
+
if (typeof allow_methods !== "undefined") {
|
|
116
|
+
logger.debug(`CORS: allow_methods present. Allowing ${allow_methods}...`);
|
|
117
|
+
microservice.route.responseHeaders["Access-Control-Allow-Methods"] = [...allow_methods].join(",");
|
|
118
|
+
} else {
|
|
119
|
+
logger.debug("CORS: No allow_methods present. Allowing only GET, OPTIONS and POST");
|
|
120
|
+
microservice.route.responseHeaders["Access-Control-Allow-Methods"] = "GET, OPTIONS, POST";
|
|
121
|
+
}
|
|
122
|
+
if (typeof allow_headers !== "undefined") {
|
|
123
|
+
logger.debug(`CORS: allow_headers present. Allowing ${allow_headers}...`);
|
|
124
|
+
microservice.route.responseHeaders["Access-Control-Allow-Headers"] = [...allow_headers].join(",");
|
|
125
|
+
} else {
|
|
126
|
+
logger.debug("CORS: No allow_headers present. Allowing all headers...");
|
|
127
|
+
microservice.route.responseHeaders["Access-Control-Allow-Headers"] = "*";
|
|
128
|
+
}
|
|
129
|
+
} else {
|
|
130
|
+
logger.debug("No CORS validation available. You can specify cors in CONFIG.backend.routes[].cors");
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
head(formData: any) {
|
|
136
|
+
logger.debug(`[BackendMicroservice.head] Data received: ${_DataStringify(formData)}`);
|
|
137
|
+
this.done();
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
get(formData: any) {
|
|
141
|
+
logger.debug(`[BackendMicroservice.get] Data received: ${_DataStringify(formData)}`);
|
|
142
|
+
this.done();
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
post(formData: any) {
|
|
146
|
+
logger.debug(`[BackendMicroservice.post] Data received: ${_DataStringify(formData)}`);
|
|
147
|
+
this.done();
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
put(formData: any) {
|
|
151
|
+
logger.debug(`[BackendMicroservice.put] Data received: ${_DataStringify(formData)}`);
|
|
152
|
+
this.done();
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
delete(formData: any) {
|
|
156
|
+
logger.debug(`[BackendMicroservice.delete] Data received: ${_DataStringify(formData)}`);
|
|
157
|
+
this.done();
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
connect(formData: any) {
|
|
161
|
+
logger.debug(`[BackendMicroservice.connect] Data received: ${_DataStringify(formData)}`);
|
|
162
|
+
this.done();
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
options(formData: any) {
|
|
166
|
+
logger.debug(`[BackendMicroservice.options] Data received: ${_DataStringify(formData)}`);
|
|
167
|
+
this.done();
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
trace(formData: any) {
|
|
171
|
+
logger.debug(`[BackendMicroservice.trace] Data received: ${_DataStringify(formData)}`);
|
|
172
|
+
this.done();
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
patch(formData: any) {
|
|
176
|
+
logger.debug(`[BackendMicroservice.patch] Data received: ${_DataStringify(formData)}`);
|
|
177
|
+
this.done();
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
finishWithBody(stream?: Http2Stream | Stream) {
|
|
181
|
+
try {
|
|
182
|
+
logger.debug("[BackendMicroservice.finishWithBody] Ending the stream...");
|
|
183
|
+
logger.debug(`[BackendMicroservice.finishWithBody] type of body is: ${typeof this.body}`);
|
|
184
|
+
if (typeof this.body !== "string") {
|
|
185
|
+
this.body = _DataStringify(this.body);
|
|
186
|
+
}
|
|
187
|
+
logger.debug(`[BackendMicroservice.finishWithBody] \n body: ${this.body} `);
|
|
188
|
+
(stream as any)?.write(this.body);
|
|
189
|
+
(stream as any)?.end();
|
|
190
|
+
logger.debug("[BackendMicroservice.finishWithBody] Stream ended.");
|
|
191
|
+
} catch (e:any) {
|
|
192
|
+
logger.debug(`[BackendMicroservice.finishWithBody] Something went wrong ending the stream: ${e}`);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
done() {
|
|
197
|
+
logger.debug("[BackendMicroservice.done] Finalizing the response...");
|
|
198
|
+
const microservice = this;
|
|
199
|
+
const stream = microservice.stream;
|
|
200
|
+
try {
|
|
201
|
+
logger.debug("[BackendMicroservice.done] Sending response headers...");
|
|
202
|
+
if (microservice.route.responseHeaders) {
|
|
203
|
+
logger.debug(`[BackendMicroservice.done] Response headers present: ${Object.keys(microservice.route.responseHeaders).join(",")}`);
|
|
204
|
+
stream.respond(microservice.route.responseHeaders);
|
|
205
|
+
} else {
|
|
206
|
+
throw Error("[BackendMicroservice.done] No headers present.");
|
|
207
|
+
}
|
|
208
|
+
} catch (e:any) {
|
|
209
|
+
logger.debug(`[BackendMicroservice.done] Something went wrong sending response headers: ${e}`);
|
|
210
|
+
}
|
|
211
|
+
if (microservice.body !== null) {
|
|
212
|
+
try {
|
|
213
|
+
logger.debug("[BackendMicroservice.done] A body of message is present. Finalizing the response...");
|
|
214
|
+
microservice.finishWithBody.call(microservice, stream);
|
|
215
|
+
} catch (e:any) {
|
|
216
|
+
logger.debug(`[BackendMicroservice.done] Something went wrong finalizing the response: ${e}`);
|
|
217
|
+
}
|
|
218
|
+
} else {
|
|
219
|
+
logger.debug("[BackendMicroservice.done] No body present. Ending stream...");
|
|
220
|
+
stream.end();
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
Package("com.qcobjects.api", [
|
|
228
|
+
BackendMicroservice
|
|
229
|
+
]);
|
package/src/Base64.ts
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
export const Base64 = {
|
|
2
|
+
_keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
|
|
3
|
+
encode(e: string) {
|
|
4
|
+
let t = "";
|
|
5
|
+
let n: number, r: number, i: number, s: number, o: number, u: number, a: number;
|
|
6
|
+
let f = 0;
|
|
7
|
+
e = Base64._utf8_encode(e);
|
|
8
|
+
while (f < e.length) {
|
|
9
|
+
n = e.charCodeAt(f++);
|
|
10
|
+
r = e.charCodeAt(f++);
|
|
11
|
+
i = e.charCodeAt(f++);
|
|
12
|
+
s = n >> 2;
|
|
13
|
+
o = (n & 3) << 4 | r >> 4;
|
|
14
|
+
u = (r & 15) << 2 | i >> 6;
|
|
15
|
+
a = i & 63;
|
|
16
|
+
if (isNaN(r)) {
|
|
17
|
+
u = a = 64;
|
|
18
|
+
} else if (isNaN(i)) {
|
|
19
|
+
a = 64;
|
|
20
|
+
}
|
|
21
|
+
t = t + this._keyStr.charAt(s) + this._keyStr.charAt(o) + this._keyStr.charAt(u) + this._keyStr.charAt(a);
|
|
22
|
+
}
|
|
23
|
+
return t;
|
|
24
|
+
},
|
|
25
|
+
decode(e: string) {
|
|
26
|
+
let t = "";
|
|
27
|
+
let n: number, r: number, i: number;
|
|
28
|
+
let s: number, o: number, u: number, a: number;
|
|
29
|
+
let f = 0;
|
|
30
|
+
e = e.replace(/[^A-Za-z0-9+/=]/g, "");
|
|
31
|
+
while (f < e.length) {
|
|
32
|
+
s = this._keyStr.indexOf(e.charAt(f++));
|
|
33
|
+
o = this._keyStr.indexOf(e.charAt(f++));
|
|
34
|
+
u = this._keyStr.indexOf(e.charAt(f++));
|
|
35
|
+
a = this._keyStr.indexOf(e.charAt(f++));
|
|
36
|
+
n = s << 2 | o >> 4;
|
|
37
|
+
r = (o & 15) << 4 | u >> 2;
|
|
38
|
+
i = (u & 3) << 6 | a;
|
|
39
|
+
t = t + String.fromCharCode(n);
|
|
40
|
+
if (u !== 64) {
|
|
41
|
+
t = t + String.fromCharCode(r);
|
|
42
|
+
}
|
|
43
|
+
if (a !== 64) {
|
|
44
|
+
t = t + String.fromCharCode(i);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
t = Base64._utf8_decode(t);
|
|
48
|
+
return t;
|
|
49
|
+
},
|
|
50
|
+
_utf8_encode(e: string) {
|
|
51
|
+
e = e.replace(/rn/g, "n");
|
|
52
|
+
let t = "";
|
|
53
|
+
for (let n = 0; n < e.length; n++) {
|
|
54
|
+
const r = e.charCodeAt(n);
|
|
55
|
+
if (r < 128) {
|
|
56
|
+
t += String.fromCharCode(r);
|
|
57
|
+
} else if (r > 127 && r < 2048) {
|
|
58
|
+
t += String.fromCharCode(r >> 6 | 192);
|
|
59
|
+
t += String.fromCharCode(r & 63 | 128);
|
|
60
|
+
} else {
|
|
61
|
+
t += String.fromCharCode(r >> 12 | 224);
|
|
62
|
+
t += String.fromCharCode(r >> 6 & 63 | 128);
|
|
63
|
+
t += String.fromCharCode(r & 63 | 128);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return t;
|
|
67
|
+
},
|
|
68
|
+
_utf8_decode(e: string) {
|
|
69
|
+
let t = "";
|
|
70
|
+
let n = 0;
|
|
71
|
+
let r = 0;
|
|
72
|
+
let c2 = 0;
|
|
73
|
+
let c3: number;
|
|
74
|
+
while (n < e.length) {
|
|
75
|
+
r = e.charCodeAt(n);
|
|
76
|
+
if (r < 128) {
|
|
77
|
+
t += String.fromCharCode(r);
|
|
78
|
+
n++;
|
|
79
|
+
} else if (r > 191 && r < 224) {
|
|
80
|
+
c2 = e.charCodeAt(n + 1);
|
|
81
|
+
t += String.fromCharCode((r & 31) << 6 | c2 & 63);
|
|
82
|
+
n += 2;
|
|
83
|
+
} else {
|
|
84
|
+
c2 = e.charCodeAt(n + 1);
|
|
85
|
+
c3 = e.charCodeAt(n + 2);
|
|
86
|
+
t += String.fromCharCode((r & 15) << 12 | (c2 & 63) << 6 | c3 & 63);
|
|
87
|
+
n += 3;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return t;
|
|
91
|
+
}
|
|
92
|
+
};
|