@forklaunch/internal 0.0.1 → 0.0.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/lib/index.d.mts +45 -8
- package/lib/index.d.ts +45 -8
- package/lib/index.js +22 -0
- package/lib/index.mjs +21 -0
- package/package.json +1 -1
package/lib/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AnySchemaValidator, IdiomaticSchema, Schema } from '@forklaunch/validator';
|
|
1
|
+
import { AnySchemaValidator, IdiomaticSchema, Schema, UnboxedObjectSchema } from '@forklaunch/validator';
|
|
2
2
|
import { TypeboxSchemaValidator } from '@forklaunch/validator/typebox';
|
|
3
3
|
import { ZodSchemaValidator } from '@forklaunch/validator/zod';
|
|
4
4
|
import { InstanceTypeRecord } from '@forklaunch/common';
|
|
@@ -35,8 +35,13 @@ declare enum DummyEnum {
|
|
|
35
35
|
B = "B"
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
type
|
|
39
|
-
|
|
38
|
+
type SchemasByValidator<T extends AnySchemaValidator, TypeBoxSchemas extends (...args: never[]) => unknown, ZodSchemas extends (...args: never[]) => unknown> = T extends TypeboxSchemaValidator ? ReturnType<TypeBoxSchemas> : T extends ZodSchemaValidator ? ReturnType<ZodSchemas> : never;
|
|
39
|
+
|
|
40
|
+
declare function serviceSchemaResolver<Options extends Record<string, unknown>, TypeBoxSchemas, ZodSchemas>(TypeBoxSchemas: (options: Options) => TypeBoxSchemas, ZodSchemas: (options: Options) => ZodSchemas): <SchemaValidator extends AnySchemaValidator>(options: Options & {
|
|
41
|
+
validator: SchemaValidator;
|
|
42
|
+
}) => SchemasByValidator<SchemaValidator, (options: Options) => TypeBoxSchemas, (options: Options) => ZodSchemas>;
|
|
43
|
+
|
|
44
|
+
type InternalDtoMapper<DtoMapper extends Record<string, {
|
|
40
45
|
dto: unknown;
|
|
41
46
|
_Entity: unknown;
|
|
42
47
|
serializeEntityToDto: unknown;
|
|
@@ -44,19 +49,19 @@ type InternalDtoMapper<SchemaValidator extends AnySchemaValidator, DtoMapper ext
|
|
|
44
49
|
dto: unknown;
|
|
45
50
|
_Entity: unknown;
|
|
46
51
|
deserializeDtoToEntity: unknown;
|
|
47
|
-
}
|
|
52
|
+
}>> = {
|
|
48
53
|
[K in keyof DtoMapper]: DtoMapper[K] extends {
|
|
49
54
|
dto: unknown;
|
|
50
55
|
_Entity: unknown;
|
|
51
56
|
serializeEntityToDto: unknown;
|
|
52
57
|
} ? {
|
|
53
|
-
serializeEntityToDto:
|
|
58
|
+
serializeEntityToDto: DtoMapper[K]['serializeEntityToDto'];
|
|
54
59
|
} : DtoMapper[K] extends {
|
|
55
60
|
dto: unknown;
|
|
56
61
|
_Entity: unknown;
|
|
57
62
|
deserializeDtoToEntity: unknown;
|
|
58
63
|
} ? {
|
|
59
|
-
deserializeDtoToEntity:
|
|
64
|
+
deserializeDtoToEntity: DtoMapper[K]['deserializeDtoToEntity'];
|
|
60
65
|
} : never;
|
|
61
66
|
};
|
|
62
67
|
|
|
@@ -68,6 +73,38 @@ declare function transformIntoInternalDtoMapper<SchemaValidator extends AnySchem
|
|
|
68
73
|
dto: unknown;
|
|
69
74
|
_Entity: unknown;
|
|
70
75
|
deserializeDtoToEntity: unknown;
|
|
71
|
-
}
|
|
76
|
+
}>>(mappers: DtoMapper, schemaValidator: SchemaValidator): InternalDtoMapper<InstanceTypeRecord<DtoMapper>>;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Type representing a schema validator object for an entity mapper.
|
|
80
|
+
*
|
|
81
|
+
* @template SV - A type that extends AnySchemaValidator.
|
|
82
|
+
* @typedef {SV['_ValidSchemaObject'] | UnboxedObjectSchema<SV>} DtoMapperSchemaValidatorObject
|
|
83
|
+
*/
|
|
84
|
+
type DtoMapperSchemaValidatorObject<SV extends AnySchemaValidator> = SV['_ValidSchemaObject'] | UnboxedObjectSchema<SV>;
|
|
85
|
+
/**
|
|
86
|
+
* Type representing a response DTO mapper for an entity mapper.
|
|
87
|
+
*
|
|
88
|
+
* @template SchemaValidator - A type that extends AnySchemaValidator.
|
|
89
|
+
* @template Dto - The type of the DTO object.
|
|
90
|
+
* @template Entity - The type of the entity object.
|
|
91
|
+
*/
|
|
92
|
+
type ResponseDtoMapperConstructor<SchemaValidator extends AnySchemaValidator, Dto, Entity, SerializeEntityToDto extends (schemaValidator: SchemaValidator, entity: Entity, ...additionalArgs: never[]) => Promise<Dto> = (schemaValidator: SchemaValidator, entity: Entity, ...additionalArgs: never[]) => Promise<Dto>> = new (schemaValidator: SchemaValidator) => {
|
|
93
|
+
dto: Dto;
|
|
94
|
+
_Entity: Entity;
|
|
95
|
+
serializeEntityToDto: SerializeEntityToDto;
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* Type representing a request DTO mapper for an entity mapper.
|
|
99
|
+
*
|
|
100
|
+
* @template SV - A type that extends AnySchemaValidator.
|
|
101
|
+
* @template Dto - The type of the DTO object.
|
|
102
|
+
* @template Entity - The type of the entity object.
|
|
103
|
+
*/
|
|
104
|
+
type RequestDtoMapperConstructor<SchemaValidator extends AnySchemaValidator, Dto, Entity, DeserializeDtoToEntity extends (schemaValidator: SchemaValidator, dto: Dto, em?: EntityManager, ...additionalArgs: never[]) => Promise<Entity> = (schemaValidator: SchemaValidator, dto: Dto, em?: EntityManager, ...additionalArgs: never[]) => Promise<Entity>> = new (schemaValidator: SchemaValidator) => {
|
|
105
|
+
dto: Dto;
|
|
106
|
+
_Entity: Entity;
|
|
107
|
+
deserializeDtoToEntity: DeserializeDtoToEntity;
|
|
108
|
+
};
|
|
72
109
|
|
|
73
|
-
export { DummyEnum, IdentityRequestMapper, IdentityResponseMapper, type InternalDtoMapper, testSchemaEquality, transformIntoInternalDtoMapper };
|
|
110
|
+
export { type DtoMapperSchemaValidatorObject, DummyEnum, IdentityRequestMapper, IdentityResponseMapper, type InternalDtoMapper, type RequestDtoMapperConstructor, type ResponseDtoMapperConstructor, type SchemasByValidator, serviceSchemaResolver, testSchemaEquality, transformIntoInternalDtoMapper };
|
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AnySchemaValidator, IdiomaticSchema, Schema } from '@forklaunch/validator';
|
|
1
|
+
import { AnySchemaValidator, IdiomaticSchema, Schema, UnboxedObjectSchema } from '@forklaunch/validator';
|
|
2
2
|
import { TypeboxSchemaValidator } from '@forklaunch/validator/typebox';
|
|
3
3
|
import { ZodSchemaValidator } from '@forklaunch/validator/zod';
|
|
4
4
|
import { InstanceTypeRecord } from '@forklaunch/common';
|
|
@@ -35,8 +35,13 @@ declare enum DummyEnum {
|
|
|
35
35
|
B = "B"
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
type
|
|
39
|
-
|
|
38
|
+
type SchemasByValidator<T extends AnySchemaValidator, TypeBoxSchemas extends (...args: never[]) => unknown, ZodSchemas extends (...args: never[]) => unknown> = T extends TypeboxSchemaValidator ? ReturnType<TypeBoxSchemas> : T extends ZodSchemaValidator ? ReturnType<ZodSchemas> : never;
|
|
39
|
+
|
|
40
|
+
declare function serviceSchemaResolver<Options extends Record<string, unknown>, TypeBoxSchemas, ZodSchemas>(TypeBoxSchemas: (options: Options) => TypeBoxSchemas, ZodSchemas: (options: Options) => ZodSchemas): <SchemaValidator extends AnySchemaValidator>(options: Options & {
|
|
41
|
+
validator: SchemaValidator;
|
|
42
|
+
}) => SchemasByValidator<SchemaValidator, (options: Options) => TypeBoxSchemas, (options: Options) => ZodSchemas>;
|
|
43
|
+
|
|
44
|
+
type InternalDtoMapper<DtoMapper extends Record<string, {
|
|
40
45
|
dto: unknown;
|
|
41
46
|
_Entity: unknown;
|
|
42
47
|
serializeEntityToDto: unknown;
|
|
@@ -44,19 +49,19 @@ type InternalDtoMapper<SchemaValidator extends AnySchemaValidator, DtoMapper ext
|
|
|
44
49
|
dto: unknown;
|
|
45
50
|
_Entity: unknown;
|
|
46
51
|
deserializeDtoToEntity: unknown;
|
|
47
|
-
}
|
|
52
|
+
}>> = {
|
|
48
53
|
[K in keyof DtoMapper]: DtoMapper[K] extends {
|
|
49
54
|
dto: unknown;
|
|
50
55
|
_Entity: unknown;
|
|
51
56
|
serializeEntityToDto: unknown;
|
|
52
57
|
} ? {
|
|
53
|
-
serializeEntityToDto:
|
|
58
|
+
serializeEntityToDto: DtoMapper[K]['serializeEntityToDto'];
|
|
54
59
|
} : DtoMapper[K] extends {
|
|
55
60
|
dto: unknown;
|
|
56
61
|
_Entity: unknown;
|
|
57
62
|
deserializeDtoToEntity: unknown;
|
|
58
63
|
} ? {
|
|
59
|
-
deserializeDtoToEntity:
|
|
64
|
+
deserializeDtoToEntity: DtoMapper[K]['deserializeDtoToEntity'];
|
|
60
65
|
} : never;
|
|
61
66
|
};
|
|
62
67
|
|
|
@@ -68,6 +73,38 @@ declare function transformIntoInternalDtoMapper<SchemaValidator extends AnySchem
|
|
|
68
73
|
dto: unknown;
|
|
69
74
|
_Entity: unknown;
|
|
70
75
|
deserializeDtoToEntity: unknown;
|
|
71
|
-
}
|
|
76
|
+
}>>(mappers: DtoMapper, schemaValidator: SchemaValidator): InternalDtoMapper<InstanceTypeRecord<DtoMapper>>;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Type representing a schema validator object for an entity mapper.
|
|
80
|
+
*
|
|
81
|
+
* @template SV - A type that extends AnySchemaValidator.
|
|
82
|
+
* @typedef {SV['_ValidSchemaObject'] | UnboxedObjectSchema<SV>} DtoMapperSchemaValidatorObject
|
|
83
|
+
*/
|
|
84
|
+
type DtoMapperSchemaValidatorObject<SV extends AnySchemaValidator> = SV['_ValidSchemaObject'] | UnboxedObjectSchema<SV>;
|
|
85
|
+
/**
|
|
86
|
+
* Type representing a response DTO mapper for an entity mapper.
|
|
87
|
+
*
|
|
88
|
+
* @template SchemaValidator - A type that extends AnySchemaValidator.
|
|
89
|
+
* @template Dto - The type of the DTO object.
|
|
90
|
+
* @template Entity - The type of the entity object.
|
|
91
|
+
*/
|
|
92
|
+
type ResponseDtoMapperConstructor<SchemaValidator extends AnySchemaValidator, Dto, Entity, SerializeEntityToDto extends (schemaValidator: SchemaValidator, entity: Entity, ...additionalArgs: never[]) => Promise<Dto> = (schemaValidator: SchemaValidator, entity: Entity, ...additionalArgs: never[]) => Promise<Dto>> = new (schemaValidator: SchemaValidator) => {
|
|
93
|
+
dto: Dto;
|
|
94
|
+
_Entity: Entity;
|
|
95
|
+
serializeEntityToDto: SerializeEntityToDto;
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* Type representing a request DTO mapper for an entity mapper.
|
|
99
|
+
*
|
|
100
|
+
* @template SV - A type that extends AnySchemaValidator.
|
|
101
|
+
* @template Dto - The type of the DTO object.
|
|
102
|
+
* @template Entity - The type of the entity object.
|
|
103
|
+
*/
|
|
104
|
+
type RequestDtoMapperConstructor<SchemaValidator extends AnySchemaValidator, Dto, Entity, DeserializeDtoToEntity extends (schemaValidator: SchemaValidator, dto: Dto, em?: EntityManager, ...additionalArgs: never[]) => Promise<Entity> = (schemaValidator: SchemaValidator, dto: Dto, em?: EntityManager, ...additionalArgs: never[]) => Promise<Entity>> = new (schemaValidator: SchemaValidator) => {
|
|
105
|
+
dto: Dto;
|
|
106
|
+
_Entity: Entity;
|
|
107
|
+
deserializeDtoToEntity: DeserializeDtoToEntity;
|
|
108
|
+
};
|
|
72
109
|
|
|
73
|
-
export { DummyEnum, IdentityRequestMapper, IdentityResponseMapper, type InternalDtoMapper, testSchemaEquality, transformIntoInternalDtoMapper };
|
|
110
|
+
export { type DtoMapperSchemaValidatorObject, DummyEnum, IdentityRequestMapper, IdentityResponseMapper, type InternalDtoMapper, type RequestDtoMapperConstructor, type ResponseDtoMapperConstructor, type SchemasByValidator, serviceSchemaResolver, testSchemaEquality, transformIntoInternalDtoMapper };
|
package/lib/index.js
CHANGED
|
@@ -23,6 +23,7 @@ __export(index_exports, {
|
|
|
23
23
|
DummyEnum: () => DummyEnum,
|
|
24
24
|
IdentityRequestMapper: () => IdentityRequestMapper,
|
|
25
25
|
IdentityResponseMapper: () => IdentityResponseMapper,
|
|
26
|
+
serviceSchemaResolver: () => serviceSchemaResolver,
|
|
26
27
|
testSchemaEquality: () => testSchemaEquality,
|
|
27
28
|
transformIntoInternalDtoMapper: () => transformIntoInternalDtoMapper
|
|
28
29
|
});
|
|
@@ -66,6 +67,26 @@ var DummyEnum = /* @__PURE__ */ ((DummyEnum2) => {
|
|
|
66
67
|
return DummyEnum2;
|
|
67
68
|
})(DummyEnum || {});
|
|
68
69
|
|
|
70
|
+
// src/serviceSchemaResolver.ts
|
|
71
|
+
var import_common2 = require("@forklaunch/common");
|
|
72
|
+
function serviceSchemaResolver(TypeBoxSchemas, ZodSchemas) {
|
|
73
|
+
return (options) => {
|
|
74
|
+
switch (options.validator._Type) {
|
|
75
|
+
case "TypeBox":
|
|
76
|
+
return TypeBoxSchemas(options);
|
|
77
|
+
case "Zod":
|
|
78
|
+
return ZodSchemas(options);
|
|
79
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
80
|
+
// @ts-ignore
|
|
81
|
+
case "Mock":
|
|
82
|
+
throw new Error("Mock schema validator not supported");
|
|
83
|
+
default:
|
|
84
|
+
(0, import_common2.isNever)(options.validator._Type);
|
|
85
|
+
throw new Error("Invalid schema validator");
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
69
90
|
// src/transformIntoInternalDtoMapper.ts
|
|
70
91
|
function transformIntoInternalDtoMapper(mappers, schemaValidator) {
|
|
71
92
|
return Object.fromEntries(
|
|
@@ -80,6 +101,7 @@ function transformIntoInternalDtoMapper(mappers, schemaValidator) {
|
|
|
80
101
|
DummyEnum,
|
|
81
102
|
IdentityRequestMapper,
|
|
82
103
|
IdentityResponseMapper,
|
|
104
|
+
serviceSchemaResolver,
|
|
83
105
|
testSchemaEquality,
|
|
84
106
|
transformIntoInternalDtoMapper
|
|
85
107
|
});
|
package/lib/index.mjs
CHANGED
|
@@ -40,6 +40,26 @@ var DummyEnum = /* @__PURE__ */ ((DummyEnum2) => {
|
|
|
40
40
|
return DummyEnum2;
|
|
41
41
|
})(DummyEnum || {});
|
|
42
42
|
|
|
43
|
+
// src/serviceSchemaResolver.ts
|
|
44
|
+
import { isNever } from "@forklaunch/common";
|
|
45
|
+
function serviceSchemaResolver(TypeBoxSchemas, ZodSchemas) {
|
|
46
|
+
return (options) => {
|
|
47
|
+
switch (options.validator._Type) {
|
|
48
|
+
case "TypeBox":
|
|
49
|
+
return TypeBoxSchemas(options);
|
|
50
|
+
case "Zod":
|
|
51
|
+
return ZodSchemas(options);
|
|
52
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
53
|
+
// @ts-ignore
|
|
54
|
+
case "Mock":
|
|
55
|
+
throw new Error("Mock schema validator not supported");
|
|
56
|
+
default:
|
|
57
|
+
isNever(options.validator._Type);
|
|
58
|
+
throw new Error("Invalid schema validator");
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
43
63
|
// src/transformIntoInternalDtoMapper.ts
|
|
44
64
|
function transformIntoInternalDtoMapper(mappers, schemaValidator) {
|
|
45
65
|
return Object.fromEntries(
|
|
@@ -53,6 +73,7 @@ export {
|
|
|
53
73
|
DummyEnum,
|
|
54
74
|
IdentityRequestMapper,
|
|
55
75
|
IdentityResponseMapper,
|
|
76
|
+
serviceSchemaResolver,
|
|
56
77
|
testSchemaEquality,
|
|
57
78
|
transformIntoInternalDtoMapper
|
|
58
79
|
};
|