@h3ravel/http 11.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.
@@ -1 +1 @@
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,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QC;EAETC,aAAqB;EACrBC,UAAkC,CAAC;EAE3C,YACIF,OAIOG,KACT;SADSA,MAAAA;AAEP,SAAKH,QAAQA;EACjB;;;;EAKAI,cAAeC,MAAoB;AAC/B,SAAKJ,aAAaI;AAClB,SAAKL,MAAMM,IAAIC,SAASF;AACxB,WAAO;EACX;;;;EAKAG,UAAWC,MAAcC,OAAqB;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"]}
1
+ {"version":3,"file":"index.cjs","names":["ServiceProvider","H3","serve","app: Application","event: H3Event","data: Resource","meta: BodyResource['meta']","#send","app: Application"],"sources":["../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":["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 { safeDot } from '@h3ravel/support'\nimport type { DotNestedKeys, DotNestedValue } from '@h3ravel/shared'\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 type { DotNestedKeys, DotNestedValue } from '@h3ravel/shared'\nimport { html, redirect, } from 'h3'\n\nimport { Application } from '@h3ravel/core'\nimport type { H3Event } from 'h3'\nimport { IResponse } from '@h3ravel/shared'\nimport { safeDot } from '@h3ravel/support'\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,IAAsB,aAAtB,MAAwD;;;;ACAxD,IAAa,cAAb,cAAiC,WAAW;CACxC,MAAM,OAAQ,EAAE,WAAwB,MAAgD;EACpF,MAAM,MAAM,QAAQ,SAAS,MAAM;AACnC,UAAQ,IAAI,IAAI,QAAQ,SAAS,SAAS,CAAC,IAAI,IAAI,WAAW,IAAI,SAAS;AAC3E,SAAO,MAAM;;;;;;;;;;;;;;;ACMrB,IAAa,sBAAb,cAAyCA,+BAAgB;CACrD,OAAc,WAAW;CAEzB,WAAY;AACR,OAAK,IAAI,UAAU,kBAAkB;AACjC,UAAO,IAAIC,OAAI;IACjB;AAEF,OAAK,IAAI,UAAU,oBAAoBC,SAAM;;;;;;ACdrD,IAAa,UAAb,MAAyC;;;;;CAKrC,AA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@ -1,18 +1,21 @@
1
- import { IMiddleware, HttpContext, IRequest, IResponse } from '@h3ravel/shared';
2
- export { HttpContext } from '@h3ravel/shared';
3
- import { ServiceProvider, Application } from '@h3ravel/core';
4
- import { H3Event, EventHandlerRequest } from 'h3';
5
- import { DotNestedKeys, DotNestedValue } from '@h3ravel/support';
6
- import { TypedHeaders, ResponseHeaderMap } from 'fetchdts';
1
+ import { DotNestedKeys, DotNestedValue, HttpContext, HttpContext as HttpContext$1, IMiddleware, IRequest, IResponse } from "@h3ravel/shared";
2
+ import { Application, ServiceProvider } from "@h3ravel/core";
3
+ import { EventHandlerRequest, H3Event } from "h3";
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
-
10
+ //#endregion
11
+ //#region src/Middleware/LogRequests.d.ts
12
12
  declare class LogRequests extends Middleware {
13
- handle({ request }: HttpContext, next: () => Promise<unknown>): Promise<unknown>;
13
+ handle({
14
+ request
15
+ }: HttpContext$1, next: () => Promise<unknown>): Promise<unknown>;
14
16
  }
15
-
17
+ //#endregion
18
+ //#region src/Providers/HttpServiceProvider.d.ts
16
19
  /**
17
20
  * Sets up HTTP kernel and request lifecycle.
18
21
  *
@@ -23,193 +26,198 @@ declare class LogRequests extends Middleware {
23
26
  * Auto-Registered
24
27
  */
25
28
  declare class HttpServiceProvider extends ServiceProvider {
26
- static priority: number;
27
- register(): void;
29
+ static priority: number;
30
+ register(): void;
28
31
  }
29
-
32
+ //#endregion
33
+ //#region src/Request.d.ts
30
34
  declare class Request implements IRequest {
31
- /**
32
- * The current app instance
33
- */
34
- app: Application;
35
- /**
36
- * Gets route parameters.
37
- * @returns An object containing route parameters.
38
- */
39
- readonly params: NonNullable<H3Event["context"]["params"]>;
40
- /**
41
- * Gets query parameters.
42
- * @returns An object containing query parameters.
43
- */
44
- readonly query: Record<string, string>;
45
- /**
46
- * Gets the request headers.
47
- * @returns An object containing request headers.
48
- */
49
- readonly headers: TypedHeaders<Record<keyof ResponseHeaderMap, string>>;
50
- /**
51
- * The current H3 H3Event instance
52
- */
53
- private readonly event;
54
- constructor(event: H3Event,
55
- /**
56
- * The current app instance
57
- */
58
- app: Application);
59
- /**
60
- * Get all input data (query + body).
61
- */
62
- all<T = Record<string, unknown>>(): Promise<T>;
63
- /**
64
- * Get a single input field from query or body.
65
- */
66
- input<T = unknown>(key: string, defaultValue?: T): Promise<T>;
67
- /**
68
- * Get the base event
69
- */
70
- getEvent(): H3Event;
71
- getEvent<K extends DotNestedKeys<H3Event>>(key: K): DotNestedValue<H3Event, K>;
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>;
72
76
  }
73
-
77
+ //#endregion
78
+ //#region src/Resources/JsonResource.d.ts
74
79
  interface Resource {
75
- [key: string]: any;
76
- pagination?: {
77
- from?: number | undefined;
78
- to?: number | undefined;
79
- perPage?: number | undefined;
80
- total?: number | undefined;
81
- } | 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;
82
87
  }
83
88
  type BodyResource = Resource & {
84
- data: Omit<Resource, 'pagination'>;
85
- meta?: {
86
- pagination?: Resource['pagination'];
87
- } | undefined;
89
+ data: Omit<Resource, 'pagination'>;
90
+ meta?: {
91
+ pagination?: Resource['pagination'];
92
+ } | undefined;
88
93
  };
89
94
  /**
90
95
  * Class to render API resource
91
96
  */
92
97
  declare class JsonResource<R extends Resource = any> {
93
- #private;
94
- protected event: H3Event;
95
- /**
96
- * The request instance
97
- */
98
- request: H3Event<EventHandlerRequest>['req'];
99
- /**
100
- * The response instance
101
- */
102
- response: H3Event['res'];
103
- /**
104
- * The data to send to the client
105
- */
106
- resource: R;
107
- /**
108
- * The final response data object
109
- */
110
- body: BodyResource;
111
- /**
112
- * Flag to track if response should be sent automatically
113
- */
114
- private shouldSend;
115
- /**
116
- * Flag to track if response has been sent
117
- */
118
- private responseSent;
119
- /**
120
- * Declare that this includes R's properties
121
- */
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 {
122
151
  [key: string]: any;
123
- /**
124
- * @param req The request instance
125
- * @param res The response instance
126
- * @param rsc The data to send to the client
127
- */
128
- constructor(event: H3Event, rsc: R);
129
- /**
130
- * Return the data in the expected format
131
- *
132
- * @returns
133
- */
134
- data(): Resource;
135
- /**
136
- * Build the response object
137
- * @returns this
138
- */
139
- json(): this;
140
- /**
141
- * Add context data to the response object
142
- * @param data Context data
143
- * @returns this
144
- */
145
- additional<X extends {
146
- [key: string]: any;
147
- }>(data: X): this;
148
- /**
149
- * Send the output to the client
150
- * @returns this
151
- */
152
- send(): this;
153
- /**
154
- * Set the status code for this response
155
- * @param code Status code
156
- * @returns this
157
- */
158
- status(code: number): this;
159
- /**
160
- * Check if send should be triggered automatically
161
- */
162
- 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;
163
168
  }
164
-
169
+ //#endregion
170
+ //#region src/Resources/ApiResource.d.ts
165
171
  declare function ApiResource(instance: JsonResource): JsonResource<any>;
166
-
172
+ //#endregion
173
+ //#region src/Response.d.ts
167
174
  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>;
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>;
213
220
  }
214
-
215
- export { ApiResource, HttpServiceProvider, JsonResource, LogRequests, Middleware, Request, type Resource, Response };
221
+ //#endregion
222
+ export { ApiResource, HttpContext, HttpServiceProvider, JsonResource, LogRequests, Middleware, Request, Resource, Response };
223
+ //# sourceMappingURL=index.d.cts.map