@forklaunch/core 0.2.37 → 0.3.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/lib/{src/database/mikro/models/entities/base.entity.d.ts → base.entity-DNfmMOgd.d.mts} +3 -2
- package/lib/base.entity-DNfmMOgd.d.ts +27 -0
- package/lib/{src/cache/redisTtlCache.d.ts → cache/index.d.mts} +67 -4
- package/lib/cache/index.d.ts +130 -0
- package/lib/cache/index.js +133 -0
- package/lib/cache/index.mjs +105 -0
- package/lib/controllers/index.d.mts +5 -0
- package/lib/controllers/index.d.ts +5 -0
- package/lib/controllers/index.js +18 -0
- package/lib/controllers/index.mjs +0 -0
- package/lib/database/index.d.mts +37 -0
- package/lib/{src/database/mikro/models/entities/mongo.base.entity.d.ts → database/index.d.ts} +5 -2
- package/lib/database/index.js +78 -0
- package/lib/database/index.mjs +53 -0
- package/lib/dtoMapper/index.d.mts +215 -0
- package/lib/dtoMapper/index.d.ts +215 -0
- package/lib/dtoMapper/index.js +230 -0
- package/lib/dtoMapper/index.mjs +202 -0
- package/lib/http/index.d.mts +910 -0
- package/lib/http/index.d.ts +910 -0
- package/lib/http/index.js +2181 -0
- package/lib/http/index.mjs +2122 -0
- package/lib/services/index.d.mts +64 -0
- package/lib/services/index.d.ts +64 -0
- package/lib/services/index.js +159 -0
- package/lib/services/index.mjs +131 -0
- package/package.json +39 -26
- package/lib/src/cache/index.d.ts +0 -5
- package/lib/src/cache/index.d.ts.map +0 -1
- package/lib/src/cache/index.js +0 -4
- package/lib/src/cache/interfaces/ttlCache.interface.d.ts +0 -48
- package/lib/src/cache/interfaces/ttlCache.interface.d.ts.map +0 -1
- package/lib/src/cache/interfaces/ttlCache.interface.js +0 -1
- package/lib/src/cache/redisTtlCache.d.ts.map +0 -1
- package/lib/src/cache/redisTtlCache.js +0 -98
- package/lib/src/cache/types/ttlCacheRecord.types.d.ts +0 -14
- package/lib/src/cache/types/ttlCacheRecord.types.d.ts.map +0 -1
- package/lib/src/cache/types/ttlCacheRecord.types.js +0 -1
- package/lib/src/cache/utils/cacheKey.d.ts +0 -2
- package/lib/src/cache/utils/cacheKey.d.ts.map +0 -1
- package/lib/src/cache/utils/cacheKey.js +0 -3
- package/lib/src/controllers/index.d.ts +0 -2
- package/lib/src/controllers/index.d.ts.map +0 -1
- package/lib/src/controllers/index.js +0 -1
- package/lib/src/controllers/interfaces/controller.interface.d.ts +0 -4
- package/lib/src/controllers/interfaces/controller.interface.d.ts.map +0 -1
- package/lib/src/controllers/interfaces/controller.interface.js +0 -1
- package/lib/src/database/index.d.ts +0 -3
- package/lib/src/database/index.d.ts.map +0 -1
- package/lib/src/database/index.js +0 -2
- package/lib/src/database/mikro/models/entities/base.entity.d.ts.map +0 -1
- package/lib/src/database/mikro/models/entities/base.entity.js +0 -42
- package/lib/src/database/mikro/models/entities/mongo.base.entity.d.ts.map +0 -1
- package/lib/src/database/mikro/models/entities/mongo.base.entity.js +0 -51
- package/lib/src/dtoMapper/index.d.ts +0 -3
- package/lib/src/dtoMapper/index.d.ts.map +0 -1
- package/lib/src/dtoMapper/index.js +0 -2
- package/lib/src/dtoMapper/interfaces/dtoMapper.interface.d.ts +0 -18
- package/lib/src/dtoMapper/interfaces/dtoMapper.interface.d.ts.map +0 -1
- package/lib/src/dtoMapper/interfaces/dtoMapper.interface.js +0 -1
- package/lib/src/dtoMapper/models/baseDtoMapper.model.d.ts +0 -72
- package/lib/src/dtoMapper/models/baseDtoMapper.model.d.ts.map +0 -1
- package/lib/src/dtoMapper/models/baseDtoMapper.model.js +0 -76
- package/lib/src/dtoMapper/models/requestDtoMapper.model.d.ts +0 -68
- package/lib/src/dtoMapper/models/requestDtoMapper.model.d.ts.map +0 -1
- package/lib/src/dtoMapper/models/requestDtoMapper.model.js +0 -71
- package/lib/src/dtoMapper/models/responseDtoMapper.model.d.ts +0 -67
- package/lib/src/dtoMapper/models/responseDtoMapper.model.d.ts.map +0 -1
- package/lib/src/dtoMapper/models/responseDtoMapper.model.js +0 -68
- package/lib/src/dtoMapper/types/dtoMapper.types.d.ts +0 -9
- package/lib/src/dtoMapper/types/dtoMapper.types.d.ts.map +0 -1
- package/lib/src/dtoMapper/types/dtoMapper.types.js +0 -1
- package/lib/src/http/application/expressLikeApplication.d.ts +0 -21
- package/lib/src/http/application/expressLikeApplication.d.ts.map +0 -1
- package/lib/src/http/application/expressLikeApplication.js +0 -21
- package/lib/src/http/guards/isConstrainedForklaunchRouter.d.ts +0 -4
- package/lib/src/http/guards/isConstrainedForklaunchRouter.d.ts.map +0 -1
- package/lib/src/http/guards/isConstrainedForklaunchRouter.js +0 -5
- package/lib/src/http/guards/isExpressLikeSchemaHandler.d.ts +0 -5
- package/lib/src/http/guards/isExpressLikeSchemaHandler.d.ts.map +0 -1
- package/lib/src/http/guards/isExpressLikeSchemaHandler.js +0 -6
- package/lib/src/http/guards/isForklaunchExpressLikeRouter.d.ts +0 -5
- package/lib/src/http/guards/isForklaunchExpressLikeRouter.d.ts.map +0 -1
- package/lib/src/http/guards/isForklaunchExpressLikeRouter.js +0 -6
- package/lib/src/http/guards/isForklaunchRouter.d.ts +0 -4
- package/lib/src/http/guards/isForklaunchRouter.d.ts.map +0 -1
- package/lib/src/http/guards/isForklaunchRouter.js +0 -7
- package/lib/src/http/guards/isHttpContractDetails.d.ts +0 -7
- package/lib/src/http/guards/isHttpContractDetails.d.ts.map +0 -1
- package/lib/src/http/guards/isHttpContractDetails.js +0 -9
- package/lib/src/http/guards/isPathParamContractDetails.d.ts +0 -4
- package/lib/src/http/guards/isPathParamContractDetails.d.ts.map +0 -1
- package/lib/src/http/guards/isPathParamContractDetails.js +0 -10
- package/lib/src/http/guards/isResponseShape.d.ts +0 -3
- package/lib/src/http/guards/isResponseShape.d.ts.map +0 -1
- package/lib/src/http/guards/isResponseShape.js +0 -7
- package/lib/src/http/guards/isTypedHandler.d.ts +0 -5
- package/lib/src/http/guards/isTypedHandler.d.ts.map +0 -1
- package/lib/src/http/guards/isTypedHandler.js +0 -6
- package/lib/src/http/handlers/delete.d.ts +0 -9
- package/lib/src/http/handlers/delete.d.ts.map +0 -1
- package/lib/src/http/handlers/delete.js +0 -4
- package/lib/src/http/handlers/get.d.ts +0 -9
- package/lib/src/http/handlers/get.d.ts.map +0 -1
- package/lib/src/http/handlers/get.js +0 -4
- package/lib/src/http/handlers/head.d.ts +0 -9
- package/lib/src/http/handlers/head.d.ts.map +0 -1
- package/lib/src/http/handlers/head.js +0 -4
- package/lib/src/http/handlers/middleware.d.ts +0 -9
- package/lib/src/http/handlers/middleware.d.ts.map +0 -1
- package/lib/src/http/handlers/middleware.js +0 -4
- package/lib/src/http/handlers/options.d.ts +0 -9
- package/lib/src/http/handlers/options.d.ts.map +0 -1
- package/lib/src/http/handlers/options.js +0 -4
- package/lib/src/http/handlers/patch.d.ts +0 -9
- package/lib/src/http/handlers/patch.d.ts.map +0 -1
- package/lib/src/http/handlers/patch.js +0 -4
- package/lib/src/http/handlers/post.d.ts +0 -9
- package/lib/src/http/handlers/post.d.ts.map +0 -1
- package/lib/src/http/handlers/post.js +0 -4
- package/lib/src/http/handlers/put.d.ts +0 -9
- package/lib/src/http/handlers/put.d.ts.map +0 -1
- package/lib/src/http/handlers/put.js +0 -4
- package/lib/src/http/handlers/trace.d.ts +0 -9
- package/lib/src/http/handlers/trace.d.ts.map +0 -1
- package/lib/src/http/handlers/trace.js +0 -4
- package/lib/src/http/handlers/typedAuthHandler.d.ts +0 -5
- package/lib/src/http/handlers/typedAuthHandler.d.ts.map +0 -1
- package/lib/src/http/handlers/typedAuthHandler.js +0 -3
- package/lib/src/http/handlers/typedHandler.d.ts +0 -21
- package/lib/src/http/handlers/typedHandler.d.ts.map +0 -1
- package/lib/src/http/handlers/typedHandler.js +0 -30
- package/lib/src/http/index.d.ts +0 -23
- package/lib/src/http/index.d.ts.map +0 -1
- package/lib/src/http/index.js +0 -22
- package/lib/src/http/interfaces/expressLikeRouter.interface.d.ts +0 -24
- package/lib/src/http/interfaces/expressLikeRouter.interface.d.ts.map +0 -1
- package/lib/src/http/interfaces/expressLikeRouter.interface.js +0 -1
- package/lib/src/http/middleware/request/auth.middleware.d.ts +0 -16
- package/lib/src/http/middleware/request/auth.middleware.d.ts.map +0 -1
- package/lib/src/http/middleware/request/auth.middleware.js +0 -143
- package/lib/src/http/middleware/request/cors.middleware.d.ts +0 -13
- package/lib/src/http/middleware/request/cors.middleware.d.ts.map +0 -1
- package/lib/src/http/middleware/request/cors.middleware.js +0 -15
- package/lib/src/http/middleware/request/createContext.middleware.d.ts +0 -15
- package/lib/src/http/middleware/request/createContext.middleware.d.ts.map +0 -1
- package/lib/src/http/middleware/request/createContext.middleware.js +0 -26
- package/lib/src/http/middleware/request/enrichDetails.middleware.d.ts +0 -15
- package/lib/src/http/middleware/request/enrichDetails.middleware.d.ts.map +0 -1
- package/lib/src/http/middleware/request/enrichDetails.middleware.js +0 -19
- package/lib/src/http/middleware/request/parse.middleware.d.ts +0 -17
- package/lib/src/http/middleware/request/parse.middleware.d.ts.map +0 -1
- package/lib/src/http/middleware/request/parse.middleware.js +0 -43
- package/lib/src/http/middleware/response/parse.middleware.d.ts +0 -31
- package/lib/src/http/middleware/response/parse.middleware.d.ts.map +0 -1
- package/lib/src/http/middleware/response/parse.middleware.js +0 -52
- package/lib/src/http/openApiV3Generator/openApiV3Generator.d.ts +0 -14
- package/lib/src/http/openApiV3Generator/openApiV3Generator.d.ts.map +0 -1
- package/lib/src/http/openApiV3Generator/openApiV3Generator.js +0 -169
- package/lib/src/http/router/expressLikeRouter.d.ts +0 -138
- package/lib/src/http/router/expressLikeRouter.d.ts.map +0 -1
- package/lib/src/http/router/expressLikeRouter.js +0 -483
- package/lib/src/http/types/apiDefinition.types.d.ts +0 -260
- package/lib/src/http/types/apiDefinition.types.d.ts.map +0 -1
- package/lib/src/http/types/apiDefinition.types.js +0 -1
- package/lib/src/http/types/contractDetails.types.d.ts +0 -211
- package/lib/src/http/types/contractDetails.types.d.ts.map +0 -1
- package/lib/src/http/types/contractDetails.types.js +0 -1
- package/lib/src/http/types/expressLikeRouter.types.d.ts +0 -51
- package/lib/src/http/types/expressLikeRouter.types.d.ts.map +0 -1
- package/lib/src/http/types/expressLikeRouter.types.js +0 -1
- package/lib/src/http/types/router.types.d.ts +0 -32
- package/lib/src/http/types/router.types.d.ts.map +0 -1
- package/lib/src/http/types/router.types.js +0 -1
- package/lib/src/http/types/typedHandler.types.d.ts +0 -10
- package/lib/src/http/types/typedHandler.types.d.ts.map +0 -1
- package/lib/src/http/types/typedHandler.types.js +0 -1
- package/lib/src/http/utils/enrichExpressLikeSend.d.ts +0 -32
- package/lib/src/http/utils/enrichExpressLikeSend.d.ts.map +0 -1
- package/lib/src/http/utils/enrichExpressLikeSend.js +0 -50
- package/lib/src/http/utils/httpStatusCodes.d.ts +0 -75
- package/lib/src/http/utils/httpStatusCodes.d.ts.map +0 -1
- package/lib/src/http/utils/httpStatusCodes.js +0 -1039
- package/lib/src/services/configInjector.d.ts +0 -21
- package/lib/src/services/configInjector.d.ts.map +0 -1
- package/lib/src/services/configInjector.js +0 -90
- package/lib/src/services/index.d.ts +0 -5
- package/lib/src/services/index.d.ts.map +0 -1
- package/lib/src/services/index.js +0 -4
- package/lib/src/services/interfaces/baseService.d.ts +0 -15
- package/lib/src/services/interfaces/baseService.d.ts.map +0 -1
- package/lib/src/services/interfaces/baseService.js +0 -1
- package/lib/src/services/types/configInjector.types.d.ts +0 -25
- package/lib/src/services/types/configInjector.types.d.ts.map +0 -1
- package/lib/src/services/types/configInjector.types.js +0 -6
- package/lib/src/services/types/entityManager.types.d.ts +0 -4
- package/lib/src/services/types/entityManager.types.d.ts.map +0 -1
- package/lib/src/services/types/entityManager.types.js +0 -1
- package/lib/tests/configInjector.test.d.ts +0 -2
- package/lib/tests/configInjector.test.d.ts.map +0 -1
- package/lib/tests/configInjector.test.js +0 -105
- package/lib/tests/dtoMapper.test.d.ts +0 -2
- package/lib/tests/dtoMapper.test.d.ts.map +0 -1
- package/lib/tests/dtoMapper.test.js +0 -170
- package/lib/tests/expressLikeRouterInstantiation.test.d.ts +0 -2
- package/lib/tests/expressLikeRouterInstantiation.test.d.ts.map +0 -1
- package/lib/tests/expressLikeRouterInstantiation.test.js +0 -118
- package/lib/tests/http.middleware.test.d.ts +0 -2
- package/lib/tests/http.middleware.test.d.ts.map +0 -1
- package/lib/tests/http.middleware.test.js +0 -102
- package/lib/tests/openApiV3Generator.test.d.ts +0 -2
- package/lib/tests/openApiV3Generator.test.d.ts.map +0 -1
- package/lib/tests/openApiV3Generator.test.js +0 -66
- package/lib/tests/redisTtlCache.test.d.ts +0 -2
- package/lib/tests/redisTtlCache.test.d.ts.map +0 -1
- package/lib/tests/redisTtlCache.test.js +0 -49
- package/lib/tests/typedHandler.test.d.ts +0 -2
- package/lib/tests/typedHandler.test.d.ts.map +0 -1
- package/lib/tests/typedHandler.test.js +0 -3
- package/lib/vitest.config.d.ts +0 -3
- package/lib/vitest.config.d.ts.map +0 -1
- package/lib/vitest.config.js +0 -7
@@ -0,0 +1,53 @@
|
|
1
|
+
var __defProp = Object.defineProperty;
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
3
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
4
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
5
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
6
|
+
if (decorator = decorators[i])
|
7
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
8
|
+
if (kind && result) __defProp(target, key, result);
|
9
|
+
return result;
|
10
|
+
};
|
11
|
+
|
12
|
+
// src/database/mikro/models/entities/base.entity.ts
|
13
|
+
import { v4 } from "uuid";
|
14
|
+
import { PrimaryKey, Property } from "@mikro-orm/core";
|
15
|
+
var BaseEntity = class {
|
16
|
+
id = v4();
|
17
|
+
createdAt = /* @__PURE__ */ new Date();
|
18
|
+
updatedAt = /* @__PURE__ */ new Date();
|
19
|
+
};
|
20
|
+
__decorateClass([
|
21
|
+
PrimaryKey({ type: "uuid" })
|
22
|
+
], BaseEntity.prototype, "id", 2);
|
23
|
+
__decorateClass([
|
24
|
+
Property()
|
25
|
+
], BaseEntity.prototype, "createdAt", 2);
|
26
|
+
__decorateClass([
|
27
|
+
Property({ onUpdate: () => /* @__PURE__ */ new Date() })
|
28
|
+
], BaseEntity.prototype, "updatedAt", 2);
|
29
|
+
|
30
|
+
// src/database/mikro/models/entities/mongo.base.entity.ts
|
31
|
+
import { PrimaryKey as PrimaryKey2, Property as Property2, SerializedPrimaryKey } from "@mikro-orm/core";
|
32
|
+
var MongoBaseEntity = class {
|
33
|
+
_id;
|
34
|
+
id;
|
35
|
+
createdAt = /* @__PURE__ */ new Date();
|
36
|
+
updatedAt = /* @__PURE__ */ new Date();
|
37
|
+
};
|
38
|
+
__decorateClass([
|
39
|
+
PrimaryKey2()
|
40
|
+
], MongoBaseEntity.prototype, "_id", 2);
|
41
|
+
__decorateClass([
|
42
|
+
SerializedPrimaryKey()
|
43
|
+
], MongoBaseEntity.prototype, "id", 2);
|
44
|
+
__decorateClass([
|
45
|
+
Property2()
|
46
|
+
], MongoBaseEntity.prototype, "createdAt", 2);
|
47
|
+
__decorateClass([
|
48
|
+
Property2({ onUpdate: () => /* @__PURE__ */ new Date() })
|
49
|
+
], MongoBaseEntity.prototype, "updatedAt", 2);
|
50
|
+
export {
|
51
|
+
BaseEntity,
|
52
|
+
MongoBaseEntity
|
53
|
+
};
|
@@ -0,0 +1,215 @@
|
|
1
|
+
import { AnySchemaValidator, UnboxedObjectSchema, SchemaValidator, Schema } from '@forklaunch/validator';
|
2
|
+
import { B as BaseEntity } from '../base.entity-DNfmMOgd.mjs';
|
3
|
+
|
4
|
+
/**
|
5
|
+
* Interface representing a constructor for an entity mapper.
|
6
|
+
*
|
7
|
+
* @template T - The type of the entity mapper.
|
8
|
+
* @template SV - The type of the schema validator.
|
9
|
+
* @interface DtoMapperConstructor
|
10
|
+
*/
|
11
|
+
interface DtoMapperConstructor<T, SV extends AnySchemaValidator> {
|
12
|
+
/**
|
13
|
+
* Creates a new instance of the entity mapper.
|
14
|
+
*
|
15
|
+
* @param {AnySchemaValidator} schemaValidator - The arguments to pass to the constructor.
|
16
|
+
* @returns {T} - A new instance of the entity mapper.
|
17
|
+
*/
|
18
|
+
new (schemaValidator: SV): T;
|
19
|
+
}
|
20
|
+
|
21
|
+
/**
|
22
|
+
* Type representing a schema validator object for an entity mapper.
|
23
|
+
*
|
24
|
+
* @template SV - A type that extends AnySchemaValidator.
|
25
|
+
* @typedef {SV['_ValidSchemaObject'] | UnboxedObjectSchema<SV>} DtoMapperSchemaValidatorObject
|
26
|
+
*/
|
27
|
+
type DtoMapperSchemaValidatorObject<SV extends AnySchemaValidator> = SV['_ValidSchemaObject'] | UnboxedObjectSchema<SV>;
|
28
|
+
|
29
|
+
/**
|
30
|
+
* Abstract class representing a base entity mapper.
|
31
|
+
*
|
32
|
+
* @template SV - A type that extends AnySchemaValidator.
|
33
|
+
*/
|
34
|
+
declare abstract class BaseDtoMapper<SV extends AnySchemaValidator> {
|
35
|
+
/**
|
36
|
+
* The schema validator exact type.
|
37
|
+
* @type {SV}
|
38
|
+
* @protected
|
39
|
+
*/
|
40
|
+
_SV: SV;
|
41
|
+
/**
|
42
|
+
* The schema validator as a general type.
|
43
|
+
* @type {SchemaValidator}
|
44
|
+
* @protected
|
45
|
+
*/
|
46
|
+
protected schemaValidator: SchemaValidator;
|
47
|
+
/**
|
48
|
+
* The schema definition.
|
49
|
+
* @type {DtoMapperSchemaValidatorObject<SV>}
|
50
|
+
* @abstract
|
51
|
+
*/
|
52
|
+
abstract schema: DtoMapperSchemaValidatorObject<SV>;
|
53
|
+
/**
|
54
|
+
* The Data Transfer Object (DTO).
|
55
|
+
* @type {Schema<this['schema'], SV>}
|
56
|
+
*/
|
57
|
+
_dto: Schema<this['schema'], SV>;
|
58
|
+
/**
|
59
|
+
* Creates an instance of BaseDtoMapper.
|
60
|
+
*
|
61
|
+
* @param {SV} schemaValidator - The schema provider.
|
62
|
+
*/
|
63
|
+
constructor(schemaValidator: SV);
|
64
|
+
/**
|
65
|
+
* Validates and sets the Data Transfer Object (DTO).
|
66
|
+
*
|
67
|
+
* @param {this['_dto']} dto - The Data Transfer Object (DTO).
|
68
|
+
* @throws {Error} - Throws an error if the DTO is invalid.
|
69
|
+
*/
|
70
|
+
set dto(_dto: this['_dto']);
|
71
|
+
/**
|
72
|
+
* Validates and gets the Data Transfer Object (DTO).
|
73
|
+
*
|
74
|
+
* @returns {this['_dto']} - The Data Transfer Object (DTO).
|
75
|
+
*/
|
76
|
+
get dto(): this['_dto'];
|
77
|
+
/**
|
78
|
+
* Gets the schema of a T.
|
79
|
+
*
|
80
|
+
* @template T - A type that extends BaseDtoMapper.
|
81
|
+
* @template SV - A type that extends AnySchemaValidator.
|
82
|
+
* @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.
|
83
|
+
* @returns {T['schema']} - The schema of the T.
|
84
|
+
*/
|
85
|
+
static schema<T extends BaseDtoMapper<SV>, SV extends AnySchemaValidator>(this: DtoMapperConstructor<T, SV>): T['schema'];
|
86
|
+
}
|
87
|
+
|
88
|
+
/**
|
89
|
+
* Abstract class representing a request entity mapper.
|
90
|
+
*
|
91
|
+
* @template Entity - A type that extends BaseEntity.
|
92
|
+
* @template SV - A type that extends AnySchemaValidator.
|
93
|
+
* @extends {BaseDtoMapper<SV>}
|
94
|
+
*/
|
95
|
+
declare abstract class RequestDtoMapper<Entity extends BaseEntity, SV extends AnySchemaValidator> extends BaseDtoMapper<SV> {
|
96
|
+
/**
|
97
|
+
* The entity type.
|
98
|
+
* @type {Entity}
|
99
|
+
* @protected
|
100
|
+
*/
|
101
|
+
_Entity: Entity;
|
102
|
+
/**
|
103
|
+
* Converts the underlying DTO to an entity.
|
104
|
+
*
|
105
|
+
* @abstract
|
106
|
+
* @param {...unknown[]} additionalArgs - Additional arguments.
|
107
|
+
* @returns {Entity} - The entity.
|
108
|
+
*/
|
109
|
+
abstract toEntity(...additionalArgs: unknown[]): Entity;
|
110
|
+
/**
|
111
|
+
* Populates the DTO with data from a JSON object.
|
112
|
+
*
|
113
|
+
* @param {this['_dto']} json - The JSON object.
|
114
|
+
* @returns {this} - The instance of the RequestDtoMapper.
|
115
|
+
*/
|
116
|
+
fromDto(json: this['_dto']): this;
|
117
|
+
/**
|
118
|
+
* Deserializes a JSON object to an entity.
|
119
|
+
*
|
120
|
+
* @param {this['_dto']} json - The JSON object.
|
121
|
+
* @param {...unknown[]} additionalArgs - Additional arguments.
|
122
|
+
* @returns {Entity} - The entity.
|
123
|
+
*/
|
124
|
+
deserializeDtoToEntity(json: this['_dto'], ...additionalArgs: Parameters<this['toEntity']>): Entity;
|
125
|
+
/**
|
126
|
+
* Creates an instance of a RequestDtoMapper from a JSON object.
|
127
|
+
*
|
128
|
+
* @template T - A type that extends RequestDtoMapper.
|
129
|
+
* @template SV - A type that extends AnySchemaValidator.
|
130
|
+
* @template JsonType - The type of the JSON object.
|
131
|
+
* @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.
|
132
|
+
* @param {SV} schemaValidator - The schema provider.
|
133
|
+
* @param {JsonType} json - The JSON object.
|
134
|
+
* @returns {T} - An instance of the T.
|
135
|
+
*/
|
136
|
+
static fromDto<T extends RequestDtoMapper<BaseEntity, SV>, SV extends AnySchemaValidator, JsonType extends T['_dto']>(this: DtoMapperConstructor<T, SV>, schemaValidator: SV, json: JsonType): T;
|
137
|
+
/**
|
138
|
+
* Deserializes a JSON object to an entity.
|
139
|
+
*
|
140
|
+
* @template T - A type that extends RequestDtoMapper.
|
141
|
+
* @template SV - A type that extends AnySchemaValidator.
|
142
|
+
* @template JsonType - The type of the JSON object.
|
143
|
+
* @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.
|
144
|
+
* @param {SV} schemaValidator - The schema provider.
|
145
|
+
* @param {JsonType} json - The JSON object.
|
146
|
+
* @param {...unknown[]} additionalArgs - Additional arguments.
|
147
|
+
* @returns {T['_Entity']} - The entity.
|
148
|
+
*/
|
149
|
+
static deserializeDtoToEntity<T extends RequestDtoMapper<BaseEntity, SV>, SV extends AnySchemaValidator, JsonType extends T['_dto']>(this: DtoMapperConstructor<T, SV>, schemaValidator: SV, json: JsonType, ...additionalArgs: Parameters<T['toEntity']>): T['_Entity'];
|
150
|
+
}
|
151
|
+
|
152
|
+
/**
|
153
|
+
* Abstract class representing a response entity mapper.
|
154
|
+
*
|
155
|
+
* @template Entity - A type that extends BaseEntity.
|
156
|
+
* @template SV - A type that extends AnySchemaValidator.
|
157
|
+
* @extends {BaseDtoMapper<SV>}
|
158
|
+
*/
|
159
|
+
declare abstract class ResponseDtoMapper<Entity extends BaseEntity, SV extends AnySchemaValidator> extends BaseDtoMapper<SV> {
|
160
|
+
/**
|
161
|
+
* The entity type.
|
162
|
+
* @type {Entity}
|
163
|
+
* @protected
|
164
|
+
*/
|
165
|
+
_Entity: Entity;
|
166
|
+
/**
|
167
|
+
* Populates entity mapper with DTO from an entity.
|
168
|
+
*
|
169
|
+
* @abstract
|
170
|
+
* @param {Entity} entity - The entity to convert.
|
171
|
+
* @param {...unknown[]} additionalArgs - Additional arguments.
|
172
|
+
* @returns {this} - The instance of the ResponseDtoMapper.
|
173
|
+
*/
|
174
|
+
abstract fromEntity(entity: Entity, ...additionalArgs: unknown[]): this;
|
175
|
+
/**
|
176
|
+
* Converts the underlying DTO to a JSON object.
|
177
|
+
*
|
178
|
+
* @returns {this['_dto']} - The JSON object.
|
179
|
+
* @throws {Error} - Throws an error if the DTO is invalid.
|
180
|
+
*/
|
181
|
+
toDto(): this['_dto'];
|
182
|
+
/**
|
183
|
+
* Serializes an entity to a JSON object.
|
184
|
+
*
|
185
|
+
* @param {Entity} entity - The entity to serialize.
|
186
|
+
* @returns {this['_dto']} - The JSON object.
|
187
|
+
* @throws {Error} - Throws an error if the DTO is invalid.
|
188
|
+
*/
|
189
|
+
serializeEntityToDto(...[entity, ...additionalArgs]: Parameters<this['fromEntity']>): this['_dto'];
|
190
|
+
/**
|
191
|
+
* Populates entity mapper with DTO from an entity.
|
192
|
+
*
|
193
|
+
* @template T - A type that extends ResponseDtoMapper.
|
194
|
+
* @template SV - A type that extends AnySchemaValidator.
|
195
|
+
* @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.
|
196
|
+
* @param {SV} schemaValidator - The schema provider.
|
197
|
+
* @param {T['_Entity']} entity - The entity to convert.
|
198
|
+
* @returns {T} - An instance of the T.
|
199
|
+
*/
|
200
|
+
static fromEntity<T extends ResponseDtoMapper<BaseEntity, SV>, SV extends AnySchemaValidator>(this: DtoMapperConstructor<T, SV>, schemaValidator: SV, ...[entity, ...additionalArgs]: Parameters<T['fromEntity']>): T;
|
201
|
+
/**
|
202
|
+
* Serializes an entity to a JSON object.
|
203
|
+
*
|
204
|
+
* @template T - A type that extends ResponseDtoMapper.
|
205
|
+
* @template SV - A type that extends AnySchemaValidator.
|
206
|
+
* @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.
|
207
|
+
* @param {SV} schemaValidator - The schema provider.
|
208
|
+
* @param {T['_Entity']} entity - The entity to serialize.
|
209
|
+
* @returns {T['_dto']} - The JSON object.
|
210
|
+
* @throws {Error} - Throws an error if the DTO is invalid.
|
211
|
+
*/
|
212
|
+
static serializeEntityToDto<T extends ResponseDtoMapper<BaseEntity, SV>, SV extends AnySchemaValidator, DtoType extends T['_dto']>(this: DtoMapperConstructor<T, SV>, schemaValidator: SV, ...[entity, ...additionalArgs]: Parameters<T['fromEntity']>): DtoType;
|
213
|
+
}
|
214
|
+
|
215
|
+
export { RequestDtoMapper, ResponseDtoMapper };
|
@@ -0,0 +1,215 @@
|
|
1
|
+
import { AnySchemaValidator, UnboxedObjectSchema, SchemaValidator, Schema } from '@forklaunch/validator';
|
2
|
+
import { B as BaseEntity } from '../base.entity-DNfmMOgd.js';
|
3
|
+
|
4
|
+
/**
|
5
|
+
* Interface representing a constructor for an entity mapper.
|
6
|
+
*
|
7
|
+
* @template T - The type of the entity mapper.
|
8
|
+
* @template SV - The type of the schema validator.
|
9
|
+
* @interface DtoMapperConstructor
|
10
|
+
*/
|
11
|
+
interface DtoMapperConstructor<T, SV extends AnySchemaValidator> {
|
12
|
+
/**
|
13
|
+
* Creates a new instance of the entity mapper.
|
14
|
+
*
|
15
|
+
* @param {AnySchemaValidator} schemaValidator - The arguments to pass to the constructor.
|
16
|
+
* @returns {T} - A new instance of the entity mapper.
|
17
|
+
*/
|
18
|
+
new (schemaValidator: SV): T;
|
19
|
+
}
|
20
|
+
|
21
|
+
/**
|
22
|
+
* Type representing a schema validator object for an entity mapper.
|
23
|
+
*
|
24
|
+
* @template SV - A type that extends AnySchemaValidator.
|
25
|
+
* @typedef {SV['_ValidSchemaObject'] | UnboxedObjectSchema<SV>} DtoMapperSchemaValidatorObject
|
26
|
+
*/
|
27
|
+
type DtoMapperSchemaValidatorObject<SV extends AnySchemaValidator> = SV['_ValidSchemaObject'] | UnboxedObjectSchema<SV>;
|
28
|
+
|
29
|
+
/**
|
30
|
+
* Abstract class representing a base entity mapper.
|
31
|
+
*
|
32
|
+
* @template SV - A type that extends AnySchemaValidator.
|
33
|
+
*/
|
34
|
+
declare abstract class BaseDtoMapper<SV extends AnySchemaValidator> {
|
35
|
+
/**
|
36
|
+
* The schema validator exact type.
|
37
|
+
* @type {SV}
|
38
|
+
* @protected
|
39
|
+
*/
|
40
|
+
_SV: SV;
|
41
|
+
/**
|
42
|
+
* The schema validator as a general type.
|
43
|
+
* @type {SchemaValidator}
|
44
|
+
* @protected
|
45
|
+
*/
|
46
|
+
protected schemaValidator: SchemaValidator;
|
47
|
+
/**
|
48
|
+
* The schema definition.
|
49
|
+
* @type {DtoMapperSchemaValidatorObject<SV>}
|
50
|
+
* @abstract
|
51
|
+
*/
|
52
|
+
abstract schema: DtoMapperSchemaValidatorObject<SV>;
|
53
|
+
/**
|
54
|
+
* The Data Transfer Object (DTO).
|
55
|
+
* @type {Schema<this['schema'], SV>}
|
56
|
+
*/
|
57
|
+
_dto: Schema<this['schema'], SV>;
|
58
|
+
/**
|
59
|
+
* Creates an instance of BaseDtoMapper.
|
60
|
+
*
|
61
|
+
* @param {SV} schemaValidator - The schema provider.
|
62
|
+
*/
|
63
|
+
constructor(schemaValidator: SV);
|
64
|
+
/**
|
65
|
+
* Validates and sets the Data Transfer Object (DTO).
|
66
|
+
*
|
67
|
+
* @param {this['_dto']} dto - The Data Transfer Object (DTO).
|
68
|
+
* @throws {Error} - Throws an error if the DTO is invalid.
|
69
|
+
*/
|
70
|
+
set dto(_dto: this['_dto']);
|
71
|
+
/**
|
72
|
+
* Validates and gets the Data Transfer Object (DTO).
|
73
|
+
*
|
74
|
+
* @returns {this['_dto']} - The Data Transfer Object (DTO).
|
75
|
+
*/
|
76
|
+
get dto(): this['_dto'];
|
77
|
+
/**
|
78
|
+
* Gets the schema of a T.
|
79
|
+
*
|
80
|
+
* @template T - A type that extends BaseDtoMapper.
|
81
|
+
* @template SV - A type that extends AnySchemaValidator.
|
82
|
+
* @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.
|
83
|
+
* @returns {T['schema']} - The schema of the T.
|
84
|
+
*/
|
85
|
+
static schema<T extends BaseDtoMapper<SV>, SV extends AnySchemaValidator>(this: DtoMapperConstructor<T, SV>): T['schema'];
|
86
|
+
}
|
87
|
+
|
88
|
+
/**
|
89
|
+
* Abstract class representing a request entity mapper.
|
90
|
+
*
|
91
|
+
* @template Entity - A type that extends BaseEntity.
|
92
|
+
* @template SV - A type that extends AnySchemaValidator.
|
93
|
+
* @extends {BaseDtoMapper<SV>}
|
94
|
+
*/
|
95
|
+
declare abstract class RequestDtoMapper<Entity extends BaseEntity, SV extends AnySchemaValidator> extends BaseDtoMapper<SV> {
|
96
|
+
/**
|
97
|
+
* The entity type.
|
98
|
+
* @type {Entity}
|
99
|
+
* @protected
|
100
|
+
*/
|
101
|
+
_Entity: Entity;
|
102
|
+
/**
|
103
|
+
* Converts the underlying DTO to an entity.
|
104
|
+
*
|
105
|
+
* @abstract
|
106
|
+
* @param {...unknown[]} additionalArgs - Additional arguments.
|
107
|
+
* @returns {Entity} - The entity.
|
108
|
+
*/
|
109
|
+
abstract toEntity(...additionalArgs: unknown[]): Entity;
|
110
|
+
/**
|
111
|
+
* Populates the DTO with data from a JSON object.
|
112
|
+
*
|
113
|
+
* @param {this['_dto']} json - The JSON object.
|
114
|
+
* @returns {this} - The instance of the RequestDtoMapper.
|
115
|
+
*/
|
116
|
+
fromDto(json: this['_dto']): this;
|
117
|
+
/**
|
118
|
+
* Deserializes a JSON object to an entity.
|
119
|
+
*
|
120
|
+
* @param {this['_dto']} json - The JSON object.
|
121
|
+
* @param {...unknown[]} additionalArgs - Additional arguments.
|
122
|
+
* @returns {Entity} - The entity.
|
123
|
+
*/
|
124
|
+
deserializeDtoToEntity(json: this['_dto'], ...additionalArgs: Parameters<this['toEntity']>): Entity;
|
125
|
+
/**
|
126
|
+
* Creates an instance of a RequestDtoMapper from a JSON object.
|
127
|
+
*
|
128
|
+
* @template T - A type that extends RequestDtoMapper.
|
129
|
+
* @template SV - A type that extends AnySchemaValidator.
|
130
|
+
* @template JsonType - The type of the JSON object.
|
131
|
+
* @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.
|
132
|
+
* @param {SV} schemaValidator - The schema provider.
|
133
|
+
* @param {JsonType} json - The JSON object.
|
134
|
+
* @returns {T} - An instance of the T.
|
135
|
+
*/
|
136
|
+
static fromDto<T extends RequestDtoMapper<BaseEntity, SV>, SV extends AnySchemaValidator, JsonType extends T['_dto']>(this: DtoMapperConstructor<T, SV>, schemaValidator: SV, json: JsonType): T;
|
137
|
+
/**
|
138
|
+
* Deserializes a JSON object to an entity.
|
139
|
+
*
|
140
|
+
* @template T - A type that extends RequestDtoMapper.
|
141
|
+
* @template SV - A type that extends AnySchemaValidator.
|
142
|
+
* @template JsonType - The type of the JSON object.
|
143
|
+
* @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.
|
144
|
+
* @param {SV} schemaValidator - The schema provider.
|
145
|
+
* @param {JsonType} json - The JSON object.
|
146
|
+
* @param {...unknown[]} additionalArgs - Additional arguments.
|
147
|
+
* @returns {T['_Entity']} - The entity.
|
148
|
+
*/
|
149
|
+
static deserializeDtoToEntity<T extends RequestDtoMapper<BaseEntity, SV>, SV extends AnySchemaValidator, JsonType extends T['_dto']>(this: DtoMapperConstructor<T, SV>, schemaValidator: SV, json: JsonType, ...additionalArgs: Parameters<T['toEntity']>): T['_Entity'];
|
150
|
+
}
|
151
|
+
|
152
|
+
/**
|
153
|
+
* Abstract class representing a response entity mapper.
|
154
|
+
*
|
155
|
+
* @template Entity - A type that extends BaseEntity.
|
156
|
+
* @template SV - A type that extends AnySchemaValidator.
|
157
|
+
* @extends {BaseDtoMapper<SV>}
|
158
|
+
*/
|
159
|
+
declare abstract class ResponseDtoMapper<Entity extends BaseEntity, SV extends AnySchemaValidator> extends BaseDtoMapper<SV> {
|
160
|
+
/**
|
161
|
+
* The entity type.
|
162
|
+
* @type {Entity}
|
163
|
+
* @protected
|
164
|
+
*/
|
165
|
+
_Entity: Entity;
|
166
|
+
/**
|
167
|
+
* Populates entity mapper with DTO from an entity.
|
168
|
+
*
|
169
|
+
* @abstract
|
170
|
+
* @param {Entity} entity - The entity to convert.
|
171
|
+
* @param {...unknown[]} additionalArgs - Additional arguments.
|
172
|
+
* @returns {this} - The instance of the ResponseDtoMapper.
|
173
|
+
*/
|
174
|
+
abstract fromEntity(entity: Entity, ...additionalArgs: unknown[]): this;
|
175
|
+
/**
|
176
|
+
* Converts the underlying DTO to a JSON object.
|
177
|
+
*
|
178
|
+
* @returns {this['_dto']} - The JSON object.
|
179
|
+
* @throws {Error} - Throws an error if the DTO is invalid.
|
180
|
+
*/
|
181
|
+
toDto(): this['_dto'];
|
182
|
+
/**
|
183
|
+
* Serializes an entity to a JSON object.
|
184
|
+
*
|
185
|
+
* @param {Entity} entity - The entity to serialize.
|
186
|
+
* @returns {this['_dto']} - The JSON object.
|
187
|
+
* @throws {Error} - Throws an error if the DTO is invalid.
|
188
|
+
*/
|
189
|
+
serializeEntityToDto(...[entity, ...additionalArgs]: Parameters<this['fromEntity']>): this['_dto'];
|
190
|
+
/**
|
191
|
+
* Populates entity mapper with DTO from an entity.
|
192
|
+
*
|
193
|
+
* @template T - A type that extends ResponseDtoMapper.
|
194
|
+
* @template SV - A type that extends AnySchemaValidator.
|
195
|
+
* @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.
|
196
|
+
* @param {SV} schemaValidator - The schema provider.
|
197
|
+
* @param {T['_Entity']} entity - The entity to convert.
|
198
|
+
* @returns {T} - An instance of the T.
|
199
|
+
*/
|
200
|
+
static fromEntity<T extends ResponseDtoMapper<BaseEntity, SV>, SV extends AnySchemaValidator>(this: DtoMapperConstructor<T, SV>, schemaValidator: SV, ...[entity, ...additionalArgs]: Parameters<T['fromEntity']>): T;
|
201
|
+
/**
|
202
|
+
* Serializes an entity to a JSON object.
|
203
|
+
*
|
204
|
+
* @template T - A type that extends ResponseDtoMapper.
|
205
|
+
* @template SV - A type that extends AnySchemaValidator.
|
206
|
+
* @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.
|
207
|
+
* @param {SV} schemaValidator - The schema provider.
|
208
|
+
* @param {T['_Entity']} entity - The entity to serialize.
|
209
|
+
* @returns {T['_dto']} - The JSON object.
|
210
|
+
* @throws {Error} - Throws an error if the DTO is invalid.
|
211
|
+
*/
|
212
|
+
static serializeEntityToDto<T extends ResponseDtoMapper<BaseEntity, SV>, SV extends AnySchemaValidator, DtoType extends T['_dto']>(this: DtoMapperConstructor<T, SV>, schemaValidator: SV, ...[entity, ...additionalArgs]: Parameters<T['fromEntity']>): DtoType;
|
213
|
+
}
|
214
|
+
|
215
|
+
export { RequestDtoMapper, ResponseDtoMapper };
|