bun-crumb 0.11.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.
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Multiplier between `bytes` and `megabytes`
3
+ *
4
+ * @example
5
+ * ```typescript
6
+ * const hugeBytes = 211_813_564;
7
+ * console.log(`Megabytes: `, hugeBytes / MB_MULTIPLIER);
8
+ * ```
9
+ */
10
+ export declare const MB_MULTIPLIER = 1048582;
@@ -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,6 @@
1
+ export namespace options {
2
+ let vus: number;
3
+ let duration: string;
4
+ }
5
+ declare function _default(): void;
6
+ export default _default;
@@ -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
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{serve as e,Cookie as t}from"bun";class s extends Error{status;constructor(e,t){super(t),this.status=e,this.name="HttpError"}}const n=new Map,o=(e,n)=>o=>{const r=o.headers.get("Content-Type")??"text/plain",a=o;return a.handleBody=()=>((e,t,n,o)=>{const r={"application/json":e=>e.json().catch(()=>{throw new s(400,"Bad Request")}).then(e=>{if(n&&o&&!o(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&&o&&!o(e,n))throw new s(400,"Request does not match schema");return e})};return t in r?r[t](e):Promise.reject(new s(415,"Unsupported media type"))})(o,r,e.schema,n),a.query=new URLSearchParams(o.url.split("?")[1]||""),Promise.resolve(((e,s)=>{let n=200,o="",r="";const a=new Headers,c={send:(e,t)=>{"object"==typeof e?(a.has("Content-Type")||a.set("Content-Type","application/json"),r=JSON.stringify(e)):"string"==typeof e?(a.has("Content-Type")||a.set("Content-Type","text/plain"),r=e):r=e,t&&(n=t.status,o=t.statusText)},redirect:(e,t)=>{r="",n=t||302,a.set("Location",e)},setHeader:(e,t)=>{a.set(e,t)},setCookie:e=>{a.append("Set-Cookie",new t(e).toString())}};return Promise.resolve(s.handler(e,c)).then(()=>new Response(r,{headers:a,status:n,statusText:o}))})(a,e)).then(e=>e).catch(e=>e instanceof s?new Response(e.message,{status:e.status}):new Response("Internal server error",{status:500}))},r=(e,t)=>{const s={};for(const n in e)Object.hasOwn(e,n)&&(s[n]=o(e[n],t));return s},a=(e,t)=>{const s={};for(const n of e)s[n[0]]=r(n[1],t);return e.clear(),s},c=t=>{e({port:t?.port,hostname:t?.hostname,development:t?.development??!1,routes:a(n,t?.schemaValidator)})},p=e=>{const t=n.get(e.url);t?t[e.method]=e:n.set(e.url,{[e.method]:e})};export{p as createRoute,c as listen};
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};
@@ -11,12 +11,15 @@
11
11
  *
12
12
  *
13
13
  *
14
+ *
15
+ *
14
16
  * declare module 'crumb-bun' {
15
17
  * interface Schema {
16
18
  * zod: ZodType;
17
19
  * }
18
20
  * }
19
21
  * ```
22
+ *
20
23
  *  
21
24
  * ```json
22
25
  * // tsconfig.json
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bun-crumb",
3
- "version": "0.11.0",
3
+ "version": "0.12.0",
4
4
  "author": "marigold",
5
5
  "module": "dist/index.js",
6
6
  "license": "UNLICENSED",