@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
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConfigProperty = ConfigProperty;
|
|
4
|
+
exports.getConfigPropertyMappings = getConfigPropertyMappings;
|
|
5
|
+
exports.hasConfigProperties = hasConfigProperties;
|
|
6
|
+
exports.clearPropertyNameCache = clearPropertyNameCache;
|
|
7
|
+
require("reflect-metadata");
|
|
8
|
+
const constants_1 = require("../constants");
|
|
9
|
+
/**
|
|
10
|
+
* Cache for converted property names to avoid recomputation
|
|
11
|
+
* Map<propertyKey, envKey>
|
|
12
|
+
*/
|
|
13
|
+
const propertyNameCache = new Map();
|
|
14
|
+
/**
|
|
15
|
+
* Convert a camelCase property name to UPPER_SNAKE_CASE
|
|
16
|
+
*
|
|
17
|
+
* @param propertyName - The property name to convert
|
|
18
|
+
* @returns The converted UPPER_SNAKE_CASE name
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* toUpperSnakeCase('dbHost') // 'DB_HOST'
|
|
23
|
+
* toUpperSnakeCase('apiKey') // 'API_KEY'
|
|
24
|
+
* toUpperSnakeCase('port') // 'PORT'
|
|
25
|
+
* toUpperSnakeCase('maxRetries') // 'MAX_RETRIES'
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
function toUpperSnakeCase(propertyName) {
|
|
29
|
+
// Check cache first (tip: cache derived names)
|
|
30
|
+
if (propertyNameCache.has(propertyName)) {
|
|
31
|
+
return propertyNameCache.get(propertyName);
|
|
32
|
+
}
|
|
33
|
+
// Convert camelCase/PascalCase to UPPER_SNAKE_CASE
|
|
34
|
+
const envKey = propertyName
|
|
35
|
+
.replace(/([A-Z])/g, '_$1')
|
|
36
|
+
.toUpperCase()
|
|
37
|
+
.replace(/^_/, '');
|
|
38
|
+
// Cache for future use
|
|
39
|
+
propertyNameCache.set(propertyName, envKey);
|
|
40
|
+
return envKey;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* @ConfigProperty() decorator
|
|
44
|
+
*
|
|
45
|
+
* Maps a class property to an environment variable. If no explicit env key is provided,
|
|
46
|
+
* automatically converts the property name from camelCase to UPPER_SNAKE_CASE.
|
|
47
|
+
*
|
|
48
|
+
* This decorator stores metadata that will be read by AbstractConfigProvider
|
|
49
|
+
* during the populate() phase to assign validated environment values to properties.
|
|
50
|
+
*
|
|
51
|
+
* @param envKey - Optional explicit environment variable name (must be UPPERCASE)
|
|
52
|
+
*
|
|
53
|
+
* @example Auto-mapping (property name → UPPER_SNAKE_CASE):
|
|
54
|
+
* ```typescript
|
|
55
|
+
* import { ConfigProperty, ProviderConfig, AbstractConfigProvider } from '@riktajs/core';
|
|
56
|
+
* import { z } from 'zod';
|
|
57
|
+
*
|
|
58
|
+
* @ProviderConfig()
|
|
59
|
+
* export class DatabaseConfigProvider extends AbstractConfigProvider {
|
|
60
|
+
* schema() {
|
|
61
|
+
* return z.object({
|
|
62
|
+
* DB_HOST: z.string(),
|
|
63
|
+
* DB_PORT: z.coerce.number().int(),
|
|
64
|
+
* DB_NAME: z.string(),
|
|
65
|
+
* });
|
|
66
|
+
* }
|
|
67
|
+
*
|
|
68
|
+
* @ConfigProperty() // Maps to 'DB_HOST'
|
|
69
|
+
* dbHost!: string;
|
|
70
|
+
*
|
|
71
|
+
* @ConfigProperty() // Maps to 'DB_PORT'
|
|
72
|
+
* dbPort!: number;
|
|
73
|
+
*
|
|
74
|
+
* @ConfigProperty() // Maps to 'DB_NAME'
|
|
75
|
+
* dbName!: string;
|
|
76
|
+
* }
|
|
77
|
+
* ```
|
|
78
|
+
*
|
|
79
|
+
* @example Custom env key mapping:
|
|
80
|
+
* ```typescript
|
|
81
|
+
* @ProviderConfig()
|
|
82
|
+
* export class AppConfigProvider extends AbstractConfigProvider {
|
|
83
|
+
* schema() {
|
|
84
|
+
* return z.object({
|
|
85
|
+
* PORT: z.coerce.number().int(),
|
|
86
|
+
* NODE_ENV: z.enum(['development', 'production', 'test']),
|
|
87
|
+
* API_SECRET_KEY: z.string(),
|
|
88
|
+
* });
|
|
89
|
+
* }
|
|
90
|
+
*
|
|
91
|
+
* @ConfigProperty('PORT')
|
|
92
|
+
* serverPort!: number;
|
|
93
|
+
*
|
|
94
|
+
* @ConfigProperty('NODE_ENV')
|
|
95
|
+
* environment!: 'development' | 'production' | 'test';
|
|
96
|
+
*
|
|
97
|
+
* @ConfigProperty('API_SECRET_KEY')
|
|
98
|
+
* secret!: string;
|
|
99
|
+
* }
|
|
100
|
+
* ```
|
|
101
|
+
*
|
|
102
|
+
* @example Mixed auto and custom mapping:
|
|
103
|
+
* ```typescript
|
|
104
|
+
* @ProviderConfig()
|
|
105
|
+
* export class ApiConfigProvider extends AbstractConfigProvider {
|
|
106
|
+
* schema() {
|
|
107
|
+
* return z.object({
|
|
108
|
+
* API_KEY: z.string(),
|
|
109
|
+
* API_URL: z.string().url(),
|
|
110
|
+
* TIMEOUT: z.coerce.number().int(),
|
|
111
|
+
* });
|
|
112
|
+
* }
|
|
113
|
+
*
|
|
114
|
+
* @ConfigProperty() // Auto: apiKey → API_KEY
|
|
115
|
+
* apiKey!: string;
|
|
116
|
+
*
|
|
117
|
+
* @ConfigProperty() // Auto: apiUrl → API_URL
|
|
118
|
+
* apiUrl!: string;
|
|
119
|
+
*
|
|
120
|
+
* @ConfigProperty('TIMEOUT') // Custom mapping
|
|
121
|
+
* requestTimeout!: number;
|
|
122
|
+
* }
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
function ConfigProperty(envKey) {
|
|
126
|
+
return (target, propertyKey) => {
|
|
127
|
+
if (typeof propertyKey === 'symbol') {
|
|
128
|
+
throw new Error(`@ConfigProperty: Symbol properties are not supported. ` +
|
|
129
|
+
`Property "${String(propertyKey)}" must be a string.`);
|
|
130
|
+
}
|
|
131
|
+
// Determine the environment variable name
|
|
132
|
+
const finalEnvKey = envKey ?? toUpperSnakeCase(propertyKey);
|
|
133
|
+
// Validate env key format
|
|
134
|
+
if (!finalEnvKey || typeof finalEnvKey !== 'string') {
|
|
135
|
+
throw new Error(`@ConfigProperty: Invalid env key for property "${propertyKey}". ` +
|
|
136
|
+
`Env key must be a non-empty string.`);
|
|
137
|
+
}
|
|
138
|
+
// Ensure env key is uppercase (convention)
|
|
139
|
+
if (finalEnvKey !== finalEnvKey.toUpperCase()) {
|
|
140
|
+
throw new Error(`@ConfigProperty: Env key "${finalEnvKey}" for property "${propertyKey}" must be UPPERCASE. ` +
|
|
141
|
+
`Use "${finalEnvKey.toUpperCase()}" instead.`);
|
|
142
|
+
}
|
|
143
|
+
// Get existing metadata or initialize
|
|
144
|
+
const constructor = target.constructor;
|
|
145
|
+
const existingMappings = Reflect.getMetadata(constants_1.CONFIG_PROPERTY_METADATA, constructor) || [];
|
|
146
|
+
// Check for duplicate property decorations
|
|
147
|
+
const duplicate = existingMappings.find(m => m.propertyKey === propertyKey);
|
|
148
|
+
if (duplicate) {
|
|
149
|
+
throw new Error(`@ConfigProperty: Property "${propertyKey}" on class "${constructor.name}" ` +
|
|
150
|
+
`is already decorated. Remove the duplicate @ConfigProperty decorator.`);
|
|
151
|
+
}
|
|
152
|
+
// Check for duplicate env key mappings
|
|
153
|
+
const duplicateEnvKey = existingMappings.find(m => m.envKey === finalEnvKey);
|
|
154
|
+
if (duplicateEnvKey) {
|
|
155
|
+
throw new Error(`@ConfigProperty: Env key "${finalEnvKey}" is already mapped to property "${duplicateEnvKey.propertyKey}" ` +
|
|
156
|
+
`on class "${constructor.name}". Each env key can only be mapped to one property.`);
|
|
157
|
+
}
|
|
158
|
+
// Add the new mapping
|
|
159
|
+
const newMapping = {
|
|
160
|
+
propertyKey,
|
|
161
|
+
envKey: finalEnvKey,
|
|
162
|
+
};
|
|
163
|
+
const updatedMappings = [...existingMappings, newMapping];
|
|
164
|
+
// Store metadata
|
|
165
|
+
Reflect.defineMetadata(constants_1.CONFIG_PROPERTY_METADATA, updatedMappings, constructor);
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Helper to retrieve all config property mappings from a class
|
|
170
|
+
*
|
|
171
|
+
* @param target - The class constructor to retrieve mappings from
|
|
172
|
+
* @returns Array of property mappings, or empty array if none defined
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```typescript
|
|
176
|
+
* const mappings = getConfigPropertyMappings(AppConfigProvider);
|
|
177
|
+
* console.log(mappings);
|
|
178
|
+
* // [
|
|
179
|
+
* // { propertyKey: 'dbHost', envKey: 'DB_HOST' },
|
|
180
|
+
* // { propertyKey: 'dbPort', envKey: 'DB_PORT' }
|
|
181
|
+
* // ]
|
|
182
|
+
* ```
|
|
183
|
+
*/
|
|
184
|
+
function getConfigPropertyMappings(target) {
|
|
185
|
+
return Reflect.getMetadata(constants_1.CONFIG_PROPERTY_METADATA, target) || [];
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Check if a class has any @ConfigProperty decorated properties
|
|
189
|
+
*
|
|
190
|
+
* @param target - The class constructor to check
|
|
191
|
+
* @returns True if the class has at least one @ConfigProperty
|
|
192
|
+
*/
|
|
193
|
+
function hasConfigProperties(target) {
|
|
194
|
+
const mappings = getConfigPropertyMappings(target);
|
|
195
|
+
return mappings.length > 0;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Clear the property name conversion cache
|
|
199
|
+
*
|
|
200
|
+
* @internal Used for testing
|
|
201
|
+
*/
|
|
202
|
+
function clearPropertyNameCache() {
|
|
203
|
+
propertyNameCache.clear();
|
|
204
|
+
}
|
|
205
|
+
//# sourceMappingURL=config-property.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-property.decorator.js","sourceRoot":"","sources":["../../../src/core/decorators/config-property.decorator.ts"],"names":[],"mappings":";;AA2IA,wCA8DC;AAkBD,8DAEC;AAQD,kDAGC;AAOD,wDAEC;AAjPD,4BAA0B;AAC1B,4CAAwD;AAiBxD;;;GAGG;AACH,MAAM,iBAAiB,GAAG,IAAI,GAAG,EAAkB,CAAC;AAEpD;;;;;;;;;;;;;GAaG;AACH,SAAS,gBAAgB,CAAC,YAAoB;IAC5C,+CAA+C;IAC/C,IAAI,iBAAiB,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE,CAAC;QACxC,OAAO,iBAAiB,CAAC,GAAG,CAAC,YAAY,CAAE,CAAC;IAC9C,CAAC;IAED,mDAAmD;IACnD,MAAM,MAAM,GAAG,YAAY;SACxB,OAAO,CAAC,UAAU,EAAE,KAAK,CAAC;SAC1B,WAAW,EAAE;SACb,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IAErB,uBAAuB;IACvB,iBAAiB,CAAC,GAAG,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;IAE5C,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkFG;AACH,SAAgB,cAAc,CAAC,MAAe;IAC5C,OAAO,CAAC,MAAc,EAAE,WAA4B,EAAE,EAAE;QACtD,IAAI,OAAO,WAAW,KAAK,QAAQ,EAAE,CAAC;YACpC,MAAM,IAAI,KAAK,CACb,wDAAwD;gBACxD,aAAa,MAAM,CAAC,WAAW,CAAC,qBAAqB,CACtD,CAAC;QACJ,CAAC;QAED,0CAA0C;QAC1C,MAAM,WAAW,GAAG,MAAM,IAAI,gBAAgB,CAAC,WAAW,CAAC,CAAC;QAE5D,0BAA0B;QAC1B,IAAI,CAAC,WAAW,IAAI,OAAO,WAAW,KAAK,QAAQ,EAAE,CAAC;YACpD,MAAM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wB,EAAE,eAAe,EAAE,WAAW,CAAC,CAAC;IACjF,CAAC,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,yBAAyB,CAAC,MAAgB;IACxD,OAAO,OAAO,CAAC,WAAW,CAAC,oCAAwB,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC;AACrE,CAAC;AAED;;;;;GAKG;AACH,SAAgB,mBAAmB,CAAC,MAAgB;IAClD,MAAM,QAAQ,GAAG,yBAAyB,CAAC,MAAM,CAAC,CAAC;IACnD,OAAO,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC;AAC7B,CAAC;AAED;;;;GAIG;AACH,SAAgB,sBAAsB;IACpC,iBAAiB,CAAC,KAAK,EAAE,CAAC;AAC5B,CAAC"}
|
|
@@ -4,4 +4,6 @@ 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
|
+
export * from './config-property.decorator';
|
|
7
9
|
//# 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"}
|
|
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;AAC5C,cAAc,6BAA6B,CAAC"}
|
|
@@ -21,4 +21,6 @@ __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
|
+
__exportStar(require("./config-property.decorator"), exports);
|
|
24
26
|
//# 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"}
|
|
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;AAC5C,8DAA4C"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
import { Constructor } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Config provider metadata stored on the class
|
|
5
|
+
*/
|
|
6
|
+
export interface ConfigProviderMetadata {
|
|
7
|
+
/**
|
|
8
|
+
* The injection token for this config provider
|
|
9
|
+
* @example 'APP_CONFIG', 'DATABASE_CONFIG'
|
|
10
|
+
*/
|
|
11
|
+
token: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* @ProviderConfig() decorator
|
|
15
|
+
*
|
|
16
|
+
* Marks a class as a configuration provider that will be auto-discovered.
|
|
17
|
+
* Config providers extend AbstractConfigProvider and manage environment variables,
|
|
18
|
+
* validation with Zod schemas, and property mapping via @ConfigProperty.
|
|
19
|
+
*
|
|
20
|
+
* The decorator automatically generates an injection token from the class name
|
|
21
|
+
* if not explicitly provided, following the pattern: ClassName → CLASS_NAME_CONFIG
|
|
22
|
+
*
|
|
23
|
+
* @param token - Optional custom injection token (must be UPPERCASE)
|
|
24
|
+
*
|
|
25
|
+
* @example Auto-generated token:
|
|
26
|
+
* ```typescript
|
|
27
|
+
* import { ProviderConfig, AbstractConfigProvider } from '@riktajs/core';
|
|
28
|
+
* import { z } from 'zod';
|
|
29
|
+
*
|
|
30
|
+
* @ProviderConfig() // Token: 'APP_CONFIG'
|
|
31
|
+
* export class AppConfigProvider extends AbstractConfigProvider {
|
|
32
|
+
* schema() {
|
|
33
|
+
* return z.object({
|
|
34
|
+
* PORT: z.coerce.number().int().min(1).max(65535),
|
|
35
|
+
* HOST: z.string().default('localhost'),
|
|
36
|
+
* });
|
|
37
|
+
* }
|
|
38
|
+
*
|
|
39
|
+
* @ConfigProperty()
|
|
40
|
+
* port!: number;
|
|
41
|
+
*
|
|
42
|
+
* @ConfigProperty()
|
|
43
|
+
* host!: string;
|
|
44
|
+
* }
|
|
45
|
+
*
|
|
46
|
+
* // Inject with auto-generated token
|
|
47
|
+
* @Injectable()
|
|
48
|
+
* class MyService {
|
|
49
|
+
* @Autowired('APP_CONFIG')
|
|
50
|
+
* private config!: AppConfigProvider;
|
|
51
|
+
* }
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* @example Custom token:
|
|
55
|
+
* ```typescript
|
|
56
|
+
* @ProviderConfig('DATABASE_CONFIG')
|
|
57
|
+
* export class DbConfigProvider extends AbstractConfigProvider {
|
|
58
|
+
* schema() {
|
|
59
|
+
* return z.object({
|
|
60
|
+
* DB_HOST: z.string(),
|
|
61
|
+
* DB_PORT: z.coerce.number().int(),
|
|
62
|
+
* DB_NAME: z.string(),
|
|
63
|
+
* });
|
|
64
|
+
* }
|
|
65
|
+
* }
|
|
66
|
+
*
|
|
67
|
+
* // Inject with custom token
|
|
68
|
+
* @Injectable()
|
|
69
|
+
* class DatabaseService {
|
|
70
|
+
* @Autowired('DATABASE_CONFIG')
|
|
71
|
+
* private config!: DbConfigProvider;
|
|
72
|
+
* }
|
|
73
|
+
* ```
|
|
74
|
+
*
|
|
75
|
+
* @example Type-safe token export:
|
|
76
|
+
* ```typescript
|
|
77
|
+
* export const APP_CONFIG = 'APP_CONFIG' as const;
|
|
78
|
+
*
|
|
79
|
+
* @ProviderConfig(APP_CONFIG)
|
|
80
|
+
* export class AppConfigProvider extends AbstractConfigProvider {
|
|
81
|
+
* // ...
|
|
82
|
+
* }
|
|
83
|
+
*
|
|
84
|
+
* // Type-safe injection
|
|
85
|
+
* @Injectable()
|
|
86
|
+
* class MyService {
|
|
87
|
+
* @Autowired(APP_CONFIG)
|
|
88
|
+
* private config!: AppConfigProvider;
|
|
89
|
+
* }
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
export declare function ProviderConfig(token?: string): ClassDecorator;
|
|
93
|
+
/**
|
|
94
|
+
* Helper to retrieve config provider metadata from a class
|
|
95
|
+
*
|
|
96
|
+
* @param target - The class to retrieve metadata from
|
|
97
|
+
* @returns The config provider metadata or undefined
|
|
98
|
+
*/
|
|
99
|
+
export declare function getConfigProviderMetadata(target: Constructor): ConfigProviderMetadata | undefined;
|
|
100
|
+
/**
|
|
101
|
+
* Check if a class has @ProviderConfig decorator
|
|
102
|
+
*
|
|
103
|
+
* @param target - The class to check
|
|
104
|
+
* @returns True if the class is decorated with @ProviderConfig
|
|
105
|
+
*/
|
|
106
|
+
export declare function isConfigProvider(target: Constructor): boolean;
|
|
107
|
+
//# sourceMappingURL=provider-config.decorator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider-config.decorator.d.ts","sourceRoot":"","sources":["../../../src/core/decorators/provider-config.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAE1B,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEvC;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC;CACf;AAkCD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8EG;AACH,wBAAgB,cAAc,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,cAAc,CAgC7D;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"}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ProviderConfig = ProviderConfig;
|
|
4
|
+
exports.getConfigProviderMetadata = getConfigProviderMetadata;
|
|
5
|
+
exports.isConfigProvider = isConfigProvider;
|
|
6
|
+
require("reflect-metadata");
|
|
7
|
+
const constants_1 = require("../constants");
|
|
8
|
+
/**
|
|
9
|
+
* Convert a class name to an uppercase config token
|
|
10
|
+
*
|
|
11
|
+
* @param className - The class name to convert
|
|
12
|
+
* @returns Uppercase token name
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* generateToken('AppConfigProvider') // Returns 'APP_CONFIG'
|
|
17
|
+
* generateToken('DatabaseConfigProvider') // Returns 'DATABASE_CONFIG'
|
|
18
|
+
* generateToken('MyCustomConfig') // Returns 'MY_CUSTOM_CONFIG'
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
function generateTokenFromClassName(className) {
|
|
22
|
+
// Remove 'Provider' suffix if present
|
|
23
|
+
let tokenName = className.replace(/Provider$/, '');
|
|
24
|
+
// Convert camelCase/PascalCase to UPPER_SNAKE_CASE
|
|
25
|
+
tokenName = tokenName
|
|
26
|
+
.replace(/([A-Z])/g, '_$1')
|
|
27
|
+
.toUpperCase()
|
|
28
|
+
.replace(/^_/, '');
|
|
29
|
+
// Ensure it ends with _CONFIG if not already present
|
|
30
|
+
// But don't add it if the name already ends with CONFIG (after conversion)
|
|
31
|
+
if (!tokenName.endsWith('_CONFIG') && tokenName !== 'CONFIG') {
|
|
32
|
+
tokenName = `${tokenName}_CONFIG`;
|
|
33
|
+
}
|
|
34
|
+
return tokenName;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* @ProviderConfig() decorator
|
|
38
|
+
*
|
|
39
|
+
* Marks a class as a configuration provider that will be auto-discovered.
|
|
40
|
+
* Config providers extend AbstractConfigProvider and manage environment variables,
|
|
41
|
+
* validation with Zod schemas, and property mapping via @ConfigProperty.
|
|
42
|
+
*
|
|
43
|
+
* The decorator automatically generates an injection token from the class name
|
|
44
|
+
* if not explicitly provided, following the pattern: ClassName → CLASS_NAME_CONFIG
|
|
45
|
+
*
|
|
46
|
+
* @param token - Optional custom injection token (must be UPPERCASE)
|
|
47
|
+
*
|
|
48
|
+
* @example Auto-generated token:
|
|
49
|
+
* ```typescript
|
|
50
|
+
* import { ProviderConfig, AbstractConfigProvider } from '@riktajs/core';
|
|
51
|
+
* import { z } from 'zod';
|
|
52
|
+
*
|
|
53
|
+
* @ProviderConfig() // Token: 'APP_CONFIG'
|
|
54
|
+
* export class AppConfigProvider extends AbstractConfigProvider {
|
|
55
|
+
* schema() {
|
|
56
|
+
* return z.object({
|
|
57
|
+
* PORT: z.coerce.number().int().min(1).max(65535),
|
|
58
|
+
* HOST: z.string().default('localhost'),
|
|
59
|
+
* });
|
|
60
|
+
* }
|
|
61
|
+
*
|
|
62
|
+
* @ConfigProperty()
|
|
63
|
+
* port!: number;
|
|
64
|
+
*
|
|
65
|
+
* @ConfigProperty()
|
|
66
|
+
* host!: string;
|
|
67
|
+
* }
|
|
68
|
+
*
|
|
69
|
+
* // Inject with auto-generated token
|
|
70
|
+
* @Injectable()
|
|
71
|
+
* class MyService {
|
|
72
|
+
* @Autowired('APP_CONFIG')
|
|
73
|
+
* private config!: AppConfigProvider;
|
|
74
|
+
* }
|
|
75
|
+
* ```
|
|
76
|
+
*
|
|
77
|
+
* @example Custom token:
|
|
78
|
+
* ```typescript
|
|
79
|
+
* @ProviderConfig('DATABASE_CONFIG')
|
|
80
|
+
* export class DbConfigProvider extends AbstractConfigProvider {
|
|
81
|
+
* schema() {
|
|
82
|
+
* return z.object({
|
|
83
|
+
* DB_HOST: z.string(),
|
|
84
|
+
* DB_PORT: z.coerce.number().int(),
|
|
85
|
+
* DB_NAME: z.string(),
|
|
86
|
+
* });
|
|
87
|
+
* }
|
|
88
|
+
* }
|
|
89
|
+
*
|
|
90
|
+
* // Inject with custom token
|
|
91
|
+
* @Injectable()
|
|
92
|
+
* class DatabaseService {
|
|
93
|
+
* @Autowired('DATABASE_CONFIG')
|
|
94
|
+
* private config!: DbConfigProvider;
|
|
95
|
+
* }
|
|
96
|
+
* ```
|
|
97
|
+
*
|
|
98
|
+
* @example Type-safe token export:
|
|
99
|
+
* ```typescript
|
|
100
|
+
* export const APP_CONFIG = 'APP_CONFIG' as const;
|
|
101
|
+
*
|
|
102
|
+
* @ProviderConfig(APP_CONFIG)
|
|
103
|
+
* export class AppConfigProvider extends AbstractConfigProvider {
|
|
104
|
+
* // ...
|
|
105
|
+
* }
|
|
106
|
+
*
|
|
107
|
+
* // Type-safe injection
|
|
108
|
+
* @Injectable()
|
|
109
|
+
* class MyService {
|
|
110
|
+
* @Autowired(APP_CONFIG)
|
|
111
|
+
* private config!: AppConfigProvider;
|
|
112
|
+
* }
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
function ProviderConfig(token) {
|
|
116
|
+
return (target) => {
|
|
117
|
+
const className = target.name;
|
|
118
|
+
// Generate token from class name if not provided
|
|
119
|
+
const configToken = token ?? generateTokenFromClassName(className);
|
|
120
|
+
// Validate token format
|
|
121
|
+
if (!configToken || typeof configToken !== 'string') {
|
|
122
|
+
throw new Error(`@ProviderConfig: Invalid token for class "${className}". Token must be a non-empty string.`);
|
|
123
|
+
}
|
|
124
|
+
// Ensure token is uppercase (convention)
|
|
125
|
+
if (configToken !== configToken.toUpperCase()) {
|
|
126
|
+
throw new Error(`@ProviderConfig: Token "${configToken}" for class "${className}" must be UPPERCASE. ` +
|
|
127
|
+
`Use "${configToken.toUpperCase()}" instead.`);
|
|
128
|
+
}
|
|
129
|
+
// Store metadata
|
|
130
|
+
const metadata = {
|
|
131
|
+
token: configToken,
|
|
132
|
+
};
|
|
133
|
+
Reflect.defineMetadata(constants_1.CONFIG_PROVIDER_METADATA, metadata, target);
|
|
134
|
+
// Note: Registration with the Registry will happen during auto-discovery (Step 3)
|
|
135
|
+
// For now, we just store the metadata
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Helper to retrieve config provider metadata from a class
|
|
140
|
+
*
|
|
141
|
+
* @param target - The class to retrieve metadata from
|
|
142
|
+
* @returns The config provider metadata or undefined
|
|
143
|
+
*/
|
|
144
|
+
function getConfigProviderMetadata(target) {
|
|
145
|
+
return Reflect.getMetadata(constants_1.CONFIG_PROVIDER_METADATA, target);
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Check if a class has @ProviderConfig decorator
|
|
149
|
+
*
|
|
150
|
+
* @param target - The class to check
|
|
151
|
+
* @returns True if the class is decorated with @ProviderConfig
|
|
152
|
+
*/
|
|
153
|
+
function isConfigProvider(target) {
|
|
154
|
+
return Reflect.hasMetadata(constants_1.CONFIG_PROVIDER_METADATA, target);
|
|
155
|
+
}
|
|
156
|
+
//# sourceMappingURL=provider-config.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider-config.decorator.js","sourceRoot":"","sources":["../../../src/core/decorators/provider-config.decorator.ts"],"names":[],"mappings":";;AA8HA,wCAgCC;AAQD,8DAIC;AAQD,4CAEC;A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QACjB,MAAM,QAAQ,GAA2B;YACvC,KAAK,EAAE,WAAqB;SAC7B,CAAC;QAEF,OAAO,CAAC,cAAc,CAAC,oCAAwB,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;QAEnE,kFAAkF;QAClF,sCAAsC;IACxC,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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"discovery.d.ts","sourceRoot":"","sources":["../../src/core/discovery.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"discovery.d.ts","sourceRoot":"","sources":["../../src/core/discovery.ts"],"names":[],"mappings":"AAsEA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAsB,eAAe,CACnC,QAAQ,GAAE,MAAM,EAAuB,EACvC,GAAG,CAAC,EAAE,MAAM,GACX,OAAO,CAAC,MAAM,EAAE,CAAC,CAqEnB;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,CAE3C"}
|
package/dist/core/discovery.js
CHANGED
|
@@ -83,10 +83,12 @@ 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
|
+
/@ProviderConfig\s*\(/, // @ProviderConfig(TOKEN)
|
|
86
87
|
// Compiled JavaScript patterns (e.g., (0, core_1.Controller)('/path'))
|
|
87
88
|
/\.\s*Controller\s*\)\s*\(/,
|
|
88
89
|
/\.\s*Injectable\s*\)\s*\(/,
|
|
89
90
|
/\.\s*Provider\s*\)\s*\(/,
|
|
91
|
+
/\.\s*ProviderConfig\s*\)\s*\(/,
|
|
90
92
|
];
|
|
91
93
|
/**
|
|
92
94
|
* Check if a file contains Rikta decorators (@Controller, @Injectable, or @Provider)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"discovery.js","sourceRoot":"","sources":["../../src/core/discovery.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
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,E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AO,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"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Exception thrown when attempting to register a config provider with a token
|
|
3
|
+
* that is already registered.
|
|
4
|
+
*/
|
|
5
|
+
export declare class ConfigProviderAlreadyRegisteredException extends Error {
|
|
6
|
+
constructor(token: string, existingClass: string, newClass: string);
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Exception thrown when attempting to retrieve a config provider that
|
|
10
|
+
* has not been registered.
|
|
11
|
+
*/
|
|
12
|
+
export declare class ConfigProviderNotFoundException extends Error {
|
|
13
|
+
constructor(token: string, availableTokens?: string[]);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Exception thrown when a config provider fails to instantiate.
|
|
17
|
+
*/
|
|
18
|
+
export declare class ConfigProviderInstantiationException extends Error {
|
|
19
|
+
constructor(token: string, className: string, cause: Error);
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=config.exceptions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.exceptions.d.ts","sourceRoot":"","sources":["../../../src/core/exceptions/config.exceptions.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,qBAAa,wCAAyC,SAAQ,KAAK;gBACrD,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;CASnE;AAED;;;GAGG;AACH,qBAAa,+BAAgC,SAAQ,KAAK;gBAC5C,KAAK,EAAE,MAAM,EAAE,eAAe,GAAE,MAAM,EAAO;CAc1D;AAED;;GAEG;AACH,qBAAa,oCAAqC,SAAQ,KAAK;gBACjD,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK;CAY3D"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConfigProviderInstantiationException = exports.ConfigProviderNotFoundException = exports.ConfigProviderAlreadyRegisteredException = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Exception thrown when attempting to register a config provider with a token
|
|
6
|
+
* that is already registered.
|
|
7
|
+
*/
|
|
8
|
+
class ConfigProviderAlreadyRegisteredException extends Error {
|
|
9
|
+
constructor(token, existingClass, newClass) {
|
|
10
|
+
super(`Config provider with token "${token}" is already registered.\n` +
|
|
11
|
+
`Existing: ${existingClass}\n` +
|
|
12
|
+
`Attempted: ${newClass}\n` +
|
|
13
|
+
`Use a different token or remove the duplicate registration.`);
|
|
14
|
+
this.name = 'ConfigProviderAlreadyRegisteredException';
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.ConfigProviderAlreadyRegisteredException = ConfigProviderAlreadyRegisteredException;
|
|
18
|
+
/**
|
|
19
|
+
* Exception thrown when attempting to retrieve a config provider that
|
|
20
|
+
* has not been registered.
|
|
21
|
+
*/
|
|
22
|
+
class ConfigProviderNotFoundException extends Error {
|
|
23
|
+
constructor(token, availableTokens = []) {
|
|
24
|
+
const suggestion = availableTokens.length > 0
|
|
25
|
+
? `\n\nAvailable tokens: ${availableTokens.join(', ')}`
|
|
26
|
+
: '';
|
|
27
|
+
super(`Config provider with token "${token}" not found.${suggestion}\n` +
|
|
28
|
+
`Make sure the provider class is:\n` +
|
|
29
|
+
`1. Decorated with @ProviderConfig('${token}')\n` +
|
|
30
|
+
`2. Located in a file matching the autowired patterns\n` +
|
|
31
|
+
`3. Properly exported from its module`);
|
|
32
|
+
this.name = 'ConfigProviderNotFoundException';
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.ConfigProviderNotFoundException = ConfigProviderNotFoundException;
|
|
36
|
+
/**
|
|
37
|
+
* Exception thrown when a config provider fails to instantiate.
|
|
38
|
+
*/
|
|
39
|
+
class ConfigProviderInstantiationException extends Error {
|
|
40
|
+
constructor(token, className, cause) {
|
|
41
|
+
super(`Failed to instantiate config provider "${className}" (token: "${token}").\n` +
|
|
42
|
+
`Cause: ${cause.message}\n\n` +
|
|
43
|
+
`Check that the provider:\n` +
|
|
44
|
+
`1. Has a valid constructor\n` +
|
|
45
|
+
`2. All constructor dependencies are registered\n` +
|
|
46
|
+
`3. The provide() method is correctly implemented`);
|
|
47
|
+
this.name = 'ConfigProviderInstantiationException';
|
|
48
|
+
this.cause = cause;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.ConfigProviderInstantiationException = ConfigProviderInstantiationException;
|
|
52
|
+
//# sourceMappingURL=config.exceptions.js.map
|
|
@@ -0,0 +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,sCAAsC,KAAK,MAAM;YACjD,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"}
|
|
@@ -3,4 +3,5 @@ export { ValidationException, ValidationErrorDetails } from './validation.except
|
|
|
3
3
|
export { BadRequestException, UnauthorizedException, ForbiddenException, NotFoundException, MethodNotAllowedException, NotAcceptableException, RequestTimeoutException, ConflictException, GoneException, PayloadTooLargeException, UnsupportedMediaTypeException, UnprocessableEntityException, TooManyRequestsException, InternalServerErrorException, NotImplementedException, BadGatewayException, ServiceUnavailableException, GatewayTimeoutException, } from './exceptions';
|
|
4
4
|
export { ExceptionFilter, ExceptionContext, ErrorResponse, GlobalExceptionFilter, GlobalExceptionFilterOptions, createExceptionHandler, } from './exception-filter';
|
|
5
5
|
export { Catch, CatchMetadata, CATCH_METADATA, getCatchMetadata } from './catch.decorator';
|
|
6
|
+
export { ConfigProviderAlreadyRegisteredException, ConfigProviderNotFoundException, ConfigProviderInstantiationException, } from './config.exceptions';
|
|
6
7
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/exceptions/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAG3F,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAGrF,OAAO,EAEL,mBAAmB,EACnB,qBAAqB,EACrB,kBAAkB,EAClB,iBAAiB,EACjB,yBAAyB,EACzB,sBAAsB,EACtB,uBAAuB,EACvB,iBAAiB,EACjB,aAAa,EACb,wBAAwB,EACxB,6BAA6B,EAC7B,4BAA4B,EAC5B,wBAAwB,EAExB,4BAA4B,EAC5B,uBAAuB,EACvB,mBAAmB,EACnB,2BAA2B,EAC3B,uBAAuB,GACxB,MAAM,cAAc,CAAC;AAGtB,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,qBAAqB,EACrB,4BAA4B,EAC5B,sBAAsB,GACvB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/exceptions/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAG3F,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAGrF,OAAO,EAEL,mBAAmB,EACnB,qBAAqB,EACrB,kBAAkB,EAClB,iBAAiB,EACjB,yBAAyB,EACzB,sBAAsB,EACtB,uBAAuB,EACvB,iBAAiB,EACjB,aAAa,EACb,wBAAwB,EACxB,6BAA6B,EAC7B,4BAA4B,EAC5B,wBAAwB,EAExB,4BAA4B,EAC5B,uBAAuB,EACvB,mBAAmB,EACnB,2BAA2B,EAC3B,uBAAuB,GACxB,MAAM,cAAc,CAAC;AAGtB,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,qBAAqB,EACrB,4BAA4B,EAC5B,sBAAsB,GACvB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAG3F,OAAO,EACL,wCAAwC,EACxC,+BAA+B,EAC/B,oCAAoC,GACrC,MAAM,qBAAqB,CAAC"}
|