From 489a6c1cd99c6367d63ef018161a38013bd6bb6f Mon Sep 17 00:00:00 2001 From: Jason Creviston Date: Sun, 8 Dec 2024 12:42:52 -0500 Subject: [PATCH] feat: include helpers with event --- lib/xink.js | 6 +++++- types.d.ts | 9 ++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/xink.js b/lib/xink.js index 4a47864..ccd8f5c 100644 --- a/lib/xink.js +++ b/lib/xink.js @@ -1,6 +1,6 @@ /** @import { Cookie, RequestEvent } from '../types.js' */ -import { json, text } from './runtime/helpers.js' +import { json, text, html, redirect } from './runtime/helpers.js' import { initRouter } from './runtime/internal.js' import { addCookiesToHeaders, getCookies, isFormContentType, redirectResponse, resolve } from './runtime/fetch.js' import { Redirect } from './runtime/shared.js' @@ -57,8 +57,11 @@ export class Xink { const event = { cookies, headers: request.headers, + html, + json, locals: {}, params: params || {}, + redirect, request, store: store || null, /* ATTR: SvelteKit */ @@ -78,6 +81,7 @@ export class Xink { } } }, + text, url, valid: {} } diff --git a/types.d.ts b/types.d.ts index aa4e1df..ec96eae 100644 --- a/types.d.ts +++ b/types.d.ts @@ -1,7 +1,6 @@ import type { Store, Params } from "@xinkjs/xin" import type { SerializeOptions, ParseOptions } from "cookie" import type { Plugin } from 'vite' -import type { ApiConfig } from "vitest"; type AtLeastOne = { [K in keyof T]: Pick }[keyof T] interface AllowedValidatorTypes { @@ -26,13 +25,17 @@ export type MaybePromise = T | Promise; export interface RequestEvent { cookies: Cookies; headers: Omit; - locals: Api.Locals, + html: typeof html; + json: typeof json; + locals: Api.Locals; params: Params; + redirect: typeof redirect; request: Request; store: Store | null; setHeaders: (headers: { [key: string]: any; }) => void; + text: typeof text; url: Omit; - valid: V + valid: V; } export type ResolveEvent = (event: RequestEvent) => MaybePromise;