arikajs 0.10.6 β†’ 0.10.8

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 (35) hide show
  1. package/README.md +70 -387
  2. package/dist/Application.d.ts +13 -0
  3. package/dist/Application.d.ts.map +1 -1
  4. package/dist/Application.js +56 -20
  5. package/dist/Application.js.map +1 -1
  6. package/dist/Contracts/Application.d.ts +2 -0
  7. package/dist/Contracts/Application.d.ts.map +1 -1
  8. package/dist/helpers.d.ts.map +1 -1
  9. package/dist/helpers.js +25 -10
  10. package/dist/helpers.js.map +1 -1
  11. package/dist/http/Actions/ActionDispatcher.d.ts +14 -0
  12. package/dist/http/Actions/ActionDispatcher.d.ts.map +1 -0
  13. package/dist/http/Actions/ActionDispatcher.js +124 -0
  14. package/dist/http/Actions/ActionDispatcher.js.map +1 -0
  15. package/dist/http/Actions/ResolveServerAction.d.ts +14 -0
  16. package/dist/http/Actions/ResolveServerAction.d.ts.map +1 -0
  17. package/dist/http/Actions/ResolveServerAction.js +34 -0
  18. package/dist/http/Actions/ResolveServerAction.js.map +1 -0
  19. package/dist/http/Handler.d.ts.map +1 -1
  20. package/dist/http/Handler.js +28 -40
  21. package/dist/http/Handler.js.map +1 -1
  22. package/dist/http/Kernel.d.ts +18 -2
  23. package/dist/http/Kernel.d.ts.map +1 -1
  24. package/dist/http/Kernel.js +102 -10
  25. package/dist/http/Kernel.js.map +1 -1
  26. package/dist/http/Middleware/RequestLoggingMiddleware.d.ts +2 -1
  27. package/dist/http/Middleware/RequestLoggingMiddleware.d.ts.map +1 -1
  28. package/dist/http/Middleware/RequestLoggingMiddleware.js +17 -6
  29. package/dist/http/Middleware/RequestLoggingMiddleware.js.map +1 -1
  30. package/dist/providers/ViewServiceProvider.d.ts +2 -4
  31. package/dist/providers/ViewServiceProvider.d.ts.map +1 -1
  32. package/dist/providers/ViewServiceProvider.js +14 -5
  33. package/dist/providers/ViewServiceProvider.js.map +1 -1
  34. package/package.json +24 -23
  35. package/dist/Application.js.bak +0 -301
package/README.md CHANGED
@@ -15,7 +15,7 @@
15
15
  [![GitHub issues](https://img.shields.io/github/issues/arikajs/arikajs.svg?style=flat-square)](https://github.com/arikajs/arikajs/issues)
16
16
  [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://github.com/arikajs/arikajs/pulls)
17
17
 
18
- [Quick Start](#quick-start) | [Examples](https://github.com/arikajs/examples) | [Community](https://discord.gg/arikajs)
18
+ [Quick Start](#quick-start) | [Core Modules](#-the-arikajs-ecosystem) | [Documentation](https://arikajs.com) | [Discord](https://discord.gg/arikajs)
19
19
 
20
20
  </div>
21
21
 
@@ -23,435 +23,120 @@
23
23
 
24
24
  ## πŸš€ What is ArikaJS?
25
25
 
26
- ArikaJS is a **modern, elegant, and powerful** Node.js framework that brings enterprise-grade features and developer-friendly patterns to the TypeScript/JavaScript ecosystem. Built from the ground up with TypeScript, ArikaJS provides a robust foundation for building scalable web applications and APIs with an intuitive, expressive syntax.
27
-
28
- ### ✨ Key Features
29
-
30
- - 🎯 **Elegant Syntax** - Clean, expressive code that's a joy to write
31
- - πŸ”₯ **TypeScript First** - Full TypeScript support with excellent type inference
32
- - πŸ›£οΈ **Powerful Routing** - Intuitive routing with implicit model binding
33
- - πŸ’‰ **Dependency Injection** - Built-in IoC container for clean architecture
34
- - πŸ—„οΈ **Active Record ORM** - Eloquent-inspired database layer
35
- - πŸ” **Authentication & Authorization** - Built-in auth system with guards and policies
36
- - βœ… **Validation** - Comprehensive request validation
37
- - πŸ“§ **Mail & Notifications** - Easy email and notification system
38
- - πŸ”„ **Queue System** - Background job processing
39
- - πŸ“¦ **Service Providers** - Modular application architecture
40
- - 🎨 **Template Engine** - Flexible view rendering
41
- - ⚑ **Event System** - Decouple your application with powerful events and listeners
42
- - πŸ§ͺ **Testing Ready** - Built with testing in mind
43
- - πŸ› οΈ **Global Helpers** - Intuitive functions like `app()`, `config()`, and `route()`
26
+ ArikaJS is a **modern, elegant, and powerful** full-stack framework for Node.js. It is designed to provide an unparalleled developer experience by bringing enterprise-grade architecture patterns (inspired by Laravel and NestJS) into a native, high-performance TypeScript environment.
44
27
 
45
- ---
46
-
47
- ## πŸ“¦ Installation
48
-
49
- ### Option 1: Quick Start (Using npx)
50
-
51
- The fastest way to create a new ArikaJS project is using `npx`. No installation required!
52
-
53
- ```bash
54
- # Create a new project
55
- npx @arikajs/cli new my-app
56
-
57
- # Navigate to your project
58
- cd my-app
28
+ Whether you're building a simple REST API or a complex enterprise monolith, ArikaJS provides the tools you needβ€”from a powerful ORM and background queues to expressive routing and real-time event broadcasting.
59
29
 
60
- # Start developing
61
- npm run dev
62
- ```
30
+ ---
63
31
 
64
- ### Option 2: Global Installation
32
+ ## ✨ Key Features
65
33
 
66
- If you prefer to have the `arika` command available everywhere, you can install the CLI globally:
34
+ - 🎯 **Elegant Syntax** - Expressive, readable code that minimizes boilerplate.
35
+ - πŸ”₯ **TypeScript First** - Deeply integrated type safety with zero-config setup.
36
+ - πŸ›οΈ **Modular Monorepo** - Built as a collection of decoupled, high-quality packages.
37
+ - πŸ—„οΈ **Active Record ORM** - An intuitive, Fluent interface for database interactions.
38
+ - πŸ’‰ **IoC & Dependency Injection** - Powerful service container for decoupled architecture.
39
+ - πŸ” **Auth & Authorization** - Guards, Policies, and multi-provider authentication.
40
+ - πŸ”„ **Queue & Scheduler** - Background jobs and Cron-like task scheduling.
41
+ - 🌍 **Localization (i18n)** - Built-in support for multi-language applications.
42
+ - πŸ“… **Carbon Date API** - Elegant date and time manipulation.
43
+ - 🎨 **Templating** - Lightning-fast Arika View engine with layout support.
44
+ - πŸ§ͺ **First-Class Testing** - Built-in testing helpers and assertions.
67
45
 
68
- ```bash
69
- # Install the CLI globally
70
- npm install -g @arikajs/cli
71
-
72
- # Create a new project
73
- arika new my-app
74
- ```
46
+ ---
75
47
 
76
- # Install dependencies
77
- npm install
48
+ ## πŸ“¦ The ArikaJS Ecosystem
49
+
50
+ ArikaJS is composed of specialized modules that can be used together or independently.
51
+
52
+ | Package | Purpose |
53
+ | :--- | :--- |
54
+ | **`arikajs`** | The core framework wrapper and "glue" |
55
+ | **`@arikajs/cli`** | Scaffolding, migrations, and local development |
56
+ | **`@arikajs/database`** | Database layer, Schema builder, and ORM |
57
+ | **`@arikajs/auth`** | Authentication (Web Session, JWT, API tokens) |
58
+ | **`@arikajs/queue`** | Redis/Database/Sync background job processing |
59
+ | **`@arikajs/scheduler`** | Fluid task scheduling for your application |
60
+ | **`@arikajs/carbon`** | Powerful, fluent date manipulation (Carbon JS) |
61
+ | **`@arikajs/view`** | Expressive template engine (Blade-inspired) |
62
+ | **`@arikajs/cache`** | High-performance multi-driver caching |
63
+ | **`@arikajs/mail`** | Fluent email API with SMTP, Log, and SES support |
64
+ | **`@arikajs/events`** | Event-driven architecture with listeners |
65
+ | **`@arikajs/validation`** | Powerful, schema-based request validation |
78
66
 
79
- # Start the development server
80
- npm run dev
81
- ```
67
+ ---
82
68
 
83
- Your application will be running at `http://localhost:8000` πŸŽ‰
69
+ ## 🚦 Quick Start
84
70
 
85
- ### Manual Installation
71
+ Create your first ArikaJS project in seconds:
86
72
 
87
73
  ```bash
88
- # Create a new project directory
89
- mkdir my-app && cd my-app
90
-
91
- # Initialize npm
92
- npm init -y
93
-
94
- # Install ArikaJS
95
- npm install arikajs
74
+ # Scaffold a new application
75
+ npx @arikajs/cli@latest new my-app
96
76
 
97
- # Install dev dependencies
98
- npm install -D @arikajs/cli typescript tsx @types/node
99
- ```
100
-
101
- ---
102
-
103
- ## πŸ—οΈ Project Structure
77
+ # Navigate into the project
78
+ cd my-app
104
79
 
105
- ```
106
- my-app/
107
- β”œβ”€β”€ app/
108
- β”‚ β”œβ”€β”€ Controllers/ # HTTP controllers
109
- β”‚ β”œβ”€β”€ Models/ # Database models
110
- β”‚ β”œβ”€β”€ Middleware/ # Custom middleware
111
- β”‚ └── Http/
112
- β”‚ └── Kernel.ts # HTTP kernel configuration
113
- β”œβ”€β”€ bootstrap/
114
- β”‚ └── app.ts # Application bootstrap
115
- β”œβ”€β”€ config/ # Configuration files
116
- β”‚ β”œβ”€β”€ app.ts
117
- β”‚ β”œβ”€β”€ database.ts
118
- β”‚ └── logging.ts
119
- β”œβ”€β”€ database/
120
- β”‚ └── migrations/ # Database migrations
121
- β”œβ”€β”€ routes/
122
- β”‚ └── web.ts # Route definitions
123
- β”œβ”€β”€ server.ts # Application entry point
124
- β”œβ”€β”€ .env # Environment variables
125
- └── package.json
80
+ # Install dependencies and start development
81
+ npm install && arika serve --dev
126
82
  ```
127
83
 
128
84
  ---
129
85
 
130
- ## πŸ“š Basic Usage
131
-
132
- ### Routing
133
-
134
- Define routes with an elegant, expressive syntax:
86
+ ## πŸ“– Basic Examples
135
87
 
88
+ ### Expressive Routing
136
89
  ```typescript
137
90
  import { Route } from 'arikajs';
138
91
 
139
- // Simple route
140
- Route.get('/', () => {
141
- return { message: 'Welcome to ArikaJS!' };
142
- });
143
-
144
- // Route with parameters
145
- Route.get('/users/{id}', (request, id) => {
146
- return { userId: id };
147
- });
92
+ Route.get('/', () => 'Hello World');
148
93
 
149
- // Route groups with middleware
150
- Route.group({ middleware: 'auth' }, () => {
151
- Route.get('/dashboard', [DashboardController, 'index']);
152
- Route.post('/posts', [PostController, 'store']);
94
+ Route.group({ prefix: 'api', middleware: 'auth' }, () => {
95
+ Route.get('/profile', [ProfileController, 'show']);
153
96
  });
154
97
  ```
155
98
 
156
- ### Implicit Model Binding
157
-
158
- Automatically resolve models from route parameters:
159
-
99
+ ### Powerful ORM (Active Record)
160
100
  ```typescript
161
- import { Route } from 'arikajs';
162
- import User from './app/Models/User';
163
-
164
- // Register model binding
165
- Route.model('user', User);
166
-
167
- // The {user} parameter will automatically resolve to a User instance
168
- Route.get('/users/{user}', (request, user: User) => {
169
- return {
170
- message: 'User found!',
171
- user: user
172
- };
173
- });
174
- ```
175
-
176
- ### Controllers
177
-
178
- Create clean, organized controllers:
101
+ const user = await User.where('email', 'prakash@example.com').first();
179
102
 
180
- ```typescript
181
- import { Request, Response } from 'arikajs';
182
- import User from '../Models/User';
183
-
184
- export class UserController {
185
- async index(request: Request, response: Response) {
186
- const users = await User.all();
187
- return response.json(users);
188
- }
189
-
190
- async show(request: Request, response: Response) {
191
- const user = await User.findOrFail(request.params.id);
192
- return response.json(user);
193
- }
194
-
195
- async store(request: Request, response: Response) {
196
- const user = await User.create(request.body);
197
- return response.status(201).json(user);
198
- }
199
- }
103
+ const posts = await user.posts().latest().get();
200
104
  ```
201
105
 
202
- ### Models (Active Record)
203
-
204
- Work with databases using an elegant ORM:
205
-
106
+ ### Background Jobs
206
107
  ```typescript
207
- import { Model } from 'arikajs';
108
+ import { dispatch } from '@arikajs/dispatcher';
208
109
 
209
- export default class User extends Model {
210
- protected static tableName = 'users';
211
-
212
- // Define relationships
213
- posts() {
214
- return this.hasMany(Post);
215
- }
216
-
217
- // Custom methods
218
- async sendWelcomeEmail() {
219
- // Send email logic
220
- }
221
- }
222
-
223
- // Usage
224
- const user = await User.find(1);
225
- const posts = await user.posts().get();
226
-
227
- const newUser = await User.create({
228
- name: 'John Doe',
229
- email: 'john@example.com'
230
- });
110
+ await dispatch(new ProcessVideoJob(videoPath));
231
111
  ```
232
112
 
233
- ### Middleware
234
-
235
- Create custom middleware for request processing:
236
-
113
+ ### Fluent Date Handling (Carbon)
237
114
  ```typescript
238
- import { MiddlewareHandler, Request, Response } from 'arikajs';
115
+ import { Carbon } from '@arikajs/carbon';
239
116
 
240
- export default class AuthMiddleware implements MiddlewareHandler {
241
- async handle(request: Request, response: Response, next: Function) {
242
- if (!request.headers.authorization) {
243
- return response.status(401).json({ error: 'Unauthorized' });
244
- }
245
-
246
- return next();
247
- }
248
- }
249
- ```
250
-
251
- ### Service Providers
252
-
253
- Organize your application with service providers:
254
-
255
- ```typescript
256
- import { ServiceProvider } from 'arikajs';
257
- import { PaymentService } from './Services/PaymentService';
258
-
259
- export class PaymentServiceProvider extends ServiceProvider {
260
- async register() {
261
- this.app.singleton('payment', () => {
262
- return new PaymentService(this.app.config().get('payment'));
263
- });
264
- }
265
-
266
- async boot() {
267
- // Bootstrap logic
268
- }
269
- }
270
- ```
271
-
272
- ### πŸ› οΈ Global Helpers
273
-
274
- ArikaJS provides several global helper functions to make your code more concise:
275
-
276
- ```typescript
277
- import { app, config, route } from 'arikajs';
278
-
279
- // Access the application container
280
- const userService = app().make(UserService);
281
-
282
- // Get configuration values with defaults
283
- const debug = config('app.debug', false);
284
-
285
- // Generate URLs for named routes
286
- const profileUrl = route('users.show', { id: 1 });
287
- ```
288
-
289
- ### Database Migrations
290
-
291
- Manage your database schema with migrations:
292
-
293
- ```typescript
294
- import { Migration, SchemaBuilder } from 'arikajs';
295
-
296
- export default class CreateUsersTable extends Migration {
297
- async up(schema: SchemaBuilder) {
298
- await schema.create('users', (table) => {
299
- table.increments('id');
300
- table.string('name');
301
- table.string('email').unique();
302
- table.string('password');
303
- table.timestamps();
304
- });
305
- }
306
-
307
- async down(schema: SchemaBuilder) {
308
- await schema.dropIfExists('users');
309
- }
310
- }
117
+ const nextWeek = Carbon.now().addWeek().toDateTimeString();
118
+ const diff = Carbon.parse(user.created_at).diffForHumans();
311
119
  ```
312
120
 
313
121
  ---
314
122
 
315
- ## πŸ”§ Configuration
123
+ ## πŸ› οΈ CLI Commands
316
124
 
317
- Configure your application in the `config/` directory:
318
-
319
- **config/app.ts**
320
- ```typescript
321
- export default {
322
- name: process.env.APP_NAME || 'ArikaJS',
323
- env: process.env.NODE_ENV || 'development',
324
- key: process.env.APP_KEY,
325
- timezone: 'UTC',
326
- };
327
- ```
328
-
329
- **config/database.ts**
330
- ```typescript
331
- export default {
332
- default: 'mysql',
333
- connections: {
334
- mysql: {
335
- driver: 'mysql',
336
- host: process.env.DB_HOST || 'localhost',
337
- port: parseInt(process.env.DB_PORT || '3306'),
338
- database: process.env.DB_DATABASE,
339
- username: process.env.DB_USERNAME,
340
- password: process.env.DB_PASSWORD,
341
- },
342
- },
343
- };
344
- ```
345
-
346
- ---
347
-
348
- ## 🎨 CLI Commands
349
-
350
- ArikaJS comes with a powerful CLI for common tasks:
125
+ The ArikaJS CLI is your best friend during development.
351
126
 
352
127
  ```bash
353
- # Create a new application
354
- arika new my-app
355
-
356
- # Start development server
357
- arika serve --dev
358
-
359
- # Generate application key
360
- arika key:generate
361
-
362
- # Database migrations
363
- arika migrate
364
- arika migrate:rollback
365
-
366
- # Create migration
367
- arika make:migration create_posts_table
128
+ arika list # List all available commands
129
+ arika help <command> # Show detailed help for a specific command
130
+ arika make:model # Interactive menu to generate models/migrations
131
+ arika migrate # Run pending database migrations
132
+ arika queue:work # Start the background worker
368
133
  ```
369
134
 
370
135
  ---
371
136
 
372
- ## πŸ§ͺ Testing
373
-
374
- ArikaJS is built with testing in mind:
375
-
376
- ```typescript
377
- import { describe, it } from 'node:test';
378
- import assert from 'node:assert';
379
- import app from './bootstrap/app';
380
-
381
- describe('User API', () => {
382
- it('should return all users', async () => {
383
- const response = await app.get('/api/users');
384
- assert.strictEqual(response.status, 200);
385
- });
386
- });
387
- ```
388
-
389
- ---
390
-
391
- ## πŸ“– Documentation
392
-
393
- Comprehensive documentation is available in the [GitHub repository](https://github.com/arikajs/arikajs).
394
-
395
- For guides and examples, check out:
396
- - [Installation Guide](https://github.com/arikajs/arikajs#installation)
397
- - [Routing](https://github.com/arikajs/arikajs#routing)
398
- - [Controllers](https://github.com/arikajs/arikajs#controllers)
399
- - [Database & ORM](https://github.com/arikajs/arikajs#models-active-record)
400
- - [Examples](https://github.com/arikajs/examples)
401
-
402
- ---
403
-
404
- ## πŸ— Architecture
405
-
406
- ```text
407
- arikajs/
408
- β”œβ”€β”€ src/
409
- β”‚ β”œβ”€β”€ Contracts
410
- β”‚ β”‚ └── Application.ts
411
- β”‚ β”œβ”€β”€ http
412
- β”‚ β”‚ β”œβ”€β”€ Middleware
413
- β”‚ β”‚ β”‚ β”œβ”€β”€ RequestLoggingMiddleware.ts
414
- β”‚ β”‚ β”‚ β”œβ”€β”€ ValidateRequestMiddleware.ts
415
- β”‚ β”‚ β”‚ └── ViewMiddleware.ts
416
- β”‚ β”‚ β”œβ”€β”€ Handler.ts
417
- β”‚ β”‚ └── Kernel.ts
418
- β”‚ β”œβ”€β”€ providers
419
- β”‚ β”‚ β”œβ”€β”€ AuthServiceProvider.ts
420
- β”‚ β”‚ β”œβ”€β”€ DatabaseServiceProvider.ts
421
- β”‚ β”‚ β”œβ”€β”€ EventsServiceProvider.ts
422
- β”‚ β”‚ β”œβ”€β”€ FrameworkServiceProvider.ts
423
- β”‚ β”‚ β”œβ”€β”€ HttpServiceProvider.ts
424
- β”‚ β”‚ β”œβ”€β”€ LoggingServiceProvider.ts
425
- β”‚ β”‚ β”œβ”€β”€ SchedulerServiceProvider.ts
426
- β”‚ β”‚ β”œβ”€β”€ ValidationServiceProvider.ts
427
- β”‚ β”‚ └── ViewServiceProvider.ts
428
- β”‚ β”œβ”€β”€ Application.ts
429
- β”‚ β”œβ”€β”€ createApp.ts
430
- β”‚ β”œβ”€β”€ helpers.ts
431
- β”‚ └── index.ts
432
- β”œβ”€β”€ tests/
433
- β”œβ”€β”€ package.json
434
- β”œβ”€β”€ tsconfig.json
435
- └── README.md
436
- ```
437
-
438
137
  ## 🀝 Contributing
439
138
 
440
- We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
441
-
442
- ```bash
443
- # Clone the repository
444
- git clone https://github.com/arikajs/arikajs.git
445
-
446
- # Install dependencies
447
- npm install
448
-
449
- # Run tests
450
- npm test
451
-
452
- # Build the project
453
- npm run build
454
- ```
139
+ We love our community! Please see our [Contributing Guide](CONTRIBUTING.md) to learn how you can help make ArikaJS even better.
455
140
 
456
141
  ---
457
142
 
@@ -459,13 +144,11 @@ npm run build
459
144
 
460
145
  ArikaJS is open-sourced software licensed under the [MIT license](LICENSE).
461
146
 
462
- ---
463
-
464
- ## πŸ™ Acknowledgments
147
+ <div align="center">
465
148
 
466
- ArikaJS draws inspiration from the best practices and patterns of modern web frameworks, including elegant API design, developer experience focus, and enterprise-grade architecture.
149
+ **Built with ❀️ by [Prakash Tank](https://github.com/prakashtank) & The ArikaJS Team**
467
150
 
468
- ---
151
+ </div>
469
152
 
470
153
  ## πŸ’¬ Community & Support
471
154
 
@@ -6,6 +6,7 @@ export declare class Application extends FoundationApplication implements Applic
6
6
  protected router: Router;
7
7
  protected server?: any;
8
8
  protected isTerminating: boolean;
9
+ protected _commands: any[];
9
10
  constructor(basePath?: string);
10
11
  boot(): Promise<void>;
11
12
  version(): string;
@@ -37,10 +38,22 @@ export declare class Application extends FoundationApplication implements Applic
37
38
  * Get the HTTP server callback for raw http.createServer() usage.
38
39
  */
39
40
  getCallback(): (req: any, res: any) => void;
41
+ /**
42
+ * Handle fatal errors that occur outside the Kernel's management.
43
+ */
44
+ private handleFatalError;
40
45
  /**
41
46
  * Gracefully terminate the application.
42
47
  */
43
48
  terminate(): Promise<void>;
49
+ /**
50
+ * Register CLI commands with the application.
51
+ */
52
+ registerCommands(commands: any[]): void;
53
+ /**
54
+ * Get all registered commands.
55
+ */
56
+ getCommands(): any[];
44
57
  /**
45
58
  * Get the router instance.
46
59
  */
@@ -1 +1 @@
1
- {"version":3,"file":"Application.d.ts","sourceRoot":"","sources":["../src/Application.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,IAAI,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAC3E,OAAO,EAAE,MAAM,EAAS,MAAM,iBAAiB,CAAC;AAGhD,OAAO,EAAE,WAAW,IAAI,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAG7E,qBAAa,WAAY,SAAQ,qBAAsB,YAAW,mBAAmB;IACjF,WAAkB,OAAO,IAAI,MAAM,CAYlC;IAED,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC;IACzB,SAAS,CAAC,MAAM,CAAC,EAAE,GAAG,CAAC;IACvB,SAAS,CAAC,aAAa,EAAE,OAAO,CAAS;gBAE7B,QAAQ,GAAE,MAAsB;IAc/B,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAM3B,OAAO,IAAI,MAAM;IAIxB;;OAEG;IACI,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG;IAIrC;;OAEG;IACI,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG;IAItC;;OAEG;IACI,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG;IAI9B,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG;IAIvC;;OAEG;IACI,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG;IAIjC,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG;IAIlC,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG;IAI1D;;OAEG;IACU,MAAM,CAAC,IAAI,GAAE,MAAa;IA4BvC,SAAS,CAAC,aAAa,CAAC,IAAI,EAAE,MAAM;IAgBpC;;OAEG;IACI,WAAW,KAmBN,KAAK,GAAG,EAAE,KAAK,GAAG;IAwB9B;;OAEG;IACU,SAAS;IAuDtB;;OAEG;IACI,SAAS,IAAI,MAAM;CAG7B"}
1
+ {"version":3,"file":"Application.d.ts","sourceRoot":"","sources":["../src/Application.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,IAAI,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAC3E,OAAO,EAAE,MAAM,EAAS,MAAM,iBAAiB,CAAC;AAGhD,OAAO,EAAE,WAAW,IAAI,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAG7E,qBAAa,WAAY,SAAQ,qBAAsB,YAAW,mBAAmB;IACjF,WAAkB,OAAO,IAAI,MAAM,CAYlC;IAED,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC;IACzB,SAAS,CAAC,MAAM,CAAC,EAAE,GAAG,CAAC;IACvB,SAAS,CAAC,aAAa,EAAE,OAAO,CAAS;IACzC,SAAS,CAAC,SAAS,EAAE,GAAG,EAAE,CAAM;gBAEpB,QAAQ,GAAE,MAAsB;IAc/B,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAM3B,OAAO,IAAI,MAAM;IAIxB;;OAEG;IACI,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG;IAIrC;;OAEG;IACI,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG;IAItC;;OAEG;IACI,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG;IAI9B,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG;IAIvC;;OAEG;IACI,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG;IAIjC,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG;IAIlC,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG;IAI1D;;OAEG;IACU,MAAM,CAAC,IAAI,GAAE,MAAa;IA4BvC,SAAS,CAAC,aAAa,CAAC,IAAI,EAAE,MAAM;IAgBpC;;OAEG;IACI,WAAW,KAcN,KAAK,GAAG,EAAE,KAAK,GAAG;IA+B9B;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAUxB;;OAEG;IACU,SAAS;IAuDtB;;OAEG;IACI,gBAAgB,CAAC,QAAQ,EAAE,GAAG,EAAE;IAIvC;;OAEG;IACI,WAAW,IAAI,GAAG,EAAE;IAI3B;;OAEG;IACI,SAAS,IAAI,MAAM;CAG7B"}
@@ -58,6 +58,7 @@ class Application extends foundation_1.Application {
58
58
  constructor(basePath = process.cwd()) {
59
59
  super(basePath);
60
60
  this.isTerminating = false;
61
+ this._commands = [];
61
62
  (0, helpers_1.setApp)(this);
62
63
  // Initialize Core Components
63
64
  this.router = new router_1.Router(this.getContainer());
@@ -158,32 +159,55 @@ class Application extends foundation_1.Application {
158
159
  const kernel = this.make(Kernel);
159
160
  const { ObjectPool } = require('@arikajs/foundation');
160
161
  const { Request: ArikaRequest, Response: ArikaResponse, RawResponse } = require('@arikajs/http');
161
- const requestPool = new ObjectPool(() => new ArikaRequest(this, null), (obj) => obj.reset(null));
162
- const responsePool = new ObjectPool(() => new ArikaResponse(null), (obj) => obj.reset(null));
162
+ const { Handler } = require('./http/Handler');
163
+ let handler;
164
+ try {
165
+ handler = this.make(Handler);
166
+ }
167
+ catch (e) {
168
+ handler = new Handler();
169
+ }
163
170
  return (req, res) => {
164
- const request = requestPool.acquire();
165
- const response = responsePool.acquire();
166
- request.reset(req);
167
- response.reset(res);
168
- const handleRequest = async () => {
169
- try {
170
- const finalResponse = await kernel.handle(request, response);
171
+ const request = new ArikaRequest(this, req);
172
+ const response = new ArikaResponse(res);
173
+ const handleError = (error) => {
174
+ handler.report(error);
175
+ Promise.resolve(handler.render(request, error, response))
176
+ .then((finalResponse) => {
171
177
  kernel.terminate(request, finalResponse);
178
+ })
179
+ .catch((renderError) => {
180
+ this.handleFatalError(res, renderError);
181
+ });
182
+ };
183
+ try {
184
+ const result = kernel.handle(request, response);
185
+ if (result instanceof Promise) {
186
+ result.then((finalResponse) => {
187
+ kernel.terminate(request, finalResponse);
188
+ }).catch(handleError);
172
189
  }
173
- catch (error) {
174
- if (!res.headersSent) {
175
- res.writeHead(500, { 'Content-Type': 'application/json' });
176
- res.end(JSON.stringify({ error: 'Internal Server Error', message: error.message }));
177
- }
178
- }
179
- finally {
180
- requestPool.release(request);
181
- responsePool.release(response);
190
+ else {
191
+ kernel.terminate(request, result);
182
192
  }
183
- };
184
- handleRequest();
193
+ }
194
+ catch (error) {
195
+ handleError(error);
196
+ }
185
197
  };
186
198
  }
199
+ /**
200
+ * Handle fatal errors that occur outside the Kernel's management.
201
+ */
202
+ handleFatalError(res, error) {
203
+ if (!res.headersSent) {
204
+ res.writeHead(500, { 'Content-Type': 'application/json' });
205
+ res.end(JSON.stringify({
206
+ error: 'Internal Server Error',
207
+ message: error.message || 'An unexpected error occurred'
208
+ }));
209
+ }
210
+ }
187
211
  /**
188
212
  * Gracefully terminate the application.
189
213
  */
@@ -235,6 +259,18 @@ class Application extends foundation_1.Application {
235
259
  }, 50);
236
260
  }
237
261
  }
262
+ /**
263
+ * Register CLI commands with the application.
264
+ */
265
+ registerCommands(commands) {
266
+ this._commands = [...this._commands, ...commands];
267
+ }
268
+ /**
269
+ * Get all registered commands.
270
+ */
271
+ getCommands() {
272
+ return this._commands;
273
+ }
238
274
  /**
239
275
  * Get the router instance.
240
276
  */