@schorts/shared-kernel 4.2.1 → 4.2.3

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 (172) hide show
  1. package/README.md +2 -0
  2. package/dist/cjs/value-objects/array-value.js +8 -0
  3. package/dist/cjs/value-objects/array-value.js.map +1 -1
  4. package/dist/cjs/value-objects/index.js +3 -1
  5. package/dist/cjs/value-objects/index.js.map +1 -1
  6. package/dist/cjs/value-objects/object-value.js +2 -0
  7. package/dist/cjs/value-objects/object-value.js.map +1 -1
  8. package/dist/cjs/value-objects/url-value.js +23 -0
  9. package/dist/cjs/value-objects/url-value.js.map +1 -0
  10. package/dist/esm/value-objects/array-value.js +8 -0
  11. package/dist/esm/value-objects/array-value.js.map +1 -1
  12. package/dist/esm/value-objects/index.js +3 -1
  13. package/dist/esm/value-objects/index.js.map +1 -1
  14. package/dist/esm/value-objects/object-value.js +2 -0
  15. package/dist/esm/value-objects/object-value.js.map +1 -1
  16. package/dist/esm/value-objects/url-value.js +23 -0
  17. package/dist/esm/value-objects/url-value.js.map +1 -0
  18. package/dist/types/value-objects/array-value.d.ts +5 -1
  19. package/dist/types/value-objects/array-value.d.ts.map +1 -1
  20. package/dist/types/value-objects/index.d.ts +1 -0
  21. package/dist/types/value-objects/index.d.ts.map +1 -1
  22. package/dist/types/value-objects/object-value.d.ts +2 -0
  23. package/dist/types/value-objects/object-value.d.ts.map +1 -1
  24. package/dist/types/value-objects/url-value.d.ts +11 -0
  25. package/dist/types/value-objects/url-value.d.ts.map +1 -0
  26. package/package.json +11 -3
  27. package/.idx/airules.md +0 -186
  28. package/.idx/dev.nix +0 -54
  29. package/.vscode/settings.json +0 -7
  30. package/CHANGELOG +0 -363
  31. package/__tests__/auth/auth-provider.test.ts +0 -50
  32. package/__tests__/auth/require-auth.decorator.test.ts +0 -88
  33. package/__tests__/criteria/criteria.test.ts +0 -159
  34. package/__tests__/criteria/direction.test.ts +0 -11
  35. package/__tests__/criteria/filter-criterion.test.ts +0 -15
  36. package/__tests__/criteria/operator.test.ts +0 -22
  37. package/__tests__/criteria/order.test.ts +0 -14
  38. package/__tests__/dao/dao.test.ts +0 -126
  39. package/__tests__/domain-events/domain-event-primitives.test.ts +0 -34
  40. package/__tests__/domain-events/domain-event.test.ts +0 -50
  41. package/__tests__/entities/entity-registry.test.ts +0 -71
  42. package/__tests__/entities/entity.test.ts +0 -114
  43. package/__tests__/entities/register-entity.decorator.test.ts +0 -54
  44. package/__tests__/formatters/pascal-camel-to-snake.test.ts +0 -19
  45. package/__tests__/http/fetch-http-provider.test.ts +0 -155
  46. package/__tests__/http/http-provider.test.ts +0 -55
  47. package/__tests__/json-api/json-api-connector.test.ts +0 -78
  48. package/__tests__/json-api/json-api-list.test.ts +0 -24
  49. package/__tests__/json-api/json-api-single.test.ts +0 -24
  50. package/__tests__/json-api/url-criteria-builder.test.ts +0 -74
  51. package/__tests__/messages/message.test.ts +0 -16
  52. package/__tests__/models/base-model.test.ts +0 -10
  53. package/__tests__/state-manager/state-manager.test.ts +0 -101
  54. package/__tests__/unit-of-work/unit-of-work.test.ts +0 -47
  55. package/__tests__/utils/url/url-with-params-builder.test.ts +0 -39
  56. package/__tests__/value-objects/coordinates-value.test.ts +0 -68
  57. package/__tests__/value-objects/email-value.test.ts +0 -43
  58. package/__tests__/value-objects/enum-value.test.ts +0 -51
  59. package/__tests__/value-objects/integer-value.test.ts +0 -115
  60. package/__tests__/value-objects/phone-value.test.ts +0 -82
  61. package/__tests__/value-objects/slug-value.test.ts +0 -43
  62. package/__tests__/value-objects/string-value.test.ts +0 -121
  63. package/__tests__/value-objects/uuid-value.test.ts +0 -67
  64. package/__tests__/value-objects/value-object.test.ts +0 -25
  65. package/jest.config.js +0 -25
  66. package/src/abac/index.ts +0 -1
  67. package/src/abac/predicate.ts +0 -3
  68. package/src/auth/auth-provider.ts +0 -11
  69. package/src/auth/exceptions/index.ts +0 -2
  70. package/src/auth/exceptions/not-authenticated.ts +0 -11
  71. package/src/auth/exceptions/require-auth-not-implemented-correctly.ts +0 -11
  72. package/src/auth/index.ts +0 -3
  73. package/src/auth/require-auth.decorator.ts +0 -42
  74. package/src/converters/index.ts +0 -1
  75. package/src/converters/remote-file-to-base64.ts +0 -19
  76. package/src/criteria/criteria.ts +0 -46
  77. package/src/criteria/direction.ts +0 -1
  78. package/src/criteria/exceptions/index.ts +0 -2
  79. package/src/criteria/exceptions/limit-not-valid.ts +0 -11
  80. package/src/criteria/exceptions/offset-not-valid.ts +0 -11
  81. package/src/criteria/index.ts +0 -5
  82. package/src/criteria/operator.ts +0 -12
  83. package/src/criteria/order.ts +0 -4
  84. package/src/dao/dao.ts +0 -16
  85. package/src/dao/index.ts +0 -1
  86. package/src/domain-events/domain-event-primitives.ts +0 -10
  87. package/src/domain-events/domain-event-registry.ts +0 -40
  88. package/src/domain-events/domain-event.ts +0 -29
  89. package/src/domain-events/exceptions/domain-event-not-registered.ts +0 -11
  90. package/src/domain-events/exceptions/index.ts +0 -1
  91. package/src/domain-events/index.ts +0 -4
  92. package/src/entities/entity-registry.ts +0 -30
  93. package/src/entities/entity.ts +0 -25
  94. package/src/entities/exceptions/entity-not-registered.ts +0 -11
  95. package/src/entities/exceptions/index.ts +0 -1
  96. package/src/entities/index.ts +0 -4
  97. package/src/entities/register-entity.decorator.ts +0 -16
  98. package/src/event-bus/event-store.ts +0 -9
  99. package/src/event-bus/event-subscriber.ts +0 -5
  100. package/src/event-bus/in-memory/async-in-memory-event-bus.ts +0 -67
  101. package/src/event-bus/in-memory/in-memory-event-store.ts +0 -28
  102. package/src/event-bus/in-memory/index.ts +0 -2
  103. package/src/event-bus/index.ts +0 -3
  104. package/src/formatters/index.ts +0 -1
  105. package/src/formatters/pascal-camel-to-snake.ts +0 -8
  106. package/src/http/exceptions/http-exception.ts +0 -8
  107. package/src/http/exceptions/index.ts +0 -1
  108. package/src/http/fetch-http-provider.ts +0 -151
  109. package/src/http/http-interceptor.ts +0 -3
  110. package/src/http/http-provider.ts +0 -7
  111. package/src/http/index.ts +0 -5
  112. package/src/i18n/index.ts +0 -2
  113. package/src/i18n/shared-kernel-translation-keys.ts +0 -19
  114. package/src/i18n/translation-resolver.ts +0 -3
  115. package/src/index.ts +0 -21
  116. package/src/json-api/exceptions/index.ts +0 -1
  117. package/src/json-api/exceptions/json-api-errors.ts +0 -17
  118. package/src/json-api/index.ts +0 -5
  119. package/src/json-api/json-api-connector.ts +0 -97
  120. package/src/json-api/json-api-list.ts +0 -13
  121. package/src/json-api/json-api-single.ts +0 -13
  122. package/src/json-api/url-criteria-builder.ts +0 -49
  123. package/src/messages/index.ts +0 -1
  124. package/src/messages/message.ts +0 -3
  125. package/src/models/base-model.ts +0 -3
  126. package/src/models/index.ts +0 -1
  127. package/src/pub-sub/index.ts +0 -2
  128. package/src/pub-sub/publisher.ts +0 -3
  129. package/src/pub-sub/subscription.ts +0 -6
  130. package/src/rbac/base-resource.ts +0 -3
  131. package/src/rbac/exceptions/index.ts +0 -1
  132. package/src/rbac/exceptions/not-authorized.ts +0 -1
  133. package/src/rbac/index.ts +0 -5
  134. package/src/rbac/permission.ts +0 -4
  135. package/src/rbac/rbac-policy.ts +0 -41
  136. package/src/result/index.ts +0 -1
  137. package/src/result/result.ts +0 -35
  138. package/src/state-manager/in-memory-state-manager.ts +0 -22
  139. package/src/state-manager/index.ts +0 -3
  140. package/src/state-manager/session-storage-state-manager.ts +0 -47
  141. package/src/state-manager/state-manager.ts +0 -28
  142. package/src/telemetry/console-telemetry.ts +0 -27
  143. package/src/telemetry/index.ts +0 -2
  144. package/src/telemetry/telemetry.ts +0 -5
  145. package/src/unit-of-work/index.ts +0 -1
  146. package/src/unit-of-work/unit-of-work.ts +0 -5
  147. package/src/utils/index.ts +0 -2
  148. package/src/utils/url/index.ts +0 -1
  149. package/src/utils/url/url-with-params-builder.ts +0 -19
  150. package/src/utils/value-objects/index.ts +0 -1
  151. package/src/utils/value-objects/rule.ts +0 -3
  152. package/src/value-objects/array-value.ts +0 -92
  153. package/src/value-objects/boolean-value.ts +0 -23
  154. package/src/value-objects/coordinates-value.ts +0 -50
  155. package/src/value-objects/date-value.ts +0 -36
  156. package/src/value-objects/email-value.ts +0 -25
  157. package/src/value-objects/enum-value.ts +0 -27
  158. package/src/value-objects/exceptions/index.ts +0 -2
  159. package/src/value-objects/exceptions/value-not-valid.ts +0 -3
  160. package/src/value-objects/exceptions/values-not-valid.ts +0 -11
  161. package/src/value-objects/float-valuet.ts +0 -39
  162. package/src/value-objects/index.ts +0 -17
  163. package/src/value-objects/integer-value.ts +0 -29
  164. package/src/value-objects/object-value.ts +0 -84
  165. package/src/value-objects/phone-value.ts +0 -53
  166. package/src/value-objects/slug-value.ts +0 -25
  167. package/src/value-objects/string-value.ts +0 -27
  168. package/src/value-objects/uuid-value.ts +0 -34
  169. package/src/value-objects/value-object.ts +0 -7
  170. package/tsconfig.cjs.json +0 -13
  171. package/tsconfig.esm.json +0 -12
  172. package/tsconfig.json +0 -47
@@ -1,55 +0,0 @@
1
- import { expectTypeOf } from "expect-type";
2
-
3
- import { HTTPProvider } from "../../src/http";
4
-
5
- describe('HTTPProvider', () => {
6
- describe('#get', () => {
7
- it('should receive an URL', () => {
8
- expectTypeOf<HTTPProvider["get"]>().parameters.toEqualTypeOf<[URL]>();
9
- });
10
-
11
- it('should return a Promise<ResponseType>', () => {
12
- expectTypeOf<HTTPProvider["get"]>().returns.toEqualTypeOf<Promise<unknown>>();
13
- });
14
- });
15
-
16
- describe('#post', () => {
17
- it('should receive an URL and a body', () => {
18
- expectTypeOf<HTTPProvider["post"]>().parameters.toEqualTypeOf<[URL, unknown]>();
19
- });
20
-
21
- it('should return a Promise<ResponseType>', () => {
22
- expectTypeOf<HTTPProvider["post"]>().returns.toEqualTypeOf<Promise<unknown>>();
23
- });
24
- });
25
-
26
- describe('#put', () => {
27
- it('should receive an URL and a body', () => {
28
- expectTypeOf<HTTPProvider["put"]>().parameters.toEqualTypeOf<[URL, unknown]>();
29
- });
30
-
31
- it('should return a Promise<ResponseType>', () => {
32
- expectTypeOf<HTTPProvider["put"]>().returns.toEqualTypeOf<Promise<unknown>>();
33
- });
34
- });
35
-
36
- describe('#patch', () => {
37
- it('should receive an URL and a body', () => {
38
- expectTypeOf<HTTPProvider["patch"]>().parameters.toEqualTypeOf<[URL, unknown]>();
39
- });
40
-
41
- it('should return a Promise<ResponseType>', () => {
42
- expectTypeOf<HTTPProvider["patch"]>().returns.toEqualTypeOf<Promise<unknown>>();
43
- });
44
- });
45
-
46
- describe('#delete', () => {
47
- it('should receive an URL', () => {
48
- expectTypeOf<HTTPProvider["delete"]>().parameters.toEqualTypeOf<[URL]>();
49
- });
50
-
51
- it('should return a Promise<ResponseType>', () => {
52
- expectTypeOf<HTTPProvider["delete"]>().returns.toEqualTypeOf<Promise<unknown>>();
53
- });
54
- });
55
- });
@@ -1,78 +0,0 @@
1
- import { JSONAPIConnector } from "../../src/json-api";
2
- import { Criteria } from "../../src/criteria";
3
- import type { HTTPProvider } from "../../src/http";
4
-
5
- describe("JSONAPIConnector", () => {
6
- const base = new URL("https://api.example.com/users");
7
- let http: jest.Mocked<HTTPProvider>;
8
- let connector: JSONAPIConnector;
9
-
10
- beforeEach(() => {
11
- http = {
12
- get: jest.fn(),
13
- post: jest.fn(),
14
- patch: jest.fn(),
15
- put: jest.fn(),
16
- delete: jest.fn(),
17
- };
18
- connector = new JSONAPIConnector(http);
19
- });
20
-
21
- it("calls findOne with correct URL and criteria", async () => {
22
- const criteria = new Criteria().where("status", "EQUAL", "active");
23
- const include = ["roles"];
24
-
25
- await connector.findOne(base, criteria, include);
26
-
27
- expect(http.get).toHaveBeenCalledWith(expect.any(URL));
28
-
29
- const calledUrl = http.get.mock.calls[0][0];
30
-
31
- expect(calledUrl.searchParams.get("filter[status]")).toBe("active");
32
- expect(calledUrl.href).toContain("include=roles");
33
- });
34
-
35
- it("calls findMany with sorting and pagination", async () => {
36
- const criteria = new Criteria()
37
- .orderBy("createdAt", "DESC")
38
- .limitResults(10)
39
- .offsetResults(20);
40
-
41
- await connector.findMany(base, criteria);
42
-
43
- const calledUrl = http.get.mock.calls[0][0];
44
-
45
- expect(calledUrl.href).toContain("sort=-createdAt");
46
- expect(calledUrl.searchParams.get("page[limit]")).toBe("10");
47
- expect(calledUrl.searchParams.get("page[offset]")).toBe("20");
48
- });
49
-
50
- it("calls create with correct payload", async () => {
51
- const payload = {
52
- type: "users",
53
- attributes: { name: "Jorge", email: "jorge@example.com" },
54
- };
55
-
56
- await connector.create(base, payload);
57
-
58
- expect(http.post).toHaveBeenCalledWith(base, { data: payload });
59
- });
60
-
61
- it("calls update with correct payload", async () => {
62
- const payload = {
63
- id: "123",
64
- type: "users",
65
- attributes: { name: "Jorge Updated" },
66
- };
67
-
68
- await connector.update(base, payload);
69
-
70
- expect(http.patch).toHaveBeenCalledWith(base, { data: payload });
71
- });
72
-
73
- it("calls delete with correct URL", async () => {
74
- await connector.delete(base);
75
-
76
- expect(http.delete).toHaveBeenCalledWith(base);
77
- });
78
- });
@@ -1,24 +0,0 @@
1
- import { expectTypeOf } from "expect-type";
2
-
3
- import { JSONAPIList } from "../../src/json-api";
4
- import { BaseModel } from "../../src/models";
5
-
6
- type ExpectedJSONAPIList<EntityAttributes> = {
7
- data: Array<{
8
- id: string;
9
- type: string;
10
- attributes: Omit<EntityAttributes, "id">;
11
- }>;
12
- included?: Array<{
13
- id: string;
14
- type: string;
15
- attributes: Record<string, any>;
16
- }>;
17
- meta?: Record<string, any>;
18
- };
19
-
20
- describe('JSONAPIList', () => {
21
- it('should match the expected schema', () => {
22
- expectTypeOf<JSONAPIList<BaseModel>>().toEqualTypeOf<ExpectedJSONAPIList<BaseModel>>()
23
- });
24
- });
@@ -1,24 +0,0 @@
1
- import { expectTypeOf } from "expect-type";
2
-
3
- import { JSONAPISingle } from "../../src/json-api";
4
- import { BaseModel } from "../../src/models";
5
-
6
- type ExpectedJSONAPISingle<EntityAttributes> = {
7
- data: {
8
- id: string;
9
- type: string;
10
- attributes: Omit<EntityAttributes, "id">;
11
- };
12
- included?: Array<{
13
- id: string;
14
- type: string;
15
- attributes: Omit<Record<string, any>, "id">;
16
- }>;
17
- meta?: Record<string, any>;
18
- };
19
-
20
- describe('JSONAPISingle', () => {
21
- it('should match the expected schema', () => {
22
- expectTypeOf<JSONAPISingle<BaseModel>>().toEqualTypeOf<ExpectedJSONAPISingle<BaseModel>>()
23
- });
24
- });
@@ -1,74 +0,0 @@
1
- import { URLCriteriaBuilder } from "../../src/json-api";
2
- import { Criteria } from "../../src/criteria";
3
-
4
- const base = new URL("https://api.example.com/resources");
5
-
6
- describe("URLCriteriaBuilder", () => {
7
- it("encodes EQUAL filters as filter[field]=value", () => {
8
- const criteria = new Criteria().where("status", "EQUAL", "active");
9
- const url = new URLCriteriaBuilder(base, criteria).build();
10
-
11
- expect(url.searchParams.get("filter[status]")).toBe("active");
12
- });
13
-
14
- it("encodes IN filters as comma-separated values", () => {
15
- const criteria = new Criteria().where("role", "IN", ["admin", "editor"]);
16
- const url = new URLCriteriaBuilder(base, criteria).build();
17
-
18
- expect(url.searchParams.get("filter[role]")).toBe("admin,editor");
19
- });
20
-
21
- it("encodes other operators as filter[field][operator]=value", () => {
22
- const criteria = new Criteria().where("createdAt", "GREATER_THAN", "2023-01-01");
23
- const url = new URLCriteriaBuilder(base, criteria).build();
24
-
25
- expect(url.searchParams.get("filter[createdAt][GREATER_THAN]")).toBe("2023-01-01");
26
- });
27
-
28
- it("supports nested filters using dot notation", () => {
29
- const criteria = new Criteria().where("roles.name", "EQUAL", "admin");
30
- const url = new URLCriteriaBuilder(base, criteria).build();
31
-
32
- expect(url.searchParams.get("filter[roles.name]")).toBe("admin");
33
- });
34
-
35
- it("encodes sorting correctly", () => {
36
- const criteria = new Criteria()
37
- .orderBy("createdAt", "DESC")
38
- .orderBy("name", "ASC");
39
- const url = new URLCriteriaBuilder(base, criteria).build();
40
-
41
- expect(url.searchParams.get("sort")).toBe("-createdAt,name");
42
- });
43
-
44
- it("encodes pagination correctly", () => {
45
- const criteria = new Criteria().limitResults(20).offsetResults(40);
46
- const url = new URLCriteriaBuilder(base, criteria).build();
47
-
48
- expect(url.searchParams.get("page[limit]")).toBe("20");
49
- expect(url.searchParams.get("page[offset]")).toBe("40");
50
- });
51
-
52
- it("adds include parameters", () => {
53
- const url = new URLCriteriaBuilder(base, undefined, ["roles", "permissions"]).build();
54
-
55
- expect(url.searchParams.getAll("include")).toEqual(["roles", "permissions"]);
56
- });
57
-
58
- it("builds full query with filters, sort, pagination, and includes", () => {
59
- const criteria = new Criteria()
60
- .where("status", "EQUAL", "active")
61
- .where("roles.name", "EQUAL", "admin")
62
- .orderBy("createdAt", "DESC")
63
- .limitResults(10)
64
- .offsetResults(30);
65
- const url = new URLCriteriaBuilder(base, criteria, ["roles"]).build();
66
-
67
- expect(url.searchParams.get("filter[status]")).toBe("active");
68
- expect(url.searchParams.get("filter[roles.name]")).toBe("admin");
69
- expect(url.searchParams.get("sort")).toBe("-createdAt");
70
- expect(url.searchParams.get("page[limit]")).toBe("10");
71
- expect(url.searchParams.get("page[offset]")).toBe("30");
72
- expect(url.searchParams.getAll("include")).toEqual(["roles"]);
73
- });
74
- });
@@ -1,16 +0,0 @@
1
- import { expectTypeOf } from "expect-type";
2
-
3
- import { Message } from "../../src/messages";
4
-
5
- type MessagePrimitives = {
6
- id: string;
7
- };
8
-
9
- describe("Message", () => {
10
- it('should declare a "toPrimitives" method', () => {
11
- expectTypeOf<Message>().toHaveProperty('toPrimitives');
12
- expectTypeOf<Message['toPrimitives']>().toBeFunction();
13
- expectTypeOf<Message<MessagePrimitives>['toPrimitives']>().returns.toEqualTypeOf<MessagePrimitives>();
14
- });
15
- });
16
-
@@ -1,10 +0,0 @@
1
- import { expectTypeOf } from "expect-type";
2
-
3
- import { BaseModel } from "../../src/models";
4
-
5
- describe("BaseModel", () => {
6
- it('should have a "id" property of type string or number', () => {
7
- expectTypeOf<BaseModel>().toHaveProperty("id");
8
- expectTypeOf<BaseModel['id']>().toEqualTypeOf<string | number>();
9
- });
10
- });
@@ -1,101 +0,0 @@
1
- import { expectTypeOf } from "expect-type";
2
-
3
- import { StateManager } from "../../src/state-manager";
4
-
5
- type Schema = {
6
- name: string;
7
- };
8
-
9
- describe("StateManager", () => {
10
- it('should have a "state" property of the provided Schema', () => {
11
- expectTypeOf<StateManager<Schema>["state"]>().toEqualTypeOf<Schema>();
12
- });
13
-
14
- it('should have a "listeners" property of type Array<(state: Schema) => void>', () => {
15
- expectTypeOf<StateManager<Schema>["listeners"]>().toEqualTypeOf<Array<(state: Schema) => void>>();
16
- });
17
-
18
- describe('#getValue', () => {
19
- it('should define the function', () => {
20
- expectTypeOf<StateManager<Schema>["getValue"]>().toBeFunction();
21
- });
22
-
23
- it('should receive a key of Schema', () => {
24
- expectTypeOf<StateManager<Schema>["getValue"]>().parameters.toEqualTypeOf<[keyof Schema]>();
25
- });
26
-
27
- it('should return a Promise with a value from the Schema', () => {
28
- expectTypeOf<StateManager<Schema>["getValue"]>().returns.toEqualTypeOf<Promise<Schema[keyof Schema]>>();
29
- });
30
- });
31
-
32
- describe('#setValue', () => {
33
- it('should define the function', () => {
34
- expectTypeOf<StateManager<Schema>["setValue"]>().toBeFunction();
35
- });
36
-
37
- it('should receive a key of Schema and the value to set', () => {
38
- expectTypeOf<StateManager<Schema>["setValue"]>().parameters.toEqualTypeOf<[keyof Schema, Schema[keyof Schema]]>();
39
- });
40
-
41
- it('should return a void Promise', () => {
42
- expectTypeOf<StateManager<Schema>["setValue"]>().returns.toEqualTypeOf<Promise<void>>();
43
- });
44
- });
45
-
46
- describe('#removeValue', () => {
47
- it('should define the function', () => {
48
- expectTypeOf<StateManager<Schema>["removeValue"]>().toBeFunction();
49
- });
50
-
51
- it('should receive a key of Schema', () => {
52
- expectTypeOf<StateManager<Schema>["removeValue"]>().parameters.toEqualTypeOf<[keyof Schema]>();
53
- });
54
-
55
- it('should return a Promise with a value from the Schema', () => {
56
- expectTypeOf<StateManager<Schema>["removeValue"]>().returns.toEqualTypeOf<Promise<void>>();
57
- });
58
- });
59
-
60
- describe('#getState', () => {
61
- it('should define the function', () => {
62
- expectTypeOf<StateManager<Schema>["getState"]>().toBeFunction();
63
- });
64
-
65
- it('should receive no params', () => {
66
- expectTypeOf<StateManager<Schema>["getState"]>().parameters.toEqualTypeOf<[]>();
67
- });
68
-
69
- it('should return the value with Schema as type', () => {
70
- expectTypeOf<StateManager<Schema>["getState"]>().returns.toEqualTypeOf<Schema>();
71
- });
72
- });
73
-
74
- describe('#subscribe', () => {
75
- it('should define the function', () => {
76
- expectTypeOf<StateManager<Schema>["subscribe"]>().toBeFunction();
77
- });
78
-
79
- it('should receive a function of type (state: Schema) => void', () => {
80
- expectTypeOf<StateManager<Schema>["subscribe"]>().parameters.toEqualTypeOf<[(state: Schema) => void]>();
81
- });
82
-
83
- it('should return a void function', () => {
84
- expectTypeOf<StateManager<Schema>["subscribe"]>().returns.toEqualTypeOf<() => void>();
85
- });
86
- });
87
-
88
- describe('#notifyListeners', () => {
89
- it('should define the function', () => {
90
- expectTypeOf<StateManager<Schema>["notifyListeners"]>().toBeFunction();
91
- });
92
-
93
- it('should receive no params', () => {
94
- expectTypeOf<StateManager<Schema>["notifyListeners"]>().parameters.toEqualTypeOf<[]>();
95
- });
96
-
97
- it('should return a void function', () => {
98
- expectTypeOf<StateManager<Schema>["notifyListeners"]>().returns.toEqualTypeOf<void>();
99
- });
100
- });
101
- });
@@ -1,47 +0,0 @@
1
- import { expectTypeOf } from "expect-type";
2
-
3
- import { UnitOfWork } from "../../src/unit-of-work";
4
-
5
- describe("UnitOfWork", () => {
6
- describe('#begin', () => {
7
- it('should declare the method', () => {
8
- expectTypeOf<UnitOfWork>().toHaveProperty("begin");
9
- });
10
-
11
- it('should no require any arguments', () => {
12
- expectTypeOf<UnitOfWork['begin']>().parameters.toEqualTypeOf<[]>();
13
- });
14
-
15
- it('should return a promise', () => {
16
- expectTypeOf<UnitOfWork['begin']>().returns.toEqualTypeOf<Promise<void>>();
17
- });
18
- })
19
-
20
- describe('#commit', () => {
21
- it('should declare the method', () => {
22
- expectTypeOf<UnitOfWork>().toHaveProperty("commit");
23
- });
24
-
25
- it('should no require any arguments', () => {
26
- expectTypeOf<UnitOfWork['commit']>().parameters.toEqualTypeOf<[]>();
27
- });
28
-
29
- it('should return a promise', () => {
30
- expectTypeOf<UnitOfWork['commit']>().returns.toEqualTypeOf<Promise<void>>();
31
- });
32
- })
33
-
34
- describe('#rollback', () => {
35
- it('should declare the method', () => {
36
- expectTypeOf<UnitOfWork>().toHaveProperty("rollback");
37
- });
38
-
39
- it('should no require any arguments', () => {
40
- expectTypeOf<UnitOfWork['rollback']>().parameters.toEqualTypeOf<[]>();
41
- });
42
-
43
- it('should return a promise', () => {
44
- expectTypeOf<UnitOfWork['rollback']>().returns.toEqualTypeOf<Promise<void>>();
45
- });
46
- })
47
- });
@@ -1,39 +0,0 @@
1
- import { expectTypeOf } from "expect-type";
2
-
3
- import { URLWithParamsBuilder } from "../../../src/utils";
4
-
5
- const baseURL = 'https://github.com/schorts';
6
- const url = new URL(baseURL);
7
-
8
- describe('URLWithParamsBuilder', () => {
9
- it('should have a "base" property of type URL', () => {
10
- expectTypeOf<URLWithParamsBuilder["base"]>().toEqualTypeOf<URL>();
11
- });
12
-
13
- describe('#with', () => {
14
- it('should receive a params with type Record<string, string | number | boolean | string[] | number[]>', () => {
15
- expectTypeOf<URLWithParamsBuilder["with"]>().parameters.toEqualTypeOf<[Record<string, string | number | boolean | string[] | number[]>]>();
16
- });
17
-
18
- it('should return the same instance', () => {
19
- const uRLWithParamsBuilder = new URLWithParamsBuilder(url);
20
- const result = uRLWithParamsBuilder.with({ page: 1 });
21
-
22
- expect(result).toEqual(uRLWithParamsBuilder);
23
- });
24
- });
25
-
26
- describe('#build', () => {
27
- it('should receive no params', () => {
28
- expectTypeOf<URLWithParamsBuilder["build"]>().parameters.toEqualTypeOf<[]>();
29
- });
30
-
31
- it('should return the updated url', () => {
32
- const uRLWithParamsBuilder = new URLWithParamsBuilder(url);
33
- const expectedURL = new URL(`${baseURL}?page=1`);
34
- const result = uRLWithParamsBuilder.with({ page: 1 }).build();
35
-
36
- expect(result.href).toEqual(expectedURL.href);
37
- });
38
- });
39
- });
@@ -1,68 +0,0 @@
1
- import { expectTypeOf } from "expect-type";
2
-
3
- import { ValueObject, CoordinatesValue } from "../../src/value-objects";
4
-
5
- class TestCoordinatesValue extends CoordinatesValue {
6
- readonly attributeName = "test";
7
- }
8
-
9
- describe("CoordinatesValue", () => {
10
- it('should implement "ValueObject" interface', () => {
11
- expectTypeOf<CoordinatesValue>().toExtend<ValueObject>();
12
- });
13
-
14
- it('should have a "valueType" with "Coordinates" as value', () => {
15
- const testCoordinatesValue = new TestCoordinatesValue({ latitude: 0, longitude: 0 });
16
-
17
- expect(testCoordinatesValue.valueType).toEqual("Coordinates");
18
- });
19
-
20
- it('should have a "value" property of type { latitude: number, longitude: number }', () => {
21
- expectTypeOf<CoordinatesValue["value"]>().toMatchObjectType<{ latitude: number, longitude: number }>();
22
- });
23
-
24
- it('should have a "latitude" property of type number or null', () => {
25
- expectTypeOf<CoordinatesValue["latitude"]>().toEqualTypeOf<number | null>();
26
- });
27
-
28
- it('should have a "longitude" property of type number or null', () => {
29
- expectTypeOf<CoordinatesValue["longitude"]>().toEqualTypeOf<number | null>();
30
- });
31
-
32
- it('should define the "equals" method', () => {
33
- expectTypeOf<CoordinatesValue["equals"]>().toEqualTypeOf<(valueObject: unknown) => boolean>();
34
- });
35
-
36
- describe('when "value" is a valid coordinate', () => {
37
- const coordinates = { latitude: 0, longitude: 0 };
38
- const testCoordinatesValue = new TestCoordinatesValue(coordinates);
39
-
40
- it('should return true the "isValid" getter', () => {
41
- expect(testCoordinatesValue.isValid).toBeTruthy();
42
- });
43
-
44
- it('should return the latitude value', () => {
45
- expect(testCoordinatesValue.latitude).toEqual(coordinates.latitude);
46
- });
47
-
48
- it('should return the longitude value', () => {
49
- expect(testCoordinatesValue.longitude).toEqual(coordinates.longitude);
50
- });
51
- });
52
-
53
- describe('when "value" is not a valid coordinate', () => {
54
- const testCoordinatesValue = new TestCoordinatesValue({ latitude: -200, longitude: 500 });
55
-
56
- it('should return false the "isValid" getter', () => {
57
- expect(testCoordinatesValue.isValid).toBeFalsy();
58
- });
59
-
60
- it('should return null as the latitude value', () => {
61
- expect(testCoordinatesValue.latitude).toBeNull();
62
- });
63
-
64
- it('should return null as the longitude value', () => {
65
- expect(testCoordinatesValue.longitude).toBeNull();
66
- });
67
- });
68
- });
@@ -1,43 +0,0 @@
1
- import { expectTypeOf } from "expect-type";
2
-
3
- import { ValueObject, EmailValue } from "../../src/value-objects";
4
-
5
- class TestEmailValue extends EmailValue {
6
- readonly attributeName = "test";
7
- }
8
-
9
- describe("EmailValue", () => {
10
- it('should implement "ValueObject" interface', () => {
11
- expectTypeOf<EmailValue>().toExtend<ValueObject>();
12
- });
13
-
14
- it('should have a "valueType" with "Email" as value', () => {
15
- const testEmailValue = new TestEmailValue("");
16
-
17
- expect(testEmailValue.valueType).toEqual("Email");
18
- });
19
-
20
- it('should have a "value" property of type string', () => {
21
- expectTypeOf<EmailValue["value"]>().toBeString();
22
- });
23
-
24
- it('should define the "equals" method', () => {
25
- expectTypeOf<EmailValue["equals"]>().toEqualTypeOf<(valueObject: unknown) => boolean>();
26
- });
27
-
28
- describe('when "value" is an email', () => {
29
- it('should return true the "isValid" getter', () => {
30
- const testEmailValue = new TestEmailValue("test@example.com");
31
-
32
- expect(testEmailValue.isValid).toBeTruthy();
33
- });
34
- });
35
-
36
- describe('when "value" is not an email', () => {
37
- it('should return false the "isValid" getter', () => {
38
- const testEmailValue = new TestEmailValue("test@com");
39
-
40
- expect(testEmailValue.isValid).toBeFalsy();
41
- });
42
- });
43
- });
@@ -1,51 +0,0 @@
1
- import { expectTypeOf } from "expect-type";
2
-
3
- import { ValueObject, EnumValue } from "../../src/value-objects";
4
-
5
- class TestEnumValue extends EnumValue {
6
- readonly attributeName = "test";
7
- }
8
-
9
- describe("EnumValue", () => {
10
- it('should implement "ValueObject" interface', () => {
11
- expectTypeOf<TestEnumValue>().toExtend<ValueObject>();
12
- });
13
-
14
- it('should have a "valueType" with "Enum" as value', () => {
15
- const testEnumValue = new TestEnumValue([], "");
16
-
17
- expect(testEnumValue.valueType).toEqual("Enum");
18
- });
19
-
20
- it('should have a "value" property of type string', () => {
21
- expectTypeOf<EnumValue["value"]>().toBeString();
22
- });
23
-
24
- it('should have a "allowedValues" property of type string[]', () => {
25
- expectTypeOf<EnumValue["allowedValues"]>().toBeArray();
26
- });
27
-
28
- it('should have a "allowedTypes" property of type string', () => {
29
- expectTypeOf<EnumValue["attributeName"]>().toBeString;
30
- });
31
-
32
- it('should define the "equals" method', () => {
33
- expectTypeOf<EnumValue["equals"]>().toEqualTypeOf<(valueObject: unknown) => boolean>();
34
- });
35
-
36
- describe('when value is in the "allowedTypes" property', () => {
37
- it('should return true on the "isValid" getter', () => {
38
- const testEnumValue = new TestEnumValue(["test"], "test");
39
-
40
- expect(testEnumValue.isValid).toBeTruthy();
41
- });
42
- });
43
-
44
- describe('when value is not in the "allowedTypes" property', () => {
45
- it('should return true on the "isValid" getter', () => {
46
- const testEnumValue = new TestEnumValue(["test"], "test2");
47
-
48
- expect(testEnumValue.isValid).toBeFalsy();
49
- });
50
- });
51
- });