@avleon/core 0.0.29 → 0.0.30

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 (43) hide show
  1. package/package.json +2 -3
  2. package/src/application.ts +0 -104
  3. package/src/authentication.ts +0 -16
  4. package/src/cache.ts +0 -91
  5. package/src/collection.test.ts +0 -71
  6. package/src/collection.ts +0 -344
  7. package/src/config.test.ts +0 -35
  8. package/src/config.ts +0 -85
  9. package/src/constants.ts +0 -1
  10. package/src/container.ts +0 -54
  11. package/src/controller.ts +0 -125
  12. package/src/decorators.ts +0 -27
  13. package/src/environment-variables.ts +0 -53
  14. package/src/event-dispatcher.ts +0 -100
  15. package/src/event-subscriber.ts +0 -79
  16. package/src/exceptions/http-exceptions.ts +0 -86
  17. package/src/exceptions/index.ts +0 -1
  18. package/src/exceptions/system-exception.ts +0 -35
  19. package/src/file-storage.ts +0 -206
  20. package/src/helpers.ts +0 -324
  21. package/src/icore.ts +0 -1106
  22. package/src/index.ts +0 -32
  23. package/src/interfaces/avleon-application.ts +0 -32
  24. package/src/logger.ts +0 -72
  25. package/src/map-types.ts +0 -159
  26. package/src/middleware.ts +0 -121
  27. package/src/multipart.ts +0 -116
  28. package/src/openapi.ts +0 -372
  29. package/src/params.ts +0 -111
  30. package/src/queue.ts +0 -126
  31. package/src/response.ts +0 -74
  32. package/src/results.ts +0 -30
  33. package/src/route-methods.ts +0 -186
  34. package/src/swagger-schema.ts +0 -213
  35. package/src/testing.ts +0 -220
  36. package/src/types/app-builder.interface.ts +0 -18
  37. package/src/types/application.interface.ts +0 -7
  38. package/src/utils/hash.ts +0 -8
  39. package/src/utils/index.ts +0 -2
  40. package/src/utils/optional-require.ts +0 -50
  41. package/src/validation.ts +0 -160
  42. package/src/validator-extend.ts +0 -25
  43. package/src/websocket.ts +0 -47
package/src/validation.ts DELETED
@@ -1,160 +0,0 @@
1
- /**
2
- * @copyright 2024
3
- * @author Tareq Hossain
4
- * @email xtrinsic96@gmail.com
5
- * @url https://github.com/xtareq
6
- */
7
-
8
- import { BadRequestException } from "./exceptions";
9
-
10
- class PValidationRule<T> {
11
- name: string;
12
- type: T;
13
- message?: string;
14
-
15
- constructor(name: string, type: T, message?: string) {
16
- this.name = name;
17
- this.type = type;
18
- this.message = message;
19
- }
20
- }
21
-
22
- type BaseRule = {
23
- required?: boolean;
24
- optional?: boolean;
25
- message?: string;
26
- };
27
-
28
- type StringRule = BaseRule & {
29
- type: "string";
30
- };
31
-
32
- type NumberRule = BaseRule & {
33
- type: "number";
34
- min?: number;
35
- max?: number;
36
- exact?: number;
37
- };
38
-
39
- type BooleanRule = BaseRule & {
40
- type: "boolean";
41
- };
42
-
43
- export type ValidationRule = StringRule | NumberRule | BooleanRule;
44
-
45
- export type ValidationProps = {
46
- [key: string]: ValidationRule;
47
- };
48
-
49
- export type ValidateOptons = {
50
- location?: "header" | "queryparam" | "param" | "body" | "custom";
51
- };
52
-
53
- class Validator {
54
- private rules: PValidationRule<any>[] = [];
55
- private options: ValidateOptons = {};
56
-
57
- constructor(obj: ValidationProps, options?: ValidateOptons) {
58
- this.init(obj);
59
- if (options) {
60
- this.options = options;
61
- }
62
- }
63
-
64
- private init(obj: ValidationProps) {
65
- Object.keys(obj).forEach((key) => {
66
- const rule = obj[key];
67
- this.rules.push(
68
- new PValidationRule<typeof rule.type>(key, rule.type, rule.message),
69
- );
70
- });
71
- }
72
-
73
- validate(obj: any | Array<any>, options?: ValidateOptons) {
74
- const erors: any[] = [];
75
-
76
- this.rules.forEach((k) => {
77
- const r = Object.keys(obj).find((key) => key == k.name);
78
- let messages: any = [];
79
- if (!r || obj[r] == undefined || obj[r] == "") {
80
- messages.push({
81
- constraint: "required",
82
- message: k.name + " is required",
83
- });
84
- }
85
-
86
- if (k.type == "string" && typeof obj[k.name] != "string") {
87
- messages.push({
88
- constraint: "type",
89
- message: `${k.name} must be type ${k.type}`,
90
- });
91
- }
92
- if (k.type == "number" && !parseInt(obj[k.name])) {
93
- messages.push({
94
- constraint: "type",
95
- message: `${k.name} must be type ${k.type}`,
96
- });
97
- }
98
-
99
- if (k.type == "number") {
100
- obj[k.name] = parseInt(obj[k.name]);
101
- }
102
- if (k.type == "boolean" && !isBool(obj[k.name])) {
103
- messages.push({
104
- constraint: "type",
105
- message: `${k.name} must be type ${k.type}`,
106
- });
107
- }
108
- if (k.type == "boolean") {
109
- obj[k.name] = parseBoolean(obj[k.name]);
110
- }
111
- if (messages.length > 0) {
112
- erors.push({
113
- path: k.name,
114
- ...(this.options.location ? { location: this.options.location } : {}),
115
- constraints: messages,
116
- });
117
- }
118
- });
119
-
120
- return [erors, obj];
121
- }
122
- }
123
-
124
- const isBool = (val: any) => {
125
- if (typeof val == "boolean") return true;
126
- if (parseInt(val) == 0 || parseInt(val) == 1) return true;
127
- if (val == "true" || val == "false") return true;
128
-
129
- return false;
130
- };
131
-
132
- const parseBoolean = (val: any): boolean => {
133
- if (typeof val === "boolean") return val;
134
-
135
- // if (typeof val === "number") {
136
- // return val !== 0; // Common convention: 0 → false, any other number → true
137
- // }
138
-
139
- if (parseInt(val) == 1) return true;
140
- if (typeof val === "string") {
141
- const normalized = val.trim().toLowerCase();
142
- return normalized === "true";
143
- }
144
- return false; // Default for unsupported types (null, undefined, objects, etc.)
145
- };
146
-
147
- export function validateOrThrow<T extends {}>(
148
- obj: T,
149
- rules: ValidationProps,
150
- options?: ValidateOptons,
151
- ) {
152
- const valid = new Validator(rules, options);
153
- const errors = valid.validate(obj);
154
-
155
- if (errors[0].length > 0) {
156
- throw new BadRequestException(errors[0]);
157
- }
158
-
159
- return errors[1];
160
- }
@@ -1,25 +0,0 @@
1
- /**
2
- * @copyright 2024
3
- * @author Tareq Hossain
4
- * @email xtrinsic96@gmail.com
5
- * @url https://github.com/xtareq
6
- */
7
- export function IsArrayNotEmpty(validationOptions?: any) {
8
- const { registerDecorator, ValidationArguments } = require("class-validator");
9
- return function (object: Object, propertyName: string) {
10
- registerDecorator({
11
- name: "isArrayWithAtLeastOneElement",
12
- target: object.constructor,
13
- propertyName: propertyName,
14
- options: validationOptions,
15
- validator: {
16
- validate(value: any, args: any) {
17
- return Array.isArray(value) && value.length > 0;
18
- },
19
- defaultMessage(args: any) {
20
- return `${args.property} must contain at least one item.`;
21
- },
22
- },
23
- });
24
- };
25
- }
package/src/websocket.ts DELETED
@@ -1,47 +0,0 @@
1
- import { PathLike } from "node:fs";
2
- import { Server } from "socket.io";
3
- import { Service } from "typedi";
4
-
5
-
6
- type FileAdapter = {
7
- type: "file",
8
- url?: PathLike
9
- }
10
-
11
- type RedisAdapter = {
12
- type: "redis",
13
- url?: string,
14
- username?: string,
15
- password?: string
16
- }
17
-
18
- type AdapterType = FileAdapter | RedisAdapter;
19
-
20
-
21
- interface BrodcastAble {
22
- channel: string;
23
- broadstTo: () => void;
24
- }
25
-
26
-
27
-
28
- @Service()
29
- export class AvleonSocketIo {
30
-
31
- private io?: Server;
32
-
33
- sendToAll() { }
34
-
35
- sendOnly() { }
36
-
37
-
38
- sendRoom() { }
39
-
40
- receive(channel: string) { }
41
-
42
- }
43
-
44
-
45
-
46
-
47
-