@riktajs/core 0.4.0-beta.2 → 0.4.0-beta.4
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/dist/core/config/abstract-config-provider.d.ts +2 -2
- package/dist/core/config/abstract-config-provider.js +2 -2
- package/dist/core/constants.d.ts +2 -2
- package/dist/core/constants.js +2 -2
- package/dist/core/decorators/config-property.decorator.d.ts +4 -4
- package/dist/core/decorators/config-property.decorator.js +4 -4
- package/dist/core/decorators/index.d.ts +0 -1
- package/dist/core/decorators/index.d.ts.map +1 -1
- package/dist/core/decorators/index.js +0 -1
- package/dist/core/decorators/index.js.map +1 -1
- package/dist/core/decorators/provider.decorator.d.ts +59 -15
- package/dist/core/decorators/provider.decorator.d.ts.map +1 -1
- package/dist/core/decorators/provider.decorator.js +124 -19
- package/dist/core/decorators/provider.decorator.js.map +1 -1
- package/dist/core/discovery.js +1 -1
- package/dist/core/discovery.js.map +1 -1
- package/dist/core/exceptions/config.exceptions.js +1 -1
- package/dist/core/exceptions/config.exceptions.js.map +1 -1
- package/package.json +1 -1
|
@@ -23,10 +23,10 @@ export declare class ConfigValidationException extends Error {
|
|
|
23
23
|
*
|
|
24
24
|
* @example
|
|
25
25
|
* ```typescript
|
|
26
|
-
* import { AbstractConfigProvider,
|
|
26
|
+
* import { AbstractConfigProvider, Provider, ConfigProperty } from '@riktajs/core';
|
|
27
27
|
* import { z } from 'zod';
|
|
28
28
|
*
|
|
29
|
-
* @
|
|
29
|
+
* @Provider('APP_CONFIG')
|
|
30
30
|
* export class AppConfigProvider extends AbstractConfigProvider {
|
|
31
31
|
* schema() {
|
|
32
32
|
* return z.object({
|
|
@@ -39,10 +39,10 @@ exports.ConfigValidationException = ConfigValidationException;
|
|
|
39
39
|
*
|
|
40
40
|
* @example
|
|
41
41
|
* ```typescript
|
|
42
|
-
* import { AbstractConfigProvider,
|
|
42
|
+
* import { AbstractConfigProvider, Provider, ConfigProperty } from '@riktajs/core';
|
|
43
43
|
* import { z } from 'zod';
|
|
44
44
|
*
|
|
45
|
-
* @
|
|
45
|
+
* @Provider('APP_CONFIG')
|
|
46
46
|
* export class AppConfigProvider extends AbstractConfigProvider {
|
|
47
47
|
* schema() {
|
|
48
48
|
* return z.object({
|
package/dist/core/constants.d.ts
CHANGED
|
@@ -51,14 +51,14 @@ export declare const AUTOWIRED_METADATA: unique symbol;
|
|
|
51
51
|
*/
|
|
52
52
|
export declare const PROVIDER_METADATA: unique symbol;
|
|
53
53
|
/**
|
|
54
|
-
* Key for storing @
|
|
54
|
+
* Key for storing @Provider() metadata on config provider classes.
|
|
55
55
|
*
|
|
56
56
|
* This metadata stores the injection token that identifies the config provider,
|
|
57
57
|
* allowing the auto-discovery mechanism to register it with the DI container.
|
|
58
58
|
*
|
|
59
59
|
* @example
|
|
60
60
|
* ```typescript
|
|
61
|
-
* @
|
|
61
|
+
* @Provider('APP_CONFIG')
|
|
62
62
|
* class AppConfigProvider extends AbstractConfigProvider {
|
|
63
63
|
* // Token 'APP_CONFIG' is stored in metadata
|
|
64
64
|
* }
|
package/dist/core/constants.js
CHANGED
|
@@ -60,14 +60,14 @@ exports.PROVIDER_METADATA = Symbol('provider:metadata');
|
|
|
60
60
|
// Configuration Metadata Keys
|
|
61
61
|
// ============================================================================
|
|
62
62
|
/**
|
|
63
|
-
* Key for storing @
|
|
63
|
+
* Key for storing @Provider() metadata on config provider classes.
|
|
64
64
|
*
|
|
65
65
|
* This metadata stores the injection token that identifies the config provider,
|
|
66
66
|
* allowing the auto-discovery mechanism to register it with the DI container.
|
|
67
67
|
*
|
|
68
68
|
* @example
|
|
69
69
|
* ```typescript
|
|
70
|
-
* @
|
|
70
|
+
* @Provider('APP_CONFIG')
|
|
71
71
|
* class AppConfigProvider extends AbstractConfigProvider {
|
|
72
72
|
* // Token 'APP_CONFIG' is stored in metadata
|
|
73
73
|
* }
|
|
@@ -25,10 +25,10 @@ export interface ConfigPropertyMapping {
|
|
|
25
25
|
*
|
|
26
26
|
* @example Auto-mapping (property name → UPPER_SNAKE_CASE):
|
|
27
27
|
* ```typescript
|
|
28
|
-
* import { ConfigProperty,
|
|
28
|
+
* import { ConfigProperty, Provider, AbstractConfigProvider } from '@riktajs/core';
|
|
29
29
|
* import { z } from 'zod';
|
|
30
30
|
*
|
|
31
|
-
* @
|
|
31
|
+
* @Provider()
|
|
32
32
|
* export class DatabaseConfigProvider extends AbstractConfigProvider {
|
|
33
33
|
* schema() {
|
|
34
34
|
* return z.object({
|
|
@@ -51,7 +51,7 @@ export interface ConfigPropertyMapping {
|
|
|
51
51
|
*
|
|
52
52
|
* @example Custom env key mapping:
|
|
53
53
|
* ```typescript
|
|
54
|
-
* @
|
|
54
|
+
* @Provider()
|
|
55
55
|
* export class AppConfigProvider extends AbstractConfigProvider {
|
|
56
56
|
* schema() {
|
|
57
57
|
* return z.object({
|
|
@@ -74,7 +74,7 @@ export interface ConfigPropertyMapping {
|
|
|
74
74
|
*
|
|
75
75
|
* @example Mixed auto and custom mapping:
|
|
76
76
|
* ```typescript
|
|
77
|
-
* @
|
|
77
|
+
* @Provider()
|
|
78
78
|
* export class ApiConfigProvider extends AbstractConfigProvider {
|
|
79
79
|
* schema() {
|
|
80
80
|
* return z.object({
|
|
@@ -52,10 +52,10 @@ function toUpperSnakeCase(propertyName) {
|
|
|
52
52
|
*
|
|
53
53
|
* @example Auto-mapping (property name → UPPER_SNAKE_CASE):
|
|
54
54
|
* ```typescript
|
|
55
|
-
* import { ConfigProperty,
|
|
55
|
+
* import { ConfigProperty, Provider, AbstractConfigProvider } from '@riktajs/core';
|
|
56
56
|
* import { z } from 'zod';
|
|
57
57
|
*
|
|
58
|
-
* @
|
|
58
|
+
* @Provider()
|
|
59
59
|
* export class DatabaseConfigProvider extends AbstractConfigProvider {
|
|
60
60
|
* schema() {
|
|
61
61
|
* return z.object({
|
|
@@ -78,7 +78,7 @@ function toUpperSnakeCase(propertyName) {
|
|
|
78
78
|
*
|
|
79
79
|
* @example Custom env key mapping:
|
|
80
80
|
* ```typescript
|
|
81
|
-
* @
|
|
81
|
+
* @Provider()
|
|
82
82
|
* export class AppConfigProvider extends AbstractConfigProvider {
|
|
83
83
|
* schema() {
|
|
84
84
|
* return z.object({
|
|
@@ -101,7 +101,7 @@ function toUpperSnakeCase(propertyName) {
|
|
|
101
101
|
*
|
|
102
102
|
* @example Mixed auto and custom mapping:
|
|
103
103
|
* ```typescript
|
|
104
|
-
* @
|
|
104
|
+
* @Provider()
|
|
105
105
|
* export class ApiConfigProvider extends AbstractConfigProvider {
|
|
106
106
|
* schema() {
|
|
107
107
|
* return z.object({
|
|
@@ -4,6 +4,5 @@ export * from './route.decorator';
|
|
|
4
4
|
export * from './param.decorator';
|
|
5
5
|
export * from './autowired.decorator';
|
|
6
6
|
export * from './provider.decorator';
|
|
7
|
-
export * from './provider-config.decorator';
|
|
8
7
|
export * from './config-property.decorator';
|
|
9
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/decorators/index.ts"],"names":[],"mappings":"AACA,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,6BAA6B,CAAC
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/decorators/index.ts"],"names":[],"mappings":"AACA,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,6BAA6B,CAAC"}
|
|
@@ -21,6 +21,5 @@ __exportStar(require("./route.decorator"), exports);
|
|
|
21
21
|
__exportStar(require("./param.decorator"), exports);
|
|
22
22
|
__exportStar(require("./autowired.decorator"), exports);
|
|
23
23
|
__exportStar(require("./provider.decorator"), exports);
|
|
24
|
-
__exportStar(require("./provider-config.decorator"), exports);
|
|
25
24
|
__exportStar(require("./config-property.decorator"), exports);
|
|
26
25
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/decorators/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wBAAwB;AACxB,yDAAuC;AACvC,yDAAuC;AACvC,oDAAkC;AAClC,oDAAkC;AAClC,wDAAsC;AACtC,uDAAqC;AACrC,8DAA4C
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/decorators/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wBAAwB;AACxB,yDAAuC;AACvC,yDAAuC;AACvC,oDAAkC;AAClC,oDAAkC;AAClC,wDAAsC;AACtC,uDAAqC;AACrC,8DAA4C"}
|
|
@@ -1,23 +1,38 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
2
|
import { Token } from '../container/injection-token';
|
|
3
|
+
import { Constructor } from '../types';
|
|
3
4
|
/**
|
|
4
5
|
* Provider metadata stored on the class
|
|
5
6
|
*/
|
|
6
7
|
export interface ProviderMetadata {
|
|
7
8
|
token: Token;
|
|
8
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* Config provider metadata stored on the class
|
|
12
|
+
*/
|
|
13
|
+
export interface ConfigProviderMetadata {
|
|
14
|
+
/**
|
|
15
|
+
* The injection token for this config provider
|
|
16
|
+
* @example 'APP_CONFIG', 'DATABASE_CONFIG'
|
|
17
|
+
*/
|
|
18
|
+
token: string;
|
|
19
|
+
}
|
|
9
20
|
/**
|
|
10
21
|
* @Provider() decorator
|
|
11
22
|
*
|
|
12
|
-
* Marks a class as a custom provider that will be auto-discovered.
|
|
13
|
-
* The class must implement a `provide()` method that returns the value.
|
|
23
|
+
* Marks a class as a custom provider or config provider that will be auto-discovered.
|
|
14
24
|
*
|
|
25
|
+
* For **custom providers**, the class must implement a `provide()` method that returns the value.
|
|
15
26
|
* Providers can inject dependencies via constructor or @Autowired properties,
|
|
16
27
|
* making them perfect for complex factory logic.
|
|
17
28
|
*
|
|
18
|
-
*
|
|
29
|
+
* For **config providers**, the class extends AbstractConfigProvider and manages
|
|
30
|
+
* environment variables with Zod validation and @ConfigProperty decorators.
|
|
31
|
+
* If no token is provided for config providers, it will be auto-generated from the class name.
|
|
32
|
+
*
|
|
33
|
+
* @param token - The injection token this provider supplies. Required for custom providers, optional for config providers.
|
|
19
34
|
*
|
|
20
|
-
* @example
|
|
35
|
+
* @example Custom provider with provide() method:
|
|
21
36
|
* ```typescript
|
|
22
37
|
* const APP_CONFIG = new InjectionToken<AppConfig>('app.config');
|
|
23
38
|
*
|
|
@@ -32,6 +47,32 @@ export interface ProviderMetadata {
|
|
|
32
47
|
* }
|
|
33
48
|
* ```
|
|
34
49
|
*
|
|
50
|
+
* @example Config provider extending AbstractConfigProvider:
|
|
51
|
+
* ```typescript
|
|
52
|
+
* import { AbstractConfigProvider, Provider, ConfigProperty } from '@riktajs/core';
|
|
53
|
+
* import { z } from 'zod';
|
|
54
|
+
*
|
|
55
|
+
* export const APP_CONFIG = 'APP_CONFIG' as const;
|
|
56
|
+
*
|
|
57
|
+
* @Provider(APP_CONFIG)
|
|
58
|
+
* export class AppConfigProvider extends AbstractConfigProvider {
|
|
59
|
+
* schema() {
|
|
60
|
+
* return z.object({
|
|
61
|
+
* PORT: z.coerce.number().int().default(3000),
|
|
62
|
+
* HOST: z.string().default('localhost'),
|
|
63
|
+
* });
|
|
64
|
+
* }
|
|
65
|
+
*
|
|
66
|
+
* @ConfigProperty() port!: number;
|
|
67
|
+
* @ConfigProperty() host!: string;
|
|
68
|
+
*
|
|
69
|
+
* constructor() {
|
|
70
|
+
* super();
|
|
71
|
+
* this.populate();
|
|
72
|
+
* }
|
|
73
|
+
* }
|
|
74
|
+
* ```
|
|
75
|
+
*
|
|
35
76
|
* @example Provider with dependencies:
|
|
36
77
|
* ```typescript
|
|
37
78
|
* const LOGGER = new InjectionToken<Logger>('logger');
|
|
@@ -48,17 +89,20 @@ export interface ProviderMetadata {
|
|
|
48
89
|
* }
|
|
49
90
|
* }
|
|
50
91
|
* ```
|
|
92
|
+
*/
|
|
93
|
+
export declare function Provider(token?: Token): ClassDecorator;
|
|
94
|
+
/**
|
|
95
|
+
* Helper to retrieve config provider metadata from a class
|
|
51
96
|
*
|
|
52
|
-
* @
|
|
53
|
-
*
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
* ```
|
|
97
|
+
* @param target - The class to retrieve metadata from
|
|
98
|
+
* @returns The config provider metadata or undefined
|
|
99
|
+
*/
|
|
100
|
+
export declare function getConfigProviderMetadata(target: Constructor): ConfigProviderMetadata | undefined;
|
|
101
|
+
/**
|
|
102
|
+
* Check if a class has config provider metadata
|
|
103
|
+
*
|
|
104
|
+
* @param target - The class to check
|
|
105
|
+
* @returns True if the class is a config provider
|
|
62
106
|
*/
|
|
63
|
-
export declare function
|
|
107
|
+
export declare function isConfigProvider(target: Constructor): boolean;
|
|
64
108
|
//# sourceMappingURL=provider.decorator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.decorator.d.ts","sourceRoot":"","sources":["../../../src/core/decorators/provider.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAE1B,OAAO,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"provider.decorator.d.ts","sourceRoot":"","sources":["../../../src/core/decorators/provider.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAE1B,OAAO,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAC;AAErD,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEvC;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,KAAK,CAAC;CACd;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC;CACf;AAkCD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwEG;AACH,wBAAgB,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,GAAG,cAAc,CA6DtD;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,WAAW,GAClB,sBAAsB,GAAG,SAAS,CAEpC;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAE7D"}
|
|
@@ -1,21 +1,55 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Provider = Provider;
|
|
4
|
+
exports.getConfigProviderMetadata = getConfigProviderMetadata;
|
|
5
|
+
exports.isConfigProvider = isConfigProvider;
|
|
4
6
|
require("reflect-metadata");
|
|
5
7
|
const constants_1 = require("../constants");
|
|
6
8
|
const registry_1 = require("../registry");
|
|
9
|
+
/**
|
|
10
|
+
* Convert a class name to an uppercase config token
|
|
11
|
+
*
|
|
12
|
+
* @param className - The class name to convert
|
|
13
|
+
* @returns Uppercase token name
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* generateToken('AppConfigProvider') // Returns 'APP_CONFIG'
|
|
18
|
+
* generateToken('DatabaseConfigProvider') // Returns 'DATABASE_CONFIG'
|
|
19
|
+
* generateToken('MyCustomConfig') // Returns 'MY_CUSTOM_CONFIG'
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
function generateTokenFromClassName(className) {
|
|
23
|
+
// Remove 'Provider' suffix if present
|
|
24
|
+
let tokenName = className.replace(/Provider$/, '');
|
|
25
|
+
// Convert camelCase/PascalCase to UPPER_SNAKE_CASE
|
|
26
|
+
tokenName = tokenName
|
|
27
|
+
.replace(/([A-Z])/g, '_$1')
|
|
28
|
+
.toUpperCase()
|
|
29
|
+
.replace(/^_/, '');
|
|
30
|
+
// Ensure it ends with _CONFIG if not already present
|
|
31
|
+
// But don't add it if the name already ends with CONFIG (after conversion)
|
|
32
|
+
if (!tokenName.endsWith('_CONFIG') && tokenName !== 'CONFIG') {
|
|
33
|
+
tokenName = `${tokenName}_CONFIG`;
|
|
34
|
+
}
|
|
35
|
+
return tokenName;
|
|
36
|
+
}
|
|
7
37
|
/**
|
|
8
38
|
* @Provider() decorator
|
|
9
39
|
*
|
|
10
|
-
* Marks a class as a custom provider that will be auto-discovered.
|
|
11
|
-
* The class must implement a `provide()` method that returns the value.
|
|
40
|
+
* Marks a class as a custom provider or config provider that will be auto-discovered.
|
|
12
41
|
*
|
|
42
|
+
* For **custom providers**, the class must implement a `provide()` method that returns the value.
|
|
13
43
|
* Providers can inject dependencies via constructor or @Autowired properties,
|
|
14
44
|
* making them perfect for complex factory logic.
|
|
15
45
|
*
|
|
16
|
-
*
|
|
46
|
+
* For **config providers**, the class extends AbstractConfigProvider and manages
|
|
47
|
+
* environment variables with Zod validation and @ConfigProperty decorators.
|
|
48
|
+
* If no token is provided for config providers, it will be auto-generated from the class name.
|
|
17
49
|
*
|
|
18
|
-
* @
|
|
50
|
+
* @param token - The injection token this provider supplies. Required for custom providers, optional for config providers.
|
|
51
|
+
*
|
|
52
|
+
* @example Custom provider with provide() method:
|
|
19
53
|
* ```typescript
|
|
20
54
|
* const APP_CONFIG = new InjectionToken<AppConfig>('app.config');
|
|
21
55
|
*
|
|
@@ -30,6 +64,32 @@ const registry_1 = require("../registry");
|
|
|
30
64
|
* }
|
|
31
65
|
* ```
|
|
32
66
|
*
|
|
67
|
+
* @example Config provider extending AbstractConfigProvider:
|
|
68
|
+
* ```typescript
|
|
69
|
+
* import { AbstractConfigProvider, Provider, ConfigProperty } from '@riktajs/core';
|
|
70
|
+
* import { z } from 'zod';
|
|
71
|
+
*
|
|
72
|
+
* export const APP_CONFIG = 'APP_CONFIG' as const;
|
|
73
|
+
*
|
|
74
|
+
* @Provider(APP_CONFIG)
|
|
75
|
+
* export class AppConfigProvider extends AbstractConfigProvider {
|
|
76
|
+
* schema() {
|
|
77
|
+
* return z.object({
|
|
78
|
+
* PORT: z.coerce.number().int().default(3000),
|
|
79
|
+
* HOST: z.string().default('localhost'),
|
|
80
|
+
* });
|
|
81
|
+
* }
|
|
82
|
+
*
|
|
83
|
+
* @ConfigProperty() port!: number;
|
|
84
|
+
* @ConfigProperty() host!: string;
|
|
85
|
+
*
|
|
86
|
+
* constructor() {
|
|
87
|
+
* super();
|
|
88
|
+
* this.populate();
|
|
89
|
+
* }
|
|
90
|
+
* }
|
|
91
|
+
* ```
|
|
92
|
+
*
|
|
33
93
|
* @example Provider with dependencies:
|
|
34
94
|
* ```typescript
|
|
35
95
|
* const LOGGER = new InjectionToken<Logger>('logger');
|
|
@@ -46,24 +106,69 @@ const registry_1 = require("../registry");
|
|
|
46
106
|
* }
|
|
47
107
|
* }
|
|
48
108
|
* ```
|
|
49
|
-
*
|
|
50
|
-
* @example Async provider:
|
|
51
|
-
* ```typescript
|
|
52
|
-
* @Provider(DATABASE)
|
|
53
|
-
* export class DatabaseProvider {
|
|
54
|
-
* async provide(): Promise<Database> {
|
|
55
|
-
* const db = await connectToDatabase();
|
|
56
|
-
* return db;
|
|
57
|
-
* }
|
|
58
|
-
* }
|
|
59
|
-
* ```
|
|
60
109
|
*/
|
|
61
110
|
function Provider(token) {
|
|
62
111
|
return (target) => {
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
//
|
|
66
|
-
|
|
112
|
+
const className = target.name;
|
|
113
|
+
// Check if this is a config provider (extends AbstractConfigProvider)
|
|
114
|
+
// by checking if it has a schema() method in its prototype
|
|
115
|
+
const isConfigProvider = typeof target.prototype.schema === 'function';
|
|
116
|
+
if (isConfigProvider) {
|
|
117
|
+
// This is a config provider - use string token and CONFIG_PROVIDER_METADATA
|
|
118
|
+
let configToken;
|
|
119
|
+
if (typeof token === 'string') {
|
|
120
|
+
// Validate non-empty string
|
|
121
|
+
if (token.trim() === '') {
|
|
122
|
+
throw new Error(`@Provider: Config provider "${className}" token must be a non-empty string.`);
|
|
123
|
+
}
|
|
124
|
+
configToken = token;
|
|
125
|
+
}
|
|
126
|
+
else if (token === undefined) {
|
|
127
|
+
// Auto-generate token from class name
|
|
128
|
+
configToken = generateTokenFromClassName(className);
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
throw new Error(`@Provider: Config provider "${className}" requires a string token or no token for auto-generation.`);
|
|
132
|
+
}
|
|
133
|
+
// Validate token format for config providers
|
|
134
|
+
if (configToken !== configToken.toUpperCase()) {
|
|
135
|
+
throw new Error(`@Provider: Token "${configToken}" for config provider "${className}" must be UPPERCASE. ` +
|
|
136
|
+
`Use "${configToken.toUpperCase()}" instead.`);
|
|
137
|
+
}
|
|
138
|
+
// Store config provider metadata
|
|
139
|
+
const configMetadata = { token: configToken };
|
|
140
|
+
Reflect.defineMetadata(constants_1.CONFIG_PROVIDER_METADATA, configMetadata, target);
|
|
141
|
+
// Register config provider in the registry
|
|
142
|
+
registry_1.registry.registerConfigProvider(configToken, target);
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
// This is a custom provider - use PROVIDER_METADATA
|
|
146
|
+
if (token === undefined) {
|
|
147
|
+
throw new Error(`@Provider: Custom provider "${className}" requires a token parameter.`);
|
|
148
|
+
}
|
|
149
|
+
const metadata = { token };
|
|
150
|
+
Reflect.defineMetadata(constants_1.PROVIDER_METADATA, metadata, target);
|
|
151
|
+
// Register in global registry for auto-discovery
|
|
152
|
+
registry_1.registry.registerCustomProvider(target);
|
|
153
|
+
}
|
|
67
154
|
};
|
|
68
155
|
}
|
|
156
|
+
/**
|
|
157
|
+
* Helper to retrieve config provider metadata from a class
|
|
158
|
+
*
|
|
159
|
+
* @param target - The class to retrieve metadata from
|
|
160
|
+
* @returns The config provider metadata or undefined
|
|
161
|
+
*/
|
|
162
|
+
function getConfigProviderMetadata(target) {
|
|
163
|
+
return Reflect.getMetadata(constants_1.CONFIG_PROVIDER_METADATA, target);
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Check if a class has config provider metadata
|
|
167
|
+
*
|
|
168
|
+
* @param target - The class to check
|
|
169
|
+
* @returns True if the class is a config provider
|
|
170
|
+
*/
|
|
171
|
+
function isConfigProvider(target) {
|
|
172
|
+
return Reflect.hasMetadata(constants_1.CONFIG_PROVIDER_METADATA, target);
|
|
173
|
+
}
|
|
69
174
|
//# sourceMappingURL=provider.decorator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.decorator.js","sourceRoot":"","sources":["../../../src/core/decorators/provider.decorator.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"provider.decorator.js","sourceRoot":"","sources":["../../../src/core/decorators/provider.decorator.ts"],"names":[],"mappings":";;AAiIA,4BA6DC;AAQD,8DAIC;AAQD,4CAEC;AApND,4BAA0B;AAC1B,4CAA2E;AAE3E,0CAAuC;AAqBvC;;;;;;;;;;;;GAYG;AACH,SAAS,0BAA0B,CAAC,SAAiB;IACnD,sCAAsC;IACtC,IAAI,SAAS,GAAG,SAAS,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;IAEnD,mDAAmD;IACnD,SAAS,GAAG,SAAS;SAClB,OAAO,CAAC,UAAU,EAAE,KAAK,CAAC;SAC1B,WAAW,EAAE;SACb,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IAErB,qDAAqD;IACrD,2EAA2E;IAC3E,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,SAAS,KAAK,QAAQ,EAAE,CAAC;QAC7D,SAAS,GAAG,G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OAAO,CAAC,cAAc,CAAC,oCAAwB,EAAE,cAAc,EAAE,MAAM,CAAC,CAAC;YAEzE,2CAA2C;YAC3C,mBAAQ,CAAC,sBAAsB,CAC7B,WAAW,EACX,MAAqB,CACtB,CAAC;QACJ,CAAC;aAAM,CAAC;YACN,oDAAoD;YACpD,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;gBACxB,MAAM,IAAI,KAAK,CACb,+BAA+B,SAAS,+BAA+B,CACxE,CAAC;YACJ,CAAC;YAED,MAAM,QAAQ,GAAqB,EAAE,KAAK,EAAE,CAAC;YAC7C,OAAO,CAAC,cAAc,CAAC,6BAAiB,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;YAE5D,iDAAiD;YACjD,mBAAQ,CAAC,sBAAsB,CAAC,MAA6C,CAAC,CAAC;QACjF,CAAC;IACH,CAAC,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,SAAgB,yBAAyB,CACvC,MAAmB;IAEnB,OAAO,OAAO,CAAC,WAAW,CAAC,oCAAwB,EAAE,MAAM,CAAC,CAAC;AAC/D,CAAC;AAED;;;;;GAKG;AACH,SAAgB,gBAAgB,CAAC,MAAmB;IAClD,OAAO,OAAO,CAAC,WAAW,CAAC,oCAAwB,EAAE,MAAM,CAAC,CAAC;AAC/D,CAAC"}
|
package/dist/core/discovery.js
CHANGED
|
@@ -83,7 +83,7 @@ const DECORATOR_PATTERNS = [
|
|
|
83
83
|
/@Controller\s*\(/, // @Controller() or @Controller('/path')
|
|
84
84
|
/@Injectable\s*\(/, // @Injectable() or @Injectable({ scope: 'singleton' })
|
|
85
85
|
/@Provider\s*\(/, // @Provider(TOKEN)
|
|
86
|
-
/@
|
|
86
|
+
/@Provider\s*\(/, // @Provider(TOKEN)
|
|
87
87
|
// Compiled JavaScript patterns (e.g., (0, core_1.Controller)('/path'))
|
|
88
88
|
/\.\s*Controller\s*\)\s*\(/,
|
|
89
89
|
/\.\s*Injectable\s*\)\s*\(/,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"discovery.js","sourceRoot":"","sources":["../../src/core/discovery.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6FA,0CAwEC;AAWD,gDAEC;AAlLD,0DAA2B;AAC3B,2DAA6B;AAC7B,gDAAwB;AAExB;;GAEG;AACH,MAAM,uBAAuB,GAAG;IAC9B,oBAAoB;IACpB,YAAY;IACZ,aAAa;IACb,kBAAkB;IAClB,cAAc;IACd,cAAc;IACd,WAAW;CACZ,CAAC;AAEF;;;;;;;;GAQG;AACH,SAAS,sBAAsB;IAC7B,MAAM,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAEnC,IAAI,UAAU,EAAE,CAAC;QACf,8CAA8C;QAC9C,MAAM,QAAQ,GAAG,UAAU,CAAC,UAAU,CAAC,SAAS,CAAC;YAC/C,CAAC,CAAC,IAAI,GAAG,CAAC,UAAU,CAAC,CAAC,QAAQ;YAC9B,CAAC,CAAC,UAAU,CAAC;QACf,OAAO,cAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAChC,CAAC;IAED,wCAAwC;IACxC,OAAO,OAAO,CAAC,GAAG,EAAE,CAAC;AACvB,CAAC;AAED;;;GAGG;AACH,MAAM,kBAAkB,GAAG;IACzB,6BAA6B;IAC7B,kBAAkB,EAAK,wCAAwC;IAC/D,kBAAkB,EAAK,uDAAuD;IAC9E,gBAAgB,EAAO,mBAAmB;IAC1C,
|
|
1
|
+
{"version":3,"file":"discovery.js","sourceRoot":"","sources":["../../src/core/discovery.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6FA,0CAwEC;AAWD,gDAEC;AAlLD,0DAA2B;AAC3B,2DAA6B;AAC7B,gDAAwB;AAExB;;GAEG;AACH,MAAM,uBAAuB,GAAG;IAC9B,oBAAoB;IACpB,YAAY;IACZ,aAAa;IACb,kBAAkB;IAClB,cA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;IAC7C,MAAM,UAAU,GAAa,EAAE,CAAC;IAEhC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,MAAM,uBAAuB,CAAC,IAAI,CAAC,EAAE,CAAC;YACxC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACxB,CAAC;IACH,CAAC;IAED,oCAAoC;IACpC,MAAM,aAAa,GAAa,EAAE,CAAC;IAEnC,KAAK,MAAM,IAAI,IAAI,UAAU,EAAE,CAAC;QAC9B,IAAI,CAAC;YACH,gCAAgC;YAChC,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;YAC7C,yBAAa,UAAU,uCAAC,CAAC;YACzB,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC3B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,2DAA2D;YAC3D,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC;gBACtB,OAAO,CAAC,IAAI,CAAC,4BAA4B,IAAI,GAAG,EAAE,KAAK,CAAC,CAAC;YAC3D,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,aAAa,CAAC;AACvB,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,kBAAkB;IAChC,OAAO,sBAAsB,EAAE,CAAC;AAClC,CAAC"}
|
|
@@ -26,7 +26,7 @@ class ConfigProviderNotFoundException extends Error {
|
|
|
26
26
|
: '';
|
|
27
27
|
super(`Config provider with token "${token}" not found.${suggestion}\n` +
|
|
28
28
|
`Make sure the provider class is:\n` +
|
|
29
|
-
`1. Decorated with @
|
|
29
|
+
`1. Decorated with @Provider('${token}')\n` +
|
|
30
30
|
`2. Located in a file matching the autowired patterns\n` +
|
|
31
31
|
`3. Properly exported from its module`);
|
|
32
32
|
this.name = 'ConfigProviderNotFoundException';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.exceptions.js","sourceRoot":"","sources":["../../../src/core/exceptions/config.exceptions.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,MAAa,wCAAyC,SAAQ,KAAK;IACjE,YAAY,KAAa,EAAE,aAAqB,EAAE,QAAgB;QAChE,KAAK,CACH,+BAA+B,KAAK,4BAA4B;YAChE,aAAa,aAAa,IAAI;YAC9B,cAAc,QAAQ,IAAI;YAC1B,6DAA6D,CAC9D,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,0CAA0C,CAAC;IACzD,CAAC;CACF;AAVD,4FAUC;AAED;;;GAGG;AACH,MAAa,+BAAgC,SAAQ,KAAK;IACxD,YAAY,KAAa,EAAE,kBAA4B,EAAE;QACvD,MAAM,UAAU,GAAG,eAAe,CAAC,MAAM,GAAG,CAAC;YAC3C,CAAC,CAAC,yBAAyB,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;YACvD,CAAC,CAAC,EAAE,CAAC;QAEP,KAAK,CACH,+BAA+B,KAAK,eAAe,UAAU,IAAI;YACjE,oCAAoC;YACpC,
|
|
1
|
+
{"version":3,"file":"config.exceptions.js","sourceRoot":"","sources":["../../../src/core/exceptions/config.exceptions.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,MAAa,wCAAyC,SAAQ,KAAK;IACjE,YAAY,KAAa,EAAE,aAAqB,EAAE,QAAgB;QAChE,KAAK,CACH,+BAA+B,KAAK,4BAA4B;YAChE,aAAa,aAAa,IAAI;YAC9B,cAAc,QAAQ,IAAI;YAC1B,6DAA6D,CAC9D,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,0CAA0C,CAAC;IACzD,CAAC;CACF;AAVD,4FAUC;AAED;;;GAGG;AACH,MAAa,+BAAgC,SAAQ,KAAK;IACxD,YAAY,KAAa,EAAE,kBAA4B,EAAE;QACvD,MAAM,UAAU,GAAG,eAAe,CAAC,MAAM,GAAG,CAAC;YAC3C,CAAC,CAAC,yBAAyB,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;YACvD,CAAC,CAAC,EAAE,CAAC;QAEP,KAAK,CACH,+BAA+B,KAAK,eAAe,UAAU,IAAI;YACjE,oCAAoC;YACpC,gCAAgC,KAAK,MAAM;YAC3C,wDAAwD;YACxD,sCAAsC,CACvC,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,iCAAiC,CAAC;IAChD,CAAC;CACF;AAfD,0EAeC;AAED;;GAEG;AACH,MAAa,oCAAqC,SAAQ,KAAK;IAC7D,YAAY,KAAa,EAAE,SAAiB,EAAE,KAAY;QACxD,KAAK,CACH,0CAA0C,SAAS,cAAc,KAAK,OAAO;YAC7E,UAAU,KAAK,CAAC,OAAO,MAAM;YAC7B,4BAA4B;YAC5B,8BAA8B;YAC9B,kDAAkD;YAClD,kDAAkD,CACnD,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,sCAAsC,CAAC;QACnD,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;CACF;AAbD,oFAaC"}
|
package/package.json
CHANGED