@riktajs/core 0.3.1 → 0.4.0-beta.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/README.md +1 -0
- package/dist/core/config/abstract-config-provider.d.ts +162 -0
- package/dist/core/config/abstract-config-provider.d.ts.map +1 -0
- package/dist/core/config/abstract-config-provider.js +215 -0
- package/dist/core/config/abstract-config-provider.js.map +1 -0
- package/dist/core/config/index.d.ts +2 -0
- package/dist/core/config/index.d.ts.map +1 -0
- package/dist/core/config/index.js +18 -0
- package/dist/core/config/index.js.map +1 -0
- package/dist/core/constants.d.ts +34 -0
- package/dist/core/constants.d.ts.map +1 -1
- package/dist/core/constants.js +38 -1
- package/dist/core/constants.js.map +1 -1
- package/dist/core/decorators/config-property.decorator.d.ts +129 -0
- package/dist/core/decorators/config-property.decorator.d.ts.map +1 -0
- package/dist/core/decorators/config-property.decorator.js +205 -0
- package/dist/core/decorators/config-property.decorator.js.map +1 -0
- package/dist/core/decorators/index.d.ts +2 -0
- package/dist/core/decorators/index.d.ts.map +1 -1
- package/dist/core/decorators/index.js +2 -0
- package/dist/core/decorators/index.js.map +1 -1
- package/dist/core/decorators/provider-config.decorator.d.ts +107 -0
- package/dist/core/decorators/provider-config.decorator.d.ts.map +1 -0
- package/dist/core/decorators/provider-config.decorator.js +156 -0
- package/dist/core/decorators/provider-config.decorator.js.map +1 -0
- package/dist/core/discovery.d.ts.map +1 -1
- package/dist/core/discovery.js +2 -0
- package/dist/core/discovery.js.map +1 -1
- package/dist/core/exceptions/config.exceptions.d.ts +21 -0
- package/dist/core/exceptions/config.exceptions.d.ts.map +1 -0
- package/dist/core/exceptions/config.exceptions.js +52 -0
- package/dist/core/exceptions/config.exceptions.js.map +1 -0
- package/dist/core/exceptions/index.d.ts +1 -0
- package/dist/core/exceptions/index.d.ts.map +1 -1
- package/dist/core/exceptions/index.js +6 -1
- package/dist/core/exceptions/index.js.map +1 -1
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +1 -0
- package/dist/core/index.js.map +1 -1
- package/dist/core/registry.d.ts +82 -0
- package/dist/core/registry.d.ts.map +1 -1
- package/dist/core/registry.js +119 -1
- package/dist/core/registry.js.map +1 -1
- package/package.json +2 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getCatchMetadata = exports.CATCH_METADATA = exports.Catch = exports.createExceptionHandler = exports.GlobalExceptionFilter = exports.GatewayTimeoutException = exports.ServiceUnavailableException = exports.BadGatewayException = exports.NotImplementedException = exports.InternalServerErrorException = exports.TooManyRequestsException = exports.UnprocessableEntityException = exports.UnsupportedMediaTypeException = exports.PayloadTooLargeException = exports.GoneException = exports.ConflictException = exports.RequestTimeoutException = exports.NotAcceptableException = exports.MethodNotAllowedException = exports.NotFoundException = exports.ForbiddenException = exports.UnauthorizedException = exports.BadRequestException = exports.ValidationException = exports.HttpException = void 0;
|
|
3
|
+
exports.ConfigProviderInstantiationException = exports.ConfigProviderNotFoundException = exports.ConfigProviderAlreadyRegisteredException = exports.getCatchMetadata = exports.CATCH_METADATA = exports.Catch = exports.createExceptionHandler = exports.GlobalExceptionFilter = exports.GatewayTimeoutException = exports.ServiceUnavailableException = exports.BadGatewayException = exports.NotImplementedException = exports.InternalServerErrorException = exports.TooManyRequestsException = exports.UnprocessableEntityException = exports.UnsupportedMediaTypeException = exports.PayloadTooLargeException = exports.GoneException = exports.ConflictException = exports.RequestTimeoutException = exports.NotAcceptableException = exports.MethodNotAllowedException = exports.NotFoundException = exports.ForbiddenException = exports.UnauthorizedException = exports.BadRequestException = exports.ValidationException = exports.HttpException = void 0;
|
|
4
4
|
// HTTP Exception
|
|
5
5
|
var http_exception_1 = require("./http-exception");
|
|
6
6
|
Object.defineProperty(exports, "HttpException", { enumerable: true, get: function () { return http_exception_1.HttpException; } });
|
|
@@ -38,4 +38,9 @@ var catch_decorator_1 = require("./catch.decorator");
|
|
|
38
38
|
Object.defineProperty(exports, "Catch", { enumerable: true, get: function () { return catch_decorator_1.Catch; } });
|
|
39
39
|
Object.defineProperty(exports, "CATCH_METADATA", { enumerable: true, get: function () { return catch_decorator_1.CATCH_METADATA; } });
|
|
40
40
|
Object.defineProperty(exports, "getCatchMetadata", { enumerable: true, get: function () { return catch_decorator_1.getCatchMetadata; } });
|
|
41
|
+
// Config Exceptions
|
|
42
|
+
var config_exceptions_1 = require("./config.exceptions");
|
|
43
|
+
Object.defineProperty(exports, "ConfigProviderAlreadyRegisteredException", { enumerable: true, get: function () { return config_exceptions_1.ConfigProviderAlreadyRegisteredException; } });
|
|
44
|
+
Object.defineProperty(exports, "ConfigProviderNotFoundException", { enumerable: true, get: function () { return config_exceptions_1.ConfigProviderNotFoundException; } });
|
|
45
|
+
Object.defineProperty(exports, "ConfigProviderInstantiationException", { enumerable: true, get: function () { return config_exceptions_1.ConfigProviderInstantiationException; } });
|
|
41
46
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/exceptions/index.ts"],"names":[],"mappings":";;;AAAA,iBAAiB;AACjB,mDAA2F;AAAlF,+GAAA,aAAa,OAAA;AAEtB,6BAA6B;AAC7B,+DAAqF;AAA5E,2HAAA,mBAAmB,OAAA;AAE5B,sBAAsB;AACtB,2CAqBsB;AApBpB,oBAAoB;AACpB,iHAAA,mBAAmB,OAAA;AACnB,mHAAA,qBAAqB,OAAA;AACrB,gHAAA,kBAAkB,OAAA;AAClB,+GAAA,iBAAiB,OAAA;AACjB,uHAAA,yBAAyB,OAAA;AACzB,oHAAA,sBAAsB,OAAA;AACtB,qHAAA,uBAAuB,OAAA;AACvB,+GAAA,iBAAiB,OAAA;AACjB,2GAAA,aAAa,OAAA;AACb,sHAAA,wBAAwB,OAAA;AACxB,2HAAA,6BAA6B,OAAA;AAC7B,0HAAA,4BAA4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AAA;AAGxB,kBAAkB;AAClB,qDAA2F;AAAlF,wGAAA,KAAK,OAAA;AAAiB,iHAAA,cAAc,OAAA;AAAE,mHAAA,gBAAgB,OAAA;AAE/D,oBAAoB;AACpB,yDAI6B;AAH3B,6IAAA,wCAAwC,OAAA;AACxC,oIAAA,+BAA+B,OAAA;AAC/B,yIAAA,oCAAoC,OAAA"}
|
package/dist/core/index.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export * from './application';
|
|
|
9
9
|
export * from './decorators';
|
|
10
10
|
export * from './exceptions';
|
|
11
11
|
export * from './guards';
|
|
12
|
+
export * from './config';
|
|
12
13
|
export { z } from 'zod';
|
|
13
14
|
export type { ZodType, ZodSchema, ZodError, ZodIssue, infer as ZodInfer } from 'zod';
|
|
14
15
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/core/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AACA,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AAKzB,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,YAAY,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,IAAI,QAAQ,EAAE,MAAM,KAAK,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AACA,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AAKzB,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,YAAY,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,IAAI,QAAQ,EAAE,MAAM,KAAK,CAAC"}
|
package/dist/core/index.js
CHANGED
|
@@ -27,6 +27,7 @@ __exportStar(require("./application"), exports);
|
|
|
27
27
|
__exportStar(require("./decorators"), exports);
|
|
28
28
|
__exportStar(require("./exceptions"), exports);
|
|
29
29
|
__exportStar(require("./guards"), exports);
|
|
30
|
+
__exportStar(require("./config"), exports);
|
|
30
31
|
// Re-export Zod for convenience
|
|
31
32
|
// This allows users to import everything from '@riktajs/core':
|
|
32
33
|
// import { z, Body, Controller } from '@riktajs/core';
|
package/dist/core/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,eAAe;AACf,0CAAwB;AACxB,8CAA4B;AAC5B,8CAA4B;AAC5B,6CAA2B;AAC3B,8CAA4B;AAC5B,8CAA4B;AAC5B,kDAAgC;AAChC,gDAA8B;AAC9B,+CAA6B;AAC7B,+CAA6B;AAC7B,2CAAyB;AAEzB,gCAAgC;AAChC,+DAA+D;AAC/D,uDAAuD;AACvD,2BAAwB;AAAf,wFAAA,CAAC,OAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,eAAe;AACf,0CAAwB;AACxB,8CAA4B;AAC5B,8CAA4B;AAC5B,6CAA2B;AAC3B,8CAA4B;AAC5B,8CAA4B;AAC5B,kDAAgC;AAChC,gDAA8B;AAC9B,+CAA6B;AAC7B,+CAA6B;AAC7B,2CAAyB;AACzB,2CAAyB;AAEzB,gCAAgC;AAChC,+DAA+D;AAC/D,uDAAuD;AACvD,2BAAwB;AAAf,wFAAA,CAAC,OAAA"}
|
package/dist/core/registry.d.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import { Constructor } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Config provider registration info
|
|
4
|
+
*/
|
|
5
|
+
interface ConfigProviderRegistration {
|
|
6
|
+
token: string;
|
|
7
|
+
providerClass: Constructor;
|
|
8
|
+
}
|
|
2
9
|
/**
|
|
3
10
|
* Global Registry
|
|
4
11
|
*
|
|
@@ -13,6 +20,10 @@ declare class Registry {
|
|
|
13
20
|
private providers;
|
|
14
21
|
/** All registered custom providers (via @Provider) */
|
|
15
22
|
private customProviders;
|
|
23
|
+
/** Map of config provider tokens to their class constructors */
|
|
24
|
+
private configProviderMap;
|
|
25
|
+
/** Cache of instantiated config provider instances (singleton scope) */
|
|
26
|
+
private configProviderInstances;
|
|
16
27
|
private constructor();
|
|
17
28
|
static getInstance(): Registry;
|
|
18
29
|
/**
|
|
@@ -55,6 +66,77 @@ declare class Registry {
|
|
|
55
66
|
* Check if a custom provider is registered
|
|
56
67
|
*/
|
|
57
68
|
hasCustomProvider(target: Constructor): boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Register a config provider with its injection token
|
|
71
|
+
*
|
|
72
|
+
* @param token - The injection token (e.g., 'APP_CONFIG')
|
|
73
|
+
* @param providerClass - The config provider class constructor
|
|
74
|
+
* @throws {ConfigProviderAlreadyRegisteredException} If the token is already registered
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```typescript
|
|
78
|
+
* registry.registerConfigProvider('APP_CONFIG', AppConfigProvider);
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
registerConfigProvider(token: string, providerClass: Constructor): void;
|
|
82
|
+
/**
|
|
83
|
+
* Get a config provider instance by its token (singleton)
|
|
84
|
+
*
|
|
85
|
+
* If the provider hasn't been instantiated yet, it will be created and cached.
|
|
86
|
+
*
|
|
87
|
+
* @param token - The injection token
|
|
88
|
+
* @returns The config provider instance
|
|
89
|
+
* @throws {ConfigProviderNotFoundException} If the token is not registered
|
|
90
|
+
* @throws {ConfigProviderInstantiationException} If instantiation fails
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```typescript
|
|
94
|
+
* const config = registry.getConfigProvider<AppConfigProvider>('APP_CONFIG');
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
getConfigProvider<T = unknown>(token: string): T;
|
|
98
|
+
/**
|
|
99
|
+
* Check if a config provider token is registered
|
|
100
|
+
*
|
|
101
|
+
* @param token - The injection token to check
|
|
102
|
+
* @returns True if the token is registered
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* ```typescript
|
|
106
|
+
* if (registry.hasConfigProvider('APP_CONFIG')) {
|
|
107
|
+
* const config = registry.getConfigProvider('APP_CONFIG');
|
|
108
|
+
* }
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
hasConfigProvider(token: string): boolean;
|
|
112
|
+
/**
|
|
113
|
+
* Get all registered config provider tokens
|
|
114
|
+
*
|
|
115
|
+
* @returns Array of all registered tokens
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```typescript
|
|
119
|
+
* const tokens = registry.getConfigProviderTokens();
|
|
120
|
+
* console.log('Available configs:', tokens);
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
getConfigProviderTokens(): string[];
|
|
124
|
+
/**
|
|
125
|
+
* Get all registered config provider classes with their tokens
|
|
126
|
+
*
|
|
127
|
+
* @returns Array of registration info objects
|
|
128
|
+
*
|
|
129
|
+
* @internal Used by auto-discovery mechanism
|
|
130
|
+
*/
|
|
131
|
+
getConfigProviderRegistrations(): ConfigProviderRegistration[];
|
|
132
|
+
/**
|
|
133
|
+
* Clear all config provider instances (useful for testing)
|
|
134
|
+
*
|
|
135
|
+
* This will force re-instantiation on next getConfigProvider call
|
|
136
|
+
*
|
|
137
|
+
* @internal
|
|
138
|
+
*/
|
|
139
|
+
clearConfigProviderInstances(): void;
|
|
58
140
|
}
|
|
59
141
|
/**
|
|
60
142
|
* Global registry instance
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/core/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/core/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAOtC;;GAEG;AACH,UAAU,0BAA0B;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,WAAW,CAAC;CAC5B;AAED;;;;;GAKG;AACH,cAAM,QAAQ;IACZ,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAW;IAElC,iCAAiC;IACjC,OAAO,CAAC,WAAW,CAA0B;IAE7C,0DAA0D;IAC1D,OAAO,CAAC,SAAS,CAA0B;IAE3C,sDAAsD;IACtD,OAAO,CAAC,eAAe,CAA0B;IAEjD,gEAAgE;IAChE,OAAO,CAAC,iBAAiB,CAAkC;IAE3D,wEAAwE;IACxE,OAAO,CAAC,uBAAuB,CAA8B;IAE7D,OAAO;IAEP,MAAM,CAAC,WAAW,IAAI,QAAQ;IAO9B;;OAEG;IACH,MAAM,CAAC,KAAK,IAAI,IAAI;IAKpB;;OAEG;IACH,kBAAkB,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI;IAI7C;;OAEG;IACH,gBAAgB,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI;IAI3C;;OAEG;IACH,cAAc,IAAI,WAAW,EAAE;IAI/B;;OAEG;IACH,YAAY,IAAI,WAAW,EAAE;IAI7B;;OAEG;IACH,aAAa,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO;IAI3C;;OAEG;IACH,WAAW,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO;IAIzC;;OAEG;IACH,sBAAsB,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI;IAIjD;;OAEG;IACH,kBAAkB,IAAI,WAAW,EAAE;IAInC;;OAEG;IACH,iBAAiB,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO;IAQ/C;;;;;;;;;;;OAWG;IACH,sBAAsB,CAAC,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,WAAW,GAAG,IAAI;IAavE;;;;;;;;;;;;;;OAcG;IACH,iBAAiB,CAAC,CAAC,GAAG,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,CAAC;IA8BhD;;;;;;;;;;;;OAYG;IACH,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAIzC;;;;;;;;;;OAUG;IACH,uBAAuB,IAAI,MAAM,EAAE;IAInC;;;;;;OAMG;IACH,8BAA8B,IAAI,0BAA0B,EAAE;IAO9D;;;;;;OAMG;IACH,4BAA4B,IAAI,IAAI;CAGrC;AAED;;GAEG;AACH,eAAO,MAAM,QAAQ,UAAyB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,CAAC"}
|
package/dist/core/registry.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Registry = exports.registry = void 0;
|
|
4
|
+
const config_exceptions_1 = require("./exceptions/config.exceptions");
|
|
4
5
|
/**
|
|
5
6
|
* Global Registry
|
|
6
7
|
*
|
|
@@ -15,6 +16,10 @@ class Registry {
|
|
|
15
16
|
providers = new Set();
|
|
16
17
|
/** All registered custom providers (via @Provider) */
|
|
17
18
|
customProviders = new Set();
|
|
19
|
+
/** Map of config provider tokens to their class constructors */
|
|
20
|
+
configProviderMap = new Map();
|
|
21
|
+
/** Cache of instantiated config provider instances (singleton scope) */
|
|
22
|
+
configProviderInstances = new Map();
|
|
18
23
|
constructor() { }
|
|
19
24
|
static getInstance() {
|
|
20
25
|
if (!Registry.instance) {
|
|
@@ -26,7 +31,8 @@ class Registry {
|
|
|
26
31
|
* Reset the registry (useful for testing)
|
|
27
32
|
*/
|
|
28
33
|
static reset() {
|
|
29
|
-
|
|
34
|
+
const newInstance = new Registry();
|
|
35
|
+
Registry.instance = newInstance;
|
|
30
36
|
}
|
|
31
37
|
/**
|
|
32
38
|
* Register a controller
|
|
@@ -82,6 +88,118 @@ class Registry {
|
|
|
82
88
|
hasCustomProvider(target) {
|
|
83
89
|
return this.customProviders.has(target);
|
|
84
90
|
}
|
|
91
|
+
// ============================================================================
|
|
92
|
+
// Config Provider Methods
|
|
93
|
+
// ============================================================================
|
|
94
|
+
/**
|
|
95
|
+
* Register a config provider with its injection token
|
|
96
|
+
*
|
|
97
|
+
* @param token - The injection token (e.g., 'APP_CONFIG')
|
|
98
|
+
* @param providerClass - The config provider class constructor
|
|
99
|
+
* @throws {ConfigProviderAlreadyRegisteredException} If the token is already registered
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```typescript
|
|
103
|
+
* registry.registerConfigProvider('APP_CONFIG', AppConfigProvider);
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
registerConfigProvider(token, providerClass) {
|
|
107
|
+
if (this.configProviderMap.has(token)) {
|
|
108
|
+
const existingClass = this.configProviderMap.get(token);
|
|
109
|
+
throw new config_exceptions_1.ConfigProviderAlreadyRegisteredException(token, existingClass.name, providerClass.name);
|
|
110
|
+
}
|
|
111
|
+
this.configProviderMap.set(token, providerClass);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Get a config provider instance by its token (singleton)
|
|
115
|
+
*
|
|
116
|
+
* If the provider hasn't been instantiated yet, it will be created and cached.
|
|
117
|
+
*
|
|
118
|
+
* @param token - The injection token
|
|
119
|
+
* @returns The config provider instance
|
|
120
|
+
* @throws {ConfigProviderNotFoundException} If the token is not registered
|
|
121
|
+
* @throws {ConfigProviderInstantiationException} If instantiation fails
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* ```typescript
|
|
125
|
+
* const config = registry.getConfigProvider<AppConfigProvider>('APP_CONFIG');
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
getConfigProvider(token) {
|
|
129
|
+
// Check if already instantiated (singleton cache)
|
|
130
|
+
if (this.configProviderInstances.has(token)) {
|
|
131
|
+
return this.configProviderInstances.get(token);
|
|
132
|
+
}
|
|
133
|
+
// Check if registered
|
|
134
|
+
const providerClass = this.configProviderMap.get(token);
|
|
135
|
+
if (!providerClass) {
|
|
136
|
+
const availableTokens = Array.from(this.configProviderMap.keys());
|
|
137
|
+
throw new config_exceptions_1.ConfigProviderNotFoundException(token, availableTokens);
|
|
138
|
+
}
|
|
139
|
+
// Instantiate the provider
|
|
140
|
+
try {
|
|
141
|
+
const instance = new providerClass();
|
|
142
|
+
// Cache the instance (singleton scope)
|
|
143
|
+
this.configProviderInstances.set(token, instance);
|
|
144
|
+
return instance;
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
throw new config_exceptions_1.ConfigProviderInstantiationException(token, providerClass.name, error);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Check if a config provider token is registered
|
|
152
|
+
*
|
|
153
|
+
* @param token - The injection token to check
|
|
154
|
+
* @returns True if the token is registered
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```typescript
|
|
158
|
+
* if (registry.hasConfigProvider('APP_CONFIG')) {
|
|
159
|
+
* const config = registry.getConfigProvider('APP_CONFIG');
|
|
160
|
+
* }
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
hasConfigProvider(token) {
|
|
164
|
+
return this.configProviderMap.has(token);
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Get all registered config provider tokens
|
|
168
|
+
*
|
|
169
|
+
* @returns Array of all registered tokens
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```typescript
|
|
173
|
+
* const tokens = registry.getConfigProviderTokens();
|
|
174
|
+
* console.log('Available configs:', tokens);
|
|
175
|
+
* ```
|
|
176
|
+
*/
|
|
177
|
+
getConfigProviderTokens() {
|
|
178
|
+
return Array.from(this.configProviderMap.keys());
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Get all registered config provider classes with their tokens
|
|
182
|
+
*
|
|
183
|
+
* @returns Array of registration info objects
|
|
184
|
+
*
|
|
185
|
+
* @internal Used by auto-discovery mechanism
|
|
186
|
+
*/
|
|
187
|
+
getConfigProviderRegistrations() {
|
|
188
|
+
return Array.from(this.configProviderMap.entries()).map(([token, providerClass]) => ({
|
|
189
|
+
token,
|
|
190
|
+
providerClass,
|
|
191
|
+
}));
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Clear all config provider instances (useful for testing)
|
|
195
|
+
*
|
|
196
|
+
* This will force re-instantiation on next getConfigProvider call
|
|
197
|
+
*
|
|
198
|
+
* @internal
|
|
199
|
+
*/
|
|
200
|
+
clearConfigProviderInstances() {
|
|
201
|
+
this.configProviderInstances.clear();
|
|
202
|
+
}
|
|
85
203
|
}
|
|
86
204
|
exports.Registry = Registry;
|
|
87
205
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/core/registry.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/core/registry.ts"],"names":[],"mappings":";;;AACA,sEAIwC;AAUxC;;;;;GAKG;AACH,MAAM,QAAQ;IACJ,MAAM,CAAC,QAAQ,CAAW;IAElC,iCAAiC;IACzB,WAAW,GAAG,IAAI,GAAG,EAAe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
|
+
"version": "0.4.0-beta.2",
|
|
4
4
|
"description": "A fast and modern TypeScript backend framework with zero-config autowiring, powered by Fastify",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"author": "",
|
|
34
34
|
"license": "MIT",
|
|
35
35
|
"dependencies": {
|
|
36
|
+
"dotenv": "^17.2.3",
|
|
36
37
|
"fast-glob": "3.3.3",
|
|
37
38
|
"fastify": "5.3.2",
|
|
38
39
|
"reflect-metadata": "0.2.2",
|