@h3ravel/http 10.0.0 → 11.0.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.cjs +116 -116
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +67 -67
- package/dist/index.d.ts +67 -67
- package/dist/index.js +107 -107
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -19,8 +19,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
19
19
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
20
|
|
|
21
21
|
// src/index.ts
|
|
22
|
-
var
|
|
23
|
-
__export(
|
|
22
|
+
var index_exports = {};
|
|
23
|
+
__export(index_exports, {
|
|
24
24
|
ApiResource: () => ApiResource,
|
|
25
25
|
HttpContext: () => import_shared.HttpContext,
|
|
26
26
|
HttpServiceProvider: () => HttpServiceProvider,
|
|
@@ -30,7 +30,10 @@ __export(src_exports, {
|
|
|
30
30
|
Request: () => Request,
|
|
31
31
|
Response: () => Response
|
|
32
32
|
});
|
|
33
|
-
module.exports = __toCommonJS(
|
|
33
|
+
module.exports = __toCommonJS(index_exports);
|
|
34
|
+
|
|
35
|
+
// src/Contracts/HttpContract.ts
|
|
36
|
+
var import_shared = require("@h3ravel/shared");
|
|
34
37
|
|
|
35
38
|
// src/Middleware.ts
|
|
36
39
|
var Middleware = class {
|
|
@@ -39,8 +42,36 @@ var Middleware = class {
|
|
|
39
42
|
}
|
|
40
43
|
};
|
|
41
44
|
|
|
42
|
-
// src/
|
|
45
|
+
// src/Middleware/LogRequests.ts
|
|
46
|
+
var LogRequests = class extends Middleware {
|
|
47
|
+
static {
|
|
48
|
+
__name(this, "LogRequests");
|
|
49
|
+
}
|
|
50
|
+
async handle({ request }, next) {
|
|
51
|
+
const url = request.getEvent("url");
|
|
52
|
+
console.log(`[${request.getEvent("method")}] ${url.pathname + url.search}`);
|
|
53
|
+
return next();
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
// src/Providers/HttpServiceProvider.ts
|
|
43
58
|
var import_h3 = require("h3");
|
|
59
|
+
var import_core = require("@h3ravel/core");
|
|
60
|
+
var HttpServiceProvider = class extends import_core.ServiceProvider {
|
|
61
|
+
static {
|
|
62
|
+
__name(this, "HttpServiceProvider");
|
|
63
|
+
}
|
|
64
|
+
static priority = 998;
|
|
65
|
+
register() {
|
|
66
|
+
this.app.singleton("http.app", () => {
|
|
67
|
+
return new import_h3.H3();
|
|
68
|
+
});
|
|
69
|
+
this.app.singleton("http.serve", () => import_h3.serve);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
// src/Request.ts
|
|
74
|
+
var import_h32 = require("h3");
|
|
44
75
|
var import_support = require("@h3ravel/support");
|
|
45
76
|
var Request = class {
|
|
46
77
|
static {
|
|
@@ -69,8 +100,8 @@ var Request = class {
|
|
|
69
100
|
constructor(event, app) {
|
|
70
101
|
this.app = app;
|
|
71
102
|
this.event = event;
|
|
72
|
-
this.query = (0,
|
|
73
|
-
this.params = (0,
|
|
103
|
+
this.query = (0, import_h32.getQuery)(this.event);
|
|
104
|
+
this.params = (0, import_h32.getRouterParams)(this.event);
|
|
74
105
|
this.headers = this.event.req.headers;
|
|
75
106
|
}
|
|
76
107
|
/**
|
|
@@ -78,13 +109,13 @@ var Request = class {
|
|
|
78
109
|
*/
|
|
79
110
|
async all() {
|
|
80
111
|
let data = {
|
|
81
|
-
...(0,
|
|
82
|
-
...(0,
|
|
112
|
+
...(0, import_h32.getRouterParams)(this.event),
|
|
113
|
+
...(0, import_h32.getQuery)(this.event)
|
|
83
114
|
};
|
|
84
115
|
if (this.event.req.method === "POST") {
|
|
85
116
|
data = Object.assign({}, data, Object.fromEntries((await this.event.req.formData()).entries()));
|
|
86
117
|
} else if (this.event.req.method === "PUT") {
|
|
87
|
-
data = Object.fromEntries(Object.entries(await (0,
|
|
118
|
+
data = Object.fromEntries(Object.entries(await (0, import_h32.readBody)(this.event)));
|
|
88
119
|
}
|
|
89
120
|
return data;
|
|
90
121
|
}
|
|
@@ -100,110 +131,6 @@ var Request = class {
|
|
|
100
131
|
}
|
|
101
132
|
};
|
|
102
133
|
|
|
103
|
-
// src/Response.ts
|
|
104
|
-
var import_support2 = require("@h3ravel/support");
|
|
105
|
-
var import_h32 = require("h3");
|
|
106
|
-
var Response = class {
|
|
107
|
-
static {
|
|
108
|
-
__name(this, "Response");
|
|
109
|
-
}
|
|
110
|
-
app;
|
|
111
|
-
/**
|
|
112
|
-
* The current H3 H3Event instance
|
|
113
|
-
*/
|
|
114
|
-
event;
|
|
115
|
-
statusCode = 200;
|
|
116
|
-
headers = {};
|
|
117
|
-
constructor(event, app) {
|
|
118
|
-
this.app = app;
|
|
119
|
-
this.event = event;
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Set HTTP status code.
|
|
123
|
-
*/
|
|
124
|
-
setStatusCode(code) {
|
|
125
|
-
this.statusCode = code;
|
|
126
|
-
this.event.res.status = code;
|
|
127
|
-
return this;
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Set a header.
|
|
131
|
-
*/
|
|
132
|
-
setHeader(name, value) {
|
|
133
|
-
this.headers[name] = value;
|
|
134
|
-
return this;
|
|
135
|
-
}
|
|
136
|
-
html(content) {
|
|
137
|
-
this.applyHeaders();
|
|
138
|
-
return (0, import_h32.html)(this.event, content);
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* Send a JSON response.
|
|
142
|
-
*/
|
|
143
|
-
json(data) {
|
|
144
|
-
this.setHeader("content-type", "application/json; charset=utf-8");
|
|
145
|
-
this.applyHeaders();
|
|
146
|
-
return data;
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Send plain text.
|
|
150
|
-
*/
|
|
151
|
-
text(data) {
|
|
152
|
-
this.setHeader("content-type", "text/plain; charset=utf-8");
|
|
153
|
-
this.applyHeaders();
|
|
154
|
-
return data;
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
* Redirect to another URL.
|
|
158
|
-
*/
|
|
159
|
-
redirect(url, status = 302) {
|
|
160
|
-
this.setStatusCode(status);
|
|
161
|
-
return (0, import_h32.redirect)(this.event, url, this.statusCode);
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* Apply headers before sending response.
|
|
165
|
-
*/
|
|
166
|
-
applyHeaders() {
|
|
167
|
-
Object.entries(this.headers).forEach(([key, value]) => {
|
|
168
|
-
this.event.res.headers.set(key, value);
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
getEvent(key) {
|
|
172
|
-
return (0, import_support2.safeDot)(this.event, key);
|
|
173
|
-
}
|
|
174
|
-
};
|
|
175
|
-
|
|
176
|
-
// src/Contracts/HttpContract.ts
|
|
177
|
-
var import_shared = require("@h3ravel/shared");
|
|
178
|
-
|
|
179
|
-
// src/Middleware/LogRequests.ts
|
|
180
|
-
var LogRequests = class extends Middleware {
|
|
181
|
-
static {
|
|
182
|
-
__name(this, "LogRequests");
|
|
183
|
-
}
|
|
184
|
-
async handle({ request }, next) {
|
|
185
|
-
const url = request.getEvent("url");
|
|
186
|
-
console.log(`[${request.getEvent("method")}] ${url.pathname + url.search}`);
|
|
187
|
-
return next();
|
|
188
|
-
}
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
// src/Providers/HttpServiceProvider.ts
|
|
192
|
-
var import_h33 = require("h3");
|
|
193
|
-
var import_core = require("@h3ravel/core");
|
|
194
|
-
var HttpServiceProvider = class extends import_core.ServiceProvider {
|
|
195
|
-
static {
|
|
196
|
-
__name(this, "HttpServiceProvider");
|
|
197
|
-
}
|
|
198
|
-
static priority = 998;
|
|
199
|
-
register() {
|
|
200
|
-
this.app.singleton("http.app", () => {
|
|
201
|
-
return new import_h33.H3();
|
|
202
|
-
});
|
|
203
|
-
this.app.singleton("http.serve", () => import_h33.serve);
|
|
204
|
-
}
|
|
205
|
-
};
|
|
206
|
-
|
|
207
134
|
// src/Resources/JsonResource.ts
|
|
208
135
|
var JsonResource = class {
|
|
209
136
|
static {
|
|
@@ -251,10 +178,10 @@ var JsonResource = class {
|
|
|
251
178
|
Object.defineProperty(this, key, {
|
|
252
179
|
enumerable: true,
|
|
253
180
|
configurable: true,
|
|
254
|
-
get: () => this.resource[key],
|
|
255
|
-
set: (value) => {
|
|
181
|
+
get: /* @__PURE__ */ __name(() => this.resource[key], "get"),
|
|
182
|
+
set: /* @__PURE__ */ __name((value) => {
|
|
256
183
|
this.resource[key] = value;
|
|
257
|
-
}
|
|
184
|
+
}, "set")
|
|
258
185
|
});
|
|
259
186
|
}
|
|
260
187
|
}
|
|
@@ -379,6 +306,79 @@ function ApiResource(instance) {
|
|
|
379
306
|
});
|
|
380
307
|
}
|
|
381
308
|
__name(ApiResource, "ApiResource");
|
|
309
|
+
|
|
310
|
+
// src/Response.ts
|
|
311
|
+
var import_support2 = require("@h3ravel/support");
|
|
312
|
+
var import_h33 = require("h3");
|
|
313
|
+
var Response = class {
|
|
314
|
+
static {
|
|
315
|
+
__name(this, "Response");
|
|
316
|
+
}
|
|
317
|
+
app;
|
|
318
|
+
/**
|
|
319
|
+
* The current H3 H3Event instance
|
|
320
|
+
*/
|
|
321
|
+
event;
|
|
322
|
+
statusCode = 200;
|
|
323
|
+
headers = {};
|
|
324
|
+
constructor(event, app) {
|
|
325
|
+
this.app = app;
|
|
326
|
+
this.event = event;
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Set HTTP status code.
|
|
330
|
+
*/
|
|
331
|
+
setStatusCode(code) {
|
|
332
|
+
this.statusCode = code;
|
|
333
|
+
this.event.res.status = code;
|
|
334
|
+
return this;
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Set a header.
|
|
338
|
+
*/
|
|
339
|
+
setHeader(name, value) {
|
|
340
|
+
this.headers[name] = value;
|
|
341
|
+
return this;
|
|
342
|
+
}
|
|
343
|
+
html(content) {
|
|
344
|
+
this.applyHeaders();
|
|
345
|
+
return (0, import_h33.html)(this.event, content);
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Send a JSON response.
|
|
349
|
+
*/
|
|
350
|
+
json(data) {
|
|
351
|
+
this.setHeader("content-type", "application/json; charset=utf-8");
|
|
352
|
+
this.applyHeaders();
|
|
353
|
+
return data;
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* Send plain text.
|
|
357
|
+
*/
|
|
358
|
+
text(data) {
|
|
359
|
+
this.setHeader("content-type", "text/plain; charset=utf-8");
|
|
360
|
+
this.applyHeaders();
|
|
361
|
+
return data;
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Redirect to another URL.
|
|
365
|
+
*/
|
|
366
|
+
redirect(url, status = 302) {
|
|
367
|
+
this.setStatusCode(status);
|
|
368
|
+
return (0, import_h33.redirect)(this.event, url, this.statusCode);
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Apply headers before sending response.
|
|
372
|
+
*/
|
|
373
|
+
applyHeaders() {
|
|
374
|
+
Object.entries(this.headers).forEach(([key, value]) => {
|
|
375
|
+
this.event.res.headers.set(key, value);
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
getEvent(key) {
|
|
379
|
+
return (0, import_support2.safeDot)(this.event, key);
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
382
|
// Annotate the CommonJS export names for ESM import in node:
|
|
383
383
|
0 && (module.exports = {
|
|
384
384
|
ApiResource,
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/Middleware.ts","../src/Request.ts","../src/Response.ts","../src/Contracts/HttpContract.ts","../src/Middleware/LogRequests.ts","../src/Providers/HttpServiceProvider.ts","../src/Resources/JsonResource.ts","../src/Resources/ApiResource.ts"],"sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from './Middleware';\nexport * from './Request';\nexport * from './Response';\nexport * from './Contracts/HttpContract';\nexport * from './Middleware/LogRequests';\nexport * from './Providers/HttpServiceProvider';\nexport * from './Resources/ApiResource';\nexport * from './Resources/JsonResource';\n","import { HttpContext } from './Contracts/HttpContract'\nimport { IMiddleware } from '@h3ravel/shared'\n\nexport abstract class Middleware implements IMiddleware {\n abstract handle (context: HttpContext, next: () => Promise<unknown>): Promise<unknown>\n}\n","import { getQuery, getRouterParams, readBody, type H3Event } from 'h3'\nimport { DotNestedKeys, DotNestedValue, safeDot } from '@h3ravel/support'\nimport type { ResponseHeaderMap, TypedHeaders } from 'fetchdts'\nimport { IRequest } from '@h3ravel/shared'\nimport { Application } from '@h3ravel/core'\n\nexport class Request implements IRequest {\n /**\n * Gets route parameters.\n * @returns An object containing route parameters.\n */\n readonly params: NonNullable<H3Event[\"context\"][\"params\"]>\n\n /**\n * Gets query parameters.\n * @returns An object containing query parameters.\n */\n readonly query: Record<string, string>;\n\n /**\n * Gets the request headers.\n * @returns An object containing request headers.\n */\n readonly headers: TypedHeaders<Record<keyof ResponseHeaderMap, string>>\n\n /**\n * The current H3 H3Event instance\n */\n private readonly event: H3Event\n\n constructor(\n event: H3Event,\n /**\n * The current app instance\n */\n public app: Application\n ) {\n this.event = event\n this.query = getQuery(this.event)\n this.params = getRouterParams(this.event)\n this.headers = this.event.req.headers\n }\n\n /**\n * Get all input data (query + body).\n */\n async all<T = Record<string, unknown>> (): Promise<T> {\n let data = {\n ...getRouterParams(this.event),\n ...getQuery(this.event),\n } as T\n\n if (this.event.req.method === 'POST') {\n data = Object.assign({}, data, Object.fromEntries((await this.event.req.formData()).entries()))\n } else if (this.event.req.method === 'PUT') {\n data = <never>Object.fromEntries(Object.entries(<never>await readBody(this.event)))\n }\n\n return data\n }\n\n /**\n * Get a single input field from query or body.\n */\n async input<T = unknown> (key: string, defaultValue?: T): Promise<T> {\n const data = await this.all<Record<string, T>>()\n return (data[key] ?? defaultValue) as T\n }\n\n /**\n * Get the base event\n */\n getEvent (): H3Event\n getEvent<K extends DotNestedKeys<H3Event>> (key: K): DotNestedValue<H3Event, K>\n getEvent<K extends DotNestedKeys<H3Event>> (key?: K): any {\n return safeDot(this.event, key)\n }\n}\n","import { DotNestedKeys, DotNestedValue, safeDot } from '@h3ravel/support'\nimport { html, redirect, } from 'h3'\n\nimport { Application } from '@h3ravel/core'\nimport type { H3Event } from 'h3'\nimport { IResponse } from '@h3ravel/shared'\n\nexport class Response implements IResponse {\n /**\n * The current H3 H3Event instance\n */\n private readonly event: H3Event\n\n private statusCode: number = 200\n private headers: Record<string, string> = {}\n\n constructor(\n event: H3Event,\n /**\n * The current app instance\n */\n public app: Application\n ) {\n this.event = event\n }\n\n /**\n * Set HTTP status code.\n */\n setStatusCode (code: number): this {\n this.statusCode = code\n this.event.res.status = code\n return this\n }\n\n /**\n * Set a header.\n */\n setHeader (name: string, value: string): this {\n this.headers[name] = value\n return this\n }\n\n html (content: string): string {\n this.applyHeaders()\n return html(this.event, content)\n }\n\n /**\n * Send a JSON response.\n */\n json<T = unknown> (data: T): T {\n this.setHeader('content-type', 'application/json; charset=utf-8')\n this.applyHeaders()\n return data\n }\n\n /**\n * Send plain text.\n */\n text (data: string): string {\n this.setHeader('content-type', 'text/plain; charset=utf-8')\n this.applyHeaders()\n return data\n }\n\n /**\n * Redirect to another URL.\n */\n redirect (url: string, status = 302): string {\n this.setStatusCode(status)\n return redirect(this.event, url, this.statusCode)\n }\n\n /**\n * Apply headers before sending response.\n */\n private applyHeaders (): void {\n Object.entries(this.headers).forEach(([key, value]) => {\n this.event.res.headers.set(key, value)\n })\n }\n\n /**\n * Get the base event\n */\n getEvent (): H3Event\n getEvent<K extends DotNestedKeys<H3Event>> (key: K): DotNestedValue<H3Event, K>\n getEvent<K extends DotNestedKeys<H3Event>> (key?: K): any {\n return safeDot(this.event, key)\n }\n}\n","export { HttpContext } from '@h3ravel/shared'\n","import { HttpContext } from '@h3ravel/shared'\nimport { Middleware } from '../Middleware'\n\nexport class LogRequests extends Middleware {\n async handle ({ request }: HttpContext, next: () => Promise<unknown>): Promise<unknown> {\n const url = request.getEvent('url')\n console.log(`[${request.getEvent('method')}] ${url.pathname + url.search}`)\n return next()\n }\n}\n","import { H3, serve } from 'h3'\n\nimport { ServiceProvider } from '@h3ravel/core'\n\n/**\n * Sets up HTTP kernel and request lifecycle.\n * \n * Register Request, Response, and Middleware classes.\n * Configure global middleware stack.\n * Boot HTTP kernel.\n * \n * Auto-Registered\n */\nexport class HttpServiceProvider extends ServiceProvider {\n public static priority = 998;\n\n register () {\n this.app.singleton('http.app', () => {\n return new H3()\n })\n\n this.app.singleton('http.serve', () => serve)\n }\n}\n","import { EventHandlerRequest, H3Event } from 'h3'\n\nexport interface Resource {\n [key: string]: any;\n pagination?: {\n from?: number | undefined;\n to?: number | undefined;\n perPage?: number | undefined;\n total?: number | undefined;\n } | undefined;\n}\n\ntype BodyResource = Resource & {\n data: Omit<Resource, 'pagination'>,\n meta?: {\n pagination?: Resource['pagination']\n } | undefined;\n}\n\n/**\n * Class to render API resource\n */\nexport class JsonResource<R extends Resource = any> {\n /**\n * The request instance\n */\n request: H3Event<EventHandlerRequest>['req']\n /**\n * The response instance\n */\n response: H3Event['res']\n /**\n * The data to send to the client\n */\n resource: R\n /**\n * The final response data object\n */\n body: BodyResource = {\n data: {},\n }\n /**\n * Flag to track if response should be sent automatically\n */\n private shouldSend: boolean = false\n /**\n * Flag to track if response has been sent\n */\n\n private responseSent: boolean = false;\n\n /**\n * Declare that this includes R's properties\n */\n [key: string]: any;\n\n /**\n * @param req The request instance\n * @param res The response instance\n * @param rsc The data to send to the client\n */\n constructor(protected event: H3Event, rsc: R) {\n this.request = event.req\n this.response = event.res\n this.resource = rsc\n\n // Copy all properties from rsc to this, avoiding conflicts\n for (const key of Object.keys(rsc)) {\n if (!(key in this)) {\n Object.defineProperty(this, key, {\n enumerable: true,\n configurable: true,\n get: () => this.resource[key],\n set: (value) => {\n (<any>this.resource)[key] = value\n },\n })\n }\n }\n }\n\n /**\n * Return the data in the expected format\n * \n * @returns \n */\n data (): Resource {\n return this.resource\n }\n\n /**\n * Build the response object\n * @returns this\n */\n json () {\n // Indicate response should be sent automatically\n this.shouldSend = true\n\n // Set default status code\n this.response.status = 200\n\n // Prepare body\n const resource = this.data()\n let data: Resource = Array.isArray(resource) ? [...resource] : { ...resource }\n\n if (typeof data.data !== 'undefined') {\n data = data.data\n }\n\n if (!Array.isArray(resource)) {\n delete data.pagination\n }\n\n this.body = {\n data,\n }\n\n // Set the pagination from the data() resource, if available\n if (!Array.isArray(resource) && resource.pagination) {\n const meta: BodyResource['meta'] = this.body.meta ?? {}\n meta.pagination = resource.pagination\n this.body.meta = meta\n }\n\n // If pagination is not available on the resource, then check and set it\n // if it's available on the base resource.\n if (this.resource.pagination && !this.body.meta?.pagination) {\n const meta: BodyResource['meta'] = this.body.meta ?? {}\n meta.pagination = this.resource.pagination\n this.body.meta = meta\n }\n\n return this\n }\n\n /**\n * Add context data to the response object\n * @param data Context data\n * @returns this\n */\n additional<X extends { [key: string]: any }> (data: X) {\n\n // Allow automatic send after additional\n this.shouldSend = true\n\n // Merge data with body\n delete data.data\n delete data.pagination\n\n this.body = {\n ...this.body,\n ...data,\n }\n\n return this\n }\n\n /**\n * Send the output to the client\n * @returns this\n */\n send () {\n this.shouldSend = false // Prevent automatic send\n if (!this.responseSent) {\n this.#send()\n }\n return this\n }\n\n /**\n * Set the status code for this response\n * @param code Status code\n * @returns this\n */\n status (code: number) {\n this.response.status = code\n return this\n }\n\n /**\n * Private method to send the response\n */\n #send () {\n if (!this.responseSent) {\n this.event.context.\n this.response.json(this.body)\n\n // Mark response as sent\n this.responseSent = true\n }\n }\n\n /**\n * Check if send should be triggered automatically\n */\n private checkSend () {\n if (this.shouldSend && !this.responseSent) {\n this.#send()\n }\n }\n}\n","import { JsonResource, Resource } from './JsonResource'\n\nimport { H3Event } from 'h3'\n\nexport function ApiResource (\n instance: JsonResource\n) {\n return new Proxy(instance, {\n get (target, prop, receiver) {\n const value = Reflect.get(target, prop, receiver)\n if (typeof value === 'function') {\n // Intercept json, additional, and send methods\n if (prop === 'json' || prop === 'additional') {\n return (...args: any[]) => {\n const result = value.apply(target, args)\n // Schedule checkSend after json or additional\n setImmediate(() => target['checkSend']())\n return result\n }\n } else if (prop === 'send') {\n return (...args: any[]) => {\n // Prevent checkSend from firing\n target['shouldSend'] = false\n\n return value.apply(target, args)\n }\n }\n }\n return value\n },\n })\n}\n\nexport default function BaseResource<R extends Resource> (\n evt: H3Event,\n rsc: R\n) {\n return ApiResource(new JsonResource<R>(evt, rsc))\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;ACGO,IAAeA,aAAf,MAAeA;EAAtB,OAAsBA;;;AAEtB;;;ACLA,gBAAkE;AAClE,qBAAuD;AAKhD,IAAMC,UAAN,MAAMA;EANb,OAMaA;;;;;;;;EAKAC;;;;;EAMAC;;;;;EAMAC;;;;EAKQC;EAEjB,YACIA,OAIOC,KACT;SADSA,MAAAA;AAEP,SAAKD,QAAQA;AACb,SAAKF,YAAQI,oBAAS,KAAKF,KAAK;AAChC,SAAKH,aAASM,2BAAgB,KAAKH,KAAK;AACxC,SAAKD,UAAU,KAAKC,MAAMI,IAAIL;EAClC;;;;EAKA,MAAMM,MAAgD;AAClD,QAAIC,OAAO;MACP,OAAGH,2BAAgB,KAAKH,KAAK;MAC7B,OAAGE,oBAAS,KAAKF,KAAK;IAC1B;AAEA,QAAI,KAAKA,MAAMI,IAAIG,WAAW,QAAQ;AAClCD,aAAOE,OAAOC,OAAO,CAAC,GAAGH,MAAME,OAAOE,aAAa,MAAM,KAAKV,MAAMI,IAAIO,SAAQ,GAAIC,QAAO,CAAA,CAAA;IAC/F,WAAW,KAAKZ,MAAMI,IAAIG,WAAW,OAAO;AACxCD,aAAcE,OAAOE,YAAYF,OAAOI,QAAe,UAAMC,oBAAS,KAAKb,KAAK,CAAA,CAAA;IACpF;AAEA,WAAOM;EACX;;;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,QAAI,KAAK1B,cAAc,CAAC,KAAKC,cAAc;AACvC,WAAK,MAAK;IACd;EACJ;AACJ;;;ACpMO,SAAS0B,YACZC,UAAsB;AAEtB,SAAO,IAAIC,MAAMD,UAAU;IACvBE,IAAKC,QAAQC,MAAMC,UAAQ;AACvB,YAAMC,QAAQC,QAAQL,IAAIC,QAAQC,MAAMC,QAAAA;AACxC,UAAI,OAAOC,UAAU,YAAY;AAE7B,YAAIF,SAAS,UAAUA,SAAS,cAAc;AAC1C,iBAAO,IAAII,SAAAA;AACP,kBAAMC,SAASH,MAAMI,MAAMP,QAAQK,IAAAA;AAEnCG,yBAAa,MAAMR,OAAO,WAAA,EAAY,CAAA;AACtC,mBAAOM;UACX;QACJ,WAAWL,SAAS,QAAQ;AACxB,iBAAO,IAAII,SAAAA;AAEPL,mBAAO,YAAA,IAAgB;AAEvB,mBAAOG,MAAMI,MAAMP,QAAQK,IAAAA;UAC/B;QACJ;MACJ;AACA,aAAOF;IACX;EACJ,CAAA;AACJ;AA3BgBP;","names":["Middleware","Request","params","query","headers","event","app","getQuery","getRouterParams","req","all","data","method","Object","assign","fromEntries","formData","entries","readBody","input","key","defaultValue","getEvent","safeDot","import_support","import_h3","Response","event","statusCode","headers","app","setStatusCode","code","res","status","setHeader","name","value","html","content","applyHeaders","json","data","text","redirect","url","Object","entries","forEach","key","set","getEvent","safeDot","LogRequests","Middleware","handle","request","next","url","getEvent","console","log","pathname","search","import_h3","HttpServiceProvider","ServiceProvider","priority","register","app","singleton","H3","serve","JsonResource","request","response","resource","body","data","shouldSend","responseSent","event","rsc","req","res","key","Object","keys","defineProperty","enumerable","configurable","get","set","value","json","status","Array","isArray","pagination","meta","additional","send","code","context","this","checkSend","ApiResource","instance","Proxy","get","target","prop","receiver","value","Reflect","args","result","apply","setImmediate"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/Contracts/HttpContract.ts","../src/Middleware.ts","../src/Middleware/LogRequests.ts","../src/Providers/HttpServiceProvider.ts","../src/Request.ts","../src/Resources/JsonResource.ts","../src/Resources/ApiResource.ts","../src/Response.ts"],"sourcesContent":["export * from './Contracts/HttpContract'\nexport * from './Middleware'\nexport * from './Middleware/LogRequests'\nexport * from './Providers/HttpServiceProvider'\nexport * from './Request'\nexport * from './Resources/ApiResource'\nexport * from './Resources/JsonResource'\nexport * from './Response'\n","export { HttpContext } from '@h3ravel/shared'\n","import { HttpContext } from './Contracts/HttpContract'\nimport { IMiddleware } from '@h3ravel/shared'\n\nexport abstract class Middleware implements IMiddleware {\n abstract handle (context: HttpContext, next: () => Promise<unknown>): Promise<unknown>\n}\n","import { HttpContext } from '@h3ravel/shared'\nimport { Middleware } from '../Middleware'\n\nexport class LogRequests extends Middleware {\n async handle ({ request }: HttpContext, next: () => Promise<unknown>): Promise<unknown> {\n const url = request.getEvent('url')\n console.log(`[${request.getEvent('method')}] ${url.pathname + url.search}`)\n return next()\n }\n}\n","import { H3, serve } from 'h3'\n\nimport { ServiceProvider } from '@h3ravel/core'\n\n/**\n * Sets up HTTP kernel and request lifecycle.\n * \n * Register Request, Response, and Middleware classes.\n * Configure global middleware stack.\n * Boot HTTP kernel.\n * \n * Auto-Registered\n */\nexport class HttpServiceProvider extends ServiceProvider {\n public static priority = 998;\n\n register () {\n this.app.singleton('http.app', () => {\n return new H3()\n })\n\n this.app.singleton('http.serve', () => serve)\n }\n}\n","import { getQuery, getRouterParams, readBody, type H3Event } from 'h3'\nimport { DotNestedKeys, DotNestedValue, safeDot } from '@h3ravel/support'\nimport type { ResponseHeaderMap, TypedHeaders } from 'fetchdts'\nimport { IRequest } from '@h3ravel/shared'\nimport { Application } from '@h3ravel/core'\n\nexport class Request implements IRequest {\n /**\n * Gets route parameters.\n * @returns An object containing route parameters.\n */\n readonly params: NonNullable<H3Event[\"context\"][\"params\"]>\n\n /**\n * Gets query parameters.\n * @returns An object containing query parameters.\n */\n readonly query: Record<string, string>;\n\n /**\n * Gets the request headers.\n * @returns An object containing request headers.\n */\n readonly headers: TypedHeaders<Record<keyof ResponseHeaderMap, string>>\n\n /**\n * The current H3 H3Event instance\n */\n private readonly event: H3Event\n\n constructor(\n event: H3Event,\n /**\n * The current app instance\n */\n public app: Application\n ) {\n this.event = event\n this.query = getQuery(this.event)\n this.params = getRouterParams(this.event)\n this.headers = this.event.req.headers\n }\n\n /**\n * Get all input data (query + body).\n */\n async all<T = Record<string, unknown>> (): Promise<T> {\n let data = {\n ...getRouterParams(this.event),\n ...getQuery(this.event),\n } as T\n\n if (this.event.req.method === 'POST') {\n data = Object.assign({}, data, Object.fromEntries((await this.event.req.formData()).entries()))\n } else if (this.event.req.method === 'PUT') {\n data = <never>Object.fromEntries(Object.entries(<never>await readBody(this.event)))\n }\n\n return data\n }\n\n /**\n * Get a single input field from query or body.\n */\n async input<T = unknown> (key: string, defaultValue?: T): Promise<T> {\n const data = await this.all<Record<string, T>>()\n return (data[key] ?? defaultValue) as T\n }\n\n /**\n * Get the base event\n */\n getEvent (): H3Event\n getEvent<K extends DotNestedKeys<H3Event>> (key: K): DotNestedValue<H3Event, K>\n getEvent<K extends DotNestedKeys<H3Event>> (key?: K): any {\n return safeDot(this.event, key)\n }\n}\n","import { EventHandlerRequest, H3Event } from 'h3'\n\nexport interface Resource {\n [key: string]: any;\n pagination?: {\n from?: number | undefined;\n to?: number | undefined;\n perPage?: number | undefined;\n total?: number | undefined;\n } | undefined;\n}\n\ntype BodyResource = Resource & {\n data: Omit<Resource, 'pagination'>,\n meta?: {\n pagination?: Resource['pagination']\n } | undefined;\n}\n\n/**\n * Class to render API resource\n */\nexport class JsonResource<R extends Resource = any> {\n /**\n * The request instance\n */\n request: H3Event<EventHandlerRequest>['req']\n /**\n * The response instance\n */\n response: H3Event['res']\n /**\n * The data to send to the client\n */\n resource: R\n /**\n * The final response data object\n */\n body: BodyResource = {\n data: {},\n }\n /**\n * Flag to track if response should be sent automatically\n */\n private shouldSend: boolean = false\n /**\n * Flag to track if response has been sent\n */\n\n private responseSent: boolean = false;\n\n /**\n * Declare that this includes R's properties\n */\n [key: string]: any;\n\n /**\n * @param req The request instance\n * @param res The response instance\n * @param rsc The data to send to the client\n */\n constructor(protected event: H3Event, rsc: R) {\n this.request = event.req\n this.response = event.res\n this.resource = rsc\n\n // Copy all properties from rsc to this, avoiding conflicts\n for (const key of Object.keys(rsc)) {\n if (!(key in this)) {\n Object.defineProperty(this, key, {\n enumerable: true,\n configurable: true,\n get: () => this.resource[key],\n set: (value) => {\n (<any>this.resource)[key] = value\n },\n })\n }\n }\n }\n\n /**\n * Return the data in the expected format\n * \n * @returns \n */\n data (): Resource {\n return this.resource\n }\n\n /**\n * Build the response object\n * @returns this\n */\n json () {\n // Indicate response should be sent automatically\n this.shouldSend = true\n\n // Set default status code\n this.response.status = 200\n\n // Prepare body\n const resource = this.data()\n let data: Resource = Array.isArray(resource) ? [...resource] : { ...resource }\n\n if (typeof data.data !== 'undefined') {\n data = data.data\n }\n\n if (!Array.isArray(resource)) {\n delete data.pagination\n }\n\n this.body = {\n data,\n }\n\n // Set the pagination from the data() resource, if available\n if (!Array.isArray(resource) && resource.pagination) {\n const meta: BodyResource['meta'] = this.body.meta ?? {}\n meta.pagination = resource.pagination\n this.body.meta = meta\n }\n\n // If pagination is not available on the resource, then check and set it\n // if it's available on the base resource.\n if (this.resource.pagination && !this.body.meta?.pagination) {\n const meta: BodyResource['meta'] = this.body.meta ?? {}\n meta.pagination = this.resource.pagination\n this.body.meta = meta\n }\n\n return this\n }\n\n /**\n * Add context data to the response object\n * @param data Context data\n * @returns this\n */\n additional<X extends { [key: string]: any }> (data: X) {\n\n // Allow automatic send after additional\n this.shouldSend = true\n\n // Merge data with body\n delete data.data\n delete data.pagination\n\n this.body = {\n ...this.body,\n ...data,\n }\n\n return this\n }\n\n /**\n * Send the output to the client\n * @returns this\n */\n send () {\n this.shouldSend = false // Prevent automatic send\n if (!this.responseSent) {\n this.#send()\n }\n return this\n }\n\n /**\n * Set the status code for this response\n * @param code Status code\n * @returns this\n */\n status (code: number) {\n this.response.status = code\n return this\n }\n\n /**\n * Private method to send the response\n */\n #send () {\n if (!this.responseSent) {\n this.event.context.\n this.response.json(this.body)\n\n // Mark response as sent\n this.responseSent = true\n }\n }\n\n /**\n * Check if send should be triggered automatically\n */\n private checkSend () {\n if (this.shouldSend && !this.responseSent) {\n this.#send()\n }\n }\n}\n","import { JsonResource, Resource } from './JsonResource'\n\nimport { H3Event } from 'h3'\n\nexport function ApiResource (\n instance: JsonResource\n) {\n return new Proxy(instance, {\n get (target, prop, receiver) {\n const value = Reflect.get(target, prop, receiver)\n if (typeof value === 'function') {\n // Intercept json, additional, and send methods\n if (prop === 'json' || prop === 'additional') {\n return (...args: any[]) => {\n const result = value.apply(target, args)\n // Schedule checkSend after json or additional\n setImmediate(() => target['checkSend']())\n return result\n }\n } else if (prop === 'send') {\n return (...args: any[]) => {\n // Prevent checkSend from firing\n target['shouldSend'] = false\n\n return value.apply(target, args)\n }\n }\n }\n return value\n },\n })\n}\n\nexport default function BaseResource<R extends Resource> (\n evt: H3Event,\n rsc: R\n) {\n return ApiResource(new JsonResource<R>(evt, rsc))\n}\n","import { DotNestedKeys, DotNestedValue, safeDot } from '@h3ravel/support'\nimport { html, redirect, } from 'h3'\n\nimport { Application } from '@h3ravel/core'\nimport type { H3Event } from 'h3'\nimport { IResponse } from '@h3ravel/shared'\n\nexport class Response implements IResponse {\n /**\n * The current H3 H3Event instance\n */\n private readonly event: H3Event\n\n private statusCode: number = 200\n private headers: Record<string, string> = {}\n\n constructor(\n event: H3Event,\n /**\n * The current app instance\n */\n public app: Application\n ) {\n this.event = event\n }\n\n /**\n * Set HTTP status code.\n */\n setStatusCode (code: number): this {\n this.statusCode = code\n this.event.res.status = code\n return this\n }\n\n /**\n * Set a header.\n */\n setHeader (name: string, value: string): this {\n this.headers[name] = value\n return this\n }\n\n html (content: string): string {\n this.applyHeaders()\n return html(this.event, content)\n }\n\n /**\n * Send a JSON response.\n */\n json<T = unknown> (data: T): T {\n this.setHeader('content-type', 'application/json; charset=utf-8')\n this.applyHeaders()\n return data\n }\n\n /**\n * Send plain text.\n */\n text (data: string): string {\n this.setHeader('content-type', 'text/plain; charset=utf-8')\n this.applyHeaders()\n return data\n }\n\n /**\n * Redirect to another URL.\n */\n redirect (url: string, status = 302): string {\n this.setStatusCode(status)\n return redirect(this.event, url, this.statusCode)\n }\n\n /**\n * Apply headers before sending response.\n */\n private applyHeaders (): void {\n Object.entries(this.headers).forEach(([key, value]) => {\n this.event.res.headers.set(key, value)\n })\n }\n\n /**\n * Get the base event\n */\n getEvent (): H3Event\n getEvent<K extends DotNestedKeys<H3Event>> (key: K): DotNestedValue<H3Event, K>\n getEvent<K extends DotNestedKeys<H3Event>> (key?: K): any {\n return safeDot(this.event, key)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;ACAA,oBAA4B;;;ACGrB,IAAeA,aAAf,MAAeA;EAAtB,OAAsBA;;;AAEtB;;;ACFO,IAAMC,cAAN,cAA0BC,WAAAA;EAFjC,OAEiCA;;;EAC7B,MAAMC,OAAQ,EAAEC,QAAO,GAAiBC,MAAgD;AACpF,UAAMC,MAAMF,QAAQG,SAAS,KAAA;AAC7BC,YAAQC,IAAI,IAAIL,QAAQG,SAAS,QAAA,CAAA,KAAcD,IAAII,WAAWJ,IAAIK,MAAM,EAAE;AAC1E,WAAON,KAAAA;EACX;AACJ;;;ACTA,gBAA0B;AAE1B,kBAAgC;AAWzB,IAAMO,sBAAN,cAAkCC,4BAAAA;EAbzC,OAayCA;;;EACrC,OAAcC,WAAW;EAEzBC,WAAY;AACR,SAAKC,IAAIC,UAAU,YAAY,MAAA;AAC3B,aAAO,IAAIC,aAAAA;IACf,CAAA;AAEA,SAAKF,IAAIC,UAAU,cAAc,MAAME,eAAAA;EAC3C;AACJ;;;ACvBA,IAAAC,aAAkE;AAClE,qBAAuD;AAKhD,IAAMC,UAAN,MAAMA;EANb,OAMaA;;;;;;;;EAKAC;;;;;EAMAC;;;;;EAM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qB;AAC1C,SAAKR,QAAQO,IAAAA,IAAQC;AACrB,WAAO;EACX;EAEAC,KAAMC,SAAyB;AAC3B,SAAKC,aAAY;AACjB,eAAOF,iBAAK,KAAKX,OAAOY,OAAAA;EAC5B;;;;EAKAE,KAAmBC,MAAY;AAC3B,SAAKP,UAAU,gBAAgB,iCAAA;AAC/B,SAAKK,aAAY;AACjB,WAAOE;EACX;;;;EAKAC,KAAMD,MAAsB;AACxB,SAAKP,UAAU,gBAAgB,2BAAA;AAC/B,SAAKK,aAAY;AACjB,WAAOE;EACX;;;;EAKAE,SAAUC,KAAaX,SAAS,KAAa;AACzC,SAAKH,cAAcG,MAAAA;AACnB,eAAOU,qBAAS,KAAKjB,OAAOkB,KAAK,KAAKjB,UAAU;EACpD;;;;EAKQY,eAAsB;AAC1BM,WAAOC,QAAQ,KAAKlB,OAAO,EAAEmB,QAAQ,CAAC,CAACC,KAAKZ,KAAAA,MAAM;AAC9C,WAAKV,MAAMM,IAAIJ,QAAQqB,IAAID,KAAKZ,KAAAA;IACpC,CAAA;EACJ;EAOAc,SAA4CF,KAAc;AACtD,eAAOG,yBAAQ,KAAKzB,OAAOsB,GAAAA;EAC/B;AACJ;","names":["Middleware","LogRequests","Middleware","handle","request","next","url","getEvent","console","log","pathname","search","HttpServiceProvider","ServiceProvider","priority","register","app","singleton","H3","serve","import_h3","Request","params","query","headers","event","app","getQuery","getRouterParams","req","all","data","method","Object","assign","fromEntries","formData","entries","readBody","input","key","defaultValue","getEvent","safeDot","JsonResource","request","response","resource","body","data","shouldSend","responseSent","event","rsc","req","res","key","Object","keys","defineProperty","enumerable","configurable","get","set","value","json","status","Array","isArray","pagination","meta","additional","send","code","context","this","checkSend","ApiResource","instance","Proxy","get","target","prop","receiver","value","Reflect","args","result","apply","setImmediate","import_support","import_h3","Response","event","statusCode","headers","app","setStatusCode","code","res","status","setHeader","name","value","html","content","applyHeaders","json","data","text","redirect","url","Object","entries","forEach","key","set","getEvent","safeDot"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,14 +1,32 @@
|
|
|
1
1
|
import { IMiddleware, HttpContext, IRequest, IResponse } from '@h3ravel/shared';
|
|
2
2
|
export { HttpContext } from '@h3ravel/shared';
|
|
3
|
+
import { ServiceProvider, Application } from '@h3ravel/core';
|
|
3
4
|
import { H3Event, EventHandlerRequest } from 'h3';
|
|
4
5
|
import { DotNestedKeys, DotNestedValue } from '@h3ravel/support';
|
|
5
6
|
import { TypedHeaders, ResponseHeaderMap } from 'fetchdts';
|
|
6
|
-
import { Application, ServiceProvider } from '@h3ravel/core';
|
|
7
7
|
|
|
8
8
|
declare abstract class Middleware implements IMiddleware {
|
|
9
9
|
abstract handle(context: HttpContext, next: () => Promise<unknown>): Promise<unknown>;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
+
declare class LogRequests extends Middleware {
|
|
13
|
+
handle({ request }: HttpContext, next: () => Promise<unknown>): Promise<unknown>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Sets up HTTP kernel and request lifecycle.
|
|
18
|
+
*
|
|
19
|
+
* Register Request, Response, and Middleware classes.
|
|
20
|
+
* Configure global middleware stack.
|
|
21
|
+
* Boot HTTP kernel.
|
|
22
|
+
*
|
|
23
|
+
* Auto-Registered
|
|
24
|
+
*/
|
|
25
|
+
declare class HttpServiceProvider extends ServiceProvider {
|
|
26
|
+
static priority: number;
|
|
27
|
+
register(): void;
|
|
28
|
+
}
|
|
29
|
+
|
|
12
30
|
declare class Request implements IRequest {
|
|
13
31
|
/**
|
|
14
32
|
* The current app instance
|
|
@@ -53,72 +71,6 @@ declare class Request implements IRequest {
|
|
|
53
71
|
getEvent<K extends DotNestedKeys<H3Event>>(key: K): DotNestedValue<H3Event, K>;
|
|
54
72
|
}
|
|
55
73
|
|
|
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
|
-
|
|
104
|
-
declare class LogRequests extends Middleware {
|
|
105
|
-
handle({ request }: HttpContext, next: () => Promise<unknown>): Promise<unknown>;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Sets up HTTP kernel and request lifecycle.
|
|
110
|
-
*
|
|
111
|
-
* Register Request, Response, and Middleware classes.
|
|
112
|
-
* Configure global middleware stack.
|
|
113
|
-
* Boot HTTP kernel.
|
|
114
|
-
*
|
|
115
|
-
* Auto-Registered
|
|
116
|
-
*/
|
|
117
|
-
declare class HttpServiceProvider extends ServiceProvider {
|
|
118
|
-
static priority: number;
|
|
119
|
-
register(): void;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
74
|
interface Resource {
|
|
123
75
|
[key: string]: any;
|
|
124
76
|
pagination?: {
|
|
@@ -212,4 +164,52 @@ declare class JsonResource<R extends Resource = any> {
|
|
|
212
164
|
|
|
213
165
|
declare function ApiResource(instance: JsonResource): JsonResource<any>;
|
|
214
166
|
|
|
167
|
+
declare class Response implements IResponse {
|
|
168
|
+
/**
|
|
169
|
+
* The current app instance
|
|
170
|
+
*/
|
|
171
|
+
app: Application;
|
|
172
|
+
/**
|
|
173
|
+
* The current H3 H3Event instance
|
|
174
|
+
*/
|
|
175
|
+
private readonly event;
|
|
176
|
+
private statusCode;
|
|
177
|
+
private headers;
|
|
178
|
+
constructor(event: H3Event,
|
|
179
|
+
/**
|
|
180
|
+
* The current app instance
|
|
181
|
+
*/
|
|
182
|
+
app: Application);
|
|
183
|
+
/**
|
|
184
|
+
* Set HTTP status code.
|
|
185
|
+
*/
|
|
186
|
+
setStatusCode(code: number): this;
|
|
187
|
+
/**
|
|
188
|
+
* Set a header.
|
|
189
|
+
*/
|
|
190
|
+
setHeader(name: string, value: string): this;
|
|
191
|
+
html(content: string): string;
|
|
192
|
+
/**
|
|
193
|
+
* Send a JSON response.
|
|
194
|
+
*/
|
|
195
|
+
json<T = unknown>(data: T): T;
|
|
196
|
+
/**
|
|
197
|
+
* Send plain text.
|
|
198
|
+
*/
|
|
199
|
+
text(data: string): string;
|
|
200
|
+
/**
|
|
201
|
+
* Redirect to another URL.
|
|
202
|
+
*/
|
|
203
|
+
redirect(url: string, status?: number): string;
|
|
204
|
+
/**
|
|
205
|
+
* Apply headers before sending response.
|
|
206
|
+
*/
|
|
207
|
+
private applyHeaders;
|
|
208
|
+
/**
|
|
209
|
+
* Get the base event
|
|
210
|
+
*/
|
|
211
|
+
getEvent(): H3Event;
|
|
212
|
+
getEvent<K extends DotNestedKeys<H3Event>>(key: K): DotNestedValue<H3Event, K>;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
215
|
export { ApiResource, HttpServiceProvider, JsonResource, LogRequests, Middleware, Request, type Resource, Response };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,32 @@
|
|
|
1
1
|
import { IMiddleware, HttpContext, IRequest, IResponse } from '@h3ravel/shared';
|
|
2
2
|
export { HttpContext } from '@h3ravel/shared';
|
|
3
|
+
import { ServiceProvider, Application } from '@h3ravel/core';
|
|
3
4
|
import { H3Event, EventHandlerRequest } from 'h3';
|
|
4
5
|
import { DotNestedKeys, DotNestedValue } from '@h3ravel/support';
|
|
5
6
|
import { TypedHeaders, ResponseHeaderMap } from 'fetchdts';
|
|
6
|
-
import { Application, ServiceProvider } from '@h3ravel/core';
|
|
7
7
|
|
|
8
8
|
declare abstract class Middleware implements IMiddleware {
|
|
9
9
|
abstract handle(context: HttpContext, next: () => Promise<unknown>): Promise<unknown>;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
+
declare class LogRequests extends Middleware {
|
|
13
|
+
handle({ request }: HttpContext, next: () => Promise<unknown>): Promise<unknown>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Sets up HTTP kernel and request lifecycle.
|
|
18
|
+
*
|
|
19
|
+
* Register Request, Response, and Middleware classes.
|
|
20
|
+
* Configure global middleware stack.
|
|
21
|
+
* Boot HTTP kernel.
|
|
22
|
+
*
|
|
23
|
+
* Auto-Registered
|
|
24
|
+
*/
|
|
25
|
+
declare class HttpServiceProvider extends ServiceProvider {
|
|
26
|
+
static priority: number;
|
|
27
|
+
register(): void;
|
|
28
|
+
}
|
|
29
|
+
|
|
12
30
|
declare class Request implements IRequest {
|
|
13
31
|
/**
|
|
14
32
|
* The current app instance
|
|
@@ -53,72 +71,6 @@ declare class Request implements IRequest {
|
|
|
53
71
|
getEvent<K extends DotNestedKeys<H3Event>>(key: K): DotNestedValue<H3Event, K>;
|
|
54
72
|
}
|
|
55
73
|
|
|
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
|
-
|
|
104
|
-
declare class LogRequests extends Middleware {
|
|
105
|
-
handle({ request }: HttpContext, next: () => Promise<unknown>): Promise<unknown>;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Sets up HTTP kernel and request lifecycle.
|
|
110
|
-
*
|
|
111
|
-
* Register Request, Response, and Middleware classes.
|
|
112
|
-
* Configure global middleware stack.
|
|
113
|
-
* Boot HTTP kernel.
|
|
114
|
-
*
|
|
115
|
-
* Auto-Registered
|
|
116
|
-
*/
|
|
117
|
-
declare class HttpServiceProvider extends ServiceProvider {
|
|
118
|
-
static priority: number;
|
|
119
|
-
register(): void;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
74
|
interface Resource {
|
|
123
75
|
[key: string]: any;
|
|
124
76
|
pagination?: {
|
|
@@ -212,4 +164,52 @@ declare class JsonResource<R extends Resource = any> {
|
|
|
212
164
|
|
|
213
165
|
declare function ApiResource(instance: JsonResource): JsonResource<any>;
|
|
214
166
|
|
|
167
|
+
declare class Response implements IResponse {
|
|
168
|
+
/**
|
|
169
|
+
* The current app instance
|
|
170
|
+
*/
|
|
171
|
+
app: Application;
|
|
172
|
+
/**
|
|
173
|
+
* The current H3 H3Event instance
|
|
174
|
+
*/
|
|
175
|
+
private readonly event;
|
|
176
|
+
private statusCode;
|
|
177
|
+
private headers;
|
|
178
|
+
constructor(event: H3Event,
|
|
179
|
+
/**
|
|
180
|
+
* The current app instance
|
|
181
|
+
*/
|
|
182
|
+
app: Application);
|
|
183
|
+
/**
|
|
184
|
+
* Set HTTP status code.
|
|
185
|
+
*/
|
|
186
|
+
setStatusCode(code: number): this;
|
|
187
|
+
/**
|
|
188
|
+
* Set a header.
|
|
189
|
+
*/
|
|
190
|
+
setHeader(name: string, value: string): this;
|
|
191
|
+
html(content: string): string;
|
|
192
|
+
/**
|
|
193
|
+
* Send a JSON response.
|
|
194
|
+
*/
|
|
195
|
+
json<T = unknown>(data: T): T;
|
|
196
|
+
/**
|
|
197
|
+
* Send plain text.
|
|
198
|
+
*/
|
|
199
|
+
text(data: string): string;
|
|
200
|
+
/**
|
|
201
|
+
* Redirect to another URL.
|
|
202
|
+
*/
|
|
203
|
+
redirect(url: string, status?: number): string;
|
|
204
|
+
/**
|
|
205
|
+
* Apply headers before sending response.
|
|
206
|
+
*/
|
|
207
|
+
private applyHeaders;
|
|
208
|
+
/**
|
|
209
|
+
* Get the base event
|
|
210
|
+
*/
|
|
211
|
+
getEvent(): H3Event;
|
|
212
|
+
getEvent<K extends DotNestedKeys<H3Event>>(key: K): DotNestedValue<H3Event, K>;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
215
|
export { ApiResource, HttpServiceProvider, JsonResource, LogRequests, Middleware, Request, type Resource, Response };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
3
|
|
|
4
|
+
// src/Contracts/HttpContract.ts
|
|
5
|
+
import { HttpContext } from "@h3ravel/shared";
|
|
6
|
+
|
|
4
7
|
// src/Middleware.ts
|
|
5
8
|
var Middleware = class {
|
|
6
9
|
static {
|
|
@@ -8,6 +11,34 @@ var Middleware = class {
|
|
|
8
11
|
}
|
|
9
12
|
};
|
|
10
13
|
|
|
14
|
+
// src/Middleware/LogRequests.ts
|
|
15
|
+
var LogRequests = class extends Middleware {
|
|
16
|
+
static {
|
|
17
|
+
__name(this, "LogRequests");
|
|
18
|
+
}
|
|
19
|
+
async handle({ request }, next) {
|
|
20
|
+
const url = request.getEvent("url");
|
|
21
|
+
console.log(`[${request.getEvent("method")}] ${url.pathname + url.search}`);
|
|
22
|
+
return next();
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// src/Providers/HttpServiceProvider.ts
|
|
27
|
+
import { H3, serve } from "h3";
|
|
28
|
+
import { ServiceProvider } from "@h3ravel/core";
|
|
29
|
+
var HttpServiceProvider = class extends ServiceProvider {
|
|
30
|
+
static {
|
|
31
|
+
__name(this, "HttpServiceProvider");
|
|
32
|
+
}
|
|
33
|
+
static priority = 998;
|
|
34
|
+
register() {
|
|
35
|
+
this.app.singleton("http.app", () => {
|
|
36
|
+
return new H3();
|
|
37
|
+
});
|
|
38
|
+
this.app.singleton("http.serve", () => serve);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
11
42
|
// src/Request.ts
|
|
12
43
|
import { getQuery, getRouterParams, readBody } from "h3";
|
|
13
44
|
import { safeDot } from "@h3ravel/support";
|
|
@@ -69,110 +100,6 @@ var Request = class {
|
|
|
69
100
|
}
|
|
70
101
|
};
|
|
71
102
|
|
|
72
|
-
// src/Response.ts
|
|
73
|
-
import { safeDot as safeDot2 } from "@h3ravel/support";
|
|
74
|
-
import { html, redirect } from "h3";
|
|
75
|
-
var Response = class {
|
|
76
|
-
static {
|
|
77
|
-
__name(this, "Response");
|
|
78
|
-
}
|
|
79
|
-
app;
|
|
80
|
-
/**
|
|
81
|
-
* The current H3 H3Event instance
|
|
82
|
-
*/
|
|
83
|
-
event;
|
|
84
|
-
statusCode = 200;
|
|
85
|
-
headers = {};
|
|
86
|
-
constructor(event, app) {
|
|
87
|
-
this.app = app;
|
|
88
|
-
this.event = event;
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Set HTTP status code.
|
|
92
|
-
*/
|
|
93
|
-
setStatusCode(code) {
|
|
94
|
-
this.statusCode = code;
|
|
95
|
-
this.event.res.status = code;
|
|
96
|
-
return this;
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Set a header.
|
|
100
|
-
*/
|
|
101
|
-
setHeader(name, value) {
|
|
102
|
-
this.headers[name] = value;
|
|
103
|
-
return this;
|
|
104
|
-
}
|
|
105
|
-
html(content) {
|
|
106
|
-
this.applyHeaders();
|
|
107
|
-
return html(this.event, content);
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Send a JSON response.
|
|
111
|
-
*/
|
|
112
|
-
json(data) {
|
|
113
|
-
this.setHeader("content-type", "application/json; charset=utf-8");
|
|
114
|
-
this.applyHeaders();
|
|
115
|
-
return data;
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Send plain text.
|
|
119
|
-
*/
|
|
120
|
-
text(data) {
|
|
121
|
-
this.setHeader("content-type", "text/plain; charset=utf-8");
|
|
122
|
-
this.applyHeaders();
|
|
123
|
-
return data;
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Redirect to another URL.
|
|
127
|
-
*/
|
|
128
|
-
redirect(url, status = 302) {
|
|
129
|
-
this.setStatusCode(status);
|
|
130
|
-
return redirect(this.event, url, this.statusCode);
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Apply headers before sending response.
|
|
134
|
-
*/
|
|
135
|
-
applyHeaders() {
|
|
136
|
-
Object.entries(this.headers).forEach(([key, value]) => {
|
|
137
|
-
this.event.res.headers.set(key, value);
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
getEvent(key) {
|
|
141
|
-
return safeDot2(this.event, key);
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
// src/Contracts/HttpContract.ts
|
|
146
|
-
import { HttpContext } from "@h3ravel/shared";
|
|
147
|
-
|
|
148
|
-
// src/Middleware/LogRequests.ts
|
|
149
|
-
var LogRequests = class extends Middleware {
|
|
150
|
-
static {
|
|
151
|
-
__name(this, "LogRequests");
|
|
152
|
-
}
|
|
153
|
-
async handle({ request }, next) {
|
|
154
|
-
const url = request.getEvent("url");
|
|
155
|
-
console.log(`[${request.getEvent("method")}] ${url.pathname + url.search}`);
|
|
156
|
-
return next();
|
|
157
|
-
}
|
|
158
|
-
};
|
|
159
|
-
|
|
160
|
-
// src/Providers/HttpServiceProvider.ts
|
|
161
|
-
import { H3, serve } from "h3";
|
|
162
|
-
import { ServiceProvider } from "@h3ravel/core";
|
|
163
|
-
var HttpServiceProvider = class extends ServiceProvider {
|
|
164
|
-
static {
|
|
165
|
-
__name(this, "HttpServiceProvider");
|
|
166
|
-
}
|
|
167
|
-
static priority = 998;
|
|
168
|
-
register() {
|
|
169
|
-
this.app.singleton("http.app", () => {
|
|
170
|
-
return new H3();
|
|
171
|
-
});
|
|
172
|
-
this.app.singleton("http.serve", () => serve);
|
|
173
|
-
}
|
|
174
|
-
};
|
|
175
|
-
|
|
176
103
|
// src/Resources/JsonResource.ts
|
|
177
104
|
var JsonResource = class {
|
|
178
105
|
static {
|
|
@@ -220,10 +147,10 @@ var JsonResource = class {
|
|
|
220
147
|
Object.defineProperty(this, key, {
|
|
221
148
|
enumerable: true,
|
|
222
149
|
configurable: true,
|
|
223
|
-
get: () => this.resource[key],
|
|
224
|
-
set: (value) => {
|
|
150
|
+
get: /* @__PURE__ */ __name(() => this.resource[key], "get"),
|
|
151
|
+
set: /* @__PURE__ */ __name((value) => {
|
|
225
152
|
this.resource[key] = value;
|
|
226
|
-
}
|
|
153
|
+
}, "set")
|
|
227
154
|
});
|
|
228
155
|
}
|
|
229
156
|
}
|
|
@@ -348,6 +275,79 @@ function ApiResource(instance) {
|
|
|
348
275
|
});
|
|
349
276
|
}
|
|
350
277
|
__name(ApiResource, "ApiResource");
|
|
278
|
+
|
|
279
|
+
// src/Response.ts
|
|
280
|
+
import { safeDot as safeDot2 } from "@h3ravel/support";
|
|
281
|
+
import { html, redirect } from "h3";
|
|
282
|
+
var Response = class {
|
|
283
|
+
static {
|
|
284
|
+
__name(this, "Response");
|
|
285
|
+
}
|
|
286
|
+
app;
|
|
287
|
+
/**
|
|
288
|
+
* The current H3 H3Event instance
|
|
289
|
+
*/
|
|
290
|
+
event;
|
|
291
|
+
statusCode = 200;
|
|
292
|
+
headers = {};
|
|
293
|
+
constructor(event, app) {
|
|
294
|
+
this.app = app;
|
|
295
|
+
this.event = event;
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Set HTTP status code.
|
|
299
|
+
*/
|
|
300
|
+
setStatusCode(code) {
|
|
301
|
+
this.statusCode = code;
|
|
302
|
+
this.event.res.status = code;
|
|
303
|
+
return this;
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Set a header.
|
|
307
|
+
*/
|
|
308
|
+
setHeader(name, value) {
|
|
309
|
+
this.headers[name] = value;
|
|
310
|
+
return this;
|
|
311
|
+
}
|
|
312
|
+
html(content) {
|
|
313
|
+
this.applyHeaders();
|
|
314
|
+
return html(this.event, content);
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Send a JSON response.
|
|
318
|
+
*/
|
|
319
|
+
json(data) {
|
|
320
|
+
this.setHeader("content-type", "application/json; charset=utf-8");
|
|
321
|
+
this.applyHeaders();
|
|
322
|
+
return data;
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Send plain text.
|
|
326
|
+
*/
|
|
327
|
+
text(data) {
|
|
328
|
+
this.setHeader("content-type", "text/plain; charset=utf-8");
|
|
329
|
+
this.applyHeaders();
|
|
330
|
+
return data;
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Redirect to another URL.
|
|
334
|
+
*/
|
|
335
|
+
redirect(url, status = 302) {
|
|
336
|
+
this.setStatusCode(status);
|
|
337
|
+
return redirect(this.event, url, this.statusCode);
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Apply headers before sending response.
|
|
341
|
+
*/
|
|
342
|
+
applyHeaders() {
|
|
343
|
+
Object.entries(this.headers).forEach(([key, value]) => {
|
|
344
|
+
this.event.res.headers.set(key, value);
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
getEvent(key) {
|
|
348
|
+
return safeDot2(this.event, key);
|
|
349
|
+
}
|
|
350
|
+
};
|
|
351
351
|
export {
|
|
352
352
|
ApiResource,
|
|
353
353
|
HttpContext,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/Middleware.ts","../src/Request.ts","../src/Response.ts","../src/Contracts/HttpContract.ts","../src/Middleware/LogRequests.ts","../src/Providers/HttpServiceProvider.ts","../src/Resources/JsonResource.ts","../src/Resources/ApiResource.ts"],"sourcesContent":["import { HttpContext } from './Contracts/HttpContract'\nimport { IMiddleware } from '@h3ravel/shared'\n\nexport abstract class Middleware implements IMiddleware {\n abstract handle (context: HttpContext, next: () => Promise<unknown>): Promise<unknown>\n}\n","import { getQuery, getRouterParams, readBody, type H3Event } from 'h3'\nimport { DotNestedKeys, DotNestedValue, safeDot } from '@h3ravel/support'\nimport type { ResponseHeaderMap, TypedHeaders } from 'fetchdts'\nimport { IRequest } from '@h3ravel/shared'\nimport { Application } from '@h3ravel/core'\n\nexport class Request implements IRequest {\n /**\n * Gets route parameters.\n * @returns An object containing route parameters.\n */\n readonly params: NonNullable<H3Event[\"context\"][\"params\"]>\n\n /**\n * Gets query parameters.\n * @returns An object containing query parameters.\n */\n readonly query: Record<string, string>;\n\n /**\n * Gets the request headers.\n * @returns An object containing request headers.\n */\n readonly headers: TypedHeaders<Record<keyof ResponseHeaderMap, string>>\n\n /**\n * The current H3 H3Event instance\n */\n private readonly event: H3Event\n\n constructor(\n event: H3Event,\n /**\n * The current app instance\n */\n public app: Application\n ) {\n this.event = event\n this.query = getQuery(this.event)\n this.params = getRouterParams(this.event)\n this.headers = this.event.req.headers\n }\n\n /**\n * Get all input data (query + body).\n */\n async all<T = Record<string, unknown>> (): Promise<T> {\n let data = {\n ...getRouterParams(this.event),\n ...getQuery(this.event),\n } as T\n\n if (this.event.req.method === 'POST') {\n data = Object.assign({}, data, Object.fromEntries((await this.event.req.formData()).entries()))\n } else if (this.event.req.method === 'PUT') {\n data = <never>Object.fromEntries(Object.entries(<never>await readBody(this.event)))\n }\n\n return data\n }\n\n /**\n * Get a single input field from query or body.\n */\n async input<T = unknown> (key: string, defaultValue?: T): Promise<T> {\n const data = await this.all<Record<string, T>>()\n return (data[key] ?? defaultValue) as T\n }\n\n /**\n * Get the base event\n */\n getEvent (): H3Event\n getEvent<K extends DotNestedKeys<H3Event>> (key: K): DotNestedValue<H3Event, K>\n getEvent<K extends DotNestedKeys<H3Event>> (key?: K): any {\n return safeDot(this.event, key)\n }\n}\n","import { DotNestedKeys, DotNestedValue, safeDot } from '@h3ravel/support'\nimport { html, redirect, } from 'h3'\n\nimport { Application } from '@h3ravel/core'\nimport type { H3Event } from 'h3'\nimport { IResponse } from '@h3ravel/shared'\n\nexport class Response implements IResponse {\n /**\n * The current H3 H3Event instance\n */\n private readonly event: H3Event\n\n private statusCode: number = 200\n private headers: Record<string, string> = {}\n\n constructor(\n event: H3Event,\n /**\n * The current app instance\n */\n public app: Application\n ) {\n this.event = event\n }\n\n /**\n * Set HTTP status code.\n */\n setStatusCode (code: number): this {\n this.statusCode = code\n this.event.res.status = code\n return this\n }\n\n /**\n * Set a header.\n */\n setHeader (name: string, value: string): this {\n this.headers[name] = value\n return this\n }\n\n html (content: string): string {\n this.applyHeaders()\n return html(this.event, content)\n }\n\n /**\n * Send a JSON response.\n */\n json<T = unknown> (data: T): T {\n this.setHeader('content-type', 'application/json; charset=utf-8')\n this.applyHeaders()\n return data\n }\n\n /**\n * Send plain text.\n */\n text (data: string): string {\n this.setHeader('content-type', 'text/plain; charset=utf-8')\n this.applyHeaders()\n return data\n }\n\n /**\n * Redirect to another URL.\n */\n redirect (url: string, status = 302): string {\n this.setStatusCode(status)\n return redirect(this.event, url, this.statusCode)\n }\n\n /**\n * Apply headers before sending response.\n */\n private applyHeaders (): void {\n Object.entries(this.headers).forEach(([key, value]) => {\n this.event.res.headers.set(key, value)\n })\n }\n\n /**\n * Get the base event\n */\n getEvent (): H3Event\n getEvent<K extends DotNestedKeys<H3Event>> (key: K): DotNestedValue<H3Event, K>\n getEvent<K extends DotNestedKeys<H3Event>> (key?: K): any {\n return safeDot(this.event, key)\n }\n}\n","export { HttpContext } from '@h3ravel/shared'\n","import { HttpContext } from '@h3ravel/shared'\nimport { Middleware } from '../Middleware'\n\nexport class LogRequests extends Middleware {\n async handle ({ request }: HttpContext, next: () => Promise<unknown>): Promise<unknown> {\n const url = request.getEvent('url')\n console.log(`[${request.getEvent('method')}] ${url.pathname + url.search}`)\n return next()\n }\n}\n","import { H3, serve } from 'h3'\n\nimport { ServiceProvider } from '@h3ravel/core'\n\n/**\n * Sets up HTTP kernel and request lifecycle.\n * \n * Register Request, Response, and Middleware classes.\n * Configure global middleware stack.\n * Boot HTTP kernel.\n * \n * Auto-Registered\n */\nexport class HttpServiceProvider extends ServiceProvider {\n public static priority = 998;\n\n register () {\n this.app.singleton('http.app', () => {\n return new H3()\n })\n\n this.app.singleton('http.serve', () => serve)\n }\n}\n","import { EventHandlerRequest, H3Event } from 'h3'\n\nexport interface Resource {\n [key: string]: any;\n pagination?: {\n from?: number | undefined;\n to?: number | undefined;\n perPage?: number | undefined;\n total?: number | undefined;\n } | undefined;\n}\n\ntype BodyResource = Resource & {\n data: Omit<Resource, 'pagination'>,\n meta?: {\n pagination?: Resource['pagination']\n } | undefined;\n}\n\n/**\n * Class to render API resource\n */\nexport class JsonResource<R extends Resource = any> {\n /**\n * The request instance\n */\n request: H3Event<EventHandlerRequest>['req']\n /**\n * The response instance\n */\n response: H3Event['res']\n /**\n * The data to send to the client\n */\n resource: R\n /**\n * The final response data object\n */\n body: BodyResource = {\n data: {},\n }\n /**\n * Flag to track if response should be sent automatically\n */\n private shouldSend: boolean = false\n /**\n * Flag to track if response has been sent\n */\n\n private responseSent: boolean = false;\n\n /**\n * Declare that this includes R's properties\n */\n [key: string]: any;\n\n /**\n * @param req The request instance\n * @param res The response instance\n * @param rsc The data to send to the client\n */\n constructor(protected event: H3Event, rsc: R) {\n this.request = event.req\n this.response = event.res\n this.resource = rsc\n\n // Copy all properties from rsc to this, avoiding conflicts\n for (const key of Object.keys(rsc)) {\n if (!(key in this)) {\n Object.defineProperty(this, key, {\n enumerable: true,\n configurable: true,\n get: () => this.resource[key],\n set: (value) => {\n (<any>this.resource)[key] = value\n },\n })\n }\n }\n }\n\n /**\n * Return the data in the expected format\n * \n * @returns \n */\n data (): Resource {\n return this.resource\n }\n\n /**\n * Build the response object\n * @returns this\n */\n json () {\n // Indicate response should be sent automatically\n this.shouldSend = true\n\n // Set default status code\n this.response.status = 200\n\n // Prepare body\n const resource = this.data()\n let data: Resource = Array.isArray(resource) ? [...resource] : { ...resource }\n\n if (typeof data.data !== 'undefined') {\n data = data.data\n }\n\n if (!Array.isArray(resource)) {\n delete data.pagination\n }\n\n this.body = {\n data,\n }\n\n // Set the pagination from the data() resource, if available\n if (!Array.isArray(resource) && resource.pagination) {\n const meta: BodyResource['meta'] = this.body.meta ?? {}\n meta.pagination = resource.pagination\n this.body.meta = meta\n }\n\n // If pagination is not available on the resource, then check and set it\n // if it's available on the base resource.\n if (this.resource.pagination && !this.body.meta?.pagination) {\n const meta: BodyResource['meta'] = this.body.meta ?? {}\n meta.pagination = this.resource.pagination\n this.body.meta = meta\n }\n\n return this\n }\n\n /**\n * Add context data to the response object\n * @param data Context data\n * @returns this\n */\n additional<X extends { [key: string]: any }> (data: X) {\n\n // Allow automatic send after additional\n this.shouldSend = true\n\n // Merge data with body\n delete data.data\n delete data.pagination\n\n this.body = {\n ...this.body,\n ...data,\n }\n\n return this\n }\n\n /**\n * Send the output to the client\n * @returns this\n */\n send () {\n this.shouldSend = false // Prevent automatic send\n if (!this.responseSent) {\n this.#send()\n }\n return this\n }\n\n /**\n * Set the status code for this response\n * @param code Status code\n * @returns this\n */\n status (code: number) {\n this.response.status = code\n return this\n }\n\n /**\n * Private method to send the response\n */\n #send () {\n if (!this.responseSent) {\n this.event.context.\n this.response.json(this.body)\n\n // Mark response as sent\n this.responseSent = true\n }\n }\n\n /**\n * Check if send should be triggered automatically\n */\n private checkSend () {\n if (this.shouldSend && !this.responseSent) {\n this.#send()\n }\n }\n}\n","import { JsonResource, Resource } from './JsonResource'\n\nimport { H3Event } from 'h3'\n\nexport function ApiResource (\n instance: JsonResource\n) {\n return new Proxy(instance, {\n get (target, prop, receiver) {\n const value = Reflect.get(target, prop, receiver)\n if (typeof value === 'function') {\n // Intercept json, additional, and send methods\n if (prop === 'json' || prop === 'additional') {\n return (...args: any[]) => {\n const result = value.apply(target, args)\n // Schedule checkSend after json or additional\n setImmediate(() => target['checkSend']())\n return result\n }\n } else if (prop === 'send') {\n return (...args: any[]) => {\n // Prevent checkSend from firing\n target['shouldSend'] = false\n\n return value.apply(target, args)\n }\n }\n }\n return value\n },\n })\n}\n\nexport default function BaseResource<R extends Resource> (\n evt: H3Event,\n rsc: R\n) {\n return ApiResource(new JsonResource<R>(evt, rsc))\n}\n"],"mappings":";;;;AAGO,IAAeA,aAAf,MAAeA;EAAtB,OAAsBA;;;AAEtB;;;ACLA,SAASC,UAAUC,iBAAiBC,gBAA8B;AAClE,SAAwCC,eAAe;AAKhD,IAAMC,UAAN,MAAMA;EANb,OAMaA;;;;;;;;EAKAC;;;;;EAMAC;;;;;EAMAC;;;;EAKQC;EAEjB,YACIA,OAIOC,KACT;SADSA,MAAAA;AAEP,SAAKD,QAAQA;AACb,SAAKF,QAAQI,SAAS,KAAKF,KAAK;AAChC,SAAKH,SAASM,gBAAgB,KAAKH,KAAK;AACxC,SAAKD,UAAU,KAAKC,MAAMI,IAAIL;EAClC;;;;EAKA,MAAMM,MAAgD;AAClD,QAAIC,OAAO;MACP,GAAGH,gBAAgB,KAAKH,KAAK;MAC7B,GAAGE,SAAS,KAAKF,KAAK;IAC1B;AAEA,QAAI,KAAKA,MAAMI,IAAIG,WAAW,QAAQ;AAClCD,aAAOE,OAAOC,OAAO,CAAC,GAAGH,MAAME,OAAOE,aAAa,MAAM,KAAKV,MAAMI,IAAIO,SAAQ,GAAIC,QAAO,CAAA,CAAA;IAC/F,WAAW,KAAKZ,MAAMI,IAAIG,WAAW,OAAO;AACxCD,aAAcE,OAAOE,YAAYF,OAAOI,QAAe,MAAMC,SAAS,KAAKb,KAAK,CAAA,CAAA;IACpF;AAEA,WAAOM;EACX;;;;EAKA,MAAMQ,MAAoBC,KAAaC,cAA8B;AACjE,UAAMV,OAAO,MAAM,KAAKD,IAAG;AAC3B,WAAQC,KAAKS,GAAAA,KAAQC;EACzB;EAOAC,SAA4CF,KAAc;AACtD,WAAOG,QAAQ,KAAKlB,OAAOe,GAAAA;EAC/B;AACJ;;;AC7EA,SAAwCI,WAAAA,gBAAe;AACvD,SAASC,MAAMC,g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,QAAAA;AACxC,UAAI,OAAOC,UAAU,YAAY;AAE7B,YAAIF,SAAS,UAAUA,SAAS,cAAc;AAC1C,iBAAO,IAAII,SAAAA;AACP,kBAAMC,SAASH,MAAMI,MAAMP,QAAQK,IAAAA;AAEnCG,yBAAa,MAAMR,OAAO,WAAA,EAAY,CAAA;AACtC,mBAAOM;UACX;QACJ,WAAWL,SAAS,QAAQ;AACxB,iBAAO,IAAII,SAAAA;AAEPL,mBAAO,YAAA,IAAgB;AAEvB,mBAAOG,MAAMI,MAAMP,QAAQK,IAAAA;UAC/B;QACJ;MACJ;AACA,aAAOF;IACX;EACJ,CAAA;AACJ;AA3BgBP;","names":["Middleware","getQuery","getRouterParams","readBody","safeDot","Request","params","query","headers","event","app","getQuery","getRouterParams","req","all","data","method","Object","assign","fromEntries","formData","entries","readBody","input","key","defaultValue","getEvent","safeDot","safeDot","html","redirect","Response","event","statusCode","headers","app","setStatusCode","code","res","status","setHeader","name","value","html","content","applyHeaders","json","data","text","redirect","url","Object","entries","forEach","key","set","getEvent","safeDot","HttpContext","LogRequests","Middleware","handle","request","next","url","getEvent","console","log","pathname","search","H3","serve","ServiceProvider","HttpServiceProvider","ServiceProvider","priority","register","app","singleton","H3","serve","JsonResource","request","response","resource","body","data","shouldSend","responseSent","event","rsc","req","res","key","Object","keys","defineProperty","enumerable","configurable","get","set","value","json","status","Array","isArray","pagination","meta","additional","send","code","context","this","checkSend","ApiResource","instance","Proxy","get","target","prop","receiver","value","Reflect","args","result","apply","setImmediate"]}
|
|
1
|
+
{"version":3,"sources":["../src/Contracts/HttpContract.ts","../src/Middleware.ts","../src/Middleware/LogRequests.ts","../src/Providers/HttpServiceProvider.ts","../src/Request.ts","../src/Resources/JsonResource.ts","../src/Resources/ApiResource.ts","../src/Response.ts"],"sourcesContent":["export { HttpContext } from '@h3ravel/shared'\n","import { HttpContext } from './Contracts/HttpContract'\nimport { IMiddleware } from '@h3ravel/shared'\n\nexport abstract class Middleware implements IMiddleware {\n abstract handle (context: HttpContext, next: () => Promise<unknown>): Promise<unknown>\n}\n","import { HttpContext } from '@h3ravel/shared'\nimport { Middleware } from '../Middleware'\n\nexport class LogRequests extends Middleware {\n async handle ({ request }: HttpContext, next: () => Promise<unknown>): Promise<unknown> {\n const url = request.getEvent('url')\n console.log(`[${request.getEvent('method')}] ${url.pathname + url.search}`)\n return next()\n }\n}\n","import { H3, serve } from 'h3'\n\nimport { ServiceProvider } from '@h3ravel/core'\n\n/**\n * Sets up HTTP kernel and request lifecycle.\n * \n * Register Request, Response, and Middleware classes.\n * Configure global middleware stack.\n * Boot HTTP kernel.\n * \n * Auto-Registered\n */\nexport class HttpServiceProvider extends ServiceProvider {\n public static priority = 998;\n\n register () {\n this.app.singleton('http.app', () => {\n return new H3()\n })\n\n this.app.singleton('http.serve', () => serve)\n }\n}\n","import { getQuery, getRouterParams, readBody, type H3Event } from 'h3'\nimport { DotNestedKeys, DotNestedValue, safeDot } from '@h3ravel/support'\nimport type { ResponseHeaderMap, TypedHeaders } from 'fetchdts'\nimport { IRequest } from '@h3ravel/shared'\nimport { Application } from '@h3ravel/core'\n\nexport class Request implements IRequest {\n /**\n * Gets route parameters.\n * @returns An object containing route parameters.\n */\n readonly params: NonNullable<H3Event[\"context\"][\"params\"]>\n\n /**\n * Gets query parameters.\n * @returns An object containing query parameters.\n */\n readonly query: Record<string, string>;\n\n /**\n * Gets the request headers.\n * @returns An object containing request headers.\n */\n readonly headers: TypedHeaders<Record<keyof ResponseHeaderMap, string>>\n\n /**\n * The current H3 H3Event instance\n */\n private readonly event: H3Event\n\n constructor(\n event: H3Event,\n /**\n * The current app instance\n */\n public app: Application\n ) {\n this.event = event\n this.query = getQuery(this.event)\n this.params = getRouterParams(this.event)\n this.headers = this.event.req.headers\n }\n\n /**\n * Get all input data (query + body).\n */\n async all<T = Record<string, unknown>> (): Promise<T> {\n let data = {\n ...getRouterParams(this.event),\n ...getQuery(this.event),\n } as T\n\n if (this.event.req.method === 'POST') {\n data = Object.assign({}, data, Object.fromEntries((await this.event.req.formData()).entries()))\n } else if (this.event.req.method === 'PUT') {\n data = <never>Object.fromEntries(Object.entries(<never>await readBody(this.event)))\n }\n\n return data\n }\n\n /**\n * Get a single input field from query or body.\n */\n async input<T = unknown> (key: string, defaultValue?: T): Promise<T> {\n const data = await this.all<Record<string, T>>()\n return (data[key] ?? defaultValue) as T\n }\n\n /**\n * Get the base event\n */\n getEvent (): H3Event\n getEvent<K extends DotNestedKeys<H3Event>> (key: K): DotNestedValue<H3Event, K>\n getEvent<K extends DotNestedKeys<H3Event>> (key?: K): any {\n return safeDot(this.event, key)\n }\n}\n","import { EventHandlerRequest, H3Event } from 'h3'\n\nexport interface Resource {\n [key: string]: any;\n pagination?: {\n from?: number | undefined;\n to?: number | undefined;\n perPage?: number | undefined;\n total?: number | undefined;\n } | undefined;\n}\n\ntype BodyResource = Resource & {\n data: Omit<Resource, 'pagination'>,\n meta?: {\n pagination?: Resource['pagination']\n } | undefined;\n}\n\n/**\n * Class to render API resource\n */\nexport class JsonResource<R extends Resource = any> {\n /**\n * The request instance\n */\n request: H3Event<EventHandlerRequest>['req']\n /**\n * The response instance\n */\n response: H3Event['res']\n /**\n * The data to send to the client\n */\n resource: R\n /**\n * The final response data object\n */\n body: BodyResource = {\n data: {},\n }\n /**\n * Flag to track if response should be sent automatically\n */\n private shouldSend: boolean = false\n /**\n * Flag to track if response has been sent\n */\n\n private responseSent: boolean = false;\n\n /**\n * Declare that this includes R's properties\n */\n [key: string]: any;\n\n /**\n * @param req The request instance\n * @param res The response instance\n * @param rsc The data to send to the client\n */\n constructor(protected event: H3Event, rsc: R) {\n this.request = event.req\n this.response = event.res\n this.resource = rsc\n\n // Copy all properties from rsc to this, avoiding conflicts\n for (const key of Object.keys(rsc)) {\n if (!(key in this)) {\n Object.defineProperty(this, key, {\n enumerable: true,\n configurable: true,\n get: () => this.resource[key],\n set: (value) => {\n (<any>this.resource)[key] = value\n },\n })\n }\n }\n }\n\n /**\n * Return the data in the expected format\n * \n * @returns \n */\n data (): Resource {\n return this.resource\n }\n\n /**\n * Build the response object\n * @returns this\n */\n json () {\n // Indicate response should be sent automatically\n this.shouldSend = true\n\n // Set default status code\n this.response.status = 200\n\n // Prepare body\n const resource = this.data()\n let data: Resource = Array.isArray(resource) ? [...resource] : { ...resource }\n\n if (typeof data.data !== 'undefined') {\n data = data.data\n }\n\n if (!Array.isArray(resource)) {\n delete data.pagination\n }\n\n this.body = {\n data,\n }\n\n // Set the pagination from the data() resource, if available\n if (!Array.isArray(resource) && resource.pagination) {\n const meta: BodyResource['meta'] = this.body.meta ?? {}\n meta.pagination = resource.pagination\n this.body.meta = meta\n }\n\n // If pagination is not available on the resource, then check and set it\n // if it's available on the base resource.\n if (this.resource.pagination && !this.body.meta?.pagination) {\n const meta: BodyResource['meta'] = this.body.meta ?? {}\n meta.pagination = this.resource.pagination\n this.body.meta = meta\n }\n\n return this\n }\n\n /**\n * Add context data to the response object\n * @param data Context data\n * @returns this\n */\n additional<X extends { [key: string]: any }> (data: X) {\n\n // Allow automatic send after additional\n this.shouldSend = true\n\n // Merge data with body\n delete data.data\n delete data.pagination\n\n this.body = {\n ...this.body,\n ...data,\n }\n\n return this\n }\n\n /**\n * Send the output to the client\n * @returns this\n */\n send () {\n this.shouldSend = false // Prevent automatic send\n if (!this.responseSent) {\n this.#send()\n }\n return this\n }\n\n /**\n * Set the status code for this response\n * @param code Status code\n * @returns this\n */\n status (code: number) {\n this.response.status = code\n return this\n }\n\n /**\n * Private method to send the response\n */\n #send () {\n if (!this.responseSent) {\n this.event.context.\n this.response.json(this.body)\n\n // Mark response as sent\n this.responseSent = true\n }\n }\n\n /**\n * Check if send should be triggered automatically\n */\n private checkSend () {\n if (this.shouldSend && !this.responseSent) {\n this.#send()\n }\n }\n}\n","import { JsonResource, Resource } from './JsonResource'\n\nimport { H3Event } from 'h3'\n\nexport function ApiResource (\n instance: JsonResource\n) {\n return new Proxy(instance, {\n get (target, prop, receiver) {\n const value = Reflect.get(target, prop, receiver)\n if (typeof value === 'function') {\n // Intercept json, additional, and send methods\n if (prop === 'json' || prop === 'additional') {\n return (...args: any[]) => {\n const result = value.apply(target, args)\n // Schedule checkSend after json or additional\n setImmediate(() => target['checkSend']())\n return result\n }\n } else if (prop === 'send') {\n return (...args: any[]) => {\n // Prevent checkSend from firing\n target['shouldSend'] = false\n\n return value.apply(target, args)\n }\n }\n }\n return value\n },\n })\n}\n\nexport default function BaseResource<R extends Resource> (\n evt: H3Event,\n rsc: R\n) {\n return ApiResource(new JsonResource<R>(evt, rsc))\n}\n","import { DotNestedKeys, DotNestedValue, safeDot } from '@h3ravel/support'\nimport { html, redirect, } from 'h3'\n\nimport { Application } from '@h3ravel/core'\nimport type { H3Event } from 'h3'\nimport { IResponse } from '@h3ravel/shared'\n\nexport class Response implements IResponse {\n /**\n * The current H3 H3Event instance\n */\n private readonly event: H3Event\n\n private statusCode: number = 200\n private headers: Record<string, string> = {}\n\n constructor(\n event: H3Event,\n /**\n * The current app instance\n */\n public app: Application\n ) {\n this.event = event\n }\n\n /**\n * Set HTTP status code.\n */\n setStatusCode (code: number): this {\n this.statusCode = code\n this.event.res.status = code\n return this\n }\n\n /**\n * Set a header.\n */\n setHeader (name: string, value: string): this {\n this.headers[name] = value\n return this\n }\n\n html (content: string): string {\n this.applyHeaders()\n return html(this.event, content)\n }\n\n /**\n * Send a JSON response.\n */\n json<T = unknown> (data: T): T {\n this.setHeader('content-type', 'application/json; charset=utf-8')\n this.applyHeaders()\n return data\n }\n\n /**\n * Send plain text.\n */\n text (data: string): string {\n this.setHeader('content-type', 'text/plain; charset=utf-8')\n this.applyHeaders()\n return data\n }\n\n /**\n * Redirect to another URL.\n */\n redirect (url: string, status = 302): string {\n this.setStatusCode(status)\n return redirect(this.event, url, this.statusCode)\n }\n\n /**\n * Apply headers before sending response.\n */\n private applyHeaders (): void {\n Object.entries(this.headers).forEach(([key, value]) => {\n this.event.res.headers.set(key, value)\n })\n }\n\n /**\n * Get the base event\n */\n getEvent (): H3Event\n getEvent<K extends DotNestedKeys<H3Event>> (key: K): DotNestedValue<H3Event, K>\n getEvent<K extends DotNestedKeys<H3Event>> (key?: K): any {\n return safeDot(this.event, key)\n }\n}\n"],"mappings":";;;;AAAA,SAASA,mBAAmB;;;ACGrB,IAAeC,aAAf,MAAeA;EAAtB,OAAsBA;;;AAEtB;;;ACFO,IAAMC,cAAN,cAA0BC,WAAAA;EAFjC,OAEiCA;;;EAC7B,MAAMC,OAAQ,EAAEC,QAAO,GAAiBC,MAAgD;AACpF,UAAMC,MAAMF,QAAQG,SAAS,KAAA;AAC7BC,YAAQC,IAAI,IAAIL,QAAQG,SAAS,QAAA,CAAA,KAAcD,IAAII,WAAWJ,IAAIK,MAAM,EAAE;AAC1E,WAAON,KAAAA;EACX;AACJ;;;ACTA,SAASO,IAAIC,aAAa;AAE1B,SAASC,uBAAuB;AAWzB,IAAMC,sBAAN,cAAkCC,gBAAAA;EAbzC,OAayCA;;;EACrC,OAAcC,WAAW;EAEzBC,WAAY;AACR,SAAKC,IAAIC,UAAU,YAAY,MAAA;AAC3B,aAAO,IAAIC,GAAAA;IACf,CAAA;AAEA,SAAKF,IAAIC,UAAU,cAAc,MAAME,KAAAA;EAC3C;AACJ;;;ACvBA,SAASC,UAAUC,iBAAiBC,gBAA8B;AAClE,SAAwCC,eAAe;AAKhD,IAAMC,UAAN,MAAMA;EANb,OAMaA;;;;;;;;EAKAC;;;;;EAMAC;;;;;EAMAC;;;;EAKQC;EAEjB,YACIA,OAIOC,KACT;SADSA,MAAAA;AAEP,SAAKD,QAAQA;AACb,SAAKF,QAAQI,SAAS,KAAKF,KAAK;AAChC,SAAKH,SAASM,gBAAgB,KAAKH,KAAK;AACxC,SAAKD,UAAU,KAAKC,MAAMI,IAAIL;EAClC;;;;EAKA,MAAMM,MAAgD;AAClD,QAAIC,OAAO;MACP,GAAGH,gBAAgB,KAAKH,KAAK;MAC7B,GAAGE,SAAS,KAAKF,KAAK;IAC1B;AAEA,QAAI,KAA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AY;AACjB,WAAOE;EACX;;;;EAKAE,SAAUC,KAAaX,SAAS,KAAa;AACzC,SAAKH,cAAcG,MAAAA;AACnB,WAAOU,SAAS,KAAKjB,OAAOkB,KAAK,KAAKjB,UAAU;EACpD;;;;EAKQY,eAAsB;AAC1BM,WAAOC,QAAQ,KAAKlB,OAAO,EAAEmB,QAAQ,CAAC,CAACC,KAAKZ,KAAAA,MAAM;AAC9C,WAAKV,MAAMM,IAAIJ,QAAQqB,IAAID,KAAKZ,KAAAA;IACpC,CAAA;EACJ;EAOAc,SAA4CF,KAAc;AACtD,WAAOG,SAAQ,KAAKzB,OAAOsB,GAAAA;EAC/B;AACJ;","names":["HttpContext","Middleware","LogRequests","Middleware","handle","request","next","url","getEvent","console","log","pathname","search","H3","serve","ServiceProvider","HttpServiceProvider","ServiceProvider","priority","register","app","singleton","H3","serve","getQuery","getRouterParams","readBody","safeDot","Request","params","query","headers","event","app","getQuery","getRouterParams","req","all","data","method","Object","assign","fromEntries","formData","entries","readBody","input","key","defaultValue","getEvent","safeDot","JsonResource","request","response","resource","body","data","shouldSend","responseSent","event","rsc","req","res","key","Object","keys","defineProperty","enumerable","configurable","get","set","value","json","status","Array","isArray","pagination","meta","additional","send","code","context","this","checkSend","ApiResource","instance","Proxy","get","target","prop","receiver","value","Reflect","args","result","apply","setImmediate","safeDot","html","redirect","Response","event","statusCode","headers","app","setStatusCode","code","res","status","setHeader","name","value","html","content","applyHeaders","json","data","text","redirect","url","Object","entries","forEach","key","set","getEvent","safeDot"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@h3ravel/http",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "11.0.0",
|
|
4
4
|
"description": "HTTP kernel, middleware pipeline, request/response classes for H3ravel.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
"module": "./dist/index.js",
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
11
12
|
"import": "./dist/index.js",
|
|
12
|
-
"require": "./dist/index.cjs"
|
|
13
|
-
"types": "./dist/index.d.ts"
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
16
|
"files": [
|
|
@@ -38,11 +38,11 @@
|
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"h3": "^2.0.0-beta.1",
|
|
40
40
|
"srvx": "^0.8.2",
|
|
41
|
-
"@h3ravel/support": "^0.
|
|
42
|
-
"@h3ravel/shared": "^0.17.
|
|
41
|
+
"@h3ravel/support": "^0.9.0",
|
|
42
|
+
"@h3ravel/shared": "^0.17.2"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
|
-
"@h3ravel/core": "^1.
|
|
45
|
+
"@h3ravel/core": "^1.7.0"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"typescript": "^5.4.0"
|