@riktajs/core 0.10.1 → 0.10.3
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/index.cjs +3591 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +770 -0
- package/dist/index.d.ts +770 -2
- package/dist/index.js +3415 -2
- package/dist/index.js.map +1 -0
- package/package.json +63 -56
- package/dist/core/application.d.ts +0 -6
- package/dist/core/application.js +0 -248
- package/dist/core/config/abstract-config-provider.d.ts +0 -14
- package/dist/core/config/abstract-config-provider.js +0 -53
- package/dist/core/config/env-loader.d.ts +0 -3
- package/dist/core/config/env-loader.js +0 -26
- package/dist/core/config/index.d.ts +0 -2
- package/dist/core/config/index.js +0 -2
- package/dist/core/constants.d.ts +0 -30
- package/dist/core/constants.js +0 -31
- package/dist/core/container/abstract-class.utils.d.ts +0 -10
- package/dist/core/container/abstract-class.utils.js +0 -44
- package/dist/core/container/container.d.ts +0 -32
- package/dist/core/container/container.js +0 -292
- package/dist/core/container/implements.decorator.d.ts +0 -6
- package/dist/core/container/implements.decorator.js +0 -39
- package/dist/core/container/index.d.ts +0 -5
- package/dist/core/container/index.js +0 -5
- package/dist/core/container/injection-token.d.ts +0 -29
- package/dist/core/container/injection-token.js +0 -11
- package/dist/core/container/request-scope.d.ts +0 -16
- package/dist/core/container/request-scope.js +0 -49
- package/dist/core/decorators/apply-decorators.d.ts +0 -8
- package/dist/core/decorators/apply-decorators.js +0 -36
- package/dist/core/decorators/autowired.decorator.d.ts +0 -11
- package/dist/core/decorators/autowired.decorator.js +0 -78
- package/dist/core/decorators/config-property.decorator.d.ts +0 -9
- package/dist/core/decorators/config-property.decorator.js +0 -59
- package/dist/core/decorators/controller.decorator.d.ts +0 -5
- package/dist/core/decorators/controller.decorator.js +0 -18
- package/dist/core/decorators/create-param-decorator.d.ts +0 -11
- package/dist/core/decorators/create-param-decorator.js +0 -21
- package/dist/core/decorators/index.d.ts +0 -9
- package/dist/core/decorators/index.js +0 -9
- package/dist/core/decorators/injectable.decorator.d.ts +0 -3
- package/dist/core/decorators/injectable.decorator.js +0 -11
- package/dist/core/decorators/param.decorator.d.ts +0 -59
- package/dist/core/decorators/param.decorator.js +0 -38
- package/dist/core/decorators/provider.decorator.d.ts +0 -12
- package/dist/core/decorators/provider.decorator.js +0 -56
- package/dist/core/decorators/route.decorator.d.ts +0 -9
- package/dist/core/decorators/route.decorator.js +0 -30
- package/dist/core/discovery.d.ts +0 -3
- package/dist/core/discovery.js +0 -111
- package/dist/core/exceptions/catch.decorator.d.ts +0 -8
- package/dist/core/exceptions/catch.decorator.js +0 -13
- package/dist/core/exceptions/config.exceptions.d.ts +0 -9
- package/dist/core/exceptions/config.exceptions.js +0 -34
- package/dist/core/exceptions/discovery.exception.d.ts +0 -18
- package/dist/core/exceptions/discovery.exception.js +0 -39
- package/dist/core/exceptions/exception-filter.d.ts +0 -38
- package/dist/core/exceptions/exception-filter.js +0 -103
- package/dist/core/exceptions/exceptions.d.ts +0 -55
- package/dist/core/exceptions/exceptions.js +0 -91
- package/dist/core/exceptions/http-exception.d.ts +0 -24
- package/dist/core/exceptions/http-exception.js +0 -62
- package/dist/core/exceptions/index.d.ts +0 -7
- package/dist/core/exceptions/index.js +0 -7
- package/dist/core/exceptions/validation.exception.d.ts +0 -17
- package/dist/core/exceptions/validation.exception.js +0 -33
- package/dist/core/guards/can-activate.interface.d.ts +0 -4
- package/dist/core/guards/can-activate.interface.js +0 -1
- package/dist/core/guards/execution-context.d.ts +0 -28
- package/dist/core/guards/execution-context.js +0 -35
- package/dist/core/guards/index.d.ts +0 -3
- package/dist/core/guards/index.js +0 -2
- package/dist/core/guards/use-guards.decorator.d.ts +0 -6
- package/dist/core/guards/use-guards.decorator.js +0 -22
- package/dist/core/index.d.ts +0 -19
- package/dist/core/index.js +0 -17
- package/dist/core/interceptors/index.d.ts +0 -2
- package/dist/core/interceptors/index.js +0 -1
- package/dist/core/interceptors/interceptor.interface.d.ts +0 -7
- package/dist/core/interceptors/interceptor.interface.js +0 -1
- package/dist/core/interceptors/use-interceptors.decorator.d.ts +0 -6
- package/dist/core/interceptors/use-interceptors.decorator.js +0 -19
- package/dist/core/lifecycle/event-bus.d.ts +0 -57
- package/dist/core/lifecycle/event-bus.js +0 -108
- package/dist/core/lifecycle/index.d.ts +0 -3
- package/dist/core/lifecycle/index.js +0 -3
- package/dist/core/lifecycle/interfaces.d.ts +0 -15
- package/dist/core/lifecycle/interfaces.js +0 -1
- package/dist/core/lifecycle/on.decorator.d.ts +0 -11
- package/dist/core/lifecycle/on.decorator.js +0 -13
- package/dist/core/metadata.d.ts +0 -20
- package/dist/core/metadata.js +0 -64
- package/dist/core/middleware/index.d.ts +0 -3
- package/dist/core/middleware/index.js +0 -2
- package/dist/core/middleware/middleware.decorator.d.ts +0 -2
- package/dist/core/middleware/middleware.decorator.js +0 -7
- package/dist/core/middleware/rikta-middleware.interface.d.ts +0 -5
- package/dist/core/middleware/rikta-middleware.interface.js +0 -1
- package/dist/core/middleware/use-middleware.decorator.d.ts +0 -6
- package/dist/core/middleware/use-middleware.decorator.js +0 -22
- package/dist/core/profiler/index.d.ts +0 -2
- package/dist/core/profiler/index.js +0 -1
- package/dist/core/profiler/performance-profiler.d.ts +0 -42
- package/dist/core/profiler/performance-profiler.js +0 -95
- package/dist/core/registry.d.ts +0 -41
- package/dist/core/registry.js +0 -109
- package/dist/core/router/router.d.ts +0 -32
- package/dist/core/router/router.js +0 -300
- package/dist/core/types.d.ts +0 -62
- package/dist/core/types.js +0 -1
package/package.json
CHANGED
|
@@ -1,56 +1,63 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@riktajs/core",
|
|
3
|
-
"version": "0.10.
|
|
4
|
-
"description": "A fast and modern TypeScript backend framework with zero-config autowiring, powered by Fastify",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"main": "dist/index.
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
"
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
"
|
|
55
|
-
|
|
56
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@riktajs/core",
|
|
3
|
+
"version": "0.10.3",
|
|
4
|
+
"description": "A fast and modern TypeScript backend framework with zero-config autowiring, powered by Fastify",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.cjs",
|
|
7
|
+
"module": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"require": {
|
|
16
|
+
"types": "./dist/index.d.cts",
|
|
17
|
+
"default": "./dist/index.cjs"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
24
|
+
"scripts": {
|
|
25
|
+
"clean": "rm -rf dist",
|
|
26
|
+
"prebuild": "npm run clean",
|
|
27
|
+
"build": "tsup",
|
|
28
|
+
"dev": "ts-node-dev --respawn src/index.ts",
|
|
29
|
+
"test": "vitest run",
|
|
30
|
+
"test:watch": "vitest",
|
|
31
|
+
"test:coverage": "vitest run --coverage",
|
|
32
|
+
"prepublishOnly": "npm run build"
|
|
33
|
+
},
|
|
34
|
+
"keywords": [
|
|
35
|
+
"framework",
|
|
36
|
+
"backend",
|
|
37
|
+
"typescript",
|
|
38
|
+
"fastify",
|
|
39
|
+
"decorators",
|
|
40
|
+
"dependency-injection",
|
|
41
|
+
"nestjs-like"
|
|
42
|
+
],
|
|
43
|
+
"author": "riktar",
|
|
44
|
+
"license": "MIT",
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"dotenv": "^17.2.3",
|
|
47
|
+
"fast-glob": "3.3.3",
|
|
48
|
+
"fastify": "5.3.2",
|
|
49
|
+
"reflect-metadata": "0.2.2",
|
|
50
|
+
"zod": "4.3.5"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@types/node": "^22.10.2",
|
|
54
|
+
"@vitest/coverage-v8": "^2.1.9",
|
|
55
|
+
"ts-node": "^10.9.2",
|
|
56
|
+
"ts-node-dev": "^2.0.0",
|
|
57
|
+
"typescript": "^5.7.2",
|
|
58
|
+
"vitest": "^2.1.8"
|
|
59
|
+
},
|
|
60
|
+
"engines": {
|
|
61
|
+
"node": ">=20.0.0"
|
|
62
|
+
}
|
|
63
|
+
}
|
package/dist/core/application.js
DELETED
|
@@ -1,248 +0,0 @@
|
|
|
1
|
-
import 'reflect-metadata';
|
|
2
|
-
import Fastify from 'fastify';
|
|
3
|
-
import { Container } from './container/container.js';
|
|
4
|
-
import { Router } from './router/router.js';
|
|
5
|
-
import { registry } from './registry.js';
|
|
6
|
-
import { discoverModules, getCallerDirectory } from './discovery.js';
|
|
7
|
-
import { EventBus } from './lifecycle/event-bus.js';
|
|
8
|
-
import { ON_EVENT_METADATA } from './lifecycle/on.decorator.js';
|
|
9
|
-
import { DEFAULT_CONFIG, PROVIDER_METADATA, INJECTABLE_METADATA } from './constants.js';
|
|
10
|
-
import { GlobalExceptionFilter, createExceptionHandler, getCatchMetadata } from './exceptions/index.js';
|
|
11
|
-
import { loadEnvFiles } from './config/env-loader.js';
|
|
12
|
-
export class RiktaFactory {
|
|
13
|
-
static async create(config = {}) {
|
|
14
|
-
loadEnvFiles();
|
|
15
|
-
const silent = config.silent ?? false;
|
|
16
|
-
if (!silent)
|
|
17
|
-
console.log('\n🚀 Rikta Framework Starting...\n');
|
|
18
|
-
const callerDir = getCallerDirectory();
|
|
19
|
-
let discoveredFiles = [];
|
|
20
|
-
if (!config.controllers && config.autowired !== false) {
|
|
21
|
-
const patterns = Array.isArray(config.autowired) && config.autowired.length > 0
|
|
22
|
-
? config.autowired
|
|
23
|
-
: ['./**'];
|
|
24
|
-
discoveredFiles = await discoverModules({
|
|
25
|
-
patterns,
|
|
26
|
-
cwd: callerDir,
|
|
27
|
-
strict: config.strictDiscovery ?? false,
|
|
28
|
-
onImportError: config.onDiscoveryError,
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
const app = new RiktaApplicationImpl(config);
|
|
32
|
-
await app.init(discoveredFiles);
|
|
33
|
-
return app;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
class RiktaApplicationImpl {
|
|
37
|
-
server;
|
|
38
|
-
container;
|
|
39
|
-
config;
|
|
40
|
-
router;
|
|
41
|
-
events;
|
|
42
|
-
initializedProviders = [];
|
|
43
|
-
customExceptionFilters = new Map();
|
|
44
|
-
startTime = Date.now();
|
|
45
|
-
isListening = false;
|
|
46
|
-
address = '';
|
|
47
|
-
constructor(config) {
|
|
48
|
-
const silent = config.silent ?? false;
|
|
49
|
-
this.config = {
|
|
50
|
-
port: config.port ?? DEFAULT_CONFIG.port,
|
|
51
|
-
host: config.host ?? DEFAULT_CONFIG.host,
|
|
52
|
-
logger: config.logger ?? (silent ? false : DEFAULT_CONFIG.logger),
|
|
53
|
-
prefix: config.prefix ?? DEFAULT_CONFIG.prefix,
|
|
54
|
-
silent: silent,
|
|
55
|
-
controllers: config.controllers,
|
|
56
|
-
providers: config.providers,
|
|
57
|
-
exceptionFilter: config.exceptionFilter,
|
|
58
|
-
exceptionFilters: config.exceptionFilters,
|
|
59
|
-
};
|
|
60
|
-
this.server = Fastify({ logger: this.config.logger });
|
|
61
|
-
this.container = Container.getInstance();
|
|
62
|
-
this.router = new Router(this.server, this.container, this.config.prefix);
|
|
63
|
-
this.events = new EventBus();
|
|
64
|
-
this.container.registerInstance(EventBus, this.events);
|
|
65
|
-
this.setupExceptionHandler();
|
|
66
|
-
}
|
|
67
|
-
setupExceptionHandler() {
|
|
68
|
-
const silent = this.config.silent ?? false;
|
|
69
|
-
const globalFilter = new GlobalExceptionFilter({
|
|
70
|
-
includeStack: this.config.exceptionFilter?.includeStack,
|
|
71
|
-
logErrors: this.config.exceptionFilter?.logErrors ?? (silent ? false : true),
|
|
72
|
-
});
|
|
73
|
-
const customFilters = this.config.exceptionFilters ?? [];
|
|
74
|
-
for (const FilterClass of customFilters) {
|
|
75
|
-
const metadata = getCatchMetadata(FilterClass);
|
|
76
|
-
const filterInstance = this.container.resolve(FilterClass);
|
|
77
|
-
if (metadata && metadata.exceptions.length > 0) {
|
|
78
|
-
for (const ExceptionType of metadata.exceptions) {
|
|
79
|
-
this.customExceptionFilters.set(ExceptionType, filterInstance);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
this.customExceptionFilters.set(Error, filterInstance);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
this.server.setErrorHandler(createExceptionHandler(globalFilter, this.customExceptionFilters));
|
|
87
|
-
}
|
|
88
|
-
async init(discoveredFiles = []) {
|
|
89
|
-
await this.events.emit('app:discovery', { files: discoveredFiles });
|
|
90
|
-
await this.processConfigProviders();
|
|
91
|
-
await this.processCustomProviders();
|
|
92
|
-
await this.events.emit('app:providers', {
|
|
93
|
-
count: registry.getCustomProviders().length
|
|
94
|
-
});
|
|
95
|
-
const providers = this.getSortedProviders();
|
|
96
|
-
const additionalProviders = this.config.providers ?? [];
|
|
97
|
-
for (const provider of additionalProviders) {
|
|
98
|
-
this.registerProvider(provider);
|
|
99
|
-
}
|
|
100
|
-
for (const { target, priority } of providers) {
|
|
101
|
-
await this.initializeProvider(target, priority);
|
|
102
|
-
}
|
|
103
|
-
const controllers = this.config.controllers ?? registry.getControllers();
|
|
104
|
-
if (!this.config.silent)
|
|
105
|
-
console.log('📡 Registering routes:');
|
|
106
|
-
for (const controller of controllers) {
|
|
107
|
-
this.router.registerController(controller, this.config.silent);
|
|
108
|
-
}
|
|
109
|
-
await this.events.emit('app:routes', { count: controllers.length });
|
|
110
|
-
await this.callHook('onApplicationBootstrap');
|
|
111
|
-
await this.events.emit('app:bootstrap', {
|
|
112
|
-
providerCount: this.initializedProviders.length
|
|
113
|
-
});
|
|
114
|
-
if (!this.config.silent)
|
|
115
|
-
console.log('\n✅ Rikta is ready\n');
|
|
116
|
-
}
|
|
117
|
-
async processConfigProviders() {
|
|
118
|
-
const configProviders = registry.getConfigProviderRegistrations();
|
|
119
|
-
if (configProviders.length === 0)
|
|
120
|
-
return;
|
|
121
|
-
for (const { token, providerClass } of configProviders) {
|
|
122
|
-
this.container.registerProvider({
|
|
123
|
-
provide: token,
|
|
124
|
-
useClass: providerClass,
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
async processCustomProviders() {
|
|
129
|
-
const customProviders = registry.getCustomProviders();
|
|
130
|
-
if (customProviders.length === 0)
|
|
131
|
-
return;
|
|
132
|
-
for (const ProviderClass of customProviders) {
|
|
133
|
-
const metadata = Reflect.getMetadata(PROVIDER_METADATA, ProviderClass);
|
|
134
|
-
if (!metadata)
|
|
135
|
-
continue;
|
|
136
|
-
const providerInstance = this.container.resolve(ProviderClass);
|
|
137
|
-
const value = await providerInstance.provide();
|
|
138
|
-
this.container.registerValue(metadata.token, value);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
getSortedProviders() {
|
|
142
|
-
const providers = registry.getProviders();
|
|
143
|
-
return providers
|
|
144
|
-
.map(target => ({
|
|
145
|
-
target,
|
|
146
|
-
priority: this.getProviderPriority(target),
|
|
147
|
-
}))
|
|
148
|
-
.sort((a, b) => b.priority - a.priority);
|
|
149
|
-
}
|
|
150
|
-
getProviderPriority(target) {
|
|
151
|
-
const options = Reflect.getMetadata(INJECTABLE_METADATA, target);
|
|
152
|
-
return options?.priority ?? 0;
|
|
153
|
-
}
|
|
154
|
-
async initializeProvider(target, priority) {
|
|
155
|
-
const instance = this.container.resolve(target);
|
|
156
|
-
const name = target.name;
|
|
157
|
-
this.initializedProviders.push({ instance, priority, name });
|
|
158
|
-
if (this.hasHook(instance, 'onProviderInit')) {
|
|
159
|
-
await instance.onProviderInit();
|
|
160
|
-
}
|
|
161
|
-
await this.events.emit('provider:init', { provider: target, name, priority });
|
|
162
|
-
this.registerEventListeners(target, instance);
|
|
163
|
-
}
|
|
164
|
-
registerEventListeners(target, instance) {
|
|
165
|
-
const metadata = Reflect.getMetadata(ON_EVENT_METADATA, target) ?? [];
|
|
166
|
-
for (const { event, methodName } of metadata) {
|
|
167
|
-
const method = instance[methodName];
|
|
168
|
-
if (typeof method === 'function') {
|
|
169
|
-
this.events.on(event, method.bind(instance), target.name);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
registerProvider(provider) {
|
|
174
|
-
const instance = this.container.resolve(provider);
|
|
175
|
-
const priority = this.getProviderPriority(provider);
|
|
176
|
-
this.initializedProviders.push({ instance, priority, name: provider.name });
|
|
177
|
-
}
|
|
178
|
-
async callHook(hookName) {
|
|
179
|
-
for (const { instance } of this.initializedProviders) {
|
|
180
|
-
if (this.hasHook(instance, hookName)) {
|
|
181
|
-
await instance[hookName]();
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
hasHook(instance, hookName) {
|
|
186
|
-
return (instance !== null &&
|
|
187
|
-
typeof instance === 'object' &&
|
|
188
|
-
hookName in instance &&
|
|
189
|
-
typeof instance[hookName] === 'function');
|
|
190
|
-
}
|
|
191
|
-
async listen() {
|
|
192
|
-
if (this.isListening) {
|
|
193
|
-
return this.address;
|
|
194
|
-
}
|
|
195
|
-
this.address = await this.server.listen({
|
|
196
|
-
port: this.config.port,
|
|
197
|
-
host: this.config.host,
|
|
198
|
-
});
|
|
199
|
-
this.isListening = true;
|
|
200
|
-
for (const { instance } of this.initializedProviders) {
|
|
201
|
-
if (this.hasHook(instance, 'onApplicationListen')) {
|
|
202
|
-
await instance.onApplicationListen(this.address);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
await this.events.emit('app:listen', {
|
|
206
|
-
address: this.address,
|
|
207
|
-
port: this.config.port
|
|
208
|
-
});
|
|
209
|
-
return this.address;
|
|
210
|
-
}
|
|
211
|
-
async close(signal) {
|
|
212
|
-
await this.events.emit('app:shutdown', { signal });
|
|
213
|
-
const reversed = [...this.initializedProviders].reverse();
|
|
214
|
-
for (const { instance, name } of reversed) {
|
|
215
|
-
if (this.hasHook(instance, 'onApplicationShutdown')) {
|
|
216
|
-
await instance.onApplicationShutdown(signal);
|
|
217
|
-
}
|
|
218
|
-
if (this.hasHook(instance, 'onProviderDestroy')) {
|
|
219
|
-
await instance.onProviderDestroy();
|
|
220
|
-
}
|
|
221
|
-
this.events.removeByOwner(name);
|
|
222
|
-
}
|
|
223
|
-
await this.server.close();
|
|
224
|
-
this.isListening = false;
|
|
225
|
-
await this.events.emit('app:destroy', {
|
|
226
|
-
uptime: Date.now() - this.startTime
|
|
227
|
-
});
|
|
228
|
-
this.events.clear();
|
|
229
|
-
if (!this.config.silent)
|
|
230
|
-
console.log('\n👋 Application closed\n');
|
|
231
|
-
}
|
|
232
|
-
getUrl() {
|
|
233
|
-
return this.address;
|
|
234
|
-
}
|
|
235
|
-
getEventBus() {
|
|
236
|
-
return this.events;
|
|
237
|
-
}
|
|
238
|
-
getContainer() {
|
|
239
|
-
return this.container;
|
|
240
|
-
}
|
|
241
|
-
getRouter() {
|
|
242
|
-
return this.router;
|
|
243
|
-
}
|
|
244
|
-
clearRouterCaches() {
|
|
245
|
-
this.router.clearAllCaches();
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
export { RiktaFactory as Rikta };
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { z, ZodSchema } from 'zod';
|
|
2
|
-
export declare class ConfigValidationException extends Error {
|
|
3
|
-
readonly errors: z.ZodError;
|
|
4
|
-
constructor(errors: z.ZodError, providerName: string);
|
|
5
|
-
}
|
|
6
|
-
export declare abstract class AbstractConfigProvider {
|
|
7
|
-
private _cache?;
|
|
8
|
-
protected abstract schema(): ZodSchema;
|
|
9
|
-
constructor();
|
|
10
|
-
private validateAndCache;
|
|
11
|
-
protected populate(): void;
|
|
12
|
-
protected getConfig(): Readonly<Record<string, unknown>>;
|
|
13
|
-
protected get<T = unknown>(key: string): T | undefined;
|
|
14
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { getConfigPropertyMappings } from '../decorators/config-property.decorator.js';
|
|
3
|
-
import { loadEnvFiles } from './env-loader.js';
|
|
4
|
-
export class ConfigValidationException extends Error {
|
|
5
|
-
errors;
|
|
6
|
-
constructor(errors, providerName) {
|
|
7
|
-
const errorMessages = errors.issues
|
|
8
|
-
.map(err => ` - ${err.path.join('.')}: ${err.message}`)
|
|
9
|
-
.join('\n');
|
|
10
|
-
super(`Configuration validation failed for ${providerName}:\n${errorMessages}\n\n` +
|
|
11
|
-
`Please check your .env file and ensure all required variables are set correctly.`);
|
|
12
|
-
this.errors = errors;
|
|
13
|
-
this.name = 'ConfigValidationException';
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
export class AbstractConfigProvider {
|
|
17
|
-
_cache;
|
|
18
|
-
constructor() {
|
|
19
|
-
loadEnvFiles();
|
|
20
|
-
}
|
|
21
|
-
validateAndCache() {
|
|
22
|
-
if (this._cache) {
|
|
23
|
-
return this._cache;
|
|
24
|
-
}
|
|
25
|
-
try {
|
|
26
|
-
const schema = this.schema();
|
|
27
|
-
const validated = schema.parse(process.env);
|
|
28
|
-
this._cache = Object.freeze(validated);
|
|
29
|
-
return this._cache;
|
|
30
|
-
}
|
|
31
|
-
catch (error) {
|
|
32
|
-
if (error instanceof z.ZodError) {
|
|
33
|
-
throw new ConfigValidationException(error, this.constructor.name);
|
|
34
|
-
}
|
|
35
|
-
throw error;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
populate() {
|
|
39
|
-
const config = this.validateAndCache();
|
|
40
|
-
const mappings = getConfigPropertyMappings(this.constructor);
|
|
41
|
-
for (const mapping of mappings) {
|
|
42
|
-
const value = config[mapping.envKey];
|
|
43
|
-
this[mapping.propertyKey] = value;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
getConfig() {
|
|
47
|
-
return this.validateAndCache();
|
|
48
|
-
}
|
|
49
|
-
get(key) {
|
|
50
|
-
const config = this.validateAndCache();
|
|
51
|
-
return config[key];
|
|
52
|
-
}
|
|
53
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { config as loadEnv } from 'dotenv';
|
|
2
|
-
import { existsSync } from 'fs';
|
|
3
|
-
import { resolve } from 'path';
|
|
4
|
-
let envLoaded = false;
|
|
5
|
-
export function loadEnvFiles() {
|
|
6
|
-
if (envLoaded) {
|
|
7
|
-
return;
|
|
8
|
-
}
|
|
9
|
-
const env = process.env.NODE_ENV || 'development';
|
|
10
|
-
const cwd = process.cwd();
|
|
11
|
-
const baseEnvPath = resolve(cwd, '.env');
|
|
12
|
-
if (existsSync(baseEnvPath)) {
|
|
13
|
-
loadEnv({ path: baseEnvPath, override: false });
|
|
14
|
-
}
|
|
15
|
-
const envSpecificPath = resolve(cwd, `.env.${env}`);
|
|
16
|
-
if (existsSync(envSpecificPath)) {
|
|
17
|
-
loadEnv({ path: envSpecificPath, override: true });
|
|
18
|
-
}
|
|
19
|
-
envLoaded = true;
|
|
20
|
-
}
|
|
21
|
-
export function isEnvLoaded() {
|
|
22
|
-
return envLoaded;
|
|
23
|
-
}
|
|
24
|
-
export function resetEnvLoaded() {
|
|
25
|
-
envLoaded = false;
|
|
26
|
-
}
|
package/dist/core/constants.d.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
export declare const CONTROLLER_METADATA: unique symbol;
|
|
2
|
-
export declare const ROUTES_METADATA: unique symbol;
|
|
3
|
-
export declare const INJECTABLE_METADATA: unique symbol;
|
|
4
|
-
export declare const PARAM_METADATA: unique symbol;
|
|
5
|
-
export declare const GUARDS_METADATA: unique symbol;
|
|
6
|
-
export declare const INTERCEPTORS_METADATA: unique symbol;
|
|
7
|
-
export declare const MIDDLEWARE_METADATA: unique symbol;
|
|
8
|
-
export declare const HTTP_CODE_METADATA: unique symbol;
|
|
9
|
-
export declare const HEADERS_METADATA: unique symbol;
|
|
10
|
-
export declare const INJECT_METADATA: unique symbol;
|
|
11
|
-
export declare const ZOD_SCHEMA_METADATA: unique symbol;
|
|
12
|
-
export declare const AUTOWIRED_METADATA: unique symbol;
|
|
13
|
-
export declare const PROVIDER_METADATA: unique symbol;
|
|
14
|
-
export declare const CONFIG_PROVIDER_METADATA: unique symbol;
|
|
15
|
-
export declare const CONFIG_PROPERTY_METADATA: unique symbol;
|
|
16
|
-
export declare enum ParamType {
|
|
17
|
-
BODY = "body",
|
|
18
|
-
QUERY = "query",
|
|
19
|
-
PARAM = "param",
|
|
20
|
-
HEADERS = "headers",
|
|
21
|
-
REQUEST = "request",
|
|
22
|
-
REPLY = "reply",
|
|
23
|
-
CONTEXT = "context"
|
|
24
|
-
}
|
|
25
|
-
export declare const DEFAULT_CONFIG: {
|
|
26
|
-
readonly port: 3000;
|
|
27
|
-
readonly host: "0.0.0.0";
|
|
28
|
-
readonly logger: true;
|
|
29
|
-
readonly prefix: "";
|
|
30
|
-
};
|
package/dist/core/constants.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
export const CONTROLLER_METADATA = Symbol.for('rikta:controller:metadata');
|
|
2
|
-
export const ROUTES_METADATA = Symbol.for('rikta:routes:metadata');
|
|
3
|
-
export const INJECTABLE_METADATA = Symbol.for('rikta:injectable:metadata');
|
|
4
|
-
export const PARAM_METADATA = Symbol.for('rikta:param:metadata');
|
|
5
|
-
export const GUARDS_METADATA = Symbol.for('rikta:guards:metadata');
|
|
6
|
-
export const INTERCEPTORS_METADATA = Symbol.for('rikta:interceptors:metadata');
|
|
7
|
-
export const MIDDLEWARE_METADATA = Symbol.for('rikta:middleware:metadata');
|
|
8
|
-
export const HTTP_CODE_METADATA = Symbol.for('rikta:http:code:metadata');
|
|
9
|
-
export const HEADERS_METADATA = Symbol.for('rikta:headers:metadata');
|
|
10
|
-
export const INJECT_METADATA = Symbol.for('rikta:inject:metadata');
|
|
11
|
-
export const ZOD_SCHEMA_METADATA = Symbol.for('rikta:zod:schema:metadata');
|
|
12
|
-
export const AUTOWIRED_METADATA = Symbol.for('rikta:autowired:metadata');
|
|
13
|
-
export const PROVIDER_METADATA = Symbol.for('rikta:provider:metadata');
|
|
14
|
-
export const CONFIG_PROVIDER_METADATA = Symbol('config:provider:metadata');
|
|
15
|
-
export const CONFIG_PROPERTY_METADATA = Symbol('config:property:metadata');
|
|
16
|
-
export var ParamType;
|
|
17
|
-
(function (ParamType) {
|
|
18
|
-
ParamType["BODY"] = "body";
|
|
19
|
-
ParamType["QUERY"] = "query";
|
|
20
|
-
ParamType["PARAM"] = "param";
|
|
21
|
-
ParamType["HEADERS"] = "headers";
|
|
22
|
-
ParamType["REQUEST"] = "request";
|
|
23
|
-
ParamType["REPLY"] = "reply";
|
|
24
|
-
ParamType["CONTEXT"] = "context";
|
|
25
|
-
})(ParamType || (ParamType = {}));
|
|
26
|
-
export const DEFAULT_CONFIG = {
|
|
27
|
-
port: 3000,
|
|
28
|
-
host: '0.0.0.0',
|
|
29
|
-
logger: true,
|
|
30
|
-
prefix: '',
|
|
31
|
-
};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Constructor } from '../types.js';
|
|
2
|
-
export declare const IMPLEMENTS_METADATA: unique symbol;
|
|
3
|
-
export declare const PRIMARY_METADATA: unique symbol;
|
|
4
|
-
export declare function isAbstractClass(target: unknown): target is Constructor;
|
|
5
|
-
export declare function extendsFrom(derived: Constructor, base: Constructor): boolean;
|
|
6
|
-
export declare function getImplementedAbstract(target: Constructor): Constructor | undefined;
|
|
7
|
-
export declare function isPrimaryImplementation(target: Constructor): boolean;
|
|
8
|
-
export declare function setImplementsMetadata(target: Constructor, abstractClass: Constructor): void;
|
|
9
|
-
export declare function setPrimaryMetadata(target: Constructor): void;
|
|
10
|
-
export declare function markAsAbstract(target: Constructor): void;
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
export const IMPLEMENTS_METADATA = Symbol('rikta:implements');
|
|
2
|
-
export const PRIMARY_METADATA = Symbol('rikta:primary');
|
|
3
|
-
export function isAbstractClass(target) {
|
|
4
|
-
if (typeof target !== 'function') {
|
|
5
|
-
return false;
|
|
6
|
-
}
|
|
7
|
-
const isMarkedAbstract = Reflect.getMetadata(IMPLEMENTS_METADATA, target) === undefined
|
|
8
|
-
&& Reflect.hasMetadata('abstract:class', target);
|
|
9
|
-
if (isMarkedAbstract) {
|
|
10
|
-
return true;
|
|
11
|
-
}
|
|
12
|
-
return Reflect.getMetadata('abstract:class', target) === true;
|
|
13
|
-
}
|
|
14
|
-
export function extendsFrom(derived, base) {
|
|
15
|
-
if (!derived || !base) {
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
if (derived === base) {
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
let current = Object.getPrototypeOf(derived);
|
|
22
|
-
while (current && current !== Function.prototype) {
|
|
23
|
-
if (current === base) {
|
|
24
|
-
return true;
|
|
25
|
-
}
|
|
26
|
-
current = Object.getPrototypeOf(current);
|
|
27
|
-
}
|
|
28
|
-
return false;
|
|
29
|
-
}
|
|
30
|
-
export function getImplementedAbstract(target) {
|
|
31
|
-
return Reflect.getMetadata(IMPLEMENTS_METADATA, target);
|
|
32
|
-
}
|
|
33
|
-
export function isPrimaryImplementation(target) {
|
|
34
|
-
return Reflect.getMetadata(PRIMARY_METADATA, target) === true;
|
|
35
|
-
}
|
|
36
|
-
export function setImplementsMetadata(target, abstractClass) {
|
|
37
|
-
Reflect.defineMetadata(IMPLEMENTS_METADATA, abstractClass, target);
|
|
38
|
-
}
|
|
39
|
-
export function setPrimaryMetadata(target) {
|
|
40
|
-
Reflect.defineMetadata(PRIMARY_METADATA, true, target);
|
|
41
|
-
}
|
|
42
|
-
export function markAsAbstract(target) {
|
|
43
|
-
Reflect.defineMetadata('abstract:class', true, target);
|
|
44
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import 'reflect-metadata';
|
|
2
|
-
import { Constructor, InjectableOptions } from '../types.js';
|
|
3
|
-
import { Token, ProviderDefinition } from './injection-token.js';
|
|
4
|
-
export declare class Container {
|
|
5
|
-
private static instance;
|
|
6
|
-
private singletons;
|
|
7
|
-
private providers;
|
|
8
|
-
private resolutionStack;
|
|
9
|
-
private constructor();
|
|
10
|
-
static getInstance(): Container;
|
|
11
|
-
static reset(): void;
|
|
12
|
-
register<T>(target: Constructor<T>, options?: InjectableOptions): void;
|
|
13
|
-
registerProvider<T>(provider: ProviderDefinition<T>): void;
|
|
14
|
-
registerValue<T>(token: Token<T>, value: T): void;
|
|
15
|
-
registerFactory<T>(token: Token<T>, factory: () => T, inject?: Token[]): void;
|
|
16
|
-
has(token: Token): boolean;
|
|
17
|
-
resolve<T>(token: Token<T>): T;
|
|
18
|
-
resolveOptional<T>(token: Token<T>): T | undefined;
|
|
19
|
-
private resolveToken;
|
|
20
|
-
private resolveAbstractClass;
|
|
21
|
-
private resolveProvider;
|
|
22
|
-
private resolveClass;
|
|
23
|
-
private injectProperties;
|
|
24
|
-
private resolveWithName;
|
|
25
|
-
private resolveWithNameOptional;
|
|
26
|
-
registerInstance<T>(target: Constructor<T>, instance: T): void;
|
|
27
|
-
getProviders(): Token[];
|
|
28
|
-
clearSingletons(): void;
|
|
29
|
-
private isPrimitive;
|
|
30
|
-
private getTokenName;
|
|
31
|
-
}
|
|
32
|
-
export declare const container: Container;
|