@riktajs/core 0.1.0

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.
Files changed (111) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +205 -0
  3. package/dist/core/application.d.ts +28 -0
  4. package/dist/core/application.d.ts.map +1 -0
  5. package/dist/core/application.js +321 -0
  6. package/dist/core/application.js.map +1 -0
  7. package/dist/core/constants.d.ts +70 -0
  8. package/dist/core/constants.d.ts.map +1 -0
  9. package/dist/core/constants.js +77 -0
  10. package/dist/core/constants.js.map +1 -0
  11. package/dist/core/container/container.d.ts +101 -0
  12. package/dist/core/container/container.d.ts.map +1 -0
  13. package/dist/core/container/container.js +327 -0
  14. package/dist/core/container/container.js.map +1 -0
  15. package/dist/core/container/index.d.ts +3 -0
  16. package/dist/core/container/index.d.ts.map +1 -0
  17. package/dist/core/container/index.js +19 -0
  18. package/dist/core/container/index.js.map +1 -0
  19. package/dist/core/container/injection-token.d.ts +58 -0
  20. package/dist/core/container/injection-token.d.ts.map +1 -0
  21. package/dist/core/container/injection-token.js +37 -0
  22. package/dist/core/container/injection-token.js.map +1 -0
  23. package/dist/core/decorators/autowired.decorator.d.ts +72 -0
  24. package/dist/core/decorators/autowired.decorator.d.ts.map +1 -0
  25. package/dist/core/decorators/autowired.decorator.js +143 -0
  26. package/dist/core/decorators/autowired.decorator.js.map +1 -0
  27. package/dist/core/decorators/controller.decorator.d.ts +33 -0
  28. package/dist/core/decorators/controller.decorator.d.ts.map +1 -0
  29. package/dist/core/decorators/controller.decorator.js +50 -0
  30. package/dist/core/decorators/controller.decorator.js.map +1 -0
  31. package/dist/core/decorators/index.d.ts +7 -0
  32. package/dist/core/decorators/index.d.ts.map +1 -0
  33. package/dist/core/decorators/index.js +24 -0
  34. package/dist/core/decorators/index.js.map +1 -0
  35. package/dist/core/decorators/injectable.decorator.d.ts +26 -0
  36. package/dist/core/decorators/injectable.decorator.d.ts.map +1 -0
  37. package/dist/core/decorators/injectable.decorator.js +40 -0
  38. package/dist/core/decorators/injectable.decorator.js.map +1 -0
  39. package/dist/core/decorators/param.decorator.d.ts +72 -0
  40. package/dist/core/decorators/param.decorator.d.ts.map +1 -0
  41. package/dist/core/decorators/param.decorator.js +88 -0
  42. package/dist/core/decorators/param.decorator.js.map +1 -0
  43. package/dist/core/decorators/provider.decorator.d.ts +64 -0
  44. package/dist/core/decorators/provider.decorator.d.ts.map +1 -0
  45. package/dist/core/decorators/provider.decorator.js +69 -0
  46. package/dist/core/decorators/provider.decorator.js.map +1 -0
  47. package/dist/core/decorators/route.decorator.d.ts +53 -0
  48. package/dist/core/decorators/route.decorator.d.ts.map +1 -0
  49. package/dist/core/decorators/route.decorator.js +85 -0
  50. package/dist/core/decorators/route.decorator.js.map +1 -0
  51. package/dist/core/discovery.d.ts +24 -0
  52. package/dist/core/discovery.d.ts.map +1 -0
  53. package/dist/core/discovery.js +168 -0
  54. package/dist/core/discovery.js.map +1 -0
  55. package/dist/core/exceptions/catch.decorator.d.ts +71 -0
  56. package/dist/core/exceptions/catch.decorator.d.ts.map +1 -0
  57. package/dist/core/exceptions/catch.decorator.js +77 -0
  58. package/dist/core/exceptions/catch.decorator.js.map +1 -0
  59. package/dist/core/exceptions/exception-filter.d.ts +134 -0
  60. package/dist/core/exceptions/exception-filter.d.ts.map +1 -0
  61. package/dist/core/exceptions/exception-filter.js +161 -0
  62. package/dist/core/exceptions/exception-filter.js.map +1 -0
  63. package/dist/core/exceptions/exceptions.d.ts +212 -0
  64. package/dist/core/exceptions/exceptions.d.ts.map +1 -0
  65. package/dist/core/exceptions/exceptions.js +275 -0
  66. package/dist/core/exceptions/exceptions.js.map +1 -0
  67. package/dist/core/exceptions/http-exception.d.ts +79 -0
  68. package/dist/core/exceptions/http-exception.d.ts.map +1 -0
  69. package/dist/core/exceptions/http-exception.js +106 -0
  70. package/dist/core/exceptions/http-exception.js.map +1 -0
  71. package/dist/core/exceptions/index.d.ts +5 -0
  72. package/dist/core/exceptions/index.d.ts.map +1 -0
  73. package/dist/core/exceptions/index.js +38 -0
  74. package/dist/core/exceptions/index.js.map +1 -0
  75. package/dist/core/index.d.ts +11 -0
  76. package/dist/core/index.d.ts.map +1 -0
  77. package/dist/core/index.js +28 -0
  78. package/dist/core/index.js.map +1 -0
  79. package/dist/core/lifecycle/event-bus.d.ts +96 -0
  80. package/dist/core/lifecycle/event-bus.d.ts.map +1 -0
  81. package/dist/core/lifecycle/event-bus.js +91 -0
  82. package/dist/core/lifecycle/event-bus.js.map +1 -0
  83. package/dist/core/lifecycle/index.d.ts +4 -0
  84. package/dist/core/lifecycle/index.d.ts.map +1 -0
  85. package/dist/core/lifecycle/index.js +21 -0
  86. package/dist/core/lifecycle/index.js.map +1 -0
  87. package/dist/core/lifecycle/interfaces.d.ts +106 -0
  88. package/dist/core/lifecycle/interfaces.d.ts.map +1 -0
  89. package/dist/core/lifecycle/interfaces.js +10 -0
  90. package/dist/core/lifecycle/interfaces.js.map +1 -0
  91. package/dist/core/lifecycle/on.decorator.d.ts +62 -0
  92. package/dist/core/lifecycle/on.decorator.d.ts.map +1 -0
  93. package/dist/core/lifecycle/on.decorator.js +65 -0
  94. package/dist/core/lifecycle/on.decorator.js.map +1 -0
  95. package/dist/core/registry.d.ts +64 -0
  96. package/dist/core/registry.d.ts.map +1 -0
  97. package/dist/core/registry.js +91 -0
  98. package/dist/core/registry.js.map +1 -0
  99. package/dist/core/router/router.d.ts +39 -0
  100. package/dist/core/router/router.d.ts.map +1 -0
  101. package/dist/core/router/router.js +150 -0
  102. package/dist/core/router/router.js.map +1 -0
  103. package/dist/core/types.d.ts +161 -0
  104. package/dist/core/types.d.ts.map +1 -0
  105. package/dist/core/types.js +3 -0
  106. package/dist/core/types.js.map +1 -0
  107. package/dist/index.d.ts +44 -0
  108. package/dist/index.d.ts.map +1 -0
  109. package/dist/index.js +64 -0
  110. package/dist/index.js.map +1 -0
  111. package/package.json +47 -0
@@ -0,0 +1,150 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Router = void 0;
4
+ require("reflect-metadata");
5
+ const constants_1 = require("../constants");
6
+ /**
7
+ * Router class
8
+ *
9
+ * Responsible for:
10
+ * - Scanning controllers for route metadata
11
+ * - Registering routes with Fastify
12
+ * - Handling parameter injection
13
+ */
14
+ class Router {
15
+ server;
16
+ container;
17
+ globalPrefix;
18
+ constructor(server, container, globalPrefix = '') {
19
+ this.server = server;
20
+ this.container = container;
21
+ this.globalPrefix = globalPrefix;
22
+ }
23
+ /**
24
+ * Register all routes from a controller
25
+ */
26
+ registerController(controllerClass) {
27
+ // Get controller metadata
28
+ const controllerMeta = Reflect.getMetadata(constants_1.CONTROLLER_METADATA, controllerClass);
29
+ if (!controllerMeta) {
30
+ throw new Error(`${controllerClass.name} is not decorated with @Controller(). ` +
31
+ `Make sure to add the decorator.`);
32
+ }
33
+ // Resolve controller instance from container
34
+ const controllerInstance = this.container.resolve(controllerClass);
35
+ // Get routes metadata
36
+ const routes = Reflect.getMetadata(constants_1.ROUTES_METADATA, controllerClass) ?? [];
37
+ // Register each route
38
+ for (const route of routes) {
39
+ this.registerRoute(controllerClass, controllerInstance, controllerMeta.prefix, route);
40
+ }
41
+ }
42
+ /**
43
+ * Register a single route
44
+ */
45
+ registerRoute(controllerClass, controllerInstance, controllerPrefix, route) {
46
+ // Build full path
47
+ const fullPath = this.buildPath(controllerPrefix, route.path);
48
+ // Get the handler method
49
+ const handler = controllerInstance[route.handlerName];
50
+ if (typeof handler !== 'function') {
51
+ throw new Error(`Handler ${String(route.handlerName)} not found on ${controllerClass.name}`);
52
+ }
53
+ // Get parameter metadata
54
+ const paramsMeta = Reflect.getMetadata(constants_1.PARAM_METADATA, controllerClass, route.handlerName) ?? [];
55
+ // Get HTTP status code if set
56
+ const statusCode = Reflect.getMetadata(constants_1.HTTP_CODE_METADATA, controllerClass, route.handlerName);
57
+ // Create the route handler
58
+ const routeHandler = async (request, reply) => {
59
+ try {
60
+ // Build route context
61
+ const context = {
62
+ request,
63
+ reply,
64
+ params: request.params,
65
+ query: request.query,
66
+ body: request.body,
67
+ };
68
+ // Resolve parameters
69
+ const args = this.resolveParams(paramsMeta, context);
70
+ // Call the handler
71
+ const result = await handler.apply(controllerInstance, args);
72
+ // Set status code if specified
73
+ if (statusCode) {
74
+ reply.status(statusCode);
75
+ }
76
+ // Return result (Fastify will serialize it)
77
+ return result;
78
+ }
79
+ catch (error) {
80
+ // Let Fastify handle the error
81
+ throw error;
82
+ }
83
+ };
84
+ // Register with Fastify
85
+ const method = route.method.toLowerCase();
86
+ this.server[method](fullPath, routeHandler);
87
+ // Log route registration
88
+ console.log(` → ${route.method.padEnd(7)} ${fullPath}`);
89
+ }
90
+ /**
91
+ * Build the full route path
92
+ */
93
+ buildPath(controllerPrefix, routePath) {
94
+ const parts = [this.globalPrefix, controllerPrefix, routePath]
95
+ .filter(Boolean)
96
+ .join('');
97
+ // Normalize multiple slashes
98
+ return parts.replace(/\/+/g, '/') || '/';
99
+ }
100
+ /**
101
+ * Resolve handler parameters based on metadata
102
+ */
103
+ resolveParams(paramsMeta, context) {
104
+ if (paramsMeta.length === 0) {
105
+ return [];
106
+ }
107
+ // Sort by parameter index
108
+ const sorted = [...paramsMeta].sort((a, b) => a.index - b.index);
109
+ // Find max index to create properly sized array
110
+ const maxIndex = Math.max(...sorted.map(p => p.index));
111
+ const args = new Array(maxIndex + 1).fill(undefined);
112
+ for (const param of sorted) {
113
+ args[param.index] = this.resolveParam(param, context);
114
+ }
115
+ return args;
116
+ }
117
+ /**
118
+ * Resolve a single parameter
119
+ */
120
+ resolveParam(param, context) {
121
+ switch (param.type) {
122
+ case constants_1.ParamType.BODY:
123
+ return param.key
124
+ ? context.body?.[param.key]
125
+ : context.body;
126
+ case constants_1.ParamType.QUERY:
127
+ return param.key
128
+ ? context.query[param.key]
129
+ : context.query;
130
+ case constants_1.ParamType.PARAM:
131
+ return param.key
132
+ ? context.params[param.key]
133
+ : context.params;
134
+ case constants_1.ParamType.HEADERS:
135
+ return param.key
136
+ ? context.request.headers[param.key.toLowerCase()]
137
+ : context.request.headers;
138
+ case constants_1.ParamType.REQUEST:
139
+ return context.request;
140
+ case constants_1.ParamType.REPLY:
141
+ return context.reply;
142
+ case constants_1.ParamType.CONTEXT:
143
+ return context;
144
+ default:
145
+ return undefined;
146
+ }
147
+ }
148
+ }
149
+ exports.Router = Router;
150
+ //# sourceMappingURL=router.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"router.js","sourceRoot":"","sources":["../../../src/core/router/router.ts"],"names":[],"mappings":";;;AAAA,4BAA0B;AAG1B,4CAMsB;AAItB;;;;;;;GAOG;AACH,MAAa,MAAM;IAEE;IACA;IACA;IAHnB,YACmB,MAAuB,EACvB,SAAoB,EACpB,eAAuB,EAAE;QAFzB,WAAM,GAAN,MAAM,CAAiB;QACvB,cAAS,GAAT,SAAS,CAAW;QACpB,iBAAY,GAAZ,YAAY,CAAa;IACzC,CAAC;IAEJ;;OAEG;IACH,kBAAkB,CAAC,eAA4B;QAC7C,0BAA0B;QAC1B,MAAM,cAAc,GAAG,OAAO,CAAC,WAAW,CAAC,+BAAmB,EAAE,eAAe,CAAC,CAAC;QACjF,IAAI,CAAC,cAAc,EAAE,CAAC;YACpB,MAAM,IAAI,KAAK,CACb,GAAG,eAAe,CAAC,IAAI,wCAAwC;gBAC/D,iCAAiC,CAClC,CAAC;QACJ,CAAC;QAED,6CAA6C;QAC7C,MAAM,kBAAkB,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;QAEnE,sBAAsB;QACtB,MAAM,MAAM,GACV,OAAO,CAAC,WAAW,CAAC,2BAAe,EAAE,eAAe,CAAC,IAAI,EAAE,CAAC;QAE9D,sBAAsB;QACtB,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YAC3B,IAAI,CAAC,aAAa,CAAC,eAAe,EAAE,kBAAkB,EAAE,cAAc,CAAC,MAAM,EAAE,KAAK,CAAC,C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,CAAC,OAAO,CAAC;YAE9B,KAAK,qBAAS,CAAC,OAAO;gBACpB,OAAO,OAAO,CAAC,OAAO,CAAC;YAEzB,KAAK,qBAAS,CAAC,KAAK;gBAClB,OAAO,OAAO,CAAC,KAAK,CAAC;YAEvB,KAAK,qBAAS,CAAC,OAAO;gBACpB,OAAO,OAAO,CAAC;YAEjB;gBACE,OAAO,SAAS,CAAC;QACrB,CAAC;IACH,CAAC;CACF;AA3KD,wBA2KC"}
@@ -0,0 +1,161 @@
1
+ import type { FastifyInstance, FastifyRequest, FastifyReply } from 'fastify';
2
+ /**
3
+ * Constructor type for class instantiation
4
+ */
5
+ export type Constructor<T = any> = new (...args: any[]) => T;
6
+ /**
7
+ * HTTP methods supported by the framework
8
+ */
9
+ export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'OPTIONS' | 'HEAD';
10
+ /**
11
+ * Route handler context
12
+ */
13
+ export interface RouteContext {
14
+ request: FastifyRequest;
15
+ reply: FastifyReply;
16
+ params: Record<string, string>;
17
+ query: Record<string, unknown>;
18
+ body: unknown;
19
+ }
20
+ /**
21
+ * Route definition metadata
22
+ */
23
+ export interface RouteDefinition {
24
+ method: HttpMethod;
25
+ path: string;
26
+ handlerName: string | symbol;
27
+ statusCode?: number;
28
+ }
29
+ /**
30
+ * Controller metadata
31
+ */
32
+ export interface ControllerMetadata {
33
+ prefix: string;
34
+ routes: RouteDefinition[];
35
+ }
36
+ /**
37
+ * Provider scope for dependency injection
38
+ */
39
+ export type ProviderScope = 'singleton' | 'transient' | 'request';
40
+ /**
41
+ * Injectable options
42
+ */
43
+ export interface InjectableOptions {
44
+ /** Provider scope (default: 'singleton') */
45
+ scope?: ProviderScope;
46
+ /**
47
+ * Initialization priority (higher = initialized first)
48
+ * Default: 0
49
+ *
50
+ * @example
51
+ * ```typescript
52
+ * @Injectable({ priority: 100 })
53
+ * class DatabaseService { } // Initialized first
54
+ *
55
+ * @Injectable({ priority: 50 })
56
+ * class CacheService { } // Initialized second
57
+ *
58
+ * @Injectable() // priority: 0
59
+ * class UserService { } // Initialized last
60
+ * ```
61
+ */
62
+ priority?: number;
63
+ }
64
+ /**
65
+ * Exception filter options
66
+ */
67
+ export interface ExceptionFilterConfig {
68
+ /** Include stack trace in error response (default: true in development) */
69
+ includeStack?: boolean;
70
+ /** Log errors to console (default: true) */
71
+ logErrors?: boolean;
72
+ }
73
+ /**
74
+ * Application configuration
75
+ */
76
+ export interface RiktaConfig {
77
+ /** Server port (default: 3000) */
78
+ port?: number;
79
+ /** Server host (default: '0.0.0.0') */
80
+ host?: string;
81
+ /** Enable Fastify logging (default: true) */
82
+ logger?: boolean | object;
83
+ /** Global route prefix (default: '') */
84
+ prefix?: string;
85
+ /**
86
+ * Glob patterns for auto-discovery of controllers and services.
87
+ * Files matching these patterns will be imported automatically.
88
+ *
89
+ * @default ['./**'] (scans current directory recursively)
90
+ *
91
+ * @example
92
+ * ```typescript
93
+ * // Scan specific directories
94
+ * autowired: ['./src/controllers', './src/services']
95
+ *
96
+ * // Scan with glob patterns
97
+ * autowired: ['./src/**\/*.controller.ts', './src/**\/*.service.ts']
98
+ * ```
99
+ */
100
+ autowired?: string[];
101
+ /**
102
+ * Explicit list of controllers to register.
103
+ * If not provided, all @Controller decorated classes are auto-discovered.
104
+ */
105
+ controllers?: Constructor[];
106
+ /**
107
+ * Additional providers to register.
108
+ * Most providers are auto-discovered via @Injectable.
109
+ * Use this for custom providers or manual registration.
110
+ */
111
+ providers?: Constructor[];
112
+ /**
113
+ * Exception filter configuration.
114
+ * Controls how errors are handled and formatted.
115
+ *
116
+ * @example
117
+ * ```typescript
118
+ * exceptionFilter: {
119
+ * includeStack: process.env.NODE_ENV !== 'production',
120
+ * logErrors: true
121
+ * }
122
+ * ```
123
+ */
124
+ exceptionFilter?: ExceptionFilterConfig;
125
+ /**
126
+ * Custom exception filters.
127
+ * Filters are matched against exception types in order.
128
+ *
129
+ * @example
130
+ * ```typescript
131
+ * exceptionFilters: [ValidationExceptionFilter, CustomErrorFilter]
132
+ * ```
133
+ */
134
+ exceptionFilters?: Constructor[];
135
+ }
136
+ /**
137
+ * Middleware function signature
138
+ */
139
+ export type MiddlewareFunction = (request: FastifyRequest, reply: FastifyReply, next: () => Promise<void>) => Promise<void> | void;
140
+ /**
141
+ * Guard interface for route protection
142
+ */
143
+ export interface Guard {
144
+ canActivate(context: RouteContext): boolean | Promise<boolean>;
145
+ }
146
+ /**
147
+ * Interceptor interface for request/response manipulation
148
+ */
149
+ export interface Interceptor {
150
+ intercept(context: RouteContext, next: () => Promise<unknown>): Promise<unknown>;
151
+ }
152
+ /**
153
+ * Application instance interface
154
+ */
155
+ export interface RiktaApplication {
156
+ readonly server: FastifyInstance;
157
+ listen(): Promise<string>;
158
+ close(): Promise<void>;
159
+ getUrl(): string;
160
+ }
161
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAM7E;;GAEG;AAEH,MAAM,MAAM,WAAW,CAAC,CAAC,GAAG,GAAG,IAAI,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;AAE7D;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,GAAG,SAAS,GAAG,MAAM,CAAC;AAE1F;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,cAAc,CAAC;IACxB,KAAK,EAAE,YAAY,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,IAAI,EAAE,OAAO,CAAC;CACf;AAED;;GAEG;AACH,M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;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG,CAC/B,OAAO,EAAE,cAAc,EACvB,KAAK,EAAE,YAAY,EACnB,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,KACtB,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;AAE1B;;GAEG;AACH,MAAM,WAAW,KAAK;IACpB,WAAW,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAChE;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,SAAS,CAAC,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAClF;AAKD;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,MAAM,EAAE,eAAe,CAAC;IACjC,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAC1B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB,MAAM,IAAI,MAAM,CAAC;CAClB"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Rikta Framework
3
+ *
4
+ * A modern TypeScript backend framework with zero-config autowiring, powered by Fastify.
5
+ *
6
+ * Features:
7
+ * - Decorator-based routing (@Controller, @Get, @Post, etc.)
8
+ * - Full Autowiring - No modules needed, everything is auto-discovered
9
+ * - Single DI decorator - @Autowired() for constructor and property injection
10
+ * - Hybrid Lifecycle - Interface hooks + EventBus
11
+ * - Exception Handling - Built-in filters with standardized JSON responses
12
+ * - Fastify under the hood for maximum performance
13
+ * - Full TypeScript support
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * import { Rikta, Controller, Get, Injectable, Autowired } from '@rikta/core';
18
+ *
19
+ * @Injectable()
20
+ * class GreetingService {
21
+ * getGreeting(): string {
22
+ * return 'Hello from Rikta!';
23
+ * }
24
+ * }
25
+ *
26
+ * @Controller()
27
+ * class AppController {
28
+ * @Autowired()
29
+ * private greetingService!: GreetingService;
30
+ *
31
+ * @Get('/')
32
+ * getHello() {
33
+ * return this.greetingService.getGreeting();
34
+ * }
35
+ * }
36
+ *
37
+ * // No modules - just create and run!
38
+ * const app = await Rikta.create({ port: 3000 });
39
+ * await app.listen();
40
+ * ```
41
+ */
42
+ export * from './core';
43
+ export { RiktaFactory as default } from './core/application';
44
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAGH,cAAc,QAAQ,CAAC;AAGvB,OAAO,EAAE,YAAY,IAAI,OAAO,EAAE,MAAM,oBAAoB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ /**
3
+ * Rikta Framework
4
+ *
5
+ * A modern TypeScript backend framework with zero-config autowiring, powered by Fastify.
6
+ *
7
+ * Features:
8
+ * - Decorator-based routing (@Controller, @Get, @Post, etc.)
9
+ * - Full Autowiring - No modules needed, everything is auto-discovered
10
+ * - Single DI decorator - @Autowired() for constructor and property injection
11
+ * - Hybrid Lifecycle - Interface hooks + EventBus
12
+ * - Exception Handling - Built-in filters with standardized JSON responses
13
+ * - Fastify under the hood for maximum performance
14
+ * - Full TypeScript support
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * import { Rikta, Controller, Get, Injectable, Autowired } from '@rikta/core';
19
+ *
20
+ * @Injectable()
21
+ * class GreetingService {
22
+ * getGreeting(): string {
23
+ * return 'Hello from Rikta!';
24
+ * }
25
+ * }
26
+ *
27
+ * @Controller()
28
+ * class AppController {
29
+ * @Autowired()
30
+ * private greetingService!: GreetingService;
31
+ *
32
+ * @Get('/')
33
+ * getHello() {
34
+ * return this.greetingService.getGreeting();
35
+ * }
36
+ * }
37
+ *
38
+ * // No modules - just create and run!
39
+ * const app = await Rikta.create({ port: 3000 });
40
+ * await app.listen();
41
+ * ```
42
+ */
43
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
44
+ if (k2 === undefined) k2 = k;
45
+ var desc = Object.getOwnPropertyDescriptor(m, k);
46
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
47
+ desc = { enumerable: true, get: function() { return m[k]; } };
48
+ }
49
+ Object.defineProperty(o, k2, desc);
50
+ }) : (function(o, m, k, k2) {
51
+ if (k2 === undefined) k2 = k;
52
+ o[k2] = m[k];
53
+ }));
54
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
55
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
56
+ };
57
+ Object.defineProperty(exports, "__esModule", { value: true });
58
+ exports.default = void 0;
59
+ // Re-export everything from core
60
+ __exportStar(require("./core"), exports);
61
+ // Default export for convenience
62
+ var application_1 = require("./core/application");
63
+ Object.defineProperty(exports, "default", { enumerable: true, get: function () { return application_1.RiktaFactory; } });
64
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;;;;;;;;;;;;;;;;;AAEH,iCAAiC;AACjC,yCAAuB;AAEvB,iCAAiC;AACjC,kDAA6D;AAApD,sGAAA,YAAY,OAAW"}
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@riktajs/core",
3
+ "version": "0.1.0",
4
+ "description": "A fast and modern TypeScript backend framework with zero-config autowiring, powered by Fastify",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "scripts": {
11
+ "build": "tsc",
12
+ "dev": "ts-node-dev --respawn src/index.ts",
13
+ "example": "ts-node example/main.ts",
14
+ "test": "vitest run",
15
+ "test:watch": "vitest",
16
+ "test:coverage": "vitest run --coverage",
17
+ "lint": "eslint src --ext .ts",
18
+ "prepublishOnly": "npm run build"
19
+ },
20
+ "keywords": [
21
+ "framework",
22
+ "backend",
23
+ "typescript",
24
+ "fastify",
25
+ "decorators",
26
+ "dependency-injection",
27
+ "nestjs-like"
28
+ ],
29
+ "author": "",
30
+ "license": "MIT",
31
+ "dependencies": {
32
+ "fast-glob": "^3.3.2",
33
+ "fastify": "^5.1.0",
34
+ "reflect-metadata": "^0.2.2"
35
+ },
36
+ "devDependencies": {
37
+ "@types/node": "^22.10.2",
38
+ "@vitest/coverage-v8": "^2.1.9",
39
+ "ts-node": "^10.9.2",
40
+ "ts-node-dev": "^2.0.0",
41
+ "typescript": "^5.7.2",
42
+ "vitest": "^2.1.8"
43
+ },
44
+ "engines": {
45
+ "node": ">=20.0.0"
46
+ }
47
+ }