@avleon/core 0.0.46 → 0.0.48

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 (142) hide show
  1. package/License +21 -21
  2. package/README.md +666 -666
  3. package/dist/chunk-9hOWP6kD.cjs +64 -0
  4. package/dist/chunk-DORXReHP.js +37 -0
  5. package/dist/index-BxIMWhgy.d.ts +1284 -0
  6. package/dist/index-DPn7qtzq.d.cts +1283 -0
  7. package/dist/index.cjs +3194 -0
  8. package/dist/index.cjs.map +1 -0
  9. package/dist/index.js +3022 -79
  10. package/dist/index.js.map +1 -0
  11. package/dist/lib-Bk8hUm06.cjs +7847 -0
  12. package/dist/lib-Bk8hUm06.cjs.map +1 -0
  13. package/dist/lib-CvDxBMkR.js +7843 -0
  14. package/dist/lib-CvDxBMkR.js.map +1 -0
  15. package/package.json +41 -103
  16. package/dist/application.test.d.ts +0 -1
  17. package/dist/application.test.js +0 -15
  18. package/dist/authentication.d.ts +0 -13
  19. package/dist/authentication.js +0 -16
  20. package/dist/cache.d.ts +0 -12
  21. package/dist/cache.js +0 -78
  22. package/dist/cache.test.d.ts +0 -1
  23. package/dist/cache.test.js +0 -36
  24. package/dist/collection.d.ts +0 -43
  25. package/dist/collection.js +0 -231
  26. package/dist/collection.test.d.ts +0 -1
  27. package/dist/collection.test.js +0 -59
  28. package/dist/config.d.ts +0 -18
  29. package/dist/config.js +0 -58
  30. package/dist/config.test.d.ts +0 -1
  31. package/dist/config.test.js +0 -40
  32. package/dist/constants.d.ts +0 -1
  33. package/dist/constants.js +0 -4
  34. package/dist/container.d.ts +0 -30
  35. package/dist/container.js +0 -55
  36. package/dist/controller.d.ts +0 -50
  37. package/dist/controller.js +0 -71
  38. package/dist/controller.test.d.ts +0 -1
  39. package/dist/controller.test.js +0 -97
  40. package/dist/core/application.d.ts +0 -74
  41. package/dist/core/application.js +0 -424
  42. package/dist/core/router.d.ts +0 -44
  43. package/dist/core/router.js +0 -520
  44. package/dist/core/testing.d.ts +0 -21
  45. package/dist/core/testing.js +0 -104
  46. package/dist/core/types.d.ts +0 -67
  47. package/dist/core/types.js +0 -2
  48. package/dist/decorators.d.ts +0 -15
  49. package/dist/decorators.js +0 -41
  50. package/dist/environment-variables.d.ts +0 -49
  51. package/dist/environment-variables.js +0 -130
  52. package/dist/environment-variables.test.d.ts +0 -1
  53. package/dist/environment-variables.test.js +0 -70
  54. package/dist/event-dispatcher.d.ts +0 -22
  55. package/dist/event-dispatcher.js +0 -97
  56. package/dist/event-subscriber.d.ts +0 -14
  57. package/dist/event-subscriber.js +0 -87
  58. package/dist/exceptions/http-exceptions.d.ts +0 -50
  59. package/dist/exceptions/http-exceptions.js +0 -85
  60. package/dist/exceptions/index.d.ts +0 -1
  61. package/dist/exceptions/index.js +0 -17
  62. package/dist/exceptions/system-exception.d.ts +0 -22
  63. package/dist/exceptions/system-exception.js +0 -26
  64. package/dist/file-storage.d.ts +0 -69
  65. package/dist/file-storage.js +0 -323
  66. package/dist/file-storage.test.d.ts +0 -1
  67. package/dist/file-storage.test.js +0 -117
  68. package/dist/helpers.d.ts +0 -11
  69. package/dist/helpers.js +0 -27
  70. package/dist/helpers.test.d.ts +0 -1
  71. package/dist/helpers.test.js +0 -95
  72. package/dist/index.d.ts +0 -57
  73. package/dist/interfaces/avleon-application.d.ts +0 -75
  74. package/dist/interfaces/avleon-application.js +0 -2
  75. package/dist/kenx-provider.d.ts +0 -7
  76. package/dist/kenx-provider.js +0 -44
  77. package/dist/kenx-provider.test.d.ts +0 -1
  78. package/dist/kenx-provider.test.js +0 -36
  79. package/dist/logger.d.ts +0 -12
  80. package/dist/logger.js +0 -87
  81. package/dist/logger.test.d.ts +0 -1
  82. package/dist/logger.test.js +0 -42
  83. package/dist/map-types.d.ts +0 -17
  84. package/dist/map-types.js +0 -89
  85. package/dist/middleware.d.ts +0 -34
  86. package/dist/middleware.js +0 -73
  87. package/dist/middleware.test.d.ts +0 -1
  88. package/dist/middleware.test.js +0 -121
  89. package/dist/multipart.d.ts +0 -17
  90. package/dist/multipart.js +0 -70
  91. package/dist/multipart.test.d.ts +0 -1
  92. package/dist/multipart.test.js +0 -87
  93. package/dist/openapi.d.ts +0 -410
  94. package/dist/openapi.js +0 -59
  95. package/dist/openapi.test.d.ts +0 -1
  96. package/dist/openapi.test.js +0 -111
  97. package/dist/params.d.ts +0 -17
  98. package/dist/params.js +0 -64
  99. package/dist/params.test.d.ts +0 -1
  100. package/dist/params.test.js +0 -83
  101. package/dist/queue.d.ts +0 -29
  102. package/dist/queue.js +0 -84
  103. package/dist/response.d.ts +0 -16
  104. package/dist/response.js +0 -56
  105. package/dist/results.d.ts +0 -20
  106. package/dist/results.js +0 -32
  107. package/dist/route-methods.d.ts +0 -25
  108. package/dist/route-methods.js +0 -60
  109. package/dist/route-methods.test.d.ts +0 -1
  110. package/dist/route-methods.test.js +0 -129
  111. package/dist/swagger-schema.d.ts +0 -37
  112. package/dist/swagger-schema.js +0 -454
  113. package/dist/swagger-schema.test.d.ts +0 -1
  114. package/dist/swagger-schema.test.js +0 -125
  115. package/dist/types/app-builder.interface.d.ts +0 -15
  116. package/dist/types/app-builder.interface.js +0 -8
  117. package/dist/types/application.interface.d.ts +0 -8
  118. package/dist/types/application.interface.js +0 -2
  119. package/dist/utils/common-utils.d.ts +0 -17
  120. package/dist/utils/common-utils.js +0 -108
  121. package/dist/utils/di-utils.d.ts +0 -1
  122. package/dist/utils/di-utils.js +0 -22
  123. package/dist/utils/hash.d.ts +0 -2
  124. package/dist/utils/hash.js +0 -11
  125. package/dist/utils/index.d.ts +0 -2
  126. package/dist/utils/index.js +0 -18
  127. package/dist/utils/object-utils.d.ts +0 -11
  128. package/dist/utils/object-utils.js +0 -198
  129. package/dist/utils/optional-require.d.ts +0 -8
  130. package/dist/utils/optional-require.js +0 -70
  131. package/dist/utils/validation-utils.d.ts +0 -13
  132. package/dist/utils/validation-utils.js +0 -119
  133. package/dist/validation.d.ts +0 -39
  134. package/dist/validation.js +0 -108
  135. package/dist/validation.test.d.ts +0 -1
  136. package/dist/validation.test.js +0 -61
  137. package/dist/validator-extend.d.ts +0 -7
  138. package/dist/validator-extend.js +0 -28
  139. package/dist/websocket.d.ts +0 -10
  140. package/dist/websocket.js +0 -21
  141. package/dist/websocket.test.d.ts +0 -1
  142. package/dist/websocket.test.js +0 -27
@@ -1,108 +0,0 @@
1
- "use strict";
2
- /**
3
- * @copyright 2024
4
- * @author Tareq Hossain
5
- * @email xtrinsic96@gmail.com
6
- * @url https://github.com/xtareq
7
- */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.Validator = void 0;
10
- exports.validateOrThrow = validateOrThrow;
11
- const exceptions_1 = require("./exceptions");
12
- class PValidationRule {
13
- constructor(name, type, message) {
14
- this.name = name;
15
- this.type = type;
16
- this.message = message;
17
- }
18
- }
19
- class Validator {
20
- constructor(obj, options) {
21
- this.rules = [];
22
- this.options = {};
23
- this.init(obj);
24
- if (options) {
25
- this.options = options;
26
- }
27
- }
28
- init(obj) {
29
- Object.keys(obj).forEach((key) => {
30
- const rule = obj[key];
31
- this.rules.push(new PValidationRule(key, rule.type, rule.message));
32
- });
33
- }
34
- validate(obj, options) {
35
- const erors = [];
36
- this.rules.forEach((k) => {
37
- const r = Object.keys(obj).find((key) => key == k.name);
38
- let messages = [];
39
- if (!r || obj[r] == undefined || obj[r] == "") {
40
- messages.push({
41
- constraint: "required",
42
- message: k.name + " is required",
43
- });
44
- }
45
- if (k.type == "string" && typeof obj[k.name] != "string") {
46
- messages.push({
47
- constraint: "type",
48
- message: `${k.name} must be type ${k.type}`,
49
- });
50
- }
51
- if (k.type == "number" && !parseInt(obj[k.name])) {
52
- messages.push({
53
- constraint: "type",
54
- message: `${k.name} must be type ${k.type}`,
55
- });
56
- }
57
- if (k.type == "number") {
58
- obj[k.name] = parseInt(obj[k.name]);
59
- }
60
- if (k.type == "boolean" && !isBool(obj[k.name])) {
61
- messages.push({
62
- constraint: "type",
63
- message: `${k.name} must be type ${k.type}`,
64
- });
65
- }
66
- if (k.type == "boolean") {
67
- obj[k.name] = parseBoolean(obj[k.name]);
68
- }
69
- if (messages.length > 0) {
70
- erors.push({
71
- path: k.name,
72
- ...(this.options.location ? { location: this.options.location } : {}),
73
- constraints: messages,
74
- });
75
- }
76
- });
77
- return [erors, obj];
78
- }
79
- }
80
- exports.Validator = Validator;
81
- const isBool = (val) => {
82
- if (typeof val == "boolean")
83
- return true;
84
- if (parseInt(val) == 0 || parseInt(val) == 1)
85
- return true;
86
- if (val == "true" || val == "false")
87
- return true;
88
- return false;
89
- };
90
- const parseBoolean = (val) => {
91
- if (typeof val === "boolean")
92
- return val;
93
- if (parseInt(val) == 1)
94
- return true;
95
- if (typeof val === "string") {
96
- const normalized = val.trim().toLowerCase();
97
- return normalized === "true";
98
- }
99
- return false;
100
- };
101
- function validateOrThrow(obj, rules, options) {
102
- const valid = new Validator(rules, options);
103
- const errors = valid.validate(obj);
104
- if (errors[0].length > 0) {
105
- throw new exceptions_1.BadRequestException(errors[0]);
106
- }
107
- return errors[1];
108
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,61 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const validation_1 = require("./validation");
4
- describe("Validator.validate", () => {
5
- const rules = {
6
- username: { type: "string", required: true },
7
- age: { type: "number", required: true },
8
- isActive: { type: "boolean", required: true },
9
- };
10
- it("should pass validation for correct types", () => {
11
- const validator = new validation_1.Validator(rules);
12
- const input = { username: "john", age: 25, isActive: true };
13
- const [errors, validated] = validator.validate(input);
14
- expect(errors).toEqual([]);
15
- expect(validated).toEqual({ username: "john", age: 25, isActive: true });
16
- });
17
- it("should fail when required fields are missing", () => {
18
- const validator = new validation_1.Validator(rules);
19
- const input = { age: 30 };
20
- const [errors] = validator.validate(input);
21
- expect(errors).toEqual(expect.arrayContaining([
22
- expect.objectContaining({ path: "username" }),
23
- expect.objectContaining({ path: "isActive" }),
24
- ]));
25
- });
26
- it("should fail when types are incorrect", () => {
27
- const validator = new validation_1.Validator(rules);
28
- const input = { username: 123, age: "notanumber", isActive: "notabool" };
29
- const [errors] = validator.validate(input);
30
- expect(errors).toEqual(expect.arrayContaining([
31
- expect.objectContaining({ path: "username" }),
32
- expect.objectContaining({ path: "age" }),
33
- expect.objectContaining({ path: "isActive" }),
34
- ]));
35
- });
36
- it("should coerce number and boolean types", () => {
37
- const validator = new validation_1.Validator(rules);
38
- const input = { username: "john", age: "42", isActive: "true" };
39
- const [errors, validated] = validator.validate(input);
40
- expect(errors).toEqual([]);
41
- expect(validated.age).toBe(42);
42
- expect(validated.isActive).toBe(true);
43
- });
44
- it("should handle boolean values as 0/1 and 'true'/'false'", () => {
45
- const validator = new validation_1.Validator(rules);
46
- const input1 = { username: "john", age: 20, isActive: 1 };
47
- const input2 = { username: "john", age: 20, isActive: "false" };
48
- const [errors1, validated1] = validator.validate(input1);
49
- const [errors2, validated2] = validator.validate(input2);
50
- expect(errors1).toEqual([]);
51
- expect(validated1.isActive).toBe(true);
52
- expect(errors2).toEqual([]);
53
- expect(validated2.isActive).toBe(false);
54
- });
55
- it("should include location in error if option is set", () => {
56
- const validator = new validation_1.Validator(rules, { location: "body" });
57
- const input = { age: 30 };
58
- const [errors] = validator.validate(input);
59
- expect(errors[0]).toHaveProperty("location", "body");
60
- });
61
- });
@@ -1,7 +0,0 @@
1
- /**
2
- * @copyright 2024
3
- * @author Tareq Hossain
4
- * @email xtrinsic96@gmail.com
5
- * @url https://github.com/xtareq
6
- */
7
- export declare function IsArrayNotEmpty(validationOptions?: any): (object: Object, propertyName: string) => void;
@@ -1,28 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.IsArrayNotEmpty = IsArrayNotEmpty;
4
- /**
5
- * @copyright 2024
6
- * @author Tareq Hossain
7
- * @email xtrinsic96@gmail.com
8
- * @url https://github.com/xtareq
9
- */
10
- function IsArrayNotEmpty(validationOptions) {
11
- const { registerDecorator, ValidationArguments } = require("class-validator");
12
- return function (object, propertyName) {
13
- registerDecorator({
14
- name: "isArrayWithAtLeastOneElement",
15
- target: object.constructor,
16
- propertyName: propertyName,
17
- options: validationOptions,
18
- validator: {
19
- validate(value, args) {
20
- return Array.isArray(value) && value.length > 0;
21
- },
22
- defaultMessage(args) {
23
- return `${args.property} must contain at least one item.`;
24
- },
25
- },
26
- });
27
- };
28
- }
@@ -1,10 +0,0 @@
1
- import { Server } from "socket.io";
2
- import { Token } from "typedi";
3
- export declare const SocketIoServer: Token<Server<import("socket.io").DefaultEventsMap, import("socket.io").DefaultEventsMap, import("socket.io").DefaultEventsMap, any>>;
4
- export declare class AvleonSocketIo {
5
- private io?;
6
- sendToAll(): void;
7
- sendOnly(): void;
8
- sendRoom(): void;
9
- receive(channel: string): void;
10
- }
package/dist/websocket.js DELETED
@@ -1,21 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.AvleonSocketIo = exports.SocketIoServer = void 0;
10
- const typedi_1 = require("typedi");
11
- exports.SocketIoServer = new typedi_1.Token("SocketIoServer");
12
- let AvleonSocketIo = class AvleonSocketIo {
13
- sendToAll() { }
14
- sendOnly() { }
15
- sendRoom() { }
16
- receive(channel) { }
17
- };
18
- exports.AvleonSocketIo = AvleonSocketIo;
19
- exports.AvleonSocketIo = AvleonSocketIo = __decorate([
20
- (0, typedi_1.Service)()
21
- ], AvleonSocketIo);
@@ -1 +0,0 @@
1
- export {};
@@ -1,27 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const websocket_1 = require("./websocket");
4
- describe("AvleonSocketIo", () => {
5
- let avleonSocketIo;
6
- beforeEach(() => {
7
- avleonSocketIo = new websocket_1.AvleonSocketIo();
8
- });
9
- it("should be defined", () => {
10
- expect(avleonSocketIo).toBeDefined();
11
- });
12
- it("should have sendToAll method", () => {
13
- expect(typeof avleonSocketIo.sendToAll).toBe("function");
14
- });
15
- it("should have sendOnly method", () => {
16
- expect(typeof avleonSocketIo.sendOnly).toBe("function");
17
- });
18
- it("should have sendRoom method", () => {
19
- expect(typeof avleonSocketIo.sendRoom).toBe("function");
20
- });
21
- it("should have receive method", () => {
22
- expect(typeof avleonSocketIo.receive).toBe("function");
23
- });
24
- it("receive should accept a channel string", () => {
25
- expect(() => avleonSocketIo.receive("test-channel")).not.toThrow();
26
- });
27
- });