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.
- package/README.md +70 -387
- package/dist/Application.d.ts +13 -0
- package/dist/Application.d.ts.map +1 -1
- package/dist/Application.js +56 -20
- package/dist/Application.js.map +1 -1
- package/dist/Contracts/Application.d.ts +2 -0
- package/dist/Contracts/Application.d.ts.map +1 -1
- package/dist/helpers.d.ts.map +1 -1
- package/dist/helpers.js +25 -10
- package/dist/helpers.js.map +1 -1
- package/dist/http/Actions/ActionDispatcher.d.ts +14 -0
- package/dist/http/Actions/ActionDispatcher.d.ts.map +1 -0
- package/dist/http/Actions/ActionDispatcher.js +124 -0
- package/dist/http/Actions/ActionDispatcher.js.map +1 -0
- package/dist/http/Actions/ResolveServerAction.d.ts +14 -0
- package/dist/http/Actions/ResolveServerAction.d.ts.map +1 -0
- package/dist/http/Actions/ResolveServerAction.js +34 -0
- package/dist/http/Actions/ResolveServerAction.js.map +1 -0
- package/dist/http/Handler.d.ts.map +1 -1
- package/dist/http/Handler.js +28 -40
- package/dist/http/Handler.js.map +1 -1
- package/dist/http/Kernel.d.ts +18 -2
- package/dist/http/Kernel.d.ts.map +1 -1
- package/dist/http/Kernel.js +102 -10
- package/dist/http/Kernel.js.map +1 -1
- package/dist/http/Middleware/RequestLoggingMiddleware.d.ts +2 -1
- package/dist/http/Middleware/RequestLoggingMiddleware.d.ts.map +1 -1
- package/dist/http/Middleware/RequestLoggingMiddleware.js +17 -6
- package/dist/http/Middleware/RequestLoggingMiddleware.js.map +1 -1
- package/dist/providers/ViewServiceProvider.d.ts +2 -4
- package/dist/providers/ViewServiceProvider.d.ts.map +1 -1
- package/dist/providers/ViewServiceProvider.js +14 -5
- package/dist/providers/ViewServiceProvider.js.map +1 -1
- package/package.json +24 -23
- package/dist/Application.js.bak +0 -301
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
[](https://github.com/arikajs/arikajs/issues)
|
|
16
16
|
[](https://github.com/arikajs/arikajs/pulls)
|
|
17
17
|
|
|
18
|
-
[Quick Start](#quick-start) | [
|
|
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**
|
|
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
|
-
|
|
61
|
-
npm run dev
|
|
62
|
-
```
|
|
30
|
+
---
|
|
63
31
|
|
|
64
|
-
|
|
32
|
+
## β¨ Key Features
|
|
65
33
|
|
|
66
|
-
|
|
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
|
-
|
|
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
|
-
|
|
77
|
-
|
|
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
|
-
|
|
80
|
-
npm run dev
|
|
81
|
-
```
|
|
67
|
+
---
|
|
82
68
|
|
|
83
|
-
|
|
69
|
+
## π¦ Quick Start
|
|
84
70
|
|
|
85
|
-
|
|
71
|
+
Create your first ArikaJS project in seconds:
|
|
86
72
|
|
|
87
73
|
```bash
|
|
88
|
-
#
|
|
89
|
-
|
|
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
|
-
#
|
|
98
|
-
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
---
|
|
102
|
-
|
|
103
|
-
## ποΈ Project Structure
|
|
77
|
+
# Navigate into the project
|
|
78
|
+
cd my-app
|
|
104
79
|
|
|
105
|
-
|
|
106
|
-
|
|
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
|
-
##
|
|
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
|
-
|
|
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
|
-
|
|
150
|
-
Route.
|
|
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
|
-
###
|
|
157
|
-
|
|
158
|
-
Automatically resolve models from route parameters:
|
|
159
|
-
|
|
99
|
+
### Powerful ORM (Active Record)
|
|
160
100
|
```typescript
|
|
161
|
-
|
|
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
|
-
|
|
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
|
-
###
|
|
203
|
-
|
|
204
|
-
Work with databases using an elegant ORM:
|
|
205
|
-
|
|
106
|
+
### Background Jobs
|
|
206
107
|
```typescript
|
|
207
|
-
import {
|
|
108
|
+
import { dispatch } from '@arikajs/dispatcher';
|
|
208
109
|
|
|
209
|
-
|
|
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
|
-
###
|
|
234
|
-
|
|
235
|
-
Create custom middleware for request processing:
|
|
236
|
-
|
|
113
|
+
### Fluent Date Handling (Carbon)
|
|
237
114
|
```typescript
|
|
238
|
-
import {
|
|
115
|
+
import { Carbon } from '@arikajs/carbon';
|
|
239
116
|
|
|
240
|
-
|
|
241
|
-
|
|
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
|
-
##
|
|
123
|
+
## π οΈ CLI Commands
|
|
316
124
|
|
|
317
|
-
|
|
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
|
-
#
|
|
354
|
-
arika
|
|
355
|
-
|
|
356
|
-
#
|
|
357
|
-
arika
|
|
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
|
|
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
|
-
|
|
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
|
|
package/dist/Application.d.ts
CHANGED
|
@@ -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;
|
|
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"}
|
package/dist/Application.js
CHANGED
|
@@ -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
|
|
162
|
-
|
|
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 =
|
|
165
|
-
const response =
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
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
|
-
|
|
174
|
-
|
|
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
|
-
|
|
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
|
*/
|