@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.
- 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 +15 -15
- 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 +23 -21
- package/dist/http/middlewares/request.middleware.js.map +1 -1
- package/dist/http/middlewares/response.middleware.d.ts +3 -3
- package/dist/http/middlewares/response.middleware.js +7 -3
- package/dist/http/middlewares/response.middleware.js.map +1 -1
- package/dist/http/types/api.types.d.ts +16 -12
- 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 -75
- 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 +103 -55
- package/http/middlewares/response.middleware.ts +56 -31
- 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
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"entityMapper.test.js","sourceRoot":"","sources":["../../tests/entityMapper.test.ts"],"names":[],"mappings":";;AAAA,2DAIuC;AACvC,+EAA2E;AAC3E,gGAAuF;AACvF,kGAAyF;AAEzF,MAAM,UAAW,SAAQ,wBAAU;IACjC,IAAI,CAAS;IACb,GAAG,CAAS;CACb;AAED,MAAM,uBAAwB,SAAQ,+CAGrC;IACC,MAAM,GAAG;QACP,EAAE,EAAE,gBAAM;QACV,IAAI,EAAE,gBAAM;QACZ,GAAG,EAAE,gBAAM;KACZ,CAAC;IAEF,QAAQ,CAAC,GAAG,cAAyB;QACnC,MAAM,MAAM,GAAG,IAAI,UAAU,EAAE,CAAC;QAChC,MAAM,CAAC,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;QACxB,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC;QAC5B,MAAM,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;QAE1B,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AAED,MAAM,wBAAyB,SAAQ,iDAGtC;IACC,MAAM,GAAG;QACP,EAAE,EAAE,gBAAM;QACV,IAAI,EAAE,gBAAM;QACZ,GAAG,EAAE,gBAAM;KACZ,CAAC;IAEF,UAAU,CAAC,MAAkB;QAC3B,IAAI,CAAC,GAAG,GAAG;YACT,EAAE,EAAE,MAAM,CAAC,EAAE;YACb,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,GAAG,EAAE,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,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QACjC,MAAM,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QACjC,MAAM,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;QACzC,MAAM,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IACzC,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,uBAAuB,EAAE,KAAK,IAAI,EAAE;QACvC,MAAM,MAAM,GAAG,IAAI,UAAU,EAAE,CAAC;QAChC,MAAM,CAAC,EAAE,GAAG,KAAK,CAAC;QAClB,MAAM,CAAC,IAAI,GAAG,MAAM,CAAC;QAErB,MAAM,CAAC,GAAG,EAAE,CAAC,cAAc,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;QACnE,MAAM,CAAC,GAAG,EAAE,CACV,wBAAwB,CAAC,UAAU,CACjC,IAAI,gCAAsB,EAAE,EAC5B,MAAM,CACP,CAAC,MAAM,EAAE,CACX,CAAC,OAAO,EAAE,CAAC;IACd,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,79 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const mockSchemaValidator_1 = require("@forklaunch/validator/tests/mockSchemaValidator");
|
4
|
+
const http_1 = require("../http");
|
5
|
+
describe('Http Middleware Tests', () => {
|
6
|
+
let contractDetails;
|
7
|
+
let req;
|
8
|
+
let resp;
|
9
|
+
const nextFunction = (err) => {
|
10
|
+
expect(err).toBeFalsy();
|
11
|
+
};
|
12
|
+
const testSchema = {
|
13
|
+
test: (0, mockSchemaValidator_1.union)(['a', (0, mockSchemaValidator_1.optional)((0, mockSchemaValidator_1.literal)('test'))])
|
14
|
+
};
|
15
|
+
beforeAll(() => {
|
16
|
+
contractDetails = {
|
17
|
+
name: 'Test Contract',
|
18
|
+
summary: 'Test Contract Summary',
|
19
|
+
body: testSchema,
|
20
|
+
params: testSchema,
|
21
|
+
requestHeaders: testSchema,
|
22
|
+
query: testSchema,
|
23
|
+
responses: {
|
24
|
+
200: testSchema
|
25
|
+
}
|
26
|
+
};
|
27
|
+
req = {
|
28
|
+
context: {},
|
29
|
+
contractDetails: {},
|
30
|
+
schemaValidator: {},
|
31
|
+
params: testSchema,
|
32
|
+
headers: testSchema,
|
33
|
+
body: testSchema,
|
34
|
+
query: testSchema
|
35
|
+
};
|
36
|
+
resp = {
|
37
|
+
bodyData: {},
|
38
|
+
statusCode: 200,
|
39
|
+
corked: false,
|
40
|
+
getHeaders: jest.fn(),
|
41
|
+
setHeader: jest.fn(),
|
42
|
+
status: jest.fn(),
|
43
|
+
send: jest.fn(),
|
44
|
+
json: jest.fn(),
|
45
|
+
jsonp: jest.fn(),
|
46
|
+
};
|
47
|
+
});
|
48
|
+
test('Create Request Context', async () => {
|
49
|
+
req.context = {};
|
50
|
+
req.schemaValidator = {};
|
51
|
+
(0, http_1.createRequestContext)(mockSchemaValidator_1.mockSchemaValidator)(req, resp, nextFunction);
|
52
|
+
expect(req.context.correlationId).not.toBe('123');
|
53
|
+
expect(req.schemaValidator).toBe(mockSchemaValidator_1.mockSchemaValidator);
|
54
|
+
});
|
55
|
+
test('Enrich Request Details', async () => {
|
56
|
+
req.contractDetails = {};
|
57
|
+
(0, http_1.enrichRequestDetails)(contractDetails)(req, resp, nextFunction);
|
58
|
+
expect(req.contractDetails).toEqual(contractDetails);
|
59
|
+
});
|
60
|
+
test('Validate Request Params', async () => {
|
61
|
+
(0, http_1.parseRequestParams)(req, resp, nextFunction);
|
62
|
+
});
|
63
|
+
test('Validate Request Headers', async () => {
|
64
|
+
(0, http_1.parseRequestHeaders)(req, resp, nextFunction);
|
65
|
+
});
|
66
|
+
test('Validate Request Body', async () => {
|
67
|
+
(0, http_1.parseRequestBody)(req, resp, nextFunction);
|
68
|
+
});
|
69
|
+
test('Validate Request Query Params', async () => {
|
70
|
+
(0, http_1.parseRequestQuery)(req, resp, nextFunction);
|
71
|
+
});
|
72
|
+
test('Validate Response', async () => {
|
73
|
+
(0, http_1.parseResponse)(req, resp, nextFunction);
|
74
|
+
});
|
75
|
+
// Not supported yet
|
76
|
+
// test('Validate Auth', async () => {
|
77
|
+
// });
|
78
|
+
});
|
79
|
+
//# sourceMappingURL=http.middleware.test.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"http.middleware.test.js","sourceRoot":"","sources":["../../tests/http.middleware.test.ts"],"names":[],"mappings":";;AACA,yFAMyD;AACzD,kCAA8O;AAE9O,QAAQ,CAAC,uBAAuB,EAAE,GAAG,EAAE;IACnC,IAAI,eAAyD,CAAC;IAC9D,IAAI,GAA2C,CAAC;IAChD,IAAI,IAAwB,CAAC;IAE7B,MAAM,YAAY,GAAG,CAAC,GAAa,EAAE,EAAE;QACnC,MAAM,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,CAAA;IAC3B,CAAC,CAAC;IAEF,MAAM,UAAU,GAAG;QACf,IAAI,EAAE,IAAA,2BAAK,EAAC,CAAC,GAAG,EAAE,IAAA,8BAAQ,EAAC,IAAA,6BAAO,EAAC,MAAM,CAAC,CAAC,CAAU,CAAC;KACzD,CAAC;IAEF,SAAS,CAAC,GAAG,EAAE;QACX,eAAe,GAAG;YACd,IAAI,EAAE,eAAe;YACrB,OAAO,EAAE,uBAAuB;YAChC,IAAI,EAAE,UAAU;YAChB,MAAM,EAAE,UAAU;YAClB,cAAc,EAAE,UAAU;YAC1B,KAAK,EAAE,UAAU;YACjB,SAAS,EAAE;gBACP,GAAG,EAAE,UAAU;aAClB;SACJ,CAAC;QAEF,GAAG,GAAG;YACF,OAAO,EAAE,EAAoB;YAC7B,eAAe,EAAE,EAA8C;YAC/D,eAAe,EAAE,EAAqB;YACtC,MAAM,EAAE,UAAU;YAClB,OAA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AAkB,EAAC,GAAG,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC;IAChD,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,0BAA0B,EAAE,KAAK,IAAI,EAAE;QACxC,IAAA,0BAAmB,EAAC,GAAG,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC;IACjD,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,uBAAuB,EAAE,KAAK,IAAI,EAAE;QACrC,IAAA,uBAAgB,EAAC,GAAG,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC;IAC9C,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,+BAA+B,EAAE,KAAK,IAAI,EAAE;QAC7C,IAAA,wBAAiB,EAAC,GAAG,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC;IAC/C,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,mBAAmB,EAAE,KAAK,IAAI,EAAE;QACjC,IAAA,oBAAa,EAAC,GAAG,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC;IAC3C,CAAC,CAAC,CAAC;IAEH,oBAAoB;IACpB,sCAAsC;IACtC,MAAM;AACV,CAAC,CAAC,CAAC"}
|
@@ -1,35 +1,52 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const testcontainers_1 = require("testcontainers");
|
3
4
|
const redisTtlCache_1 = require("../cache/redisTtlCache");
|
4
5
|
describe('RedisTtlCache', () => {
|
6
|
+
let container;
|
5
7
|
let cache;
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
let key;
|
9
|
+
let value;
|
10
|
+
let ttlMilliseconds;
|
11
|
+
beforeAll(async () => {
|
12
|
+
container = await new testcontainers_1.GenericContainer('redis')
|
13
|
+
.withExposedPorts(6379)
|
14
|
+
.start();
|
15
|
+
cache = new redisTtlCache_1.RedisTtlCache(5000, {
|
16
|
+
url: `redis://${container.getHost()}:${container.getMappedPort(6379)}`
|
17
|
+
});
|
18
|
+
key = 'testKey';
|
19
|
+
value = { data: 'testValue' };
|
20
|
+
ttlMilliseconds = 1000;
|
21
|
+
}, 30000);
|
11
22
|
afterAll(async () => {
|
12
|
-
// Ensure the Redis client is disconnected after tests complete
|
13
23
|
await cache.disconnect();
|
24
|
+
await container.stop();
|
14
25
|
});
|
15
|
-
|
16
|
-
const key = 'testKey';
|
17
|
-
const value = { data: 'testValue' };
|
18
|
-
const ttlMilliseconds = 10000; // 10 seconds
|
26
|
+
it('PutRecord', async () => {
|
19
27
|
await cache.putRecord({ key, value, ttlMilliseconds });
|
28
|
+
});
|
29
|
+
test('Read Record', async () => {
|
20
30
|
const storedValue = await cache.readRecord(key);
|
21
|
-
expect(storedValue).toEqual(
|
31
|
+
expect(storedValue).toEqual({
|
32
|
+
key,
|
33
|
+
ttlMilliseconds,
|
34
|
+
value
|
35
|
+
});
|
22
36
|
});
|
23
|
-
test('
|
24
|
-
const key = 'testKey';
|
37
|
+
test('Peek Record', async () => {
|
25
38
|
const exists = await cache.peekRecord(key);
|
26
39
|
expect(exists).toBeTruthy();
|
27
40
|
});
|
28
|
-
test('
|
29
|
-
const key = 'testKey';
|
41
|
+
test('Delete Record', async () => {
|
30
42
|
await cache.deleteRecord(key);
|
31
43
|
const existsAfterDelete = await cache.peekRecord(key);
|
32
44
|
expect(existsAfterDelete).toBeFalsy();
|
33
45
|
});
|
46
|
+
test('Check No Record', async () => {
|
47
|
+
await Promise.resolve(setTimeout(async () => { }, ttlMilliseconds));
|
48
|
+
const existsAfterTtl = await cache.peekRecord(key);
|
49
|
+
expect(existsAfterTtl).toBeFalsy();
|
50
|
+
});
|
34
51
|
});
|
35
52
|
//# sourceMappingURL=redisTtlCache.test.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"redisTtlCache.test.js","sourceRoot":"","sources":["../../tests/redisTtlCache.test.ts"],"names":[],"mappings":";;AAAA,0DAAuD;AAEvD,QAAQ,CAAC,eAAe,EAAE,GAAG,EAA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CAAC;YAC1B,GAAG;YACH,eAAe;YACf,KAAK;SACN,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,aAAa,EAAE,KAAK,IAAI,EAAE;QAC7B,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;QAE3C,MAAM,CAAC,MAAM,CAAC,CAAC,UAAU,EAAE,CAAC;IAC9B,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,eAAe,EAAE,KAAK,IAAI,EAAE;QAC/B,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;IACxC,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,iBAAiB,EAAE,KAAK,IAAI,EAAE;QACjC,MAAM,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,IAAI,EAAE,GAAE,CAAC,EAAE,eAAe,CAAC,CAAC,CAAC;QACnE,MAAM,cAAc,GAAG,MAAM,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;QACnD,MAAM,CAAC,cAAc,CAAC,CAAC,SAAS,EAAE,CAAC;IACrC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
@@ -1,17 +1,17 @@
|
|
1
|
-
import {
|
1
|
+
import { AnySchemaValidator } from '@forklaunch/validator';
|
2
2
|
|
3
3
|
/**
|
4
4
|
* Interface representing a constructor for an entity mapper.
|
5
|
-
*
|
5
|
+
*
|
6
6
|
* @template T - The type of the entity mapper.
|
7
7
|
* @interface EntityMapperConstructor
|
8
8
|
*/
|
9
|
-
export interface EntityMapperConstructor<T, SV extends
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
}
|
9
|
+
export interface EntityMapperConstructor<T, SV extends AnySchemaValidator> {
|
10
|
+
/**
|
11
|
+
* Creates a new instance of the entity mapper.
|
12
|
+
*
|
13
|
+
* @param {AnySchemaValidator} 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
|
+
}
|
@@ -1,17 +1,24 @@
|
|
1
|
-
import {
|
2
|
-
|
3
|
-
|
1
|
+
import {
|
2
|
+
AnySchemaValidator,
|
3
|
+
Schema,
|
4
|
+
SchemaValidator
|
5
|
+
} from '@forklaunch/validator';
|
6
|
+
import { EntityMapperConstructor } from '../interfaces/entityMapper.interface';
|
7
|
+
import { EntityMapperSchemaValidatorObject } from '../types/entityMapper.types';
|
4
8
|
|
5
9
|
/**
|
6
|
-
* Constructs an instance of a
|
10
|
+
* Constructs an instance of a T.
|
7
11
|
*
|
8
|
-
* @template
|
9
|
-
* @param {EntityMapperConstructor<
|
12
|
+
* @template T - A type that extends BaseEntityMapper.
|
13
|
+
* @param {EntityMapperConstructor<T>} self - The constructor of the T.
|
10
14
|
* @param {...any[]} args - The arguments to pass to the constructor.
|
11
|
-
* @returns {
|
15
|
+
* @returns {T} - An instance of the T.
|
12
16
|
*/
|
13
|
-
export function construct<
|
14
|
-
|
17
|
+
export function construct<T, SV extends AnySchemaValidator>(
|
18
|
+
self: EntityMapperConstructor<T, SV>,
|
19
|
+
schemaValidator?: SV
|
20
|
+
): T {
|
21
|
+
return new self(schemaValidator || ({} as SV));
|
15
22
|
}
|
16
23
|
|
17
24
|
/**
|
@@ -19,75 +26,85 @@ export function construct<EntityMapperType, SV extends SchemaValidator>(self: En
|
|
19
26
|
*
|
20
27
|
* @template SV - A type that extends SchemaValidator.
|
21
28
|
*/
|
22
|
-
export abstract class BaseEntityMapper<SV extends
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
+
export abstract class BaseEntityMapper<SV extends AnySchemaValidator> {
|
30
|
+
/**
|
31
|
+
* The schema validator exact type.
|
32
|
+
* @type {SV}
|
33
|
+
* @protected
|
34
|
+
*/
|
35
|
+
_SV!: SV;
|
29
36
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
37
|
+
/**
|
38
|
+
* The schema validator as a general type.
|
39
|
+
* @type {SchemaValidator}
|
40
|
+
* @protected
|
41
|
+
*/
|
42
|
+
protected schemaValidator: SchemaValidator;
|
36
43
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
44
|
+
/**
|
45
|
+
* The schema definition.
|
46
|
+
* @type {EntityMapperSchemaValidatorObject<SV>}
|
47
|
+
* @abstract
|
48
|
+
*/
|
49
|
+
abstract schema: EntityMapperSchemaValidatorObject<SV>;
|
43
50
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
51
|
+
/**
|
52
|
+
* The Data Transfer Object (DTO).
|
53
|
+
* @type {Schema<this['schema'], SV>}
|
54
|
+
*
|
55
|
+
*/
|
56
|
+
_dto: Schema<this['schema'], SV> = {} as unknown as Schema<
|
57
|
+
this['schema'],
|
58
|
+
SV
|
59
|
+
>;
|
50
60
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
61
|
+
/**
|
62
|
+
* Creates an instance of BaseEntityMapper.
|
63
|
+
*
|
64
|
+
* @param {SV} schemaValidator - The schema provider.
|
65
|
+
*/
|
66
|
+
constructor(schemaValidator: SV) {
|
67
|
+
this.schemaValidator = schemaValidator as unknown as SchemaValidator;
|
68
|
+
}
|
59
69
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
70
|
+
/**
|
71
|
+
* Validates and sets the Data Transfer Object (DTO).
|
72
|
+
*
|
73
|
+
* @param {this['_dto']} dto - The Data Transfer Object (DTO).
|
74
|
+
* @throws {Error} - Throws an error if the DTO is invalid.
|
75
|
+
*/
|
76
|
+
set dto(_dto: this['_dto']) {
|
77
|
+
if (
|
78
|
+
!this.schemaValidator.validate(
|
79
|
+
this.schemaValidator.schemify(this.schema),
|
80
|
+
_dto
|
81
|
+
)
|
82
|
+
) {
|
83
|
+
throw new Error('Invalid DTO');
|
71
84
|
}
|
85
|
+
this._dto = _dto as unknown as Schema<this['schema'], SV>;
|
86
|
+
}
|
72
87
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
88
|
+
/**
|
89
|
+
* Validates and gets the Data Transfer Object (DTO).
|
90
|
+
*
|
91
|
+
* @returns {this['_dto']} - The Data Transfer Object (DTO).
|
92
|
+
* @throws {Error} - Throws an error if the DTO is invalid.
|
93
|
+
*/
|
94
|
+
get dto(): this['_dto'] {
|
95
|
+
return this._dto as unknown as this['_dto'];
|
96
|
+
}
|
82
97
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
98
|
+
/**
|
99
|
+
* Gets the schema of a T.
|
100
|
+
*
|
101
|
+
* @template T - A type that extends BaseEntityMapper.
|
102
|
+
* @param {EntityMapperConstructor<T>} this - The constructor of the T.
|
103
|
+
* @returns {T['schema']} - The schema of the T.
|
104
|
+
*/
|
105
|
+
static schema<T extends BaseEntityMapper<SV>, SV extends AnySchemaValidator>(
|
106
|
+
this: EntityMapperConstructor<T, SV>
|
107
|
+
): T['schema'] {
|
108
|
+
return construct(this).schema;
|
109
|
+
}
|
110
|
+
}
|
@@ -1,7 +1,7 @@
|
|
1
|
-
import {
|
2
|
-
import { BaseEntity } from
|
3
|
-
import { EntityMapperConstructor } from
|
4
|
-
import { BaseEntityMapper, construct } from
|
1
|
+
import { AnySchemaValidator } from '@forklaunch/validator';
|
2
|
+
import { BaseEntity } from '../../database/mikro/models/entities/base.entity';
|
3
|
+
import { EntityMapperConstructor } from '../interfaces/entityMapper.interface';
|
4
|
+
import { BaseEntityMapper, construct } from './baseEntityMapper.model';
|
5
5
|
|
6
6
|
/**
|
7
7
|
* Abstract class representing a request entityMapper.
|
@@ -10,81 +10,102 @@ import { BaseEntityMapper, construct } from "./baseEntityMapper.model";
|
|
10
10
|
* @template SV - A type that extends SchemaValidator.
|
11
11
|
* @extends {BaseEntityMapper<SV>}
|
12
12
|
*/
|
13
|
-
export abstract class RequestEntityMapper<
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
*
|
24
|
-
* @param {SV} schemaValidator - The schema provider.
|
25
|
-
*/
|
26
|
-
constructor(schemaValidator: SV) {
|
27
|
-
super(schemaValidator);
|
28
|
-
}
|
13
|
+
export abstract class RequestEntityMapper<
|
14
|
+
Entity extends BaseEntity,
|
15
|
+
SV extends AnySchemaValidator
|
16
|
+
> extends BaseEntityMapper<SV> {
|
17
|
+
/**
|
18
|
+
* The entity.
|
19
|
+
* @type {Entity}
|
20
|
+
* @protected
|
21
|
+
*/
|
22
|
+
_Entity!: Entity;
|
29
23
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
24
|
+
/**
|
25
|
+
* Converts the underlying DTO to an entity.
|
26
|
+
*
|
27
|
+
* @abstract
|
28
|
+
* @param {...unknown[]} additionalArgs - Additional arguments.
|
29
|
+
* @returns {Entity} - The entity.
|
30
|
+
*/
|
31
|
+
abstract toEntity(...additionalArgs: unknown[]): Entity;
|
38
32
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
33
|
+
/**
|
34
|
+
* Populates the DTO with data from a JSON object.
|
35
|
+
*
|
36
|
+
* @param {this['_dto']} json - The JSON object.
|
37
|
+
* @returns {this} - The instance of the RequestEntityMapper.
|
38
|
+
*/
|
39
|
+
fromJson(json: this['_dto']): this {
|
40
|
+
if (
|
41
|
+
!this.schemaValidator.validate(
|
42
|
+
this.schemaValidator.schemify(this.schema),
|
43
|
+
json
|
44
|
+
)
|
45
|
+
) {
|
46
|
+
throw new Error('Invalid DTO');
|
51
47
|
}
|
48
|
+
this.dto = json;
|
49
|
+
return this;
|
50
|
+
}
|
52
51
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
52
|
+
/**
|
53
|
+
* Deserializes a JSON object to an entity.
|
54
|
+
*
|
55
|
+
* @param {this['_dto']} json - The JSON object.
|
56
|
+
* @param {...unknown[]} additionalArgs - Additional arguments.
|
57
|
+
* @returns {Entity} - The entity.
|
58
|
+
*/
|
59
|
+
deserializeJsonToEntity(
|
60
|
+
json: this['_dto'],
|
61
|
+
...additionalArgs: unknown[]
|
62
|
+
): Entity {
|
63
|
+
return this.fromJson(json).toEntity(...additionalArgs);
|
64
|
+
}
|
63
65
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
66
|
+
/**
|
67
|
+
* Creates an instance of a RequestEntityMapper from a JSON object.
|
68
|
+
*
|
69
|
+
* @template T - A type that extends RequestEntityMapper.
|
70
|
+
* @param {EntityMapperConstructor<T>} this - The constructor of the T.
|
71
|
+
* @param {T['_SV']} schemaValidator - The schema provider.
|
72
|
+
* @param {T['_dto']} json - The JSON object.
|
73
|
+
* @returns {T} - An instance of the T.
|
74
|
+
*/
|
75
|
+
static fromJson<
|
76
|
+
T extends RequestEntityMapper<BaseEntity, SV>,
|
77
|
+
SV extends AnySchemaValidator,
|
78
|
+
JsonType extends T['_dto']
|
79
|
+
>(
|
80
|
+
this: EntityMapperConstructor<T, SV>,
|
81
|
+
schemaValidator: SV,
|
82
|
+
json: JsonType
|
83
|
+
): T {
|
84
|
+
return construct(this, schemaValidator).fromJson(json);
|
85
|
+
}
|
76
86
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
87
|
+
/**
|
88
|
+
* Deserializes a JSON object to an entity.
|
89
|
+
*
|
90
|
+
* @template T - A type that extends RequestEntityMapper.
|
91
|
+
* @param {EntityMapperConstructor<T>} this - The constructor of the T.
|
92
|
+
* @param {T['_SV']} schemaValidator - The schema provider.
|
93
|
+
* @param {T['_dto']} json - The JSON object.
|
94
|
+
* @param {...unknown[]} additionalArgs - Additional arguments.
|
95
|
+
* @returns {T['_Entity']} - The entity.
|
96
|
+
*/
|
97
|
+
static deserializeJsonToEntity<
|
98
|
+
T extends RequestEntityMapper<BaseEntity, SV>,
|
99
|
+
SV extends AnySchemaValidator,
|
100
|
+
JsonType extends T['_dto']
|
101
|
+
>(
|
102
|
+
this: EntityMapperConstructor<T, SV>,
|
103
|
+
schemaValidator: SV,
|
104
|
+
json: JsonType,
|
105
|
+
...additionalArgs: unknown[]
|
106
|
+
): T['_Entity'] {
|
107
|
+
return construct(this, schemaValidator)
|
108
|
+
.fromJson(json)
|
109
|
+
.toEntity(...additionalArgs);
|
110
|
+
}
|
90
111
|
}
|