@forklaunch/core 0.2.36 → 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.
Files changed (222) hide show
  1. package/lib/{src/database/mikro/models/entities/base.entity.d.ts → base.entity-DNfmMOgd.d.mts} +3 -2
  2. package/lib/base.entity-DNfmMOgd.d.ts +27 -0
  3. package/lib/{src/cache/redisTtlCache.d.ts → cache/index.d.mts} +67 -4
  4. package/lib/cache/index.d.ts +130 -0
  5. package/lib/cache/index.js +133 -0
  6. package/lib/cache/index.mjs +105 -0
  7. package/lib/controllers/index.d.mts +5 -0
  8. package/lib/controllers/index.d.ts +5 -0
  9. package/lib/controllers/index.js +18 -0
  10. package/lib/controllers/index.mjs +0 -0
  11. package/lib/database/index.d.mts +37 -0
  12. package/lib/{src/database/mikro/models/entities/mongo.base.entity.d.ts → database/index.d.ts} +5 -2
  13. package/lib/database/index.js +78 -0
  14. package/lib/database/index.mjs +53 -0
  15. package/lib/dtoMapper/index.d.mts +215 -0
  16. package/lib/dtoMapper/index.d.ts +215 -0
  17. package/lib/dtoMapper/index.js +230 -0
  18. package/lib/dtoMapper/index.mjs +202 -0
  19. package/lib/http/index.d.mts +910 -0
  20. package/lib/http/index.d.ts +910 -0
  21. package/lib/http/index.js +2181 -0
  22. package/lib/http/index.mjs +2122 -0
  23. package/lib/services/index.d.mts +64 -0
  24. package/lib/services/index.d.ts +64 -0
  25. package/lib/services/index.js +159 -0
  26. package/lib/services/index.mjs +131 -0
  27. package/package.json +39 -26
  28. package/lib/src/cache/index.d.ts +0 -5
  29. package/lib/src/cache/index.d.ts.map +0 -1
  30. package/lib/src/cache/index.js +0 -4
  31. package/lib/src/cache/interfaces/ttlCache.interface.d.ts +0 -48
  32. package/lib/src/cache/interfaces/ttlCache.interface.d.ts.map +0 -1
  33. package/lib/src/cache/interfaces/ttlCache.interface.js +0 -1
  34. package/lib/src/cache/redisTtlCache.d.ts.map +0 -1
  35. package/lib/src/cache/redisTtlCache.js +0 -98
  36. package/lib/src/cache/types/ttlCacheRecord.types.d.ts +0 -14
  37. package/lib/src/cache/types/ttlCacheRecord.types.d.ts.map +0 -1
  38. package/lib/src/cache/types/ttlCacheRecord.types.js +0 -1
  39. package/lib/src/cache/utils/cacheKey.d.ts +0 -2
  40. package/lib/src/cache/utils/cacheKey.d.ts.map +0 -1
  41. package/lib/src/cache/utils/cacheKey.js +0 -3
  42. package/lib/src/controllers/index.d.ts +0 -2
  43. package/lib/src/controllers/index.d.ts.map +0 -1
  44. package/lib/src/controllers/index.js +0 -1
  45. package/lib/src/controllers/interfaces/controller.interface.d.ts +0 -4
  46. package/lib/src/controllers/interfaces/controller.interface.d.ts.map +0 -1
  47. package/lib/src/controllers/interfaces/controller.interface.js +0 -1
  48. package/lib/src/database/index.d.ts +0 -3
  49. package/lib/src/database/index.d.ts.map +0 -1
  50. package/lib/src/database/index.js +0 -2
  51. package/lib/src/database/mikro/models/entities/base.entity.d.ts.map +0 -1
  52. package/lib/src/database/mikro/models/entities/base.entity.js +0 -42
  53. package/lib/src/database/mikro/models/entities/mongo.base.entity.d.ts.map +0 -1
  54. package/lib/src/database/mikro/models/entities/mongo.base.entity.js +0 -51
  55. package/lib/src/dtoMapper/index.d.ts +0 -3
  56. package/lib/src/dtoMapper/index.d.ts.map +0 -1
  57. package/lib/src/dtoMapper/index.js +0 -2
  58. package/lib/src/dtoMapper/interfaces/dtoMapper.interface.d.ts +0 -18
  59. package/lib/src/dtoMapper/interfaces/dtoMapper.interface.d.ts.map +0 -1
  60. package/lib/src/dtoMapper/interfaces/dtoMapper.interface.js +0 -1
  61. package/lib/src/dtoMapper/models/baseDtoMapper.model.d.ts +0 -72
  62. package/lib/src/dtoMapper/models/baseDtoMapper.model.d.ts.map +0 -1
  63. package/lib/src/dtoMapper/models/baseDtoMapper.model.js +0 -76
  64. package/lib/src/dtoMapper/models/requestDtoMapper.model.d.ts +0 -68
  65. package/lib/src/dtoMapper/models/requestDtoMapper.model.d.ts.map +0 -1
  66. package/lib/src/dtoMapper/models/requestDtoMapper.model.js +0 -71
  67. package/lib/src/dtoMapper/models/responseDtoMapper.model.d.ts +0 -67
  68. package/lib/src/dtoMapper/models/responseDtoMapper.model.d.ts.map +0 -1
  69. package/lib/src/dtoMapper/models/responseDtoMapper.model.js +0 -68
  70. package/lib/src/dtoMapper/types/dtoMapper.types.d.ts +0 -9
  71. package/lib/src/dtoMapper/types/dtoMapper.types.d.ts.map +0 -1
  72. package/lib/src/dtoMapper/types/dtoMapper.types.js +0 -1
  73. package/lib/src/http/application/expressLikeApplication.d.ts +0 -21
  74. package/lib/src/http/application/expressLikeApplication.d.ts.map +0 -1
  75. package/lib/src/http/application/expressLikeApplication.js +0 -21
  76. package/lib/src/http/guards/isConstrainedForklaunchRouter.d.ts +0 -4
  77. package/lib/src/http/guards/isConstrainedForklaunchRouter.d.ts.map +0 -1
  78. package/lib/src/http/guards/isConstrainedForklaunchRouter.js +0 -5
  79. package/lib/src/http/guards/isExpressLikeSchemaHandler.d.ts +0 -5
  80. package/lib/src/http/guards/isExpressLikeSchemaHandler.d.ts.map +0 -1
  81. package/lib/src/http/guards/isExpressLikeSchemaHandler.js +0 -6
  82. package/lib/src/http/guards/isForklaunchExpressLikeRouter.d.ts +0 -5
  83. package/lib/src/http/guards/isForklaunchExpressLikeRouter.d.ts.map +0 -1
  84. package/lib/src/http/guards/isForklaunchExpressLikeRouter.js +0 -6
  85. package/lib/src/http/guards/isForklaunchRouter.d.ts +0 -4
  86. package/lib/src/http/guards/isForklaunchRouter.d.ts.map +0 -1
  87. package/lib/src/http/guards/isForklaunchRouter.js +0 -7
  88. package/lib/src/http/guards/isHttpContractDetails.d.ts +0 -7
  89. package/lib/src/http/guards/isHttpContractDetails.d.ts.map +0 -1
  90. package/lib/src/http/guards/isHttpContractDetails.js +0 -9
  91. package/lib/src/http/guards/isPathParamContractDetails.d.ts +0 -4
  92. package/lib/src/http/guards/isPathParamContractDetails.d.ts.map +0 -1
  93. package/lib/src/http/guards/isPathParamContractDetails.js +0 -10
  94. package/lib/src/http/guards/isResponseShape.d.ts +0 -3
  95. package/lib/src/http/guards/isResponseShape.d.ts.map +0 -1
  96. package/lib/src/http/guards/isResponseShape.js +0 -7
  97. package/lib/src/http/guards/isTypedHandler.d.ts +0 -5
  98. package/lib/src/http/guards/isTypedHandler.d.ts.map +0 -1
  99. package/lib/src/http/guards/isTypedHandler.js +0 -6
  100. package/lib/src/http/handlers/delete.d.ts +0 -9
  101. package/lib/src/http/handlers/delete.d.ts.map +0 -1
  102. package/lib/src/http/handlers/delete.js +0 -4
  103. package/lib/src/http/handlers/get.d.ts +0 -9
  104. package/lib/src/http/handlers/get.d.ts.map +0 -1
  105. package/lib/src/http/handlers/get.js +0 -4
  106. package/lib/src/http/handlers/head.d.ts +0 -9
  107. package/lib/src/http/handlers/head.d.ts.map +0 -1
  108. package/lib/src/http/handlers/head.js +0 -4
  109. package/lib/src/http/handlers/middleware.d.ts +0 -9
  110. package/lib/src/http/handlers/middleware.d.ts.map +0 -1
  111. package/lib/src/http/handlers/middleware.js +0 -4
  112. package/lib/src/http/handlers/options.d.ts +0 -9
  113. package/lib/src/http/handlers/options.d.ts.map +0 -1
  114. package/lib/src/http/handlers/options.js +0 -4
  115. package/lib/src/http/handlers/patch.d.ts +0 -9
  116. package/lib/src/http/handlers/patch.d.ts.map +0 -1
  117. package/lib/src/http/handlers/patch.js +0 -4
  118. package/lib/src/http/handlers/post.d.ts +0 -9
  119. package/lib/src/http/handlers/post.d.ts.map +0 -1
  120. package/lib/src/http/handlers/post.js +0 -4
  121. package/lib/src/http/handlers/put.d.ts +0 -9
  122. package/lib/src/http/handlers/put.d.ts.map +0 -1
  123. package/lib/src/http/handlers/put.js +0 -4
  124. package/lib/src/http/handlers/trace.d.ts +0 -9
  125. package/lib/src/http/handlers/trace.d.ts.map +0 -1
  126. package/lib/src/http/handlers/trace.js +0 -4
  127. package/lib/src/http/handlers/typedAuthHandler.d.ts +0 -5
  128. package/lib/src/http/handlers/typedAuthHandler.d.ts.map +0 -1
  129. package/lib/src/http/handlers/typedAuthHandler.js +0 -3
  130. package/lib/src/http/handlers/typedHandler.d.ts +0 -21
  131. package/lib/src/http/handlers/typedHandler.d.ts.map +0 -1
  132. package/lib/src/http/handlers/typedHandler.js +0 -30
  133. package/lib/src/http/index.d.ts +0 -23
  134. package/lib/src/http/index.d.ts.map +0 -1
  135. package/lib/src/http/index.js +0 -22
  136. package/lib/src/http/interfaces/expressLikeRouter.interface.d.ts +0 -24
  137. package/lib/src/http/interfaces/expressLikeRouter.interface.d.ts.map +0 -1
  138. package/lib/src/http/interfaces/expressLikeRouter.interface.js +0 -1
  139. package/lib/src/http/middleware/request/auth.middleware.d.ts +0 -16
  140. package/lib/src/http/middleware/request/auth.middleware.d.ts.map +0 -1
  141. package/lib/src/http/middleware/request/auth.middleware.js +0 -143
  142. package/lib/src/http/middleware/request/cors.middleware.d.ts +0 -13
  143. package/lib/src/http/middleware/request/cors.middleware.d.ts.map +0 -1
  144. package/lib/src/http/middleware/request/cors.middleware.js +0 -15
  145. package/lib/src/http/middleware/request/createContext.middleware.d.ts +0 -15
  146. package/lib/src/http/middleware/request/createContext.middleware.d.ts.map +0 -1
  147. package/lib/src/http/middleware/request/createContext.middleware.js +0 -26
  148. package/lib/src/http/middleware/request/enrichDetails.middleware.d.ts +0 -15
  149. package/lib/src/http/middleware/request/enrichDetails.middleware.d.ts.map +0 -1
  150. package/lib/src/http/middleware/request/enrichDetails.middleware.js +0 -19
  151. package/lib/src/http/middleware/request/parse.middleware.d.ts +0 -17
  152. package/lib/src/http/middleware/request/parse.middleware.d.ts.map +0 -1
  153. package/lib/src/http/middleware/request/parse.middleware.js +0 -43
  154. package/lib/src/http/middleware/response/parse.middleware.d.ts +0 -31
  155. package/lib/src/http/middleware/response/parse.middleware.d.ts.map +0 -1
  156. package/lib/src/http/middleware/response/parse.middleware.js +0 -52
  157. package/lib/src/http/openApiV3Generator/openApiV3Generator.d.ts +0 -14
  158. package/lib/src/http/openApiV3Generator/openApiV3Generator.d.ts.map +0 -1
  159. package/lib/src/http/openApiV3Generator/openApiV3Generator.js +0 -169
  160. package/lib/src/http/router/expressLikeRouter.d.ts +0 -138
  161. package/lib/src/http/router/expressLikeRouter.d.ts.map +0 -1
  162. package/lib/src/http/router/expressLikeRouter.js +0 -483
  163. package/lib/src/http/types/apiDefinition.types.d.ts +0 -260
  164. package/lib/src/http/types/apiDefinition.types.d.ts.map +0 -1
  165. package/lib/src/http/types/apiDefinition.types.js +0 -1
  166. package/lib/src/http/types/contractDetails.types.d.ts +0 -211
  167. package/lib/src/http/types/contractDetails.types.d.ts.map +0 -1
  168. package/lib/src/http/types/contractDetails.types.js +0 -1
  169. package/lib/src/http/types/expressLikeRouter.types.d.ts +0 -51
  170. package/lib/src/http/types/expressLikeRouter.types.d.ts.map +0 -1
  171. package/lib/src/http/types/expressLikeRouter.types.js +0 -1
  172. package/lib/src/http/types/router.types.d.ts +0 -32
  173. package/lib/src/http/types/router.types.d.ts.map +0 -1
  174. package/lib/src/http/types/router.types.js +0 -1
  175. package/lib/src/http/types/typedHandler.types.d.ts +0 -10
  176. package/lib/src/http/types/typedHandler.types.d.ts.map +0 -1
  177. package/lib/src/http/types/typedHandler.types.js +0 -1
  178. package/lib/src/http/utils/enrichExpressLikeSend.d.ts +0 -32
  179. package/lib/src/http/utils/enrichExpressLikeSend.d.ts.map +0 -1
  180. package/lib/src/http/utils/enrichExpressLikeSend.js +0 -50
  181. package/lib/src/http/utils/httpStatusCodes.d.ts +0 -75
  182. package/lib/src/http/utils/httpStatusCodes.d.ts.map +0 -1
  183. package/lib/src/http/utils/httpStatusCodes.js +0 -1039
  184. package/lib/src/services/configInjector.d.ts +0 -21
  185. package/lib/src/services/configInjector.d.ts.map +0 -1
  186. package/lib/src/services/configInjector.js +0 -90
  187. package/lib/src/services/index.d.ts +0 -5
  188. package/lib/src/services/index.d.ts.map +0 -1
  189. package/lib/src/services/index.js +0 -4
  190. package/lib/src/services/interfaces/baseService.d.ts +0 -15
  191. package/lib/src/services/interfaces/baseService.d.ts.map +0 -1
  192. package/lib/src/services/interfaces/baseService.js +0 -1
  193. package/lib/src/services/types/configInjector.types.d.ts +0 -25
  194. package/lib/src/services/types/configInjector.types.d.ts.map +0 -1
  195. package/lib/src/services/types/configInjector.types.js +0 -6
  196. package/lib/src/services/types/entityManager.types.d.ts +0 -4
  197. package/lib/src/services/types/entityManager.types.d.ts.map +0 -1
  198. package/lib/src/services/types/entityManager.types.js +0 -1
  199. package/lib/tests/configInjector.test.d.ts +0 -2
  200. package/lib/tests/configInjector.test.d.ts.map +0 -1
  201. package/lib/tests/configInjector.test.js +0 -105
  202. package/lib/tests/dtoMapper.test.d.ts +0 -2
  203. package/lib/tests/dtoMapper.test.d.ts.map +0 -1
  204. package/lib/tests/dtoMapper.test.js +0 -170
  205. package/lib/tests/expressLikeRouterInstantiation.test.d.ts +0 -2
  206. package/lib/tests/expressLikeRouterInstantiation.test.d.ts.map +0 -1
  207. package/lib/tests/expressLikeRouterInstantiation.test.js +0 -118
  208. package/lib/tests/http.middleware.test.d.ts +0 -2
  209. package/lib/tests/http.middleware.test.d.ts.map +0 -1
  210. package/lib/tests/http.middleware.test.js +0 -102
  211. package/lib/tests/openApiV3Generator.test.d.ts +0 -2
  212. package/lib/tests/openApiV3Generator.test.d.ts.map +0 -1
  213. package/lib/tests/openApiV3Generator.test.js +0 -66
  214. package/lib/tests/redisTtlCache.test.d.ts +0 -2
  215. package/lib/tests/redisTtlCache.test.d.ts.map +0 -1
  216. package/lib/tests/redisTtlCache.test.js +0 -49
  217. package/lib/tests/typedHandler.test.d.ts +0 -2
  218. package/lib/tests/typedHandler.test.d.ts.map +0 -1
  219. package/lib/tests/typedHandler.test.js +0 -3
  220. package/lib/vitest.config.d.ts +0 -3
  221. package/lib/vitest.config.d.ts.map +0 -1
  222. package/lib/vitest.config.js +0 -7
@@ -0,0 +1,64 @@
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 ScopedDependencyFactory<SV extends AnySchemaValidator, CV extends ConfigValidator<SV>, M extends keyof CV> = (scope?: ConfigInjector<SV, CV>) => ResolvedConfigValidator<SV, CV>[M];
26
+
27
+ declare class ConfigInjector<SV extends AnySchemaValidator, CV extends ConfigValidator<SV>> {
28
+ private schemaValidator;
29
+ private configShapes;
30
+ private dependenciesDefinition;
31
+ instances: {
32
+ [K in keyof CV]?: ResolvedConfigValidator<SV, CV>[K];
33
+ };
34
+ private loadSingletons;
35
+ private resolveInstance;
36
+ constructor(schemaValidator: SV, configShapes: CV, dependenciesDefinition: {
37
+ [K in keyof CV]: Singleton<ResolvedConfigValidator<SV, CV>[K]> | Constructed<Omit<ResolvedConfigValidator<SV, CV>, K>, ResolvedConfigValidator<SV, CV>[K]>;
38
+ });
39
+ validateConfigSingletons(config: Partial<ResolvedConfigValidator<SV, CV>>): ParseResult<unknown>;
40
+ resolve<T extends keyof CV>(token: T, context?: Record<string, unknown>, resolutionPath?: (keyof CV)[]): ResolvedConfigValidator<SV, CV>[T];
41
+ scopedResolver<T extends keyof CV>(token: T, context?: Record<string, unknown>, resolutionPath?: (keyof CV)[]): (scope?: ConfigInjector<SV, CV>) => ResolvedConfigValidator<SV, CV>[T];
42
+ createScope(): ConfigInjector<SV, CV>;
43
+ dispose(): void;
44
+ }
45
+
46
+ /**
47
+ * Interface representing a base service.
48
+ *
49
+ * @interface BaseService
50
+ */
51
+ interface BaseService {
52
+ /**
53
+ * The EntityManager instance for managing entities.
54
+ *
55
+ * @type {EntityManager}
56
+ */
57
+ em: EntityManager$1;
58
+ }
59
+
60
+ type EntityManager = {
61
+ fork: <Options>(options?: Options) => EntityManager;
62
+ };
63
+
64
+ 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 };
@@ -0,0 +1,64 @@
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 ScopedDependencyFactory<SV extends AnySchemaValidator, CV extends ConfigValidator<SV>, M extends keyof CV> = (scope?: ConfigInjector<SV, CV>) => ResolvedConfigValidator<SV, CV>[M];
26
+
27
+ declare class ConfigInjector<SV extends AnySchemaValidator, CV extends ConfigValidator<SV>> {
28
+ private schemaValidator;
29
+ private configShapes;
30
+ private dependenciesDefinition;
31
+ instances: {
32
+ [K in keyof CV]?: ResolvedConfigValidator<SV, CV>[K];
33
+ };
34
+ private loadSingletons;
35
+ private resolveInstance;
36
+ constructor(schemaValidator: SV, configShapes: CV, dependenciesDefinition: {
37
+ [K in keyof CV]: Singleton<ResolvedConfigValidator<SV, CV>[K]> | Constructed<Omit<ResolvedConfigValidator<SV, CV>, K>, ResolvedConfigValidator<SV, CV>[K]>;
38
+ });
39
+ validateConfigSingletons(config: Partial<ResolvedConfigValidator<SV, CV>>): ParseResult<unknown>;
40
+ resolve<T extends keyof CV>(token: T, context?: Record<string, unknown>, resolutionPath?: (keyof CV)[]): ResolvedConfigValidator<SV, CV>[T];
41
+ scopedResolver<T extends keyof CV>(token: T, context?: Record<string, unknown>, resolutionPath?: (keyof CV)[]): (scope?: ConfigInjector<SV, CV>) => ResolvedConfigValidator<SV, CV>[T];
42
+ createScope(): ConfigInjector<SV, CV>;
43
+ dispose(): void;
44
+ }
45
+
46
+ /**
47
+ * Interface representing a base service.
48
+ *
49
+ * @interface BaseService
50
+ */
51
+ interface BaseService {
52
+ /**
53
+ * The EntityManager instance for managing entities.
54
+ *
55
+ * @type {EntityManager}
56
+ */
57
+ em: EntityManager$1;
58
+ }
59
+
60
+ type EntityManager = {
61
+ fork: <Options>(options?: Options) => EntityManager;
62
+ };
63
+
64
+ 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 };
@@ -0,0 +1,159 @@
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
+ });
26
+ module.exports = __toCommonJS(services_exports);
27
+
28
+ // src/services/configInjector.ts
29
+ var import_common = require("@forklaunch/common");
30
+
31
+ // src/services/types/configInjector.types.ts
32
+ var Lifetime = /* @__PURE__ */ ((Lifetime2) => {
33
+ Lifetime2[Lifetime2["Singleton"] = 0] = "Singleton";
34
+ Lifetime2[Lifetime2["Transient"] = 1] = "Transient";
35
+ Lifetime2[Lifetime2["Scoped"] = 2] = "Scoped";
36
+ return Lifetime2;
37
+ })(Lifetime || {});
38
+
39
+ // src/services/configInjector.ts
40
+ var ConfigInjector = class _ConfigInjector {
41
+ constructor(schemaValidator, configShapes, dependenciesDefinition) {
42
+ this.schemaValidator = schemaValidator;
43
+ this.configShapes = configShapes;
44
+ this.dependenciesDefinition = dependenciesDefinition;
45
+ this.loadSingletons();
46
+ }
47
+ instances = {};
48
+ loadSingletons() {
49
+ for (const token in this.dependenciesDefinition) {
50
+ const definition = this.dependenciesDefinition[token];
51
+ if (definition.lifetime === 0 /* Singleton */) {
52
+ this.instances[token] = definition.value;
53
+ }
54
+ }
55
+ }
56
+ resolveInstance(token, definition, context, resolutionPath = []) {
57
+ const injectorArgument = (0, import_common.extractArgumentNames)(definition.factory)[0];
58
+ if (injectorArgument === "_args") {
59
+ return definition.factory(
60
+ {},
61
+ this.resolve.bind(this),
62
+ context ?? {}
63
+ );
64
+ }
65
+ if (!injectorArgument.startsWith("{") || !injectorArgument.endsWith("}")) {
66
+ throw new Error(
67
+ `Invalid injector argument for ${String(token)}: ${injectorArgument}. Please use object destructuring syntax: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment.`
68
+ );
69
+ }
70
+ const resolvedArguments = Object.fromEntries(
71
+ injectorArgument.replace("{", "").replace("}", "").split(",").map((arg) => arg.split(":")[0].trim()).map((arg) => {
72
+ const newResolutionPath = [...resolutionPath, token];
73
+ if (resolutionPath.includes(arg)) {
74
+ throw new Error(
75
+ `Circular dependency detected: ${newResolutionPath.join(" -> ")} -> ${arg}`
76
+ );
77
+ }
78
+ const resolvedArg = this.resolve(arg, context, newResolutionPath);
79
+ return [arg, resolvedArg];
80
+ })
81
+ );
82
+ return definition.factory(
83
+ resolvedArguments,
84
+ this.resolve.bind(this),
85
+ context ?? {}
86
+ );
87
+ }
88
+ validateConfigSingletons(config) {
89
+ return this.schemaValidator.parse(
90
+ this.schemaValidator.schemify(
91
+ Object.fromEntries(
92
+ Object.entries(this.configShapes).filter(
93
+ ([key, value]) => this.dependenciesDefinition[key].lifetime === 0 /* Singleton */ && this.schemaValidator.isSchema(value)
94
+ )
95
+ )
96
+ ),
97
+ config
98
+ );
99
+ }
100
+ resolve(token, context, resolutionPath = []) {
101
+ const instance = this.instances[token];
102
+ if (!instance) {
103
+ const definition = this.dependenciesDefinition[token];
104
+ if (!definition) {
105
+ throw new Error(`Unable to resolve dependency ${String(token)}`);
106
+ }
107
+ switch (definition.lifetime) {
108
+ case 0 /* Singleton */: {
109
+ return definition.value;
110
+ }
111
+ case 2 /* Scoped */: {
112
+ const scopedInstance = this.resolveInstance(
113
+ token,
114
+ definition,
115
+ context,
116
+ resolutionPath
117
+ );
118
+ this.instances[token] = scopedInstance;
119
+ return scopedInstance;
120
+ }
121
+ case 1 /* Transient */: {
122
+ return this.resolveInstance(
123
+ token,
124
+ definition,
125
+ context,
126
+ resolutionPath
127
+ );
128
+ }
129
+ default: {
130
+ (0, import_common.isNever)(definition);
131
+ throw new Error(
132
+ `Unable to resolve lifetime for dependency ${String(token)}, ${resolutionPath}`
133
+ );
134
+ }
135
+ }
136
+ } else {
137
+ return instance;
138
+ }
139
+ }
140
+ scopedResolver(token, context, resolutionPath = []) {
141
+ return (scope) => (scope ?? this.createScope()).resolve(token, context, resolutionPath);
142
+ }
143
+ createScope() {
144
+ return new _ConfigInjector(
145
+ this.schemaValidator,
146
+ this.configShapes,
147
+ this.dependenciesDefinition
148
+ );
149
+ }
150
+ dispose() {
151
+ this.instances = {};
152
+ this.loadSingletons();
153
+ }
154
+ };
155
+ // Annotate the CommonJS export names for ESM import in node:
156
+ 0 && (module.exports = {
157
+ ConfigInjector,
158
+ Lifetime
159
+ });
@@ -0,0 +1,131 @@
1
+ // src/services/configInjector.ts
2
+ import { extractArgumentNames, isNever } from "@forklaunch/common";
3
+
4
+ // src/services/types/configInjector.types.ts
5
+ var Lifetime = /* @__PURE__ */ ((Lifetime2) => {
6
+ Lifetime2[Lifetime2["Singleton"] = 0] = "Singleton";
7
+ Lifetime2[Lifetime2["Transient"] = 1] = "Transient";
8
+ Lifetime2[Lifetime2["Scoped"] = 2] = "Scoped";
9
+ return Lifetime2;
10
+ })(Lifetime || {});
11
+
12
+ // src/services/configInjector.ts
13
+ var ConfigInjector = class _ConfigInjector {
14
+ constructor(schemaValidator, configShapes, dependenciesDefinition) {
15
+ this.schemaValidator = schemaValidator;
16
+ this.configShapes = configShapes;
17
+ this.dependenciesDefinition = dependenciesDefinition;
18
+ this.loadSingletons();
19
+ }
20
+ instances = {};
21
+ loadSingletons() {
22
+ for (const token in this.dependenciesDefinition) {
23
+ const definition = this.dependenciesDefinition[token];
24
+ if (definition.lifetime === 0 /* Singleton */) {
25
+ this.instances[token] = definition.value;
26
+ }
27
+ }
28
+ }
29
+ resolveInstance(token, definition, context, resolutionPath = []) {
30
+ const injectorArgument = extractArgumentNames(definition.factory)[0];
31
+ if (injectorArgument === "_args") {
32
+ return definition.factory(
33
+ {},
34
+ this.resolve.bind(this),
35
+ context ?? {}
36
+ );
37
+ }
38
+ if (!injectorArgument.startsWith("{") || !injectorArgument.endsWith("}")) {
39
+ throw new Error(
40
+ `Invalid injector argument for ${String(token)}: ${injectorArgument}. Please use object destructuring syntax: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment.`
41
+ );
42
+ }
43
+ const resolvedArguments = Object.fromEntries(
44
+ injectorArgument.replace("{", "").replace("}", "").split(",").map((arg) => arg.split(":")[0].trim()).map((arg) => {
45
+ const newResolutionPath = [...resolutionPath, token];
46
+ if (resolutionPath.includes(arg)) {
47
+ throw new Error(
48
+ `Circular dependency detected: ${newResolutionPath.join(" -> ")} -> ${arg}`
49
+ );
50
+ }
51
+ const resolvedArg = this.resolve(arg, context, newResolutionPath);
52
+ return [arg, resolvedArg];
53
+ })
54
+ );
55
+ return definition.factory(
56
+ resolvedArguments,
57
+ this.resolve.bind(this),
58
+ context ?? {}
59
+ );
60
+ }
61
+ validateConfigSingletons(config) {
62
+ return this.schemaValidator.parse(
63
+ this.schemaValidator.schemify(
64
+ Object.fromEntries(
65
+ Object.entries(this.configShapes).filter(
66
+ ([key, value]) => this.dependenciesDefinition[key].lifetime === 0 /* Singleton */ && this.schemaValidator.isSchema(value)
67
+ )
68
+ )
69
+ ),
70
+ config
71
+ );
72
+ }
73
+ resolve(token, context, resolutionPath = []) {
74
+ const instance = this.instances[token];
75
+ if (!instance) {
76
+ const definition = this.dependenciesDefinition[token];
77
+ if (!definition) {
78
+ throw new Error(`Unable to resolve dependency ${String(token)}`);
79
+ }
80
+ switch (definition.lifetime) {
81
+ case 0 /* Singleton */: {
82
+ return definition.value;
83
+ }
84
+ case 2 /* Scoped */: {
85
+ const scopedInstance = this.resolveInstance(
86
+ token,
87
+ definition,
88
+ context,
89
+ resolutionPath
90
+ );
91
+ this.instances[token] = scopedInstance;
92
+ return scopedInstance;
93
+ }
94
+ case 1 /* Transient */: {
95
+ return this.resolveInstance(
96
+ token,
97
+ definition,
98
+ context,
99
+ resolutionPath
100
+ );
101
+ }
102
+ default: {
103
+ isNever(definition);
104
+ throw new Error(
105
+ `Unable to resolve lifetime for dependency ${String(token)}, ${resolutionPath}`
106
+ );
107
+ }
108
+ }
109
+ } else {
110
+ return instance;
111
+ }
112
+ }
113
+ scopedResolver(token, context, resolutionPath = []) {
114
+ return (scope) => (scope ?? this.createScope()).resolve(token, context, resolutionPath);
115
+ }
116
+ createScope() {
117
+ return new _ConfigInjector(
118
+ this.schemaValidator,
119
+ this.configShapes,
120
+ this.dependenciesDefinition
121
+ );
122
+ }
123
+ dispose() {
124
+ this.instances = {};
125
+ this.loadSingletons();
126
+ }
127
+ };
128
+ export {
129
+ ConfigInjector,
130
+ Lifetime
131
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forklaunch/core",
3
- "version": "0.2.36",
3
+ "version": "0.3.0",
4
4
  "description": "forklaunch-js core package. Contains useful building blocks.",
5
5
  "files": [
6
6
  "lib"
@@ -17,64 +17,77 @@
17
17
  },
18
18
  "homepage": "https://github.com/forklaunch/forklaunch-js#readme",
19
19
  "dependencies": {
20
- "@mikro-orm/core": "^6.4.0",
21
- "@mikro-orm/mongodb": "^6.4.2",
20
+ "@mikro-orm/core": "^6.4.3",
21
+ "@mikro-orm/mongodb": "^6.4.3",
22
22
  "cors": "^2.8.5",
23
23
  "jose": "^5.9.6",
24
24
  "openapi3-ts": "^4.4.0",
25
25
  "redis": "^4.7.0",
26
- "uuid": "^11.0.3",
27
- "@forklaunch/common": "0.1.14",
28
- "@forklaunch/validator": "0.3.13"
26
+ "uuid": "^11.0.5",
27
+ "@forklaunch/common": "0.2.0",
28
+ "@forklaunch/validator": "0.4.0"
29
29
  },
30
30
  "devDependencies": {
31
- "@eslint/js": "^9.16.0",
31
+ "@eslint/js": "^9.17.0",
32
32
  "@types/cors": "^2.8.17",
33
33
  "@types/jest": "^29.5.14",
34
34
  "@types/qs": "^6.9.17",
35
35
  "@types/uuid": "^10.0.0",
36
- "globals": "^15.13.0",
36
+ "globals": "^15.14.0",
37
37
  "jest": "^29.7.0",
38
- "prettier": "^3.4.1",
39
- "testcontainers": "^10.15.0",
38
+ "prettier": "^3.4.2",
39
+ "testcontainers": "^10.16.0",
40
40
  "ts-jest": "^29.2.5",
41
41
  "ts-node": "^10.9.2",
42
- "typedoc": "^0.27.2",
43
- "typescript": "^5.7.2",
44
- "typescript-eslint": "^8.17.0"
42
+ "tsup": "^8.3.5",
43
+ "typedoc": "^0.27.6",
44
+ "typescript": "^5.7.3",
45
+ "typescript-eslint": "^8.19.1"
45
46
  },
46
47
  "directories": {
47
48
  "test": "tests"
48
49
  },
49
50
  "exports": {
50
51
  "./cache": {
51
- "types": "./lib/src/cache/index.d.ts",
52
- "default": "./lib/src/cache/index.js"
52
+ "types": "./lib/cache/index.d.ts",
53
+ "import": "./lib/cache/index.mjs",
54
+ "require": "./lib/cache/index.js",
55
+ "default": "./lib/cache/index.js"
53
56
  },
54
57
  "./controllers": {
55
- "types": "./lib/src/controllers/index.d.ts",
56
- "default": "./lib/src/controllers/index.js"
58
+ "types": "./lib/controllers/index.d.ts",
59
+ "import": "./lib/controllers/index.mjs",
60
+ "require": "./lib/controllers/index.js",
61
+ "default": "./lib/controllers/index.js"
57
62
  },
58
63
  "./database": {
59
- "types": "./lib/src/database/index.d.ts",
60
- "default": "./lib/src/database/index.js"
64
+ "types": "./lib/database/index.d.ts",
65
+ "import": "./lib/database/index.mjs",
66
+ "require": "./lib/database/index.js",
67
+ "default": "./lib/database/index.js"
61
68
  },
62
69
  "./dtoMapper": {
63
- "types": "./lib/src/dtoMapper/index.d.ts",
64
- "default": "./lib/src/dtoMapper/index.js"
70
+ "types": "./lib/dtoMapper/index.d.ts",
71
+ "import": "./lib/dtoMapper/index.mjs",
72
+ "require": "./lib/dtoMapper/index.js",
73
+ "default": "./lib/dtoMapper/index.js"
65
74
  },
66
75
  "./http": {
67
- "types": "./lib/src/http/index.d.ts",
68
- "default": "./lib/src/http/index.js"
76
+ "types": "./lib/http/index.d.ts",
77
+ "import": "./lib/http/index.mjs",
78
+ "require": "./lib/http/index.js",
79
+ "default": "./lib/http/index.js"
69
80
  },
70
81
  "./services": {
71
- "types": "./lib/src/services/index.d.ts",
72
- "default": "./lib/src/services/index.js"
82
+ "types": "./lib/services/index.d.ts",
83
+ "import": "./lib/services/index.mjs",
84
+ "require": "./lib/services/index.js",
85
+ "default": "./lib/services/index.js"
73
86
  }
74
87
  },
75
88
  "scripts": {
76
89
  "test": "vitest --passWithNoTests",
77
- "build": "tsc",
90
+ "build": "tsc --noEmit && tsup ./src/cache/index.ts ./src/controllers/index.ts ./src/database/index.ts ./src/dtoMapper/index.ts ./src/http/index.ts ./src/services/index.ts --format cjs,esm --no-splitting --dts --tsconfig tsconfig.json --out-dir lib --clean",
78
91
  "clean": "rm -rf lib pnpm.lock.yaml node_modules",
79
92
  "docs": "typedoc --out docs *",
80
93
  "lint": "eslint . -c eslint.config.mjs",
@@ -1,5 +0,0 @@
1
- export * from './interfaces/ttlCache.interface';
2
- export * from './redisTtlCache';
3
- export * from './types/ttlCacheRecord.types';
4
- export * from './utils/cacheKey';
5
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/cache/index.ts"],"names":[],"mappings":"AAAA,cAAc,iCAAiC,CAAC;AAChD,cAAc,iBAAiB,CAAC;AAChC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,kBAAkB,CAAC"}
@@ -1,4 +0,0 @@
1
- export * from './interfaces/ttlCache.interface';
2
- export * from './redisTtlCache';
3
- export * from './types/ttlCacheRecord.types';
4
- export * from './utils/cacheKey';
@@ -1,48 +0,0 @@
1
- import { TtlCacheRecord } from '../types/ttlCacheRecord.types';
2
- /**
3
- * Interface representing a TTL (Time-To-Live) cache.
4
- */
5
- export interface TtlCache {
6
- /**
7
- * Puts a record into the cache.
8
- *
9
- * @param {TtlCacheRecord} cacheRecord - The cache record to put into the cache.
10
- * @returns {Promise<void>} - A promise that resolves when the record is put into the cache.
11
- */
12
- putRecord<T>(cacheRecord: TtlCacheRecord<T>): Promise<void>;
13
- /**
14
- * Deletes a record from the cache.
15
- *
16
- * @param {string} cacheRecordKey - The key of the cache record to delete.
17
- * @returns {Promise<void>} - A promise that resolves when the record is deleted from the cache.
18
- */
19
- deleteRecord(cacheRecordKey: string): Promise<void>;
20
- /**
21
- * Reads a record from the cache.
22
- *
23
- * @param {string} cacheRecordKey - The key of the cache record to read.
24
- * @returns {Promise<TtlCacheRecord>} - A promise that resolves with the cache record.
25
- */
26
- readRecord<T>(cacheRecordKey: string): Promise<TtlCacheRecord<T>>;
27
- /**
28
- * Peeks at a record in the cache to check if it exists.
29
- *
30
- * @param {string} cacheRecordKey - The key of the cache record to peek at.
31
- * @returns {Promise<boolean>} - A promise that resolves with a boolean indicating if the record exists.
32
- */
33
- peekRecord(cacheRecordKey: string): Promise<boolean>;
34
- /**
35
- * Gets the TTL (Time-To-Live) in milliseconds.
36
- *
37
- * @returns {number} - The TTL in milliseconds.
38
- */
39
- getTtlMilliseconds(): number;
40
- /**
41
- * Lists the keys in the cache that match a pattern prefix.
42
- *
43
- * @param {string} pattern_prefix - The pattern prefix to match.
44
- * @returns {Promise<string[]>} - A promise that resolves with an array of keys matching the pattern prefix.
45
- */
46
- listKeys(pattern_prefix: string): Promise<string[]>;
47
- }
48
- //# sourceMappingURL=ttlCache.interface.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ttlCache.interface.d.ts","sourceRoot":"","sources":["../../../../src/cache/interfaces/ttlCache.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAE/D;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB;;;;;OAKG;IACH,SAAS,CAAC,CAAC,EAAE,WAAW,EAAE,cAAc,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE5D;;;;;OAKG;IACH,YAAY,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEpD;;;;;OAKG;IACH,UAAU,CAAC,CAAC,EAAE,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC;IAElE;;;;;OAKG;IACH,UAAU,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAErD;;;;OAIG;IACH,kBAAkB,IAAI,MAAM,CAAC;IAE7B;;;;;OAKG;IACH,QAAQ,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;CACrD"}
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- {"version":3,"file":"redisTtlCache.d.ts","sourceRoot":"","sources":["../../../src/cache/redisTtlCache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAgB,MAAM,OAAO,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAE9D;;;GAGG;AACH,qBAAa,aAAc,YAAW,QAAQ;IAU1C,OAAO,CAAC,eAAe;IATzB,OAAO,CAAC,MAAM,CAAC;IAEf;;;;;OAKG;gBAEO,eAAe,EAAE,MAAM,EAC/B,cAAc,CAAC,EAAE,kBAAkB;IASrC;;;;;OAKG;IACG,SAAS,CAAC,CAAC,EAAE,EACjB,GAAG,EACH,KAAK,EACL,eAAsC,EACvC,EAAE,cAAc,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAMpC;;;;;OAKG;IACG,YAAY,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIzD;;;;;;OAMG;IACG,UAAU,CAAC,CAAC,EAAE,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;IAavE;;;;;OAKG;IACG,QAAQ,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAKzD;;;;;OAKG;IACG,UAAU,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAK1D;;;;OAIG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAIjC;;;;OAIG;IACH,kBAAkB,IAAI,MAAM;CAG7B"}