@avleon/core 0.0.40 → 0.0.43

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 (52) hide show
  1. package/README.md +37 -5
  2. package/dist/cache.test.d.ts +1 -0
  3. package/dist/cache.test.js +36 -0
  4. package/dist/controller.d.ts +2 -0
  5. package/dist/controller.js +13 -0
  6. package/dist/controller.test.d.ts +1 -0
  7. package/dist/controller.test.js +111 -0
  8. package/dist/environment-variables.test.d.ts +1 -0
  9. package/dist/environment-variables.test.js +70 -0
  10. package/dist/exceptions/http-exceptions.d.ts +1 -0
  11. package/dist/exceptions/http-exceptions.js +3 -1
  12. package/dist/file-storage.d.ts +44 -9
  13. package/dist/file-storage.js +209 -59
  14. package/dist/file-storage.test.d.ts +1 -0
  15. package/dist/file-storage.test.js +104 -0
  16. package/dist/helpers.test.d.ts +1 -0
  17. package/dist/helpers.test.js +95 -0
  18. package/dist/icore.d.ts +8 -5
  19. package/dist/icore.js +225 -81
  20. package/dist/icore.test.d.ts +1 -0
  21. package/dist/icore.test.js +14 -0
  22. package/dist/index.d.ts +24 -0
  23. package/dist/index.js +8 -1
  24. package/dist/kenx-provider.test.d.ts +1 -0
  25. package/dist/kenx-provider.test.js +36 -0
  26. package/dist/logger.test.d.ts +1 -0
  27. package/dist/logger.test.js +42 -0
  28. package/dist/middleware.test.d.ts +1 -0
  29. package/dist/middleware.test.js +121 -0
  30. package/dist/multipart.test.d.ts +1 -0
  31. package/dist/multipart.test.js +87 -0
  32. package/dist/openapi.test.d.ts +1 -0
  33. package/dist/openapi.test.js +111 -0
  34. package/dist/params.test.d.ts +1 -0
  35. package/dist/params.test.js +83 -0
  36. package/dist/queue.d.ts +16 -14
  37. package/dist/queue.js +76 -63
  38. package/dist/queue.test.d.ts +1 -0
  39. package/dist/queue.test.js +79 -0
  40. package/dist/route-methods.test.d.ts +1 -0
  41. package/dist/route-methods.test.js +129 -0
  42. package/dist/swagger-schema.d.ts +42 -0
  43. package/dist/swagger-schema.js +331 -58
  44. package/dist/swagger-schema.test.d.ts +1 -0
  45. package/dist/swagger-schema.test.js +105 -0
  46. package/dist/validation.d.ts +7 -0
  47. package/dist/validation.js +2 -0
  48. package/dist/validation.test.d.ts +1 -0
  49. package/dist/validation.test.js +61 -0
  50. package/dist/websocket.test.d.ts +1 -0
  51. package/dist/websocket.test.js +27 -0
  52. package/package.json +11 -9
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ require("reflect-metadata");
4
+ const swagger_schema_1 = require("./swagger-schema");
5
+ // Mocks for class-validator metadata
6
+ const mockValidationMetadatas = [
7
+ { propertyName: "name", name: "isNotEmpty", constraints: [] },
8
+ { propertyName: "age", name: "isInt", constraints: [] },
9
+ { propertyName: "email", name: "isEmail", constraints: [] },
10
+ { propertyName: "tags", name: "isOptional", constraints: [] },
11
+ { propertyName: "desc", name: "minLength", constraints: [5] },
12
+ { propertyName: "desc", name: "maxLength", constraints: [100] },
13
+ ];
14
+ const mockGetMetadataStorage = jest.fn(() => ({
15
+ getTargetValidationMetadatas: jest.fn(() => mockValidationMetadatas),
16
+ }));
17
+ jest.mock("class-validator", () => ({
18
+ getMetadataStorage: mockGetMetadataStorage,
19
+ }));
20
+ // Helper to set Reflect metadata for property types and openapi
21
+ function setPropertyMetadata(target, property, type, openApi) {
22
+ Reflect.defineMetadata("design:type", type, target, property);
23
+ if (openApi) {
24
+ Reflect.defineMetadata("property:openapi", openApi, target, property);
25
+ }
26
+ }
27
+ // Test class
28
+ class TestDto {
29
+ }
30
+ setPropertyMetadata(TestDto.prototype, "name", String);
31
+ setPropertyMetadata(TestDto.prototype, "age", Number);
32
+ setPropertyMetadata(TestDto.prototype, "email", String);
33
+ setPropertyMetadata(TestDto.prototype, "tags", Array);
34
+ setPropertyMetadata(TestDto.prototype, "desc", String, { description: "Description", example: "A desc" });
35
+ setPropertyMetadata(TestDto.prototype, "ignored", String, { exclude: true });
36
+ describe("generateSwaggerSchema", () => {
37
+ it("should generate correct schema for class properties and validation", () => {
38
+ const schema = (0, swagger_schema_1.generateSwaggerSchema)(TestDto);
39
+ expect(schema).toEqual({
40
+ type: "object",
41
+ properties: {
42
+ name: { type: "string" },
43
+ age: { type: "integer" },
44
+ email: { type: "string", format: "email" },
45
+ tags: { type: "array", items: { type: "string" } },
46
+ desc: {
47
+ type: "string",
48
+ description: "Description",
49
+ example: "A desc",
50
+ minLength: 5,
51
+ maxLength: 100,
52
+ },
53
+ },
54
+ required: ["name", "age", "email", "desc"],
55
+ });
56
+ expect(schema.properties.ignored).toBeUndefined();
57
+ });
58
+ it("should handle openapi metadata fields", () => {
59
+ setPropertyMetadata(TestDto.prototype, "desc", String, {
60
+ description: "desc field",
61
+ example: "example",
62
+ deprecated: true,
63
+ enum: ["a", "b"],
64
+ format: "custom-format",
65
+ default: "default",
66
+ minimum: 1,
67
+ maximum: 10,
68
+ minLength: 2,
69
+ maxLength: 20,
70
+ pattern: ".*",
71
+ oneOf: [{ type: "string" }],
72
+ allOf: [{ type: "string" }],
73
+ anyOf: [{ type: "string" }],
74
+ });
75
+ const schema = (0, swagger_schema_1.generateSwaggerSchema)(TestDto);
76
+ expect(schema.properties.desc).toMatchObject({
77
+ description: "desc field",
78
+ example: "example",
79
+ deprecated: true,
80
+ enum: ["a", "b"],
81
+ format: "custom-format",
82
+ default: "default",
83
+ minimum: 1,
84
+ maximum: 10,
85
+ minLength: 2,
86
+ maxLength: 20,
87
+ pattern: ".*",
88
+ oneOf: [{ type: "string" }],
89
+ allOf: [{ type: "string" }],
90
+ anyOf: [{ type: "string" }],
91
+ type: "string",
92
+ });
93
+ });
94
+ it("should not include excluded properties", () => {
95
+ setPropertyMetadata(TestDto.prototype, "ignored", String, { exclude: true });
96
+ const schema = (0, swagger_schema_1.generateSwaggerSchema)(TestDto);
97
+ expect(schema.properties.ignored).toBeUndefined();
98
+ });
99
+ it("should fallback to string type if type is unknown", () => {
100
+ setPropertyMetadata(TestDto.prototype, "unknown", undefined);
101
+ mockValidationMetadatas.push({ propertyName: "unknown", name: "isNotEmpty", constraints: [] });
102
+ const schema = (0, swagger_schema_1.generateSwaggerSchema)(TestDto);
103
+ expect(schema.properties.unknown.type).toBe("string");
104
+ });
105
+ });
@@ -28,5 +28,12 @@ export type ValidationProps = {
28
28
  export type ValidateOptons = {
29
29
  location?: "header" | "queryparam" | "param" | "body" | "custom";
30
30
  };
31
+ export declare class Validator {
32
+ private rules;
33
+ private options;
34
+ constructor(obj: ValidationProps, options?: ValidateOptons);
35
+ private init;
36
+ validate(obj: any | Array<any>, options?: ValidateOptons): any[];
37
+ }
31
38
  export declare function validateOrThrow<T extends {}>(obj: T, rules: ValidationProps, options?: ValidateOptons): any;
32
39
  export {};
@@ -6,6 +6,7 @@
6
6
  * @url https://github.com/xtareq
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.Validator = void 0;
9
10
  exports.validateOrThrow = validateOrThrow;
10
11
  const exceptions_1 = require("./exceptions");
11
12
  class PValidationRule {
@@ -76,6 +77,7 @@ class Validator {
76
77
  return [erors, obj];
77
78
  }
78
79
  }
80
+ exports.Validator = Validator;
79
81
  const isBool = (val) => {
80
82
  if (typeof val == "boolean")
81
83
  return true;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,61 @@
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
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,27 @@
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
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@avleon/core",
3
- "version": "0.0.40",
3
+ "version": "0.0.43",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "keywords": [
@@ -25,22 +25,24 @@
25
25
  "dependencies": {
26
26
  "class-transformer": "^0.5.1",
27
27
  "class-validator": "^0.14.2",
28
- "fastify": "^5.6.0",
28
+ "fastify": "^5.1.0",
29
+ "mime": "^4.1.0",
29
30
  "pino": "^9.10.0",
31
+ "pino-pretty": "^13.1.1",
30
32
  "reflect-metadata": "^0.2.2",
31
33
  "typedi": "^0.10.0"
32
34
  },
33
35
  "peerDependencies": {
34
- "@fastify/cors": "*",
35
- "@fastify/multipart": "*",
36
- "@fastify/static": "*",
37
- "@fastify/swagger": "*",
38
- "@fastify/swagger-ui": "*",
39
- "@fastify/view": "*",
36
+ "@fastify/cors": "^11.0.0",
37
+ "@fastify/multipart": "^9.0.3",
38
+ "@fastify/static": "^8.1.1",
39
+ "@fastify/swagger": "^9.4.0",
40
+ "@fastify/swagger-ui": "^5.1.0",
41
+ "@fastify/view": "^11.0.0",
40
42
  "@scalar/fastify-api-reference": "*",
41
43
  "bcryptjs": "3.0.2",
42
44
  "dotenv": "*",
43
- "fastify-socket.io": "*",
45
+ "fastify-socket.io": "^4.0.0",
44
46
  "highlight.js": "*",
45
47
  "ioredis": "*",
46
48
  "knex": "*",