@h3ravel/http 10.0.0 → 11.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,110 +1,21 @@
1
- import { IMiddleware, HttpContext, IRequest, IResponse } from '@h3ravel/shared';
2
- export { HttpContext } from '@h3ravel/shared';
3
- import { H3Event, EventHandlerRequest } from 'h3';
4
- import { DotNestedKeys, DotNestedValue } from '@h3ravel/support';
5
- import { TypedHeaders, ResponseHeaderMap } from 'fetchdts';
6
- import { Application, ServiceProvider } from '@h3ravel/core';
1
+ import { DotNestedKeys, DotNestedValue, HttpContext, HttpContext as HttpContext$1, IMiddleware, IRequest, IResponse } from "@h3ravel/shared";
2
+ import { EventHandlerRequest, H3Event } from "h3";
3
+ import { Application, ServiceProvider } from "@h3ravel/core";
4
+ import { ResponseHeaderMap, TypedHeaders } from "fetchdts";
7
5
 
6
+ //#region src/Middleware.d.ts
8
7
  declare abstract class Middleware implements IMiddleware {
9
- abstract handle(context: HttpContext, next: () => Promise<unknown>): Promise<unknown>;
8
+ abstract handle(context: HttpContext, next: () => Promise<unknown>): Promise<unknown>;
10
9
  }
11
-
12
- declare class Request implements IRequest {
13
- /**
14
- * The current app instance
15
- */
16
- app: Application;
17
- /**
18
- * Gets route parameters.
19
- * @returns An object containing route parameters.
20
- */
21
- readonly params: NonNullable<H3Event["context"]["params"]>;
22
- /**
23
- * Gets query parameters.
24
- * @returns An object containing query parameters.
25
- */
26
- readonly query: Record<string, string>;
27
- /**
28
- * Gets the request headers.
29
- * @returns An object containing request headers.
30
- */
31
- readonly headers: TypedHeaders<Record<keyof ResponseHeaderMap, string>>;
32
- /**
33
- * The current H3 H3Event instance
34
- */
35
- private readonly event;
36
- constructor(event: H3Event,
37
- /**
38
- * The current app instance
39
- */
40
- app: Application);
41
- /**
42
- * Get all input data (query + body).
43
- */
44
- all<T = Record<string, unknown>>(): Promise<T>;
45
- /**
46
- * Get a single input field from query or body.
47
- */
48
- input<T = unknown>(key: string, defaultValue?: T): Promise<T>;
49
- /**
50
- * Get the base event
51
- */
52
- getEvent(): H3Event;
53
- getEvent<K extends DotNestedKeys<H3Event>>(key: K): DotNestedValue<H3Event, K>;
54
- }
55
-
56
- declare class Response implements IResponse {
57
- /**
58
- * The current app instance
59
- */
60
- app: Application;
61
- /**
62
- * The current H3 H3Event instance
63
- */
64
- private readonly event;
65
- private statusCode;
66
- private headers;
67
- constructor(event: H3Event,
68
- /**
69
- * The current app instance
70
- */
71
- app: Application);
72
- /**
73
- * Set HTTP status code.
74
- */
75
- setStatusCode(code: number): this;
76
- /**
77
- * Set a header.
78
- */
79
- setHeader(name: string, value: string): this;
80
- html(content: string): string;
81
- /**
82
- * Send a JSON response.
83
- */
84
- json<T = unknown>(data: T): T;
85
- /**
86
- * Send plain text.
87
- */
88
- text(data: string): string;
89
- /**
90
- * Redirect to another URL.
91
- */
92
- redirect(url: string, status?: number): string;
93
- /**
94
- * Apply headers before sending response.
95
- */
96
- private applyHeaders;
97
- /**
98
- * Get the base event
99
- */
100
- getEvent(): H3Event;
101
- getEvent<K extends DotNestedKeys<H3Event>>(key: K): DotNestedValue<H3Event, K>;
102
- }
103
-
10
+ //#endregion
11
+ //#region src/Middleware/LogRequests.d.ts
104
12
  declare class LogRequests extends Middleware {
105
- handle({ request }: HttpContext, next: () => Promise<unknown>): Promise<unknown>;
13
+ handle({
14
+ request
15
+ }: HttpContext$1, next: () => Promise<unknown>): Promise<unknown>;
106
16
  }
107
-
17
+ //#endregion
18
+ //#region src/Providers/HttpServiceProvider.d.ts
108
19
  /**
109
20
  * Sets up HTTP kernel and request lifecycle.
110
21
  *
@@ -115,101 +26,198 @@ declare class LogRequests extends Middleware {
115
26
  * Auto-Registered
116
27
  */
117
28
  declare class HttpServiceProvider extends ServiceProvider {
118
- static priority: number;
119
- register(): void;
29
+ static priority: number;
30
+ register(): void;
120
31
  }
121
-
32
+ //#endregion
33
+ //#region src/Request.d.ts
34
+ declare class Request implements IRequest {
35
+ /**
36
+ * The current app instance
37
+ */
38
+ app: Application;
39
+ /**
40
+ * Gets route parameters.
41
+ * @returns An object containing route parameters.
42
+ */
43
+ readonly params: NonNullable<H3Event["context"]["params"]>;
44
+ /**
45
+ * Gets query parameters.
46
+ * @returns An object containing query parameters.
47
+ */
48
+ readonly query: Record<string, string>;
49
+ /**
50
+ * Gets the request headers.
51
+ * @returns An object containing request headers.
52
+ */
53
+ readonly headers: TypedHeaders<Record<keyof ResponseHeaderMap, string>>;
54
+ /**
55
+ * The current H3 H3Event instance
56
+ */
57
+ private readonly event;
58
+ constructor(event: H3Event,
59
+ /**
60
+ * The current app instance
61
+ */
62
+ app: Application);
63
+ /**
64
+ * Get all input data (query + body).
65
+ */
66
+ all<T = Record<string, unknown>>(): Promise<T>;
67
+ /**
68
+ * Get a single input field from query or body.
69
+ */
70
+ input<T = unknown>(key: string, defaultValue?: T): Promise<T>;
71
+ /**
72
+ * Get the base event
73
+ */
74
+ getEvent(): H3Event;
75
+ getEvent<K extends DotNestedKeys<H3Event>>(key: K): DotNestedValue<H3Event, K>;
76
+ }
77
+ //#endregion
78
+ //#region src/Resources/JsonResource.d.ts
122
79
  interface Resource {
123
- [key: string]: any;
124
- pagination?: {
125
- from?: number | undefined;
126
- to?: number | undefined;
127
- perPage?: number | undefined;
128
- total?: number | undefined;
129
- } | undefined;
80
+ [key: string]: any;
81
+ pagination?: {
82
+ from?: number | undefined;
83
+ to?: number | undefined;
84
+ perPage?: number | undefined;
85
+ total?: number | undefined;
86
+ } | undefined;
130
87
  }
131
88
  type BodyResource = Resource & {
132
- data: Omit<Resource, 'pagination'>;
133
- meta?: {
134
- pagination?: Resource['pagination'];
135
- } | undefined;
89
+ data: Omit<Resource, 'pagination'>;
90
+ meta?: {
91
+ pagination?: Resource['pagination'];
92
+ } | undefined;
136
93
  };
137
94
  /**
138
95
  * Class to render API resource
139
96
  */
140
97
  declare class JsonResource<R extends Resource = any> {
141
- #private;
142
- protected event: H3Event;
143
- /**
144
- * The request instance
145
- */
146
- request: H3Event<EventHandlerRequest>['req'];
147
- /**
148
- * The response instance
149
- */
150
- response: H3Event['res'];
151
- /**
152
- * The data to send to the client
153
- */
154
- resource: R;
155
- /**
156
- * The final response data object
157
- */
158
- body: BodyResource;
159
- /**
160
- * Flag to track if response should be sent automatically
161
- */
162
- private shouldSend;
163
- /**
164
- * Flag to track if response has been sent
165
- */
166
- private responseSent;
167
- /**
168
- * Declare that this includes R's properties
169
- */
98
+ #private;
99
+ protected event: H3Event;
100
+ /**
101
+ * The request instance
102
+ */
103
+ request: H3Event<EventHandlerRequest>['req'];
104
+ /**
105
+ * The response instance
106
+ */
107
+ response: H3Event['res'];
108
+ /**
109
+ * The data to send to the client
110
+ */
111
+ resource: R;
112
+ /**
113
+ * The final response data object
114
+ */
115
+ body: BodyResource;
116
+ /**
117
+ * Flag to track if response should be sent automatically
118
+ */
119
+ private shouldSend;
120
+ /**
121
+ * Flag to track if response has been sent
122
+ */
123
+ private responseSent;
124
+ /**
125
+ * Declare that this includes R's properties
126
+ */
127
+ [key: string]: any;
128
+ /**
129
+ * @param req The request instance
130
+ * @param res The response instance
131
+ * @param rsc The data to send to the client
132
+ */
133
+ constructor(event: H3Event, rsc: R);
134
+ /**
135
+ * Return the data in the expected format
136
+ *
137
+ * @returns
138
+ */
139
+ data(): Resource;
140
+ /**
141
+ * Build the response object
142
+ * @returns this
143
+ */
144
+ json(): this;
145
+ /**
146
+ * Add context data to the response object
147
+ * @param data Context data
148
+ * @returns this
149
+ */
150
+ additional<X extends {
170
151
  [key: string]: any;
171
- /**
172
- * @param req The request instance
173
- * @param res The response instance
174
- * @param rsc The data to send to the client
175
- */
176
- constructor(event: H3Event, rsc: R);
177
- /**
178
- * Return the data in the expected format
179
- *
180
- * @returns
181
- */
182
- data(): Resource;
183
- /**
184
- * Build the response object
185
- * @returns this
186
- */
187
- json(): this;
188
- /**
189
- * Add context data to the response object
190
- * @param data Context data
191
- * @returns this
192
- */
193
- additional<X extends {
194
- [key: string]: any;
195
- }>(data: X): this;
196
- /**
197
- * Send the output to the client
198
- * @returns this
199
- */
200
- send(): this;
201
- /**
202
- * Set the status code for this response
203
- * @param code Status code
204
- * @returns this
205
- */
206
- status(code: number): this;
207
- /**
208
- * Check if send should be triggered automatically
209
- */
210
- private checkSend;
152
+ }>(data: X): this;
153
+ /**
154
+ * Send the output to the client
155
+ * @returns this
156
+ */
157
+ send(): this;
158
+ /**
159
+ * Set the status code for this response
160
+ * @param code Status code
161
+ * @returns this
162
+ */
163
+ status(code: number): this;
164
+ /**
165
+ * Check if send should be triggered automatically
166
+ */
167
+ private checkSend;
211
168
  }
212
-
169
+ //#endregion
170
+ //#region src/Resources/ApiResource.d.ts
213
171
  declare function ApiResource(instance: JsonResource): JsonResource<any>;
214
-
215
- export { ApiResource, HttpServiceProvider, JsonResource, LogRequests, Middleware, Request, type Resource, Response };
172
+ //#endregion
173
+ //#region src/Response.d.ts
174
+ declare class Response implements IResponse {
175
+ /**
176
+ * The current app instance
177
+ */
178
+ app: Application;
179
+ /**
180
+ * The current H3 H3Event instance
181
+ */
182
+ private readonly event;
183
+ private statusCode;
184
+ private headers;
185
+ constructor(event: H3Event,
186
+ /**
187
+ * The current app instance
188
+ */
189
+ app: Application);
190
+ /**
191
+ * Set HTTP status code.
192
+ */
193
+ setStatusCode(code: number): this;
194
+ /**
195
+ * Set a header.
196
+ */
197
+ setHeader(name: string, value: string): this;
198
+ html(content: string): string;
199
+ /**
200
+ * Send a JSON response.
201
+ */
202
+ json<T = unknown>(data: T): T;
203
+ /**
204
+ * Send plain text.
205
+ */
206
+ text(data: string): string;
207
+ /**
208
+ * Redirect to another URL.
209
+ */
210
+ redirect(url: string, status?: number): string;
211
+ /**
212
+ * Apply headers before sending response.
213
+ */
214
+ private applyHeaders;
215
+ /**
216
+ * Get the base event
217
+ */
218
+ getEvent(): H3Event;
219
+ getEvent<K extends DotNestedKeys<H3Event>>(key: K): DotNestedValue<H3Event, K>;
220
+ }
221
+ //#endregion
222
+ export { ApiResource, HttpContext, HttpServiceProvider, JsonResource, LogRequests, Middleware, Request, Resource, Response };
223
+ //# sourceMappingURL=index.d.ts.map