quantum-flow 1.0.1

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 (102) hide show
  1. package/.prettierrc.json +9 -0
  2. package/README.md +37 -0
  3. package/dist/app/aws/index.d.ts +1 -0
  4. package/dist/app/aws/index.js +17 -0
  5. package/dist/app/aws/lambda.d.ts +13 -0
  6. package/dist/app/aws/lambda.js +241 -0
  7. package/dist/app/http/Application.d.ts +23 -0
  8. package/dist/app/http/Application.js +208 -0
  9. package/dist/app/http/Socket.d.ts +16 -0
  10. package/dist/app/http/Socket.js +32 -0
  11. package/dist/app/http/decorators.d.ts +7 -0
  12. package/dist/app/http/decorators.js +81 -0
  13. package/dist/app/http/index.d.ts +3 -0
  14. package/dist/app/http/index.js +19 -0
  15. package/dist/app/http/websocket/WebsocetService.d.ts +20 -0
  16. package/dist/app/http/websocket/WebsocetService.js +41 -0
  17. package/dist/app/http/websocket/WebsocketServer.d.ts +30 -0
  18. package/dist/app/http/websocket/WebsocketServer.js +221 -0
  19. package/dist/constants.d.ts +16 -0
  20. package/dist/constants.js +24 -0
  21. package/dist/core/Controller.d.ts +43 -0
  22. package/dist/core/Controller.js +159 -0
  23. package/dist/core/Endpoint.d.ts +8 -0
  24. package/dist/core/Endpoint.js +43 -0
  25. package/dist/core/index.d.ts +4 -0
  26. package/dist/core/index.js +19 -0
  27. package/dist/core/utils/extractors.d.ts +15 -0
  28. package/dist/core/utils/extractors.js +29 -0
  29. package/dist/core/utils/helpers.d.ts +4 -0
  30. package/dist/core/utils/helpers.js +22 -0
  31. package/dist/core/utils/index.d.ts +3 -0
  32. package/dist/core/utils/index.js +19 -0
  33. package/dist/core/utils/websocket.d.ts +8 -0
  34. package/dist/core/utils/websocket.js +45 -0
  35. package/dist/types/common.d.ts +47 -0
  36. package/dist/types/common.js +2 -0
  37. package/dist/types/controller.d.ts +4 -0
  38. package/dist/types/controller.js +2 -0
  39. package/dist/types/http.d.ts +18 -0
  40. package/dist/types/http.js +2 -0
  41. package/dist/types/index.d.ts +5 -0
  42. package/dist/types/index.js +21 -0
  43. package/dist/types/lambda.d.ts +26 -0
  44. package/dist/types/lambda.js +2 -0
  45. package/dist/types/websocket.d.ts +55 -0
  46. package/dist/types/websocket.js +2 -0
  47. package/dist/utils/controller.d.ts +9 -0
  48. package/dist/utils/controller.js +111 -0
  49. package/dist/utils/helper.d.ts +1 -0
  50. package/dist/utils/helper.js +24 -0
  51. package/dist/utils/index.d.ts +7 -0
  52. package/dist/utils/index.js +23 -0
  53. package/dist/utils/multipart.d.ts +15 -0
  54. package/dist/utils/multipart.js +109 -0
  55. package/dist/utils/parsers.d.ts +4 -0
  56. package/dist/utils/parsers.js +76 -0
  57. package/dist/utils/server.d.ts +4 -0
  58. package/dist/utils/server.js +46 -0
  59. package/dist/utils/transform.d.ts +1 -0
  60. package/dist/utils/transform.js +23 -0
  61. package/dist/utils/validate.d.ts +1 -0
  62. package/dist/utils/validate.js +46 -0
  63. package/dist/validators/Validate.d.ts +3 -0
  64. package/dist/validators/Validate.js +40 -0
  65. package/dist/validators/index.d.ts +1 -0
  66. package/dist/validators/index.js +17 -0
  67. package/eslint.config.mjs +84 -0
  68. package/nodemon.json +5 -0
  69. package/package.json +70 -0
  70. package/src/app/aws/index.ts +1 -0
  71. package/src/app/aws/lambda.ts +283 -0
  72. package/src/app/http/Application.ts +250 -0
  73. package/src/app/http/Socket.ts +38 -0
  74. package/src/app/http/decorators.ts +115 -0
  75. package/src/app/http/index.ts +3 -0
  76. package/src/app/http/websocket/WebsocetService.ts +44 -0
  77. package/src/app/http/websocket/WebsocketServer.ts +262 -0
  78. package/src/constants.ts +25 -0
  79. package/src/core/Controller.ts +229 -0
  80. package/src/core/Endpoint.ts +39 -0
  81. package/src/core/index.ts +14 -0
  82. package/src/core/utils/extractors.ts +32 -0
  83. package/src/core/utils/helpers.ts +22 -0
  84. package/src/core/utils/index.ts +3 -0
  85. package/src/core/utils/websocket.ts +45 -0
  86. package/src/types/common.ts +60 -0
  87. package/src/types/controller.ts +2 -0
  88. package/src/types/http.ts +19 -0
  89. package/src/types/index.ts +5 -0
  90. package/src/types/lambda.ts +28 -0
  91. package/src/types/websocket.ts +57 -0
  92. package/src/utils/controller.ts +143 -0
  93. package/src/utils/helper.ts +24 -0
  94. package/src/utils/index.ts +7 -0
  95. package/src/utils/multipart.ts +93 -0
  96. package/src/utils/parsers.ts +87 -0
  97. package/src/utils/server.ts +49 -0
  98. package/src/utils/transform.ts +24 -0
  99. package/src/utils/validate.ts +53 -0
  100. package/src/validators/Validate.ts +48 -0
  101. package/src/validators/index.ts +1 -0
  102. package/tsconfig.json +51 -0
@@ -0,0 +1,53 @@
1
+ import { plainToInstance } from 'class-transformer';
2
+ import { validate as Validate, ValidationError } from 'class-validator';
3
+
4
+ export async function validate(dtoClass: any, data: any) {
5
+ if (!dtoClass) {
6
+ return data;
7
+ }
8
+
9
+ try {
10
+ if (typeof dtoClass.from === 'function') {
11
+ return dtoClass.from(data);
12
+ }
13
+
14
+ if (typeof dtoClass === 'function') {
15
+ const instance = plainToInstance(dtoClass, data);
16
+ const errors = await Validate(instance);
17
+
18
+ if (errors.length > 0) {
19
+ const formattedErrors = formatValidationErrors(errors);
20
+
21
+ throw {
22
+ status: 400,
23
+ message: 'Validation failed',
24
+ errors: formattedErrors,
25
+ };
26
+ }
27
+
28
+ return instance;
29
+ }
30
+
31
+ return data;
32
+ } catch (error) {
33
+ throw error;
34
+ }
35
+ }
36
+
37
+ function formatValidationErrors(errors: ValidationError[]): any[] {
38
+ return errors.map((error) => {
39
+ const constraints = error.constraints || {};
40
+
41
+ const children =
42
+ error.children && error.children.length > 0
43
+ ? formatValidationErrors(error.children)
44
+ : undefined;
45
+
46
+ return {
47
+ property: error.property,
48
+ value: error.value,
49
+ constraints: Object.values(constraints),
50
+ children,
51
+ };
52
+ });
53
+ }
@@ -0,0 +1,48 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import { validate } from 'class-validator';
3
+
4
+ type ToValidate = 'query' | 'body' | 'params' | 'headers';
5
+
6
+ export function Validate(param: ToValidate, dtoClass: any) {
7
+ return function (target: any, propertyKey?: string, descriptor?: PropertyDescriptor): void {
8
+ // METHOD DECORATOR
9
+ if (descriptor) {
10
+ wrapMethod(descriptor, param, dtoClass);
11
+ return;
12
+ }
13
+
14
+ // CLASS DECORATOR
15
+ const prototype = target.prototype;
16
+
17
+ Object.getOwnPropertyNames(prototype).forEach((method) => {
18
+ if (method === 'constructor') return;
19
+
20
+ const desc = Object.getOwnPropertyDescriptor(prototype, method);
21
+ if (!desc || typeof desc.value !== 'function') return;
22
+
23
+ wrapMethod(desc, param, dtoClass);
24
+ Object.defineProperty(prototype, method, desc);
25
+ });
26
+ };
27
+ }
28
+
29
+ function wrapMethod(descriptor: PropertyDescriptor, param: any, dtoClass: any) {
30
+ const originalMethod = descriptor.value;
31
+
32
+ descriptor.value = async function (...args: any[]) {
33
+ const value = args[0][param];
34
+ const instance = new dtoClass();
35
+
36
+ Object.entries(value || {}).forEach(([key, val]) => {
37
+ instance[key] = val;
38
+ });
39
+
40
+ const errors = await validate(instance, { whitelist: true });
41
+
42
+ if (errors.length) {
43
+ throw { status: 422, message: 'Validation failed', data: errors };
44
+ }
45
+
46
+ return originalMethod.apply(this, args);
47
+ };
48
+ }
@@ -0,0 +1 @@
1
+ export * from './Validate';
package/tsconfig.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "compilerOptions": {
3
+ "moduleResolution": "nodenext",
4
+ "module": "nodenext",
5
+ "target": "es2022",
6
+ "types": [
7
+ "node"
8
+ ],
9
+ "declaration": true,
10
+ "outDir": "./dist",
11
+ "rootDir": "./src",
12
+ "esModuleInterop": true,
13
+ "strict": true,
14
+ "skipLibCheck": true,
15
+ "experimentalDecorators": true,
16
+ "emitDecoratorMetadata": true,
17
+ "strictPropertyInitialization": false,
18
+ "typeRoots": [
19
+ "./node_modules/@types"
20
+ ],
21
+ "paths": {
22
+ "@controllers": [
23
+ "./src/controllers/index.ts"
24
+ ],
25
+ "@utils": [
26
+ "./src/utils/index.ts"
27
+ ],
28
+ "@types": [
29
+ "./src/types/index.ts"
30
+ ],
31
+ "@validators": [
32
+ "./src/validators/index.ts"
33
+ ],
34
+ "@constants": [
35
+ "./src/constants.ts"
36
+ ]
37
+ },
38
+ },
39
+ "include": [
40
+ "src/**/*"
41
+ ],
42
+ "exclude": [
43
+ "node_modules",
44
+ "dist",
45
+ "testing",
46
+ "./testing",
47
+ "**/*.test.ts",
48
+ "**/*.spec.ts",
49
+ "examples"
50
+ ]
51
+ }