@forklaunch/core 0.1.1 → 0.1.2

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 (87) hide show
  1. package/.prettierignore +2 -0
  2. package/.prettierrc +6 -0
  3. package/dist/cache/index.d.ts +3 -0
  4. package/dist/cache/index.js +20 -0
  5. package/dist/cache/index.js.map +1 -0
  6. package/dist/cache/interfaces/ttlCache.interface.d.ts +1 -1
  7. package/dist/cache/redisTtlCache.d.ts +3 -2
  8. package/dist/cache/redisTtlCache.js +2 -2
  9. package/dist/cache/redisTtlCache.js.map +1 -1
  10. package/dist/cache/types/{ttlCacheRecord.js → ttlCacheRecord.types.js} +1 -1
  11. package/dist/cache/types/ttlCacheRecord.types.js.map +1 -0
  12. package/dist/controllers/index.d.ts +1 -0
  13. package/dist/controllers/index.js +18 -0
  14. package/dist/controllers/index.js.map +1 -0
  15. package/dist/database/index.d.ts +1 -0
  16. package/dist/database/index.js +18 -0
  17. package/dist/database/index.js.map +1 -0
  18. package/dist/database/mikro/models/entities/base.entity.js +1 -1
  19. package/dist/entityMapper/index.d.ts +2 -0
  20. package/dist/entityMapper/index.js +19 -0
  21. package/dist/entityMapper/index.js.map +1 -0
  22. package/dist/entityMapper/interfaces/entityMapper.interface.d.ts +3 -3
  23. package/dist/entityMapper/models/baseEntityMapper.model.d.ts +23 -23
  24. package/dist/entityMapper/models/baseEntityMapper.model.js +15 -15
  25. package/dist/entityMapper/models/baseEntityMapper.model.js.map +1 -1
  26. package/dist/entityMapper/models/requestEntityMapper.model.d.ts +17 -23
  27. package/dist/entityMapper/models/requestEntityMapper.model.js +13 -19
  28. package/dist/entityMapper/models/requestEntityMapper.model.js.map +1 -1
  29. package/dist/entityMapper/models/responseEntityMapper.model.d.ts +15 -16
  30. package/dist/entityMapper/models/responseEntityMapper.model.js +8 -8
  31. package/dist/entityMapper/models/responseEntityMapper.model.js.map +1 -1
  32. package/dist/entityMapper/types/entityMapper.types.d.ts +3 -22
  33. package/dist/http/index.d.ts +2 -0
  34. package/dist/http/index.js +19 -0
  35. package/dist/http/index.js.map +1 -0
  36. package/dist/http/middlewares/index.d.ts +2 -0
  37. package/dist/http/middlewares/index.js +19 -0
  38. package/dist/http/middlewares/index.js.map +1 -0
  39. package/dist/http/middlewares/request.middleware.d.ts +11 -11
  40. package/dist/http/middlewares/request.middleware.js +23 -21
  41. package/dist/http/middlewares/request.middleware.js.map +1 -1
  42. package/dist/http/middlewares/response.middleware.d.ts +3 -3
  43. package/dist/http/middlewares/response.middleware.js +7 -3
  44. package/dist/http/middlewares/response.middleware.js.map +1 -1
  45. package/dist/http/types/api.types.d.ts +16 -12
  46. package/dist/http/types/index.d.ts +2 -0
  47. package/dist/http/types/index.js +19 -0
  48. package/dist/http/types/index.js.map +1 -0
  49. package/dist/http/types/primitive.types.d.ts +14 -13
  50. package/dist/index.d.ts +6 -1
  51. package/dist/index.js +20 -5
  52. package/dist/index.js.map +1 -1
  53. package/dist/services/index.d.ts +1 -0
  54. package/dist/services/index.js +18 -0
  55. package/dist/services/index.js.map +1 -0
  56. package/dist/services/interfaces/baseService.d.ts +1 -1
  57. package/dist/tests/{dto.test.js → entityMapper.test.js} +10 -32
  58. package/dist/tests/entityMapper.test.js.map +1 -0
  59. package/dist/tests/http.middleware.test.d.ts +1 -0
  60. package/dist/tests/http.middleware.test.js +79 -0
  61. package/dist/tests/http.middleware.test.js.map +1 -0
  62. package/dist/tests/redisTtlCache.test.js +32 -15
  63. package/dist/tests/redisTtlCache.test.js.map +1 -1
  64. package/entityMapper/index.ts +2 -0
  65. package/entityMapper/interfaces/entityMapper.interface.ts +11 -11
  66. package/entityMapper/models/baseEntityMapper.model.ts +90 -73
  67. package/entityMapper/models/requestEntityMapper.model.ts +96 -75
  68. package/entityMapper/models/responseEntityMapper.model.ts +83 -62
  69. package/entityMapper/types/entityMapper.types.ts +6 -23
  70. package/http/index.ts +2 -0
  71. package/http/middlewares/index.ts +2 -0
  72. package/http/middlewares/request.middleware.ts +103 -55
  73. package/http/middlewares/response.middleware.ts +56 -31
  74. package/http/types/api.types.ts +43 -25
  75. package/http/types/index.ts +2 -0
  76. package/http/types/primitive.types.ts +65 -44
  77. package/index.ts +6 -5
  78. package/jest.config.ts +2 -2
  79. package/package.json +13 -4
  80. package/tests/entityMapper.test.ts +219 -0
  81. package/tests/http.middleware.test.ts +99 -0
  82. package/tests/redisTtlCache.test.ts +49 -29
  83. package/dist/cache/types/ttlCacheRecord.js.map +0 -1
  84. package/dist/tests/dto.test.js.map +0 -1
  85. package/tests/dto.test.ts +0 -235
  86. /package/dist/cache/types/{ttlCacheRecord.d.ts → ttlCacheRecord.types.d.ts} +0 -0
  87. /package/dist/tests/{dto.test.d.ts → entityMapper.test.d.ts} +0 -0
@@ -1,42 +1,62 @@
1
+ import { GenericContainer, StartedTestContainer } from 'testcontainers';
1
2
  import { RedisTtlCache } from '../cache/redisTtlCache';
2
3
 
3
4
  describe('RedisTtlCache', () => {
4
- let cache: RedisTtlCache;
5
-
6
- beforeAll(() => {
7
- // Mock the Redis client
8
- // Override the RedisTtlCache's client with the mock client
9
- cache = new RedisTtlCache(5000);
5
+ let container: StartedTestContainer;
6
+ let cache: RedisTtlCache;
7
+ let key: string;
8
+ let value: unknown;
9
+ let ttlMilliseconds: number;
10
+
11
+ beforeAll(async () => {
12
+ container = await new GenericContainer('redis')
13
+ .withExposedPorts(6379)
14
+ .start();
15
+
16
+ cache = new RedisTtlCache(5000, {
17
+ url: `redis://${container.getHost()}:${container.getMappedPort(6379)}`
10
18
  });
11
19
 
12
- afterAll(async () => {
13
- // Ensure the Redis client is disconnected after tests complete
14
- await cache.disconnect();
15
- });
20
+ key = 'testKey';
21
+ value = { data: 'testValue' };
22
+ ttlMilliseconds = 1000;
23
+ }, 30000);
24
+
25
+ afterAll(async () => {
26
+ await cache.disconnect();
27
+ await container.stop();
28
+ });
16
29
 
17
- test('putRecord and readRecord', async () => {
18
- const key = 'testKey';
19
- const value = { data: 'testValue' };
20
- const ttlMilliseconds = 10000; // 10 seconds
30
+ it('PutRecord', async () => {
31
+ await cache.putRecord({ key, value, ttlMilliseconds });
32
+ });
21
33
 
22
- await cache.putRecord({ key, value, ttlMilliseconds });
23
- const storedValue = await cache.readRecord(key);
34
+ test('Read Record', async () => {
35
+ const storedValue = await cache.readRecord(key);
24
36
 
25
- expect(storedValue).toEqual(value);
37
+ expect(storedValue).toEqual({
38
+ key,
39
+ ttlMilliseconds,
40
+ value
26
41
  });
42
+ });
27
43
 
28
- test('peekRecord', async () => {
29
- const key = 'testKey';
30
- const exists = await cache.peekRecord(key);
44
+ test('Peek Record', async () => {
45
+ const exists = await cache.peekRecord(key);
31
46
 
32
- expect(exists).toBeTruthy();
33
- });
47
+ expect(exists).toBeTruthy();
48
+ });
34
49
 
35
- test('deleteRecord', async () => {
36
- const key = 'testKey';
37
- await cache.deleteRecord(key);
38
- const existsAfterDelete = await cache.peekRecord(key);
50
+ test('Delete Record', async () => {
51
+ await cache.deleteRecord(key);
52
+ const existsAfterDelete = await cache.peekRecord(key);
39
53
 
40
- expect(existsAfterDelete).toBeFalsy();
41
- });
42
- });
54
+ expect(existsAfterDelete).toBeFalsy();
55
+ });
56
+
57
+ test('Check No Record', async () => {
58
+ await Promise.resolve(setTimeout(async () => {}, ttlMilliseconds));
59
+ const existsAfterTtl = await cache.peekRecord(key);
60
+ expect(existsAfterTtl).toBeFalsy();
61
+ });
62
+ });
@@ -1 +0,0 @@
1
- {"version":3,"file":"ttlCacheRecord.js","sourceRoot":"","sources":["../../../cache/types/ttlCacheRecord.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"dto.test.js","sourceRoot":"","sources":["../../tests/dto.test.ts"],"names":[],"mappings":";;AACA,2DAAuF;AAEvF,+EAA2E;AAC3E,gGAAuF;AACvF,kGAAyF;AAEzF,MAAM,UAAW,SAAQ,wBAAU;IAC/B,IAAI,CAAS;IACb,GAAG,CAAS;CACf;AAED,MAAM,CAAE,SAA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AAC,CAAC,CAAC"}
package/tests/dto.test.ts DELETED
@@ -1,235 +0,0 @@
1
- import { SchemaValidator } from "@forklaunch/validator/interfaces";
2
- import { TypeboxSchemaValidator, number, string } from "@forklaunch/validator/typebox";
3
- import { TCatchall, TIdiomaticSchema, TUnionContainer } from "@forklaunch/validator/typebox/types";
4
- import { BaseEntity } from "../database/mikro/models/entities/base.entity";
5
- import { RequestEntityMapper } from "../entityMapper/models/requestEntityMapper.model";
6
- import { ResponseEntityMapper } from "../entityMapper/models/responseEntityMapper.model";
7
-
8
- class TestEntity extends BaseEntity {
9
- name: string;
10
- age: number;
11
- }
12
-
13
- class T extends RequestEntityMapper<TestEntity, TypeboxSchemaValidator> {
14
- toEntity(...additionalArgs: unknown[]): TestEntity {
15
- const entity = new TestEntity();
16
- entity.id = this.dto.id;
17
- entity.name = this.dto.name;
18
- entity.age = this.dto.age;
19
-
20
- return entity;
21
- }
22
- schema = {
23
- id: string,
24
- name: string,
25
- age: number
26
- };
27
-
28
- }
29
-
30
- const y = new T(new TypeboxSchemaValidator());
31
- y.fromJson({ id: '123', name: 'test', age: 1 });
32
-
33
- var x = { id: '123', name: 'test', age: 1 };
34
-
35
- type r = typeof x extends T['_dto'] ? true : false;
36
-
37
- T.fromJson(new TypeboxSchemaValidator(), x);
38
- T.fromJson(new TypeboxSchemaValidator(), {
39
- id: '123',
40
- name: 'test',
41
- age: 1
42
- });
43
-
44
- class TestRequestEntityMapper extends RequestEntityMapper<TestEntity, TypeboxSchemaValidator> {
45
- schema = {
46
- id: string,
47
- name: string,
48
- age: number,
49
- };
50
-
51
- toEntity(...additionalArgs: unknown[]): TestEntity {
52
- const entity = new TestEntity();
53
- entity.id = this.dto.id;
54
- entity.name = this.dto.name;
55
- entity.age = this.dto.age;
56
-
57
- return entity;
58
- }
59
- }
60
-
61
- type h = Expand<SchemaValidator>;
62
- type TypeboxSV = SchemaValidator<TUnionContainer, TIdiomaticSchema, TCatchall>;
63
- type y = TypeboxSchemaValidator extends SchemaValidator ? true : false;
64
- type j = TypeboxSV extends SchemaValidator<unknown, unknown, unknown> ? true : false;
65
- type m = TypeboxSV extends TypeboxSchemaValidator ? true : false;
66
- type n = TypeboxSchemaValidator extends TypeboxSV ? true : false;
67
- type k = string extends unknown ? true : false;
68
- type u = Expand<TypeboxSchemaValidator>;
69
- type ExpandRecursively<T> = T extends object
70
- ? T extends infer O ? { [K in keyof O]: ExpandRecursively<O[K]> } : never
71
- : T;
72
- type Expand<T> = T extends infer O ? { [K in keyof O]: O[K] } : never;
73
-
74
-
75
- class TestResponseEntityMapper extends ResponseEntityMapper<TestEntity, TypeboxSchemaValidator> {
76
- schema = {
77
- id: string,
78
- name: string,
79
- age: number
80
- };
81
-
82
- fromEntity(entity: TestEntity): this {
83
- this.dto = {
84
- id: entity.id,
85
- name: entity.name,
86
- age: entity.age
87
- };
88
-
89
- return this;
90
- }
91
- }
92
-
93
- type iii = Expand<TestResponseEntityMapper['schema']>;
94
-
95
- function extractNonTimeBasedEntityFields<T extends BaseEntity>(entity: T): T {
96
- entity.createdAt = new Date(0);
97
- entity.updatedAt = new Date(0);
98
- return entity;
99
- }
100
-
101
- describe('Request Entity Mapper Test', () => {
102
- let TestRequestEM: TestRequestEntityMapper;
103
-
104
-
105
- beforeAll(() => {
106
- TestRequestEM = new TestRequestEntityMapper(new TypeboxSchemaValidator());
107
- });
108
-
109
- test('Schema Equality', async () => {
110
- expect(TestRequestEM.schema).toEqual(TestRequestEntityMapper.schema());
111
- });
112
-
113
- test('From JSON', async () => {
114
- const json = {
115
- id: '123',
116
- name: 'test',
117
- age: 1,
118
- };
119
-
120
- const responseEM = TestRequestEM.fromJson(json);
121
- const staticEM = TestRequestEntityMapper.fromJson(new TypeboxSchemaValidator(), json);
122
- const expectedDto = {
123
- id: '123',
124
- name: 'test',
125
- age: 1,
126
- };
127
-
128
- expect(staticEM.dto).toEqual(expectedDto);
129
- expect(responseEM.dto).toEqual(expectedDto);
130
- expect(responseEM.dto).toEqual(staticEM.dto);
131
- });
132
-
133
- test('Deserialization Equality', async () => {
134
- const json = {
135
- id: '123',
136
- name: 'test',
137
- age: 1,
138
- };
139
-
140
- const entity = extractNonTimeBasedEntityFields(TestRequestEM.deserializeJsonToEntity(json));
141
- const objectEntity = extractNonTimeBasedEntityFields(TestRequestEM.fromJson(json).toEntity());
142
- const staticEntity = extractNonTimeBasedEntityFields(TestRequestEntityMapper.deserializeJsonToEntity(new TypeboxSchemaValidator(), json));
143
- let expectedEntity = new TestEntity();
144
- expectedEntity.id = '123';
145
- expectedEntity.name = 'test';
146
- expectedEntity.age = 1;
147
-
148
- expectedEntity = extractNonTimeBasedEntityFields(expectedEntity);
149
-
150
- expect(entity).toEqual(expectedEntity);
151
- expect(objectEntity).toEqual(expectedEntity);
152
- expect(staticEntity).toEqual(expectedEntity);
153
- expect(entity).toEqual(objectEntity);
154
- expect(entity).toEqual(staticEntity);
155
- expect(staticEntity).toEqual(expectedEntity);
156
- expect(staticEntity).toEqual(objectEntity);
157
- });
158
-
159
- test('Serialization Failure', async () => {
160
- const json = {
161
- id: '123',
162
- name: 'test',
163
- };
164
-
165
- // @ts-expect-error
166
- expect(() => TestRequestEM.fromJson(json)).toThrow();
167
- // @ts-expect-error
168
- expect(() => TestRequestEntityMapper.fromJson(new TypeboxSchemaValidator(), json)).toThrow();
169
- });
170
- });
171
-
172
- describe('Response Entity Mapper Test', () => {
173
- let TestResponseEM: TestResponseEntityMapper;
174
-
175
- beforeAll(() => {
176
- TestResponseEM = new TestResponseEntityMapper(new TypeboxSchemaValidator());
177
- });
178
-
179
- test('Schema Equality', async () => {
180
- expect(TestResponseEM.schema).toEqual(TestResponseEntityMapper.schema());
181
- });
182
-
183
- test('From Entity', async () => {
184
- const entity = new TestEntity();
185
- entity.id = '123';
186
- entity.name = 'test';
187
- entity.age = 1;
188
-
189
- const responseEM = TestResponseEM.fromEntity(entity);
190
- const staticEM = TestResponseEntityMapper.fromEntity(new TypeboxSchemaValidator(), entity);
191
- const expectedDto = {
192
- id: '123',
193
- name: 'test',
194
- age: 1,
195
- };
196
-
197
- expect(staticEM.dto).toEqual(expectedDto);
198
- expect(responseEM.dto).toEqual(expectedDto);
199
- expect(responseEM.dto).toEqual(staticEM.dto);
200
- });
201
-
202
- test('Serialization Equality', async () => {
203
- const entity = new TestEntity();
204
- entity.id = '123';
205
- entity.name = 'test';
206
- entity.age = 1;
207
-
208
- const json = TestResponseEM.serializeEntityToJson(entity);
209
- const objectJson = TestResponseEM.fromEntity(entity).toJson();
210
- const staticJson = TestResponseEntityMapper.serializeEntityToJson(new TypeboxSchemaValidator(), entity);
211
- const expectedJson = {
212
- id: '123',
213
- name: 'test',
214
- age: 1,
215
- };
216
-
217
- expect(json).toEqual(expectedJson);
218
- expect(objectJson).toEqual(expectedJson);
219
- expect(staticJson).toEqual(expectedJson);
220
- expect(json).toEqual(objectJson);
221
- expect(json).toEqual(staticJson);
222
- expect(staticJson).toEqual(expectedJson);
223
- expect(staticJson).toEqual(objectJson);
224
- });
225
-
226
- test('Serialization Failure', async () => {
227
- const entity = new TestEntity();
228
- entity.id = '123';
229
- entity.name = 'test';
230
-
231
- expect(() => TestResponseEM.fromEntity(entity).toJson()).toThrow();
232
- expect(() => TestResponseEntityMapper.fromEntity(new TypeboxSchemaValidator(), entity).toJson()).toThrow();
233
- });
234
- });
235
-