Skip to content

Commit

Permalink
feat: include helpers with event
Browse files Browse the repository at this point in the history
  • Loading branch information
j4w8n committed Dec 8, 2024
1 parent f5306d0 commit 489a6c1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
6 changes: 5 additions & 1 deletion lib/xink.js
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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 */
Expand All @@ -78,6 +81,7 @@ export class Xink {
}
}
},
text,
url,
valid: {}
}
Expand Down
9 changes: 6 additions & 3 deletions types.d.ts
Original file line number Diff line number Diff line change
@@ -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<T, P> = { [K in keyof T]: Pick<T, K> }[keyof T]
interface AllowedValidatorTypes {
Expand All @@ -26,13 +25,17 @@ export type MaybePromise<T> = T | Promise<T>;
export interface RequestEvent<V extends AllowedValidatorTypes = AllowedValidatorTypes> {
cookies: Cookies;
headers: Omit<Headers, 'toJSON' | 'count' | 'getAll'>;
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<URL, 'createObjectURL' | 'revokeObjectURL' | 'canParse'>;
valid: V
valid: V;
}
export type ResolveEvent = (event: RequestEvent) => MaybePromise<Response>;

Expand Down

0 comments on commit 489a6c1

Please sign in to comment.