diesel-core 1.4.3 → 1.4.4
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/main.d.ts
CHANGED
@@ -2,10 +2,9 @@ import Trie from "./trie.js";
|
|
2
2
|
import { CompileConfig, ContextType, corsT, FilterMethods, HookFunction, HookType, listenArgsT, middlewareFunc, onError, onRequest, RouteNotFoundHandler, type handlerFunction, type Hooks, type HttpMethod } from "./types.js";
|
3
3
|
import { BunRequest, Server } from "bun";
|
4
4
|
import { AdvancedLoggerOptions, LoggerOptions } from "./middlewares/logger/logger.js";
|
5
|
-
import { ServerOptions } from "http";
|
6
5
|
export default class Diesel {
|
7
6
|
private static instance;
|
8
|
-
fecth:
|
7
|
+
fecth: any;
|
9
8
|
routes: Record<string, Function>;
|
10
9
|
private tempRoutes;
|
11
10
|
globalMiddlewares: middlewareFunc[];
|
@@ -52,7 +51,7 @@ export default class Diesel {
|
|
52
51
|
private loadRoutes;
|
53
52
|
useLogger(options: LoggerOptions): this;
|
54
53
|
useAdvancedLogger(options: AdvancedLoggerOptions): this;
|
55
|
-
BunRoute(method: string, path: string, ...
|
54
|
+
BunRoute(method: string, path: string, ...handlersOrResponse: any[]): this;
|
56
55
|
listen(port: any, ...args: listenArgsT[]): Server | void;
|
57
56
|
fetch(): (req: BunRequest, server: Server) => Promise<any>;
|
58
57
|
close(callback?: () => void): void;
|
@@ -1,3 +1,3 @@
|
|
1
|
-
var t={reset:"\x1B[0m",info:"\x1B[36m",warn:"\x1B[33m",error:"\x1B[31m",method:{GET:"\x1B[32m",POST:"\x1B[34m",PUT:"\x1B[35m",DELETE:"\x1B[31m",PATCH:"\x1B[36m"}},p=(
|
2
|
-
${
|
3
|
-
`)},$=(
|
1
|
+
var t={reset:"\x1B[0m",info:"\x1B[36m",warn:"\x1B[33m",error:"\x1B[31m",method:{GET:"\x1B[32m",POST:"\x1B[34m",PUT:"\x1B[35m",DELETE:"\x1B[31m",PATCH:"\x1B[36m"}},p=(i,n,o)=>{let a=t[i]||t.reset,g=o?.method?t.method[o.method]||t.reset:t.reset,u=o?.status?o.status>=500?t.error:o.status>=400?t.warn:t.info:t.reset;console.log(`
|
2
|
+
${a}[${i.toUpperCase()}]${t.reset} ${n} - ${g}${o?.method||""}${t.reset}`);let s={timestamp:new Date().toISOString(),...o,status:o?.status?`${u}${o.status}${t.reset}`:void 0,method:o?.method?`${g>a}${o.method}${t.reset}`:void 0};console.log(JSON.stringify(s,null,2)+`
|
3
|
+
`)},$=(i)=>{let{app:n,logger:o,logLevel:a="info",onRequest:g,onSend:u,onError:s}=i||{};n?.addHooks("onRequest",(e,r)=>{e.startTime=Date.now(),o?.()??p(a,"Incoming Request",{method:e.method,url:r,headers:{"user-agent":e.headers.get("user-agent"),"content-type":e.headers.get("content-type")}}),g?.(e,r)}),n?.addHooks("onSend",async(e)=>{let r=`${Date.now()-e.req.startTime}ms`;o?.()??p(a,"Response Sent",{method:e.req.method,url:e.url.toString(),status:e.status,duration:r,reqId:e.get?.("requestId"),headers:{"content-type":e.headers.get("content-type")}});let d=await u?.(e);if(d instanceof Response)return d}),n?.addHooks("onError",async(e,r,d)=>{o?.()??p("error","Unhandled Error",{method:r.method,url:d,status:500,error:e.message});let m=await s?.(e,r,d);if(m instanceof Response)return m})},c=(i,n,o,a=0,g,u)=>{let s=t.method[n]||t.reset,e=a>=500?t.error:a>=400?t.warn:t.info,r=u?`[${u}] `:"",d=i==="<--"?`${i} ${s}${n}${t.reset} ${o} ${r}`:`${i} ${s}${n}${t.reset} ${o} ${e}${a}${t.reset} ${g??""} ${r}`;console.log(d)},R=(i)=>{let n=Date.now()-i;return n<1000?`${n}ms`:`${Math.round(n/1000)}s`},h=(i)=>{let{app:n,log:o,onRequest:a,onSend:g,onError:u}=i;n.addHooks("onRequest",(s,e)=>{s.startTime=Date.now(),o?.()??c("<--",s.method,e),a?.(s,e)}),n.addHooks("onSend",async(s)=>{let{method:e,url:r}=s.req,d=new URL(r).pathname,m=s.get?.("requestId");o?.()??c("-->",e,d,s.status,R(s.req.startTime),m);let l=await g?.(s);if(l instanceof Response)return l}),n.addHooks("onError",async(s,e,r)=>{o?.()??c(s.message,e.method,r,500);let d=await u?.(s,e,r);if(d instanceof Response)return d})};export{h as logger,$ as advancedLogger};
|
@@ -1 +1 @@
|
|
1
|
-
class
|
1
|
+
class r{redis;constructor(t){this.redis=t}async get(t){let e=await this.redis.get(t);return e?parseInt(e):null}async set(t,e,s){await this.redis.set(t,e,"PX",s)}async reset(t){await this.redis.del(t)}}export{r as RedisStore};
|
@@ -1,3 +1,3 @@
|
|
1
1
|
import { CompileConfig, DieselT } from "./types";
|
2
2
|
export declare const buildRequestPipeline: (config: CompileConfig, diesel: DieselT) => any;
|
3
|
-
export declare const BunRequestPipline: (config: CompileConfig, diesel: DieselT, method: string, path: string, ...
|
3
|
+
export declare const BunRequestPipline: (config: CompileConfig, diesel: DieselT, method: string, path: string, ...handlersOrResponse: Function[]) => any;
|
package/dist/trie.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import type { handlerFunction, HttpMethod,
|
1
|
+
import type { handlerFunction, HttpMethod, RouteHandlerT } from "./types";
|
2
2
|
declare class TrieNode {
|
3
3
|
children: Record<string, TrieNode>;
|
4
4
|
isEndOfWord: boolean;
|
@@ -12,7 +12,7 @@ declare class TrieNode {
|
|
12
12
|
export default class Trie {
|
13
13
|
root: TrieNode;
|
14
14
|
constructor();
|
15
|
-
insert(path: string, route:
|
15
|
+
insert(path: string, route: RouteHandlerT): void;
|
16
16
|
search(path: string, method: HttpMethod): {
|
17
17
|
path: string;
|
18
18
|
handler: handlerFunction;
|