@arikajs/http 0.0.1

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 (43) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +235 -0
  3. package/dist/Contracts/Application.d.ts +9 -0
  4. package/dist/Contracts/Application.d.ts.map +1 -0
  5. package/dist/Contracts/Application.js +3 -0
  6. package/dist/Contracts/Application.js.map +1 -0
  7. package/dist/Exceptions/HttpException.d.ts +16 -0
  8. package/dist/Exceptions/HttpException.d.ts.map +1 -0
  9. package/dist/Exceptions/HttpException.js +37 -0
  10. package/dist/Exceptions/HttpException.js.map +1 -0
  11. package/dist/Middleware/BodyParserMiddleware.d.ts +14 -0
  12. package/dist/Middleware/BodyParserMiddleware.d.ts.map +1 -0
  13. package/dist/Middleware/BodyParserMiddleware.js +62 -0
  14. package/dist/Middleware/BodyParserMiddleware.js.map +1 -0
  15. package/dist/Middleware/ConvertEmptyStringsToNull.d.ts +18 -0
  16. package/dist/Middleware/ConvertEmptyStringsToNull.d.ts.map +1 -0
  17. package/dist/Middleware/ConvertEmptyStringsToNull.js +34 -0
  18. package/dist/Middleware/ConvertEmptyStringsToNull.js.map +1 -0
  19. package/dist/Middleware/CorsMiddleware.d.ts +14 -0
  20. package/dist/Middleware/CorsMiddleware.d.ts.map +1 -0
  21. package/dist/Middleware/CorsMiddleware.js +30 -0
  22. package/dist/Middleware/CorsMiddleware.js.map +1 -0
  23. package/dist/Middleware/TrimStrings.d.ts +22 -0
  24. package/dist/Middleware/TrimStrings.d.ts.map +1 -0
  25. package/dist/Middleware/TrimStrings.js +46 -0
  26. package/dist/Middleware/TrimStrings.js.map +1 -0
  27. package/dist/Middleware.d.ts +16 -0
  28. package/dist/Middleware.d.ts.map +1 -0
  29. package/dist/Middleware.js +3 -0
  30. package/dist/Middleware.js.map +1 -0
  31. package/dist/Request.d.ts +81 -0
  32. package/dist/Request.d.ts.map +1 -0
  33. package/dist/Request.js +176 -0
  34. package/dist/Request.js.map +1 -0
  35. package/dist/Response.d.ts +72 -0
  36. package/dist/Response.d.ts.map +1 -0
  37. package/dist/Response.js +166 -0
  38. package/dist/Response.js.map +1 -0
  39. package/dist/index.d.ts +10 -0
  40. package/dist/index.d.ts.map +1 -0
  41. package/dist/index.js +26 -0
  42. package/dist/index.js.map +1 -0
  43. package/package.json +38 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ArikaJs
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,235 @@
1
+ # Arika HTTP
2
+
3
+ `@arikajs/http` is the **web engine** for the ArikaJS ecosystem.
4
+
5
+ Arika HTTP provides a native, framework-controlled HTTP layer that sits directly on top of Node.js HTTP primitives. It handles the request lifecycle, routing, and middleware without relying on external frameworks like Express or Fastify.
6
+
7
+ If the following works cleanly, the HTTP layer is considered correct:
8
+
9
+ ```ts
10
+ const app = new Application(basePath);
11
+ const kernel = new HttpKernel(app);
12
+
13
+ const server = http.createServer((req, res) => {
14
+ kernel.handle(req, res);
15
+ });
16
+
17
+ server.listen(3000);
18
+ ```
19
+
20
+ ---
21
+
22
+ ### Status
23
+
24
+ - **Stage**: Experimental / v0.x
25
+ - **Scope (v0.x)**:
26
+ - HTTP Kernel (Request/Response lifecycle)
27
+ - Router (RESTful routing, route parameters)
28
+ - Middleware system (Pipeline pattern)
29
+ - Request & Response abstractions (Fluent API)
30
+ - Controller resolution via Service Container
31
+ - **Out of scope (for this package)**:
32
+ - WebSocket support
33
+ - Session/Cookie persistence (contracts only)
34
+ - CSRF/Security headers (middleware only)
35
+ - File upload parsing (use middleware)
36
+
37
+ ---
38
+
39
+ ## Features
40
+
41
+ - **HTTP Kernel**
42
+ - Central entry point for all HTTP requests
43
+ - Implements the Foundation `Kernel` contract
44
+ - Manages the global middleware stack
45
+
46
+ - **Powerful Routing**
47
+ - Express-like routing API (`get`, `post`, `put`, `delete`)
48
+ - Route parameters (e.g., `/user/:id`)
49
+ - Route-specific middleware
50
+ - Controller resolution directly from the DI container
51
+
52
+ - **Middleware Pipeline**
53
+ - Chainable middleware execution
54
+ - Supports both class-based and closure-based middleware
55
+ - Short-circuiting for authentication and validation
56
+
57
+ - **Request & Response**
58
+ - Immutable `Request` wrapper for Node's `IncomingMessage`
59
+ - Fluent `Response` builder for Node's `ServerResponse`
60
+ - JSON-first responses and status code helpers
61
+
62
+ ---
63
+
64
+ ## Installation
65
+
66
+ ```bash
67
+ npm install @arikajs/http
68
+ # or
69
+ yarn add @arikajs/http
70
+ # or
71
+ pnpm add @arikajs/http
72
+ ```
73
+
74
+ This package requires `@arikajs/foundation` as a peer dependency.
75
+
76
+ ---
77
+
78
+ ## Quick Start
79
+
80
+ ### 1. Define a Controller
81
+
82
+ ```ts
83
+ class UserController {
84
+ async show(request: Request, id: string) {
85
+ return { id, name: 'John Doe' };
86
+ }
87
+ }
88
+ ```
89
+
90
+ ### 2. Configure the Router
91
+
92
+ ```ts
93
+ import { Router } from '@arikajs/http';
94
+
95
+ const router = new Router();
96
+
97
+ router.get('/users/:id', [UserController, 'show']);
98
+ ```
99
+
100
+ ### 3. Initialize the Kernel and Server
101
+
102
+ ```ts
103
+ import { Application } from '@arikajs/foundation';
104
+ import { HttpKernel } from '@arikajs/http';
105
+ import http from 'node:http';
106
+
107
+ const app = new Application(__dirname);
108
+ const kernel = new HttpKernel(app);
109
+
110
+ // Register routes if needed via a Service Provider or direct injection
111
+ kernel.getRouter().get('/', (req) => ({ hello: 'arika' }));
112
+
113
+ const server = http.createServer((req, res) => {
114
+ kernel.handle(req, res);
115
+ });
116
+
117
+ server.listen(3000);
118
+ ```
119
+
120
+ ---
121
+
122
+ ## Http Kernel
123
+
124
+ The `HttpKernel` is the "heart" of your web application. It receives a Node.js request and response, and coordinates the entire framework lifecycle to produce an output.
125
+
126
+ Core responsibilities:
127
+ - Bootstrapping the application if not already booted
128
+ - Converting Node.js primitives into Arika `Request` and `Response` objects
129
+ - Sending the request through the global middleware pipeline
130
+ - Dispatching the request to the Router
131
+
132
+ ---
133
+
134
+ ## Router
135
+
136
+ The Arika Router allows you to define your application's routes using a simple, expressive API.
137
+
138
+ ### Basic Routing
139
+ ```ts
140
+ router.get('/hello', (request) => 'Hello World');
141
+ router.post('/data', async (request) => {
142
+ const body = await request.body();
143
+ return { received: body };
144
+ });
145
+ ```
146
+
147
+ ### Route Parameters
148
+ ```ts
149
+ router.get('/posts/:slug', (request, slug) => {
150
+ return `Viewing post: ${slug}`;
151
+ });
152
+ ```
153
+
154
+ ---
155
+
156
+ ## Middleware
157
+
158
+ Middleware provide a convenient mechanism for inspecting and filtering HTTP requests entering your application.
159
+
160
+ ### Class-based Middleware
161
+ ```ts
162
+ import { Middleware, Request, Response } from '@arikajs/http';
163
+
164
+ class AuthMiddleware implements Middleware {
165
+ async handle(request: Request, next: Function): Promise<Response> {
166
+ if (!request.header('Authorization')) {
167
+ return new Response().status(401).json({ error: 'Unauthorized' });
168
+ }
169
+ return next(request);
170
+ }
171
+ }
172
+ ```
173
+
174
+ ---
175
+
176
+ ## Request & Response
177
+
178
+ ### Request
179
+ The `Request` object provides a clean API for interacting with the current HTTP request.
180
+
181
+ ```ts
182
+ request.path(); // /users/1
183
+ request.method(); // GET
184
+ request.baseUrl(); // http://localhost:3000 (uses Host header or config.app.url)
185
+ request.query('page'); // ?page=1
186
+ request.header('Content-Type');
187
+ request.all(); // combined input
188
+ ```
189
+
190
+ ### Response
191
+ The `Response` object allows you to build a response using a fluent interface.
192
+
193
+ ```ts
194
+ return response
195
+ .status(201)
196
+ .header('X-Custom', 'Value')
197
+ .json({ created: true });
198
+ ```
199
+
200
+ ---
201
+
202
+ ## Project Structure (recommended)
203
+
204
+ - `src/`
205
+ - `HttpKernel.ts` – The main HTTP entry point
206
+ - `Router.ts` – The route collection and dispatcher
207
+ - `Request.ts` – HTTP Request abstraction
208
+ - `Response.ts` – HTTP Response builder
209
+ - `Pipeline.ts` – Middleware execution engine
210
+ - `Middleware/` – Built-in middleware (e.g., BodyParser)
211
+ - `index.ts` – Public exports
212
+ - `tests/` – Unit tests for the HTTP layer
213
+
214
+ ---
215
+
216
+ ## Versioning & Stability
217
+
218
+ - While in **v0.x**, the API may change between minor versions.
219
+ - Post **v1.0**, we will follow **semver** strictly.
220
+ - `@arikajs/http` aims to maintain a stable contract with `@arikajs/foundation`.
221
+
222
+ ---
223
+
224
+ ## Contributing
225
+
226
+ Contributions are welcome! Please check the issues or submit a pull request for:
227
+ - Router optimizations
228
+ - New built-in middleware
229
+ - Improved Request/Response helper methods
230
+
231
+ ---
232
+
233
+ ## License
234
+
235
+ `@arikajs/http` is open-sourced software licensed under the **MIT license**.
@@ -0,0 +1,9 @@
1
+ export interface Application {
2
+ config(): any;
3
+ isBooted(): boolean;
4
+ boot(): Promise<void>;
5
+ make<T = any>(token: any): T;
6
+ singleton<T = any>(token: any, factory: any): void;
7
+ getContainer(): any;
8
+ }
9
+ //# sourceMappingURL=Application.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Application.d.ts","sourceRoot":"","sources":["../../src/Contracts/Application.ts"],"names":[],"mappings":"AACA,MAAM,WAAW,WAAW;IACxB,MAAM,IAAI,GAAG,CAAC;IACd,QAAQ,IAAI,OAAO,CAAC;IACpB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACtB,IAAI,CAAC,CAAC,GAAG,GAAG,EAAE,KAAK,EAAE,GAAG,GAAG,CAAC,CAAC;IAC7B,SAAS,CAAC,CAAC,GAAG,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,GAAG,IAAI,CAAC;IACnD,YAAY,IAAI,GAAG,CAAC;CACvB"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=Application.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Application.js","sourceRoot":"","sources":["../../src/Contracts/Application.ts"],"names":[],"mappings":""}
@@ -0,0 +1,16 @@
1
+ export declare class HttpException extends Error {
2
+ statusCode: number;
3
+ originalError: any;
4
+ constructor(statusCode: number, message: string, originalError?: any);
5
+ getStatusCode(): number;
6
+ }
7
+ export declare class NotFoundHttpException extends HttpException {
8
+ constructor(message?: string, originalError?: any);
9
+ }
10
+ export declare class MethodNotAllowedHttpException extends HttpException {
11
+ constructor(message?: string, originalError?: any);
12
+ }
13
+ export declare class UnauthorizedHttpException extends HttpException {
14
+ constructor(message?: string, originalError?: any);
15
+ }
16
+ //# sourceMappingURL=HttpException.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HttpException.d.ts","sourceRoot":"","sources":["../../src/Exceptions/HttpException.ts"],"names":[],"mappings":"AACA,qBAAa,aAAc,SAAQ,KAAK;IAEzB,UAAU,EAAE,MAAM;IAElB,aAAa,EAAE,GAAG;gBAFlB,UAAU,EAAE,MAAM,EACzB,OAAO,EAAE,MAAM,EACR,aAAa,GAAE,GAAU;IAM7B,aAAa,IAAI,MAAM;CAGjC;AAED,qBAAa,qBAAsB,SAAQ,aAAa;gBACxC,OAAO,GAAE,MAAoB,EAAE,aAAa,GAAE,GAAU;CAIvE;AAED,qBAAa,6BAA8B,SAAQ,aAAa;gBAChD,OAAO,GAAE,MAA6B,EAAE,aAAa,GAAE,GAAU;CAIhF;AAED,qBAAa,yBAA0B,SAAQ,aAAa;gBAC5C,OAAO,GAAE,MAAuB,EAAE,aAAa,GAAE,GAAU;CAI1E"}
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UnauthorizedHttpException = exports.MethodNotAllowedHttpException = exports.NotFoundHttpException = exports.HttpException = void 0;
4
+ class HttpException extends Error {
5
+ constructor(statusCode, message, originalError = null) {
6
+ super(message);
7
+ this.statusCode = statusCode;
8
+ this.originalError = originalError;
9
+ this.name = 'HttpException';
10
+ }
11
+ getStatusCode() {
12
+ return this.statusCode;
13
+ }
14
+ }
15
+ exports.HttpException = HttpException;
16
+ class NotFoundHttpException extends HttpException {
17
+ constructor(message = 'Not Found', originalError = null) {
18
+ super(404, message, originalError);
19
+ this.name = 'NotFoundHttpException';
20
+ }
21
+ }
22
+ exports.NotFoundHttpException = NotFoundHttpException;
23
+ class MethodNotAllowedHttpException extends HttpException {
24
+ constructor(message = 'Method Not Allowed', originalError = null) {
25
+ super(405, message, originalError);
26
+ this.name = 'MethodNotAllowedHttpException';
27
+ }
28
+ }
29
+ exports.MethodNotAllowedHttpException = MethodNotAllowedHttpException;
30
+ class UnauthorizedHttpException extends HttpException {
31
+ constructor(message = 'Unauthorized', originalError = null) {
32
+ super(401, message, originalError);
33
+ this.name = 'UnauthorizedHttpException';
34
+ }
35
+ }
36
+ exports.UnauthorizedHttpException = UnauthorizedHttpException;
37
+ //# sourceMappingURL=HttpException.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HttpException.js","sourceRoot":"","sources":["../../src/Exceptions/HttpException.ts"],"names":[],"mappings":";;;AACA,MAAa,aAAc,SAAQ,KAAK;IACpC,YACW,UAAkB,EACzB,OAAe,EACR,gBAAqB,IAAI;QAEhC,KAAK,CAAC,OAAO,CAAC,CAAC;QAJR,eAAU,GAAV,UAAU,CAAQ;QAElB,kBAAa,GAAb,aAAa,CAAY;QAGhC,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;IAChC,CAAC;IAEM,aAAa;QAChB,OAAO,IAAI,CAAC,UAAU,CAAC;IAC3B,CAAC;CACJ;AAbD,sCAaC;AAED,MAAa,qBAAsB,SAAQ,aAAa;IACpD,YAAY,UAAkB,WAAW,EAAE,gBAAqB,IAAI;QAChE,KAAK,CAAC,GAAG,EAAE,OAAO,EAAE,aAAa,CAAC,CAAC;QACnC,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;IACxC,CAAC;CACJ;AALD,sDAKC;AAED,MAAa,6BAA8B,SAAQ,aAAa;IAC5D,YAAY,UAAkB,oBAAoB,EAAE,gBAAqB,IAAI;QACzE,KAAK,CAAC,GAAG,EAAE,OAAO,EAAE,aAAa,CAAC,CAAC;QACnC,IAAI,CAAC,IAAI,GAAG,+BAA+B,CAAC;IAChD,CAAC;CACJ;AALD,sEAKC;AAED,MAAa,yBAA0B,SAAQ,aAAa;IACxD,YAAY,UAAkB,cAAc,EAAE,gBAAqB,IAAI;QACnE,KAAK,CAAC,GAAG,EAAE,OAAO,EAAE,aAAa,CAAC,CAAC;QACnC,IAAI,CAAC,IAAI,GAAG,2BAA2B,CAAC;IAC5C,CAAC;CACJ;AALD,8DAKC"}
@@ -0,0 +1,14 @@
1
+ import { Request } from '../Request';
2
+ import { Response } from '../Response';
3
+ import { Middleware } from '../Middleware';
4
+ export declare class BodyParserMiddleware implements Middleware {
5
+ /**
6
+ * Handle the incoming request.
7
+ */
8
+ handle(request: Request, next: (request: Request) => Promise<Response> | Response, response?: Response): Promise<Response>;
9
+ /**
10
+ * Parse the raw request stream.
11
+ */
12
+ private parseBody;
13
+ }
14
+ //# sourceMappingURL=BodyParserMiddleware.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BodyParserMiddleware.d.ts","sourceRoot":"","sources":["../../src/Middleware/BodyParserMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,qBAAa,oBAAqB,YAAW,UAAU;IACnD;;OAEG;IACG,MAAM,CACR,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,GAAG,QAAQ,EACxD,QAAQ,CAAC,EAAE,QAAQ,GACpB,OAAO,CAAC,QAAQ,CAAC;IAiBpB;;OAEG;IACH,OAAO,CAAC,SAAS;CAmCpB"}
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BodyParserMiddleware = void 0;
4
+ class BodyParserMiddleware {
5
+ /**
6
+ * Handle the incoming request.
7
+ */
8
+ async handle(request, next, response) {
9
+ const method = request.method();
10
+ const contentType = request.header('content-type');
11
+ // Only parse for methods that can have a body
12
+ if (['POST', 'PUT', 'PATCH', 'DELETE'].includes(method) && contentType) {
13
+ try {
14
+ const body = await this.parseBody(request);
15
+ request.setBody(body);
16
+ }
17
+ catch (error) {
18
+ // If parsing fails, we'll just continue with empty body
19
+ }
20
+ }
21
+ return next(request);
22
+ }
23
+ /**
24
+ * Parse the raw request stream.
25
+ */
26
+ parseBody(request) {
27
+ return new Promise((resolve, reject) => {
28
+ let body = '';
29
+ const req = request.getRaw();
30
+ req.on('data', (chunk) => {
31
+ body += chunk.toString();
32
+ });
33
+ req.on('end', () => {
34
+ const contentType = request.header('content-type');
35
+ if (contentType?.includes('application/json')) {
36
+ try {
37
+ resolve(JSON.parse(body || '{}'));
38
+ }
39
+ catch (e) {
40
+ reject(new Error('Invalid JSON'));
41
+ }
42
+ }
43
+ else if (contentType?.includes('application/x-www-form-urlencoded')) {
44
+ const params = new URLSearchParams(body);
45
+ const data = {};
46
+ params.forEach((value, key) => {
47
+ data[key] = value;
48
+ });
49
+ resolve(data);
50
+ }
51
+ else {
52
+ resolve({});
53
+ }
54
+ });
55
+ req.on('error', (err) => {
56
+ reject(err);
57
+ });
58
+ });
59
+ }
60
+ }
61
+ exports.BodyParserMiddleware = BodyParserMiddleware;
62
+ //# sourceMappingURL=BodyParserMiddleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BodyParserMiddleware.js","sourceRoot":"","sources":["../../src/Middleware/BodyParserMiddleware.ts"],"names":[],"mappings":";;;AAIA,MAAa,oBAAoB;IAC7B;;OAEG;IACH,KAAK,CAAC,MAAM,CACR,OAAgB,EAChB,IAAwD,EACxD,QAAmB;QAEnB,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;QAChC,MAAM,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,cAAc,CAAuB,CAAC;QAEzE,8CAA8C;QAC9C,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,WAAW,EAAE,CAAC;YACrE,IAAI,CAAC;gBACD,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;gBAC3C,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YAC1B,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACb,wDAAwD;YAC5D,CAAC;QACL,CAAC;QAED,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;IACzB,CAAC;IAED;;OAEG;IACK,SAAS,CAAC,OAAgB;QAC9B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACn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AC,CAAC;IACP,CAAC;CACJ;AA/DD,oDA+DC"}
@@ -0,0 +1,18 @@
1
+ import { Middleware } from '../Middleware';
2
+ import { Request } from '../Request';
3
+ import { Response } from '../Response';
4
+ /**
5
+ * Convert empty strings to null middleware.
6
+ * Automatically converts empty string inputs in the request body to null.
7
+ */
8
+ export declare class ConvertEmptyStringsToNull implements Middleware {
9
+ /**
10
+ * Handle an incoming request.
11
+ */
12
+ handle(request: Request, next: (request: Request) => Promise<Response> | Response): Promise<Response>;
13
+ /**
14
+ * Clean the given data.
15
+ */
16
+ protected clean(data: any): void;
17
+ }
18
+ //# sourceMappingURL=ConvertEmptyStringsToNull.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConvertEmptyStringsToNull.d.ts","sourceRoot":"","sources":["../../src/Middleware/ConvertEmptyStringsToNull.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC;;;GAGG;AACH,qBAAa,yBAA0B,YAAW,UAAU;IACxD;;OAEG;IACU,MAAM,CACf,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,GAAG,QAAQ,GACzD,OAAO,CAAC,QAAQ,CAAC;IAUpB;;OAEG;IACH,SAAS,CAAC,KAAK,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI;CASnC"}
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConvertEmptyStringsToNull = void 0;
4
+ /**
5
+ * Convert empty strings to null middleware.
6
+ * Automatically converts empty string inputs in the request body to null.
7
+ */
8
+ class ConvertEmptyStringsToNull {
9
+ /**
10
+ * Handle an incoming request.
11
+ */
12
+ async handle(request, next) {
13
+ const body = request.all();
14
+ if (body && typeof body === 'object') {
15
+ this.clean(body);
16
+ }
17
+ return next(request);
18
+ }
19
+ /**
20
+ * Clean the given data.
21
+ */
22
+ clean(data) {
23
+ for (const key in data) {
24
+ if (data[key] === '') {
25
+ data[key] = null;
26
+ }
27
+ else if (typeof data[key] === 'object' && data[key] !== null) {
28
+ this.clean(data[key]);
29
+ }
30
+ }
31
+ }
32
+ }
33
+ exports.ConvertEmptyStringsToNull = ConvertEmptyStringsToNull;
34
+ //# sourceMappingURL=ConvertEmptyStringsToNull.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConvertEmptyStringsToNull.js","sourceRoot":"","sources":["../../src/Middleware/ConvertEmptyStringsToNull.ts"],"names":[],"mappings":";;;AAIA;;;GAGG;AACH,MAAa,yBAAyB;IAClC;;OAEG;IACI,KAAK,CAAC,MAAM,CACf,OAAgB,EAChB,IAAwD;QAExD,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;QAE3B,IAAI,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;YACnC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACrB,CAAC;QAED,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;IACzB,CAAC;IAED;;OAEG;IACO,KAAK,CAAC,IAAS;QACrB,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;YACrB,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,CAAC;gBACnB,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;YACrB,CAAC;iBAAM,IAAI,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,QAAQ,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC;gBAC7D,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;YAC1B,CAAC;QACL,CAAC;IACL,CAAC;CACJ;AA7BD,8DA6BC"}
@@ -0,0 +1,14 @@
1
+ import { Request } from '../Request';
2
+ import { Response } from '../Response';
3
+ import { Middleware } from '../Middleware';
4
+ export declare class CorsMiddleware implements Middleware {
5
+ /**
6
+ * Handle the incoming request.
7
+ */
8
+ handle(request: Request, next: (request: Request) => Promise<Response> | Response, response?: Response): Promise<Response>;
9
+ /**
10
+ * Set the CORS headers on the response.
11
+ */
12
+ private setCorsHeaders;
13
+ }
14
+ //# sourceMappingURL=CorsMiddleware.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CorsMiddleware.d.ts","sourceRoot":"","sources":["../../src/Middleware/CorsMiddleware.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,qBAAa,cAAe,YAAW,UAAU;IAC7C;;OAEG;IACG,MAAM,CACR,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,GAAG,QAAQ,EACxD,QAAQ,CAAC,EAAE,QAAQ,GACpB,OAAO,CAAC,QAAQ,CAAC;IAapB;;OAEG;IACH,OAAO,CAAC,cAAc;CAKzB"}
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CorsMiddleware = void 0;
4
+ const Response_1 = require("../Response");
5
+ class CorsMiddleware {
6
+ /**
7
+ * Handle the incoming request.
8
+ */
9
+ async handle(request, next, response) {
10
+ // If it's an OPTIONS request (preflight), we can short-circuit
11
+ if (request.method() === 'OPTIONS') {
12
+ const res = response || new Response_1.Response(request.getRaw()); // Fallback though Kernel always passes response
13
+ this.setCorsHeaders(res);
14
+ return res.status(204).send('');
15
+ }
16
+ const res = await next(request);
17
+ this.setCorsHeaders(res);
18
+ return res;
19
+ }
20
+ /**
21
+ * Set the CORS headers on the response.
22
+ */
23
+ setCorsHeaders(response) {
24
+ response.header('Access-Control-Allow-Origin', '*');
25
+ response.header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, PATCH, OPTIONS');
26
+ response.header('Access-Control-Allow-Headers', 'Content-Type, Authorization, X-Requested-With');
27
+ }
28
+ }
29
+ exports.CorsMiddleware = CorsMiddleware;
30
+ //# sourceMappingURL=CorsMiddleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CorsMiddleware.js","sourceRoot":"","sources":["../../src/Middleware/CorsMiddleware.ts"],"names":[],"mappings":";;;AAEA,0CAAuC;AAGvC,MAAa,cAAc;IACvB;;OAEG;IACH,KAAK,CAAC,MAAM,CACR,OAAgB,EAChB,IAAwD,EACxD,QAAmB;QAEnB,+DAA+D;QAC/D,IAAI,OAAO,CAAC,MAAM,EAAE,KAAK,SAAS,EAAE,CAAC;YACjC,MAAM,GAAG,GAAG,QAAQ,IAAI,IAAI,mBAAQ,CAAC,OAAO,CAAC,MAAM,EAAS,CAAC,CAAC,CAAC,gDAAgD;YAC/G,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;YACzB,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACpC,CAAC;QAED,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,CAAC;QAChC,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;QACzB,OAAO,GAAG,CAAC;IACf,CAAC;IAED;;OAEG;IACK,cAAc,CAAC,QAAkB;QACrC,QAAQ,CAAC,MAAM,CAAC,6BAA6B,EAAE,GAAG,CAAC,CAAC;QACpD,QAAQ,CAAC,MAAM,CAAC,8BAA8B,EAAE,wCAAwC,CAAC,CAAC;QAC1F,QAAQ,CAAC,MAAM,CAAC,8BAA8B,EAAE,+CAA+C,CAAC,CAAC;IACrG,CAAC;CACJ;AA7BD,wCA6BC"}
@@ -0,0 +1,22 @@
1
+ import { Middleware } from '../Middleware';
2
+ import { Request } from '../Request';
3
+ import { Response } from '../Response';
4
+ /**
5
+ * Trim strings middleware.
6
+ * Automatically trims whitespace from all string inputs in the request body.
7
+ */
8
+ export declare class TrimStrings implements Middleware {
9
+ /**
10
+ * The names of the attributes that should not be trimmed.
11
+ */
12
+ protected except: string[];
13
+ /**
14
+ * Handle an incoming request.
15
+ */
16
+ handle(request: Request, next: (request: Request) => Promise<Response> | Response): Promise<Response>;
17
+ /**
18
+ * Clean the given data.
19
+ */
20
+ protected clean(data: any): void;
21
+ }
22
+ //# sourceMappingURL=TrimStrings.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TrimStrings.d.ts","sourceRoot":"","sources":["../../src/Middleware/TrimStrings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC;;;GAGG;AACH,qBAAa,WAAY,YAAW,UAAU;IAC1C;;OAEG;IACH,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,CAGxB;IAEF;;OAEG;IACU,MAAM,CACf,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,GAAG,QAAQ,GACzD,OAAO,CAAC,QAAQ,CAAC;IAUpB;;OAEG;IACH,SAAS,CAAC,KAAK,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI;CAanC"}
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TrimStrings = void 0;
4
+ /**
5
+ * Trim strings middleware.
6
+ * Automatically trims whitespace from all string inputs in the request body.
7
+ */
8
+ class TrimStrings {
9
+ constructor() {
10
+ /**
11
+ * The names of the attributes that should not be trimmed.
12
+ */
13
+ this.except = [
14
+ 'password',
15
+ 'password_confirmation',
16
+ ];
17
+ }
18
+ /**
19
+ * Handle an incoming request.
20
+ */
21
+ async handle(request, next) {
22
+ const body = request.all();
23
+ if (body && typeof body === 'object') {
24
+ this.clean(body);
25
+ }
26
+ return next(request);
27
+ }
28
+ /**
29
+ * Clean the given data.
30
+ */
31
+ clean(data) {
32
+ for (const key in data) {
33
+ if (this.except.includes(key)) {
34
+ continue;
35
+ }
36
+ if (typeof data[key] === 'string') {
37
+ data[key] = data[key].trim();
38
+ }
39
+ else if (typeof data[key] === 'object' && data[key] !== null) {
40
+ this.clean(data[key]);
41
+ }
42
+ }
43
+ }
44
+ }
45
+ exports.TrimStrings = TrimStrings;
46
+ //# sourceMappingURL=TrimStrings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TrimStrings.js","sourceRoot":"","sources":["../../src/Middleware/TrimStrings.ts"],"names":[],"mappings":";;;AAIA;;;GAGG;AACH,MAAa,WAAW;IAAxB;QACI;;WAEG;QACO,WAAM,GAAa;YACzB,UAAU;YACV,uBAAuB;SAC1B,CAAC;IAkCN,CAAC;IAhCG;;OAEG;IACI,KAAK,CAAC,MAAM,CACf,OAAgB,EAChB,IAAwD;QAExD,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;QAE3B,IAAI,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;YACnC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACrB,CAAC;QAED,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;IACzB,CAAC;IAED;;OAEG;IACO,KAAK,CAAC,IAAS;QACrB,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;YACrB,IAAI,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;gBAC5B,SAAS;YACb,CAAC;YAED,IAAI,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,QAAQ,EAAE,CAAC;gBAChC,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;YACjC,CAAC;iBAAM,IAAI,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,QAAQ,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC;gBAC7D,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;YAC1B,CAAC;QACL,CAAC;IACL,CAAC;CACJ;AAzCD,kCAyCC"}
@@ -0,0 +1,16 @@
1
+ import { Request } from './Request';
2
+ import { Response } from './Response';
3
+ /**
4
+ * Middleware contract for ArikaJS.
5
+ */
6
+ export interface Middleware {
7
+ /**
8
+ * Handle an incoming request.
9
+ */
10
+ handle(request: Request, next: (request: Request) => Promise<Response> | Response, response?: Response): Promise<Response> | Response;
11
+ }
12
+ /**
13
+ * Type for middleware that can be either a class or a function.
14
+ */
15
+ export type MiddlewareHandler = Middleware | ((request: Request, next: (request: Request) => Promise<Response> | Response, response?: Response) => Promise<Response> | Response);
16
+ //# sourceMappingURL=Middleware.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Middleware.d.ts","sourceRoot":"","sources":["../src/Middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC;;GAEG;AACH,MAAM,WAAW,UAAU;IACvB;;OAEG;IACH,MAAM,CACF,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,GAAG,QAAQ,EACxD,QAAQ,CAAC,EAAE,QAAQ,GACpB,OAAO,CAAC,QAAQ,CAAC,GAAG,QAAQ,CAAC;CACnC;AAED;;GAEG;AACH,MAAM,MAAM,iBAAiB,GACvB,UAAU,GACV,CAAC,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,GAAG,QAAQ,EAAE,QAAQ,CAAC,EAAE,QAAQ,KAAK,OAAO,CAAC,QAAQ,CAAC,GAAG,QAAQ,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=Middleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Middleware.js","sourceRoot":"","sources":["../src/Middleware.ts"],"names":[],"mappings":""}
@@ -0,0 +1,81 @@
1
+ import { Application } from './Contracts/Application';
2
+ import { IncomingMessage } from 'node:http';
3
+ export declare class Request {
4
+ private readonly app;
5
+ private readonly req;
6
+ private readonly searchParams;
7
+ private _cookies;
8
+ private _body;
9
+ private _params;
10
+ constructor(app: Application, req: IncomingMessage);
11
+ /**
12
+ * Get the base URL (scheme + host) of the request.
13
+ * Falls back to app.url config if host header is missing.
14
+ */
15
+ baseUrl(): string;
16
+ /**
17
+ * Get the application instance.
18
+ */
19
+ getApplication(): Application;
20
+ /**
21
+ * Get the underlying Node request.
22
+ */
23
+ getRaw(): IncomingMessage;
24
+ /**
25
+ * Get the HTTP method.
26
+ */
27
+ method(): string;
28
+ /**
29
+ * Get the request path.
30
+ */
31
+ path(): string;
32
+ /**
33
+ * Get all headers.
34
+ */
35
+ headers(): Record<string, string | string[] | undefined>;
36
+ /**
37
+ * Get a specific header.
38
+ */
39
+ header(name: string): string | string[] | undefined;
40
+ /**
41
+ * Get all cookies.
42
+ */
43
+ cookies(): Record<string, string | undefined>;
44
+ /**
45
+ * Get a specific cookie.
46
+ */
47
+ cookie(name: string): string | undefined;
48
+ /**
49
+ * Get a query parameter.
50
+ */
51
+ query(key: string): string | null;
52
+ /**
53
+ * Set the route parameters.
54
+ */
55
+ setParams(params: Record<string, string>): void;
56
+ /**
57
+ * Get all route parameters.
58
+ */
59
+ params(): Record<string, string>;
60
+ /**
61
+ * Get a specific route parameter.
62
+ */
63
+ param(key: string, defaultValue?: string | null): string | null;
64
+ /**
65
+ * Set the parsed body (usually set by middleware).
66
+ */
67
+ setBody(body: any): void;
68
+ /**
69
+ * Get an input value from route params, body, or query.
70
+ */
71
+ input(key: string, defaultValue?: any): any;
72
+ /**
73
+ * Get the parsed body.
74
+ */
75
+ body(): any;
76
+ /**
77
+ * Get all input (query + body).
78
+ */
79
+ all(): any;
80
+ }
81
+ //# sourceMappingURL=Request.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Request.d.ts","sourceRoot":"","sources":["../src/Request.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAI5C,qBAAa,OAAO;IAChB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAc;IAClC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAkB;IACtC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAkB;IAC/C,OAAO,CAAC,QAAQ,CAAmD;IACnE,OAAO,CAAC,KAAK,CAAa;IAC1B,OAAO,CAAC,OAAO,CAA8B;gBAEjC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,eAAe;IAQlD;;;OAGG;IACH,OAAO,IAAI,MAAM;IAYjB;;OAEG;IACH,cAAc,IAAI,WAAW;IAI7B;;OAEG;IACH,MAAM,IAAI,eAAe;IAIzB;;OAEG;IACH,MAAM,IAAI,MAAM;IAIhB;;OAEG;IACH,IAAI,IAAI,MAAM;IAKd;;OAEG;IACH,OAAO,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC;IAIxD;;OAEG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS;IAInD;;OAEG;IACH,OAAO,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAQ7C;;OAEG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAIxC;;OAEG;IACH,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAIjC;;OAEG;IACH,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI;IAI/C;;OAEG;IACH,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAIhC;;OAEG;IACH,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,YAAY,GAAE,MAAM,GAAG,IAAW,GAAG,MAAM,GAAG,IAAI;IAIrE;;OAEG;IACH,OAAO,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI;IAIxB;;OAEG;IACH,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,YAAY,GAAE,GAAU,GAAG,GAAG;IAejD;;OAEG;IACH,IAAI,IAAI,GAAG;IAIX;;OAEG;IACH,GAAG,IAAI,GAAG;CAKb"}
@@ -0,0 +1,176 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.Request = void 0;
37
+ const node_url_1 = require("node:url");
38
+ const cookie = __importStar(require("cookie"));
39
+ class Request {
40
+ constructor(app, req) {
41
+ this._cookies = null;
42
+ this._body = null;
43
+ this._params = {};
44
+ this.app = app;
45
+ this.req = req;
46
+ const fullUrl = `${this.baseUrl()}${req.url || '/'}`;
47
+ this.searchParams = new node_url_1.URL(fullUrl).searchParams;
48
+ }
49
+ /**
50
+ * Get the base URL (scheme + host) of the request.
51
+ * Falls back to app.url config if host header is missing.
52
+ */
53
+ baseUrl() {
54
+ const trustProxy = this.app.config().get('http.trustProxy', false);
55
+ const protocol = trustProxy ? (this.header('x-forwarded-proto') || 'http') : 'http';
56
+ const host = trustProxy ? (this.header('x-forwarded-host') || this.req.headers.host) : this.req.headers.host;
57
+ if (host) {
58
+ return `${protocol}://${host}`;
59
+ }
60
+ return this.app.config().get('app.url', 'http://localhost');
61
+ }
62
+ /**
63
+ * Get the application instance.
64
+ */
65
+ getApplication() {
66
+ return this.app;
67
+ }
68
+ /**
69
+ * Get the underlying Node request.
70
+ */
71
+ getRaw() {
72
+ return this.req;
73
+ }
74
+ /**
75
+ * Get the HTTP method.
76
+ */
77
+ method() {
78
+ return this.req.method || 'GET';
79
+ }
80
+ /**
81
+ * Get the request path.
82
+ */
83
+ path() {
84
+ const url = new node_url_1.URL(this.req.url || '/', `http://${this.req.headers.host || 'localhost'}`);
85
+ return url.pathname;
86
+ }
87
+ /**
88
+ * Get all headers.
89
+ */
90
+ headers() {
91
+ return this.req.headers;
92
+ }
93
+ /**
94
+ * Get a specific header.
95
+ */
96
+ header(name) {
97
+ return this.req.headers[name.toLowerCase()];
98
+ }
99
+ /**
100
+ * Get all cookies.
101
+ */
102
+ cookies() {
103
+ if (this._cookies === null) {
104
+ const cookieHeader = this.header('cookie');
105
+ this._cookies = typeof cookieHeader === 'string' ? cookie.parse(cookieHeader) : {};
106
+ }
107
+ return this._cookies;
108
+ }
109
+ /**
110
+ * Get a specific cookie.
111
+ */
112
+ cookie(name) {
113
+ return this.cookies()[name];
114
+ }
115
+ /**
116
+ * Get a query parameter.
117
+ */
118
+ query(key) {
119
+ return this.searchParams.get(key);
120
+ }
121
+ /**
122
+ * Set the route parameters.
123
+ */
124
+ setParams(params) {
125
+ this._params = params;
126
+ }
127
+ /**
128
+ * Get all route parameters.
129
+ */
130
+ params() {
131
+ return this._params;
132
+ }
133
+ /**
134
+ * Get a specific route parameter.
135
+ */
136
+ param(key, defaultValue = null) {
137
+ return this._params[key] ?? defaultValue;
138
+ }
139
+ /**
140
+ * Set the parsed body (usually set by middleware).
141
+ */
142
+ setBody(body) {
143
+ this._body = body;
144
+ }
145
+ /**
146
+ * Get an input value from route params, body, or query.
147
+ */
148
+ input(key, defaultValue = null) {
149
+ // 1. Check route parameters
150
+ if (this._params[key] !== undefined) {
151
+ return this._params[key];
152
+ }
153
+ // 2. Check body
154
+ if (this._body && typeof this._body === 'object' && key in this._body) {
155
+ return this._body[key];
156
+ }
157
+ // 3. Check query string
158
+ return this.query(key) ?? defaultValue;
159
+ }
160
+ /**
161
+ * Get the parsed body.
162
+ */
163
+ body() {
164
+ return this._body;
165
+ }
166
+ /**
167
+ * Get all input (query + body).
168
+ */
169
+ all() {
170
+ const query = Object.fromEntries(this.searchParams.entries());
171
+ const body = typeof this._body === 'object' && this._body !== null ? this._body : {};
172
+ return { ...query, ...body };
173
+ }
174
+ }
175
+ exports.Request = Request;
176
+ //# sourceMappingURL=Request.js.map
@@ -0,0 +1 @@
1
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IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;QACrF,OAAO,EAAE,GAAG,KAAK,EAAE,GAAG,IAAI,EAAE,CAAC;IACjC,CAAC;CACJ;AAjKD,0BAiKC"}
@@ -0,0 +1,72 @@
1
+ import { ServerResponse } from 'node:http';
2
+ import * as cookie from 'cookie';
3
+ export declare class Response {
4
+ private readonly res;
5
+ private _status;
6
+ private _headers;
7
+ private _cookies;
8
+ private _content;
9
+ constructor(res: ServerResponse);
10
+ /**
11
+ * Set the HTTP status code.
12
+ */
13
+ status(code: number): this;
14
+ /**
15
+ * Helper: 200 OK.
16
+ */
17
+ ok(): this;
18
+ /**
19
+ * Helper: 201 Created.
20
+ */
21
+ created(): this;
22
+ /**
23
+ * Helper: 204 No Content.
24
+ */
25
+ noContent(): this;
26
+ /**
27
+ * Helper: 403 Forbidden.
28
+ */
29
+ forbidden(): this;
30
+ /**
31
+ * Helper: 404 Not Found.
32
+ */
33
+ notFound(): this;
34
+ /**
35
+ * Set a header.
36
+ */
37
+ header(name: string, value: string | number | string[]): this;
38
+ /**
39
+ * Set a cookie.
40
+ */
41
+ cookie(name: string, value: string, options?: cookie.SerializeOptions): this;
42
+ /**
43
+ * Set the response content as JSON.
44
+ */
45
+ json(data: any): this;
46
+ /**
47
+ * Set the response content as plain text or HTML.
48
+ */
49
+ send(content: string | Buffer): this;
50
+ /**
51
+ * Set the response content.
52
+ */
53
+ setContent(content: string | Buffer): this;
54
+ /**
55
+ * Get the current content.
56
+ */
57
+ getContent(): string | Buffer | null;
58
+ /**
59
+ * Get the current status code.
60
+ */
61
+ getStatusCode(): number;
62
+ /**
63
+ * Get all currently set headers.
64
+ */
65
+ getHeaders(): Record<string, string | number | string[]>;
66
+ /**
67
+ * Actually terminate the request and send to client.
68
+ * This is called by the Kernel.
69
+ */
70
+ terminate(): void;
71
+ }
72
+ //# sourceMappingURL=Response.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Response.d.ts","sourceRoot":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AAC;IAIxD;;;OAGG;IACH,SAAS,IAAI,IAAI;CAqBpB"}
@@ -0,0 +1,166 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.Response = void 0;
37
+ const cookie = __importStar(require("cookie"));
38
+ class Response {
39
+ constructor(res) {
40
+ this._status = 200;
41
+ this._headers = {};
42
+ this._cookies = [];
43
+ this._content = null;
44
+ this.res = res;
45
+ }
46
+ /**
47
+ * Set the HTTP status code.
48
+ */
49
+ status(code) {
50
+ this._status = code;
51
+ return this;
52
+ }
53
+ /**
54
+ * Helper: 200 OK.
55
+ */
56
+ ok() {
57
+ return this.status(200);
58
+ }
59
+ /**
60
+ * Helper: 201 Created.
61
+ */
62
+ created() {
63
+ return this.status(201);
64
+ }
65
+ /**
66
+ * Helper: 204 No Content.
67
+ */
68
+ noContent() {
69
+ return this.status(204);
70
+ }
71
+ /**
72
+ * Helper: 403 Forbidden.
73
+ */
74
+ forbidden() {
75
+ return this.status(403);
76
+ }
77
+ /**
78
+ * Helper: 404 Not Found.
79
+ */
80
+ notFound() {
81
+ return this.status(404);
82
+ }
83
+ /**
84
+ * Set a header.
85
+ */
86
+ header(name, value) {
87
+ this._headers[name] = value;
88
+ return this;
89
+ }
90
+ /**
91
+ * Set a cookie.
92
+ */
93
+ cookie(name, value, options = {}) {
94
+ this._cookies.push(cookie.serialize(name, value, {
95
+ path: '/',
96
+ ...options
97
+ }));
98
+ return this;
99
+ }
100
+ /**
101
+ * Set the response content as JSON.
102
+ */
103
+ json(data) {
104
+ this._content = JSON.stringify(data);
105
+ this.header('Content-Type', 'application/json');
106
+ return this;
107
+ }
108
+ /**
109
+ * Set the response content as plain text or HTML.
110
+ */
111
+ send(content) {
112
+ this._content = content;
113
+ if (typeof content === 'string' && !this._headers['Content-Type']) {
114
+ this.header('Content-Type', content.startsWith('<') ? 'text/html' : 'text/plain');
115
+ }
116
+ return this;
117
+ }
118
+ /**
119
+ * Set the response content.
120
+ */
121
+ setContent(content) {
122
+ this._content = content;
123
+ return this;
124
+ }
125
+ /**
126
+ * Get the current content.
127
+ */
128
+ getContent() {
129
+ return this._content;
130
+ }
131
+ /**
132
+ * Get the current status code.
133
+ */
134
+ getStatusCode() {
135
+ return this._status;
136
+ }
137
+ /**
138
+ * Get all currently set headers.
139
+ */
140
+ getHeaders() {
141
+ return this._headers;
142
+ }
143
+ /**
144
+ * Actually terminate the request and send to client.
145
+ * This is called by the Kernel.
146
+ */
147
+ terminate() {
148
+ if (this.res.writableEnded) {
149
+ return;
150
+ }
151
+ // 1. Set Status
152
+ this.res.statusCode = this._status;
153
+ // 2. Set Headers
154
+ for (const [name, value] of Object.entries(this._headers)) {
155
+ this.res.setHeader(name, value);
156
+ }
157
+ // 3. Set Cookies
158
+ if (this._cookies.length > 0) {
159
+ this.res.setHeader('Set-Cookie', this._cookies);
160
+ }
161
+ // 4. Send body and end
162
+ this.res.end(this._content ?? '');
163
+ }
164
+ }
165
+ exports.Response = Response;
166
+ //# sourceMappingURL=Response.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Response.js","sourceRoot":"","sources":["../src/Response.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,+CAAiC;AAEjC,MAAa,QAAQ;IAOjB,YAAY,GAAmB;QALvB,YAAO,GAAW,GAAG,CAAC;QACtB,aAAQ,GAA+C,EAAE,CAAC;QAC1D,aAAQ,GAAa,EAAE,CAAC;QACxB,aAAQ,GAA2B,IAAI,CAAC;QAG5C,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACnB,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,IAAY;QACf,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QACpB,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;OAEG;IACH,EAAE;QACE,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAC5B,CAAC;IAED;;OAEG;IACH,OAAO;QACH,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAC5B,CAAC;IAED;;OAEG;IACH,SAAS;QACL,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAC5B,CAAC;IAED;;OAEG;IACH,SAAS;QACL,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAC5B,CAAC;IAED;;OAEG;IACH,QAAQ;QACJ,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAC5B,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,IAAY,EAAE,KAAiC;QAClD,IAAI,CAAC,QAAQ,CAAC,IAAI,CAA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SAAS;QACL,IAAI,IAAI,CAAC,GAAG,CAAC,aAAa,EAAE,CAAC;YACzB,OAAO;QACX,CAAC;QAED,gBAAgB;QAChB,IAAI,CAAC,GAAG,CAAC,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC;QAEnC,iBAAiB;QACjB,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;YACxD,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QACpC,CAAC;QAED,iBAAiB;QACjB,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC3B,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,YAAY,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;QACpD,CAAC;QAED,uBAAuB;QACvB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC;IACtC,CAAC;CACJ;AAnJD,4BAmJC"}
@@ -0,0 +1,10 @@
1
+ export * from './Request';
2
+ export * from './Response';
3
+ export * from './Middleware';
4
+ export * from './Middleware/BodyParserMiddleware';
5
+ export * from './Middleware/CorsMiddleware';
6
+ export * from './Middleware/TrimStrings';
7
+ export * from './Middleware/ConvertEmptyStringsToNull';
8
+ export * from './Exceptions/HttpException';
9
+ export * from './Contracts/Application';
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,mCAAmC,CAAC;AAClD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,0BAA0B,CAAC;AACzC,cAAc,wCAAwC,CAAC;AACvD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,yBAAyB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./Request"), exports);
18
+ __exportStar(require("./Response"), exports);
19
+ __exportStar(require("./Middleware"), exports);
20
+ __exportStar(require("./Middleware/BodyParserMiddleware"), exports);
21
+ __exportStar(require("./Middleware/CorsMiddleware"), exports);
22
+ __exportStar(require("./Middleware/TrimStrings"), exports);
23
+ __exportStar(require("./Middleware/ConvertEmptyStringsToNull"), exports);
24
+ __exportStar(require("./Exceptions/HttpException"), exports);
25
+ __exportStar(require("./Contracts/Application"), exports);
26
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B;AAC1B,6CAA2B;AAC3B,+CAA6B;AAC7B,oEAAkD;AAClD,8DAA4C;AAC5C,2DAAyC;AACzC,yEAAuD;AACvD,6DAA2C;AAC3C,0DAAwC"}
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@arikajs/http",
3
+ "version": "0.0.1",
4
+ "description": "Native HTTP layer for the ArikaJS framework.",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/arikajs/http.git"
8
+ },
9
+ "bugs": {
10
+ "url": "https://github.com/arikajs/http/issues"
11
+ },
12
+ "homepage": "https://github.com/arikajs/http#readme",
13
+ "license": "MIT",
14
+ "main": "dist/index.js",
15
+ "types": "dist/index.d.ts",
16
+ "scripts": {
17
+ "build": "tsc -p tsconfig.json",
18
+ "clean": "rm -rf dist",
19
+ "prepare": "echo skip",
20
+ "test": "npx tsx --test tests/*.test.ts",
21
+ "test:watch": "npx tsx --test --watch tests/*.test.ts"
22
+ },
23
+ "files": [
24
+ "dist"
25
+ ],
26
+ "engines": {
27
+ "node": ">=20.0.0"
28
+ },
29
+ "dependencies": {
30
+ "cookie": "^1.1.1"
31
+ },
32
+ "devDependencies": {
33
+ "@types/cookie": "^0.6.0",
34
+ "@types/node": "^20.11.24",
35
+ "typescript": "^5.3.3"
36
+ },
37
+ "author": "Prakash Tank"
38
+ }