diff --git a/src/components/nativePlugins/session.ts b/src/components/nativePlugins/session.ts index dde99ed..dd88683 100644 --- a/src/components/nativePlugins/session.ts +++ b/src/components/nativePlugins/session.ts @@ -1,7 +1,7 @@ import * as plugins from "../../exportable/plugin.ts"; import { f as cookieParser } from "../cookies/mainCookies.ts"; import type { Petition } from "../../morphism.ts"; -import type { CyclePlugin } from "../../options.ts"; + interface InnerElement { lastUsed: { @@ -124,7 +124,7 @@ const session = < tolerance?: number; autoDeleteTolerance?: number; injectMap?: Map; -}): CyclePlugin<{ isFunction: false; return: SessionType }> => { +}) => { // Declaring map const sym = Symbol("session"); const map = opt?.injectMap ?? new Map(); @@ -148,7 +148,7 @@ const session = < f: (ctx) => { return mapper(map)()(opt?.tolerance ?? 300000)(ctx.getPetition()); }, - }) as unknown as CyclePlugin<{ isFunction: false; return: SessionType }>; + }); }; export { session }; diff --git a/src/exportable/plugin.ts b/src/exportable/plugin.ts index d67f30f..be18501 100644 --- a/src/exportable/plugin.ts +++ b/src/exportable/plugin.ts @@ -7,7 +7,6 @@ import type { } from "../morphism.ts"; import checkerTools from "../composer/checkPetition/checkTools.ts"; import { - type CyclePlugin, type FunRouterOptions, globalOptions, } from "../options.ts"; diff --git a/src/morphism.ts b/src/morphism.ts index fee0dce..915cd7b 100644 --- a/src/morphism.ts +++ b/src/morphism.ts @@ -1113,32 +1113,24 @@ export type CryptoOptions = { }; } | {}; -export type StaticFilePlugin< - TP extends "response" | "request" | undefined, -> = { - checker: (path: string) => boolean; - type?: TP; +type StaticFileOptions = { + path: () => string + thisOptions: () => fileServerPetition + globalOptions: () => FunRouterOptions +} +type StaticFilePlugin <> = { + type?: 'add' async?: boolean; -} & StaticFilePluginExtensions; + checker?: (ctx: StaticFileOptions) => boolean; + f: (options: { + root: string; + path: string; + o?: FunRouterOptions; + relativeName: string; + }) => (req: Request) => Response +} + -export type StaticFilePluginExtensions< - TP extends "response" | "request" | undefined, -> = TP extends "request" ? { - f: (options: { - root: string; - path: string; - o?: FunRouterOptions; - relativeName: string; - }) => ReturnType>; - } - : { - r: (options: { - root: string; - path: string; - o?: FunRouterOptions; - relativeName: string; - }) => ReturnType>; - }; /** * Object for raw response static. @@ -1151,7 +1143,7 @@ export type fileServerPetition< path: string; mime?: MI; extra?: MI extends true ? [string, string][] : never; - template?: StaticFilePlugin[]; + template?: StaticFilePlugin[]; removeExtensionOf?: defaultMime[]; slashIs?: string; }; diff --git a/test/staticFile/main.test.ts b/test/staticFile/main.test.ts index a03b0fb..15688c3 100644 --- a/test/staticFile/main.test.ts +++ b/test/staticFile/main.test.ts @@ -1,7 +1,8 @@ import { assertEquals } from "@std/assert"; import { test } from "@cross/test"; import main from "../../src/staticFiles/staticFileMain.ts"; -import { type fileServerPetition, petitions } from "../../src/morphism.ts"; +import { type fileServerPetition } from "../../src/morphism.ts"; + test( "static file checking logo", @@ -68,13 +69,11 @@ test( name: "/hello/nested", mime: false, template: [{ - checker: (s) => s.includes(".png"), - type: "response", - r: (options) => - petitions.response()({ - path: options.relativeName.slice(0, -4), - r: () => new Response(""), - }), + checker: (s) => s.path().includes(".png"), + type: 'add', + f: (options) => + () => new Response(options.relativeName.slice(0, -4)), + }], } as fileServerPetition) .some((x) => x.path === "/hello/nested/logo"),