bun-crumb 0.10.0 → 0.12.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.
- package/dist/bench/src/constants/MB_MULTIPLIER.d.ts +10 -0
- package/dist/bench/src/fastifyRoutes.d.ts +1 -0
- package/dist/bench/src/handleBody.d.ts +1 -0
- package/dist/bench/src/headersMicroBench.d.ts +1 -0
- package/dist/bench/src/k6/constants.d.ts +1 -0
- package/dist/bench/src/k6/script.d.ts +6 -0
- package/dist/bench/src/k6/server.d.ts +1 -0
- package/dist/bench/src/prepareRoutes.d.ts +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +1 -1
- package/dist/internal/index.d.ts +1 -0
- package/dist/server.d.ts +2 -1
- package/dist/types/route.d.ts +9 -0
- package/dist/types/schema.d.ts +3 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const PORT: 59957;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.d.ts
CHANGED
|
@@ -13,12 +13,15 @@ import { BunRequest, CookieInit } from 'bun';
|
|
|
13
13
|
*
|
|
14
14
|
*
|
|
15
15
|
*
|
|
16
|
+
*
|
|
17
|
+
*
|
|
16
18
|
* declare module 'crumb-bun' {
|
|
17
19
|
* interface Schema {
|
|
18
20
|
* zod: ZodType;
|
|
19
21
|
* }
|
|
20
22
|
* }
|
|
21
23
|
* ```
|
|
24
|
+
*
|
|
22
25
|
*
|
|
23
26
|
* ```json
|
|
24
27
|
* // tsconfig.json
|
|
@@ -83,6 +86,7 @@ interface RouteRequestGeneric {
|
|
|
83
86
|
* Type of route handler `request` parameter
|
|
84
87
|
*/
|
|
85
88
|
interface RouteRequest<T extends RouteRequestGeneric = RouteRequestGeneric> extends Omit<BunRequest, 'params'> {
|
|
89
|
+
query: URLSearchParams;
|
|
86
90
|
params: RouteRequestParams<T['params']>;
|
|
87
91
|
/**
|
|
88
92
|
* #### Parses and validates body of request.
|
|
@@ -163,6 +167,14 @@ interface RouteResponse<T extends {
|
|
|
163
167
|
* ```
|
|
164
168
|
*/
|
|
165
169
|
setHeader: (name: Header['name'], value: Header['value']) => void;
|
|
170
|
+
/**
|
|
171
|
+
*
|
|
172
|
+
* @param options `Bun.Cookie` options parametr
|
|
173
|
+
*
|
|
174
|
+
*
|
|
175
|
+
*
|
|
176
|
+
*
|
|
177
|
+
*/
|
|
166
178
|
setCookie: (options: CookieInit) => void;
|
|
167
179
|
}
|
|
168
180
|
type Route = Partial<Record<HttpMethod, RouteOptions>>;
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{serve as e,Cookie as
|
|
1
|
+
import{serve as e,stdout as t,Cookie as n}from"bun";class s extends Error{status;constructor(e,t){super(t),this.status=e,this.name="HttpError"}}const r=new Map,o=(e,t)=>r=>{const o=r.headers.get("Content-Type")??"text/plain",a=r;return a.handleBody=()=>((e,t,n,r)=>{const o={"application/json":e=>e.json().catch(()=>{throw new s(400,"Bad Request")}).then(e=>{if(n&&r&&!r(e,n))throw new s(400,"Request does not match schema");return e}),"text/plain":e=>e.text().catch(e=>{throw new s(400,e)}).then(e=>{if(n&&r&&!r(e,n))throw new s(400,"Request does not match schema");return e})};return t in o?o[t](e):Promise.reject(new s(415,"Unsupported media type"))})(r,o,e.schema,t),a.query=new URLSearchParams(r.url.split("?")[1]||""),Promise.resolve(((e,t)=>{let s=200,r="",o="";const a=new Headers,c={send:(e,t)=>{"object"==typeof e?(a.has("Content-Type")||a.set("Content-Type","application/json"),o=JSON.stringify(e)):"string"==typeof e?(a.has("Content-Type")||a.set("Content-Type","text/plain"),o=e):o=e,t&&(s=t.status,r=t.statusText)},redirect:(e,t)=>{o="",s=t||302,a.set("Location",e)},setHeader:(e,t)=>{a.set(e,t)},setCookie:e=>{a.append("Set-Cookie",new n(e).toString())}};return Promise.resolve(t.handler(e,c)).then(()=>new Response(o,{headers:a,status:s,statusText:r}))})(a,e)).then(e=>e).catch(e=>e instanceof s?new Response(e.message,{status:e.status}):new Response("Internal server error",{status:500}))},a=(e,t)=>{const n={};for(const s in e)Object.hasOwn(e,s)&&(n[s]=o(e[s],t));return n},c=(e,t)=>{const n={};for(const s of e)n[s[0]]=a(s[1],t);return e.clear(),n},h=n=>{const s=e({port:n?.port,hostname:n?.hostname,development:n?.development??!1,routes:c(r,n?.schemaValidator)});t.write("Server is running on "+s.url.href+"\n")},i=e=>{const t=r.get(e.url);t?t[e.method]=e:r.set(e.url,{[e.method]:e})};export{i as createRoute,h as listen};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { _routes, prepareRoutes, handleBody } from '../server';
|
package/dist/server.d.ts
CHANGED
|
@@ -15,7 +15,8 @@ export type Routes = Map<RouteOptions['url'], Route>;
|
|
|
15
15
|
export declare const _routes: Routes;
|
|
16
16
|
/**
|
|
17
17
|
*
|
|
18
|
-
*
|
|
18
|
+
*
|
|
19
|
+
*
|
|
19
20
|
* Parses body to supported content type (json, plain text) and validates it with route schema.
|
|
20
21
|
*
|
|
21
22
|
* @param {BunRequest} request incoming bun request.
|
package/dist/types/route.d.ts
CHANGED
|
@@ -25,6 +25,7 @@ export interface RouteRequestGeneric {
|
|
|
25
25
|
* Type of route handler `request` parameter
|
|
26
26
|
*/
|
|
27
27
|
export interface RouteRequest<T extends RouteRequestGeneric = RouteRequestGeneric> extends Omit<BunRequest, 'params'> {
|
|
28
|
+
query: URLSearchParams;
|
|
28
29
|
params: RouteRequestParams<T['params']>;
|
|
29
30
|
/**
|
|
30
31
|
* #### Parses and validates body of request.
|
|
@@ -105,6 +106,14 @@ export interface RouteResponse<T extends {
|
|
|
105
106
|
* ```
|
|
106
107
|
*/
|
|
107
108
|
setHeader: (name: Header['name'], value: Header['value']) => void;
|
|
109
|
+
/**
|
|
110
|
+
*
|
|
111
|
+
* @param options `Bun.Cookie` options parametr
|
|
112
|
+
*
|
|
113
|
+
*
|
|
114
|
+
*
|
|
115
|
+
*
|
|
116
|
+
*/
|
|
108
117
|
setCookie: (options: CookieInit) => void;
|
|
109
118
|
}
|
|
110
119
|
export type Route = Partial<Record<HttpMethod, RouteOptions>>;
|
package/dist/types/schema.d.ts
CHANGED