@forklaunch/core 0.2.37 → 0.3.1
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 +235 -0
- package/lib/dtoMapper/index.mjs +213 -0
- package/lib/http/index.d.mts +910 -0
- package/lib/http/index.d.ts +910 -0
- package/lib/http/index.js +2189 -0
- package/lib/http/index.mjs +2134 -0
- package/lib/services/index.d.mts +69 -0
- package/lib/services/index.d.ts +69 -0
- package/lib/services/index.js +244 -0
- package/lib/services/index.mjs +215 -0
- package/package.json +68 -55
- 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,69 @@
|
|
1
|
+
import { AnySchemaValidator, IdiomaticSchema, Schema, ParseResult } from '@forklaunch/validator';
|
2
|
+
import { EntityManager as EntityManager$1 } from '@mikro-orm/core';
|
3
|
+
|
4
|
+
declare enum Lifetime {
|
5
|
+
Singleton = 0,
|
6
|
+
Transient = 1,
|
7
|
+
Scoped = 2
|
8
|
+
}
|
9
|
+
type Singleton<Value> = {
|
10
|
+
lifetime: Lifetime.Singleton;
|
11
|
+
value: Value;
|
12
|
+
};
|
13
|
+
type Constructed<Args, Return> = {
|
14
|
+
lifetime: Lifetime.Transient | Lifetime.Scoped;
|
15
|
+
factory: (args: Args, resolve: <T extends keyof Args>(token: T, context?: Record<string, unknown>) => Args[T], context: Record<string, unknown>) => Return;
|
16
|
+
};
|
17
|
+
type Constructor = new (...args: never[]) => unknown;
|
18
|
+
type SchemaConstructor<SV extends AnySchemaValidator> = new (...args: unknown[]) => IdiomaticSchema<SV>;
|
19
|
+
type Function = (...args: never[]) => unknown;
|
20
|
+
type SchemaFunction<SV extends AnySchemaValidator> = (args: unknown) => IdiomaticSchema<SV>;
|
21
|
+
type ConfigValidator<SV extends AnySchemaValidator> = Record<string, Function | SchemaFunction<SV> | Constructor | SchemaConstructor<SV> | IdiomaticSchema<SV>>;
|
22
|
+
type ResolvedConfigValidator<SV extends AnySchemaValidator, CV extends ConfigValidator<SV>> = {
|
23
|
+
[M in keyof CV]: CV[M] extends SchemaConstructor<SV> ? Schema<InstanceType<CV[M]>, SV> : CV[M] extends SchemaFunction<SV> ? Schema<ReturnType<CV[M]>, SV> : CV[M] extends Function ? ReturnType<CV[M]> : CV[M] extends Constructor ? InstanceType<CV[M]> : Schema<CV[M], SV>;
|
24
|
+
};
|
25
|
+
type ValidResolvedConfigValidator<SV extends AnySchemaValidator, CV extends ConfigValidator<SV>> = ResolvedConfigValidator<SV, CV> & {
|
26
|
+
validResolvedConfigValidator: void;
|
27
|
+
};
|
28
|
+
type ScopedDependencyFactory<SV extends AnySchemaValidator, CV extends ConfigValidator<SV>, M extends keyof CV> = (scope?: ConfigInjector<SV, CV>) => ResolvedConfigValidator<SV, CV>[M];
|
29
|
+
|
30
|
+
declare class ConfigInjector<SV extends AnySchemaValidator, CV extends ConfigValidator<SV>> {
|
31
|
+
private schemaValidator;
|
32
|
+
private configShapes;
|
33
|
+
private dependenciesDefinition;
|
34
|
+
instances: {
|
35
|
+
[K in keyof CV]?: ResolvedConfigValidator<SV, CV>[K];
|
36
|
+
};
|
37
|
+
private loadSingletons;
|
38
|
+
private resolveInstance;
|
39
|
+
constructor(schemaValidator: SV, configShapes: CV, dependenciesDefinition: {
|
40
|
+
[K in keyof CV]: Singleton<ResolvedConfigValidator<SV, CV>[K]> | Constructed<Omit<ResolvedConfigValidator<SV, CV>, K>, ResolvedConfigValidator<SV, CV>[K]>;
|
41
|
+
});
|
42
|
+
validateConfigSingletons(): ParseResult<ValidResolvedConfigValidator<SV, CV>>;
|
43
|
+
resolve<T extends keyof CV>(token: T, context?: Record<string, unknown>, resolutionPath?: (keyof CV)[]): ResolvedConfigValidator<SV, CV>[T];
|
44
|
+
scopedResolver<T extends keyof CV>(token: T, context?: Record<string, unknown>, resolutionPath?: (keyof CV)[]): (scope?: ConfigInjector<SV, CV>) => ResolvedConfigValidator<SV, CV>[T];
|
45
|
+
createScope(): ConfigInjector<SV, CV>;
|
46
|
+
dispose(): void;
|
47
|
+
}
|
48
|
+
|
49
|
+
declare function getEnvVar(name: string): string;
|
50
|
+
|
51
|
+
/**
|
52
|
+
* Interface representing a base service.
|
53
|
+
*
|
54
|
+
* @interface BaseService
|
55
|
+
*/
|
56
|
+
interface BaseService {
|
57
|
+
/**
|
58
|
+
* The EntityManager instance for managing entities.
|
59
|
+
*
|
60
|
+
* @type {EntityManager}
|
61
|
+
*/
|
62
|
+
em: EntityManager$1;
|
63
|
+
}
|
64
|
+
|
65
|
+
type EntityManager = {
|
66
|
+
fork: <Options>(options?: Options) => EntityManager;
|
67
|
+
};
|
68
|
+
|
69
|
+
export { type BaseService, ConfigInjector, type ConfigValidator, type Constructed, type Constructor, type EntityManager, type Function, Lifetime, type ResolvedConfigValidator, type SchemaConstructor, type SchemaFunction, type ScopedDependencyFactory, type Singleton, type ValidResolvedConfigValidator, getEnvVar };
|
@@ -0,0 +1,69 @@
|
|
1
|
+
import { AnySchemaValidator, IdiomaticSchema, Schema, ParseResult } from '@forklaunch/validator';
|
2
|
+
import { EntityManager as EntityManager$1 } from '@mikro-orm/core';
|
3
|
+
|
4
|
+
declare enum Lifetime {
|
5
|
+
Singleton = 0,
|
6
|
+
Transient = 1,
|
7
|
+
Scoped = 2
|
8
|
+
}
|
9
|
+
type Singleton<Value> = {
|
10
|
+
lifetime: Lifetime.Singleton;
|
11
|
+
value: Value;
|
12
|
+
};
|
13
|
+
type Constructed<Args, Return> = {
|
14
|
+
lifetime: Lifetime.Transient | Lifetime.Scoped;
|
15
|
+
factory: (args: Args, resolve: <T extends keyof Args>(token: T, context?: Record<string, unknown>) => Args[T], context: Record<string, unknown>) => Return;
|
16
|
+
};
|
17
|
+
type Constructor = new (...args: never[]) => unknown;
|
18
|
+
type SchemaConstructor<SV extends AnySchemaValidator> = new (...args: unknown[]) => IdiomaticSchema<SV>;
|
19
|
+
type Function = (...args: never[]) => unknown;
|
20
|
+
type SchemaFunction<SV extends AnySchemaValidator> = (args: unknown) => IdiomaticSchema<SV>;
|
21
|
+
type ConfigValidator<SV extends AnySchemaValidator> = Record<string, Function | SchemaFunction<SV> | Constructor | SchemaConstructor<SV> | IdiomaticSchema<SV>>;
|
22
|
+
type ResolvedConfigValidator<SV extends AnySchemaValidator, CV extends ConfigValidator<SV>> = {
|
23
|
+
[M in keyof CV]: CV[M] extends SchemaConstructor<SV> ? Schema<InstanceType<CV[M]>, SV> : CV[M] extends SchemaFunction<SV> ? Schema<ReturnType<CV[M]>, SV> : CV[M] extends Function ? ReturnType<CV[M]> : CV[M] extends Constructor ? InstanceType<CV[M]> : Schema<CV[M], SV>;
|
24
|
+
};
|
25
|
+
type ValidResolvedConfigValidator<SV extends AnySchemaValidator, CV extends ConfigValidator<SV>> = ResolvedConfigValidator<SV, CV> & {
|
26
|
+
validResolvedConfigValidator: void;
|
27
|
+
};
|
28
|
+
type ScopedDependencyFactory<SV extends AnySchemaValidator, CV extends ConfigValidator<SV>, M extends keyof CV> = (scope?: ConfigInjector<SV, CV>) => ResolvedConfigValidator<SV, CV>[M];
|
29
|
+
|
30
|
+
declare class ConfigInjector<SV extends AnySchemaValidator, CV extends ConfigValidator<SV>> {
|
31
|
+
private schemaValidator;
|
32
|
+
private configShapes;
|
33
|
+
private dependenciesDefinition;
|
34
|
+
instances: {
|
35
|
+
[K in keyof CV]?: ResolvedConfigValidator<SV, CV>[K];
|
36
|
+
};
|
37
|
+
private loadSingletons;
|
38
|
+
private resolveInstance;
|
39
|
+
constructor(schemaValidator: SV, configShapes: CV, dependenciesDefinition: {
|
40
|
+
[K in keyof CV]: Singleton<ResolvedConfigValidator<SV, CV>[K]> | Constructed<Omit<ResolvedConfigValidator<SV, CV>, K>, ResolvedConfigValidator<SV, CV>[K]>;
|
41
|
+
});
|
42
|
+
validateConfigSingletons(): ParseResult<ValidResolvedConfigValidator<SV, CV>>;
|
43
|
+
resolve<T extends keyof CV>(token: T, context?: Record<string, unknown>, resolutionPath?: (keyof CV)[]): ResolvedConfigValidator<SV, CV>[T];
|
44
|
+
scopedResolver<T extends keyof CV>(token: T, context?: Record<string, unknown>, resolutionPath?: (keyof CV)[]): (scope?: ConfigInjector<SV, CV>) => ResolvedConfigValidator<SV, CV>[T];
|
45
|
+
createScope(): ConfigInjector<SV, CV>;
|
46
|
+
dispose(): void;
|
47
|
+
}
|
48
|
+
|
49
|
+
declare function getEnvVar(name: string): string;
|
50
|
+
|
51
|
+
/**
|
52
|
+
* Interface representing a base service.
|
53
|
+
*
|
54
|
+
* @interface BaseService
|
55
|
+
*/
|
56
|
+
interface BaseService {
|
57
|
+
/**
|
58
|
+
* The EntityManager instance for managing entities.
|
59
|
+
*
|
60
|
+
* @type {EntityManager}
|
61
|
+
*/
|
62
|
+
em: EntityManager$1;
|
63
|
+
}
|
64
|
+
|
65
|
+
type EntityManager = {
|
66
|
+
fork: <Options>(options?: Options) => EntityManager;
|
67
|
+
};
|
68
|
+
|
69
|
+
export { type BaseService, ConfigInjector, type ConfigValidator, type Constructed, type Constructor, type EntityManager, type Function, Lifetime, type ResolvedConfigValidator, type SchemaConstructor, type SchemaFunction, type ScopedDependencyFactory, type Singleton, type ValidResolvedConfigValidator, getEnvVar };
|
@@ -0,0 +1,244 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __defProp = Object.defineProperty;
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
+
var __export = (target, all) => {
|
7
|
+
for (var name in all)
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
9
|
+
};
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
12
|
+
for (let key of __getOwnPropNames(from))
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
15
|
+
}
|
16
|
+
return to;
|
17
|
+
};
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
|
+
|
20
|
+
// src/services/index.ts
|
21
|
+
var services_exports = {};
|
22
|
+
__export(services_exports, {
|
23
|
+
ConfigInjector: () => ConfigInjector,
|
24
|
+
Lifetime: () => Lifetime,
|
25
|
+
getEnvVar: () => getEnvVar
|
26
|
+
});
|
27
|
+
module.exports = __toCommonJS(services_exports);
|
28
|
+
|
29
|
+
// src/services/configInjector.ts
|
30
|
+
var import_common = require("@forklaunch/common");
|
31
|
+
|
32
|
+
// src/services/guards/isConstructed.ts
|
33
|
+
function isConstructed(value) {
|
34
|
+
return typeof value === "object" && value != null && "constructor" in value && value.constructor != null;
|
35
|
+
}
|
36
|
+
|
37
|
+
// src/services/guards/isConstructor.ts
|
38
|
+
function isConstructor(value) {
|
39
|
+
return typeof value === "function" && value.constructor != null && value.prototype != null;
|
40
|
+
}
|
41
|
+
|
42
|
+
// src/services/types/configInjector.types.ts
|
43
|
+
var Lifetime = /* @__PURE__ */ ((Lifetime2) => {
|
44
|
+
Lifetime2[Lifetime2["Singleton"] = 0] = "Singleton";
|
45
|
+
Lifetime2[Lifetime2["Transient"] = 1] = "Transient";
|
46
|
+
Lifetime2[Lifetime2["Scoped"] = 2] = "Scoped";
|
47
|
+
return Lifetime2;
|
48
|
+
})(Lifetime || {});
|
49
|
+
|
50
|
+
// src/services/configInjector.ts
|
51
|
+
var ConfigInjector = class _ConfigInjector {
|
52
|
+
constructor(schemaValidator, configShapes, dependenciesDefinition) {
|
53
|
+
this.schemaValidator = schemaValidator;
|
54
|
+
this.configShapes = configShapes;
|
55
|
+
this.dependenciesDefinition = dependenciesDefinition;
|
56
|
+
this.loadSingletons();
|
57
|
+
}
|
58
|
+
instances = {};
|
59
|
+
loadSingletons() {
|
60
|
+
for (const token in this.dependenciesDefinition) {
|
61
|
+
const definition = this.dependenciesDefinition[token];
|
62
|
+
if (definition.lifetime === 0 /* Singleton */) {
|
63
|
+
this.instances[token] = definition.value;
|
64
|
+
}
|
65
|
+
}
|
66
|
+
}
|
67
|
+
resolveInstance(token, definition, context, resolutionPath = []) {
|
68
|
+
const injectorArgument = (0, import_common.extractArgumentNames)(definition.factory)[0];
|
69
|
+
if (injectorArgument === "_args") {
|
70
|
+
return definition.factory(
|
71
|
+
{},
|
72
|
+
this.resolve.bind(this),
|
73
|
+
context ?? {}
|
74
|
+
);
|
75
|
+
}
|
76
|
+
if (!injectorArgument.startsWith("{") || !injectorArgument.endsWith("}")) {
|
77
|
+
throw new Error(
|
78
|
+
`Invalid injector argument for ${String(
|
79
|
+
token
|
80
|
+
)}: ${injectorArgument}. Please use object destructuring syntax: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment.`
|
81
|
+
);
|
82
|
+
}
|
83
|
+
const resolvedArguments = Object.fromEntries(
|
84
|
+
injectorArgument.replace("{", "").replace("}", "").split(",").map((arg) => arg.split(":")[0].trim()).map((arg) => {
|
85
|
+
const newResolutionPath = [...resolutionPath, token];
|
86
|
+
if (resolutionPath.includes(arg)) {
|
87
|
+
throw new Error(
|
88
|
+
`Circular dependency detected: ${newResolutionPath.join(
|
89
|
+
" -> "
|
90
|
+
)} -> ${arg}`
|
91
|
+
);
|
92
|
+
}
|
93
|
+
const resolvedArg = this.resolve(arg, context, newResolutionPath);
|
94
|
+
return [arg, resolvedArg];
|
95
|
+
})
|
96
|
+
);
|
97
|
+
return definition.factory(
|
98
|
+
resolvedArguments,
|
99
|
+
this.resolve.bind(this),
|
100
|
+
context ?? {}
|
101
|
+
);
|
102
|
+
}
|
103
|
+
validateConfigSingletons() {
|
104
|
+
const validNonSchemaSingletons = Object.entries(this.configShapes).reduce(
|
105
|
+
(acc, [key, value]) => {
|
106
|
+
if (this.dependenciesDefinition[key].lifetime === 0 /* Singleton */ && !this.schemaValidator.isSchema(value) && isConstructor(value)) {
|
107
|
+
if (!(this.dependenciesDefinition[key].value instanceof value)) {
|
108
|
+
const expected = value.name;
|
109
|
+
const receivedValue = this.dependenciesDefinition[key].value;
|
110
|
+
const received = isConstructed(receivedValue) ? receivedValue.constructor.name : typeof receivedValue;
|
111
|
+
if (acc.ok) {
|
112
|
+
acc = {
|
113
|
+
ok: false,
|
114
|
+
errors: []
|
115
|
+
};
|
116
|
+
}
|
117
|
+
acc.errors?.push({
|
118
|
+
message: `Expected ${expected}, received ${received}`,
|
119
|
+
path: [key]
|
120
|
+
});
|
121
|
+
} else {
|
122
|
+
if (acc.ok) {
|
123
|
+
acc = {
|
124
|
+
ok: true,
|
125
|
+
value: {
|
126
|
+
...acc.value,
|
127
|
+
[key]: this.dependenciesDefinition[key].value
|
128
|
+
}
|
129
|
+
};
|
130
|
+
}
|
131
|
+
}
|
132
|
+
return acc;
|
133
|
+
}
|
134
|
+
return acc;
|
135
|
+
},
|
136
|
+
{
|
137
|
+
ok: true,
|
138
|
+
value: {}
|
139
|
+
}
|
140
|
+
);
|
141
|
+
const singletons = Object.fromEntries(
|
142
|
+
Object.entries(this.configShapes).filter(
|
143
|
+
([key, value]) => this.dependenciesDefinition[key].lifetime === 0 /* Singleton */ && this.schemaValidator.isSchema(value)
|
144
|
+
)
|
145
|
+
);
|
146
|
+
const schemaSingletonParseResult = this.schemaValidator.parse(
|
147
|
+
this.schemaValidator.schemify(singletons),
|
148
|
+
Object.fromEntries(
|
149
|
+
Object.keys(singletons).map((key) => {
|
150
|
+
const dependency = this.dependenciesDefinition[key];
|
151
|
+
return [
|
152
|
+
key,
|
153
|
+
dependency.lifetime === 0 /* Singleton */ ? dependency.value : void 0
|
154
|
+
];
|
155
|
+
})
|
156
|
+
)
|
157
|
+
);
|
158
|
+
const configKeys = Object.keys(this.configShapes);
|
159
|
+
return validNonSchemaSingletons.ok && schemaSingletonParseResult.ok ? {
|
160
|
+
ok: true,
|
161
|
+
value: {
|
162
|
+
validResolvedConfigValidator: void 0,
|
163
|
+
...validNonSchemaSingletons.value,
|
164
|
+
...schemaSingletonParseResult.value
|
165
|
+
}
|
166
|
+
} : {
|
167
|
+
ok: false,
|
168
|
+
errors: [
|
169
|
+
...!validNonSchemaSingletons.ok && validNonSchemaSingletons.errors ? validNonSchemaSingletons.errors : [],
|
170
|
+
...!schemaSingletonParseResult.ok && schemaSingletonParseResult.errors ? schemaSingletonParseResult.errors : []
|
171
|
+
].sort(
|
172
|
+
(a, b) => configKeys.indexOf(a.path[0]) - configKeys.indexOf(b.path[0])
|
173
|
+
)
|
174
|
+
};
|
175
|
+
}
|
176
|
+
resolve(token, context, resolutionPath = []) {
|
177
|
+
const instance = this.instances[token];
|
178
|
+
if (!instance) {
|
179
|
+
const definition = this.dependenciesDefinition[token];
|
180
|
+
if (!definition) {
|
181
|
+
throw new Error(`Unable to resolve dependency ${String(token)}`);
|
182
|
+
}
|
183
|
+
switch (definition.lifetime) {
|
184
|
+
case 0 /* Singleton */: {
|
185
|
+
return definition.value;
|
186
|
+
}
|
187
|
+
case 2 /* Scoped */: {
|
188
|
+
const scopedInstance = this.resolveInstance(
|
189
|
+
token,
|
190
|
+
definition,
|
191
|
+
context,
|
192
|
+
resolutionPath
|
193
|
+
);
|
194
|
+
this.instances[token] = scopedInstance;
|
195
|
+
return scopedInstance;
|
196
|
+
}
|
197
|
+
case 1 /* Transient */: {
|
198
|
+
return this.resolveInstance(
|
199
|
+
token,
|
200
|
+
definition,
|
201
|
+
context,
|
202
|
+
resolutionPath
|
203
|
+
);
|
204
|
+
}
|
205
|
+
default: {
|
206
|
+
(0, import_common.isNever)(definition);
|
207
|
+
throw new Error(
|
208
|
+
`Unable to resolve lifetime for dependency ${String(
|
209
|
+
token
|
210
|
+
)}, ${resolutionPath}`
|
211
|
+
);
|
212
|
+
}
|
213
|
+
}
|
214
|
+
} else {
|
215
|
+
return instance;
|
216
|
+
}
|
217
|
+
}
|
218
|
+
scopedResolver(token, context, resolutionPath = []) {
|
219
|
+
return (scope) => (scope ?? this.createScope()).resolve(token, context, resolutionPath);
|
220
|
+
}
|
221
|
+
createScope() {
|
222
|
+
return new _ConfigInjector(
|
223
|
+
this.schemaValidator,
|
224
|
+
this.configShapes,
|
225
|
+
this.dependenciesDefinition
|
226
|
+
);
|
227
|
+
}
|
228
|
+
dispose() {
|
229
|
+
this.instances = {};
|
230
|
+
this.loadSingletons();
|
231
|
+
}
|
232
|
+
};
|
233
|
+
|
234
|
+
// src/services/getEnvVar.ts
|
235
|
+
function getEnvVar(name) {
|
236
|
+
const value = process.env[name];
|
237
|
+
return value;
|
238
|
+
}
|
239
|
+
// Annotate the CommonJS export names for ESM import in node:
|
240
|
+
0 && (module.exports = {
|
241
|
+
ConfigInjector,
|
242
|
+
Lifetime,
|
243
|
+
getEnvVar
|
244
|
+
});
|
@@ -0,0 +1,215 @@
|
|
1
|
+
// src/services/configInjector.ts
|
2
|
+
import { extractArgumentNames, isNever } from "@forklaunch/common";
|
3
|
+
|
4
|
+
// src/services/guards/isConstructed.ts
|
5
|
+
function isConstructed(value) {
|
6
|
+
return typeof value === "object" && value != null && "constructor" in value && value.constructor != null;
|
7
|
+
}
|
8
|
+
|
9
|
+
// src/services/guards/isConstructor.ts
|
10
|
+
function isConstructor(value) {
|
11
|
+
return typeof value === "function" && value.constructor != null && value.prototype != null;
|
12
|
+
}
|
13
|
+
|
14
|
+
// src/services/types/configInjector.types.ts
|
15
|
+
var Lifetime = /* @__PURE__ */ ((Lifetime2) => {
|
16
|
+
Lifetime2[Lifetime2["Singleton"] = 0] = "Singleton";
|
17
|
+
Lifetime2[Lifetime2["Transient"] = 1] = "Transient";
|
18
|
+
Lifetime2[Lifetime2["Scoped"] = 2] = "Scoped";
|
19
|
+
return Lifetime2;
|
20
|
+
})(Lifetime || {});
|
21
|
+
|
22
|
+
// src/services/configInjector.ts
|
23
|
+
var ConfigInjector = class _ConfigInjector {
|
24
|
+
constructor(schemaValidator, configShapes, dependenciesDefinition) {
|
25
|
+
this.schemaValidator = schemaValidator;
|
26
|
+
this.configShapes = configShapes;
|
27
|
+
this.dependenciesDefinition = dependenciesDefinition;
|
28
|
+
this.loadSingletons();
|
29
|
+
}
|
30
|
+
instances = {};
|
31
|
+
loadSingletons() {
|
32
|
+
for (const token in this.dependenciesDefinition) {
|
33
|
+
const definition = this.dependenciesDefinition[token];
|
34
|
+
if (definition.lifetime === 0 /* Singleton */) {
|
35
|
+
this.instances[token] = definition.value;
|
36
|
+
}
|
37
|
+
}
|
38
|
+
}
|
39
|
+
resolveInstance(token, definition, context, resolutionPath = []) {
|
40
|
+
const injectorArgument = extractArgumentNames(definition.factory)[0];
|
41
|
+
if (injectorArgument === "_args") {
|
42
|
+
return definition.factory(
|
43
|
+
{},
|
44
|
+
this.resolve.bind(this),
|
45
|
+
context ?? {}
|
46
|
+
);
|
47
|
+
}
|
48
|
+
if (!injectorArgument.startsWith("{") || !injectorArgument.endsWith("}")) {
|
49
|
+
throw new Error(
|
50
|
+
`Invalid injector argument for ${String(
|
51
|
+
token
|
52
|
+
)}: ${injectorArgument}. Please use object destructuring syntax: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment.`
|
53
|
+
);
|
54
|
+
}
|
55
|
+
const resolvedArguments = Object.fromEntries(
|
56
|
+
injectorArgument.replace("{", "").replace("}", "").split(",").map((arg) => arg.split(":")[0].trim()).map((arg) => {
|
57
|
+
const newResolutionPath = [...resolutionPath, token];
|
58
|
+
if (resolutionPath.includes(arg)) {
|
59
|
+
throw new Error(
|
60
|
+
`Circular dependency detected: ${newResolutionPath.join(
|
61
|
+
" -> "
|
62
|
+
)} -> ${arg}`
|
63
|
+
);
|
64
|
+
}
|
65
|
+
const resolvedArg = this.resolve(arg, context, newResolutionPath);
|
66
|
+
return [arg, resolvedArg];
|
67
|
+
})
|
68
|
+
);
|
69
|
+
return definition.factory(
|
70
|
+
resolvedArguments,
|
71
|
+
this.resolve.bind(this),
|
72
|
+
context ?? {}
|
73
|
+
);
|
74
|
+
}
|
75
|
+
validateConfigSingletons() {
|
76
|
+
const validNonSchemaSingletons = Object.entries(this.configShapes).reduce(
|
77
|
+
(acc, [key, value]) => {
|
78
|
+
if (this.dependenciesDefinition[key].lifetime === 0 /* Singleton */ && !this.schemaValidator.isSchema(value) && isConstructor(value)) {
|
79
|
+
if (!(this.dependenciesDefinition[key].value instanceof value)) {
|
80
|
+
const expected = value.name;
|
81
|
+
const receivedValue = this.dependenciesDefinition[key].value;
|
82
|
+
const received = isConstructed(receivedValue) ? receivedValue.constructor.name : typeof receivedValue;
|
83
|
+
if (acc.ok) {
|
84
|
+
acc = {
|
85
|
+
ok: false,
|
86
|
+
errors: []
|
87
|
+
};
|
88
|
+
}
|
89
|
+
acc.errors?.push({
|
90
|
+
message: `Expected ${expected}, received ${received}`,
|
91
|
+
path: [key]
|
92
|
+
});
|
93
|
+
} else {
|
94
|
+
if (acc.ok) {
|
95
|
+
acc = {
|
96
|
+
ok: true,
|
97
|
+
value: {
|
98
|
+
...acc.value,
|
99
|
+
[key]: this.dependenciesDefinition[key].value
|
100
|
+
}
|
101
|
+
};
|
102
|
+
}
|
103
|
+
}
|
104
|
+
return acc;
|
105
|
+
}
|
106
|
+
return acc;
|
107
|
+
},
|
108
|
+
{
|
109
|
+
ok: true,
|
110
|
+
value: {}
|
111
|
+
}
|
112
|
+
);
|
113
|
+
const singletons = Object.fromEntries(
|
114
|
+
Object.entries(this.configShapes).filter(
|
115
|
+
([key, value]) => this.dependenciesDefinition[key].lifetime === 0 /* Singleton */ && this.schemaValidator.isSchema(value)
|
116
|
+
)
|
117
|
+
);
|
118
|
+
const schemaSingletonParseResult = this.schemaValidator.parse(
|
119
|
+
this.schemaValidator.schemify(singletons),
|
120
|
+
Object.fromEntries(
|
121
|
+
Object.keys(singletons).map((key) => {
|
122
|
+
const dependency = this.dependenciesDefinition[key];
|
123
|
+
return [
|
124
|
+
key,
|
125
|
+
dependency.lifetime === 0 /* Singleton */ ? dependency.value : void 0
|
126
|
+
];
|
127
|
+
})
|
128
|
+
)
|
129
|
+
);
|
130
|
+
const configKeys = Object.keys(this.configShapes);
|
131
|
+
return validNonSchemaSingletons.ok && schemaSingletonParseResult.ok ? {
|
132
|
+
ok: true,
|
133
|
+
value: {
|
134
|
+
validResolvedConfigValidator: void 0,
|
135
|
+
...validNonSchemaSingletons.value,
|
136
|
+
...schemaSingletonParseResult.value
|
137
|
+
}
|
138
|
+
} : {
|
139
|
+
ok: false,
|
140
|
+
errors: [
|
141
|
+
...!validNonSchemaSingletons.ok && validNonSchemaSingletons.errors ? validNonSchemaSingletons.errors : [],
|
142
|
+
...!schemaSingletonParseResult.ok && schemaSingletonParseResult.errors ? schemaSingletonParseResult.errors : []
|
143
|
+
].sort(
|
144
|
+
(a, b) => configKeys.indexOf(a.path[0]) - configKeys.indexOf(b.path[0])
|
145
|
+
)
|
146
|
+
};
|
147
|
+
}
|
148
|
+
resolve(token, context, resolutionPath = []) {
|
149
|
+
const instance = this.instances[token];
|
150
|
+
if (!instance) {
|
151
|
+
const definition = this.dependenciesDefinition[token];
|
152
|
+
if (!definition) {
|
153
|
+
throw new Error(`Unable to resolve dependency ${String(token)}`);
|
154
|
+
}
|
155
|
+
switch (definition.lifetime) {
|
156
|
+
case 0 /* Singleton */: {
|
157
|
+
return definition.value;
|
158
|
+
}
|
159
|
+
case 2 /* Scoped */: {
|
160
|
+
const scopedInstance = this.resolveInstance(
|
161
|
+
token,
|
162
|
+
definition,
|
163
|
+
context,
|
164
|
+
resolutionPath
|
165
|
+
);
|
166
|
+
this.instances[token] = scopedInstance;
|
167
|
+
return scopedInstance;
|
168
|
+
}
|
169
|
+
case 1 /* Transient */: {
|
170
|
+
return this.resolveInstance(
|
171
|
+
token,
|
172
|
+
definition,
|
173
|
+
context,
|
174
|
+
resolutionPath
|
175
|
+
);
|
176
|
+
}
|
177
|
+
default: {
|
178
|
+
isNever(definition);
|
179
|
+
throw new Error(
|
180
|
+
`Unable to resolve lifetime for dependency ${String(
|
181
|
+
token
|
182
|
+
)}, ${resolutionPath}`
|
183
|
+
);
|
184
|
+
}
|
185
|
+
}
|
186
|
+
} else {
|
187
|
+
return instance;
|
188
|
+
}
|
189
|
+
}
|
190
|
+
scopedResolver(token, context, resolutionPath = []) {
|
191
|
+
return (scope) => (scope ?? this.createScope()).resolve(token, context, resolutionPath);
|
192
|
+
}
|
193
|
+
createScope() {
|
194
|
+
return new _ConfigInjector(
|
195
|
+
this.schemaValidator,
|
196
|
+
this.configShapes,
|
197
|
+
this.dependenciesDefinition
|
198
|
+
);
|
199
|
+
}
|
200
|
+
dispose() {
|
201
|
+
this.instances = {};
|
202
|
+
this.loadSingletons();
|
203
|
+
}
|
204
|
+
};
|
205
|
+
|
206
|
+
// src/services/getEnvVar.ts
|
207
|
+
function getEnvVar(name) {
|
208
|
+
const value = process.env[name];
|
209
|
+
return value;
|
210
|
+
}
|
211
|
+
export {
|
212
|
+
ConfigInjector,
|
213
|
+
Lifetime,
|
214
|
+
getEnvVar
|
215
|
+
};
|