@forklaunch/core 0.1.0 → 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.
- package/.prettierignore +2 -0
- package/.prettierrc +6 -0
- package/dist/cache/index.d.ts +3 -0
- package/dist/cache/index.js +20 -0
- package/dist/cache/index.js.map +1 -0
- package/dist/cache/interfaces/ttlCache.interface.d.ts +1 -1
- package/dist/cache/redisTtlCache.d.ts +3 -2
- package/dist/cache/redisTtlCache.js +2 -2
- package/dist/cache/redisTtlCache.js.map +1 -1
- package/dist/cache/types/{ttlCacheRecord.js → ttlCacheRecord.types.js} +1 -1
- package/dist/cache/types/ttlCacheRecord.types.js.map +1 -0
- package/dist/controllers/index.d.ts +1 -0
- package/dist/controllers/index.js +18 -0
- package/dist/controllers/index.js.map +1 -0
- package/dist/database/index.d.ts +1 -0
- package/dist/database/index.js +18 -0
- package/dist/database/index.js.map +1 -0
- package/dist/database/mikro/models/entities/base.entity.js +1 -1
- package/dist/entityMapper/index.d.ts +2 -0
- package/dist/entityMapper/index.js +19 -0
- package/dist/entityMapper/index.js.map +1 -0
- package/dist/entityMapper/interfaces/entityMapper.interface.d.ts +3 -3
- package/dist/entityMapper/models/baseEntityMapper.model.d.ts +23 -23
- package/dist/entityMapper/models/baseEntityMapper.model.js +17 -17
- package/dist/entityMapper/models/baseEntityMapper.model.js.map +1 -1
- package/dist/entityMapper/models/requestEntityMapper.model.d.ts +17 -23
- package/dist/entityMapper/models/requestEntityMapper.model.js +13 -19
- package/dist/entityMapper/models/requestEntityMapper.model.js.map +1 -1
- package/dist/entityMapper/models/responseEntityMapper.model.d.ts +15 -16
- package/dist/entityMapper/models/responseEntityMapper.model.js +8 -8
- package/dist/entityMapper/models/responseEntityMapper.model.js.map +1 -1
- package/dist/entityMapper/types/entityMapper.types.d.ts +3 -22
- package/dist/http/index.d.ts +2 -0
- package/dist/http/index.js +19 -0
- package/dist/http/index.js.map +1 -0
- package/dist/http/middlewares/index.d.ts +2 -0
- package/dist/http/middlewares/index.js +19 -0
- package/dist/http/middlewares/index.js.map +1 -0
- package/dist/http/middlewares/request.middleware.d.ts +11 -11
- package/dist/http/middlewares/request.middleware.js +32 -31
- package/dist/http/middlewares/request.middleware.js.map +1 -1
- package/dist/http/middlewares/response.middleware.d.ts +3 -2
- package/dist/http/middlewares/response.middleware.js +9 -6
- package/dist/http/middlewares/response.middleware.js.map +1 -1
- package/dist/http/types/api.types.d.ts +16 -13
- package/dist/http/types/index.d.ts +2 -0
- package/dist/http/types/index.js +19 -0
- package/dist/http/types/index.js.map +1 -0
- package/dist/http/types/primitive.types.d.ts +14 -13
- package/dist/index.d.ts +6 -1
- package/dist/index.js +20 -5
- package/dist/index.js.map +1 -1
- package/dist/services/index.d.ts +1 -0
- package/dist/services/index.js +18 -0
- package/dist/services/index.js.map +1 -0
- package/dist/services/interfaces/baseService.d.ts +1 -1
- package/dist/tests/{dto.test.js → entityMapper.test.js} +10 -32
- package/dist/tests/entityMapper.test.js.map +1 -0
- package/dist/tests/http.middleware.test.d.ts +1 -0
- package/dist/tests/http.middleware.test.js +79 -0
- package/dist/tests/http.middleware.test.js.map +1 -0
- package/dist/tests/redisTtlCache.test.js +32 -15
- package/dist/tests/redisTtlCache.test.js.map +1 -1
- package/entityMapper/index.ts +2 -0
- package/entityMapper/interfaces/entityMapper.interface.ts +11 -11
- package/entityMapper/models/baseEntityMapper.model.ts +90 -73
- package/entityMapper/models/requestEntityMapper.model.ts +96 -76
- package/entityMapper/models/responseEntityMapper.model.ts +83 -62
- package/entityMapper/types/entityMapper.types.ts +6 -23
- package/http/index.ts +2 -0
- package/http/middlewares/index.ts +2 -0
- package/http/middlewares/request.middleware.ts +118 -62
- package/http/middlewares/response.middleware.ts +56 -30
- package/http/types/api.types.ts +43 -25
- package/http/types/index.ts +2 -0
- package/http/types/primitive.types.ts +65 -44
- package/index.ts +6 -5
- package/jest.config.ts +2 -2
- package/package.json +13 -4
- package/tests/entityMapper.test.ts +219 -0
- package/tests/http.middleware.test.ts +99 -0
- package/tests/redisTtlCache.test.ts +49 -29
- package/dist/cache/types/ttlCacheRecord.js.map +0 -1
- package/dist/tests/dto.test.js.map +0 -1
- package/tests/dto.test.ts +0 -235
- /package/dist/cache/types/{ttlCacheRecord.d.ts → ttlCacheRecord.types.d.ts} +0 -0
- /package/dist/tests/{dto.test.d.ts → entityMapper.test.d.ts} +0 -0
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
|
-
|
File without changes
|
File without changes
|