arikajs 0.10.3 → 0.10.4
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/package.json +36 -32
- package/CHANGELOG.md +0 -152
- package/src/Application.ts +0 -248
- package/src/Contracts/Application.ts +0 -24
- package/src/createApp.ts +0 -9
- package/src/facades/Schedule.ts +0 -26
- package/src/helpers.ts +0 -150
- package/src/http/Handler.ts +0 -539
- package/src/http/Kernel.ts +0 -110
- package/src/http/Middleware/RequestLoggingMiddleware.ts +0 -17
- package/src/http/Middleware/ServeStaticMiddleware.ts +0 -34
- package/src/http/Middleware/ValidateRequestMiddleware.ts +0 -35
- package/src/http/Middleware/VerifyCsrfToken.ts +0 -101
- package/src/http/Middleware/ViewMiddleware.ts +0 -56
- package/src/http/views/errors/401.ark.html +0 -57
- package/src/http/views/errors/403.ark.html +0 -54
- package/src/http/views/errors/404.ark.html +0 -179
- package/src/http/views/errors/419.ark.html +0 -54
- package/src/http/views/errors/429.ark.html +0 -54
- package/src/http/views/errors/500.ark.html +0 -54
- package/src/http/views/errors/503.ark.html +0 -49
- package/src/index.ts +0 -87
- package/src/providers/AuthServiceProvider.ts +0 -28
- package/src/providers/CacheServiceProvider.ts +0 -29
- package/src/providers/DatabaseServiceProvider.ts +0 -46
- package/src/providers/EventsServiceProvider.ts +0 -19
- package/src/providers/FrameworkServiceProvider.ts +0 -46
- package/src/providers/HttpServiceProvider.ts +0 -37
- package/src/providers/LoggingServiceProvider.ts +0 -17
- package/src/providers/MailServiceProvider.ts +0 -33
- package/src/providers/QueueServiceProvider.ts +0 -32
- package/src/providers/SchedulerServiceProvider.ts +0 -18
- package/src/providers/SessionServiceProvider.ts +0 -68
- package/src/providers/StorageServiceProvider.ts +0 -42
- package/src/providers/TranslationServiceProvider.ts +0 -51
- package/src/providers/ValidationServiceProvider.ts +0 -24
- package/src/providers/ViewServiceProvider.ts +0 -50
- package/tests/Framework.test.ts +0 -140
- package/tsconfig.json +0 -25
package/package.json
CHANGED
|
@@ -1,42 +1,40 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "arikajs",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.4",
|
|
4
4
|
"description": "The ArikaJS Framework.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
|
|
12
|
-
"dev": "tsc -p tsconfig.json --watch"
|
|
13
|
-
},
|
|
8
|
+
"files": [
|
|
9
|
+
"dist",
|
|
10
|
+
"README.md"
|
|
11
|
+
],
|
|
14
12
|
"dependencies": {
|
|
15
|
-
"@arikajs/auth": "workspace:*",
|
|
16
|
-
"@arikajs/authorization": "workspace:*",
|
|
17
|
-
"@arikajs/cache": "workspace:*",
|
|
18
|
-
"@arikajs/carbon": "workspace:^",
|
|
19
|
-
"@arikajs/console": "workspace:*",
|
|
20
|
-
"@arikajs/database": "workspace:*",
|
|
21
|
-
"@arikajs/dispatcher": "workspace:*",
|
|
22
|
-
"@arikajs/encryption": "workspace:*",
|
|
23
|
-
"@arikajs/events": "workspace:*",
|
|
24
|
-
"@arikajs/foundation": "workspace:*",
|
|
25
|
-
"@arikajs/http": "workspace:*",
|
|
26
|
-
"@arikajs/localization": "workspace:*",
|
|
27
|
-
"@arikajs/logging": "workspace:*",
|
|
28
|
-
"@arikajs/mail": "workspace:*",
|
|
29
|
-
"@arikajs/middleware": "workspace:*",
|
|
30
|
-
"@arikajs/queue": "workspace:*",
|
|
31
|
-
"@arikajs/router": "workspace:*",
|
|
32
|
-
"@arikajs/scheduler": "workspace:*",
|
|
33
|
-
"@arikajs/session": "workspace:*",
|
|
34
|
-
"@arikajs/storage": "workspace:*",
|
|
35
|
-
"@arikajs/validation": "workspace:*",
|
|
36
|
-
"@arikajs/view": "workspace:*",
|
|
37
13
|
"@types/serve-static": "^2.2.0",
|
|
38
14
|
"busboy": "^1.6.0",
|
|
39
|
-
"serve-static": "^2.2.1"
|
|
15
|
+
"serve-static": "^2.2.1",
|
|
16
|
+
"@arikajs/carbon": "^0.10.4",
|
|
17
|
+
"@arikajs/auth": "0.10.4",
|
|
18
|
+
"@arikajs/dispatcher": "0.10.4",
|
|
19
|
+
"@arikajs/database": "0.10.4",
|
|
20
|
+
"@arikajs/encryption": "0.10.4",
|
|
21
|
+
"@arikajs/console": "0.10.4",
|
|
22
|
+
"@arikajs/events": "0.10.4",
|
|
23
|
+
"@arikajs/cache": "0.10.4",
|
|
24
|
+
"@arikajs/foundation": "0.10.4",
|
|
25
|
+
"@arikajs/authorization": "0.10.4",
|
|
26
|
+
"@arikajs/logging": "0.10.4",
|
|
27
|
+
"@arikajs/middleware": "0.10.4",
|
|
28
|
+
"@arikajs/queue": "0.10.4",
|
|
29
|
+
"@arikajs/router": "0.10.4",
|
|
30
|
+
"@arikajs/scheduler": "0.10.4",
|
|
31
|
+
"@arikajs/http": "0.10.4",
|
|
32
|
+
"@arikajs/session": "0.10.4",
|
|
33
|
+
"@arikajs/storage": "0.10.4",
|
|
34
|
+
"@arikajs/localization": "0.10.4",
|
|
35
|
+
"@arikajs/validation": "0.10.4",
|
|
36
|
+
"@arikajs/mail": "0.10.4",
|
|
37
|
+
"@arikajs/view": "0.10.4"
|
|
40
38
|
},
|
|
41
39
|
"devDependencies": {
|
|
42
40
|
"@types/node": "^20.11.24",
|
|
@@ -52,5 +50,11 @@
|
|
|
52
50
|
"bugs": {
|
|
53
51
|
"url": "https://github.com/ArikaJs/arikajs/issues"
|
|
54
52
|
},
|
|
55
|
-
"homepage": "https://github.com/ArikaJs/arikajs/tree/main/packages/arikajs#readme"
|
|
56
|
-
|
|
53
|
+
"homepage": "https://github.com/ArikaJs/arikajs/tree/main/packages/arikajs#readme",
|
|
54
|
+
"scripts": {
|
|
55
|
+
"build": "tsc -p tsconfig.json && cp -R src/http/views dist/http/",
|
|
56
|
+
"clean": "rm -rf dist",
|
|
57
|
+
"test": "npx tsx tests/Framework.test.ts",
|
|
58
|
+
"dev": "tsc -p tsconfig.json --watch"
|
|
59
|
+
}
|
|
60
|
+
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
# arikajs
|
|
2
|
-
|
|
3
|
-
## 0.10.3
|
|
4
|
-
|
|
5
|
-
### Patch Changes
|
|
6
|
-
|
|
7
|
-
- Updated dependencies
|
|
8
|
-
- @arikajs/view@0.10.3
|
|
9
|
-
- @arikajs/auth@0.10.3
|
|
10
|
-
- @arikajs/authorization@0.10.3
|
|
11
|
-
- @arikajs/cache@0.10.3
|
|
12
|
-
- @arikajs/carbon@0.10.3
|
|
13
|
-
- @arikajs/console@0.10.3
|
|
14
|
-
- @arikajs/database@0.10.3
|
|
15
|
-
- @arikajs/dispatcher@0.10.3
|
|
16
|
-
- @arikajs/encryption@0.10.3
|
|
17
|
-
- @arikajs/events@0.10.3
|
|
18
|
-
- @arikajs/foundation@0.10.3
|
|
19
|
-
- @arikajs/http@0.10.3
|
|
20
|
-
- @arikajs/localization@0.10.3
|
|
21
|
-
- @arikajs/logging@0.10.3
|
|
22
|
-
- @arikajs/mail@0.10.3
|
|
23
|
-
- @arikajs/middleware@0.10.3
|
|
24
|
-
- @arikajs/queue@0.10.3
|
|
25
|
-
- @arikajs/router@0.10.3
|
|
26
|
-
- @arikajs/scheduler@0.10.3
|
|
27
|
-
- @arikajs/session@0.10.3
|
|
28
|
-
- @arikajs/storage@0.10.3
|
|
29
|
-
- @arikajs/validation@0.10.3
|
|
30
|
-
|
|
31
|
-
## 0.0.8
|
|
32
|
-
|
|
33
|
-
### Patch Changes
|
|
34
|
-
|
|
35
|
-
- fix: ensure newly created projects automatically sync their framework version with the CLI version
|
|
36
|
-
- Updated dependencies
|
|
37
|
-
- @arikajs/cli@0.0.8
|
|
38
|
-
- @arikajs/auth@0.0.8
|
|
39
|
-
- @arikajs/authorization@0.0.8
|
|
40
|
-
- @arikajs/cache@0.0.8
|
|
41
|
-
- @arikajs/console@0.0.8
|
|
42
|
-
- @arikajs/database@0.0.8
|
|
43
|
-
- @arikajs/dispatcher@0.0.8
|
|
44
|
-
- @arikajs/encryption@0.0.8
|
|
45
|
-
- @arikajs/events@0.0.8
|
|
46
|
-
- @arikajs/foundation@0.0.8
|
|
47
|
-
- @arikajs/http@0.0.8
|
|
48
|
-
- @arikajs/localization@0.0.8
|
|
49
|
-
- @arikajs/logging@0.0.8
|
|
50
|
-
- @arikajs/mail@0.0.8
|
|
51
|
-
- @arikajs/middleware@0.0.8
|
|
52
|
-
- @arikajs/queue@0.0.8
|
|
53
|
-
- @arikajs/router@0.0.8
|
|
54
|
-
- @arikajs/scheduler@0.0.8
|
|
55
|
-
- @arikajs/session@0.0.8
|
|
56
|
-
- @arikajs/storage@0.0.8
|
|
57
|
-
- @arikajs/validation@0.0.8
|
|
58
|
-
- @arikajs/view@0.0.8
|
|
59
|
-
|
|
60
|
-
## 0.0.7
|
|
61
|
-
|
|
62
|
-
### Patch Changes
|
|
63
|
-
|
|
64
|
-
- fix: removed workspace: versioning from http package and ensured CLI templates use semantic versions by default
|
|
65
|
-
- Updated dependencies
|
|
66
|
-
- @arikajs/cli@0.0.7
|
|
67
|
-
- @arikajs/http@0.0.7
|
|
68
|
-
- @arikajs/auth@0.0.7
|
|
69
|
-
- @arikajs/authorization@0.0.7
|
|
70
|
-
- @arikajs/cache@0.0.7
|
|
71
|
-
- @arikajs/console@0.0.7
|
|
72
|
-
- @arikajs/database@0.0.7
|
|
73
|
-
- @arikajs/dispatcher@0.0.7
|
|
74
|
-
- @arikajs/encryption@0.0.7
|
|
75
|
-
- @arikajs/events@0.0.7
|
|
76
|
-
- @arikajs/foundation@0.0.7
|
|
77
|
-
- @arikajs/localization@0.0.7
|
|
78
|
-
- @arikajs/logging@0.0.7
|
|
79
|
-
- @arikajs/mail@0.0.7
|
|
80
|
-
- @arikajs/middleware@0.0.7
|
|
81
|
-
- @arikajs/queue@0.0.7
|
|
82
|
-
- @arikajs/router@0.0.7
|
|
83
|
-
- @arikajs/scheduler@0.0.7
|
|
84
|
-
- @arikajs/session@0.0.7
|
|
85
|
-
- @arikajs/storage@0.0.7
|
|
86
|
-
- @arikajs/validation@0.0.7
|
|
87
|
-
- @arikajs/view@0.0.7
|
|
88
|
-
|
|
89
|
-
## 0.0.6
|
|
90
|
-
|
|
91
|
-
### Patch Changes
|
|
92
|
-
|
|
93
|
-
- fix: ensure CLI templates use semantic version dependencies instead of local file paths when published to npm
|
|
94
|
-
- Updated dependencies
|
|
95
|
-
- @arikajs/cli@0.0.6
|
|
96
|
-
- @arikajs/auth@0.0.6
|
|
97
|
-
- @arikajs/authorization@0.0.6
|
|
98
|
-
- @arikajs/cache@0.0.6
|
|
99
|
-
- @arikajs/console@0.0.6
|
|
100
|
-
- @arikajs/database@0.0.6
|
|
101
|
-
- @arikajs/dispatcher@0.0.6
|
|
102
|
-
- @arikajs/encryption@0.0.6
|
|
103
|
-
- @arikajs/events@0.0.6
|
|
104
|
-
- @arikajs/foundation@0.0.6
|
|
105
|
-
- @arikajs/http@0.0.6
|
|
106
|
-
- @arikajs/localization@0.0.6
|
|
107
|
-
- @arikajs/logging@0.0.6
|
|
108
|
-
- @arikajs/mail@0.0.6
|
|
109
|
-
- @arikajs/middleware@0.0.6
|
|
110
|
-
- @arikajs/queue@0.0.6
|
|
111
|
-
- @arikajs/router@0.0.6
|
|
112
|
-
- @arikajs/scheduler@0.0.6
|
|
113
|
-
- @arikajs/session@0.0.6
|
|
114
|
-
- @arikajs/storage@0.0.6
|
|
115
|
-
- @arikajs/validation@0.0.6
|
|
116
|
-
- @arikajs/view@0.0.6
|
|
117
|
-
|
|
118
|
-
## 0.0.5
|
|
119
|
-
|
|
120
|
-
### Patch Changes
|
|
121
|
-
|
|
122
|
-
- feat: implement CSRF protection and standardized middleware architecture
|
|
123
|
-
|
|
124
|
-
- Added session-based CSRF protection middleware.
|
|
125
|
-
- Refactored middleware into project-level stubs for better customization.
|
|
126
|
-
- Standardized auth controller stubs.
|
|
127
|
-
- Enhanced CLI project scaffolding.
|
|
128
|
-
- Added session and localization packages.
|
|
129
|
-
|
|
130
|
-
- Updated dependencies
|
|
131
|
-
- @arikajs/auth@0.0.5
|
|
132
|
-
- @arikajs/authorization@0.0.5
|
|
133
|
-
- @arikajs/cache@0.0.5
|
|
134
|
-
- @arikajs/cli@0.0.5
|
|
135
|
-
- @arikajs/console@0.0.5
|
|
136
|
-
- @arikajs/database@0.0.5
|
|
137
|
-
- @arikajs/dispatcher@0.0.5
|
|
138
|
-
- @arikajs/encryption@0.0.5
|
|
139
|
-
- @arikajs/events@0.0.5
|
|
140
|
-
- @arikajs/foundation@0.0.5
|
|
141
|
-
- @arikajs/http@0.0.5
|
|
142
|
-
- @arikajs/localization@0.0.5
|
|
143
|
-
- @arikajs/logging@0.0.5
|
|
144
|
-
- @arikajs/mail@0.0.5
|
|
145
|
-
- @arikajs/middleware@0.0.5
|
|
146
|
-
- @arikajs/queue@0.0.5
|
|
147
|
-
- @arikajs/router@0.0.5
|
|
148
|
-
- @arikajs/scheduler@0.0.5
|
|
149
|
-
- @arikajs/session@0.0.5
|
|
150
|
-
- @arikajs/storage@0.0.5
|
|
151
|
-
- @arikajs/validation@0.0.5
|
|
152
|
-
- @arikajs/view@0.0.5
|
package/src/Application.ts
DELETED
|
@@ -1,248 +0,0 @@
|
|
|
1
|
-
import { Application as FoundationApplication } from '@arikajs/foundation';
|
|
2
|
-
import { Router, Route } from '@arikajs/router';
|
|
3
|
-
import { FrameworkServiceProvider } from './providers/FrameworkServiceProvider';
|
|
4
|
-
import { Log } from '@arikajs/logging';
|
|
5
|
-
import { Application as ApplicationContract } from './Contracts/Application';
|
|
6
|
-
import { setApp } from './helpers';
|
|
7
|
-
|
|
8
|
-
export class Application extends FoundationApplication implements ApplicationContract {
|
|
9
|
-
public static get VERSION(): string {
|
|
10
|
-
try {
|
|
11
|
-
// Find the version from the local package.json
|
|
12
|
-
return require('../package.json').version;
|
|
13
|
-
} catch (e) {
|
|
14
|
-
try {
|
|
15
|
-
// Fallback if running in a different environment
|
|
16
|
-
return require('../../package.json').version;
|
|
17
|
-
} catch (e) {
|
|
18
|
-
return 'unknown';
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
protected router: Router;
|
|
24
|
-
protected server?: any;
|
|
25
|
-
protected isTerminating: boolean = false;
|
|
26
|
-
|
|
27
|
-
constructor(basePath: string = process.cwd()) {
|
|
28
|
-
super(basePath);
|
|
29
|
-
setApp(this);
|
|
30
|
-
|
|
31
|
-
// Initialize Core Components
|
|
32
|
-
this.router = new Router(this.getContainer());
|
|
33
|
-
|
|
34
|
-
// Register within container
|
|
35
|
-
this.instance(Router, this.router);
|
|
36
|
-
|
|
37
|
-
// Register Core Framework Provider
|
|
38
|
-
this.register(FrameworkServiceProvider);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
public async boot(): Promise<void> {
|
|
42
|
-
if (this.isBooted()) return;
|
|
43
|
-
await super.boot();
|
|
44
|
-
(this.router as any).sync();
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
public version(): string {
|
|
48
|
-
return Application.VERSION;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Map a GET route.
|
|
53
|
-
*/
|
|
54
|
-
public get(path: string, handler: any) {
|
|
55
|
-
return Route.get(path, handler);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Map a POST route.
|
|
60
|
-
*/
|
|
61
|
-
public post(path: string, handler: any) {
|
|
62
|
-
return Route.post(path, handler);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Map a PUT route.
|
|
67
|
-
*/
|
|
68
|
-
public put(path: string, handler: any) {
|
|
69
|
-
return Route.put(path, handler);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
public patch(path: string, handler: any) {
|
|
73
|
-
return Route.patch(path, handler);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Map a DELETE route.
|
|
78
|
-
*/
|
|
79
|
-
public delete(path: string, handler: any) {
|
|
80
|
-
return Route.delete(path, handler);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
public options(path: string, handler: any) {
|
|
84
|
-
return Route.options(path, handler);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
public match(methods: string[], path: string, handler: any) {
|
|
88
|
-
return Route.match(methods, path, handler);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Start the HTTP server.
|
|
93
|
-
*/
|
|
94
|
-
public async listen(port: number = 3000) {
|
|
95
|
-
if (!this.isBooted()) {
|
|
96
|
-
await this.boot();
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const http = await import('node:http');
|
|
100
|
-
const { Request, Response } = await import('@arikajs/http');
|
|
101
|
-
const { Kernel } = await import('./http/Kernel');
|
|
102
|
-
|
|
103
|
-
// Resolve Kernel from the container
|
|
104
|
-
const kernel = this.make(Kernel);
|
|
105
|
-
const callback = this.getCallback();
|
|
106
|
-
|
|
107
|
-
this.server = http.createServer(callback);
|
|
108
|
-
|
|
109
|
-
// Graceful shutdown
|
|
110
|
-
const shutdown = () => this.terminate();
|
|
111
|
-
process.on('SIGINT', shutdown);
|
|
112
|
-
process.on('SIGTERM', shutdown);
|
|
113
|
-
|
|
114
|
-
return new Promise<void>((resolve) => {
|
|
115
|
-
this.server.listen(port, () => {
|
|
116
|
-
this.displayBanner(port);
|
|
117
|
-
resolve();
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
protected displayBanner(port: number) {
|
|
123
|
-
const env = this.config().get('app.env', 'development');
|
|
124
|
-
|
|
125
|
-
console.log(`\x1b[38;5;99m
|
|
126
|
-
_ _ _ _ ____
|
|
127
|
-
/ \\ _ __(_) | ____ _ | / ___|
|
|
128
|
-
/ _ \\ | '__| | |/ / _\` | | \\___ \\
|
|
129
|
-
/ ___ \\| | | | < (_| | __| |___) |
|
|
130
|
-
/_/ \\_\\_| |_|_|\\_\\__,_| |____|____/
|
|
131
|
-
\x1b[0m`);
|
|
132
|
-
console.log(` \x1b[1mArikaJS Framework\x1b[0m \x1b[38;5;99mv${this.version()}\x1b[0m`);
|
|
133
|
-
console.log(` \x1b[90mEnvironment:\x1b[0m \x1b[33m${env}\x1b[0m`);
|
|
134
|
-
console.log(` \x1b[90mLocal URL:\x1b[0m \x1b[36mhttp://localhost:${port}\x1b[0m`);
|
|
135
|
-
console.log('');
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Get the HTTP server callback for raw http.createServer() usage.
|
|
140
|
-
*/
|
|
141
|
-
public getCallback() {
|
|
142
|
-
if (!this.isBooted()) {
|
|
143
|
-
throw new Error('Application must be booted before calling getCallback()');
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
const { Kernel } = require('./http/Kernel');
|
|
147
|
-
const kernel = this.make(Kernel);
|
|
148
|
-
const { ObjectPool } = require('@arikajs/foundation');
|
|
149
|
-
const { Request: ArikaRequest, Response: ArikaResponse, RawResponse } = require('@arikajs/http');
|
|
150
|
-
|
|
151
|
-
const requestPool = new ObjectPool(
|
|
152
|
-
() => new (ArikaRequest as any)(this, null),
|
|
153
|
-
(obj: any) => obj.reset(null)
|
|
154
|
-
);
|
|
155
|
-
const responsePool = new ObjectPool(
|
|
156
|
-
() => new (ArikaResponse as any)(null),
|
|
157
|
-
(obj: any) => obj.reset(null)
|
|
158
|
-
);
|
|
159
|
-
|
|
160
|
-
return (req: any, res: any) => {
|
|
161
|
-
const request = requestPool.acquire();
|
|
162
|
-
const response = responsePool.acquire();
|
|
163
|
-
request.reset(req);
|
|
164
|
-
response.reset(res);
|
|
165
|
-
|
|
166
|
-
const handleRequest = async () => {
|
|
167
|
-
try {
|
|
168
|
-
const finalResponse = await (kernel as any).handle(request, response);
|
|
169
|
-
(kernel as any).terminate(request, finalResponse);
|
|
170
|
-
} catch (error: any) {
|
|
171
|
-
if (!res.headersSent) {
|
|
172
|
-
res.writeHead(500, { 'Content-Type': 'application/json' });
|
|
173
|
-
res.end(JSON.stringify({ error: 'Internal Server Error', message: error.message }));
|
|
174
|
-
}
|
|
175
|
-
} finally {
|
|
176
|
-
requestPool.release(request);
|
|
177
|
-
responsePool.release(response);
|
|
178
|
-
}
|
|
179
|
-
};
|
|
180
|
-
handleRequest();
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Gracefully terminate the application.
|
|
186
|
-
*/
|
|
187
|
-
public async terminate() {
|
|
188
|
-
if (this.isTerminating) return;
|
|
189
|
-
this.isTerminating = true;
|
|
190
|
-
|
|
191
|
-
if (this.server) {
|
|
192
|
-
// Close all active connections to speed up shutdown (Node 18.2+)
|
|
193
|
-
if (typeof this.server.closeAllConnections === 'function') {
|
|
194
|
-
this.server.closeAllConnections();
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
// Force close idle connections
|
|
198
|
-
if (typeof this.server.closeIdleConnections === 'function') {
|
|
199
|
-
this.server.closeIdleConnections();
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
await new Promise<void>((resolve) => {
|
|
203
|
-
// Set a timeout to force resolve if server doesn't close in time
|
|
204
|
-
const timeout = setTimeout(() => {
|
|
205
|
-
Log.warning('HTTP server forced to close due to timeout.');
|
|
206
|
-
resolve();
|
|
207
|
-
}, 1000);
|
|
208
|
-
|
|
209
|
-
this.server.close(() => {
|
|
210
|
-
clearTimeout(timeout);
|
|
211
|
-
Log.info('HTTP server closed.');
|
|
212
|
-
resolve();
|
|
213
|
-
});
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
// Close database connections
|
|
218
|
-
if (this.has('db')) {
|
|
219
|
-
try {
|
|
220
|
-
const db = this.make<any>('db');
|
|
221
|
-
if (typeof db.closeAll === 'function') {
|
|
222
|
-
await db.closeAll();
|
|
223
|
-
}
|
|
224
|
-
} catch (e) { }
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
// Potential for other service termination (Queues, etc.)
|
|
228
|
-
|
|
229
|
-
// Remove signal listeners to prevent double triggers during exit
|
|
230
|
-
process.removeAllListeners('SIGINT');
|
|
231
|
-
process.removeAllListeners('SIGTERM');
|
|
232
|
-
|
|
233
|
-
// If we are in a testing or specific environment, we might not want to exit
|
|
234
|
-
if (process.env.NODE_ENV !== 'test') {
|
|
235
|
-
// Give a short delay for logs to flush before exiting
|
|
236
|
-
setTimeout(() => {
|
|
237
|
-
process.exit(0);
|
|
238
|
-
}, 50);
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* Get the router instance.
|
|
244
|
-
*/
|
|
245
|
-
public getRouter(): Router {
|
|
246
|
-
return this.router;
|
|
247
|
-
}
|
|
248
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { Router } from '@arikajs/router';
|
|
3
|
-
import { Application as HttpApplicationContract } from '@arikajs/http';
|
|
4
|
-
|
|
5
|
-
export interface Application extends HttpApplicationContract {
|
|
6
|
-
getRouter(): Router;
|
|
7
|
-
getContainer(): any;
|
|
8
|
-
getBasePath(): string;
|
|
9
|
-
make<T = any>(token: any): T;
|
|
10
|
-
singleton<T = any>(token: any, factory: any): void;
|
|
11
|
-
instance<T = any>(token: any, value: T): void;
|
|
12
|
-
bind<T = any>(token: any, factory: any): void;
|
|
13
|
-
resolve<T = any>(token: any): T;
|
|
14
|
-
has(token: any): boolean;
|
|
15
|
-
alias(token: any, alias: any): void;
|
|
16
|
-
tag(token: any, tag: string): void;
|
|
17
|
-
tagged<T = any>(tag: string): T[];
|
|
18
|
-
extend<T = any>(token: any, callback: (instance: T) => T): void;
|
|
19
|
-
register(provider: any): void;
|
|
20
|
-
boot(): Promise<void>;
|
|
21
|
-
run(): Promise<void>;
|
|
22
|
-
terminate(): Promise<void>;
|
|
23
|
-
isBooted(): boolean;
|
|
24
|
-
}
|
package/src/createApp.ts
DELETED
package/src/facades/Schedule.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { app } from '../helpers.js';
|
|
2
|
-
import { Scheduler, Schedule as BaseSchedule } from '@arikajs/scheduler';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* The amazing Laravel-like static Schedule Facade.
|
|
6
|
-
* This completely eliminates the need for developers to manually resolve
|
|
7
|
-
* the Scheduler from the container or wrap their events in `.define()`!
|
|
8
|
-
*/
|
|
9
|
-
export const Schedule = new Proxy({} as BaseSchedule, {
|
|
10
|
-
get(target, prop) {
|
|
11
|
-
// Automatically inject and resolve the underlying Scheduler singleton on demand
|
|
12
|
-
const scheduler = app().make(Scheduler) as Scheduler;
|
|
13
|
-
|
|
14
|
-
// Expose the raw schedule builder instance
|
|
15
|
-
const underlyingSchedule = (scheduler as any).schedule as BaseSchedule;
|
|
16
|
-
|
|
17
|
-
const value = (underlyingSchedule as any)[prop];
|
|
18
|
-
|
|
19
|
-
// If it's a builder method (like .call() or .command()), bind it perfectly
|
|
20
|
-
if (typeof value === 'function') {
|
|
21
|
-
return value.bind(underlyingSchedule);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return value;
|
|
25
|
-
}
|
|
26
|
-
});
|
package/src/helpers.ts
DELETED
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { Application } from './Application';
|
|
3
|
-
import { Route } from '@arikajs/router';
|
|
4
|
-
import { Log } from '@arikajs/logging';
|
|
5
|
-
import { Translator } from '@arikajs/localization';
|
|
6
|
-
import { env as configEnv } from '@arikajs/config';
|
|
7
|
-
import { carbon as carbonFactory } from '@arikajs/carbon';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Get the application instance.
|
|
11
|
-
*/
|
|
12
|
-
let appInstance: Application | null = null;
|
|
13
|
-
|
|
14
|
-
export function setApp(app: Application) {
|
|
15
|
-
appInstance = app;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function app(): Application {
|
|
19
|
-
if (!appInstance) {
|
|
20
|
-
throw new Error('Application instance not set.');
|
|
21
|
-
}
|
|
22
|
-
return appInstance;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Get a configuration value.
|
|
27
|
-
*/
|
|
28
|
-
export function config<T = any>(key?: string, defaultValue: T = null as any): T {
|
|
29
|
-
const repository = app().config();
|
|
30
|
-
if (!key) return repository as any;
|
|
31
|
-
return repository.get(key, defaultValue);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Get an environment variable.
|
|
36
|
-
*/
|
|
37
|
-
export function env<T = any>(key: string, defaultValue?: T): T {
|
|
38
|
-
return configEnv(key, defaultValue);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Log an info message.
|
|
43
|
-
*/
|
|
44
|
-
export function info(message: string, context: any = {}) {
|
|
45
|
-
Log.info(message, context);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Log an error message.
|
|
50
|
-
*/
|
|
51
|
-
export function error(message: string, context: any = {}) {
|
|
52
|
-
Log.error(message, context);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Log a warning message.
|
|
57
|
-
*/
|
|
58
|
-
export function warning(message: string, context: any = {}) {
|
|
59
|
-
Log.warning(message, context);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Log a debug message.
|
|
64
|
-
*/
|
|
65
|
-
export function debug(message: string, context: any = {}) {
|
|
66
|
-
Log.debug(message, context);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Generate a URL for a named route.
|
|
71
|
-
*/
|
|
72
|
-
export function route(name: string, params: any = {}): string {
|
|
73
|
-
return app().getRouter().route(name, params);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Translate the given message.
|
|
78
|
-
*/
|
|
79
|
-
export function lang(key: string, replace: Record<string, any> = {}, locale: string | null = null): string {
|
|
80
|
-
return (app().make(Translator) as Translator).get(key, replace, locale);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// Alias for common patterns
|
|
84
|
-
export const trans = lang;
|
|
85
|
-
export const __ = lang;
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Get the current request instance.
|
|
89
|
-
*/
|
|
90
|
-
export function request(): any {
|
|
91
|
-
return (app() as any).currentRequest;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Get the current auth context or manager.
|
|
96
|
-
*/
|
|
97
|
-
export function auth(): any {
|
|
98
|
-
const req = request();
|
|
99
|
-
if (req && req.auth) {
|
|
100
|
-
return req.auth;
|
|
101
|
-
}
|
|
102
|
-
return app().make('auth');
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Render a view template or get the view engine.
|
|
107
|
-
*/
|
|
108
|
-
export async function view(template?: string, data: any = {}): Promise<any> {
|
|
109
|
-
const req = request();
|
|
110
|
-
|
|
111
|
-
// 1. If we are in a request context and req.view.render exists, use it!
|
|
112
|
-
// This is the preferred way as it handles session errors, CSRF, etc. correctly
|
|
113
|
-
if (req && req.view && typeof req.view.render === 'function') {
|
|
114
|
-
if (template === undefined) return req.view;
|
|
115
|
-
return await req.view.render(template, data);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// 2. Fallback to global view engine
|
|
119
|
-
const engine = app().make('view') as any;
|
|
120
|
-
if (template === undefined) return engine;
|
|
121
|
-
|
|
122
|
-
return await engine.render(template, data);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Create a new Carbon instance for date manipulation.
|
|
127
|
-
*/
|
|
128
|
-
export function carbon(date?: any): any {
|
|
129
|
-
return carbonFactory(date);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Format the given date.
|
|
134
|
-
*/
|
|
135
|
-
export function date(date?: any, format = 'Y-m-d'): string {
|
|
136
|
-
return carbon(date).format(format);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// Add properties to support view.render() and view.share() as seen in the README
|
|
140
|
-
view.render = (template: string, data: any = {}) => {
|
|
141
|
-
return (app().make('view') as any).render(template, data);
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
view.share = (key: string, value: any) => {
|
|
145
|
-
return (app().make('view') as any).share(key, value);
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
view.composer = (template: string, callback: any) => {
|
|
149
|
-
return (app().make('view') as any).composer(template, callback);
|
|
150
|
-
};
|