@forklaunch/core 0.1.0
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/dist/cache/interfaces/ttlCache.interface.d.ts +47 -0
- package/dist/cache/interfaces/ttlCache.interface.js +3 -0
- package/dist/cache/interfaces/ttlCache.interface.js.map +1 -0
- package/dist/cache/redisTtlCache.d.ts +64 -0
- package/dist/cache/redisTtlCache.js +105 -0
- package/dist/cache/redisTtlCache.js.map +1 -0
- package/dist/cache/types/ttlCacheRecord.d.ts +13 -0
- package/dist/cache/types/ttlCacheRecord.js +3 -0
- package/dist/cache/types/ttlCacheRecord.js.map +1 -0
- package/dist/controllers/interfaces/controller.interface.d.ts +15 -0
- package/dist/controllers/interfaces/controller.interface.js +3 -0
- package/dist/controllers/interfaces/controller.interface.js.map +1 -0
- package/dist/database/mikro/models/entities/base.entity.d.ts +25 -0
- package/dist/database/mikro/models/entities/base.entity.js +53 -0
- package/dist/database/mikro/models/entities/base.entity.js.map +1 -0
- package/dist/entityMapper/interfaces/entityMapper.interface.d.ts +16 -0
- package/dist/entityMapper/interfaces/entityMapper.interface.js +3 -0
- package/dist/entityMapper/interfaces/entityMapper.interface.js.map +1 -0
- package/dist/entityMapper/models/baseEntityMapper.model.d.ts +71 -0
- package/dist/entityMapper/models/baseEntityMapper.model.js +81 -0
- package/dist/entityMapper/models/baseEntityMapper.model.js.map +1 -0
- package/dist/entityMapper/models/requestEntityMapper.model.d.ts +69 -0
- package/dist/entityMapper/models/requestEntityMapper.model.js +77 -0
- package/dist/entityMapper/models/requestEntityMapper.model.js.map +1 -0
- package/dist/entityMapper/models/responseEntityMapper.model.d.ts +60 -0
- package/dist/entityMapper/models/responseEntityMapper.model.js +64 -0
- package/dist/entityMapper/models/responseEntityMapper.model.js.map +1 -0
- package/dist/entityMapper/types/entityMapper.types.d.ts +28 -0
- package/dist/entityMapper/types/entityMapper.types.js +3 -0
- package/dist/entityMapper/types/entityMapper.types.js.map +1 -0
- package/dist/http/middlewares/request.middleware.d.ts +11 -0
- package/dist/http/middlewares/request.middleware.js +187 -0
- package/dist/http/middlewares/request.middleware.js.map +1 -0
- package/dist/http/middlewares/response.middleware.d.ts +2 -0
- package/dist/http/middlewares/response.middleware.js +30 -0
- package/dist/http/middlewares/response.middleware.js.map +1 -0
- package/dist/http/types/api.types.d.ts +50 -0
- package/dist/http/types/api.types.js +3 -0
- package/dist/http/types/api.types.js.map +1 -0
- package/dist/http/types/primitive.types.d.ts +35 -0
- package/dist/http/types/primitive.types.js +3 -0
- package/dist/http/types/primitive.types.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/jest.config.d.ts +3 -0
- package/dist/jest.config.js.map +1 -0
- package/dist/services/interfaces/baseService.d.ts +14 -0
- package/dist/services/interfaces/baseService.js +3 -0
- package/dist/services/interfaces/baseService.js.map +1 -0
- package/dist/tests/dto.test.d.ts +1 -0
- package/dist/tests/dto.test.js +179 -0
- package/dist/tests/dto.test.js.map +1 -0
- package/dist/tests/redisTtlCache.test.d.ts +1 -0
- package/dist/tests/redisTtlCache.test.js +35 -0
- package/dist/tests/redisTtlCache.test.js.map +1 -0
- package/entityMapper/interfaces/entityMapper.interface.ts +17 -0
- package/entityMapper/models/baseEntityMapper.model.ts +93 -0
- package/entityMapper/models/requestEntityMapper.model.ts +91 -0
- package/entityMapper/models/responseEntityMapper.model.ts +77 -0
- package/entityMapper/types/entityMapper.types.ts +29 -0
- package/eslint.config.mjs +12 -0
- package/http/middlewares/request.middleware.ts +201 -0
- package/http/middlewares/response.middleware.ts +37 -0
- package/http/types/api.types.ts +65 -0
- package/http/types/primitive.types.ts +55 -0
- package/index.ts +5 -0
- package/jest.config.ts +10 -0
- package/package.json +47 -0
- package/tests/dto.test.ts +235 -0
- package/tests/redisTtlCache.test.ts +42 -0
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"baseService.js","sourceRoot":"","sources":["../../../services/interfaces/baseService.ts"],"names":[],"mappings":""}
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,179 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const typebox_1 = require("@forklaunch/validator/typebox");
|
4
|
+
const base_entity_1 = require("../database/mikro/models/entities/base.entity");
|
5
|
+
const requestEntityMapper_model_1 = require("../entityMapper/models/requestEntityMapper.model");
|
6
|
+
const responseEntityMapper_model_1 = require("../entityMapper/models/responseEntityMapper.model");
|
7
|
+
class TestEntity extends base_entity_1.BaseEntity {
|
8
|
+
name;
|
9
|
+
age;
|
10
|
+
}
|
11
|
+
class T extends requestEntityMapper_model_1.RequestEntityMapper {
|
12
|
+
toEntity(...additionalArgs) {
|
13
|
+
const entity = new TestEntity();
|
14
|
+
entity.id = this.dto.id;
|
15
|
+
entity.name = this.dto.name;
|
16
|
+
entity.age = this.dto.age;
|
17
|
+
return entity;
|
18
|
+
}
|
19
|
+
schema = {
|
20
|
+
id: typebox_1.string,
|
21
|
+
name: typebox_1.string,
|
22
|
+
age: typebox_1.number
|
23
|
+
};
|
24
|
+
}
|
25
|
+
const y = new T(new typebox_1.TypeboxSchemaValidator());
|
26
|
+
y.fromJson({ id: '123', name: 'test', age: 1 });
|
27
|
+
var x = { id: '123', name: 'test', age: 1 };
|
28
|
+
T.fromJson(new typebox_1.TypeboxSchemaValidator(), x);
|
29
|
+
T.fromJson(new typebox_1.TypeboxSchemaValidator(), {
|
30
|
+
id: '123',
|
31
|
+
name: 'test',
|
32
|
+
age: 1
|
33
|
+
});
|
34
|
+
class TestRequestEntityMapper extends requestEntityMapper_model_1.RequestEntityMapper {
|
35
|
+
schema = {
|
36
|
+
id: typebox_1.string,
|
37
|
+
name: typebox_1.string,
|
38
|
+
age: typebox_1.number,
|
39
|
+
};
|
40
|
+
toEntity(...additionalArgs) {
|
41
|
+
const entity = new TestEntity();
|
42
|
+
entity.id = this.dto.id;
|
43
|
+
entity.name = this.dto.name;
|
44
|
+
entity.age = this.dto.age;
|
45
|
+
return entity;
|
46
|
+
}
|
47
|
+
}
|
48
|
+
class TestResponseEntityMapper extends responseEntityMapper_model_1.ResponseEntityMapper {
|
49
|
+
schema = {
|
50
|
+
id: typebox_1.string,
|
51
|
+
name: typebox_1.string,
|
52
|
+
age: typebox_1.number
|
53
|
+
};
|
54
|
+
fromEntity(entity) {
|
55
|
+
this.dto = {
|
56
|
+
id: entity.id,
|
57
|
+
name: entity.name,
|
58
|
+
age: entity.age
|
59
|
+
};
|
60
|
+
return this;
|
61
|
+
}
|
62
|
+
}
|
63
|
+
function extractNonTimeBasedEntityFields(entity) {
|
64
|
+
entity.createdAt = new Date(0);
|
65
|
+
entity.updatedAt = new Date(0);
|
66
|
+
return entity;
|
67
|
+
}
|
68
|
+
describe('Request Entity Mapper Test', () => {
|
69
|
+
let TestRequestEM;
|
70
|
+
beforeAll(() => {
|
71
|
+
TestRequestEM = new TestRequestEntityMapper(new typebox_1.TypeboxSchemaValidator());
|
72
|
+
});
|
73
|
+
test('Schema Equality', async () => {
|
74
|
+
expect(TestRequestEM.schema).toEqual(TestRequestEntityMapper.schema());
|
75
|
+
});
|
76
|
+
test('From JSON', async () => {
|
77
|
+
const json = {
|
78
|
+
id: '123',
|
79
|
+
name: 'test',
|
80
|
+
age: 1,
|
81
|
+
};
|
82
|
+
const responseEM = TestRequestEM.fromJson(json);
|
83
|
+
const staticEM = TestRequestEntityMapper.fromJson(new typebox_1.TypeboxSchemaValidator(), json);
|
84
|
+
const expectedDto = {
|
85
|
+
id: '123',
|
86
|
+
name: 'test',
|
87
|
+
age: 1,
|
88
|
+
};
|
89
|
+
expect(staticEM.dto).toEqual(expectedDto);
|
90
|
+
expect(responseEM.dto).toEqual(expectedDto);
|
91
|
+
expect(responseEM.dto).toEqual(staticEM.dto);
|
92
|
+
});
|
93
|
+
test('Deserialization Equality', async () => {
|
94
|
+
const json = {
|
95
|
+
id: '123',
|
96
|
+
name: 'test',
|
97
|
+
age: 1,
|
98
|
+
};
|
99
|
+
const entity = extractNonTimeBasedEntityFields(TestRequestEM.deserializeJsonToEntity(json));
|
100
|
+
const objectEntity = extractNonTimeBasedEntityFields(TestRequestEM.fromJson(json).toEntity());
|
101
|
+
const staticEntity = extractNonTimeBasedEntityFields(TestRequestEntityMapper.deserializeJsonToEntity(new typebox_1.TypeboxSchemaValidator(), json));
|
102
|
+
let expectedEntity = new TestEntity();
|
103
|
+
expectedEntity.id = '123';
|
104
|
+
expectedEntity.name = 'test';
|
105
|
+
expectedEntity.age = 1;
|
106
|
+
expectedEntity = extractNonTimeBasedEntityFields(expectedEntity);
|
107
|
+
expect(entity).toEqual(expectedEntity);
|
108
|
+
expect(objectEntity).toEqual(expectedEntity);
|
109
|
+
expect(staticEntity).toEqual(expectedEntity);
|
110
|
+
expect(entity).toEqual(objectEntity);
|
111
|
+
expect(entity).toEqual(staticEntity);
|
112
|
+
expect(staticEntity).toEqual(expectedEntity);
|
113
|
+
expect(staticEntity).toEqual(objectEntity);
|
114
|
+
});
|
115
|
+
test('Serialization Failure', async () => {
|
116
|
+
const json = {
|
117
|
+
id: '123',
|
118
|
+
name: 'test',
|
119
|
+
};
|
120
|
+
// @ts-expect-error
|
121
|
+
expect(() => TestRequestEM.fromJson(json)).toThrow();
|
122
|
+
// @ts-expect-error
|
123
|
+
expect(() => TestRequestEntityMapper.fromJson(new typebox_1.TypeboxSchemaValidator(), json)).toThrow();
|
124
|
+
});
|
125
|
+
});
|
126
|
+
describe('Response Entity Mapper Test', () => {
|
127
|
+
let TestResponseEM;
|
128
|
+
beforeAll(() => {
|
129
|
+
TestResponseEM = new TestResponseEntityMapper(new typebox_1.TypeboxSchemaValidator());
|
130
|
+
});
|
131
|
+
test('Schema Equality', async () => {
|
132
|
+
expect(TestResponseEM.schema).toEqual(TestResponseEntityMapper.schema());
|
133
|
+
});
|
134
|
+
test('From Entity', async () => {
|
135
|
+
const entity = new TestEntity();
|
136
|
+
entity.id = '123';
|
137
|
+
entity.name = 'test';
|
138
|
+
entity.age = 1;
|
139
|
+
const responseEM = TestResponseEM.fromEntity(entity);
|
140
|
+
const staticEM = TestResponseEntityMapper.fromEntity(new typebox_1.TypeboxSchemaValidator(), entity);
|
141
|
+
const expectedDto = {
|
142
|
+
id: '123',
|
143
|
+
name: 'test',
|
144
|
+
age: 1,
|
145
|
+
};
|
146
|
+
expect(staticEM.dto).toEqual(expectedDto);
|
147
|
+
expect(responseEM.dto).toEqual(expectedDto);
|
148
|
+
expect(responseEM.dto).toEqual(staticEM.dto);
|
149
|
+
});
|
150
|
+
test('Serialization Equality', async () => {
|
151
|
+
const entity = new TestEntity();
|
152
|
+
entity.id = '123';
|
153
|
+
entity.name = 'test';
|
154
|
+
entity.age = 1;
|
155
|
+
const json = TestResponseEM.serializeEntityToJson(entity);
|
156
|
+
const objectJson = TestResponseEM.fromEntity(entity).toJson();
|
157
|
+
const staticJson = TestResponseEntityMapper.serializeEntityToJson(new typebox_1.TypeboxSchemaValidator(), entity);
|
158
|
+
const expectedJson = {
|
159
|
+
id: '123',
|
160
|
+
name: 'test',
|
161
|
+
age: 1,
|
162
|
+
};
|
163
|
+
expect(json).toEqual(expectedJson);
|
164
|
+
expect(objectJson).toEqual(expectedJson);
|
165
|
+
expect(staticJson).toEqual(expectedJson);
|
166
|
+
expect(json).toEqual(objectJson);
|
167
|
+
expect(json).toEqual(staticJson);
|
168
|
+
expect(staticJson).toEqual(expectedJson);
|
169
|
+
expect(staticJson).toEqual(objectJson);
|
170
|
+
});
|
171
|
+
test('Serialization Failure', async () => {
|
172
|
+
const entity = new TestEntity();
|
173
|
+
entity.id = '123';
|
174
|
+
entity.name = 'test';
|
175
|
+
expect(() => TestResponseEM.fromEntity(entity).toJson()).toThrow();
|
176
|
+
expect(() => TestResponseEntityMapper.fromEntity(new typebox_1.TypeboxSchemaValidator(), entity).toJson()).toThrow();
|
177
|
+
});
|
178
|
+
});
|
179
|
+
//# sourceMappingURL=dto.test.js.map
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UAAU,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;QACnE,MAAM,CAAC,GAAG,EAAE,CAAC,wBAAwB,CAAC,UAAU,CAAC,IAAI,gCAAsB,EAAE,EAAE,MAAM,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;IAC/G,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,35 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const redisTtlCache_1 = require("../cache/redisTtlCache");
|
4
|
+
describe('RedisTtlCache', () => {
|
5
|
+
let cache;
|
6
|
+
beforeAll(() => {
|
7
|
+
// Mock the Redis client
|
8
|
+
// Override the RedisTtlCache's client with the mock client
|
9
|
+
cache = new redisTtlCache_1.RedisTtlCache(5000);
|
10
|
+
});
|
11
|
+
afterAll(async () => {
|
12
|
+
// Ensure the Redis client is disconnected after tests complete
|
13
|
+
await cache.disconnect();
|
14
|
+
});
|
15
|
+
test('putRecord and readRecord', async () => {
|
16
|
+
const key = 'testKey';
|
17
|
+
const value = { data: 'testValue' };
|
18
|
+
const ttlMilliseconds = 10000; // 10 seconds
|
19
|
+
await cache.putRecord({ key, value, ttlMilliseconds });
|
20
|
+
const storedValue = await cache.readRecord(key);
|
21
|
+
expect(storedValue).toEqual(value);
|
22
|
+
});
|
23
|
+
test('peekRecord', async () => {
|
24
|
+
const key = 'testKey';
|
25
|
+
const exists = await cache.peekRecord(key);
|
26
|
+
expect(exists).toBeTruthy();
|
27
|
+
});
|
28
|
+
test('deleteRecord', async () => {
|
29
|
+
const key = 'testKey';
|
30
|
+
await cache.deleteRecord(key);
|
31
|
+
const existsAfterDelete = await cache.peekRecord(key);
|
32
|
+
expect(existsAfterDelete).toBeFalsy();
|
33
|
+
});
|
34
|
+
});
|
35
|
+
//# sourceMappingURL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G,SAAS,CAAC;QACtB,MAAM,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;QAC9B,MAAM,iBAAiB,GAAG,MAAM,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;QAEtD,MAAM,CAAC,iBAAiB,CAAC,CAAC,SAAS,EAAE,CAAC;IAC1C,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import { SchemaValidator } from "@forklaunch/validator/interfaces";
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Interface representing a constructor for an entity mapper.
|
5
|
+
*
|
6
|
+
* @template T - The type of the entity mapper.
|
7
|
+
* @interface EntityMapperConstructor
|
8
|
+
*/
|
9
|
+
export interface EntityMapperConstructor<T, SV extends SchemaValidator> {
|
10
|
+
/**
|
11
|
+
* Creates a new instance of the entity mapper.
|
12
|
+
*
|
13
|
+
* @param {SchemaValidator} schemaValidator - The arguments to pass to the constructor.
|
14
|
+
* @returns {T} - A new instance of the entity mapper.
|
15
|
+
*/
|
16
|
+
new (schemaValidator: SV): T;
|
17
|
+
}
|
@@ -0,0 +1,93 @@
|
|
1
|
+
import { SchemaValidator } from "@forklaunch/validator/interfaces";
|
2
|
+
import { EntityMapperConstructor } from "../interfaces/entityMapper.interface";
|
3
|
+
import { EntityMapperSchema, EntityMapperSchemaValidatorObject } from "../types/entityMapper.types";
|
4
|
+
|
5
|
+
/**
|
6
|
+
* Constructs an instance of a EntityMapperType.
|
7
|
+
*
|
8
|
+
* @template EntityMapperType - A type that extends BaseEntityMapper.
|
9
|
+
* @param {EntityMapperConstructor<EntityMapperType>} self - The constructor of the EntityMapperType.
|
10
|
+
* @param {...any[]} args - The arguments to pass to the constructor.
|
11
|
+
* @returns {EntityMapperType} - An instance of the EntityMapperType.
|
12
|
+
*/
|
13
|
+
export function construct<EntityMapperType, SV extends SchemaValidator>(self: EntityMapperConstructor<EntityMapperType, SV>, schemaValidator?: SV): EntityMapperType {
|
14
|
+
return new self(schemaValidator || {} as SV);
|
15
|
+
}
|
16
|
+
|
17
|
+
/**
|
18
|
+
* Abstract class representing a base entityMapper.
|
19
|
+
*
|
20
|
+
* @template SV - A type that extends SchemaValidator.
|
21
|
+
*/
|
22
|
+
export abstract class BaseEntityMapper<SV extends SchemaValidator> {
|
23
|
+
/**
|
24
|
+
* The schema validator.
|
25
|
+
* @type {SV}
|
26
|
+
* @protected
|
27
|
+
*/
|
28
|
+
_SV!: SV;
|
29
|
+
|
30
|
+
/**
|
31
|
+
* The schema provider.
|
32
|
+
* @type {SV}
|
33
|
+
* @protected
|
34
|
+
*/
|
35
|
+
protected schemaValidator: SV;
|
36
|
+
|
37
|
+
/**
|
38
|
+
* The schema definition.
|
39
|
+
* @type {EntityMapperSchemaValidatorObject<SV>}
|
40
|
+
* @abstract
|
41
|
+
*/
|
42
|
+
abstract schema: EntityMapperSchemaValidatorObject<SV>;
|
43
|
+
|
44
|
+
/**
|
45
|
+
* The Data Transfer Object (DTO).
|
46
|
+
* @type {EntityMapperSchema<this['schema'], SV>}
|
47
|
+
*
|
48
|
+
*/
|
49
|
+
_dto: EntityMapperSchema<this['schema'], SV> = {} as unknown as EntityMapperSchema<this['schema'], SV>;
|
50
|
+
|
51
|
+
/**
|
52
|
+
* Creates an instance of BaseEntityMapper.
|
53
|
+
*
|
54
|
+
* @param {SV} schemaValidator - The schema provider.
|
55
|
+
*/
|
56
|
+
constructor(schemaValidator: SV) {
|
57
|
+
this.schemaValidator = schemaValidator;
|
58
|
+
}
|
59
|
+
|
60
|
+
/**
|
61
|
+
* Validates and sets the Data Transfer Object (DTO).
|
62
|
+
*
|
63
|
+
* @param {this['_dto']} dto - The Data Transfer Object (DTO).
|
64
|
+
* @throws {Error} - Throws an error if the DTO is invalid.
|
65
|
+
*/
|
66
|
+
set dto(_dto: this['_dto']) {
|
67
|
+
if (!this.schemaValidator.validate(this.schemaValidator.schemify(this.schema), _dto)) {
|
68
|
+
throw new Error('Invalid DTO');
|
69
|
+
}
|
70
|
+
this._dto = _dto as unknown as EntityMapperSchema<this['schema'], SV>;
|
71
|
+
}
|
72
|
+
|
73
|
+
/**
|
74
|
+
* Validates and gets the Data Transfer Object (DTO).
|
75
|
+
*
|
76
|
+
* @returns {this['_dto']} - The Data Transfer Object (DTO).
|
77
|
+
* @throws {Error} - Throws an error if the DTO is invalid.
|
78
|
+
*/
|
79
|
+
get dto(): this['_dto'] {
|
80
|
+
return this._dto as unknown as this['_dto'];
|
81
|
+
}
|
82
|
+
|
83
|
+
/**
|
84
|
+
* Gets the schema of a EntityMapperType.
|
85
|
+
*
|
86
|
+
* @template EntityMapperType - A type that extends BaseEntityMapper.
|
87
|
+
* @param {EntityMapperConstructor<EntityMapperType>} this - The constructor of the EntityMapperType.
|
88
|
+
* @returns {EntityMapperType['schema']} - The schema of the EntityMapperType.
|
89
|
+
*/
|
90
|
+
static schema<EntityMapperType extends BaseEntityMapper<any>>(this: EntityMapperConstructor<EntityMapperType, EntityMapperType['_SV']>): EntityMapperType['schema'] {
|
91
|
+
return construct(this).schema;
|
92
|
+
}
|
93
|
+
}
|
@@ -0,0 +1,91 @@
|
|
1
|
+
import { SchemaValidator } from "@forklaunch/validator/interfaces";
|
2
|
+
import { BaseEntity } from "../../database/mikro/models/entities/base.entity";
|
3
|
+
import { EntityMapperConstructor } from "../interfaces/entityMapper.interface";
|
4
|
+
import { EntityMapperStaticSchema } from "../types/entityMapper.types";
|
5
|
+
import { BaseEntityMapper, construct } from "./baseEntityMapper.model";
|
6
|
+
|
7
|
+
/**
|
8
|
+
* Abstract class representing a request entityMapper.
|
9
|
+
*
|
10
|
+
* @template Entity - A type that extends BaseEntity.
|
11
|
+
* @template SV - A type that extends SchemaValidator.
|
12
|
+
* @extends {BaseEntityMapper<SV>}
|
13
|
+
*/
|
14
|
+
export abstract class RequestEntityMapper<Entity extends BaseEntity | unknown, SV extends SchemaValidator> extends BaseEntityMapper<SV> {
|
15
|
+
/**
|
16
|
+
* The entity.
|
17
|
+
* @type {Entity}
|
18
|
+
* @protected
|
19
|
+
*/
|
20
|
+
_Entity!: Entity;
|
21
|
+
|
22
|
+
/**
|
23
|
+
* Creates an instance of RequestEntityMapper.
|
24
|
+
*
|
25
|
+
* @param {SV} schemaValidator - The schema provider.
|
26
|
+
*/
|
27
|
+
constructor(schemaValidator: SV) {
|
28
|
+
super(schemaValidator);
|
29
|
+
}
|
30
|
+
|
31
|
+
/**
|
32
|
+
* Converts the underlying DTO to an entity.
|
33
|
+
*
|
34
|
+
* @abstract
|
35
|
+
* @param {...unknown[]} additionalArgs - Additional arguments.
|
36
|
+
* @returns {Entity} - The entity.
|
37
|
+
*/
|
38
|
+
abstract toEntity(...additionalArgs: unknown[]): Entity;
|
39
|
+
|
40
|
+
/**
|
41
|
+
* Populates the DTO with data from a JSON object.
|
42
|
+
*
|
43
|
+
* @param {this['_dto']} json - The JSON object.
|
44
|
+
* @returns {this} - The instance of the RequestEntityMapper.
|
45
|
+
*/
|
46
|
+
fromJson(json: this['_dto']): this {
|
47
|
+
if (!this.schemaValidator.validate(this.schemaValidator.schemify(this.schema), json)) {
|
48
|
+
throw new Error('Invalid DTO');
|
49
|
+
}
|
50
|
+
this.dto = json;
|
51
|
+
return this;
|
52
|
+
}
|
53
|
+
|
54
|
+
/**
|
55
|
+
* Deserializes a JSON object to an entity.
|
56
|
+
*
|
57
|
+
* @param {this['_dto']} json - The JSON object.
|
58
|
+
* @param {...unknown[]} additionalArgs - Additional arguments.
|
59
|
+
* @returns {Entity} - The entity.
|
60
|
+
*/
|
61
|
+
deserializeJsonToEntity(json: this['_dto'], ...additionalArgs: unknown[]): Entity {
|
62
|
+
return this.fromJson(json).toEntity(...additionalArgs);
|
63
|
+
}
|
64
|
+
|
65
|
+
/**
|
66
|
+
* Creates an instance of a RequestEntityMapper from a JSON object.
|
67
|
+
*
|
68
|
+
* @template EntityMapperType - A type that extends RequestEntityMapper.
|
69
|
+
* @param {EntityMapperConstructor<EntityMapperType>} this - The constructor of the EntityMapperType.
|
70
|
+
* @param {EntityMapperType['_SV']} schemaValidator - The schema provider.
|
71
|
+
* @param {EntityMapperStaticSchema<EntityMapperType>} json - The JSON object.
|
72
|
+
* @returns {EntityMapperType} - An instance of the EntityMapperType.
|
73
|
+
*/
|
74
|
+
static fromJson<EntityMapperType extends RequestEntityMapper<unknown, any>>(this: EntityMapperConstructor<EntityMapperType, EntityMapperType['_SV']>, schemaValidator: EntityMapperType['_SV'], json: EntityMapperType['_dto']): EntityMapperType {
|
75
|
+
return construct(this, schemaValidator).fromJson(json as unknown as EntityMapperType['_dto']);
|
76
|
+
}
|
77
|
+
|
78
|
+
/**
|
79
|
+
* Deserializes a JSON object to an entity.
|
80
|
+
*
|
81
|
+
* @template EntityMapperType - A type that extends RequestEntityMapper.
|
82
|
+
* @param {EntityMapperConstructor<EntityMapperType>} this - The constructor of the EntityMapperType.
|
83
|
+
* @param {EntityMapperType['_SV']} schemaValidator - The schema provider.
|
84
|
+
* @param {EntityMapperStaticSchema<EntityMapperType>} json - The JSON object.
|
85
|
+
* @param {...unknown[]} additionalArgs - Additional arguments.
|
86
|
+
* @returns {EntityMapperType['_Entity']} - The entity.
|
87
|
+
*/
|
88
|
+
static deserializeJsonToEntity<EntityMapperType extends RequestEntityMapper<unknown, any>>(this: EntityMapperConstructor<EntityMapperType, EntityMapperType['_SV']>, schemaValidator: EntityMapperType['_SV'], json: EntityMapperType['_dto'], ...additionalArgs: unknown[]): EntityMapperType['_Entity'] {
|
89
|
+
return construct(this, schemaValidator).fromJson(json as EntityMapperType['_dto']).toEntity(...additionalArgs);
|
90
|
+
}
|
91
|
+
}
|
@@ -0,0 +1,77 @@
|
|
1
|
+
import { SchemaValidator } from "@forklaunch/validator/interfaces";
|
2
|
+
import { BaseEntity } from "../../database/mikro/models/entities/base.entity";
|
3
|
+
import { EntityMapperConstructor } from "../interfaces/entityMapper.interface";
|
4
|
+
import { EntityMapperStaticSchema } from "../types/entityMapper.types";
|
5
|
+
import { BaseEntityMapper, construct } from "./baseEntityMapper.model";
|
6
|
+
|
7
|
+
/**
|
8
|
+
* Abstract class representing a response entityMapper.
|
9
|
+
*
|
10
|
+
* @template Entity - A type that extends BaseEntity.
|
11
|
+
* @template SV - A type that extends SchemaValidator.
|
12
|
+
* @extends {BaseEntityMapper<SV>}
|
13
|
+
*/
|
14
|
+
export abstract class ResponseEntityMapper<Entity extends BaseEntity | unknown, SV extends SchemaValidator> extends BaseEntityMapper<SV> {
|
15
|
+
/**
|
16
|
+
* The entity type.
|
17
|
+
* @type {Entity}
|
18
|
+
* @protected
|
19
|
+
*/
|
20
|
+
_Entity!: Entity;
|
21
|
+
|
22
|
+
/**
|
23
|
+
* Populates entityMapper with DTO from an entity.
|
24
|
+
*
|
25
|
+
* @abstract
|
26
|
+
* @param {Entity} entity - The entity to convert.
|
27
|
+
* @returns {this} - The instance of the ResponseEntityMapper.
|
28
|
+
*/
|
29
|
+
abstract fromEntity(entity: Entity, ...additionalArgs: unknown[]): this;
|
30
|
+
|
31
|
+
/**
|
32
|
+
* Converts the underlying DTO to a JSON object.
|
33
|
+
*
|
34
|
+
* @param {...unknown[]} additionalArgs - Additional arguments.
|
35
|
+
* @returns {this['_dto']} - The JSON object.
|
36
|
+
*/
|
37
|
+
toJson(): this['_dto'] {
|
38
|
+
if (!this.schemaValidator.validate(this.schemaValidator.schemify(this.schema), this.dto)) {
|
39
|
+
throw new Error('Invalid DTO');
|
40
|
+
}
|
41
|
+
return this.dto;
|
42
|
+
}
|
43
|
+
|
44
|
+
/**
|
45
|
+
* Serializes an entity to a JSON object.
|
46
|
+
*
|
47
|
+
* @param {Entity} entity - The entity to serialize.
|
48
|
+
* @returns {this['_dto']} - The JSON object.
|
49
|
+
*/
|
50
|
+
serializeEntityToJson(entity: Entity): this['_dto'] {
|
51
|
+
return this.fromEntity(entity).toJson();
|
52
|
+
}
|
53
|
+
|
54
|
+
/**
|
55
|
+
* Populates entityMapper with DTO from an entity.
|
56
|
+
*
|
57
|
+
* @template EntityMapperType - A type that extends ResponseEntityMapper.
|
58
|
+
* @param {EntityMapperConstructor<EntityMapperType>} this - The constructor of the EntityMapperType.
|
59
|
+
* @param {EntityMapperType['_Entity']} entity - The entity to convert.
|
60
|
+
* @returns {EntityMapperType} - An instance of the EntityMapperType.
|
61
|
+
*/
|
62
|
+
static fromEntity<EntityMapperType extends ResponseEntityMapper<unknown, any>>(this: EntityMapperConstructor<EntityMapperType, EntityMapperType['_SV']>, schemaValidator: EntityMapperType['_SV'], entity: EntityMapperType['_Entity']): EntityMapperType {
|
63
|
+
return construct(this, schemaValidator).fromEntity(entity);
|
64
|
+
}
|
65
|
+
|
66
|
+
/**
|
67
|
+
* Serializes an entity to a JSON object.
|
68
|
+
*
|
69
|
+
* @template EntityMapperType - A type that extends ResponseEntityMapper.
|
70
|
+
* @param {EntityMapperConstructor<EntityMapperType>} this - The constructor of the EntityMapperType.
|
71
|
+
* @param {EntityMapperType['_Entity']} entity - The entity to serialize.
|
72
|
+
* @returns {EntityMapperStaticSchema<EntityMapperType>} - The JSON object.
|
73
|
+
*/
|
74
|
+
static serializeEntityToJson<EntityMapperType extends ResponseEntityMapper<unknown, any>>(this: EntityMapperConstructor<EntityMapperType, EntityMapperType['_SV']>, schemaValidator: EntityMapperType['_SV'], entity: EntityMapperType['_Entity']): EntityMapperStaticSchema<EntityMapperType> {
|
75
|
+
return construct(this, schemaValidator).serializeEntityToJson(entity) as EntityMapperStaticSchema<EntityMapperType>;
|
76
|
+
}
|
77
|
+
}
|
@@ -0,0 +1,29 @@
|
|
1
|
+
import { Schema, SchemaCatchall, ValidSchemaObject } from "@forklaunch/validator/";
|
2
|
+
import { SchemaValidator } from "@forklaunch/validator/interfaces";
|
3
|
+
import { UnboxedObjectSchema } from "@forklaunch/validator/types";
|
4
|
+
import { BaseEntityMapper } from "../models/baseEntityMapper.model";
|
5
|
+
|
6
|
+
/**
|
7
|
+
* Type representing a schema validator object for an entity mapper.
|
8
|
+
*
|
9
|
+
* @template SV - A type that extends SchemaValidator.
|
10
|
+
* @typedef {ValidSchemaObject<SV> | UnboxedObjectSchema<SchemaCatchall<SV>> & {}} EntityMapperSchemaValidatorObject
|
11
|
+
*/
|
12
|
+
export type EntityMapperSchemaValidatorObject<SV extends SchemaValidator> = ValidSchemaObject<SV> | UnboxedObjectSchema<SchemaCatchall<SV>>;
|
13
|
+
|
14
|
+
/**
|
15
|
+
* Type representing the static schema of an entity mapper.
|
16
|
+
*
|
17
|
+
* @template T - A type that extends BaseEntityMapper with a schema property.
|
18
|
+
* @typedef {Schema<T['schema'], T['_SV']> & {}} EntityMapperStaticSchema
|
19
|
+
*/
|
20
|
+
export type EntityMapperStaticSchema<T extends BaseEntityMapper<any> & { schema: any }> = Schema<T['schema'], T['_SV']>;
|
21
|
+
|
22
|
+
/**
|
23
|
+
* Type representing the schema of an entity mapper.
|
24
|
+
*
|
25
|
+
* @template T - A type that extends ValidSchemaObject or UnboxedObjectSchema with SchemaCatchall.
|
26
|
+
* @template SV - A type that extends SchemaValidator.
|
27
|
+
* @typedef {Schema<T, SV> & {}} EntityMapperSchema
|
28
|
+
*/
|
29
|
+
export type EntityMapperSchema<T extends ValidSchemaObject<SV> | UnboxedObjectSchema<SchemaCatchall<SV>>, SV extends SchemaValidator> = Schema<T, SV>;
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import pluginJs from "@eslint/js";
|
2
|
+
import globals from "globals";
|
3
|
+
import tseslint from "typescript-eslint";
|
4
|
+
|
5
|
+
|
6
|
+
export default [
|
7
|
+
{files: ["**/*.{ts}"]},
|
8
|
+
{ignores: ["tests/**/*", "dist/**/*", "node_modules/**/*"]},
|
9
|
+
{languageOptions: { globals: globals.browser }},
|
10
|
+
pluginJs.configs.recommended,
|
11
|
+
...tseslint.configs.recommended,
|
12
|
+
];
|