quantum-flow 1.0.1 → 1.0.4

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 (70) hide show
  1. package/README.md +243 -17
  2. package/dist/app/aws/lambda.d.ts +1 -1
  3. package/dist/app/aws/lambda.js +2 -2
  4. package/dist/app/http/Application.d.ts +1 -1
  5. package/dist/app/http/Application.js +2 -2
  6. package/dist/app/http/decorators.d.ts +1 -1
  7. package/dist/app/http/decorators.js +1 -1
  8. package/dist/app/http/websocket/WebsocetService.d.ts +1 -1
  9. package/dist/app/http/websocket/WebsocketServer.d.ts +1 -1
  10. package/dist/core/Controller.d.ts +24 -3
  11. package/dist/core/Controller.js +26 -5
  12. package/dist/core/Endpoint.d.ts +63 -7
  13. package/dist/core/Endpoint.js +69 -13
  14. package/dist/core/index.d.ts +7 -1
  15. package/dist/core/utils/extractors.d.ts +31 -1
  16. package/dist/core/utils/extractors.js +31 -1
  17. package/dist/core/utils/helpers.d.ts +13 -0
  18. package/dist/core/utils/helpers.js +14 -1
  19. package/dist/core/utils/websocket.d.ts +26 -1
  20. package/dist/core/utils/websocket.js +26 -1
  21. package/dist/examples/controllers/index.d.ts +2 -0
  22. package/dist/examples/controllers/index.js +18 -0
  23. package/dist/examples/controllers/socket.d.ts +24 -0
  24. package/dist/examples/controllers/socket.js +107 -0
  25. package/dist/examples/controllers/user.d.ts +3 -0
  26. package/dist/examples/controllers/user.js +55 -0
  27. package/dist/examples/server.d.ts +1 -0
  28. package/dist/examples/server.js +48 -0
  29. package/dist/utils/controller.d.ts +1 -1
  30. package/dist/utils/controller.js +2 -2
  31. package/dist/utils/server.d.ts +1 -1
  32. package/dist/utils/server.js +1 -1
  33. package/dist/utils/transform.js +0 -1
  34. package/package.json +20 -6
  35. package/.prettierrc.json +0 -9
  36. package/eslint.config.mjs +0 -84
  37. package/nodemon.json +0 -5
  38. package/src/app/aws/index.ts +0 -1
  39. package/src/app/aws/lambda.ts +0 -283
  40. package/src/app/http/Application.ts +0 -250
  41. package/src/app/http/Socket.ts +0 -38
  42. package/src/app/http/decorators.ts +0 -115
  43. package/src/app/http/index.ts +0 -3
  44. package/src/app/http/websocket/WebsocetService.ts +0 -44
  45. package/src/app/http/websocket/WebsocketServer.ts +0 -262
  46. package/src/constants.ts +0 -25
  47. package/src/core/Controller.ts +0 -229
  48. package/src/core/Endpoint.ts +0 -39
  49. package/src/core/index.ts +0 -14
  50. package/src/core/utils/extractors.ts +0 -32
  51. package/src/core/utils/helpers.ts +0 -22
  52. package/src/core/utils/index.ts +0 -3
  53. package/src/core/utils/websocket.ts +0 -45
  54. package/src/types/common.ts +0 -60
  55. package/src/types/controller.ts +0 -2
  56. package/src/types/http.ts +0 -19
  57. package/src/types/index.ts +0 -5
  58. package/src/types/lambda.ts +0 -28
  59. package/src/types/websocket.ts +0 -57
  60. package/src/utils/controller.ts +0 -143
  61. package/src/utils/helper.ts +0 -24
  62. package/src/utils/index.ts +0 -7
  63. package/src/utils/multipart.ts +0 -93
  64. package/src/utils/parsers.ts +0 -87
  65. package/src/utils/server.ts +0 -49
  66. package/src/utils/transform.ts +0 -24
  67. package/src/utils/validate.ts +0 -53
  68. package/src/validators/Validate.ts +0 -48
  69. package/src/validators/index.ts +0 -1
  70. package/tsconfig.json +0 -51
@@ -1,87 +0,0 @@
1
- import http from 'http';
2
- export const ParseQuery = (url: URL) => {
3
- const params = url.searchParams;
4
- const query: Record<string, string | string[]> = {};
5
-
6
- for (const key of params.keys()) {
7
- const values = params.getAll(key);
8
-
9
- query[key] = values.length > 1 ? values : values[0];
10
- }
11
-
12
- return query;
13
- };
14
-
15
- export const ParseBody = (request: any): any => {
16
- if (request.body && typeof request.body === 'object' && !Buffer.isBuffer(request.body)) {
17
- return request.body;
18
- }
19
-
20
- const { body, headers, isBase64Encoded } = request;
21
-
22
- if (!body) {
23
- return {};
24
- }
25
-
26
- let contentType = headers['content-type'] ?? headers['Content-Type'] ?? '';
27
- if (Array.isArray(contentType)) {
28
- contentType = contentType[0];
29
- }
30
-
31
- const cleanContentType = contentType.split(';')[0].trim().toLowerCase();
32
-
33
- if (cleanContentType === 'application/json') {
34
- try {
35
- if (typeof body === 'string') {
36
- return JSON.parse(body);
37
- }
38
- if (Buffer.isBuffer(body)) {
39
- return JSON.parse(body.toString('utf8'));
40
- }
41
- } catch (error) {
42
- console.error(error);
43
- throw error;
44
- }
45
- }
46
-
47
- if (cleanContentType.startsWith('text/')) {
48
- if (Buffer.isBuffer(body)) {
49
- return { text: body.toString('utf8') };
50
- }
51
- return { text: body };
52
- }
53
-
54
- if (cleanContentType === 'application/x-www-form-urlencoded') {
55
- if (Buffer.isBuffer(body)) {
56
- const text = body.toString('utf8');
57
- const params = new URLSearchParams(text);
58
- const result: Record<string, any> = {};
59
- params.forEach((value, key) => {
60
- result[key] = value;
61
- });
62
- return result;
63
- }
64
- }
65
-
66
- if (Buffer.isBuffer(body)) {
67
- return { raw: body.toString('utf8') };
68
- }
69
-
70
- return body;
71
- };
72
-
73
- export const ParseCookies = (req: http.IncomingMessage): Record<string, string> => {
74
- const cookieHeader = req.headers.cookie;
75
- if (!cookieHeader) return {};
76
-
77
- return cookieHeader.split(';').reduce(
78
- (cookies, cookie) => {
79
- const [name, value] = cookie.trim().split('=');
80
- if (name && value) {
81
- cookies[name] = decodeURIComponent(value);
82
- }
83
- return cookies;
84
- },
85
- {} as Record<string, string>,
86
- );
87
- };
@@ -1,49 +0,0 @@
1
- import { SERVER_CONFIG_KEY, SERVER_MODULES_KEY } from '@constants';
2
- import { ServerConfig } from '@types';
3
- import http from 'http';
4
-
5
- export const resolveConfig = (configOrClass?: any): ServerConfig => {
6
- let config: ServerConfig = {};
7
-
8
- if (configOrClass && typeof configOrClass === 'function') {
9
- const decoratorConfig = Reflect.getMetadata(SERVER_CONFIG_KEY, configOrClass) || {};
10
- const controllers = Reflect.getMetadata(SERVER_MODULES_KEY, configOrClass) || [];
11
-
12
- config = {
13
- port: 3000,
14
- host: 'localhost',
15
- ...decoratorConfig,
16
- controllers: [...controllers, ...(decoratorConfig.controllers || [])],
17
- };
18
- } else if (configOrClass && typeof configOrClass === 'object') {
19
- config = { port: 3000, host: 'localhost', ...configOrClass };
20
- } else {
21
- config = {
22
- port: 3000,
23
- host: 'localhost',
24
- controllers: [],
25
- };
26
- console.log('⚙️ Using default configuration');
27
- }
28
-
29
- return config;
30
- };
31
-
32
- export const collectRawBody = (req: http.IncomingMessage): Promise<Buffer> => {
33
- return new Promise((resolve) => {
34
- const chunks: Buffer[] = [];
35
-
36
- req.on('data', (chunk) => {
37
- chunks.push(Buffer.from(chunk));
38
- });
39
-
40
- req.on('end', () => {
41
- const buffer = Buffer.concat(chunks);
42
- resolve(buffer);
43
- });
44
-
45
- req.on('error', () => {
46
- resolve(Buffer.from(''));
47
- });
48
- });
49
- };
@@ -1,24 +0,0 @@
1
- export async function transformAndValidate(dtoClass: any, data: any) {
2
- if (!dtoClass) return data;
3
-
4
- if (typeof dtoClass.from === 'function') {
5
- return dtoClass.from(data);
6
- }
7
- if (typeof dtoClass === 'function') {
8
- const instance = new dtoClass();
9
- Object.entries(data).forEach(([key, val]) => {
10
- instance[key] = val;
11
- });
12
-
13
- Object.assign(instance, data);
14
- if (typeof instance.validate === 'function') {
15
- await instance.validate();
16
- }
17
-
18
- console.log('ppppppp', dtoClass, data);
19
-
20
- return instance;
21
- }
22
-
23
- return data;
24
- }
@@ -1,53 +0,0 @@
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
- }
@@ -1,48 +0,0 @@
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
- }
@@ -1 +0,0 @@
1
- export * from './Validate';
package/tsconfig.json DELETED
@@ -1,51 +0,0 @@
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
- }