@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
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import 'reflect-metadata';
|
|
2
|
-
import { CONTROLLER_METADATA, INJECTABLE_METADATA } from '../constants.js';
|
|
3
|
-
import { container } from '../container/container.js';
|
|
4
|
-
import { registry } from '../registry.js';
|
|
5
|
-
export function Controller(prefixOrOptions) {
|
|
6
|
-
return (target) => {
|
|
7
|
-
const prefix = typeof prefixOrOptions === 'string'
|
|
8
|
-
? prefixOrOptions
|
|
9
|
-
: prefixOrOptions?.prefix ?? '';
|
|
10
|
-
const normalizedPrefix = prefix
|
|
11
|
-
? (prefix.startsWith('/') ? prefix : `/${prefix}`)
|
|
12
|
-
: '';
|
|
13
|
-
Reflect.defineMetadata(CONTROLLER_METADATA, { prefix: normalizedPrefix }, target);
|
|
14
|
-
Reflect.defineMetadata(INJECTABLE_METADATA, { scope: 'singleton' }, target);
|
|
15
|
-
container.register(target, { scope: 'singleton' });
|
|
16
|
-
registry.registerController(target);
|
|
17
|
-
};
|
|
18
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import 'reflect-metadata';
|
|
2
|
-
import { ExecutionContext } from '../guards/execution-context.js';
|
|
3
|
-
export declare const CUSTOM_PARAM_METADATA: unique symbol;
|
|
4
|
-
export interface CustomParamMetadata<T = unknown> {
|
|
5
|
-
index: number;
|
|
6
|
-
factory: CustomParamFactory<T, unknown>;
|
|
7
|
-
data?: T;
|
|
8
|
-
}
|
|
9
|
-
export type CustomParamFactory<TData = unknown, TResult = unknown> = (data: TData, ctx: ExecutionContext) => TResult | Promise<TResult>;
|
|
10
|
-
export declare function createParamDecorator<TData = unknown, TResult = unknown>(factory: CustomParamFactory<TData, TResult>): (data?: TData) => ParameterDecorator;
|
|
11
|
-
export declare function getCustomParamMetadata<T = unknown>(target: Function, propertyKey: string | symbol): CustomParamMetadata<T>[];
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import 'reflect-metadata';
|
|
2
|
-
export const CUSTOM_PARAM_METADATA = Symbol.for('rikta:custom:param:metadata');
|
|
3
|
-
export function createParamDecorator(factory) {
|
|
4
|
-
return (data) => {
|
|
5
|
-
return (target, propertyKey, parameterIndex) => {
|
|
6
|
-
if (propertyKey === undefined)
|
|
7
|
-
return;
|
|
8
|
-
const existingParams = Reflect.getMetadata(CUSTOM_PARAM_METADATA, target.constructor, propertyKey) ?? [];
|
|
9
|
-
const metadata = {
|
|
10
|
-
index: parameterIndex,
|
|
11
|
-
factory: factory,
|
|
12
|
-
data,
|
|
13
|
-
};
|
|
14
|
-
existingParams.push(metadata);
|
|
15
|
-
Reflect.defineMetadata(CUSTOM_PARAM_METADATA, existingParams, target.constructor, propertyKey);
|
|
16
|
-
};
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
export function getCustomParamMetadata(target, propertyKey) {
|
|
20
|
-
return Reflect.getMetadata(CUSTOM_PARAM_METADATA, target, propertyKey) ?? [];
|
|
21
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export * from './injectable.decorator.js';
|
|
2
|
-
export * from './controller.decorator.js';
|
|
3
|
-
export * from './route.decorator.js';
|
|
4
|
-
export * from './param.decorator.js';
|
|
5
|
-
export * from './autowired.decorator.js';
|
|
6
|
-
export * from './provider.decorator.js';
|
|
7
|
-
export * from './config-property.decorator.js';
|
|
8
|
-
export * from './create-param-decorator.js';
|
|
9
|
-
export * from './apply-decorators.js';
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export * from './injectable.decorator.js';
|
|
2
|
-
export * from './controller.decorator.js';
|
|
3
|
-
export * from './route.decorator.js';
|
|
4
|
-
export * from './param.decorator.js';
|
|
5
|
-
export * from './autowired.decorator.js';
|
|
6
|
-
export * from './provider.decorator.js';
|
|
7
|
-
export * from './config-property.decorator.js';
|
|
8
|
-
export * from './create-param-decorator.js';
|
|
9
|
-
export * from './apply-decorators.js';
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import 'reflect-metadata';
|
|
2
|
-
import { INJECTABLE_METADATA } from '../constants.js';
|
|
3
|
-
import { container } from '../container/container.js';
|
|
4
|
-
import { registry } from '../registry.js';
|
|
5
|
-
export function Injectable(options = {}) {
|
|
6
|
-
return (target) => {
|
|
7
|
-
Reflect.defineMetadata(INJECTABLE_METADATA, options, target);
|
|
8
|
-
container.register(target, options);
|
|
9
|
-
registry.registerProvider(target);
|
|
10
|
-
};
|
|
11
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import 'reflect-metadata';
|
|
2
|
-
import type { ZodType } from 'zod';
|
|
3
|
-
import { ParamType } from '../constants.js';
|
|
4
|
-
export interface ParamMetadata {
|
|
5
|
-
index: number;
|
|
6
|
-
type: ParamType;
|
|
7
|
-
key?: string;
|
|
8
|
-
zodSchema?: ZodType<unknown>;
|
|
9
|
-
}
|
|
10
|
-
export declare const Body: {
|
|
11
|
-
(): ParameterDecorator;
|
|
12
|
-
(key: string): ParameterDecorator;
|
|
13
|
-
<T>(schema: ZodType<T>): ParameterDecorator;
|
|
14
|
-
};
|
|
15
|
-
export declare const Query: {
|
|
16
|
-
(): ParameterDecorator;
|
|
17
|
-
(key: string): ParameterDecorator;
|
|
18
|
-
<T>(schema: ZodType<T>): ParameterDecorator;
|
|
19
|
-
};
|
|
20
|
-
export declare const Param: {
|
|
21
|
-
(): ParameterDecorator;
|
|
22
|
-
(key: string): ParameterDecorator;
|
|
23
|
-
<T>(schema: ZodType<T>): ParameterDecorator;
|
|
24
|
-
};
|
|
25
|
-
export declare const Headers: {
|
|
26
|
-
(): ParameterDecorator;
|
|
27
|
-
(key: string): ParameterDecorator;
|
|
28
|
-
<T>(schema: ZodType<T>): ParameterDecorator;
|
|
29
|
-
};
|
|
30
|
-
export declare const Req: {
|
|
31
|
-
(): ParameterDecorator;
|
|
32
|
-
(key: string): ParameterDecorator;
|
|
33
|
-
<T>(schema: ZodType<T>): ParameterDecorator;
|
|
34
|
-
};
|
|
35
|
-
export declare const Request: {
|
|
36
|
-
(): ParameterDecorator;
|
|
37
|
-
(key: string): ParameterDecorator;
|
|
38
|
-
<T>(schema: ZodType<T>): ParameterDecorator;
|
|
39
|
-
};
|
|
40
|
-
export declare const Res: {
|
|
41
|
-
(): ParameterDecorator;
|
|
42
|
-
(key: string): ParameterDecorator;
|
|
43
|
-
<T>(schema: ZodType<T>): ParameterDecorator;
|
|
44
|
-
};
|
|
45
|
-
export declare const Reply: {
|
|
46
|
-
(): ParameterDecorator;
|
|
47
|
-
(key: string): ParameterDecorator;
|
|
48
|
-
<T>(schema: ZodType<T>): ParameterDecorator;
|
|
49
|
-
};
|
|
50
|
-
export declare const Ctx: {
|
|
51
|
-
(): ParameterDecorator;
|
|
52
|
-
(key: string): ParameterDecorator;
|
|
53
|
-
<T>(schema: ZodType<T>): ParameterDecorator;
|
|
54
|
-
};
|
|
55
|
-
export declare const Context: {
|
|
56
|
-
(): ParameterDecorator;
|
|
57
|
-
(key: string): ParameterDecorator;
|
|
58
|
-
<T>(schema: ZodType<T>): ParameterDecorator;
|
|
59
|
-
};
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import 'reflect-metadata';
|
|
2
|
-
import { PARAM_METADATA, ParamType } from '../constants.js';
|
|
3
|
-
function isZodType(value) {
|
|
4
|
-
return (value !== null &&
|
|
5
|
-
typeof value === 'object' &&
|
|
6
|
-
('_zod' in value || '_def' in value) &&
|
|
7
|
-
'safeParse' in value &&
|
|
8
|
-
typeof value.safeParse === 'function');
|
|
9
|
-
}
|
|
10
|
-
function createParamDecorator(type) {
|
|
11
|
-
function decorator(keyOrSchema) {
|
|
12
|
-
return (target, propertyKey, parameterIndex) => {
|
|
13
|
-
if (propertyKey === undefined)
|
|
14
|
-
return;
|
|
15
|
-
const existingParams = Reflect.getMetadata(PARAM_METADATA, target.constructor, propertyKey) ?? [];
|
|
16
|
-
const isSchema = isZodType(keyOrSchema);
|
|
17
|
-
const metadata = {
|
|
18
|
-
index: parameterIndex,
|
|
19
|
-
type,
|
|
20
|
-
key: isSchema ? undefined : keyOrSchema,
|
|
21
|
-
zodSchema: isSchema ? keyOrSchema : undefined,
|
|
22
|
-
};
|
|
23
|
-
existingParams.push(metadata);
|
|
24
|
-
Reflect.defineMetadata(PARAM_METADATA, existingParams, target.constructor, propertyKey);
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
return decorator;
|
|
28
|
-
}
|
|
29
|
-
export const Body = createParamDecorator(ParamType.BODY);
|
|
30
|
-
export const Query = createParamDecorator(ParamType.QUERY);
|
|
31
|
-
export const Param = createParamDecorator(ParamType.PARAM);
|
|
32
|
-
export const Headers = createParamDecorator(ParamType.HEADERS);
|
|
33
|
-
export const Req = createParamDecorator(ParamType.REQUEST);
|
|
34
|
-
export const Request = Req;
|
|
35
|
-
export const Res = createParamDecorator(ParamType.REPLY);
|
|
36
|
-
export const Reply = Res;
|
|
37
|
-
export const Ctx = createParamDecorator(ParamType.CONTEXT);
|
|
38
|
-
export const Context = Ctx;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import 'reflect-metadata';
|
|
2
|
-
import { Token } from '../container/injection-token.js';
|
|
3
|
-
import { Constructor } from '../types.js';
|
|
4
|
-
export interface ProviderMetadata {
|
|
5
|
-
token: Token;
|
|
6
|
-
}
|
|
7
|
-
export interface ConfigProviderMetadata {
|
|
8
|
-
token: string;
|
|
9
|
-
}
|
|
10
|
-
export declare function Provider(token?: Token): ClassDecorator;
|
|
11
|
-
export declare function getConfigProviderMetadata(target: Constructor): ConfigProviderMetadata | undefined;
|
|
12
|
-
export declare function isConfigProvider(target: Constructor): boolean;
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import 'reflect-metadata';
|
|
2
|
-
import { PROVIDER_METADATA, CONFIG_PROVIDER_METADATA } from '../constants.js';
|
|
3
|
-
import { registry } from '../registry.js';
|
|
4
|
-
function generateTokenFromClassName(className) {
|
|
5
|
-
let tokenName = className.replace(/Provider$/, '');
|
|
6
|
-
tokenName = tokenName
|
|
7
|
-
.replace(/([A-Z])/g, '_$1')
|
|
8
|
-
.toUpperCase()
|
|
9
|
-
.replace(/^_/, '');
|
|
10
|
-
if (!tokenName.endsWith('_CONFIG') && tokenName !== 'CONFIG') {
|
|
11
|
-
tokenName = `${tokenName}_CONFIG`;
|
|
12
|
-
}
|
|
13
|
-
return tokenName;
|
|
14
|
-
}
|
|
15
|
-
export function Provider(token) {
|
|
16
|
-
return (target) => {
|
|
17
|
-
const className = target.name;
|
|
18
|
-
const isConfigProvider = typeof target.prototype.schema === 'function';
|
|
19
|
-
if (isConfigProvider) {
|
|
20
|
-
let configToken;
|
|
21
|
-
if (typeof token === 'string') {
|
|
22
|
-
if (token.trim() === '') {
|
|
23
|
-
throw new Error(`@Provider: Config provider "${className}" token must be a non-empty string.`);
|
|
24
|
-
}
|
|
25
|
-
configToken = token;
|
|
26
|
-
}
|
|
27
|
-
else if (token === undefined) {
|
|
28
|
-
configToken = generateTokenFromClassName(className);
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
throw new Error(`@Provider: Config provider "${className}" requires a string token or no token for auto-generation.`);
|
|
32
|
-
}
|
|
33
|
-
if (configToken !== configToken.toUpperCase()) {
|
|
34
|
-
throw new Error(`@Provider: Token "${configToken}" for config provider "${className}" must be UPPERCASE. ` +
|
|
35
|
-
`Use "${configToken.toUpperCase()}" instead.`);
|
|
36
|
-
}
|
|
37
|
-
const configMetadata = { token: configToken };
|
|
38
|
-
Reflect.defineMetadata(CONFIG_PROVIDER_METADATA, configMetadata, target);
|
|
39
|
-
registry.registerConfigProvider(configToken, target);
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
if (token === undefined) {
|
|
43
|
-
throw new Error(`@Provider: Custom provider "${className}" requires a token parameter.`);
|
|
44
|
-
}
|
|
45
|
-
const metadata = { token };
|
|
46
|
-
Reflect.defineMetadata(PROVIDER_METADATA, metadata, target);
|
|
47
|
-
registry.registerCustomProvider(target);
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
export function getConfigProviderMetadata(target) {
|
|
52
|
-
return Reflect.getMetadata(CONFIG_PROVIDER_METADATA, target);
|
|
53
|
-
}
|
|
54
|
-
export function isConfigProvider(target) {
|
|
55
|
-
return Reflect.hasMetadata(CONFIG_PROVIDER_METADATA, target);
|
|
56
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import 'reflect-metadata';
|
|
2
|
-
export declare const Get: (path?: string) => MethodDecorator;
|
|
3
|
-
export declare const Post: (path?: string) => MethodDecorator;
|
|
4
|
-
export declare const Put: (path?: string) => MethodDecorator;
|
|
5
|
-
export declare const Patch: (path?: string) => MethodDecorator;
|
|
6
|
-
export declare const Delete: (path?: string) => MethodDecorator;
|
|
7
|
-
export declare const Options: (path?: string) => MethodDecorator;
|
|
8
|
-
export declare const Head: (path?: string) => MethodDecorator;
|
|
9
|
-
export declare function HttpCode(statusCode: number): MethodDecorator;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import 'reflect-metadata';
|
|
2
|
-
import { ROUTES_METADATA, HTTP_CODE_METADATA } from '../constants.js';
|
|
3
|
-
function createRouteDecorator(method) {
|
|
4
|
-
return (path = '') => {
|
|
5
|
-
return (target, propertyKey, descriptor) => {
|
|
6
|
-
const normalizedPath = path.startsWith('/') ? path : `/${path}`;
|
|
7
|
-
const routes = Reflect.getMetadata(ROUTES_METADATA, target.constructor) ?? [];
|
|
8
|
-
routes.push({
|
|
9
|
-
method,
|
|
10
|
-
path: normalizedPath === '/' ? '' : normalizedPath,
|
|
11
|
-
handlerName: propertyKey,
|
|
12
|
-
});
|
|
13
|
-
Reflect.defineMetadata(ROUTES_METADATA, routes, target.constructor);
|
|
14
|
-
return descriptor;
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
export const Get = createRouteDecorator('GET');
|
|
19
|
-
export const Post = createRouteDecorator('POST');
|
|
20
|
-
export const Put = createRouteDecorator('PUT');
|
|
21
|
-
export const Patch = createRouteDecorator('PATCH');
|
|
22
|
-
export const Delete = createRouteDecorator('DELETE');
|
|
23
|
-
export const Options = createRouteDecorator('OPTIONS');
|
|
24
|
-
export const Head = createRouteDecorator('HEAD');
|
|
25
|
-
export function HttpCode(statusCode) {
|
|
26
|
-
return (target, propertyKey, descriptor) => {
|
|
27
|
-
Reflect.defineMetadata(HTTP_CODE_METADATA, statusCode, target.constructor, propertyKey);
|
|
28
|
-
return descriptor;
|
|
29
|
-
};
|
|
30
|
-
}
|
package/dist/core/discovery.d.ts
DELETED
package/dist/core/discovery.js
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import fg from 'fast-glob';
|
|
2
|
-
import fs from 'fs/promises';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
import { DiscoveryException } from './exceptions/discovery.exception.js';
|
|
5
|
-
const DEFAULT_IGNORE_PATTERNS = [
|
|
6
|
-
'**/node_modules/**',
|
|
7
|
-
'**/dist/**',
|
|
8
|
-
'**/build/**',
|
|
9
|
-
'**/benchmarks/**',
|
|
10
|
-
'**/*.test.ts',
|
|
11
|
-
'**/*.spec.ts',
|
|
12
|
-
'**/*.d.ts',
|
|
13
|
-
];
|
|
14
|
-
function getEntryPointDirectory() {
|
|
15
|
-
const mainScript = process.argv[1];
|
|
16
|
-
if (mainScript) {
|
|
17
|
-
const filePath = mainScript.startsWith('file://')
|
|
18
|
-
? new URL(mainScript).pathname
|
|
19
|
-
: mainScript;
|
|
20
|
-
return path.dirname(filePath);
|
|
21
|
-
}
|
|
22
|
-
return process.cwd();
|
|
23
|
-
}
|
|
24
|
-
const DECORATOR_PATTERNS = [
|
|
25
|
-
/@Controller\s*\(/,
|
|
26
|
-
/@Injectable\s*\(/,
|
|
27
|
-
/@Provider\s*\(/,
|
|
28
|
-
/\.\s*Controller\s*\)\s*\(/,
|
|
29
|
-
/\.\s*Injectable\s*\)\s*\(/,
|
|
30
|
-
/\.\s*Provider\s*\)\s*\(/,
|
|
31
|
-
/\.\s*ProviderConfig\s*\)\s*\(/,
|
|
32
|
-
/import\s*{\s*[^}]*\bController\b[^}]*}\s*from\s*['"]@riktajs\/core['"]/,
|
|
33
|
-
/import\s*{\s*[^}]*\bInjectable\b[^}]*}\s*from\s*['"]@riktajs\/core['"]/,
|
|
34
|
-
/import\s*{\s*[^}]*\bProvider\b[^}]*}\s*from\s*['"]@riktajs\/core['"]/,
|
|
35
|
-
];
|
|
36
|
-
async function containsRiktaDecorators(filePath) {
|
|
37
|
-
try {
|
|
38
|
-
const content = await fs.readFile(filePath, 'utf-8');
|
|
39
|
-
return DECORATOR_PATTERNS.some(pattern => pattern.test(content));
|
|
40
|
-
}
|
|
41
|
-
catch {
|
|
42
|
-
return false;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
export async function discoverModules(optionsOrPatterns = ['./**/*.{ts,js}'], cwd) {
|
|
46
|
-
const options = Array.isArray(optionsOrPatterns)
|
|
47
|
-
? { patterns: optionsOrPatterns, cwd }
|
|
48
|
-
: optionsOrPatterns;
|
|
49
|
-
const patterns = options.patterns ?? ['./**/*.{ts,js}'];
|
|
50
|
-
const strict = options.strict ?? false;
|
|
51
|
-
const onImportError = options.onImportError;
|
|
52
|
-
const baseDir = options.cwd ?? cwd ?? getEntryPointDirectory();
|
|
53
|
-
const absoluteBaseDir = path.isAbsolute(baseDir)
|
|
54
|
-
? baseDir
|
|
55
|
-
: path.resolve(process.cwd(), baseDir);
|
|
56
|
-
const normalizedPatterns = patterns.map(pattern => {
|
|
57
|
-
let normalizedPattern = pattern;
|
|
58
|
-
if (path.isAbsolute(pattern)) {
|
|
59
|
-
normalizedPattern = path.relative(absoluteBaseDir, pattern);
|
|
60
|
-
if (!normalizedPattern.startsWith('.')) {
|
|
61
|
-
normalizedPattern = './' + normalizedPattern;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
if (/\.\w+$/.test(normalizedPattern) || normalizedPattern.endsWith('*')) {
|
|
65
|
-
return normalizedPattern;
|
|
66
|
-
}
|
|
67
|
-
return normalizedPattern.endsWith('/')
|
|
68
|
-
? `${normalizedPattern}**/*.{ts,js}`
|
|
69
|
-
: `${normalizedPattern}/**/*.{ts,js}`;
|
|
70
|
-
});
|
|
71
|
-
const files = await fg(normalizedPatterns, {
|
|
72
|
-
cwd: absoluteBaseDir,
|
|
73
|
-
absolute: true,
|
|
74
|
-
ignore: DEFAULT_IGNORE_PATTERNS,
|
|
75
|
-
onlyFiles: true,
|
|
76
|
-
});
|
|
77
|
-
const decoratorChecks = await Promise.all(files.map(async (file) => ({ file, hasDecorators: await containsRiktaDecorators(file) })));
|
|
78
|
-
const riktaFiles = decoratorChecks
|
|
79
|
-
.filter(({ hasDecorators }) => hasDecorators)
|
|
80
|
-
.map(({ file }) => file);
|
|
81
|
-
const importedFiles = [];
|
|
82
|
-
const failedImports = [];
|
|
83
|
-
for (const file of riktaFiles) {
|
|
84
|
-
try {
|
|
85
|
-
let importPath;
|
|
86
|
-
if (file.endsWith('.js')) {
|
|
87
|
-
importPath = `file://${file}`;
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
importPath = file.replace(/\.ts$/, '');
|
|
91
|
-
}
|
|
92
|
-
await import(importPath);
|
|
93
|
-
importedFiles.push(file);
|
|
94
|
-
}
|
|
95
|
-
catch (err) {
|
|
96
|
-
const error = err instanceof Error ? err : new Error(String(err));
|
|
97
|
-
onImportError?.(file, error);
|
|
98
|
-
if (process.env.DEBUG) {
|
|
99
|
-
console.warn(`[Rikta] Failed to import ${file}:`, error.message);
|
|
100
|
-
}
|
|
101
|
-
failedImports.push({ filePath: file, error });
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
if (strict && failedImports.length > 0) {
|
|
105
|
-
throw new DiscoveryException(failedImports);
|
|
106
|
-
}
|
|
107
|
-
return importedFiles;
|
|
108
|
-
}
|
|
109
|
-
export function getCallerDirectory() {
|
|
110
|
-
return getEntryPointDirectory();
|
|
111
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import 'reflect-metadata';
|
|
2
|
-
import { Constructor } from '../types.js';
|
|
3
|
-
export declare const CATCH_METADATA: unique symbol;
|
|
4
|
-
export interface CatchMetadata {
|
|
5
|
-
exceptions: Constructor<Error>[];
|
|
6
|
-
}
|
|
7
|
-
export declare function Catch(...exceptions: Constructor<Error>[]): ClassDecorator;
|
|
8
|
-
export declare function getCatchMetadata(target: Constructor): CatchMetadata | undefined;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import 'reflect-metadata';
|
|
2
|
-
export const CATCH_METADATA = Symbol('catch:metadata');
|
|
3
|
-
export function Catch(...exceptions) {
|
|
4
|
-
return (target) => {
|
|
5
|
-
const metadata = {
|
|
6
|
-
exceptions: exceptions.length > 0 ? exceptions : [],
|
|
7
|
-
};
|
|
8
|
-
Reflect.defineMetadata(CATCH_METADATA, metadata, target);
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
export function getCatchMetadata(target) {
|
|
12
|
-
return Reflect.getMetadata(CATCH_METADATA, target);
|
|
13
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export declare class ConfigProviderAlreadyRegisteredException extends Error {
|
|
2
|
-
constructor(token: string, existingClass: string, newClass: string);
|
|
3
|
-
}
|
|
4
|
-
export declare class ConfigProviderNotFoundException extends Error {
|
|
5
|
-
constructor(token: string, availableTokens?: string[]);
|
|
6
|
-
}
|
|
7
|
-
export declare class ConfigProviderInstantiationException extends Error {
|
|
8
|
-
constructor(token: string, className: string, cause: Error);
|
|
9
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
export class ConfigProviderAlreadyRegisteredException extends Error {
|
|
2
|
-
constructor(token, existingClass, newClass) {
|
|
3
|
-
super(`Config provider with token "${token}" is already registered.\n` +
|
|
4
|
-
`Existing: ${existingClass}\n` +
|
|
5
|
-
`Attempted: ${newClass}\n` +
|
|
6
|
-
`Use a different token or remove the duplicate registration.`);
|
|
7
|
-
this.name = 'ConfigProviderAlreadyRegisteredException';
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
export class ConfigProviderNotFoundException extends Error {
|
|
11
|
-
constructor(token, availableTokens = []) {
|
|
12
|
-
const suggestion = availableTokens.length > 0
|
|
13
|
-
? `\n\nAvailable tokens: ${availableTokens.join(', ')}`
|
|
14
|
-
: '';
|
|
15
|
-
super(`Config provider with token "${token}" not found.${suggestion}\n` +
|
|
16
|
-
`Make sure the provider class is:\n` +
|
|
17
|
-
`1. Decorated with @Provider('${token}')\n` +
|
|
18
|
-
`2. Located in a file matching the autowired patterns\n` +
|
|
19
|
-
`3. Properly exported from its module`);
|
|
20
|
-
this.name = 'ConfigProviderNotFoundException';
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
export class ConfigProviderInstantiationException extends Error {
|
|
24
|
-
constructor(token, className, cause) {
|
|
25
|
-
super(`Failed to instantiate config provider "${className}" (token: "${token}").\n` +
|
|
26
|
-
`Cause: ${cause.message}\n\n` +
|
|
27
|
-
`Check that the provider:\n` +
|
|
28
|
-
`1. Has a valid constructor\n` +
|
|
29
|
-
`2. All constructor dependencies are registered\n` +
|
|
30
|
-
`3. The provide() method is correctly implemented`);
|
|
31
|
-
this.name = 'ConfigProviderInstantiationException';
|
|
32
|
-
this.cause = cause;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export declare class DiscoveryException extends Error {
|
|
2
|
-
readonly filePath: string;
|
|
3
|
-
readonly originalError: Error;
|
|
4
|
-
readonly failedImports: DiscoveryFailure[];
|
|
5
|
-
constructor(filePath: string, originalError: Error);
|
|
6
|
-
constructor(failures: DiscoveryFailure[]);
|
|
7
|
-
getReport(): string;
|
|
8
|
-
}
|
|
9
|
-
export interface DiscoveryFailure {
|
|
10
|
-
filePath: string;
|
|
11
|
-
error: Error;
|
|
12
|
-
}
|
|
13
|
-
export interface DiscoveryOptions {
|
|
14
|
-
patterns?: string[];
|
|
15
|
-
cwd?: string;
|
|
16
|
-
strict?: boolean;
|
|
17
|
-
onImportError?: (filePath: string, error: Error) => void;
|
|
18
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
export class DiscoveryException extends Error {
|
|
2
|
-
filePath;
|
|
3
|
-
originalError;
|
|
4
|
-
failedImports;
|
|
5
|
-
constructor(filePathOrFailures, originalError) {
|
|
6
|
-
if (typeof filePathOrFailures === 'string') {
|
|
7
|
-
const filePath = filePathOrFailures;
|
|
8
|
-
const error = originalError;
|
|
9
|
-
super(`[Rikta Discovery] Failed to import module: ${filePath}\n` +
|
|
10
|
-
`Reason: ${error.message}`);
|
|
11
|
-
this.filePath = filePath;
|
|
12
|
-
this.originalError = error;
|
|
13
|
-
this.failedImports = [{ filePath, error }];
|
|
14
|
-
}
|
|
15
|
-
else {
|
|
16
|
-
const failures = filePathOrFailures;
|
|
17
|
-
const fileList = failures.map(f => ` - ${f.filePath}: ${f.error.message}`).join('\n');
|
|
18
|
-
super(`[Rikta Discovery] Failed to import ${failures.length} module(s):\n${fileList}`);
|
|
19
|
-
this.filePath = failures[0]?.filePath ?? '';
|
|
20
|
-
this.originalError = failures[0]?.error ?? new Error('Unknown error');
|
|
21
|
-
this.failedImports = failures;
|
|
22
|
-
}
|
|
23
|
-
this.name = 'DiscoveryException';
|
|
24
|
-
Error.captureStackTrace(this, this.constructor);
|
|
25
|
-
}
|
|
26
|
-
getReport() {
|
|
27
|
-
const lines = ['Discovery Failures:', ''];
|
|
28
|
-
for (const { filePath, error } of this.failedImports) {
|
|
29
|
-
lines.push(`📁 ${filePath}`);
|
|
30
|
-
lines.push(` Error: ${error.message}`);
|
|
31
|
-
if (error.stack) {
|
|
32
|
-
const stackLines = error.stack.split('\n').slice(1, 4);
|
|
33
|
-
lines.push(` Stack: ${stackLines.join('\n ')}`);
|
|
34
|
-
}
|
|
35
|
-
lines.push('');
|
|
36
|
-
}
|
|
37
|
-
return lines.join('\n');
|
|
38
|
-
}
|
|
39
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import type { FastifyRequest, FastifyReply, FastifyError } from 'fastify';
|
|
2
|
-
export interface ExceptionContext {
|
|
3
|
-
exception: Error;
|
|
4
|
-
request: FastifyRequest;
|
|
5
|
-
reply: FastifyReply;
|
|
6
|
-
path: string;
|
|
7
|
-
method: string;
|
|
8
|
-
requestId?: string;
|
|
9
|
-
}
|
|
10
|
-
export interface ExceptionFilter<T extends Error = Error> {
|
|
11
|
-
catch(exception: T, context: ExceptionContext): void | Promise<void>;
|
|
12
|
-
}
|
|
13
|
-
export interface ErrorResponse {
|
|
14
|
-
statusCode: number;
|
|
15
|
-
message: string;
|
|
16
|
-
error: string;
|
|
17
|
-
timestamp: string;
|
|
18
|
-
path: string;
|
|
19
|
-
requestId?: string;
|
|
20
|
-
details?: unknown;
|
|
21
|
-
code?: string;
|
|
22
|
-
stack?: string;
|
|
23
|
-
}
|
|
24
|
-
export declare class GlobalExceptionFilter implements ExceptionFilter {
|
|
25
|
-
private readonly includeStack;
|
|
26
|
-
private readonly logErrors;
|
|
27
|
-
constructor(options?: GlobalExceptionFilterOptions);
|
|
28
|
-
catch(exception: Error, context: ExceptionContext): void;
|
|
29
|
-
private buildResponse;
|
|
30
|
-
private isFastifyValidationError;
|
|
31
|
-
private isFastifyError;
|
|
32
|
-
private logError;
|
|
33
|
-
}
|
|
34
|
-
export interface GlobalExceptionFilterOptions {
|
|
35
|
-
includeStack?: boolean;
|
|
36
|
-
logErrors?: boolean;
|
|
37
|
-
}
|
|
38
|
-
export declare function createExceptionHandler(filter: ExceptionFilter, customFilters?: Map<Function, ExceptionFilter>): (error: FastifyError | Error, request: FastifyRequest, reply: FastifyReply) => Promise<void>;
|